28 #define foreach_esp_decrypt_next \ 29 _(DROP, "error-drop") \ 30 _(IP4_INPUT, "ip4-input") \ 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 _(NO_CRYPTODEV, "Cryptodev not configured") \ 47 _(BAD_LEN, "Invalid ciphertext length") 51 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 58 #define _(sym,string) string, 77 s =
format (s,
"esp: crypto %U integrity %U",
88 u32 n_left_from, *from, *to_next, next_index;
101 struct rte_crypto_op ** cops_to_enq[n_qps];
102 u32 n_cop_qp[n_qps], * bi_to_enq[n_qps];
104 for (i = 0; i < n_qps; i++)
110 memset(n_cop_qp, 0, n_qps *
sizeof(
u32));
114 next_index = ESP_DECRYPT_NEXT_DROP;
116 while (n_left_from > 0)
122 while (n_left_from > 0 && n_left_to_next > 0)
124 u32 bi0, sa_index0 = ~0, seq, trunc_size, iv_size;
128 struct rte_mbuf * mb0 = 0;
129 const int BLOCK_SIZE = 16;
133 struct rte_crypto_op * cop = 0;
145 seq = clib_host_to_net_u32(esp0->
seq);
161 ESP_DECRYPT_ERROR_REPLAY, 1);
186 sess = sa_sess->
sess;
191 ASSERT (cop->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
193 cops_to_enq[qp_index][0] = cop;
194 cops_to_enq[qp_index] += 1;
195 n_cop_qp[qp_index] += 1;
196 bi_to_enq[qp_index][0] = bi0;
197 bi_to_enq[qp_index] += 1;
199 rte_crypto_op_attach_sym_session(cop, sess);
201 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
211 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
215 iv_size - trunc_size;
217 if ((payload_len & (BLOCK_SIZE - 1)) || (payload_len <= 0))
220 payload_len, BLOCK_SIZE);
222 ESP_DECRYPT_ERROR_BAD_LEN, 1);
224 bi_to_enq[qp_index] -= 1;
225 cops_to_enq[qp_index] -= 1;
226 n_cop_qp[qp_index] -= 1;
233 struct rte_crypto_sym_op *sym_cop = (
struct rte_crypto_sym_op *)(cop + 1);
235 u8 is_aead = sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128;
236 u32 cipher_off, cipher_len;
237 u32 auth_off = 0, auth_len = 0, aad_size = 0;
241 u8 *iv = rte_pktmbuf_mtod_offset(mb0,
void*,
sizeof (
esp_header_t));
246 cipher_len = payload_len;
250 iv_size + payload_len;
252 digest_paddr = mb0->buf_physaddr + (digest - (
u8 *) mb0->buf_addr);
275 auth_len =
sizeof(
esp_header_t) + iv_size + payload_len;
283 auth_len +=
sizeof(sa0->
seq_hi);
287 cop->phys_addr + (uintptr_t) priv->
icv - (uintptr_t) cop;
292 cipher_off, cipher_len, (
u8 *) icb, iv_size,
293 auth_off, auth_len, aad, aad_size,
294 digest, digest_paddr, trunc_size);
306 ESP_DECRYPT_ERROR_RX_PKTS,
318 enq = rte_cryptodev_enqueue_burst(qpd->
dev_id, qpd->
qp_id,
319 qpd->
cops, n_cop_qp[i]);
328 ESP_DECRYPT_ERROR_ENQ_FAIL,
340 .name =
"dpdk-esp-decrypt",
341 .vector_size =
sizeof (
u32),
350 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 363 #define foreach_esp_decrypt_post_error \ 364 _(PKTS, "ESP post pkts") 367 #define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym, 374 #define _(sym,string) string, 391 u32 n_left_from, *from, *to_next = 0, next_index;
402 while (n_left_from > 0)
408 while (n_left_from > 0 && n_left_to_next > 0)
411 u32 bi0, next0, trunc_size, iv_size;
416 u8 transport_ip6 = 0;
418 next0 = ESP_DECRYPT_NEXT_DROP;
433 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
443 seq = clib_host_to_net_u32(esp0->
seq);
472 ESP_DECRYPT_ERROR_NOT_IP, 1);
481 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
483 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
488 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
503 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
505 oh6->payload_length =
506 clib_host_to_net_u16 (
516 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
517 oh4->ip_version_and_header_length = 0x45;
518 oh4->fragment_id = 0;
519 oh4->flags_and_fragment_offset = 0;
521 oh4->length = clib_host_to_net_u16 (
538 to_next, n_left_to_next, bi0, next0);
543 ESP_DECRYPT_POST_ERROR_PKTS,
552 .name =
"dpdk-esp-decrypt-post",
553 .vector_size =
sizeof (
u32),
562 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
#define vec_foreach_index(var, v)
Iterate over vector indices.
sll srl srl sll sra u16x4 i
static void esp_replay_advance(ipsec_sa_t *sa, u32 seq)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static char * esp_decrypt_post_error_strings[]
static u8 * format_esp_decrypt_post_trace(u8 *s, va_list *args)
static int esp_replay_check(ipsec_sa_t *sa, u32 seq)
static_always_inline i32 create_sym_sess(ipsec_sa_t *sa, crypto_sa_session_t *sa_sess, u8 is_outbound)
ipsec_integ_alg_t integ_alg
ipsec_crypto_alg_t crypto_alg
vlib_node_registration_t dpdk_esp_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_post_node)
struct _vlib_node_registration vlib_node_registration_t
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
static void esp_replay_advance_esn(ipsec_sa_t *sa, u32 seq)
#define vec_pop(V)
Returns last element of a vector and decrements its length.
static_always_inline void crypto_free_cop(crypto_qp_data_t *qpd, struct rte_crypto_op **cops, u32 n)
static char * esp_decrypt_error_strings[]
dpdk_crypto_main_t dpdk_crypto_main
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define foreach_esp_decrypt_next
static_always_inline void crypto_alloc_cops()
#define foreach_esp_decrypt_post_error
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
dpdk_esp_main_t dpdk_esp_main
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
dpdk_esp_integ_alg_t * esp_integ_algs
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
dpdk_esp_crypto_alg_t * esp_crypto_algs
static uword dpdk_esp_decrypt_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#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.
static_always_inline void crypto_op_setup(u8 is_aead, struct rte_mbuf *mb0, struct rte_crypto_op *cop, void *session, u32 cipher_off, u32 cipher_len, u8 *icb __unused, u32 iv_size __unused, u32 auth_off, u32 auth_len, u8 *aad __unused, u32 aad_size __unused, u8 *digest, u64 digest_paddr, u32 digest_size __unused)
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)
struct rte_crypto_op * cops[VLIB_FRAME_SIZE]
#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)
static int esp_replay_check_esn(ipsec_sa_t *sa, u32 seq)
static_always_inline uword vlib_get_thread_index(void)
#define clib_warning(format, args...)
#define VLIB_BUFFER_IS_TRACED
#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.
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
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_qp_data_t * qp_data
crypto_sa_session_t * sa_sess_d[2]
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
ipsec_crypto_alg_t crypto_alg
#define VLIB_REGISTER_NODE(x,...)
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
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
vlib_node_registration_t dpdk_esp_decrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_node)