Repository navigation
Conversation
Removing a VLAN or sub-interface (config vlan del, config interface breakout, GCU) finds the rows that depend on it only through YANG leafrefs. These fields named a local VLAN, and the BGP neighbor keys also a sub-interface, by string pattern or plain string, so deleting the interface left their rows behind, and nothing refused a row naming a VLAN that never existed: - BGP_NEIGHBOR, BGP_INTERNAL_NEIGHBOR, BGP_VOQ_CHASSIS_NEIGHBOR neighbor - BGP local_addr (sonic-bgp-common) - DHCPV4_RELAY name and source_interface - DHCP_SERVER_IPV4 name - ROUTE_MAP match_interface and match_neighbor - RADIUS_SERVER src_intf - NEIGH port - MCLAG_UNIQUE_IP if_name - STP_VLAN name - DASH_HA_GLOBAL_CONFIG dpu_vlan Each pattern becomes a leafref to VLAN or VLAN_SUB_INTERFACE, and the commented-out leafrefs and imports left "until libyang back-links issue is resolved" are restored: libyang3 resolves a leafref inside a union per member. None of the changed modules is in the import closure of sonic-vlan or sonic-vlan-sub-interface. Where the old pattern stopped at Vlan4094, a must keeps Vlan4095 refused, because the VLAN name pattern accepts it and vlanid is optional. NEIGH port, STP_VLAN name and dpu_vlan accepted Vlan4095 before and still do. Fixtures that named a VLAN without defining it gain the VLAN row (the DHCP relay, server and match cases, and the sonic-yang-mgmt DHCP match fixture), and sample_config_db.json gains Vlan222, which its DHCPV4_RELAY already named. sonic-yang-mgmt gains a static SonicYang.union_member_types(type_obj), the compiled member types of a union ([] for a non-union). libyang-python's Type.union_types() zips compiled members with parsed ones, and libyang compiles a nested union such as inet:ip-address flat, so it drops the trailing compiled members: the leafrefs these unions now end with. sonic-utilities needs them to find what references a VLAN and goes through sonic_yang rather than importing libyang. The yJson view's union types use it too, so they keep those members. Signed-off-by: Brad House <bhouse@nexthop.ai>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
1 open issue
What changed in this PR
Adds YANG validation to ensure DHCP relay/server configuration is only accepted when the corresponding VLAN has a same-VLAN, matching-family interface IP prefix configured—closing a validation gap where DHCP settings could be applied to L2-only VLANs.
Changes:
- Add
mustconstraints in VLAN and DHCP relay YANG modules to require VLAN interface IP prefixes (IPv4/IPv6 as appropriate). - Import
sonic-vlaninto DHCPv4/DHCPv6 relay modules and add new revisions documenting the behavior. - Update existing test fixtures and add new negative/edge test cases covering missing/wrong-family/wrong-VLAN IP scenarios.
| File | Description |
|---|---|
| src/sonic-yang-models/yang-models/sonic-vlan.yang | Adds must constraints requiring VLAN interface IPv4/IPv6 prefixes when DHCP server leaf-lists are configured. |
| src/sonic-yang-models/yang-models/sonic-dhcpv6-relay.yang | Imports VLAN model and requires same-VLAN IPv6 prefix for DHCPv6 relay servers. |
| src/sonic-yang-models/yang-models/sonic-dhcpv4-relay.yang | Imports VLAN model and requires same-VLAN IPv4 prefix for DHCPv4 relay servers. |
| src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan.json | Updates VLAN fixtures to include VLAN_INTERFACE prefixes; adds new negative cases. |
| src/sonic-yang-models/tests/yang_model_tests/tests_config/dhcpv6_relay.json | Updates fixtures to include VLAN + IPv6 prefixes; adds negative cases and options-without-servers case. |
| src/sonic-yang-models/tests/yang_model_tests/tests_config/dhcpv4_relay.json | Updates fixtures to include VLAN + IPv4 prefixes; adds negative cases. |
| src/sonic-yang-models/tests/yang_model_tests/tests/vlan.json | Adds expected error assertions for new VLAN DHCP server validation cases. |
| src/sonic-yang-models/tests/yang_model_tests/tests/dhcpv6_relay.json | Adds expected error assertions for new DHCPv6 relay validation cases. |
| src/sonic-yang-models/tests/yang_model_tests/tests/dhcpv4_relay.json | Adds expected error assertions for new DHCPv4 relay validation cases. |
Review effort: Lite
Copilot stopped reviewing on behalf of
Xichen96 due to an error
November 27, 2026 06:06
Reject DHCP server configuration unless the same VLAN has a configured VLAN_INTERFACE prefix of the corresponding address family. Apply the dependency to legacy VLAN fields and native DHCPv4/DHCPv6 relay tables. Keep vlanid optional and preserve bare VLANs without DHCP servers. Add focused dependency tests and provide valid IP dependencies in existing fixtures so their original checks remain meaningful. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7a24f7e2-7126-444f-bc0c-4ee2c7d97330 Signed-off-by: Xichen Lin <lukelin0907@gmail.com>
Xichen96
force-pushed
the
dev/xichenlin/dhcp-relay-ip-yang
branch
from
November 27, 2026 08:40
6986bc3 to
934c9de
Compare
Collaborator
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why I did it
DHCP server configuration can pass YANG validation without an IP address on the corresponding VLAN. A bare L2 VLAN is valid, but its existence alone does not establish the interface-address dependency needed by DHCP relay.
vlanidis not an address-readiness check: it is optional, and a VLAN can be created from its name without that field. This change therefore validates the VLAN IP dependency instead of requiringvlanidor VLAN membership.Work item tracking
How I did it
Added
mustconstraints requiring a configuredVLAN_INTERFACEprefix on the same VLAN:VLAN.dhcp_serversVLAN.dhcpv6_serversDHCPV4_RELAY.dhcpv4_serversDHCP_RELAY.dhcpv6_serversThe check uses the prefix itself, not the optional
familyattribute. It accepts multiple addresses as long as a matching-family prefix exists. Bare VLANs without DHCP servers remain valid,vlanidremains optional, and existing minimum-server requirements are unchanged.Updated existing fixtures with their required VLAN IP dependencies and added 14 focused cases for missing IPs, opposite-family IPs, IPs on another VLAN, empty legacy server lists and DHCPv6 options without servers.
This PR changes only YANG validation. It does not enable global CLI validation, alter CLI writers or intercept direct CONFIG_DB edits. Those paths can bypass YANG and require separate enforcement work.
How to verify it
Run the existing
sonic-yang-modelsYANG model tests, including the VLAN and DHCPv4/DHCPv6 relay fixtures. Verify that DHCP server configuration fails without a same-VLAN, matching-family prefix, while existing valid configurations and bare VLANs without DHCP remain accepted.For GCU, verify rejection of DHCP-before-IP and last-required-IP removal, and acceptance of combined DHCP/IP additions and IP replacement.
Which release branch to backport (provide reason below if selected)
No backport requested; master only.
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO): N/A
Failure type: pre-existing validation gap
Tested branch
Test result
Current-master model tests are pending PR CI.
Before preparing this PR, a prototype of the four constraints was exercised on
SONiC.20260510.25. Model validation rejected missing/opposite-family IPs and accepted matching-family IPs withoutvlanid. GCU rejected missing-IP DHCP and last-IP removal, and accepted combined additions and IP replacements. This is prototype compatibility evidence, not a claim that the current PR head has passed master or release-branch CI.Description for the changelog
Require a matching-family VLAN interface IP prefix for legacy and native DHCP relay server configuration.
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)