Re: Question about NDIS memory management



Thanks for the reply Stephan - in my original message when I said "NDIS
frees ..." I was refering to the API's you listed. I was just checking
that there is no issue with indicating that the data size in the buffer
is X while the actual memory allocated is >X.


Stephan Wolf [MVP] wrote:
2) NDIS will *not* free anything for you when you call NdisSend(),
i.e., NDIS will not free neither the NDIS_PACKET, nor any
NDIS_BUFFER(s) associated with it, nor the memory that make up the
actual buffer area(s). Instead, you need to take "appropriate" action
in your ProtocolSendComplete() handler. For instance, you could call
NdisFreeMemory(), NdisFreeBuffer(), and NdisFreePacket(). This would be
"appropriate" for the code you presented.

1) But you could also choose to reuse the packet/buffer/memory without
freeing and reallocating them. This implies a more complicated design.
Not sure whether this would make sense for you.

Stephan
---
atweir@xxxxxxxxx wrote:
I am writing an IM driver based on the PT example. The driver will
inspect each packet received from the network and if it meets certain
criteria it will append its payload plus a locally generated header to
NDIS memory. When the memory is full a new packet and buffer are
created and the packet is sent back over the network. None of these
received packets are sent up the network stack. Here is my pseudo code

For each received network packet
{
If (packet meets criteria)
{
If (packet payload size > (MaxMTU + index))
{
NdisDprAllocatePacket(,&NewPacket,);
NdisAllocateBuffer(,&NewBuffer, pool, data, index);
NdisChainBufferAtFront(NewPacket, NewBuffer)
NdisSend(,,NewPacket);
}
If (data == NULL)
{
NdisAllocateMemoryWithTag(&data,MaxMTU,);
Build UDP header
Index = sizeof(UDPHeader);
}
Build a descriptor for this payload and copy it to &data[index]
Adjust index
Copy the payload from packet to &data[index]
Adjust index
}
}

My questions are:
1) is there a better way to manage the NDIS memory/buffers?
2) When I allocate the memory I specify a size of MaxMTU but when I
associate the memory with the buffer I specify the amount of data in
the buffer which will be less. When NDIS frees the memory after sending
the packet will this difference cause a memory leak?

TIA, Alan

.



Relevant Pages

  • Re: Library design for downloading an unknown amount of data?
    ... Multiple manufacturers just adds to the fun! ... Some devices send everything in a single packet, ... you could malloc the correct sized buffer. ... devices that only have 32KB of memory. ...
    (comp.lang.c)
  • Re: Library design for downloading an unknown amount of data?
    ... A potential problem with this approach is that the buffer size will be ... Some devices send everything in a single packet, ... In some protocols it is simply fixed, and for others you can choose it yourself, but you should use the maximum allowable size for maximum speed. ... Right now the device with the highest memory capacity has 2MB of memory. ...
    (comp.lang.c)
  • CONFIG_PACKET_MMAP revisited
    ... I've been looking into faster ways to do packet captures and I stumbled on ... In that discussion Jamie Lokier suggested having a memory buffer that's ... shared between user and kernel space and having the NIC do DMA transfers ...
    (Linux-Kernel)
  • Re: Question about modifing the NDIS packet?
    ... packet FROM a miniport BACK of the net. ... If your driver is an intermediate ... you driver changes the length of the ndis packet buffer - here you ... your driver is not a registered ndis driver. ...
    (microsoft.public.windowsxp.device_driver.dev)
  • Re: How much RAM needed for low end Ethernet application?
    ... >> the fact that the Ethernet controller had buffer memory. ... it seems a convenient resource for packet ... How many Ethernet controllers are able to address this memory directly? ...
    (comp.arch.embedded)

Loading