NDIS driver to modify IP headers
- From: David Sackstein <DavidSackstein@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 03:58:02 -0700
Hi all knowledgeable NDIS miniport driver writers,
My objective is to write a driver that will modify flags in the IP header of
certain multicast flows of data that are being sent by a Windows computer.
I am using NuMega's DriverNetworks to create the driver and I am able to
compile, install and run the driver successfully.
I know that I cannot modify NDIS packets that I did not allocate, so I
allocate my own as follows:
m_PoolLock.Lock();
KNdisPacket DstPacket = m_TxPool.Allocate();
if (!DstPacket.IsValid())
{
m_PoolLock.Unlock();
return NDIS_STATUS_SUCCESS;
}
if( m_BufferIndex+totalLength> BUFFER_SIZE)
m_BufferIndex = 0;
KNdisBuffer Buf = m_BufPool.Allocate( &m_pBuffer[m_BufferIndex]
,totalLength);
m_BufferIndex += totalLength;
DstPacket.ChainAtFront( Buf);
DstPacket.SetFlags(SrcPacket.GetFlags());
NdisMoveMemory(NDIS_OOB_DATA_FROM_PACKET( (PNDIS_PACKET)DstPacket),
NDIS_OOB_DATA_FROM_PACKET( (PNDIS_PACKET)SrcPacket),
sizeof(NDIS_PACKET_OOB_DATA));
DstPacket.STATUS( NDIS_STATUS_PENDING);
// Lock packet buffers before calling NdisCopyFromPacketToPacket (which
// does not according to the DDK's comment). If we fail, complete
// the irp anyway. This would be an indication of low memory conditions.
if (SrcPacket.LockBuffers() && DstPacket.LockBuffers())
{
SrcPacket.CopyFrom(DstPacket, 0, totalLength, 0);
}
else
{
// TBD handle situation when lock failed - printd, fatal error, etc
}
At the end of this snippet I use Ndis functions to walkthrough and modify
the flags I need.
It doesn’t work.
That is:
1. I wrote a simple application in C# that sends synthetic data to a
multicast address. By using DbgPrint I have asserted that SrcPacket contains
the packets with the payload I expect - so the environment of this snippet
seems to be functioning.
2. I use Ethereal to view the packets and I do not see any change in the data.
I thought this might be because someone is overiding my changes after I make
my changes. I know I am processing packets because I traced the payload of
the packets from within the processing function in the driver.
3. I switched to another application to send the multicast data. (an
application called WinSend that sends MPEG video files). Now I found that I
have managed to modify the flags of some packets but not all. Actually, I set
the value of the flags to a counter which I incremented each time I process a
packet. I noticed that all the values of the counter appear in the dump, but
there are packets in between that are not stamped by my counter. This seems
to indicate a different phenomenon to that in 2. It would seem that now I am
not receiving all packets, but that those I do receive and process are
stamped correctly and are not overidden.
So I have these questions:
1. Does this snippet of code satisfy the requirement of "allocate your own
packets"?
2. Can anyone explain why in 2 (using the first application), modifying the
IP header has no effect?
3. Can anyone explain why in 3 modifying DstPacket sometimes works and
sometimes doesn’t? Is there any reason that I might not be receiving all
outgoing packets in my driver?
4. Can anyone explain the different result in 2 and 3. Please note, both
applications send to the same multicast address and the driver is the same in
both tests.
Thanks in advance
--
David Sackstein
Optibase
.
- Follow-Ups:
- Re: NDIS driver to modify IP headers
- From: Maxim S. Shatskih
- Re: NDIS driver to modify IP headers
- Prev by Date: Re: Install NDIS Driver
- Next by Date: Re: Urgent problem on Win XP driver program memory size
- Previous by thread: Sending a UDP packet using TDI at IRQL == DISPATCH_LEVEL
- Next by thread: Re: NDIS driver to modify IP headers
- Index(es):
Relevant Pages
|