21 #include <openssl/hmac.h> 22 #include <openssl/rand.h> 23 #include <openssl/evp.h> 28 #define IPSEC_FLAG_IPSEC_GRE_TUNNEL (1 << 0) 30 #define foreach_ipsec_output_next \ 31 _ (DROP, "error-drop") \ 32 _ (ESP4_ENCRYPT, "esp4-encrypt") \ 33 _ (AH4_ENCRYPT, "ah4-encrypt") \ 34 _ (ESP6_ENCRYPT, "esp6-encrypt") \ 35 _ (AH6_ENCRYPT, "ah6-encrypt") 37 #define _(v, s) IPSEC_OUTPUT_NEXT_##v, 45 #define foreach_ipsec_input_next \ 46 _ (DROP, "error-drop") \ 47 _ (ESP4_DECRYPT, "esp4-decrypt") \ 48 _ (AH4_DECRYPT, "ah4-decrypt") \ 49 _ (ESP6_DECRYPT, "esp6-decrypt") \ 50 _ (AH6_DECRYPT, "ah6-decrypt") 52 #define _(v, s) IPSEC_INPUT_NEXT_##v, 60 #define foreach_ipsec_policy_action \ 61 _ (0, BYPASS, "bypass") \ 62 _ (1, DISCARD, "discard") \ 63 _ (2, RESOLVE, "resolve") \ 64 _ (3, PROTECT, "protect") 68 #define _(v, f, s) IPSEC_POLICY_ACTION_##f = v, 74 #define foreach_ipsec_crypto_alg \ 76 _ (1, AES_CBC_128, "aes-cbc-128") \ 77 _ (2, AES_CBC_192, "aes-cbc-192") \ 78 _ (3, AES_CBC_256, "aes-cbc-256") \ 79 _ (4, AES_CTR_128, "aes-ctr-128") \ 80 _ (5, AES_CTR_192, "aes-ctr-192") \ 81 _ (6, AES_CTR_256, "aes-ctr-256") \ 82 _ (7, AES_GCM_128, "aes-gcm-128") \ 83 _ (8, AES_GCM_192, "aes-gcm-192") \ 84 _ (9, AES_GCM_256, "aes-gcm-256") \ 85 _ (10, DES_CBC, "des-cbc") \ 86 _ (11, 3DES_CBC, "3des-cbc") 90 #define _(v, f, s) IPSEC_CRYPTO_ALG_##f = v, 96 #define foreach_ipsec_integ_alg \ 98 _ (1, MD5_96, "md5-96") \ 99 _ (2, SHA1_96, "sha1-96") \ 100 _ (3, SHA_256_96, "sha-256-96") \ 101 _ (4, SHA_256_128, "sha-256-128") \ 102 _ (5, SHA_384_192, "sha-384-192") \ 103 _ (6, SHA_512_256, "sha-512-256") 107 #define _(v, f, s) IPSEC_INTEG_ALG_##f = v, 176 u8 local_crypto_key[128];
178 u8 remote_crypto_key[128];
181 u8 local_integ_key[128];
183 u8 remote_integ_key[128];
318 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 321 EVP_CIPHER_CTX encrypt_ctx;
324 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 327 EVP_CIPHER_CTX decrypt_ctx;
330 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 368 u32 feature_next_node_index[32];
503 const char *ah4_encrypt_node_name,
504 const char *ah4_decrypt_node_name,
505 const char *ah6_encrypt_node_name,
506 const char *ah6_decrypt_node_name,
512 const char *esp4_encrypt_node_name,
513 const char *esp4_decrypt_node_name,
514 const char *esp6_encrypt_node_name,
515 const char *esp6_decrypt_node_name,
int ipsec_set_interface_key(vnet_main_t *vnm, u32 hw_if_index, ipsec_if_set_key_type_t type, u8 alg, u8 *key)
u32 * ipv6_inbound_protect_policy_indices
int ipsec_set_interface_sa(vnet_main_t *vnm, u32 hw_if_index, u32 sa_id, u8 is_outbound)
EVP_CIPHER_CTX * encrypt_ctx
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
u32 esp4_encrypt_next_index
u32 * ipv4_inbound_protect_policy_indices
ipsec_tunnel_if_t * tunnel_interfaces
ip46_address_t tunnel_src_addr
u32 esp6_decrypt_node_index
uword * tunnel_index_by_key
u32 ah4_decrypt_next_index
ipsec_proto_main_integ_alg_t * ipsec_proto_main_integ_algs
int ipsec_set_interface_spd(vlib_main_t *vm, u32 sw_if_index, u32 spd_id, int is_add)
u32 ipsec_get_sa_index_by_sa_id(u32 sa_id)
u32 esp4_decrypt_node_index
ipsec_crypto_alg_t last_decrypt_alg
clib_error_t * ipsec_check_support_cb(ipsec_main_t *im, ipsec_sa_t *sa)
ipsec_integ_alg_t integ_alg
u32 ah6_decrypt_next_index
u32 esp6_decrypt_next_index
u32 ah4_encrypt_next_index
u32 ah4_encrypt_node_index
u32 esp6_encrypt_node_index
Combined counter to hold both packets and byte differences.
u32 * ipv4_outbound_policies
int ipsec_add_del_spd(vlib_main_t *vm, u32 spd_id, int is_add)
uword * ipsec_if_pool_index_by_key
u32 ah6_decrypt_node_index
ipsec_proto_main_crypto_alg_t * ipsec_proto_main_crypto_algs
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
vlib_node_registration_t esp6_decrypt_node
(constructor) VLIB_REGISTER_NODE (esp6_decrypt_node)
u8 ipsec_is_sa_used(u32 sa_index)
uword * spd_index_by_sw_if_index
int ipsec_select_esp_backend(ipsec_main_t *im, u32 esp_backend_idx)
u32 esp6_encrypt_next_index
u32 ah6_encrypt_node_index
#define static_always_inline
vlib_node_registration_t esp4_encrypt_node
(constructor) VLIB_REGISTER_NODE (esp4_encrypt_node)
vlib_node_registration_t esp4_decrypt_node
(constructor) VLIB_REGISTER_NODE (esp4_decrypt_node)
uword unformat_ipsec_integ_alg(unformat_input_t *input, va_list *args)
u32 esp6_encrypt_node_index
u32 esp4_decrypt_next_index
u32 ah6_encrypt_next_index
int ipsec_add_del_ipsec_gre_tunnel(vnet_main_t *vnm, ipsec_add_del_ipsec_gre_tunnel_args_t *args)
#define foreach_ipsec_input_next
check_support_cb_t check_support_cb
ipsec_spd_t * spd_to_sort
clib_error_t *(* add_del_sa_sess_cb_t)(u32 sa_index, u8 is_add)
u32 esp6_decrypt_node_index
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
ipsec_policy_t * policies
u32 ah4_decrypt_node_index
u32 error_drop_node_index
ipsec_proto_main_per_thread_data_t * per_thread_data
u32 esp4_encrypt_node_index
u32 ah4_decrypt_next_index
uword unformat_ipsec_crypto_alg(unformat_input_t *input, va_list *args)
vlib_node_registration_t ah6_decrypt_node
(constructor) VLIB_REGISTER_NODE (ah6_decrypt_node)
vlib_node_registration_t ah4_encrypt_node
(constructor) VLIB_REGISTER_NODE (ah4_encrypt_node)
ipsec_crypto_alg_t last_encrypt_alg
vlib_node_registration_t esp6_encrypt_node
(constructor) VLIB_REGISTER_NODE (esp6_encrypt_node)
ip46_address_range_t laddr
u32 node_index
Node index.
#define foreach_ipsec_integ_alg
u32 esp4_encrypt_node_index
uword * spd_index_by_spd_id
ip46_address_t tunnel_dst_addr
#define foreach_ipsec_crypto_alg
u32 ah4_decrypt_node_index
ipsec_crypto_alg_t crypto_alg
u32 ah6_encrypt_next_index
#define foreach_ipsec_policy_action
ipsec_ah_backend_t * ah_backends
EVP_CIPHER_CTX * decrypt_ctx
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
vlib_node_registration_t ipsec_if_input_node
(constructor) VLIB_REGISTER_NODE (ipsec_if_input_node)
u32 esp4_encrypt_next_index
vlib_node_registration_t ah6_encrypt_node
(constructor) VLIB_REGISTER_NODE (ah6_encrypt_node)
#define foreach_ipsec_output_next
u32 ah4_encrypt_next_index
uword * sa_index_by_sa_id
static void ipsec_alloc_empty_buffers(vlib_main_t *vm, ipsec_main_t *im)
u32 esp6_decrypt_next_index
clib_error_t * ipsec_add_del_sa_sess_cb(ipsec_main_t *im, u32 sa_index, u8 is_add)
static_always_inline u32 get_next_output_feature_node_index(vlib_buffer_t *b, vlib_node_runtime_t *nr)
uword * ipsec_if_real_dev_by_show_dev
u32 ipsec_register_ah_backend(vlib_main_t *vm, ipsec_main_t *im, const char *name, const char *ah4_encrypt_node_name, const char *ah4_decrypt_node_name, const char *ah6_encrypt_node_name, const char *ah6_decrypt_node_name, check_support_cb_t ah_check_support_cb, add_del_sa_sess_cb_t ah_add_del_sa_sess_cb)
int ipsec_set_sa_key(vlib_main_t *vm, ipsec_sa_t *sa_update)
ip46_address_range_t raddr
u32 esp6_encrypt_next_index
clib_error_t *(* check_support_cb_t)(ipsec_sa_t *sa)
u32 ah4_encrypt_node_index
u8 * format_ipsec_replay_window(u8 *s, va_list *args)
ipsec_integ_alg_t integ_alg
u32 esp4_decrypt_node_index
ipsec_protocol_t protocol
uword unformat_ipsec_policy_action(unformat_input_t *input, va_list *args)
add_del_sa_sess_cb_t add_del_sa_sess_cb
u32 ah6_decrypt_node_index
static vlib_main_t * vlib_get_main(void)
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
struct _vlib_node_registration vlib_node_registration_t
u32 ah6_encrypt_node_index
int ipsec_add_del_policy(vlib_main_t *vm, ipsec_policy_t *policy, int is_add)
u8 * format_ipsec_policy_action(u8 *s, va_list *args)
int ipsec_add_del_tunnel_if_internal(vnet_main_t *vnm, ipsec_add_del_tunnel_args_t *args, u32 *sw_if_index)
u32 ah6_decrypt_next_index
check_support_cb_t check_support_cb
u32 * ipv4_inbound_policy_discard_and_bypass_indices
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 * free_tunnel_if_indices
u32 * ipv6_inbound_policy_discard_and_bypass_indices
ipsec_integ_alg_t last_integ_alg
u32 * ipv6_outbound_policies
u32 esp4_decrypt_next_index
vlib_node_registration_t ah4_decrypt_node
(constructor) VLIB_REGISTER_NODE (ah4_decrypt_node)
ipsec_proto_main_t ipsec_proto_main
ipsec_crypto_alg_t crypto_alg
int ipsec_select_ah_backend(ipsec_main_t *im, u32 ah_backend_idx)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
u32 ipsec_register_esp_backend(vlib_main_t *vm, ipsec_main_t *im, const char *name, const char *esp4_encrypt_node_name, const char *esp4_decrypt_node_name, const char *esp6_encrypt_node_name, const char *esp6_decrypt_node_name, check_support_cb_t esp_check_support_cb, add_del_sa_sess_cb_t esp_add_del_sa_sess_cb)
int ipsec_add_del_tunnel_if(ipsec_add_del_tunnel_args_t *args)
add_del_sa_sess_cb_t add_del_sa_sess_cb
ipsec_esp_backend_t * esp_backends
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
int ipsec_add_del_sa(vlib_main_t *vm, ipsec_sa_t *new_sa, int is_add)