From patchwork Tue Oct 1 07:04:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Zhang X-Patchwork-Id: 1169733 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jEvCcGfW"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46j9J25HqHz9sN1 for ; Tue, 1 Oct 2019 17:04:49 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 07F397A82; Tue, 1 Oct 2019 07:04:46 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id EBF807A7E for ; Tue, 1 Oct 2019 07:04:30 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 57E488AE for ; Tue, 1 Oct 2019 07:04:30 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id l21so12147835lje.4 for ; Tue, 01 Oct 2019 00:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AThvmUlIeXWxHBZXYRZ1rD9gpvHuLCfnkWENe5+kbHE=; b=jEvCcGfWDWsZzFvu+AXbhGDoP/7WvufyQt89t7SYf+XeOZjhOmDvnnioZiOi3LoIa1 anshEkxcDRDr2KEKQtB75+KcHTu8NnDhG6CIeIFnow+PUpzUFOx2CuOwkkf9/xwiKfbT LjJqs/yxwiH81Z6lrPchA9Qq2k0EBZRlzk9LOIuhZK9cpm+4ZJq7INSGvVzn3fiY27B+ GQdkzNzYYLtnl7o574jHnsiAwSmGsJglDWamSKqws14BPS+F+qYs7pgNdXWa7xaycQ8a b4zHOdyxkcM+nTmzXRtvrP5Xqm1qQLeFctvGh2D8OvMohyQNAnVjg/v+mvsiUAUaDADv 9Txw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AThvmUlIeXWxHBZXYRZ1rD9gpvHuLCfnkWENe5+kbHE=; b=WsDpVT2WBqkax87LL7bUwvcMpDGMC3fW9mlBnqSoRbKcKypgROWcLuyJuZ1dnX4vHi Um6pbpGfk0QslqXWySgIrw4LAXzfIZJioNCEc56SVVkcvqiBoNuPIx4d64As2OvVBFzY Ro4vKuOag9NyGew/QMLI2b4rLRqLHp/icBK2OUuGbx+j00pibD3BT7RdIloEqq6olKif wgks2grEFv2OKjkVpSuZMEuRamWNoLj7Du1pC21Hs2LQdEYRLRXfzs+Wf1VlbSJt8a9c eG38arqLq+2BXT2vYOQFqQwfc3aVz2voFF8ZbF5UUF4b7n0V1X08NaRW2kr3LlVAr+yp HklA== X-Gm-Message-State: APjAAAVbPkq4rTLMcndVoP/jawbQT4/yFU7Ypfy/3Zpex2QrN6oeezCS WB5hRnS823OGWOsTUv8UVF3CLA1YRRE= X-Google-Smtp-Source: APXvYqyK2qWGF905BPbWlnYVUgj+b0SdsPt1ZkRLuAGjw7OQX3G3CbO6uizBz94XGX0mrNCUufhAoQ== X-Received: by 2002:a2e:7611:: with SMTP id r17mr1538551ljc.133.1569913468240; Tue, 01 Oct 2019 00:04:28 -0700 (PDT) Received: from localhost.localdomain.localdomain ([185.22.154.209]) by smtp.gmail.com with ESMTPSA id m17sm4632820lje.0.2019.10.01.00.04.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 00:04:27 -0700 (PDT) From: martinbj2008@gmail.com To: dev@openvswitch.org Date: Tue, 1 Oct 2019 15:04:01 +0800 Message-Id: <1569913441-3779-1-git-send-email-martinbj2008@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <=20190927163854.GZ7850@ovn.org> References: <=20190927163854.GZ7850@ovn.org> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Martin Zhang Subject: [ovs-dev] [PATCH v3] odp-util: calc checksum of ip hdr for tunnel encap X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Martin Zhang V2: fix warning V3: replace tab with spaces Signed-off-by: Martin Zhang --- lib/odp-util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/odp-util.c b/lib/odp-util.c index fe59a56..36c6c3b 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -44,6 +44,7 @@ #include "openvswitch/vlog.h" #include "openvswitch/match.h" #include "odp-netlink-macros.h" +#include "csum.h" VLOG_DEFINE_THIS_MODULE(odp_util); @@ -1482,7 +1483,7 @@ ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data) struct gre_base_hdr *greh; struct erspan_base_hdr *ersh; struct erspan_md2 *md2; - uint16_t gre_proto, gre_flags, dl_type, udp_src, udp_dst, csum, sid; + uint16_t gre_proto, gre_flags, dl_type, udp_src, udp_dst, udp_csum, sid; ovs_be32 sip, dip; uint32_t tnl_type = 0, header_len = 0, ip_len = 0, erspan_idx = 0; void *l3, *l4; @@ -1516,6 +1517,7 @@ ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data) if (eth->eth_type == htons(ETH_TYPE_IP)) { /* IPv4 */ uint16_t ip_frag_off; + memset(ip, 0, sizeof(*ip)); if (!ovs_scan_len(s, &n, "ipv4(src="IP_SCAN_FMT",dst="IP_SCAN_FMT",proto=%"SCNi8 ",tos=%"SCNi8",ttl=%"SCNi8",frag=0x%"SCNx16"),", IP_SCAN_ARGS(&sip), @@ -1529,6 +1531,7 @@ ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data) ip->ip_frag_off = htons(ip_frag_off); ip->ip_ihl_ver = IP_IHL_VER(5, 4); ip_len = sizeof *ip; + ip->ip_csum = csum(ip, ip_len); } else { char sip6_s[IPV6_SCAN_LEN + 1]; char dip6_s[IPV6_SCAN_LEN + 1]; @@ -1557,13 +1560,13 @@ ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data) udp = (struct udp_header *) l4; greh = (struct gre_base_hdr *) l4; if (ovs_scan_len(s, &n, "udp(src=%"SCNi16",dst=%"SCNi16",csum=0x%"SCNx16"),", - &udp_src, &udp_dst, &csum)) { + &udp_src, &udp_dst, &udp_csum)) { uint32_t vx_flags, vni; udp->udp_src = htons(udp_src); udp->udp_dst = htons(udp_dst); udp->udp_len = 0; - udp->udp_csum = htons(csum); + udp->udp_csum = htons(udp_csum); if (ovs_scan_len(s, &n, "vxlan(flags=0x%"SCNx32",vni=0x%"SCNx32"))", &vx_flags, &vni)) { @@ -1629,6 +1632,7 @@ ovs_parse_tnl_push(const char *s, struct ovs_action_push_tnl *data) ovs_16aligned_be32 *options = (ovs_16aligned_be32 *) (greh + 1); if (greh->flags & htons(GRE_CSUM)) { + uint16_t csum; if (!ovs_scan_len(s, &n, ",csum=0x%"SCNx16, &csum)) { return -EINVAL; }