ipsec_sa_t *sa;
hi = vnet_get_hw_interface (vnm, hw_if_index);
+ t = pool_elt_at_index (im->tunnel_interfaces, hi->hw_instance);
+
if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
{
- t = pool_elt_at_index (im->tunnel_interfaces, hi->hw_instance);
ASSERT (im->cb.check_support_cb);
+
sa = pool_elt_at_index (im->sad, t->input_sa_index);
+
err = im->cb.check_support_cb (sa);
if (err)
return err;
+ if (im->cb.add_del_sa_sess_cb)
+ {
+ err = im->cb.add_del_sa_sess_cb (t->input_sa_index, 1);
+ if (err)
+ return err;
+ }
+
sa = pool_elt_at_index (im->sad, t->output_sa_index);
+
err = im->cb.check_support_cb (sa);
if (err)
return err;
+ if (im->cb.add_del_sa_sess_cb)
+ {
+ err = im->cb.add_del_sa_sess_cb (t->output_sa_index, 1);
+ if (err)
+ return err;
+ }
+
vnet_hw_interface_set_flags (vnm, hw_if_index,
VNET_HW_INTERFACE_FLAG_LINK_UP);
}
else
- vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */ );
+ {
+ vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */ );
+
+ sa = pool_elt_at_index (im->sad, t->input_sa_index);
+
+ if (im->cb.add_del_sa_sess_cb)
+ {
+ err = im->cb.add_del_sa_sess_cb (t->input_sa_index, 0);
+ if (err)
+ return err;
+ }
+
+ sa = pool_elt_at_index (im->sad, t->output_sa_index);
+
+ if (im->cb.add_del_sa_sess_cb)
+ {
+ err = im->cb.add_del_sa_sess_cb (t->output_sa_index, 0);
+ if (err)
+ return err;
+ }
+ }
return /* no error */ 0;
}
{
.name = "IPSec",
.build_rewrite = default_build_rewrite,
+ .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
};
/* *INDENT-ON* */
args->remote_crypto_key_len);
}
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->input_sa_index, args->is_add) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
-
pool_get (im->sad, sa);
memset (sa, 0, sizeof (*sa));
t->output_sa_index = sa - im->sad;
sa->tunnel_src_addr.ip4.as_u32 = args->local_ip.as_u32;
sa->tunnel_dst_addr.ip4.as_u32 = args->remote_ip.as_u32;
sa->is_tunnel = 1;
- sa->seq = 1;
sa->use_esn = args->esn;
sa->use_anti_replay = args->anti_replay;
sa->integ_alg = args->integ_alg;
args->local_crypto_key_len);
}
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->output_sa_index, args->is_add) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
-
hash_set (im->ipsec_if_pool_index_by_key, key,
t - im->tunnel_interfaces);
}
else
{
+ vnet_interface_main_t *vim = &vnm->interface_main;
+
/* check if exists */
if (!p)
return VNET_API_ERROR_INVALID_VALUE;
vnet_sw_interface_set_flags (vnm, hi->sw_if_index, 0); /* admin down */
vec_add1 (im->free_tunnel_if_indices, t->hw_if_index);
+ vnet_interface_counter_lock (vim);
+ vlib_zero_combined_counter (vim->combined_sw_if_counters +
+ VNET_INTERFACE_COUNTER_TX, hi->sw_if_index);
+ vlib_zero_combined_counter (vim->combined_sw_if_counters +
+ VNET_INTERFACE_COUNTER_RX, hi->sw_if_index);
+ vnet_interface_counter_unlock (vim);
+
/* delete input and output SA */
sa = pool_elt_at_index (im->sad, t->input_sa_index);
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->input_sa_index, args->is_add) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
-
pool_put (im->sad, sa);
sa = pool_elt_at_index (im->sad, t->output_sa_index);
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->output_sa_index, args->is_add) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
-
pool_put (im->sad, sa);
hash_unset (im->ipsec_if_pool_index_by_key, key);
hi = vnet_get_hw_interface (vnm, hw_if_index);
t = pool_elt_at_index (im->tunnel_interfaces, hi->dev_instance);
+ if (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP)
+ return VNET_API_ERROR_SYSCALL_ERROR_1;
+
if (type == IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO)
{
sa = pool_elt_at_index (im->sad, t->output_sa_index);
sa->crypto_alg = alg;
sa->crypto_key_len = vec_len (key);
clib_memcpy (sa->crypto_key, key, vec_len (key));
-
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->output_sa_index, 0) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
}
else if (type == IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG)
{
sa->integ_alg = alg;
sa->integ_key_len = vec_len (key);
clib_memcpy (sa->integ_key, key, vec_len (key));
-
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->output_sa_index, 0) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
}
else if (type == IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO)
{
sa->crypto_alg = alg;
sa->crypto_key_len = vec_len (key);
clib_memcpy (sa->crypto_key, key, vec_len (key));
-
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->input_sa_index, 0) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
}
else if (type == IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG)
{
sa->integ_alg = alg;
sa->integ_key_len = vec_len (key);
clib_memcpy (sa->integ_key, key, vec_len (key));
-
- if (im->cb.add_del_sa_sess_cb &&
- im->cb.add_del_sa_sess_cb (t->input_sa_index, 0) < 0)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
}
else
return VNET_API_ERROR_INVALID_VALUE;