diff options
author | Adam <Adam@anope.org> | 2016-03-27 20:25:16 -0400 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2016-03-29 15:48:18 +0200 |
commit | 896bb56f5a7f4c9ef7f4ae8c180255a71d218453 (patch) | |
tree | 6d67b57e290c68062d5add8c7401ead5d2b574a0 /src/coremods | |
parent | 8d716c51554b19d112b22ad84a97f6e2233eedaa (diff) |
core_dns: allow configuring source address
Diffstat (limited to 'src/coremods')
-rw-r--r-- | src/coremods/core_dns.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index 1e8bb7533..1e7f6afca 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -658,7 +658,7 @@ class MyManager : public Manager, public Timer, public EventHandler return true; } - void Rehash(const std::string& dnsserver) + void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport) { if (this->GetFd() > -1) { @@ -682,8 +682,15 @@ class MyManager : public Manager, public Timer, public EventHandler SocketEngine::NonBlocking(s); irc::sockets::sockaddrs bindto; - memset(&bindto, 0, sizeof(bindto)); - bindto.sa.sa_family = myserver.sa.sa_family; + if (sourceaddr.empty()) + { + // set a sourceaddr for irc::sockets::aptosa() based on the servers af type + if (myserver.sa.sa_family == AF_INET) + sourceaddr = "0.0.0.0"; + else if (myserver.sa.sa_family == AF_INET6) + sourceaddr = "::"; + } + irc::sockets::aptosa(sourceaddr, sourceport, bindto); if (SocketEngine::Bind(this->GetFd(), bindto) < 0) { @@ -698,6 +705,9 @@ class MyManager : public Manager, public Timer, public EventHandler SocketEngine::Close(this->GetFd()); this->SetFd(-1); } + + if (bindto.sa.sa_family != myserver.sa.sa_family) + ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Nameserver address family differs from source address family - hostnames might not resolve"); } else { @@ -710,6 +720,8 @@ class ModuleDNS : public Module { MyManager manager; std::string DNSServer; + std::string SourceIP; + unsigned int SourcePort; void FindDNSServer() { @@ -770,19 +782,27 @@ class ModuleDNS : public Module } public: - ModuleDNS() : manager(this) + ModuleDNS() : manager(this) + , SourcePort(0) { } void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { std::string oldserver = DNSServer; - DNSServer = ServerInstance->Config->ConfValue("dns")->getString("server"); + const std::string oldip = SourceIP; + const unsigned int oldport = SourcePort; + + ConfigTag* tag = ServerInstance->Config->ConfValue("dns"); + DNSServer = tag->getString("server"); + SourceIP = tag->getString("sourceip"); + SourcePort = tag->getInt("sourceport", 0, 0, 65535); + if (DNSServer.empty()) FindDNSServer(); - if (oldserver != DNSServer) - this->manager.Rehash(DNSServer); + if (oldserver != DNSServer || oldip != SourceIP || oldport != SourcePort) + this->manager.Rehash(DNSServer, SourceIP, SourcePort); } void OnUnloadModule(Module* mod) |