Skip to content

Commit

Permalink
Track packet filter separately for each open instance. See nmap/nmap#…
Browse files Browse the repository at this point in the history
…1035
  • Loading branch information
bonsaiviking committed May 14, 2018
1 parent 032c6ce commit e5a6772
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
57 changes: 46 additions & 11 deletions packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,10 @@ NPF_RemoveFromGroupOpenArray(
{
POPEN_INSTANCE GroupOpen;
POPEN_INSTANCE GroupPrev = NULL;
POPEN_INSTANCE GroupHead = NULL;
BOOLEAN Success = FALSE;
ULONG OldPacketFilter;
ULONG BytesProcessed;

TRACE_ENTER();

Expand All @@ -1148,28 +1152,59 @@ NPF_RemoveFromGroupOpenArray(
TRACE_EXIT();
return;
}
GroupHead = Open->GroupHead;

NdisAcquireSpinLock(&Open->GroupHead->GroupLock);
GroupPrev = Open->GroupHead;
NdisAcquireSpinLock(&GroupHead->GroupLock);

/* Store the previous combined packet filter */
OldPacketFilter = GroupHead->MyPacketFilter;
/* Reset the combined packet filter and recalculate it */
GroupHead->MyPacketFilter = 0;

GroupPrev = GroupHead;
GroupOpen = GroupPrev->GroupNext;
while (GroupOpen)
{
if (GroupOpen == Open)
{
GroupPrev->GroupNext = GroupOpen->GroupNext;
NdisReleaseSpinLock(&Open->GroupHead->GroupLock);
GroupOpen->GroupHead = NULL;

TRACE_EXIT();
return;

}
GroupPrev = GroupOpen;
}
else
{
GroupPrev = GroupOpen;
GroupHead->MyPacketFilter = GroupHead->MyPacketFilter | GroupOpen->MyPacketFilter;
}
GroupOpen = GroupOpen->GroupNext;
}
NdisReleaseSpinLock(&Open->GroupHead->GroupLock);
NdisReleaseSpinLock(&GroupHead->GroupLock);

IF_LOUD(DbgPrint("NPF_RemoveFromGroupOpenArray: error, the open isn't in the group open list.\n");)
/* If the packet filter has changed, originate an OID Request to set it to the new value */
if (GroupHead->MyPacketFilter != OldPacketFilter)
{
#ifdef HAVE_DOT11_SUPPORT
GroupHead->LowerPacketFilter = GroupHead->HigherPacketFilter | GroupHead->MyPacketFilter | GroupHead->Dot11PacketFilter;
#else
GroupHead->LowerPacketFilter = GroupHead->HigherPacketFilter | GroupHead->MyPacketFilter;
#endif
NPF_DoInternalRequest(Open,
NdisRequestSetInformation,
OID_GEN_CURRENT_PACKET_FILTER,
&GroupHead->LowerPacketFilter,
sizeof(GroupHead->LowerPacketFilter),
0,
0,
&BytesProcessed);
if (BytesProcessed != sizeof(GroupHead->LowerPacketFilter))
{
IF_LOUD(DbgPrint("NPF_RemoveFromGroupOpenArray: Failed to set resulting packet filter.\n");)
}
}

if (Open->GroupHead != NULL)
{
IF_LOUD(DbgPrint("NPF_RemoveFromGroupOpenArray: error, the open isn't in the group open list.\n");)
}

TRACE_EXIT();
}
Expand Down
17 changes: 12 additions & 5 deletions packetWin7/npf/npf/Packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ NPF_IoControl(
)
{
POPEN_INSTANCE Open;
POPEN_INSTANCE Current;
PIO_STACK_LOCATION IrpSp;
PLIST_ENTRY RequestListEntry;
PINTERNAL_REQUEST pRequest;
Expand Down Expand Up @@ -2242,11 +2243,6 @@ NPF_IoControl(
if (OidData->Oid == OID_GEN_CURRENT_PACKET_FILTER && FunctionCode == BIOCSETOID)
{
ASSERT(Open->GroupHead != NULL);
Open->GroupHead->MyPacketFilter = *(ULONG*)OidData->Data;
if (Open->GroupHead->MyPacketFilter == NDIS_PACKET_TYPE_ALL_LOCAL)
{
Open->GroupHead->MyPacketFilter = 0;
}

// Disable setting Packet Filter for wireless adapters, because this will cause limited connectivity.
if (Open->GroupHead->PhysicalMedium == NdisPhysicalMediumNative802_11)
Expand All @@ -2267,6 +2263,17 @@ NPF_IoControl(
break;
}

// Store the requested packet filter for *this* Open instance
Open->MyPacketFilter = *(ULONG*)OidData->Data;
// Set the group head packet filter to the union of all instances' filters
NdisAcquireSpinLock(&Open->GroupHead->GroupLock);
Open->GroupHead->MyPacketFilter = 0;
for (Current = Open->GroupHead->GroupNext; Current != NULL; Current = Current->GroupNext)
{
Open->GroupHead->MyPacketFilter = Open->GroupHead->MyPacketFilter | Current->MyPacketFilter;
}
NdisReleaseSpinLock(&Open->GroupHead->GroupLock);

#ifdef HAVE_DOT11_SUPPORT
combinedPacketFilter = Open->GroupHead->HigherPacketFilter | Open->GroupHead->MyPacketFilter | Open->GroupHead->Dot11PacketFilter;
#else
Expand Down

0 comments on commit e5a6772

Please sign in to comment.