Hi All,

I am trying to modify the NDIS packet. I want to redirect the packet from
destined for 172.10.10.10 to 172.10.10.10.
steps taken to modify the packets.

1. Modify the Destination IP address.
2. Calculate the Checksum.
3. Modify the Destination MAC address.
4. Send the packet.

I have used both Network stacking and own NDIS packets.

When i tested my code, it worked on One Ethernet Adapter and it did not work
on another adapters. I do not know why.
When i captured the packet with Etherreal, it shows that the Checksum is 0
at the destination. Everything else is fine. I checked the IP address, MAC
address, then are updated.
I am calculating the right checksum and i made sure i am updating the
checksum after i modified the packet.
I am not sure, when Checksum became 0.

I do not know, if Miniport driver made it 0. Is that the posibility? if yes
then why? Is my checksum wrong? I am attaching the code to calculate
checksum here. Thanks in advance for your help.

Regards
Rajesh


/*

**************************************************************************

Function: FltIPSumCalculation

Description: Calculate the 16 bit IP sum.

***************************************************************************

*/

USHORT FltIPSumCalculation(USHORT len, PUSHORT pbuf)

{

ULONG sum=0;


while(len > 1){

sum += *pbuf++;

len -= sizeof(USHORT);

}

if(len)

sum += *(UCHAR*)pbuf;

sum = (sum >> 16) + (sum & 0xffff);

sum += (sum >> 16);

// one's complement the result

sum = ~sum;

return ((USHORT) sum);

}

Re: Problem Modifing the NDIS packet by Maxim

Maxim
Tue Jul 20 10:38:01 CDT 2004

You cannot modify NDIS_PACKET in place.

You will need to allocate another NDIS_PACKET and another NDIS_BUFFER+the
data area for the update data, and re-link the buffer chain to the new
NDIS_PACKET.

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


"Rajesh Gupta" <guptar@gmail.com> wrote in message
news:%23gmxgymbEHA.252@TK2MSFTNGP10.phx.gbl...
> Hi All,
>
> I am trying to modify the NDIS packet. I want to redirect the packet from
> destined for 172.10.10.10 to 172.10.10.10.
> steps taken to modify the packets.
>
> 1. Modify the Destination IP address.
> 2. Calculate the Checksum.
> 3. Modify the Destination MAC address.
> 4. Send the packet.
>
> I have used both Network stacking and own NDIS packets.
>
> When i tested my code, it worked on One Ethernet Adapter and it did not work
> on another adapters. I do not know why.
> When i captured the packet with Etherreal, it shows that the Checksum is 0
> at the destination. Everything else is fine. I checked the IP address, MAC
> address, then are updated.
> I am calculating the right checksum and i made sure i am updating the
> checksum after i modified the packet.
> I am not sure, when Checksum became 0.
>
> I do not know, if Miniport driver made it 0. Is that the posibility? if yes
> then why? Is my checksum wrong? I am attaching the code to calculate
> checksum here. Thanks in advance for your help.
>
> Regards
> Rajesh
>
>
> /*
>
> **************************************************************************
>
> Function: FltIPSumCalculation
>
> Description: Calculate the 16 bit IP sum.
>
> ***************************************************************************
>
> */
>
> USHORT FltIPSumCalculation(USHORT len, PUSHORT pbuf)
>
> {
>
> ULONG sum=0;
>
>
> while(len > 1){
>
> sum += *pbuf++;
>
> len -= sizeof(USHORT);
>
> }
>
> if(len)
>
> sum += *(UCHAR*)pbuf;
>
> sum = (sum >> 16) + (sum & 0xffff);
>
> sum += (sum >> 16);
>
> // one's complement the result
>
> sum = ~sum;
>
> return ((USHORT) sum);
>
> }
>
>



Re: Problem Modifing the NDIS packet by Rajesh

Rajesh
Tue Jul 20 11:46:59 CDT 2004

Hi Maxim,

Thanks a lot for your response. I did not modify the NDIS_PACKET in place.

1. Allocate a send Packet buffer.
2. Allocate the buffer, i got this buffer size by quering the NDIS buffer.
(i am chaining only one buffer, even if original NDIS-PACKET has more than
one)
3. Copy all the data into this allocated buffer.
4. Modified the desired buffer contains.
5. Copied all the OOB, and other information.
6. Chained the buffer in the packet
7. and send it.

i did follow all these steps. Only while using the Network Stacking in 5.1,
i am trying to modify the NDIS-PACKET. I tested both, i am not sure why it
does not work for Intel adapter and it works for VIA adapter.

Thanks
Rajesh

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:OblZJ%23mbEHA.2468@TK2MSFTNGP09.phx.gbl...
> You cannot modify NDIS_PACKET in place.
>
> You will need to allocate another NDIS_PACKET and another
NDIS_BUFFER+the
> data area for the update data, and re-link the buffer chain to the new
> NDIS_PACKET.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>
> "Rajesh Gupta" <guptar@gmail.com> wrote in message
> news:%23gmxgymbEHA.252@TK2MSFTNGP10.phx.gbl...
> > Hi All,
> >
> > I am trying to modify the NDIS packet. I want to redirect the packet
from
> > destined for 172.10.10.10 to 172.10.10.10.
> > steps taken to modify the packets.
> >
> > 1. Modify the Destination IP address.
> > 2. Calculate the Checksum.
> > 3. Modify the Destination MAC address.
> > 4. Send the packet.
> >
> > I have used both Network stacking and own NDIS packets.
> >
> > When i tested my code, it worked on One Ethernet Adapter and it did not
work
> > on another adapters. I do not know why.
> > When i captured the packet with Etherreal, it shows that the Checksum is
0
> > at the destination. Everything else is fine. I checked the IP address,
MAC
> > address, then are updated.
> > I am calculating the right checksum and i made sure i am updating the
> > checksum after i modified the packet.
> > I am not sure, when Checksum became 0.
> >
> > I do not know, if Miniport driver made it 0. Is that the posibility? if
yes
> > then why? Is my checksum wrong? I am attaching the code to calculate
> > checksum here. Thanks in advance for your help.
> >
> > Regards
> > Rajesh
> >
> >
> > /*
> >
> >
**************************************************************************
> >
> > Function: FltIPSumCalculation
> >
> > Description: Calculate the 16 bit IP sum.
> >
> >
***************************************************************************
> >
> > */
> >
> > USHORT FltIPSumCalculation(USHORT len, PUSHORT pbuf)
> >
> > {
> >
> > ULONG sum=0;
> >
> >
> > while(len > 1){
> >
> > sum += *pbuf++;
> >
> > len -= sizeof(USHORT);
> >
> > }
> >
> > if(len)
> >
> > sum += *(UCHAR*)pbuf;
> >
> > sum = (sum >> 16) + (sum & 0xffff);
> >
> > sum += (sum >> 16);
> >
> > // one's complement the result
> >
> > sum = ~sum;
> >
> > return ((USHORT) sum);
> >
> > }
> >
> >
>
>



Re: Problem Modifing the NDIS packet by Maxim

Maxim
Tue Jul 20 11:53:26 CDT 2004

See the PASSTHRU and MUX samples for details in this procedure.

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

"Rajesh Gupta" <guptar@gmail.com> wrote in message
news:%23GOOtknbEHA.3596@tk2msftngp13.phx.gbl...
> Hi Maxim,
>
> Thanks a lot for your response. I did not modify the NDIS_PACKET in place.
>
> 1. Allocate a send Packet buffer.
> 2. Allocate the buffer, i got this buffer size by quering the NDIS buffer.
> (i am chaining only one buffer, even if original NDIS-PACKET has more than
> one)
> 3. Copy all the data into this allocated buffer.
> 4. Modified the desired buffer contains.
> 5. Copied all the OOB, and other information.
> 6. Chained the buffer in the packet
> 7. and send it.
>
> i did follow all these steps. Only while using the Network Stacking in 5.1,
> i am trying to modify the NDIS-PACKET. I tested both, i am not sure why it
> does not work for Intel adapter and it works for VIA adapter.
>
> Thanks
> Rajesh
>
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> news:OblZJ%23mbEHA.2468@TK2MSFTNGP09.phx.gbl...
> > You cannot modify NDIS_PACKET in place.
> >
> > You will need to allocate another NDIS_PACKET and another
> NDIS_BUFFER+the
> > data area for the update data, and re-link the buffer chain to the new
> > NDIS_PACKET.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim@storagecraft.com
> > http://www.storagecraft.com
> >
> >
> > "Rajesh Gupta" <guptar@gmail.com> wrote in message
> > news:%23gmxgymbEHA.252@TK2MSFTNGP10.phx.gbl...
> > > Hi All,
> > >
> > > I am trying to modify the NDIS packet. I want to redirect the packet
> from
> > > destined for 172.10.10.10 to 172.10.10.10.
> > > steps taken to modify the packets.
> > >
> > > 1. Modify the Destination IP address.
> > > 2. Calculate the Checksum.
> > > 3. Modify the Destination MAC address.
> > > 4. Send the packet.
> > >
> > > I have used both Network stacking and own NDIS packets.
> > >
> > > When i tested my code, it worked on One Ethernet Adapter and it did not
> work
> > > on another adapters. I do not know why.
> > > When i captured the packet with Etherreal, it shows that the Checksum is
> 0
> > > at the destination. Everything else is fine. I checked the IP address,
> MAC
> > > address, then are updated.
> > > I am calculating the right checksum and i made sure i am updating the
> > > checksum after i modified the packet.
> > > I am not sure, when Checksum became 0.
> > >
> > > I do not know, if Miniport driver made it 0. Is that the posibility? if
> yes
> > > then why? Is my checksum wrong? I am attaching the code to calculate
> > > checksum here. Thanks in advance for your help.
> > >
> > > Regards
> > > Rajesh
> > >
> > >
> > > /*
> > >
> > >
> **************************************************************************
> > >
> > > Function: FltIPSumCalculation
> > >
> > > Description: Calculate the 16 bit IP sum.
> > >
> > >
> ***************************************************************************
> > >
> > > */
> > >
> > > USHORT FltIPSumCalculation(USHORT len, PUSHORT pbuf)
> > >
> > > {
> > >
> > > ULONG sum=0;
> > >
> > >
> > > while(len > 1){
> > >
> > > sum += *pbuf++;
> > >
> > > len -= sizeof(USHORT);
> > >
> > > }
> > >
> > > if(len)
> > >
> > > sum += *(UCHAR*)pbuf;
> > >
> > > sum = (sum >> 16) + (sum & 0xffff);
> > >
> > > sum += (sum >> 16);
> > >
> > > // one's complement the result
> > >
> > > sum = ~sum;
> > >
> > > return ((USHORT) sum);
> > >
> > > }
> > >
> > >
> >
> >
>
>



Re: Problem Modifing the NDIS packet by Rajesh

Rajesh
Tue Jul 20 12:24:35 CDT 2004

Maxim,

I have modified the Passthru sample.

If i do not change anything in my packet(packet and buffer allocated by me).
Then everything works fine. So i think my created packet and allocated
buffer is fine.

I am modifing the received packet as well. Receive packet modification
works. I am using the same code to modify the receive packet.
I am facing the problem only when i am modifing the send packet. I am not
sure, what is happening.

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:OoqTSonbEHA.636@TK2MSFTNGP12.phx.gbl...
> See the PASSTHRU and MUX samples for details in this procedure.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
> "Rajesh Gupta" <guptar@gmail.com> wrote in message
> news:%23GOOtknbEHA.3596@tk2msftngp13.phx.gbl...
> > Hi Maxim,
> >
> > Thanks a lot for your response. I did not modify the NDIS_PACKET in
place.
> >
> > 1. Allocate a send Packet buffer.
> > 2. Allocate the buffer, i got this buffer size by quering the NDIS
buffer.
> > (i am chaining only one buffer, even if original NDIS-PACKET has more
than
> > one)
> > 3. Copy all the data into this allocated buffer.
> > 4. Modified the desired buffer contains.
> > 5. Copied all the OOB, and other information.
> > 6. Chained the buffer in the packet
> > 7. and send it.
> >
> > i did follow all these steps. Only while using the Network Stacking in
5.1,
> > i am trying to modify the NDIS-PACKET. I tested both, i am not sure why
it
> > does not work for Intel adapter and it works for VIA adapter.
> >
> > Thanks
> > Rajesh
> >
> > "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> > news:OblZJ%23mbEHA.2468@TK2MSFTNGP09.phx.gbl...
> > > You cannot modify NDIS_PACKET in place.
> > >
> > > You will need to allocate another NDIS_PACKET and another
> > NDIS_BUFFER+the
> > > data area for the update data, and re-link the buffer chain to the new
> > > NDIS_PACKET.
> > >
> > > --
> > > Maxim Shatskih, Windows DDK MVP
> > > StorageCraft Corporation
> > > maxim@storagecraft.com
> > > http://www.storagecraft.com
> > >
> > >
> > > "Rajesh Gupta" <guptar@gmail.com> wrote in message
> > > news:%23gmxgymbEHA.252@TK2MSFTNGP10.phx.gbl...
> > > > Hi All,
> > > >
> > > > I am trying to modify the NDIS packet. I want to redirect the packet
> > from
> > > > destined for 172.10.10.10 to 172.10.10.10.
> > > > steps taken to modify the packets.
> > > >
> > > > 1. Modify the Destination IP address.
> > > > 2. Calculate the Checksum.
> > > > 3. Modify the Destination MAC address.
> > > > 4. Send the packet.
> > > >
> > > > I have used both Network stacking and own NDIS packets.
> > > >
> > > > When i tested my code, it worked on One Ethernet Adapter and it did
not
> > work
> > > > on another adapters. I do not know why.
> > > > When i captured the packet with Etherreal, it shows that the
Checksum is
> > 0
> > > > at the destination. Everything else is fine. I checked the IP
address,
> > MAC
> > > > address, then are updated.
> > > > I am calculating the right checksum and i made sure i am updating
the
> > > > checksum after i modified the packet.
> > > > I am not sure, when Checksum became 0.
> > > >
> > > > I do not know, if Miniport driver made it 0. Is that the posibility?
if
> > yes
> > > > then why? Is my checksum wrong? I am attaching the code to calculate
> > > > checksum here. Thanks in advance for your help.
> > > >
> > > > Regards
> > > > Rajesh
> > > >
> > > >
> > > > /*
> > > >
> > > >
> >
**************************************************************************
> > > >
> > > > Function: FltIPSumCalculation
> > > >
> > > > Description: Calculate the 16 bit IP sum.
> > > >
> > > >
> >
***************************************************************************
> > > >
> > > > */
> > > >
> > > > USHORT FltIPSumCalculation(USHORT len, PUSHORT pbuf)
> > > >
> > > > {
> > > >
> > > > ULONG sum=0;
> > > >
> > > >
> > > > while(len > 1){
> > > >
> > > > sum += *pbuf++;
> > > >
> > > > len -= sizeof(USHORT);
> > > >
> > > > }
> > > >
> > > > if(len)
> > > >
> > > > sum += *(UCHAR*)pbuf;
> > > >
> > > > sum = (sum >> 16) + (sum & 0xffff);
> > > >
> > > > sum += (sum >> 16);
> > > >
> > > > // one's complement the result
> > > >
> > > > sum = ~sum;
> > > >
> > > > return ((USHORT) sum);
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: Problem Modifing the NDIS packet by Rajesh

Rajesh
Tue Jul 20 16:08:53 CDT 2004

Thanks everyone.

I was having problem with NDIS Task Offload. It works now.

Thanks everyone, if someone has the same problem, hope it helps.

"Rajesh Gupta" <guptar@gmail.com> wrote in message
news:eiEtv5nbEHA.2940@TK2MSFTNGP10.phx.gbl...
> Maxim,
>
> I have modified the Passthru sample.
>
> If i do not change anything in my packet(packet and buffer allocated by
me).
> Then everything works fine. So i think my created packet and allocated
> buffer is fine.
>
> I am modifing the received packet as well. Receive packet modification
> works. I am using the same code to modify the receive packet.
> I am facing the problem only when i am modifing the send packet. I am not
> sure, what is happening.
>
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> news:OoqTSonbEHA.636@TK2MSFTNGP12.phx.gbl...
> > See the PASSTHRU and MUX samples for details in this procedure.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim@storagecraft.com
> > http://www.storagecraft.com
> >
> > "Rajesh Gupta" <guptar@gmail.com> wrote in message
> > news:%23GOOtknbEHA.3596@tk2msftngp13.phx.gbl...
> > > Hi Maxim,
> > >
> > > Thanks a lot for your response. I did not modify the NDIS_PACKET in
> place.
> > >
> > > 1. Allocate a send Packet buffer.
> > > 2. Allocate the buffer, i got this buffer size by quering the NDIS
> buffer.
> > > (i am chaining only one buffer, even if original NDIS-PACKET has more
> than
> > > one)
> > > 3. Copy all the data into this allocated buffer.
> > > 4. Modified the desired buffer contains.
> > > 5. Copied all the OOB, and other information.
> > > 6. Chained the buffer in the packet
> > > 7. and send it.
> > >
> > > i did follow all these steps. Only while using the Network Stacking in
> 5.1,
> > > i am trying to modify the NDIS-PACKET. I tested both, i am not sure
why
> it
> > > does not work for Intel adapter and it works for VIA adapter.
> > >
> > > Thanks
> > > Rajesh
> > >
> > > "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> > > news:OblZJ%23mbEHA.2468@TK2MSFTNGP09.phx.gbl...
> > > > You cannot modify NDIS_PACKET in place.
> > > >
> > > > You will need to allocate another NDIS_PACKET and another
> > > NDIS_BUFFER+the
> > > > data area for the update data, and re-link the buffer chain to the
new
> > > > NDIS_PACKET.
> > > >
> > > > --
> > > > Maxim Shatskih, Windows DDK MVP
> > > > StorageCraft Corporation
> > > > maxim@storagecraft.com
> > > > http://www.storagecraft.com
> > > >
> > > >
> > > > "Rajesh Gupta" <guptar@gmail.com> wrote in message
> > > > news:%23gmxgymbEHA.252@TK2MSFTNGP10.phx.gbl...
> > > > > Hi All,
> > > > >
> > > > > I am trying to modify the NDIS packet. I want to redirect the
packet
> > > from
> > > > > destined for 172.10.10.10 to 172.10.10.10.
> > > > > steps taken to modify the packets.
> > > > >
> > > > > 1. Modify the Destination IP address.
> > > > > 2. Calculate the Checksum.
> > > > > 3. Modify the Destination MAC address.
> > > > > 4. Send the packet.
> > > > >
> > > > > I have used both Network stacking and own NDIS packets.
> > > > >
> > > > > When i tested my code, it worked on One Ethernet Adapter and it
did
> not
> > > work
> > > > > on another adapters. I do not know why.
> > > > > When i captured the packet with Etherreal, it shows that the
> Checksum is
> > > 0
> > > > > at the destination. Everything else is fine. I checked the IP
> address,
> > > MAC
> > > > > address, then are updated.
> > > > > I am calculating the right checksum and i made sure i am updating
> the
> > > > > checksum after i modified the packet.
> > > > > I am not sure, when Checksum became 0.
> > > > >
> > > > > I do not know, if Miniport driver made it 0. Is that the
posibility?
> if
> > > yes
> > > > > then why? Is my checksum wrong? I am attaching the code to
calculate
> > > > > checksum here. Thanks in advance for your help.
> > > > >
> > > > > Regards
> > > > > Rajesh
> > > > >
> > > > >
> > > > > /*
> > > > >
> > > > >
> > >
> **************************************************************************
> > > > >
> > > > > Function: FltIPSumCalculation
> > > > >
> > > > > Description: Calculate the 16 bit IP sum.
> > > > >
> > > > >
> > >
>
***************************************************************************
> > > > >
> > > > > */
> > > > >
> > > > > USHORT FltIPSumCalculation(USHORT len, PUSHORT pbuf)
> > > > >
> > > > > {
> > > > >
> > > > > ULONG sum=0;
> > > > >
> > > > >
> > > > > while(len > 1){
> > > > >
> > > > > sum += *pbuf++;
> > > > >
> > > > > len -= sizeof(USHORT);
> > > > >
> > > > > }
> > > > >
> > > > > if(len)
> > > > >
> > > > > sum += *(UCHAR*)pbuf;
> > > > >
> > > > > sum = (sum >> 16) + (sum & 0xffff);
> > > > >
> > > > > sum += (sum >> 16);
> > > > >
> > > > > // one's complement the result
> > > > >
> > > > > sum = ~sum;
> > > > >
> > > > > return ((USHORT) sum);
> > > > >
> > > > > }
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



RE: Problem Modifing the NDIS packet by bburgin

bburgin
Tue Jul 20 18:31:25 CDT 2004

------=_NextPart_0001_6F3C8591
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Does one card support checksum offload and the other does not?

Bryan S. Burgin
bburgin@microsoft.com

This posting is provided "AS IS" with no warranties, and confers no rights.
------=_NextPart_0001_6F3C8591
Content-Type: text/x-rtf
Content-Transfer-Encoding: 7bit

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 Does one card support checksum offload and the other does not?
\par
\par Bryan S. Burgin
\par bburgin@microsoft.com
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par }
------=_NextPart_0001_6F3C8591--


Re: Problem Modifing the NDIS packet by Rajesh

Rajesh
Tue Jul 20 18:49:45 CDT 2004

Yes Bryam,

One card does and another does not. Thats why i was having problem.

if(checksum == 0)
{
// do nothing..
}else
{
//calculate the new checksum
}

Is this reliable? Or do i need to block/Query the checksum offload OID.

thanks
Rajesh

""Bryan S. Burgin [MSFT]"" <bburgin@online.microsoft.com> wrote in message
news:eQvvzGrbEHA.3848@cpmsftngxa06.phx.gbl...
> Does one card support checksum offload and the other does not?
>
> Bryan S. Burgin
> bburgin@microsoft.com
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.



Re: Problem Modifing the NDIS packet by Stephan

Stephan
Wed Jul 21 05:32:06 CDT 2004

If you modify a send packet the IP and TCP checksums need to be
corrected. If the NIC has support for Checksum Task Offload (CTO) (for
the send side) you're done. Otherwise your IM driver needs to adjust
the checksum(s) before passing the send packet down to the miniport.

On the receive side, if you maniulate packet contents, you should set
both the "Failed" and "Succeeded" CTO bits to FALSE. That forces the
TCP/IP stack to calculate the checksum.

Also always set to FALSE for NICs that do not support CTO.

Stephan
---
On Tue, 20 Jul 2004 16:49:45 -0700, "Rajesh Gupta" <guptar@gmail.com>
wrote:

>Yes Bryam,
>
>One card does and another does not. Thats why i was having problem.
>
>if(checksum == 0)
>{
>// do nothing..
>}else
>{
>//calculate the new checksum
>}
>
>Is this reliable? Or do i need to block/Query the checksum offload OID.
>
>thanks
>Rajesh