30 #define foreach_esp_encrypt_next \ 31 _(DROP, "error-drop") \ 32 _(IP4_LOOKUP, "ip4-lookup") \ 33 _(IP6_LOOKUP, "ip6-lookup") \ 34 _(INTERFACE_OUTPUT, "interface-output") 36 #define _(v, s) ESP_ENCRYPT_NEXT_##v, 44 #define foreach_esp_encrypt_error \ 45 _(RX_PKTS, "ESP pkts received") \ 46 _(SEQ_CYCLED, "Sequence number cycled") \ 47 _(ENQ_FAIL, "Enqueue failed to crypto device") \ 48 _(DISCARD, "Not enough crypto operations, discarding frame") \ 49 _(SESSION, "Failed to get crypto session") \ 50 _(NOSUP, "Cipher/Auth not supported") 55 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym, 62 #define _(sym,string) string, 87 s =
format (s,
"cipher %U auth %U\n",
115 u32 n_left_from, *from, *to_next, next_index, thread_index;
122 struct rte_cryptodev_sym_session *session = 0;
123 u32 ret, last_sa_index = ~0;
124 u8 numa = rte_socket_id ();
128 struct rte_crypto_op **ops = cwm->
ops;
139 ESP_ENCRYPT_ERROR_DISCARD, 1);
142 ESP_ENCRYPT_ERROR_DISCARD, 1);
147 next_index = ESP_ENCRYPT_NEXT_DROP;
149 while (n_left_from > 0)
155 while (n_left_from > 0 && n_left_to_next > 0)
161 ip4_and_esp_header_t *ih0, *oh0 = 0;
162 ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
163 ip4_and_udp_and_esp_header_t *ouh0 = 0;
171 u16 udp_encap_adv = 0;
172 struct rte_mbuf *mb0 = 0;
173 struct rte_crypto_op *op;
193 ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
201 sizeof (op[0]) +
sizeof (op[0].sym[0]) +
sizeof (priv[0]);
215 if (sa_index0 != last_sa_index)
223 is_aead = (cipher_alg->
type == RTE_CRYPTO_SYM_XFORM_AEAD);
226 auth_alg = cipher_alg;
237 ESP_ENCRYPT_ERROR_NOSUP, 1);
241 ESP_ENCRYPT_ERROR_NOSUP, 1);
256 ESP_ENCRYPT_ERROR_SESSION,
261 ESP_ENCRYPT_ERROR_SESSION,
269 last_sa_index = sa_index0;
274 clib_warning (
"sequence number counter has cycled SPI %u",
279 ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
283 ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
306 iv_size = cipher_alg->
iv_len;
307 trunc_size = auth_alg->trunc_size;
310 if (ipsec_sa_is_set_UDP_ENCAP (sa0) && !is_ip6)
313 if (ipsec_sa_is_set_IS_TUNNEL (sa0))
316 if (!is_ip6 && !ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
319 priv->
next = DPDK_CRYPTO_INPUT_NEXT_IP4_LOOKUP;
325 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
332 oh0->ip4.checksum_data_64[0] =
333 clib_host_to_net_u64 (0x45ULL << 56);
338 oh0->ip4.checksum_data_32[2] =
339 clib_host_to_net_u32 (0xfe320000);
341 oh0->ip4.src_address.as_u32 =
343 oh0->ip4.dst_address.as_u32 =
346 if (ipsec_sa_is_set_UDP_ENCAP (sa0))
348 oh0->ip4.protocol = IP_PROTOCOL_UDP;
353 esp0->
spi = clib_host_to_net_u32 (sa0->
spi);
354 esp0->
seq = clib_host_to_net_u32 (sa0->
seq);
356 else if (is_ip6 && ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
360 priv->
next = DPDK_CRYPTO_INPUT_NEXT_IP6_LOOKUP;
365 ih6_0 = (ip6_and_esp_header_t *) ih0;
368 next_hdr_type = IP_PROTOCOL_IPV6;
370 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
371 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
373 oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
374 oh6_0->ip6.hop_limit = 254;
375 oh6_0->ip6.src_address.as_u64[0] =
377 oh6_0->ip6.src_address.as_u64[1] =
379 oh6_0->ip6.dst_address.as_u64[0] =
381 oh6_0->ip6.dst_address.as_u64[1] =
384 oh6_0->esp.
spi = clib_host_to_net_u32 (sa0->
spi);
385 oh6_0->esp.seq = clib_host_to_net_u32 (sa0->
seq);
392 ESP_ENCRYPT_ERROR_NOSUP, 1);
396 ESP_ENCRYPT_ERROR_NOSUP, 1);
406 priv->
next = DPDK_CRYPTO_INPUT_NEXT_INTERFACE_OUTPUT;
407 rewrite_len =
vnet_buffer (b0)->ip.save_rewrite_length;
410 u8 *
src = ((
u8 *) ih0) - rewrite_len;
417 ih6_0 = (ip6_and_esp_header_t *) ih0;
418 next_hdr_type = ih6_0->ip6.protocol;
419 memmove (dst, src, rewrite_len +
sizeof (
ip6_header_t));
420 oh6_0 = (ip6_and_esp_header_t *) oh0;
421 oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
428 next_hdr_type = ih0->ip4.protocol;
429 memmove (dst, src, rewrite_len + ip_size);
430 oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
432 if (ipsec_sa_is_set_UDP_ENCAP (sa0))
434 oh0->ip4.protocol = IP_PROTOCOL_UDP;
436 (((
u8 *) oh0) + ip_size + udp_encap_adv);
440 oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
444 esp0->
spi = clib_host_to_net_u32 (sa0->
spi);
445 esp0->
seq = clib_host_to_net_u32 (sa0->
seq);
448 if (ipsec_sa_is_set_UDP_ENCAP (sa0) && ouh0)
450 ouh0->udp.src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
451 ouh0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
452 ouh0->udp.checksum = 0;
456 u16 pad_payload_len = ((orig_sz + 2) + mask) & ~mask;
457 u8 pad_bytes = pad_payload_len - 2 - orig_sz;
473 oh6_0->ip6.payload_length =
474 clib_host_to_net_u16 (len - rewrite_len);
481 if (ipsec_sa_is_set_UDP_ENCAP (sa0) && ouh0)
484 clib_host_to_net_u16 (clib_net_to_host_u16
490 b0->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
495 mb0->data_off = ((
void *) esp0) - mb0->buf_addr;
497 u32 cipher_off, cipher_len, auth_len = 0;
502 mb0->buf_physaddr + digest - ((
u8 *) mb0->buf_addr);
504 if (!is_aead && cipher_alg->
alg == RTE_CRYPTO_CIPHER_AES_CBC)
507 cipher_len = iv_size + pad_payload_len;
511 u32 *esp_iv = (
u32 *) (esp0 + 1);
512 esp_iv[0] = sa0->
seq;
516 cipher_len = pad_payload_len;
522 aad[0] = clib_host_to_net_u32 (sa0->
spi);
523 aad[1] = clib_host_to_net_u32 (sa0->
seq);
527 aad[2] = clib_host_to_net_u32 (sa0->
seq_hi);
535 if (ipsec_sa_is_set_USE_ESN (sa0))
537 u32 *_digest = (
u32 *) digest;
538 _digest[0] = clib_host_to_net_u32 (sa0->
seq_hi);
544 0, auth_len, (
u8 *) aad, digest, digest_paddr);
554 if (!ipsec_sa_is_set_IS_TUNNEL (sa0))
564 ESP_ENCRYPT_ERROR_RX_PKTS,
568 ESP_ENCRYPT_ERROR_ENQ_FAIL, numa, 1 );
573 ESP_ENCRYPT_ERROR_RX_PKTS,
577 ESP_ENCRYPT_ERROR_ENQ_FAIL, numa, 1 );
594 .name =
"dpdk-esp4-encrypt",
596 .vector_size =
sizeof (
u32),
603 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",
617 .name =
"dpdk-esp6-encrypt",
619 .vector_size =
sizeof (
u32),
626 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",
640 .name =
"dpdk-esp4-encrypt-tun",
642 .vector_size =
sizeof (
u32),
649 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",
655 .arc_name =
"ip4-output",
656 .node_name =
"dpdk-esp4-encrypt-tun",
670 .name =
"dpdk-esp6-encrypt-tun",
672 .vector_size =
sizeof (
u32),
679 [ESP_ENCRYPT_NEXT_DROP] =
"error-drop",
685 .arc_name =
"ip6-output",
686 .node_name =
"dpdk-esp6-encrypt-tun",
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_always_inline void crypto_op_setup(u8 is_aead, struct rte_mbuf *mb0, struct rte_crypto_op *op, void *session, u32 cipher_off, u32 cipher_len, u32 auth_off, u32 auth_len, u8 *aad, u8 *digest, u64 digest_paddr)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer's data.
ip46_address_t tunnel_src_addr
vlib_node_registration_t dpdk_esp4_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_encrypt_node)
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
#define clib_memcpy_fast(a, b, c)
static_always_inline i32 crypto_alloc_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
ipsec_integ_alg_t integ_alg
u16 current_length
Nbytes between current data and the end of this buffer.
static u8 * format_esp_encrypt_trace(u8 *s, va_list *args)
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
ipsec_integ_alg_t integ_alg
ipsec_crypto_alg_t crypto_alg
#define VLIB_NODE_FN(node)
static int esp_seq_advance(ipsec_sa_t *sa)
static_always_inline clib_error_t * crypto_get_session(struct rte_cryptodev_sym_session **session, u32 sa_idx, crypto_resource_t *res, crypto_worker_main_t *cwm, u8 is_outbound)
static_always_inline void crypto_free_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
dpdk_crypto_main_t dpdk_crypto_main
static_always_inline void crypto_enqueue_ops(vlib_main_t *vm, crypto_worker_main_t *cwm, u32 node_index, u32 error, u8 numa, u8 encrypt)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static const u8 pad_data[]
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vlib_node_registration_t dpdk_esp6_encrypt_tun_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_encrypt_tun_node)
crypto_alg_t * cipher_algs
#define rte_mbuf_from_vlib_buffer(x)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#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 VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t dpdk_esp4_encrypt_tun_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_encrypt_tun_node)
static_always_inline uword vlib_get_thread_index(void)
#define CLIB_PREFETCH(addr, size, type)
#define foreach_esp_encrypt_error
vlib_node_registration_t dpdk_esp6_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_encrypt_node)
#define clib_warning(format, args...)
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.
u8 * format_esp_header(u8 *s, va_list *args)
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
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.
#define VNET_FEATURES(...)
crypto_resource_t * resource
static uword is_pow2(uword x)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
static uword dpdk_esp_encrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6, int is_tun)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
struct rte_crypto_op ** ops
struct clib_bihash_value offset
template key/value backing page structure
enum rte_crypto_sym_xform_type type
static_always_inline u16 get_resource(crypto_worker_main_t *cwm, ipsec_sa_t *sa)
ipsec_crypto_alg_t crypto_alg
#define VLIB_NODE_FLAG_IS_OUTPUT
#define foreach_esp_encrypt_next
static void * vlib_buffer_put_uninit(vlib_buffer_t *b, u16 size)
Append uninitialized data to buffer.
static int ip4_header_bytes(const ip4_header_t *i)
VNET_FEATURE_INIT(esp4_encrypt_tun_feat_node, static)
#define CLIB_CACHE_LINE_BYTES
struct rte_crypto_op * ops[VLIB_FRAME_SIZE]
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 dpdk_op_priv_t * crypto_op_get_priv(struct rte_crypto_op *op)