VpnHood.Net.VpnAdapters.WindowsVpnPlugin
The VPN adapter of VpnHood for a Windows VPN plug-in: a packaged app's VPN,
which Windows lists in its VPN settings and runs over a VpnChannel of Windows.Networking.Vpn. It implements
VpnHood.Net.VpnAdapters.Abstractions.
dotnet add package VpnHood.Net.VpnAdapters.WindowsVpnPlugin
How it works
WindowsVpnPluginAdapteris anIVpnAdapter: make it in the plug-in'sConnectwith theVpnChannelWindows gave it, and use it as the Abstractions quick start usesNullVpnAdapter, with the VPN server's address in the options'ServerIp, which the channel's transport needs. Windows wants the channel started beforeConnectreturns, so wait there forStartedTask, which completes once it has.- Windows freezes the plug-in's process between VPN events; VpnHood's host keeps it running with a connection from its app to the package's app service.
- Windows owns the interface: a start gathers the addresses, routes, DNS servers and MTU, and the adapter starts the channel with them. Its MTU is at most 1,400 bytes. There is no NAT and no app filter.
- Pass the plug-in's
Encapsulatecallback toOnEncapsulate: the adapter reads the device's packets from there, and leaves their buffers to Windows. It writes incoming packets into the channel's receive buffers, so the plug-in'sDecapsulatehas nothing to do. - A close leaves the channel up: stop it in the plug-in's
Disconnect, as Windows takes a channel stopped by itself for a dropped connection and dials again.
Requirements
- Windows 11 or later.
- A packaged app with the
networkingVpnProvidercapability and avpnClientbackground task, whoseIVpnPlugInruns the adapter, and a VPN profile of the app for Windows to connect.
License
LGPL-2.1-only. See the VpnHood repository.