add AAAA records that return SIIT addresses

pull/454/head
Jeff Becker 5 years ago
parent 3a4d8f16a7
commit c931ac069f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -153,7 +153,7 @@ namespace llarp
}
void
Message::AddINReply(llarp::huint32_t ip, RR_TTL_t ttl)
Message::AddINReply(llarp::huint32_t ip, bool isV6, RR_TTL_t ttl)
{
if(questions.size())
{
@ -161,11 +161,19 @@ namespace llarp
const auto& question = questions[0];
ResourceRecord rec;
rec.rr_name = question.qname;
rec.rr_type = qTypeA;
rec.rr_class = qClassIN;
rec.ttl = ttl;
rec.rData.resize(4);
htobe32buf(rec.rData.data(), ip.h);
if(isV6)
{
rec.rr_type = qTypeAAAA;
ip.SIIT(rec.rData);
}
else
{
rec.rr_type = qTypeA;
rec.rData.resize(4);
htobe32buf(rec.rData.data(), ip.h);
}
answers.emplace_back(std::move(rec));
}
}

@ -61,7 +61,7 @@ namespace llarp
AddCNAMEReply(std::string name, RR_TTL_t ttl = 1);
void
AddINReply(llarp::huint32_t addr, RR_TTL_t ttl = 1);
AddINReply(llarp::huint32_t addr, bool isV6, RR_TTL_t ttl = 1);
void
AddAReply(std::string name, RR_TTL_t ttl = 1);

@ -70,7 +70,8 @@ namespace llarp
return m_OurRange.Contains(ip);
}
else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeCNAME)
|| msg.questions[0].qtype == dns::qTypeCNAME
|| msg.questions[0].qtype == dns::qTypeAAAA)
{
// hook for forward dns or cname when using snode tld
if(msg.questions[0].qname.find(".snode.")
@ -130,8 +131,10 @@ namespace llarp
else
msg.AddNXReply();
}
else if(msg.questions[0].qtype == dns::qTypeA)
else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA)
{
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA;
if(msg.questions[0].qname == "random.snode"
|| msg.questions[0].qname == "random.snode.")
{
@ -146,7 +149,7 @@ namespace llarp
if(msg.questions[0].qname == "localhost.loki."
|| msg.questions[0].qname == "localhost.loki")
{
msg.AddINReply(GetIfAddr());
msg.AddINReply(GetIfAddr(), isV6);
reply(msg);
return true;
}
@ -161,7 +164,7 @@ namespace llarp
// we do not have it mapped
// map it
ip = ObtainServiceNodeIP(r);
msg.AddINReply(ip);
msg.AddINReply(ip, isV6);
}
else
{
@ -170,7 +173,7 @@ namespace llarp
if(itr != m_KeyToIP.end())
{
ip = itr->second;
msg.AddINReply(ip);
msg.AddINReply(ip, isV6);
}
else // fallback case that should never happen (probably)
msg.AddNXReply();

@ -248,7 +248,8 @@ namespace llarp
TunEndpoint::HandleHookedDNSMessage(
dns::Message &&msg, std::function< void(dns::Message) > reply)
{
//llarp::LogInfo("Tun.HandleHookedDNSMessage ", msg.questions[0].qname, " of type", msg.questions[0].qtype);
// llarp::LogInfo("Tun.HandleHookedDNSMessage ", msg.questions[0].qname, "
// of type", msg.questions[0].qtype);
if(msg.questions.size() != 1)
{
llarp::LogWarn("bad number of dns questions: ", msg.questions.size());
@ -294,8 +295,10 @@ namespace llarp
msg.AddNXReply();
reply(msg);
}
else if(msg.questions[0].qtype == dns::qTypeA)
else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA)
{
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA;
llarp::service::Address addr;
// on MacOS this is a typeA query
if(is_random_snode(msg))
@ -315,7 +318,7 @@ namespace llarp
huint32_t ip = service->GetIfAddr();
if(ip.h)
{
msg.AddINReply(ip);
msg.AddINReply(ip, isV6);
++counter;
}
return true;
@ -328,7 +331,7 @@ namespace llarp
if(HasAddress(addr))
{
huint32_t ip = ObtainIPForAddr(addr, false);
msg.AddINReply(ip);
msg.AddINReply(ip, isV6);
}
else
{
@ -336,7 +339,7 @@ namespace llarp
return EnsurePathToService(
addr,
[=](const service::Address &remote, OutboundContext *ctx) {
SendDNSReply(remote, ctx, replyMsg, reply, false);
SendDNSReply(remote, ctx, replyMsg, reply, false, isV6);
},
2000);
}
@ -346,7 +349,8 @@ namespace llarp
dns::Message *replyMsg = new dns::Message(std::move(msg));
EnsurePathToSNode(addr.as_array(),
[=](const RouterID &remote, exit::BaseSession *s) {
SendDNSReply(remote, s, replyMsg, reply, true);
SendDNSReply(remote, s, replyMsg, reply, true,
isV6);
});
return true;
}

@ -196,12 +196,13 @@ namespace llarp
template < typename Addr_t, typename Endpoint_t >
void
SendDNSReply(Addr_t addr, Endpoint_t* ctx, dns::Message* query,
std::function< void(dns::Message) > reply, bool snode)
std::function< void(dns::Message) > reply, bool snode,
bool sendIPv6)
{
if(ctx)
{
huint32_t ip = ObtainIPForAddr(addr, snode);
query->AddINReply(ip);
query->AddINReply(ip, sendIPv6);
}
else
query->AddNXReply();

@ -53,6 +53,16 @@ namespace llarp
return out;
}
template<typename Container>
void SIIT(Container & c)
{
c.resize(16);
std::fill(c.begin(), c.end(), 0);
htobe32buf(c.data() + 12, h);
c[11] = 0xff;
c[10] = 0xff;
}
std::string ToString() const
{
uint32_t n = htonl(h);

@ -115,7 +115,7 @@ TEST_F(DNSLibTest, TestSerializeMessage)
q.qname = "whatever.tld";
q.qclass = 1;
q.qtype = 1;
m.AddINReply({1});
m.AddINReply({1}, false);
ASSERT_EQ(m.questions.size(), 1U);
ASSERT_EQ(m.answers.size(), 1U);
ASSERT_TRUE(m.Encode(&buf));

Loading…
Cancel
Save