30 #define foreach_esp_decrypt_next \ 31 _(DROP, "error-drop") \ 32 _(IP4_INPUT, "ip4-input-no-checksum") \ 33 _(IP6_INPUT, "ip6-input") \ 34 _(L2_INPUT, "l2-input") \ 37 #define _(v, s) ESP_DECRYPT_NEXT_##v, 46 #define foreach_esp_decrypt_error \ 47 _(RX_PKTS, "ESP pkts received") \ 48 _(DECRYPTION_FAILED, "ESP decryption failed") \ 49 _(INTEG_ERROR, "Integrity check failed") \ 50 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \ 51 _(REPLAY, "SA replayed packet") \ 52 _(RUNT, "undersized packet") \ 53 _(CHAINED_BUFFER, "chained buffers (packet dropped)") \ 54 _(OVERSIZED_HEADER, "buffer with oversized header (dropped)") \ 55 _(NO_TAIL_SPACE, "no enough buffer tail space (dropped)") \ 56 _(TUN_NO_PROTO, "no tunnel protocol") \ 57 _(UNSUP_PAYLOAD, "unsupported payload") \ 62 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 69 #define _(sym,string) string, 93 "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u",
121 #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2) 139 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
164 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_CHAINED_BUFFER];
165 next[0] = ESP_DECRYPT_NEXT_DROP;
169 if (
vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
176 current_sa_bytes = current_sa_pkts = 0;
178 current_sa_index =
vnet_buffer (b[0])->ipsec.sad_index;
197 next[0] = ESP_DECRYPT_NEXT_HANDOFF;
210 if (ipsec_sa_is_set_USE_ESN (sa0) && pd->
icv_sz &&
213 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_NO_TAIL_SPACE];
214 next[0] = ESP_DECRYPT_NEXT_DROP;
221 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_REPLAY];
222 next[0] = ESP_DECRYPT_NEXT_DROP;
228 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_RUNT];
229 next[0] = ESP_DECRYPT_NEXT_DROP;
234 current_sa_pkts += 1;
250 if (ipsec_sa_is_set_USE_ESN (sa0))
253 u32 seq_hi = clib_host_to_net_u32 (sa0->
seq_hi);
274 if (ipsec_sa_is_set_IS_AEAD (sa0))
284 scratch = payload - esp_sz;
287 scratch -= (
sizeof (*aad) + pd->
hdr_sz);
297 op->
iv -=
sizeof (sa0->
salt);
318 current_sa_index, current_sa_pkts,
328 if (op->
status != VNET_CRYPTO_OP_STATUS_COMPLETED)
331 if (op->
status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
332 err = ESP_DECRYPT_ERROR_INTEG_ERROR;
334 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
336 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
349 if (op->
status != VNET_CRYPTO_OP_STATUS_COMPLETED)
355 if (op->
status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
356 err = ESP_DECRYPT_ERROR_DECRYPTION_FAILED;
358 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
361 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
378 const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL |
379 IPSEC_SA_FLAG_IS_TUNNEL_V6;
389 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
426 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_REPLAY];
427 next[0] = ESP_DECRYPT_NEXT_DROP;
439 if ((pd->
flags & tun_flags) == 0 && !is_tun)
441 u8 udp_sz = (is_ip6 == 0 && pd->
flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
445 u8 *
ip = old_ip + adv + udp_sz;
447 if (is_ip6 && ip_hdr_sz > 64)
448 memmove (ip, old_ip, ip_hdr_sz);
462 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
468 u16 len = clib_net_to_host_u16 (ip4->
length);
469 len = clib_host_to_net_u16 (len - adv - tail - udp_sz);
477 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
484 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
490 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
507 switch (clib_net_to_host_u16 (gre->
protocol))
509 case GRE_PROTOCOL_teb:
511 next[0] = ESP_DECRYPT_NEXT_L2_INPUT;
513 case GRE_PROTOCOL_ip4:
514 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
516 case GRE_PROTOCOL_ip6:
517 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
521 node->
errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
522 next[0] = ESP_DECRYPT_NEXT_DROP;
528 next[0] = ESP_DECRYPT_NEXT_DROP;
529 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
535 if (ipsec_sa_is_set_IS_PROTECT (sa0))
569 next[0] = ESP_DECRYPT_NEXT_DROP;
571 node->
errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
585 next[0] = ESP_DECRYPT_NEXT_DROP;
587 node->
errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
617 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
655 .name =
"esp4-decrypt",
656 .vector_size =
sizeof (
u32),
660 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
665 [ESP_DECRYPT_NEXT_DROP] =
"ip4-drop",
666 [ESP_DECRYPT_NEXT_IP4_INPUT] =
"ip4-input-no-checksum",
667 [ESP_DECRYPT_NEXT_IP6_INPUT] =
"ip6-input",
668 [ESP_DECRYPT_NEXT_L2_INPUT] =
"l2-input",
669 [ESP_DECRYPT_NEXT_HANDOFF] =
"esp4-decrypt-handoff",
674 .name =
"esp6-decrypt",
675 .vector_size =
sizeof (
u32),
679 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
684 [ESP_DECRYPT_NEXT_DROP] =
"ip6-drop",
685 [ESP_DECRYPT_NEXT_IP4_INPUT] =
"ip4-input-no-checksum",
686 [ESP_DECRYPT_NEXT_IP6_INPUT] =
"ip6-input",
687 [ESP_DECRYPT_NEXT_L2_INPUT] =
"l2-input",
688 [ESP_DECRYPT_NEXT_HANDOFF]=
"esp6-decrypt-handoff",
693 .name =
"esp4-decrypt-tun",
694 .vector_size =
sizeof (
u32),
697 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
701 [ESP_DECRYPT_NEXT_DROP] =
"ip4-drop",
702 [ESP_DECRYPT_NEXT_IP4_INPUT] =
"ip4-input-no-checksum",
703 [ESP_DECRYPT_NEXT_IP6_INPUT] =
"ip6-input",
704 [ESP_DECRYPT_NEXT_L2_INPUT] =
"l2-input",
705 [ESP_DECRYPT_NEXT_HANDOFF] =
"esp4-decrypt-tun-handoff",
710 .name =
"esp6-decrypt-tun",
711 .vector_size =
sizeof (
u32),
714 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
718 [ESP_DECRYPT_NEXT_DROP] =
"ip6-drop",
719 [ESP_DECRYPT_NEXT_IP4_INPUT] =
"ip4-input-no-checksum",
720 [ESP_DECRYPT_NEXT_IP6_INPUT] =
"ip6-input",
721 [ESP_DECRYPT_NEXT_L2_INPUT] =
"l2-input",
722 [ESP_DECRYPT_NEXT_HANDOFF]=
"esp6-decrypt-tun-handoff",
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
ipsec_per_thread_data_t * ptd
vnet_crypto_op_t * integ_ops
static char * esp_decrypt_error_strings[]
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.
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define clib_memcpy_fast(a, b, c)
static u32 ipsec_sa_assign_thread(u32 thread_id)
#define vec_add2_aligned(V, P, N, A)
Add N elements to end of vector V, return pointer to new elements in P.
ipsec_integ_alg_t integ_alg
u16 current_length
Nbytes between current data and the end of this buffer.
vnet_crypto_op_t * crypto_ops
ipsec_crypto_alg_t crypto_alg
AES GCM Additional Authentication data.
#define VLIB_NODE_FN(node)
vlib_error_t * errors
Vector of errors for this node.
vnet_crypto_op_id_t integ_op_id
static_always_inline int ip46_address_is_equal_v6(const ip46_address_t *ip46, const ip6_address_t *ip6)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vnet_crypto_key_index_t crypto_key_index
vl_api_ip_proto_t protocol
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define foreach_esp_decrypt_error
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void esp_aad_fill(vnet_crypto_op_t *op, const esp_header_t *esp, const ipsec_sa_t *sa)
static void ipsec_sa_anti_replay_advance(ipsec_sa_t *sa, u32 seq)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
u32 node_index
Node index.
#define VNET_CRYPTO_OP_FLAG_HMAC_CHECK
STATIC_ASSERT_SIZEOF(esp_decrypt_packet_data_t, 3 *sizeof(u64))
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
static uword esp_decrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6, int is_tun)
#define CLIB_PREFETCH(addr, size, type)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
vlib_main_t vlib_node_runtime_t * node
#define clib_atomic_cmp_and_swap(addr, old, new)
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
static ipsec_tun_protect_t * ipsec_tun_protect_get(u32 index)
static int ipsec_sa_anti_replay_check(ipsec_sa_t *sa, u32 seq)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
vnet_crypto_key_index_t integ_key_index
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static_always_inline void clib_memset_u16(void *p, u16 val, uword count)
static_always_inline void clib_memcpy_le64(u8 *dst, u8 *src, u8 len)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define ip_csum_update(sum, old, new, type, field)
vnet_crypto_op_id_t crypto_enc_op_id
static_always_inline int ip46_address_is_equal_v4(const ip46_address_t *ip46, const ip4_address_t *ip4)
vnet_crypto_op_status_t status
#define foreach_esp_decrypt_next
ipsec_crypto_alg_t crypto_alg
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#define CLIB_CACHE_LINE_BYTES
vnet_crypto_op_id_t crypto_dec_op_id
static u16 ip_csum_fold(ip_csum_t c)
ipsec_integ_alg_t integ_alg