Skip to content

Commit

Permalink
Track whether OID_GEN_CURRENT_PACKET_FILTER is allowed as query
Browse files Browse the repository at this point in the history
WiFi adapters on Windows 10 and 11 return NDIS_STATUS_INVALID_OID for
this query. Previously, this was ignored and we would probably set an
empty packet filter on exit, but since we started checking return value,
it led to inability to capture at all, since libpcap expects to be able
to set the packet filter. No explanation so far for why WiFi adapters
are different in this way, but if any adapter returns
NDIS_STATUS_INVALID_OID, we will avoid sending it again in the future.
  • Loading branch information
bonsaiviking committed Aug 17, 2022
1 parent 9115d5f commit 53a19f3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
45 changes: 38 additions & 7 deletions packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,18 +909,28 @@ NPF_GetPacketFilter(
)
{
// This can only be used before we start mucking with the packet filter.
NT_ASSERT(pFiltMod->MyPacketFilter == 0);
INFO_DBG("pFiltMod(%p) OID_GEN_CURRENT_PACKET_FILTER (%#x)\n",
pFiltMod, OID_GEN_CURRENT_PACKET_FILTER);
if (!pFiltMod->PacketFilterGetOK)
{
INFO_DBG("pFiltMod(%p) OID_GEN_CURRENT_PACKET_FILTER query not supported\n", pFiltMod);
return STATUS_NOT_SUPPORTED;
}
NTSTATUS Status = NPF_OidGetUlongNonpagedPtr(pFiltMod,
OID_GEN_CURRENT_PACKET_FILTER,
&pFiltMod->HigherPacketFilter
);

if (Status == STATUS_SUCCESS)
{
pFiltMod->PacketFilterOK = 1;
pFiltMod->HigherPacketFilterSet = 1;
pFiltMod->PacketFilterGetOK = 1;
}
else if (Status == NDIS_STATUS_INVALID_OID)
{
pFiltMod->PacketFilterGetOK = 0;
}

return Status;
}

Expand Down Expand Up @@ -2038,6 +2048,17 @@ NPF_AttachAdapter(
pFiltMod->Fragile = 1;
break;
}
switch (AttachParameters->MiniportPhysicalMediaType)
{
case NdisPhysicalMediumNative802_11:
// NDIS always answers OID_GEN_CURRENT_PACKET_FILTER queries for
// Wifi adapters with NDIS_STATUS_INVALID_OID
pFiltMod->PacketFilterGetOK = 0;
break;
default:
pFiltMod->PacketFilterGetOK = 1;
break;
}

#ifdef HAVE_RX_SUPPORT
// Determine whether this is our send-to-Rx adapter for the open_instance.
Expand Down Expand Up @@ -2181,7 +2202,7 @@ NPF_Restart(
PNPCAP_FILTER_MODULE pFiltMod = (PNPCAP_FILTER_MODULE)FilterModuleContext;
NDIS_STATUS Status;
NTSTATUS ntStatus;
ULONG ulTmp;
ULONG ulTmp = 0;
PNDIS_RESTART_ATTRIBUTES Curr = RestartParameters->RestartAttributes;
PNDIS_RESTART_GENERAL_ATTRIBUTES GenAttr = NULL;
BOOLEAN bDot11 = FALSE;
Expand Down Expand Up @@ -2494,7 +2515,7 @@ NOTE: Called at <= DISPATCH_LEVEL (unlike a miniport's MiniportOidRequest)
{
case OID_GEN_CURRENT_PACKET_FILTER:
pFiltMod->HigherPacketFilter = *(ULONG *) Request->DATA.SET_INFORMATION.InformationBuffer;
pFiltMod->PacketFilterOK = 1;
pFiltMod->HigherPacketFilterSet = 1;
if (*(PULONG) pBuffer & ~pFiltMod->SupportedPacketFilters)
WARNING_DBG("Upper driver setting unsupported packet filter: %#x\n", *(PULONG) pBuffer);
*(PULONG) pBuffer = pFiltMod->HigherPacketFilter | pFiltMod->MyPacketFilter;
Expand Down Expand Up @@ -3056,19 +3077,29 @@ NPF_SetPacketFilter(
if (pFiltMod->Fragile || pFiltMod->Loopback)
{
// Fake it
return NDIS_STATUS_SUCCESS;
bail_early = TRUE;
}

if (!pFiltMod->PacketFilterOK)
if (!pFiltMod->HigherPacketFilterSet)
{
Status = NPF_GetPacketFilter(pFiltMod);
if (Status != NDIS_STATUS_SUCCESS)
{
INFO_DBG("pFiltMod(%p) can't set PacketFilter; no valid HigherPacketFilter present.\n", pFiltMod);
return Status;
// Have to fake success; many miniport types don't like queries to OID_GEN_CURRENT_PACKET_FILTER.
bail_early = TRUE;
}
}

if (bail_early)
{
pFiltMod->MyPacketFilter = PacketFilter;
return Status;
}

// Only set packet filter if we know what it was previously and can revert to that.
NT_ASSERT(pFiltMod->HigherPacketFilterSet);

NdisAcquireRWLockWrite(pFiltMod->OpenInstancesLock, &lockState, 0);

// Calculate old and new effective filters
Expand Down
3 changes: 2 additions & 1 deletion packetWin7/npf/npf/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ typedef struct _NPCAP_FILTER_MODULE
UINT SendToRxPath:1;
UINT BlockRxPath:1;
UINT Dot11:1;
UINT PacketFilterOK:1; // Have we correctly set HigherPacketFilter yet?
UINT PacketFilterGetOK:1; // Can we issue OID_GEN_CURRENT_PACKET_FILTER queries?
UINT HigherPacketFilterSet:1; // Have we correctly set HigherPacketFilter yet?
UINT Fragile:1; // Avoid OID set operations on these adapters

ULONG SupportedPacketFilters;
Expand Down

0 comments on commit 53a19f3

Please sign in to comment.