--- natd.c Thu Dec 20 13:21:46 2001 +++ natd.c Wed Jun 12 21:59:31 2002 @@ -86,6 +86,7 @@ static void InitiateShutdown (int); static void Shutdown (int); static void RefreshAddr (int); +static void SetReloadConfig (int); static void ParseOption (const char* option, const char* parms); static void ReadConfigFile (const char* fileName); static void SetupPortRedirect (const char* parms); @@ -97,8 +98,10 @@ static int StrToProto (const char* str); static int StrToAddrAndPortRange (const char* str, struct in_addr* addr, char* proto, port_range *portRange); static void ParseArgs (int argc, char** argv); +static void ReloadConfig (int argc, char** argv); static void FlushPacketBuffer (int fd); static void SetupPunchFW(const char *strValue); +static void StoreLink(struct alias_link* link); /* * Globals. @@ -108,6 +111,7 @@ static int background; static int running; static int assignAliasAddr; +static int doReloadConfig; static char* ifName; static int ifIndex; static u_short inPort; @@ -127,6 +131,8 @@ static int logDropped; static int logFacility; static int logIpfwDenied; +static int aliasCount; +static struct alias_link* aliasLinks[128*1024]; int main (int argc, char** argv) { @@ -162,6 +168,7 @@ logDropped = 0; logFacility = LOG_DAEMON; logIpfwDenied = -1; + aliasCount = 0; /* * Mark packet buffer empty. */ @@ -298,13 +305,15 @@ if (!verbose) DaemonMode (); /* - * Catch signals to manage shutdown and - * refresh of interface address. + * Catch signals to manage shutdown, + * refresh of interface address and + * reloading of configuration. */ + doReloadConfig = 0; siginterrupt(SIGTERM, 1); siginterrupt(SIGHUP, 1); signal (SIGTERM, InitiateShutdown); - signal (SIGHUP, RefreshAddr); + signal (SIGHUP, SetReloadConfig); /* * Set alias address if it has been given. */ @@ -384,6 +393,9 @@ Quit ("Select failed."); } + if (doReloadConfig) + ReloadConfig(argc, argv); + if (packetSock != -1) if (FD_ISSET (packetSock, &writeMask)) FlushPacketBuffer (packetSock); @@ -426,6 +438,25 @@ } } +static void ReloadConfig (int argc, char** argv) +{ + int i; + + if (verbose) + printf("Reloading config on signal HUP\n"); + doReloadConfig = 0; + for (i = 0; i < aliasCount; i++) { + PacketAliasRedirectDelete(aliasLinks[i]); + } + aliasCount = 0; + ParseArgs(argc, argv); +} + +static void StoreLink (struct alias_link* link) +{ + aliasLinks[aliasCount++] = link; +} + static void ParseArgs (int argc, char** argv) { int arg; @@ -838,6 +869,15 @@ assignAliasAddr = 1; } +static void SetReloadConfig (int sig) +{ + if (verbose) + printf("Caught SIGHUP\n"); + doReloadConfig = 1; + if (ifName) + assignAliasAddr = 1; +} + static void InitiateShutdown (int sig) { /* @@ -1495,6 +1535,7 @@ publicAddr, htons(publicPort + i), proto); + StoreLink(link); } /* @@ -1526,6 +1567,7 @@ int proto; char* protoName; struct protoent *protoent; + struct alias_link* link; strcpy (buf, parms); /* @@ -1567,8 +1609,9 @@ /* * Create aliasing link. */ - (void)PacketAliasRedirectProto(localAddr, remoteAddr, publicAddr, + link = PacketAliasRedirectProto(localAddr, remoteAddr, publicAddr, proto); + StoreLink(link); } void SetupAddressRedirect (const char* parms) @@ -1579,7 +1622,7 @@ struct in_addr localAddr; struct in_addr publicAddr; char* serverPool; - struct alias_link *link; + struct alias_link* link; strcpy (buf, parms); /* @@ -1606,6 +1649,7 @@ StrToAddr (ptr, &publicAddr); link = PacketAliasRedirectAddr(localAddr, publicAddr); + StoreLink(link); /* * Setup LSNAT server pool.