- NDIS - sending packets
- Posted by Michal Filka on June 7th, 2005
Hi all,
I'm interested in solwing following problem in my NDIS intermediate
driver. I need to send one packet (little changed) throught more than one
adapter (resending broadcast to all conected networks). If I call NdisSend,
is my packet copyed by underlying miniport driver (or is it possible to
require this behaviour)? So, I can do the required little change (change
source address) in the packet and use it again, or do I have to clone this
packet for each adapter?
Thanks for answers
Michal
- Posted by Thomas F. Divine [DDK MVP] on June 7th, 2005
"Michal Filka" <michal.filka@atlas.cz> wrote in message
news:OJ$Zk6zaFHA.1404@TK2MSFTNGP09.phx.gbl...
the MP. You should clone each packet that you modify.
In addition, is you send on multiple adapters you should use NDIS_PACKET
allocated from a send packet pool on the adapter you are sending on. Don't
use the NDIS_PACKET allocated on one adapter's pool for sending on another
adapter. Microsoft keeps hidden information in the packet that identified
the pool it came from and also maintains other private data. I would
actually suggest having completely separate send and receive packet pools
allocated on each adapter that you use exclusively for sending/receiving
your modified packets.
Good luck,
Thomas F. Divine, Windows DDK MVP
http://www.rawether.net
- Posted by Stephan Wolf [MVP] on June 8th, 2005
Thomas F. Divine [DDK MVP] wrote:
Umm, well, it's the IM's protocol part that allocates the NDIS_PACKET,
right? So one is free to use one and the same packet pool to allocate
from and send to different adapters.
There were actually some problems regarding packets allocated from the
same pool that are used for both send and receive. You actually filed
that on your web site:
http://www.pcausa.com/support/SWolf091010.txt
I think the OP should follow these rules:
1. *Never* change the contents of any packets that you did not allocate
yourself. Any such packets that your IMs gets via either its
MiniportSend[Packets]() or ProtocolReceivePacket() routines are
read-only to the IM.
2. You must allocate a new NDIS_PACKET descriptor for each such
original packet that your IM forwards (unless you use packet stacking
*and* there is room left in the packet's stack).
3. You can, however, have your local NDIS_PACKET point to the
NDIS_BUFFERs of the original packet.
4. This way, you do not need to make an actual copy of the packet
contents (payload). If you need to alter for instance only the source
MAC address, you can simply:
a) allocate your own (local) MAC header
b) allocate your own NDIS_BUFFER and let it point to your local MAC
header
c) set up the MAC header as required
d) have your local NDIS_PACKET point to your local NDIS_BUFFER
e) allocate a second local NDIS_BUFFER an have it point to the same
virtual address as the first NDIS_BUFFER from the original NDIS_PACKET
*plus* the offset of the MAC header (i.e. skip the MAC header of the
original packet)
Caution: Make sure the 1st original buffer actually contains the
complete MAC header...
f) Append all other original NDIS_BUFFERs to your second local
NDIS_BUFFER
What you get is a list of local NDIS_BUFFERs followed by a list of
original NDIS_BUFFERs:
loc1 -> loc2 -> org2 -> org3 -> org4 -> ...
Then pass the local NDIS_PACKET to either NdisSend() or
NdisMIndicateReceivePacket(). Now you need to wait for NDIS to return
this NDIS_PACKET to you via either NdisMSendComplete() or
NdisMReturnPacket().
Only now may you complete the original NDIS_PACKET back to NDIS!
It is common practice to save a pointer to the original packet in the
local packet's 'MiniportReserved' (when passed to NdisSend()) or
'ProtocolReserved' (when passed to NdisMIndicateReceivePacket()) field.
If you need to pass the same original NDIS_PACKET to several underlying
adapters at the same time, simply place a "use" counter in the original
(!) packet's 'Reserved' field: 'MiniportReserved' when passed to your
MiniportSend[Packets]() routine and 'ProtocolReserved' when passed to
your ProtocolReceive[Packet]() routine.
[Note that the use of the respective 'reserved' field depends on
whether the packet is used by your IMs miniport or protocol part.]
Stephan
- Posted by Stephan Wolf [MVP] on June 8th, 2005
Stephan Wolf [MVP] wrote:
I just realized there is also a complete knowledge base article here:
http://www.pcausa.com/support/KB05050101.htm
See also
http://www.ndis.com/papers/ndispacket/ndispacket1.htm
and
http://www.ndis.com/papers/ndispacket/ndispacket2.htm
Even more White papers on NDIS by Microsoft MVP Tom Divine:
http://www.ndis.com/papers/
Stephan