lokinet/llarp/vpn/win32.hpp

79 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
#include <winsock2.h>
#include <windows.h>
#include <iphlpapi.h>
#include <llarp/router/abstractrouter.hpp>
#include <llarp/win32/exec.hpp>
#include <llarp.hpp>
2022-07-18 20:04:30 +00:00
#include "platform.hpp"
namespace llarp::win32
{
using namespace llarp::vpn;
class VPNPlatform : public Platform, public IRouteManager
{
llarp::Context* const _ctx;
const int m_Metric{2};
const auto&
Net() const
{
return _ctx->router->Net();
}
void
2022-09-13 16:25:27 +00:00
Route(std::string ip, std::string gw, std::string cmd);
void
2022-09-13 16:25:27 +00:00
DefaultRouteViaInterface(NetworkInterface& vpn, std::string cmd);
2021-08-27 15:02:21 +00:00
OneShotExec
2022-09-13 16:25:27 +00:00
RouteViaInterface(NetworkInterface& vpn, std::string addr, std::string mask, std::string cmd);
public:
VPNPlatform(const VPNPlatform&) = delete;
VPNPlatform(VPNPlatform&&) = delete;
VPNPlatform(llarp::Context* ctx) : Platform{}, _ctx{ctx}
{}
2022-09-13 16:25:27 +00:00
~VPNPlatform() override = default;
void
2022-09-13 16:25:27 +00:00
AddRoute(net::ipaddr_t ip, net::ipaddr_t gateway) override;
2021-08-27 15:02:21 +00:00
void
2022-09-13 16:25:27 +00:00
DelRoute(net::ipaddr_t ip, net::ipaddr_t gateway) override;
2021-08-27 15:02:21 +00:00
void
2022-09-13 16:25:27 +00:00
AddRouteViaInterface(NetworkInterface& vpn, IPRange range) override;
2021-08-27 15:02:21 +00:00
void
2022-09-13 16:25:27 +00:00
DelRouteViaInterface(NetworkInterface& vpn, IPRange range) override;
2021-08-27 15:02:21 +00:00
std::vector<net::ipaddr_t>
2022-09-13 16:25:27 +00:00
GetGatewaysNotOnInterface(NetworkInterface& vpn) override;
2021-08-27 15:02:21 +00:00
void
2022-09-13 16:25:27 +00:00
AddDefaultRouteViaInterface(NetworkInterface& vpn) override;
void
2022-09-13 16:25:27 +00:00
DelDefaultRouteViaInterface(NetworkInterface& vpn) override;
2021-08-27 15:02:21 +00:00
std::shared_ptr<NetworkInterface>
2022-09-13 16:25:27 +00:00
ObtainInterface(InterfaceInfo info, AbstractRouter* router) override;
2021-08-27 15:02:21 +00:00
std::shared_ptr<I_Packet_IO>
create_packet_io(unsigned int ifindex, const std::optional<SockAddr>& dns_upstream_src) override;
2021-08-27 15:02:21 +00:00
IRouteManager&
RouteManager() override
{
return *this;
2021-08-27 15:02:21 +00:00
}
};
} // namespace llarp::win32