DPDK patches and discussions
 help / color / mirror / Atom feed
From: Konstantin Ananyev <konstantin.ananyev@intel.com>
To: dev@dpdk.org
To: dev@dpdk.org
Cc: akhil.goyal@nxp.com,
	Konstantin Ananyev <konstantin.ananyev@intel.com>,
	Mohammad Abdul Awal <mohammad.abdul.awal@intel.com>,
	Bernard Iremonger <bernard.iremonger@intel.com>
Subject: [dpdk-dev] [PATCH v6 08/10] examples/ipsec-secgw: make data-path to use ipsec library
Date: Thu,  3 Jan 2019 20:25:36 +0000	[thread overview]
Message-ID: <1546547138-24965-9-git-send-email-konstantin.ananyev@intel.com> (raw)
In-Reply-To: <1546011238-22318-2-git-send-email-konstantin.ananyev@intel.com>

Changes to make ipsec-secgw data-path code to utilize librte_ipsec library.
Note that right now by default current (non-librte_ipsec) code-path will
be used. User has to run application with new command-line option ('-l')
to enable new codepath.

Signed-off-by: Mohammad Abdul Awal <mohammad.abdul.awal@intel.com>
Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Radu Nicolau <radu.nicolau@intel.com>
---
 examples/ipsec-secgw/Makefile        |   1 +
 examples/ipsec-secgw/ipsec-secgw.c   | 179 ++++++++------
 examples/ipsec-secgw/ipsec.c         |   2 +-
 examples/ipsec-secgw/ipsec.h         |  23 ++
 examples/ipsec-secgw/ipsec_process.c | 357 +++++++++++++++++++++++++++
 examples/ipsec-secgw/meson.build     |   4 +-
 6 files changed, 487 insertions(+), 79 deletions(-)
 create mode 100644 examples/ipsec-secgw/ipsec_process.c

diff --git a/examples/ipsec-secgw/Makefile b/examples/ipsec-secgw/Makefile
index 3918ee63e..08f474da6 100644
--- a/examples/ipsec-secgw/Makefile
+++ b/examples/ipsec-secgw/Makefile
@@ -13,6 +13,7 @@ SRCS-y += sp4.c
 SRCS-y += sp6.c
 SRCS-y += sa.c
 SRCS-y += rt.c
+SRCS-y += ipsec_process.c
 SRCS-y += ipsec-secgw.c
 
 CFLAGS += -gdwarf-2
diff --git a/examples/ipsec-secgw/ipsec-secgw.c b/examples/ipsec-secgw/ipsec-secgw.c
index 4b7309954..4f7a77d8d 100644
--- a/examples/ipsec-secgw/ipsec-secgw.c
+++ b/examples/ipsec-secgw/ipsec-secgw.c
@@ -229,19 +229,6 @@ static struct rte_eth_conf port_conf = {
 
 static struct socket_ctx socket_ctx[NB_SOCKETS];
 
-struct traffic_type {
-	const uint8_t *data[MAX_PKT_BURST * 2];
-	struct rte_mbuf *pkts[MAX_PKT_BURST * 2];
-	uint32_t res[MAX_PKT_BURST * 2];
-	uint32_t num;
-};
-
-struct ipsec_traffic {
-	struct traffic_type ipsec;
-	struct traffic_type ip4;
-	struct traffic_type ip6;
-};
-
 static inline void
 prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 {
@@ -258,6 +245,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 			t->ip4.data[t->ip4.num] = nlp;
 			t->ip4.pkts[(t->ip4.num)++] = pkt;
 		}
+		pkt->l2_len = 0;
+		pkt->l3_len = sizeof(struct ip);
 	} else if (eth->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) {
 		nlp = (uint8_t *)rte_pktmbuf_adj(pkt, ETHER_HDR_LEN);
 		nlp = RTE_PTR_ADD(nlp, offsetof(struct ip6_hdr, ip6_nxt));
@@ -267,6 +256,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 			t->ip6.data[t->ip6.num] = nlp;
 			t->ip6.pkts[(t->ip6.num)++] = pkt;
 		}
+		pkt->l2_len = 0;
+		pkt->l3_len = sizeof(struct ip6_hdr);
 	} else {
 		/* Unknown/Unsupported type, drop the packet */
 		RTE_LOG(ERR, IPSEC, "Unsupported packet type\n");
@@ -516,10 +507,15 @@ process_pkts_inbound(struct ipsec_ctx *ipsec_ctx,
 	n_ip4 = traffic->ip4.num;
 	n_ip6 = traffic->ip6.num;
 
-	nb_pkts_in = ipsec_inbound(ipsec_ctx, traffic->ipsec.pkts,
-			traffic->ipsec.num, MAX_PKT_BURST);
-
-	split46_traffic(traffic, traffic->ipsec.pkts, nb_pkts_in);
+	if (app_sa_prm.enable == 0) {
+		nb_pkts_in = ipsec_inbound(ipsec_ctx, traffic->ipsec.pkts,
+				traffic->ipsec.num, MAX_PKT_BURST);
+		split46_traffic(traffic, traffic->ipsec.pkts, nb_pkts_in);
+	} else {
+		inbound_sa_lookup(ipsec_ctx->sa_ctx, traffic->ipsec.pkts,
+			traffic->ipsec.saptr, traffic->ipsec.num);
+		ipsec_process(ipsec_ctx, traffic);
+	}
 
 	inbound_sp_sa(ipsec_ctx->sp4_ctx, ipsec_ctx->sa_ctx, &traffic->ip4,
 			n_ip4);
@@ -575,20 +571,27 @@ process_pkts_outbound(struct ipsec_ctx *ipsec_ctx,
 
 	outbound_sp(ipsec_ctx->sp6_ctx, &traffic->ip6, &traffic->ipsec);
 
-	nb_pkts_out = ipsec_outbound(ipsec_ctx, traffic->ipsec.pkts,
-			traffic->ipsec.res, traffic->ipsec.num,
-			MAX_PKT_BURST);
-
-	for (i = 0; i < nb_pkts_out; i++) {
-		m = traffic->ipsec.pkts[i];
-		struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
-		if (ip->ip_v == IPVERSION) {
-			idx = traffic->ip4.num++;
-			traffic->ip4.pkts[idx] = m;
-		} else {
-			idx = traffic->ip6.num++;
-			traffic->ip6.pkts[idx] = m;
+	if (app_sa_prm.enable == 0) {
+
+		nb_pkts_out = ipsec_outbound(ipsec_ctx, traffic->ipsec.pkts,
+				traffic->ipsec.res, traffic->ipsec.num,
+				MAX_PKT_BURST);
+
+		for (i = 0; i < nb_pkts_out; i++) {
+			m = traffic->ipsec.pkts[i];
+			struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
+			if (ip->ip_v == IPVERSION) {
+				idx = traffic->ip4.num++;
+				traffic->ip4.pkts[idx] = m;
+			} else {
+				idx = traffic->ip6.num++;
+				traffic->ip6.pkts[idx] = m;
+			}
 		}
+	} else {
+		outbound_sa_lookup(ipsec_ctx->sa_ctx, traffic->ipsec.res,
+			traffic->ipsec.saptr, traffic->ipsec.num);
+		ipsec_process(ipsec_ctx, traffic);
 	}
 }
 
@@ -611,19 +614,26 @@ process_pkts_inbound_nosp(struct ipsec_ctx *ipsec_ctx,
 
 	traffic->ip6.num = 0;
 
-	nb_pkts_in = ipsec_inbound(ipsec_ctx, traffic->ipsec.pkts,
-			traffic->ipsec.num, MAX_PKT_BURST);
+	if (app_sa_prm.enable == 0) {
 
-	for (i = 0; i < nb_pkts_in; i++) {
-		m = traffic->ipsec.pkts[i];
-		struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
-		if (ip->ip_v == IPVERSION) {
-			idx = traffic->ip4.num++;
-			traffic->ip4.pkts[idx] = m;
-		} else {
-			idx = traffic->ip6.num++;
-			traffic->ip6.pkts[idx] = m;
+		nb_pkts_in = ipsec_inbound(ipsec_ctx, traffic->ipsec.pkts,
+				traffic->ipsec.num, MAX_PKT_BURST);
+
+		for (i = 0; i < nb_pkts_in; i++) {
+			m = traffic->ipsec.pkts[i];
+			struct ip *ip = rte_pktmbuf_mtod(m, struct ip *);
+			if (ip->ip_v == IPVERSION) {
+				idx = traffic->ip4.num++;
+				traffic->ip4.pkts[idx] = m;
+			} else {
+				idx = traffic->ip6.num++;
+				traffic->ip6.pkts[idx] = m;
+			}
 		}
+	} else {
+		inbound_sa_lookup(ipsec_ctx->sa_ctx, traffic->ipsec.pkts,
+			traffic->ipsec.saptr, traffic->ipsec.num);
+		ipsec_process(ipsec_ctx, traffic);
 	}
 }
 
@@ -655,21 +665,28 @@ process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx,
 	traffic->ip6.num = 0;
 	traffic->ipsec.num = n;
 
-	nb_pkts_out = ipsec_outbound(ipsec_ctx, traffic->ipsec.pkts,
-			traffic->ipsec.res, traffic->ipsec.num,
-			MAX_PKT_BURST);
+	if (app_sa_prm.enable == 0) {
 
-	/* They all sue the same SA (ip4 or ip6 tunnel) */
-	m = traffic->ipsec.pkts[i];
-	ip = rte_pktmbuf_mtod(m, struct ip *);
-	if (ip->ip_v == IPVERSION) {
-		traffic->ip4.num = nb_pkts_out;
-		for (i = 0; i < nb_pkts_out; i++)
-			traffic->ip4.pkts[i] = traffic->ipsec.pkts[i];
+		nb_pkts_out = ipsec_outbound(ipsec_ctx, traffic->ipsec.pkts,
+				traffic->ipsec.res, traffic->ipsec.num,
+				MAX_PKT_BURST);
+
+		/* They all sue the same SA (ip4 or ip6 tunnel) */
+		m = traffic->ipsec.pkts[0];
+		ip = rte_pktmbuf_mtod(m, struct ip *);
+		if (ip->ip_v == IPVERSION) {
+			traffic->ip4.num = nb_pkts_out;
+			for (i = 0; i < nb_pkts_out; i++)
+				traffic->ip4.pkts[i] = traffic->ipsec.pkts[i];
+		} else {
+			traffic->ip6.num = nb_pkts_out;
+			for (i = 0; i < nb_pkts_out; i++)
+				traffic->ip6.pkts[i] = traffic->ipsec.pkts[i];
+		}
 	} else {
-		traffic->ip6.num = nb_pkts_out;
-		for (i = 0; i < nb_pkts_out; i++)
-			traffic->ip6.pkts[i] = traffic->ipsec.pkts[i];
+		outbound_sa_lookup(ipsec_ctx->sa_ctx, traffic->ipsec.res,
+			traffic->ipsec.saptr, traffic->ipsec.num);
+		ipsec_process(ipsec_ctx, traffic);
 	}
 }
 
@@ -870,25 +887,31 @@ drain_inbound_crypto_queues(const struct lcore_conf *qconf,
 	uint32_t n;
 	struct ipsec_traffic trf;
 
-	/* dequeue packets from crypto-queue */
-	n = ipsec_inbound_cqp_dequeue(ctx, trf.ipsec.pkts,
+	if (app_sa_prm.enable == 0) {
+
+		/* dequeue packets from crypto-queue */
+		n = ipsec_inbound_cqp_dequeue(ctx, trf.ipsec.pkts,
 			RTE_DIM(trf.ipsec.pkts));
-	if (n == 0)
-		return;
 
-	trf.ip4.num = 0;
-	trf.ip6.num = 0;
+		trf.ip4.num = 0;
+		trf.ip6.num = 0;
 
-	/* split traffic by ipv4-ipv6 */
-	split46_traffic(&trf, trf.ipsec.pkts, n);
+		/* split traffic by ipv4-ipv6 */
+		split46_traffic(&trf, trf.ipsec.pkts, n);
+	} else
+		ipsec_cqp_process(ctx, &trf);
 
 	/* process ipv4 packets */
-	inbound_sp_sa(ctx->sp4_ctx, ctx->sa_ctx, &trf.ip4, 0);
-	route4_pkts(qconf->rt4_ctx, trf.ip4.pkts, trf.ip4.num);
+	if (trf.ip4.num != 0) {
+		inbound_sp_sa(ctx->sp4_ctx, ctx->sa_ctx, &trf.ip4, 0);
+		route4_pkts(qconf->rt4_ctx, trf.ip4.pkts, trf.ip4.num);
+	}
 
 	/* process ipv6 packets */
-	inbound_sp_sa(ctx->sp6_ctx, ctx->sa_ctx, &trf.ip6, 0);
-	route6_pkts(qconf->rt6_ctx, trf.ip6.pkts, trf.ip6.num);
+	if (trf.ip6.num != 0) {
+		inbound_sp_sa(ctx->sp6_ctx, ctx->sa_ctx, &trf.ip6, 0);
+		route6_pkts(qconf->rt6_ctx, trf.ip6.pkts, trf.ip6.num);
+	}
 }
 
 static void
@@ -898,23 +921,27 @@ drain_outbound_crypto_queues(const struct lcore_conf *qconf,
 	uint32_t n;
 	struct ipsec_traffic trf;
 
-	/* dequeue packets from crypto-queue */
-	n = ipsec_outbound_cqp_dequeue(ctx, trf.ipsec.pkts,
+	if (app_sa_prm.enable == 0) {
+
+		/* dequeue packets from crypto-queue */
+		n = ipsec_outbound_cqp_dequeue(ctx, trf.ipsec.pkts,
 			RTE_DIM(trf.ipsec.pkts));
-	if (n == 0)
-		return;
 
-	trf.ip4.num = 0;
-	trf.ip6.num = 0;
+		trf.ip4.num = 0;
+		trf.ip6.num = 0;
 
-	/* split traffic by ipv4-ipv6 */
-	split46_traffic(&trf, trf.ipsec.pkts, n);
+		/* split traffic by ipv4-ipv6 */
+		split46_traffic(&trf, trf.ipsec.pkts, n);
+	} else
+		ipsec_cqp_process(ctx, &trf);
 
 	/* process ipv4 packets */
-	route4_pkts(qconf->rt4_ctx, trf.ip4.pkts, trf.ip4.num);
+	if (trf.ip4.num != 0)
+		route4_pkts(qconf->rt4_ctx, trf.ip4.pkts, trf.ip4.num);
 
 	/* process ipv6 packets */
-	route6_pkts(qconf->rt6_ctx, trf.ip6.pkts, trf.ip6.num);
+	if (trf.ip6.num != 0)
+		route6_pkts(qconf->rt6_ctx, trf.ip6.pkts, trf.ip6.num);
 }
 
 /* main processing loop */
diff --git a/examples/ipsec-secgw/ipsec.c b/examples/ipsec-secgw/ipsec.c
index 72a29bcb1..36ead5cf9 100644
--- a/examples/ipsec-secgw/ipsec.c
+++ b/examples/ipsec-secgw/ipsec.c
@@ -39,7 +39,7 @@ set_ipsec_conf(struct ipsec_sa *sa, struct rte_security_ipsec_xform *ipsec)
 	ipsec->esn_soft_limit = IPSEC_OFFLOAD_ESN_SOFTLIMIT;
 }
 
-static inline int
+int
 create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
 {
 	struct rte_cryptodev_info cdev_info;
diff --git a/examples/ipsec-secgw/ipsec.h b/examples/ipsec-secgw/ipsec.h
index 8da86c4de..8629f5045 100644
--- a/examples/ipsec-secgw/ipsec.h
+++ b/examples/ipsec-secgw/ipsec.h
@@ -190,6 +190,20 @@ struct cnt_blk {
 	uint32_t cnt;
 } __attribute__((packed));
 
+struct traffic_type {
+	const uint8_t *data[MAX_PKT_BURST * 2];
+	struct rte_mbuf *pkts[MAX_PKT_BURST * 2];
+	struct ipsec_sa *saptr[MAX_PKT_BURST * 2];
+	uint32_t res[MAX_PKT_BURST * 2];
+	uint32_t num;
+};
+
+struct ipsec_traffic {
+	struct traffic_type ipsec;
+	struct traffic_type ip4;
+	struct traffic_type ip6;
+};
+
 uint16_t
 ipsec_inbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
 		uint16_t nb_pkts, uint16_t len);
@@ -206,6 +220,12 @@ uint16_t
 ipsec_outbound_cqp_dequeue(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
 		uint16_t len);
 
+void
+ipsec_process(struct ipsec_ctx *ctx, struct ipsec_traffic *trf);
+
+void
+ipsec_cqp_process(struct ipsec_ctx *ctx, struct ipsec_traffic *trf);
+
 static inline uint16_t
 ipsec_metadata_size(void)
 {
@@ -283,4 +303,7 @@ add_dst_ethaddr(uint16_t port, const struct ether_addr *addr);
 void
 enqueue_cop_burst(struct cdev_qp *cqp);
 
+int
+create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa);
+
 #endif /* __IPSEC_H__ */
diff --git a/examples/ipsec-secgw/ipsec_process.c b/examples/ipsec-secgw/ipsec_process.c
new file mode 100644
index 000000000..e403c461a
--- /dev/null
+++ b/examples/ipsec-secgw/ipsec_process.c
@@ -0,0 +1,357 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2016-2017 Intel Corporation
+ */
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+
+#include <rte_branch_prediction.h>
+#include <rte_log.h>
+#include <rte_cryptodev.h>
+#include <rte_ethdev.h>
+#include <rte_mbuf.h>
+
+#include "ipsec.h"
+
+#define SATP_OUT_IPV4(t)	\
+	((((t) & RTE_IPSEC_SATP_MODE_MASK) == RTE_IPSEC_SATP_MODE_TRANS && \
+	(((t) & RTE_IPSEC_SATP_IPV_MASK) == RTE_IPSEC_SATP_IPV4)) || \
+	((t) & RTE_IPSEC_SATP_MODE_MASK) == RTE_IPSEC_SATP_MODE_TUNLV4)
+
+
+/* helper routine to free bulk of packets */
+static inline void
+free_pkts(struct rte_mbuf *mb[], uint32_t n)
+{
+	uint32_t i;
+
+	for (i = 0; i != n; i++)
+		rte_pktmbuf_free(mb[i]);
+}
+
+/* helper routine to free bulk of crypto-ops and related packets */
+static inline void
+free_cops(struct rte_crypto_op *cop[], uint32_t n)
+{
+	uint32_t i;
+
+	for (i = 0; i != n; i++)
+		rte_pktmbuf_free(cop[i]->sym->m_src);
+}
+
+/* helper routine to enqueue bulk of crypto ops */
+static inline void
+enqueue_cop_bulk(struct cdev_qp *cqp, struct rte_crypto_op *cop[], uint32_t num)
+{
+	uint32_t i, k, len, n;
+
+	len = cqp->len;
+
+	/*
+	 * if cqp is empty and we have enough ops,
+	 * then queue them to the PMD straightway.
+	 */
+	if (num >= RTE_DIM(cqp->buf) * 3 / 4 && len == 0) {
+		n = rte_cryptodev_enqueue_burst(cqp->id, cqp->qp, cop, num);
+		cqp->in_flight += n;
+		free_cops(cop + n, num - n);
+		return;
+	}
+
+	k = 0;
+
+	do {
+		n = RTE_DIM(cqp->buf) - len;
+		n = RTE_MIN(num - k, n);
+
+		/* put packets into cqp */
+		for (i = 0; i != n; i++)
+			cqp->buf[len + i] = cop[k + i];
+
+		len += n;
+		k += n;
+
+		/* if cqp is full then, enqueue crypto-ops to PMD */
+		if (len == RTE_DIM(cqp->buf)) {
+			n = rte_cryptodev_enqueue_burst(cqp->id, cqp->qp,
+					cqp->buf, len);
+			cqp->in_flight += n;
+			free_cops(cqp->buf + n, len - n);
+			len = 0;
+		}
+
+
+	} while (k != num);
+
+	cqp->len = len;
+}
+
+static inline int
+fill_ipsec_session(struct rte_ipsec_session *ss, struct ipsec_ctx *ctx,
+	struct ipsec_sa *sa)
+{
+	int32_t rc;
+
+	/* setup crypto section */
+	if (ss->type == RTE_SECURITY_ACTION_TYPE_NONE) {
+		if (sa->crypto_session == NULL) {
+			rc = create_session(ctx, sa);
+			if (rc != 0)
+				return rc;
+		}
+		ss->crypto.ses = sa->crypto_session;
+	/* setup session action type */
+	} else {
+		if (sa->sec_session == NULL) {
+			rc = create_session(ctx, sa);
+			if (rc != 0)
+				return rc;
+		}
+		ss->security.ses = sa->sec_session;
+		ss->security.ctx = sa->security_ctx;
+		ss->security.ol_flags = sa->ol_flags;
+	}
+
+	rc = rte_ipsec_session_prepare(ss);
+	if (rc != 0)
+		memset(ss, 0, sizeof(*ss));
+
+	return rc;
+}
+
+/*
+ * group input packets byt the SA they belong to.
+ */
+static uint32_t
+sa_group(struct ipsec_sa *sa_ptr[], struct rte_mbuf *pkts[],
+	struct rte_ipsec_group grp[], uint32_t num)
+{
+	uint32_t i, n, spi;
+	void *sa;
+	void * const nosa = &spi;
+
+	sa = nosa;
+	for (i = 0, n = 0; i != num; i++) {
+
+		if (sa != sa_ptr[i]) {
+			grp[n].cnt = pkts + i - grp[n].m;
+			n += (sa != nosa);
+			grp[n].id.ptr = sa_ptr[i];
+			grp[n].m = pkts + i;
+			sa = sa_ptr[i];
+		}
+	}
+
+	/* terminate last group */
+	if (sa != nosa) {
+		grp[n].cnt = pkts + i - grp[n].m;
+		n++;
+	}
+
+	return n;
+}
+
+/*
+ * helper function, splits processed packets into ipv4/ipv6 traffic.
+ */
+static inline void
+copy_to_trf(struct ipsec_traffic *trf, uint64_t satp, struct rte_mbuf *mb[],
+	uint32_t num)
+{
+	uint32_t j, ofs, s;
+	struct traffic_type *out;
+
+	/*
+	 * determine traffic type(ipv4/ipv6) and offset for ACL classify
+	 * based on SA type
+	 */
+	if ((satp & RTE_IPSEC_SATP_DIR_MASK) == RTE_IPSEC_SATP_DIR_IB) {
+		if ((satp & RTE_IPSEC_SATP_IPV_MASK) == RTE_IPSEC_SATP_IPV4) {
+			out = &trf->ip4;
+			ofs = offsetof(struct ip, ip_p);
+		} else {
+			out = &trf->ip6;
+			ofs = offsetof(struct ip6_hdr, ip6_nxt);
+		}
+	} else if (SATP_OUT_IPV4(satp)) {
+		out = &trf->ip4;
+		ofs = offsetof(struct ip, ip_p);
+	} else {
+		out = &trf->ip6;
+		ofs = offsetof(struct ip6_hdr, ip6_nxt);
+	}
+
+	for (j = 0, s = out->num; j != num; j++) {
+		out->data[s + j] = rte_pktmbuf_mtod_offset(mb[j],
+				void *, ofs);
+		out->pkts[s + j] = mb[j];
+	}
+
+	out->num += num;
+}
+
+/*
+ * Process ipsec packets.
+ * If packet belong to SA that is subject of inline-crypto,
+ * then process it immediately.
+ * Otherwise do necessary preparations and queue it to related
+ * crypto-dev queue.
+ */
+void
+ipsec_process(struct ipsec_ctx *ctx, struct ipsec_traffic *trf)
+{
+	uint64_t satp;
+	uint32_t i, j, k, n;
+	struct ipsec_sa *sa;
+	struct ipsec_mbuf_metadata *priv;
+	struct rte_ipsec_group *pg;
+	struct rte_ipsec_session *ips;
+	struct cdev_qp *cqp;
+	struct rte_crypto_op *cop[RTE_DIM(trf->ipsec.pkts)];
+	struct rte_ipsec_group grp[RTE_DIM(trf->ipsec.pkts)];
+
+	n = sa_group(trf->ipsec.saptr, trf->ipsec.pkts, grp, trf->ipsec.num);
+
+	for (i = 0; i != n; i++) {
+
+		pg = grp + i;
+		sa = pg->id.ptr;
+
+		/* no valid SA found */
+		if (sa == NULL)
+			k = 0;
+
+		ips = &sa->ips;
+		satp = rte_ipsec_sa_type(ips->sa);
+
+		/* no valid HW session for that SA, try to create one */
+		if (ips->crypto.ses == NULL &&
+				fill_ipsec_session(ips, ctx, sa) != 0)
+			k = 0;
+
+		/* process packets inline */
+		else if (sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO ||
+				sa->type ==
+				RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) {
+
+			/*
+			 * This is just to satisfy inbound_sa_check()
+			 * and get_hop_for_offload_pkt().
+			 * Should be removed in future.
+			 */
+			for (j = 0; j != pg->cnt; j++) {
+				priv = get_priv(pg->m[j]);
+				priv->sa = sa;
+			}
+
+			k = rte_ipsec_pkt_process(ips, pg->m, pg->cnt);
+			copy_to_trf(trf, satp, pg->m, k);
+
+		/* enqueue packets to crypto dev */
+		} else {
+
+			cqp = &ctx->tbl[sa->cdev_id_qp];
+
+			/* for that app each mbuf has it's own crypto op */
+			for (j = 0; j != pg->cnt; j++) {
+				priv = get_priv(pg->m[j]);
+				cop[j] = &priv->cop;
+				/*
+				 * this is just to satisfy inbound_sa_check()
+				 * should be removed in future.
+				 */
+				priv->sa = sa;
+			}
+
+			/* prepare and enqueue crypto ops */
+			k = rte_ipsec_pkt_crypto_prepare(ips, pg->m, cop,
+				pg->cnt);
+			if (k != 0)
+				enqueue_cop_bulk(cqp, cop, k);
+		}
+
+		/* drop packets that cannot be enqueued/processed */
+		if (k != pg->cnt)
+			free_pkts(pg->m + k, pg->cnt - k);
+	}
+}
+
+static inline uint32_t
+cqp_dequeue(struct cdev_qp *cqp, struct rte_crypto_op *cop[], uint32_t num)
+{
+	uint32_t n;
+
+	if (cqp->in_flight == 0)
+		return 0;
+
+	n = rte_cryptodev_dequeue_burst(cqp->id, cqp->qp, cop, num);
+	RTE_ASSERT(cqp->in_flight >= n);
+	cqp->in_flight -= n;
+
+	return n;
+}
+
+static inline uint32_t
+ctx_dequeue(struct ipsec_ctx *ctx, struct rte_crypto_op *cop[], uint32_t num)
+{
+	uint32_t i, n;
+
+	n = 0;
+
+	for (i = ctx->last_qp; n != num && i != ctx->nb_qps; i++)
+		n += cqp_dequeue(ctx->tbl + i, cop + n, num - n);
+
+	for (i = 0; n != num && i != ctx->last_qp; i++)
+		n += cqp_dequeue(ctx->tbl + i, cop + n, num - n);
+
+	ctx->last_qp = i;
+	return n;
+}
+
+/*
+ * dequeue packets from crypto-queues and finalize processing.
+ */
+void
+ipsec_cqp_process(struct ipsec_ctx *ctx, struct ipsec_traffic *trf)
+{
+	uint64_t satp;
+	uint32_t i, k, n, ng;
+	struct rte_ipsec_session *ss;
+	struct traffic_type *out;
+	struct rte_ipsec_group *pg;
+	struct rte_crypto_op *cop[RTE_DIM(trf->ipsec.pkts)];
+	struct rte_ipsec_group grp[RTE_DIM(trf->ipsec.pkts)];
+
+	trf->ip4.num = 0;
+	trf->ip6.num = 0;
+
+	out = &trf->ipsec;
+
+	/* dequeue completed crypto-ops */
+	n = ctx_dequeue(ctx, cop, RTE_DIM(cop));
+	if (n == 0)
+		return;
+
+	/* group them by ipsec session */
+	ng = rte_ipsec_pkt_crypto_group((const struct rte_crypto_op **)
+		(uintptr_t)cop, out->pkts, grp, n);
+
+	/* process each group of packets */
+	for (i = 0; i != ng; i++) {
+
+		pg = grp + i;
+		ss = pg->id.ptr;
+		satp = rte_ipsec_sa_type(ss->sa);
+
+		k = rte_ipsec_pkt_process(ss, pg->m, pg->cnt);
+		copy_to_trf(trf, satp, pg->m, k);
+
+		/* free bad packets, if any */
+		free_pkts(pg->m + k, pg->cnt - k);
+
+		n -= pg->cnt;
+	}
+
+	/* we should never have packet with unknown SA here */
+	RTE_VERIFY(n == 0);
+}
diff --git a/examples/ipsec-secgw/meson.build b/examples/ipsec-secgw/meson.build
index 31f68fee2..81c146ebc 100644
--- a/examples/ipsec-secgw/meson.build
+++ b/examples/ipsec-secgw/meson.build
@@ -9,6 +9,6 @@
 deps += ['security', 'lpm', 'acl', 'hash', 'ipsec']
 allow_experimental_apis = true
 sources = files(
-	'esp.c', 'ipsec.c', 'ipsec-secgw.c', 'parser.c',
-	'rt.c', 'sa.c', 'sp4.c', 'sp6.c'
+	'esp.c', 'ipsec.c', 'ipsec_process.c', 'ipsec-secgw.c',
+	'parser.c', 'rt.c', 'sa.c', 'sp4.c', 'sp6.c'
 )
-- 
2.17.1

  parent reply	other threads:[~2019-01-03 20:25 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-22 18:49 [dpdk-dev] [PATCH 0/7] examples/ipsec-secgw: make app " Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 1/7] examples/ipsec-secgw: avoid to request unused TX offloads Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 0/7] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 1/7] examples/ipsec-secgw: avoid to request unused TX offloads Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 0/8] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-12-07 10:01       ` Radu Nicolau
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 0/9] " Konstantin Ananyev
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 1/9] examples/ipsec-secgw: avoid to request unused TX offloads Konstantin Ananyev
2018-12-21 13:57         ` Akhil Goyal
2018-12-21 15:58           ` Ananyev, Konstantin
2018-12-24  9:45             ` Akhil Goyal
2018-12-24 10:19               ` Ananyev, Konstantin
2018-12-24 10:54                 ` Akhil Goyal
2018-12-24 10:55                   ` Akhil Goyal
2018-12-24 11:22                   ` Ananyev, Konstantin
2018-12-24 11:24                     ` Akhil Goyal
2018-12-24 11:37                       ` Ananyev, Konstantin
2018-12-24 12:31                         ` Akhil Goyal
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 00/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-02  8:48           ` Akhil Goyal
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 01/10] examples/ipsec-secgw: allow user to disable some RX/TX offloads Konstantin Ananyev
2019-01-02 13:42           ` Akhil Goyal
2019-01-02 15:29             ` Ananyev, Konstantin
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 00/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-04 11:37             ` Akhil Goyal
2019-01-04 12:29               ` Ananyev, Konstantin
2019-01-04 14:40                 ` Akhil Goyal
2019-01-04 15:02                   ` Akhil Goyal
2019-01-04 17:04                   ` Ananyev, Konstantin
2019-01-04 17:38                     ` Akhil Goyal
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 01/10] examples/ipsec-secgw: allow user to disable some RX/TX offloads Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 00/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-10 15:20               ` Akhil Goyal
2019-01-11  1:08               ` Xu, Yanjie
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 01/10] examples/ipsec-secgw: allow user to disable some RX/TX offloads Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 00/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-11  0:00                 ` De Lara Guarch, Pablo
2019-01-11  0:16                   ` Ananyev, Konstantin
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 01/10] examples/ipsec-secgw: allow user to disable some Rx/Tx offloads Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 02/10] examples/ipsec-secgw: allow to specify neighbour MAC address Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 03/10] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 04/10] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 05/10] examples/ipsec-secgw: make local variables static Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 06/10] examples/ipsec-secgw: fix inbound SA checking Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 07/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 08/10] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 09/10] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2019-01-10 21:09               ` [dpdk-dev] [PATCH v8 10/10] doc: update ipsec-secgw guide and relelase notes Konstantin Ananyev
2019-01-11  2:49                 ` Varghese, Vipin
2019-01-11  6:56                   ` Akhil Goyal
2019-01-11  8:11                     ` Varghese, Vipin
2019-01-12 23:49                 ` Thomas Monjalon
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 02/10] examples/ipsec-secgw: allow to specify neighbour mac address Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 03/10] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 04/10] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 05/10] examples/ipsec-secgw: make local variables static Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 06/10] examples/ipsec-secgw: fix inbound SA checking Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 07/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 08/10] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 09/10] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2019-01-09 11:44             ` [dpdk-dev] [PATCH v7 10/10] doc: update ipsec-secgw guide and relelase notes Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 02/10] examples/ipsec-secgw: allow to specify neighbour mac address Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 03/10] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 04/10] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 05/10] examples/ipsec-secgw: make local variables static Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 06/10] examples/ipsec-secgw: fix inbound SA checking Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 07/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2019-01-03 20:25           ` Konstantin Ananyev [this message]
2019-01-04 14:58             ` [dpdk-dev] [PATCH v6 08/10] examples/ipsec-secgw: make data-path " Akhil Goyal
2019-01-04 16:25               ` Ananyev, Konstantin
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 09/10] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2019-01-03 20:25           ` [dpdk-dev] [PATCH v6 10/10] doc: update ipsec-secgw guide and relelase notes Konstantin Ananyev
2019-01-04  2:42             ` Varghese, Vipin
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 02/10] examples/ipsec-secgw: allow to specify neighbour mac address Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 03/10] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2019-01-02 11:44           ` Akhil Goyal
2019-01-02 13:43             ` Ananyev, Konstantin
2019-01-02 13:50               ` Akhil Goyal
2019-01-02 15:06                 ` Ananyev, Konstantin
2019-01-03 20:36                 ` Ananyev, Konstantin
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 04/10] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 05/10] examples/ipsec-secgw: make local variables static Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 06/10] examples/ipsec-secgw: fix inbound SA checking Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 07/10] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 08/10] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 09/10] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2018-12-28 15:33         ` [dpdk-dev] [PATCH v5 10/10] doc: update ipsec-secgw guide and relelase notes Konstantin Ananyev
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 2/9] examples/ipsec-secgw: allow to specify neighbor mac address Konstantin Ananyev
2018-12-21 14:05         ` Akhil Goyal
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 3/9] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2018-12-21 14:12         ` Akhil Goyal
2018-12-21 14:49           ` Ananyev, Konstantin
2018-12-21 14:57             ` Akhil Goyal
2018-12-21 15:01               ` Ananyev, Konstantin
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 4/9] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2018-12-21 14:25         ` Akhil Goyal
2018-12-21 14:54           ` Ananyev, Konstantin
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 5/9] examples/ipsec-secgw: make local variables static Konstantin Ananyev
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 6/9] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-12-21 15:15         ` Akhil Goyal
2018-12-24 12:29           ` Ananyev, Konstantin
2018-12-24 12:32             ` Akhil Goyal
2018-12-24 12:37               ` Ananyev, Konstantin
2018-12-24 13:21                 ` Ananyev, Konstantin
2018-12-24 13:50                   ` Akhil Goyal
2018-12-24 15:01                     ` Ananyev, Konstantin
2018-12-26  9:02                       ` Akhil Goyal
2018-12-27 11:06                         ` Ananyev, Konstantin
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 7/9] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2018-12-21 15:23         ` Akhil Goyal
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 8/9] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2018-12-14 16:40       ` [dpdk-dev] [PATCH v4 9/9] doc: update ipsec-secgw guide and relelase notes Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 1/8] examples/ipsec-secgw: avoid to request unused TX offloads Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 2/8] examples/ipsec-secgw: allow to specify neighbor mac address Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 3/8] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 4/8] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 5/8] examples/ipsec-secgw: make local variables static Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 6/8] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 7/8] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2018-12-06 15:54     ` [dpdk-dev] [PATCH v3 8/8] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 2/7] examples/ipsec-secgw: allow to specify neighbor mac address Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 3/7] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 4/7] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 5/7] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 6/7] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2018-11-30 17:04   ` [dpdk-dev] [PATCH v2 7/7] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 2/7] examples/ipsec-secgw: allow to specify neighbor mac address Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 3/7] examples/ipsec-secgw: fix crypto-op might never get dequeued Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 4/7] examples/ipsec-secgw: fix outbound codepath for single SA Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 5/7] examples/ipsec-secgw: make app to use ipsec library Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 6/7] examples/ipsec-secgw: make data-path " Konstantin Ananyev
2018-11-22 18:49 ` [dpdk-dev] [PATCH 7/7] examples/ipsec-secgw: add scripts for functional test Konstantin Ananyev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1546547138-24965-9-git-send-email-konstantin.ananyev@intel.com \
    --to=konstantin.ananyev@intel.com \
    --cc=akhil.goyal@nxp.com \
    --cc=bernard.iremonger@intel.com \
    --cc=dev@dpdk.org \
    --cc=mohammad.abdul.awal@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).