Skip to content

frr: Strictly validate isolate BGP ASN - #29227

Open
ashutosh-agrawal wants to merge 7 commits into
sonic-net:masterfrom
ashutosh-agrawal:render-isolate-bgp-asn-as-integer
Open

ashutosh-agrawal wants to merge 7 commits into
sonic-net:masterfrom
ashutosh-agrawal:render-isolate-bgp-asn-as-integer

Conversation

@ashutosh-agrawal

@ashutosh-agrawal ashutosh-agrawal commented Aug 27, 2026

Copy link
Copy Markdown
Member

Why I did it

The isolate and unisolate templates expect DEVICE_METADATA|localhost bgp_asn to be numeric, but currently render its value directly into their generated routing command streams. Strictly validate the value during template rendering so malformed input stops rendering instead of being coerced into a different BGP instance.

Work item tracking
  • Microsoft ADO (number only): N/A

How I did it

  • Add a reusable strict ASN filter to sonic-cfggen.
  • Apply the filter in isolate.j2 and unisolate.j2.
  • Preserve valid decimal ASN values unchanged.
  • Render explicit successful no-op helpers when BGP is legitimately unconfigured
    (missing ASN, JSON null, or the existing case-insensitive none/null
    sentinels).
  • Verify configured and non-BGP rendering while malformed, coercible,
    out-of-range, Unicode, oversized, and sentinel-lookalike values fail
    rendering for both templates.

How to verify it

cd src/sonic-bgpcfgd && pytest -q tests/test_sonic-cfggen.py::test_isolate_templates_validate_bgp_asn

Result: 1 passed.

Which release branch to backport (provide reason below if selected)

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608

Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type: other

Tested branch

  • master
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608
  • N/A

Test result

  • master: focused template regression passed (1 passed)

Description for the changelog

Strictly validate the BGP ASN when rendering the isolate and unisolate scripts.

Link to config_db schema for YANG module changes

N/A - no YANG or CONFIG_DB schema change.

A picture of a cute animal (not mandatory but encouraged)

Ensure the isolate and unisolate scripts render a numeric BGP ASN before passing their command streams to vtysh.

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread dockers/docker-fpm-frr/frr/isolate.j2 Outdated
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@ashutosh-agrawal ashutosh-agrawal changed the title frr: Render isolate BGP ASN as an integer frr: Strictly validate isolate BGP ASN Aug 27, 2026
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@ashutosh-agrawal

Copy link
Copy Markdown
Member Author

/azpw run

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1204992:

✅Stage Test:

  • Job impacted-area-kvmtest-multi-asic-t1 by Elastictest: retried.
  • Job impacted-area-kvmtest-t2 by Elastictest: retried.
  • Job impacted-area-kvmtest-t1-lag by Elastictest: retried.
  • Job impacted-area-kvmtest-dualtor by Elastictest: retried.
  • Job impacted-area-kvmtest-t0 by Elastictest: retried.

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

qiluo-msft pushed a commit that referenced this pull request Sep 18, 2026
Why I did it
Several Python components need to apply the same validation when processing BGP ASNs. Keeping those checks in each component makes it easy for their behavior to drift.

Work item tracking
Microsoft ADO (number only):
How I did it
Added a common validate_asn() helper to sonic-py-common.

The helper accepts decimal strings and integer values, rejects booleans and other representations, and checks the 32-bit BGP ASN range. Handling of missing values or component-specific sentinel values remains with the caller.

Added unit coverage for accepted values, range boundaries, invalid types, and invalid decimal representations.

Current consumers being updated to use this helper:

bgpcfgd: Validate DEVICE_METADATA BGP ASN #29226 validates the DEVICE_METADATA BGP ASN before caching it.
frr: Strictly validate isolate BGP ASN #29227 uses it as the sonic-cfggen filter for BGP isolation templates.
frrcfgd: Validate BGP table key components #29230 uses it for BGP ASN fields processed by frrcfgd.
How to verify it
Run:

PYTHONPATH=src/sonic-py-common pytest -q --noconftest src/sonic-py-common/tests/test_bgp.py

Result: 22 passed.
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants