mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
9ddf7413af
- windivert was being set up *before* DNS is set up, so the DNS port was nullopt and thus we couldn't properly identify upstream DNS traffic. - close() doesn't close a socket on Windows, so the socket-bind-close approach to get a free UDP port wasn't actually closing, and thus unbound upstream constrained to the given port were completely failing. - The unbound thread was accessing the same shared_ptr instance as the outer code, which isn't thread-safe; changed it to copy a weak_ptr into the lambda instead. - Exclude upstream DNS traffic in the filter rather than capturing and reinjecting it.
79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <winsock2.h>
|
|
#include <windows.h>
|
|
#include <iphlpapi.h>
|
|
#include <llarp/router/abstractrouter.hpp>
|
|
#include <llarp/win32/exec.hpp>
|
|
#include <llarp.hpp>
|
|
|
|
#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
|
|
Route(std::string ip, std::string gw, std::string cmd);
|
|
|
|
void
|
|
DefaultRouteViaInterface(NetworkInterface& vpn, std::string cmd);
|
|
|
|
OneShotExec
|
|
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}
|
|
{}
|
|
|
|
~VPNPlatform() override = default;
|
|
|
|
void
|
|
AddRoute(net::ipaddr_t ip, net::ipaddr_t gateway) override;
|
|
|
|
void
|
|
DelRoute(net::ipaddr_t ip, net::ipaddr_t gateway) override;
|
|
|
|
void
|
|
AddRouteViaInterface(NetworkInterface& vpn, IPRange range) override;
|
|
|
|
void
|
|
DelRouteViaInterface(NetworkInterface& vpn, IPRange range) override;
|
|
|
|
std::vector<net::ipaddr_t>
|
|
GetGatewaysNotOnInterface(NetworkInterface& vpn) override;
|
|
|
|
void
|
|
AddDefaultRouteViaInterface(NetworkInterface& vpn) override;
|
|
|
|
void
|
|
DelDefaultRouteViaInterface(NetworkInterface& vpn) override;
|
|
|
|
std::shared_ptr<NetworkInterface>
|
|
ObtainInterface(InterfaceInfo info, AbstractRouter* router) override;
|
|
|
|
std::shared_ptr<I_Packet_IO>
|
|
create_packet_io(unsigned int ifindex, const std::optional<SockAddr>& dns_upstream_src) override;
|
|
|
|
IRouteManager&
|
|
RouteManager() override
|
|
{
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
} // namespace llarp::win32
|