]> granicus.if.org Git - pdns/commitdiff
Allow matching based on destination port.
authorphonedph1 <phoned@gmail.com>
Thu, 26 Jul 2018 15:41:27 +0000 (15:41 +0000)
committerphonedph1 <phoned@gmail.com>
Thu, 26 Jul 2018 15:41:27 +0000 (15:41 +0000)
pdns/dnsdist-lua-rules.cc
pdns/dnsdistdist/dnsdist-rules.hh
pdns/dnsdistdist/docs/rules-actions.rst

index edfbafcf713dbb183e6364516fa61bcd3b360f0d..f65a68c466f1acfd3ba9df5d3e4f4777b7cb9d58 100644 (file)
@@ -373,6 +373,10 @@ void setupLuaRules()
       return std::shared_ptr<DNSRule>(new OrRule(a));
     });
 
+  g_lua.writeFunction("DSTPortRule", [](uint16_t port) {
+      return std::shared_ptr<DNSRule>(new DSTPortRule(port));
+    });
+
   g_lua.writeFunction("TCPRule", [](bool tcp) {
       return std::shared_ptr<DNSRule>(new TCPRule(tcp));
     });
index de5eb920163fc610715966bf458ef020655b5b2e..2b9349e78fdd56fc229a27f56fc8960603995c9e 100644 (file)
@@ -598,6 +598,26 @@ private:
   uint8_t d_opcode;
 };
 
+class DSTPortRule : public DNSRule
+{
+public:
+  DSTPortRule(uint16_t port) : d_port(port)
+  {
+    d_port_htons = htons(d_port);
+  }
+  bool matches(const DNSQuestion* dq) const override
+  {
+    return d_port_htons == dq->local->sin4.sin_port;
+  }
+  string toString() const override
+  {
+    return "dst port=="+std::to_string(d_port);
+  }
+private:
+  uint16_t d_port;
+  uint16_t d_port_htons;
+};
+
 class TCPRule : public DNSRule
 {
 public:
index b9c5374f908a7fe28a10b27f7bd0e750ca619555..386feea2df02f999e8cdeb31f53cdf9eb350e6e9 100644 (file)
@@ -714,6 +714,12 @@ These ``DNSRule``\ s be one of the following items:
 
   :param bool tcp: Match TCP traffic. Default is true.
 
+.. function:: DSTPortRule(port)
+
+  Matches questions received to the destination port.
+
+  :param int port: Match destination port.
+
 .. function:: TrailingDataRule()
 
   Matches if the query has trailing data.