Skip to content

[dhcp6relay] Apply relay config changes at runtime without container restart#116

Open
AnantKishorSharma wants to merge 1 commit into
sonic-net:masterfrom
AnantKishorSharma:dhcp6relay-dynamic-config
Open

[dhcp6relay] Apply relay config changes at runtime without container restart#116
AnantKishorSharma wants to merge 1 commit into
sonic-net:masterfrom
AnantKishorSharma:dhcp6relay-dynamic-config

Conversation

@AnantKishorSharma

@AnantKishorSharma AnantKishorSharma commented Jun 23, 2026

Copy link
Copy Markdown

Fixes #18

Why I did it

The SONiC-native DHCPv6 relay agent (dhcp6relay) read the DHCP_RELAY table once at startup and required a dhcp_relay container restart for any subsequent relay configuration change. A container restart is disruptive: it tears down relay state for every VLAN, interrupting DHCPv6 service on all VLANs even when only a single VLAN's configuration changed.

How I did it

Apply DHCP_RELAY changes at runtime instead of requiring a restart:

  • A detached monitor thread (config_interface.cpp) subscribes to DHCP_RELAY, VLAN_INTERFACE, VLAN (CONFIG_DB) and INTERFACE_TABLE (STATE_DB), builds the desired per-VLAN config under a mutex, and wakes the libevent main loop through a self-pipe.
  • config_change_callback (relay.cpp), on the libevent main thread, reconciles the live vlans map with the desired config: server-list / option changes apply in place, newly-eligible VLANs are armed via the existing link-local-readiness path, and removed VLANs are torn down. All socket and libevent work stays on the main thread; the monitor thread only reads CONFIG_DB and publishes a snapshot under a mutex.
  • dhcp6relay now starts unconditionally; the resulting per-packet "config not found" warnings are rate-limited (should_log_throttled).

Dual ToR mode is unchanged — it is still selected by the -u option at startup.

How to verify it

  • Unit tests: 59/59 gtests pass — added coverage for the reconcile (apply_desired_config / teardown_vlan_relay / config_change_callback), the config monitor, the STATE_DB interface-readiness path, and the Dual-ToR interface_id default.

  • Hardware (qfx5200 t0, sonic-mgmt tests/dhcp_relay/test_dhcpv6_relay_runtime_config.py):

    mode dhcp6relay command result
    non-Dual-ToR /usr/sbin/dhcp6relay 4 passed (304.91s)
    Dual-ToR /usr/sbin/dhcp6relay -u Loopback0 4 passed (398.09s)

    Each run confirms dhcpv6_servers add/modify/remove and VLAN add/remove apply without a container restart (process PID unchanged) and that the need restart container to take effect log is no longer emitted.

Companion PRs

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@AnantKishorSharma

AnantKishorSharma commented Jun 23, 2026

Copy link
Copy Markdown
Author

@Xichen96 @yaqiangz @jcaiMR @saiarcot895 @yxieca @kellyyeh - Please review when you have a chance.

This makes the SONiC-native dhcp6relay apply DHCP_RELAY configuration changes at runtime, so a dhcp_relay container restart is no longer needed for an IPv6 relay config change. A detached monitor thread watches CONFIG_DB/STATE_DB and the libevent main thread reconciles the live config; Dual ToR (-u) behavior is unchanged.

Companion PRs:

Verification: 59/59 gtests, and on a qfx5200 t0 testbed the new sonic-mgmt tests pass in both modes (non-DualToR 4/4, DualToR -u Loopback0 4/4) — config changes applied at runtime with the process PID unchanged.

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@AnantKishorSharma

Copy link
Copy Markdown
Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

…restart

dhcp6relay read DHCP_RELAY once at startup and required a dhcp_relay
container restart for any relay config change. Apply changes at runtime
instead: a detached monitor thread watches CONFIG_DB/STATE_DB and the
libevent main thread reconciles the live config.

Signed-off-by: Anant Kishor Sharma <anant.kishor-sharma@hpe.com>
@AnantKishorSharma
AnantKishorSharma force-pushed the dhcp6relay-dynamic-config branch from 0647561 to 9036c80 Compare July 14, 2026 11:26
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@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.

Question about do we need restart the process to make the new configuration take effect for now?

2 participants