25 #include <dpdk/ipsec/ipsec.h>
29 #define foreach_esp_decrypt_next \
30 _(DROP, "error-drop") \
31 _(IP4_INPUT, "ip4-input-no-checksum") \
32 _(IP6_INPUT, "ip6-input")
34 #define _(v, s) ESP_DECRYPT_NEXT_##v,
42 #define foreach_esp_decrypt_error \
43 _(RX_PKTS, "ESP pkts received") \
44 _(DECRYPTION_FAILED, "ESP decryption failed") \
45 _(REPLAY, "SA replayed packet") \
46 _(NOT_IP, "Not IP packet (dropped)") \
47 _(ENQ_FAIL, "Enqueue decrypt failed (queue full)") \
48 _(DISCARD, "Not enough crypto operations") \
49 _(BAD_LEN, "Invalid ciphertext length") \
50 _(SESSION, "Failed to get crypto session") \
51 _(NOSUP, "Cipher/Auth not supported")
56 #define _(sym,str) ESP_DECRYPT_ERROR_##sym,
63 #define _(sym,string) string,
73 ipsec_crypto_alg_t crypto_alg;
87 s =
format (s,
"cipher %U auth %U\n",
106 struct rte_cryptodev_sym_session *session = 0;
107 u32 ret, last_sa_index = ~0;
108 u8 numa = rte_socket_id ();
112 struct rte_crypto_op **ops = cwm->
ops;
143 u32 bi0, sa_index0, iv_size;
147 struct rte_mbuf *mb0;
148 struct rte_crypto_op *op;
166 ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
174 sizeof (op[0]) +
sizeof (op[0].sym[0]) +
sizeof (priv[0]);
181 if (sa_index0 != last_sa_index)
189 is_aead = (cipher_alg->
type == RTE_CRYPTO_SYM_XFORM_AEAD);
191 auth_alg = cipher_alg;
200 ESP_DECRYPT_ERROR_NOSUP, 1);
204 ESP_DECRYPT_ERROR_NOSUP, 1);
218 ESP_DECRYPT_ERROR_SESSION,
223 ESP_DECRYPT_ERROR_SESSION,
231 last_sa_index = sa_index0;
236 (sa0, clib_host_to_net_u32 (esp0->
seq)))
241 ESP_DECRYPT_ERROR_REPLAY, 1);
245 ESP_DECRYPT_ERROR_REPLAY, 1);
253 priv->
next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT6_POST;
256 priv->
next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT4_POST;
257 b0->
flags |= VNET_BUFFER_F_IS_IP4;
272 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
274 trunc_size = auth_alg->trunc_size;
275 iv_size = cipher_alg->
iv_len;
281 ASSERT (payload_len >= 4);
283 if (payload_len & (cipher_alg->
boundary - 1))
287 ESP_DECRYPT_ERROR_BAD_LEN, 1);
290 ESP_DECRYPT_ERROR_BAD_LEN, 1);
298 u32 cipher_off, cipher_len;
302 u8 *
iv = (
u8 *) (esp0 + 1);
307 cipher_len = payload_len;
310 u64 digest_paddr = mb0->buf_iova + digest - ((
u8 *) mb0->buf_addr);
312 if (!is_aead && cipher_alg->
alg == RTE_CRYPTO_CIPHER_AES_CBC)
331 _aad[1] = clib_host_to_net_u32 (sa0->
seq_hi);
338 auth_len =
sizeof (
esp_header_t) + iv_size + payload_len;
340 if (ipsec_sa_is_set_USE_ESN (sa0))
343 u32 *_digest = (
u32 *) digest;
344 _digest[0] = clib_host_to_net_u32 (sa0->
seq_hi);
345 auth_len +=
sizeof (sa0->
seq_hi);
349 op->phys_addr + (uintptr_t) priv->
icv - (uintptr_t) op;
354 0, auth_len, aad, digest, digest_paddr);
372 ESP_DECRYPT_ERROR_RX_PKTS,
376 ESP_DECRYPT_ERROR_ENQ_FAIL, numa, 0 );
381 ESP_DECRYPT_ERROR_RX_PKTS,
385 ESP_DECRYPT_ERROR_ENQ_FAIL, numa, 0 );
402 .name =
"dpdk-esp4-decrypt",
403 .vector_size =
sizeof (
u32),
412 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
428 .name =
"dpdk-esp6-decrypt",
429 .vector_size =
sizeof (
u32),
438 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
449 #define foreach_esp_decrypt_post_error \
450 _(PKTS, "ESP post pkts")
454 #define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym,
461 #define _(sym,string) string,
477 s =
format (s,
"cipher %U auth %U\n",
516 u32 bi0, iv_size, next0;
522 u8 trunc_size, is_aead;
523 u16 udp_encap_adv = 0;
525 next0 = ESP_DECRYPT_NEXT_DROP;
543 is_aead = cipher_alg->
type == RTE_CRYPTO_SYM_XFORM_AEAD;
545 auth_alg = cipher_alg;
549 iv_size = cipher_alg->
iv_len;
552 clib_host_to_net_u32 (esp0->
seq));
555 if (ipsec_sa_is_set_UDP_ENCAP (sa0)
556 && (b0->
flags & VNET_BUFFER_F_IS_IP4))
561 if (b0->
flags & VNET_BUFFER_F_IS_IP4)
569 b0->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
579 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
584 if (ipsec_sa_is_set_IS_TUNNEL (sa0))
587 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
589 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
596 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
601 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
612 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
615 memmove (oh4, ih4, ih4_len);
627 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
630 oh6->payload_length = clib_host_to_net_u16 (
len);
638 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
643 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
663 to_next, n_left_to_next, bi0,
671 ESP_DECRYPT_POST_ERROR_PKTS,
675 ESP_DECRYPT_POST_ERROR_PKTS,
690 .name =
"dpdk-esp4-decrypt-post",
691 .vector_size =
sizeof (
u32),
700 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
716 .name =
"dpdk-esp6-decrypt-post",
717 .vector_size =
sizeof (
u32),
726 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,