X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ffib%2Ffib_path.c;h=3a67a544ecab90fddf6bd531f9eaed2fbb8d4ade;hb=a0a908f1dfb679c384ab34ee3c1a2a63ba2448df;hp=6c1bd6bd65dd6394d8dd766ef4de47a27e4e13c7;hpb=107e7d4b5375295e94e01653e3cf064ea6647064;p=vpp.git diff --git a/src/vnet/fib/fib_path.c b/src/vnet/fib/fib_path.c index 6c1bd6bd65d..3a67a544eca 100644 --- a/src/vnet/fib/fib_path.c +++ b/src/vnet/fib/fib_path.c @@ -196,9 +196,16 @@ typedef struct fib_path_t_ { fib_protocol_t fp_nh_proto; /** - * UCMP [unnormalised] weigt + * UCMP [unnormalised] weigth */ - u32 fp_weight; + u8 fp_weight; + + /** + * A path preference. 0 is the best. + * Only paths of the best preference, that are 'up', are considered + * for forwarding. + */ + u8 fp_preference; /** * per-type union of the data required to resolve the path @@ -376,6 +383,7 @@ format_fib_path (u8 * s, va_list * args) s = format (s, "pl-index:%d ", path->fp_pl_index); s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto); s = format (s, "weight=%d ", path->fp_weight); + s = format (s, "pref=%d ", path->fp_preference); s = format (s, "%s: ", fib_path_type_names[path->fp_type]); if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) { s = format(s, " oper-flags:"); @@ -588,6 +596,30 @@ fib_path_attached_next_hop_set (fib_path_t *path) } } +static const adj_index_t +fib_path_attached_get_adj (fib_path_t *path, + vnet_link_t link) +{ + if (vnet_sw_interface_is_p2p(vnet_get_main(), + path->attached.fp_interface)) + { + /* + * point-2-point interfaces do not require a glean, since + * there is nothing to ARP. Install a rewrite/nbr adj instead + */ + return (adj_nbr_add_or_lock(path->fp_nh_proto, + link, + &zero_addr, + path->attached.fp_interface)); + } + else + { + return (adj_glean_add_or_lock(path->fp_nh_proto, + path->attached.fp_interface, + NULL)); + } +} + /* * create of update the paths recursive adj */ @@ -675,6 +707,14 @@ fib_path_recursive_adj_update (fib_path_t *path, load_balance_map_path_state_change(fib_path_get_index(path)); } + /* + * If this path is contributing a drop, then it's not resolved + */ + if (dpo_is_drop(&via_dpo) || load_balance_is_drop(&via_dpo)) + { + path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED; + } + /* * update the path's contributed DPO */ @@ -778,7 +818,7 @@ fib_path_to_chain_type (const fib_path_t *path) } else { - return (FIB_FORW_CHAIN_TYPE_MPLS_EOS); + return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS); } } return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4); @@ -1047,6 +1087,7 @@ fib_path_create (fib_node_index_t pl_index, */ path->fp_weight = 1; } + path->fp_preference = rpath->frp_preference; path->fp_cfg_flags = fib_path_route_flags_to_cfg_flags(rpath); /* @@ -1141,6 +1182,7 @@ fib_path_create_special (fib_node_index_t pl_index, path->fp_pl_index = pl_index; path->fp_weight = 1; + path->fp_preference = 0; path->fp_nh_proto = nh_proto; path->fp_via_fib = FIB_NODE_INDEX_INVALID; path->fp_cfg_flags = flags; @@ -1251,7 +1293,7 @@ fib_path_cmp_i (const fib_path_t *path1, /* * paths of different types and protocol are not equal. - * different weights only are the same path. + * different weights and/or preference only are the same path. */ if (path1->fp_type != path2->fp_type) { @@ -1326,6 +1368,15 @@ fib_path_cmp_for_sort (void * v1, path1 = fib_path_get(*pi1); path2 = fib_path_get(*pi2); + /* + * when sorting paths we want the highest preference paths + * first, so that the choices set built is in prefernce order + */ + if (path1->fp_preference != path2->fp_preference) + { + return (path1->fp_preference - path2->fp_preference); + } + return (fib_path_cmp_i(path1, path2)); } @@ -1559,31 +1610,12 @@ fib_path_resolve (fib_node_index_t path_index) { path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED; } - if (vnet_sw_interface_is_p2p(vnet_get_main(), - path->attached.fp_interface)) - { - /* - * point-2-point interfaces do not require a glean, since - * there is nothing to ARP. Install a rewrite/nbr adj instead - */ - dpo_set(&path->fp_dpo, - DPO_ADJACENCY, - fib_proto_to_dpo(path->fp_nh_proto), - adj_nbr_add_or_lock( - path->fp_nh_proto, - fib_proto_to_link(path->fp_nh_proto), - &zero_addr, - path->attached.fp_interface)); - } - else - { - dpo_set(&path->fp_dpo, - DPO_ADJACENCY_GLEAN, - fib_proto_to_dpo(path->fp_nh_proto), - adj_glean_add_or_lock(path->fp_nh_proto, - path->attached.fp_interface, - NULL)); - } + dpo_set(&path->fp_dpo, + DPO_ADJACENCY, + fib_proto_to_dpo(path->fp_nh_proto), + fib_path_attached_get_adj(path, + fib_proto_to_link(path->fp_nh_proto))); + /* * become a child of the adjacency so we receive updates * when the interface state changes @@ -1621,8 +1653,7 @@ fib_path_resolve (fib_node_index_t path_index) fei = fib_table_entry_special_add(path->recursive.fp_tbl_id, &pfx, FIB_SOURCE_RR, - FIB_ENTRY_FLAG_NONE, - ADJ_INDEX_INVALID); + FIB_ENTRY_FLAG_NONE); path = fib_path_get(path_index); path->fp_via_fib = fei; @@ -1717,7 +1748,11 @@ fib_path_get_resolving_interface (fib_node_index_t path_index) case FIB_PATH_TYPE_RECEIVE: return (path->receive.fp_interface); case FIB_PATH_TYPE_RECURSIVE: - return (fib_entry_get_resolving_interface(path->fp_via_fib)); + if (fib_path_is_resolved(path_index)) + { + return (fib_entry_get_resolving_interface(path->fp_via_fib)); + } + break; case FIB_PATH_TYPE_INTF_RX: case FIB_PATH_TYPE_SPECIAL: case FIB_PATH_TYPE_DEAG: @@ -1742,7 +1777,7 @@ fib_path_get_adj (fib_node_index_t path_index) return (ADJ_INDEX_INVALID); } -int +u16 fib_path_get_weight (fib_node_index_t path_index) { fib_path_t *path; @@ -1754,6 +1789,18 @@ fib_path_get_weight (fib_node_index_t path_index) return (path->fp_weight); } +u16 +fib_path_get_preference (fib_node_index_t path_index) +{ + fib_path_t *path; + + path = fib_path_get(path_index); + + ASSERT(path); + + return (path->fp_preference); +} + /** * @brief Contribute the path's adjacency to the list passed. * By calling this function over all paths, recursively, a child @@ -1782,11 +1829,12 @@ fib_path_contribute_urpf (fib_node_index_t path_index, break; case FIB_PATH_TYPE_RECURSIVE: - if (FIB_NODE_INDEX_INVALID != path->fp_via_fib) + if (FIB_NODE_INDEX_INVALID != path->fp_via_fib && + !fib_path_is_looped(path_index)) { /* * there's unresolved due to constraints, and there's unresolved - * due to ain't go no via. can't do nowt w'out via. + * due to ain't got no via. can't do nowt w'out via. */ fib_entry_contribute_urpf(path->fp_via_fib, urpf); } @@ -1965,7 +2013,20 @@ fib_path_contribute_forwarding (fib_node_index_t path_index, case FIB_FORW_CHAIN_TYPE_MPLS_EOS: case FIB_FORW_CHAIN_TYPE_ETHERNET: case FIB_FORW_CHAIN_TYPE_NSH: - break; + { + adj_index_t ai; + + /* + * get a appropriate link type adj. + */ + ai = fib_path_attached_get_adj( + path, + fib_forw_chain_type_to_link_type(fct)); + dpo_set(dpo, DPO_ADJACENCY, + fib_forw_chain_type_to_dpo_proto(fct), ai); + adj_unlock(ai); + break; + } case FIB_FORW_CHAIN_TYPE_MCAST_IP4: case FIB_FORW_CHAIN_TYPE_MCAST_IP6: { @@ -2026,13 +2087,15 @@ fib_path_append_nh_for_multipath_hash (fib_node_index_t path_index, } int -fib_path_is_recursive (fib_node_index_t path_index) +fib_path_is_recursive_constrained (fib_node_index_t path_index) { fib_path_t *path; path = fib_path_get(path_index); - return (FIB_PATH_TYPE_RECURSIVE == path->fp_type); + return ((FIB_PATH_TYPE_RECURSIVE == path->fp_type) && + ((path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED) || + (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_RESOLVE_HOST))); } int @@ -2078,7 +2141,7 @@ fib_path_is_looped (fib_node_index_t path_index) return (path->fp_oper_flags & FIB_PATH_OPER_FLAG_RECURSIVE_LOOP); } -int +fib_path_list_walk_rc_t fib_path_encode (fib_node_index_t path_list_index, fib_node_index_t path_index, void *ctx) @@ -2089,9 +2152,10 @@ fib_path_encode (fib_node_index_t path_list_index, path = fib_path_get(path_index); if (!path) - return (0); + return (FIB_PATH_LIST_WALK_CONTINUE); vec_add2(*api_rpaths, api_rpath, 1); api_rpath->rpath.frp_weight = path->fp_weight; + api_rpath->rpath.frp_preference = path->fp_preference; api_rpath->rpath.frp_proto = path->fp_nh_proto; api_rpath->rpath.frp_sw_if_index = ~0; api_rpath->dpo = path->exclusive.fp_ex_dpo; @@ -2100,9 +2164,11 @@ fib_path_encode (fib_node_index_t path_list_index, case FIB_PATH_TYPE_RECEIVE: api_rpath->rpath.frp_addr = path->receive.fp_addr; api_rpath->rpath.frp_sw_if_index = path->receive.fp_interface; + api_rpath->dpo = path->fp_dpo; break; case FIB_PATH_TYPE_ATTACHED: api_rpath->rpath.frp_sw_if_index = path->attached.fp_interface; + api_rpath->dpo = path->fp_dpo; break; case FIB_PATH_TYPE_ATTACHED_NEXT_HOP: api_rpath->rpath.frp_sw_if_index = path->attached_next_hop.fp_interface; @@ -2118,7 +2184,7 @@ fib_path_encode (fib_node_index_t path_list_index, default: break; } - return (1); + return (FIB_PATH_LIST_WALK_CONTINUE); } fib_protocol_t