From f3d23d6fb6b4092ae46df430ddf3865fef37a33e Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 9 Mar 2020 16:47:27 -0400 Subject: [PATCH] strip rr from dns reply for .snode and .loki (#1172) fix dns replies so that extra RR for edns are not included. --- llarp/dns/message.cpp | 49 +++++++++++++------------------------- llarp/handlers/tun.cpp | 4 ++-- llarp/handlers/tun.hpp | 1 + llarp/service/endpoint.cpp | 4 ++-- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/llarp/dns/message.cpp b/llarp/dns/message.cpp index 577debb4c..18fad99ee 100644 --- a/llarp/dns/message.cpp +++ b/llarp/dns/message.cpp @@ -84,8 +84,8 @@ namespace llarp hdr.fields = hdr_fields; hdr.qd_count = questions.size(); hdr.an_count = answers.size(); - hdr.ns_count = authorities.size(); - hdr.ar_count = additional.size(); + hdr.ns_count = 0; + hdr.ar_count = 0; if(!hdr.Encode(buf)) return false; @@ -98,14 +98,6 @@ namespace llarp if(!answer.Encode(buf)) return false; - for(const auto& auth : authorities) - if(!auth.Encode(buf)) - return false; - - for(const auto& rr : additional) - if(!rr.Encode(buf)) - return false; - return true; } @@ -129,24 +121,6 @@ namespace llarp return false; } } - /* - for(auto& auth : authorities) - { - if(!auth.Decode(buf)) - { - llarp::LogError("failed to decode auth"); - return false; - } - } - for(auto& rr : additional) - { - if(!rr.Decode(buf)) - { - llarp::LogError("failed to decode additional"); - return false; - } - } - */ return true; } @@ -162,12 +136,18 @@ namespace llarp } } + static constexpr uint16_t + reply_flags(uint16_t setbits) + { + return setbits | flags_QR | flags_AA | flags_RA; + } + void Message::AddINReply(llarp::huint128_t ip, bool isV6, RR_TTL_t ttl) { if(questions.size()) { - hdr_fields |= flags_QR | flags_AA | flags_RA; + hdr_fields = reply_flags(hdr_fields); ResourceRecord rec; rec.rr_name = questions[0].qname; rec.rr_class = qClassIN; @@ -193,7 +173,8 @@ namespace llarp { if(questions.size()) { - hdr_fields |= flags_QR | flags_AA | flags_RA; + hdr_fields = reply_flags(hdr_fields); + const auto& question = questions[0]; answers.emplace_back(); auto& rec = answers.back(); @@ -217,7 +198,8 @@ namespace llarp { if(questions.size()) { - hdr_fields |= flags_QR | flags_AA | flags_RA; + hdr_fields = reply_flags(hdr_fields); + const auto& question = questions[0]; answers.emplace_back(); auto& rec = answers.back(); @@ -241,7 +223,8 @@ namespace llarp { if(questions.size()) { - hdr_fields |= flags_QR | flags_AA; + hdr_fields = reply_flags(hdr_fields); + const auto& question = questions[0]; answers.emplace_back(); auto& rec = answers.back(); @@ -266,7 +249,7 @@ namespace llarp if(questions.size()) { // authorative response with recursion available - hdr_fields |= flags_QR | flags_AA | flags_RA; + hdr_fields = reply_flags(hdr_fields); // don't allow recursion on this request hdr_fields &= ~flags_RD; hdr_fields |= flags_RCODENameError; diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index e4468ab72..cd653f139 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -448,7 +448,7 @@ namespace llarp } else { - auto replyMsg = std::make_shared< dns::Message >(msg); + auto replyMsg = std::make_shared< dns::Message >(std::move(msg)); using service::Address; using service::OutboundContext; return EnsurePathToService( @@ -554,7 +554,7 @@ namespace llarp } else { - auto replyMsg = std::make_shared< dns::Message >(std::move(msg)); + auto replyMsg = std::make_shared< dns::Message >(msg); using service::Address; using service::OutboundContext; return EnsurePathToService( diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 538a36abb..4b564677f 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -278,6 +278,7 @@ namespace llarp if(ctx) { huint128_t ip = ObtainIPForAddr(addr, snode); + query->answers.clear(); query->AddINReply(ip, sendIPv6); } else diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 3d483dd06..41291e131 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -667,7 +667,7 @@ namespace llarp auto range = serviceLookups.equal_range(addr); auto i = range.first; - if(i != range.second) + while(i != range.second) { i->second(addr, itr->second.get()); ++i; @@ -945,7 +945,7 @@ namespace llarp LogError(Name(), " failed to lookup ", addr.ToString(), " from ", endpoint); fails[endpoint] = fails[endpoint] + 1; - // inform all + // inform one auto range = lookups.equal_range(addr); auto itr = range.first; if(itr != range.second)