Skip to contentSkip to conversation

examples/ip_fragmentation: fix check of packet type

PATCH Superseded Wei Dai 2 participants 8 messages Mar 10, 2017 – Mar 14, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Dai

author
#0 lore raw

PATCH 1/1 examples/ip_fragmentation: fix check of packet type

The packet_type in mbuf is not correctly filled by ixgbe 82599 NIC. To use the ether_type in ethernet header to check packet type is more reliaber.

Fixes 3c0184cc0c60 ("examples: replace some offload flags with packet type")
Fixes ab351fe1c95c ("mbuf: remove packet type from offload flags")
---
 examples/ip_fragmentation/main.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
examples/ip_fragmentation/main.c +6 -4
index e1e32c6..8612984 100644
@@ -268,6 +268,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 	uint32_t i, len, next_hop_ipv4;
 	uint8_t next_hop_ipv6, port_out, ipv6;
 	int32_t len2;
+	struct ether_hdr *eth_hdr;
 
 	ipv6 = 0;
 	rxq = &qconf->rx_queue_list[queueid];
@@ -276,13 +277,14 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 	port_out = port_in;
 
 	/* Remove the Ethernet header and trailer from the input packet */
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	rte_pktmbuf_adj(m, (uint16_t)sizeof(struct ether_hdr));
 
 	/* Build transmission burst */
 	len = qconf->tx_mbufs[port_out].len;
 
 	/* if this is an IPv4 packet */
-	if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
+	if (eth_hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
 		struct ipv4_hdr *ip_hdr;
 		uint32_t ip_dst;
 		/* Read the lookup key (i.e. ip_dst) from the input packet */
@@ -316,7 +318,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 			if (unlikely (len2 < 0))
 				return;
 		}
-	} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
+	} else if (eth_hdr->ether_type == rte_be_to_cpu_16(ETHER_TYPE_IPv6)) {
 		/* if this is an IPv6 packet */
 		struct ipv6_hdr *ip_hdr;
 
@@ -363,8 +365,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 		void *d_addr_bytes;
 
 		m = qconf->tx_mbufs[port_out].m_table[i];
-		struct ether_hdr *eth_hdr = (struct ether_hdr *)
-			rte_pktmbuf_prepend(m, (uint16_t)sizeof(struct ether_hdr));
+		eth_hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m,
+			(uint16_t)sizeof(struct ether_hdr));
 		if (eth_hdr == NULL) {
 			rte_panic("No headroom in mbuf.\n");
 		}
Signature · 1 line
2.7.4
author Tested-by Fangfang Wei on v1 1/1
#1 lore raw

Sorry, correct the name of Tester

Quoted 10 lines

-----Original Message-----
From: Dai, Wei
Sent: Friday, March 10, 2017 11:28 AM
To: [email protected]; Ananyev, Konstantin <[email protected]>
Cc: Dai, Wei <[email protected]>; [email protected]
Subject: [PATCH] examples/ip_fragmentation: fix check of packet type

The packet_type in mbuf is not correctly filled by ixgbe 82599 NIC. To use the ether_type in ethernet header to check packet type is more reliaber.

Quoted 7 lines
Fixes 3c0184cc0c60 ("examples: replace some offload flags with packet type")
Fixes ab351fe1c95c ("mbuf: remove packet type from offload flags")
Quoted 59 lines
---
 examples/ip_fragmentation/main.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
examples/ip_fragmentation/main.c +1 -0
index e1e32c6..8612984 100644
@@ -268,6 +268,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct
 lcore_queue_conf *qconf,
 	uint32_t i, len, next_hop_ipv4;
 	uint8_t next_hop_ipv6, port_out, ipv6;
 	int32_t len2;
+	struct ether_hdr *eth_hdr;
 
 	ipv6 = 0;
examples/ip_fragmentation/main.c +2 -1
 	rxq = &qconf->rx_queue_list[queueid];
@@ -276,13 +277,14 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct
 lcore_queue_conf *qconf,
 	port_out = port_in;
 
 	/* Remove the Ethernet header and trailer from the input packet */
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	rte_pktmbuf_adj(m, (uint16_t)sizeof(struct ether_hdr));
 
 	/* Build transmission burst */
 	len = qconf->tx_mbufs[port_out].len;
 
 	/* if this is an IPv4 packet */
-	if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
+	if (eth_hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
 		struct ipv4_hdr *ip_hdr;
 		uint32_t ip_dst;

/* Read the lookup key (i.e. ip_dst) from the input packet */ @@
-316,7 +318,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c +3 -3
 			if (unlikely (len2 < 0))
 				return;
 		}
-	} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
+	} else if (eth_hdr->ether_type == rte_be_to_cpu_16(ETHER_TYPE_IPv6)) {
 		/* if this is an IPv6 packet */
 		struct ipv6_hdr *ip_hdr;
@@ -363,8 +365,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct
 lcore_queue_conf *qconf,
 		void *d_addr_bytes;
 
 		m = qconf->tx_mbufs[port_out].m_table[i];
-		struct ether_hdr *eth_hdr = (struct ether_hdr *)
-			rte_pktmbuf_prepend(m, (uint16_t)sizeof(struct ether_hdr));
+		eth_hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m,
+			(uint16_t)sizeof(struct ether_hdr));
 		if (eth_hdr == NULL) {
 			rte_panic("No headroom in mbuf.\n");

}
--
2.7.4

#2 lore raw
In reply to Wei Dai

Hi Wei,

Quoted 61 lines

-----Original Message-----
From: Dai, Wei
Sent: Friday, March 10, 2017 3:28 AM
To: [email protected]; Ananyev, Konstantin <[email protected]>
Cc: Dai, Wei <[email protected]>; [email protected]
Subject: [PATCH] examples/ip_fragmentation: fix check of packet type

The packet_type in mbuf is not correctly filled by ixgbe 82599 NIC. To use the ether_type in ethernet header to check packet type is more reliaber.

Fixes 3c0184cc0c60 ("examples: replace some offload flags with packet type")
Fixes ab351fe1c95c ("mbuf: remove packet type from offload flags")
---
 examples/ip_fragmentation/main.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
examples/ip_fragmentation/main.c +4 -2
index e1e32c6..8612984 100644
@@ -268,6 +268,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 	uint32_t i, len, next_hop_ipv4;
 	uint8_t next_hop_ipv6, port_out, ipv6;
 	int32_t len2;
+	struct ether_hdr *eth_hdr;
 
 	ipv6 = 0;
 	rxq = &qconf->rx_queue_list[queueid];
@@ -276,13 +277,14 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 	port_out = port_in;
 
 	/* Remove the Ethernet header and trailer from the input packet */
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	rte_pktmbuf_adj(m, (uint16_t)sizeof(struct ether_hdr));
 
 	/* Build transmission burst */
 	len = qconf->tx_mbufs[port_out].len;
 
 	/* if this is an IPv4 packet */
-	if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
+	if (eth_hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
 		struct ipv4_hdr *ip_hdr;
 		uint32_t ip_dst;
 		/* Read the lookup key (i.e. ip_dst) from the input packet */
@@ -316,7 +318,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 			if (unlikely (len2 < 0))
 				return;
 		}
-	} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
+	} else if (eth_hdr->ether_type == rte_be_to_cpu_16(ETHER_TYPE_IPv6)) {
 		/* if this is an IPv6 packet */
 		struct ipv6_hdr *ip_hdr;
 

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf, · line 372

Quoted 10 lines
examples/ip_fragmentation/main.c +2 -2
@@ -363,8 +365,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,
 		void *d_addr_bytes;
 
 		m = qconf->tx_mbufs[port_out].m_table[i];
-		struct ether_hdr *eth_hdr = (struct ether_hdr *)
-			rte_pktmbuf_prepend(m, (uint16_t)sizeof(struct ether_hdr));
+		eth_hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m,
+			(uint16_t)sizeof(struct ether_hdr));
 		if (eth_hdr == NULL) {
 			rte_panic("No headroom in mbuf.\n");
 		}

Thanks for the fix.
Would it be more convenient to do what l3fwd does:
Check what ptype capabilities are provided by HW, if no ptype support detected, then install an RX callback?
Konstantin

Quoted 2 lines

--
2.7.4

author
#3 lore raw

Hi, Konstantin
I see your point.
I think your method can work.
But I think your method is a bit complex. As you method need to add more codes. Anyway this is a simple bug.
How do you think now ?

Quoted 95 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Friday, March 10, 2017 8:21 PM
To: Dai, Wei <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH] examples/ip_fragmentation: fix check of packet type

Hi Wei,

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct

Quoted 30 lines

-----Original Message-----
From: Dai, Wei
Sent: Friday, March 10, 2017 3:28 AM
To: [email protected]; Ananyev, Konstantin <[email protected]>
Cc: Dai, Wei <[email protected]>; [email protected]
Subject: [PATCH] examples/ip_fragmentation: fix check of packet type

The packet_type in mbuf is not correctly filled by ixgbe 82599 NIC. To use the ether_type in ethernet header to check packet type is more reliaber.

Fixes 3c0184cc0c60 ("examples: replace some offload flags with packet

type")

Fixes ab351fe1c95c ("mbuf: remove packet type from offload flags")
---
 examples/ip_fragmentation/main.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
examples/ip_fragmentation/main.c +0 -0
index e1e32c6..8612984 100644
@@ -268,6 +268,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct

lcore_queue_conf *qconf,

Quoted 14 lines
examples/ip_fragmentation/main.c +1 -0
 	uint32_t i, len, next_hop_ipv4;
 	uint8_t next_hop_ipv6, port_out, ipv6;
 	int32_t len2;
+	struct ether_hdr *eth_hdr;
 
 	ipv6 = 0;
 	rxq = &qconf->rx_queue_list[queueid]; @@ -276,13 +277,14 @@

l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c +1 -0
 	port_out = port_in;
 
 	/* Remove the Ethernet header and trailer from the input packet */
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	rte_pktmbuf_adj(m, (uint16_t)sizeof(struct ether_hdr));
 

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,

Quoted 10 lines
examples/ip_fragmentation/main.c +1 -2
 	/* Build transmission burst */
 	len = qconf->tx_mbufs[port_out].len;
 
 	/* if this is an IPv4 packet */
-	if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
+	if (eth_hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
 		struct ipv4_hdr *ip_hdr;
 		uint32_t ip_dst;
 		/* Read the lookup key (i.e. ip_dst) from the input packet */ @@
-316,7 +318,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct

lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct

Quoted 10 lines
examples/ip_fragmentation/main.c +2 -1
 			if (unlikely (len2 < 0))
 				return;
 		}
-	} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
+	} else if (eth_hdr->ether_type == rte_be_to_cpu_16(ETHER_TYPE_IPv6))
+{
 		/* if this is an IPv6 packet */
 		struct ipv6_hdr *ip_hdr;
@@ -363,8 +365,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct

lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf, · line 372

Quoted 10 lines
examples/ip_fragmentation/main.c +2 -2
 		void *d_addr_bytes;
 
 		m = qconf->tx_mbufs[port_out].m_table[i];
-		struct ether_hdr *eth_hdr = (struct ether_hdr *)
-			rte_pktmbuf_prepend(m, (uint16_t)sizeof(struct ether_hdr));
+		eth_hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m,
+			(uint16_t)sizeof(struct ether_hdr));
 		if (eth_hdr == NULL) {
 			rte_panic("No headroom in mbuf.\n");
 		}

Thanks for the fix.
Would it be more convenient to do what l3fwd does:
Check what ptype capabilities are provided by HW, if no ptype support detected, then install an RX callback?
Konstantin

Quoted 2 lines

--
2.7.4

#4 lore raw

Hi Wei,

Quoted 7 lines

Hi, Konstantin
I see your point.
I think your method can work.
But I think your method is a bit complex. As you method need to add more codes. Anyway this is a simple bug.
How do you think now ?

I still think it is better for all apps to handle this issue in a uniform way. Again in that case for NICs that do support PTYPE offloads the performance should be unaffected. Konstantin

Quoted 96 lines
Quoted 96 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Friday, March 10, 2017 8:21 PM
To: Dai, Wei <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH] examples/ip_fragmentation: fix check of packet type

Hi Wei,

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct

Quoted 30 lines

-----Original Message-----
From: Dai, Wei
Sent: Friday, March 10, 2017 3:28 AM
To: [email protected]; Ananyev, Konstantin <[email protected]>
Cc: Dai, Wei <[email protected]>; [email protected]
Subject: [PATCH] examples/ip_fragmentation: fix check of packet type

The packet_type in mbuf is not correctly filled by ixgbe 82599 NIC. To use the ether_type in ethernet header to check packet type is more reliaber.

Fixes 3c0184cc0c60 ("examples: replace some offload flags with packet

type")

Fixes ab351fe1c95c ("mbuf: remove packet type from offload flags")
---
 examples/ip_fragmentation/main.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
examples/ip_fragmentation/main.c +0 -0
index e1e32c6..8612984 100644
@@ -268,6 +268,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct

lcore_queue_conf *qconf,

Quoted 14 lines
examples/ip_fragmentation/main.c +1 -0
 	uint32_t i, len, next_hop_ipv4;
 	uint8_t next_hop_ipv6, port_out, ipv6;
 	int32_t len2;
+	struct ether_hdr *eth_hdr;
 
 	ipv6 = 0;
 	rxq = &qconf->rx_queue_list[queueid]; @@ -276,13 +277,14 @@

l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c +1 -0
 	port_out = port_in;
 
 	/* Remove the Ethernet header and trailer from the input packet */
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	rte_pktmbuf_adj(m, (uint16_t)sizeof(struct ether_hdr));
 

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf,

Quoted 10 lines
examples/ip_fragmentation/main.c +1 -2
 	/* Build transmission burst */
 	len = qconf->tx_mbufs[port_out].len;
 
 	/* if this is an IPv4 packet */
-	if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
+	if (eth_hdr->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
 		struct ipv4_hdr *ip_hdr;
 		uint32_t ip_dst;
 		/* Read the lookup key (i.e. ip_dst) from the input packet */ @@
-316,7 +318,7 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct

lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct

Quoted 10 lines
examples/ip_fragmentation/main.c +2 -1
 			if (unlikely (len2 < 0))
 				return;
 		}
-	} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
+	} else if (eth_hdr->ether_type == rte_be_to_cpu_16(ETHER_TYPE_IPv6))
+{
 		/* if this is an IPv6 packet */
 		struct ipv6_hdr *ip_hdr;
@@ -363,8 +365,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, struct

lcore_queue_conf *qconf,

examples/ip_fragmentation/main.c l3fwd_simple_forward(struct rte_mbuf *m, struct lcore_queue_conf *qconf, · line 372

Quoted 10 lines
examples/ip_fragmentation/main.c +2 -2
 		void *d_addr_bytes;
 
 		m = qconf->tx_mbufs[port_out].m_table[i];
-		struct ether_hdr *eth_hdr = (struct ether_hdr *)
-			rte_pktmbuf_prepend(m, (uint16_t)sizeof(struct ether_hdr));
+		eth_hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m,
+			(uint16_t)sizeof(struct ether_hdr));
 		if (eth_hdr == NULL) {
 			rte_panic("No headroom in mbuf.\n");
 		}

Thanks for the fix.
Would it be more convenient to do what l3fwd does:
Check what ptype capabilities are provided by HW, if no ptype support detected, then install an RX callback?
Konstantin

Quoted 2 lines

--
2.7.4

author
#5 lore raw
Quoted 14 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Monday, March 13, 2017 3:02 PM
To: Dai, Wei <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH] examples/ip_fragmentation: fix check of packet type

Hi Wei,

Quoted 5 lines

Hi, Konstantin
I see your point.
I think your method can work.
But I think your method is a bit complex. As you method need to add more

Quoted 9 lines

codes.

Quoted 2 lines

Anyway this is a simple bug.
How do you think now ?

I still think it is better for all apps to handle this issue in a uniform way. Again in that case for NICs that do support PTYPE offloads the performance should be unaffected.
Konstantin

I have just had a quick look through the l3fwd and didn't find any codes to check what ptypes capabilities ae provided by stuff below DPDK PMD & its base driver. L3fwd only check an input argument "--parse-ptype" to enable ptype check implemented in a Rx callback function.
In this l3fwd rx callback function, it has done the same thing as my code. Anyway, I'd like to provide a v2 patch to deal with this issue in a uniform way.

Thanks & Best Regards
-Wei

#6 lore raw
Quoted 19 lines
Quoted 9 lines

Hi Wei,

Quoted 5 lines

Hi, Konstantin
I see your point.
I think your method can work.
But I think your method is a bit complex. As you method need to add more

Quoted 9 lines

codes.

Quoted 2 lines

Anyway this is a simple bug.
How do you think now ?

I still think it is better for all apps to handle this issue in a uniform way. Again in that case for NICs that do support PTYPE offloads the performance should be unaffected.
Konstantin

Quoted 4 lines

I have just had a quick look through the l3fwd and didn't find any codes to check what ptypes capabilities ae provided by stuff below DPDK PMD & its base driver. L3fwd only check an input argument "--parse-ptype" to enable ptype check implemented in a Rx callback function.

As an example for lpm:
http://dpdk.org/browse/dpdk/tree/examples/l3fwd/l3fwd_lpm.c#n279
Konstantin

Quoted 5 lines

In this l3fwd rx callback function, it has done the same thing as my code. Anyway, I'd like to provide a v2 patch to deal with this issue in a uniform way.

Thanks & Best Regards
-Wei

author
#7 lore raw
Quoted 29 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, March 14, 2017 6:13 AM
To: Dai, Wei <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH] examples/ip_fragmentation: fix check of packet type

Quoted 12 lines
Quoted 12 lines

Hi Wei,

Quoted 6 lines

Hi, Konstantin
I see your point.
I think your method can work.
But I think your method is a bit complex. As you method need to add more

codes.

Quoted 2 lines

Anyway this is a simple bug.
How do you think now ?

Quoted 8 lines
Quoted 5 lines

I still think it is better for all apps to handle this issue in a uniform way. Again in that case for NICs that do support PTYPE offloads the performance should be unaffected.
Konstantin

I have just had a quick look through the l3fwd and didn't find any codes to check what ptypes capabilities ae provided by stuff below DPDK

Quoted 7 lines

PMD & its base driver.

Quoted 2 lines

L3fwd only check an input argument "--parse-ptype" to enable ptype check implemented in a Rx callback function.

As an example for lpm:
http://dpdk.org/browse/dpdk/tree/examples/l3fwd/l3fwd_lpm.c#n279
Konstantin

Thanks for your guide.
I will use rte_eth_dev_get_supported_ptypes( ) in my v2 patch.

Quoted 7 lines
Quoted 7 lines

In this l3fwd rx callback function, it has done the same thing as my code. Anyway, I'd like to provide a v2 patch to deal with this issue in a uniform way.

Thanks & Best Regards
-Wei