#include <plugins/ikev2/ikev2_priv.h>
#include <openssl/sha.h>
+#define IKEV2_LIVENESS_RETRIES 3
+#define IKEV2_LIVENESS_PERIOD_CHECK 30
+
ikev2_main_t ikev2_main;
static int ikev2_delete_tunnel_interface (vnet_main_t * vnm,
ikev2_sa_transform_t *t = 0, *t2;
ikev2_main_t *km = &ikev2_main;
+ sai->init_response_received = 1;
/*move some data to the new SA */
#define _(A) ({void* __tmp__ = (A); (A) = 0; __tmp__;})
sa->i_id.type = sai->i_id.type;
sa->profile_index = sai->profile_index;
sa->is_profile_index_set = sai->is_profile_index_set;
+ sa->tun_itf = sai->tun_itf;
+ sa->is_tun_itf_set = sai->is_tun_itf_set;
sa->i_id.data = _(sai->i_id.data);
sa->i_auth.method = sai->i_auth.method;
sa->i_auth.hex = sai->i_auth.hex;
sa->i_auth.key = _(sai->i_auth.key);
sa->last_sa_init_req_packet_data = _(sai->last_sa_init_req_packet_data);
sa->childs = _(sai->childs);
+ sa->udp_encap = sai->udp_encap;
+ sa->dst_port = sai->dst_port;
#undef _
vec_free (delete);
sa->initial_contact = 0;
-
- km->log_level = IKEV2_LOG_ERROR;
- km->log_class = vlib_log_register_class ("ikev2", 0);
}
static void
ike_payload_header_t *ikep;
u32 plen;
+ sa->liveness_retries = 0;
ikev2_elog_exchange ("ispi %lx rspi %lx INFORMATIONAL received "
"from %d.%d.%d.%d", clib_host_to_net_u64 (ike->ispi),
clib_host_to_net_u64 (ike->rspi), sa->iaddr.as_u32);
}));
/* *INDENT-ON* */
+ if (sel_p)
+ {
+ sa->udp_encap = sel_p->udp_encap;
+ sa->dst_port = sel_p->dst_port;
+ }
vec_free (authmsg);
if (sa->state == IKEV2_STATE_AUTHENTICATED)
sa->childs[0].r_proposals =
ikev2_select_proposal (sa->childs[0].i_proposals,
IKEV2_PROTOCOL_ESP);
+
+ if (~0 != sel_p->tun_itf)
+ {
+ sa->is_tun_itf_set = 1;
+ sa->tun_itf = sel_p->tun_itf;
+ }
}
}
else
typedef struct
{
+ u32 sw_if_index;
u32 salt_local;
u32 salt_remote;
u32 local_sa_id;
ip46_address_t local_ip;
ip46_address_t remote_ip;
ipsec_key_t loc_ckey, rem_ckey, loc_ikey, rem_ikey;
+ u8 is_rekey;
+ u32 old_remote_sa_id;
+ u16 dst_port;
} ikev2_add_ipsec_tunnel_args_t;
static void
{
ikev2_main_t *km = &ikev2_main;
u32 sw_if_index;
- int rv;
- uword *p = 0;
+ int rv = 0;
- rv = ipip_add_tunnel (IPIP_TRANSPORT_IP4, ~0,
- &a->local_ip, &a->remote_ip, 0,
- TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0,
- TUNNEL_MODE_P2P, &sw_if_index);
+ if (~0 == a->sw_if_index)
+ {
+ /* no tunnel associated with the SA/profile - create a new one */
+ rv = ipip_add_tunnel (IPIP_TRANSPORT_IP4, ~0,
+ &a->local_ip, &a->remote_ip, 0,
+ TUNNEL_ENCAP_DECAP_FLAG_NONE, IP_DSCP_CS0,
+ TUNNEL_MODE_P2P, &sw_if_index);
- if (rv == VNET_API_ERROR_IF_ALREADY_EXISTS)
+ if (rv == VNET_API_ERROR_IF_ALREADY_EXISTS)
+ {
+ if (hash_get (km->sw_if_indices, sw_if_index))
+ /* interface is managed by IKE; proceed with updating SAs */
+ rv = 0;
+ }
+ hash_set1 (km->sw_if_indices, sw_if_index);
+ }
+ else
{
- p = hash_get (km->sw_if_indices, sw_if_index);
- if (p)
- /* interface is managed by IKE; proceed with updating SAs */
- rv = 0;
+ sw_if_index = a->sw_if_index;
+ vnet_sw_interface_admin_up (vnet_get_main (), sw_if_index);
}
if (rv)
return;
}
+ u32 *sas_in = NULL;
+ vec_add1 (sas_in, a->remote_sa_id);
+ if (a->is_rekey)
+ {
+ ipsec_tun_protect_del (sw_if_index, NULL);
+
+ /* replace local SA immediately */
+ ipsec_sa_unlock_id (a->local_sa_id);
+
+ /* keep the old sa */
+ vec_add1 (sas_in, a->old_remote_sa_id);
+ }
+
rv |= ipsec_sa_add_and_lock (a->local_sa_id,
a->local_spi,
IPSEC_PROTOCOL_ESP, a->encr_type,
&a->loc_ckey, a->integ_type, &a->loc_ikey,
a->flags, 0, a->salt_local, &a->local_ip,
- &a->remote_ip, NULL);
+ &a->remote_ip, NULL, a->dst_port);
rv |= ipsec_sa_add_and_lock (a->remote_sa_id, a->remote_spi,
IPSEC_PROTOCOL_ESP, a->encr_type, &a->rem_ckey,
a->integ_type, &a->rem_ikey,
(a->flags | IPSEC_SA_FLAG_IS_INBOUND), 0,
a->salt_remote, &a->remote_ip,
- &a->local_ip, NULL);
+ &a->local_ip, NULL, a->dst_port);
- u32 *sas_in = NULL;
- vec_add1 (sas_in, a->remote_sa_id);
- rv |= ipsec_tun_protect_update (sw_if_index, a->local_sa_id, sas_in);
- hash_set1 (km->sw_if_indices, sw_if_index);
+ rv |= ipsec_tun_protect_update (sw_if_index, NULL, a->local_sa_id, sas_in);
}
static int
u32 thread_index,
ikev2_sa_t * sa,
ikev2_child_sa_t * child, u32 sa_index,
- u32 child_index)
+ u32 child_index, u8 is_rekey)
{
ikev2_main_t *km = &ikev2_main;
ipsec_crypto_alg_t encr_type;
}
a.flags = IPSEC_SA_FLAG_USE_ANTI_REPLAY;
+ if (sa->udp_encap)
+ {
+ a.flags |= IPSEC_SA_FLAG_IS_TUNNEL;
+ a.flags |= IPSEC_SA_FLAG_UDP_ENCAP;
+ }
+ a.is_rekey = is_rekey;
tr = ikev2_sa_get_td_for_type (proposals, IKEV2_TRANSFORM_TYPE_ESN);
if (tr && tr->esn_type)
child->local_sa_id =
a.local_sa_id =
ikev2_mk_local_sa_id (sa_index, child_index, thread_index);
- child->remote_sa_id =
- a.remote_sa_id =
- ikev2_mk_remote_sa_id (sa_index, child_index, thread_index);
+
+ u32 remote_sa_id = ikev2_mk_remote_sa_id (sa_index, child_index,
+ thread_index);
+
+ if (is_rekey)
+ {
+ /* create a new remote SA ID to keep the old SA for a bit longer
+ * so the peer has some time to swap their SAs */
+
+ /* use most significat bit of child index part in id */
+ u32 mask = 0x800;
+ if (sa->current_remote_id_mask)
+ {
+ sa->old_remote_id = a.old_remote_sa_id = remote_sa_id | mask;
+ sa->current_remote_id_mask = 0;
+ }
+ else
+ {
+ sa->old_remote_id = a.old_remote_sa_id = remote_sa_id;
+ sa->current_remote_id_mask = mask;
+ remote_sa_id |= mask;
+ }
+ sa->old_id_expiration = 3.0;
+ sa->old_remote_id_present = 1;
+ }
+
+ child->remote_sa_id = a.remote_sa_id = remote_sa_id;
+
+ a.sw_if_index = (sa->is_tun_itf_set ? sa->tun_itf : ~0);
+ a.dst_port = sa->dst_port;
vl_api_rpc_call_main_thread (ikev2_add_tunnel_from_main,
(u8 *) & a, sizeof (a));
ip46_address_t remote_ip;
u32 remote_sa_id;
u32 local_sa_id;
+ u32 sw_if_index;
} ikev2_del_ipsec_tunnel_args_t;
+static_always_inline u32
+ikev2_flip_alternate_sa_bit (u32 id)
+{
+ u32 mask = 0x800;
+ if (mask & id)
+ return id & ~mask;
+ return id | mask;
+}
+
static void
ikev2_del_tunnel_from_main (ikev2_del_ipsec_tunnel_args_t * a)
{
ikev2_main_t *km = &ikev2_main;
- /* *INDENT-OFF* */
- ipip_tunnel_key_t key = {
- .src = a->local_ip,
- .dst = a->remote_ip,
- .transport = IPIP_TRANSPORT_IP4,
- .fib_index = 0,
- };
- ipip_tunnel_t *ipip;
- /* *INDENT-ON* */
+ ipip_tunnel_t *ipip = NULL;
+ u32 sw_if_index;
+
+ if (~0 == a->sw_if_index)
+ {
+ /* *INDENT-OFF* */
+ ipip_tunnel_key_t key = {
+ .src = a->local_ip,
+ .dst = a->remote_ip,
+ .transport = IPIP_TRANSPORT_IP4,
+ .fib_index = 0,
+ };
+ /* *INDENT-ON* */
- ipip = ipip_tunnel_db_find (&key);
+ ipip = ipip_tunnel_db_find (&key);
- if (ipip)
+ if (ipip)
+ {
+ sw_if_index = ipip->sw_if_index;
+ hash_unset (km->sw_if_indices, ipip->sw_if_index);
+ }
+ else
+ sw_if_index = ~0;
+ }
+ else
{
- hash_unset (km->sw_if_indices, ipip->sw_if_index);
- ipsec_tun_protect_del (ipip->sw_if_index);
- ipsec_sa_unlock_id (a->remote_sa_id);
- ipsec_sa_unlock_id (a->local_sa_id);
- ipip_del_tunnel (ipip->sw_if_index);
+ sw_if_index = a->sw_if_index;
+ vnet_sw_interface_admin_down (vnet_get_main (), sw_if_index);
}
+
+ if (~0 != sw_if_index)
+ ipsec_tun_protect_del (sw_if_index, NULL);
+
+ ipsec_sa_unlock_id (a->remote_sa_id);
+ ipsec_sa_unlock_id (a->local_sa_id);
+ ipsec_sa_unlock_id (ikev2_flip_alternate_sa_bit (a->remote_sa_id));
+
+ if (ipip)
+ ipip_del_tunnel (ipip->sw_if_index);
}
static int
a.remote_sa_id = child->remote_sa_id;
a.local_sa_id = child->local_sa_id;
+ a.sw_if_index = (sa->is_tun_itf_set ? sa->tun_itf : ~0);
vl_api_rpc_call_main_thread (ikev2_del_tunnel_from_main, (u8 *) & a,
sizeof (a));
ikev2_payload_add_sa (chain, sa->childs[0].i_proposals);
ikev2_payload_add_ts (chain, sa->childs[0].tsi, IKEV2_PAYLOAD_TSI);
ikev2_payload_add_ts (chain, sa->childs[0].tsr, IKEV2_PAYLOAD_TSR);
+ ikev2_payload_add_notify (chain, IKEV2_NOTIFY_MSG_INITIAL_CONTACT,
+ 0);
}
else
{
return -1;
}
+static void
+ikev2_init_sa (ikev2_sa_t * sa)
+{
+ ikev2_main_t *km = &ikev2_main;
+ sa->liveness_period_check =
+ vlib_time_now (km->vlib_main) + km->liveness_period;
+}
static uword
ikev2_node_fn (vlib_main_t * vm,
pool_get (km->per_thread_data[thread_index].sas,
sa0);
clib_memcpy_fast (sa0, &sa, sizeof (*sa0));
+ ikev2_init_sa (sa0);
hash_set (km->
per_thread_data[thread_index].sa_by_rspi,
sa0->rspi,
ikev2_sa_t *sai =
pool_elt_at_index (km->sais, p[0]);
- ikev2_complete_sa_data (sa0, sai);
- ikev2_calc_keys (sa0);
- ikev2_sa_auth_init (sa0);
- len = ikev2_generate_message (sa0, ike0, 0);
+ if (sai->init_response_received)
+ {
+ /* we've already processed sa-init response */
+ sa0->state = IKEV2_STATE_UNKNOWN;
+ }
+ else
+ {
+ ikev2_complete_sa_data (sa0, sai);
+ ikev2_calc_keys (sa0);
+ ikev2_sa_auth_init (sa0);
+ len = ikev2_generate_message (sa0, ike0, 0);
+ }
}
}
ikev2_create_tunnel_interface (km->vnet_main,
thread_index, sa0,
&sa0->childs[0],
- p[0], 0);
+ p[0], 0, 0);
}
if (sa0->is_initiator)
}
}
}
- if (!sa0->is_initiator)
+ if (!(ike0->flags & IKEV2_HDR_FLAG_RESPONSE))
{
+ ike0->flags |= IKEV2_HDR_FLAG_RESPONSE;
len = ikev2_generate_message (sa0, ike0, 0);
}
}
ikev2_create_tunnel_interface (km->vnet_main,
thread_index, sa0,
child, p[0],
- child - sa0->childs);
+ child - sa0->childs,
+ 1);
}
if (sa0->is_initiator)
{
return r;
}
- /* Integrity */
- error = 1;
- vec_foreach (td, km->supported_transforms)
- {
- if (td->type == IKEV2_TRANSFORM_TYPE_INTEG
- && td->integ_type == ts->integ_alg)
+ if (is_ike || IKEV2_TRANSFORM_ENCR_TYPE_AES_GCM_16 != ts->crypto_alg)
+ {
+ /* Integrity */
+ error = 1;
+ vec_foreach (td, km->supported_transforms)
{
- vec_add1 (proposal->transforms, *td);
- error = 0;
- break;
+ if (td->type == IKEV2_TRANSFORM_TYPE_INTEG
+ && td->integ_type == ts->integ_alg)
+ {
+ vec_add1 (proposal->transforms, *td);
+ error = 0;
+ break;
+ }
}
- }
- if (error)
- {
- ikev2_elog_error
- ("Didn't find any supported algorithm for IKEV2_TRANSFORM_TYPE_INTEG");
- r = clib_error_return (0, "Unsupported algorithm");
- return r;
+ if (error)
+ {
+ ikev2_elog_error
+ ("Didn't find any supported algorithm for IKEV2_TRANSFORM_TYPE_INTEG");
+ r = clib_error_return (0, "Unsupported algorithm");
+ return r;
+ }
}
/* PRF */
return 0;
}
+static_always_inline vnet_api_error_t
+ikev2_register_udp_port (ikev2_profile_t * p, u16 port)
+{
+ ikev2_main_t *km = &ikev2_main;
+ udp_dst_port_info_t *pi;
+
+ uword *v = hash_get (km->udp_ports, port);
+ pi = udp_get_dst_port_info (&udp_main, port, UDP_IP4);
+
+ if (v)
+ {
+ /* IKE already uses this port, only increment reference counter */
+ ASSERT (pi);
+ v[0]++;
+ }
+ else
+ {
+ if (pi)
+ return VNET_API_ERROR_UDP_PORT_TAKEN;
+
+ udp_register_dst_port (km->vlib_main, port,
+ ipsec4_tun_input_node.index, 1);
+ hash_set (km->udp_ports, port, 1);
+ }
+ p->dst_port = port;
+ return 0;
+}
+
+static_always_inline void
+ikev2_unregister_udp_port (ikev2_profile_t * p)
+{
+ ikev2_main_t *km = &ikev2_main;
+ uword *v;
+
+ if (p->dst_port == IPSEC_UDP_PORT_NONE)
+ return;
+
+ v = hash_get (km->udp_ports, p->dst_port);
+ if (!v)
+ return;
+
+ v[0]--;
+
+ if (v[0] == 0)
+ {
+ udp_unregister_dst_port (km->vlib_main, p->dst_port, 1);
+ hash_unset (km->udp_ports, p->dst_port);
+ }
+
+ p->dst_port = IPSEC_UDP_PORT_NONE;
+}
+
clib_error_t *
ikev2_add_del_profile (vlib_main_t * vm, u8 * name, int is_add)
{
pool_get (km->profiles, p);
clib_memset (p, 0, sizeof (*p));
p->name = vec_dup (name);
+ p->dst_port = IPSEC_UDP_PORT_NONE;
p->responder.sw_if_index = ~0;
+ p->tun_itf = ~0;
uword index = p - km->profiles;
mhash_set_mem (&km->profile_index_by_name, name, &index, 0);
}
if (!p)
return clib_error_return (0, "policy %v does not exists", name);
+ ikev2_unregister_udp_port (p);
+
vec_free (p->name);
pool_put (km->profiles, p);
mhash_unset (&km->profile_index_by_name, name, 0);
return 0;
}
+clib_error_t *
+ikev2_set_profile_tunnel_interface (vlib_main_t * vm,
+ u8 * name, u32 sw_if_index)
+{
+ ikev2_profile_t *p;
+ clib_error_t *r;
+
+ p = ikev2_profile_index_by_name (name);
+
+ if (!p)
+ {
+ r = clib_error_return (0, "unknown profile %v", name);
+ return r;
+ }
+
+ p->tun_itf = sw_if_index;
+
+ return 0;
+}
+
+vnet_api_error_t
+ikev2_set_profile_ipsec_udp_port (vlib_main_t * vm, u8 * name, u16 port,
+ u8 is_set)
+{
+ ikev2_profile_t *p = ikev2_profile_index_by_name (name);
+ ikev2_main_t *km = &ikev2_main;
+ vnet_api_error_t rv = 0;
+ uword *v;
+
+ if (!p)
+ return VNET_API_ERROR_INVALID_VALUE;
+
+ if (is_set)
+ {
+ if (p->dst_port != IPSEC_UDP_PORT_NONE)
+ return VNET_API_ERROR_VALUE_EXIST;
+
+ rv = ikev2_register_udp_port (p, port);
+ }
+ else
+ {
+ v = hash_get (km->udp_ports, port);
+ if (!v)
+ return VNET_API_ERROR_IKE_NO_PORT;
+
+ if (p->dst_port == IPSEC_UDP_PORT_NONE)
+ return VNET_API_ERROR_INVALID_VALUE;
+
+ ikev2_unregister_udp_port (p);
+ }
+ return rv;
+}
+
+clib_error_t *
+ikev2_set_profile_udp_encap (vlib_main_t * vm, u8 * name)
+{
+ ikev2_profile_t *p = ikev2_profile_index_by_name (name);
+ clib_error_t *r;
+
+ if (!p)
+ {
+ r = clib_error_return (0, "unknown profile %v", name);
+ return r;
+ }
+
+ p->udp_encap = 1;
+ return 0;
+}
+
clib_error_t *
ikev2_set_profile_sa_lifetime (vlib_main_t * vm, u8 * name,
u64 lifetime, u32 jitter, u32 handover,
ikev2_sa_free_proposal_vector (&proposals);
sa.is_initiator = 1;
- sa.profile_index = km->profiles - p;
+ sa.profile_index = p - km->profiles;
sa.is_profile_index_set = 1;
sa.state = IKEV2_STATE_SA_INIT;
+ sa.tun_itf = p->tun_itf;
+ sa.udp_encap = p->udp_encap;
+ sa.dst_port = p->dst_port;
+ sa.is_tun_itf_set = 1;
+ sa.initial_contact = 1;
ikev2_generate_sa_init_data (&sa);
ikev2_payload_add_ke (chain, sa.dh_group, sa.i_dh_data);
ikev2_payload_add_nonce (chain, sa.i_nonce);
vec_add (sa.childs[0].tsi, &p->loc_ts, 1);
vec_add (sa.childs[0].tsr, &p->rem_ts, 1);
+ ikev2_initial_contact_cleanup (&sa);
+
/* add SA to the pool */
ikev2_sa_t *sa0 = 0;
pool_get (km->sais, sa0);
km->vnet_main = vnet_get_main ();
km->vlib_main = vm;
+ km->liveness_period = IKEV2_LIVENESS_PERIOD_CHECK;
+ km->liveness_max_retries = IKEV2_LIVENESS_RETRIES;
ikev2_crypto_init (km);
mhash_init_vec_string (&km->profile_index_by_name, sizeof (uword));
- vec_validate (km->per_thread_data, tm->n_vlib_mains - 1);
+ vec_validate_aligned (km->per_thread_data, tm->n_vlib_mains - 1,
+ CLIB_CACHE_LINE_BYTES);
for (thread_id = 0; thread_id < tm->n_vlib_mains - 1; thread_id++)
{
km->per_thread_data[thread_id].sa_by_rspi =
km->sa_by_ispi = hash_create (0, sizeof (uword));
km->sw_if_indices = hash_create (0, 0);
+ km->udp_ports = hash_create (0, sizeof (uword));
udp_register_dst_port (vm, 500, ikev2_node.index, 1);
ikev2_cli_reference ();
+ km->log_level = IKEV2_LOG_ERROR;
+ km->log_class = vlib_log_register_class ("ikev2", 0);
return 0;
}
};
/* *INDENT-ON* */
-
static u8
-ikev2_mngr_process_child_sa (ikev2_sa_t * sa, ikev2_child_sa_t * csa)
+ikev2_mngr_process_child_sa (ikev2_sa_t * sa, ikev2_child_sa_t * csa,
+ u8 del_old_ids)
{
ikev2_main_t *km = &ikev2_main;
ikev2_profile_t *p = 0;
}
}
+ if (del_old_ids)
+ {
+ ipip_tunnel_t *ipip = NULL;
+ u32 sw_if_index = sa->is_tun_itf_set ? sa->tun_itf : ~0;
+ if (~0 == sw_if_index)
+ {
+ ip46_address_t local_ip;
+ ip46_address_t remote_ip;
+ if (sa->is_initiator)
+ {
+ ip46_address_set_ip4 (&local_ip, &sa->iaddr);
+ ip46_address_set_ip4 (&remote_ip, &sa->raddr);
+ }
+ else
+ {
+ ip46_address_set_ip4 (&local_ip, &sa->raddr);
+ ip46_address_set_ip4 (&remote_ip, &sa->iaddr);
+ }
+
+ /* *INDENT-OFF* */
+ ipip_tunnel_key_t key = {
+ .src = local_ip,
+ .dst = remote_ip,
+ .transport = IPIP_TRANSPORT_IP4,
+ .fib_index = 0,
+ };
+ /* *INDENT-ON* */
+
+ ipip = ipip_tunnel_db_find (&key);
+
+ if (ipip)
+ sw_if_index = ipip->sw_if_index;
+ else
+ return res;
+ }
+
+ u32 *sas_in = NULL;
+ vec_add1 (sas_in, csa->remote_sa_id);
+ ipsec_tun_protect_update (sw_if_index, NULL, csa->local_sa_id, sas_in);
+ ipsec_sa_unlock_id (ikev2_flip_alternate_sa_bit (csa->remote_sa_id));
+ }
+
return res;
}
return 0;
}
+clib_error_t *
+ikev2_set_liveness_params (u32 period, u32 max_retries)
+{
+ ikev2_main_t *km = &ikev2_main;
+
+ if (period == 0 || max_retries == 0)
+ return clib_error_return (0, "invalid args");
+
+ km->liveness_period = period;
+ km->liveness_max_retries = max_retries;
+ return 0;
+}
+
static void
ikev2_mngr_process_ipsec_sa (ipsec_sa_t * ipsec_sa)
{
}
}
+static void
+ikev2_process_pending_sa_init (ikev2_main_t * km)
+{
+ u32 sai;
+ u64 ispi;
+ ikev2_sa_t *sa;
+
+ /* *INDENT-OFF* */
+ hash_foreach (ispi, sai, km->sa_by_ispi,
+ ({
+ sa = pool_elt_at_index (km->sais, sai);
+ if (sa->init_response_received)
+ continue;
+
+ u32 bi0;
+ if (vlib_buffer_alloc (km->vlib_main, &bi0, 1) != 1)
+ return;
+
+ vlib_buffer_t * b = vlib_get_buffer (km->vlib_main, bi0);
+ clib_memcpy_fast (vlib_buffer_get_current (b),
+ sa->last_sa_init_req_packet_data,
+ vec_len (sa->last_sa_init_req_packet_data));
+ ikev2_send_ike (km->vlib_main, &sa->iaddr, &sa->raddr, bi0,
+ vec_len (sa->last_sa_init_req_packet_data));
+ }));
+ /* *INDENT-ON* */
+}
+
static vlib_node_registration_t ikev2_mngr_process_node;
+static void
+ikev2_send_informational_request (ikev2_sa_t * sa)
+{
+ ikev2_main_t *km = &ikev2_main;
+ ip4_address_t *src, *dst;
+ ike_header_t *ike0;
+ u32 bi0 = 0;
+ int len;
+
+ bi0 = ikev2_get_new_ike_header_buff (km->vlib_main, &ike0);
+
+ ike0->exchange = IKEV2_EXCHANGE_INFORMATIONAL;
+ ike0->ispi = clib_host_to_net_u64 (sa->ispi);
+ ike0->rspi = clib_host_to_net_u64 (sa->rspi);
+ ike0->msgid = clib_host_to_net_u32 (sa->last_init_msg_id + 1);
+ sa->last_init_msg_id = clib_net_to_host_u32 (ike0->msgid);
+ len = ikev2_generate_message (sa, ike0, 0);
+
+ if (sa->is_initiator)
+ {
+ src = &sa->iaddr;
+ dst = &sa->raddr;
+ }
+ else
+ {
+
+ dst = &sa->iaddr;
+ src = &sa->raddr;
+ }
+
+ ikev2_send_ike (km->vlib_main, src, dst, bi0, len);
+}
+
+static_always_inline int
+ikev2_mngr_process_responder_sas (ikev2_sa_t * sa)
+{
+ ikev2_main_t *km = &ikev2_main;
+ vlib_main_t *vm = km->vlib_main;
+
+ if (!sa->sk_ai || !sa->sk_ar)
+ return 0;
+
+ if (sa->liveness_retries >= km->liveness_max_retries)
+ return 1;
+
+ f64 now = vlib_time_now (vm);
+
+ if (sa->liveness_period_check < now)
+ {
+ sa->liveness_retries++;
+ sa->liveness_period_check = now + km->liveness_period;
+ ikev2_send_informational_request (sa);
+ }
+ return 0;
+}
+
static uword
ikev2_mngr_process_fn (vlib_main_t * vm, vlib_node_runtime_t * rt,
vlib_frame_t * f)
{
ikev2_main_t *km = &ikev2_main;
ipsec_main_t *im = &ipsec_main;
+ ikev2_profile_t *p;
+ ikev2_child_sa_t *c;
+ u32 *sai;
while (1)
{
vec_foreach (tkm, km->per_thread_data)
{
ikev2_sa_t *sa;
+ u32 *to_be_deleted = 0;
+
/* *INDENT-OFF* */
pool_foreach (sa, tkm->sas, ({
ikev2_child_sa_t *c;
+ u8 del_old_ids = 0;
+ if (sa->old_remote_id_present && 0 > sa->old_id_expiration)
+ {
+ sa->old_remote_id_present = 0;
+ del_old_ids = 1;
+ }
+ else
+ sa->old_id_expiration -= 1;
+
vec_foreach (c, sa->childs)
{
- req_sent |= ikev2_mngr_process_child_sa(sa, c);
+ req_sent |= ikev2_mngr_process_child_sa(sa, c, del_old_ids);
}
+
+ if (ikev2_mngr_process_responder_sas (sa))
+ vec_add1 (to_be_deleted, sa - tkm->sas);
}));
/* *INDENT-ON* */
+
+ vec_foreach (sai, to_be_deleted)
+ {
+ sa = pool_elt_at_index (tkm->sas, sai[0]);
+ if (sa->is_initiator && sa->is_profile_index_set)
+ {
+ p = pool_elt_at_index (km->profiles, sa->profile_index);
+ if (p)
+ {
+ ikev2_initiate_sa_init (vm, p->name);
+ continue;
+ }
+ }
+ vec_foreach (c, sa->childs)
+ ikev2_delete_tunnel_interface (km->vnet_main, sa, c);
+ hash_unset (tkm->sa_by_rspi, sa->rspi);
+ pool_put (tkm->sas, sa);
+ }
}
/* process ipsec sas */
}));
/* *INDENT-ON* */
+ ikev2_process_pending_sa_init (km);
+
if (req_sent)
{
vlib_process_wait_for_event_or_clock (vm, 5);