From 632af7b716a84128c6c3fdd8d86b775024317bb5 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Wed, 4 Nov 2020 11:46:06 -0700 Subject: [PATCH] interface: learn hostname from uname(2) only if an interface requests the dhcp executor Closes #74. --- libifupdown/interface.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libifupdown/interface.c b/libifupdown/interface.c index 7e96bcd..69a38c8 100644 --- a/libifupdown/interface.c +++ b/libifupdown/interface.c @@ -122,16 +122,6 @@ lif_interface_init(struct lif_interface *interface, const char *ifname) /* keep the 'vlan' executor as a config hint for backwards compatibility */ if (strchr(ifname, '.') != NULL) lif_interface_use_executor(interface, "vlan"); - - if (!lif_config.use_hostname_for_dhcp) - return; - - /* learn a reasonable default hostname */ - struct utsname un; - if (uname(&un) < 0) - return; - - lif_dict_add(&interface->vars, "hostname", strdup(un.nodename)); } bool @@ -211,6 +201,16 @@ lif_interface_use_executor(struct lif_interface *interface, const char *executor interface->is_bridge = true; else if (!strcmp(executor, "bond")) interface->is_bond = true; + + if (strcmp(executor, "dhcp") || !lif_config.use_hostname_for_dhcp) + return; + + /* learn a reasonable default hostname */ + struct utsname un; + if (uname(&un) < 0) + return; + + lif_dict_add(&interface->vars, "hostname", strdup(un.nodename)); } void