ipsec: enable UDP encap for IPv6 ESP tun protect
[vpp.git] / src / vnet / fib / fib_entry.c
index a2e2a1e..b78346c 100644 (file)
 #include <vnet/fib/fib_internal.h>
 #include <vnet/fib/fib_attached_export.h>
 #include <vnet/fib/fib_path_ext.h>
+#include <vnet/fib/fib_entry_delegate.h>
+#include <vnet/fib/fib_entry_track.h>
 
 /*
  * Array of strings/names for the FIB sources
  */
-static const char *fib_source_names[] = FIB_SOURCES;
 static const char *fib_attribute_names[] = FIB_ENTRY_ATTRIBUTES;
 static const char *fib_src_attribute_names[] = FIB_ENTRY_SRC_ATTRIBUTES;
 
@@ -95,16 +96,6 @@ fib_entry_get_default_chain_type (const fib_entry_t *fib_entry)
     return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
 }
 
-u8 *
-format_fib_source (u8 * s, va_list * args)
-{
-    fib_source_t source = va_arg (*args, int);
-
-    s = format (s, "src:%s", fib_source_names[source]);
-
-    return (s);
-}
-
 u8 *
 format_fib_entry_flags (u8 *s, va_list *args)
 {
@@ -203,14 +194,13 @@ format_fib_entry (u8 * s, va_list * args)
 
         if (level >= FIB_ENTRY_FORMAT_DETAIL2)
         {
-            fib_entry_delegate_type_t fdt;
-            fib_entry_delegate_t *fed;
+            index_t *fedi;
 
             s = format (s, " Delegates:\n");
-            FOR_EACH_DELEGATE(fib_entry, fdt, fed,
+            vec_foreach(fedi, fib_entry->fe_delegates)
             {
-                s = format(s, "  %U\n", format_fib_entry_deletegate, fed);
-            });
+                s = format(s, "  %U\n", format_fib_entry_delegate, *fedi);
+            }
         }
     }
 
@@ -284,7 +274,7 @@ fib_entry_src_get_source (const fib_entry_src_t *esrc)
     {
        return (esrc->fes_src);
     }
-    return (FIB_SOURCE_MAX);
+    return (FIB_SOURCE_INVALID);
 }
 
 static fib_entry_flag_t
@@ -303,58 +293,6 @@ fib_entry_get_flags (fib_node_index_t fib_entry_index)
     return (fib_entry_get_flags_i(fib_entry_get(fib_entry_index)));
 }
 
-/*
- * fib_entry_back_walk_notify
- *
- * A back walk has reach this entry.
- */
-static fib_node_back_walk_rc_t
-fib_entry_back_walk_notify (fib_node_t *node,
-                           fib_node_back_walk_ctx_t *ctx)
-{
-    fib_entry_t *fib_entry;
-
-    fib_entry = fib_entry_from_fib_node(node);
-
-    if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason        ||
-        FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason      ||
-        FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason        ||
-       FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason    ||
-       FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason  ||
-       FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
-    {
-       fib_entry_src_action_reactivate(fib_entry,
-                                        fib_entry_get_best_source(
-                                            fib_entry_get_index(fib_entry)));
-    }
-
-    /*
-     * all other walk types can be reclassifed to a re-evaluate to
-     * all recursive dependents.
-     * By reclassifying we ensure that should any of these walk types meet
-     * they can be merged.
-     */
-    ctx->fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE;
-
-    /*
-     * ... and nothing is forced sync from now on.
-     */
-    ctx->fnbw_flags &= ~FIB_NODE_BW_FLAG_FORCE_SYNC;
-
-    FIB_ENTRY_DBG(fib_entry, "bw:%U",
-                  format_fib_node_bw_reason, ctx->fnbw_reason);
-
-    /*
-     * propagate the backwalk further if we haven't already reached the
-     * maximum depth.
-     */
-    fib_walk_sync(FIB_NODE_TYPE_ENTRY,
-                 fib_entry_get_index(fib_entry),
-                 ctx);
-
-    return (FIB_NODE_BACK_WALK_CONTINUE);
-}
-
 static void
 fib_entry_show_memory (void)
 {
@@ -367,14 +305,14 @@ fib_entry_show_memory (void)
                          pool_len(fib_entry_pool),
                          sizeof(fib_entry_t));
 
-    pool_foreach(entry, fib_entry_pool,
-    ({
+    pool_foreach (entry, fib_entry_pool)
+     {
        n_srcs += vec_len(entry->fe_srcs);
        vec_foreach(esrc, entry->fe_srcs)
        {
            n_exts += fib_path_ext_list_length(&esrc->fes_path_exts);
        }
-    }));
+    }
 
     fib_show_memory_usage("Entry Source",
                          n_srcs, n_srcs, sizeof(fib_entry_src_t));
@@ -383,16 +321,6 @@ fib_entry_show_memory (void)
                          sizeof(fib_path_ext_t));
 }
 
-/*
- * The FIB path-list's graph node virtual function table
- */
-static const fib_node_vft_t fib_entry_vft = {
-    .fnv_get = fib_entry_get_node,
-    .fnv_last_lock = fib_entry_last_lock_gone,
-    .fnv_back_walk = fib_entry_back_walk_notify,
-    .fnv_mem_show = fib_entry_show_memory,
-};
-
 /**
  * @brief Contribute the set of Adjacencies that this entry forwards with
  * to build the uRPF list of its children
@@ -464,14 +392,17 @@ fib_entry_contribute_forwarding (fib_node_index_t fib_entry_index,
     }
     else
     {
-        fed = fib_entry_delegate_get(fib_entry,
-                                     fib_entry_chain_type_to_delegate_type(fct));
+        fed = fib_entry_delegate_find(fib_entry,
+                                      fib_entry_chain_type_to_delegate_type(fct));
 
         if (NULL == fed)
         {
-            fed = fib_entry_delegate_find_or_add(
-                      fib_entry,
-                      fib_entry_chain_type_to_delegate_type(fct));
+            /*
+             * use a temporary DPO lest the delegate realloc in the recursive
+             * calculation.
+             */
+            dpo_id_t tmp = DPO_INVALID;
+
             /*
              * on-demand create eos/non-eos.
              * There is no on-demand delete because:
@@ -480,9 +411,16 @@ fib_entry_contribute_forwarding (fib_node_index_t fib_entry_index,
              *      then up on the right trigger is more code. i favour the latter.
              */
             fib_entry_src_mk_lb(fib_entry,
-                                fib_entry_get_best_src_i(fib_entry),
+                                fib_entry_get_best_source(fib_entry_index),
                                 fct,
-                                &fed->fd_dpo);
+                                &tmp);
+
+            fed = fib_entry_delegate_find_or_add(
+                fib_entry,
+                fib_entry_chain_type_to_delegate_type(fct));
+
+            dpo_copy(&fed->fd_dpo, &tmp);
+            dpo_reset(&tmp);
         }
 
         dpo_copy(dpo, &fed->fd_dpo);
@@ -599,8 +537,18 @@ fib_entry_alloc (u32 fib_index,
 {
     fib_entry_t *fib_entry;
     fib_prefix_t *fep;
+    u8 need_barrier_sync = pool_get_will_expand (fib_entry_pool);
+    vlib_main_t *vm = vlib_get_main();
+    ASSERT (vm->thread_index == 0);
+
+    if (need_barrier_sync)
+        vlib_worker_thread_barrier_sync (vm);
 
     pool_get(fib_entry_pool, fib_entry);
+
+    if (need_barrier_sync)
+        vlib_worker_thread_barrier_release (vm);
+
     clib_memset(fib_entry, 0, sizeof(*fib_entry));
 
     fib_node_init(&fib_entry->fe_node,
@@ -634,7 +582,8 @@ fib_entry_alloc (u32 fib_index,
 
 static fib_entry_t*
 fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
-                                   fib_entry_flag_t old_flags)
+                                   fib_entry_flag_t old_flags,
+                                    u32 new_fib_index)
 {
     fib_node_index_t fei;
 
@@ -659,12 +608,14 @@ fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
         * there is an assumption here that the entry resolves via only
         * one interface and that it is the cross VRF interface.
         */
-       u32 sw_if_index = fib_path_list_get_resolving_interface(fib_entry->fe_parent);
-
-       fib_attached_export_import(fib_entry,
-                                  fib_table_get_index_for_sw_if_index(
-                                      fib_entry_get_proto(fib_entry),
-                                       sw_if_index));
+        if (~0 == new_fib_index)
+        {
+            u32 sw_if_index = fib_path_list_get_resolving_interface(fib_entry->fe_parent);
+            new_fib_index = fib_table_get_index_for_sw_if_index(
+                fib_entry_get_proto(fib_entry),
+                sw_if_index);
+        }
+        fib_attached_export_import(fib_entry, new_fib_index);
     }
     else if (was_import && !is_import)
     {
@@ -673,6 +624,14 @@ fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
         */
        fib_attached_export_purge(fib_entry);
     }
+    else if (was_import && is_import && ~0 != new_fib_index)
+    {
+        /*
+         * transition from export from one table to another
+         */
+        fib_attached_export_purge(fib_entry);
+        fib_attached_export_import(fib_entry, new_fib_index);
+    }
     /*
      * else
      *   no change. nothing to do.
@@ -701,14 +660,15 @@ fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
     return (fib_entry);
 }
 
-static void
+static fib_entry_t*
 fib_entry_post_install_actions (fib_entry_t *fib_entry,
                                fib_source_t source,
                                fib_entry_flag_t old_flags)
 {
-    fib_entry = fib_entry_post_flag_update_actions(fib_entry,
-                                                   old_flags);
-    fib_entry_src_action_installed(fib_entry, source);
+    fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags, ~0);
+    fib_entry = fib_entry_src_action_installed(fib_entry, source);
+
+    return (fib_entry);
 }
 
 fib_node_index_t
@@ -743,7 +703,8 @@ fib_entry_create (u32 fib_index,
     fib_entry = fib_entry_get(fib_entry_index);
     fib_entry_src_action_activate(fib_entry, source);
 
-    fib_entry_post_install_actions(fib_entry, source, FIB_ENTRY_FLAG_NONE);
+    fib_entry = fib_entry_post_install_actions(fib_entry, source,
+                                               FIB_ENTRY_FLAG_NONE);
 
     FIB_ENTRY_DBG(fib_entry, "create");
 
@@ -761,7 +722,7 @@ fib_entry_create_special (u32 fib_index,
     fib_entry_t *fib_entry;
 
     /*
-     * create and initiliase the new enty
+     * create and initialize the new enty
      */
     fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
 
@@ -771,7 +732,8 @@ fib_entry_create_special (u32 fib_index,
     fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
     fib_entry_src_action_activate(fib_entry, source);
 
-    fib_entry_post_install_actions(fib_entry, source, FIB_ENTRY_FLAG_NONE);
+    fib_entry = fib_entry_post_install_actions(fib_entry, source,
+                                               FIB_ENTRY_FLAG_NONE);
 
     FIB_ENTRY_DBG(fib_entry, "create-special");
 
@@ -821,16 +783,17 @@ fib_entry_source_change_w_flags (fib_entry_t *fib_entry,
                                  fib_entry_flag_t old_flags,
                                  fib_source_t new_source)
 {
-    if (new_source < old_source)
+    switch (fib_source_cmp(new_source, old_source))
     {
+    case FIB_SOURCE_CMP_BETTER:
        /*
         * we have a new winning source.
         */
        fib_entry_src_action_deactivate(fib_entry, old_source);
        fib_entry_src_action_activate(fib_entry, new_source);
-    }
-    else if (new_source > old_source)
-    {
+        break;
+
+    case FIB_SOURCE_CMP_WORSE:
         /*
          * the new source loses. Re-activate the winning sources
          * in case it is an interposer and hence relied on the losing
@@ -838,15 +801,15 @@ fib_entry_source_change_w_flags (fib_entry_t *fib_entry,
          */
         fib_entry_src_action_reactivate(fib_entry, old_source);
         return;
-    }
-    else
-    {
+
+    case FIB_SOURCE_CMP_EQUAL:
        /*
         * the new source is one this entry already has.
         * But the path-list was updated, which will contribute new forwarding,
         * so install it.
         */
         fib_entry_src_action_reactivate(fib_entry, new_source);
+        break;
     }
 
     fib_entry_post_update_actions(fib_entry, new_source, old_flags);
@@ -906,21 +869,19 @@ void
 fib_entry_path_add (fib_node_index_t fib_entry_index,
                    fib_source_t source,
                    fib_entry_flag_t flags,
-                   const fib_route_path_t *rpath)
+                   const fib_route_path_t *rpaths)
 {
     fib_source_t best_source;
     fib_entry_t *fib_entry;
     fib_entry_src_t *bsrc;
 
-    ASSERT(1 == vec_len(rpath));
-
     fib_entry = fib_entry_get(fib_entry_index);
     ASSERT(NULL != fib_entry);
 
     bsrc = fib_entry_get_best_src_i(fib_entry);
     best_source = fib_entry_src_get_source(bsrc);
     
-    fib_entry = fib_entry_src_action_path_add(fib_entry, source, flags, rpath);
+    fib_entry = fib_entry_src_action_path_add(fib_entry, source, flags, rpaths);
 
     fib_entry_source_change(fib_entry, best_source, source);
 
@@ -971,12 +932,12 @@ fib_entry_source_removed (fib_entry_t *fib_entry,
     bsrc = fib_entry_get_best_src_i(fib_entry);
     best_source = fib_entry_src_get_source(bsrc);
 
-    if (FIB_SOURCE_MAX == best_source)
+    if (FIB_SOURCE_INVALID == best_source)
     {
         /*
          * no more sources left. this entry is toast.
          */
-        fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags);
+        fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags, ~0);
         fib_entry_src_action_uninstall(fib_entry);
 
         return (FIB_ENTRY_SRC_FLAG_NONE);
@@ -1003,7 +964,7 @@ fib_entry_source_removed (fib_entry_t *fib_entry,
 fib_entry_src_flag_t
 fib_entry_path_remove (fib_node_index_t fib_entry_index,
                       fib_source_t source,
-                      const fib_route_path_t *rpath)
+                      const fib_route_path_t *rpaths)
 {
     fib_entry_src_flag_t sflag;
     fib_source_t best_source;
@@ -1011,8 +972,6 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
     fib_entry_t *fib_entry;
     fib_entry_src_t *bsrc;
 
-    ASSERT(1 == vec_len(rpath));
-
     fib_entry = fib_entry_get(fib_entry_index);
     ASSERT(NULL != fib_entry);
 
@@ -1020,7 +979,7 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
     best_source = fib_entry_src_get_source(bsrc);
     bflags = fib_entry_src_get_flags(bsrc);
 
-    sflag = fib_entry_src_action_path_remove(fib_entry, source, rpath);
+    sflag = fib_entry_src_action_path_remove(fib_entry, source, rpaths);
 
     FIB_ENTRY_DBG(fib_entry, "path remove:%U", format_fib_source, source);
 
@@ -1029,16 +988,16 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
      * then we need to create a new one. else we are updating
      * an existing.
      */
-    if (source < best_source)
+    switch (fib_source_cmp(source, best_source))
     {
+    case FIB_SOURCE_CMP_BETTER:
        /*
         * Que! removing a path from a source that is better than the
         * one this entry is using.
         */
        ASSERT(0);
-    }
-    else if (source > best_source )
-    {
+        break;
+    case FIB_SOURCE_CMP_WORSE:
        /*
         * the source is not the best. no need to update forwarding
         */
@@ -1056,10 +1015,9 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
              * that remain are non-inherited
              */
             return (fib_entry_src_burn_only_inherited(fib_entry));
-       }
-    }
-    else
-    {
+        }
+        break;
+    case FIB_SOURCE_CMP_EQUAL:
        /*
         * removing a path from the path-list we were using.
         */
@@ -1078,6 +1036,7 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
             */
            fib_entry_src_action_reactivate(fib_entry, source);
        }
+        break;
     }
 
     fib_entry_post_update_actions(fib_entry, source, bflags);
@@ -1120,16 +1079,17 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
      * then we need to create a new one. else we are updating
      * an existing.
      */
-    if (source < best_source )
+    switch (fib_source_cmp(source, best_source))
     {
+    case FIB_SOURCE_CMP_BETTER:
        /*
         * Que! removing a path from a source that is better than the
         * one this entry is using. This can only mean it is a source
          * this prefix does not have.
         */
         return (FIB_ENTRY_SRC_FLAG_ADDED);
-    }
-    else if (source > best_source ) {
+
+    case FIB_SOURCE_CMP_WORSE:
        /*
         * the source is not the best. no need to update forwarding
         */
@@ -1151,7 +1111,7 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
                 /*
                  * no more sources left. this entry is toast.
                  */
-                fib_entry = fib_entry_post_flag_update_actions(fib_entry, bflags);
+                fib_entry = fib_entry_post_flag_update_actions(fib_entry, bflags, ~0);
                 fib_entry_src_action_uninstall(fib_entry);
                 return (FIB_ENTRY_SRC_FLAG_NONE);
             }
@@ -1163,9 +1123,9 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
 
             return (FIB_ENTRY_SRC_FLAG_ADDED);
         }
-    }
-    else
-    {
+        break;
+
+    case FIB_SOURCE_CMP_EQUAL:
        if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
        {
            /*
@@ -1180,6 +1140,7 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
             */
            fib_entry_src_action_reactivate(fib_entry, source);
        }
+        break;
     }
 
     fib_entry_post_update_actions(fib_entry, source, bflags);
@@ -1193,7 +1154,7 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
 /**
  * fib_entry_inherit
  *
- * If the source on the cover is inherting then push this source
+ * If the source on the cover is inheriting then push this source
  * down to the covered.
  */
 void
@@ -1275,7 +1236,7 @@ fib_entry_cover_changed (fib_node_index_t fib_entry_index)
     fib_attached_export_cover_change(fib_entry);
 
     /*
-     * propagate the notificuation to each of the added sources
+     * propagate the notification to each of the added sources
      */
     index = 0;
     FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
@@ -1301,7 +1262,9 @@ fib_entry_cover_changed (fib_node_index_t fib_entry_index)
        fib_entry_src_action_reactivate(fib_entry,
                                        fib_entry_src_get_source(
                                            fib_entry_get_best_src_i(fib_entry)));
-        fib_entry_post_install_actions(fib_entry, best_source, bflags);
+        fib_entry = fib_entry_post_install_actions(fib_entry,
+                                                   best_source,
+                                                   bflags);
     }
     else
     {
@@ -1349,7 +1312,7 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index)
     fib_attached_export_cover_update(fib_entry);
 
     /*
-     * propagate the notificuation to each of the added sources
+     * propagate the notification to each of the added sources
      */
     index = 0;
     FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
@@ -1357,7 +1320,7 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index)
        if (0 == index)
        {
            /*
-            * only the best source gets to set the back walk flags
+            * only the best source gets to set the install result
             */
            res = fib_entry_src_action_cover_update(fib_entry, esrc);
             bflags = fib_entry_src_get_flags(esrc);
@@ -1365,7 +1328,23 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index)
        }
        else
        {
-           fib_entry_src_action_cover_update(fib_entry, esrc);
+           /*
+            * contirubting sources can set backwalk flags
+            */
+            if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING)
+            {
+                fib_entry_src_cover_res_t tmp = {
+                    .install = !0,
+                    .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
+                };
+
+                tmp = fib_entry_src_action_cover_update(fib_entry, esrc);
+                res.bw_reason |= tmp.bw_reason;
+            }
+            else
+            {
+                fib_entry_src_action_cover_update(fib_entry, esrc);
+            }
        }
        index++;
     }));
@@ -1375,7 +1354,9 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index)
        fib_entry_src_action_reactivate(fib_entry,
                                        fib_entry_src_get_source(
                                            fib_entry_get_best_src_i(fib_entry)));
-        fib_entry_post_install_actions(fib_entry, best_source, bflags);
+        fib_entry = fib_entry_post_install_actions(fib_entry,
+                                                   best_source,
+                                                   bflags);
     }
     else
     {
@@ -1428,7 +1409,7 @@ fib_entry_recursive_loop_detect (fib_node_index_t entry_index,
             FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
             {
                 fib_entry_src_mk_lb(fib_entry,
-                                    fib_entry_get_best_src_i(fib_entry),
+                                    fib_entry_get_best_source(entry_index),
                                     fib_entry_delegate_type_to_chain_type(fdt),
                                     &fed->fd_dpo);
            });
@@ -1447,6 +1428,126 @@ fib_entry_recursive_loop_detect (fib_node_index_t entry_index,
     return (is_looped);
 }
 
+/*
+ * fib_entry_attached_cross_table
+ *
+ * Return true if the route is attached via an interface that
+ * is not in the same table as the route
+ */
+static int
+fib_entry_attached_cross_table (const fib_entry_t *fib_entry,
+                                u32 fib_index)
+{
+    const fib_prefix_t *pfx = &fib_entry->fe_prefix;
+
+    switch (pfx->fp_proto)
+    {
+    case FIB_PROTOCOL_MPLS:
+        /* MPLS routes are never imported/exported */
+       return (0);
+    case FIB_PROTOCOL_IP6:
+        /* Ignore link local addresses these also can't be imported/exported */
+        if (ip6_address_is_link_local_unicast (&pfx->fp_addr.ip6))
+        {
+            return (0);
+        }
+        break;
+    case FIB_PROTOCOL_IP4:
+        break;
+    }
+
+    return (fib_entry->fe_fib_index != fib_index);
+}
+
+/*
+ * fib_entry_back_walk_notify
+ *
+ * A back walk has reach this entry.
+ */
+static fib_node_back_walk_rc_t
+fib_entry_back_walk_notify (fib_node_t *node,
+                           fib_node_back_walk_ctx_t *ctx)
+{
+    fib_source_t best_source;
+    fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
+
+    fib_entry = fib_entry_from_fib_node(node);
+    bsrc = fib_entry_get_best_src_i(fib_entry);
+    best_source = fib_entry_src_get_source(bsrc);
+
+    if (FIB_NODE_BW_REASON_FLAG_INTERFACE_BIND & ctx->fnbw_reason)
+    {
+        fib_entry_flag_t bflags;
+
+        bflags = fib_entry_src_get_flags(bsrc);
+
+       fib_entry_src_action_reactivate(fib_entry, best_source);
+
+        /* re-evaluate whether the prefix is cross table */
+        if (fib_entry_attached_cross_table(
+                fib_entry, ctx->interface_bind.fnbw_to_fib_index) &&
+            !(bsrc->fes_entry_flags & FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT))
+        {
+            bsrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
+        }
+        else
+        {
+            bsrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
+        }
+
+        fib_entry = fib_entry_post_flag_update_actions(
+            fib_entry, bflags,
+            ctx->interface_bind.fnbw_to_fib_index);
+    }
+    else if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason        ||
+             FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason      ||
+             FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason        ||
+             FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason    ||
+             FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason  ||
+             FIB_NODE_BW_REASON_FLAG_INTERFACE_BIND & ctx->fnbw_reason  ||
+             FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
+    {
+       fib_entry_src_action_reactivate(fib_entry, best_source);
+    }
+
+    /*
+     * all other walk types can be reclassifed to a re-evaluate to
+     * all recursive dependents.
+     * By reclassifying we ensure that should any of these walk types meet
+     * they can be merged.
+     */
+    ctx->fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE;
+
+    /*
+     * ... and nothing is forced sync from now on.
+     */
+    ctx->fnbw_flags &= ~FIB_NODE_BW_FLAG_FORCE_SYNC;
+
+    FIB_ENTRY_DBG(fib_entry, "bw:%U",
+                  format_fib_node_bw_reason, ctx->fnbw_reason);
+
+    /*
+     * propagate the backwalk further if we haven't already reached the
+     * maximum depth.
+     */
+    fib_walk_sync(FIB_NODE_TYPE_ENTRY,
+                 fib_entry_get_index(fib_entry),
+                 ctx);
+
+    return (FIB_NODE_BACK_WALK_CONTINUE);
+}
+
+/*
+ * The FIB path-list's graph node virtual function table
+ */
+static const fib_node_vft_t fib_entry_vft = {
+    .fnv_get = fib_entry_get_node,
+    .fnv_last_lock = fib_entry_last_lock_gone,
+    .fnv_back_walk = fib_entry_back_walk_notify,
+    .fnv_mem_show = fib_entry_show_memory,
+};
+
 u32
 fib_entry_get_resolving_interface (fib_node_index_t entry_index)
 {
@@ -1457,6 +1558,27 @@ fib_entry_get_resolving_interface (fib_node_index_t entry_index)
     return (fib_path_list_get_resolving_interface(fib_entry->fe_parent));
 }
 
+u32
+fib_entry_get_any_resolving_interface (fib_node_index_t entry_index)
+{
+    const fib_entry_src_t *src;
+    fib_entry_t *fib_entry;
+    fib_source_t source;
+    u32 sw_if_index;
+
+    fib_entry = fib_entry_get(entry_index);
+
+    FOR_EACH_SRC_ADDED(fib_entry, src, source,
+    ({
+        sw_if_index = fib_entry_get_resolving_interface_for_source (entry_index,
+                                                                    source);
+
+        if (~0 != sw_if_index)
+            break;
+    }));
+    return (sw_if_index);
+}
+
 fib_source_t
 fib_entry_get_best_source (fib_node_index_t entry_index)
 {
@@ -1479,7 +1601,7 @@ fib_entry_is_host (fib_node_index_t fib_entry_index)
 }
 
 /**
- * Return !0 is the entry is reoslved, i.e. will return a valid forwarding
+ * Return !0 is the entry is resolved, i.e. will return a valid forwarding
  * chain
  */
 int
@@ -1490,7 +1612,7 @@ fib_entry_is_resolved (fib_node_index_t fib_entry_index)
 
     fib_entry = fib_entry_get(fib_entry_index);
 
-    fed = fib_entry_delegate_get(fib_entry, FIB_ENTRY_DELEGATE_BFD);
+    fed = fib_entry_delegate_find(fib_entry, FIB_ENTRY_DELEGATE_BFD);
 
     if (NULL == fed)
     {
@@ -1552,9 +1674,9 @@ fib_ip4_address_compare (const ip4_address_t * a1,
                          const ip4_address_t * a2)
 {
     /*
-     * IP addresses are unsiged ints. the return value here needs to be signed
+     * IP addresses are unsigned ints. the return value here needs to be signed
      * a simple subtraction won't cut it.
-     * If the addresses are the same, the sort order is undefiend, so phoey.
+     * If the addresses are the same, the sort order is undefined, so phoey.
      */
     return ((clib_net_to_host_u32(a1->data_u32) >
             clib_net_to_host_u32(a2->data_u32) ) ?
@@ -1646,13 +1768,17 @@ fib_entry_module_init (void)
 {
     fib_node_register_type(FIB_NODE_TYPE_ENTRY, &fib_entry_vft);
     fib_entry_logger = vlib_log_register_class("fib", "entry");
+
+    fib_entry_track_module_init();
 }
 
-void
-fib_entry_encode (fib_node_index_t fib_entry_index,
-                 fib_route_path_encode_t **api_rpaths)
+fib_route_path_t *
+fib_entry_encode (fib_node_index_t fib_entry_index)
 {
     fib_path_ext_list_t *ext_list;
+    fib_path_encode_ctx_t ctx = {
+        .rpaths = NULL,
+    };
     fib_entry_t *fib_entry;
     fib_entry_src_t *bsrc;
 
@@ -1670,8 +1796,10 @@ fib_entry_encode (fib_node_index_t fib_entry_index,
         fib_path_list_walk_w_ext(fib_entry->fe_parent,
                                  ext_list,
                                  fib_path_encode,
-                                 api_rpaths);
+                                 &ctx);
     }
+
+    return (ctx.rpaths);
 }
 
 const fib_prefix_t *
@@ -1700,6 +1828,29 @@ fib_entry_pool_size (void)
     return (pool_elts(fib_entry_pool));
 }
 
+#if CLIB_DEBUG > 0
+void
+fib_table_assert_empty (const fib_table_t *fib_table)
+{
+    fib_node_index_t *fei, *feis = NULL;
+    fib_entry_t *fib_entry;
+
+    pool_foreach (fib_entry, fib_entry_pool)
+     {
+        if (fib_entry->fe_fib_index == fib_table->ft_index)
+            vec_add1 (feis, fib_entry_get_index(fib_entry));
+    }
+
+    if (vec_len(feis))
+    {
+        vec_foreach (fei, feis)
+            clib_error ("%U", format_fib_entry, *fei, FIB_ENTRY_FORMAT_DETAIL);
+    }
+
+    ASSERT(0);
+}
+#endif
+
 static clib_error_t *
 show_fib_entry_command (vlib_main_t * vm,
                        unformat_input_t * input,
@@ -1730,13 +1881,13 @@ show_fib_entry_command (vlib_main_t * vm,
         * show all
         */
        vlib_cli_output (vm, "FIB Entries:");
-       pool_foreach_index(fei, fib_entry_pool,
-        ({
+       pool_foreach_index (fei, fib_entry_pool)
+         {
            vlib_cli_output (vm, "%d@%U",
                             fei,
                             format_fib_entry, fei,
                             FIB_ENTRY_FORMAT_BRIEF);
-       }));
+       }
     }
 
     return (NULL);