NdisGetDataBuffer - Storage Parameter

I retrieve the Buffer into storage parameter, If I do some modifications on the retrieved buffer, will that reflect in the NB associated with this buffer.

Here is what I am trying to do.

currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

packetData = (PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
total_nb_length,
TAG,
HighPoolPriority);

if (packetData == NULL)
{
break;
}

bufferAddress = NdisGetDataBuffer(currNB, total_nb_length, packetData, 1, 0);

if (bufferAddress == NULL)
{
break;
}

packetData[total_nb_length - 1] = 10 // Example Sequence Number.

NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);

It may or may not be changing the original NB buffer memory. NdisGetDataBuffer is documented as returning a pointer to the original buffer if it’s contiguous, but copying to your supplied buffer if it’s multiple fragments.

Jan


From: xxxxx@lists.osr.com on behalf of xxxxx@gmail.com
Sent: Tuesday, February 7, 2017 4:59:40 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] NdisGetDataBuffer - Storage Parameter

I retrieve the Buffer into storage parameter, If I do some modifications on the retrieved buffer, will that reflect in the NB associated with this buffer.

Here is what I am trying to do.

currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

packetData = (PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
total_nb_length,
TAG,
HighPoolPriority);

if (packetData == NULL)
{
break;
}

bufferAddress = NdisGetDataBuffer(currNB, total_nb_length, packetData, 1, 0);

if (bufferAddress == NULL)
{
break;
}

packetData[total_nb_length - 1] = 10 // Example Sequence Number.

NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

Thanks Jan, I will retrieve the buffer using NdisGetDataBuffer, and do modifications on the buffer as needed, and create a new NBL like mentioned below. Let me know if the approach is right path.

currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

packetData =
(PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
total_nb_length,
TAG,
HighPoolPriority);

if (packetData == NULL)
{
break;
}

bufferAddress = NdisGetDataBuffer(currNB, total_nb_length,
packetData, 1, 0);

if (bufferAddress == NULL)
{
break;
}

packetData[total_nb_length - 1] = 10 // Example Sequence
Number.

// Allocate Memory for MDL
MDL= NdisAllocateMdl(pAdapt->SendBufferPoolHandle,
packetData,
total_nb_length);

if (MDL== NULL)
{
return;
}

// No Chained MDL’s
MDL->Next = NULL;

NBL= NdisAllocateNetBufferAndNetBufferList(pAdapt->SendPacketPoolHandle,
0,
0,
MDL,
0,
total_nb_length);

NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);

Nope, not correct. Read what I previously said about the value returned by NdisGetDataBuffer. Your buffer MIGHT not have been used at all.

Jan


From: xxxxx@lists.osr.com on behalf of xxxxx@gmail.com
Sent: Tuesday, February 7, 2017 9:16:15 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] NdisGetDataBuffer - Storage Parameter

Thanks Jan, I will retrieve the buffer using NdisGetDataBuffer, and do modifications on the buffer as needed, and create a new NBL like mentioned below. Let me know if the approach is right path.

currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

packetData =
(PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
total_nb_length,
TAG,
HighPoolPriority);

if (packetData == NULL)
{
break;
}

bufferAddress = NdisGetDataBuffer(currNB, total_nb_length,
packetData, 1, 0);

if (bufferAddress == NULL)
{
break;
}

packetData[total_nb_length - 1] = 10 // Example Sequence
Number.

// Allocate Memory for MDL
MDL= NdisAllocateMdl(pAdapt->SendBufferPoolHandle,
packetData,
total_nb_length);

if (MDL== NULL)
{
return;
}

// No Chained MDL’s
MDL->Next = NULL;

NBL= NdisAllocateNetBufferAndNetBufferList(pAdapt->SendPacketPoolHandle,
0,
0,
MDL,
0,
total_nb_length);

NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>