examples/ipsec-secgw: rework processing loop
[dpdk.git] / examples / ipsec-secgw / ipsec.c
index 3ffa77a..90a9a86 100644 (file)
@@ -42,6 +42,7 @@
 #include <rte_hash.h>
 
 #include "ipsec.h"
+#include "esp.h"
 
 static inline int
 create_session(struct ipsec_ctx *ipsec_ctx __rte_unused, struct ipsec_sa *sa)
@@ -99,15 +100,14 @@ enqueue_cop(struct cdev_qp *cqp, struct rte_crypto_op *cop)
        }
 }
 
-static inline uint16_t
-ipsec_processing(struct ipsec_ctx *ipsec_ctx, struct rte_mbuf *pkts[],
-               struct ipsec_sa *sas[], uint16_t nb_pkts, uint16_t max_pkts)
+static inline void
+ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
+               struct rte_mbuf *pkts[], struct ipsec_sa *sas[],
+               uint16_t nb_pkts)
 {
-       int ret = 0, i, j, nb_cops;
+       int ret = 0, i;
        struct ipsec_mbuf_metadata *priv;
-       struct rte_crypto_op *cops[max_pkts];
        struct ipsec_sa *sa;
-       struct rte_mbuf *pkt;
 
        for (i = 0; i < nb_pkts; i++) {
                rte_prefetch0(sas[i]);
@@ -133,7 +133,7 @@ ipsec_processing(struct ipsec_ctx *ipsec_ctx, struct rte_mbuf *pkts[],
                rte_crypto_op_attach_sym_session(&priv->cop,
                                sa->crypto_session);
 
-               ret = sa->pre_crypto(pkts[i], sa, &priv->cop);
+               ret = xform_func(pkts[i], sa, &priv->cop);
                if (unlikely(ret)) {
                        rte_pktmbuf_free(pkts[i]);
                        continue;
@@ -142,8 +142,18 @@ ipsec_processing(struct ipsec_ctx *ipsec_ctx, struct rte_mbuf *pkts[],
                RTE_ASSERT(sa->cdev_id_qp < ipsec_ctx->nb_qps);
                enqueue_cop(&ipsec_ctx->tbl[sa->cdev_id_qp], &priv->cop);
        }
+}
+
+static inline int
+ipsec_dequeue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
+               struct rte_mbuf *pkts[], uint16_t max_pkts)
+{
+       int nb_pkts = 0, ret = 0, i, j, nb_cops;
+       struct ipsec_mbuf_metadata *priv;
+       struct rte_crypto_op *cops[max_pkts];
+       struct ipsec_sa *sa;
+       struct rte_mbuf *pkt;
 
-       nb_pkts = 0;
        for (i = 0; i < ipsec_ctx->nb_qps && nb_pkts < max_pkts; i++) {
                struct cdev_qp *cqp;
 
@@ -168,7 +178,7 @@ ipsec_processing(struct ipsec_ctx *ipsec_ctx, struct rte_mbuf *pkts[],
 
                        RTE_ASSERT(sa != NULL);
 
-                       ret = sa->post_crypto(pkt, sa, cops[j]);
+                       ret = xform_func(pkt, sa, cops[j]);
                        if (unlikely(ret))
                                rte_pktmbuf_free(pkt);
                        else
@@ -188,7 +198,9 @@ ipsec_inbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
 
        inbound_sa_lookup(ctx->sa_ctx, pkts, sas, nb_pkts);
 
-       return ipsec_processing(ctx, pkts, sas, nb_pkts, len);
+       ipsec_enqueue(esp_inbound, ctx, pkts, sas, nb_pkts);
+
+       return ipsec_dequeue(esp_inbound_post, ctx, pkts, len);
 }
 
 uint16_t
@@ -199,5 +211,7 @@ ipsec_outbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
 
        outbound_sa_lookup(ctx->sa_ctx, sa_idx, sas, nb_pkts);
 
-       return ipsec_processing(ctx, pkts, sas, nb_pkts, len);
+       ipsec_enqueue(esp_outbound, ctx, pkts, sas, nb_pkts);
+
+       return ipsec_dequeue(esp_outbound_post, ctx, pkts, len);
 }