From patchwork Thu May 14 18:04:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 48536 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D73A42121F for ; Thu, 14 May 2015 18:04:13 +0000 (UTC) Received: by wgvl6 with SMTP id l6sf20943626wgv.2 for ; Thu, 14 May 2015 11:04:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:message-id:date:from :user-agent:mime-version:to:references:in-reply-to:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:content-transfer-encoding:content-type :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Kqr9vxSxhQv58LwU54EAMyvXzQiEGAogkKq3potkVKE=; b=mBdfilRj9xxjvO7N0rHvBoDIQZy6z7X2HNostB+r8b/6RtTUxntoyf4uZb8Jy/suyO AyAjj7Uxpg0tv9vhriDmeplhgka6eW4wmfUFv/A97phHH9Szd07alAtNFDQNtm9fY8ne /uB9ugNgck5/Te8H77+brmUvoQPTbDhHdSzn1Y2N7JYTbqyVrHzSZOGibSL2uMj6BL3Z eZ3e1fP5uqmfra1c3Q2VjACb6vvJ34HLloesHm02SaDE6WhjLRTyvHta0AZ+0LKLTOjG HUKVAvIEfi2Gv2UMaOB76Wk9X2d+Y4+3RZvwVXd2pvFzxZr2BhrmvhcpAPhPODCzTAVr 9jLw== X-Gm-Message-State: ALoCoQkps+QobUXjlVIcDZgCkDlBUiIjTejBmVaaEDlBSR4DAgP82EbtG+DnuynyJINhNegdzexu X-Received: by 10.180.106.10 with SMTP id gq10mr19247754wib.0.1431626653157; Thu, 14 May 2015 11:04:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.229 with SMTP id w5ls416984lag.44.gmail; Thu, 14 May 2015 11:04:13 -0700 (PDT) X-Received: by 10.112.199.1 with SMTP id jg1mr483890lbc.59.1431626652977; Thu, 14 May 2015 11:04:12 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id ac10si15007743lbc.134.2015.05.14.11.04.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2015 11:04:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lagv1 with SMTP id v1so79147911lag.3 for ; Thu, 14 May 2015 11:04:12 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr4216795lag.106.1431626652832; Thu, 14 May 2015 11:04:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1437749lbb; Thu, 14 May 2015 11:04:11 -0700 (PDT) X-Received: by 10.140.20.150 with SMTP id 22mr7291742qgj.26.1431626651214; Thu, 14 May 2015 11:04:11 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d131si2772853qka.18.2015.05.14.11.04.10; Thu, 14 May 2015 11:04:11 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id 1285161FFD; Thu, 14 May 2015 18:04:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id C004361D5E; Thu, 14 May 2015 18:04:07 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3F0FA61E73; Thu, 14 May 2015 18:04:05 +0000 (UTC) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 4225561D5E for ; Thu, 14 May 2015 18:04:03 +0000 (UTC) Received: by labbd9 with SMTP id bd9so79278928lab.2 for ; Thu, 14 May 2015 11:04:02 -0700 (PDT) X-Received: by 10.112.77.234 with SMTP id v10mr4011912lbw.119.1431626642093; Thu, 14 May 2015 11:04:02 -0700 (PDT) Received: from [192.168.1.52] (ppp91-76-166-40.pppoe.mtu-net.ru. [91.76.166.40]) by mx.google.com with ESMTPSA id h8sm6332814lam.32.2015.05.14.11.04.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2015 11:04:01 -0700 (PDT) Message-ID: <5554E390.9050308@linaro.org> Date: Thu, 14 May 2015 21:04:00 +0300 From: Maxim Uvarov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: lng-odp@lists.linaro.org References: <1430827646-15525-1-git-send-email-alexandru.badicioiu@linaro.org> In-Reply-To: <1430827646-15525-1-git-send-email-alexandru.badicioiu@linaro.org> X-Topics: patch Subject: Re: [lng-odp] [PATCH 1/1 v1] helpers: fix udp checksum computation X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Hello Alexandru, Your patch fixes check summ now that function is better: 20:49:45.613467 IP (tos 0x0, id 35630, offset 0, flags [none], proto UDP (17), length 84) 192.168.0.1.0 > 192.168.0.2.0: [bad udp cksum 0x1a7e -> 0x7e1a!] UDP, length 56 20:49:45.613470 IP (tos 0x0, id 35662, offset 0, flags [none], proto UDP (17), length 84) 192.168.0.1.0 > 192.168.0.2.0: [bad udp cksum 0x1a7e -> 0x7e1a!] UDP, length 56 I used packets generated with our odp_generator. After that fix check summ is valid: return pkt; That will work on both BE/LE right? Thanks, Maxim. On 05/05/2015 15:07, alexandru.badicioiu@linaro.org wrote: > From: Alexandru Badicioiu > > v1 - fixed compile error due to -Wcast-align > > Signed-off-by: Alexandru Badicioiu > --- > helper/include/odp/helper/udp.h | 37 +++++++++++++------------------------ > 1 files changed, 13 insertions(+), 24 deletions(-) > > diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h > index 99a96f2..d14cbef 100644 > --- a/helper/include/odp/helper/udp.h > +++ b/helper/include/odp/helper/udp.h > @@ -33,15 +33,6 @@ typedef struct ODP_PACKED { > uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ > } odph_udphdr_t; > > -/** UDP pseudo header */ > -typedef struct ODPH_PACKET { > - uint32be_t src_addr; /**< Source addr */ > - uint32be_t dst_addr; /**< Destination addr */ > - uint8_t pad; /**< pad byte */ > - uint8_t proto; /**< UDP protocol */ > - uint16be_t length; /**< data length */ > -} odph_udpphdr_t; > - > /** > * UDP checksum > * > @@ -53,10 +44,10 @@ typedef struct ODPH_PACKET { > static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) > { > uint32_t sum = 0; > - odph_udpphdr_t phdr; > odph_udphdr_t *udph; > odph_ipv4hdr_t *iph; > uint16_t udplen; > + uint8_t *buf; > > if (!odp_packet_l3_offset(pkt)) > return 0; > @@ -68,24 +59,22 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) > udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL); > udplen = odp_be_to_cpu_16(udph->length); > > - /* the source ip */ > - phdr.src_addr = iph->src_addr; > - /* the dest ip */ > - phdr.dst_addr = iph->dst_addr; > - /* proto */ > - phdr.pad = 0; > - phdr.proto = ODPH_IPPROTO_UDP; > - /* the length */ > - phdr.length = udph->length; > - > - /* calc UDP pseudo header chksum */ > - sum = (__odp_force uint32_t) odp_chksum(&phdr, sizeof(odph_udpphdr_t)); > - /* calc udp header and data chksum */ > - sum += (__odp_force uint32_t) odp_chksum(udph, udplen); > + /* 32-bit sum of all 16-bit words covered by UDP chksum */ > + sum = (iph->src_addr & 0xFFFF) + (iph->src_addr >> 16) + > + (iph->dst_addr & 0xFFFF) + (iph->dst_addr >> 16) + > + (uint16_t) iph->proto + udplen; > + for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) { > + sum += ((*buf << 8) + *(buf + 1)); > + buf += 2; > + } > > /* Fold sum to 16 bits: add carrier to result */ > while (sum >> 16) > sum = (sum & 0xFFFF) + (sum >> 16); > + > + /* 1's complement */ > + sum = ~sum; > + > /* set computation result */ > sum = (sum == 0x0) ? 0xFFFF : sum; > --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -238,7 +238,6 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) udp->dst_port = 0; udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN); udp->chksum = 0; - udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt)); udp->chksum = odph_ipv4_udp_chksum(pkt);