Skip to content

Commit

Permalink
bgpd: clarify nht path validity logic
Browse files Browse the repository at this point in the history
path_valid is the previous path validity state. Setting BGP_PATH_VALID
to true if path_valid is false is confusing.

Clarify the logic.

Signed-off-by: Louis Scalbert <[email protected]>
  • Loading branch information
louis-6wind committed Feb 9, 2022
1 parent 74309be commit f3fc37a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions bgpd/bgp_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
safi_t safi;
struct bgp *bgp_path;
const struct prefix *p;
bool path_valid_changed, bnc_is_valid_nexthop;

if (BGP_DEBUG(nht, NHT)) {
char buf[PREFIX2STR_BUFFER];
Expand Down Expand Up @@ -1019,8 +1020,7 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
* do not check for a valid label.
*/

bool bnc_is_valid_nexthop = false;
bool path_valid = false;
bnc_is_valid_nexthop = false;

if (safi == SAFI_UNICAST && path->sub_type == BGP_ROUTE_IMPORTED
&& path->extra && path->extra->num_labels
Expand Down Expand Up @@ -1076,23 +1076,24 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
|| path->attr->srte_color != 0)
SET_FLAG(path->flags, BGP_PATH_IGP_CHANGED);

path_valid = CHECK_FLAG(path->flags, BGP_PATH_VALID);
if (path_valid != bnc_is_valid_nexthop) {
if (path_valid) {
/* No longer valid, clear flag */
bgp_aggregate_decrement(bgp_path, p, path, afi,
safi);
bgp_path_info_unset_flag(dest, path,
BGP_PATH_VALID);
} else {
path_valid_changed = CHECK_FLAG(path->flags, BGP_PATH_VALID) !=
bnc_is_valid_nexthop;
if (path_valid_changed) {
if (bnc_is_valid_nexthop) {
/* Path becomes valid, set flag */
bgp_path_info_set_flag(dest, path,
BGP_PATH_VALID);
bgp_aggregate_increment(bgp_path, p, path, afi,
safi);
} else {
/* No longer valid, clear flag */
bgp_aggregate_decrement(bgp_path, p, path, afi,
safi);
bgp_path_info_unset_flag(dest, path,
BGP_PATH_VALID);
}
}
if ((path_valid != bnc_is_valid_nexthop ||
if ((path_valid_changed ||
CHECK_FLAG(path->flags, BGP_PATH_IGP_CHANGED)) &&
safi == SAFI_EVPN &&
bgp_evpn_is_prefix_nht_supported(
Expand Down

0 comments on commit f3fc37a

Please sign in to comment.