[dpdk-dev] [PATCH v2 5/8] pipeline: add table action for packet decap

Cristian Dumitrescu cristian.dumitrescu at intel.com
Wed Oct 10 19:53:31 CEST 2018


This patch introduces a new table action for packet decapsulation
which removes n bytes from the start of the input packet. The n
is read from the current table entry. The following mbuf fields
are updated by the action: data_off, data_len, pkt_len.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu at intel.com>
---
 lib/librte_pipeline/rte_table_action.c | 111 +++++++++++++++++++++++++++++++++
 lib/librte_pipeline/rte_table_action.h |  12 ++++
 2 files changed, 123 insertions(+)

diff --git a/lib/librte_pipeline/rte_table_action.c b/lib/librte_pipeline/rte_table_action.c
index fb7eaf9..6fa31e1 100644
--- a/lib/librte_pipeline/rte_table_action.c
+++ b/lib/librte_pipeline/rte_table_action.c
@@ -2056,6 +2056,83 @@ pkt4_work_tag(struct rte_mbuf *mbuf0,
 }
 
 /**
+ * RTE_TABLE_ACTION_DECAP
+ */
+struct decap_data {
+	uint16_t n;
+} __attribute__((__packed__));
+
+static int
+decap_apply(struct decap_data *data,
+	struct rte_table_action_decap_params *p)
+{
+	data->n = p->n;
+	return 0;
+}
+
+static __rte_always_inline void
+pkt_work_decap(struct rte_mbuf *mbuf,
+	struct decap_data *data)
+{
+	uint16_t data_off = mbuf->data_off;
+	uint16_t data_len = mbuf->data_len;
+	uint32_t pkt_len = mbuf->pkt_len;
+	uint16_t n = data->n;
+
+	mbuf->data_off = data_off + n;
+	mbuf->data_len = data_len - n;
+	mbuf->pkt_len = pkt_len - n;
+}
+
+static __rte_always_inline void
+pkt4_work_decap(struct rte_mbuf *mbuf0,
+	struct rte_mbuf *mbuf1,
+	struct rte_mbuf *mbuf2,
+	struct rte_mbuf *mbuf3,
+	struct decap_data *data0,
+	struct decap_data *data1,
+	struct decap_data *data2,
+	struct decap_data *data3)
+{
+	uint16_t data_off0 = mbuf0->data_off;
+	uint16_t data_len0 = mbuf0->data_len;
+	uint32_t pkt_len0 = mbuf0->pkt_len;
+
+	uint16_t data_off1 = mbuf1->data_off;
+	uint16_t data_len1 = mbuf1->data_len;
+	uint32_t pkt_len1 = mbuf1->pkt_len;
+
+	uint16_t data_off2 = mbuf2->data_off;
+	uint16_t data_len2 = mbuf2->data_len;
+	uint32_t pkt_len2 = mbuf2->pkt_len;
+
+	uint16_t data_off3 = mbuf3->data_off;
+	uint16_t data_len3 = mbuf3->data_len;
+	uint32_t pkt_len3 = mbuf3->pkt_len;
+
+	uint16_t n0 = data0->n;
+	uint16_t n1 = data1->n;
+	uint16_t n2 = data2->n;
+	uint16_t n3 = data3->n;
+
+	mbuf0->data_off = data_off0 + n0;
+	mbuf0->data_len = data_len0 - n0;
+	mbuf0->pkt_len = pkt_len0 - n0;
+
+	mbuf1->data_off = data_off1 + n1;
+	mbuf1->data_len = data_len1 - n1;
+	mbuf1->pkt_len = pkt_len1 - n1;
+
+	mbuf2->data_off = data_off2 + n2;
+	mbuf2->data_len = data_len2 - n2;
+	mbuf2->pkt_len = pkt_len2 - n2;
+
+	mbuf3->data_off = data_off3 + n3;
+	mbuf3->data_len = data_len3 - n3;
+	mbuf3->pkt_len = pkt_len3 - n3;
+}
+
+/**
  * Action profile
  */
 static int
@@ -2073,6 +2150,7 @@ action_valid(enum rte_table_action_type action)
 	case RTE_TABLE_ACTION_TIME:
 	case RTE_TABLE_ACTION_SYM_CRYPTO:
 	case RTE_TABLE_ACTION_TAG:
+	case RTE_TABLE_ACTION_DECAP:
 		return 1;
 	default:
 		return 0;
@@ -2210,6 +2288,9 @@ action_data_size(enum rte_table_action_type action,
 	case RTE_TABLE_ACTION_TAG:
 		return sizeof(struct tag_data);
 
+	case RTE_TABLE_ACTION_DECAP:
+		return sizeof(struct decap_data);
+
 	default:
 		return 0;
 	}
@@ -2471,6 +2552,10 @@ rte_table_action_apply(struct rte_table_action *action,
 		return tag_apply(action_data,
 			action_params);
 
+	case RTE_TABLE_ACTION_DECAP:
+		return decap_apply(action_data,
+			action_params);
+
 	default:
 		return -EINVAL;
 	}
@@ -2863,6 +2948,14 @@ pkt_work(struct rte_mbuf *mbuf,
 		pkt_work_tag(mbuf, data);
 	}
 
+	if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
+		void *data = action_data_get(table_entry,
+			action,
+			RTE_TABLE_ACTION_DECAP);
+
+		pkt_work_decap(mbuf, data);
+	}
+
 	return drop_mask;
 }
 
@@ -3189,6 +3282,24 @@ pkt4_work(struct rte_mbuf **mbufs,
 			data0, data1, data2, data3);
 	}
 
+	if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
+		void *data0 = action_data_get(table_entry0,
+			action,
+			RTE_TABLE_ACTION_DECAP);
+		void *data1 = action_data_get(table_entry1,
+			action,
+			RTE_TABLE_ACTION_DECAP);
+		void *data2 = action_data_get(table_entry2,
+			action,
+			RTE_TABLE_ACTION_DECAP);
+		void *data3 = action_data_get(table_entry3,
+			action,
+			RTE_TABLE_ACTION_DECAP);
+
+		pkt4_work_decap(mbuf0, mbuf1, mbuf2, mbuf3,
+			data0, data1, data2, data3);
+	}
+
 	return drop_mask0 |
 		(drop_mask1 << 1) |
 		(drop_mask2 << 2) |
diff --git a/lib/librte_pipeline/rte_table_action.h b/lib/librte_pipeline/rte_table_action.h
index 5dbb147..c960612 100644
--- a/lib/librte_pipeline/rte_table_action.h
+++ b/lib/librte_pipeline/rte_table_action.h
@@ -99,6 +99,9 @@ enum rte_table_action_type {
 
 	/** Tag. */
 	RTE_TABLE_ACTION_TAG,
+
+	/** Packet decapsulations. */
+	RTE_TABLE_ACTION_DECAP,
 };
 
 /** Common action configuration (per table action profile). */
@@ -783,6 +786,15 @@ struct rte_table_action_tag_params {
 };
 
 /**
+ * RTE_TABLE_ACTION_DECAP
+ */
+/** Decap action parameters (per table rule). */
+struct rte_table_action_decap_params {
+	/** Number of bytes to be removed from the start of the packet. */
+	uint16_t n;
+};
+
+/**
  * Table action profile.
  */
 struct rte_table_action_profile;
-- 
2.7.4



More information about the dev mailing list