diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-31 19:17:04 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-31 19:17:04 +0000 |
commit | 6a6f5b2275b1bfc0ab1e2b1393ec1df2fa734c86 (patch) | |
tree | 5581a4ad71a9c3e44e6729fde2d8ca708f046636 | |
parent | 739b08770578b891cab4c824ca29eeb01445457f (diff) |
Add missing feature: /rehash reinitializes dns subsytem (and can handle changed addresses)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6193 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/dns.h | 5 | ||||
-rw-r--r-- | src/cmd_rehash.cpp | 1 | ||||
-rw-r--r-- | src/dns.cpp | 52 | ||||
-rw-r--r-- | src/inspircd.cpp | 1 | ||||
-rw-r--r-- | src/modules.cpp | 1 |
5 files changed, 36 insertions, 24 deletions
diff --git a/include/dns.h b/include/dns.h index 038323a43..92f3fe8f7 100644 --- a/include/dns.h +++ b/include/dns.h @@ -353,6 +353,11 @@ class DNS : public EventHandler DNS(InspIRCd* Instance); /** + * Re-initialize the DNS subsystem. + */ + void Rehash(); + + /** * Destructor */ ~DNS(); diff --git a/src/cmd_rehash.cpp b/src/cmd_rehash.cpp index f5e65d6b2..579c04300 100644 --- a/src/cmd_rehash.cpp +++ b/src/cmd_rehash.cpp @@ -40,6 +40,7 @@ CmdResult cmd_rehash::Handle (const char** parameters, int pcnt, userrec *user) ServerInstance->RehashUsersAndChans(); FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); ServerInstance->Config->Read(false,user); + ServerInstance->Res->Rehash(); } if (old_disabled != ServerInstance->Config->DisabledCommands) InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance); diff --git a/src/dns.cpp b/src/dns.cpp index 756c2d5dc..66c0d8085 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -250,40 +250,23 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id) return req; } -/** Initialise the DNS UDP socket so that we can send requests */ -DNS::DNS(InspIRCd* Instance) : ServerInstance(Instance) +void DNS::Rehash() { - ServerInstance->Log(DEBUG,"DNS::DNS: Instance = %08x",Instance); - insp_inaddr addr; - - /* Clear the Resolver class table */ - memset(Classes,0,sizeof(Classes)); - - /* Clear the requests class table */ - memset(requests,0,sizeof(requests)); - - /* Set the id of the next request to 0 - */ - currid = 0; - - /* By default we're not munging ip's - */ ip6munge = false; - /* Clear the namesever address */ - memset(&myserver,0,sizeof(insp_inaddr)); + if (this->GetFd() > -1) + { + shutdown(this->GetFd(), 2); + close(this->GetFd()); + this->SetFd(-1); + } - /* Convert the nameserver address into an insp_inaddr */ if (insp_aton(ServerInstance->Config->DNSServer,&addr) > 0) { memcpy(&myserver,&addr,sizeof(insp_inaddr)); if ((strstr(ServerInstance->Config->DNSServer,"::ffff:") == (char*)&ServerInstance->Config->DNSServer) || (strstr(ServerInstance->Config->DNSServer,"::FFFF:") == (char*)&ServerInstance->Config->DNSServer)) { - /* These dont come back looking like they did when they went in. - * We're forced to turn some checks off. - * If anyone knows how to fix this, let me know. --Brain - */ ServerInstance->Log(DEFAULT,"WARNING: Using IPv4 addresses over IPv6 forces some DNS checks to be disabled."); ServerInstance->Log(DEFAULT," This should not cause a problem, however it is recommended you migrate"); ServerInstance->Log(DEFAULT," to a true IPv6 environment."); @@ -313,6 +296,7 @@ DNS::DNS(InspIRCd* Instance) : ServerInstance(Instance) { ServerInstance->Log(DEBUG,"I cant socket() this socket! (%s)",strerror(errno)); } + /* Have we got a socket and is it nonblocking? */ if (this->GetFd() != -1) { @@ -357,6 +341,26 @@ DNS::DNS(InspIRCd* Instance) : ServerInstance(Instance) } } +/** Initialise the DNS UDP socket so that we can send requests */ +DNS::DNS(InspIRCd* Instance) : ServerInstance(Instance) +{ + ServerInstance->Log(DEBUG,"DNS::DNS: Instance = %08x",Instance); + + /* Clear the Resolver class table */ + memset(Classes,0,sizeof(Classes)); + + /* Clear the requests class table */ + memset(requests,0,sizeof(requests)); + + /* Set the id of the next request to 0 + */ + currid = 0; + + this->SetFd(-1); + + this->Rehash(); +} + /** Build a payload to be placed after the header, based upon input data, a resource type, a class and a pointer to a buffer */ int DNS::MakePayload(const char * const name, const QueryType rr, const unsigned short rr_class, unsigned char * const payload) { diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 4b86d3816..9905a78d0 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -143,6 +143,7 @@ void InspIRCd::Rehash(int status) SI->RehashUsersAndChans(); FOREACH_MOD_I(SI, I_OnGarbageCollect, OnGarbageCollect()); SI->Config->Read(false,NULL); + SI->Res->Rehash(); FOREACH_MOD_I(SI,I_OnRehash,OnRehash("")); } diff --git a/src/modules.cpp b/src/modules.cpp index 69506c7a6..a67ebc6da 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -348,6 +348,7 @@ void InspIRCd::RehashServer() this->WriteOpers("*** Rehashing config file"); this->RehashUsersAndChans(); this->Config->Read(false,NULL); + this->Res->Rehash(); } /* This is ugly, yes, but hash_map's arent designed to be |