mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
limit route poker
This commit is contained in:
parent
61f66ac1ec
commit
26c1336517
|
@ -97,6 +97,12 @@ namespace llarp
|
|||
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
|
||||
constexpr huint128_t
|
||||
HighestAddr() const
|
||||
|
|
|
@ -201,6 +201,11 @@ namespace llarp::net
|
|||
saddr.asIPv6(),
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace llarp
|
|||
DisableRoute(ip, gw);
|
||||
// update and add new mapping
|
||||
gw = *m_CurrentGateway;
|
||||
log::info(logcat, "add route {} via {}", ip, gw);
|
||||
EnableRoute(ip, gw);
|
||||
}
|
||||
else
|
||||
|
@ -57,7 +58,7 @@ namespace llarp
|
|||
const auto itr = m_PokedRoutes.find(ip);
|
||||
if (itr == m_PokedRoutes.end())
|
||||
return;
|
||||
|
||||
log::info(logcat, "del route {} via {}", itr->first, itr->second);
|
||||
DisableRoute(itr->first, itr->second);
|
||||
m_PokedRoutes.erase(itr);
|
||||
}
|
||||
|
@ -69,7 +70,10 @@ namespace llarp
|
|||
if (m_Router->IsServiceNode())
|
||||
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
|
||||
|
@ -186,6 +190,8 @@ namespace llarp
|
|||
m_CurrentGateway = next_gw;
|
||||
}
|
||||
}
|
||||
else if (m_Router->HasClientExit())
|
||||
Up();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -201,7 +207,7 @@ namespace llarp
|
|||
void
|
||||
RoutePoker::Up()
|
||||
{
|
||||
if (IsEnabled())
|
||||
if (IsEnabled() and m_CurrentGateway and not m_up)
|
||||
{
|
||||
vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager();
|
||||
|
||||
|
@ -216,6 +222,9 @@ namespace llarp
|
|||
const auto ep = m_Router->hiddenServiceContext().GetDefault();
|
||||
if (auto* vpn = ep->GetVPNInterface())
|
||||
route.AddDefaultRouteViaInterface(*vpn);
|
||||
|
||||
m_up = true;
|
||||
log::info(logcat, "route poker up");
|
||||
}
|
||||
SetDNSMode(true);
|
||||
}
|
||||
|
@ -229,7 +238,7 @@ namespace llarp
|
|||
|
||||
// remove default route
|
||||
|
||||
if (IsEnabled())
|
||||
if (IsEnabled() and m_up)
|
||||
{
|
||||
vpn::IRouteManager& route = m_Router->GetVPNPlatform()->RouteManager();
|
||||
const auto ep = m_Router->hiddenServiceContext().GetDefault();
|
||||
|
@ -238,6 +247,8 @@ namespace llarp
|
|||
|
||||
// delete route blackhole
|
||||
route.DelBlackhole();
|
||||
m_up = false;
|
||||
log::info(logcat, "route poker down");
|
||||
}
|
||||
SetDNSMode(false);
|
||||
}
|
||||
|
|
|
@ -63,5 +63,6 @@ namespace llarp
|
|||
std::optional<net::ipv4addr_t> m_CurrentGateway;
|
||||
|
||||
AbstractRouter* m_Router = nullptr;
|
||||
bool m_up{false};
|
||||
};
|
||||
} // namespace llarp
|
||||
|
|
|
@ -72,18 +72,20 @@ namespace llarp::win32
|
|||
std::vector<net::ipaddr_t>
|
||||
VPNPlatform::GetGatewaysNotOnInterface(NetworkInterface& vpn)
|
||||
{
|
||||
std::vector<net::ipaddr_t> gateways;
|
||||
std::set<net::ipaddr_t> gateways;
|
||||
|
||||
auto idx = vpn.Info().index;
|
||||
using UInt_t = decltype(idx);
|
||||
const auto ifaddr = vpn.Info()[0];
|
||||
for (const auto& iface : Net().AllNetworkInterfaces())
|
||||
{
|
||||
if (static_cast<UInt_t>(iface.index) == idx)
|
||||
if (not iface.gateway)
|
||||
continue;
|
||||
if (iface.gateway)
|
||||
gateways.emplace_back(*iface.gateway);
|
||||
for (const auto& range : iface.addrs)
|
||||
{
|
||||
if (not range.Contains(ifaddr))
|
||||
gateways.emplace(*iface.gateway);
|
||||
}
|
||||
}
|
||||
return gateways;
|
||||
return {gateways.begin(), gateways.end()};
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue