From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 6484F591F for ; Tue, 5 Jul 2016 17:42:01 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 4F4FB27ACC for ; Tue, 5 Jul 2016 17:42:01 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Date: Tue, 5 Jul 2016 17:41:45 +0200 Message-Id: <1467733310-20875-14-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1467733310-20875-1-git-send-email-olivier.matz@6wind.com> References: <1467733310-20875-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH 13/18] mbuf: support Nvgre in software packet type parser X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2016 15:42:02 -0000 Add support of Nvgre tunnels in rte_pktmbuf_get_ptype(). At the same time, as Nvgre transports Ethernet, we need to add the support for inner Vlan, QinQ, and Mpls. Signed-off-by: Jean Dao Signed-off-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_ptype.c | 48 ++++++++++++++++++++++++++++++++++++++-- lib/librte_mbuf/rte_mbuf_ptype.h | 20 ++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf_ptype.c b/lib/librte_mbuf/rte_mbuf_ptype.c index f681a42..e5be308 100644 --- a/lib/librte_mbuf/rte_mbuf_ptype.c +++ b/lib/librte_mbuf/rte_mbuf_ptype.c @@ -183,7 +183,10 @@ ptype_tunnel(uint16_t *proto, const struct rte_mbuf *m, *off += opt_len[flags]; *proto = gh->proto; - return RTE_PTYPE_TUNNEL_GRE; + if (*proto == rte_cpu_to_be_16(ETHER_TYPE_TEB)) + return RTE_PTYPE_TUNNEL_NVGRE; + else + return RTE_PTYPE_TUNNEL_GRE; } case IPPROTO_IPIP: *proto = rte_cpu_to_be_16(ETHER_TYPE_IPv4); @@ -392,7 +395,48 @@ uint32_t rte_pktmbuf_get_ptype(const struct rte_mbuf *m, /* same job for inner header: we need to duplicate the code * because the packet types do not have the same value. */ - hdr_lens->inner_l2_len = 0; + if (proto == rte_cpu_to_be_16(ETHER_TYPE_TEB)) { + eh = rte_pktmbuf_read(m, off, sizeof(*eh), &eh_copy); + if (unlikely(eh == NULL)) + return pkt_type; + pkt_type |= RTE_PTYPE_INNER_L2_ETHER; + proto = eh->ether_type; + off += sizeof(*eh); + hdr_lens->inner_l2_len = sizeof(*eh); + } + + if (proto == rte_cpu_to_be_16(ETHER_TYPE_VLAN)) { + const struct vlan_hdr *vh; + struct vlan_hdr vh_copy; + + pkt_type &= ~RTE_PTYPE_INNER_L2_MASK; + pkt_type |= RTE_PTYPE_INNER_L2_ETHER_VLAN; + vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy); + if (unlikely(vh == NULL)) + return pkt_type; + off += sizeof(*vh); + hdr_lens->inner_l2_len += sizeof(*vh); + proto = vh->eth_proto; + } else if (proto == rte_cpu_to_be_16(ETHER_TYPE_QINQ)) { + const struct vlan_hdr *vh; + struct vlan_hdr vh_copy; + + pkt_type &= ~RTE_PTYPE_INNER_L2_MASK; + pkt_type |= RTE_PTYPE_INNER_L2_ETHER_QINQ; + vh = rte_pktmbuf_read(m, off + sizeof(*vh), sizeof(*vh), + &vh_copy); + if (unlikely(vh == NULL)) + return pkt_type; + off += 2 * sizeof(*vh); + hdr_lens->inner_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))) { + pkt_type &= ~RTE_PTYPE_INNER_L2_MASK; + pkt_type |= RTE_PTYPE_INNER_L2_ETHER_MPLS; + hdr_lens->inner_l2_len += 4; + return pkt_type; + } if (proto == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { const struct ipv4_hdr *ip4h; diff --git a/lib/librte_mbuf/rte_mbuf_ptype.h b/lib/librte_mbuf/rte_mbuf_ptype.h index d037504..be3ad96 100644 --- a/lib/librte_mbuf/rte_mbuf_ptype.h +++ b/lib/librte_mbuf/rte_mbuf_ptype.h @@ -403,6 +403,24 @@ extern "C" { */ #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000 /** + * QinQ packet type. + * + * Packet format: + * <'ether type'=[0x88A8]> + */ +#define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000 +/** + * MPLS packet type. + * + * Packet format: + * <'ether type'=[0x8847|0x0x8848]> + */ +#define RTE_PTYPE_INNER_L2_ETHER_MPLS 0x00040000 +/** + * Mask of layer 2 packet types. + * It is used for outer packet for tunneling cases. + */ +/** * Mask of inner layer 2 packet types. */ #define RTE_PTYPE_INNER_L2_MASK 0x000f0000 @@ -597,7 +615,7 @@ struct rte_mbuf_hdr_lens { * L2: Ether, Vlan, QinQ, Mpls * L3: IPv4, IPv6 * L4: TCP, UDP, SCTP - * Tunnels: IPv4, IPv6, Gre + * Tunnels: IPv4, IPv6, Gre, Nvgre * * @param m * The packet mbuf to be parsed. -- 2.8.1