mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user