From 0cf09d643581aeea3f6d5949217cc8cd7b557471 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 11 Jun 2019 15:42:11 -0400 Subject: [PATCH] make exits support v6 probably --- llarp/handlers/exit.cpp | 20 +++++++++++++++++++- llarp/handlers/exit.hpp | 4 ++++ llarp/handlers/tun.cpp | 13 ++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index 371b88930..0470077b4 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -57,6 +57,12 @@ namespace llarp return obj; } + bool + ExitEndpoint::SupportsV6() const + { + return m_UseV6; + } + bool ExitEndpoint::ShouldHookDNSMessage(const dns::Message &msg) const { @@ -86,6 +92,7 @@ namespace llarp ExitEndpoint::HandleHookedDNSMessage( dns::Message &&msg, std::function< void(dns::Message) > reply) { + if(msg.questions[0].qtype == dns::qTypePTR) { huint32_t ip; @@ -132,6 +139,7 @@ namespace llarp || 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")) { RouterID random; @@ -158,7 +166,11 @@ namespace llarp { huint128_t ip; 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 // map it @@ -539,8 +551,14 @@ namespace llarp } else if(m_IfAddr.FromString(host_str)) { + m_UseV6 = true; m_OurRange.netmask_bits = netmask_ipv6_bits(m_Tun.netmask); } + else + { + LogError(Name(), " invalid ifaddr: ", v); + return false; + } m_OurRange.addr = m_IfAddr; m_NextAddr = m_IfAddr; m_HigestAddr = m_IfAddr | (~m_OurRange.netmask_bits); diff --git a/llarp/handlers/exit.hpp b/llarp/handlers/exit.hpp index 461a406aa..e96409468 100644 --- a/llarp/handlers/exit.hpp +++ b/llarp/handlers/exit.hpp @@ -32,6 +32,9 @@ namespace llarp util::StatusObject ExtractStatus() const; + bool + SupportsV6() const; + bool ShouldHookDNSMessage(const dns::Message& msg) const override; @@ -177,6 +180,7 @@ namespace llarp /// internet to llarp packet queue PacketQueue_t m_InetToNetwork; + bool m_UseV6; }; } // namespace handlers } // namespace llarp diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 26fd604ef..7422680a5 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -366,7 +366,8 @@ namespace llarp else if(msg.questions[0].qtype == dns::qTypeA || 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; llarp::service::Address addr; // on MacOS this is a typeA query @@ -404,7 +405,7 @@ namespace llarp else if(HasAddress(addr)) { huint128_t ip = ObtainIPForAddr(addr, false); - msg.AddINReply(ip, isV6); + msg.AddINReply(ip, isV6); } else { @@ -414,7 +415,8 @@ namespace llarp return EnsurePathToService( addr, [=](const Address &, OutboundContext *ctx) { - SendDNSReply(addr, ctx, replyMsg, reply, false, isV6 || !isV4); + SendDNSReply(addr, ctx, replyMsg, reply, false, + isV6 || !isV4); }, 2000); } @@ -778,7 +780,8 @@ namespace llarp { 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()) { @@ -871,7 +874,7 @@ namespace llarp void 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]); }