How to update source ip address in UDP packets

I am trying to update the source IP address of the UDP and TCP packets which are captured at layer FWPM_LAYER_ALE_CONNECT_REDIRECT_V4and FWPM_LAYER_ALE_AUTH_CONNECT_V4.
In case of TCP packets source IP address is successfully updated but in the case of UDP packets source IP address is not updated.
I am checking the IP address used in the packet using Wireshark.

UINT64 classifyHandle = 0;
NTSTATUS status = FwpsAcquireClassifyHandle0(
	(void*)classifyContext,
	(UINT32)0,
	&classifyHandle
);
if (!NT_SUCCESS(status))
{
	DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, "Could not get the classify handle %x\r\n", status);
	return;
}
FWPS_CONNECT_REQUEST* writableLayerData = NULL;
status = FwpsAcquireWritableLayerDataPointer(
	classifyHandle,
	filter->filterId,
	0,
	(PVOID*)&writableLayerData,
	classifyOut
);
if (!NT_SUCCESS(status))
{
	DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, "FwpsAcquireWritableLayerDataPointer Failed %x\r\n", status);
	return;
}
SOCKADDR_IN* sourceAddr = (SOCKADDR_IN*)(&(writableLayerData->localAddressAndPort));
if(sourceAddr ==NULL)
{
	DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, "socket address is NULL\r\n");
	goto Exit;
}
sourceAddr->sin_addr.S_un.S_addr = RtlUlongByteSwap(*(unsigned long*)&vip);

#if (NTDDI_VERSION >= NTDDI_WIN8)
	if (inFixedValues->layerId == FWPS_LAYER_ALE_CONNECT_REDIRECT_V4)
		writableLayerData->localRedirectHandle = gRedirectConnectHandlev4;
	else if (inFixedValues->layerId == FWPS_LAYER_ALE_AUTH_CONNECT_V4)
		writableLayerData->localRedirectHandle = gAuthConnectHandlev4;

	writableLayerData->localRedirectContext = NULL;
	writableLayerData->localRedirectContextSize = 0;
#endif
	classifyOut->actionType = FWP_ACTION_PERMIT;
	FwpsApplyModifiedLayerData(
		classifyHandle,
		writableLayerData,
		0
	);
Exit:
	FwpsReleaseClassifyHandle(classifyHandle);

Please let me know how to correctly update the source IP address in UDP packets.

Thanks,
Chetan

https://docs.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection

Changing the local address and port of a flow is only supported in the bind-redirect layer. This is not supported in the connect-redirect layer.

1 Like

Thanks Jason,

I am able to update the UDP packet using FWPM_LAYER_ALE_BIND_REDIRECT_V4 layer.

Dear chetanchauhan111992,

How did you get the classifyContext “option” turned on?

When I try a classifyFn in the FWPM_LAYER_ALE_AUTH_CONNECT_V4 myself, the classifyContext variable passed comes in as NULL. There is no documentation on this that I can find. What operating system does your code target, only Win 8 and above, or did you have this working in Win 7?

Did you declare something extra when you registered the callout?

Thank you in advance for sharing.

Peace,

Pen

First post… at it’s to a thread that’s almost a year old.

You know, of course, from reading the forum rules before posting, that posting to such an old thread is not allowed.

Soooo… I’m locking this thread. If you want to ask a question, start a new thread.

Please… DO try to follow the rules, OK?