From: Olivier MATZ <olivier.matz@6wind.com>
To: Adrien Mazarguil <adrien.mazarguil@6wind.com>, dev@dpdk.org
Subject: Re: [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies
Date: Fri, 22 May 2015 14:42:08 +0200 [thread overview]
Message-ID: <555F2420.8010200@6wind.com> (raw)
In-Reply-To: <1432292852-15701-2-git-send-email-adrien.mazarguil@6wind.com>
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(ð_h->s_addr, ð_addr);
> ether_addr_copy(ð_h->d_addr, ð_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;
> }
>
>
next prev parent reply other threads:[~2015-05-22 12:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-22 11:07 [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Adrien Mazarguil
2015-05-22 11:07 ` [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies Adrien Mazarguil
2015-05-22 12:42 ` Olivier MATZ [this message]
2015-05-22 13:34 ` Adrien Mazarguil
2015-05-22 17:03 ` [PATCH v2] " Adrien Mazarguil
2015-05-25 11:40 ` Olivier MATZ
2015-05-29 16:12 ` Thomas Monjalon
2015-05-29 16:11 ` [PATCH 1/2] app/testpmd: use correct hardware address in ARP replies Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555F2420.8010200@6wind.com \
--to=olivier.matz@6wind.com \
--cc=adrien.mazarguil@6wind.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.