NDIS driver to modify IP headers



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: NDIS driver to modify IP headers
    ... You must use an NDIS IM and not a miniport. ... 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: raw sockets and blocking
    ... >> sends to actually down ethernet interface are multicast packets. ... Hello's in broadcast network are multicast. ... It appears to be bug in e100 driver in 2.4.x. ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: WinCE500 (WM5.0 PPC) Passthru Driver Example
    ... Is there passthru driver prefix like "UIO1:" to call createfile? ... > 1) I am Using Sprint PCS 6700 device and i want to modify all the ip packets ... You can also modify the packets ...
    (microsoft.public.pocketpc.developer)
  • Re: WinCE500 (WM5.0 PPC) Passthru Driver Example
    ... You get those prefixes when you load your NDIS driver as a Stream ... > So i want to modify all the received and out going packets by setting I/O call functions ...
    (microsoft.public.pocketpc.developer)
  • Re: Filter Hook
    ... the callback routine is been invoked at DISPATCH_LEVEL. ... If you really have to keep such a queue for the packets, then the IP filter driver is not suitable for your needs since you have to process all the packets in the callback routine without any wait actionand return it to the tcpip driver immediately when the callback routine returns. ... What IRQL are you running at when you crash, ...
    (microsoft.public.development.device.drivers)