forked from OpenVPN/ovpn-dco-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer.cpp
589 lines (462 loc) · 17.4 KB
/
peer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*
* ovpn-dco-win OpenVPN protocol accelerator for Windows
*
* Copyright (C) 2020-2021 OpenVPN Inc <[email protected]>
* Copyright (C) 2023 Rubicon Communications LLC (Netgate)
*
* Author: Lev Stipakov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <ntifs.h>
#include "trace.h"
#include "peer.h"
#include "timer.h"
#include "socket.h"
_Use_decl_annotations_
OvpnPeerContext*
OvpnPeerCtxAlloc()
{
OvpnPeerContext* peer = (OvpnPeerContext*)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(OvpnPeerContext), 'ovpn');
if (peer != NULL) {
RtlZeroMemory(peer, sizeof(OvpnPeerContext));
}
InterlockedIncrement(&peer->RefCounter);
return peer;
}
_Use_decl_annotations_
VOID
OvpnPeerCtxRelease(OvpnPeerContext* peer)
{
if (InterlockedDecrement(&peer->RefCounter) == 0) {
auto peerId = peer->PeerId;
OvpnPeerCtxFree(peer);
LOG_INFO("Peer freed", TraceLoggingValue(peerId, "peer-id"));
}
}
_Use_decl_annotations_
VOID
OvpnPeerCtxFree(OvpnPeerContext* peer)
{
auto irql = ExAcquireSpinLockExclusive(&peer->SpinLock);
OvpnCryptoUninit(&peer->CryptoContext);
OvpnTimerDestroy(&peer->Timer);
ExReleaseSpinLockExclusive(&peer->SpinLock, irql);
ExFreePoolWithTag(peer, 'ovpn');
}
_Use_decl_annotations_
PVOID
OvpnPeerAllocateRoutine(RTL_GENERIC_TABLE* table, CLONG size)
{
UNREFERENCED_PARAMETER(table);
return ExAllocatePool2(POOL_FLAG_NON_PAGED, size, 'ovpn');
}
_Use_decl_annotations_
VOID
OvpnPeerFreeRoutine(RTL_GENERIC_TABLE* table, PVOID buffer)
{
UNREFERENCED_PARAMETER(table);
ExFreePoolWithTag(buffer, 'ovpn');
}
RTL_GENERIC_COMPARE_RESULTS
OvpnPeerCompareByPeerIdRoutine(RTL_GENERIC_TABLE* table, PVOID first, PVOID second)
{
UNREFERENCED_PARAMETER(table);
OvpnPeerContext* peer1 = *(OvpnPeerContext**)first;
OvpnPeerContext* peer2 = *(OvpnPeerContext**)second;
if (peer1->PeerId == peer2->PeerId)
return GenericEqual;
else if (peer1->PeerId < peer2->PeerId)
return GenericLessThan;
else
return GenericGreaterThan;
}
RTL_GENERIC_COMPARE_RESULTS
OvpnPeerCompareByVPN4Routine(RTL_GENERIC_TABLE* table, PVOID first, PVOID second)
{
UNREFERENCED_PARAMETER(table);
OvpnPeerContext* peer1 = *(OvpnPeerContext**)first;
OvpnPeerContext* peer2 = *(OvpnPeerContext**)second;
int n = memcmp(&peer1->VpnAddrs.IPv4, &peer2->VpnAddrs.IPv4, sizeof(IN_ADDR));
if (n == 0)
return GenericEqual;
else if (n < 0)
return GenericLessThan;
else
return GenericGreaterThan;
}
RTL_GENERIC_COMPARE_RESULTS
OvpnPeerCompareByVPN6Routine(RTL_GENERIC_TABLE* table, PVOID first, PVOID second)
{
UNREFERENCED_PARAMETER(table);
OvpnPeerContext* peer1 = *(OvpnPeerContext**)first;
OvpnPeerContext* peer2 = *(OvpnPeerContext**)second;
int n = memcmp(&peer1->VpnAddrs.IPv6, &peer2->VpnAddrs.IPv6, sizeof(IN6_ADDR));
if (n == 0)
return GenericEqual;
else if (n < 0)
return GenericLessThan;
else
return GenericGreaterThan;
}
static
VOID
OvpnPeerZeroStats(POVPN_STATS stats)
{
InterlockedExchange(&stats->LostInControlPackets, 0);
InterlockedExchange(&stats->LostInDataPackets, 0);
InterlockedExchange(&stats->LostOutControlPackets, 0);
InterlockedExchange(&stats->LostOutDataPackets, 0);
InterlockedExchange(&stats->ReceivedControlPackets, 0);
InterlockedExchange(&stats->ReceivedDataPackets, 0);
InterlockedExchange(&stats->SentControlPackets, 0);
InterlockedExchange(&stats->SentDataPackets, 0);
InterlockedExchange64(&stats->TransportBytesReceived, 0);
InterlockedExchange64(&stats->TransportBytesSent, 0);
InterlockedExchange64(&stats->TunBytesReceived, 0);
InterlockedExchange64(&stats->TunBytesSent, 0);
}
_Use_decl_annotations_
NTSTATUS
OvpnPeerNew(POVPN_DEVICE device, WDFREQUEST request)
{
LOG_ENTER();
POVPN_NEW_PEER peer = NULL;
NTSTATUS status;
auto peerCtx = OvpnGetFirstPeer(device);
if (peerCtx != nullptr) {
LOG_WARN("Peer already exists");
status = STATUS_OBJECTID_EXISTS;
goto done;
}
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_NEW_PEER), (PVOID*)&peer, nullptr));
if ((peer->Remote.Addr4.sin_family != AF_INET) && (peer->Remote.Addr4.sin_family != AF_INET6))
{
status = STATUS_INVALID_DEVICE_REQUEST;
LOG_ERROR("Unknown address family in peer->Remote", TraceLoggingValue(peer->Remote.Addr4.sin_family, "AF"));
goto done;
}
POVPN_DRIVER driver = OvpnGetDriverContext(WdfGetDriver());
PWSK_SOCKET socket = NULL;
BOOLEAN proto_tcp = peer->Proto == OVPN_PROTO_TCP;
SIZE_T remoteAddrSize = peer->Remote.Addr4.sin_family == AF_INET ? sizeof(peer->Remote.Addr4) : sizeof(peer->Remote.Addr6);
peerCtx = OvpnPeerCtxAlloc();
if (peerCtx == NULL) {
status = STATUS_NO_MEMORY;
goto done;
}
// assign remote transport address
if (peer->Remote.Addr4.sin_family == AF_INET) {
peerCtx->TransportAddrs.Remote.IPv4 = peer->Remote.Addr4;
}
else {
peerCtx->TransportAddrs.Remote.IPv6 = peer->Remote.Addr6;
}
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnSocketInit(&driver->WskProviderNpi,
&driver->WskRegistration, peer->Local.Addr4.sin_family, proto_tcp,
(PSOCKADDR)&peer->Local,
(PSOCKADDR)&peer->Remote,
remoteAddrSize, device, &socket));
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnAddPeerToTable(device, &device->Peers, peerCtx));
device->Socket.Socket = socket;
device->Socket.Tcp = proto_tcp;
RtlZeroMemory(&device->Socket.TcpState, sizeof(OvpnSocketTcpState));
RtlZeroMemory(&device->Socket.UdpState, sizeof(OvpnSocketUdpState));
OvpnPeerZeroStats(&device->Stats);
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnTimerCreate(device->WdfDevice, peerCtx, &peerCtx->Timer));
if (proto_tcp) {
LOG_IF_NOT_NT_SUCCESS(status = WdfRequestForwardToIoQueue(request, device->PendingNewPeerQueue));
// start async connect
status = OvpnSocketTcpConnect(socket, device, (PSOCKADDR)&peer->Remote);
}
done:
if (peerCtx != nullptr) {
OvpnPeerCtxRelease(peerCtx);
}
LOG_EXIT();
return status;
}
_Use_decl_annotations_
NTSTATUS
OvpnMPPeerNew(POVPN_DEVICE device, WDFREQUEST request)
{
LOG_ENTER();
const struct in6_addr ovpn_in6addr_any = { { 0 } };
NTSTATUS status = STATUS_SUCCESS;
POVPN_MP_NEW_PEER peer;
OvpnPeerContext* peerCtx = nullptr;
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_MP_NEW_PEER), (PVOID*)&peer, nullptr));
// check if we already have a peer with the same peer-id
peerCtx = OvpnFindPeer(device, peer->PeerId);
if (peerCtx != nullptr) {
status = STATUS_OBJECTID_EXISTS;
goto done;
}
// ensure local/remote address is AF_INET or AF_INET6
if ((peer->Local.Addr4.sin_family != AF_INET) && (peer->Local.Addr4.sin_family != AF_INET6))
{
status = STATUS_INVALID_DEVICE_REQUEST;
LOG_ERROR("Unknown address family in peer->Local", TraceLoggingValue(peer->Local.Addr4.sin_family, "AF"));
goto done;
}
if ((peer->Remote.Addr4.sin_family != AF_INET) && (peer->Remote.Addr4.sin_family != AF_INET6))
{
status = STATUS_INVALID_DEVICE_REQUEST;
LOG_ERROR("Unknown address family in peer->Remote", TraceLoggingValue(peer->Remote.Addr4.sin_family, "AF"));
goto done;
}
// allocate peer
peerCtx = OvpnPeerCtxAlloc();
if (peerCtx == NULL) {
status = STATUS_NO_MEMORY;
goto done;
}
// assign local transport address
if (peer->Local.Addr4.sin_family == AF_INET) {
peerCtx->TransportAddrs.Local.IPv4 = peer->Local.Addr4.sin_addr;
}
else {
peerCtx->TransportAddrs.Local.IPv6 = peer->Local.Addr6.sin6_addr;
}
// assign remote transport address
if (peer->Remote.Addr4.sin_family == AF_INET) {
peerCtx->TransportAddrs.Remote.IPv4 = peer->Remote.Addr4;
}
else {
peerCtx->TransportAddrs.Remote.IPv6 = peer->Remote.Addr6;
}
peerCtx->VpnAddrs.IPv4 = peer->VpnAddr4;
peerCtx->VpnAddrs.IPv6 = peer->VpnAddr6;
peerCtx->PeerId = peer->PeerId;
// create peer-specific timer
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnTimerCreate(device->WdfDevice, peerCtx, &peerCtx->Timer));
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnAddPeerToTable(device, &device->Peers, peerCtx));
if (peer->VpnAddr4.S_un.S_addr != INADDR_ANY) {
LOG_IF_NOT_NT_SUCCESS(status = OvpnAddPeerToTable(device, &device->PeersByVpn4, peerCtx));
}
if (RtlCompareMemory(&peer->VpnAddr6, &ovpn_in6addr_any, sizeof(IN6_ADDR)) != sizeof(IN6_ADDR)) {
LOG_IF_NOT_NT_SUCCESS(status = OvpnAddPeerToTable(device, &device->PeersByVpn6, peerCtx));
}
done:
if (peerCtx != nullptr) {
OvpnPeerCtxRelease(peerCtx);
}
LOG_EXIT();
return status;
}
VOID OvpnPeerSetDoWork(OvpnPeerContext *peer, LONG keepaliveInterval, LONG keepaliveTimeout, LONG mss)
{
auto irql = ExAcquireSpinLockExclusive(&peer->SpinLock);
if (mss != -1) {
peer->MSS = (UINT16)mss;
}
if (keepaliveInterval != -1) {
peer->KeepaliveInterval = keepaliveInterval;
// keepalive xmit timer, sends ping packets
OvpnTimerSetXmitInterval(peer->Timer, peer->KeepaliveInterval);
}
if (keepaliveTimeout != -1) {
peer->KeepaliveTimeout = keepaliveTimeout;
// keepalive recv timer, detects keepalive timeout
OvpnTimerSetRecvTimeout(peer->Timer, peer->KeepaliveTimeout);
}
ExReleaseSpinLockExclusive(&peer->SpinLock, irql);
}
_Use_decl_annotations_
NTSTATUS OvpnPeerSet(POVPN_DEVICE device, WDFREQUEST request)
{
LOG_ENTER();
NTSTATUS status = STATUS_SUCCESS;
OvpnPeerContext* peer = OvpnGetFirstPeer(device);
if (peer == nullptr) {
LOG_ERROR("Peer not added");
status = STATUS_INVALID_DEVICE_REQUEST;
goto done;
}
POVPN_SET_PEER set_peer = NULL;
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_SET_PEER), (PVOID*)&set_peer, nullptr));
LOG_INFO("Set peer", TraceLoggingValue(set_peer->KeepaliveInterval, "interval"),
TraceLoggingValue(set_peer->KeepaliveTimeout, "timeout"),
TraceLoggingValue(set_peer->MSS, "MSS"));
OvpnPeerSetDoWork(peer, set_peer->KeepaliveInterval, set_peer->KeepaliveTimeout, set_peer->MSS);
done:
if (peer != nullptr) {
OvpnPeerCtxRelease(peer);
}
LOG_EXIT();
return status;
}
_Use_decl_annotations_
NTSTATUS OvpnMPPeerSet(POVPN_DEVICE device, WDFREQUEST request)
{
LOG_ENTER();
NTSTATUS status = STATUS_SUCCESS;
OvpnPeerContext* peer = nullptr;
POVPN_MP_SET_PEER set_peer = NULL;
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_MP_SET_PEER), (PVOID*)&set_peer, nullptr));
LOG_INFO("MP Set peer", TraceLoggingValue(set_peer->PeerId, "peer-id"),
TraceLoggingValue(set_peer->KeepaliveInterval, "interval"),
TraceLoggingValue(set_peer->KeepaliveTimeout, "timeout"),
TraceLoggingValue(set_peer->MSS, "MSS"));
peer = OvpnFindPeer(device, set_peer->PeerId);
if (peer == nullptr) {
LOG_ERROR("Peer not found", TraceLoggingValue(set_peer->PeerId, "peer-id"));
status = STATUS_INVALID_DEVICE_REQUEST;
goto done;
}
OvpnPeerSetDoWork(peer, set_peer->KeepaliveInterval, set_peer->KeepaliveTimeout, set_peer->MSS);
done:
if (peer != nullptr) {
OvpnPeerCtxRelease(peer);
}
LOG_EXIT();
return status;
}
_Use_decl_annotations_
NTSTATUS
OvpnPeerGetStats(POVPN_DEVICE device, WDFREQUEST request, ULONG_PTR* bytesReturned)
{
NTSTATUS status = STATUS_SUCCESS;
POVPN_STATS stats = NULL;
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveOutputBuffer(request, sizeof(OVPN_STATS), (PVOID*)&stats, NULL));
stats->LostInControlPackets = InterlockedCompareExchangeNoFence(&device->Stats.LostInControlPackets, 0, 0);
stats->LostInDataPackets = InterlockedCompareExchangeNoFence(&device->Stats.LostInDataPackets, 0, 0);
stats->LostOutControlPackets = InterlockedCompareExchangeNoFence(&device->Stats.LostOutControlPackets, 0, 0);
stats->LostOutDataPackets = InterlockedCompareExchangeNoFence(&device->Stats.LostOutDataPackets, 0, 0);
stats->ReceivedControlPackets = InterlockedCompareExchangeNoFence(&device->Stats.ReceivedControlPackets, 0, 0);
stats->ReceivedDataPackets = InterlockedCompareExchangeNoFence(&device->Stats.ReceivedDataPackets, 0, 0);
stats->SentControlPackets = InterlockedCompareExchangeNoFence(&device->Stats.SentControlPackets, 0, 0);
stats->SentDataPackets = InterlockedCompareExchangeNoFence(&device->Stats.SentDataPackets, 0, 0);
stats->TransportBytesReceived = InterlockedCompareExchangeNoFence64(&device->Stats.TransportBytesReceived, 0, 0);
stats->TransportBytesSent = InterlockedCompareExchangeNoFence64(&device->Stats.TransportBytesSent, 0, 0);
stats->TunBytesReceived = InterlockedCompareExchangeNoFence64(&device->Stats.TunBytesReceived, 0, 0);
stats->TunBytesSent = InterlockedCompareExchangeNoFence64(&device->Stats.TunBytesSent, 0, 0);
*bytesReturned = sizeof(OVPN_STATS);
done:
return status;
}
_Use_decl_annotations_
NTSTATUS
OvpnPeerStartVPN(POVPN_DEVICE device)
{
LOG_ENTER();
NTSTATUS status = STATUS_SUCCESS;
auto peer = OvpnGetFirstPeer(device);
if (peer == nullptr) {
LOG_ERROR("Peer not added");
status = STATUS_INVALID_DEVICE_REQUEST;
goto done;
}
OvpnAdapterSetLinkState(OvpnGetAdapterContext(device->Adapter), MediaConnectStateConnected);
done:
if (peer != nullptr) {
OvpnPeerCtxRelease(peer);
}
LOG_EXIT();
return status;
}
static NTSTATUS
OvpnPeerGetAlgHandle(POVPN_DEVICE device, OVPN_CIPHER_ALG cipherAlg, BCRYPT_ALG_HANDLE& algHandle)
{
NTSTATUS status = STATUS_SUCCESS;
switch (cipherAlg) {
case OVPN_CIPHER_ALG_AES_GCM:
algHandle = device->AesAlgHandle;
break;
case OVPN_CIPHER_ALG_CHACHA20_POLY1305:
algHandle = device->ChachaAlgHandle;
if (algHandle == NULL) {
LOG_ERROR("CHACHA20-POLY1305 is not available");
status = STATUS_INVALID_DEVICE_REQUEST;
}
break;
default:
break;
}
return status;
}
_Use_decl_annotations_
NTSTATUS
OvpnPeerNewKey(POVPN_DEVICE device, WDFREQUEST request)
{
LOG_ENTER();
NTSTATUS status = STATUS_SUCCESS;
POVPN_CRYPTO_DATA cryptoData = NULL;
OVPN_CRYPTO_DATA_V2 cryptoDataV2{};
OvpnPeerContext* peer = nullptr;
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_CRYPTO_DATA), (PVOID*)&cryptoData, nullptr));
BCRYPT_ALG_HANDLE algHandle = NULL;
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnPeerGetAlgHandle(device, cryptoData->CipherAlg, algHandle));
peer = OvpnFindPeer(device, cryptoData->PeerId);
if (peer == nullptr) {
status = STATUS_OBJECTID_NOT_FOUND;
goto done;
}
RtlCopyMemory(&cryptoDataV2.V1, cryptoData, sizeof(OVPN_CRYPTO_DATA));
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnCryptoNewKey(&peer->CryptoContext, &cryptoDataV2, algHandle));
done:
if (peer != nullptr) {
OvpnPeerCtxRelease(peer);
}
LOG_EXIT();
return status;
}
_Use_decl_annotations_
NTSTATUS
OvpnPeerNewKeyV2(POVPN_DEVICE device, WDFREQUEST request)
{
LOG_ENTER();
NTSTATUS status = STATUS_SUCCESS;
OvpnPeerContext* peer = nullptr;
POVPN_CRYPTO_DATA_V2 cryptoDataV2 = NULL;
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_CRYPTO_DATA_V2), (PVOID*)&cryptoDataV2, nullptr));
BCRYPT_ALG_HANDLE algHandle = NULL;
GOTO_IF_NOT_NT_SUCCESS(done, status, OvpnPeerGetAlgHandle(device, cryptoDataV2->V1.CipherAlg, algHandle));
peer = OvpnFindPeer(device, cryptoDataV2->V1.PeerId);
if (peer == nullptr) {
status = STATUS_OBJECTID_NOT_FOUND;
goto done;
}
KIRQL irql = ExAcquireSpinLockExclusive(&peer->SpinLock);
LOG_IF_NOT_NT_SUCCESS(status = OvpnCryptoNewKey(&peer->CryptoContext, cryptoDataV2, algHandle));
ExReleaseSpinLockExclusive(&peer->SpinLock, irql);
done:
if (peer != nullptr) {
OvpnPeerCtxRelease(peer);
}
LOG_EXIT();
return status;
}
_Use_decl_annotations_
NTSTATUS
OvpnPeerSwapKeys(POVPN_DEVICE device)
{
LOG_ENTER();
NTSTATUS status = STATUS_SUCCESS;
OvpnPeerContext* peer = OvpnGetFirstPeer(device);
if (peer == nullptr) {
LOG_ERROR("Peer not found");
status = STATUS_INVALID_DEVICE_REQUEST;
goto done;
}
KIRQL irql = ExAcquireSpinLockExclusive(&peer->SpinLock);
OvpnCryptoSwapKeys(&peer->CryptoContext);
ExReleaseSpinLockExclusive(&peer->SpinLock, irql);
done:
if (peer != nullptr) {
OvpnPeerCtxRelease(peer);
}
LOG_EXIT();
return status;
}