Question about modifing the NDIS packet?

G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.device_driver.dev (More info?)

Hi everyone,

I am trying to modify the NDIS packet. Do i need to allocate new buffers?

I want to modify the destination IP address. I am doing the address mapping,
if i receive data for specific destination, i want to redirect that data to
go to another IP address. Do i need to allocate new buffers, copy all the
data from old packet, modify it and then send it again. Can i do the
following?

1. Query the NDIS packet.
2. Get the Virtual Address.
3. Modify the Header, with new IP and checksum.
4. Allocate new packet from my own pool.
5. Copy all the header information and OOB data.
6. Send that packet again.


Can i use the same buffer and packet. Or i will have to allocate new buffer
and packet if i am modifing the data in the packet.

Thanks in Advance

Rajesh
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.device_driver.dev (More info?)

Rajesh

A complete answer to your question requires us to know the OS you are
targeting because there are some differences between win98/ME, Win2k, WinXP
and Win2003

In general you need to allocate your own buffers if you are re-trasmitting a
packet FROM a miniport BACK of the net. If your driver is an intermediate
driver and it merely modifies the packet on its way to the protocol driver
or to a miniport then you only need to allocate a new buffer if

1. you driver changes the length of the ndis packet buffer - here you
allocate the appropriate packet buffer, not the packet structure
2. your driver changes the length of the ip header or oob data - here you
allocate the data buffer
3. your driver is not a registered ndis driver. In general ndis doesn't
notify a miniport or protocol to release buffers until all consumers have
indicated they are done with it. But you would have to be a registered
consumer (i.e. a miniport, protocol or intermediate driver) so ndis knew you
were part of the data flow.

If you are merely querying the packet from ndis through IoCallDriver or
DeviceIoControl then ndis assumes you are done with it when you return.
Futhermore modifications you make to the ndis packet may or may not be
passed on to other ndis drivers. This is why you should register your
driver with ndis during initialization and support one of the ndis driver
types.

This is a simplification because protocols often allocate data in their own
buffer pools and perform buffer integrity checks (like checking the internal
pointers of complex structures). Miniports often use memory on the card to
reduce the number of buffer copies. So if you are going to change some of
the internal pointers in the ndis packet structure you may want to create
your own copy if you can't re-assign the original pointer value when the
consumer returns. I haven't played with this in over a year so please
perform your own tests.

Have a great day
Bill

"Rajesh Gupta" <guptar@gmail.com> wrote in message
news:uXzZ5dWWEHA.3988@tk2msftngp13.phx.gbl...
> Hi everyone,
>
> I am trying to modify the NDIS packet. Do i need to allocate new buffers?
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.device_driver.dev (More info?)

Thanks a lot Bill,

I was able to sucessfully modify the packet. thanks a lot for your response.
Rajesh
"William Ingle" <williamingle@comcast.net> wrote in message
news:l2eGc.28809$Oq2.8881@attbi_s52...
> Rajesh
>
> A complete answer to your question requires us to know the OS you are
> targeting because there are some differences between win98/ME, Win2k,
WinXP
> and Win2003
>
> In general you need to allocate your own buffers if you are re-trasmitting
a
> packet FROM a miniport BACK of the net. If your driver is an intermediate
> driver and it merely modifies the packet on its way to the protocol driver
> or to a miniport then you only need to allocate a new buffer if
>
> 1. you driver changes the length of the ndis packet buffer - here you
> allocate the appropriate packet buffer, not the packet structure
> 2. your driver changes the length of the ip header or oob data - here you
> allocate the data buffer
> 3. your driver is not a registered ndis driver. In general ndis doesn't
> notify a miniport or protocol to release buffers until all consumers have
> indicated they are done with it. But you would have to be a registered
> consumer (i.e. a miniport, protocol or intermediate driver) so ndis knew
you
> were part of the data flow.
>
> If you are merely querying the packet from ndis through IoCallDriver or
> DeviceIoControl then ndis assumes you are done with it when you return.
> Futhermore modifications you make to the ndis packet may or may not be
> passed on to other ndis drivers. This is why you should register your
> driver with ndis during initialization and support one of the ndis driver
> types.
>
> This is a simplification because protocols often allocate data in their
own
> buffer pools and perform buffer integrity checks (like checking the
internal
> pointers of complex structures). Miniports often use memory on the card
to
> reduce the number of buffer copies. So if you are going to change some of
> the internal pointers in the ndis packet structure you may want to create
> your own copy if you can't re-assign the original pointer value when the
> consumer returns. I haven't played with this in over a year so please
> perform your own tests.
>
> Have a great day
> Bill
>
> "Rajesh Gupta" <guptar@gmail.com> wrote in message
> news:uXzZ5dWWEHA.3988@tk2msftngp13.phx.gbl...
> > Hi everyone,
> >
> > I am trying to modify the NDIS packet. Do i need to allocate new
buffers?
> >
>
>