return boost::optional<Netmask>();
}
+std::vector<std::pair<uint8_t, string>> RecursorLua4::DNSQuestion::getProxyProtocolValues() const
+{
+ std::vector<std::pair<uint8_t, string>> result;
+ if (proxyProtocolValues) {
+ result.reserve(proxyProtocolValues->size());
+
+ for (const auto& value: *proxyProtocolValues) {
+ result.push_back({ value.type, value.content });
+ }
+ }
+
+ return result;
+}
vector<pair<int, DNSRecord> > RecursorLua4::DNSQuestion::getRecords() const
{
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);
#include "ednsoptions.hh"
#include "validate.hh"
#include "lua-base4.hh"
+#include "proxy-protocol.hh"
+
#include <unordered_map>
#include "lua-recursor4-ffi.hh"
vector<DNSRecord>* currentRecords{nullptr};
DNSFilterEngine::Policy* appliedPolicy{nullptr};
std::vector<std::string>* policyTags{nullptr};
+ const std::vector<ProxyProtocolValue>* proxyProtocolValues{nullptr};
std::unordered_map<std::string,bool>* discardedPolicies{nullptr};
std::string requestorId;
std::string deviceId;
vector<pair<uint16_t, string> > getEDNSOptions() const;
boost::optional<string> getEDNSOption(uint16_t code) const;
boost::optional<Netmask> getEDNSSubnet() const;
+ std::vector<std::pair<uint8_t, string>> getProxyProtocolValues() const;
vector<string> getEDNSFlags() const;
bool getEDNSFlag(string flag) const;
void setRecords(const vector<pair<int,DNSRecord> >& records);
dq.deviceId = dc->d_deviceId;
dq.deviceName = dc->d_deviceName;
#endif
+ dq.proxyProtocolValues = &dc->d_proxyProtocolValues;
if(ednsExtRCode != 0) {
goto sendit;
t_fdm->removeReadFD(fd);
return;
}
+
+ /* check the real source */
+ if (t_allowFrom && !t_allowFrom->match(&conn->d_source)) {
+ if (!g_quiet) {
+ g_log<<Logger::Error<<"["<<MT->getTid()<<"] dropping TCP query from "<<conn->d_source.toString()<<", address not matched by allow-from"<<endl;
+ }
+
+ ++g_stats.unauthorizedTCP;
+ t_fdm->removeReadFD(fd);
+ return;
+ }
+
conn->data.resize(2);
conn->state = TCPConnection::BYTE0;
}
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<<Logger::Error<<"["<<MT->getTid()<<"] dropping TCP query from "<<addr.toString()<<", address not matched by allow-from"<<endl;
+ g_log<<Logger::Error<<"["<<MT->getTid()<<"] dropping TCP query from "<<addr.toString()<<", address neither matched by allow-from nor proxy-protocol-from"<<endl;
g_stats.unauthorizedTCP++;
try {
}
return;
}
+
if(g_maxTCPPerClient && t_tcpClientCounts->count(addr) && (*t_tcpClientCounts)[addr] >= g_maxTCPPerClient) {
g_stats.tcpClientOverflow++;
try {
socklen_t len = tc->d_destination.getSocklen();
getsockname(tc->getFD(), reinterpret_cast<sockaddr*>(&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;
t_remotes->push_back(fromaddr);
}
- if(t_allowFrom && !t_allowFrom->match(&fromaddr)) {
+ if(t_allowFrom && !t_allowFrom->match(&source)) {
if(!g_quiet) {
g_log<<Logger::Error<<"["<<MT->getTid()<<"] dropping UDP query from "<<fromaddr.toString()<<", address not matched by allow-from"<<endl;
}
g_XPFAcl.toMasks(::arg()["xpf-allow-from"]);
g_xpfRRCode = ::arg().asNum("xpf-rr-code");
- g_proxyProtocolACL.toMasks(::arg()["proxy-protocol-allow-from"]);
+ g_proxyProtocolACL.toMasks(::arg()["proxy-protocol-from"]);
g_proxyProtocolMaximumSize = ::arg().asNum("proxy-protocol-maximum-size");
g_networkTimeoutMsec = ::arg().asNum("network-timeout");