From: bert hubert Date: Sat, 7 Mar 2015 21:46:12 +0000 (+0100) Subject: strip dnsdist down to the bare essentials X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~88^2~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cffde2fd89926ba74188f57f2bd59b2d7bc5a008;p=thirdparty%2Fpdns.git strip dnsdist down to the bare essentials --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 0e2e2f63a6..bd05946bc4 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -556,30 +556,19 @@ dnstcpbench_LDADD = \ $(BOOST_PROGRAM_OPTIONS_LIBS) dnsdist_SOURCES = \ - arguments.cc \ base32.cc \ base64.cc base64.hh \ - dns.cc \ dnsdist.cc \ dnsdist-lua.cc \ dnslabeltext.cc \ dnsname.cc dnsname.hh \ - dnsparser.cc dnsparser.hh \ - dnsrecords.cc \ - dnswriter.cc dnswriter.hh \ + dnswriter.cc \ dolog.hh \ iputils.cc \ - logger.cc \ - lua-iputils.cc \ misc.cc misc.hh \ - nsecrecords.cc \ qtype.cc \ - rcpgenerator.cc rcpgenerator.hh \ - sillyrecords.cc \ sodcrypto.cc sodcrypto.hh \ - sstuff.hh \ - statbag.cc \ - unix_utility.cc + sstuff.hh dnsdist_LDFLAGS = \ $(AM_LDFLAGS) \ diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index c036e8f50a..38202f9bc2 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -106,7 +106,9 @@ vector> setupLua(bool client) g_lua.writeVariable("wrandom", ServerPolicy{"wrandom", wrandom}); g_lua.writeVariable("leastOutstanding", ServerPolicy{"leastOutstanding", leastOutstanding}); g_lua.writeFunction("addACL", [](const std::string& domain) { - g_ACL.addMask(domain); + auto state=g_ACL.getCopy(); + state->addMask(domain); + g_ACL.setState(state); }); g_lua.writeFunction("addLocal", [client](const std::string& addr) { @@ -121,19 +123,20 @@ vector> setupLua(bool client) } }); g_lua.writeFunction("setACL", [](const vector>& parts) { - NetmaskGroup nmg; - for(const auto& p : parts) { - nmg.addMask(p.second); - } - g_ACL=nmg; + auto nmg = std::make_shared(); + for(const auto& p : parts) { + nmg->addMask(p.second); + } + g_ACL.setState(nmg); }); g_lua.writeFunction("showACL", []() { vector vec; - g_ACL.toStringVector(&vec); - string ret; + + g_ACL.getCopy()->toStringVector(&vec); + for(const auto& s : vec) - ret+=s+"\n"; - return ret; + g_outputBuffer+=s+"\n"; + }); g_lua.writeFunction("shutdown", []() { _exit(0);} ); @@ -376,7 +379,7 @@ vector> setupLua(bool client) } } - cout<<"Looked at "<> rcounts; for(const auto& c : counts) rcounts.push_back(make_pair(c.second, c.first)); diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index bbce2725ae..26fe837acd 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -23,14 +23,12 @@ #include "dnsdist.hh" #include "sstuff.hh" #include "misc.hh" -#include "statbag.hh" #include #include -#include "arguments.hh" #include "dolog.hh" #include #include @@ -53,12 +51,6 @@ we offer now way to log from Lua */ -ArgvMap& arg() -{ - static ArgvMap a; - return a; -} -StatBag S; namespace po = boost::program_options; po::variables_map g_vm; using std::atomic; @@ -68,7 +60,8 @@ atomic g_pos; atomic g_regexBlocks; uint16_t g_maxOutstanding; bool g_console; -NetmaskGroup g_ACL; + +GlobalStateHolder g_ACL; string g_outputBuffer; vector g_locals; @@ -303,13 +296,15 @@ try if(candidate) blockFilter = *candidate; } + auto acl = g_ACL.getLocal(); for(;;) { try { len = recvfrom(cs->udpFD, packet, sizeof(packet), 0, (struct sockaddr*) &remote, &socklen); if(len < (int)sizeof(struct dnsheader)) continue; + - if(!g_ACL.match(remote)) + if(!acl->match(remote)) continue; if(dh->qr) // don't respond to responses @@ -999,9 +994,10 @@ try for(auto& t : todo) t(); + auto acl = g_ACL.getCopy(); for(auto& addr : {"127.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "169.254.0.0/16", "192.168.0.0/16", "172.16.0.0/12", "::1/128", "fc00::/7", "fe80::/10"}) - g_ACL.addMask(addr); - + acl->addMask(addr); + g_ACL.setState(acl); if(g_vm.count("remotes")) { for(const auto& address : g_vm["remotes"].as>()) {