X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ffib%2Ffib_entry.c;h=32e45f24453ec276d566e50b3a20ed86b5cf8b95;hb=775f73c6b;hp=fed42129cff067e447f35a770666078d5b4d8e55;hpb=89541992000433b743cbbe8cb396faab42bcf6ae;p=vpp.git diff --git a/src/vnet/fib/fib_entry.c b/src/vnet/fib/fib_entry.c index fed42129cff..32e45f24453 100644 --- a/src/vnet/fib/fib_entry.c +++ b/src/vnet/fib/fib_entry.c @@ -41,6 +41,11 @@ static const char *fib_src_attribute_names[] = FIB_ENTRY_SRC_ATTRIBUTES; */ static fib_entry_t *fib_entry_pool; +/** + * the logger + */ +vlib_log_class_t fib_entry_logger; + fib_entry_t * fib_entry_get (fib_node_index_t index) { @@ -101,11 +106,39 @@ format_fib_source (u8 * s, va_list * args) } u8 * -format_fib_entry (u8 * s, va_list * args) +format_fib_entry_flags (u8 *s, va_list *args) +{ + fib_entry_attribute_t attr; + fib_entry_flag_t flag = va_arg(*args, int); + + FOR_EACH_FIB_ATTRIBUTE(attr) { + if ((1<fes_ref_count); if (FIB_ENTRY_FLAG_NONE != src->fes_entry_flags) { - s = format(s, " entry-flags:"); - FOR_EACH_FIB_ATTRIBUTE(attr) { - if ((1<fes_entry_flags) { - s = format (s, "%s,", fib_attribute_names[attr]); - } - } + s = format(s, " entry-flags:%U", + format_fib_entry_flags, src->fes_entry_flags); } if (FIB_ENTRY_SRC_FLAG_NONE != src->fes_flags) { - s = format(s, " src-flags:"); - FOR_EACH_FIB_SRC_ATTRIBUTE(sattr) { - if ((1<fes_flags) { - s = format (s, "%s,", fib_src_attribute_names[sattr]); - } - } + s = format(s, " src-flags:%U", + format_fib_entry_src_flags, src->fes_flags); } + s = fib_entry_src_format(fib_entry, source, s); s = format (s, "\n"); if (FIB_NODE_INDEX_INVALID != src->fes_pl) { @@ -214,6 +239,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); @@ -223,7 +250,6 @@ fib_entry_last_lock_gone (fib_node_t *node) FIB_ENTRY_DBG(fib_entry, "last-lock"); fib_node_deinit(&fib_entry->fe_node); - // FIXME -RR Backwalk ASSERT(0 == vec_len(fib_entry->fe_delegates)); vec_free(fib_entry->fe_delegates); @@ -315,6 +341,9 @@ fib_entry_back_walk_notify (fib_node_t *node, */ 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. @@ -458,6 +487,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 @@ -477,7 +514,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 @@ -559,7 +601,7 @@ fib_entry_alloc (u32 fib_index, fib_prefix_t *fep; pool_get(fib_entry_pool, fib_entry); - memset(fib_entry, 0, sizeof(*fib_entry)); + clib_memset(fib_entry, 0, sizeof(*fib_entry)); fib_node_init(&fib_entry->fe_node, FIB_NODE_TYPE_ENTRY); @@ -587,8 +629,6 @@ fib_entry_alloc (u32 fib_index, *fib_entry_index = fib_entry_get_index(fib_entry); - FIB_ENTRY_DBG(fib_entry, "alloc"); - return (fib_entry); } @@ -705,6 +745,8 @@ fib_entry_create (u32 fib_index, fib_entry_post_install_actions(fib_entry, source, FIB_ENTRY_FLAG_NONE); + FIB_ENTRY_DBG(fib_entry, "create"); + return (fib_entry_index); } @@ -731,6 +773,8 @@ fib_entry_create_special (u32 fib_index, fib_entry_post_install_actions(fib_entry, source, FIB_ENTRY_FLAG_NONE); + FIB_ENTRY_DBG(fib_entry, "create-special"); + return (fib_entry_index); } @@ -757,15 +801,26 @@ fib_entry_post_update_actions (fib_entry_t *fib_entry, } void -fib_entry_source_change (fib_entry_t *fib_entry, - fib_source_t old_source, - fib_source_t new_source) +fib_entry_recalculate_forwarding (fib_node_index_t fib_entry_index) { - fib_entry_flag_t old_flags; + fib_source_t best_source; + fib_entry_t *fib_entry; + fib_entry_src_t *bsrc; - old_flags = fib_entry_get_flags_for_source( - fib_entry_get_index(fib_entry), old_source); + 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_w_flags (fib_entry_t *fib_entry, + fib_source_t old_source, + fib_entry_flag_t old_flags, + fib_source_t new_source) +{ if (new_source < old_source) { /* @@ -776,11 +831,13 @@ fib_entry_source_change (fib_entry_t *fib_entry, } 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 { @@ -795,6 +852,20 @@ fib_entry_source_change (fib_entry_t *fib_entry, 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, @@ -809,6 +880,7 @@ fib_entry_special_add (fib_node_index_t fib_entry_index, fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo); fib_entry_source_change(fib_entry, best_source, source); + FIB_ENTRY_DBG(fib_entry, "special-add:%U", format_fib_source, source); } void @@ -825,6 +897,8 @@ fib_entry_special_update (fib_node_index_t fib_entry_index, fib_entry = fib_entry_src_action_update(fib_entry, source, flags, dpo); fib_entry_source_change(fib_entry, best_source, source); + + FIB_ENTRY_DBG(fib_entry, "special-updated:%U", format_fib_source, source); } @@ -835,7 +909,6 @@ fib_entry_path_add (fib_node_index_t fib_entry_index, const fib_route_path_t *rpath) { fib_source_t best_source; - fib_entry_flag_t bflags; fib_entry_t *fib_entry; fib_entry_src_t *bsrc; @@ -846,42 +919,12 @@ 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) - { - /* - * 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_reactivate(fib_entry, source); - } + fib_entry_source_change(fib_entry, best_source, source); - fib_entry_post_update_actions(fib_entry, source, bflags); + FIB_ENTRY_DBG(fib_entry, "path add:%U", format_fib_source, source); } static fib_entry_src_flag_t @@ -928,7 +971,8 @@ 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_MAX == best_source) + { /* * no more sources left. this entry is toast. */ @@ -978,6 +1022,8 @@ fib_entry_path_remove (fib_node_index_t fib_entry_index, sflag = fib_entry_src_action_path_remove(fib_entry, source, rpath); + FIB_ENTRY_DBG(fib_entry, "path remove:%U", format_fib_source, source); + /* * if the path list for the source passed is invalid, * then we need to create a new one. else we are updating @@ -1067,6 +1113,8 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index, sflag = fib_entry_src_action_remove_or_update_inherit(fib_entry, source); + FIB_ENTRY_DBG(fib_entry, "special remove:%U", format_fib_source, source); + /* * if the path list for the source passed is invalid, * then we need to create a new one. else we are updating @@ -1107,6 +1155,12 @@ fib_entry_special_remove (fib_node_index_t fib_entry_index, 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); } } @@ -1183,48 +1237,15 @@ fib_entry_update (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_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); + bflags = fib_entry_get_flags_i(fib_entry); - /* - * 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_reactivate(fib_entry, source); - } + fib_entry = fib_entry_src_action_path_swap(fib_entry, + source, + flags, + paths); - fib_entry_post_update_actions(fib_entry, source, bflags); + fib_entry_source_change_w_flags(fib_entry, best_source, bflags, source); + FIB_ENTRY_DBG(fib_entry, "update"); } @@ -1240,7 +1261,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; @@ -1263,13 +1285,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++; })); @@ -1297,6 +1319,7 @@ fib_entry_cover_changed (fib_node_index_t fib_entry_index) fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx); } + FIB_ENTRY_DBG(fib_entry, "cover-changed"); } /* @@ -1312,7 +1335,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; @@ -1335,13 +1359,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++; })); @@ -1369,6 +1393,7 @@ fib_entry_cover_updated (fib_node_index_t fib_entry_index) fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx); } + FIB_ENTRY_DBG(fib_entry, "cover-updated"); } int @@ -1444,6 +1469,15 @@ fib_entry_get_best_source (fib_node_index_t entry_index) return (fib_entry_src_get_source(bsrc)); } +/** + * Return !0 is the entry represents a host prefix + */ +int +fib_entry_is_host (fib_node_index_t fib_entry_index) +{ + return (fib_prefix_is_host(fib_entry_get_prefix(fib_entry_index))); +} + /** * Return !0 is the entry is reoslved, i.e. will return a valid forwarding * chain @@ -1503,6 +1537,16 @@ fib_entry_set_flow_hash_config (fib_node_index_t fib_entry_index, } } +u32 +fib_entry_get_stats_index (fib_node_index_t fib_entry_index) +{ + fib_entry_t *fib_entry; + + fib_entry = fib_entry_get(fib_entry_index); + + return (fib_entry->fe_lb.dpoi_index); +} + static int fib_ip4_address_compare (const ip4_address_t * a1, const ip4_address_t * a2) @@ -1600,30 +1644,44 @@ fib_entry_unlock (fib_node_index_t fib_entry_index) void fib_entry_module_init (void) { - fib_node_register_type (FIB_NODE_TYPE_ENTRY, &fib_entry_vft); + fib_node_register_type(FIB_NODE_TYPE_ENTRY, &fib_entry_vft); + fib_entry_logger = vlib_log_register_class("fib", "entry"); } void fib_entry_encode (fib_node_index_t fib_entry_index, fib_route_path_encode_t **api_rpaths) { + fib_path_ext_list_t *ext_list; fib_entry_t *fib_entry; + fib_entry_src_t *bsrc; + ext_list = NULL; fib_entry = fib_entry_get(fib_entry_index); + bsrc = fib_entry_get_best_src_i(fib_entry); + + if (bsrc) + { + ext_list = &bsrc->fes_path_exts; + } + if (FIB_NODE_INDEX_INVALID != fib_entry->fe_parent) { - fib_path_list_walk(fib_entry->fe_parent, fib_path_encode, api_rpaths); + fib_path_list_walk_w_ext(fib_entry->fe_parent, + ext_list, + fib_path_encode, + api_rpaths); } } -void -fib_entry_get_prefix (fib_node_index_t fib_entry_index, - fib_prefix_t *pfx) +const fib_prefix_t * +fib_entry_get_prefix (fib_node_index_t fib_entry_index) { fib_entry_t *fib_entry; fib_entry = fib_entry_get(fib_entry_index); - *pfx = fib_entry->fe_prefix; + + return (&fib_entry->fe_prefix); } u32