Skip to contentSkip to conversation

net/mlx5: fix IP tunnel detection for IPIP and IPv6 ENCAP

PATCH In review Junfeng Guo 3 participants 3 messages Nov 19, 2025 – Feb 4 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: fix IP tunnel detection for IPIP and IPv6 ENCAP

The HWS (Hardware Steering) IP tunnel detection implementation was not recognizing IPIP tunnel types based on the next protocol value in the outer IP header as specified by RFC 2003 (IP-in-IP) and RFC 2473 (IPv6 Encapsulation).

The issue was that the code treated all combinations of [IPv4|6] / [IPv4|6] as IPIP tunnels, setting MLX5_FLOW_LAYER_IPIP flag regardless of the actual protocol. While this happened to work for simple cases due to the fallback classification, it violated RFC compliance and could cause issues with protocol validation.

The fix adds RFC-compliant tunnel detection by
1. Checking the protocol field (IPPROTO_IPIP=4 or IPPROTO_IPV6=41) in the outer IP header to determine tunnel type
2. Adding protocol mismatch validation to ensure outer protocol matches inner header type
3. Correctly setting MLX5_FLOW_LAYER_IPV6_ENCAP for IPv6 encapsulation

The expected tunnel patterns are now:
- [ipv4 | ipv6] proto is 4 / ipv4 -> MLX5_FLOW_LAYER_IPIP
- [ipv4 | ipv6] proto is 41 / ipv6 -> MLX5_FLOW_LAYER_IPV6_ENCAP

For cases without protocol specification, fallback classification based on inner header type is still supported.

Fixes f66c7c3ab983 ("net/mlx5/hws: recognize IP-in-IP tunnel in definer layer")
Fixes 4b7044562f59 ("net/mlx5: support IP-in-IP tunnel for all combinations")
---
 drivers/net/mlx5/hws/mlx5dr_definer.c |   4 +-
 drivers/net/mlx5/mlx5_flow.c          |   5 -
 drivers/net/mlx5/mlx5_flow_hw.c       | 162 ++++++++++++++++++++++----
 3 files changed, 143 insertions(+), 28 deletions(-)
drivers/net/mlx5/hws/mlx5dr_definer.c +3 -1
index afa70bf793..03d2794367 100644
@@ -3381,6 +3381,7 @@ mlx5dr_definer_conv_items_to_hl(struct mlx5dr_context *ctx,
 			if (cd.last_item == RTE_FLOW_ITEM_TYPE_IPV4 ||
 			    cd.last_item == RTE_FLOW_ITEM_TYPE_IPV6) {
 				cd.tunnel = true;
+				/* [IPv4 | IPv6] / IPv4: IPIP */
 				item_flags |= MLX5_FLOW_LAYER_IPIP;
 			}
 			ret = mlx5dr_definer_conv_item_ipv4(&cd, items, i);
@@ -3391,7 +3392,8 @@ mlx5dr_definer_conv_items_to_hl(struct mlx5dr_context *ctx,
 			if (cd.last_item == RTE_FLOW_ITEM_TYPE_IPV4 ||
 			    cd.last_item == RTE_FLOW_ITEM_TYPE_IPV6) {
 				cd.tunnel = true;
-				item_flags |= MLX5_FLOW_LAYER_IPIP;
+				/* [IPv4 | IPv6] / IPv6: IPV6_ENCAP */
+				item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
 			}
 			ret = mlx5dr_definer_conv_item_ipv6(&cd, items, i);
 			item_flags |= cd.tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
drivers/net/mlx5/mlx5_flow.c +0 -5
index 2c48f1b01b..0821c93a9a 100644
@@ -2892,11 +2892,6 @@ mlx5_flow_validate_item_ipv4(const struct rte_eth_dev *dev,
 						  "multiple tunnel "
 						  "not supported");
 	}
-	if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
-		return rte_flow_error_set(error, EINVAL,
-					  RTE_FLOW_ERROR_TYPE_ITEM, item,
-					  "wrong tunnel type - IPv6 specified "
-					  "but IPv4 item provided");
 	if (item_flags & l3m)
 		return rte_flow_error_set(error, ENOTSUP,
 					  RTE_FLOW_ERROR_TYPE_ITEM, item,
drivers/net/mlx5/mlx5_flow_hw.c +140 -22

196 lines not on this page · raw message

Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Junfeng Guo

The HWS (Hardware Steering) IP tunnel detection implementation was not recognizing IPIP tunnel types based on the next protocol value in the outer IP header as specified by RFC 2003 (IP-in-IP) and RFC 2473 (IPv6 Encapsulation).

The issue was that the code treated all combinations of [IPv4|6] / [IPv4|6] as IPIP tunnels, setting MLX5_FLOW_LAYER_IPIP flag regardless of the actual protocol. While this happened to work for simple cases due to the fallback classification, it violated RFC compliance and could cause issues with protocol validation.

The fix adds RFC-compliant tunnel detection by
1. Checking the protocol field (IPPROTO_IPIP=4 or IPPROTO_IPV6=41) in the outer IP header to determine tunnel type
2. Adding protocol mismatch validation to ensure outer protocol matches inner header type
3. Correctly setting MLX5_FLOW_LAYER_IPV6_ENCAP for IPv6 encapsulation

The expected tunnel patterns are now:
- [ipv4 | ipv6] proto is 4 / ipv4 -> MLX5_FLOW_LAYER_IPIP
- [ipv4 | ipv6] proto is 41 / ipv6 -> MLX5_FLOW_LAYER_IPV6_ENCAP

Quoted 8 lines

For cases without protocol specification, fallback classification based on inner header type is still supported.

Fixes f66c7c3ab983 ("net/mlx5/hws: recognize IP-in-IP tunnel in definer layer")
Fixes 4b7044562f59 ("net/mlx5: support IP-in-IP tunnel for all combinations")

Best regards,
Dariusz Sosnowski

#2 lore raw
In reply to Junfeng Guo

Hi,

Quoted 22 lines · Junfeng Guo

The HWS (Hardware Steering) IP tunnel detection implementation was not recognizing IPIP tunnel types based on the next protocol value in the outer IP header as specified by RFC 2003 (IP-in-IP) and RFC 2473 (IPv6 Encapsulation).

The issue was that the code treated all combinations of [IPv4|6] / [IPv4|6] as IPIP tunnels, setting MLX5_FLOW_LAYER_IPIP flag regardless of the actual protocol. While this happened to work for simple cases due to the fallback classification, it violated RFC compliance and could cause issues with protocol validation.

The fix adds RFC-compliant tunnel detection by
1. Checking the protocol field (IPPROTO_IPIP=4 or IPPROTO_IPV6=41) in the outer IP header to determine tunnel type
2. Adding protocol mismatch validation to ensure outer protocol matches inner header type
3. Correctly setting MLX5_FLOW_LAYER_IPV6_ENCAP for IPv6 encapsulation

The expected tunnel patterns are now:
- [ipv4 | ipv6] proto is 4 / ipv4 -> MLX5_FLOW_LAYER_IPIP
- [ipv4 | ipv6] proto is 41 / ipv6 -> MLX5_FLOW_LAYER_IPV6_ENCAP

Quoted 8 lines

For cases without protocol specification, fallback classification based on inner header type is still supported.

Fixes f66c7c3ab983 ("net/mlx5/hws: recognize IP-in-IP tunnel in definer layer")
Fixes 4b7044562f59 ("net/mlx5: support IP-in-IP tunnel for all combinations")

Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh