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") \ 47 _(UNSUPPORTED, "Cipher/Auth not supported") 52 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym, 59 #define _(sym,string) string, 82 s =
format (s,
"esp: spi %u seq %u crypto %U integrity %U",
94 u32 n_left_from, *from, *to_next, next_index;
108 ESP_ENCRYPT_ERROR_NO_CRYPTODEV,
116 struct rte_crypto_op **cops_to_enq[n_qps];
117 u32 n_cop_qp[n_qps], *bi_to_enq[n_qps];
119 for (i = 0; i < n_qps; i++)
125 memset (n_cop_qp, 0, n_qps *
sizeof (
u32));
129 next_index = ESP_ENCRYPT_NEXT_DROP;
131 while (n_left_from > 0)
137 while (n_left_from > 0 && n_left_to_next > 0)
143 ip4_and_esp_header_t *ih0, *oh0 = 0;
144 ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
145 struct rte_mbuf *mb0 = 0;
150 u8 transport_mode = 0;
151 const int BLOCK_SIZE = 16;
156 struct rte_crypto_op *cop = 0;
169 clib_warning (
"sequence number counter has cycled SPI %u",
172 ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
197 sess = sa_sess->
sess;
201 ASSERT (cop->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
203 cops_to_enq[qp_index][0] = cop;
204 cops_to_enq[qp_index] += 1;
205 n_cop_qp[qp_index] += 1;
206 bi_to_enq[qp_index][0] = bi0;
207 bi_to_enq[qp_index] += 1;
213 is_ipv6 = (ih0->ip4.ip_version_and_header_length & 0xF0) == 0x60;
218 adv = -
sizeof (ip4_and_esp_header_t);
220 adv = -
sizeof (ip6_and_esp_header_t);
249 ih6_0 = (ip6_and_esp_header_t *) ih0;
255 next_hdr_type = IP_PROTOCOL_IPV6;
256 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
257 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
261 next_hdr_type = ih6_0->ip6.protocol;
265 oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
266 oh6_0->ip6.hop_limit = 254;
267 oh6_0->esp.spi = clib_net_to_host_u32 (sa0->
spi);
268 oh6_0->esp.seq = clib_net_to_host_u32 (sa0->
seq);
277 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
278 oh0->ip4.tos = ih0->ip4.tos;
282 next_hdr_type = ih0->ip4.protocol;
286 oh0->ip4.ip_version_and_header_length = 0x45;
287 oh0->ip4.fragment_id = 0;
288 oh0->ip4.flags_and_fragment_offset = 0;
290 oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
291 oh0->esp.spi = clib_net_to_host_u32 (sa0->
spi);
292 oh0->esp.seq = clib_net_to_host_u32 (sa0->
seq);
301 next0 = ESP_ENCRYPT_NEXT_IP4_LOOKUP;
306 oh6_0->ip6.src_address.as_u64[0] =
308 oh6_0->ip6.src_address.as_u64[1] =
310 oh6_0->ip6.dst_address.as_u64[0] =
312 oh6_0->ip6.dst_address.as_u64[1] =
316 next0 = ESP_ENCRYPT_NEXT_IP6_LOOKUP;
321 next0 = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
328 int blocks = 1 + (orig_sz + 1) / BLOCK_SIZE;
331 u8 pad_bytes = BLOCK_SIZE * blocks - 2 - orig_sz;
335 for (i = 0; i < pad_bytes; ++
i)
348 struct rte_crypto_sym_op *sym_cop;
349 sym_cop = (
struct rte_crypto_sym_op *) (cop + 1);
358 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
360 rte_crypto_op_attach_sym_session (cop, sess);
362 sym_cop->m_src = mb0;
366 icb->
iv[0] = sa0->
seq;
369 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
371 icb->
cnt = clib_host_to_net_u32 (1);
374 sym_cop->cipher.data.offset =
376 sym_cop->cipher.data.length = BLOCK_SIZE * blocks;
377 sym_cop->cipher.iv.length = 16;
381 sym_cop->cipher.data.offset =
383 sym_cop->cipher.data.length = BLOCK_SIZE * blocks + iv_size;
384 sym_cop->cipher.iv.length = iv_size;
387 sym_cop->cipher.iv.data = (
u8 *) icb;
388 sym_cop->cipher.
iv.phys_addr = cop->phys_addr + (uintptr_t) icb
400 sym_cop->auth.aad.data = aad;
401 sym_cop->auth.aad.phys_addr = cop->phys_addr +
402 (uintptr_t) aad - (uintptr_t) cop;
407 sym_cop->auth.aad.length = 12;
411 sym_cop->auth.aad.length = 8;
416 sym_cop->auth.data.offset = ip_hdr_size;
425 sym_cop->auth.data.length +=
sizeof (sa0->
seq_hi);
431 sym_cop->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset (mb0,
436 sym_cop->auth.digest.length =
442 oh6_0->ip6.payload_length =
470 ESP_ENCRYPT_ERROR_RX_PKTS,
479 enq = rte_cryptodev_enqueue_burst(qpd->
dev_id, qpd->
qp_id,
480 qpd->
cops, n_cop_qp[i]);
489 ESP_ENCRYPT_ERROR_ENQ_FAIL,
506 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",}
513 #define foreach_esp_encrypt_post_error \ 514 _(PKTS, "ESP post pkts") 517 #define _(sym,str) ESP_ENCRYPT_POST_ERROR_##sym, 524 #define _(sym,string) string, 542 u32 n_left_from, *from, *to_next = 0, next_index;
549 while (n_left_from > 0)
555 while (n_left_from > 0 && n_left_to_next > 0)
573 to_next, n_left_to_next, bi0,
580 ESP_ENCRYPT_POST_ERROR_PKTS,
589 "dpdk-esp-encrypt-post",.vector_size =
sizeof (
u32),.format_trace =
595 #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)
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
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.
uword os_get_cpu_number(void)
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
#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[]
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 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_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)
static_always_inline int create_sym_sess(ipsec_sa_t *sa, crypto_sa_session_t *sa_sess, u8 is_outbound)