25 #define foreach_esp_decrypt_next \ 26 _(DROP, "error-drop") \ 27 _(IP4_INPUT, "ip4-input") \ 28 _(IP6_INPUT, "ip6-input") \ 29 _(IPSEC_GRE_INPUT, "ipsec-gre-input") 31 #define _(v, s) ESP_DECRYPT_NEXT_##v, 40 #define foreach_esp_decrypt_error \ 41 _(RX_PKTS, "ESP pkts received") \ 42 _(NO_BUFFER, "No buffer (packed dropped)") \ 43 _(DECRYPTION_FAILED, "ESP decryption failed") \ 44 _(INTEG_ERROR, "Integrity check failed") \ 45 _(REPLAY, "SA replayed packet") \ 46 _(NOT_IP, "Not IP packet (dropped)") 51 #define _(sym,str) ESP_DECRYPT_ERROR_##sym, 58 #define _(sym,string) string, 77 s =
format (s,
"esp: crypto %U integrity %U",
85 u8 * in,
u8 * out,
size_t in_len,
u8 * key,
u8 * iv)
89 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 94 const EVP_CIPHER *cipher =
NULL;
109 EVP_DecryptInit_ex (ctx, cipher,
NULL, key, iv);
111 EVP_DecryptUpdate (ctx, out, &out_len, in, in_len);
112 EVP_DecryptFinal_ex (ctx, out + out_len, &out_len);
120 u32 n_left_from, *from, next_index, *to_next;
135 ESP_DECRYPT_ERROR_NO_BUFFER, n_left_from);
136 goto free_buffers_and_exit;
141 while (n_left_from > 0)
147 while (n_left_from > 0 && n_left_to_next > 0)
149 u32 i_bi0, o_bi0 = (
u32) ~ 0, next0;
165 next0 = ESP_DECRYPT_NEXT_DROP;
173 seq = clib_host_to_net_u32 (esp0->
seq);
188 ESP_DECRYPT_ERROR_REPLAY, 1);
216 ESP_DECRYPT_ERROR_INTEG_ERROR,
235 o_bi0 = empty_buffers[last_empty_buffer];
240 empty_buffers[last_empty_buffer -
242 _vec_len (empty_buffers) = last_empty_buffer;
247 if ((sa0->
crypto_alg >= IPSEC_CRYPTO_ALG_AES_CBC_128 &&
248 sa0->
crypto_alg <= IPSEC_CRYPTO_ALG_AES_CBC_256) ||
249 (sa0->
crypto_alg >= IPSEC_CRYPTO_ALG_DES_CBC &&
250 sa0->
crypto_alg <= IPSEC_CRYPTO_ALG_3DES_CBC))
252 const int BLOCK_SIZE =
261 IV_SIZE) / BLOCK_SIZE;
299 esp0->
data + IV_SIZE,
301 ip_hdr_size, BLOCK_SIZE * blocks,
305 o_b0->
flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
316 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
320 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
324 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
335 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
336 oh6->ip_version_traffic_class_and_flow_label =
344 oh6->payload_length =
351 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
352 oh4->ip_version_and_header_length = 0x45;
354 oh4->fragment_id = 0;
355 oh4->flags_and_fragment_offset = 0;
371 next0 = ESP_DECRYPT_NEXT_IPSEC_GRE_INPUT;
383 o_b0->
flags |= VLIB_BUFFER_IS_TRACED;
393 n_left_to_next, o_bi0, next0);
398 ESP_DECRYPT_ERROR_RX_PKTS,
402 free_buffers_and_exit:
418 .name =
"esp4-decrypt",
419 .vector_size =
sizeof (
u32),
428 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n, 444 .name =
"esp6-decrypt",
445 .vector_size =
sizeof (
u32),
454 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
static char * esp_decrypt_error_strings[]
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
ipsec_proto_main_integ_alg_t * ipsec_proto_main_integ_algs
static void esp_replay_advance(ipsec_sa_t *sa, u32 seq)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
ipsec_crypto_alg_t last_decrypt_alg
static unsigned int hmac_calc(ipsec_integ_alg_t alg, u8 *key, int key_len, u8 *data, int data_len, u8 *signature, u8 use_esn, u32 seq_hi)
ipsec_integ_alg_t integ_alg
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
ipsec_crypto_alg_t crypto_alg
#define VLIB_NODE_FN(node)
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
ipsec_proto_main_crypto_alg_t * ipsec_proto_main_crypto_algs
ipsec_proto_main_t ipsec_proto_main
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
static void esp_replay_advance_esn(ipsec_sa_t *sa, u32 seq)
static void esp_decrypt_cbc(ipsec_crypto_alg_t alg, u8 *in, u8 *out, size_t in_len, u8 *key, u8 *iv)
#define foreach_esp_decrypt_error
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
ipsec_proto_main_per_thread_data_t * per_thread_data
#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 int esp_replay_check_esn(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 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)
#define VLIB_REGISTER_NODE(x,...)
static_always_inline uword vlib_get_thread_index(void)
EVP_CIPHER_CTX * decrypt_ctx
#define vec_free(V)
Free vector's memory (no header).
static void ipsec_alloc_empty_buffers(vlib_main_t *vm, ipsec_main_t *im)
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.
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
static int esp_replay_check(ipsec_sa_t *sa, u32 seq)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define foreach_esp_decrypt_next
ipsec_crypto_alg_t crypto_alg
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 uword esp_decrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6)
vlib_node_registration_t esp6_decrypt_node
(constructor) VLIB_REGISTER_NODE (esp6_decrypt_node)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
#define IPSEC_FLAG_IPSEC_GRE_TUNNEL
static u16 ip4_header_checksum(ip4_header_t *i)
ipsec_integ_alg_t integ_alg
vlib_node_registration_t esp4_decrypt_node
(constructor) VLIB_REGISTER_NODE (esp4_decrypt_node)