make exits support v6 probably

pull/686/head
Jeff Becker 5 years ago
parent de51ef23bf
commit 0cf09d6435
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -57,6 +57,12 @@ namespace llarp
return obj; return obj;
} }
bool
ExitEndpoint::SupportsV6() const
{
return m_UseV6;
}
bool bool
ExitEndpoint::ShouldHookDNSMessage(const dns::Message &msg) const ExitEndpoint::ShouldHookDNSMessage(const dns::Message &msg) const
{ {
@ -86,6 +92,7 @@ namespace llarp
ExitEndpoint::HandleHookedDNSMessage( ExitEndpoint::HandleHookedDNSMessage(
dns::Message &&msg, std::function< void(dns::Message) > reply) dns::Message &&msg, std::function< void(dns::Message) > reply)
{ {
if(msg.questions[0].qtype == dns::qTypePTR) if(msg.questions[0].qtype == dns::qTypePTR)
{ {
huint32_t ip; huint32_t ip;
@ -132,6 +139,7 @@ namespace llarp
|| msg.questions[0].qtype == dns::qTypeAAAA) || msg.questions[0].qtype == dns::qTypeAAAA)
{ {
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA; const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA;
const bool isV4 = msg.questions[0].qtype == dns::qTypeA;
if(msg.questions[0].IsName("random.snode")) if(msg.questions[0].IsName("random.snode"))
{ {
RouterID random; RouterID random;
@ -158,7 +166,11 @@ namespace llarp
{ {
huint128_t ip; huint128_t ip;
PubKey pubKey(r); PubKey pubKey(r);
if(m_SNodeKeys.find(pubKey) == m_SNodeKeys.end()) if(isV4 && SupportsV6())
{
msg.hdr_fields |= dns::flags_QR | dns::flags_AA | dns::flags_RA;
}
else if(m_SNodeKeys.find(pubKey) == m_SNodeKeys.end())
{ {
// we do not have it mapped // we do not have it mapped
// map it // map it
@ -539,8 +551,14 @@ namespace llarp
} }
else if(m_IfAddr.FromString(host_str)) else if(m_IfAddr.FromString(host_str))
{ {
m_UseV6 = true;
m_OurRange.netmask_bits = netmask_ipv6_bits(m_Tun.netmask); m_OurRange.netmask_bits = netmask_ipv6_bits(m_Tun.netmask);
} }
else
{
LogError(Name(), " invalid ifaddr: ", v);
return false;
}
m_OurRange.addr = m_IfAddr; m_OurRange.addr = m_IfAddr;
m_NextAddr = m_IfAddr; m_NextAddr = m_IfAddr;
m_HigestAddr = m_IfAddr | (~m_OurRange.netmask_bits); m_HigestAddr = m_IfAddr | (~m_OurRange.netmask_bits);

@ -32,6 +32,9 @@ namespace llarp
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;
bool
SupportsV6() const;
bool bool
ShouldHookDNSMessage(const dns::Message& msg) const override; ShouldHookDNSMessage(const dns::Message& msg) const override;
@ -177,6 +180,7 @@ namespace llarp
/// internet to llarp packet queue /// internet to llarp packet queue
PacketQueue_t m_InetToNetwork; PacketQueue_t m_InetToNetwork;
bool m_UseV6;
}; };
} // namespace handlers } // namespace handlers
} // namespace llarp } // namespace llarp

@ -366,7 +366,8 @@ namespace llarp
else if(msg.questions[0].qtype == dns::qTypeA else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA) || msg.questions[0].qtype == dns::qTypeAAAA)
{ {
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA && SupportsV6(); const bool isV6 =
msg.questions[0].qtype == dns::qTypeAAAA && SupportsV6();
const bool isV4 = msg.questions[0].qtype == dns::qTypeA; const bool isV4 = msg.questions[0].qtype == dns::qTypeA;
llarp::service::Address addr; llarp::service::Address addr;
// on MacOS this is a typeA query // on MacOS this is a typeA query
@ -404,7 +405,7 @@ namespace llarp
else if(HasAddress(addr)) else if(HasAddress(addr))
{ {
huint128_t ip = ObtainIPForAddr(addr, false); huint128_t ip = ObtainIPForAddr(addr, false);
msg.AddINReply(ip, isV6); msg.AddINReply(ip, isV6);
} }
else else
{ {
@ -414,7 +415,8 @@ namespace llarp
return EnsurePathToService( return EnsurePathToService(
addr, addr,
[=](const Address &, OutboundContext *ctx) { [=](const Address &, OutboundContext *ctx) {
SendDNSReply(addr, ctx, replyMsg, reply, false, isV6 || !isV4); SendDNSReply(addr, ctx, replyMsg, reply, false,
isV6 || !isV4);
}, },
2000); 2000);
} }
@ -778,7 +780,8 @@ namespace llarp
{ {
return false; return false;
} }
pkt.UpdateV4Address(net::IPPacket::TruncateV6(themIP), net::IPPacket::TruncateV6(usIP)); pkt.UpdateV4Address(net::IPPacket::TruncateV6(themIP),
net::IPPacket::TruncateV6(usIP));
} }
else if(pkt.IsV6()) else if(pkt.IsV6())
{ {
@ -871,7 +874,7 @@ namespace llarp
void void
TunEndpoint::MarkIPActive(huint128_t ip) TunEndpoint::MarkIPActive(huint128_t ip)
{ {
llarp::LogDebug(Name(), " address " , ip, " is active"); llarp::LogDebug(Name(), " address ", ip, " is active");
m_IPActivity[ip] = std::max(Now(), m_IPActivity[ip]); m_IPActivity[ip] = std::max(Now(), m_IPActivity[ip]);
} }

Loading…
Cancel
Save