From 7f771d0a05fd691b2965bc8ae91a6aa9a6453a53 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 10 Apr 2014 18:02:52 -0500 Subject: [PATCH] core: use IP interface hardware address for IP-level operations The IP interface may have its own hardware address (like the net port for WWAN devices) and that's the hardware address that must be used for DHCP and IPv6 SLAAC, not the hardware address (if any) of the NMDevice itself. This patch does change the NMDevice hardware address property to always be the Device's hardware address, instead of the IP interface hardware address. This means that ADSL and WWAN will no longer change their hardware address to the hardware address of their IP interface. But in all these cases, the hardware address is non-existent (PPP) or transient and meaningless (WWAN/ADSL). --- src/devices/adsl/nm-device-adsl.c | 10 +--------- src/devices/nm-device-private.h | 1 - src/devices/nm-device.c | 33 ++++++++++++++++++++----------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 0c35bb7ada..627594c378 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -142,9 +142,6 @@ set_nas_iface (NMDeviceAdsl *self, int idx, const char *name) g_warn_if_fail (priv->nas_ifname == NULL); priv->nas_ifname = g_strdup (name); - - /* Update NAS interface's MAC address */ - nm_device_update_hw_address (NM_DEVICE (self)); } static gboolean @@ -482,9 +479,6 @@ deactivate (NMDevice *device) priv->nas_ifindex = -1; g_free (priv->nas_ifname); priv->nas_ifname = NULL; - - /* Poke NMDevice to notice that our hw_address is no longer valid */ - nm_device_update_hw_address (NM_DEVICE (self)); } /**************************************************************/ @@ -492,9 +486,7 @@ deactivate (NMDevice *device) static guint get_hw_address_length (NMDevice *device, gboolean *out_permanent) { - NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device); - - return priv->nas_ifname ? ETH_ALEN : 0; + return 0; } static gboolean diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 24bb0b3362..c1f1c799bf 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -52,7 +52,6 @@ gboolean nm_device_bring_up (NMDevice *self, gboolean wait, gboolean *no_firmwar void nm_device_take_down (NMDevice *self, gboolean block); -gboolean nm_device_update_hw_address (NMDevice *self); gboolean nm_device_set_hw_addr (NMDevice *device, const guint8 *addr, const char *detail, guint64 hw_log_domain); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b3de5580f5..0558fd47ba 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -324,6 +324,8 @@ static void _set_state_full (NMDevice *device, NMDeviceStateReason reason, gboolean quitting); +static gboolean nm_device_update_hw_address (NMDevice *dev); + /***********************************************************/ static GQuark @@ -2751,6 +2753,8 @@ dhcp4_start (NMDevice *self, { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMSettingIP4Config *s_ip4; + const guint8 *hw_addr; + size_t hw_addr_len = 0; GByteArray *tmp = NULL; s_ip4 = nm_connection_get_setting_ip4_config (connection); @@ -2760,9 +2764,10 @@ dhcp4_start (NMDevice *self, g_object_unref (priv->dhcp4_config); priv->dhcp4_config = nm_dhcp4_config_new (); - if (priv->hw_addr_len) { - tmp = g_byte_array_sized_new (priv->hw_addr_len); - g_byte_array_append (tmp, priv->hw_addr, priv->hw_addr_len); + hw_addr = nm_platform_link_get_address (nm_device_get_ip_ifindex (self), &hw_addr_len); + if (hw_addr_len) { + tmp = g_byte_array_sized_new (hw_addr_len); + g_byte_array_append (tmp, hw_addr, hw_addr_len); } /* Begin DHCP on the interface */ @@ -3205,6 +3210,8 @@ dhcp6_start (NMDevice *self, NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; GByteArray *tmp = NULL; + const guint8 *hw_addr; + size_t hw_addr_len = 0; if (!connection) { connection = nm_device_get_connection (self); @@ -3225,9 +3232,10 @@ dhcp6_start (NMDevice *self, priv->dhcp6_ip6_config = NULL; } - if (priv->hw_addr_len) { - tmp = g_byte_array_sized_new (priv->hw_addr_len); - g_byte_array_append (tmp, priv->hw_addr, priv->hw_addr_len); + hw_addr = nm_platform_link_get_address (nm_device_get_ip_ifindex (self), &hw_addr_len); + if (hw_addr_len) { + tmp = g_byte_array_sized_new (hw_addr_len); + g_byte_array_append (tmp, hw_addr, hw_addr_len); } priv->dhcp6_client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (), @@ -3639,12 +3647,15 @@ static void addrconf6_start_with_link_ready (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + const guint8 *hw_addr; + size_t hw_addr_len = 0; g_assert (priv->rdisc); /* FIXME: what if interface has no lladdr, like PPP? */ - if (priv->hw_addr_len) - nm_rdisc_set_lladdr (priv->rdisc, (const char *) priv->hw_addr, priv->hw_addr_len); + hw_addr = nm_platform_link_get_address (nm_device_get_ip_ifindex (self), &hw_addr_len); + if (hw_addr_len) + nm_rdisc_set_lladdr (priv->rdisc, (const char *) hw_addr, hw_addr_len); nm_device_ipv6_sysctl_set (self, "accept_ra", "1"); nm_device_ipv6_sysctl_set (self, "accept_ra_defrtr", "0"); @@ -6946,7 +6957,7 @@ nm_device_get_hw_address (NMDevice *dev, guint *out_len) return priv->hw_addr; } -gboolean +static gboolean nm_device_update_hw_address (NMDevice *dev) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (dev); @@ -6959,7 +6970,7 @@ nm_device_update_hw_address (NMDevice *dev) return FALSE; if (priv->hw_addr_len) { - int ifindex = nm_device_get_ip_ifindex (dev); + int ifindex = nm_device_get_ifindex (dev); gsize addrlen; const guint8 *binaddr; @@ -7112,7 +7123,7 @@ get_hw_address_length (NMDevice *dev, gboolean *out_permanent) { size_t len; - if (nm_platform_link_get_address (nm_device_get_ip_ifindex (dev), &len)) + if (nm_platform_link_get_address (nm_device_get_ifindex (dev), &len)) return len; else return 0;