mirror of https://github.com/oxen-io/lokinet
Add RouteManager; make exit on/off work
parent
c74dcba463
commit
e84390748d
@ -0,0 +1,61 @@
|
||||
#include "route_manager.hpp"
|
||||
|
||||
namespace llarp::apple {
|
||||
|
||||
void RouteManager::AddDefaultRouteViaInterface(std::string)
|
||||
{
|
||||
LogWarn("AddDefaultRouteViaInterface with cbctx=", (bool) callback_context, ", adr=", (bool) route_callbacks.add_default_route);
|
||||
if (callback_context and route_callbacks.add_default_route)
|
||||
route_callbacks.add_default_route(callback_context);
|
||||
}
|
||||
|
||||
void RouteManager::DelDefaultRouteViaInterface(std::string)
|
||||
{
|
||||
LogWarn("DelDefaultRouteViaInterface with cbctx=", (bool) callback_context, ", ddr=", (bool) route_callbacks.del_default_route);
|
||||
if (callback_context and route_callbacks.del_default_route)
|
||||
route_callbacks.del_default_route(callback_context);
|
||||
}
|
||||
|
||||
void
|
||||
RouteManager::AddRouteViaInterface(vpn::NetworkInterface&, IPRange range)
|
||||
{
|
||||
LogWarn("AddRoute with cbctx=", (bool) callback_context, ", a4r=", (bool) route_callbacks.add_ipv4_route,
|
||||
"a6r", (bool) route_callbacks.add_ipv6_route);
|
||||
|
||||
if (callback_context)
|
||||
{
|
||||
if (range.IsV4()) {
|
||||
if (route_callbacks.add_ipv4_route)
|
||||
route_callbacks.add_ipv4_route(
|
||||
range.BaseAddressString().c_str(),
|
||||
net::TruncateV6(range.netmask_bits).ToString().c_str(),
|
||||
callback_context);
|
||||
} else {
|
||||
if (route_callbacks.add_ipv6_route)
|
||||
route_callbacks.add_ipv6_route(range.BaseAddressString().c_str(), range.HostmaskBits(), callback_context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RouteManager::DelRouteViaInterface(vpn::NetworkInterface&, IPRange range)
|
||||
{
|
||||
LogWarn("DelRoute with cbctx=", (bool) callback_context, ", a4r=", (bool) route_callbacks.del_ipv4_route,
|
||||
"a6r", (bool) route_callbacks.del_ipv6_route);
|
||||
|
||||
if (callback_context)
|
||||
{
|
||||
if (range.IsV4()) {
|
||||
if (route_callbacks.del_ipv4_route)
|
||||
route_callbacks.del_ipv4_route(
|
||||
range.BaseAddressString().c_str(),
|
||||
net::TruncateV6(range.netmask_bits).ToString().c_str(),
|
||||
callback_context);
|
||||
} else {
|
||||
if (route_callbacks.del_ipv6_route)
|
||||
route_callbacks.del_ipv6_route(range.BaseAddressString().c_str(), range.HostmaskBits(), callback_context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <llarp/ev/vpn.hpp>
|
||||
#include "context_wrapper.h"
|
||||
|
||||
namespace llarp::apple {
|
||||
|
||||
class RouteManager final : public llarp::vpn::IRouteManager {
|
||||
public:
|
||||
RouteManager(llarp_route_callbacks rcs, void* callback_context)
|
||||
: route_callbacks{std::move(rcs)}, callback_context{callback_context} {}
|
||||
|
||||
/// These are called for poking route holes, but we don't have to do that at all on macos
|
||||
/// because the appex isn't subject to its own rules.
|
||||
void
|
||||
AddRoute(IPVariant_t ip, IPVariant_t gateway) override {}
|
||||
|
||||
void
|
||||
DelRoute(IPVariant_t ip, IPVariant_t gateway) override {}
|
||||
|
||||
void
|
||||
AddDefaultRouteViaInterface(std::string ifname) override;
|
||||
|
||||
void
|
||||
DelDefaultRouteViaInterface(std::string ifname) override;
|
||||
|
||||
void
|
||||
AddRouteViaInterface(vpn::NetworkInterface& vpn, IPRange range) override;
|
||||
|
||||
void
|
||||
DelRouteViaInterface(vpn::NetworkInterface& vpn, IPRange range) override;
|
||||
|
||||
virtual std::vector<IPVariant_t>
|
||||
GetGatewaysNotOnInterface(std::string ifname) override {
|
||||
// We can't get this on mac from our sandbox, but we don't actually need it because we
|
||||
// ignore the gateway for AddRoute/DelRoute anyway, so just return a zero IP.
|
||||
std::vector<IPVariant_t> ret;
|
||||
ret.push_back(huint32_t{0});
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* callback_context = nullptr;
|
||||
llarp_route_callbacks route_callbacks;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue