zebra: Copy the NHG ID in copy_state for NHT events#21892
Conversation
The copy_state function creates a temporary copy of the route entry's nexthop group for use in nexthop tracking (NHT) notifications to protocol clients. When zebra forwards an NHT event to fpmsyncd, the nexthop group ID stored in the copied nhe should be preserved so that fpmsyncd can identify the NHG and build the FIB entry correctly. Change the ID argument of zebra_nhe_copy from 0 to re->nhe->id so that the copied NHE carries the correct identifier. Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
Greptile SummaryThis PR fixes a one-line bug in
Confidence Score: 5/5Safe to merge; the one-line change is narrowly scoped and well-supported by existing patterns in the codebase. The fix is a single-line correction that passes the real NHG ID rather than 0 to zebra_nhe_copy. The free path (free_state → zebra_nhg_free) only releases memory and never performs hash-table removal, so a non-zero ID in the copy cannot corrupt the live NHE. The same pattern of copying an NHE with its real ID already exists in zebra_nhg.c at multiple call sites, confirming the approach is sound. No files require special attention; the change is confined to a single call site in zebra_rnh.c. Important Files Changed
Sequence DiagramsequenceDiagram
participant ZebraRIB as Zebra RIB
participant copy_state
participant rnh_state as rnh->state (snapshot)
participant notify as zebra_rnh_notify_protocol_clients
participant fpmsyncd
ZebraRIB->>copy_state: "re (route_entry with nhe->id=X)"
copy_state->>copy_state: "zebra_nhe_copy(re->nhe, re->nhe->id)"
Note over copy_state: Before fix: id=0 in copy<br/>After fix: id=X preserved in copy
copy_state->>rnh_state: "state->nhe->id = X (preserved)"
copy_state->>notify: "rnh->state passed to clients"
notify->>fpmsyncd: "NHT event with NHG id=X"
Note over fpmsyncd: Can now identify NHG<br/>and build FIB entry correctly
Reviews (1): Last reviewed commit: "zebra: Copy the NHG ID in copy_state for..." | Re-trigger Greptile |
|
Hi @mjstapp , I noticed the zebra_nhe_copy call in copy_state passes 0 for the ID argument. Is there a specific reason for that? We're looking at preserving the NHE ID in NHT events for fpmsyncd and wanted to understand the original design intent. Thanks. |
|
I think, if you look at the
|
| state->status = re->status; | ||
|
|
||
| state->nhe = zebra_nhe_copy(re->nhe, 0); | ||
| state->nhe = zebra_nhe_copy(re->nhe, re->nhe->id); |
There was a problem hiding this comment.
it might be safer to use a separate dedicated cell for the id that's being referenced. I'm a little concerned about possible side-effects if there's a copy with a valid id.
The copy_state function creates a temporary copy of the route entry's nexthop group for use in nexthop tracking (NHT) notifications to protocol clients. When zebra forwards an NHT event to fpmsyncd, the nexthop group ID stored in the copied nhe should be preserved so that fpmsyncd can identify the NHG and build the FIB entry correctly.
Change the ID argument of zebra_nhe_copy from 0 to re->nhe->id so that the copied NHE carries the correct identifier.