From patchwork Tue Oct 23 07:46:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 47212 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8D1911B2AC; Tue, 23 Oct 2018 09:47:13 +0200 (CEST) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 68E8E1B296 for ; Tue, 23 Oct 2018 09:47:12 +0200 (CEST) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 64B44207921; Tue, 23 Oct 2018 09:43:21 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: jerin.jacob@caviumnetworks.com Date: Tue, 23 Oct 2018 09:46:48 +0200 Message-Id: <20181023074649.10438-1-olivier.matz@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH 1/2] net: add Mpls header structure 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" Add the Mpls header structure in librte_net. It will be used by next patch that adds the support of Mpls L2 layer in the software packet type parser. Signed-off-by: Olivier Matz Reviewed-by: Ferruh Yigit --- lib/librte_net/Makefile | 2 +- lib/librte_net/meson.build | 3 ++- lib/librte_net/rte_mpls.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 lib/librte_net/rte_mpls.h diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile index 85e403f41..c3082069a 100644 --- a/lib/librte_net/Makefile +++ b/lib/librte_net/Makefile @@ -20,6 +20,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_NET) += rte_arp.c SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h rte_esp.h SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include += rte_sctp.h rte_icmp.h rte_arp.h SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include += rte_ether.h rte_gre.h rte_net.h -SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include += rte_net_crc.h +SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include += rte_net_crc.h rte_mpls.h include $(RTE_SDK)/mk/rte.lib.mk diff --git a/lib/librte_net/meson.build b/lib/librte_net/meson.build index d3ea1feb5..7d66f693c 100644 --- a/lib/librte_net/meson.build +++ b/lib/librte_net/meson.build @@ -13,7 +13,8 @@ headers = files('rte_ip.h', 'rte_ether.h', 'rte_gre.h', 'rte_net.h', - 'rte_net_crc.h') + 'rte_net_crc.h', + 'rte_mpls.h') sources = files('rte_arp.c', 'rte_net.c', 'rte_net_crc.c') deps += ['mbuf'] diff --git a/lib/librte_net/rte_mpls.h b/lib/librte_net/rte_mpls.h new file mode 100644 index 000000000..11d26ba35 --- /dev/null +++ b/lib/librte_net/rte_mpls.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2016 6WIND S.A. + */ + +#ifndef _RTE_MPLS_H_ +#define _RTE_MPLS_H_ + +/** + * @file + * + * MPLS-related defines + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * MPLS header. + */ +struct mpls_hdr { + uint16_t tag_msb; /**< Label(msb). */ +#if RTE_BYTE_ORDER == RTE_BIG_ENDIAN + uint8_t tag_lsb:4; /**< Label(lsb). */ + uint8_t tc:3; /**< Traffic class. */ + uint8_t bs:1; /**< Bottom of stack. */ +#else + uint8_t bs:1; /**< Bottom of stack. */ + uint8_t tc:3; /**< Traffic class. */ + uint8_t tag_lsb:4; /**< label(lsb) */ +#endif + uint8_t ttl; /**< Time to live. */ +} __attribute__((__packed__)); + +#ifdef __cplusplus +} +#endif + +#endif /* RTE_MPLS_H_ */ From patchwork Tue Oct 23 07:46:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 47213 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A2FAB1B3AC; Tue, 23 Oct 2018 09:47:15 +0200 (CEST) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 6D2301B2AB for ; Tue, 23 Oct 2018 09:47:12 +0200 (CEST) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 70811207922; Tue, 23 Oct 2018 09:43:21 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: jerin.jacob@caviumnetworks.com, Didier Pallard Date: Tue, 23 Oct 2018 09:46:49 +0200 Message-Id: <20181023074649.10438-2-olivier.matz@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181023074649.10438-1-olivier.matz@6wind.com> References: <20181023074649.10438-1-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH 2/2] net: support Mpls in software packet type parser 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" Add a new RTE_PTYPE_L2_ETHER_MPLS packet type, and its support in rte_net_get_ptype(). Signed-off-by: Didier Pallard Signed-off-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_ptype.h | 7 +++++++ lib/librte_net/rte_ether.h | 2 ++ lib/librte_net/rte_net.c | 21 ++++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf_ptype.h b/lib/librte_mbuf/rte_mbuf_ptype.h index 01acc66e2..3029777e2 100644 --- a/lib/librte_mbuf/rte_mbuf_ptype.h +++ b/lib/librte_mbuf/rte_mbuf_ptype.h @@ -131,6 +131,13 @@ extern "C" { */ #define RTE_PTYPE_L2_ETHER_PPPOE 0x00000008 /** + * MPLS packet type. + * + * Packet format: + * <'ether type'=[0x8847|0x0x8848]> + */ +#define RTE_PTYPE_L2_ETHER_MPLS 0x00000009 +/** * Mask of layer 2 packet types. * It is used for outer packet for tunneling cases. */ diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index bee2b34f0..c2c5e249f 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -306,6 +306,8 @@ struct vxlan_hdr { #define ETHER_TYPE_SLOW 0x8809 /**< Slow protocols (LACP and Marker). */ #define ETHER_TYPE_TEB 0x6558 /**< Transparent Ethernet Bridging. */ #define ETHER_TYPE_LLDP 0x88CC /**< LLDP Protocol. */ +#define ETHER_TYPE_MPLS 0x8847 /**< MPLS ethertype. */ +#define ETHER_TYPE_MPLSM 0x8848 /**< MPLS multicast ethertype. */ #define ETHER_VXLAN_HLEN (sizeof(struct udp_hdr) + sizeof(struct vxlan_hdr)) /**< VXLAN tunnel header length. */ diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c index 9eb7c7438..378a4126c 100644 --- a/lib/librte_net/rte_net.c +++ b/lib/librte_net/rte_net.c @@ -13,6 +13,7 @@ #include #include #include +#include #include /* get l3 packet type from ip6 next protocol */ @@ -274,9 +275,27 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m, off += 2 * sizeof(*vh); hdr_lens->l2_len += 2 * sizeof(*vh); proto = vh->eth_proto; + } else if ((proto == rte_cpu_to_be_16(ETHER_TYPE_MPLS)) || + (proto == rte_cpu_to_be_16(ETHER_TYPE_MPLSM))) { + unsigned int i; + const struct mpls_hdr *mh; + struct mpls_hdr mh_copy; + +#define MAX_MPLS_HDR 5 + for (i = 0; i < MAX_MPLS_HDR; i++) { + mh = rte_pktmbuf_read(m, off + (i * sizeof(*mh)), + sizeof(*mh), &mh_copy); + if (unlikely(mh == NULL)) + return pkt_type; + } + if (i == MAX_MPLS_HDR) + return pkt_type; + pkt_type = RTE_PTYPE_L2_ETHER_MPLS; + hdr_lens->l2_len += (sizeof(*mh) * i); + return pkt_type; } - l3: +l3: if ((layers & RTE_PTYPE_L3_MASK) == 0) return pkt_type;