[dpdk-dev] [PATCH 08/12] i40e: extend flow director to filter by tunnel ID

Jingjing Wu jingjing.wu at intel.com
Tue Jan 26 07:20:20 CET 2016


This patch extended flow director to select Vxlan/GRE tunnel ID
as filter's input set and program the filter rule with the defined
tunnel type.

Signed-off-by: Jingjing Wu <jingjing.wu at intel.com>
---
 drivers/net/i40e/i40e_ethdev.c |  11 ++++
 drivers/net/i40e/i40e_fdir.c   | 125 ++++++++++++++++++++++++++++++-----------
 2 files changed, 102 insertions(+), 34 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 32ffc9f..62cdf81 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -6555,48 +6555,59 @@ i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
 	 */
 	static const uint64_t valid_fdir_inset_table[] = {
 		[I40E_FILTER_PCTYPE_FRAG_IPV4] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
 		I40E_INSET_IPV4_TTL,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
 		I40E_INSET_SCTP_VT,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
 		I40E_INSET_IPV4_TTL,
 		[I40E_FILTER_PCTYPE_FRAG_IPV6] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
 		I40E_INSET_IPV6_HOP_LIMIT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
 		I40E_INSET_SCTP_VT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
 		I40E_INSET_IPV6_HOP_LIMIT,
 		[I40E_FILTER_PCTYPE_L2_PAYLOAD] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_LAST_ETHER_TYPE,
 	};
 
diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index 5ea97e5..7566017 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -688,11 +688,13 @@ i40e_fdir_configure(struct rte_eth_dev *dev)
 
 static inline void
 i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
-			       unsigned char *raw_pkt)
+			       unsigned char *pkt, bool need_mac)
 {
-	struct ether_hdr *ether = (struct ether_hdr *)raw_pkt;
-	struct ipv4_hdr *ip;
-	struct ipv6_hdr *ip6;
+	struct ether_hdr *ether = (struct ether_hdr *)pkt;
+	struct ipv4_hdr *ip =
+			(struct ipv4_hdr *)(pkt + sizeof(struct ether_hdr));
+	struct ipv6_hdr *ip6 =
+			(struct ipv6_hdr *)(pkt + sizeof(struct ether_hdr));
 	static const uint8_t next_proto[] = {
 		[RTE_ETH_FLOW_FRAG_IPV4] = IPPROTO_IP,
 		[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] = IPPROTO_TCP,
@@ -708,16 +710,18 @@ i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
 
 	switch (fdir_input->flow_type) {
 	case RTE_ETH_FLOW_L2_PAYLOAD:
-		ether->ether_type = fdir_input->flow.l2_flow.ether_type;
+		if (need_mac)
+			ether->ether_type = fdir_input->flow.l2_flow.ether_type;
 		break;
 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV4:
-		ip = (struct ipv4_hdr *)(raw_pkt + sizeof(struct ether_hdr));
-
-		ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
+		if (!need_mac)
+			ip = (struct ipv4_hdr *)pkt;
+		else
+			ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
 		ip->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
 		/* set len to by default */
 		ip->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
@@ -741,9 +745,10 @@ i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV6:
-		ip6 = (struct ipv6_hdr *)(raw_pkt + sizeof(struct ether_hdr));
-
-		ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
+		if (!need_mac)
+			ip6 = (struct ipv6_hdr *)pkt;
+		else
+			ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
 		ip6->vtc_flow =
 			rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
 					 (fdir_input->flow.ipv6_flow.tc <<
@@ -775,7 +780,7 @@ i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
 	}
 }
 
-
+#define I40E_TUNNEL_KEY_LEN 4
 /*
  * i40e_fdir_construct_pkt - construct packet based on fields in input
  * @pf: board private structure
@@ -787,21 +792,80 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 			     const struct rte_eth_fdir_input *fdir_input,
 			     unsigned char *raw_pkt)
 {
-	unsigned char *payload, *ptr;
+	unsigned char *payload, *ptr, *inner_pkt = raw_pkt;
 	struct udp_hdr *udp;
 	struct tcp_hdr *tcp;
 	struct sctp_hdr *sctp;
 	uint8_t size, dst = 0;
 	uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
-
-	/* fill the ethernet and IP head */
-	i40e_fdir_fill_eth_ip_head(fdir_input, raw_pkt);
-
+	bool need_mac = TRUE;
+	static uint8_t gre4_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x2F,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0x08, 0,
+			0, 0, 0, 0}; /* Mac+ IP + GRE hdr + key */
+	static uint8_t gre6_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x2F,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0x86, 0xDD,
+			0, 0, 0, 0, 0}; /* Mac+ IP + GRE hdr + key */
+	static uint8_t vxlan_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x11,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+			0x12, 0xB5, 0x12, 0xB5, 0x08, 0, 0, 0,
+			0, 0, 0, 0, 0, 0, 0, 0}; /* Mac + IP + UDP + VXLAN hdr */
+	static uint8_t nvgre_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x2F,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0x65, 0x58,
+			0, 0, 0, 0}; /*Mac + IP + NVGRE hdr*/
+
+	inner_pkt += 2 * sizeof(struct ether_addr);
+	/* fill the tunnel header if required */
+	switch (fdir_input->flow.tunnel_flow.tunnel_type) {
+	case RTE_FDIR_TUNNEL_TYPE_GRE:
+		if (fdir_input->flow_type == RTE_ETH_FLOW_L2_PAYLOAD) {
+			PMD_DRV_LOG(ERR, "GRE's inner pkt shouldn't"
+				    " be L2 frame.");
+			return -EINVAL;
+		}
+		if ((fdir_input->flow_type) == RTE_ETH_FLOW_FRAG_IPV4 ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_TCP ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_UDP ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_SCTP ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_OTHER)
+			rte_memcpy(inner_pkt, gre4_frame, sizeof(gre4_frame));
+		else
+			rte_memcpy(inner_pkt, gre6_frame, sizeof(gre6_frame));
+		/* gre4_frame and gre4_frame have the same size */
+		inner_pkt += sizeof(gre4_frame);
+		rte_memcpy(inner_pkt - I40E_TUNNEL_KEY_LEN,
+			   &fdir_input->flow.tunnel_flow.tunnel_id,
+			   I40E_TUNNEL_KEY_LEN);
+		need_mac = FALSE;
+		break;
+	case RTE_FDIR_TUNNEL_TYPE_VXLAN:
+		rte_memcpy(inner_pkt, vxlan_frame, sizeof(vxlan_frame));
+		inner_pkt += sizeof(vxlan_frame);
+		rte_memcpy(inner_pkt - I40E_TUNNEL_KEY_LEN,
+			   &fdir_input->flow.tunnel_flow.tunnel_id,
+			   I40E_TUNNEL_KEY_LEN);
+		break;
+	case RTE_FDIR_TUNNEL_TYPE_NVGRE:
+		rte_memcpy(inner_pkt, nvgre_frame, sizeof(nvgre_frame));
+		inner_pkt += sizeof(nvgre_frame);
+		rte_memcpy(inner_pkt - I40E_TUNNEL_KEY_LEN,
+			   &fdir_input->flow.tunnel_flow.tunnel_id,
+			   I40E_TUNNEL_KEY_LEN);
+		break;
+	default:
+		break;
+	}
+	/* fill the ethernet and IP head of inner or single frame */
+	i40e_fdir_fill_eth_ip_head(fdir_input, inner_pkt, need_mac);
+	if (need_mac)
+		inner_pkt += sizeof(struct ether_hdr);
 	/* fill the L4 head */
 	switch (fdir_input->flow_type) {
 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
-		udp = (struct udp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-				sizeof(struct ipv4_hdr));
+		udp = (struct udp_hdr *)(inner_pkt + sizeof(struct ipv4_hdr));
 		payload = (unsigned char *)udp + sizeof(struct udp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -814,8 +878,7 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
-		tcp = (struct tcp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					 sizeof(struct ipv4_hdr));
+		tcp = (struct tcp_hdr *)(inner_pkt + sizeof(struct ipv4_hdr));
 		payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -828,8 +891,7 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
-		sctp = (struct sctp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					   sizeof(struct ipv4_hdr));
+		sctp = (struct sctp_hdr *)(inner_pkt + sizeof(struct ipv4_hdr));
 		payload = (unsigned char *)sctp + sizeof(struct sctp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -843,14 +905,12 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 
 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV4:
-		payload = raw_pkt + sizeof(struct ether_hdr) +
-			  sizeof(struct ipv4_hdr);
+		payload = inner_pkt + sizeof(struct ipv4_hdr);
 		set_idx = I40E_FLXPLD_L3_IDX;
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
-		udp = (struct udp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					 sizeof(struct ipv6_hdr));
+		udp = (struct udp_hdr *)(inner_pkt + sizeof(struct ipv6_hdr));
 		payload = (unsigned char *)udp + sizeof(struct udp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -863,8 +923,7 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
-		tcp = (struct tcp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					 sizeof(struct ipv6_hdr));
+		tcp = (struct tcp_hdr *)(inner_pkt + sizeof(struct ipv6_hdr));
 		payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -877,8 +936,7 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
-		sctp = (struct sctp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					   sizeof(struct ipv6_hdr));
+		sctp = (struct sctp_hdr *)(inner_pkt + sizeof(struct ipv6_hdr));
 		payload = (unsigned char *)sctp + sizeof(struct sctp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -892,12 +950,11 @@ i40e_fdir_construct_pkt(struct i40e_pf *pf,
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV6:
-		payload = raw_pkt + sizeof(struct ether_hdr) +
-			  sizeof(struct ipv6_hdr);
+		payload = inner_pkt + sizeof(struct ipv6_hdr);
 		set_idx = I40E_FLXPLD_L3_IDX;
 		break;
 	case RTE_ETH_FLOW_L2_PAYLOAD:
-		payload = raw_pkt + sizeof(struct ether_hdr);
+		payload = inner_pkt;
 		/*
 		 * ARP packet is a special case on which the payload
 		 * starts after the whole ARP header
-- 
2.4.0



More information about the dev mailing list