Hello. On the TX path I want to modify IP address, TCP port, and TCP data. Initially I was using NdisGetDataBuffer() but sometimes the data is fragmented and creates a new buffer, hence modifying that data does not affect the original MDL to be sent downwards.
At the moment I manually walk the cloned MDLs chain to find the data. I had a look through the NDIS macros but couldn’t find anything relevant. What is the correct way to modify the data and send it down? I know I need to fix the TCP checksum of data if modified. But for now I just changing TCP destinationPort and even that doesn’t succeed. I checked IP checksum and it is NULL, from what I read online, the NIC card calculates checksum for Tx packets.
What I do doesn’t quite work - i.e. if I omit the modification the clone works fine against webserver I test against. However if I change the TCP.destinationPort port my webserver still gets a request to original IP:port. However I am sure I am know editing the correct MDL, and in the FilterSendNetBufferListsComplete I also inspect my clonedNbl to be freed, and I see the modified port (that is proven since I target port 8000 (0x401f) and it only appears once in the frame data, and is at offset 0n34 = (ETH len)0n14 + (IP4 len)0n20) = 0n34 (TCP)
Pseudocode of what I do.
FilterSendNetBufferLists:
while (currentNbl)
…while (pNetBuffer)
…if (search) {…}
…cloneNbl = NdisAllocateCloneNetBufferList(currentNbl, NULL, NULL, 0);
…NdisCopySendNetBufferListInfo(cloneNbl, currentNbl); // copy flags
…for (mdl link loop) {…} // search and replace data
…cloneNbl->ParentNetBufferList = currentNbl; //save orig nbl, for restoration in completion
NdisFSendNetBufferLists(NBL list of cloneNbl) // send down to NIC
FilterSendNetBufferListsComplete:
while (currentNbl) …
//check NBL belongs to me
…parentNbl = currentNbl->ParentNetBufferList; // add to nbl list
…InsertTailQueue(&PacketCompleteQueue, parentNbl);
NdisFSendNetBufferListsComplete(PacketCompleteQueue…) // send original NBL I cloned back up to protocol flt
Meh this markup and my code example is kapoot…