Skip to content

bgpd: initialise nh_flag attribute#21498

Open
fdumontet6WIND wants to merge 2 commits intoFRRouting:masterfrom
fdumontet6WIND:init_attr
Open

bgpd: initialise nh_flag attribute#21498
fdumontet6WIND wants to merge 2 commits intoFRRouting:masterfrom
fdumontet6WIND:init_attr

Conversation

@fdumontet6WIND
Copy link
Copy Markdown
Contributor

in "leak_update" function
nh_flag is not initialized when nexthop is valid at route creation.

@frrbot frrbot bot added the bgp label Apr 10, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 10, 2026

Greptile Summary

This PR fixes a bug in leak_update() where BGP_ATTR_NH_VALID was never set in new->attr->nh_flags for newly-created leaked routes when the nexthop is valid. As part of the fix, the function is refactored to accept a non-interned static_attr instead of a pre-interned new_attr, moving all bgp_attr_intern() calls into leak_update() itself. The refactoring is internally consistent: the early-return "no change" path no longer calls bgp_attr_unintern, the update path interns at line 1354, and the new-route path interns at line 1447 — after setting the flag.

The code correctly sets SET_FLAG(new->attr->nh_flags, BGP_ATTR_NH_VALID) while new->attr still points to the uninterned static_attr, then immediately replaces new->attr with the interned copy via bgp_attr_intern(static_attr). Since bgp_attr_intern hashes on all fields including nh_flags, the interned attr captures the flag correctly.

Confidence Score: 5/5

Safe to merge — the fix is correct and the refactoring is internally consistent with no logic regressions.

The bug fix correctly initialises BGP_ATTR_NH_VALID in nh_flags before the attr is interned. The accompanying refactoring (moving bgp_attr_intern into leak_update) is sound: the "no change" early return no longer needs bgp_attr_unintern, the update path interns before setting bpi->attr, the new-route path interns after setting the flag, and bgp_attr_flush in callers is correctly placed after leak_update returns. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_mplsvpn.c Refactors leak_update() to accept a non-interned attr, moves bgp_attr_intern calls inside the function, and adds the missing SET_FLAG(new->attr->nh_flags, BGP_ATTR_NH_VALID) for the new-route creation path; logic is correct.

Sequence Diagram

sequenceDiagram
    participant Caller as vpn_leak_to_vrf_update_onevrf
    participant LU as leak_update()
    participant AI as bgp_attr_intern()
    participant NHV as leak_update_nexthop_valid()

    Caller->>LU: leak_update(..., &static_attr [uninterned])
    Note over LU: New-route path
    LU->>LU: info_make(..., static_attr, bn) / new->attr = static_attr (uninterned)
    LU->>NHV: leak_update_nexthop_valid(..., new, ...)
    NHV-->>LU: nh_valid = true
    LU->>LU: bgp_path_info_set_flag(BGP_PATH_VALID)
    LU->>LU: SET_FLAG(new->attr->nh_flags, BGP_ATTR_NH_VALID)
    LU->>AI: bgp_attr_intern(static_attr)
    AI-->>LU: interned attr (nh_flags set)
    LU->>LU: new->attr = interned attr
    LU-->>Caller: new route
    Caller->>Caller: bgp_attr_flush(&static_attr)
Loading

Reviews (2): Last reviewed commit: "bgpd: initialise nh_flag attribute" | Re-trigger Greptile

Comment thread bgpd/bgp_mplsvpn.c Outdated
@fdumontet6WIND fdumontet6WIND force-pushed the init_attr branch 2 times, most recently from c2cf998 to dd5baf1 Compare April 10, 2026 15:48
Comment thread bgpd/bgp_mplsvpn.c
source_bpi, new, bgp_orig, p, debug)) {
bgp_path_info_set_flag(bn, new, BGP_PATH_VALID);
else
SET_FLAG(new->attr->nh_flags, BGP_ATTR_NH_VALID);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this BGP_ATTR_NH_VALID flag used anywhere at all in the code?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greptileai is this nh_flags (BGP_ATTR_NH_VALID) used anywhere despite SET/UNSET?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — BGP_ATTR_NH_VALID is not checked anywhere in the codebase. Searching the entire repo, it only appears in:

  1. bgpd/bgp_attr.h — the #define
  2. bgpd/bgp_mplsvpn.c — this PR's SET_FLAG call (and the corresponding UNSET_FLAG in the else branch)

There are zero CHECK_FLAG(attr->nh_flags, BGP_ATTR_NH_VALID) calls anywhere. The flag is defined, set, and unset — but never consumed. That makes this change a no-op from a behavioral standpoint, which raises the question of whether the fix is addressing the real bug, or whether BGP_ATTR_NH_VALID needs to actually be wired into nexthop resolution/route selection logic somewhere to have any meaningful effect.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules and .greptile/config.

This patch modifies `leak_update()` to accept a non-interned static
attribute rather than requiring an already-interned one.

Previously, callers such as `vpn_leak_to_vrf_update_onevrf()` and
`_vpn_leak_from_vrf_update_leak_attr()` would intern the attribute
prior to calling `leak_update()`. If `leak_update()` determined that
the route was unchanged, it would simply unintern the attribute and
continue, resulting in unnecessary memory allocation and hash table
overhead.

With this change, the caller passes a pointer to the static attribute,
and `leak_update()` now defers calling `bgp_attr_intern()` until it
actually needs to update an existing path or allocate a new one. The
callers handle flushing the static attribute when done.

Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
this commit fixes an issue during new path creation:
if the new leaked path is determined to have a valid nexthop, the
`BGP_ATTR_NH_VALID` flag is now correctly set on the  `nh_flags`.

Fixes: 879bfc0 (bgpd: fix VRF leaking with 'network import-check')
Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
@fdumontet6WIND
Copy link
Copy Markdown
Contributor Author

failure not linked with commit
ci:rerun

@mjstapp
Copy link
Copy Markdown
Contributor

mjstapp commented Apr 15, 2026

so you've now added a completely unrelated second commit - why?

@pguibert6WIND
Copy link
Copy Markdown
Member

so you've now added a completely unrelated second commit - why?

preparatory commit.
changing attr requires uninterning and re-interning it.
this rework avoids doing this, and will do an intern a single time.

@donaldsharp
Copy link
Copy Markdown
Member

@greptile review

@fdumontet6WIND fdumontet6WIND requested a review from ton31337 April 17, 2026 08:30
Copy link
Copy Markdown
Member

@ton31337 ton31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Seems BGP_ATTR_NH_VALID flag is not used at all (despite SET/UNSET);
  • 90c0b89 is not aimed for this PR?

@fdumontet6WIND
Copy link
Copy Markdown
Contributor Author

in fact BGP_ATTR_NH_VALID flag is tested in "attrhash_cmp" function.
old value is tested against the new one to detect change

@fdumontet6WIND
Copy link
Copy Markdown
Contributor Author

90c0b89
is to allowing change of nh_flags (with BGP_ATTR_NH_VALID) ,that can't be changed when it is unterned.

@fdumontet6WIND fdumontet6WIND requested a review from ton31337 April 20, 2026 09:49
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.

5 participants