[v1] gro: fix gro for UDP fragmented packets

Message ID 20220319111829.71676-1-kumaraparamesh92@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] gro: fix gro for UDP fragmented packets |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues

Commit Message

Kumara Parameshwaran March 19, 2022, 11:18 a.m. UTC
  From: Kumara Parameshwaran <kparameshwar@vmware.com>

A packet with RTE_PTYPE_L4_FRAG(0x300) contains both RTE_PTYPE_L4_TCP
(0x100) & RTE_PTYPE_L4_UDP (0x200). A fragmented packet as defined in
rte_mbuf_ptype.h cannot be recognized as other L4 types and hence the
GRO layer should not use IS_IPV4_TCP_PKT or IS_IPV4_UDP_PKT for
RTE_PTYPE_L4_FRAG. Hence, if the packet type is RTE_PTYPE_L4_FRAG the
ip header should be parsed to recognize the appropriate IP type and
invoke the respective gro handler.

Fixes: 1ca5e6740852 ("gro: support UDP/IPv4")
Cc: stable@dpdk.org

Signed-off-by: Kumara Parameshwaran <kparameshwar@vmware.com>
---
v1:
* Introduce IS_IPV4_FRAGMENT macro to check if fragmented packet and 
  if true extract the IP header to identify the protocol type and 
  invoke the appropriate gro handler. This is done for both 
  rte_gro_reassemble and rte_gro_reassemble_burst APIs.

 lib/gro/rte_gro.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/gro/rte_gro.c b/lib/gro/rte_gro.c
index 6f7dd4d709..2f0e6d7088 100644
--- a/lib/gro/rte_gro.c
+++ b/lib/gro/rte_gro.c
@@ -38,6 +38,9 @@  static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM] = {
 		((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \
 		(RTE_ETH_IS_TUNNEL_PKT(ptype) == 0))
 
+#define IS_IPV4_FRAGMENT(ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \
+		((ptype & RTE_PTYPE_L4_FRAG) == RTE_PTYPE_L4_FRAG))
+
 #define IS_IPV4_VXLAN_TCP4_PKT(ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \
 		((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \
 		((ptype & RTE_PTYPE_TUNNEL_VXLAN) == \
@@ -240,7 +243,28 @@  rte_gro_reassemble_burst(struct rte_mbuf **pkts,
 		 * The timestamp is ignored, since all packets
 		 * will be flushed from the tables.
 		 */
-		if (IS_IPV4_VXLAN_TCP4_PKT(pkts[i]->packet_type) &&
+		if (IS_IPV4_FRAGMENT(pkts[i]->packet_type)) {
+			struct rte_ipv4_hdr ip4h_copy;
+			const struct rte_ipv4_hdr *ip4h = rte_pktmbuf_read(pkts[i], pkts[i]->l2_len, sizeof(*ip4h), 
+													&ip4h_copy);
+			if (ip4h->next_proto_id == IPPROTO_UDP && do_udp4_gro) {
+				ret = gro_udp4_reassemble(pkts[i],
+							&udp_tbl, 0);
+				if (ret > 0)
+					nb_after_gro--;
+				else if (ret < 0)
+					unprocess_pkts[unprocess_num++] = pkts[i];
+			} else if (ip4h->next_proto_id == IPPROTO_TCP && do_tcp4_gro) {
+				ret = gro_tcp4_reassemble(pkts[i],
+						&tcp_tbl, 0);
+				if (ret > 0)
+					nb_after_gro--;
+				else if (ret < 0)
+					unprocess_pkts[unprocess_num++] = pkts[i];
+			} else {
+				unprocess_pkts[unprocess_num++] = pkts[i];
+			}
+		} else if (IS_IPV4_VXLAN_TCP4_PKT(pkts[i]->packet_type) &&
 				do_vxlan_tcp_gro) {
 			ret = gro_vxlan_tcp4_reassemble(pkts[i],
 							&vxlan_tcp_tbl, 0);
@@ -349,7 +373,22 @@  rte_gro_reassemble(struct rte_mbuf **pkts,
 	current_time = rte_rdtsc();
 
 	for (i = 0; i < nb_pkts; i++) {
-		if (IS_IPV4_VXLAN_TCP4_PKT(pkts[i]->packet_type) &&
+		if (IS_IPV4_FRAGMENT(pkts[i]->packet_type)) {
+			struct rte_ipv4_hdr ip4h_copy;
+			const struct rte_ipv4_hdr *ip4h = rte_pktmbuf_read(pkts[i], pkts[i]->l2_len, sizeof(*ip4h),
+												&ip4h_copy);
+			if (ip4h->next_proto_id == IPPROTO_UDP && do_udp4_gro) {
+				if (gro_udp4_reassemble(pkts[i], udp_tbl,
+						current_time) < 0)
+					unprocess_pkts[unprocess_num++] = pkts[i];
+			} else if (ip4h->next_proto_id == IPPROTO_TCP && do_tcp4_gro) {
+				if (gro_tcp4_reassemble(pkts[i], tcp_tbl,
+						current_time) < 0)
+					unprocess_pkts[unprocess_num++] = pkts[i];
+			} else {
+				unprocess_pkts[unprocess_num++] = pkts[i];
+			}
+		} else if (IS_IPV4_VXLAN_TCP4_PKT(pkts[i]->packet_type) &&
 				do_vxlan_tcp_gro) {
 			if (gro_vxlan_tcp4_reassemble(pkts[i], vxlan_tcp_tbl,
 						current_time) < 0)