NdisGetDataBuffer behavior with Storage=NULL

Hi
It is mentioned in MSDN:

If the requested data in the buffer is contiguous, the return value is a pointer to a location that NDIS provides. If the data is not contiguous, NDIS uses the Storage parameter as follows
I call NdisGetDataBuffer like:
nblBufferSize = NET_BUFFER_DATA_LENGTH(pNetBuffer);
VOID *pBuff = NdisGetDataBuffer(pNetBuffer, nblBufferSize, NULL, 1, 0);

Sometimes, it returns NULL, sometimes non-NULL.
Can you suggest why it can be ? Protocol is UDP-based.
Is it related to Do Not Fragment bit in IP header?

Thanks!

here is the MSDN documentation
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ndis/nf-ndis-ndisgetdatabuffer

it clearly states several reasons why the return can be NULL including this part

The return value can also be NULL due to a low resource condition where a data buffer cannot be mapped. This may occur even if the data is contiguous or the Storage parameter is non-NULL

it seems clear that you have to expect this to fail and handle that. you also have to handle this case

_If the requested data in the buffer is contiguous, the return value is a pointer to a location that NDIS provides. If the data is not contiguous, NDIS uses the Storage parameter as follows:

If the Storage parameter is non-NULL, NDIS copies the data to the buffer at Storage. The return value is the pointer passed to the Storage parameter.
If the Storage parameter is NULL, the return value is NULL._

and since you are passing NULL, and other layers can affect whether the data of interest is contiguous or not you need some failback logic

1 Like

I am sorry, probably my question was unclear…
It is more important to understand why buffer is not contiguous. Is it possible to tweak the HW driver or packets sender device to prevent it ?
Redundant memory copying is not good for my system, and it would be great to avoid it.

Sure, it would be great to avoid it, but that’s out of your hands. It is what it is. You have to be handle to this condition.

https://community.osr.com/discussion/241014/ndisgetdatabuffer

1 Like

Tim_Roberts, thanks again. The post gave me the direction to dig into.