]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add the source and destination ports to the protobuf msg
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 14 Jan 2020 09:12:18 +0000 (10:12 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 14 Jan 2020 09:12:18 +0000 (10:12 +0100)
pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc
pdns/dnsdistdist/docs/reference/protobuf.rst
pdns/dnsmessage.proto
pdns/protobuf.cc
pdns/protobuf.hh

index 876c8124ddf715a5e0e8c987c8be2ed11b1ce842..5241005261fbd54407a51a4345da6137eaac8f4a 100644 (file)
@@ -72,17 +72,29 @@ void setupLuaBindingsProtoBuf(bool client)
   g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(time_t, uint32_t)>("setQueryTime", [](DNSDistProtoBufMessage& message, time_t sec, uint32_t usec) { message.setQueryTime(sec, usec); });
   g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(uint8_t)>("setResponseCode", [](DNSDistProtoBufMessage& message, uint8_t rcode) { message.setResponseCode(rcode); });
   g_lua.registerFunction<std::string(DNSDistProtoBufMessage::*)()>("toDebugString", [](const DNSDistProtoBufMessage& message) { return message.toDebugString(); });
-  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const ComboAddress&)>("setRequestor", [](DNSDistProtoBufMessage& message, const ComboAddress& addr) {
+  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const ComboAddress&, boost::optional<uint16_t>)>("setRequestor", [](DNSDistProtoBufMessage& message, const ComboAddress& addr, boost::optional<uint16_t> port) {
       message.setRequestor(addr);
+      if (port) {
+        message.setRequestorPort(*port);
+      }
     });
-  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const std::string&)>("setRequestorFromString", [](DNSDistProtoBufMessage& message, const std::string& str) {
+  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const std::string&, boost::optional<uint16_t>)>("setRequestorFromString", [](DNSDistProtoBufMessage& message, const std::string& str, boost::optional<uint16_t> port) {
       message.setRequestor(str);
+      if (port) {
+        message.setRequestorPort(*port);
+      }
     });
-  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const ComboAddress&)>("setResponder", [](DNSDistProtoBufMessage& message, const ComboAddress& addr) {
+  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const ComboAddress&, boost::optional<uint16_t>)>("setResponder", [](DNSDistProtoBufMessage& message, const ComboAddress& addr, boost::optional<uint16_t> port) {
       message.setResponder(addr);
+      if (port) {
+        message.setResponderPort(*port);
+      }
     });
-  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const std::string&)>("setResponderFromString", [](DNSDistProtoBufMessage& message, const std::string& str) {
+  g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const std::string&, boost::optional<uint16_t>)>("setResponderFromString", [](DNSDistProtoBufMessage& message, const std::string& str, boost::optional<uint16_t> port) {
       message.setResponder(str);
+      if (port) {
+        message.setResponderPort(*port);
+      }
     });
   g_lua.registerFunction<void(DNSDistProtoBufMessage::*)(const std::string&)>("setServerIdentity", [](DNSDistProtoBufMessage& message, const std::string& str) {
       message.setServerIdentity(str);
index 1cb71a7d667724e170845a591e5c723b670d2eff..cbceafd60b39ce5e900f72195a2475126ea212c6 100644 (file)
@@ -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)
 
index c9db4778f4094c7fd52531cb1991b9a0e51eda14..6b33ab0930eb0e80eb17e05fc125a34306dbad62 100644 (file)
@@ -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)
 }
index cd0877d2eaf76a8ae438cd90c2ec883639a1e202..31fe67edf87c22cab3c81ca4eecb11648bf53d3e 100644 (file)
@@ -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());
   }
 }
 
index 86b47c11f075b8ea28b3baaaf3a1eff1749d2df2..0df3ee62bebd733ef413874c6fe767303084a287 100644 (file)
@@ -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);