From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 41473A04B1; Thu, 27 Aug 2020 09:03:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 95B9E1BF5A; Thu, 27 Aug 2020 09:02:59 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 425261BFD7 for ; Thu, 27 Aug 2020 09:02:58 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ophirmu@nvidia.com) with SMTP; 27 Aug 2020 10:02:52 +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 07R72qrY020045; Thu, 27 Aug 2020 10:02:52 +0300 From: Ophir Munk To: dev@dpdk.org, Wenzhuo Lu , Beilei Xing , Bernard Iremonger Cc: Ophir Munk Date: Thu, 27 Aug 2020 07:02:44 +0000 Message-Id: <20200827070244.32392-4-ophirmu@nvidia.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200827070244.32392-1-ophirmu@nvidia.com> References: <20200729082905.19499-4-ophirmu@mellanox.com> <20200827070244.32392-1-ophirmu@nvidia.com> Subject: [dpdk-dev] [PATCH v2 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 5f29868..3a0e46e 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. -- 2.8.4