limit route poker

pull/1969/head
Jeff Becker 2 years ago committed by Jason Rhinelander
parent 61f66ac1ec
commit 26c1336517
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -97,6 +97,12 @@ namespace llarp
return Contains(net::ExpandV4(ip)); return Contains(net::ExpandV4(ip));
} }
inline bool
Contains(const net::ipaddr_t& ip) const
{
return var::visit([this](auto&& ip) { return Contains(ToHost(ip)); }, ip);
}
/// get the highest address on this range /// get the highest address on this range
constexpr huint128_t constexpr huint128_t
HighestAddr() const HighestAddr() const

@ -201,6 +201,11 @@ namespace llarp::net
saddr.asIPv6(), saddr.asIPv6(),
ipaddr_netmask_bits(addr->OnLinkPrefixLength, addr->Address.lpSockaddr->sa_family)); ipaddr_netmask_bits(addr->OnLinkPrefixLength, addr->Address.lpSockaddr->sa_family));
} }
if (auto* addr = a->FirstGatewayAddress)
{
SockAddr gw{*addr->Address.lpSockaddr};
cur.gateway = gw.getIP();
}
}); });
return all; return all;
} }

@ -25,6 +25,7 @@ namespace llarp
DisableRoute(ip, gw); DisableRoute(ip, gw);
// update and add new mapping // update and add new mapping
gw = *m_CurrentGateway; gw = *m_CurrentGateway;
log::info(logcat, "add route {} via {}", ip, gw);
EnableRoute(ip, gw); EnableRoute(ip, gw);
} }
else else
@ -57,7 +58,7 @@ namespace llarp
const auto itr = m_PokedRoutes.find(ip); const auto itr = m_PokedRoutes.find(ip);
if (itr == m_PokedRoutes.end()) if (itr == m_PokedRoutes.end())
return; return;
log::info(logcat, "del route {} via {}", itr->first, itr->second);
DisableRoute(itr->first, itr->second); DisableRoute(itr->first, itr->second);
m_PokedRoutes.erase(itr); m_PokedRoutes.erase(itr);
} }
@ -69,7 +70,10 @@ namespace llarp
if (m_Router->IsServiceNode()) if (m_Router->IsServiceNode())
return; return;
m_Router->loop()->call_every(100ms, weak_from_this(), [this]() { Update(); }); m_Router->loop()->call_every(100ms, weak_from_this(), [self = weak_from_this()]() {
if (auto ptr = self.lock())
ptr->Update();
});
} }
void void
@ -186,6 +190,8 @@ namespace llarp
m_CurrentGateway = next_gw; m_CurrentGateway = next_gw;
} }
} }
else if (m_Router->HasClientExit())
Up();
} }
void void
@ -201,7 +207,7 @@ namespace llarp
void void
RoutePoker::Up() RoutePoker::Up()
{ {
if (IsEnabled()) if (IsEnabled() and m_CurrentGateway and not m_up)
{ {
vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager(); vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager();
@ -216,6 +222,9 @@ namespace llarp
const auto ep = m_Router->hiddenServiceContext().GetDefault(); const auto ep = m_Router->hiddenServiceContext().GetDefault();
if (auto* vpn = ep->GetVPNInterface()) if (auto* vpn = ep->GetVPNInterface())
route.AddDefaultRouteViaInterface(*vpn); route.AddDefaultRouteViaInterface(*vpn);
m_up = true;
log::info(logcat, "route poker up");
} }
SetDNSMode(true); SetDNSMode(true);
} }
@ -229,7 +238,7 @@ namespace llarp
// remove default route // remove default route
if (IsEnabled()) if (IsEnabled() and m_up)
{ {
vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager(); vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager();
const auto ep = m_Router->hiddenServiceContext().GetDefault(); const auto ep = m_Router->hiddenServiceContext().GetDefault();
@ -238,6 +247,8 @@ namespace llarp
// delete route blackhole // delete route blackhole
route.DelBlackhole(); route.DelBlackhole();
m_up = false;
log::info(logcat, "route poker down");
} }
SetDNSMode(false); SetDNSMode(false);
} }

@ -63,5 +63,6 @@ namespace llarp
std::optional<net::ipv4addr_t> m_CurrentGateway; std::optional<net::ipv4addr_t> m_CurrentGateway;
AbstractRouter* m_Router = nullptr; AbstractRouter* m_Router = nullptr;
bool m_up{false};
}; };
} // namespace llarp } // namespace llarp

@ -72,18 +72,20 @@ namespace llarp::win32
std::vector<net::ipaddr_t> std::vector<net::ipaddr_t>
VPNPlatform::GetGatewaysNotOnInterface(NetworkInterface& vpn) VPNPlatform::GetGatewaysNotOnInterface(NetworkInterface& vpn)
{ {
std::vector<net::ipaddr_t> gateways; std::set<net::ipaddr_t> gateways;
auto idx = vpn.Info().index; const auto ifaddr = vpn.Info()[0];
using UInt_t = decltype(idx);
for (const auto& iface : Net().AllNetworkInterfaces()) for (const auto& iface : Net().AllNetworkInterfaces())
{ {
if (static_cast<UInt_t>(iface.index) == idx) if (not iface.gateway)
continue; continue;
if (iface.gateway) for (const auto& range : iface.addrs)
gateways.emplace_back(*iface.gateway); {
if (not range.Contains(ifaddr))
gateways.emplace(*iface.gateway);
}
} }
return gateways; return {gateways.begin(), gateways.end()};
} }
void void

Loading…
Cancel
Save