From patchwork Tue Sep 15 13:17:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ophir Munk X-Patchwork-Id: 77732 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B1BA5A04C7; Tue, 15 Sep 2020 15:17:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 85D751BE8E; Tue, 15 Sep 2020 15:17:24 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 018741BF59 for ; Tue, 15 Sep 2020 15:17:22 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ophirmu@nvidia.com) with SMTP; 15 Sep 2020 16:17:22 +0300 Received: from nvidia.com (pegasus05.mtr.labs.mlnx [10.210.16.100]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 08FDHL47017444; Tue, 15 Sep 2020 16:17:21 +0300 From: Ophir Munk To: dev@dpdk.org, Wenzhuo Lu , Beilei Xing , Bernard Iremonger , Ferruh Yigit Cc: Ophir Munk , Ophir Munk Date: Tue, 15 Sep 2020 13:17:17 +0000 Message-Id: <20200915131717.18252-4-ophirmu@nvidia.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200915131717.18252-1-ophirmu@nvidia.com> References: <20200915125319.16568-2-ophirmu@nvidia.com> <20200915131717.18252-1-ophirmu@nvidia.com> Subject: [dpdk-dev] [PATCH v4 3/3] app/testpmd: reduce tunnel parsing code duplication X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ophir Munk This is a cleanup commit. It assembles all tunnel outer updates into one function call to avoid code duplications. It defines RTE_VXLAN_GPE_DEFAULT_PORT (4790) in accordance with all other tunnel protocol definitions. Signed-off-by: Ophir Munk --- app/test-pmd/csumonly.c | 72 +++++++++++++--------------------------------- lib/librte_net/rte_vxlan.h | 1 + 2 files changed, 21 insertions(+), 52 deletions(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index eb87b9b..6f24a14 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -63,7 +63,7 @@ #define _htons(x) (x) #endif -uint16_t vxlan_gpe_udp_port = 4790; +uint16_t vxlan_gpe_udp_port = RTE_VXLAN_GPE_DEFAULT_PORT; uint16_t geneve_udp_port = RTE_GENEVE_DEFAULT_PORT; /* structure that caches offload info for the current packet */ @@ -181,6 +181,17 @@ parse_ethernet(struct rte_ether_hdr *eth_hdr, struct testpmd_offload_info *info) } } +/* Fill in outer layers length */ +static void +update_tunnel_outer(struct testpmd_offload_info *info) +{ + info->is_tunnel = 1; + info->outer_ethertype = info->ethertype; + info->outer_l2_len = info->l2_len; + info->outer_l3_len = info->l3_len; + info->outer_l4_proto = info->l4_proto; +} + /* * Parse a GTP protocol header. * No optional fields and next extension header type. @@ -201,11 +212,7 @@ parse_gtp(struct rte_udp_hdr *udp_hdr, udp_hdr->dst_port != _htons(RTE_GTPU_UDP_PORT)) return; - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); info->l2_len = 0; gtp_hdr = (struct rte_gtp_hdr *)((char *)udp_hdr + @@ -257,11 +264,7 @@ parse_vxlan(struct rte_udp_hdr *udp_hdr, RTE_ETH_IS_TUNNEL_PKT(pkt_type) == 0) return; - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); eth_hdr = (struct rte_ether_hdr *)((char *)udp_hdr + sizeof(struct rte_udp_hdr) + @@ -291,11 +294,7 @@ parse_vxlan_gpe(struct rte_udp_hdr *udp_hdr, if (!vxlan_gpe_hdr->proto || vxlan_gpe_hdr->proto == RTE_VXLAN_GPE_TYPE_IPV4) { - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); ipv4_hdr = (struct rte_ipv4_hdr *)((char *)vxlan_gpe_hdr + vxlan_gpe_len); @@ -305,11 +304,7 @@ parse_vxlan_gpe(struct rte_udp_hdr *udp_hdr, info->l2_len = 0; } else if (vxlan_gpe_hdr->proto == RTE_VXLAN_GPE_TYPE_IPV6) { - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); ipv6_hdr = (struct rte_ipv6_hdr *)((char *)vxlan_gpe_hdr + vxlan_gpe_len); @@ -319,11 +314,7 @@ parse_vxlan_gpe(struct rte_udp_hdr *udp_hdr, info->l2_len = 0; } else if (vxlan_gpe_hdr->proto == RTE_VXLAN_GPE_TYPE_ETH) { - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); eth_hdr = (struct rte_ether_hdr *)((char *)vxlan_gpe_hdr + vxlan_gpe_len); @@ -335,17 +326,6 @@ parse_vxlan_gpe(struct rte_udp_hdr *udp_hdr, info->l2_len += RTE_ETHER_VXLAN_GPE_HLEN; } -/* Fill in outer layers length */ -static void -update_tunnel_outer(struct testpmd_offload_info *info) -{ - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; -} - /* Parse a geneve header */ static void parse_geneve(struct rte_udp_hdr *udp_hdr, @@ -412,11 +392,7 @@ parse_gre(struct simple_gre_hdr *gre_hdr, struct testpmd_offload_info *info) gre_len += GRE_EXT_LEN; if (gre_hdr->proto == _htons(RTE_ETHER_TYPE_IPV4)) { - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); ipv4_hdr = (struct rte_ipv4_hdr *)((char *)gre_hdr + gre_len); @@ -425,11 +401,7 @@ parse_gre(struct simple_gre_hdr *gre_hdr, struct testpmd_offload_info *info) info->l2_len = 0; } else if (gre_hdr->proto == _htons(RTE_ETHER_TYPE_IPV6)) { - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); ipv6_hdr = (struct rte_ipv6_hdr *)((char *)gre_hdr + gre_len); @@ -438,11 +410,7 @@ parse_gre(struct simple_gre_hdr *gre_hdr, struct testpmd_offload_info *info) info->l2_len = 0; } else if (gre_hdr->proto == _htons(RTE_ETHER_TYPE_TEB)) { - info->is_tunnel = 1; - info->outer_ethertype = info->ethertype; - info->outer_l2_len = info->l2_len; - info->outer_l3_len = info->l3_len; - info->outer_l4_proto = info->l4_proto; + update_tunnel_outer(info); eth_hdr = (struct rte_ether_hdr *)((char *)gre_hdr + gre_len); diff --git a/lib/librte_net/rte_vxlan.h b/lib/librte_net/rte_vxlan.h index c23c10c..2ad6061 100644 --- a/lib/librte_net/rte_vxlan.h +++ b/lib/librte_net/rte_vxlan.h @@ -22,6 +22,7 @@ extern "C" { /** VXLAN default port. */ #define RTE_VXLAN_DEFAULT_PORT 4789 +#define RTE_VXLAN_GPE_DEFAULT_PORT 4790 /** * VXLAN protocol header.