diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index c4c08cf10c..72db9975fd 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -3097,6 +3097,58 @@ need_null_label: return true; } +/* Right now, since we only deal with per-prefix labels, it is not + * necessary to do this upon changes to best path. Exceptions: + * - label index has changed -> recalculate resulting label + * - path_info sub_type changed -> switch to/from null label value + * - no valid label (due to removed static label binding) -> get new one + */ +static void bgp_lu_handle_label_allocation(struct bgp *bgp, + struct bgp_dest *dest, + struct bgp_path_info *new_select, + struct bgp_path_info *old_select, + afi_t afi) +{ + mpls_label_t mpls_label_null; + + if (bgp->allocate_mpls_labels[afi][SAFI_UNICAST]) { + if (new_select) { + if (!old_select || + bgp_label_index_differs(new_select, old_select) || + new_select->sub_type != old_select->sub_type || + !bgp_is_valid_label(&dest->local_label)) { + /* control label imposition for local + * routes, aggregate and redistributed + * routes + */ + mpls_label_null = MPLS_LABEL_IMPLICIT_NULL; + if (bgp_lu_need_null_label(bgp, new_select, afi, + &mpls_label_null)) { + if (CHECK_FLAG( + dest->flags, + BGP_NODE_REGISTERED_FOR_LABEL) || + CHECK_FLAG( + dest->flags, + BGP_NODE_LABEL_REQUESTED)) + bgp_unregister_for_label(dest); + dest->local_label = mpls_lse_encode( + mpls_label_null, 0, 0, 1); + bgp_set_valid_label(&dest->local_label); + } else + bgp_register_for_label(dest, + new_select); + } + } else if (CHECK_FLAG(dest->flags, + BGP_NODE_REGISTERED_FOR_LABEL) || + CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) { + bgp_unregister_for_label(dest); + } + } else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL) || + CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) { + bgp_unregister_for_label(dest); + } +} + /* * old_select = The old best path * new_select = the new best path @@ -3123,7 +3175,6 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, struct bgp_path_info *old_select; struct bgp_path_info_pair old_and_new; int debug = 0; - mpls_label_t mpls_label_null; if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) { if (dest) @@ -3174,49 +3225,12 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, old_select = old_and_new.old; new_select = old_and_new.new; - /* Do we need to allocate or free labels? - * Right now, since we only deal with per-prefix labels, it is not - * necessary to do this upon changes to best path. Exceptions: - * - label index has changed -> recalculate resulting label - * - path_info sub_type changed -> switch to/from null label value - * - no valid label (due to removed static label binding) -> get new one - */ - if (bgp->allocate_mpls_labels[afi][safi]) { - if (new_select) { - if (!old_select - || bgp_label_index_differs(new_select, old_select) - || new_select->sub_type != old_select->sub_type - || !bgp_is_valid_label(&dest->local_label)) { - /* control label imposition for local routes, - * aggregate and redistributed routes - */ - mpls_label_null = MPLS_LABEL_IMPLICIT_NULL; - if (bgp_lu_need_null_label(bgp, new_select, afi, - &mpls_label_null)) { - if (CHECK_FLAG( - dest->flags, - BGP_NODE_REGISTERED_FOR_LABEL) - || CHECK_FLAG( - dest->flags, - BGP_NODE_LABEL_REQUESTED)) - bgp_unregister_for_label(dest); - dest->local_label = mpls_lse_encode( - mpls_label_null, 0, 0, 1); - bgp_set_valid_label(&dest->local_label); - } else - bgp_register_for_label(dest, - new_select); - } - } else if (CHECK_FLAG(dest->flags, - BGP_NODE_REGISTERED_FOR_LABEL) - || CHECK_FLAG(dest->flags, - BGP_NODE_LABEL_REQUESTED)) { - bgp_unregister_for_label(dest); - } - } else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL) - || CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) { - bgp_unregister_for_label(dest); - } + if (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST) + /* label unicast path : + * Do we need to allocate or free labels? + */ + bgp_lu_handle_label_allocation(bgp, dest, new_select, + old_select, afi); if (debug) zlog_debug(