summaryrefslogtreecommitdiffstats
path: root/src/vnet/sr/sr_steering.c
diff options
context:
space:
mode:
authorPablo Camarillo <pcamaril@cisco.com>2017-03-16 10:43:05 +0100
committerNeale Ranns <nranns@cisco.com>2017-03-29 14:01:49 +0000
commitf60b77c159c794c5a847b76d77a12c584a85bfbd (patch)
tree7431840fb1d2138ae2f60d7ab89e831def4c99e8 /src/vnet/sr/sr_steering.c
parentff077a040194eb3dd80214738d741bc757f4f210 (diff)
Bugfixing and documentation for SRv6
- Fixed three coverity issues - Linked SRv6 docs - Moved sample plugin to examples folder - Fixed bug with hash. Now everything is using mhash. Potentially in the future we want to do bihash. Change-Id: Ie03a13c8fecb1e315e67d0596cbd23220779aaf2 Signed-off-by: Pablo Camarillo <pcamaril@cisco.com>
Diffstat (limited to 'src/vnet/sr/sr_steering.c')
-rwxr-xr-xsrc/vnet/sr/sr_steering.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/vnet/sr/sr_steering.c b/src/vnet/sr/sr_steering.c
index 8d66c5f8ce9..a7b0dd199b1 100755
--- a/src/vnet/sr/sr_steering.c
+++ b/src/vnet/sr/sr_steering.c
@@ -62,14 +62,14 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
u32 sw_if_index, u8 traffic_type)
{
ip6_sr_main_t *sm = &sr_main;
- sr_steering_key_t key, *key_copy;
+ sr_steering_key_t key;
ip6_sr_steering_policy_t *steer_pl;
fib_prefix_t pfx = { 0 };
ip6_sr_policy_t *sr_policy = 0;
uword *p = 0;
- hash_pair_t *hp;
+ memset (&key, 0, sizeof (sr_steering_key_t));
/* Compute the steer policy key */
if (prefix)
@@ -78,6 +78,8 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
key.l3.prefix.as_u64[1] = prefix->as_u64[1];
key.l3.mask_width = mask_width;
key.l3.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
+ if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6)
+ return -1;
}
else
{
@@ -92,12 +94,14 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
vnet_get_sw_interface (sm->vnet_main, sw_if_index);
if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
return -3;
+ if (traffic_type != SR_STEER_L2)
+ return -1;
}
key.traffic_type = traffic_type;
/* Search for the item */
- p = hash_get_mem (sm->steer_policies_index_by_key, &key);
+ p = mhash_get (&sm->sr_steer_policies_hash, &key);
if (p)
{
@@ -152,10 +156,17 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
/* Delete SR steering policy entry */
pool_put (sm->steer_policies, steer_pl);
- hp = hash_get_pair (sm->steer_policies_index_by_key, &key);
- key_copy = (void *) (hp->key);
- hash_unset_mem (sm->steer_policies_index_by_key, &key);
- vec_free (key_copy);
+ mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
+
+ /* If no more SR policies or steering policies */
+ if (!pool_elts (sm->sr_policies) && !pool_elts (sm->steer_policies))
+ {
+ fib_table_unlock (sm->fib_table_ip6, FIB_PROTOCOL_IP6);
+ fib_table_unlock (sm->fib_table_ip4, FIB_PROTOCOL_IP6);
+ sm->fib_table_ip6 = (u32) ~ 0;
+ sm->fib_table_ip4 = (u32) ~ 0;
+ }
+
return 1;
}
else /* It means user requested to update an existing SR steering policy */
@@ -163,7 +174,7 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
/* Retrieve SR steering policy */
if (bsid)
{
- p = hash_get_mem (sm->sr_policy_index_by_key, bsid);
+ p = mhash_get (&sm->sr_policies_index_hash, bsid);
if (p)
sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
else
@@ -192,7 +203,6 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
/* Create a new one */
goto update_fib;
-
}
else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
{
@@ -224,7 +234,7 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
/* Retrieve SR policy */
if (bsid)
{
- p = hash_get_mem (sm->sr_policy_index_by_key, bsid);
+ p = mhash_get (&sm->sr_policies_index_hash, bsid);
if (p)
sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
else
@@ -255,19 +265,14 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
{
/* Incorrect API usage. Should never get here */
pool_put (sm->steer_policies, steer_pl);
- hp = hash_get_pair (sm->steer_policies_index_by_key, &key);
- key_copy = (void *) (hp->key);
- hash_unset_mem (sm->steer_policies_index_by_key, &key);
- vec_free (key_copy);
+ mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
return -1;
}
steer_pl->sr_policy = sr_policy - sm->sr_policies;
/* Create and store key */
- key_copy = vec_new (sr_steering_key_t, 1);
- clib_memcpy (key_copy, &key, sizeof (sr_steering_key_t));
- hash_set_mem (sm->steer_policies_index_by_key,
- key_copy, steer_pl - sm->steer_policies);
+ mhash_set (&sm->sr_steer_policies_hash, &key, steer_pl - sm->steer_policies,
+ NULL);
if (traffic_type == SR_STEER_L2)
{
@@ -347,18 +352,12 @@ update_fib:
cleanup_error_encap:
pool_put (sm->steer_policies, steer_pl);
- hp = hash_get_pair (sm->steer_policies_index_by_key, &key);
- key_copy = (void *) (hp->key);
- hash_unset_mem (sm->steer_policies_index_by_key, &key);
- vec_free (key_copy);
+ mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
return -5;
cleanup_error_redirection:
pool_put (sm->steer_policies, steer_pl);
- hp = hash_get_pair (sm->steer_policies_index_by_key, &key);
- key_copy = (void *) (hp->key);
- hash_unset_mem (sm->steer_policies_index_by_key, &key);
- vec_free (key_copy);
+ mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
return -3;
}
@@ -381,6 +380,8 @@ sr_steer_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
u8 sr_policy_set = 0;
+ memset (&prefix, 0, sizeof (ip46_address_t));
+
int rv;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
@@ -452,7 +453,7 @@ sr_steer_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
"Unable to do SW redirect. Incorrect interface.");
case -4:
return clib_error_return (0,
- "The requested SR policy could not be deleted. Review the BSID/index.");
+ "The requested SR steering policy could not be deleted.");
case -5:
return clib_error_return (0,
"The SR policy is not an encapsulation one.");
@@ -543,8 +544,8 @@ sr_steering_init (vlib_main_t * vm)
ip6_sr_main_t *sm = &sr_main;
/* Init memory for function keys */
- sm->steer_policies_index_by_key =
- hash_create_mem (0, sizeof (sr_steering_key_t), sizeof (uword));
+ mhash_init (&sm->sr_steer_policies_hash, sizeof (uword),
+ sizeof (sr_steering_key_t));
sm->sw_iface_sr_policies = 0;