26 #define foreach_esp_decrypt_next \ 27 _(DROP, "error-drop") \ 28 _(IP4_INPUT, "ip4-input-no-checksum") \ 29 _(IP6_INPUT, "ip6-input") \ 30 _(IPSEC_GRE_INPUT, "ipsec-gre-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 _(CHAINED_BUFFER, "chained buffers (packet dropped)") \ 48 _(OVERSIZED_HEADER, "buffer with oversized header (dropped)") \ 49 _(NO_TAIL_SPACE, "no enough buffer tail space (dropped)") 54 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 61 #define _(sym,string) string, 81 s =
format (s,
"esp: crypto %U integrity %U seq %u",
108 #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2) 126 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
151 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_CHAINED_BUFFER];
152 next[0] = ESP_DECRYPT_NEXT_DROP;
156 if (
vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
158 current_sa_index =
vnet_buffer (b[0])->ipsec.sad_index;
166 current_sa_index, current_sa_pkts,
169 current_sa_bytes = current_sa_pkts = 0;
180 if (ipsec_sa_is_set_USE_ESN (sa0) && pd->
icv_sz &&
183 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_NO_TAIL_SPACE];
184 next[0] = ESP_DECRYPT_NEXT_DROP;
191 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_REPLAY];
192 next[0] = ESP_DECRYPT_NEXT_DROP;
197 current_sa_pkts += 1;
214 if (ipsec_sa_is_set_USE_ESN (sa0))
237 if (ipsec_sa_is_set_IS_AEAD (sa0))
248 scratch = payload - esp_sz;
251 scratch -= (
sizeof (*aad) + pd->
hdr_sz);
261 salt = clib_host_to_net_u32 (sa0->
salt);
262 op->
iv -=
sizeof (sa0->
salt);
283 current_sa_index, current_sa_pkts,
293 if (op->
status != VNET_CRYPTO_OP_STATUS_COMPLETED)
296 if (op->
status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
297 err = ESP_DECRYPT_ERROR_INTEG_ERROR;
299 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
301 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
314 if (op->
status != VNET_CRYPTO_OP_STATUS_COMPLETED)
320 if (op->
status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
321 err = ESP_DECRYPT_ERROR_DECRYPTION_FAILED;
323 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
326 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
343 const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL |
344 IPSEC_SA_FLAG_IS_TUNNEL_V6;
354 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
376 if ((pd->
flags & tun_flags) == 0)
378 u8 udp_sz = (is_ip6 == 0 && pd->
flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
382 u8 *ip = old_ip + adv + udp_sz;
384 if (is_ip6 && ip_hdr_sz > 64)
385 memmove (ip, old_ip, ip_hdr_sz);
399 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
405 u16 len = clib_net_to_host_u16 (ip4->
length);
406 len = clib_host_to_net_u16 (len - adv - tail - udp_sz);
414 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
421 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
427 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
433 next[0] = ESP_DECRYPT_NEXT_DROP;
434 b[0]->
error = node->
errors[ESP_DECRYPT_ERROR_DECRYPTION_FAILED];
439 next[0] = ESP_DECRYPT_NEXT_IPSEC_GRE_INPUT;
463 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
480 .name =
"esp4-decrypt",
481 .vector_size =
sizeof (
u32),
485 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
490 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 506 .name =
"esp6-decrypt",
507 .vector_size =
sizeof (
u32),
511 .n_errors =
ARRAY_LEN(esp_decrypt_error_strings),
516 #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 int ipsec_sa_anti_replay_check(ipsec_sa_t *sa, u32 *seqp)
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
static void ipsec_sa_anti_replay_advance(ipsec_sa_t *sa, u32 *seqp)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#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
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 * 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 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,...)
#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)
STATIC_ASSERT_SIZEOF(esp_decrypt_packet_data_t, 2 *sizeof(u64))
enum ipsec_sad_flags_t_ ipsec_sa_flags_t
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
u8 data[IPSEC_KEY_MAX_LEN]
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
#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 uword esp_decrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6)
static u16 ip_csum_fold(ip_csum_t c)
ipsec_integ_alg_t integ_alg