[sonic-bgpcfgd]: Validate dynamic peer-range names - #29448
qiluo-msft merged 10 commits into
Conversation
Require dynamic BGP peer-range names to be single-line values before FRR template processing. Reject CR and LF values before add or update handling and leave configuration state unchanged for unsupported names. Add regression coverage for LF, CR, and CRLF values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c208e923-9777-44d4-aab6-4da92b7abb44 Signed-off-by: Baiju Parameswaran <baijup@microsoft.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azpw retry |
|
Retrying failed(or canceled) jobs... |
|
Retrying failed(or canceled) stages in build 1216257: ✅Stage Test:
|
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The new validation currently returns False (which implies “retry later” and can cause requeueing), and the added test can yield false positives without resetting the mocked logger per iteration.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens sonic-bgpcfgd dynamic BGP peer-range handling by validating that peer-range names are single-line strings, preventing malformed multiline identifiers from generating invalid FRR configuration.
Changes:
- Add validation in the BGP peer manager to reject dynamic peer-range names containing CR/LF characters.
- Add regression tests covering
\n,\r, and\r\nin dynamic peer-range names.
File summaries
| File | Description |
|---|---|
| src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py | Adds a validation check for CR/LF in dynamic peer-range name before processing updates. |
| src/sonic-bgpcfgd/tests/test_bgp.py | Adds a new unit test verifying multiline dynamic peer-range names are rejected without updating state. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Treat rejected multiline dynamic peer-range names as permanently handled so Manager does not queue them for retry. Reset the logger mock per test case, require exactly one error, and verify invalid updates are not added to the retry queue. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c208e923-9777-44d4-aab6-4da92b7abb44 Signed-off-by: Baiju Parameswaran <baijup@microsoft.com>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟡 Changes recommended
The new validation runs only in set_handler(), so invalid multiline names can still be queued when dependencies are unmet, and the added “not queued” test doesn’t currently cover that queued code path.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
Validate dynamic peer-range names before dependency handling so permanent validation failures are not added to the retry queue. Keep set_handler validation as a defensive backstop and cover invalid, valid, non-dynamic, and delete handler paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c208e923-9777-44d4-aab6-4da92b7abb44 Signed-off-by: Baiju Parameswaran <baijup@microsoft.com>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟡 Changes recommended
The new validation only checks data["name"] and should also validate the dynamic peer-range key to prevent CR/LF from reaching vtysh/peer-group identifiers in other code paths.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
qiluo-msft
left a comment
There was a problem hiding this comment.
F065 fix is incomplete — see thread on managers_bgp.py#L208. data["name"] is validated but the peer-range key (nbr from split_key(key)) isn't, and it reaches the same vtysh push path via get_existing_ip_ranges(), the delete/shutdown templates, and no listen range's peer_group=nbr. Requesting the key be validated the same way before this closes the reported vuln.
Validate CR/LF characters across qualified dynamic peer-range keys before dependency checks and retain the defensive set-handler guard. Add regression coverage for set, delete, direct handler, and qualified VRF/VNET key paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Baiju Parameswaran <baijup@microsoft.com>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
There was a problem hiding this comment.
🟢 Approval recommended
Validation and regression coverage are present; the remaining comment is a documentation nit.
Review details
Suppressed comments (1)
src/sonic-yang-models/yang-models/sonic-bgp-peerrange.yang:34
- The PR description says “N/A - no YANG module changes,” but this patch adds a new revision and changes the BGP peer-range schema with a typedef and
mustconstraint. Please update the description (including the schema link section) to reflect this YANG model change, or remove these schema edits if they were unintended.
revision 2026-09-18 {
description
"Reject line breaks in dynamic peer-range names and qualified keys.";
}
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
/azpw retry |
|
Retrying failed(or canceled) jobs... |
|
No Azure DevOps builds found for #29448. |
Resolve the manager conflict by retaining upstream key parsing and normalization alongside the dynamic peer-range CR/LF guards before queueing, SET, and DEL. Add dispatch regression coverage for upstream invalid-key rejection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c208e923-9777-44d4-aab6-4da92b7abb44 Signed-off-by: Baiju Parameswaran <baijup@microsoft.com>
|
/azpw ms_conflict |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
…29435) Why I did it BGP neighbor names must remain single-line descriptions. This PR also extends the scope to BGP Sentinel names, which are used as peer-group identifiers. Runtime and YANG validation consistently reject CR/LF values without changing existing single-line behavior. Work item tracking Microsoft ADO (number only): 39463596 How I did it Validate general, internal, monitor, VOQ chassis, and sentinel names before SET dependency queueing and before add/update dispatch. Log and consume invalid events without FRR, in-memory Directory, peer-cache, or configured STATE_DB changes. Direct calls and queued replay are covered. Rejection does not remove the originating CONFIG_DB record. Restrict the shared sonic-bgp-cmn-neigh/name leaf to [^\n\r]*. Extended scope: sentinels. Apply the same CR/LF-only runtime guard and constrain both sentinel_name and name in sonic-bgp-sentinel.yang, retaining the existing key/name equality constraint. Reject sentinel keys containing CR/LF independently of the name field, before dependency queueing. Reject non-string sentinel keys safely and consume invalid direct calls and queued replay without side effects. Preserve upstream key validation and existing requiredness/empty-value behavior; do not introduce a broader sentinel naming policy. Add 63 sentinel runtime cases and nine sentinel YANG negative cases, including CR/LF/CRLF, new/existing peers, dependency readiness, stale replay, no side effects, and valid IPv4/IPv6 add/update/delete behavior. Add another 158 runtime cases for key-only rejection with clean/empty/absent names, malformed key types, and preservation of valid queued IPv4/IPv6 peers. Defensively reject non-None, non-string names before CR/LF checks, with 280 regression cases across the five in-scope peer types and event paths. Normal SWSS inputs are strings; this hardens malformed direct Python calls without changing missing-name compatibility or dynamic handling. Dynamic-name scope and companion PR Dynamic peer-range work remains in #29448, tracked by ADO 39463597, and is not included in this PR. At companion head d52a0a3, runtime guards reject multiline dynamic keys/names before dependency queueing and SET dispatch. That is runtime coverage, not complete runtime-and-YANG coverage. Remaining companion work is to constrain dynamic peer_range_name and name in both VRF and template list variants of sonic-bgp-peerrange.yang, preserve equality constraints, add schema and explicit existing-peer update/replay regressions, and reconcile its shared handler changes and general-peer queue test with this PR. The dynamic/sentinel review discussion remains open.
|
Please resolve conflict |
Merge current upstream master and reconcile the shared BGP peer-name validation with dynamic peer-range key and name checks. Remove superseded queue-behavior assertions now covered by the merged neighbor and sentinel validation. Signed-off-by: Baiju Parameswaran <baijup@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 99ed51af-eaba-47df-9d95-e565b1e72c3b
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azpw ms_conflict |
|
@qiluo-msft The conflict with current |
Why I did it
Dynamic BGP peer-range names and table-key components are used as identifiers
in generated FRR configuration and must be single-line values. Reject CR/LF
before these inputs reach configuration generation, dependency queues, or
configured-peer state.
Work item tracking
How I did it
BGP_PEER_RANGE.nameand the complete raw table key,including both components of VRF/VNET-qualified keys.
handler(), retain defensiveset_handler()validation for direct calls and stale queued events, andprotect direct
del_handler()calls. Permanently invalid SET input isconsumed rather than queued for retry.
rejecting invalid events.
peer_range_nameandnamein bothpeer-range lists, plus a
mustconstraint for the qualified VRF/VNET name.Preserve existing union leafrefs, key/name equality, and optionality without
changing global VRF/VNET naming policy.
cached updates, direct deletes, dependency readiness, stale replay, mixed
retry queues, and valid IPv4/IPv6 behavior.
to avoid mocked-versus-real SWSS dispatch mismatches in the full CI suite.
Temporary diagnostic instrumentation has been removed.
How to verify it
From
src/sonic-bgpcfgd, with the component dependencies available:python3 -m pytest -q -o addopts="" \ tests/test_bgp.py tests/test_bgp_dynamic_validation.py \ tests/test_bgp_options.py tests/test_bgp_unnumbered.py tests/test_bgpmon.py \ tests/test_directory.py tests/test_db.pyFrom
src/sonic-yang-models:Canonical component targets from the repository root:
BUILD_SKIP_TEST=n SONIC_DPKG_CACHE_METHOD=none \ SONIC_DPKG_CACHE_METHOD_OVERRIDE=none \ make -f Makefile.work BLDENV=trixie \ target/python-wheels/trixie/sonic_yang_models-1.0-py3-none-any.whl \ target/python-wheels/trixie/sonic_bgpcfgd-1.0-py3-none-any.whlPreserve and move existing target wheels aside before running the canonical
targets to ensure fresh execution rather than an up-to-date result.
Which release branch to backport (provide reason below if selected)
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO): 39463597
Failure type: other
Tested branch
Test result
Local validation of the conflict-resolved head
85e0679dd, completedSeptember 30, 2026:
Both component wheels were generated successfully. Packaged BGP runtime/tests
and both YANG/CVL peer-range schema copies match the local source. SWSS rebuilt
successfully through the normal dependency chain. The merge reconciles the
shared neighbor/sentinel validation now present in
masterwith this PR'sdynamic peer-range validation, and removes superseded queue-behavior
assertions. These are local component results, not a claim that remote Azure
end-to-end validation has passed.
Description for the changelog
Reject line breaks in dynamic BGP peer-range names and qualified keys at runtime
and in YANG, with regression coverage for queued events, updates, and deletes.
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)
Not included.