2021-01-11 23:13:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-13 20:24:25 +00:00
|
|
|
#include <winsock2.h>
|
2021-01-11 23:13:22 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <iphlpapi.h>
|
2021-12-07 16:17:20 +00:00
|
|
|
#include <llarp/router/abstractrouter.hpp>
|
2022-07-28 16:07:38 +00:00
|
|
|
#include <llarp/win32/exec.hpp>
|
|
|
|
#include <llarp.hpp>
|
2022-07-18 20:04:30 +00:00
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
#include "platform.hpp"
|
2021-01-11 23:13:22 +00:00
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
namespace llarp::win32
|
2021-01-11 23:13:22 +00:00
|
|
|
{
|
2022-07-28 16:07:38 +00:00
|
|
|
using namespace llarp::vpn;
|
|
|
|
class VPNPlatform : public Platform, public IRouteManager
|
2022-04-18 20:23:21 +00:00
|
|
|
{
|
2022-07-28 16:07:38 +00:00
|
|
|
llarp::Context* const _ctx;
|
|
|
|
const int m_Metric{2};
|
2022-04-18 20:23:21 +00:00
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
const auto&
|
|
|
|
Net() const
|
2021-01-11 23:13:22 +00:00
|
|
|
{
|
2022-07-28 16:07:38 +00:00
|
|
|
return _ctx->router->Net();
|
2021-01-11 23:13:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
void
|
2022-09-13 16:25:27 +00:00
|
|
|
Route(std::string ip, std::string gw, std::string cmd);
|
2021-01-11 23:13:22 +00:00
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
void
|
2022-09-13 16:25:27 +00:00
|
|
|
DefaultRouteViaInterface(NetworkInterface& vpn, std::string cmd);
|
2021-08-27 15:02:21 +00:00
|
|
|
|
2022-09-13 23:28:21 +00:00
|
|
|
void
|
2022-09-13 16:25:27 +00:00
|
|
|
RouteViaInterface(NetworkInterface& vpn, std::string addr, std::string mask, std::string cmd);
|
2021-01-11 23:13:22 +00:00
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
public:
|
|
|
|
VPNPlatform(const VPNPlatform&) = delete;
|
|
|
|
VPNPlatform(VPNPlatform&&) = delete;
|
2021-01-11 23:13:22 +00:00
|
|
|
|
2022-09-12 12:40:33 +00:00
|
|
|
VPNPlatform(llarp::Context* ctx) : Platform{}, _ctx{ctx}
|
2022-07-28 16:07:38 +00:00
|
|
|
{}
|
2021-02-02 14:35:40 +00:00
|
|
|
|
2022-09-13 16:25:27 +00:00
|
|
|
~VPNPlatform() override = default;
|
2021-01-11 23:13:22 +00:00
|
|
|
|
|
|
|
void
|
2022-09-13 16:25:27 +00:00
|
|
|
AddRoute(net::ipaddr_t ip, net::ipaddr_t gateway) override;
|
2021-01-11 23:13:22 +00:00
|
|
|
|
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
|
|
|
|
2022-07-28 16:07:38 +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;
|
2021-08-27 15:40:40 +00:00
|
|
|
|
|
|
|
void
|
2022-09-13 16:25:27 +00:00
|
|
|
DelDefaultRouteViaInterface(NetworkInterface& vpn) override;
|
2021-08-27 15:02:21 +00:00
|
|
|
|
2022-07-28 16:07:38 +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
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
std::shared_ptr<I_Packet_IO>
|
2022-09-13 23:28:21 +00:00
|
|
|
create_packet_io(
|
|
|
|
unsigned int ifindex, const std::optional<SockAddr>& dns_upstream_src) override;
|
2021-12-07 16:17:20 +00:00
|
|
|
|
2021-08-27 15:02:21 +00:00
|
|
|
IRouteManager&
|
|
|
|
RouteManager() override
|
|
|
|
{
|
2022-07-28 16:07:38 +00:00
|
|
|
return *this;
|
2021-08-27 15:02:21 +00:00
|
|
|
}
|
2021-01-11 23:13:22 +00:00
|
|
|
};
|
|
|
|
|
2022-07-28 16:07:38 +00:00
|
|
|
} // namespace llarp::win32
|