From: Remi Gacogne Date: Tue, 14 Jan 2020 09:12:18 +0000 (+0100) Subject: dnsdist: Add the source and destination ports to the protobuf msg X-Git-Tag: auth-4.3.0-beta1~38^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36de33306ac5bfa4f55e26975f35fb35a90914da;p=thirdparty%2Fpdns.git dnsdist: Add the source and destination ports to the protobuf msg --- diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc index 876c8124dd..5241005261 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc @@ -72,17 +72,29 @@ void setupLuaBindingsProtoBuf(bool client) g_lua.registerFunction("setQueryTime", [](DNSDistProtoBufMessage& message, time_t sec, uint32_t usec) { message.setQueryTime(sec, usec); }); g_lua.registerFunction("setResponseCode", [](DNSDistProtoBufMessage& message, uint8_t rcode) { message.setResponseCode(rcode); }); g_lua.registerFunction("toDebugString", [](const DNSDistProtoBufMessage& message) { return message.toDebugString(); }); - g_lua.registerFunction("setRequestor", [](DNSDistProtoBufMessage& message, const ComboAddress& addr) { + g_lua.registerFunction)>("setRequestor", [](DNSDistProtoBufMessage& message, const ComboAddress& addr, boost::optional port) { message.setRequestor(addr); + if (port) { + message.setRequestorPort(*port); + } }); - g_lua.registerFunction("setRequestorFromString", [](DNSDistProtoBufMessage& message, const std::string& str) { + g_lua.registerFunction)>("setRequestorFromString", [](DNSDistProtoBufMessage& message, const std::string& str, boost::optional port) { message.setRequestor(str); + if (port) { + message.setRequestorPort(*port); + } }); - g_lua.registerFunction("setResponder", [](DNSDistProtoBufMessage& message, const ComboAddress& addr) { + g_lua.registerFunction)>("setResponder", [](DNSDistProtoBufMessage& message, const ComboAddress& addr, boost::optional port) { message.setResponder(addr); + if (port) { + message.setResponderPort(*port); + } }); - g_lua.registerFunction("setResponderFromString", [](DNSDistProtoBufMessage& message, const std::string& str) { + g_lua.registerFunction)>("setResponderFromString", [](DNSDistProtoBufMessage& message, const std::string& str, boost::optional port) { message.setResponder(str); + if (port) { + message.setResponderPort(*port); + } }); g_lua.registerFunction("setServerIdentity", [](DNSDistProtoBufMessage& message, const std::string& str) { message.setServerIdentity(str); diff --git a/pdns/dnsdistdist/docs/reference/protobuf.rst b/pdns/dnsdistdist/docs/reference/protobuf.rst index 1cb71a7d66..cbceafd60b 100644 --- a/pdns/dnsdistdist/docs/reference/protobuf.rst +++ b/pdns/dnsdistdist/docs/reference/protobuf.rst @@ -62,29 +62,45 @@ Protobuf Logging Reference :param int sec: Optional query time in seconds. :param int usec: Optional query time in additional micro-seconds. - .. method:: DNSDistProtoBufMessage:setRequestor(address) + .. method:: DNSDistProtoBufMessage:setRequestor(address [, port]) + + .. versionchanged:: 1.5.0 + ``port`` optional parameter added. Set the requestor's address. :param ComboAddress address: The address to set to + :param int port: The requestor source port + + .. method:: DNSDistProtoBufMessage:setRequestorFromString(address [, port]) - .. method:: DNSDistProtoBufMessage:setRequestorFromString(address) + .. versionchanged:: 1.5.0 + ``port`` optional parameter added. Set the requestor's address from a string. :param string address: The address to set to + :param int port: The requestor source port - .. method:: DNSDistProtoBufMessage:setResponder(address) + .. method:: DNSDistProtoBufMessage:setResponder(address [, port]) + + .. versionchanged:: 1.5.0 + ``port`` optional parameter added. Set the responder's address. :param ComboAddress address: The address to set to + :param int port: The responder port + + .. method:: DNSDistProtoBufMessage:setResponderFromString(address [, port]) - .. method:: DNSDistProtoBufMessage:setResponderFromString(address) + .. versionchanged:: 1.5.0 + ``port`` optional parameter added. Set the responder's address. :param string address: The address to set to + :param int port: The responder port .. method:: DNSDistProtoBufMessage:setResponseCode(rcode) diff --git a/pdns/dnsmessage.proto b/pdns/dnsmessage.proto index c9db4778f4..6b33ab0930 100644 --- a/pdns/dnsmessage.proto +++ b/pdns/dnsmessage.proto @@ -88,4 +88,6 @@ message PBDNSMessage { optional bytes deviceId = 17; // Device ID of the requestor (could be mac address IP address or e.g. IMEI) optional bool newlyObservedDomain = 18; // True if the domain has not been seen before optional string deviceName = 19; // Device name of the requestor + optional uint32 fromPort = 20; // Source port of the DNS query (client) + optional uint32 toPort = 21; // Destination port of the DNS query (server) } diff --git a/pdns/protobuf.cc b/pdns/protobuf.cc index cd0877d2ea..31fe67edf8 100644 --- a/pdns/protobuf.cc +++ b/pdns/protobuf.cc @@ -239,6 +239,13 @@ void DNSProtoBufMessage::setRequestor(const ComboAddress& requestor) #endif /* HAVE_PROTOBUF */ } +void DNSProtoBufMessage::setRequestorPort(uint16_t port) +{ +#ifdef HAVE_PROTOBUF + d_message.set_fromport(port); +#endif /* HAVE_PROTOBUF */ +} + void DNSProtoBufMessage::setRequestorId(const std::string& requestorId) { #ifdef HAVE_PROTOBUF @@ -286,6 +293,13 @@ void DNSProtoBufMessage::setResponder(const ComboAddress& responder) #endif /* HAVE_PROTOBUF */ } +void DNSProtoBufMessage::setResponderPort(uint16_t port) +{ +#ifdef HAVE_PROTOBUF + d_message.set_toport(port); +#endif /* HAVE_PROTOBUF */ +} + void DNSProtoBufMessage::serialize(std::string& data) const { #ifdef HAVE_PROTOBUF @@ -342,9 +356,11 @@ void DNSProtoBufMessage::update(const boost::uuids::uuid& uuid, const ComboAddre if (responder) { setResponder(*responder); + setResponderPort(responder->getPort()); } if (requestor) { setRequestor(*requestor); + setRequestorPort(requestor->getPort()); } } diff --git a/pdns/protobuf.hh b/pdns/protobuf.hh index 86b47c11f0..0df3ee62be 100644 --- a/pdns/protobuf.hh +++ b/pdns/protobuf.hh @@ -67,8 +67,10 @@ public: void serialize(std::string& data) const; void setRequestor(const std::string& requestor); void setRequestor(const ComboAddress& requestor); + void setRequestorPort(uint16_t port); void setResponder(const std::string& responder); void setResponder(const ComboAddress& responder); + void setResponderPort(uint16_t port); void setRequestorId(const std::string& requestorId); void setDeviceId(const std::string& deviceId); void setDeviceName(const std::string& deviceName);