[dpdk-dev] [RFC] ethdev: add sanity packet checks

Ori Kam orika at nvidia.com
Sun Feb 28 20:48:19 CET 2021


Currently, DPDK application can offload the checksum check,
and report it in the mbuf.

However, this approach doesn't work if the traffic
is offloaded and should not arrive to the application.

This commit introduces rte flow item that enables
matching on the checksum of the L3 and L4 layers,
in addition to other checks that can determine if
the packet is valid.
some of those tests can be packet len, data len,
unsupported flags, and so on.

The full check is HW dependent.

Signed-off-by: Ori Kam <orika at nvidia.com>
---
 lib/librte_ethdev/rte_flow.c |  1 +
 lib/librte_ethdev/rte_flow.h | 50 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index b07dbff..a8d7c7a 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -99,6 +99,7 @@ struct rte_flow_desc_data {
 	MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
 	MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)),
 	MK_FLOW_ITEM(SFT, sizeof(struct rte_flow_item_sft)),
+	MK_FLOW_ITEM(SANITY_CHECKS, sizeof(struct rte_flow_item_sanity_checks)),
 };
 
 /** Generate flow_action[] entry. */
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index ad876dd..f948c5e 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -559,6 +559,15 @@ enum rte_flow_item_type {
 	 * See struct rte_flow_item_sft.
 	 */
 	RTE_FLOW_ITEM_TYPE_SFT,
+
+	/**
+	 * [META]
+	 *
+	 * Matches packet sanity checks.
+	 *
+	 * See struct rte_flow_item_sanity_checks.
+	 */
+	RTE_FLOW_ITEM_TYPE_SANITY_CHECKS,
 };
 
 /**
@@ -1709,6 +1718,47 @@ struct rte_flow_item_sft {
 };
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ITEM_TYPE_SANITY_CHECKS
+ *
+ * Enable matching on packet validity based on HW checks for the L3 and L4
+ * layers.
+ */
+struct rte_flow_item_sanity_checks {
+	uint32_t level;
+	/**< Packet encapsulation level the item should apply to.
+	 * @see rte_flow_action_rss
+	 */
+RTE_STD_C11
+	union {
+		struct {
+			uint32_t l3_ok:1;
+			/**< L3 layer is valid after passing all HW checking. */
+			uint32_t l4_ok:1;
+			/**< L4 layer is valid after passing all HW checking. */
+			uint32_t l3_ok_csum:1;
+			/**< L3 layer checksum is valid. */
+			uint32_t l4_ok_csum:1;
+			/**< L4 layer checksum is valid. */
+			uint32_t reserved:28;
+		};
+		uint32_t  value;
+	};
+};
+
+#ifndef __cplusplus
+static const struct rte_flow_item_sanity_checks
+	rte_flow_item_sanity_checks_mask = {
+	.l3_ok = 1,
+	.l4_ok = 1,
+	.l3_ok_csum = 1,
+	.l4_ok_csum = 1,
+};
+#endif
+
+/**
  * Matching pattern item definition.
  *
  * A pattern is formed by stacking items starting from the lowest protocol
-- 
1.8.3.1



More information about the dev mailing list