FIB table add/delete API
[vpp.git] / src / vnet / mfib / ip4_mfib.c
index 08001c3..b248258 100644 (file)
@@ -33,7 +33,8 @@ static const mfib_prefix_t ip4_specials[] = {
 };
 
 static u32
-ip4_create_mfib_with_table_id (u32 table_id)
+ip4_create_mfib_with_table_id (u32 table_id,
+                               mfib_source_t src)
 {
     mfib_table_t *mfib_table;
 
@@ -53,7 +54,7 @@ ip4_create_mfib_with_table_id (u32 table_id)
         mfib_table->v4.table_id =
             table_id;
 
-    mfib_table_lock(mfib_table->mft_index, FIB_PROTOCOL_IP4);
+    mfib_table_lock(mfib_table->mft_index, FIB_PROTOCOL_IP4, src);
 
     /*
      * add the special entries into the new FIB
@@ -72,6 +73,7 @@ ip4_create_mfib_with_table_id (u32 table_id)
         mfib_table_entry_update(mfib_table->mft_index,
                                 &prefix,
                                 MFIB_SOURCE_DEFAULT_ROUTE,
+                                MFIB_RPF_ID_NONE,
                                 MFIB_ENTRY_FLAG_DROP);
     }
 
@@ -112,14 +114,15 @@ ip4_mfib_table_destroy (ip4_mfib_t *mfib)
 }
 
 u32
-ip4_mfib_table_find_or_create_and_lock (u32 table_id)
+ip4_mfib_table_find_or_create_and_lock (u32 table_id,
+                                        mfib_source_t src)
 {
     u32 index;
 
     index = ip4_mfib_index_from_table_id(table_id);
     if (~0 == index)
-        return ip4_create_mfib_with_table_id(table_id);
-    mfib_table_lock(index, FIB_PROTOCOL_IP4);
+        return ip4_create_mfib_with_table_id(table_id, src);
+    mfib_table_lock(index, FIB_PROTOCOL_IP4, src);
 
     return (index);
 }
@@ -279,6 +282,29 @@ ip4_mfib_table_entry_remove (ip4_mfib_t *mfib,
     mfib->fib_entry_by_dst_address[len] = hash;
 }
 
+void
+ip4_mfib_table_walk (ip4_mfib_t *mfib,
+                     mfib_table_walk_fn_t fn,
+                     void *ctx)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++)
+    {
+       uword * hash = mfib->fib_entry_by_dst_address[i];
+
+       if (NULL != hash)
+       {
+           hash_pair_t * p;
+
+           hash_foreach_pair (p, hash,
+           ({
+               fn(p->value[0], ctx);
+           }));
+       }
+    }
+}
+
 static void
 ip4_mfib_table_show_all (ip4_mfib_t *mfib,
                          vlib_main_t * vm)
@@ -358,14 +384,17 @@ ip4_show_mfib (vlib_main_t * vm,
             matching = 1;
             mask = 64;
         }
+        else if (unformat (input, "%U/%d", unformat_ip4_address, &grp, &mask))
+        {
+            memset(&src, 0, sizeof(src));
+            matching = 1;
+        }
         else if (unformat (input, "%U", unformat_ip4_address, &grp))
         {
+            memset(&src, 0, sizeof(src));
             matching = 1;
             mask = 32;
         }
-        else if (unformat (input, "%U/%d",
-                           unformat_ip4_address, &grp, &mask))
-            matching = 1;
         else if (unformat (input, "table %d", &table_id))
             ;
         else if (unformat (input, "index %d", &fib_index))
@@ -457,9 +486,9 @@ ip4_show_mfib (vlib_main_t * vm,
  * @cliexend
  ?*/
 /* *INDENT-OFF* */
-VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
+VLIB_CLI_COMMAND (ip4_show_mfib_command, static) = {
     .path = "show ip mfib",
-    .short_help = "show ip mfib [summary] [table <table-id>] [index <fib-id>] [<gre-addr>[/<mask>]] [<gre-addr>] [<src-addr> <gre-addr>]",
+    .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* */