[PATCH v9 05/30] net/hinic3: fix wildcard IPv4, ICMP and UDP flow items
Jiacheng Ye
yejiacheng4 at h-partners.com
Wed Nov 25 18:03:59 CET 2026
Accept a wildcard IPv4 item, such as eth / ipv4 / udp, that has neither
a spec nor a mask, so the L4 item alone constrains the rule. The fdir
parser required both fields and rejected such a rule with -EINVAL.
The ICMP item was not translated, so an ICMP rule with an IPv4 spec or
mask matched every IPv4 packet that passed the IPv4 fields, and with the
wildcard above it would also match when the IPv4 item is empty.
Translate the ICMP item into the IPv4 protocol key, as the TCP and UDP
items already are, and reject a mask that selects fields the TCAM cannot
match: the ICMP type, code, checksum, identifier or sequence number, and
the UDP length or checksum. The TCP item already rejects its unsupported
fields; the ICMP and UDP items silently ignored them.
Fixes: efa3b9b36fc7 ("net/hinic3: add flow control and filters")
Cc: stable at dpdk.org
Signed-off-by: Jiacheng Ye <yejiacheng4 at h-partners.com>
---
drivers/net/hinic3/hinic3_flow.c | 60 +++++++++++++++++++++++++++++++++++++--
1 file changed, 58 insertions(+), 2 deletions(-)
diff --git a/drivers/net/hinic3/hinic3_flow.c b/drivers/net/hinic3/hinic3_flow.c
index 1f686d4675..3fbed5497b 100644
--- a/drivers/net/hinic3/hinic3_flow.c
+++ b/drivers/net/hinic3/hinic3_flow.c
@@ -230,6 +230,14 @@ hinic3_flow_fdir_ipv4(const struct rte_flow_item *flow_item,
mask_ipv4 = (const struct rte_flow_item_ipv4 *)flow_item->mask;
spec_ipv4 = (const struct rte_flow_item_ipv4 *)flow_item->spec;
+
+ filter->fdir_filter.ip_type = HINIC3_FDIR_IP_TYPE_IPV4;
+ filter->fdir_filter.tunnel_type = HINIC3_FDIR_TUNNEL_MODE_NORMAL;
+
+ /* A wildcard IPv4 item leaves the L4 item in charge of the rule. */
+ if (!mask_ipv4 && !spec_ipv4)
+ return 0;
+
if (!mask_ipv4 || !spec_ipv4) {
rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
flow_item,
@@ -252,8 +260,6 @@ hinic3_flow_fdir_ipv4(const struct rte_flow_item *flow_item,
}
/* Set the filter information. */
- filter->fdir_filter.ip_type = HINIC3_FDIR_IP_TYPE_IPV4;
- filter->fdir_filter.tunnel_type = HINIC3_FDIR_TUNNEL_MODE_NORMAL;
filter->fdir_filter.key_mask.ipv4.src_ip =
rte_be_to_cpu_32(mask_ipv4->hdr.src_addr);
filter->fdir_filter.key_spec.ipv4.src_ip =
@@ -381,3 +387,11 @@ hinic3_flow_fdir_udp(const struct rte_flow_item *flow_item,
}
+ /* Only support src, dst ports, others should be masked. */
+ if (mask_udp->hdr.dgram_len || mask_udp->hdr.dgram_cksum) {
+ rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
+ flow_item,
+ "Not supported by fdir filter, udp only support src port, dst port");
+ return -rte_errno;
+ }
+
/* Set the filter information. */
@@ -393,6 +407,42 @@ hinic3_flow_fdir_udp(const struct rte_flow_item *flow_item,
return 0;
}
+static int
+hinic3_flow_fdir_icmp(const struct rte_flow_item *flow_item,
+ struct hinic3_filter_t *filter,
+ struct rte_flow_error *error)
+{
+ const struct rte_flow_item_icmp *spec_icmp, *mask_icmp;
+
+ mask_icmp = (const struct rte_flow_item_icmp *)flow_item->mask;
+ spec_icmp = (const struct rte_flow_item_icmp *)flow_item->spec;
+
+ filter->fdir_filter.key_mask.proto = HINIC3_UINT8_MAX;
+ filter->fdir_filter.key_spec.proto = IPPROTO_ICMP;
+
+ if (!mask_icmp && !spec_icmp)
+ return 0;
+
+ if (!mask_icmp || !spec_icmp) {
+ rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
+ flow_item,
+ "Invalid fdir filter icmp mask or spec");
+ return -rte_errno;
+ }
+
+ /* Only the protocol number can be matched, others should be masked. */
+ if (mask_icmp->hdr.icmp_type || mask_icmp->hdr.icmp_code ||
+ mask_icmp->hdr.icmp_cksum || mask_icmp->hdr.icmp_ident ||
+ mask_icmp->hdr.icmp_seq_nb) {
+ rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
+ flow_item,
+ "Not supported by fdir filter, icmp only support protocol number");
+ return -rte_errno;
+ }
+
+ return 0;
+}
+
/**
* Parse the pattern of network traffic and apply the parsing result to the
* traffic filter.
@@ -464,6 +514,12 @@ hinic3_flow_parse_fdir_pattern(__rte_unused struct rte_eth_dev *dev,
return -rte_errno;
break;
+ case RTE_FLOW_ITEM_TYPE_ICMP:
+ err = hinic3_flow_fdir_icmp(flow_item, filter, error);
+ if (err)
+ return -rte_errno;
+ break;
+
default:
break;
}
--
2.33.0
More information about the stable
mailing list