From cf4de78d29d5933bba54b1d98e9cafa6b3301601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 22 May 2026 15:51:20 +0200 Subject: [PATCH] confd: move dhcp-client hostname dependency to core tracker Move the hostname-triggers-dhcp-client logic from dhcp-client.c into the centralized dep_hostname() dependency tracker. When the hostname changes, all interfaces with DHCP client configured are now added to the diff by the core dependency resolver, so dhcp_client_change() picks them up through its normal diff-based interface iteration. --- src/confd/src/core.c | 21 +++++++++++++++++++++ src/confd/src/dhcp-client.c | 14 -------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/confd/src/core.c b/src/confd/src/core.c index 5f7291dc..956b5501 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -323,6 +323,8 @@ static confd_dependency_t dep_hostname(struct lyd_node **diff, struct lyd_node * { confd_dependency_t result = CONFD_DEP_DONE; struct lyd_node *hostname, *mdns, *dhcp_server; + struct ly_set *ifaces; + uint32_t i; hostname = lydx_get_xpathf(*diff, "/ietf-system:system/hostname"); if (!hostname) @@ -346,6 +348,25 @@ static confd_dependency_t dep_hostname(struct lyd_node **diff, struct lyd_node * } } + ifaces = lydx_find_xpathf(config, + "/ietf-interfaces:interfaces/interface[ietf-ip:ipv4/infix-dhcp-client:dhcp]"); + if (ifaces && ifaces->count > 0) { + for (i = 0; i < ifaces->count; i++) { + const char *ifname = lydx_get_cattr(ifaces->dnodes[i], "name"); + char xpath[256]; + + snprintf(xpath, sizeof(xpath), + "/ietf-interfaces:interfaces/interface[name='%s']/ietf-ip:ipv4/infix-dhcp-client:dhcp", ifname); + result = add_dependencies(diff, xpath, ifname); + if (result == CONFD_DEP_ERROR) { + ERROR("Failed to add dhcp-client to diff for interface %s", ifname); + ly_set_free(ifaces, NULL); + return result; + } + } + } + ly_set_free(ifaces, NULL); + return result; } diff --git a/src/confd/src/dhcp-client.c b/src/confd/src/dhcp-client.c index 652b2323..2ef8d1cc 100644 --- a/src/confd/src/dhcp-client.c +++ b/src/confd/src/dhcp-client.c @@ -180,20 +180,6 @@ 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");