Skip to content

Commit b2c4053

Browse files
committed
fix: dhcp client host name resend
Signed-off-by: Ejub Sabic <ejub1946@outlook.com>
1 parent 9373c9c commit b2c4053

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

src/confd/src/dhcp-client.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ int dhcp_client_change(sr_session_ctx_t *session, struct lyd_node *config, struc
180180
ifaces = lydx_get_descendant(config, "interfaces", "interface", NULL);
181181
difaces = lydx_get_descendant(diff, "interfaces", "interface", NULL);
182182

183+
if (diff && lydx_get_xpathf(diff, "/ietf-system:system/hostname")) {
184+
LYX_LIST_FOR_EACH(ifaces, iface, "interface") {
185+
const char *ifname = lydx_get_cattr(iface, "name");
186+
187+
ipv4 = lydx_get_descendant(lyd_child(iface), "ipv4", NULL);
188+
if (!ipv4)
189+
continue;
190+
191+
dhcp = lydx_get_descendant(lyd_child(ipv4), "dhcp", NULL);
192+
if (dhcp)
193+
add(ifname, dhcp);
194+
}
195+
}
196+
183197
/* find the modified interfaces */
184198
LYX_LIST_FOR_EACH(difaces, diface, "interface") {
185199
const char *ifname = lydx_get_cattr(diface, "name");

test/case/dhcp/client_hostname_resend/test.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
#!/usr/bin/env python3
22
"""DHCP Hostname Resend
33
4-
Verify that updating the system hostname regenerates the DHCP client
5-
Finit service file so subsequent DHCP requests advertise the current
6-
hostname (option 12, RFC 2132).
4+
Verify that updating the system hostname restarts the DHCP client so
5+
subsequent DHCP requests advertise the current hostname (option 12,
6+
RFC 2132).
77
88
Regression test for a bug where the DHCP client callback only reacts
99
on diffs in infix-dhcp-client, so a standalone change of
10-
ietf-system:system/hostname leaves the previously written
11-
/etc/finit.d/available/dhcp-client-<iface>.conf untouched and the
12-
running udhcpc keeps announcing the old name.
10+
ietf-system:system/hostname leaves the running udhcpc untouched with
11+
the old '-x hostname:' argument from when it was first started.
1312
1413
"""
1514

1615
import infamy
1716
from infamy.util import until
1817

1918

20-
def finit_conf(ssh, ifname):
21-
"""Return the contents of the generated DHCP client Finit service file."""
22-
path = f"/etc/finit.d/available/dhcp-client-{ifname}.conf"
23-
cmd = ssh.runsh(f"cat {path} 2>/dev/null")
24-
return cmd.stdout
25-
26-
2719
def udhcpc_cmdline(ssh, ifname):
2820
"""Return the NUL-separated argv of the running udhcpc for ifname."""
2921
pidfile = f"/run/dhcp-client-{ifname}.pid"

0 commit comments

Comments
 (0)