Skip to contentSkip to conversation

ethdev: add packet type matching item

PATCH Superseded Alexander Kozyrev 2 participants 3 messages Oct 9, 2023 – Oct 10, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected][D

#1 lore raw

PATCH v2 1/1 ethdev: add packet type matching item

Add RTE_FLOW_ITEM_TYPE_PTYPE to allow matching on L2/L3/L4 and tunnel information as defined in mbuf.

To match on RTE_PTYPE_L4_TCP and RTE_PTYPE_INNER_L4_UDP:
flow pattern_template 0 create pattern_template_id 1

    ingress template ptype packet_type mask 0x0f000f00 / end
  flow queue 0 create 0 template_table 1 pattern_template 0 actions_template 0
    pattern ptype packet_type is 0x02000100 / end actions queue index 1 / end
---
 app/test-pmd/cmdline_flow.c                 | 27 +++++++++++++++++++++
 doc/guides/nics/features/default.ini        |  1 +
 doc/guides/prog_guide/rte_flow.rst          |  7 ++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 +++
 lib/ethdev/rte_flow.c                       |  1 +
 lib/ethdev/rte_flow.h                       | 25 +++++++++++++++++++
 6 files changed, 65 insertions(+)
app/test-pmd/cmdline_flow.c +27 -0
index 12809f1042..cb203ad99c 100644
@@ -535,6 +535,8 @@ enum index {
 	ITEM_IPV6_PUSH_REMOVE_EXT,
 	ITEM_IPV6_PUSH_REMOVE_EXT_TYPE,
 	ITEM_NSH,
+	ITEM_PTYPE,
+	ITEM_PTYPE_VALUE,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -1581,6 +1583,7 @@ static const enum index next_item[] = {
 	ITEM_TX_QUEUE,
 	ITEM_IB_BTH,
 	ITEM_NSH,
+	ITEM_PTYPE,
 	END_SET,
 	ZERO,
 };
@@ -2106,6 +2109,12 @@ static const enum index item_nsh[] = {
 	ZERO,
 };
 
+static const enum index item_ptype[] = {
+	ITEM_PTYPE_VALUE,
+	ITEM_NEXT,
+	ZERO,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -5921,6 +5930,21 @@ static const struct token token_list[] = {
 		.next = NEXT(item_nsh),
 		.call = parse_vc,
 	},
+	[ITEM_PTYPE] = {
+		.name = "ptype",
+		.help = "match L2/L3/L4 and tunnel information",
+		.priv = PRIV_ITEM(PTYPE,
+				  sizeof(struct rte_flow_item_ptype)),
+		.next = NEXT(item_ptype),
+		.call = parse_vc,
+	},
+	[ITEM_PTYPE_VALUE] = {
+		.name = "packet_type",
+		.help = "packet type as defined in rte_mbuf_ptype",
+		.next = NEXT(item_ptype, NEXT_ENTRY(COMMON_UNSIGNED),
+			     item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_ptype, packet_type)),
+	},
 
 	/* Validate/create actions. */
 	[ACTIONS] = {
@@ -12836,6 +12860,9 @@ flow_item_default_mask(const struct rte_flow_item *item)
 	case RTE_FLOW_ITEM_TYPE_IB_BTH:
 		mask = &rte_flow_item_ib_bth_mask;
 		break;
+	case RTE_FLOW_ITEM_TYPE_PTYPE:
+		mask = &rte_flow_item_ptype_mask;
+		break;
 	default:
 		break;
 	}
doc/guides/nics/features/default.ini +1 -0
index 2011e97127..e41a97b3bb 100644
@@ -137,6 +137,7 @@ ppp                  =
 pppoed               =
 pppoes               =
 pppoe_proto_id       =
+ptype                =
 quota                =
 raw                  =
 represented_port     =
doc/guides/prog_guide/rte_flow.rst +7 -0
index 860e42025f..b65b25d443 100644
@@ -1566,6 +1566,13 @@ Matches an InfiniBand base transport header in RoCE packet.
 
 - ``hdr``: InfiniBand base transport header definition (``rte_ib.h``).
 
+Item: ``PTYPE``
+^^^^^^^^^^^^^^^
+
+Matches the packet type as defined in rte_mbuf_ptype.
+
+- ``packet_type``: L2/L3/L4 and tunnel information.
+
 Actions
 ~~~~~~~
 
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -0
index e6d218caaa..07bac9a311 100644
@@ -3808,6 +3808,10 @@ This section lists supported pattern items and their attributes, if any.
 
 - ``send_to_kernel``: send packets to kernel.
 
+- ``ptype``: match the packet type (L2/L3/L4 and tunnel information).
+
+        - ``packet_type {unsigned}``: packet type.
+
 
 Actions list
 ^^^^^^^^^^^^
lib/ethdev/rte_flow.c +1 -0
index c9d23da702..ba8bf27090 100644
@@ -167,6 +167,7 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = {
 	MK_FLOW_ITEM(AGGR_AFFINITY, sizeof(struct rte_flow_item_aggr_affinity)),
 	MK_FLOW_ITEM(TX_QUEUE, sizeof(struct rte_flow_item_tx_queue)),
 	MK_FLOW_ITEM(IB_BTH, sizeof(struct rte_flow_item_ib_bth)),
+	MK_FLOW_ITEM(PTYPE, sizeof(struct rte_flow_item_ptype)),
 };
 
 /** Generate flow_action[] entry. */
lib/ethdev/rte_flow.h +25 -0
index e576b15e3d..b79bb9968b 100644
@@ -694,6 +694,14 @@ enum rte_flow_item_type {
 	 * @see struct rte_flow_item_ib_bth.
 	 */
 	RTE_FLOW_ITEM_TYPE_IB_BTH,
+
+	/**
+	 * Matches the packet type as defined in rte_mbuf_ptype.
+	 *
+	 * See struct rte_flow_item_ptype.
+	 *
+	 */
+	RTE_FLOW_ITEM_TYPE_PTYPE,
 };
 
 /**
@@ -2309,6 +2317,23 @@ static const struct rte_flow_item_tx_queue rte_flow_item_tx_queue_mask = {
 };
 #endif
 
+/**
+ *
+ * RTE_FLOW_ITEM_TYPE_PTYPE
+ *
+ * Matches the packet type as defined in rte_mbuf_ptype.
+ */
+struct rte_flow_item_ptype {
+	uint32_t packet_type; /**< L2/L3/L4 and tunnel information. */
+};
+
+/** Default mask for RTE_FLOW_ITEM_TYPE_PTYPE. */
+#ifndef __cplusplus
+static const struct rte_flow_item_ptype rte_flow_item_ptype_mask = {
+	.packet_type = 0xffffffff,
+};
+#endif
+
 /**
  * Action types.
  *
Signature · 1 line
2.18.2
#2 lore raw

PATCH v3 1/1 ethdev: add packet type matching item

Add RTE_FLOW_ITEM_TYPE_PTYPE to allow matching on L2/L3/L4 and tunnel information as defined in mbuf.

To match on RTE_PTYPE_L4_TCP and RTE_PTYPE_INNER_L4_UDP:
flow pattern_template 0 create pattern_template_id 1

    ingress template ptype packet_type mask 0x0f000f00 / end

flow queue 0 create 0 template_table 1
pattern_template 0 actions_template 0
pattern ptype packet_type is 0x02000100 / end
actions queue index 1 / end

---
 app/test-pmd/cmdline_flow.c                 | 28 +++++++++++++++++++++
 doc/guides/nics/features/default.ini        |  1 +
 doc/guides/prog_guide/rte_flow.rst          |  7 ++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 +++
 lib/ethdev/rte_flow.c                       |  1 +
 lib/ethdev/rte_flow.h                       | 25 ++++++++++++++++++
 6 files changed, 66 insertions(+)
app/test-pmd/cmdline_flow.c +28 -0
index 2b1d9b70ee..02874c4597 100644
@@ -534,6 +534,8 @@ enum index {
 	ITEM_IB_BTH_PSN,
 	ITEM_IPV6_PUSH_REMOVE_EXT,
 	ITEM_IPV6_PUSH_REMOVE_EXT_TYPE,
+	ITEM_PTYPE,
+	ITEM_PTYPE_VALUE,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -1579,6 +1581,7 @@ static const enum index next_item[] = {
 	ITEM_AGGR_AFFINITY,
 	ITEM_TX_QUEUE,
 	ITEM_IB_BTH,
+	ITEM_PTYPE,
 	END_SET,
 	ZERO,
 };
@@ -2099,6 +2102,12 @@ static const enum index item_ib_bth[] = {
 	ZERO,
 };
 
+static const enum index item_ptype[] = {
+	ITEM_PTYPE_VALUE,
+	ITEM_NEXT,
+	ZERO,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -5906,6 +5915,22 @@ static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ib_bth,
 						 hdr.psn)),
 	},
+	[ITEM_PTYPE] = {
+		.name = "ptype",
+		.help = "match L2/L3/L4 and tunnel information",
+		.priv = PRIV_ITEM(PTYPE,
+				  sizeof(struct rte_flow_item_ptype)),
+		.next = NEXT(item_ptype),
+		.call = parse_vc,
+	},
+	[ITEM_PTYPE_VALUE] = {
+		.name = "packet_type",
+		.help = "packet type as defined in rte_mbuf_ptype",
+		.next = NEXT(item_ptype, NEXT_ENTRY(COMMON_UNSIGNED),
+			     item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_ptype, packet_type)),
+	},
+
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
@@ -12820,6 +12845,9 @@ flow_item_default_mask(const struct rte_flow_item *item)
 	case RTE_FLOW_ITEM_TYPE_IB_BTH:
 		mask = &rte_flow_item_ib_bth_mask;
 		break;
+	case RTE_FLOW_ITEM_TYPE_PTYPE:
+		mask = &rte_flow_item_ptype_mask;
+		break;
 	default:
 		break;
 	}
doc/guides/nics/features/default.ini +1 -0
index 2011e97127..e41a97b3bb 100644
@@ -137,6 +137,7 @@ ppp                  =
 pppoed               =
 pppoes               =
 pppoe_proto_id       =
+ptype                =
 quota                =
 raw                  =
 represented_port     =
doc/guides/prog_guide/rte_flow.rst +7 -0
index 860e42025f..b65b25d443 100644
@@ -1566,6 +1566,13 @@ Matches an InfiniBand base transport header in RoCE packet.
 
 - ``hdr``: InfiniBand base transport header definition (``rte_ib.h``).
 
+Item: ``PTYPE``
+^^^^^^^^^^^^^^^
+
+Matches the packet type as defined in rte_mbuf_ptype.
+
+- ``packet_type``: L2/L3/L4 and tunnel information.
+
 Actions
 ~~~~~~~
 
doc/guides/testpmd_app_ug/testpmd_funcs.rst +4 -0
index e6d218caaa..07bac9a311 100644
@@ -3808,6 +3808,10 @@ This section lists supported pattern items and their attributes, if any.
 
 - ``send_to_kernel``: send packets to kernel.
 
+- ``ptype``: match the packet type (L2/L3/L4 and tunnel information).
+
+        - ``packet_type {unsigned}``: packet type.
+
 
 Actions list
 ^^^^^^^^^^^^
lib/ethdev/rte_flow.c +1 -0
index c9d23da702..ba8bf27090 100644
@@ -167,6 +167,7 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = {
 	MK_FLOW_ITEM(AGGR_AFFINITY, sizeof(struct rte_flow_item_aggr_affinity)),
 	MK_FLOW_ITEM(TX_QUEUE, sizeof(struct rte_flow_item_tx_queue)),
 	MK_FLOW_ITEM(IB_BTH, sizeof(struct rte_flow_item_ib_bth)),
+	MK_FLOW_ITEM(PTYPE, sizeof(struct rte_flow_item_ptype)),
 };
 
 /** Generate flow_action[] entry. */
lib/ethdev/rte_flow.h +25 -0
index e576b15e3d..b79bb9968b 100644
@@ -694,6 +694,14 @@ enum rte_flow_item_type {
 	 * @see struct rte_flow_item_ib_bth.
 	 */
 	RTE_FLOW_ITEM_TYPE_IB_BTH,
+
+	/**
+	 * Matches the packet type as defined in rte_mbuf_ptype.
+	 *
+	 * See struct rte_flow_item_ptype.
+	 *
+	 */
+	RTE_FLOW_ITEM_TYPE_PTYPE,
 };
 
 /**
@@ -2309,6 +2317,23 @@ static const struct rte_flow_item_tx_queue rte_flow_item_tx_queue_mask = {
 };
 #endif
 
+/**
+ *
+ * RTE_FLOW_ITEM_TYPE_PTYPE
+ *
+ * Matches the packet type as defined in rte_mbuf_ptype.
+ */
+struct rte_flow_item_ptype {
+	uint32_t packet_type; /**< L2/L3/L4 and tunnel information. */
+};
+
+/** Default mask for RTE_FLOW_ITEM_TYPE_PTYPE. */
+#ifndef __cplusplus
+static const struct rte_flow_item_ptype rte_flow_item_ptype_mask = {
+	.packet_type = 0xffffffff,
+};
+#endif
+
 /**
  * Action types.
  *
Signature · 1 line
2.18.2
Applied
#3 lore raw
Quoted 5 lines · Alexander Kozyrev

Add RTE_FLOW_ITEM_TYPE_PTYPE to allow matching on L2/L3/L4 and tunnel information as defined in mbuf.

To match on RTE_PTYPE_L4_TCP and RTE_PTYPE_INNER_L4_UDP:
flow pattern_template 0 create pattern_template_id 1

Quoted 9 lines
    ingress template ptype packet_type mask 0x0f000f00 / end

flow queue 0 create 0 template_table 1
pattern_template 0 actions_template 0
pattern ptype packet_type is 0x02000100 / end
actions queue index 1 / end

Applied to dpdk-next-net/main, thanks.