DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies
@ 2015-05-22 11:07 Adrien Mazarguil
  2015-05-22 11:07 ` [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies Adrien Mazarguil
  2015-05-29 16:11 ` [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Thomas Monjalon
  0 siblings, 2 replies; 7+ messages in thread
From: Adrien Mazarguil @ 2015-05-22 11:07 UTC (permalink / raw)
  To: dev

In the icmpecho forwarding mode, ARP replies from testpmd contain
invalid zero-filled MAC addresses. This is broken since the commit below.

Fixes: 31db4d38de72 ("net: change arp header struct declaration")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Acked-by: Ivan Boule <ivan.boule@6wind.com>
---
 app/test-pmd/icmpecho.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index 010c5a9..c5933f4 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -400,7 +400,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 			arp_h->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY);
 			ether_addr_copy(&arp_h->arp_data.arp_tha, &eth_addr);
 			ether_addr_copy(&arp_h->arp_data.arp_sha, &arp_h->arp_data.arp_tha);
-			ether_addr_copy(&eth_addr, &arp_h->arp_data.arp_sha);
+			ether_addr_copy(&eth_h->s_addr, &arp_h->arp_data.arp_sha);
 
 			/* Swap IP addresses in ARP payload */
 			ip_addr = arp_h->arp_data.arp_sip;
-- 
2.1.0

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

* [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies
  2015-05-22 11:07 [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Adrien Mazarguil
@ 2015-05-22 11:07 ` Adrien Mazarguil
  2015-05-22 12:42   ` Olivier MATZ
  2015-05-22 17:03   ` [dpdk-dev] [PATCH v2] " Adrien Mazarguil
  2015-05-29 16:11 ` [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Thomas Monjalon
  1 sibling, 2 replies; 7+ messages in thread
From: Adrien Mazarguil @ 2015-05-22 11:07 UTC (permalink / raw)
  To: dev

ICMP echo replies with invalid checksums may be dropped by network nodes or
ignored by the ping utility.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Acked-by: Ivan Boule <ivan.boule@6wind.com>
---
 app/test-pmd/icmpecho.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index c5933f4..c278baf 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -445,7 +445,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		 * - switch IPv4 source and destinations addresses,
 		 * - set IP_ICMP_ECHO_REPLY in ICMP header.
 		 * No need to re-compute the IP header checksum.
-		 * Reset ICMP checksum.
+		 * ICMP checksum is computed by assuming it is valid in the
+		 * echo request and not verified.
 		 */
 		ether_addr_copy(&eth_h->s_addr, &eth_addr);
 		ether_addr_copy(&eth_h->d_addr, &eth_h->s_addr);
@@ -454,7 +455,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		ip_h->src_addr = ip_h->dst_addr;
 		ip_h->dst_addr = ip_addr;
 		icmp_h->icmp_type = IP_ICMP_ECHO_REPLY;
-		icmp_h->icmp_cksum = 0;
+		icmp_h->icmp_cksum += htons(IP_ICMP_ECHO_REQUEST << 8);
 		pkts_burst[nb_replies++] = pkt;
 	}
 
-- 
2.1.0

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

* Re: [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies
  2015-05-22 11:07 ` [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies Adrien Mazarguil
@ 2015-05-22 12:42   ` Olivier MATZ
  2015-05-22 13:34     ` Adrien Mazarguil
  2015-05-22 17:03   ` [dpdk-dev] [PATCH v2] " Adrien Mazarguil
  1 sibling, 1 reply; 7+ messages in thread
From: Olivier MATZ @ 2015-05-22 12:42 UTC (permalink / raw)
  To: Adrien Mazarguil, dev

Hi Adrien,

On 05/22/2015 01:07 PM, Adrien Mazarguil wrote:
> ICMP echo replies with invalid checksums may be dropped by network nodes or
> ignored by the ping utility.
> 
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> Acked-by: Ivan Boule <ivan.boule@6wind.com>
> ---
>  app/test-pmd/icmpecho.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
> index c5933f4..c278baf 100644
> --- a/app/test-pmd/icmpecho.c
> +++ b/app/test-pmd/icmpecho.c
> @@ -445,7 +445,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
>  		 * - switch IPv4 source and destinations addresses,
>  		 * - set IP_ICMP_ECHO_REPLY in ICMP header.
>  		 * No need to re-compute the IP header checksum.
> -		 * Reset ICMP checksum.
> +		 * ICMP checksum is computed by assuming it is valid in the
> +		 * echo request and not verified.
>  		 */
>  		ether_addr_copy(&eth_h->s_addr, &eth_addr);
>  		ether_addr_copy(&eth_h->d_addr, &eth_h->s_addr);
> @@ -454,7 +455,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
>  		ip_h->src_addr = ip_h->dst_addr;
>  		ip_h->dst_addr = ip_addr;
>  		icmp_h->icmp_type = IP_ICMP_ECHO_REPLY;
> -		icmp_h->icmp_cksum = 0;
> +		icmp_h->icmp_cksum += htons(IP_ICMP_ECHO_REQUEST << 8);


I don't think this checksum calculation method is always correct.

Example of a working case:

>>> p=Ether(str(Ether()/IP()/ICMP(seq=0)))
>>> p
<Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>
>>> del(p[ICMP].chksum)
>>> p[ICMP].type = 0
>>> p=Ether(str(p))
>>> p
<Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
type=echo-reply code=0 chksum=0xffff id=0x0 seq=0x0 |>>>

We have 0xffff - 0xf7ff = 0x0800


Example of a non-working case:

>>> p=Ether(str(Ether()/IP()/ICMP(seq=0xf800)))
>>> p
<Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
type=echo-request code=0 chksum=0xfffe id=0x0 seq=0xf800 |>>>
>>> del(p[ICMP].chksum)
>>> p[ICMP].type = 0
>>> p=Ether(str(p))
>>> p
<Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
type=echo-reply code=0 chksum=0x7ff id=0x0 seq=0xf800 |>>>

Here, 0x7ff - 0xfffe != 0x08000


A correct solution (not tested) would be something like:

	uint32_t cksum;
	cksum = (~(icmp_h->icmp_cksum)) & 0xffff;
	cksum += (~htons(IP_ICMP_ECHO_REQUEST << 8)) & 0xffff;
	cksum += (htons(IP_ICMP_ECHO_REPLY << 8)) & 0xffff;
	cksum = (cksum & 0xffff) + (cksum >> 16);
	cksum = (cksum & 0xffff) + (cksum >> 16);
	icmp_h->icmp_cksum = (~cksum) & 0xffff;

Regards,
Olivier


>  		pkts_burst[nb_replies++] = pkt;
>  	}
>  
> 

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

* Re: [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies
  2015-05-22 12:42   ` Olivier MATZ
@ 2015-05-22 13:34     ` Adrien Mazarguil
  0 siblings, 0 replies; 7+ messages in thread
From: Adrien Mazarguil @ 2015-05-22 13:34 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

On Fri, May 22, 2015 at 02:42:08PM +0200, Olivier MATZ wrote:
> Hi Adrien,

Hi Olivier,

> On 05/22/2015 01:07 PM, Adrien Mazarguil wrote:
> > ICMP echo replies with invalid checksums may be dropped by network nodes or
> > ignored by the ping utility.
> > 
> > Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> > Acked-by: Ivan Boule <ivan.boule@6wind.com>
> > ---
> >  app/test-pmd/icmpecho.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
> > index c5933f4..c278baf 100644
> > --- a/app/test-pmd/icmpecho.c
> > +++ b/app/test-pmd/icmpecho.c
> > @@ -445,7 +445,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
> >  		 * - switch IPv4 source and destinations addresses,
> >  		 * - set IP_ICMP_ECHO_REPLY in ICMP header.
> >  		 * No need to re-compute the IP header checksum.
> > -		 * Reset ICMP checksum.
> > +		 * ICMP checksum is computed by assuming it is valid in the
> > +		 * echo request and not verified.
> >  		 */
> >  		ether_addr_copy(&eth_h->s_addr, &eth_addr);
> >  		ether_addr_copy(&eth_h->d_addr, &eth_h->s_addr);
> > @@ -454,7 +455,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
> >  		ip_h->src_addr = ip_h->dst_addr;
> >  		ip_h->dst_addr = ip_addr;
> >  		icmp_h->icmp_type = IP_ICMP_ECHO_REPLY;
> > -		icmp_h->icmp_cksum = 0;
> > +		icmp_h->icmp_cksum += htons(IP_ICMP_ECHO_REQUEST << 8);
> 
> 
> I don't think this checksum calculation method is always correct.
> 
> Example of a working case:
> 
> >>> p=Ether(str(Ether()/IP()/ICMP(seq=0)))
> >>> p
> <Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
> version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
> chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
> type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>
> >>> del(p[ICMP].chksum)
> >>> p[ICMP].type = 0
> >>> p=Ether(str(p))
> >>> p
> <Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
> version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
> chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
> type=echo-reply code=0 chksum=0xffff id=0x0 seq=0x0 |>>>
> 
> We have 0xffff - 0xf7ff = 0x0800
> 
> 
> Example of a non-working case:
> 
> >>> p=Ether(str(Ether()/IP()/ICMP(seq=0xf800)))
> >>> p
> <Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
> version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
> chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
> type=echo-request code=0 chksum=0xfffe id=0x0 seq=0xf800 |>>>
> >>> del(p[ICMP].chksum)
> >>> p[ICMP].type = 0
> >>> p=Ether(str(p))
> >>> p
> <Ether  dst=ff:ff:ff:ff:ff:ff src=00:00:00:00:00:00 type=0x800 |<IP
> version=4L ihl=5L tos=0x0 len=28 id=1 flags= frag=0L ttl=64 proto=icmp
> chksum=0x7cde src=127.0.0.1 dst=127.0.0.1 options=[] |<ICMP
> type=echo-reply code=0 chksum=0x7ff id=0x0 seq=0xf800 |>>>
> 
> Here, 0x7ff - 0xfffe != 0x08000
> 
> 
> A correct solution (not tested) would be something like:
> 
> 	uint32_t cksum;
> 	cksum = (~(icmp_h->icmp_cksum)) & 0xffff;
> 	cksum += (~htons(IP_ICMP_ECHO_REQUEST << 8)) & 0xffff;
> 	cksum += (htons(IP_ICMP_ECHO_REPLY << 8)) & 0xffff;
> 	cksum = (cksum & 0xffff) + (cksum >> 16);
> 	cksum = (cksum & 0xffff) + (cksum >> 16);
> 	icmp_h->icmp_cksum = (~cksum) & 0xffff;

You're right, my patch is taking too many shortcuts. I'll submit a new patch
with your suggestion.

Regards,

-- 
Adrien Mazarguil
6WIND

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

* [dpdk-dev] [PATCH v2] app/testpmd: compute checksum in icmpecho replies
  2015-05-22 11:07 ` [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies Adrien Mazarguil
  2015-05-22 12:42   ` Olivier MATZ
@ 2015-05-22 17:03   ` Adrien Mazarguil
       [not found]     ` <55630A3E.5080708@6wind.com>
  1 sibling, 1 reply; 7+ messages in thread
From: Adrien Mazarguil @ 2015-05-22 17:03 UTC (permalink / raw)
  To: dev

ICMP echo replies with invalid checksums may be dropped by network nodes or
ignored by the ping utility.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Acked-by: Ivan Boule <ivan.boule@6wind.com>
---

v2:
- Compute correct checksum value by taking overflow into account.

 app/test-pmd/icmpecho.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c
index c5933f4..e249e71 100644
--- a/app/test-pmd/icmpecho.c
+++ b/app/test-pmd/icmpecho.c
@@ -295,6 +295,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 	uint16_t vlan_id;
 	uint16_t arp_op;
 	uint16_t arp_pro;
+	uint32_t cksum;
 	uint8_t  i;
 	int l2_len;
 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
@@ -445,7 +446,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		 * - switch IPv4 source and destinations addresses,
 		 * - set IP_ICMP_ECHO_REPLY in ICMP header.
 		 * No need to re-compute the IP header checksum.
-		 * Reset ICMP checksum.
+		 * ICMP checksum is computed by assuming it is valid in the
+		 * echo request and not verified.
 		 */
 		ether_addr_copy(&eth_h->s_addr, &eth_addr);
 		ether_addr_copy(&eth_h->d_addr, &eth_h->s_addr);
@@ -454,7 +456,12 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 		ip_h->src_addr = ip_h->dst_addr;
 		ip_h->dst_addr = ip_addr;
 		icmp_h->icmp_type = IP_ICMP_ECHO_REPLY;
-		icmp_h->icmp_cksum = 0;
+		cksum = ~icmp_h->icmp_cksum & 0xffff;
+		cksum += ~htons(IP_ICMP_ECHO_REQUEST << 8) & 0xffff;
+		cksum += htons(IP_ICMP_ECHO_REPLY << 8);
+		cksum = (cksum & 0xffff) + (cksum >> 16);
+		cksum = (cksum & 0xffff) + (cksum >> 16);
+		icmp_h->icmp_cksum = ~cksum;
 		pkts_burst[nb_replies++] = pkt;
 	}
 
-- 
2.1.0

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

* Re: [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies
  2015-05-22 11:07 [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Adrien Mazarguil
  2015-05-22 11:07 ` [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies Adrien Mazarguil
@ 2015-05-29 16:11 ` Thomas Monjalon
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2015-05-29 16:11 UTC (permalink / raw)
  To: Adrien Mazarguil; +Cc: dev

2015-05-22 13:07, Adrien Mazarguil:
> In the icmpecho forwarding mode, ARP replies from testpmd contain
> invalid zero-filled MAC addresses. This is broken since the commit below.
> 
> Fixes: 31db4d38de72 ("net: change arp header struct declaration")
> 
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> Acked-by: Ivan Boule <ivan.boule@6wind.com>

Applied, thanks

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

* Re: [dpdk-dev] [PATCH v2] app/testpmd: compute checksum in icmpecho replies
       [not found]     ` <55630A3E.5080708@6wind.com>
@ 2015-05-29 16:12       ` Thomas Monjalon
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2015-05-29 16:12 UTC (permalink / raw)
  To: Adrien Mazarguil; +Cc: dev

2015-05-25 13:40, Olivier MATZ:
> On 05/22/2015 07:03 PM, Adrien Mazarguil wrote:
> > ICMP echo replies with invalid checksums may be dropped by network nodes or
> > ignored by the ping utility.
> > 
> > Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> > Acked-by: Ivan Boule <ivan.boule@6wind.com>
> 
> Acked-by: Olivier Matz <olivier.matz@6wind.com>

Applied, thanks

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

end of thread, other threads:[~2015-05-29 18:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-22 11:07 [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Adrien Mazarguil
2015-05-22 11:07 ` [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies Adrien Mazarguil
2015-05-22 12:42   ` Olivier MATZ
2015-05-22 13:34     ` Adrien Mazarguil
2015-05-22 17:03   ` [dpdk-dev] [PATCH v2] " Adrien Mazarguil
     [not found]     ` <55630A3E.5080708@6wind.com>
2015-05-29 16:12       ` Thomas Monjalon
2015-05-29 16:11 ` [dpdk-dev] [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Thomas Monjalon

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).