I am building a filter driver in NDIS 6. I want to add some data at the back of my NET_BUFFER.
To add data I have allocated an MDL through the NdisAllocateMdl
API. Now I want to know, is there any wrapper to add this MDL to the existing MDL chain?
If not, is it correct to make the last MDL's Next
pointer to point to my new allocated MDL, as I was able to do so? Also what are the fields in NET_BUFFER I have to change to make it recognize the added MDL?
The actual packet payload of an
NET_BUFFER
is a subset of the payload of the entire MDL chain. The packet might not start at the beginning of the MDL chain, and the packet might not end at the end of the MDL chain.Therefore, in the most general case, you'll actually need to remove some MDLs from the end of the
NET_BUFFER
, before you append your new MDL. Let me give a specific example:So in this example, the
NET_BUFFER
points to an MDL chain with 4 MDLs in it. Let's look at the buffers in ASCII-art:As hopefully the diagram illustrates, the actual packet payload is only spread across the second & third MDLs. Both the first & fourth MDLs are completely ignored. So if you want to append data to the packet, you need to:
NET_BUFFER::DataLength
.Here's a diagram of what the packet will look like after finishing step 3:
Then after step #4:
When the packet is completed back to your driver, you need to undo the modifications you made earlier:
DataLength
.