Repository navigation
Conversation
The agent kept a single tunnel, so a tun setup request from a second client destroyed the tunnel of the first one. Move the per-tunnel state (tun setup, client process, confirm and destroy events, ring buffer, bypass routes, VPN interface index) into a TunSession class and keep sessions in a map keyed by the PID of the named pipe client. Requests only affect the session of the calling client, and a session is torn down and forgotten when its client exits or signals the destroy event. On service stop all sessions, including their bypass routes, are closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
The agent read HKLM\SOFTWARE\OpenVPN\omi_exe_path on startup and exited when the value was missing, although only the /start request uses it. Clients which start their own process, such as omicliagent launched by a GUI, could therefore not use the agent without that registry value. Read the path in start_openvpn_process() instead, so a missing value only fails the /start request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
The OMI client read the profile as is, so directives that refer to external files, such as "ca ca.crt" or "tls-auth ta.key 1", failed with errors like "CA not defined". OpenVPN 2.x profiles commonly keep keys and certificates in separate files. Read the profile through ProfileMerge with FOLLOW_FULL, like the test client does, which inlines ca, cert, key, tls-auth, tls-crypt, auth-user-pass, crl-verify, pkcs12 and the other file references. Relative paths are resolved against the directory of the profile. Reading the profile from stdin is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
DCO is enabled by default, and the client throws "config/options are not compatible with dco" for profiles with compress, comp-lzo or http-proxy, which are common in OpenVPN 2.x profiles. Like openvpn2, disable DCO and use the TAP or Wintun driver when the profile is not DCO compatible or asks for another windows-driver, and log why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
On a failed agent transaction the details were written to a stream that is only logged on success, so clients only reported "communication error" or "request error". Include the transaction status, or the error text returned by the agent, in the exception. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
Running "ovpnagent run" while the service is up makes both serve \.\pipe\ovpnagent. Windows reports the process that created the pipe first as its server, so once that process is gone clients fail to validate the server and every request fails. Exit with an error when the pipe is already served. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
With several tunnels up at the same time the agent only considered the tunnel of the requesting client: - The server bypass route excluded only the client's own VPN interface, so with another full tunnel up it went through that tunnel instead of the physical network. - The WFP filters of block-outside-dns or block-local permitted only the client's own interface and blocked DNS and other traffic of the other tunnels. BestGateway now takes a set of excluded interfaces, and TunWin::Setup and the WFP context keep the interfaces of the other tunnels: the bypass route skips them and extra permit filters let their traffic through. The agent passes them when a tunnel is set up and updates the other sessions when a tunnel comes up or goes down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
Two tunnels with redirect-gateway would both install the 0/1 and 128/1 routes. The pushed options are only known when the tunnel is set up, so refuse a second such tunnel in /tun-setup with an error that names the process whose tunnel already redirects the gateway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
The DCO fallback also disabled DCO for profiles with a windows-driver other than ovpn-dco. With "windows-driver wintun" and no Wintun adapter installed, which is common as openvpn 2.7 dropped Wintun, the connection then failed with "cannot acquire TAP handle" although free DCO adapters were available. The core used DCO for such profiles before. Only fall back from DCO when the profile is not DCO compatible; windows-driver just picks the driver used then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
block-ipv6 adds the same blackhole routes (2000::/4, 3000::/4, fc00::/7 on the loopback interface) for every tunnel. With two such tunnels the second add failed with "already exists", and the first tunnel to go down removed the routes for both, so IPv6 traffic of the other one was no longer blocked. TunWin::Setup can now leave these routes to its owner. The agent adds them for the first session that needs them and removes them with the last one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
When two tunnels push the same route, e.g. two gateways of one organization, destinations in it may go through either tunnel. Compare the routes of a new tunnel with those of the other sessions and add "ROUTE CONFLICT: <route> overlaps <route> of the tunnel of process <pid>" for identical routes to the reply, which the client logs. Nested routes are only logged as "ROUTE OVERLAP", as the more specific route always wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Анисимов Сергей Викторович <s.anisimov@itfbgroup.ru>
sa363
force-pushed
the
win-agent-multi-session
branch
from
October 16, 2026 11:08
654711c to
82daa47
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This series lets several clients use
ovpnagentat the same time on Windows, so that several VPN connections can be up at once, each run by its ownomicliagentprocess. Today the agent keeps a single tunnel, and a/tun-setupfrom a second client destroys the tunnel of the first one.I'm sending this as a PR for initial review and discussion, as described in CONTRIBUTING.md; the final patches will go to openvpn-devel.
Agent (
openvpn/ovpnagent/win)TunSession, kept in a map keyed by the PID of the named pipe client. Requests only touch the session of the calling client; a session is torn down when its client exits or signals the destroy event.omi_exe_pathis optional. It is only read for/start, so the agent no longer exits on startup when the registry value is missing.ovpnagent runstarted while the service is up, both serve\\.\pipe\ovpnagent. Windows reports the process that created the pipe first as its server, so once that one is gone clients fail to validate the server and every request fails with "communication error".BestGatewaytakes a set of excluded interfaces, and server bypass routes skip the VPN interfaces of all tunnels.block-outside-dns/block-localof one tunnel get permit filters for the interfaces of the others, updated as tunnels come and go./tun-setup, so a second such tunnel is refused there with an error naming the process that already redirects it.block-ipv6routes. The blackhole routes are the same for every tunnel:TunWin::Setupcan leave them to its owner, and the agent adds them for the first session that needs them and removes them with the last one. Before, the first tunnel to go down removed them for all.ROUTE CONFLICT: ...in the reply; nested ones are logged asROUTE OVERLAP.Client side
cmdagenterrors. The transaction status or the agent's error text goes into the exception; before it was written to a stream that is only logged on success, so clients only saw "communication error" / "request error".omiprofile files. Profiles are read throughProfileMerge(FOLLOW_FULL, as in the test client), soca ca.crt,tls-auth ta.key 1,auth-user-pass fileand the other file references of OpenVPN 2.x profiles work.omiDCO fallback. DCO is disabled, with a log line saying why, for profiles that are not DCO compatible (compress,comp-lzo,http-proxy), instead of failing with "not compatible with dco".windows-driveronly selects the driver used then.Testing
On Windows 11 x64 with ovpn-dco-win and TAP-Windows6, MSVC 2022, preset
win-x64-release:block-ipv6, one of them withblock-outside-dns;route-nopullthat drops a pushedredirect-gateway.agent.logand withroute print/netsh: bypass routes go through the physical gateway; the WFP filters of theblock-outside-dnstunnel permit the two other VPN interfaces, so the split DNS of another tunnel keeps working; theblock-ipv6routes stay while one of the two tunnels that need them is up; the identical route pushed by two of the servers is reported./and\\,tls-authwith key direction,auth-user-passfile, a missing file.comp-lzoandhttp-proxy;windows-driver wintunwithout Wintun adapters now uses DCO.BestGatewaytests, and the rest ofcoreUnitTestspasses except tests that need administrator rights (IpHelperTest.TestAddRoute4) or the OpenSSL legacy provider module (Ssl.EnablelegacyProvider,Proto.IvCiphersLegacy), which are missing in this environment and unrelated to the changes.The
Buildworkflow passes in the fork for MSVC x64, x86 and arm64 and MinGW x64 and x86, including the unit tests on MSVC x64 and x86 (https://github.com/sa363/openvpn3/actions/runs/38891819005).Not tested: Wintun.
Not part of this PR
A Qt tray GUI that runs several connections through these pieces, and an MSI installer for it, live in the
agent-multi-sessionbranch of the fork (gui/,doc/windows_multi_connection.md). I left them out, as they are not part of the core library; happy to discuss if there is interest.🤖 Generated with Claude Code