DPDK usage discussions
 help / color / mirror / Atom feed
* [dpdk-users] How to change IP and port in packet header and recalculate checksum
@ 2016-04-09 10:34 Murad Kablan
  2016-04-09 13:45 ` Jesper Wramberg
  0 siblings, 1 reply; 5+ messages in thread
From: Murad Kablan @ 2016-04-09 10:34 UTC (permalink / raw)
  To: users

Hi,
I'm trying to change the IP and port of packets before sending them out.
The captured packet in the receiving machines seems to be corrupted as the
port is different than the one I inserted. Am I doing the checksum right?
And do I need to do other HW configurations?

This is my code:
struct udp_hdr *udp_h;
struct ipv4_hdr *ipv4_h;
struct ether_hdr *eth_hdr;
eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
ipv4_h = (struct ipv4_hdr *)(eth_hdr + 1);
udp_h = (struct udp_hdr *)((unsigned char *)ipv4_h + sizeof(struct
ipv4_hdr));

ipv4_h->dst_addr  = 6777226 //(gateway-ip 10.77.0.51)
udp_h->src_port = 88
ipv4_h->hdr_checksum = 0;
udp_h->dgram_cksum = 0;
udp_h->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_h, udp_h);
ipv4_h->hdr_checksum = rte_ipv4_cksum(ipv4_h);
l2fwd_simple_forward(m, 0);

Thanks,

Murad

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-users] How to change IP and port in packet header and recalculate checksum
  2016-04-09 10:34 [dpdk-users] How to change IP and port in packet header and recalculate checksum Murad Kablan
@ 2016-04-09 13:45 ` Jesper Wramberg
  2016-04-09 15:36   ` Murad Kablan
  0 siblings, 1 reply; 5+ messages in thread
From: Jesper Wramberg @ 2016-04-09 13:45 UTC (permalink / raw)
  To: Murad.Kablan; +Cc: users

Hey Murad,

Are you running DPDK on the receiving end as well ?
In any case, I'm guessing you forgot to convert to network byte order ? :-)



2016-04-09 12:34 GMT+02:00 Murad Kablan <Murad.Kablan@colorado.edu>:

> Hi,
> I'm trying to change the IP and port of packets before sending them out.
> The captured packet in the receiving machines seems to be corrupted as the
> port is different than the one I inserted. Am I doing the checksum right?
> And do I need to do other HW configurations?
>
> This is my code:
> struct udp_hdr *udp_h;
> struct ipv4_hdr *ipv4_h;
> struct ether_hdr *eth_hdr;
> eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
> ipv4_h = (struct ipv4_hdr *)(eth_hdr + 1);
> udp_h = (struct udp_hdr *)((unsigned char *)ipv4_h + sizeof(struct
> ipv4_hdr));
>
> ipv4_h->dst_addr  = 6777226 //(gateway-ip 10.77.0.51)
> udp_h->src_port = 88
> ipv4_h->hdr_checksum = 0;
> udp_h->dgram_cksum = 0;
> udp_h->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_h, udp_h);
> ipv4_h->hdr_checksum = rte_ipv4_cksum(ipv4_h);
> l2fwd_simple_forward(m, 0);
>
> Thanks,
>
> Murad
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-users] How to change IP and port in packet header and recalculate checksum
  2016-04-09 13:45 ` Jesper Wramberg
@ 2016-04-09 15:36   ` Murad Kablan
  2016-04-09 18:41     ` Jesper Wramberg
  0 siblings, 1 reply; 5+ messages in thread
From: Murad Kablan @ 2016-04-09 15:36 UTC (permalink / raw)
  To: Jesper Wramberg; +Cc: users

Hi Jesper,
I'm not running DPDK on the receiving side. Just tcpdump.
Can you please be more specific? What and how to convert to network byte
order?

Thanks
On Apr 9, 2016 7:45 AM, "Jesper Wramberg" <jesper.wramberg@gmail.com> wrote:

> Hey Murad,
>
> Are you running DPDK on the receiving end as well ?
> In any case, I'm guessing you forgot to convert to network byte order ? :-)
>
>
>
> 2016-04-09 12:34 GMT+02:00 Murad Kablan <Murad.Kablan@colorado.edu>:
>
>> Hi,
>> I'm trying to change the IP and port of packets before sending them out.
>> The captured packet in the receiving machines seems to be corrupted as the
>> port is different than the one I inserted. Am I doing the checksum right?
>> And do I need to do other HW configurations?
>>
>> This is my code:
>> struct udp_hdr *udp_h;
>> struct ipv4_hdr *ipv4_h;
>> struct ether_hdr *eth_hdr;
>> eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
>> ipv4_h = (struct ipv4_hdr *)(eth_hdr + 1);
>> udp_h = (struct udp_hdr *)((unsigned char *)ipv4_h + sizeof(struct
>> ipv4_hdr));
>>
>> ipv4_h->dst_addr  = 6777226 //(gateway-ip 10.77.0.51)
>> udp_h->src_port = 88
>> ipv4_h->hdr_checksum = 0;
>> udp_h->dgram_cksum = 0;
>> udp_h->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_h, udp_h);
>> ipv4_h->hdr_checksum = rte_ipv4_cksum(ipv4_h);
>> l2fwd_simple_forward(m, 0);
>>
>> Thanks,
>>
>> Murad
>>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-users] How to change IP and port in packet header and recalculate checksum
  2016-04-09 15:36   ` Murad Kablan
@ 2016-04-09 18:41     ` Jesper Wramberg
  2016-04-10 18:06       ` Murad Kablan
  0 siblings, 1 reply; 5+ messages in thread
From: Jesper Wramberg @ 2016-04-09 18:41 UTC (permalink / raw)
  To: Murad Kablan; +Cc: users

Assuming you are working on a standard Intel architecture or alike, the
constants you write are stored in little endian.
Network byte order is big endian, so for the UDP port (which is 16 bit
large) your code would be:

udp_h->src_port = rte_cpu_to_be_16(88);

Unless you actually want the port to be read as 22528 by the receiver ;-)
Check out the DPDK byte order API for your other constants.

2016-04-09 17:36 GMT+02:00 Murad Kablan <Murad.Kablan@colorado.edu>:

> Hi Jesper,
> I'm not running DPDK on the receiving side. Just tcpdump.
> Can you please be more specific? What and how to convert to network byte
> order?
>
> Thanks
> On Apr 9, 2016 7:45 AM, "Jesper Wramberg" <jesper.wramberg@gmail.com>
> wrote:
>
>> Hey Murad,
>>
>> Are you running DPDK on the receiving end as well ?
>> In any case, I'm guessing you forgot to convert to network byte order ?
>> :-)
>>
>>
>>
>> 2016-04-09 12:34 GMT+02:00 Murad Kablan <Murad.Kablan@colorado.edu>:
>>
>>> Hi,
>>> I'm trying to change the IP and port of packets before sending them out.
>>> The captured packet in the receiving machines seems to be corrupted as
>>> the
>>> port is different than the one I inserted. Am I doing the checksum right?
>>> And do I need to do other HW configurations?
>>>
>>> This is my code:
>>> struct udp_hdr *udp_h;
>>> struct ipv4_hdr *ipv4_h;
>>> struct ether_hdr *eth_hdr;
>>> eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
>>> ipv4_h = (struct ipv4_hdr *)(eth_hdr + 1);
>>> udp_h = (struct udp_hdr *)((unsigned char *)ipv4_h + sizeof(struct
>>> ipv4_hdr));
>>>
>>> ipv4_h->dst_addr  = 6777226 //(gateway-ip 10.77.0.51)
>>> udp_h->src_port = 88
>>> ipv4_h->hdr_checksum = 0;
>>> udp_h->dgram_cksum = 0;
>>> udp_h->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_h, udp_h);
>>> ipv4_h->hdr_checksum = rte_ipv4_cksum(ipv4_h);
>>> l2fwd_simple_forward(m, 0);
>>>
>>> Thanks,
>>>
>>> Murad
>>>
>>
>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-users] How to change IP and port in packet header and recalculate checksum
  2016-04-09 18:41     ` Jesper Wramberg
@ 2016-04-10 18:06       ` Murad Kablan
  0 siblings, 0 replies; 5+ messages in thread
From: Murad Kablan @ 2016-04-10 18:06 UTC (permalink / raw)
  To: Jesper Wramberg; +Cc: users

I see what you are saying now. I tried your solution and it works.

Thanks a lot!
On Apr 9, 2016 12:41 PM, "Jesper Wramberg" <jesper.wramberg@gmail.com>
wrote:

> Assuming you are working on a standard Intel architecture or alike, the
> constants you write are stored in little endian.
> Network byte order is big endian, so for the UDP port (which is 16 bit
> large) your code would be:
>
> udp_h->src_port = rte_cpu_to_be_16(88);
>
> Unless you actually want the port to be read as 22528 by the receiver ;-)
> Check out the DPDK byte order API for your other constants.
>
> 2016-04-09 17:36 GMT+02:00 Murad Kablan <Murad.Kablan@colorado.edu>:
>
>> Hi Jesper,
>> I'm not running DPDK on the receiving side. Just tcpdump.
>> Can you please be more specific? What and how to convert to network byte
>> order?
>>
>> Thanks
>> On Apr 9, 2016 7:45 AM, "Jesper Wramberg" <jesper.wramberg@gmail.com>
>> wrote:
>>
>>> Hey Murad,
>>>
>>> Are you running DPDK on the receiving end as well ?
>>> In any case, I'm guessing you forgot to convert to network byte order ?
>>> :-)
>>>
>>>
>>>
>>> 2016-04-09 12:34 GMT+02:00 Murad Kablan <Murad.Kablan@colorado.edu>:
>>>
>>>> Hi,
>>>> I'm trying to change the IP and port of packets before sending them out.
>>>> The captured packet in the receiving machines seems to be corrupted as
>>>> the
>>>> port is different than the one I inserted. Am I doing the checksum
>>>> right?
>>>> And do I need to do other HW configurations?
>>>>
>>>> This is my code:
>>>> struct udp_hdr *udp_h;
>>>> struct ipv4_hdr *ipv4_h;
>>>> struct ether_hdr *eth_hdr;
>>>> eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
>>>> ipv4_h = (struct ipv4_hdr *)(eth_hdr + 1);
>>>> udp_h = (struct udp_hdr *)((unsigned char *)ipv4_h + sizeof(struct
>>>> ipv4_hdr));
>>>>
>>>> ipv4_h->dst_addr  = 6777226 //(gateway-ip 10.77.0.51)
>>>> udp_h->src_port = 88
>>>> ipv4_h->hdr_checksum = 0;
>>>> udp_h->dgram_cksum = 0;
>>>> udp_h->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_h, udp_h);
>>>> ipv4_h->hdr_checksum = rte_ipv4_cksum(ipv4_h);
>>>> l2fwd_simple_forward(m, 0);
>>>>
>>>> Thanks,
>>>>
>>>> Murad
>>>>
>>>
>>>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-04-10 18:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-09 10:34 [dpdk-users] How to change IP and port in packet header and recalculate checksum Murad Kablan
2016-04-09 13:45 ` Jesper Wramberg
2016-04-09 15:36   ` Murad Kablan
2016-04-09 18:41     ` Jesper Wramberg
2016-04-10 18:06       ` Murad Kablan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).