LISP: fix deleting src/dst entry from GID dictionary 42/5142/2
authorFilip Tehlar <ftehlar@cisco.com>
Wed, 15 Feb 2017 12:27:08 +0000 (13:27 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 15 Feb 2017 16:19:32 +0000 (16:19 +0000)
Change-Id: Ic674cc953b45ddd4811e07821e1a0af28b5f6214
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
src/vnet/lisp-cp/gid_dictionary.c
src/vnet/lisp-cp/gid_dictionary.h

index d238124..b01bb0e 100644 (file)
@@ -464,11 +464,15 @@ add_del_ip4_key (gid_ip4_table_t * db, u32 vni, ip_prefix_t * pref, u32 val,
     old_val = value.value;
 
   if (!is_add)
-    BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 0 /* is_add */ );
+    {
+      BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 0 /* is_add */ );
+      db->count--;
+    }
   else
     {
       kv.value = val;
       BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 1 /* is_add */ );
+      db->count++;
     }
   return old_val;
 }
@@ -553,7 +557,6 @@ add_del_sd_ip4_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
     {
       if (GID_LOOKUP_MISS != sfi)
        {
-         add_del_ip4_key (&db->dst_ip4_table, vni, dst_pref, 0, is_add);
          sfib = pool_elt_at_index (db->src_ip4_table_pool, sfi);
          if (src_pref)
            old_val = add_del_ip4_key (sfib, 0, src_pref, 0, is_add);
@@ -563,6 +566,9 @@ add_del_sd_ip4_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
              memset (&sp, 0, sizeof (sp));
              old_val = add_del_ip4_key (sfib, 0, &sp, 0, is_add);
            }
+
+         if (sfib->count == 0)
+           add_del_ip4_key (&db->dst_ip4_table, vni, dst_pref, 0, is_add);
        }
       else
        clib_warning ("cannot delete dst mapping %U!", format_ip_prefix,
@@ -630,11 +636,15 @@ add_del_ip6_key (gid_ip6_table_t * db, u32 vni, ip_prefix_t * pref, u32 val,
     old_val = value.value;
 
   if (!is_add)
-    BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 0 /* is_add */ );
+    {
+      BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 0 /* is_add */ );
+      db->count--;
+    }
   else
     {
       kv.value = val;
       BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 1 /* is_add */ );
+      db->count++;
     }
   return old_val;
 }
@@ -652,11 +662,15 @@ add_del_mac (gid_mac_table_t * db, u32 vni, u8 * dst_mac, u8 * src_mac,
     old_val = value.value;
 
   if (!is_add)
-    BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 0 /* is_add */ );
+    {
+      BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 0 /* is_add */ );
+      db->count--;
+    }
   else
     {
       kv.value = val;
       BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 1 /* is_add */ );
+      db->count++;
     }
   return old_val;
 }
@@ -748,7 +762,6 @@ add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
     {
       if (GID_LOOKUP_MISS != sfi)
        {
-         add_del_ip6_key (&db->dst_ip6_table, vni, dst_pref, 0, is_add);
          sfib = pool_elt_at_index (db->src_ip6_table_pool, sfi);
          if (src_pref)
            old_val = add_del_ip6_key (sfib, 0, src_pref, 0, is_add);
@@ -759,6 +772,9 @@ add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref,
              ip_prefix_version (&sp) = IP6;
              old_val = add_del_ip6_key (sfib, 0, &sp, 0, is_add);
            }
+
+         if (sfib->count == 0)
+           add_del_ip6_key (&db->dst_ip6_table, vni, dst_pref, 0, is_add);
        }
       else
        clib_warning ("cannot delete dst mapping %U!", format_ip_prefix,
index c5aaf8c..825e985 100644 (file)
@@ -50,6 +50,7 @@ typedef struct
   /* ip4 lookup table config parameters */
   u32 ip4_lookup_table_nbuckets;
   uword ip4_lookup_table_size;
+  u32 count;
 } gid_ip4_table_t;
 
 typedef struct
@@ -65,6 +66,7 @@ typedef struct
   /* ip6 lookup table config parameters */
   u32 ip6_lookup_table_nbuckets;
   uword ip6_lookup_table_size;
+  u64 count;
 } gid_ip6_table_t;
 
 typedef struct gid_mac_table
@@ -74,6 +76,7 @@ typedef struct gid_mac_table
   /* mac lookup table config parameters */
   u32 mac_lookup_table_nbuckets;
   uword mac_lookup_table_size;
+  u64 count;
 } gid_mac_table_t;
 
 typedef struct