[dpdk-dev] [PATCH 09/18] mbuf: support Mpls in software packet type parser
Olivier Matz
olivier.matz at 6wind.com
Tue Jul 5 17:41:41 CEST 2016
Add a new RTE_PTYPE_L2_ETHER_MPLS packet type, and its support in
rte_pktmbuf_get_ptype().
Signed-off-by: Didier Pallard <didier.pallard at 6wind.com>
Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
---
lib/librte_mbuf/rte_mbuf_ptype.c | 25 +++++++++++++++++++++++++
lib/librte_mbuf/rte_mbuf_ptype.h | 9 ++++++++-
lib/librte_net/Makefile | 4 +++-
lib/librte_net/rte_ether.h | 2 ++
4 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/lib/librte_mbuf/rte_mbuf_ptype.c b/lib/librte_mbuf/rte_mbuf_ptype.c
index 5d46608..0dea600 100644
--- a/lib/librte_mbuf/rte_mbuf_ptype.c
+++ b/lib/librte_mbuf/rte_mbuf_ptype.c
@@ -41,6 +41,7 @@
#include <rte_tcp.h>
#include <rte_udp.h>
#include <rte_sctp.h>
+#include <rte_mpls.h>
/* get l3 packet type from ip6 next protocol */
static uint32_t
@@ -166,6 +167,9 @@ uint32_t rte_pktmbuf_get_ptype(const struct rte_mbuf *m,
off = sizeof(*eh);
hdr_lens->l2_len = off;
+ if (proto == rte_cpu_to_be_16(ETHER_TYPE_IPv4))
+ goto l3; /* fast path if packet is IPv4 */
+
if (proto == rte_cpu_to_be_16(ETHER_TYPE_VLAN)) {
const struct vlan_hdr *vh;
struct vlan_hdr vh_copy;
@@ -189,8 +193,29 @@ uint32_t rte_pktmbuf_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 (mh->bs)
+ break;
+ }
+ if (i == MAX_MPLS_HDR)
+ return pkt_type;
+ pkt_type = RTE_PTYPE_L2_ETHER_MPLS;
+ hdr_lens->l2_len += (sizeof(*mh) * (i + 1));
+ return pkt_type;
}
+ l3:
if (proto == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
const struct ipv4_hdr *ip4h;
struct ipv4_hdr ip4h_copy;
diff --git a/lib/librte_mbuf/rte_mbuf_ptype.h b/lib/librte_mbuf/rte_mbuf_ptype.h
index e2e92d0..adc4c03 100644
--- a/lib/librte_mbuf/rte_mbuf_ptype.h
+++ b/lib/librte_mbuf/rte_mbuf_ptype.h
@@ -150,6 +150,13 @@ extern "C" {
*/
#define RTE_PTYPE_L2_ETHER_QINQ 0x00000007
/**
+ * MPLS packet type.
+ *
+ * Packet format:
+ * <'ether type'=[0x8847|0x0x8848]>
+ */
+#define RTE_PTYPE_L2_ETHER_MPLS 0x00000008
+/**
* Mask of layer 2 packet types.
* It is used for outer packet for tunneling cases.
*/
@@ -587,7 +594,7 @@ struct rte_mbuf_hdr_lens {
* (retval & RTE_PTYPE_L2_MASK) != RTE_PTYPE_UNKNOWN.
*
* Supported packet types are:
- * L2: Ether, Vlan, QinQ
+ * L2: Ether, Vlan, QinQ, Mpls
* L3: IPv4, IPv6
* L4: TCP, UDP, SCTP
*
diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile
index fc332ff..af57f40 100644
--- a/lib/librte_net/Makefile
+++ b/lib/librte_net/Makefile
@@ -34,7 +34,9 @@ include $(RTE_SDK)/mk/rte.vars.mk
CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
# install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.h rte_sctp.h rte_icmp.h rte_arp.h rte_ether.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include := rte_ip.h rte_tcp.h rte_udp.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_mpls.h
include $(RTE_SDK)/mk/rte.install.mk
diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index ff3d065..254cb2d 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -333,6 +333,8 @@ struct vxlan_hdr {
#define ETHER_TYPE_1588 0x88F7 /**< IEEE 802.1AS 1588 Precise Time Protocol. */
#define ETHER_TYPE_SLOW 0x8809 /**< Slow protocols (LACP and Marker). */
#define ETHER_TYPE_TEB 0x6558 /**< Transparent Ethernet Bridging. */
+#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. */
--
2.8.1
More information about the dev
mailing list