Unify and cleanup usage of hash_set/unset_mem by various tunnels
[vpp.git] / src / vnet / vxlan / vxlan.c
index a6e799f..5926062 100644 (file)
@@ -263,23 +263,6 @@ vxlan_decap_next_is_valid (vxlan_main_t * vxm, u32 is_ip6, u32 decap_next_index)
   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)
 {
@@ -290,7 +273,7 @@ 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;
 }
 
@@ -305,7 +288,7 @@ vtep_addr_unref(ip46_address_t *ip)
                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;
 }
 
@@ -336,7 +319,7 @@ mcast_shared_add(ip46_address_t *dst,
         .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
@@ -348,7 +331,7 @@ mcast_shared_remove(ip46_address_t *dst)
     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
@@ -415,7 +398,8 @@ int vnet_vxlan_add_del_tunnel
 
       /* 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);
 
@@ -588,7 +572,7 @@ int vnet_vxlan_add_del_tunnel
       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))
         {