[dpdk-dev] [PATCH v2 4/5] gso: add GRE GSO support

Jiayu Hu jiayu.hu at intel.com
Tue Sep 5 09:57:49 CEST 2017


From: Mark Kavanagh <mark.b.kavanagh at intel.com>

This patch adds GSO support for GRE-tunneled packets. Supported GRE
packets must contain an outer IPv4 header, and inner TCP/IPv4 headers.
They may also contain a single VLAN tag. GRE GSO assumes that all input
packets have correct checksums and doesn't update checksums for output
packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each
output packet, which requires multi-segment mbuf support in the TX
functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces
its MBUF refcnt by 1. As a result, when all of its GSOed segments are
freed, the packet is freed automatically.

Signed-off-by: Mark Kavanagh <mark.b.kavanagh at intel.com>
Signed-off-by: Jiayu Hu <jiayu.hu at intel.com>
---
 lib/librte_gso/gso_common.c | 24 ++++++++++++++++++++++++
 lib/librte_gso/gso_common.h | 15 +++++++++++++++
 lib/librte_gso/rte_gso.c    |  2 ++
 3 files changed, 41 insertions(+)

diff --git a/lib/librte_gso/gso_common.c b/lib/librte_gso/gso_common.c
index 1e16c9c..668d2d0 100644
--- a/lib/librte_gso/gso_common.c
+++ b/lib/librte_gso/gso_common.c
@@ -37,6 +37,7 @@
 #include <rte_malloc.h>
 
 #include <rte_ether.h>
+#include <rte_gre.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
@@ -238,6 +239,25 @@ update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
 	update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
 }
 
+static inline void
+update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t i, id;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	for (i = 0; i < nb_segs; i++) {
+		update_outer_ipv4_header(segs[i], id);
+		id += ipid_delta;
+	}
+
+	/* update inner TCP/IPv4 headers */
+	update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+}
+
 void
 gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
 		struct rte_mbuf **segs, uint16_t nb_segs)
@@ -249,6 +269,10 @@ gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
 	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
 		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, segs, nb_segs);
 		break;
+	case ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT:
+	case ETHER_IPv4_GRE_IPv4_TCP_PKT:
+		update_ipv4_gre_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+		break;
 	case ETHER_VLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_TCP_PKT:
 		update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
diff --git a/lib/librte_gso/gso_common.h b/lib/librte_gso/gso_common.h
index 3f76fd1..bd53bde 100644
--- a/lib/librte_gso/gso_common.h
+++ b/lib/librte_gso/gso_common.h
@@ -85,6 +85,21 @@
 		RTE_PTYPE_TUNNEL_VXLAN | \
 		INNER_ETHER_VLAN_IPv4_TCP_PKT)
 
+/* GRE packet. */
+#define ETHER_IPv4_GRE_IPv4_TCP_PKT (\
+		ETHER_IPv4_PKT          | \
+		RTE_PTYPE_TUNNEL_GRE    | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
+/* GRE packet with VLAN tag. */
+#define ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT (\
+		RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4       | \
+		RTE_PTYPE_TUNNEL_GRE    | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
 /**
  * Internal function which updates relevant packet headers, following
  * segmentation. This is required to update, for example, the IPv4
diff --git a/lib/librte_gso/rte_gso.c b/lib/librte_gso/rte_gso.c
index 0170abc..d40fda9 100644
--- a/lib/librte_gso/rte_gso.c
+++ b/lib/librte_gso/rte_gso.c
@@ -76,6 +76,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	case ETHER_VLAN_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+	case ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT:
+	case ETHER_IPv4_GRE_IPv4_TCP_PKT:
 		ret = gso_tunnel_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
-- 
2.7.4



More information about the dev mailing list