From: Remi Gacogne Date: Mon, 15 Nov 2021 13:55:27 +0000 (+0100) Subject: dnsdist: Remove useless actions and rules when support is not present X-Git-Tag: auth-4.7.0-alpha1~103^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e389f8f13035a27c9a2d814856fce801b04b0c6;p=thirdparty%2Fpdns.git dnsdist: Remove useless actions and rules when support is not present --- diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index c0b184c2d4..44b614dfe1 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -1679,6 +1679,7 @@ private: int d_msec; }; +#ifdef HAVE_NET_SNMP class SNMPTrapResponseAction : public DNSResponseAction { public: @@ -1701,6 +1702,7 @@ public: private: std::string d_reason; }; +#endif /* HAVE_NET_SNMP */ class SetTagResponseAction : public DNSResponseAction { @@ -1819,6 +1821,7 @@ private: }; #endif /* HAVE_DNS_OVER_HTTPS */ +#if defined(HAVE_LMDB) || defined(HAVE_CDB) class KeyValueStoreLookupAction : public DNSAction { public: @@ -1886,6 +1889,7 @@ private: std::shared_ptr d_key; std::string d_tag; }; +#endif /* defined(HAVE_LMDB) || defined(HAVE_CDB) */ class NegativeAndSOAAction: public DNSAction { @@ -2396,21 +2400,15 @@ void setupLuaActions(LuaContext& luaCtx) return std::shared_ptr(new SetECSAction(Netmask(v4))); }); - luaCtx.writeFunction("SNMPTrapAction", [](boost::optional reason) { #ifdef HAVE_NET_SNMP + luaCtx.writeFunction("SNMPTrapAction", [](boost::optional reason) { return std::shared_ptr(new SNMPTrapAction(reason ? *reason : "")); -#else - throw std::runtime_error("NET SNMP support is required to use SNMPTrapAction()"); -#endif /* HAVE_NET_SNMP */ }); luaCtx.writeFunction("SNMPTrapResponseAction", [](boost::optional reason) { -#ifdef HAVE_NET_SNMP return std::shared_ptr(new SNMPTrapResponseAction(reason ? *reason : "")); -#else - throw std::runtime_error("NET SNMP support is required to use SNMPTrapResponseAction()"); -#endif /* HAVE_NET_SNMP */ }); +#endif /* HAVE_NET_SNMP */ luaCtx.writeFunction("SetTagAction", [](std::string tag, std::string value) { return std::shared_ptr(new SetTagAction(tag, value)); @@ -2433,6 +2431,7 @@ void setupLuaActions(LuaContext& luaCtx) }); #endif /* HAVE_DNS_OVER_HTTPS */ +#if defined(HAVE_LMDB) || defined(HAVE_CDB) luaCtx.writeFunction("KeyValueStoreLookupAction", [](std::shared_ptr& kvs, std::shared_ptr& lookupKey, const std::string& destinationTag) { return std::shared_ptr(new KeyValueStoreLookupAction(kvs, lookupKey, destinationTag)); }); @@ -2440,6 +2439,7 @@ void setupLuaActions(LuaContext& luaCtx) luaCtx.writeFunction("KeyValueStoreRangeLookupAction", [](std::shared_ptr& kvs, std::shared_ptr& lookupKey, const std::string& destinationTag) { return std::shared_ptr(new KeyValueStoreRangeLookupAction(kvs, lookupKey, destinationTag)); }); +#endif /* defined(HAVE_LMDB) || defined(HAVE_CDB) */ luaCtx.writeFunction("NegativeAndSOAAction", [](bool nxd, const std::string& zone, uint32_t ttl, const std::string& mname, const std::string& rname, uint32_t serial, uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum, boost::optional vars) { auto ret = std::shared_ptr(new NegativeAndSOAAction(nxd, DNSName(zone), ttl, DNSName(mname), DNSName(rname), serial, refresh, retry, expire, minimum)); diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index bc17df30e7..f850856307 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -369,11 +369,11 @@ void setupLuaRules(LuaContext& luaCtx) return rulesToString(getTopRules(*rules, top.get_value_or(10)), vars); }); - luaCtx.writeFunction("MaxQPSIPRule", [](unsigned int qps, boost::optional ipv4trunc, boost::optional ipv6trunc, boost::optional burst, boost::optional expiration, boost::optional cleanupDelay, boost::optional scanFraction) { + luaCtx.writeFunction("MaxQPSIPRule", [](unsigned int qps, boost::optional ipv4trunc, boost::optional ipv6trunc, boost::optional burst, boost::optional expiration, boost::optional cleanupDelay, boost::optional scanFraction) { return std::shared_ptr(new MaxQPSIPRule(qps, burst.get_value_or(qps), ipv4trunc.get_value_or(32), ipv6trunc.get_value_or(64), expiration.get_value_or(300), cleanupDelay.get_value_or(60), scanFraction.get_value_or(10))); }); - luaCtx.writeFunction("MaxQPSRule", [](unsigned int qps, boost::optional burst) { + luaCtx.writeFunction("MaxQPSRule", [](unsigned int qps, boost::optional burst) { if(!burst) return std::shared_ptr(new MaxQPSRule(qps)); else @@ -414,9 +414,9 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new NetmaskGroupRule(nmg, src ? *src : true, quiet ? *quiet : false)); }); - luaCtx.writeFunction("benchRule", [](std::shared_ptr rule, boost::optional times_, boost::optional suffix_) { + luaCtx.writeFunction("benchRule", [](std::shared_ptr rule, boost::optional times_, boost::optional suffix_) { setLuaNoSideEffect(); - int times = times_.get_value_or(100000); + unsigned int times = times_.get_value_or(100000); DNSName suffix(suffix_.get_value_or("powerdns.com")); struct item { PacketBuffer packet; @@ -442,7 +442,7 @@ void setupLuaRules(LuaContext& luaCtx) ComboAddress dummy("127.0.0.1"); StopWatch sw; sw.start(); - for(int n=0; n < times; ++n) { + for(unsigned int n=0; n < times; ++n) { item& i = items[n % items.size()]; DNSQuestion dq(&i.qname, i.qtype, i.qclass, &i.rem, &i.rem, i.packet, dnsdist::Protocol::DoUDP, &sw.d_start); if (rule->matches(&dq)) { @@ -466,25 +466,28 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new QNameRule(DNSName(qname))); }); - luaCtx.writeFunction("QTypeRule", [](boost::variant str) { + luaCtx.writeFunction("QTypeRule", [](boost::variant str) { uint16_t qtype; - if(auto dir = boost::get(&str)) { + if (auto dir = boost::get(&str)) { qtype = *dir; } else { - string val=boost::get(str); + string val = boost::get(str); qtype = QType::chartocode(val.c_str()); - if(!qtype) + if (!qtype) { throw std::runtime_error("Unable to convert '"+val+"' to a DNS type"); + } } return std::shared_ptr(new QTypeRule(qtype)); }); - luaCtx.writeFunction("QClassRule", [](int c) { + luaCtx.writeFunction("QClassRule", [](uint64_t c) { + checkParameterBound("QClassRule", c, std::numeric_limits::max()); return std::shared_ptr(new QClassRule(c)); }); - luaCtx.writeFunction("OpcodeRule", [](uint8_t code) { + luaCtx.writeFunction("OpcodeRule", [](uint64_t code) { + checkParameterBound("OpcodeRule", code, std::numeric_limits::max()); return std::shared_ptr(new OpcodeRule(code)); }); @@ -496,7 +499,8 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new OrRule(a)); }); - luaCtx.writeFunction("DSTPortRule", [](uint16_t port) { + luaCtx.writeFunction("DSTPortRule", [](uint64_t port) { + checkParameterBound("DSTPortRule", port, std::numeric_limits::max()); return std::shared_ptr(new DSTPortRule(port)); }); @@ -512,11 +516,18 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new NotRule(rule)); }); - luaCtx.writeFunction("RecordsCountRule", [](uint8_t section, uint16_t minCount, uint16_t maxCount) { + luaCtx.writeFunction("RecordsCountRule", [](uint64_t section, uint64_t minCount, uint64_t maxCount) { + checkParameterBound("RecordsCountRule", section, std::numeric_limits::max()); + checkParameterBound("RecordsCountRule", minCount, std::numeric_limits::max()); + checkParameterBound("RecordsCountRule", maxCount, std::numeric_limits::max()); return std::shared_ptr(new RecordsCountRule(section, minCount, maxCount)); }); - luaCtx.writeFunction("RecordsTypeCountRule", [](uint8_t section, uint16_t type, uint16_t minCount, uint16_t maxCount) { + luaCtx.writeFunction("RecordsTypeCountRule", [](uint64_t section, uint64_t type, uint64_t minCount, uint64_t maxCount) { + checkParameterBound("RecordsTypeCountRule", section, std::numeric_limits::max()); + checkParameterBound("RecordsTypeCountRule", type, std::numeric_limits::max()); + checkParameterBound("RecordsTypeCountRule", minCount, std::numeric_limits::max()); + checkParameterBound("RecordsTypeCountRule", maxCount, std::numeric_limits::max()); return std::shared_ptr(new RecordsTypeCountRule(section, type, minCount, maxCount)); }); @@ -524,27 +535,33 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new TrailingDataRule()); }); - luaCtx.writeFunction("QNameLabelsCountRule", [](unsigned int minLabelsCount, unsigned int maxLabelsCount) { + luaCtx.writeFunction("QNameLabelsCountRule", [](uint64_t minLabelsCount, uint64_t maxLabelsCount) { + checkParameterBound("QNameLabelsCountRule", minLabelsCount, std::numeric_limits::max()); + checkParameterBound("QNameLabelsCountRule", maxLabelsCount, std::numeric_limits::max()); return std::shared_ptr(new QNameLabelsCountRule(minLabelsCount, maxLabelsCount)); }); - luaCtx.writeFunction("QNameWireLengthRule", [](size_t min, size_t max) { + luaCtx.writeFunction("QNameWireLengthRule", [](uint64_t min, uint64_t max) { return std::shared_ptr(new QNameWireLengthRule(min, max)); }); - luaCtx.writeFunction("RCodeRule", [](uint8_t rcode) { + luaCtx.writeFunction("RCodeRule", [](uint64_t rcode) { + checkParameterBound("RCodeRule", rcode, std::numeric_limits::max()); return std::shared_ptr(new RCodeRule(rcode)); }); - luaCtx.writeFunction("ERCodeRule", [](uint8_t rcode) { + luaCtx.writeFunction("ERCodeRule", [](uint64_t rcode) { + checkParameterBound("ERCodeRule", rcode, std::numeric_limits::max()); return std::shared_ptr(new ERCodeRule(rcode)); }); - luaCtx.writeFunction("EDNSVersionRule", [](uint8_t version) { + luaCtx.writeFunction("EDNSVersionRule", [](uint64_t version) { + checkParameterBound("EDNSVersionRule", version, std::numeric_limits::max()); return std::shared_ptr(new EDNSVersionRule(version)); }); - luaCtx.writeFunction("EDNSOptionRule", [](uint16_t optcode) { + luaCtx.writeFunction("EDNSOptionRule", [](uint64_t optcode) { + checkParameterBound("EDNSOptionRule", optcode, std::numeric_limits::max()); return std::shared_ptr(new EDNSOptionRule(optcode)); }); @@ -568,7 +585,7 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new PoolAvailableRule(poolname)); }); - luaCtx.writeFunction("PoolOutstandingRule", [](std::string poolname, size_t limit) { + luaCtx.writeFunction("PoolOutstandingRule", [](std::string poolname, uint64_t limit) { return std::shared_ptr(new PoolOutstandingRule(poolname, limit)); }); @@ -595,6 +612,7 @@ void setupLuaRules(LuaContext& luaCtx) return std::shared_ptr(new QNameSetRule(names)); }); +#if defined(HAVE_LMDB) || defined(HAVE_CDB) luaCtx.writeFunction("KeyValueStoreLookupRule", [](std::shared_ptr& kvs, std::shared_ptr& lookupKey) { return std::shared_ptr(new KeyValueStoreLookupRule(kvs, lookupKey)); }); @@ -602,6 +620,7 @@ void setupLuaRules(LuaContext& luaCtx) luaCtx.writeFunction("KeyValueStoreRangeLookupRule", [](std::shared_ptr& kvs, std::shared_ptr& lookupKey) { return std::shared_ptr(new KeyValueStoreRangeLookupRule(kvs, lookupKey)); }); +#endif /* defined(HAVE_LMDB) || defined(HAVE_CDB) */ luaCtx.writeFunction("LuaRule", [](LuaRule::func_t func) { return std::shared_ptr(new LuaRule(func));