Skip to content

zebra: fix wrong comparision for nexthop#21503

Open
anlancs wants to merge 1 commit intoFRRouting:masterfrom
anlancs:zebra/fix-cmp-nexthop
Open

zebra: fix wrong comparision for nexthop#21503
anlancs wants to merge 1 commit intoFRRouting:masterfrom
anlancs:zebra/fix-cmp-nexthop

Conversation

@anlancs
Copy link
Copy Markdown
Contributor

@anlancs anlancs commented Apr 11, 2026

By accident, i found the "same" field in log of the nexthop was actually opposite. Regardless of whether it is active or not, "same" field should be true.

Before:

ZEBRA: [M8H8E-HFGSQ] zebra_nhg_nexthop_compare: 3.3.3.3/32 Comparing via 192.168.0.1, enp2s0(1) ACTIVE: 1 to old: via 192.168.0.1, enp2s0(3) ACTIVE: 1 nexthop same: 0

After:

ZEBRA: [M8H8E-HFGSQ] zebra_nhg_nexthop_compare: 3.3.3.3/32 Comparing via 192.168.0.1, enp2s0(1) ACTIVE: 1 to old: via 192.168.0.1, enp2s0(3) ACTIVE: 1 nexthop same: 1

And this commit should affect the scenarios where nexthop_same_no_ifindex is introduced.

By accident, i found the "same" field in log of the nexthop was actually opposite.
Regardless of whether it is active or not, "same" field should be true.

Before:
```
ZEBRA: [M8H8E-HFGSQ] zebra_nhg_nexthop_compare: 3.3.3.3/32 Comparing via 192.168.0.1, enp2s0(1) ACTIVE: 1 to old: via 192.168.0.1, enp2s0(3) ACTIVE: 1 nexthop same: 0
```

After:
```
ZEBRA: [M8H8E-HFGSQ] zebra_nhg_nexthop_compare: 3.3.3.3/32 Comparing via 192.168.0.1, enp2s0(1) ACTIVE: 1 to old: via 192.168.0.1, enp2s0(3) ACTIVE: 1 nexthop same: 1
```

And this commit should affect the scenarios where `nexthop_same_no_ifindex` is introduced.

Signed-off-by: anlan_cs <[email protected]>
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 11, 2026

Greptile Summary

This PR fixes an inverted boolean return in nexthop_same_no_ifindex where the raw integer result of nexthop_cmp_internal (a comparator that returns 0 for equality) was being cast directly to bool, causing the function to return false when nexthops are identical and true when they differ. The one-line fix adds == 0 to correctly map the comparator semantics to boolean "same" semantics, consistent with how nexthop_same and nexthop_same_no_labels handle the same pattern.

Confidence Score: 5/5

This PR is safe to merge — it is a correct, minimal one-line bug fix with no side effects.

The change fixes a clear boolean-inversion bug (comparator returning 0-for-equal being cast to bool) in a single line, consistent with the established pattern in sibling functions nexthop_same and nexthop_same_no_labels. No other issues were identified.

No files require special attention.

Important Files Changed

Filename Overview
lib/nexthop.c Fixes inverted boolean return in nexthop_same_no_ifindex by adding == 0 comparison — correct, minimal, and consistent with sibling functions.

Reviews (1): Last reviewed commit: "zebra: fix wrong comparision for nexthop" | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant