strip rr from dns reply for .snode and .loki (#1172)

fix dns replies so that extra RR for edns are not included.
pull/1175/head
Jeff 4 years ago committed by GitHub
parent 1441115d96
commit f3d23d6fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -84,8 +84,8 @@ namespace llarp
hdr.fields = hdr_fields; hdr.fields = hdr_fields;
hdr.qd_count = questions.size(); hdr.qd_count = questions.size();
hdr.an_count = answers.size(); hdr.an_count = answers.size();
hdr.ns_count = authorities.size(); hdr.ns_count = 0;
hdr.ar_count = additional.size(); hdr.ar_count = 0;
if(!hdr.Encode(buf)) if(!hdr.Encode(buf))
return false; return false;
@ -98,14 +98,6 @@ namespace llarp
if(!answer.Encode(buf)) if(!answer.Encode(buf))
return false; 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; return true;
} }
@ -129,24 +121,6 @@ namespace llarp
return false; 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; 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 void
Message::AddINReply(llarp::huint128_t ip, bool isV6, RR_TTL_t ttl) Message::AddINReply(llarp::huint128_t ip, bool isV6, RR_TTL_t ttl)
{ {
if(questions.size()) if(questions.size())
{ {
hdr_fields |= flags_QR | flags_AA | flags_RA; hdr_fields = reply_flags(hdr_fields);
ResourceRecord rec; ResourceRecord rec;
rec.rr_name = questions[0].qname; rec.rr_name = questions[0].qname;
rec.rr_class = qClassIN; rec.rr_class = qClassIN;
@ -193,7 +173,8 @@ namespace llarp
{ {
if(questions.size()) if(questions.size())
{ {
hdr_fields |= flags_QR | flags_AA | flags_RA; hdr_fields = reply_flags(hdr_fields);
const auto& question = questions[0]; const auto& question = questions[0];
answers.emplace_back(); answers.emplace_back();
auto& rec = answers.back(); auto& rec = answers.back();
@ -217,7 +198,8 @@ namespace llarp
{ {
if(questions.size()) if(questions.size())
{ {
hdr_fields |= flags_QR | flags_AA | flags_RA; hdr_fields = reply_flags(hdr_fields);
const auto& question = questions[0]; const auto& question = questions[0];
answers.emplace_back(); answers.emplace_back();
auto& rec = answers.back(); auto& rec = answers.back();
@ -241,7 +223,8 @@ namespace llarp
{ {
if(questions.size()) if(questions.size())
{ {
hdr_fields |= flags_QR | flags_AA; hdr_fields = reply_flags(hdr_fields);
const auto& question = questions[0]; const auto& question = questions[0];
answers.emplace_back(); answers.emplace_back();
auto& rec = answers.back(); auto& rec = answers.back();
@ -266,7 +249,7 @@ namespace llarp
if(questions.size()) if(questions.size())
{ {
// authorative response with recursion available // 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 // don't allow recursion on this request
hdr_fields &= ~flags_RD; hdr_fields &= ~flags_RD;
hdr_fields |= flags_RCODENameError; hdr_fields |= flags_RCODENameError;

@ -448,7 +448,7 @@ namespace llarp
} }
else else
{ {
auto replyMsg = std::make_shared< dns::Message >(msg); auto replyMsg = std::make_shared< dns::Message >(std::move(msg));
using service::Address; using service::Address;
using service::OutboundContext; using service::OutboundContext;
return EnsurePathToService( return EnsurePathToService(
@ -554,7 +554,7 @@ namespace llarp
} }
else else
{ {
auto replyMsg = std::make_shared< dns::Message >(std::move(msg)); auto replyMsg = std::make_shared< dns::Message >(msg);
using service::Address; using service::Address;
using service::OutboundContext; using service::OutboundContext;
return EnsurePathToService( return EnsurePathToService(

@ -278,6 +278,7 @@ namespace llarp
if(ctx) if(ctx)
{ {
huint128_t ip = ObtainIPForAddr(addr, snode); huint128_t ip = ObtainIPForAddr(addr, snode);
query->answers.clear();
query->AddINReply(ip, sendIPv6); query->AddINReply(ip, sendIPv6);
} }
else else

@ -667,7 +667,7 @@ namespace llarp
auto range = serviceLookups.equal_range(addr); auto range = serviceLookups.equal_range(addr);
auto i = range.first; auto i = range.first;
if(i != range.second) while(i != range.second)
{ {
i->second(addr, itr->second.get()); i->second(addr, itr->second.get());
++i; ++i;
@ -945,7 +945,7 @@ namespace llarp
LogError(Name(), " failed to lookup ", addr.ToString(), " from ", LogError(Name(), " failed to lookup ", addr.ToString(), " from ",
endpoint); endpoint);
fails[endpoint] = fails[endpoint] + 1; fails[endpoint] = fails[endpoint] + 1;
// inform all // inform one
auto range = lookups.equal_range(addr); auto range = lookups.equal_range(addr);
auto itr = range.first; auto itr = range.first;
if(itr != range.second) if(itr != range.second)

Loading…
Cancel
Save