26 #define foreach_esp_decrypt_next \ 27 _(DROP, "error-drop") \ 28 _(IP4_INPUT, "ip4-input") \ 29 _(IP6_INPUT, "ip6-input") 31 #define _(v, s) ESP_DECRYPT_NEXT_##v, 38 #define foreach_esp_decrypt_error \ 39 _(RX_PKTS, "ESP pkts received") \ 40 _(DECRYPTION_FAILED, "ESP decryption failed") \ 41 _(REPLAY, "SA replayed packet") \ 42 _(NOT_IP, "Not IP packet (dropped)") \ 43 _(ENQ_FAIL, "Enqueue failed (buffer full)") \ 44 _(NO_CRYPTODEV, "Cryptodev not configured") \ 45 _(BAD_LEN, "Invalid ciphertext length") \ 46 _(UNSUPPORTED, "Cipher/Auth not supported") 50 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 57 #define _(sym,string) string, 76 s =
format (s,
"esp: crypto %U integrity %U",
87 u32 n_left_from, *from, *to_next, next_index;
100 ESP_DECRYPT_ERROR_NO_CRYPTODEV, n_left_from);
107 struct rte_crypto_op ** cops_to_enq[n_qps];
108 u32 n_cop_qp[n_qps], * bi_to_enq[n_qps];
110 for (i = 0; i < n_qps; i++)
116 memset(n_cop_qp, 0, n_qps *
sizeof(
u32));
120 next_index = ESP_DECRYPT_NEXT_DROP;
122 while (n_left_from > 0)
128 while (n_left_from > 0 && n_left_to_next > 0)
130 u32 bi0, sa_index0 = ~0, seq, icv_size, iv_size;
134 struct rte_mbuf * mb0 = 0;
135 const int BLOCK_SIZE = 16;
139 struct rte_crypto_op * cop = 0;
151 seq = clib_host_to_net_u32(esp0->
seq);
167 ESP_DECRYPT_ERROR_REPLAY, 1);
180 ESP_DECRYPT_ERROR_UNSUPPORTED, 1);
195 sess = sa_sess->
sess;
200 ASSERT (cop->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
202 cops_to_enq[qp_index][0] = cop;
203 cops_to_enq[qp_index] += 1;
204 n_cop_qp[qp_index] += 1;
205 bi_to_enq[qp_index][0] = bi0;
206 bi_to_enq[qp_index] += 1;
208 rte_crypto_op_attach_sym_session(cop, sess);
217 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
223 if ((payload_len & (BLOCK_SIZE - 1)) || (payload_len <= 0))
226 payload_len, BLOCK_SIZE);
228 ESP_DECRYPT_ERROR_BAD_LEN, 1);
230 bi_to_enq[qp_index] -= 1;
231 cops_to_enq[qp_index] -= 1;
232 n_cop_qp[qp_index] -= 1;
239 struct rte_crypto_sym_op *sym_cop = (
struct rte_crypto_sym_op *)(cop + 1);
241 sym_cop->m_src = mb0;
242 sym_cop->cipher.data.offset =
sizeof (
esp_header_t) + iv_size;
243 sym_cop->cipher.data.length = payload_len;
245 u8 *iv = rte_pktmbuf_mtod_offset(mb0,
void*,
sizeof (
esp_header_t));
248 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
253 icb->
cnt = clib_host_to_net_u32(1);
254 sym_cop->cipher.iv.data = (
u8 *)icb;
255 sym_cop->cipher.iv.phys_addr = cop->phys_addr +
256 (uintptr_t)icb - (uintptr_t)cop;
257 sym_cop->cipher.iv.length = 16;
261 sym_cop->auth.aad.data = aad;
262 sym_cop->auth.aad.phys_addr = cop->phys_addr +
263 (uintptr_t)aad - (uintptr_t)cop;
267 sym_cop->auth.aad.length = 12;
271 sym_cop->auth.aad.length = 8;
274 sym_cop->auth.digest.data = rte_pktmbuf_mtod_offset(mb0,
void*,
275 rte_pktmbuf_pkt_len(mb0) - icv_size);
276 sym_cop->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(mb0,
277 rte_pktmbuf_pkt_len(mb0) - icv_size);
278 sym_cop->auth.digest.length = icv_size;
283 sym_cop->cipher.iv.data = rte_pktmbuf_mtod_offset(mb0,
void*,
285 sym_cop->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(mb0,
287 sym_cop->cipher.iv.length = iv_size;
292 u8* payload_end = rte_pktmbuf_mtod_offset(
297 sym_cop->auth.data.offset = 0;
298 sym_cop->auth.data.length =
sizeof(
esp_header_t) + iv_size
299 + payload_len +
sizeof(sa0->
seq_hi);
300 sym_cop->auth.digest.data = priv->
icv;
301 sym_cop->auth.digest.phys_addr = cop->phys_addr
302 + (uintptr_t) priv->
icv - (uintptr_t) cop;
303 sym_cop->auth.digest.length = icv_size;
307 sym_cop->auth.data.offset = 0;
309 iv_size + payload_len;
311 sym_cop->auth.digest.data = rte_pktmbuf_mtod_offset(mb0,
void*,
312 rte_pktmbuf_pkt_len(mb0) - icv_size);
313 sym_cop->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(mb0,
314 rte_pktmbuf_pkt_len(mb0) - icv_size);
315 sym_cop->auth.digest.length = icv_size;
330 ESP_DECRYPT_ERROR_RX_PKTS,
339 enq = rte_cryptodev_enqueue_burst(qpd->
dev_id, qpd->
qp_id,
340 qpd->
cops, n_cop_qp[i]);
349 ESP_DECRYPT_ERROR_ENQ_FAIL,
360 .name =
"dpdk-esp-decrypt",
361 .vector_size =
sizeof (
u32),
370 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 382 #define foreach_esp_decrypt_post_error \ 383 _(PKTS, "ESP post pkts") 386 #define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym, 393 #define _(sym,string) string, 410 u32 n_left_from, *from, *to_next = 0, next_index;
421 while (n_left_from > 0)
427 while (n_left_from > 0 && n_left_to_next > 0)
430 u32 bi0, next0, icv_size, iv_size;
435 u8 transport_ip6 = 0;
437 next0 = ESP_DECRYPT_NEXT_DROP;
459 seq = clib_host_to_net_u32(esp0->
seq);
488 ESP_DECRYPT_ERROR_NOT_IP, 1);
497 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
499 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
504 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
519 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
521 oh6->payload_length =
522 clib_host_to_net_u16 (
532 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
533 oh4->ip_version_and_header_length = 0x45;
534 oh4->fragment_id = 0;
535 oh4->flags_and_fragment_offset = 0;
537 oh4->length = clib_host_to_net_u16 (
554 to_next, n_left_to_next, bi0, next0);
559 ESP_DECRYPT_POST_ERROR_PKTS,
567 .name =
"dpdk-esp-decrypt-post",
568 .vector_size =
sizeof (
u32),
577 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
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.
#define vec_foreach_index(var, v)
Iterate over vector indices.
vlib_node_registration_t dpdk_esp_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_post_node)
sll srl srl sll sra u16x4 i
#define rte_mbuf_from_vlib_buffer(x)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static int esp_replay_check_esn(ipsec_sa_t *sa, u32 seq)
ipsec_integ_alg_t integ_alg
ipsec_crypto_alg_t crypto_alg
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.
#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)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define foreach_esp_decrypt_error
static int esp_replay_check(ipsec_sa_t *sa, u32 seq)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_warning(format, args...)
dpdk_esp_integ_alg_t * esp_integ_algs
static_always_inline int create_sym_sess(ipsec_sa_t *sa, crypto_sa_session_t *sa_sess, u8 is_outbound)
dpdk_esp_crypto_alg_t * esp_crypto_algs
dpdk_crypto_main_t dpdk_crypto_main
#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_alloc_cops()
uword os_get_cpu_number(void)
static u8 * format_esp_decrypt_post_trace(u8 *s, va_list *args)
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)
#define foreach_esp_decrypt_post_error
dpdk_esp_main_t dpdk_esp_main
#define clib_memcpy(a, b, c)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
crypto_worker_main_t * workers_main
static uword dpdk_esp_decrypt_post_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define VLIB_BUFFER_IS_TRACED
crypto_qp_data_t * qp_data
crypto_sa_session_t * sa_sess_d[2]
static void esp_replay_advance(ipsec_sa_t *sa, u32 seq)
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)
vlib_node_registration_t dpdk_esp_decrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_decrypt_node)
#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 void esp_replay_advance_esn(ipsec_sa_t *sa, u32 seq)
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
ipsec_crypto_alg_t crypto_alg
#define VLIB_REGISTER_NODE(x,...)
#define foreach_esp_decrypt_next
static char * esp_decrypt_error_strings[]
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
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 uword dpdk_esp_decrypt_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
static char * esp_decrypt_post_error_strings[]