From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id 90678592A for ; Fri, 22 May 2015 14:41:57 +0200 (CEST) Received: from was59-1-82-226-113-214.fbx.proxad.net ([82.226.113.214] helo=[192.168.0.10]) by mail.droids-corp.org with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YvmLM-0004zg-2W; Fri, 22 May 2015 14:46:32 +0200 Message-ID: <555F2420.8010200@6wind.com> Date: Fri, 22 May 2015 14:42:08 +0200 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: Adrien Mazarguil , dev@dpdk.org References: <1432292852-15701-1-git-send-email-adrien.mazarguil@6wind.com> <1432292852-15701-2-git-send-email-adrien.mazarguil@6wind.com> In-Reply-To: <1432292852-15701-2-git-send-email-adrien.mazarguil@6wind.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 2/2] app/testpmd: compute checksum in icmpecho replies X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 May 2015 12:41:57 -0000 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 > Acked-by: Ivan Boule > --- > 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 >> >>> del(p[ICMP].chksum) >>> p[ICMP].type = 0 >>> p=Ether(str(p)) >>> p >> We have 0xffff - 0xf7ff = 0x0800 Example of a non-working case: >>> p=Ether(str(Ether()/IP()/ICMP(seq=0xf800))) >>> p >> >>> del(p[ICMP].chksum) >>> p[ICMP].type = 0 >>> p=Ether(str(p)) >>> p >> 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; > } > >