[action] [PR:104] [dhcp4relay] Fix bug: DHCP relay broken after "config vrf bind <Vlan> <Vrf>" (socket not rebound to new VRF)#107
Merged
mssonicbld merged 1 commit intosonic-net:202511from Apr 28, 2026
Conversation
… <Vrf>" (socket not rebound to new VRF) ### Why I did it On a SONiC device with dhcp_relay running on a VLAN, moving that VLAN to a non-default VRF at runtime via `config vrf bind <Vlan> <Vrf>` silently breaks DHCP: the relay's upstream socket stays bound to the original VRF, so OFFER/ACK never reach clients. The bug is silent — no log, no counter, no restart. Restarting dhcp_relay (or `config reload`) papers over it because the startup path uses the correct CONFIG_DB lookup. Bug has been latent since PR sonic-net#67 / sonic-net#84. ### How I did it `process_vlan_interface_notification()` in `dhcp4relay_mgr.cpp` reads field `"vrf"` from the `VLAN_INTERFACE` update, but the schema field is `"vrf_name"` (the same module's startup path uses the correct name). The mismatch leaves `msg->vrf` empty, the consumer in `dhcp4relay.cpp` short-circuits at `if (msg->vrf.empty()) return;`, and `handle_server_sock()` — which would `setsockopt(SO_BINDTODEVICE, vrf)` — never runs. Fix: read `VRF_NAME_FIELD` instead of the typo, and pull the five reused CONFIG_DB field-name literals (`vrf_name`, `server_vrf`, `source_interface`, `link_selection`, `state`) into named macros in `dhcp4relay.h` so this typo class cannot recur silently. The IP-suffix branch is left untouched — bare-key event drives the rebind. ### How to verify it sonic-mgmt `tests/dhcp_relay/test_dhcpv4_relay.py::test_dhcp_relay_with_non_default_vrf` (4 cases). Without the fix all 4 fail with PTF `expected 48, got 0`. With the fix applied to the on-DUT dhcp_relay deb, all 4 pass; the test-side `restart_dhcp_service` workaround can be removed. Signed-off-by: Sonic Build Admin <[email protected]>
Collaborator
Author
|
Original PR: #104 |
Collaborator
Author
|
/azp run |
|
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
On a SONiC device with dhcp_relay running on a VLAN, moving that VLAN to a non-default VRF at runtime via
config vrf bind <Vlan> <Vrf>silently breaks DHCP: the relay's upstream socket stays bound to the original VRF, so OFFER/ACK never reach clients. The bug is silent — no log, no counter, no restart. Restarting dhcp_relay (orconfig reload) papersover it because the startup path uses the correct CONFIG_DB lookup. Bug has been latent since PR #67 / #84.
How I did it
process_vlan_interface_notification()indhcp4relay_mgr.cppreads field"vrf"from theVLAN_INTERFACEupdate, but the schema field is"vrf_name"(the same module's startup path uses the correct name). The mismatch leavesmsg->vrfempty, the consumer indhcp4relay.cppshort-circuits atif (msg->vrf.empty()) return;, andhandle_server_sock()— which wouldsetsockopt(SO_BINDTODEVICE, vrf)— never runs.Fix: read
VRF_NAME_FIELDinstead of the typo, and pull the five reused CONFIG_DB field-name literals (vrf_name,server_vrf,source_interface,link_selection,state) into named macros indhcp4relay.hso this typo class cannot recur silently. The IP-suffix branch is left untouched — bare-key event drives the rebind.How to verify it
sonic-mgmt
tests/dhcp_relay/test_dhcpv4_relay.py::test_dhcp_relay_with_non_default_vrf(4 cases). Without the fix all 4 fail with PTFexpected 48, got 0. With the fix applied to the on-DUT dhcp_relay deb, all 4 pass; the test-siderestart_dhcp_serviceworkaround can be removed.Signed-off-by: Sonic Build Admin [email protected]