net: add rte prefix to ESP structure
[dpdk.git] / lib / librte_ipsec / esp_outb.c
index 09bfb86..862a998 100644 (file)
 #include "misc.h"
 #include "pad.h"
 
+
+/*
+ * helper function to fill crypto_sym op for cipher+auth algorithms.
+ * used by outb_cop_prepare(), see below.
+ */
+static inline void
+sop_ciph_auth_prepare(struct rte_crypto_sym_op *sop,
+       const struct rte_ipsec_sa *sa, const union sym_op_data *icv,
+       uint32_t pofs, uint32_t plen)
+{
+       sop->cipher.data.offset = sa->ctp.cipher.offset + pofs;
+       sop->cipher.data.length = sa->ctp.cipher.length + plen;
+       sop->auth.data.offset = sa->ctp.auth.offset + pofs;
+       sop->auth.data.length = sa->ctp.auth.length + plen;
+       sop->auth.digest.data = icv->va;
+       sop->auth.digest.phys_addr = icv->pa;
+}
+
+/*
+ * helper function to fill crypto_sym op for cipher+auth algorithms.
+ * used by outb_cop_prepare(), see below.
+ */
+static inline void
+sop_aead_prepare(struct rte_crypto_sym_op *sop,
+       const struct rte_ipsec_sa *sa, const union sym_op_data *icv,
+       uint32_t pofs, uint32_t plen)
+{
+       sop->aead.data.offset = sa->ctp.cipher.offset + pofs;
+       sop->aead.data.length = sa->ctp.cipher.length + plen;
+       sop->aead.digest.data = icv->va;
+       sop->aead.digest.phys_addr = icv->pa;
+       sop->aead.aad.data = icv->va + sa->icv_len;
+       sop->aead.aad.phys_addr = icv->pa + sa->icv_len;
+}
+
 /*
  * setup crypto op and crypto sym op for ESP outbound packet.
  */
@@ -40,21 +75,11 @@ outb_cop_prepare(struct rte_crypto_op *cop,
                /* Cipher-Auth (3DES-CBC *) case */
        case ALGO_TYPE_NULL:
                /* NULL case */
-               sop->cipher.data.offset = sa->ctp.cipher.offset + hlen;
-               sop->cipher.data.length = sa->ctp.cipher.length + plen;
-               sop->auth.data.offset = sa->ctp.auth.offset + hlen;
-               sop->auth.data.length = sa->ctp.auth.length + plen;
-               sop->auth.digest.data = icv->va;
-               sop->auth.digest.phys_addr = icv->pa;
+               sop_ciph_auth_prepare(sop, sa, icv, hlen, plen);
                break;
        case ALGO_TYPE_AES_GCM:
                /* AEAD (AES_GCM) case */
-               sop->aead.data.offset = sa->ctp.cipher.offset + hlen;
-               sop->aead.data.length = sa->ctp.cipher.length + plen;
-               sop->aead.digest.data = icv->va;
-               sop->aead.digest.phys_addr = icv->pa;
-               sop->aead.aad.data = icv->va + sa->icv_len;
-               sop->aead.aad.phys_addr = icv->pa + sa->icv_len;
+               sop_aead_prepare(sop, sa, icv, hlen, plen);
 
                /* fill AAD IV (located inside crypto op) */
                gcm = rte_crypto_op_ctod_offset(cop, struct aead_gcm_iv *,
@@ -63,13 +88,9 @@ outb_cop_prepare(struct rte_crypto_op *cop,
                break;
        case ALGO_TYPE_AES_CTR:
                /* Cipher-Auth (AES-CTR *) case */
-               sop->cipher.data.offset = sa->ctp.cipher.offset + hlen;
-               sop->cipher.data.length = sa->ctp.cipher.length + plen;
-               sop->auth.data.offset = sa->ctp.auth.offset + hlen;
-               sop->auth.data.length = sa->ctp.auth.length + plen;
-               sop->auth.digest.data = icv->va;
-               sop->auth.digest.phys_addr = icv->pa;
+               sop_ciph_auth_prepare(sop, sa, icv, hlen, plen);
 
+               /* fill CTR block (located inside crypto op) */
                ctr = rte_crypto_op_ctod_offset(cop, struct aesctr_cnt_blk *,
                        sa->iv_ofs);
                aes_ctr_cnt_blk_fill(ctr, ivp[0], sa->salt);
@@ -87,7 +108,7 @@ outb_tun_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc,
 {
        uint32_t clen, hlen, l2len, pdlen, pdofs, plen, tlen;
        struct rte_mbuf *ml;
-       struct esp_hdr *esph;
+       struct rte_esp_hdr *esph;
        struct esp_tail *espt;
        char *ph, *pt;
        uint64_t *iv;
@@ -135,7 +156,7 @@ outb_tun_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc,
                        sqn_low16(sqc));
 
        /* update spi, seqn and iv */
-       esph = (struct esp_hdr *)(ph + sa->hdr_len);
+       esph = (struct rte_esp_hdr *)(ph + sa->hdr_len);
        iv = (uint64_t *)(esph + 1);
        copy_iv(iv, ivp, sa->iv_len);
 
@@ -254,7 +275,7 @@ outb_trs_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc,
        uint8_t np;
        uint32_t clen, hlen, pdlen, pdofs, plen, tlen, uhlen;
        struct rte_mbuf *ml;
-       struct esp_hdr *esph;
+       struct rte_esp_hdr *esph;
        struct esp_tail *espt;
        char *ph, *pt;
        uint64_t *iv;
@@ -297,7 +318,7 @@ outb_trs_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc,
                        IPPROTO_ESP);
 
        /* update spi, seqn and iv */
-       esph = (struct esp_hdr *)(ph + uhlen);
+       esph = (struct rte_esp_hdr *)(ph + uhlen);
        iv = (uint64_t *)(esph + 1);
        copy_iv(iv, ivp, sa->iv_len);