28 #define foreach_esp_decrypt_next \ 29 _(DROP, "error-drop") \ 30 _(IP4_INPUT, "ip4-input-no-checksum") \ 31 _(IP6_INPUT, "ip6-input") 33 #define _(v, s) ESP_DECRYPT_NEXT_##v, 40 #define foreach_esp_decrypt_error \ 41 _(RX_PKTS, "ESP pkts received") \ 42 _(DECRYPTION_FAILED, "ESP decryption failed") \ 43 _(REPLAY, "SA replayed packet") \ 44 _(NOT_IP, "Not IP packet (dropped)") \ 45 _(ENQ_FAIL, "Enqueue failed (buffer full)") \ 46 _(DISCARD, "Not enough crypto operations, discarding frame") \ 47 _(BAD_LEN, "Invalid ciphertext length") \ 48 _(SESSION, "Failed to get crypto session") \ 49 _(NOSUP, "Cipher/Auth not supported") 53 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 60 #define _(sym,string) string, 81 s =
format (s,
"cipher %U auth %U\n",
95 u32 n_left_from, *from, *to_next, next_index;
102 struct rte_cryptodev_sym_session *session = 0;
103 u32 ret, last_sa_index = ~0;
104 u8 numa = rte_socket_id ();
108 struct rte_crypto_op **ops = cwm->
ops;
117 ESP_DECRYPT_ERROR_DISCARD, 1);
122 next_index = ESP_DECRYPT_NEXT_DROP;
124 while (n_left_from > 0)
130 while (n_left_from > 0 && n_left_to_next > 0)
133 u32 bi0, sa_index0, seq, iv_size;
137 struct rte_mbuf *mb0;
138 struct rte_crypto_op *op;
156 ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
161 sizeof (op[0]) +
sizeof (op[0].sym[0]) +
sizeof (priv[0]);
166 if (sa_index0 != last_sa_index)
173 is_aead = (cipher_alg->
type == RTE_CRYPTO_SYM_XFORM_AEAD);
175 auth_alg = cipher_alg;
181 clib_warning (
"unsupported SA by thread index %u", thread_idx);
183 ESP_DECRYPT_ERROR_NOSUP, 1);
196 ESP_DECRYPT_ERROR_SESSION, 1);
203 last_sa_index = sa_index0;
211 seq = clib_net_to_host_u32 (esp0->
seq);
222 ESP_DECRYPT_ERROR_REPLAY, 1);
230 priv->
next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT_POST;
242 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
244 trunc_size = auth_alg->trunc_size;
245 iv_size = cipher_alg->
iv_len;
251 ASSERT (payload_len >= 4);
253 if (payload_len & (cipher_alg->
boundary - 1))
258 ESP_DECRYPT_ERROR_BAD_LEN, 1);
266 u32 cipher_off, cipher_len;
270 u8 *iv = (
u8 *) (esp0 + 1);
275 cipher_len = payload_len;
279 mb0->buf_physaddr + digest - ((
u8 *) mb0->buf_addr);
281 if (!is_aead && cipher_alg->
alg == RTE_CRYPTO_CIPHER_AES_CBC)
298 _aad[2] = clib_host_to_net_u32 (sa0->
seq_hi);
304 auth_len =
sizeof(
esp_header_t) + iv_size + payload_len;
309 u32 *_digest = (
u32 *) digest;
310 _digest[0] = clib_host_to_net_u32 (sa0->
seq_hi);
311 auth_len +=
sizeof(sa0->
seq_hi);
315 op->phys_addr + (uintptr_t) priv->
icv - (uintptr_t) op;
320 0, auth_len, aad, digest, digest_paddr);
335 ESP_DECRYPT_ERROR_RX_PKTS,
339 ESP_DECRYPT_ERROR_ENQ_FAIL, numa);
349 .name =
"dpdk-esp-decrypt",
350 .vector_size =
sizeof (
u32),
359 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 372 #define foreach_esp_decrypt_post_error \ 373 _(PKTS, "ESP post pkts") 376 #define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym, 383 #define _(sym,string) string, 397 s =
format (s,
"cipher %U auth %U\n",
415 u32 n_left_from, *from, *to_next = 0, next_index;
426 while (n_left_from > 0)
432 while (n_left_from > 0 && n_left_to_next > 0)
435 u32 bi0, iv_size, next0;
441 u8 trunc_size, is_aead;
442 u16 udp_encap_adv = 0;
444 next0 = ESP_DECRYPT_NEXT_DROP;
462 is_aead = cipher_alg->
type == RTE_CRYPTO_SYM_XFORM_AEAD;
464 auth_alg = cipher_alg;
468 iv_size = cipher_alg->
iv_len;
473 seq = clib_host_to_net_u32(esp0->
seq);
486 if (b0->
flags & VNET_BUFFER_F_IS_IP4)
495 b0->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
505 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
513 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
515 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
520 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
531 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
535 memmove(oh4, ih4, ih4_len);
548 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
551 oh6->payload_length = clib_host_to_net_u16 (len);
557 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
576 to_next, n_left_to_next, bi0, next0);
582 ESP_DECRYPT_POST_ERROR_PKTS,
591 .name =
"dpdk-esp-decrypt-post",
592 .vector_size =
sizeof (
u32),
601 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
static_always_inline void crypto_op_setup(u8 is_aead, struct rte_mbuf *mb0, struct rte_crypto_op *op, void *session, u32 cipher_off, u32 cipher_len, u32 auth_off, u32 auth_len, u8 *aad, u8 *digest, u64 digest_paddr)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer's data.
static char * esp_decrypt_post_error_strings[]
static u8 * format_esp_decrypt_post_trace(u8 *s, va_list *args)
static void esp_replay_advance(ipsec_sa_t *sa, u32 seq)
static int ip4_header_bytes(ip4_header_t *i)
static_always_inline i32 crypto_alloc_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
ipsec_integ_alg_t integ_alg
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
ipsec_crypto_alg_t crypto_alg
vlib_node_registration_t dpdk_esp_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_post_node)
static_always_inline void crypto_enqueue_ops(vlib_main_t *vm, crypto_worker_main_t *cwm, u8 outbound, u32 node_index, u32 error, u8 numa)
static char * esp_decrypt_error_strings[]
static_always_inline clib_error_t * crypto_get_session(struct rte_cryptodev_sym_session **session, u32 sa_idx, crypto_resource_t *res, crypto_worker_main_t *cwm, u8 is_outbound)
static_always_inline void crypto_free_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define foreach_esp_decrypt_next
dpdk_crypto_main_t dpdk_crypto_main
static void esp_replay_advance_esn(ipsec_sa_t *sa, u32 seq)
#define foreach_esp_decrypt_post_error
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static const u8 pad_data[]
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
static uword dpdk_esp_decrypt_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
#define rte_mbuf_from_vlib_buffer(x)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
crypto_alg_t * cipher_algs
static int esp_replay_check_esn(ipsec_sa_t *sa, u32 seq)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static uword dpdk_esp_decrypt_post_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define VLIB_REGISTER_NODE(x,...)
static_always_inline uword vlib_get_thread_index(void)
#define CLIB_PREFETCH(addr, size, type)
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
u8 * format_esp_header(u8 *s, va_list *args)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
static int esp_replay_check(ipsec_sa_t *sa, u32 seq)
crypto_worker_main_t * workers_main
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
crypto_resource_t * resource
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
struct _vlib_node_registration vlib_node_registration_t
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
struct rte_crypto_op ** ops
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
enum rte_crypto_sym_xform_type type
static_always_inline u16 get_resource(crypto_worker_main_t *cwm, ipsec_sa_t *sa)
ipsec_crypto_alg_t crypto_alg
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
#define foreach_esp_decrypt_error
struct rte_crypto_op * ops[VLIB_FRAME_SIZE]
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
ipsec_integ_alg_t integ_alg
static_always_inline dpdk_op_priv_t * crypto_op_get_priv(struct rte_crypto_op *op)
vlib_node_registration_t dpdk_esp_decrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_node)