-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Existing mechanism of userspace notifications (by erroring out pending read requests) is not flexible enough to be used by multipeer. This adds a new OVPN_IOCTL_NOTIFY_EVENT ioctl. When request arrives, we check if there are pending notifications. If yes, then we complete request, writing notification command, peer-id and peer delete reason (if applicable). If there are no pending notifications, request is queued. When notification occurs (such as peer keepalive timeout), we check if there is a pending requests in the queue (see above). If yes, we complete request with notification details. If there are no pending requests, we add notification event to a queue. Events queue is implemented with a C++ class and a kernel linked lists. The queue is a member of device context. Since there is no C++ runtime and constructors are not called for context members, we have to use a separate method for initialization. GitHub: #87 Signed-off-by: Lev Stipakov <[email protected]>
- Loading branch information
Showing
7 changed files
with
254 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* ovpn-dco-win OpenVPN protocol accelerator for Windows | ||
* | ||
* Copyright (C) 2024- OpenVPN Inc <[email protected]> | ||
* | ||
* 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 "notifyqueue.h" | ||
|
||
#include "trace.h" | ||
|
||
VOID | ||
NotifyQueue::Init() | ||
{ | ||
LOG_ENTER(); | ||
|
||
InitializeListHead(&Head); | ||
KeInitializeSpinLock(&Lock); | ||
|
||
LOG_EXIT(); | ||
} | ||
|
||
NTSTATUS | ||
NotifyQueue::AddEvent(OVPN_NOTIFY_CMD cmd, int peerId, OVPN_DEL_PEER_REASON delPeerReason) | ||
{ | ||
NotifyEvent* event = (NotifyEvent*)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(NotifyEvent), 'ovpn'); | ||
if (!event) { | ||
return STATUS_MEMORY_NOT_ALLOCATED; | ||
} | ||
|
||
RtlZeroMemory(event, sizeof(NotifyEvent)); | ||
|
||
event->Cmd = cmd; | ||
event->PeerId = peerId; | ||
event->DelPeerReason = delPeerReason; | ||
|
||
ExInterlockedInsertTailList(&Head, &event->ListEntry, &Lock); | ||
|
||
return STATUS_SUCCESS; | ||
} | ||
|
||
NotifyEvent* | ||
NotifyQueue::GetEvent() | ||
{ | ||
PLIST_ENTRY entry = ExInterlockedRemoveHeadList(&Head, &Lock); | ||
if (entry == nullptr) { | ||
return nullptr; | ||
} | ||
|
||
return CONTAINING_RECORD(entry, NotifyEvent, ListEntry); | ||
} | ||
|
||
VOID | ||
NotifyQueue::FreeEvent(NotifyEvent* event) | ||
{ | ||
if (event != nullptr) { | ||
ExFreePoolWithTag(event, 'ovpn'); | ||
} | ||
} | ||
|
||
VOID | ||
NotifyQueue::FlushEvents() | ||
{ | ||
LOG_ENTER(); | ||
|
||
NotifyEvent* event = nullptr; | ||
while ((event = GetEvent()) != nullptr) { | ||
FreeEvent(event); | ||
} | ||
|
||
LOG_EXIT(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* ovpn-dco-win OpenVPN protocol accelerator for Windows | ||
* | ||
* Copyright (C) 2024- OpenVPN Inc <[email protected]> | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ntddk.h> | ||
|
||
#include "uapi/ovpn-dco.h" | ||
|
||
struct NotifyEvent { | ||
LIST_ENTRY ListEntry; | ||
|
||
OVPN_NOTIFY_CMD Cmd; | ||
int PeerId; | ||
OVPN_DEL_PEER_REASON DelPeerReason; | ||
}; | ||
|
||
class NotifyQueue { | ||
private: | ||
LIST_ENTRY Head; | ||
KSPIN_LOCK Lock; | ||
|
||
public: | ||
NotifyQueue() = delete; | ||
|
||
VOID Init(); | ||
|
||
NTSTATUS AddEvent(OVPN_NOTIFY_CMD cmd, int peerId, OVPN_DEL_PEER_REASON delPeerReason=OVPN_DEL_PEER_REASON_EXPIRED); | ||
|
||
NotifyEvent* GetEvent(); | ||
|
||
VOID FreeEvent(NotifyEvent* event); | ||
|
||
VOID FlushEvents(); | ||
}; |
This file contains 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
This file contains 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
This file contains 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