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 5D0B65A34 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 44E1F27ACB for ; Tue, 5 Jul 2016 17:42:01 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Date: Tue, 5 Jul 2016 17:41:44 +0200 Message-Id: <1467733310-20875-13-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 12/18] mbuf: support Gre 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 Gre tunnels in rte_pktmbuf_get_ptype(). Signed-off-by: Jean Dao Signed-off-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_ptype.c | 40 ++++++++++++++++++++++++++++++++++++---- lib/librte_mbuf/rte_mbuf_ptype.h | 2 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf_ptype.c b/lib/librte_mbuf/rte_mbuf_ptype.c index 1fddbc3..f681a42 100644 --- a/lib/librte_mbuf/rte_mbuf_ptype.c +++ b/lib/librte_mbuf/rte_mbuf_ptype.c @@ -42,6 +42,7 @@ #include #include #include +#include /* get l3 packet type from ip6 next protocol */ static uint32_t @@ -150,11 +151,40 @@ ptype_inner_l4(uint8_t proto) return ptype_inner_l4_proto[proto]; } -/* get the tunnel packet type if any, update proto. */ +/* get the tunnel packet type if any, update proto and off. */ static uint32_t -ptype_tunnel(uint16_t *proto) +ptype_tunnel(uint16_t *proto, const struct rte_mbuf *m, + uint32_t *off) { switch (*proto) { + case IPPROTO_GRE: { + static const uint8_t opt_len[16] = { + [0x0] = 4, + [0x1] = 8, + [0x2] = 8, + [0x8] = 8, + [0x3] = 12, + [0x9] = 12, + [0xa] = 12, + [0xb] = 16, + }; + const struct gre_hdr *gh; + struct gre_hdr gh_copy; + uint16_t flags; + + gh = rte_pktmbuf_read(m, *off, sizeof(*gh), &gh_copy); + if (unlikely(gh == NULL)) + return 0; + + flags = rte_be_to_cpu_16(*(const uint16_t *)gh); + flags >>= 12; + if (opt_len[flags] == 0) + return 0; + + *off += opt_len[flags]; + *proto = gh->proto; + return RTE_PTYPE_TUNNEL_GRE; + } case IPPROTO_IPIP: *proto = rte_cpu_to_be_16(ETHER_TYPE_IPv4); return RTE_PTYPE_TUNNEL_IP; @@ -352,9 +382,11 @@ uint32_t rte_pktmbuf_get_ptype(const struct rte_mbuf *m, hdr_lens->l4_len = sizeof(struct sctp_hdr); return pkt_type; } else { + uint32_t prev_off = off; + hdr_lens->l4_len = 0; - pkt_type |= ptype_tunnel(&proto); - hdr_lens->tunnel_len = 0; + pkt_type |= ptype_tunnel(&proto, m, &off); + hdr_lens->tunnel_len = off - prev_off; } /* same job for inner header: we need to duplicate the code diff --git a/lib/librte_mbuf/rte_mbuf_ptype.h b/lib/librte_mbuf/rte_mbuf_ptype.h index 87749b0..d037504 100644 --- a/lib/librte_mbuf/rte_mbuf_ptype.h +++ b/lib/librte_mbuf/rte_mbuf_ptype.h @@ -597,7 +597,7 @@ struct rte_mbuf_hdr_lens { * L2: Ether, Vlan, QinQ, Mpls * L3: IPv4, IPv6 * L4: TCP, UDP, SCTP - * Tunnels: IPv4, IPv6 + * Tunnels: IPv4, IPv6, Gre * * @param m * The packet mbuf to be parsed. -- 2.8.1