From: Remi Gacogne Date: Thu, 27 Feb 2020 13:40:30 +0000 (+0100) Subject: rec: Add support for TLV values X-Git-Tag: dnsdist-1.5.0-alpha1~12^2~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38d8b937a95045dfb39ea8eb1fa3e95323e62bb4;p=thirdparty%2Fpdns.git rec: Add support for TLV values --- diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 36239b0e14..e8b413f2eb 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -183,6 +183,19 @@ boost::optional RecursorLua4::DNSQuestion::getEDNSSubnet() const return boost::optional(); } +std::vector> RecursorLua4::DNSQuestion::getProxyProtocolValues() const +{ + std::vector> result; + if (proxyProtocolValues) { + result.reserve(proxyProtocolValues->size()); + + for (const auto& value: *proxyProtocolValues) { + result.push_back({ value.type, value.content }); + } + } + + return result; +} vector > RecursorLua4::DNSQuestion::getRecords() const { @@ -291,6 +304,7 @@ void RecursorLua4::postPrepareContext() d_lw->registerFunction("getEDNSOptions", &DNSQuestion::getEDNSOptions); d_lw->registerFunction("getEDNSOption", &DNSQuestion::getEDNSOption); d_lw->registerFunction("getEDNSSubnet", &DNSQuestion::getEDNSSubnet); + d_lw->registerFunction("getProxyProtocolValues", &DNSQuestion::getProxyProtocolValues); d_lw->registerFunction("getEDNSFlags", &DNSQuestion::getEDNSFlags); d_lw->registerFunction("getEDNSFlag", &DNSQuestion::getEDNSFlag); d_lw->registerMember("name", &DNSRecord::d_name); diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index 4515136a4a..8e3e082bd7 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -33,6 +33,8 @@ #include "ednsoptions.hh" #include "validate.hh" #include "lua-base4.hh" +#include "proxy-protocol.hh" + #include #include "lua-recursor4-ffi.hh" @@ -74,6 +76,7 @@ public: vector* currentRecords{nullptr}; DNSFilterEngine::Policy* appliedPolicy{nullptr}; std::vector* policyTags{nullptr}; + const std::vector* proxyProtocolValues{nullptr}; std::unordered_map* discardedPolicies{nullptr}; std::string requestorId; std::string deviceId; @@ -91,6 +94,7 @@ public: vector > getEDNSOptions() const; boost::optional getEDNSOption(uint16_t code) const; boost::optional getEDNSSubnet() const; + std::vector> getProxyProtocolValues() const; vector getEDNSFlags() const; bool getEDNSFlag(string flag) const; void setRecords(const vector >& records); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 24e9e82b1c..bed4ea90b6 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1287,6 +1287,7 @@ static void startDoResolve(void *p) dq.deviceId = dc->d_deviceId; dq.deviceName = dc->d_deviceName; #endif + dq.proxyProtocolValues = &dc->d_proxyProtocolValues; if(ednsExtRCode != 0) { goto sendit; @@ -2049,6 +2050,18 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) t_fdm->removeReadFD(fd); return; } + + /* check the real source */ + if (t_allowFrom && !t_allowFrom->match(&conn->d_source)) { + if (!g_quiet) { + g_log<getTid()<<"] dropping TCP query from "<d_source.toString()<<", address not matched by allow-from"<removeReadFD(fd); + return; + } + conn->data.resize(2); conn->state = TCPConnection::BYTE0; } @@ -2280,11 +2293,14 @@ static void handleNewTCPQuestion(int fd, FDMultiplexer::funcparam_t& ) return; } - if(t_remotes) + if(t_remotes) { t_remotes->push_back(addr); - if(t_allowFrom && !t_allowFrom->match(&addr)) { + } + + bool fromProxyProtocolSource = expectProxyProtocol(addr); + if(t_allowFrom && !t_allowFrom->match(&addr) && !fromProxyProtocolSource) { if(!g_quiet) - g_log<getTid()<<"] dropping TCP query from "<getTid()<<"] dropping TCP query from "<count(addr) && (*t_tcpClientCounts)[addr] >= g_maxTCPPerClient) { g_stats.tcpClientOverflow++; try { @@ -2314,7 +2331,7 @@ static void handleNewTCPQuestion(int fd, FDMultiplexer::funcparam_t& ) socklen_t len = tc->d_destination.getSocklen(); getsockname(tc->getFD(), reinterpret_cast(&tc->d_destination), &len); // if this fails, we're ok with it - if (expectProxyProtocol(addr)) { + if (fromProxyProtocolSource) { tc->proxyProtocolNeed = s_proxyProtocolMinimumHeaderSize; tc->data.resize(tc->proxyProtocolNeed); tc->state = TCPConnection::PROXYPROTOCOLHEADER; @@ -2641,7 +2658,7 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) t_remotes->push_back(fromaddr); } - if(t_allowFrom && !t_allowFrom->match(&fromaddr)) { + if(t_allowFrom && !t_allowFrom->match(&source)) { if(!g_quiet) { g_log<getTid()<<"] dropping UDP query from "<