From patchwork Wed Sep 11 14:10:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Obrembski X-Patchwork-Id: 1161022 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=intel.com 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 46T3pn4pBBz9s4Y for ; Thu, 12 Sep 2019 00:16:01 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C8CC814B7; Wed, 11 Sep 2019 14:12:04 +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 EA900148F for ; Wed, 11 Sep 2019 14:12:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 56CBF896 for ; Wed, 11 Sep 2019 14:12:01 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 07:12:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,493,1559545200"; d="scan'208";a="200528266" Received: from mobrembx-mobl.ger.corp.intel.com ([10.103.104.26]) by fmsmga001.fm.intel.com with ESMTP; 11 Sep 2019 07:12:00 -0700 From: Michal Obrembski To: dev@openvswitch.org Date: Wed, 11 Sep 2019 16:10:04 +0200 Message-Id: <20190911141005.1346-7-michalx.obrembski@intel.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20190911141005.1346-1-michalx.obrembski@intel.com> References: <20190911141005.1346-1-michalx.obrembski@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v5 6/7] Give the variables more meaningful names 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Artur Twardowski Replaced variable names "hlen", "ulen", "gnh" with longer ones to make the code analysis easier. Additionally, UDP header len is no longer accumulated into GENEVE header length, additions are used in the places where the sum of both headers is used. Signed-off-by: Artur Twardowski --- lib/netdev-native-tnl.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c index 54ed0e9..d0ea3d5 100644 --- a/lib/netdev-native-tnl.c +++ b/lib/netdev-native-tnl.c @@ -837,8 +837,8 @@ netdev_geneve_pop_header(struct dp_packet *packet) { struct pkt_metadata *md = &packet->md; struct flow_tnl *tnl = &md->tunnel; - struct genevehdr *gnh; - unsigned int hlen, opts_len, ulen; + struct genevehdr *geneve_hdr; + unsigned int geneve_hdr_len, opts_len, udp_hdr_len; pkt_metadata_init_tnl(md); if (!dp_packet_may_pull(packet, packet->l4_ofs, GENEVE_BASE_HLEN)) { @@ -847,40 +847,42 @@ netdev_geneve_pop_header(struct dp_packet *packet) goto err; } - gnh = udp_extract_tnl_md(packet, tnl, &ulen); - if (!gnh) { + geneve_hdr = udp_extract_tnl_md(packet, tnl, &udp_hdr_len); + if (!geneve_hdr) { goto err; } - opts_len = gnh->opt_len * 4; - hlen = ulen + GENEVE_BASE_HLEN + opts_len; - if (!dp_packet_may_pull(packet, packet->l4_ofs, hlen - ulen)) { - VLOG_WARN_RL(&err_rl, "geneve packet too small: header len=%u packet size=%u\n", - hlen, dp_packet_size(packet)); + opts_len = geneve_hdr->opt_len * 4; + geneve_hdr_len = GENEVE_BASE_HLEN + opts_len; + if (!dp_packet_may_pull(packet, udp_hdr_len, geneve_hdr_len)) { + VLOG_WARN_RL(&err_rl, "geneve packet too small: " + "wanted headers=%u, but packet size=%u\n", + geneve_hdr_len + udp_hdr_len, + dp_packet_size(packet)); goto err; } - if (gnh->ver != 0) { - VLOG_WARN_RL(&err_rl, "unknown geneve version: %"PRIu8"\n", gnh->ver); + if (geneve_hdr->ver != 0) { + VLOG_WARN_RL(&err_rl, "unknown geneve version: %"PRIu8"\n", geneve_hdr->ver); goto err; } - if (gnh->proto_type != htons(ETH_TYPE_TEB)) { + if (geneve_hdr->proto_type != htons(ETH_TYPE_TEB)) { VLOG_WARN_RL(&err_rl, "unknown geneve encapsulated protocol: %#x\n", - ntohs(gnh->proto_type)); + ntohs(geneve_hdr->proto_type)); goto err; } - tnl->flags |= gnh->oam ? FLOW_TNL_F_OAM : 0; - tnl->tun_id = htonll(ntohl(get_16aligned_be32(&gnh->vni)) >> 8); + tnl->flags |= geneve_hdr->oam ? FLOW_TNL_F_OAM : 0; + tnl->tun_id = htonll(ntohl(get_16aligned_be32(&geneve_hdr->vni)) >> 8); tnl->flags |= FLOW_TNL_F_KEY; - memcpy(tnl->metadata.opts.gnv, gnh->options, opts_len); + memcpy(tnl->metadata.opts.gnv, geneve_hdr->options, opts_len); tnl->metadata.present.len = opts_len; tnl->flags |= FLOW_TNL_F_UDPIF; packet->packet_type = htonl(PT_ETH); - dp_packet_reset_packet(packet, hlen); + dp_packet_reset_packet(packet, geneve_hdr_len + udp_hdr_len); return packet; err: