zebra: fix wrong comparision for nexthop#228
Conversation
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 <anlan_cs@126.com>
Greptile SummaryFixes a boolean inversion bug in
|
| Filename | Overview |
|---|---|
| lib/nexthop.c | Fixes inverted boolean return in nexthop_same_no_ifindex: nexthop_cmp_internal is a comparator returning 0 for equal, but the bare return was casting non-zero (not equal) to true and 0 (equal) to false — the exact opposite of the function's contract. Fix is correct and consistent with all other nexthop_same_* helpers. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["nexthop_same_no_ifindex(nh1, nh2)"] --> B{nh1 && !nh2\nor !nh1 && nh2?}
B -- yes --> C["return false"]
B -- no --> D{nh1 == nh2?}
D -- yes --> E["return true"]
D -- no --> F["nexthop_cmp_internal(nh1, nh2, true, false)"]
F --> G["returns int: 0 if equal, ±N if different"]
G --> H_OLD["[BEFORE] return int directly as bool\n0 → false (same→wrong!)\n±N → true (different→wrong!)"]
G --> H_NEW["[AFTER] return == 0\n0 → true (same→correct ✓)\n±N → false (different→correct ✓)"]
style H_OLD fill:#ffcccc,stroke:#cc0000
style H_NEW fill:#ccffcc,stroke:#006600
Prompt To Fix All With AI
This is a comment left during a code review.
Path: lib/nexthop.c
Line: 464
Comment:
**Missing topotest for behavioral fix**
This corrects a long-standing inversion in `zebra_nhg_nexthop_compare` — nexthops that are the same were reported as different, and vice versa. That is a substantive behavioral change in NHG install/update logic and requires a topotest to verify the fix and prevent regression. The existing `tests/topotests/zebra_nhg_check/` suite is the natural home for a case that exercises a route with two equal nexthops on different interface indices and verifies the NHG is not spuriously re-installed.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "zebra: fix wrong comparision for nexthop" | Re-trigger Greptile
| return true; | ||
|
|
||
| return nexthop_cmp_internal(nh1, nh2, true, false); | ||
| return (nexthop_cmp_internal(nh1, nh2, true, false) == 0); |
There was a problem hiding this comment.
Missing topotest for behavioral fix
This corrects a long-standing inversion in zebra_nhg_nexthop_compare — nexthops that are the same were reported as different, and vice versa. That is a substantive behavioral change in NHG install/update logic and requires a topotest to verify the fix and prevent regression. The existing tests/topotests/zebra_nhg_check/ suite is the natural home for a case that exercises a route with two equal nexthops on different interface indices and verifies the NHG is not spuriously re-installed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/nexthop.c
Line: 464
Comment:
**Missing topotest for behavioral fix**
This corrects a long-standing inversion in `zebra_nhg_nexthop_compare` — nexthops that are the same were reported as different, and vice versa. That is a substantive behavioral change in NHG install/update logic and requires a topotest to verify the fix and prevent regression. The existing `tests/topotests/zebra_nhg_check/` suite is the natural home for a case that exercises a route with two equal nexthops on different interface indices and verifies the NHG is not spuriously re-installed.
How can I resolve this? If you propose a fix, please make it concise.
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:
After:
And this commit should affect the scenarios where
nexthop_same_no_ifindexis introduced.Original PR21503 by anlancs