From: Remi Gacogne Date: Fri, 12 Nov 2021 17:04:44 +0000 (+0100) Subject: dnsdist: More options to disable features, fix compilation on OpenWRT X-Git-Tag: auth-4.7.0-alpha1~103^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=393ed4889ccc2dd1a0fef0a6a965418cd8638c45;p=thirdparty%2Fpdns.git dnsdist: More options to disable features, fix compilation on OpenWRT --- diff --git a/pdns/dnsdist-lua-bindings-dnsquestion.cc b/pdns/dnsdist-lua-bindings-dnsquestion.cc index 2baa1c9bdc..40919afdac 100644 --- a/pdns/dnsdist-lua-bindings-dnsquestion.cc +++ b/pdns/dnsdist-lua-bindings-dnsquestion.cc @@ -26,6 +26,7 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx) { +#ifndef DISABLE_NON_FFI_DQ_BINDINGS /* DNSQuestion */ /* PowerDNS DNSQuestion compat */ luaCtx.registerMember("localaddr", [](const DNSQuestion& dq) -> const ComboAddress { return *dq.local; }, [](DNSQuestion& dq, const ComboAddress newLocal) { (void) newLocal; }); @@ -306,4 +307,5 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx) checkParameterBound("setNegativeAndAdditionalSOA", minimum, std::numeric_limits::max()); return setNegativeAndAdditionalSOA(dq, nxd, DNSName(zone), ttl, DNSName(mname), DNSName(rname), serial, refresh, retry, expire, minimum); }); +#endif /* DISABLE_NON_FFI_DQ_BINDINGS */ } diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index 265f712aad..bc264ab67e 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -57,6 +57,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) } return string("No exception"); }); +#ifndef DISABLE_POLICIES_BINDINGS /* ServerPolicy */ luaCtx.writeFunction("newServerPolicy", [](string name, ServerPolicy::policyfunc_t policy) { return std::make_shared(name, policy, true);}); luaCtx.registerMember("name", &ServerPolicy::d_name); @@ -74,6 +75,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.writeVariable("whashed", ServerPolicy{"whashed", whashed, false}); luaCtx.writeVariable("chashed", ServerPolicy{"chashed", chashed, false}); luaCtx.writeVariable("leastOutstanding", ServerPolicy{"leastOutstanding", leastOutstanding, false}); +#endif /* DISABLE_POLICIES_BINDINGS */ /* ServerPool */ luaCtx.registerFunction::*)(std::shared_ptr)>("setCache", [](std::shared_ptr pool, std::shared_ptr cache) { @@ -90,6 +92,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.registerFunction("getECS", &ServerPool::getECS); luaCtx.registerFunction("setECS", &ServerPool::setECS); +#ifndef DISABLE_DOWNSTREAM_BINDINGS /* DownstreamState */ luaCtx.registerFunction("setQPS", [](DownstreamState& s, int lim) { s.qps = lim ? QPSLimiter(lim, lim) : QPSLimiter(); }); luaCtx.registerFunction::*)(string)>("addPool", [](std::shared_ptr s, string pool) { @@ -126,7 +129,9 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.registerMember("order", &DownstreamState::order); luaCtx.registerMember("name", [](const DownstreamState& backend) -> const std::string { return backend.getName(); }, [](DownstreamState& backend, const std::string& newName) { backend.setName(newName); }); luaCtx.registerFunction("getID", [](const DownstreamState& s) { return boost::uuids::to_string(s.id); }); +#endif /* DISABLE_DOWNSTREAM_BINDINGS */ +#ifndef DISABLE_DNSHEADER_BINDINGS /* dnsheader */ luaCtx.registerFunction("setRD", [](dnsheader& dh, bool v) { dh.rd=v; @@ -176,7 +181,9 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.registerFunction("setQR", [](dnsheader& dh, bool v) { dh.qr=v; }); +#endif /* DISABLE_DNSHEADER_BINDINGS */ +#ifndef DISABLE_COMBO_ADDR_BINDINGS /* ComboAddress */ luaCtx.writeFunction("newCA", [](const std::string& name) { return ComboAddress(name); }); luaCtx.writeFunction("newCAFromRaw", [](const std::string& raw, boost::optional port) { @@ -214,7 +221,9 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.registerFunction("isMappedIPv4", [](const ComboAddress& ca) { return ca.isMappedIPv4(); }); luaCtx.registerFunction("mapToIPv4", [](const ComboAddress& ca) { return ca.mapToIPv4(); }); luaCtx.registerFunction("match", [](nmts_t& s, const ComboAddress& ca) { return s.match(ca); }); +#endif /* DISABLE_COMBO_ADDR_BINDINGS */ +#ifndef DISABLE_DNSNAME_BINDINGS /* DNSName */ luaCtx.registerFunction("isPartOf", &DNSName::isPartOf); luaCtx.registerFunction("chopOff", [](DNSName&dn ) { return dn.chopOff(); }); @@ -239,7 +248,9 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.registerFunction("size",(size_t (DNSNameSet::*)() const) &DNSNameSet::size); luaCtx.registerFunction("clear",(void (DNSNameSet::*)()) &DNSNameSet::clear); luaCtx.registerFunction("empty",(bool (DNSNameSet::*)() const) &DNSNameSet::empty); +#endif /* DISABLE_DNSNAME_BINDINGS */ +#ifndef DISABLE_SUFFIX_MATCH_BINDINGS /* SuffixMatchNode */ luaCtx.registerFunction>, vector>> &name)>("add", [](SuffixMatchNode &smn, const boost::variant>, vector>> &name) { if (name.type() == typeid(DNSName)) { @@ -297,7 +308,9 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) }); luaCtx.registerFunction("check",(bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check); +#endif /* DISABLE_SUFFIX_MATCH_BINDINGS */ +#ifndef DISABLE_NETMASK_BINDINGS /* Netmask */ luaCtx.writeFunction("newNetmask", [](boost::variant s, boost::optional bits) { if (s.type() == typeid(ComboAddress)) { @@ -345,11 +358,15 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) luaCtx.registerFunction("clear", &NetmaskGroup::clear); luaCtx.registerFunction("toString", [](const NetmaskGroup& nmg ) { return "NetmaskGroup " + nmg.toString(); }); luaCtx.registerFunction("__tostring", [](const NetmaskGroup& nmg ) { return "NetmaskGroup " + nmg.toString(); }); +#endif /* DISABLE_NETMASK_BINDINGS */ +#ifndef DISABLE_QPS_LIMITER_BINDINGS /* QPSLimiter */ luaCtx.writeFunction("newQPSLimiter", [](int rate, int burst) { return QPSLimiter(rate, burst); }); luaCtx.registerFunction("check", &QPSLimiter::check); +#endif /* DISABLE_QPS_LIMITER_BINDINGS */ +#ifndef DISABLE_CLIENT_STATE_BINDINGS /* ClientState */ luaCtx.registerFunction("toString", [](const ClientState& fe) { setLuaNoSideEffect(); @@ -394,6 +411,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) frontend.detachFilter(); }); #endif /* HAVE_EBPF */ +#endif /* DISABLE_CLIENT_STATE_BINDINGS */ /* BPF Filter */ #ifdef HAVE_EBPF diff --git a/pdns/dnsdist-lua-inspection.cc b/pdns/dnsdist-lua-inspection.cc index a365698c5a..5645cc83ed 100644 --- a/pdns/dnsdist-lua-inspection.cc +++ b/pdns/dnsdist-lua-inspection.cc @@ -70,7 +70,7 @@ static std::vector>>> getGen }); std::vector>>> ret; - ret.reserve(std::min(rcounts.size(), top + 1U)); + ret.reserve(std::min(rcounts.size(), static_cast(top + 1U))); uint64_t count = 1; unsigned int rest = 0; for(const auto& rc : rcounts) { diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 1e7bf17dc2..b822ba2893 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -698,8 +698,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) bool reusePort = false; int tcpFastOpenQueueSize = 0; int tcpListenQueueSize = 0; - size_t maxInFlightQueriesPerConn = 0; - size_t tcpMaxConcurrentConnections = 0; + uint64_t maxInFlightQueriesPerConn = 0; + uint64_t tcpMaxConcurrentConnections = 0; std::string interface; std::set cpus; @@ -748,8 +748,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) bool reusePort = false; int tcpFastOpenQueueSize = 0; int tcpListenQueueSize = 0; - size_t maxInFlightQueriesPerConn = 0; - size_t tcpMaxConcurrentConnections = 0; + uint64_t maxInFlightQueriesPerConn = 0; + uint64_t tcpMaxConcurrentConnections = 0; std::string interface; std::set cpus; @@ -1501,17 +1501,17 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) DynBlockMaintenance::s_expiredDynBlocksPurgeInterval = interval; }); +#ifdef HAVE_DNSCRYPT luaCtx.writeFunction("addDNSCryptBind", [](const std::string& addr, const std::string& providerName, boost::variant>> certFiles, boost::variant>> keyFiles, boost::optional vars) { if (g_configurationDone) { g_outputBuffer = "addDNSCryptBind cannot be used at runtime!\n"; return; } -#ifdef HAVE_DNSCRYPT bool reusePort = false; int tcpFastOpenQueueSize = 0; int tcpListenQueueSize = 0; - size_t maxInFlightQueriesPerConn = 0; - size_t tcpMaxConcurrentConnections = 0; + uint64_t maxInFlightQueriesPerConn = 0; + uint64_t tcpMaxConcurrentConnections = 0; std::string interface; std::set cpus; std::vector certKeys; @@ -1571,14 +1571,10 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) errlog(e.what()); g_outputBuffer = "Error: " + string(e.what()) + "\n"; } -#else - g_outputBuffer = "Error: DNSCrypt support is not enabled.\n"; -#endif }); luaCtx.writeFunction("showDNSCryptBinds", []() { setLuaNoSideEffect(); -#ifdef HAVE_DNSCRYPT ostringstream ret; boost::format fmt("%1$-3d %2% %|25t|%3$-20.20s"); ret << (fmt % "#" % "Address" % "Provider Name") << endl; @@ -1596,28 +1592,22 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } g_outputBuffer = ret.str(); -#else - g_outputBuffer = "Error: DNSCrypt support is not enabled.\n"; -#endif }); luaCtx.writeFunction("getDNSCryptBind", [](uint64_t idx) { setLuaNoSideEffect(); -#ifdef HAVE_DNSCRYPT std::shared_ptr ret = nullptr; if (idx < g_dnsCryptLocals.size()) { ret = g_dnsCryptLocals.at(idx); } return ret; -#else - g_outputBuffer = "Error: DNSCrypt support is not enabled.\n"; -#endif }); luaCtx.writeFunction("getDNSCryptBindCount", []() { setLuaNoSideEffect(); return g_dnsCryptLocals.size(); }); +#endif /* HAVE_DNSCRYPT */ luaCtx.writeFunction("showPools", []() { setLuaNoSideEffect(); @@ -1735,11 +1725,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) g_outputBuffer = "dnsdist " + std::string(VERSION) + "\n"; }); - luaCtx.writeFunction("showSecurityStatus", []() { - setLuaNoSideEffect(); - g_outputBuffer = std::to_string(g_stats.securityStatus) + "\n"; - }); - #ifdef HAVE_EBPF luaCtx.writeFunction("setDefaultBPFFilter", [](std::shared_ptr bpf) { if (g_configurationDone) { @@ -1979,6 +1964,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) }); #endif /* HAVE_NET_SNMP */ +#ifndef DISABLE_POLICIES_BINDINGS luaCtx.writeFunction("setServerPolicy", [](const ServerPolicy& policy) { setLuaSideEffect(); g_policy.setState(policy); @@ -2045,6 +2031,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) g_outputBuffer = poolObj->policy->getName() + "\n"; } }); +#endif /* DISABLE_POLICIES_BINDINGS */ luaCtx.writeFunction("setTCPDownstreamCleanupInterval", [](uint64_t interval) { setLuaSideEffect(); @@ -2115,9 +2102,10 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) return; } setLuaSideEffect(); - g_proxyProtocolMaximumSize = std::max(static_cast(16), size); + g_proxyProtocolMaximumSize = std::max(static_cast(16), size); }); +#ifndef DISABLE_RECVMMSG luaCtx.writeFunction("setUDPMultipleMessagesVectorSize", [](uint64_t vSize) { if (g_configurationDone) { errlog("setUDPMultipleMessagesVectorSize() cannot be used at runtime!"); @@ -2132,6 +2120,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) g_outputBuffer = "recvmmsg support is not available!\n"; #endif }); +#endif /* DISABLE_RECVMMSG */ luaCtx.writeFunction("setAddEDNSToSelfGeneratedResponses", [](bool add) { g_addEDNSToSelfGeneratedResponses = add; @@ -2152,6 +2141,11 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) }); #ifndef DISABLE_SECPOLL + luaCtx.writeFunction("showSecurityStatus", []() { + setLuaNoSideEffect(); + g_outputBuffer = std::to_string(g_stats.securityStatus) + "\n"; + }); + luaCtx.writeFunction("setSecurityPollSuffix", [](const std::string& suffix) { if (g_configurationDone) { g_outputBuffer = "setSecurityPollSuffix() cannot be used at runtime!\n"; @@ -2297,8 +2291,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) bool reusePort = false; int tcpFastOpenQueueSize = 0; int tcpListenQueueSize = 0; - size_t maxInFlightQueriesPerConn = 0; - size_t tcpMaxConcurrentConnections = 0; + uint64_t maxInFlightQueriesPerConn = 0; + uint64_t tcpMaxConcurrentConnections = 0; std::string interface; std::set cpus; @@ -2500,8 +2494,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) bool reusePort = false; int tcpFastOpenQueueSize = 0; int tcpListenQueueSize = 0; - size_t maxInFlightQueriesPerConn = 0; - size_t tcpMaxConcurrentConns = 0; + uint64_t maxInFlightQueriesPerConn = 0; + uint64_t tcpMaxConcurrentConns = 0; std::string interface; std::set cpus; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index b3f61390fa..31fc9ad247 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1121,6 +1121,7 @@ bool checkQueryHeaders(const struct dnsheader* dh) return true; } +#ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) static void queueResponse(const ClientState& cs, const PacketBuffer& response, const ComboAddress& dest, const ComboAddress& remote, struct mmsghdr& outMsg, struct iovec* iov, cmsgbuf_aligned* cbuf) { @@ -1135,6 +1136,7 @@ static void queueResponse(const ClientState& cs, const PacketBuffer& response, c } } #endif /* defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) */ +#endif /* DISABLE_RECVMMSG */ /* self-generated responses or cache hits */ static bool prepareOutgoingResponse(LocalHolders& holders, ClientState& cs, DNSQuestion& dq, bool cacheHit) @@ -1492,6 +1494,7 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct // the buffer might have been invalidated by now (resized) struct dnsheader* dh = dq.getHeader(); if (result == ProcessQueryResult::SendAnswer) { +#ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) if (dq.delayMsec == 0 && responsesVect != nullptr) { queueResponse(cs, query, dest, remote, responsesVect[*queuedResponses], respIOV, respCBuf); @@ -1499,6 +1502,7 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct return; } #endif /* defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) */ +#endif /* DISABLE_RECVMMSG */ /* we use dest, always, because we don't want to use the listening address to send a response since it could be 0.0.0.0 */ sendUDPResponse(cs.udpFD, query, dq.delayMsec, dest, remote); return; @@ -1596,6 +1600,7 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct } } +#ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) static void MultipleMessagesUDPClientThread(ClientState* cs, LocalHolders& holders) { @@ -1680,6 +1685,7 @@ static void MultipleMessagesUDPClientThread(ClientState* cs, LocalHolders& holde } } #endif /* defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) */ +#endif /* DISABLE_RECVMMSG */ // listens to incoming queries, sends out to downstream servers, noting the intended return path static void udpClientThread(ClientState* cs) @@ -1687,13 +1693,14 @@ static void udpClientThread(ClientState* cs) try { setThreadName("dnsdist/udpClie"); LocalHolders holders; - +#ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) if (g_udpVectorSize > 1) { MultipleMessagesUDPClientThread(cs, holders); } else #endif /* defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) */ +#endif /* DISABLE_RECVMMSG */ { /* the actual buffer is larger because: - we may have to add EDNS and/or ECS @@ -2404,9 +2411,11 @@ int main(int argc, char** argv) #ifdef HAVE_RE2 cout<<"re2 "; #endif +#ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) cout<<"recvmmsg/sendmmsg "; #endif +#endif /* DISABLE_RECVMMSG */ #ifdef HAVE_NET_SNMP cout<<"snmp "; #endif diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc index f77051e417..a5a37924e4 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc @@ -119,6 +119,8 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client) return res; }); + +#ifndef DISABLE_PACKETCACHE_BINDINGS luaCtx.registerFunction::*)()const>("toString", [](const std::shared_ptr& cache) { if (cache) { return cache->toString(); @@ -211,4 +213,5 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client) g_outputBuffer += "Dumped " + std::to_string(records) + " records\n"; } }); +#endif /* DISABLE_PACKETCACHE_BINDINGS */ } diff --git a/pdns/dnsdistdist/dnsdist-lua-web.cc b/pdns/dnsdistdist/dnsdist-lua-web.cc index 4b5c20bd5c..379402f4a8 100644 --- a/pdns/dnsdistdist/dnsdist-lua-web.cc +++ b/pdns/dnsdistdist/dnsdist-lua-web.cc @@ -29,6 +29,7 @@ void registerWebHandler(const std::string& endpoint, std::function handler) { /* LuaWrapper does a copy for objects passed by reference, so we pass a pointer */ registerWebHandler(path, [handler](const YaHTTP::Request& req, YaHTTP::Response& resp) { handler(&req, &resp); }); @@ -75,5 +76,6 @@ void setupLuaWeb(LuaContext& luaCtx) resp.headers.insert({entry.first, entry.second}); } }); +#endif /* DISABLE_LUA_WEB_HANDLERS */ }