Skip to content

bgpd: Move link_bw from attr_extra to bgp_path_info_extra - #22093

Merged
donaldsharp merged 1 commit into
FRRouting:masterfrom
opensourcerouting:fix/move_link_bw_from_attr_extra_to_bgp_path_info_extra
May 28, 2026
Merged

bgpd: Move link_bw from attr_extra to bgp_path_info_extra#22093
donaldsharp merged 1 commit into
FRRouting:masterfrom
opensourcerouting:fix/move_link_bw_from_attr_extra_to_bgp_path_info_extra

Conversation

@ton31337

Copy link
Copy Markdown
Member

No description provided.

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-apps

greptile-apps Bot commented May 28, 2026

Copy link
Copy Markdown

Greptile Summary

This PR removes the cached link_bw field from attr_extra and the associated bgp_attr_get_link_bw/bgp_attr_set_link_bw helpers, replacing eager extraction at attribute-parse time with an on-demand bgp_path_info_get_link_bw function that reads directly from the path's extended communities. It also fixes a latent side-effect bug in bgp_zebra_announce_parse_nexthop where the shared mpinfo->attr was being mutated mid-loop.

  • bgp_attr.c / bgp_attr.h: Removes link_bw from attr_extra, the get/set inline helpers, and the bgp_attr_set_link_bw(attr, 0) cleanup calls in bgp_attr_unintern_sub and bgp_attr_flush.
  • bgp_route.c / bgp_route.h: Adds bgp_path_info_get_link_bw, which calls ecommunity_linkbw_present on demand (standard then IPv6 ecommunity fallback).
  • bgp_zebra.c: Rewires bgp_zebra_use_nhop_weighted to accept struct bgp_path_info * directly, eliminating the per-nexthop attr mutation in the announce loop.

Confidence Score: 4/5

Safe 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

Filename Overview
bgpd/bgp_attr.h Removes link_bw field from attr_extra and the bgp_attr_get_link_bw/bgp_attr_set_link_bw inline helpers; cleans up refcount management logic tied to this cached field.
bgpd/bgp_attr.c Drops the eager ecommunity_linkbw_present extraction in both bgp_attr_ext_communities and bgp_attr_ipv6_ext_communities, and removes the bgp_attr_set_link_bw(attr, 0) cleanup calls from bgp_attr_unintern_sub and bgp_attr_flush.
bgpd/bgp_route.c Introduces bgp_path_info_get_link_bw, which computes link bandwidth on demand by calling ecommunity_linkbw_present rather than reading a cached value; called in the per-nexthop announce loop.
bgpd/bgp_route.h Exports the new bgp_path_info_get_link_bw declaration.
bgpd/bgp_zebra.c Updates bgp_zebra_use_nhop_weighted to accept struct bgp_path_info * instead of struct attr *, and removes the inline extraction + mutation of mpinfo->attr's link_bw in the announce loop.

Sequence Diagram

sequenceDiagram
    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
Loading
Prompt To Fix All With AI
Fix 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

Comment thread bgpd/bgp_route.c
Comment thread bgpd/bgp_route.c
@donaldsharp
donaldsharp merged commit 02c3c84 into FRRouting:master May 28, 2026
25 checks passed
@ton31337
ton31337 deleted the fix/move_link_bw_from_attr_extra_to_bgp_path_info_extra branch May 29, 2026 05:39
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.

2 participants