X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=pdns%2Flua-recursor4.cc;h=445092448ed0985ddaa58e3c17e0a1703c4dc357;hb=941eea9402cf4a4060b6f95ac276b9f3db8812dc;hp=3b13bd464db95c5b0d12197a78ee53173154a90c;hpb=0871face0e02c9b26afc2bbc719afb6701477190;p=thirdparty%2Fpdns.git diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 3b13bd464d..445092448e 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -34,95 +34,6 @@ RecursorLua4::RecursorLua4() { prepareContext(); } -static int getFakeAAAARecords(const DNSName& qname, const std::string& prefix, vector& ret) -{ - int rcode=directResolve(qname, QType(QType::A), 1, ret); - - ComboAddress prefixAddress(prefix); - - // Remove double CNAME records - std::set seenCNAMEs; - ret.erase(std::remove_if( - ret.begin(), - ret.end(), - [&seenCNAMEs](DNSRecord& rr) { - if (rr.d_type == QType::CNAME) { - auto target = getRR(rr); - if (target == nullptr) { - return false; - } - if (seenCNAMEs.count(target->getTarget()) > 0) { - // We've had this CNAME before, remove it - return true; - } - seenCNAMEs.insert(target->getTarget()); - } - return false; - }), - ret.end()); - - bool seenA = false; - for(DNSRecord& rr : ret) - { - if(rr.d_type == QType::A && rr.d_place==DNSResourceRecord::ANSWER) { - if(auto rec = getRR(rr)) { - ComboAddress ipv4(rec->getCA()); - uint32_t tmp; - memcpy((void*)&tmp, &ipv4.sin4.sin_addr.s_addr, 4); - // tmp=htonl(tmp); - memcpy(((char*)&prefixAddress.sin6.sin6_addr.s6_addr)+12, &tmp, 4); - rr.d_content = std::make_shared(prefixAddress); - rr.d_type = QType::AAAA; - } - seenA = true; - } - } - - if (seenA) { - // We've seen an A in the ANSWER section, so there is no need to keep any - // SOA in the AUTHORITY section as this is not a NODATA response. - ret.erase(std::remove_if( - ret.begin(), - ret.end(), - [](DNSRecord& rr) { - return (rr.d_type == QType::SOA && rr.d_place==DNSResourceRecord::AUTHORITY); - }), - ret.end()); - } - return rcode; -} - -static int getFakePTRRecords(const DNSName& qname, const std::string& prefix, vector& ret) -{ - /* qname has a reverse ordered IPv6 address, need to extract the underlying IPv4 address from it - and turn it into an IPv4 in-addr.arpa query */ - ret.clear(); - vector parts = qname.getRawLabels(); - - if(parts.size() < 8) - return -1; - - string newquery; - for(int n = 0; n < 4; ++n) { - newquery += - std::to_string(stoll(parts[n*2], 0, 16) + 16*stoll(parts[n*2+1], 0, 16)); - newquery.append(1,'.'); - } - newquery += "in-addr.arpa."; - - - DNSRecord rr; - rr.d_name = qname; - rr.d_type = QType::CNAME; - rr.d_content = std::make_shared(newquery); - ret.push_back(rr); - - int rcode = directResolve(DNSName(newquery), QType(QType::PTR), 1, ret); - - return rcode; - -} - boost::optional RecursorLua4::DNSQuestion::getDH() const { if (dh) @@ -481,7 +392,7 @@ void RecursorLua4::postLoad() { void RecursorLua4::getFeatures(Features & features) { // Add key-values pairs below. - // Make sure you add string values explicity converted to string. + // Make sure you add string values explicitly converted to string. // e.g. features.push_back(make_pair("somekey", string("stringvalue")); // Both int and double end up as a lua number type. features.push_back(make_pair("PR8001_devicename", true)); @@ -537,7 +448,7 @@ bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& loca return false; // don't block } -unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::unordered_set* policyTags, LuaContext::LuaObject& data, const EDNSOptionViewMap& ednsOptions, bool tcp, std::string& requestorId, std::string& deviceId, std::string& deviceName, const std::vector& proxyProtocolValues) const +unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::unordered_set* policyTags, LuaContext::LuaObject& data, const EDNSOptionViewMap& ednsOptions, bool tcp, std::string& requestorId, std::string& deviceId, std::string& deviceName, std::string& routingTag, const std::vector& proxyProtocolValues) const { if(d_gettag) { std::vector> proxyProtocolValuesMap; @@ -575,6 +486,12 @@ unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& edn if (deviceNameret) { deviceName = *deviceNameret; } + + const auto routingTarget = std::get<6>(ret); + if (routingTarget) { + routingTag = *routingTarget; + } + return std::get<0>(ret); } return 0; @@ -583,7 +500,7 @@ unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& edn struct pdns_ffi_param { public: - pdns_ffi_param(const DNSName& qname_, uint16_t qtype_, const ComboAddress& local_, const ComboAddress& remote_, const Netmask& ednssubnet_, std::unordered_set& policyTags_, std::vector& records_, const EDNSOptionViewMap& ednsOptions_, const std::vector& proxyProtocolValues_, std::string& requestorId_, std::string& deviceId_, std::string& deviceName_, boost::optional& rcode_, uint32_t& ttlCap_, bool& variable_, bool tcp_, bool& logQuery_, bool& logResponse_, bool& followCNAMERecords_): qname(qname_), local(local_), remote(remote_), ednssubnet(ednssubnet_), policyTags(policyTags_), records(records_), ednsOptions(ednsOptions_), proxyProtocolValues(proxyProtocolValues_), requestorId(requestorId_), deviceId(deviceId_), deviceName(deviceName_), rcode(rcode_), ttlCap(ttlCap_), variable(variable_), logQuery(logQuery_), logResponse(logResponse_), followCNAMERecords(followCNAMERecords_), qtype(qtype_), tcp(tcp_) + pdns_ffi_param(const DNSName& qname_, uint16_t qtype_, const ComboAddress& local_, const ComboAddress& remote_, const Netmask& ednssubnet_, std::unordered_set& policyTags_, std::vector& records_, const EDNSOptionViewMap& ednsOptions_, const std::vector& proxyProtocolValues_, std::string& requestorId_, std::string& deviceId_, std::string& deviceName_, std::string& routingTag_, boost::optional& rcode_, uint32_t& ttlCap_, bool& variable_, bool tcp_, bool& logQuery_, bool& logResponse_, bool& followCNAMERecords_): qname(qname_), local(local_), remote(remote_), ednssubnet(ednssubnet_), policyTags(policyTags_), records(records_), ednsOptions(ednsOptions_), proxyProtocolValues(proxyProtocolValues_), requestorId(requestorId_), deviceId(deviceId_), deviceName(deviceName_), routingTag(routingTag_), rcode(rcode_), ttlCap(ttlCap_), variable(variable_), logQuery(logQuery_), logResponse(logResponse_), followCNAMERecords(followCNAMERecords_), qtype(qtype_), tcp(tcp_) { } @@ -605,6 +522,7 @@ public: std::string& requestorId; std::string& deviceId; std::string& deviceName; + std::string& routingTag; boost::optional& rcode; uint32_t& ttlCap; bool& variable; @@ -617,10 +535,10 @@ public: bool tcp; }; -unsigned int RecursorLua4::gettag_ffi(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::unordered_set* policyTags, std::vector& records, LuaContext::LuaObject& data, const EDNSOptionViewMap& ednsOptions, bool tcp, const std::vector& proxyProtocolValues, std::string& requestorId, std::string& deviceId, std::string& deviceName, boost::optional& rcode, uint32_t& ttlCap, bool& variable, bool& logQuery, bool& logResponse, bool& followCNAMERecords) const +unsigned int RecursorLua4::gettag_ffi(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::unordered_set* policyTags, std::vector& records, LuaContext::LuaObject& data, const EDNSOptionViewMap& ednsOptions, bool tcp, const std::vector& proxyProtocolValues, std::string& requestorId, std::string& deviceId, std::string& deviceName, std::string& routingTag, boost::optional& rcode, uint32_t& ttlCap, bool& variable, bool& logQuery, bool& logResponse, bool& followCNAMERecords) const { if (d_gettag_ffi) { - pdns_ffi_param_t param(qname, qtype, local, remote, ednssubnet, *policyTags, records, ednsOptions, proxyProtocolValues, requestorId, deviceId, deviceName, rcode, ttlCap, variable, tcp, logQuery, logResponse, followCNAMERecords); + pdns_ffi_param_t param(qname, qtype, local, remote, ednssubnet, *policyTags, records, ednsOptions, proxyProtocolValues, requestorId, deviceId, deviceName, routingTag, rcode, ttlCap, variable, tcp, logQuery, logResponse, followCNAMERecords); auto ret = d_gettag_ffi(¶m); if (ret) { @@ -662,10 +580,10 @@ loop:; ret = followCNAMERecords(dq.records, QType(dq.qtype)); } else if(dq.followupFunction=="getFakeAAAARecords") { - ret=getFakeAAAARecords(dq.followupName, dq.followupPrefix, dq.records); + ret=getFakeAAAARecords(dq.followupName, ComboAddress(dq.followupPrefix), dq.records); } else if(dq.followupFunction=="getFakePTRRecords") { - ret=getFakePTRRecords(dq.followupName, dq.followupPrefix, dq.records); + ret=getFakePTRRecords(dq.followupName, dq.records); } else if(dq.followupFunction=="udpQueryResponse") { dq.udpAnswer = GenUDPQueryResponse(dq.udpQueryDest, dq.udpQuery); @@ -899,6 +817,11 @@ void pdns_ffi_param_set_deviceid(pdns_ffi_param_t* ref, size_t len, const void* ref->deviceId = std::string(reinterpret_cast(name), len); } +void pdns_ffi_param_set_routingtag(pdns_ffi_param_t* ref, const char* rtag) +{ + ref->routingTag = std::string(rtag); +} + void pdns_ffi_param_set_variable(pdns_ffi_param_t* ref, bool variable) { ref->variable = variable;