From 08ca47fdab28ceaca71be5b49681f0dcb34e8a58 Mon Sep 17 00:00:00 2001 From: Ejub Sabic Date: Fri, 24 Apr 2026 10:08:59 +0200 Subject: [PATCH] fix: dhcp client host name resend Signed-off-by: Ejub Sabic --- src/confd/src/dhcp-client.c | 14 ++++++++++++++ test/case/dhcp/client_hostname_resend/test.py | 18 +++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/confd/src/dhcp-client.c b/src/confd/src/dhcp-client.c index 2ef8d1cc..652b2323 100644 --- a/src/confd/src/dhcp-client.c +++ b/src/confd/src/dhcp-client.c @@ -180,6 +180,20 @@ int dhcp_client_change(sr_session_ctx_t *session, struct lyd_node *config, struc ifaces = lydx_get_descendant(config, "interfaces", "interface", NULL); difaces = lydx_get_descendant(diff, "interfaces", "interface", NULL); + if (diff && lydx_get_xpathf(diff, "/ietf-system:system/hostname")) { + LYX_LIST_FOR_EACH(ifaces, iface, "interface") { + const char *ifname = lydx_get_cattr(iface, "name"); + + ipv4 = lydx_get_descendant(lyd_child(iface), "ipv4", NULL); + if (!ipv4) + continue; + + dhcp = lydx_get_descendant(lyd_child(ipv4), "dhcp", NULL); + if (dhcp) + add(ifname, dhcp); + } + } + /* find the modified interfaces */ LYX_LIST_FOR_EACH(difaces, diface, "interface") { const char *ifname = lydx_get_cattr(diface, "name"); diff --git a/test/case/dhcp/client_hostname_resend/test.py b/test/case/dhcp/client_hostname_resend/test.py index 748f8c5b..b510a1f1 100755 --- a/test/case/dhcp/client_hostname_resend/test.py +++ b/test/case/dhcp/client_hostname_resend/test.py @@ -1,15 +1,14 @@ #!/usr/bin/env python3 """DHCP Hostname Resend -Verify that updating the system hostname regenerates the DHCP client -Finit service file so subsequent DHCP requests advertise the current -hostname (option 12, RFC 2132). +Verify that updating the system hostname restarts the DHCP client so +subsequent DHCP requests advertise the current hostname (option 12, +RFC 2132). Regression test for a bug where the DHCP client callback only reacts on diffs in infix-dhcp-client, so a standalone change of -ietf-system:system/hostname leaves the previously written -/etc/finit.d/available/dhcp-client-.conf untouched and the -running udhcpc keeps announcing the old name. +ietf-system:system/hostname leaves the running udhcpc untouched with +the old '-x hostname:' argument from when it was first started. """ @@ -17,13 +16,6 @@ import infamy from infamy.util import until -def finit_conf(ssh, ifname): - """Return the contents of the generated DHCP client Finit service file.""" - path = f"/etc/finit.d/available/dhcp-client-{ifname}.conf" - cmd = ssh.runsh(f"cat {path} 2>/dev/null") - return cmd.stdout - - def udhcpc_cmdline(ssh, ifname): """Return the NUL-separated argv of the running udhcpc for ifname.""" pidfile = f"/run/dhcp-client-{ifname}.pid"