Skip to content

bgpd: register ENCAP and LINK_STATE in attr_flags_values table#22443

Open
guoguojia2021 wants to merge 2 commits into
FRRouting:masterfrom
guoguojia2021:fix/bgpd-attr-flags-missing-encap-linkstate
Open

bgpd: register ENCAP and LINK_STATE in attr_flags_values table#22443
guoguojia2021 wants to merge 2 commits into
FRRouting:masterfrom
guoguojia2021:fix/bgpd-attr-flags-missing-encap-linkstate

Conversation

@guoguojia2021

Copy link
Copy Markdown
Contributor

The attr_flags_values array was missing entries for BGP_ATTR_ENCAP (type 23) and BGP_ATTR_LINK_STATE (type 29). Without a registered entry, bgp_attr_flag_invalid() returns false early and skips all flag validation for these attributes, allowing malformed UPDATE messages with incorrect Optional/Transitive bits to be silently accepted instead of generating a NOTIFICATION.

Add:

  • BGP_ATTR_ENCAP: Optional + Transitive (RFC 5512)
  • BGP_ATTR_LINK_STATE: Optional (RFC 7752 Section 3.3.1, RFC 9552 Section 4)

@frrbot frrbot Bot added the bgp label Jun 22, 2026
@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown

Greptile Summary

Fixes a flag-validation gap in bgp_attr_flag_invalid() where BGP_ATTR_ENCAP (type 23) and BGP_ATTR_LINK_STATE (type 29) had no entries in attr_flags_values[], causing the function to hit the early-exit == 0 guard and skip all flag checks for these attribute types.

  • Adds [BGP_ATTR_ENCAP] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS (Optional+Transitive, per RFC 5512).
  • Adds [BGP_ATTR_LINK_STATE] = BGP_ATTR_FLAG_OPTIONAL (Optional non-transitive, per RFC 9552 §4 / RFC 7752 §3.3.1).

Confidence Score: 5/5

Safe to merge — two-line addition to a designated-initializer table with flag values confirmed against the relevant RFCs.

Both added entries match their RFC-mandated flags: RFC 5512 defines ENCAP (type 23) as Optional+Transitive, and RFC 9552 §4 defines BGP-LS (type 29) as Optional non-transitive. The designated-initializer syntax means no existing entries are disturbed and array bounds are unaffected, since both new indices (23 and 29) fall well within the current array size (largest existing index is BGP_ATTR_PREFIX_SID = 40).

No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_attr.c Adds BGP_ATTR_ENCAP (type 23, Optional+Transitive per RFC 5512) and BGP_ATTR_LINK_STATE (type 29, Optional non-transitive per RFC 9552) to the attr_flags_values table so bgp_attr_flag_invalid() no longer silently skips flag validation for these two attribute types.

Reviews (1): Last reviewed commit: "bgpd: register ENCAP and LINK_STATE in a..." | Re-trigger Greptile

@riw777 riw777 left a comment

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.

looks good

@riw777

riw777 commented Jun 23, 2026

Copy link
Copy Markdown
Member

@ton31337 should this have a topo test to check that we're not accepting updates with incorrect transitive/optional bits? I can see where this would be useful, but I don't know if it should be included in this pr.

@ton31337

Copy link
Copy Markdown
Member

That would be like a good addition to have a separate topotest to include all well-known attributes to be tested against transitivness, IMO.

@frrbot frrbot Bot added the tests Topotests, make check, etc label Jun 26, 2026
@github-actions github-actions Bot added size/L and removed size/XS labels Jun 26, 2026
@guoguojia2021 guoguojia2021 force-pushed the fix/bgpd-attr-flags-missing-encap-linkstate branch 6 times, most recently from 2e4e1a1 to 555835a Compare June 29, 2026 03:32
Comment thread tests/topotests/bgp_attr_flag_validation/test_bgp_attr_flag_validation.py Outdated
Comment thread bgpd/bgp_attr.c Outdated
The attr_flags_values array was missing entries for BGP_ATTR_ENCAP
(type 23) and BGP_ATTR_LINK_STATE (type 29). Without a registered
entry, bgp_attr_flag_invalid() returns false early and skips all
flag validation for these attributes, allowing malformed UPDATE
messages with incorrect Optional/Transitive bits to be silently
accepted instead of generating a NOTIFICATION.

Add:
  - BGP_ATTR_ENCAP: Optional + Transitive (RFC 5512)
  - BGP_ATTR_LINK_STATE: Optional (RFC 7752 Section 3.3.1,
    RFC 9552 Section 4)

Signed-off-by: Zhongfeng Guo <guozhongfeng.gzf@alibaba-inc.com>
@guoguojia2021 guoguojia2021 force-pushed the fix/bgpd-attr-flags-missing-encap-linkstate branch 2 times, most recently from 22329d9 to 385655f Compare June 29, 2026 08:19
@ton31337

ton31337 commented Jul 1, 2026

Copy link
Copy Markdown
Member

@guoguojia2021, please use real first/last names in the Signed-off-by tag...

Add a comprehensive topotest that validates BGP correctly handles routes
with malformed attribute flags using treat-as-withdraw behavior per RFC 7606.

The test uses ExaBGP to dynamically announce routes in two phases:
1. First, announce routes with CORRECT flags (should be accepted)
2. Then, announce the same routes with WRONG flags (should be withdrawn)

Tested attributes:
- ENCAP (type 23): correct=0xC0 (Optional+Transitive), wrong=0x40 (Optional only)
- LINK_STATE (type 29): correct=0x80 (Optional), wrong=0x40 (Transitive)
- ORIGIN (type 1): correct=0x40 (Transitive), wrong=0x80 (Optional)

Expected behavior: routes with wrong flags are treated as withdrawn, BGP
session remains established.

Signed-off-by: Zhongfeng Guo <guozhongfeng.gzf@alibaba-inc.com>
@guoguojia2021 guoguojia2021 force-pushed the fix/bgpd-attr-flags-missing-encap-linkstate branch from 385655f to 4b3a298 Compare July 2, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bgp master rebase PR needs rebase size/L tests Topotests, make check, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants