Skip to content

Commit

Permalink
multipeer: implement reverse path filtering
Browse files Browse the repository at this point in the history
After decrypting transport packet, make sure
its source address matches peer's address.

If address doesn't match or packet is not IP
packet, drop the packet.

GitHub: #97

Signed-off-by: Lev Stipakov <[email protected]>
  • Loading branch information
lstipakov committed Jan 10, 2025
1 parent 841d05c commit 53d805b
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,54 @@ VOID OvpnSocketDataPacketReceived(_In_ POVPN_DEVICE device, UCHAR op, UINT32 pee

OvpnPeerCtxRelease(peer);

if (NT_SUCCESS(status)) {
// ping packet?
if (OvpnTimerIsKeepaliveMessage(buffer->Data, buffer->Len)) {
LOG_INFO("Ping received", TraceLoggingValue(peerId, "peer-id"));
if (!NT_SUCCESS(status)) {
return;
}

// no need to inject ping packet into OS, return buffer to the pool
OvpnRxBufferPoolPut(buffer);
}
else {
if (OvpnMssIsIPv4(buffer->Data, buffer->Len)) {
// ping packet?
if (OvpnTimerIsKeepaliveMessage(buffer->Data, buffer->Len)) {
LOG_INFO("Ping received", TraceLoggingValue(peerId, "peer-id"));

// no need to inject ping packet into OS, return buffer to the pool
OvpnRxBufferPoolPut(buffer);
}
else {
BOOLEAN drop = TRUE;
OvpnPeerContext* lookup_peer = NULL;

if (OvpnMssIsIPv4(buffer->Data, buffer->Len)) {
// perform Reverse Path Filtering
auto addr = ((IPV4_HEADER*)(buffer->Data))->SourceAddress;
lookup_peer = OvpnFindPeerVPN4(device, addr);
if (lookup_peer == peer) {
drop = FALSE;
OvpnMssDoIPv4(buffer->Data, buffer->Len, mss);
}
else if (OvpnMssIsIPv6(buffer->Data, buffer->Len)) {
}
else if (OvpnMssIsIPv6(buffer->Data, buffer->Len)) {
// perform Reverse Path Filtering
auto addr = ((IPV6_HEADER*)(buffer->Data))->SourceAddress;
lookup_peer = OvpnFindPeerVPN6(device, addr);
if (lookup_peer == peer) {
drop = FALSE;
OvpnMssDoIPv6(buffer->Data, buffer->Len, mss);
}
}

if (lookup_peer) {
OvpnPeerCtxRelease(lookup_peer);
}

if (!drop) {
// enqueue plaintext buffer, it will be dequeued by NetAdapter RX datapath
OvpnBufferQueueEnqueue(device->DataRxBufferQueue, &buffer->QueueListEntry);

OvpnAdapterNotifyRx(device->Adapter);
}
else {
// packet is dropped dur to RPF, return buffer to the pool
OvpnRxBufferPoolPut(buffer);
}
}
}

Expand Down

0 comments on commit 53d805b

Please sign in to comment.