26 #define foreach_esp_encrypt_next \ 27 _(DROP, "error-drop") \ 28 _(IP4_LOOKUP, "ip4-lookup") \ 29 _(IP6_LOOKUP, "ip6-lookup") \ 30 _(INTERFACE_OUTPUT, "interface-output") 32 #define _(v, s) ESP_ENCRYPT_NEXT_##v, 40 #define foreach_esp_encrypt_error \ 41 _(RX_PKTS, "ESP pkts received") \ 42 _(SEQ_CYCLED, "sequence number cycled") \ 43 _(ENQ_FAIL, "Enqueue failed (buffer full)") \ 44 _(NO_CRYPTODEV, "Cryptodev not configured") \ 45 _(UNSUPPORTED, "Cipher/Auth not supported") 50 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym, 57 #define _(sym,string) string, 80 s =
format (s,
"esp: spi %u seq %u crypto %U integrity %U",
92 u32 n_left_from, *from, *to_next, next_index;
106 ESP_ENCRYPT_ERROR_NO_CRYPTODEV,
114 struct rte_crypto_op **cops_to_enq[n_qps];
115 u32 n_cop_qp[n_qps], *bi_to_enq[n_qps];
117 for (i = 0; i < n_qps; i++)
123 memset (n_cop_qp, 0, n_qps *
sizeof (
u32));
127 next_index = ESP_ENCRYPT_NEXT_DROP;
129 while (n_left_from > 0)
135 while (n_left_from > 0 && n_left_to_next > 0)
141 ip4_and_esp_header_t *ih0, *oh0 = 0;
142 ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
143 struct rte_mbuf *mb0 = 0;
148 u8 transport_mode = 0;
149 const int BLOCK_SIZE = 16;
154 struct rte_crypto_op *cop = 0;
167 clib_warning (
"sequence number counter has cycled SPI %u",
170 ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
186 sess = sa_sess->
sess;
190 ASSERT (cop->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
192 cops_to_enq[qp_index][0] = cop;
193 cops_to_enq[qp_index] += 1;
194 n_cop_qp[qp_index] += 1;
195 bi_to_enq[qp_index][0] = bi0;
196 bi_to_enq[qp_index] += 1;
202 is_ipv6 = (ih0->ip4.ip_version_and_header_length & 0xF0) == 0x60;
207 adv = -
sizeof (ip4_and_esp_header_t);
209 adv = -
sizeof (ip6_and_esp_header_t);
238 ih6_0 = (ip6_and_esp_header_t *) ih0;
244 next_hdr_type = IP_PROTOCOL_IPV6;
245 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
246 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
250 next_hdr_type = ih6_0->ip6.protocol;
254 oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
255 oh6_0->ip6.hop_limit = 254;
256 oh6_0->esp.spi = clib_net_to_host_u32 (sa0->
spi);
257 oh6_0->esp.seq = clib_net_to_host_u32 (sa0->
seq);
266 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
267 oh0->ip4.tos = ih0->ip4.tos;
271 next_hdr_type = ih0->ip4.protocol;
275 oh0->ip4.ip_version_and_header_length = 0x45;
276 oh0->ip4.fragment_id = 0;
277 oh0->ip4.flags_and_fragment_offset = 0;
279 oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
280 oh0->esp.spi = clib_net_to_host_u32 (sa0->
spi);
281 oh0->esp.seq = clib_net_to_host_u32 (sa0->
seq);
290 next0 = ESP_ENCRYPT_NEXT_IP4_LOOKUP;
295 oh6_0->ip6.src_address.as_u64[0] =
297 oh6_0->ip6.src_address.as_u64[1] =
299 oh6_0->ip6.dst_address.as_u64[0] =
301 oh6_0->ip6.dst_address.as_u64[1] =
305 next0 = ESP_ENCRYPT_NEXT_IP6_LOOKUP;
310 next0 = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
317 int blocks = 1 + (orig_sz + 1) / BLOCK_SIZE;
320 u8 pad_bytes = BLOCK_SIZE * blocks - 2 - orig_sz;
324 for (i = 0; i < pad_bytes; ++
i)
337 struct rte_crypto_sym_op *sym_cop;
338 sym_cop = (
struct rte_crypto_sym_op *) (cop + 1);
347 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->
current_data;
349 rte_crypto_op_attach_sym_session (cop, sess);
351 sym_cop->m_src = mb0;
355 icb->
iv[0] = sa0->
seq;
358 if (sa0->
crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128)
360 icb->
cnt = clib_host_to_net_u32 (1);
363 sym_cop->cipher.data.offset =
365 sym_cop->cipher.data.length = BLOCK_SIZE * blocks;
366 sym_cop->cipher.iv.length = 16;
370 sym_cop->cipher.data.offset =
372 sym_cop->cipher.data.length = BLOCK_SIZE * blocks + iv_size;
373 sym_cop->cipher.iv.length = iv_size;
376 sym_cop->cipher.iv.data = (
u8 *) icb;
377 sym_cop->cipher.
iv.phys_addr = cop->phys_addr + (uintptr_t) icb
389 sym_cop->auth.aad.data = aad;
390 sym_cop->auth.aad.phys_addr = cop->phys_addr +
391 (uintptr_t) aad - (uintptr_t) cop;
396 sym_cop->auth.aad.length = 12;
400 sym_cop->auth.aad.length = 8;
405 sym_cop->auth.data.offset = ip_hdr_size;
414 sym_cop->auth.data.length +=
sizeof (sa0->
seq_hi);
420 sym_cop->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset (mb0,
425 sym_cop->auth.digest.length =
431 oh6_0->ip6.payload_length =
459 ESP_ENCRYPT_ERROR_RX_PKTS,
468 enq = rte_cryptodev_enqueue_burst(qpd->
dev_id, qpd->
qp_id,
469 qpd->
cops, n_cop_qp[i]);
478 ESP_ENCRYPT_ERROR_ENQ_FAIL,
495 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",}
502 #define foreach_esp_encrypt_post_error \ 503 _(PKTS, "ESP post pkts") 506 #define _(sym,str) ESP_ENCRYPT_POST_ERROR_##sym, 513 #define _(sym,string) string, 531 u32 n_left_from, *from, *to_next = 0, next_index;
538 while (n_left_from > 0)
544 while (n_left_from > 0 && n_left_to_next > 0)
562 to_next, n_left_to_next, bi0,
569 ESP_ENCRYPT_POST_ERROR_PKTS,
578 "dpdk-esp-encrypt-post",.vector_size =
sizeof (
u32),.format_trace =
584 #define _(s,n) [ESP_ENCRYPT_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.
sll srl srl sll sra u16x4 i
#define rte_mbuf_from_vlib_buffer(x)
ip46_address_t tunnel_src_addr
static uword dpdk_esp_encrypt_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
vlib_node_registration_t dpdk_esp_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_encrypt_node)
ipsec_integ_alg_t integ_alg
static u8 * format_esp_encrypt_post_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 u8 * format_esp_encrypt_trace(u8 *s, va_list *args)
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define foreach_esp_encrypt_post_error
#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)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
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)
#define foreach_esp_encrypt_error
struct rte_crypto_op * cops[VLIB_FRAME_SIZE]
static char * esp_encrypt_post_error_strings[]
#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
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
#define foreach_esp_encrypt_next
#define VLIB_BUFFER_IS_TRACED
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.
#define VLIB_NODE_FLAG_IS_OUTPUT
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_registration_t dpdk_esp_encrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp_encrypt_post_node)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static char * esp_encrypt_error_strings[]
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,...)
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)
static int esp_seq_advance(ipsec_sa_t *sa)