Message ID | 1432292852-15701-2-git-send-email-adrien.mazarguil@6wind.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 961395A63; Fri, 22 May 2015 13:07:52 +0200 (CEST) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179]) by dpdk.org (Postfix) with ESMTP id 8A02A5A57 for <dev@dpdk.org>; Fri, 22 May 2015 13:07:50 +0200 (CEST) Received: by wicmc15 with SMTP id mc15so37341956wic.1 for <dev@dpdk.org>; Fri, 22 May 2015 04:07:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=uCNw3rsXASpXcwEpUF1fEeLrFii1Pt0LMNiW8XEsefY=; b=BTpF+y50WHzv9aAmKwQRHDTD3acDNWl6z/EjV1EhhqBUPsye3doQJHi1IgWZoMdpZz nPfTHFj4569x/69HNVRVjhPtS1Ch7nNrlIV3rl0iil9wn+vQX08d4i+JAmp+J4+1PtUm GmdQKIoVVMw8fkuVidO8KXTKasHozFGb+qGEJhATIx2MygLELWIMoj9wqHDiYsWXy/NV jLUhliz4LMBPCJtCqZC/3g39AYrcSHaSwUbnrk1oez0P166jEIl5c2P2piOTHmFI3Lee usJGFI/FlNMimMUHWR2xYH3PgT3lDDhiY5cMayojP2dX72xA7DtofqFNJ8cIQBXSYzbf m5kg== X-Gm-Message-State: ALoCoQnqOIFZqMQDWK/IvsEAE7nBrTbItwIlPArv4RSelkkm4IIOG5X8Ayx3Z8MuzRrUEiQL2KRc X-Received: by 10.180.221.69 with SMTP id qc5mr6551621wic.72.1432292870455; Fri, 22 May 2015 04:07:50 -0700 (PDT) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id fs9sm2638694wjc.34.2015.05.22.04.07.49 for <dev@dpdk.org> (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 22 May 2015 04:07:49 -0700 (PDT) From: Adrien Mazarguil <adrien.mazarguil@6wind.com> To: dev@dpdk.org Date: Fri, 22 May 2015 13:07:32 +0200 Message-Id: <1432292852-15701-2-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1432292852-15701-1-git-send-email-adrien.mazarguil@6wind.com> References: <1432292852-15701-1-git-send-email-adrien.mazarguil@6wind.com> Subject: [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 <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Adrien Mazarguil
May 22, 2015, 11:07 a.m. UTC
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(-)
Comments
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; > } > >
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(ð_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; You're right, my patch is taking too many shortcuts. I'll submit a new patch with your suggestion. Regards,
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); pkts_burst[nb_replies++] = pkt; }