FIB Interpose Source
[vpp.git] / src / vnet / fib / fib_entry.c
index a9ca0f2..19e8433 100644 (file)
@@ -34,6 +34,7 @@
  */
 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;
 
 /*
  * Pool for all fib_entries
@@ -102,6 +103,7 @@ format_fib_source (u8 * s, va_list * args)
 u8 *
 format_fib_entry (u8 * s, va_list * args)
 {
+    fib_entry_src_attribute_t sattr;
     fib_forward_chain_type_t fct;
     fib_entry_attribute_t attr;
     fib_entry_t *fib_entry;
@@ -116,8 +118,8 @@ format_fib_entry (u8 * s, va_list * args)
 
     s = format (s, "%U", format_fib_prefix, &fib_entry->fe_prefix);
 
-    if (level >= FIB_ENTRY_FORMAT_DETAIL)
-    {
+//    if (level >= FIB_ENTRY_FORMAT_DETAIL)
+//    {
        s = format (s, " fib:%d", fib_entry->fe_fib_index);
        s = format (s, " index:%d", fib_entry_get_index(fib_entry));
        s = format (s, " locks:%d", fib_entry->fe_node.fn_locks);
@@ -125,16 +127,24 @@ format_fib_entry (u8 * s, va_list * args)
        FOR_EACH_SRC_ADDED(fib_entry, src, source,
         ({
            s = format (s, "\n  %U", format_fib_source, source);
-           s = fib_entry_src_format(fib_entry, source, s);
-           s = format (s, " refs:%d ", src->fes_ref_count);
+           s = format (s, " refs:%d", src->fes_ref_count);
            if (FIB_ENTRY_FLAG_NONE != src->fes_entry_flags) {
-               s = format(s, "flags:");
+               s = format(s, " entry-flags:");
                FOR_EACH_FIB_ATTRIBUTE(attr) {
                    if ((1<<attr) & src->fes_entry_flags) {
                        s = format (s, "%s,", fib_attribute_names[attr]);
                    }
                }
            }
+           if (FIB_ENTRY_SRC_FLAG_NONE != src->fes_flags) {
+               s = format(s, " src-flags:");
+               FOR_EACH_FIB_SRC_ATTRIBUTE(sattr) {
+                   if ((1<<sattr) & src->fes_flags) {
+                       s = format (s, "%s,", fib_src_attribute_names[sattr]);
+                   }
+               }
+           }
+            s = fib_entry_src_format(fib_entry, source, s);
            s = format (s, "\n");
            if (FIB_NODE_INDEX_INVALID != src->fes_pl)
            {
@@ -144,11 +154,11 @@ format_fib_entry (u8 * s, va_list * args)
        }));
     
        s = format (s, "\n forwarding: ");
-    }
-    else
-    {
-       s = format (s, "\n");
-    }
+//    }
+//    else
+//    {
+//     s = format (s, "\n");
+//    }
 
     fct = fib_entry_get_default_chain_type(fib_entry);
 
@@ -204,6 +214,8 @@ fib_entry_last_lock_gone (fib_node_t *node)
 
     fib_entry = fib_entry_from_fib_node(node);
 
+    ASSERT(!dpo_id_is_valid(&fib_entry->fe_lb));
+
     FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
     {
        dpo_reset(&fed->fd_dpo);
@@ -216,30 +228,25 @@ fib_entry_last_lock_gone (fib_node_t *node)
 
     ASSERT(0 == vec_len(fib_entry->fe_delegates));
     vec_free(fib_entry->fe_delegates);
-    if (fib_entry_has_multiple_srcs(fib_entry))
-    {
-        vec_free(fib_entry->fe_u_src.fe_srcs);
-    }
+    vec_free(fib_entry->fe_srcs);
     pool_put(fib_entry_pool, fib_entry);
 }
 
-static const fib_entry_src_t*
+static fib_entry_src_t*
 fib_entry_get_best_src_i (const fib_entry_t *fib_entry)
 {
-    const fib_entry_src_t *bsrc;
+    fib_entry_src_t *bsrc;
 
     /*
      * the enum of sources is deliberately arranged in priority order
      */
-    if (fib_entry_has_multiple_srcs(fib_entry))
+    if (0 == vec_len(fib_entry->fe_srcs))
     {
-        ASSERT(vec_len(fib_entry->fe_u_src.fe_srcs));
-
-        bsrc = vec_elt_at_index(fib_entry->fe_u_src.fe_srcs, 0);
+       bsrc = NULL;
     }
     else
     {
-        bsrc = &fib_entry->fe_u_src.fe_src;
+       bsrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
     }
 
     return (bsrc);
@@ -252,7 +259,7 @@ fib_entry_src_get_source (const fib_entry_src_t *esrc)
     {
        return (esrc->fes_src);
     }
-    return (FIB_SOURCE_INVALID);
+    return (FIB_SOURCE_MAX);
 }
 
 static fib_entry_flag_t
@@ -265,18 +272,6 @@ fib_entry_src_get_flags (const fib_entry_src_t *esrc)
     return (FIB_ENTRY_FLAG_NONE);
 }
 
-fib_entry_flag_t
-fib_entry_get_flags_i (const fib_entry_t *fib_entry)
-{
-    const fib_entry_src_t *esrc;
-
-    esrc = fib_entry_get_best_src_i(fib_entry);
-
-    ASSERT(esrc);
-
-    return (esrc->fes_entry_flags);
-}
-
 fib_entry_flag_t
 fib_entry_get_flags (fib_node_index_t fib_entry_index)
 {
@@ -346,18 +341,11 @@ fib_entry_show_memory (void)
 
     pool_foreach(entry, fib_entry_pool,
     ({
-        if (fib_entry_has_multiple_srcs(entry))
-        {
-            n_srcs += vec_len(entry->fe_u_src.fe_srcs);
-            vec_foreach(esrc, entry->fe_u_src.fe_srcs)
-            {
-                n_exts += fib_path_ext_list_length(&esrc->fes_path_exts);
-            }
-        }
-        else
-        {
-            n_exts += fib_path_ext_list_length(&entry->fe_u_src.fe_src.fes_path_exts);
-        }
+       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",
@@ -471,6 +459,14 @@ fib_entry_contribute_forwarding (fib_node_index_t fib_entry_index,
 
         dpo_copy(dpo, &fed->fd_dpo);
     }
+    /*
+     * use the drop DPO is nothing else is present
+     */
+    if (!dpo_id_is_valid(dpo))
+    {
+        dpo_copy(dpo, drop_dpo_get(fib_forw_chain_type_to_dpo_proto(fct)));
+    }
+
     /*
      * don't allow the special index indicating replicate.vs.load-balance
      * to escape to the clients
@@ -490,7 +486,12 @@ fib_entry_contribute_ip_forwarding (fib_node_index_t fib_entry_index)
     ASSERT((fct == FIB_FORW_CHAIN_TYPE_UNICAST_IP4 ||
             fct == FIB_FORW_CHAIN_TYPE_UNICAST_IP6));
 
-    return (&fib_entry->fe_lb);
+    if (dpo_id_is_valid(&fib_entry->fe_lb))
+    {
+        return (&fib_entry->fe_lb);
+    }
+
+    return (drop_dpo_get(fib_forw_chain_type_to_dpo_proto(fct)));
 }
 
 adj_index_t
@@ -607,7 +608,6 @@ fib_entry_alloc (u32 fib_index,
 
 static fib_entry_t*
 fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
-                                   fib_source_t source,
                                    fib_entry_flag_t old_flags)
 {
     fib_node_index_t fei;
@@ -681,7 +681,6 @@ fib_entry_post_install_actions (fib_entry_t *fib_entry,
                                fib_entry_flag_t old_flags)
 {
     fib_entry = fib_entry_post_flag_update_actions(fib_entry,
-                                                   source,
                                                    old_flags);
     fib_entry_src_action_installed(fib_entry, source);
 }
@@ -771,32 +770,44 @@ fib_entry_post_update_actions (fib_entry_t *fib_entry,
     fib_entry_post_install_actions(fib_entry, source, old_flags);
 }
 
+void
+fib_entry_recalculate_forwarding (fib_node_index_t fib_entry_index)
+{
+    fib_source_t best_source;
+    fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
+
+    fib_entry = fib_entry_get(fib_entry_index);
+
+    bsrc = fib_entry_get_best_src_i(fib_entry);
+    best_source = fib_entry_src_get_source(bsrc);
+
+    fib_entry_src_action_reactivate(fib_entry, best_source);
+}
+
 static void
-fib_entry_source_change (fib_entry_t *fib_entry,
-                        fib_source_t best_source,
-                        fib_source_t new_source,
-                        fib_entry_flag_t old_flags)
+fib_entry_source_change_w_flags (fib_entry_t *fib_entry,
+                                 fib_source_t old_source,
+                                 fib_entry_flag_t old_flags,
+                                 fib_source_t new_source)
 {
-    /*
-     * if the path list for the source passed is invalid,
-     * then we need to create a new one. else we are updating
-     * an existing.
-     */
-    if (new_source < best_source)
+    if (new_source < old_source)
     {
        /*
         * we have a new winning source.
         */
-       fib_entry_src_action_deactivate(fib_entry, best_source);
+       fib_entry_src_action_deactivate(fib_entry, old_source);
        fib_entry_src_action_activate(fib_entry, new_source);
     }
-    else if (new_source > best_source)
+    else if (new_source > old_source)
     {
-       /*
-        * the new source loses. nothing to do here.
-        * the data from the source is saved in the path-list created
-        */
-       return;
+        /*
+         * the new source loses. Re-activate the winning sources
+         * in case it is an interposer and hence relied on the losing
+         * source's path-list.
+         */
+        fib_entry_src_action_reactivate(fib_entry, old_source);
+        return;
     }
     else
     {
@@ -805,32 +816,40 @@ fib_entry_source_change (fib_entry_t *fib_entry,
         * But the path-list was updated, which will contribute new forwarding,
         * so install it.
         */
-       fib_entry_src_action_deactivate(fib_entry, new_source);
-       fib_entry_src_action_activate(fib_entry, new_source);
+        fib_entry_src_action_reactivate(fib_entry, new_source);
     }
 
     fib_entry_post_update_actions(fib_entry, new_source, old_flags);
 }
 
+void
+fib_entry_source_change (fib_entry_t *fib_entry,
+                         fib_source_t old_source,
+                        fib_source_t new_source)
+{
+    fib_entry_flag_t old_flags;
+
+    old_flags = fib_entry_get_flags_for_source(
+        fib_entry_get_index(fib_entry), old_source);
+
+    return (fib_entry_source_change_w_flags(fib_entry, old_source,
+                                            old_flags, new_source));
+}
+
 void
 fib_entry_special_add (fib_node_index_t fib_entry_index,
                       fib_source_t source,
                       fib_entry_flag_t flags,
                       const dpo_id_t *dpo)
 {
-    const fib_entry_src_t *bsrc;
     fib_source_t best_source;
-    fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
 
     fib_entry = fib_entry_get(fib_entry_index);
-
-    bsrc = fib_entry_get_best_src_i(fib_entry);
-    best_source = fib_entry_src_get_source(bsrc);
-    bflags = fib_entry_src_get_flags(bsrc);
+    best_source = fib_entry_get_best_source(fib_entry_index);
 
     fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
-    fib_entry_source_change(fib_entry, best_source, source, bflags);
+    fib_entry_source_change(fib_entry, best_source, source);
 }
 
 void
@@ -839,19 +858,14 @@ fib_entry_special_update (fib_node_index_t fib_entry_index,
                          fib_entry_flag_t flags,
                          const dpo_id_t *dpo)
 {
-    const fib_entry_src_t *bsrc;
     fib_source_t best_source;
-    fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
 
     fib_entry = fib_entry_get(fib_entry_index);
-
-    bsrc = fib_entry_get_best_src_i(fib_entry);
-    best_source = fib_entry_src_get_source(bsrc);
-    bflags = fib_entry_src_get_flags(bsrc);
+    best_source = fib_entry_get_best_source(fib_entry_index);
 
     fib_entry = fib_entry_src_action_update(fib_entry, source, flags, dpo);
-    fib_entry_source_change(fib_entry, best_source, source, bflags);
+    fib_entry_source_change(fib_entry, best_source, source);
 }
 
 
@@ -861,10 +875,9 @@ fib_entry_path_add (fib_node_index_t fib_entry_index,
                    fib_entry_flag_t flags,
                    const fib_route_path_t *rpath)
 {
-    const fib_entry_src_t *bsrc;
     fib_source_t best_source;
-    fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
 
     ASSERT(1 == vec_len(rpath));
 
@@ -873,43 +886,77 @@ fib_entry_path_add (fib_node_index_t fib_entry_index,
 
     bsrc = fib_entry_get_best_src_i(fib_entry);
     best_source = fib_entry_src_get_source(bsrc);
-    bflags = fib_entry_src_get_flags(bsrc);
     
     fib_entry = fib_entry_src_action_path_add(fib_entry, source, flags, rpath);
 
-    /*
-     * if the path list for the source passed is invalid,
-     * then we need to create a new one. else we are updating
-     * an existing.
-     */
-    if (source < best_source)
+    fib_entry_source_change(fib_entry, best_source, source);
+}
+
+static fib_entry_src_flag_t
+fib_entry_src_burn_only_inherited (fib_entry_t *fib_entry)
+{
+    fib_entry_src_t *src;
+    fib_source_t source;
+    int has_only_inherited_sources = 1;
+
+    FOR_EACH_SRC_ADDED(fib_entry, src, source,
+    ({
+        if (!(src->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
+        {
+            has_only_inherited_sources = 0;
+            break;
+        }
+    }));
+    if (has_only_inherited_sources)
     {
-       /*
-        * we have a new winning source.
-        */
-       fib_entry_src_action_deactivate(fib_entry, best_source);
-       fib_entry_src_action_activate(fib_entry, source);
+        FOR_EACH_SRC_ADDED(fib_entry, src, source,
+        ({
+            fib_entry_src_action_remove(fib_entry, source);
+        }));
+        return (FIB_ENTRY_SRC_FLAG_NONE);
     }
-    else if (source > best_source)
+    else
     {
-       /*
-        * the new source loses. nothing to do here.
-        * the data from the source is saved in the path-list created
-        */
-       return;
+        return (FIB_ENTRY_SRC_FLAG_ADDED);
+    }
+}
+
+static fib_entry_src_flag_t
+fib_entry_source_removed (fib_entry_t *fib_entry,
+                          fib_entry_flag_t old_flags)
+{
+    const fib_entry_src_t *bsrc;
+    fib_source_t best_source;
+
+    /*
+     * if all that is left are inherited sources, then burn them
+     */
+    fib_entry_src_burn_only_inherited(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)
+    {
+        /*
+         * no more sources left. this entry is toast.
+         */
+        fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags);
+        fib_entry_src_action_uninstall(fib_entry);
+
+        return (FIB_ENTRY_SRC_FLAG_NONE);
     }
     else
     {
-       /*
-        * 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_deactivate(fib_entry, source);
-       fib_entry_src_action_activate(fib_entry, source);
+        fib_entry_src_action_activate(fib_entry, best_source);
     }
 
-    fib_entry_post_update_actions(fib_entry, source, bflags);
+    fib_entry_post_update_actions(fib_entry, best_source, old_flags);
+
+    /*
+     * still have sources
+     */
+    return (FIB_ENTRY_SRC_FLAG_ADDED);
 }
 
 /*
@@ -923,11 +970,11 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
                       fib_source_t source,
                       const fib_route_path_t *rpath)
 {
-    const fib_entry_src_t *bsrc;
     fib_entry_src_flag_t sflag;
     fib_source_t best_source;
     fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
 
     ASSERT(1 == vec_len(rpath));
 
@@ -945,7 +992,7 @@ 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 )
+    if (source < best_source)
     {
        /*
         * Que! removing a path from a source that is better than the
@@ -956,9 +1003,23 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
     else if (source > best_source )
     {
        /*
-        * the source is not the best. nothing to do.
+        * the source is not the best. no need to update forwarding
         */
-       return (FIB_ENTRY_SRC_FLAG_ADDED);
+       if (FIB_ENTRY_SRC_FLAG_ADDED & sflag)
+        {
+            /*
+             * the source being removed still has paths
+             */
+            return (FIB_ENTRY_SRC_FLAG_ADDED);
+        }
+        else
+        {
+            /*
+             * that was the last path from this source, check if those
+             * that remain are non-inherited
+             */
+            return (fib_entry_src_burn_only_inherited(fib_entry));
+       }
     }
     else
     {
@@ -971,33 +1032,14 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index,
             * the last path from the source was removed.
             * fallback to lower source
             */
-           bsrc = fib_entry_get_best_src_i(fib_entry);
-           best_source = fib_entry_src_get_source(bsrc);
-
-           if (FIB_SOURCE_INVALID == best_source) {
-               /*
-                * no more sources left. this entry is toast.
-                */
-               fib_entry = fib_entry_post_flag_update_actions(fib_entry,
-                                                               source,
-                                                               bflags);
-               fib_entry_src_action_uninstall(fib_entry);
-
-               return (FIB_ENTRY_SRC_FLAG_NONE);
-           }
-           else
-           {
-               fib_entry_src_action_activate(fib_entry, best_source);
-               source = best_source;
-           }
+            return (fib_entry_source_removed(fib_entry, bflags));
        }
        else
        {
            /*
             * re-install the new forwarding information
             */
-           fib_entry_src_action_deactivate(fib_entry, source);
-           fib_entry_src_action_activate(fib_entry, source);
+           fib_entry_src_action_reactivate(fib_entry, source);
        }
     }
 
@@ -1019,11 +1061,11 @@ fib_entry_src_flag_t
 fib_entry_special_remove (fib_node_index_t fib_entry_index,
                          fib_source_t source)
 {
-    const fib_entry_src_t *bsrc;
     fib_entry_src_flag_t sflag;
     fib_source_t best_source;
     fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
 
     fib_entry = fib_entry_get(fib_entry_index);
     ASSERT(NULL != fib_entry);
@@ -1032,7 +1074,7 @@ fib_entry_special_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_remove(fib_entry, source);
+    sflag = fib_entry_src_action_remove_or_update_inherit(fib_entry, source);
 
     /*
      * if the path list for the source passed is invalid,
@@ -1050,9 +1092,38 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
     }
     else if (source > best_source ) {
        /*
-        * the source is not the best. nothing to do.
+        * the source is not the best. no need to update forwarding
         */
-       return (FIB_ENTRY_SRC_FLAG_ADDED);
+       if (FIB_ENTRY_SRC_FLAG_ADDED & sflag)
+        {
+            /*
+             * the source being removed still has paths
+             */
+            return (FIB_ENTRY_SRC_FLAG_ADDED);
+        }
+        else
+        {
+            /*
+             * that was the last path from this source, check if those
+             * that remain are non-inherited
+             */
+            if (FIB_ENTRY_SRC_FLAG_NONE == fib_entry_src_burn_only_inherited(fib_entry))
+            {
+                /*
+                 * no more sources left. this entry is toast.
+                 */
+                fib_entry = fib_entry_post_flag_update_actions(fib_entry, bflags);
+                fib_entry_src_action_uninstall(fib_entry);
+                return (FIB_ENTRY_SRC_FLAG_NONE);
+            }
+
+            /*
+             * reactivate the best source so the interposer gets restacked
+             */
+            fib_entry_src_action_reactivate(fib_entry, best_source);
+
+            return (FIB_ENTRY_SRC_FLAG_ADDED);
+        }
     }
     else
     {
@@ -1061,25 +1132,7 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
            /*
             * the source was removed. use the next best.
             */
-           bsrc = fib_entry_get_best_src_i(fib_entry);
-           best_source = fib_entry_src_get_source(bsrc);
-
-           if (FIB_SOURCE_INVALID == best_source) {
-               /*
-                * no more sources left. this entry is toast.
-                */
-               fib_entry = fib_entry_post_flag_update_actions(fib_entry,
-                                                               source,
-                                                               bflags);
-               fib_entry_src_action_uninstall(fib_entry);
-
-               return (FIB_ENTRY_SRC_FLAG_NONE);
-           }
-           else
-           {
-               fib_entry_src_action_activate(fib_entry, best_source);
-               source = best_source;
-           }
+            return (fib_entry_source_removed(fib_entry, bflags));
        }
        else
        {
@@ -1098,6 +1151,20 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index,
     return (FIB_ENTRY_SRC_FLAG_ADDED);
 }
 
+/**
+ * fib_entry_inherit
+ *
+ * If the source on the cover is inherting then push this source
+ * down to the covered.
+ */
+void
+fib_entry_inherit (fib_node_index_t cover,
+                   fib_node_index_t covered)
+{
+    fib_entry_src_inherit(fib_entry_get(cover),
+                          fib_entry_get(covered));
+}
+
 /**
  * fib_entry_delete
  *
@@ -1121,59 +1188,24 @@ fib_entry_update (fib_node_index_t fib_entry_index,
                  fib_entry_flag_t flags,
                  const fib_route_path_t *paths)
 {
-    const fib_entry_src_t *bsrc;
     fib_source_t best_source;
     fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
 
     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);
-    bflags = fib_entry_src_get_flags(bsrc);
+    bflags = fib_entry_get_flags_i(fib_entry);
 
-    fib_entry_src_action_path_swap(fib_entry,
-                                  source,
-                                  flags,
-                                  paths);
-    /*
-     * handle possible realloc's by refetching the pointer
-     */
-    fib_entry = fib_entry_get(fib_entry_index);
+    fib_entry = fib_entry_src_action_path_swap(fib_entry,
+                                               source,
+                                               flags,
+                                               paths);
 
-    /*
-     * if the path list for the source passed is invalid,
-     * then we need to create a new one. else we are updating
-     * an existing.
-     */
-    if (source < best_source)
-    {
-       /*
-        * we have a new winning source.
-        */
-       fib_entry_src_action_deactivate(fib_entry, best_source);
-       fib_entry_src_action_activate(fib_entry, source);
-    }
-    else if (source > best_source) {
-       /*
-        * the new source loses. nothing to do here.
-        * the data from the source is saved in the path-list created
-        */
-       return;
-    }
-    else
-    {
-       /*
-        * 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_deactivate(fib_entry, source);
-       fib_entry_src_action_activate(fib_entry, source);
-    }
-
-    fib_entry_post_update_actions(fib_entry, source, bflags);
+    fib_entry_source_change_w_flags(fib_entry, best_source, bflags, source);
 }
 
 
@@ -1189,7 +1221,8 @@ fib_entry_cover_changed (fib_node_index_t fib_entry_index)
        .install = !0,
        .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
     };
-    fib_source_t source, best_source;
+    CLIB_UNUSED(fib_source_t source);
+    fib_source_t best_source;
     fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
     fib_entry_src_t *esrc;
@@ -1212,13 +1245,13 @@ fib_entry_cover_changed (fib_node_index_t fib_entry_index)
            /*
             * only the best source gets to set the back walk flags
             */
-           res = fib_entry_src_action_cover_change(fib_entry, source);
+           res = fib_entry_src_action_cover_change(fib_entry, esrc);
             bflags = fib_entry_src_get_flags(esrc);
             best_source = fib_entry_src_get_source(esrc);
        }
        else
        {
-           fib_entry_src_action_cover_change(fib_entry, source);
+           fib_entry_src_action_cover_change(fib_entry, esrc);
        }
        index++;
     }));
@@ -1261,7 +1294,8 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index)
        .install = !0,
        .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
     };
-    fib_source_t source, best_source;
+    CLIB_UNUSED(fib_source_t source);
+    fib_source_t best_source;
     fib_entry_flag_t bflags;
     fib_entry_t *fib_entry;
     fib_entry_src_t *esrc;
@@ -1284,13 +1318,13 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index)
            /*
             * only the best source gets to set the back walk flags
             */
-           res = fib_entry_src_action_cover_update(fib_entry, source);
+           res = fib_entry_src_action_cover_update(fib_entry, esrc);
             bflags = fib_entry_src_get_flags(esrc);
             best_source = fib_entry_src_get_source(esrc);
        }
        else
        {
-           fib_entry_src_action_cover_update(fib_entry, source);
+           fib_entry_src_action_cover_update(fib_entry, esrc);
        }
        index++;
     }));
@@ -1384,8 +1418,8 @@ fib_entry_get_resolving_interface (fib_node_index_t entry_index)
 fib_source_t
 fib_entry_get_best_source (fib_node_index_t entry_index)
 {
-    const fib_entry_src_t *bsrc;
     fib_entry_t *fib_entry;
+    fib_entry_src_t *bsrc;
 
     fib_entry = fib_entry_get(entry_index);