28 #define foreach_esp_encrypt_next \ 29 _(DROP, "error-drop") \ 30 _(IP4_LOOKUP, "ip4-lookup") \ 31 _(IP6_LOOKUP, "ip6-lookup") \ 32 _(INTERFACE_OUTPUT, "interface-output") 34 #define _(v, s) ESP_ENCRYPT_NEXT_##v, 42 #define foreach_esp_encrypt_error \ 43 _(RX_PKTS, "ESP pkts received") \ 44 _(SEQ_CYCLED, "sequence number cycled") \ 45 _(ENQ_FAIL, "Enqueue failed (buffer full)") \ 46 _(NO_CRYPTODEV, "Cryptodev not configured") 51 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym, 58 #define _(sym,string) string, 81 s =
format (s,
"esp: spi %u seq %u crypto %U integrity %U",
93 u32 n_left_from, *from, *to_next, next_index;
106 struct rte_crypto_op **cops_to_enq[n_qps];
107 u32 n_cop_qp[n_qps], *bi_to_enq[n_qps];
109 for (i = 0; i < n_qps; i++)
115 memset (n_cop_qp, 0, n_qps *
sizeof (
u32));
119 next_index = ESP_ENCRYPT_NEXT_DROP;
121 while (n_left_from > 0)
127 while (n_left_from > 0 && n_left_to_next > 0)
133 ip4_and_esp_header_t *ih0, *oh0 = 0;
134 ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
135 struct rte_mbuf *mb0 = 0;
140 u8 transport_mode = 0;
141 const int BLOCK_SIZE = 16;
147 struct rte_crypto_op *cop = 0;
160 clib_warning (
"sequence number counter has cycled SPI %u",
163 ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
188 sess = sa_sess->
sess;
192 ASSERT (cop->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
194 cops_to_enq[qp_index][0] = cop;
195 cops_to_enq[qp_index] += 1;
196 n_cop_qp[qp_index] += 1;
197 bi_to_enq[qp_index][0] = bi0;
198 bi_to_enq[qp_index] += 1;
202 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
209 is_ipv6 = (ih0->ip4.ip_version_and_header_length & 0xF0) == 0x60;
214 adv = -
sizeof (ip4_and_esp_header_t);
216 adv = -
sizeof (ip6_and_esp_header_t);
245 ih6_0 = (ip6_and_esp_header_t *) ih0;
251 next_hdr_type = IP_PROTOCOL_IPV6;
252 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
253 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
257 next_hdr_type = ih6_0->ip6.protocol;
261 oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
262 oh6_0->ip6.hop_limit = 254;
263 oh6_0->esp.spi = clib_net_to_host_u32 (sa0->
spi);
264 oh6_0->esp.seq = clib_net_to_host_u32 (sa0->
seq);
273 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
274 oh0->ip4.tos = ih0->ip4.tos;
278 next_hdr_type = ih0->ip4.protocol;
282 oh0->ip4.ip_version_and_header_length = 0x45;
283 oh0->ip4.fragment_id = 0;
284 oh0->ip4.flags_and_fragment_offset = 0;
286 oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
287 oh0->esp.spi = clib_net_to_host_u32 (sa0->
spi);
288 oh0->esp.seq = clib_net_to_host_u32 (sa0->
seq);
298 next0 = ESP_ENCRYPT_NEXT_IP4_LOOKUP;
303 oh6_0->ip6.src_address.as_u64[0] =
305 oh6_0->ip6.src_address.as_u64[1] =
307 oh6_0->ip6.dst_address.as_u64[0] =
309 oh6_0->ip6.dst_address.as_u64[1] =
313 next0 = ESP_ENCRYPT_NEXT_IP6_LOOKUP;
318 next0 = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
322 int blocks = 1 + (orig_sz + 1) / BLOCK_SIZE;
325 u8 pad_bytes = BLOCK_SIZE * blocks - 2 - orig_sz;
329 for (i = 0; i < pad_bytes; ++
i)
341 struct rte_crypto_sym_op *sym_cop;
342 sym_cop = (
struct rte_crypto_sym_op *) (cop + 1);
351 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
357 u8 is_aead = sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128;
358 u32 cipher_off, cipher_len;
359 u32 auth_off = 0, auth_len = 0, aad_size = 0;
366 digest_paddr = mb0->buf_physaddr + (digest - (
u8 *) mb0->buf_addr);
373 esp_iv[0] = sa0->
seq;
376 cipher_off = ip_hdr_size +
sizeof (
esp_header_t) + iv_size;
377 cipher_len = BLOCK_SIZE * blocks;
393 cipher_len = BLOCK_SIZE * blocks + iv_size;
395 auth_off = ip_hdr_size;
401 auth_len +=
sizeof (sa0->
seq_hi);
406 cipher_off, cipher_len, (
u8 *) icb, iv_size,
407 auth_off, auth_len, aad, aad_size,
408 digest, digest_paddr, trunc_size);
412 oh6_0->ip6.payload_length =
440 ESP_ENCRYPT_ERROR_RX_PKTS,
452 enq = rte_cryptodev_enqueue_burst(qpd->
dev_id, qpd->
qp_id,
453 qpd->
cops, n_cop_qp[i]);
462 ESP_ENCRYPT_ERROR_ENQ_FAIL,
474 .name =
"dpdk-esp-encrypt",
476 .vector_size =
sizeof (
u32),
483 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",
492 #define foreach_esp_encrypt_post_error \ 493 _(PKTS, "ESP post pkts") 496 #define _(sym,str) ESP_ENCRYPT_POST_ERROR_##sym, 503 #define _(sym,string) string, 521 u32 n_left_from, *from, *to_next = 0, next_index;
528 while (n_left_from > 0)
534 while (n_left_from > 0 && n_left_to_next > 0)
552 to_next, n_left_to_next, bi0,
559 ESP_ENCRYPT_POST_ERROR_PKTS,
568 .name =
"dpdk-esp-encrypt-post",
569 .vector_size =
sizeof (
u32),
577 #define _(s,n) [ESP_ENCRYPT_NEXT_##s] = n,
#define vec_foreach_index(var, v)
Iterate over vector indices.
sll srl srl sll sra u16x4 i
ip46_address_t tunnel_src_addr
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_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
static u8 * format_esp_encrypt_trace(u8 *s, va_list *args)
struct _vlib_node_registration vlib_node_registration_t
ipsec_integ_alg_t integ_alg
ipsec_crypto_alg_t crypto_alg
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)
dpdk_crypto_main_t dpdk_crypto_main
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
vlib_node_registration_t dpdk_esp_encrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_encrypt_post_node)
static_always_inline void crypto_alloc_cops()
#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.
vlib_node_registration_t dpdk_esp_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_encrypt_node)
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
#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.
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)
ip46_address_t tunnel_dst_addr
static_always_inline uword vlib_get_thread_index(void)
#define foreach_esp_encrypt_error
#define clib_warning(format, args...)
#define VLIB_BUFFER_IS_TRACED
#define foreach_esp_encrypt_post_error
#define clib_memcpy(a, b, c)
static char * esp_encrypt_error_strings[]
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 VLIB_NODE_FLAG_IS_OUTPUT
static char * esp_encrypt_post_error_strings[]
#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 uword dpdk_esp_encrypt_post_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
ipsec_crypto_alg_t crypto_alg
#define VLIB_REGISTER_NODE(x,...)
static uword dpdk_esp_encrypt_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define foreach_esp_encrypt_next
static int esp_seq_advance(ipsec_sa_t *sa)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static u8 * format_esp_encrypt_post_trace(u8 *s, va_list *args)
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)