From 9446481f4cc06c657d9467bce0921a85bb94ae6b Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sat, 23 Jul 2016 19:13:00 +0200 Subject: [PATCH] policy: update system hostname when DHCP configuration changes If both IPv4 and IPv6 are enabled and IPv6 terminates first (and ipv4.may-fail=yes), the device becomes ACTIVATED and we try to update the system hostname from the DHCP lease, if necessary. But later, the termination of DHCPv4 doesn't trigger a new update and so it's possible that the system hostname remains unset even if the DHCPv4 lease specifies a hostname. To have a deterministic behavior we should always try to update the system hostname when a DHCP transaction terminates. https://bugzilla.redhat.com/show_bug.cgi?id=1356015 --- src/nm-policy.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/nm-policy.c b/src/nm-policy.c index 0af67425ed..0a67464946 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1293,6 +1293,22 @@ device_state_changed (NMDevice *device, check_activating_devices (self); } +static void +device_dhcp_config_changed (NMDevice *device, + GParamSpec *pspec, + gpointer user_data) +{ + NMPolicyPrivate *priv = user_data; + NMPolicy *self = priv->self; + + if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) { + /* Ensure that a hostname received through DHCP4/DHCP6 is applied even + * if the IPv4/IPv6 method completed after initial activation. + */ + update_routing_and_dns (self, FALSE); + } +} + static void device_ip4_config_changed (NMDevice *device, NMIP4Config *new_config, @@ -1401,6 +1417,8 @@ devices_list_register (NMPolicy *self, NMDevice *device) g_signal_connect (device, NM_DEVICE_IP6_CONFIG_CHANGED, (GCallback) device_ip6_config_changed, priv); g_signal_connect (device, "notify::" NM_DEVICE_AUTOCONNECT, (GCallback) device_autoconnect_changed, priv); g_signal_connect (device, NM_DEVICE_RECHECK_AUTO_ACTIVATE, (GCallback) device_recheck_auto_activate, priv); + g_signal_connect (device, "notify::" NM_DEVICE_DHCP4_CONFIG,(GCallback) device_dhcp_config_changed, priv); + g_signal_connect (device, "notify::" NM_DEVICE_DHCP6_CONFIG,(GCallback) device_dhcp_config_changed, priv); } static void