From patchwork Fri Sep 27 01:26:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Zhang X-Patchwork-Id: 1168204 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="NilBFNfV"; 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 46fYzJ3Q4kz9sNx for ; Fri, 27 Sep 2019 11:26:19 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 78825E8C; Fri, 27 Sep 2019 01:26:15 +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 B5041E85 for ; Fri, 27 Sep 2019 01:26:14 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 577418AE for ; Fri, 27 Sep 2019 01:26:14 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id i14so2502046pgt.11 for ; Thu, 26 Sep 2019 18:26:14 -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=KIJ2wvXLrow4Ajd0Bh5zvERIF+ZisLtkJYpMZTz4Ih8=; b=NilBFNfVSY6OMfyzoPSmJa2hnQcz3qjkP1VuOwUd9/WpHu4qsT7BS4npkkAxSZcfLk ao5wZdTt8YuTMi5u4CgnYd3VIYjHET4c+tCo1139Kc2CmaF1Z9G6ZdmVPY0LWE4dpOyh swkoF7XbE5YNPAJtDyZBjNDggToUPb9iuAlHV+EU7iSdVN6mBDjzFJ411CN7XIm1yeDC C6mRHctFmMxfojjWdbfP6Xzaz3UsbuQJUmMjuMCBpkyHN6Fv5fxClJxx+GyTr3rU9siE SffOFML+nB7UPH7FEVRZuEEfy22HycdWz/qN2i6RiAcw5/Rp6LCUYiszIDw3FfX/BbU9 nkpA== 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=KIJ2wvXLrow4Ajd0Bh5zvERIF+ZisLtkJYpMZTz4Ih8=; b=adbLM3n3p/ppqO91bEI4KgjO1L/fxwzaRXsY+KLrV8mstVOOztV/fg68X7MEUsL6gq Ky77uQ32aYKq6YKOU5P9XSwzCRm3oU18qKA/N4K4pxxPgkde8xHuHoX5gS6jxB6xfpwW FTv4wDJ+VxhRIPtopNMfEl6yvU3sOa9dbu0HPaNaHHJ2XqhjUSbelF4YDuMd/LTUXE+4 3jPwHFMuBxE7GIJf+YQGISR0YI4Dt52D4/yk5HFcy2X9Keoj4qVfnZBuXlrR4uSjP8m0 25ZoF4+RwdxVR5xgtklgZmV3GsbesFirOZSnUgCLahhG5F7ALwmI8A5hS52miQQOfIvR 8nUQ== X-Gm-Message-State: APjAAAVX/vHBuOFxHWb82nKpYkHEpStOneBCeUZWtEjahHlx0VOOF25Z jmh1HrlN/tRJ5R6osi6YZPVzHjZJ X-Google-Smtp-Source: APXvYqycQT7I6AhVhWlK09xq4cGnNDVMXTVyYY0LrqV8om4IcvPvPy1F9oyOQ675kCuavW9cM4maeQ== X-Received: by 2002:a62:ea10:: with SMTP id t16mr1098282pfh.233.1569547573364; Thu, 26 Sep 2019 18:26:13 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id r23sm3054541pjo.3.2019.09.26.18.26.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Sep 2019 18:26:12 -0700 (PDT) From: martinbj2008@gmail.com To: dev@openvswitch.org Date: Fri, 27 Sep 2019 09:26:07 +0800 Message-Id: <1569547567-2901-1-git-send-email-martinbj2008@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <=20190925162120.GZ7850@ovn.org> References: <=20190925162120.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 , zhangjunweimartin@didiglobal.com Subject: [ovs-dev] [PATCH v2] 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 Signed-off-by: Martin Zhang V2: fix compile warning 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..29ffd6d 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; }