From: Olivier Matz Date: Mon, 3 Oct 2016 08:38:52 +0000 (+0200) Subject: net: support NVGRE in software packet type parser X-Git-Tag: spdx-start~5677 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=2c15c5377da23863b02a4b94ae89a3a76dfa0e4a;p=dpdk.git net: support NVGRE in software packet type parser Add support of Nvgre tunnels in rte_net_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 --- diff --git a/lib/librte_mbuf/rte_mbuf_ptype.h b/lib/librte_mbuf/rte_mbuf_ptype.h index 6e62492d49..fbe764a6c0 100644 --- a/lib/librte_mbuf/rte_mbuf_ptype.h +++ b/lib/librte_mbuf/rte_mbuf_ptype.h @@ -395,6 +395,13 @@ extern "C" { * <'ether type'=[0x800|0x86DD], vlan=[1-4095]> */ #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000 +/** + * QinQ packet type. + * + * Packet format: + * <'ether type'=[0x88A8]> + */ +#define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000 /** * Mask of inner layer 2 packet types. */ diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c index 66db2c833c..53cfef8a3a 100644 --- a/lib/librte_net/rte_net.c +++ b/lib/librte_net/rte_net.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); @@ -372,7 +375,42 @@ uint32_t rte_net_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; + } if (proto == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { const struct ipv4_hdr *ip4h; diff --git a/lib/librte_net/rte_net.h b/lib/librte_net/rte_net.h index 4a72b1b2d4..02299db93a 100644 --- a/lib/librte_net/rte_net.h +++ b/lib/librte_net/rte_net.h @@ -68,7 +68,7 @@ struct rte_net_hdr_lens { * L2: Ether, Vlan, QinQ * L3: IPv4, IPv6 * L4: TCP, UDP, SCTP - * Tunnels: IPv4, IPv6, Gre + * Tunnels: IPv4, IPv6, Gre, Nvgre * * @param m * The packet mbuf to be parsed.