diff --git a/lib/nexthop.c b/lib/nexthop.c index 65c12c1e6931..04bf7874611b 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -139,7 +139,7 @@ static int _nexthop_source_cmp(const struct nexthop *nh1, } static int _nexthop_cmp_no_labels(const struct nexthop *next1, - const struct nexthop *next2) + const struct nexthop *next2, bool use_weight) { int ret = 0; @@ -155,11 +155,13 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1, if (next1->type > next2->type) return 1; - if (next1->weight < next2->weight) - return -1; + if (use_weight) { + if (next1->weight < next2->weight) + return -1; - if (next1->weight > next2->weight) - return 1; + if (next1->weight > next2->weight) + return 1; + } switch (next1->type) { case NEXTHOP_TYPE_IPV4: @@ -227,11 +229,12 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1, return ret; } -int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2) +int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2, + bool use_weight) { int ret = 0; - ret = _nexthop_cmp_no_labels(next1, next2); + ret = _nexthop_cmp_no_labels(next1, next2, use_weight); if (ret != 0) return ret; @@ -423,7 +426,7 @@ bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2) if (nh1 == nh2) return true; - if (nexthop_cmp(nh1, nh2) != 0) + if (nexthop_cmp(nh1, nh2, true) != 0) return false; return true; @@ -441,7 +444,7 @@ bool nexthop_same_no_labels(const struct nexthop *nh1, if (nh1 == nh2) return true; - if (_nexthop_cmp_no_labels(nh1, nh2) != 0) + if (_nexthop_cmp_no_labels(nh1, nh2, true) != 0) return false; return true; diff --git a/lib/nexthop.h b/lib/nexthop.h index 27073b948dea..63e4416eee78 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -206,7 +206,8 @@ uint32_t nexthop_hash_quick(const struct nexthop *nexthop); extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2); extern bool nexthop_same_no_labels(const struct nexthop *nh1, const struct nexthop *nh2); -extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2); +extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2, + bool use_weight); extern int nexthop_g_addr_cmp(enum nexthop_types_t type, const union g_addr *addr1, const union g_addr *addr2); diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 3f408e0a71f9..1bf6d965b7e3 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -301,7 +301,7 @@ static void _nexthop_add_sorted(struct nexthop **head, for (position = *head, prev = NULL; position; prev = position, position = position->next) { - if (nexthop_cmp(position, nexthop) > 0) { + if (nexthop_cmp(position, nexthop, true) > 0) { nexthop->next = position; nexthop->prev = prev; @@ -334,7 +334,7 @@ void nexthop_group_add_sorted(struct nexthop_group *nhg, */ tail = nexthop_group_tail(nhg); - if (tail && (nexthop_cmp(tail, nexthop) < 0)) { + if (tail && (nexthop_cmp(tail, nexthop, true) < 0)) { tail->next = nexthop; nexthop->prev = tail; @@ -405,7 +405,7 @@ void nexthop_group_copy_nh_sorted(struct nexthop_group *nhg, for (nh1 = nh; nh1; nh1 = nh1->next) { nexthop = nexthop_dup(nh1, NULL); - if (tail && (nexthop_cmp(tail, nexthop) < 0)) { + if (tail && (nexthop_cmp(tail, nexthop, true) < 0)) { tail->next = nexthop; nexthop->prev = tail; diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 303a81bb3e2b..70b0e9349d32 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -936,7 +936,7 @@ static struct nexthop *next_valid_primary_nh(struct route_entry *re, nhg = rib_get_fib_nhg(re); for (bnh = nhg->nexthop; bnh; bnh = nexthop_next(bnh)) { - if (nexthop_cmp(nh, bnh) == 0) + if (nexthop_cmp(nh, bnh, true) == 0) break; } @@ -1010,7 +1010,7 @@ static bool compare_valid_nexthops(struct route_entry *r1, if (nh1 && nh2) { /* Any difference is a no-match */ - if (nexthop_cmp(nh1, nh2) != 0) { + if (nexthop_cmp(nh1, nh2, true) != 0) { if (IS_ZEBRA_DEBUG_NHT_DETAILED) zlog_debug("%s: nh1: %pNHv, nh2: %pNHv differ", __func__, nh1, nh2); @@ -1078,7 +1078,7 @@ static bool compare_valid_nexthops(struct route_entry *r1, if (nh1 && nh2) { /* Any difference is a no-match */ - if (nexthop_cmp(nh1, nh2) != 0) { + if (nexthop_cmp(nh1, nh2, true) != 0) { if (IS_ZEBRA_DEBUG_NHT_DETAILED) zlog_debug("%s: backup nh1: %pNHv, nh2: %pNHv differ", __func__, nh1, nh2);