From: phonedph1 Date: Thu, 26 Jul 2018 15:41:27 +0000 (+0000) Subject: Allow matching based on destination port. X-Git-Tag: dnsdist-1.3.3~177^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dfa098fbbcfb91c5d837ed8198066f202c072520;p=pdns Allow matching based on destination port. --- diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index edfbafcf7..f65a68c46 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -373,6 +373,10 @@ void setupLuaRules() return std::shared_ptr(new OrRule(a)); }); + g_lua.writeFunction("DSTPortRule", [](uint16_t port) { + return std::shared_ptr(new DSTPortRule(port)); + }); + g_lua.writeFunction("TCPRule", [](bool tcp) { return std::shared_ptr(new TCPRule(tcp)); }); diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index de5eb9201..2b9349e78 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -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: diff --git a/pdns/dnsdistdist/docs/rules-actions.rst b/pdns/dnsdistdist/docs/rules-actions.rst index b9c5374f9..386feea2d 100644 --- a/pdns/dnsdistdist/docs/rules-actions.rst +++ b/pdns/dnsdistdist/docs/rules-actions.rst @@ -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.