NdisCopyFromNetBufferToNetBuffer Can This Be Used To Guarantee Contiguous Packet Memory RRS feed

  • Question

  • If you allocate a net buffer and call tis copy routine with an existing net buffer that has non-contiguous packet buffer data will it normalize the packet data and make it contiguous.  I am trying to find a way that when NdisGetDataBuffer returns back NULL I can use he storage location.  Use that  as an indication copy the original to the new with the copy BufferToBuffer routne and hopefully end up with a contigous buffer.


    If not how is the best way to get and guarantee a contigous buffer and more important once I have it and have modified it how do I re-inject it back in to WFP.  

    Thanks Doug


    Wednesday, June 8, 2011 1:54 PM


  • Hi Doug, thanks for your message, but I'm not sure I understand your question fully.  You have a NET_BUFFER, and you want to obtain a contiguous view of the data, modify the data, then reinject the (contiguous) data buffer back into WFP?  Is that right?

    NdisCopyFromNetBufferToNetBuffer does not change the arrangement of MDLs in the destination NET_BUFFER (nor in the source NET_BUFFER!).  So if the destination was a single MDL with a big, contiguous buffer before NdisCopyFromNetBufferToNetBuffer, then it will be a single MDL with a big contiguous buffer after NdisCopyFromNetBufferToNetBuffer.  Therefore, if you want to guarantee that the NET_BUFFER is contiguous, all you have to do is ensure that you create the destination NET_BUFFER with a single big MDL.  In bulleted list form:

    1. Allocate a big chunk of nonpaged pool for the data buffer.
    2. Allocate a NET_BUFFER and NET_BUFFER_LIST, and point them at your data buffer (e.g., with FwpsAllocateNetBufferAndNetBufferList0).
    3. When you receive a source NET_BUFFER, use NdisCopyFromNetBufferToNetBuffer to copy the data into your contiguous buffer.
    4. Modify the data in the packet, however you want.
    5. Re-inject the NET_BUFFER_LIST.

    Hope this helps!

    Wednesday, June 8, 2011 8:58 PM