[v5,16/80] net/ntnic: add item ICMP

Message ID 20241030213940.3470062-17-sil-plv@napatech.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series Provide flow filter and statistics support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Serhii Iliushyk Oct. 30, 2024, 9:38 p.m. UTC
Add possibility to use RTE_FLOW_ITEM_TYPE_ICMP.

Signed-off-by: Serhii Iliushyk <sil-plv@napatech.com>
---
 doc/guides/nics/features/ntnic.ini            |   1 +
 .../profile_inline/flow_api_profile_inline.c  | 101 ++++++++++++++++++
 2 files changed, 102 insertions(+)
  

Patch

diff --git a/doc/guides/nics/features/ntnic.ini b/doc/guides/nics/features/ntnic.ini
index bae25d2e2d..d403ea01f3 100644
--- a/doc/guides/nics/features/ntnic.ini
+++ b/doc/guides/nics/features/ntnic.ini
@@ -16,6 +16,7 @@  x86-64               = Y
 [rte_flow items]
 any                  = Y
 eth                  = Y
+icmp                 = Y
 ipv4                 = Y
 
 [rte_flow actions]
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
index eb73e6ca22..88665dbf15 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
@@ -827,6 +827,107 @@  static int interpret_flow_elements(const struct flow_eth_dev *dev,
 
 			break;
 
+		case RTE_FLOW_ITEM_TYPE_ICMP:
+			NT_LOG(DBG, FILTER, "Adap %i, Port %i: RTE_FLOW_ITEM_TYPE_ICMP",
+				dev->ndev->adapter_no, dev->port);
+			{
+				const struct rte_flow_item_icmp *icmp_spec =
+					(const struct rte_flow_item_icmp *)elem[eidx].spec;
+				const struct rte_flow_item_icmp *icmp_mask =
+					(const struct rte_flow_item_icmp *)elem[eidx].mask;
+
+				if (icmp_spec == NULL || icmp_mask == NULL) {
+					if (any_count > 0 || fd->l4_prot != -1) {
+						fd->tunnel_l4_prot = PROT_TUN_L4_ICMP;
+						fd->tunnel_ip_prot = 1;
+						key_def->inner_proto = 1;
+					} else {
+						fd->l4_prot = PROT_L4_ICMP;
+						fd->ip_prot = 1;
+						key_def->outer_proto = 1;
+					}
+					break;
+				}
+
+				if (icmp_mask->hdr.icmp_cksum != 0 ||
+					icmp_mask->hdr.icmp_ident != 0 ||
+					icmp_mask->hdr.icmp_seq_nb != 0) {
+					NT_LOG(ERR, FILTER,
+						"Requested ICMP field not supported by running SW version");
+					flow_nic_set_error(ERR_FAILED, error);
+					return -1;
+				}
+
+				if (icmp_mask->hdr.icmp_type || icmp_mask->hdr.icmp_code) {
+					if (sw_counter < 2) {
+						uint32_t *sw_data = &packet_data[1 - sw_counter];
+						uint32_t *sw_mask = &packet_mask[1 - sw_counter];
+
+						sw_mask[0] = icmp_mask->hdr.icmp_type << 24 |
+							icmp_mask->hdr.icmp_code << 16;
+						sw_data[0] = icmp_spec->hdr.icmp_type << 24 |
+							icmp_spec->hdr.icmp_code << 16;
+						sw_data[0] &= sw_mask[0];
+
+						km_add_match_elem(&fd->km, &sw_data[0],
+							&sw_mask[0], 1, any_count > 0
+							? DYN_TUN_L4 : DYN_L4, 0);
+						set_key_def_sw(key_def, sw_counter,
+							any_count > 0 ? DYN_TUN_L4 : DYN_L4, 0);
+						sw_counter += 1;
+
+					} else if (qw_counter < 2 && qw_free > 0) {
+						uint32_t *qw_data =
+							&packet_data[2 + 4 - qw_counter * 4];
+						uint32_t *qw_mask =
+							&packet_mask[2 + 4 - qw_counter * 4];
+
+						qw_data[0] = icmp_spec->hdr.icmp_type << 24 |
+							icmp_spec->hdr.icmp_code << 16;
+						qw_data[1] = 0;
+						qw_data[2] = 0;
+						qw_data[3] = 0;
+
+						qw_mask[0] = icmp_mask->hdr.icmp_type << 24 |
+							icmp_mask->hdr.icmp_code << 16;
+						qw_mask[1] = 0;
+						qw_mask[2] = 0;
+						qw_mask[3] = 0;
+
+						qw_data[0] &= qw_mask[0];
+						qw_data[1] &= qw_mask[1];
+						qw_data[2] &= qw_mask[2];
+						qw_data[3] &= qw_mask[3];
+
+						km_add_match_elem(&fd->km, &qw_data[0], &qw_mask[0],
+							4, any_count > 0 ? DYN_TUN_L4 : DYN_L4, 0);
+						set_key_def_qw(key_def, qw_counter, any_count > 0
+							? DYN_TUN_L4 : DYN_L4, 0);
+						qw_counter += 1;
+						qw_free -= 1;
+
+					} else {
+						NT_LOG(ERR, FILTER,
+							"Key size too big. Out of SW-QW resources.");
+						flow_nic_set_error(ERR_FAILED, error);
+						return -1;
+					}
+				}
+
+				if (any_count > 0 || fd->l4_prot != -1) {
+					fd->tunnel_l4_prot = PROT_TUN_L4_ICMP;
+					fd->tunnel_ip_prot = 1;
+					key_def->inner_proto = 1;
+
+				} else {
+					fd->l4_prot = PROT_L4_ICMP;
+					fd->ip_prot = 1;
+					key_def->outer_proto = 1;
+				}
+			}
+
+			break;
+
 		default:
 			NT_LOG(ERR, FILTER, "Invalid or unsupported flow request: %d",
 				(int)elem[eidx].type);