GBP: update semantics for subnets 94/18294/2
authorNeale Ranns <nranns@cisco.com>
Thu, 14 Mar 2019 15:06:48 +0000 (08:06 -0700)
committerNeale Ranns <nranns@cisco.com>
Thu, 14 Mar 2019 18:14:35 +0000 (18:14 +0000)
Change-Id: I895c03b365619e6c66613242f4a97c79ce579879
Signed-off-by: Neale Ranns <nranns@cisco.com>
src/plugins/gbp/gbp_subnet.c

index 5e56c82..a7bee55 100644 (file)
@@ -199,12 +199,29 @@ gbp_subnet_l3_out_add (gbp_subnet_t * gs, u32 sw_if_index, sclass_t sclass)
   return (0);
 }
 
+static void
+gbp_subnet_del_i (index_t gsi)
+{
+  gbp_subnet_t *gs;
+
+  gs = pool_elt_at_index (gbp_subnet_pool, gsi);
+
+  if (GBP_SUBNET_L3_OUT == gs->gs_type)
+    fib_table_entry_delete_index (gs->gs_fei, FIB_SOURCE_SPECIAL);
+  else
+    fib_table_entry_delete_index (gs->gs_fei, FIB_SOURCE_PLUGIN_HI);
+
+  gbp_subnet_db_del (gs);
+  gbp_route_domain_unlock (gs->gs_rd);
+
+  pool_put (gbp_subnet_pool, gs);
+}
+
 int
 gbp_subnet_del (u32 rd_id, const fib_prefix_t * pfx)
 {
   gbp_route_domain_t *grd;
   index_t gsi, grdi;
-  gbp_subnet_t *gs;
   u32 fib_index;
 
   grdi = gbp_route_domain_find (rd_id);
@@ -220,17 +237,7 @@ gbp_subnet_del (u32 rd_id, const fib_prefix_t * pfx)
   if (INDEX_INVALID == gsi)
     return (VNET_API_ERROR_NO_SUCH_ENTRY);
 
-  gs = pool_elt_at_index (gbp_subnet_pool, gsi);
-
-  if (GBP_SUBNET_L3_OUT == gs->gs_type)
-    fib_table_entry_delete (fib_index, pfx, FIB_SOURCE_SPECIAL);
-  else
-    fib_table_entry_delete (fib_index, pfx, FIB_SOURCE_PLUGIN_HI);
-
-  gbp_subnet_db_del (gs);
-  gbp_route_domain_unlock (gs->gs_rd);
-
-  pool_put (gbp_subnet_pool, gs);
+  gbp_subnet_del_i (gsi);
 
   return (0);
 }
@@ -256,8 +263,11 @@ gbp_subnet_add (u32 rd_id,
 
   gsi = gbp_subnet_db_find (fib_index, pfx);
 
+  /*
+   * this is an update if the subnet already exists, so remove the old
+   */
   if (INDEX_INVALID != gsi)
-    return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
+    gbp_subnet_del_i (gsi);
 
   rv = -2;