From: Peter van Dijk Date: Tue, 2 Oct 2018 10:17:31 +0000 (+0200) Subject: send REFUSED for UDP queries we are unable to handle X-Git-Tag: dnsdist-1.3.3~75^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3852fafa73ad92dab35363cfd3c36525b459f4d2;p=thirdparty%2Fpdns.git send REFUSED for UDP queries we are unable to handle --- diff --git a/pdns/ixfrdist.cc b/pdns/ixfrdist.cc index 2e29679d94..98fc97e820 100644 --- a/pdns/ixfrdist.cc +++ b/pdns/ixfrdist.cc @@ -423,15 +423,16 @@ static bool checkQuery(const MOADNSParser& mdp, const ComboAddress& saddr, const if (g_domainConfigs.find(mdp.d_qname) == g_domainConfigs.end()) { info_msg.push_back("Domain name '" + mdp.d_qname.toLogString() + "' is not configured for distribution"); } - - const auto zoneInfo = getCurrentZoneInfo(mdp.d_qname); - if (zoneInfo == nullptr) { - info_msg.push_back("Domain has not been transferred yet"); + else { + const auto zoneInfo = getCurrentZoneInfo(mdp.d_qname); + if (zoneInfo == nullptr) { + info_msg.push_back("Domain has not been transferred yet"); + } } } if (!info_msg.empty()) { - g_log< that represents the full response to a SOA + * Returns a vector that represents the full positive response to a SOA * query. QNAME is read from mdp. */ static bool makeSOAPacket(const MOADNSParser& mdp, vector& packet) { @@ -471,6 +472,20 @@ static bool makeSOAPacket(const MOADNSParser& mdp, vector& packet) { return true; } +/* + * Returns a vector that represents the full REFUSED response to a + * query. QNAME and type are read from mdp. + */ +static bool makeRefusedPacket(const MOADNSParser& mdp, vector& packet) { + DNSPacketWriter pw(packet, mdp.d_qname, mdp.d_qtype); + pw.getHeader()->id = mdp.d_header.id; + pw.getHeader()->rd = mdp.d_header.rd; + pw.getHeader()->qr = 1; + pw.getHeader()->rcode = RCode::Refused; + + return true; +} + static vector getSOAPacket(const MOADNSParser& mdp, const shared_ptr& soa) { vector packet; DNSPacketWriter pw(packet, mdp.d_qname, mdp.d_qtype); @@ -710,23 +725,24 @@ static void handleUDPRequest(int fd, boost::any&) { } MOADNSParser mdp(true, string(buf, res)); - if (!checkQuery(mdp, saddr)) { - return; + vector packet; + if (checkQuery(mdp, saddr)) { + /* RFC 1995 Section 2 + * Transport of a query may be by either UDP or TCP. If an IXFR query + * is via UDP, the IXFR server may attempt to reply using UDP if the + * entire response can be contained in a single DNS packet. If the UDP + * reply does not fit, the query is responded to with a single SOA + * record of the server's current version to inform the client that a + * TCP query should be initiated. + * + * Let's not complicate this with IXFR over UDP (and looking if we need to truncate etc). + * Just send the current SOA and let the client try over TCP + */ + makeSOAPacket(mdp, packet); + } else { + makeRefusedPacket(mdp, packet); } - /* RFC 1995 Section 2 - * Transport of a query may be by either UDP or TCP. If an IXFR query - * is via UDP, the IXFR server may attempt to reply using UDP if the - * entire response can be contained in a single DNS packet. If the UDP - * reply does not fit, the query is responded to with a single SOA - * record of the server's current version to inform the client that a - * TCP query should be initiated. - * - * Let's not complicate this with IXFR over UDP (and looking if we need to truncate etc). - * Just send the current SOA and let the client try over TCP - */ - vector packet; - makeSOAPacket(mdp, packet); if(sendto(fd, &packet[0], packet.size(), 0, (struct sockaddr*) &saddr, fromlen) < 0) { auto savedErrno = errno; g_log<