diff --git a/llarp/dns/server.cpp b/llarp/dns/server.cpp index 8b3a7efe3..f75b280a7 100644 --- a/llarp/dns/server.cpp +++ b/llarp/dns/server.cpp @@ -400,9 +400,11 @@ namespace llarp::dns } void - ResetInternalState() override + ResetInternalState(std::optional> replace_upstream) override { Down(); + if (replace_upstream) + m_conf.m_upstreamDNS = *replace_upstream; Up(m_conf); } diff --git a/llarp/dns/server.hpp b/llarp/dns/server.hpp index 39770fe60..eef7ee8cb 100644 --- a/llarp/dns/server.hpp +++ b/llarp/dns/server.hpp @@ -174,9 +174,12 @@ namespace llarp::dns virtual std::string_view ResolverName() const = 0; - /// reset state + /// reset state, replace upstream info with new info if desired virtual void - ResetInternalState(){}; + ResetInternalState(std::optional> replace_upstream = std::nullopt) + { + (void)replace_upstream; + }; /// cancel all pending requests and ceace further operation virtual void diff --git a/llarp/handlers/exit.hpp b/llarp/handlers/exit.hpp index 66bb09784..470cfea4c 100644 --- a/llarp/handlers/exit.hpp +++ b/llarp/handlers/exit.hpp @@ -24,9 +24,6 @@ namespace llarp return "snode"; } - void - ResetInternalState() override{}; - void CancelPendingQueries() override{}; diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index e3a3333ae..0fa6774e3 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -67,7 +67,7 @@ namespace llarp : m_Reply{std::move(reply)}, m_OurIP{std::move(our_ip)}, m_Config{std::move(conf)} {} - ~DnsInterceptor() override = default; + ~DnsInterceptor() override = default; void SendTo(const SockAddr& to, const SockAddr& from, OwnedBuffer buf) const override @@ -91,14 +91,16 @@ namespace llarp bool WouldLoop(const SockAddr& to, const SockAddr& from) const override { - if constexpr (platform::is_apple) { - // DNS on Apple is a bit weird because in order for the NetworkExtension itself to send data - // through the tunnel we have to proxy DNS requests through Apple APIs (and so our actual - // upstream DNS won't be set in our resolvers, which is why the vanilla WouldLoop won't work - // for us). However when active the mac also only queries the main tunnel IP for DNS, so we - // consider anything else to be upstream-bound DNS to let it through the tunnel. - return to.getIP() != m_OurIP; - } + if constexpr (platform::is_apple) + { + // DNS on Apple is a bit weird because in order for the NetworkExtension itself to send + // data through the tunnel we have to proxy DNS requests through Apple APIs (and so our + // actual upstream DNS won't be set in our resolvers, which is why the vanilla WouldLoop + // won't work for us). However when active the mac also only queries the main tunnel IP + // for DNS, so we consider anything else to be upstream-bound DNS to let it through the + // tunnel. + return to.getIP() != m_OurIP; + } else if (auto maybe_addr = m_Config.m_QueryBind) { const auto& addr = *maybe_addr; @@ -261,7 +263,14 @@ namespace llarp std::vector TunEndpoint::ReconfigureDNS(std::vector servers) { - // TODO: implement me + if (m_DNS) + { + for (auto weak : m_DNS->GetAllResolvers()) + { + if (auto ptr = weak.lock()) + ptr->ResetInternalState(servers); + } + } return servers; } diff --git a/llarp/net/posix.cpp b/llarp/net/posix.cpp index 2f32ada62..8d0cdfdde 100644 --- a/llarp/net/posix.cpp +++ b/llarp/net/posix.cpp @@ -22,7 +22,6 @@ namespace llarp::net { - class Platform_Impl : public Platform { template