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") \ 48 _(UNSUPPORTED, "Cipher/Auth not supported") 52 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 59 #define _(sym,string) string, 78 s =
format (s,
"esp: crypto %U integrity %U",
89 u32 n_left_from, *from, *to_next, next_index;
102 struct rte_crypto_op ** cops_to_enq[n_qps];
103 u32 n_cop_qp[n_qps], * bi_to_enq[n_qps];
105 for (i = 0; i < n_qps; i++)
111 memset(n_cop_qp, 0, n_qps *
sizeof(
u32));
115 next_index = ESP_DECRYPT_NEXT_DROP;
117 while (n_left_from > 0)
123 while (n_left_from > 0 && n_left_to_next > 0)
125 u32 bi0, sa_index0 = ~0, seq, icv_size, iv_size;
129 struct rte_mbuf * mb0 = 0;
130 const int BLOCK_SIZE = 16;
134 struct rte_crypto_op * cop = 0;
146 seq = clib_host_to_net_u32(esp0->
seq);
162 ESP_DECRYPT_ERROR_REPLAY, 1);
177 ESP_DECRYPT_ERROR_UNSUPPORTED, 1);
199 sess = sa_sess->
sess;
204 ASSERT (cop->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
206 cops_to_enq[qp_index][0] = cop;
207 cops_to_enq[qp_index] += 1;
208 n_cop_qp[qp_index] += 1;
209 bi_to_enq[qp_index][0] = bi0;
210 bi_to_enq[qp_index] += 1;
212 rte_crypto_op_attach_sym_session(cop, sess);
221 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
227 if ((payload_len & (BLOCK_SIZE - 1)) || (payload_len <= 0))
230 payload_len, BLOCK_SIZE);
232 ESP_DECRYPT_ERROR_BAD_LEN, 1);
234 bi_to_enq[qp_index] -= 1;
235 cops_to_enq[qp_index] -= 1;
236 n_cop_qp[qp_index] -= 1;
243 struct rte_crypto_sym_op *sym_cop = (
struct rte_crypto_sym_op *)(cop + 1);
245 sym_cop->m_src = mb0;
246 sym_cop->cipher.data.offset =
sizeof (
esp_header_t) + iv_size;
247 sym_cop->cipher.data.length = payload_len;
249 u8 *iv = rte_pktmbuf_mtod_offset(mb0,
void*,
sizeof (
esp_header_t));
252 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
257 icb->
cnt = clib_host_to_net_u32(1);
258 sym_cop->cipher.iv.data = (
u8 *)icb;
259 sym_cop->cipher.iv.phys_addr = cop->phys_addr +
260 (uintptr_t)icb - (uintptr_t)cop;
261 sym_cop->cipher.iv.length = 16;
265 sym_cop->auth.aad.data = aad;
266 sym_cop->auth.aad.phys_addr = cop->phys_addr +
267 (uintptr_t)aad - (uintptr_t)cop;
271 sym_cop->auth.aad.length = 12;
275 sym_cop->auth.aad.length = 8;
278 sym_cop->auth.digest.data = rte_pktmbuf_mtod_offset(mb0,
void*,
279 rte_pktmbuf_pkt_len(mb0) - icv_size);
280 sym_cop->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(mb0,
281 rte_pktmbuf_pkt_len(mb0) - icv_size);
282 sym_cop->auth.digest.length = icv_size;
287 sym_cop->cipher.iv.data = rte_pktmbuf_mtod_offset(mb0,
void*,
289 sym_cop->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(mb0,
291 sym_cop->cipher.iv.length = iv_size;
296 u8* payload_end = rte_pktmbuf_mtod_offset(
301 sym_cop->auth.data.offset = 0;
302 sym_cop->auth.data.length =
sizeof(
esp_header_t) + iv_size
303 + payload_len +
sizeof(sa0->
seq_hi);
304 sym_cop->auth.digest.data = priv->
icv;
305 sym_cop->auth.digest.phys_addr = cop->phys_addr
306 + (uintptr_t) priv->
icv - (uintptr_t) cop;
307 sym_cop->auth.digest.length = icv_size;
311 sym_cop->auth.data.offset = 0;
313 iv_size + payload_len;
315 sym_cop->auth.digest.data = rte_pktmbuf_mtod_offset(mb0,
void*,
316 rte_pktmbuf_pkt_len(mb0) - icv_size);
317 sym_cop->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(mb0,
318 rte_pktmbuf_pkt_len(mb0) - icv_size);
319 sym_cop->auth.digest.length = icv_size;
334 ESP_DECRYPT_ERROR_RX_PKTS,
343 enq = rte_cryptodev_enqueue_burst(qpd->
dev_id, qpd->
qp_id,
344 qpd->
cops, n_cop_qp[i]);
353 ESP_DECRYPT_ERROR_ENQ_FAIL,
365 .name =
"dpdk-esp-decrypt",
366 .vector_size =
sizeof (
u32),
375 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 388 #define foreach_esp_decrypt_post_error \ 389 _(PKTS, "ESP post pkts") 392 #define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym, 399 #define _(sym,string) string, 416 u32 n_left_from, *from, *to_next = 0, next_index;
427 while (n_left_from > 0)
433 while (n_left_from > 0 && n_left_to_next > 0)
436 u32 bi0, next0, icv_size, iv_size;
441 u8 transport_ip6 = 0;
443 next0 = ESP_DECRYPT_NEXT_DROP;
465 seq = clib_host_to_net_u32(esp0->
seq);
494 ESP_DECRYPT_ERROR_NOT_IP, 1);
503 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
505 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
510 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
525 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
527 oh6->payload_length =
528 clib_host_to_net_u16 (
538 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
539 oh4->ip_version_and_header_length = 0x45;
540 oh4->fragment_id = 0;
541 oh4->flags_and_fragment_offset = 0;
543 oh4->length = clib_host_to_net_u16 (
560 to_next, n_left_to_next, bi0, next0);
565 ESP_DECRYPT_POST_ERROR_PKTS,
574 .name =
"dpdk-esp-decrypt-post",
575 .vector_size =
sizeof (
u32),
584 #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)
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.
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 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)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
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_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
static_always_inline int create_sym_sess(ipsec_sa_t *sa, crypto_sa_session_t *sa_sess, u8 is_outbound)
vlib_node_registration_t dpdk_esp_decrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_node)