bgpd: Move link_bw from attr_extra to bgp_path_info_extra - #22093
Conversation
attr and attr_extra are "designed" for BGP attributes, but link_bw is not an actual BGP attribute, it's derived from Extended Community. Let's move it to bgp_path_info_extra. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Greptile SummaryThis PR removes the cached
Confidence Score: 4/5Safe to merge; the refactoring correctly removes attr mutation side-effects and functional behaviour is preserved. The change fixes a latent attr-mutation bug in the zebra announce loop, but introduces per-nexthop ecommunity scanning in place of a cached O(1) read, and misses a consolidation opportunity in bgp_mpath.c. bgpd/bgp_route.c and its per-nexthop call site in bgpd/bgp_zebra.c deserve a second look for scale implications. Important Files Changed
Sequence DiagramsequenceDiagram
participant Parser as bgp_attr_ext_communities (parse time)
participant Announce as bgp_zebra_announce_parse_nexthop
participant WeightFn as bgp_zebra_use_nhop_weighted
participant LinkBW as bgp_path_info_get_link_bw (NEW)
participant ECom as ecommunity_linkbw_present
note over Parser: BEFORE (removed): link_bw extracted once and cached in attr_extra
Parser->>ECom: "ecommunity_linkbw_present(ecom, &link_bw)"
Parser->>Parser: bgp_attr_set_link_bw(attr, link_bw)
note over Announce: BEFORE: O(1) cached lookup
Announce->>WeightFn: "bgp_zebra_use_nhop_weighted(bgp, attr, &weight)"
WeightFn->>WeightFn: bgp_attr_get_link_bw(attr) - read cached value
note over Announce: AFTER (new): on-demand parse per nexthop
loop for each mpinfo
Announce->>WeightFn: "bgp_zebra_use_nhop_weighted(bgp, mpinfo, &weight)"
WeightFn->>LinkBW: bgp_path_info_get_link_bw(bpi)
LinkBW->>ECom: "ecommunity_linkbw_present(ecommunity, &link_bw)"
alt link_bw not found
LinkBW->>ECom: "ecommunity_linkbw_present(ipv6_ecommunity, &link_bw)"
end
LinkBW-->>WeightFn: link_bw
end
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
bgpd/bgp_route.c:440-452
**On-demand parsing called per nexthop in a hot loop**
`bgp_path_info_get_link_bw` is called once per multipath nexthop in `bgp_zebra_announce_parse_nexthop` (inside the `for (; mpinfo; ...)` loop). Previously the value was extracted once during attribute parsing and cached in `attr_extra->link_bw` for O(1) lookup. Now it calls `ecommunity_linkbw_present`, which linearly scans all ecommunity entries, on every nexthop iteration. For large multipath groups over link-BW ECMP this will scan the ecommunity list O(nexthops) times rather than once at parse time. The impact is bounded by typically small ecommunity list sizes, but it is a measurable regression on the critical path of route installation.
### Issue 2 of 2
bgpd/bgp_route.c:436-452
**Duplicate two-step ecommunity check pattern in `bgp_mpath.c` not consolidated**
`bgp_mpath.c` lines 554β558 contain the same identical two-step `ecommunity_linkbw_present` fallback pattern (`ecommunity` β `ipv6_ecommunity`) that this new helper encapsulates. If the intent is to centralise link-bandwidth extraction through `bgp_path_info_get_link_bw`, the `bgp_mpath.c` site is an obvious candidate for the same treatment.
Reviews (1): Last reviewed commit: "bgpd: Move link_bw from attr_extra to bg..." | Re-trigger Greptile |
No description provided.