27 #define foreach_esp_decrypt_next \ 28 _(DROP, "error-drop") \ 29 _(IP4_INPUT, "ip4-input-no-checksum") \ 30 _(IP6_INPUT, "ip6-input") 32 #define _(v, s) ESP_DECRYPT_NEXT_##v, 41 #define foreach_esp_decrypt_error \ 42 _(RX_PKTS, "ESP pkts received") \ 43 _(DECRYPTION_FAILED, "ESP decryption failed") \ 44 _(INTEG_ERROR, "Integrity check failed") \ 45 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \ 46 _(REPLAY, "SA replayed packet") \ 47 _(RUNT, "undersized packet") \ 48 _(CHAINED_BUFFER, "chained buffers (packet dropped)") \ 49 _(OVERSIZED_HEADER, "buffer with oversized header (dropped)") \ 50 _(NO_TAIL_SPACE, "no enough buffer tail space (dropped)") 55 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 62 #define _(sym,string) string, 86 "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u",
114 #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2) 119 int is_ip6,
int is_tun)
132 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
157 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_CHAINED_BUFFER];
158 next[0] = ESP_DECRYPT_NEXT_DROP;
162 if (
vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
169 current_sa_bytes = current_sa_pkts = 0;
171 current_sa_index =
vnet_buffer (b[0])->ipsec.sad_index;
188 if (ipsec_sa_is_set_USE_ESN (sa0) && pd->
icv_sz &&
191 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_NO_TAIL_SPACE];
192 next[0] = ESP_DECRYPT_NEXT_DROP;
199 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_REPLAY];
200 next[0] = ESP_DECRYPT_NEXT_DROP;
206 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_RUNT];
207 next[0] = ESP_DECRYPT_NEXT_DROP;
212 current_sa_pkts += 1;
228 if (ipsec_sa_is_set_USE_ESN (sa0))
231 u32 seq_hi = clib_host_to_net_u32 (sa0->
seq_hi);
252 if (ipsec_sa_is_set_IS_AEAD (sa0))
262 scratch = payload - esp_sz;
265 scratch -= (
sizeof (*aad) + pd->
hdr_sz);
275 op->
iv -=
sizeof (sa0->
salt);
295 current_sa_index, current_sa_pkts,
305 if (op->
status != VNET_CRYPTO_OP_STATUS_COMPLETED)
308 if (op->
status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
309 err = ESP_DECRYPT_ERROR_INTEG_ERROR;
311 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
313 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
326 if (op->
status != VNET_CRYPTO_OP_STATUS_COMPLETED)
332 if (op->
status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
333 err = ESP_DECRYPT_ERROR_DECRYPTION_FAILED;
335 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
338 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
355 const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL |
356 IPSEC_SA_FLAG_IS_TUNNEL_V6;
366 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
403 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_REPLAY];
404 next[0] = ESP_DECRYPT_NEXT_DROP;
416 if ((pd->
flags & tun_flags) == 0 && !is_tun)
418 u8 udp_sz = (is_ip6 == 0 && pd->
flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
422 u8 *
ip = old_ip + adv + udp_sz;
424 if (is_ip6 && ip_hdr_sz > 64)
425 memmove (ip, old_ip, ip_hdr_sz);
439 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
445 u16 len = clib_net_to_host_u16 (ip4->
length);
446 len = clib_host_to_net_u16 (len - adv - tail - udp_sz);
454 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
461 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
467 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
473 next[0] = ESP_DECRYPT_NEXT_DROP;
474 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_DECRYPTION_FAILED];
479 if (ipsec_sa_is_set_IS_PROTECT (sa0))
489 ipsec.protect_index);
500 next[0] = ESP_DECRYPT_NEXT_DROP;
513 next[0] = ESP_DECRYPT_NEXT_DROP;
542 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
580 .name =
"esp4-decrypt",
581 .vector_size =
sizeof (
u32),
585 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
590 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 597 .name =
"esp6-decrypt",
598 .vector_size =
sizeof (
u32),
602 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
607 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 614 .name =
"esp4-decrypt-tun",
615 .vector_size =
sizeof (
u32),
619 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
624 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 631 .name =
"esp6-decrypt-tun",
632 .vector_size =
sizeof (
u32),
636 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
641 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 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)
#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
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vnet_crypto_key_index_t crypto_key_index
#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_always_inline int ip46_address_is_equal_v6(const ip46_address_t *ip46, const ip6_address_t *ip6)
static void esp_aad_fill(vnet_crypto_op_t *op, const esp_header_t *esp, const ipsec_sa_t *sa)
vl_api_ip_proto_t protocol
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_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)
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
vnet_crypto_op_status_t status
static_always_inline int ip46_address_is_equal_v4(const ip46_address_t *ip46, const ip4_address_t *ip4)
#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