Re: NDIS driver to modify IP headers



You must use an NDIS IM and not a miniport.
DriverNetworks are no more supported. Sorry. Switch to plain NDIS.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@xxxxxxxxxxxxxxxx
http://www.storagecraft.com

"David Sackstein" <DavidSackstein@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:62E41217-4E35-445F-AF08-475A0A6942D0@xxxxxxxxxxxxxxxx
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

.



Relevant Pages

  • Re: Problem with matching kind of NDIS driver.
    ... When it comes to outgoing packets, the reasons why his task is infeasible ... context of different threads. ... NDIS IM filter that is located immediately below ... We are telling you that in a NDIS Intermediate driver the process ...
    (microsoft.public.development.device.drivers)
  • NDIS driver to modify IP headers
    ... 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 ... I know that I cannot modify NDIS packets that I did not allocate, ...
    (microsoft.public.development.device.drivers)
  • Re:NDIS Irda protocol driver
    ... in between miniport driver's indication of packets to NDIS library and NDIS ... library's notification of your driver about incoming packets. ...
    (microsoft.public.win32.programmer.kernel)
  • RE: Help!! Out of the Pot and into the Driver Fire
    ... We are for now doing all this on pre-Vista OS. ... However, if you are just desperate to do things at NDIS level, you can write ... NDIS IM filter is not always easy to write - the same driver may work well ... the effect of lag and dropped packets and I got tagged as the lucky developer ...
    (microsoft.public.development.device.drivers)
  • Crash in wanarp.sys module
    ... I'm working on filter driver based on NDIS IM driver from DDK. ... As part of it's functionality it needs to inject sometimes packets - ... This works fine in Windows XP. ...
    (microsoft.public.win32.programmer.kernel)