Skip to content

Commit

Permalink
multipeer: support for dual-stack
Browse files Browse the repository at this point in the history
Enable bind for both IPv4 and IPv6 clients.

Github: #95

Signed-off-by: Lev Stipakov <[email protected]>
  • Loading branch information
lstipakov committed Nov 14, 2024
1 parent cf7a29e commit acf1f28
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ OvpnMPStartVPN(POVPN_DEVICE device, WDFREQUEST request, ULONG_PTR* bytesReturned
status = OvpnSocketInit(&driver->WskProviderNpi, &driver->WskRegistration,
addrIn->ListenAddress.Addr4.sin_family, false,
(PSOCKADDR)&addrIn->ListenAddress, NULL,
0, device, &socket);
0, device, &socket, addrIn->IPv6Only > 0 ? TRUE : FALSE);
if (!NT_SUCCESS(status)) {
LOG_ERROR("Socket create failed", TraceLoggingValue((UINT32)status),
TraceLoggingHexUInt32(*(UINT32*)(&addrIn->ListenAddress.Addr4.sin_addr), "addr"));
Expand Down
2 changes: 1 addition & 1 deletion peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ OvpnPeerNew(POVPN_DEVICE device, WDFREQUEST request)
&driver->WskRegistration, peer->Local.Addr4.sin_family, proto_tcp,
(PSOCKADDR)&peer->Local,
(PSOCKADDR)&peer->Remote,
remoteAddrSize, device, &socket));
remoteAddrSize, device, &socket, TRUE));

GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnAddPeerToTable(device, &device->Peers, peerCtx));

Expand Down
15 changes: 12 additions & 3 deletions socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ const WSK_CLIENT_CONNECTION_DISPATCH OvpnSocketTcpDispatch = { OvpnSocketTcpRece
_Use_decl_annotations_
NTSTATUS
OvpnSocketInit(WSK_PROVIDER_NPI* wskProviderNpi, WSK_REGISTRATION* wskRegistration, ADDRESS_FAMILY addressFamily, BOOLEAN tcp, PSOCKADDR localAddr,
PSOCKADDR remoteAddr, SIZE_T remoteAddrSize, PVOID deviceContext, PWSK_SOCKET* socket)
PSOCKADDR remoteAddr, SIZE_T remoteAddrSize, PVOID deviceContext, PWSK_SOCKET* socket, BOOLEAN ipv6only)
{
NTSTATUS status;
WSK_EVENT_CALLBACK_CONTROL eventCallbackControl = {};
Expand Down Expand Up @@ -563,6 +563,17 @@ OvpnSocketInit(WSK_PROVIDER_NPI* wskProviderNpi, WSK_REGISTRATION* wskRegistrati
sizeof(tcpNoDelay), &tcpNoDelay, 0, NULL, &outputSizeReturned, NULL));
}
else {
PWSK_PROVIDER_BASIC_DISPATCH basicDispatch = (PWSK_PROVIDER_BASIC_DISPATCH)(*socket)->Dispatch;

if (!ipv6only) {
LOG_INFO("Enable dual-stack");
// enable dual-stack
LOG_IF_NOT_NT_SUCCESS(status = OvpnSocketSyncOp("IPV6_V6ONLY", [basicDispatch, socket](PIRP irp) {
ULONG ipv6Only = 0;
return basicDispatch->WskControlSocket(*socket, WskSetOption, IPV6_V6ONLY, IPPROTO_IPV6, sizeof(ipv6Only), &ipv6Only, 0, NULL, NULL, irp);
}, [](PIRP) {}));
}

// bind
PWSK_PROVIDER_DATAGRAM_DISPATCH datagramDispatch = (PWSK_PROVIDER_DATAGRAM_DISPATCH)(*socket)->Dispatch;

Expand All @@ -577,8 +588,6 @@ OvpnSocketInit(WSK_PROVIDER_NPI* wskProviderNpi, WSK_REGISTRATION* wskRegistrati

if (remoteAddr != NULL) {
// set remote
PWSK_PROVIDER_BASIC_DISPATCH basicDispatch = (PWSK_PROVIDER_BASIC_DISPATCH)(*socket)->Dispatch;

GOTO_IF_NOT_NT_SUCCESS(error, status, OvpnSocketSyncOp("SetRemote", [basicDispatch, socket, remoteAddrSize, remoteAddr](PIRP irp) {
return basicDispatch->WskControlSocket(*socket, WskIoctl, SIO_WSK_SET_REMOTE_ADDRESS, 0, remoteAddrSize, remoteAddr, 0, NULL, NULL, irp);
}, [](PIRP) {}));
Expand Down
2 changes: 1 addition & 1 deletion socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ _IRQL_requires_(PASSIVE_LEVEL)
NTSTATUS
OvpnSocketInit(_In_ WSK_PROVIDER_NPI* wskProviderNpi, _In_ WSK_REGISTRATION* wskRegistration, ADDRESS_FAMILY addrFamily,
BOOLEAN tcp, _In_ PSOCKADDR localAddr, _In_opt_ PSOCKADDR remoteAddr, SIZE_T remoteAddrSize,
_In_ PVOID deviceContext, _Out_ PWSK_SOCKET* socket);
_In_ PVOID deviceContext, _Out_ PWSK_SOCKET* socket, BOOLEAN ipv6only);

_Must_inspect_result_
_IRQL_requires_(PASSIVE_LEVEL)
Expand Down
1 change: 1 addition & 0 deletions uapi/ovpn-dco.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ typedef struct _OVPN_MP_START_VPN {
SOCKADDR_IN Addr4;
SOCKADDR_IN6 Addr6;
} ListenAddress;
int IPv6Only;
} OVPN_MP_START_VPN, * POVPN_MP_START_VPN;

typedef enum {
Expand Down

0 comments on commit acf1f28

Please sign in to comment.