return decap_next_index < r->n_next_nodes;
}
-static void
-hash_set_key_copy (uword ** h, void *key, uword v)
-{
- size_t ksz = hash_header (*h)->user;
- void *copy = clib_mem_alloc (ksz);
- clib_memcpy (copy, key, ksz);
- hash_set_mem (*h, copy, v);
-}
-
-static void
-hash_unset_key_free (uword ** h, void *key)
-{
- hash_pair_t *hp = hash_get_pair_mem (*h, key);
- ASSERT (hp);
- key = uword_to_pointer (hp->key, void *);
- hash_unset_mem (*h, key);
- clib_mem_free (key);
-}
-
static uword
vtep_addr_ref (ip46_address_t * ip)
{
return ++(*vtep);
ip46_address_is_ip4 (ip) ?
hash_set (gtpu_main.vtep4, ip->ip4.as_u32, 1) :
- hash_set_key_copy (>pu_main.vtep6, &ip->ip6, 1);
+ hash_set_mem_alloc (>pu_main.vtep6, &ip->ip6, 1);
return 1;
}
return *vtep;
ip46_address_is_ip4 (ip) ?
hash_unset (gtpu_main.vtep4, ip->ip4.as_u32) :
- hash_unset_key_free (>pu_main.vtep6, &ip->ip6);
+ hash_unset_mem_free (>pu_main.vtep6, &ip->ip6);
return 0;
}
.mfib_entry_index = mfei,
};
- hash_set_key_copy (>pu_main.mcast_shared, dst, new_ep.as_u64);
+ hash_set_mem_alloc (>pu_main.mcast_shared, dst, new_ep.as_u64);
}
static inline void
adj_unlock (ep.mcast_adj_index);
mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_GTPU);
- hash_unset_key_free (>pu_main.mcast_shared, dst);
+ hash_unset_mem_free (>pu_main.mcast_shared, dst);
}
static inline fib_protocol_t
/* copy the key */
if (is_ip6)
- hash_set_key_copy (>m->gtpu6_tunnel_by_key, &key6,
- t - gtm->tunnels);
+ hash_set_mem_alloc (>m->gtpu6_tunnel_by_key, &key6,
+ t - gtm->tunnels);
else
hash_set (gtm->gtpu4_tunnel_by_key, key4.as_u64, t - gtm->tunnels);
if (!is_ip6)
hash_unset (gtm->gtpu4_tunnel_by_key, key4.as_u64);
else
- hash_unset_key_free (>m->gtpu6_tunnel_by_key, &key6);
+ hash_unset_mem_free (>m->gtpu6_tunnel_by_key, &key6);
if (!ip46_address_is_multicast (&t->dst))
{
return decap_next_index < r->n_next_nodes;
}
-static void
-hash_set_key_copy (uword ** h, void *key, uword v)
-{
- size_t ksz = hash_header (*h)->user;
- void *copy = clib_mem_alloc (ksz);
- clib_memcpy (copy, key, ksz);
- hash_set_mem (*h, copy, v);
-}
-
-static void
-hash_unset_key_free (uword ** h, void *key)
-{
- hash_pair_t *hp = hash_get_pair_mem (*h, key);
- ASSERT (hp);
- key = uword_to_pointer (hp->key, void *);
- hash_unset_mem (*h, key);
- clib_mem_free (key);
-}
-
static uword
vtep_addr_ref (ip46_address_t * ip)
{
return ++(*vtep);
ip46_address_is_ip4 (ip) ?
hash_set (geneve_main.vtep4, ip->ip4.as_u32, 1) :
- hash_set_key_copy (&geneve_main.vtep6, &ip->ip6, 1);
+ hash_set_mem_alloc (&geneve_main.vtep6, &ip->ip6, 1);
return 1;
}
return *vtep;
ip46_address_is_ip4 (ip) ?
hash_unset (geneve_main.vtep4, ip->ip4.as_u32) :
- hash_unset_key_free (&geneve_main.vtep6, &ip->ip6);
+ hash_unset_mem_free (&geneve_main.vtep6, &ip->ip6);
return 0;
}
.mfib_entry_index = mfei,
};
- hash_set_key_copy (&geneve_main.mcast_shared, remote, new_ep.as_u64);
+ hash_set_mem_alloc (&geneve_main.mcast_shared, remote, new_ep.as_u64);
}
static inline void
adj_unlock (ep.mcast_adj_index);
mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_GENEVE);
- hash_unset_key_free (&geneve_main.mcast_shared, remote);
+ hash_unset_mem_free (&geneve_main.mcast_shared, remote);
}
static inline fib_protocol_t
/* copy the key */
if (is_ip6)
- hash_set_key_copy (&vxm->geneve6_tunnel_by_key, &key6,
- t - vxm->tunnels);
+ hash_set_mem_alloc (&vxm->geneve6_tunnel_by_key, &key6,
+ t - vxm->tunnels);
else
hash_set (vxm->geneve4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
if (!is_ip6)
hash_unset (vxm->geneve4_tunnel_by_key, key4.as_u64);
else
- hash_unset_key_free (&vxm->geneve6_tunnel_by_key, &key6);
+ hash_unset_mem_free (&vxm->geneve6_tunnel_by_key, &key6);
if (!ip46_address_is_multicast (&t->remote))
{
return (0);
}
-static void
-hash_set_key_copy (uword ** h, void *key, uword v)
-{
- size_t ksz = hash_header (*h)->user;
- void *copy = clib_mem_alloc (ksz);
- clib_memcpy (copy, key, ksz);
- hash_set_mem (*h, copy, v);
-}
-
-static void
-hash_unset_key_free (uword ** h, void *key)
-{
- hash_pair_t *hp = hash_get_pair_mem (*h, key);
- ASSERT (hp);
- key = uword_to_pointer (hp->key, void *);
- hash_unset_mem (*h, key);
- clib_mem_free (key);
-}
-
static uword
vtep_addr_ref (ip46_address_t * ip)
{
return ++(*vtep);
ip46_address_is_ip4 (ip) ?
hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) :
- hash_set_key_copy (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
+ hash_set_mem_alloc (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
return 1;
}
return *vtep;
ip46_address_is_ip4 (ip) ?
hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
- hash_unset_key_free (&vxlan_gpe_main.vtep6, &ip->ip6);
+ hash_unset_mem_free (&vxlan_gpe_main.vtep6, &ip->ip6);
return 0;
}
.mfib_entry_index = mfei,
};
- hash_set_key_copy (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
+ hash_set_mem_alloc (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
}
static inline void
adj_unlock (ep.mcast_adj_index);
mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
- hash_unset_key_free (&vxlan_gpe_main.mcast_shared, remote);
+ hash_unset_mem_free (&vxlan_gpe_main.mcast_shared, remote);
}
static inline fib_protocol_t
memset (t, 0, sizeof (*t));
/* copy from arg structure */
+/* *INDENT-OFF* */
#define _(x) t->x = a->x;
foreach_gpe_copy_field;
if (!a->is_ip6)
foreach_copy_ipv4
- else
+ else
foreach_copy_ipv6
#undef _
- if (!a->is_ip6)
- t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
+/* *INDENT-ON* */
+
+ if (!a->is_ip6)
+ t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
if (!a->is_ip6)
{
if (!is_ip6)
hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
else
- hash_unset_key_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
+ hash_unset_mem_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
if (!ip46_address_is_multicast (&t->remote))
{
a->is_add = is_add;
a->is_ip6 = ipv6_set;
+/* *INDENT-OFF* */
#define _(x) a->x = x;
foreach_gpe_copy_field;
if (ipv4_set)
foreach_copy_ipv4
- else
+ else
foreach_copy_ipv6
#undef _
- rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
+/* *INDENT-ON* */
+
+ rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
switch (rv)
{
return decap_next_index < r->n_next_nodes;
}
-static void
-hash_set_key_copy (uword ** h, void * key, uword v) {
- size_t ksz = hash_header(*h)->user;
- void * copy = clib_mem_alloc (ksz);
- clib_memcpy (copy, key, ksz);
- hash_set_mem (*h, copy, v);
-}
-
-static void
-hash_unset_key_free (uword ** h, void * key) {
- hash_pair_t * hp = hash_get_pair_mem (*h, key);
- ASSERT (hp);
- key = uword_to_pointer (hp->key, void *);
- hash_unset_mem (*h, key);
- clib_mem_free (key);
-}
-
static uword
vtep_addr_ref(ip46_address_t *ip)
{
return ++(*vtep);
ip46_address_is_ip4(ip) ?
hash_set (vxlan_main.vtep4, ip->ip4.as_u32, 1) :
- hash_set_key_copy (&vxlan_main.vtep6, &ip->ip6, 1);
+ hash_set_mem_alloc (&vxlan_main.vtep6, &ip->ip6, 1);
return 1;
}
return *vtep;
ip46_address_is_ip4(ip) ?
hash_unset (vxlan_main.vtep4, ip->ip4.as_u32) :
- hash_unset_key_free (&vxlan_main.vtep6, &ip->ip6);
+ hash_unset_mem_free (&vxlan_main.vtep6, &ip->ip6);
return 0;
}
.mfib_entry_index = mfei,
};
- hash_set_key_copy (&vxlan_main.mcast_shared, dst, new_ep.as_u64);
+ hash_set_mem_alloc (&vxlan_main.mcast_shared, dst, new_ep.as_u64);
}
static inline void
mfib_table_entry_delete_index(ep.mfib_entry_index,
MFIB_SOURCE_VXLAN);
- hash_unset_key_free (&vxlan_main.mcast_shared, dst);
+ hash_unset_mem_free (&vxlan_main.mcast_shared, dst);
}
static inline fib_protocol_t
/* copy the key */
if (is_ip6)
- hash_set_key_copy (&vxm->vxlan6_tunnel_by_key, &key6, t - vxm->tunnels);
+ hash_set_mem_alloc (&vxm->vxlan6_tunnel_by_key, &key6,
+ t - vxm->tunnels);
else
hash_set (vxm->vxlan4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
if (!is_ip6)
hash_unset (vxm->vxlan4_tunnel_by_key, key4.as_u64);
else
- hash_unset_key_free (&vxm->vxlan6_tunnel_by_key, &key6);
+ hash_unset_mem_free (&vxm->vxlan6_tunnel_by_key, &key6);
if (!ip46_address_is_multicast(&t->dst))
{
/* Public macro to set (key, value) for pointer key */
#define hash_set_mem(h,key,value) hash_set3 (h, pointer_to_uword (key), (value), 0)
+/* Public inline funcion allocate and copy key to use in hash for pointer key */
+always_inline void
+hash_set_mem_alloc (uword ** h, void *key, uword v)
+{
+ size_t ksz = hash_header (*h)->user;
+ void *copy = clib_mem_alloc (ksz);
+ clib_memcpy (copy, key, ksz);
+ hash_set_mem (*h, copy, v);
+}
+
/* Public macro to set (key, 0) for pointer key */
#define hash_set1_mem(h,key) hash_set3 ((h), pointer_to_uword (key), 0, 0)
/* Public macro to unset (key, value) for pointer key */
#define hash_unset_mem(h,key) ((h) = _hash_unset ((h), pointer_to_uword (key),0))
+/* Public inline funcion to unset pointer key and then free the key memory */
+always_inline void
+hash_unset_mem_free (uword ** h, void *key)
+{
+ hash_pair_t *hp = hash_get_pair_mem (*h, key);
+ ASSERT (hp);
+ key = uword_to_pointer (hp->key, void *);
+ hash_unset_mem (*h, key);
+ clib_mem_free (key);
+}
+
/* internal routine to free a hash table */
extern void *_hash_free (void *v);