2021-08-30 17:55:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-09-01 18:10:08 +00:00
|
|
|
#include <llarp/router/abstractrouter.hpp>
|
2021-08-30 17:55:33 +00:00
|
|
|
#include <llarp/ev/vpn.hpp>
|
|
|
|
#include "context_wrapper.h"
|
|
|
|
|
2021-09-01 18:31:45 +00:00
|
|
|
namespace llarp::apple
|
|
|
|
{
|
|
|
|
class RouteManager final : public llarp::vpn::IRouteManager
|
|
|
|
{
|
|
|
|
public:
|
2021-09-01 18:10:08 +00:00
|
|
|
RouteManager(llarp::Context& ctx, llarp_route_callbacks rcs, void* callback_context)
|
2021-09-01 18:31:45 +00:00
|
|
|
: context{ctx}, route_callbacks{std::move(rcs)}, callback_context{callback_context}
|
|
|
|
{}
|
2021-08-30 17:55:33 +00:00
|
|
|
|
|
|
|
/// 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
|
2021-09-01 18:31:45 +00:00
|
|
|
AddRoute(IPVariant_t ip, IPVariant_t gateway) override
|
|
|
|
{}
|
2021-08-30 17:55:33 +00:00
|
|
|
|
|
|
|
void
|
2021-09-01 18:31:45 +00:00
|
|
|
DelRoute(IPVariant_t ip, IPVariant_t gateway) override
|
|
|
|
{}
|
2021-08-30 17:55:33 +00:00
|
|
|
|
|
|
|
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>
|
2021-09-01 18:31:45 +00:00
|
|
|
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;
|
2021-08-30 17:55:33 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 18:31:45 +00:00
|
|
|
private:
|
2021-09-01 18:10:08 +00:00
|
|
|
llarp::Context& context;
|
|
|
|
bool trampoline_active = false;
|
|
|
|
std::vector<llarp::SockAddr> saved_upstream_dns;
|
2021-09-01 18:31:45 +00:00
|
|
|
void
|
|
|
|
check_trampoline(bool enable);
|
2021-09-01 18:10:08 +00:00
|
|
|
|
2021-08-30 17:55:33 +00:00
|
|
|
void* callback_context = nullptr;
|
|
|
|
llarp_route_callbacks route_callbacks;
|
2021-09-01 18:31:45 +00:00
|
|
|
};
|
2021-08-30 17:55:33 +00:00
|
|
|
|
2021-09-01 18:31:45 +00:00
|
|
|
} // namespace llarp::apple
|