From 14ffdb6639fb65001e4f279f7268f863abd46aa3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 4 Dec 2021 10:08:18 -0500 Subject: [PATCH] configurable route poker this allows you to use exit nodes without forcing routes over the interface, useful for using lokinet with an exit and selectively routing over the lokinet interface using an external socks proxy or binding to device explicitly. * make route poker configurable, defaults to enabled but allows disabling it on runtime if desired * add config option [network]:auto-routing to enable/disable route poker --- llarp/config/config.cpp | 12 ++++++++++++ llarp/config/config.hpp | 2 ++ llarp/router/route_poker.cpp | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index b625b9e78..84088b8aa 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -533,6 +533,18 @@ namespace llarp m_ExitAuths.emplace(exit, auth); }); + conf.defineOption( + "network", + "auto-routing", + ClientOnly, + Default{true}, + Comment{ + "enable / disable auto routing. When using an exit lokinet will add routes to " + "the OS to make traffic go over the network interface via lokinet.", + "enabled by default.", + }, + AssignmentAcceptor(m_EnableRoutePoker)); + conf.defineOption( "network", "ifname", diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index b738bdfb2..677a5ed2e 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -129,6 +129,8 @@ namespace llarp std::optional m_AddrMapPersistFile; + bool m_EnableRoutePoker; + void defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params); }; diff --git a/llarp/router/route_poker.cpp b/llarp/router/route_poker.cpp index 9017125bc..217814fe5 100644 --- a/llarp/router/route_poker.cpp +++ b/llarp/router/route_poker.cpp @@ -162,10 +162,13 @@ namespace llarp if (m_Enabled) return; - m_Enabling = true; - Update(); - m_Enabling = false; - m_Enabled = true; + if (m_Router->GetConfig()->network.m_EnableRoutePoker) + { + m_Enabling = true; + Update(); + m_Enabling = false; + m_Enabled = true; + } systemd_resolved_set_dns( m_Router->hiddenServiceContext().GetDefault()->GetIfName(), @@ -191,6 +194,9 @@ namespace llarp void RoutePoker::Up() { + if (not m_Router->GetConfig()->network.m_EnableRoutePoker) + return; + vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager(); // black hole all routes by default @@ -207,6 +213,9 @@ namespace llarp void RoutePoker::Down() { + if (not m_Router->GetConfig()->network.m_EnableRoutePoker) + return; + // unpoke routes for first hops m_Router->ForEachPeer( [&](auto session, auto) mutable { DelRoute(session->GetRemoteEndpoint().asIPv4()); },