From 9ae77eb7a50615f3cfdd0f35a08bdd0b3516e48f Mon Sep 17 00:00:00 2001 From: basil00 Date: Wed, 1 Nov 2017 20:47:45 +0800 Subject: [PATCH] Loopback packets are now considered outbound only Workaround for #17 --- sys/windivert.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/windivert.c b/sys/windivert.c index 3c986a0..14c2f12 100644 --- a/sys/windivert.c +++ b/sys/windivert.c @@ -419,7 +419,7 @@ static void windivert_classify_forward_network_v6_callout( OUT FWPS_CLASSIFY_OUT0 *result); static void windivert_classify_callout(context_t context, IN UINT8 direction, IN UINT32 if_idx, IN UINT32 sub_if_idx, IN BOOL isipv4, - IN BOOL isloopback, IN UINT advance, IN OUT void *data, + IN BOOL loopback, IN UINT advance, IN OUT void *data, IN UINT64 flow_context, OUT FWPS_CLASSIFY_OUT0 *result); static BOOL windivert_queue_packet(context_t context, PNET_BUFFER buffer, UINT8 direction, UINT32 if_idx, UINT32 sub_if_idx, BOOL is_ipv4, BOOL hop, @@ -2351,7 +2351,7 @@ static void windivert_classify_forward_network_v6_callout( * WinDivert classify callout. */ static void windivert_classify_callout(context_t context, IN UINT8 direction, - IN UINT32 if_idx, IN UINT32 sub_if_idx, IN BOOL isipv4, IN BOOL isloopback, + IN UINT32 if_idx, IN UINT32 sub_if_idx, IN BOOL isipv4, IN BOOL loopback, IN UINT advance, IN OUT void *data, IN UINT64 flow_context, OUT FWPS_CLASSIFY_OUT0 *result) { @@ -2430,10 +2430,16 @@ static void windivert_classify_callout(context_t context, IN UINT8 direction, hop = TRUE; } - timestamp = KeQueryPerformanceCounter(NULL).QuadPart; + // Loopback packets are considered outbound only. + if (loopback && direction == WINDIVERT_DIRECTION_INBOUND) + { + WdfObjectDereference(object); + result->actionType = FWP_ACTION_CONTINUE; + return; + } // Determine which checksum fields are present or not. - if (isloopback) + if (loopback) { // Loopback packets appear to have bogus checksums, so do not trust. checksums = 0; @@ -2456,6 +2462,8 @@ static void windivert_classify_callout(context_t context, IN UINT8 direction, checksums &= ~WINDIVERT_IP_CHECKSUM; } + timestamp = KeQueryPerformanceCounter(NULL).QuadPart; + // Retreat the NET_BUFFER to the IP header, if necessary. // If (advance != 0) then this must be in the inbound path, and the // NET_BUFFER_LIST must contain exactly one NET_BUFFER.