net: support VLAN in software packet type parser
authorOlivier Matz <olivier.matz@6wind.com>
Mon, 3 Oct 2016 08:38:47 +0000 (10:38 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 11 Oct 2016 16:17:12 +0000 (18:17 +0200)
Add a new RTE_PTYPE_L2_ETHER_VLAN packet type, and its support in
rte_net_get_ptype().

Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
lib/librte_mbuf/rte_mbuf_ptype.h
lib/librte_net/rte_net.c

index 65e9ced..a955c5a 100644 (file)
@@ -135,6 +135,13 @@ extern "C" {
  * <'ether type'=0x894F>
  */
 #define RTE_PTYPE_L2_ETHER_NSH              0x00000005
+/**
+ * VLAN packet type.
+ *
+ * Packet format:
+ * <'ether type'=[0x8100]>
+ */
+#define RTE_PTYPE_L2_ETHER_VLAN             0x00000006
 /**
  * Mask of layer 2 packet types.
  * It is used for outer packet for tunneling cases.
index 93e9df0..a75b509 100644 (file)
@@ -167,6 +167,19 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
        off = sizeof(*eh);
        hdr_lens->l2_len = off;
 
+       if (proto == rte_cpu_to_be_16(ETHER_TYPE_VLAN)) {
+               const struct vlan_hdr *vh;
+               struct vlan_hdr vh_copy;
+
+               pkt_type = RTE_PTYPE_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->l2_len += sizeof(*vh);
+               proto = vh->eth_proto;
+       }
+
        if (proto == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
                const struct ipv4_hdr *ip4h;
                struct ipv4_hdr ip4h_copy;