From: Remi Gacogne Date: Tue, 29 Jun 2021 12:35:16 +0000 (+0200) Subject: dnsdist: Expose the protocol to Lua X-Git-Tag: dnsdist-1.7.0-alpha1~100^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a58258f9c3c356438628270221a293dedd09f131;p=thirdparty%2Fpdns.git dnsdist: Expose the protocol to Lua --- diff --git a/pdns/dnsdist-lua-bindings-dnsquestion.cc b/pdns/dnsdist-lua-bindings-dnsquestion.cc index 94e84350b8..f213335e26 100644 --- a/pdns/dnsdist-lua-bindings-dnsquestion.cc +++ b/pdns/dnsdist-lua-bindings-dnsquestion.cc @@ -73,6 +73,10 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx) return dq.sni; }); + luaCtx.registerFunction("getProtocol", [](const DNSQuestion& dq) { + return DNSQuestion::ProtocolToString(dq.getProtocol()); + }); + luaCtx.registerFunction("sendTrap", [](const DNSQuestion& dq, boost::optional reason) { #ifdef HAVE_NET_SNMP if (g_snmpAgent && g_snmpTrapsEnabled) { @@ -247,6 +251,10 @@ void setupLuaBindingsDNSQuestion(LuaContext& luaCtx) return *dr.qTag; }); + luaCtx.registerFunction("getProtocol", [](const DNSResponse& dr) { + return DNSQuestion::ProtocolToString(dr.getProtocol()); + }); + luaCtx.registerFunction("sendTrap", [](const DNSResponse& dr, boost::optional reason) { #ifdef HAVE_NET_SNMP if (g_snmpAgent && g_snmpTrapsEnabled) { diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 2ec6e2c485..153eee4e12 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -64,6 +64,11 @@ using QTag = std::unordered_map; struct DNSQuestion { enum class Protocol : uint8_t { DoUDP, DoTCP, DNSCryptUDP, DNSCryptTCP, DoT, DoH }; + static const std::string& ProtocolToString(Protocol proto) + { + static const std::vector values = { "Do53 UDP", "Do53 TCP", "DNSCrypt UDP", "DNSCrypt TCP", "DNS over TLS", "DNS over HTTPS" }; + return values.at(static_cast(proto)); + } DNSQuestion(const DNSName* name, uint16_t type, uint16_t class_, const ComboAddress* lc, const ComboAddress* rem, PacketBuffer& data_, Protocol proto, const struct timespec* queryTime_): data(data_), qname(name), local(lc), remote(rem), queryTime(queryTime_), tempFailureTTL(boost::none), qtype(type), qclass(class_), ecsPrefixLength(rem->sin4.sin_family == AF_INET ? g_ECSSourcePrefixV4 : g_ECSSourcePrefixV6), protocol(proto), ecsOverride(g_ECSOverride) {