fib: multiple memory leaks upon deleting a VRF table
[vpp.git] / src / vnet / mfib / ip4_mfib.c
index 6973380..2ad873f 100644 (file)
@@ -42,6 +42,18 @@ static const mfib_prefix_t ip4_specials[] =
         .fp_proto = FIB_PROTOCOL_IP4,
     },
 };
+static const fib_route_path_t ip4_special_path =
+  {
+   .frp_proto = DPO_PROTO_IP4,
+   .frp_addr = {
+               .ip4.data_u32 = 0x0,
+               },
+   .frp_sw_if_index = ~0,
+   .frp_fib_index = ~0,
+   .frp_weight = 1,
+   .frp_flags = FIB_ROUTE_PATH_LOCAL,
+   .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
+  };
 
 static u32
 ip4_create_mfib_with_table_id (u32 table_id,
@@ -76,15 +88,6 @@ ip4_create_mfib_with_table_id (u32 table_id,
                             MFIB_RPF_ID_NONE,
                             MFIB_ENTRY_FLAG_DROP);
 
-    const fib_route_path_t path = {
-        .frp_proto = DPO_PROTO_IP4,
-        .frp_addr = zero_addr,
-        .frp_sw_if_index = ~0,
-        .frp_fib_index = ~0,
-        .frp_weight = 1,
-        .frp_flags = FIB_ROUTE_PATH_LOCAL,
-        .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
-    };
     int ii;
 
     for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
@@ -92,7 +95,8 @@ ip4_create_mfib_with_table_id (u32 table_id,
         mfib_table_entry_path_update(mfib_table->mft_index,
                                      &ip4_specials[ii],
                                      MFIB_SOURCE_SPECIAL,
-                                     &path);
+                                     MFIB_ENTRY_FLAG_NONE,
+                                     &ip4_special_path);
     }
 
     return (mfib_table->mft_index);
@@ -112,11 +116,12 @@ ip4_mfib_table_destroy (ip4_mfib_t *mfib)
                             MFIB_SOURCE_DEFAULT_ROUTE);
 
     for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
-    {
-        mfib_table_entry_delete(mfib_table->mft_index,
-                                &ip4_specials[ii],
-                                MFIB_SOURCE_SPECIAL);
-    }
+      {
+       mfib_table_entry_path_remove(mfib_table->mft_index,
+                                    &ip4_specials[ii],
+                                    MFIB_SOURCE_SPECIAL,
+                                    &ip4_special_path);
+      }
 
     /*
      * validate no more routes.
@@ -124,6 +129,8 @@ ip4_mfib_table_destroy (ip4_mfib_t *mfib)
     ASSERT(0 == mfib_table->mft_total_route_counts);
     ASSERT(~0 != mfib_table->mft_table_id);
 
+    for (u32 i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++)
+      hash_free (mfib->fib_entry_by_dst_address[i]);
     hash_unset (ip4_main.mfib_index_by_table_id, mfib_table->mft_table_id);
     pool_put(ip4_main.mfibs, mfib_table);
 }
@@ -142,7 +149,6 @@ ip4_mfib_interface_enable_disable (u32 sw_if_index, int is_enable)
     u32 mfib_index;
     int ii;
 
-    vec_validate (ip4_main.mfib_index_by_sw_if_index, sw_if_index);
     mfib_index = ip4_mfib_table_get_index_for_sw_if_index(sw_if_index);
 
     for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
@@ -152,6 +158,7 @@ ip4_mfib_interface_enable_disable (u32 sw_if_index, int is_enable)
             mfib_table_entry_path_update(mfib_index,
                                          &ip4_specials[ii],
                                          MFIB_SOURCE_SPECIAL,
+                                         MFIB_ENTRY_FLAG_NONE,
                                          &path);
         }
         else
@@ -396,8 +403,8 @@ format_ip4_mfib_table_memory (u8 * s, va_list * args)
 
     total_memory = 0;
 
-    pool_foreach (mfib_table, ip4_main.mfibs,
-    ({
+    pool_foreach (mfib_table, ip4_main.mfibs)
+     {
         ip4_mfib_t *mfib = &mfib_table->v4;
         uword mfib_size;
         int i;
@@ -415,7 +422,7 @@ format_ip4_mfib_table_memory (u8 * s, va_list * args)
         }
 
         total_memory += mfib_size;
-    }));
+    }
 
     s = format(s, "%=30s %=6d %=12ld\n",
                "IPv4 multicast",
@@ -525,8 +532,8 @@ ip4_show_mfib (vlib_main_t * vm,
             break;
     }
 
-    pool_foreach (mfib_table, im4->mfibs,
-    ({
+    pool_foreach (mfib_table, im4->mfibs)
+     {
         ip4_mfib_t *mfib = &mfib_table->v4;
 
         if (table_id >= 0 && table_id != (int)mfib->table_id)
@@ -584,19 +591,20 @@ ip4_show_mfib (vlib_main_t * vm,
         {
             ip4_mfib_table_show_one(mfib, vm, &src, &grp, mask);
         }
-    }));
+    }
     if (memory)
         vlib_cli_output (vm, "totals: hash:%ld", total_hash_memory);
 
     return 0;
 }
 
+/* clang-format off */
 /*?
  * This command displays the IPv4 MulticasrFIB Tables (VRF Tables) and
  * the route entries for each table.
  *
  * @note This command will run for a long time when the FIB tables are
- * comprised of millions of entries. For those senarios, consider displaying
+ * comprised of millions of entries. For those scenarios, consider displaying
  * a single table or summary mode.
  *
  * @cliexpar
@@ -633,10 +641,9 @@ ip4_show_mfib (vlib_main_t * vm,
  *                   32               4
  * @cliexend
  ?*/
-/* *INDENT-OFF* */
+/* clang-format on */
 VLIB_CLI_COMMAND (ip4_show_mfib_command, static) = {
     .path = "show ip mfib",
     .short_help = "show ip mfib [summary] [table <table-id>] [index <fib-id>] [<grp-addr>[/<mask>]] [<grp-addr>] [<src-addr> <grp-addr>]",
     .function = ip4_show_mfib,
 };
-/* *INDENT-ON* */