From patchwork Tue May 19 10:49:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 48740 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BD2A12121F for ; Tue, 19 May 2015 10:49:49 +0000 (UTC) Received: by wiz9 with SMTP id 9sf5872327wiz.3 for ; Tue, 19 May 2015 03:49:49 -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:from:to:date :message-id:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=5RZ1Nd9N4Zkom7UMRlDiZDPclwKoRDdO9NEndI0APnQ=; b=QDbDgKbBjmdEGLsU2JjZNYmjCq96DQohJrL+TY+LB9Vcb47wJxZBcyE5JuQSHjGy+K RizGctNST2g683G5v+V7fjmWdeQP2sjGdiIMzzs1u3E8ny9OJnzDem3Ud4W2Sp1vapHx Ba7I4V3SFE/s6/leNAnKM+qkUrLzDAu0DnrCemBfHMFJ2J6HlafUisCnCHWz2BGrxIjH +KslZOHR/YmosG7KWGO5w8zWPt8KK+/Lp7VZg2sCqEChKDZIGNko8rl1xx5JIjUIS1uy qfcYMHrJlfur878OjXZ/u0XKMAHwrmLkkDCQwxF2yRTLXR3WeDt8J1WGcbq3FyGYcLh1 1n2Q== X-Gm-Message-State: ALoCoQkicLyVPp5qcX9vHN//RS9zVE82Gg5N6WcbgNzIXfj/7vUn3mSU+ilQ0SJThrMXzzBgh2/j X-Received: by 10.180.97.9 with SMTP id dw9mr13561665wib.2.1432032589110; Tue, 19 May 2015 03:49:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.168 with SMTP id kz8ls33810lac.105.gmail; Tue, 19 May 2015 03:49:48 -0700 (PDT) X-Received: by 10.112.125.33 with SMTP id mn1mr20867432lbb.82.1432032588871; Tue, 19 May 2015 03:49:48 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id h1si8651129lah.56.2015.05.19.03.49.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 May 2015 03:49:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by laat2 with SMTP id t2so17070457laa.1 for ; Tue, 19 May 2015 03:49:48 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr20627108lbc.41.1432032588718; Tue, 19 May 2015 03:49:48 -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 hn6csp708257lbb; Tue, 19 May 2015 03:49:47 -0700 (PDT) X-Received: by 10.229.96.138 with SMTP id h10mr10262042qcn.5.1432032586970; Tue, 19 May 2015 03:49:46 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w71si1847833qkw.90.2015.05.19.03.49.46; Tue, 19 May 2015 03:49:46 -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 07F0B61830; Tue, 19 May 2015 10:49:46 +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 C239461828; Tue, 19 May 2015 10:49:41 +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 82E066182B; Tue, 19 May 2015 10:49:39 +0000 (UTC) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id 7D9EA61094 for ; Tue, 19 May 2015 10:49:38 +0000 (UTC) Received: by laat2 with SMTP id t2so17062766laa.1 for ; Tue, 19 May 2015 03:49:36 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr20626545lbc.41.1432032576453; Tue, 19 May 2015 03:49:36 -0700 (PDT) Received: from localhost.localdomain (ppp91-76-163-142.pppoe.mtu-net.ru. [91.76.163.142]) by mx.google.com with ESMTPSA id f7sm3489040lbc.9.2015.05.19.03.49.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 May 2015 03:49:35 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 19 May 2015 13:49:31 +0300 Message-Id: <1432032571-25179-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv2] 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: , MIME-Version: 1.0 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.52 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 From: Alexandru Badicioiu Signed-off-by: Alexandru Badicioiu Signed-off-by: Maxim Uvarov --- v2: fix csum in odp generatior. example/generator/odp_generator.c | 2 +- helper/include/odp/helper/udp.h | 37 +++++++++++++------------------------ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 8ae5b29..8c224f3 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -238,7 +238,7 @@ 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); return pkt; } diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h index 866145a..06c439b 100644 --- a/helper/include/odp/helper/udp.h +++ b/helper/include/odp/helper/udp.h @@ -38,15 +38,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 * @@ -58,10 +49,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; @@ -73,24 +64,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;