examples/ipsec-secgw: rework processing loop
[dpdk.git] / examples / ipsec-secgw / esp.c
index 1927380..2ca97ad 100644 (file)
@@ -58,7 +58,7 @@ random_iv_u64(uint64_t *buf, uint16_t n)
        unsigned left = n & 0x7;
        unsigned i;
 
-       IPSEC_ASSERT((n & 0x3) == 0);
+       RTE_ASSERT((n & 0x3) == 0);
 
        for (i = 0; i < (n >> 3); i++)
                buf[i] = rte_rand();
@@ -67,23 +67,22 @@ random_iv_u64(uint64_t *buf, uint16_t n)
                *((uint32_t *)&buf[i]) = (uint32_t)lrand48();
 }
 
-/* IPv4 Tunnel */
 int
-esp4_tunnel_inbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
+esp_inbound(struct rte_mbuf *m, struct ipsec_sa *sa,
                struct rte_crypto_op *cop)
 {
        int32_t payload_len;
        struct rte_crypto_sym_op *sym_cop;
 
-       IPSEC_ASSERT(m != NULL);
-       IPSEC_ASSERT(sa != NULL);
-       IPSEC_ASSERT(cop != NULL);
+       RTE_ASSERT(m != NULL);
+       RTE_ASSERT(sa != NULL);
+       RTE_ASSERT(cop != NULL);
 
        payload_len = rte_pktmbuf_pkt_len(m) - IP_ESP_HDR_SZ - sa->iv_len -
                sa->digest_len;
 
        if ((payload_len & (sa->block_size - 1)) || (payload_len <= 0)) {
-               IPSEC_LOG(DEBUG, IPSEC_ESP, "payload %d not multiple of %u\n",
+               RTE_LOG(DEBUG, IPSEC_ESP, "payload %d not multiple of %u\n",
                                payload_len, sa->block_size);
                return -EINVAL;
        }
@@ -117,19 +116,19 @@ esp4_tunnel_inbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
 }
 
 int
-esp4_tunnel_inbound_post_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
+esp_inbound_post(struct rte_mbuf *m, struct ipsec_sa *sa,
                struct rte_crypto_op *cop)
 {
        uint8_t *nexthdr, *pad_len;
        uint8_t *padding;
        uint16_t i;
 
-       IPSEC_ASSERT(m != NULL);
-       IPSEC_ASSERT(sa != NULL);
-       IPSEC_ASSERT(cop != NULL);
+       RTE_ASSERT(m != NULL);
+       RTE_ASSERT(sa != NULL);
+       RTE_ASSERT(cop != NULL);
 
        if (cop->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
-               IPSEC_LOG(ERR, IPSEC_ESP, "Failed crypto op\n");
+               RTE_LOG(ERR, IPSEC_ESP, "Failed crypto op\n");
                return -1;
        }
 
@@ -139,14 +138,14 @@ esp4_tunnel_inbound_post_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
 
        padding = pad_len - *pad_len;
        for (i = 0; i < *pad_len; i++) {
-               if (padding[i] != i) {
-                       IPSEC_LOG(ERR, IPSEC_ESP, "invalid pad_len field\n");
+               if (padding[i] != i + 1) {
+                       RTE_LOG(ERR, IPSEC_ESP, "invalid pad_len field\n");
                        return -EINVAL;
                }
        }
 
        if (rte_pktmbuf_trim(m, *pad_len + 2 + sa->digest_len)) {
-               IPSEC_LOG(ERR, IPSEC_ESP,
+               RTE_LOG(ERR, IPSEC_ESP,
                                "failed to remove pad_len + digest\n");
                return -EINVAL;
        }
@@ -155,7 +154,7 @@ esp4_tunnel_inbound_post_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
 }
 
 int
-esp4_tunnel_outbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
+esp_outbound(struct rte_mbuf *m, struct ipsec_sa *sa,
                struct rte_crypto_op *cop)
 {
        uint16_t pad_payload_len, pad_len;
@@ -165,9 +164,9 @@ esp4_tunnel_outbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
        char *padding;
        struct rte_crypto_sym_op *sym_cop;
 
-       IPSEC_ASSERT(m != NULL);
-       IPSEC_ASSERT(sa != NULL);
-       IPSEC_ASSERT(cop != NULL);
+       RTE_ASSERT(m != NULL);
+       RTE_ASSERT(sa != NULL);
+       RTE_ASSERT(cop != NULL);
 
        /* Payload length */
        pad_payload_len = RTE_ALIGN_CEIL(rte_pktmbuf_pkt_len(m) + 2,
@@ -180,13 +179,13 @@ esp4_tunnel_outbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
        /* Check maximum packet size */
        if (unlikely(IP_ESP_HDR_SZ + sa->iv_len + pad_payload_len +
                                sa->digest_len > IP_MAXPACKET)) {
-               IPSEC_LOG(DEBUG, IPSEC_ESP, "ipsec packet is too big\n");
+               RTE_LOG(DEBUG, IPSEC_ESP, "ipsec packet is too big\n");
                return -EINVAL;
        }
 
        padding = rte_pktmbuf_append(m, pad_len + sa->digest_len);
 
-       IPSEC_ASSERT(padding != NULL);
+       RTE_ASSERT(padding != NULL);
 
        ip = ip4ip_outbound(m, sizeof(struct esp_hdr) + sa->iv_len,
                        sa->src, sa->dst);
@@ -195,7 +194,7 @@ esp4_tunnel_outbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
        esp->spi = sa->spi;
        esp->seq = htonl(sa->seq++);
 
-       IPSEC_LOG(DEBUG, IPSEC_ESP, "pktlen %u\n", rte_pktmbuf_pkt_len(m));
+       RTE_LOG(DEBUG, IPSEC_ESP, "pktlen %u\n", rte_pktmbuf_pkt_len(m));
 
        /* Fill pad_len using default sequential scheme */
        for (i = 0; i < pad_len - 2; i++)
@@ -234,16 +233,16 @@ esp4_tunnel_outbound_pre_crypto(struct rte_mbuf *m, struct ipsec_sa *sa,
 }
 
 int
-esp4_tunnel_outbound_post_crypto(struct rte_mbuf *m __rte_unused,
+esp_outbound_post(struct rte_mbuf *m __rte_unused,
                struct ipsec_sa *sa __rte_unused,
                struct rte_crypto_op *cop)
 {
-       IPSEC_ASSERT(m != NULL);
-       IPSEC_ASSERT(sa != NULL);
-       IPSEC_ASSERT(cop != NULL);
+       RTE_ASSERT(m != NULL);
+       RTE_ASSERT(sa != NULL);
+       RTE_ASSERT(cop != NULL);
 
        if (cop->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
-               IPSEC_LOG(ERR, IPSEC_ESP, "Failed crypto op\n");
+               RTE_LOG(ERR, IPSEC_ESP, "Failed crypto op\n");
                return -1;
        }