From 9ce458256da896f2dcfd2c0bb6624014f83ddae8 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 1 May 2013 09:28:16 -0400 Subject: [PATCH] core: reorganize hw-address properties Now that NMDevice reads the hwaddr directly from netlink, it's silly to have every device subtype maintain its own hw-address property (using data that it gets from the NMDevice base class). Remove all the device-specific hw-address properties, and add one to NMDevice instead. (Because of the way nm-properties-changed-signal works, this has no effect on the D-Bus API.) Subclasses now call nm_device_get_hw_address() in places where they used to just refer to priv->hw_addr (and to simplify this, we now allow passing NULL for the out length parameter, since the subclasses almost always know what the length will be already). Also reorganize/simplify a few other methods to take advantage of the fact that NMDevice is now keeping track of the hw-address directly. https://bugzilla.gnome.org/show_bug.cgi?id=699391 --- src/nm-device-adsl.c | 21 ++- src/nm-device-bond.c | 52 +++---- src/nm-device-bridge.c | 42 +----- src/nm-device-bt.c | 67 +-------- src/nm-device-ethernet.c | 97 ++----------- src/nm-device-infiniband.c | 82 +++-------- src/nm-device-modem.c | 7 + src/nm-device-olpc-mesh.c | 50 +------ src/nm-device-private.h | 2 +- src/nm-device-vlan.c | 51 +------ src/nm-device-wifi.c | 96 ++----------- src/nm-device.c | 264 ++++++++++++++++++++++-------------- src/nm-device.h | 12 +- src/wimax/nm-device-wimax.c | 80 ++--------- 14 files changed, 268 insertions(+), 655 deletions(-) diff --git a/src/nm-device-adsl.c b/src/nm-device-adsl.c index 47b0a53f71..c9acfdb666 100644 --- a/src/nm-device-adsl.c +++ b/src/nm-device-adsl.c @@ -82,7 +82,6 @@ typedef struct { int brfd; int nas_ifindex; char * nas_ifname; - guint8 nas_hw_addr[ETH_ALEN]; } NMDeviceAdslPrivate; enum { @@ -208,7 +207,6 @@ static void set_nas_iface (NMDeviceAdsl *self, int idx, const char *name) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); - gsize addrlen; g_return_if_fail (name != NULL); @@ -223,11 +221,7 @@ set_nas_iface (NMDeviceAdsl *self, int idx, const char *name) priv->nas_ifname = g_strdup (name); /* Update NAS interface's MAC address */ - addrlen = nm_device_read_hwaddr (NM_DEVICE (self), - priv->nas_hw_addr, - sizeof (priv->nas_hw_addr), - NULL); - g_warn_if_fail (addrlen == sizeof (priv->nas_hw_addr)); + nm_device_update_hw_address (NM_DEVICE (self)); } static gboolean @@ -574,18 +568,19 @@ deactivate (NMDevice *device) priv->nas_ifindex = -1; g_free (priv->nas_ifname); priv->nas_ifname = NULL; - memset (priv->nas_hw_addr, 0, sizeof (priv->nas_hw_addr)); + + /* Poke NMDevice to notice that our hw_address is no longer valid */ + nm_device_update_hw_address (NM_DEVICE (self)); } /**************************************************************/ -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) +static guint +get_hw_address_length (NMDevice *device) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device); - *out_len = priv->nas_ifname ? sizeof (priv->nas_hw_addr) : 0; - return priv->nas_hw_addr; + return priv->nas_ifname ? ETH_ALEN : 0; } static void @@ -789,7 +784,7 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass) parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; - parent_class->get_hw_address = get_hw_address; + parent_class->get_hw_address_length = get_hw_address_length; parent_class->act_stage2_config = act_stage2_config; parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start; parent_class->deactivate = deactivate; diff --git a/src/nm-device-bond.c b/src/nm-device-bond.c index aaf59e434e..3b8d23ae64 100644 --- a/src/nm-device-bond.c +++ b/src/nm-device-bond.c @@ -46,8 +46,7 @@ G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE_WIRED) #define NM_BOND_ERROR (nm_bond_error_quark ()) typedef struct { - guint8 hw_addr[NM_UTILS_HWADDR_LEN_MAX]; - gsize hw_addr_len; + int dummy; } NMDeviceBondPrivate; enum { @@ -60,7 +59,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_HW_ADDRESS, PROP_CARRIER, PROP_SLAVES, @@ -80,26 +78,23 @@ nm_bond_error_quark (void) /******************************************************************/ -static void -update_hw_address (NMDevice *dev) +static guint +get_hw_address_length (NMDevice *device) { - NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (dev); - gsize addrlen; - gboolean changed = FALSE; + GSList *slaves; + guint length; - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - priv->hw_addr_len = addrlen; - if (changed) - g_object_notify (G_OBJECT (dev), NM_DEVICE_BOND_HW_ADDRESS); - } -} + /* A bond's hwaddr length depends on what kind of slaves it has; + * if it has no slaves, then it doesn't have a valid hwaddr. + */ + slaves = nm_device_master_get_slaves (device); + if (slaves) { + nm_device_get_hw_address (slaves->data, &length); + g_slist_free (slaves); + } else + length = 0; -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - *out_len = NM_DEVICE_BOND_GET_PRIVATE (device)->hw_addr_len; - return NM_DEVICE_BOND_GET_PRIVATE (device)->hw_addr; + return length; } static guint32 @@ -329,16 +324,10 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object); GPtrArray *slaves; GSList *list, *iter; - char *hwaddr; switch (prop_id) { - case PROP_HW_ADDRESS: - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len)); - g_value_take_string (value, hwaddr); - break; case PROP_CARRIER: g_value_set_boolean (value, nm_device_wired_get_carrier (NM_DEVICE_WIRED (object))); break; @@ -381,8 +370,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) object_class->set_property = set_property; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; + parent_class->get_hw_address_length = get_hw_address_length; parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; @@ -394,14 +382,6 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) parent_class->release_slave = release_slave; /* properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_BOND_HW_ADDRESS, - "Active MAC Address", - "Currently set hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_CARRIER, g_param_spec_boolean (NM_DEVICE_BOND_CARRIER, diff --git a/src/nm-device-bridge.c b/src/nm-device-bridge.c index 3dc869679f..1f5dd51d44 100644 --- a/src/nm-device-bridge.c +++ b/src/nm-device-bridge.c @@ -46,8 +46,7 @@ G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE_WIRED) #define NM_BRIDGE_ERROR (nm_bridge_error_quark ()) typedef struct { - guint8 hw_addr[NM_UTILS_HWADDR_LEN_MAX]; - gsize hw_addr_len; + int dummy; } NMDeviceBridgePrivate; enum { @@ -60,7 +59,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_HW_ADDRESS, PROP_CARRIER, PROP_SLAVES, @@ -80,28 +78,6 @@ nm_bridge_error_quark (void) /******************************************************************/ -static void -update_hw_address (NMDevice *dev) -{ - NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (dev); - gsize addrlen; - gboolean changed = FALSE; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - priv->hw_addr_len = addrlen; - if (changed) - g_object_notify (G_OBJECT (dev), NM_DEVICE_BRIDGE_HW_ADDRESS); - } -} - -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - *out_len = NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_addr_len; - return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_addr; -} - static guint32 get_generic_capabilities (NMDevice *dev) { @@ -381,16 +357,10 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object); GPtrArray *slaves; GSList *list, *iter; - char *hwaddr; switch (prop_id) { - case PROP_HW_ADDRESS: - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len)); - g_value_take_string (value, hwaddr); - break; case PROP_CARRIER: g_value_set_boolean (value, nm_device_wired_get_carrier (NM_DEVICE_WIRED (object))); break; @@ -433,8 +403,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) object_class->set_property = set_property; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; @@ -446,14 +414,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) parent_class->release_slave = release_slave; /* properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_BRIDGE_HW_ADDRESS, - "Active MAC Address", - "Currently set hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_CARRIER, g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER, diff --git a/src/nm-device-bt.c b/src/nm-device-bt.c index 2c9225341a..a0b4a3375b 100644 --- a/src/nm-device-bt.c +++ b/src/nm-device-bt.c @@ -63,7 +63,6 @@ typedef struct { guint mm_watch_id; gboolean mm_running; - guint8 hw_addr[ETH_ALEN]; /* binary representation of bdaddr */ char *bdaddr; char *name; guint32 capabilities; @@ -83,7 +82,6 @@ typedef struct { enum { PROP_0, - PROP_HW_ADDRESS, PROP_BT_NAME, PROP_BT_CAPABILITIES, @@ -380,49 +378,14 @@ get_generic_capabilities (NMDevice *dev) return NM_DEVICE_CAP_NM_SUPPORTED; } -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) +static const GByteArray * +get_connection_hw_address (NMDevice *device, + NMConnection *connection) { - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device); - - *out_len = sizeof (priv->hw_addr); - return priv->hw_addr; -} - -static gboolean -hwaddr_matches (NMDevice *device, - NMConnection *connection, - const guint8 *other_hwaddr, - guint other_hwaddr_len, - gboolean fail_if_no_hwaddr) -{ - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device); NMSettingBluetooth *s_bt; - const GByteArray *mac = NULL; - gboolean matches = FALSE; - GByteArray *devmac; s_bt = nm_connection_get_setting_bluetooth (connection); - if (s_bt) - mac = nm_setting_bluetooth_get_bdaddr (s_bt); - - if (mac) { - devmac = nm_utils_hwaddr_atoba (priv->bdaddr, ARPHRD_ETHER); - g_return_val_if_fail (devmac != NULL, FALSE); - g_return_val_if_fail (devmac->len == mac->len, FALSE); - - if (other_hwaddr) { - g_return_val_if_fail (other_hwaddr_len == devmac->len, FALSE); - matches = (memcmp (mac->data, other_hwaddr, mac->len) == 0) ? TRUE : FALSE; - } else - matches = (memcmp (mac->data, devmac->data, mac->len) == 0) ? TRUE : FALSE; - - g_byte_array_free (devmac, TRUE); - return matches; - } else if (fail_if_no_hwaddr == FALSE) - return TRUE; - - return FALSE; + return s_bt ? nm_setting_bluetooth_get_bdaddr (s_bt) : NULL; } /*****************************************************************************/ @@ -1173,7 +1136,7 @@ nm_device_bt_new (const char *udi, NM_DEVICE_UDI, udi, NM_DEVICE_IFACE, bdaddr, NM_DEVICE_DRIVER, "bluez", - NM_DEVICE_BT_HW_ADDRESS, bdaddr, + NM_DEVICE_HW_ADDRESS, bdaddr, NM_DEVICE_BT_NAME, name, NM_DEVICE_BT_CAPABILITIES, capabilities, NM_DEVICE_MANAGED, managed, @@ -1211,12 +1174,6 @@ set_property (GObject *object, guint prop_id, NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object); switch (prop_id) { - case PROP_HW_ADDRESS: - /* Construct only */ - priv->bdaddr = g_ascii_strup (g_value_get_string (value), -1); - if (!nm_utils_hwaddr_aton (priv->bdaddr, ARPHRD_ETHER, &priv->hw_addr)) - nm_log_err (LOGD_HW, "Failed to convert BT address '%s'", priv->bdaddr); - break; case PROP_BT_NAME: /* Construct only */ priv->name = g_value_dup_string (value); @@ -1238,9 +1195,6 @@ get_property (GObject *object, guint prop_id, NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object); switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_set_string (value, priv->bdaddr); - break; case PROP_BT_NAME: g_value_set_string (value, priv->name); break; @@ -1310,21 +1264,12 @@ nm_device_bt_class_init (NMDeviceBtClass *klass) device_class->check_connection_compatible = check_connection_compatible; device_class->check_connection_available = check_connection_available; device_class->complete_connection = complete_connection; - device_class->hwaddr_matches = hwaddr_matches; - device_class->get_hw_address = get_hw_address; + device_class->get_connection_hw_address = get_connection_hw_address; device_class->is_available = is_available; device_class->state_changed = device_state_changed; /* Properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_BT_HW_ADDRESS, - "Bluetooth address", - "Bluetooth address", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, PROP_BT_NAME, g_param_spec_string (NM_DEVICE_BT_NAME, diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c index 5aa7a6c929..976c22f363 100644 --- a/src/nm-device-ethernet.c +++ b/src/nm-device-ethernet.c @@ -81,7 +81,6 @@ typedef struct Supplicant { } Supplicant; typedef struct { - guint8 hw_addr[ETH_ALEN]; /* Current MAC address */ guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */ guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */ @@ -109,7 +108,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_HW_ADDRESS, PROP_PERM_HW_ADDRESS, PROP_SPEED, PROP_CARRIER, @@ -350,36 +348,21 @@ nm_device_ethernet_new (const char *udi, NULL); } -static void -update_hw_address (NMDevice *dev) -{ - NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (dev); - gsize addrlen; - gboolean changed = FALSE; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - g_return_if_fail (addrlen == ETH_ALEN); - if (changed) - g_object_notify (G_OBJECT (dev), NM_DEVICE_ETHERNET_HW_ADDRESS); - } -} - static gboolean _set_hw_addr (NMDeviceEthernet *self, const guint8 *addr, const char *detail) { NMDevice *dev = NM_DEVICE (self); - NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); const char *iface; char *mac_str = NULL; gboolean success = FALSE; + const guint8 *cur_addr = nm_device_get_hw_address (dev, NULL); g_return_val_if_fail (addr != NULL, FALSE); iface = nm_device_get_iface (dev); /* Do nothing if current MAC is same */ - if (!memcmp (priv->hw_addr, addr, ETH_ALEN)) { + if (cur_addr && !memcmp (cur_addr, addr, ETH_ALEN)) { nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): no MAC address change needed", iface); return TRUE; } @@ -393,8 +376,9 @@ _set_hw_addr (NMDeviceEthernet *self, const guint8 *addr, const char *detail) success = nm_system_iface_set_mac (nm_device_get_ip_ifindex (dev), (struct ether_addr *) addr); if (success) { /* MAC address succesfully changed; update the current MAC to match */ - update_hw_address (dev); - if (memcmp (priv->hw_addr, addr, ETH_ALEN) == 0) { + nm_device_update_hw_address (dev); + cur_addr = nm_device_get_hw_address (dev, NULL); + if (memcmp (cur_addr, addr, ETH_ALEN) == 0) { nm_log_info (LOGD_DEVICE | LOGD_ETHER, "(%s): %s MAC address to %s", iface, detail, mac_str); } else { @@ -442,7 +426,7 @@ update_permanent_hw_address (NMDevice *dev) nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): unable to read permanent MAC address (error %d)", nm_device_get_iface (dev), errno); /* Fall back to current address */ - memcpy (epaddr->data, priv->hw_addr, ETH_ALEN); + memcpy (epaddr->data, nm_device_get_hw_address (dev, NULL), ETH_ALEN); } if (memcmp (&priv->perm_hw_addr, epaddr->data, ETH_ALEN)) { @@ -459,40 +443,19 @@ update_initial_hw_address (NMDevice *dev) { NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev); NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); - gsize addrlen; - char *mac_str = NULL; + char *mac_str; /* This sets initial MAC address from current MAC address. It should only * be called from NMDevice constructor() to really get the initial address. */ - addrlen = nm_device_read_hwaddr (dev, - priv->initial_hw_addr, - sizeof (priv->initial_hw_addr), - NULL); - if (addrlen) - g_return_if_fail (addrlen == ETH_ALEN); - - mac_str = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", - priv->initial_hw_addr[0], - priv->initial_hw_addr[1], - priv->initial_hw_addr[2], - priv->initial_hw_addr[3], - priv->initial_hw_addr[4], - priv->initial_hw_addr[5]); + memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN); + mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER); nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): read initial MAC address %s", nm_device_get_iface (dev), mac_str); - g_free (mac_str); } -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - *out_len = ETH_ALEN; - return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_addr; -} - static guint32 get_generic_capabilities (NMDevice *dev) { @@ -1352,33 +1315,14 @@ match_l2_config (NMDevice *self, NMConnection *connection) return TRUE; } -static gboolean -hwaddr_matches (NMDevice *device, - NMConnection *connection, - const guint8 *other_hwaddr, - guint other_hwaddr_len, - gboolean fail_if_no_hwaddr) +static const GByteArray * +get_connection_hw_address (NMDevice *device, + NMConnection *connection) { - NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device); NMSettingWired *s_wired; - const GByteArray *mac = NULL; s_wired = nm_connection_get_setting_wired (connection); - if (s_wired) - mac = nm_setting_wired_get_mac_address (s_wired); - - if (mac) { - g_return_val_if_fail (mac->len == ETH_ALEN, FALSE); - if (other_hwaddr) { - g_return_val_if_fail (other_hwaddr_len == ETH_ALEN, FALSE); - if (memcmp (mac->data, other_hwaddr, mac->len) == 0) - return TRUE; - } else if (memcmp (mac->data, priv->hw_addr, mac->len) == 0) - return TRUE; - } else if (fail_if_no_hwaddr == FALSE) - return TRUE; - - return FALSE; + return s_wired ? nm_setting_wired_get_mac_address (s_wired) : NULL; } static void @@ -1403,9 +1347,6 @@ get_property (GObject *object, guint prop_id, NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, ARPHRD_ETHER)); - break; case PROP_PERM_HW_ADDRESS: g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER)); break; @@ -1450,8 +1391,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) parent_class->is_up = is_up; parent_class->bring_up = bring_up; parent_class->take_down = take_down; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; parent_class->update_permanent_hw_address = update_permanent_hw_address; parent_class->update_initial_hw_address = update_initial_hw_address; parent_class->check_connection_compatible = check_connection_compatible; @@ -1464,19 +1403,11 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) parent_class->deactivate = deactivate; parent_class->spec_match_list = spec_match_list; parent_class->match_l2_config = match_l2_config; - parent_class->hwaddr_matches = hwaddr_matches; + parent_class->get_connection_hw_address = get_connection_hw_address; parent_class->state_changed = device_state_changed; /* properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_ETHERNET_HW_ADDRESS, - "Active MAC Address", - "Currently set hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_PERM_HW_ADDRESS, g_param_spec_string (NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, diff --git a/src/nm-device-infiniband.c b/src/nm-device-infiniband.c index d71d4ba47d..5321e05da2 100644 --- a/src/nm-device-infiniband.c +++ b/src/nm-device-infiniband.c @@ -44,7 +44,7 @@ G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE_WIRED) #define NM_INFINIBAND_ERROR (nm_infiniband_error_quark ()) typedef struct { - guint8 hw_addr[INFINIBAND_ALEN]; + int dummy; } NMDeviceInfinibandPrivate; enum { @@ -57,7 +57,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_HW_ADDRESS, PROP_CARRIER, LAST_PROP @@ -120,26 +119,10 @@ nm_device_infiniband_new (const char *udi, NULL); } -static void -update_hw_address (NMDevice *dev) +static guint +get_hw_address_length (NMDevice *device) { - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (dev); - gsize addrlen; - gboolean changed = FALSE; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - g_return_if_fail (addrlen == INFINIBAND_ALEN); - if (changed) - g_object_notify (G_OBJECT (dev), NM_DEVICE_INFINIBAND_HW_ADDRESS); - } -} - -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - *out_len = INFINIBAND_ALEN; - return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_addr; + return INFINIBAND_ALEN; } static guint32 @@ -216,7 +199,6 @@ check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device); NMSettingInfiniband *s_infiniband; const GByteArray *mac; @@ -241,7 +223,7 @@ check_connection_compatible (NMDevice *device, if (s_infiniband) { mac = nm_setting_infiniband_get_mac_address (s_infiniband); - if (mac && memcmp (mac->data, priv->hw_addr, INFINIBAND_ALEN)) { + if (mac && memcmp (mac->data, nm_device_get_hw_address (device, NULL), INFINIBAND_ALEN)) { g_set_error (error, NM_INFINIBAND_ERROR, NM_INFINIBAND_ERROR_CONNECTION_INCOMPATIBLE, @@ -260,9 +242,9 @@ complete_connection (NMDevice *device, const GSList *existing_connections, GError **error) { - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device); NMSettingInfiniband *s_infiniband; const GByteArray *setting_mac; + const guint8 *hw_address; nm_utils_complete_generic (connection, NM_SETTING_INFINIBAND_SETTING_NAME, @@ -278,9 +260,10 @@ complete_connection (NMDevice *device, } setting_mac = nm_setting_infiniband_get_mac_address (s_infiniband); + hw_address = nm_device_get_hw_address (device, NULL); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's MAC */ - if (memcmp (setting_mac->data, priv->hw_addr, INFINIBAND_ALEN)) { + if (memcmp (setting_mac->data, hw_address, INFINIBAND_ALEN)) { g_set_error_literal (error, NM_SETTING_INFINIBAND_ERROR, NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY, @@ -291,8 +274,8 @@ complete_connection (NMDevice *device, GByteArray *mac; /* Lock the connection to this device by default */ - mac = g_byte_array_sized_new (sizeof (priv->hw_addr)); - g_byte_array_append (mac, priv->hw_addr, sizeof (priv->hw_addr)); + mac = g_byte_array_sized_new (INFINIBAND_ALEN); + g_byte_array_append (mac, hw_address, INFINIBAND_ALEN); g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL); g_byte_array_free (mac, TRUE); } @@ -310,45 +293,21 @@ match_l2_config (NMDevice *self, NMConnection *connection) return TRUE; } -static gboolean -hwaddr_matches (NMDevice *device, - NMConnection *connection, - const guint8 *other_hwaddr, - guint other_hwaddr_len, - gboolean fail_if_no_hwaddr) +static const GByteArray * +get_connection_hw_address (NMDevice *device, + NMConnection *connection) { - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device); NMSettingInfiniband *s_ib; - const GByteArray *mac = NULL; s_ib = nm_connection_get_setting_infiniband (connection); - if (s_ib) - mac = nm_setting_infiniband_get_mac_address (s_ib); - - if (mac) { - g_return_val_if_fail (mac->len == INFINIBAND_ALEN, FALSE); - if (other_hwaddr) { - g_return_val_if_fail (other_hwaddr_len == INFINIBAND_ALEN, FALSE); - if (memcmp (mac->data, other_hwaddr, mac->len) == 0) - return TRUE; - } else if (memcmp (mac->data, priv->hw_addr, mac->len) == 0) - return TRUE; - } else if (fail_if_no_hwaddr == FALSE) - return TRUE; - - return FALSE; + return s_ib ? nm_setting_infiniband_get_mac_address (s_ib) : NULL; } static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object); - switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, ARPHRD_INFINIBAND)); - break; case PROP_CARRIER: g_value_set_boolean (value, nm_device_wired_get_carrier (NM_DEVICE_WIRED (object))); break; @@ -383,25 +342,16 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass) object_class->set_property = set_property; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; + parent_class->get_hw_address_length = get_hw_address_length; parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->ip4_config_pre_commit = ip4_config_pre_commit; parent_class->match_l2_config = match_l2_config; - parent_class->hwaddr_matches = hwaddr_matches; + parent_class->get_connection_hw_address = get_connection_hw_address; /* properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_INFINIBAND_HW_ADDRESS, - "Active MAC Address", - "Currently set hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_CARRIER, g_param_spec_boolean (NM_DEVICE_INFINIBAND_CARRIER, diff --git a/src/nm-device-modem.c b/src/nm-device-modem.c index a203fb8827..6b0d2d5a10 100644 --- a/src/nm-device-modem.c +++ b/src/nm-device-modem.c @@ -221,6 +221,12 @@ get_generic_capabilities (NMDevice *device) return NM_DEVICE_CAP_NM_SUPPORTED; } +static guint +get_hw_address_length (NMDevice *device) +{ + return 0; +} + static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection, @@ -480,6 +486,7 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass) object_class->set_property = set_property; device_class->get_generic_capabilities = get_generic_capabilities; + device_class->get_hw_address_length = get_hw_address_length; device_class->check_connection_compatible = check_connection_compatible; device_class->complete_connection = complete_connection; device_class->deactivate = deactivate; diff --git a/src/nm-device-olpc-mesh.c b/src/nm-device-olpc-mesh.c index 076b012394..4bdddb9d1a 100644 --- a/src/nm-device-olpc-mesh.c +++ b/src/nm-device-olpc-mesh.c @@ -72,7 +72,6 @@ G_DEFINE_TYPE (NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE) enum { PROP_0, - PROP_HW_ADDRESS, PROP_COMPANION, PROP_ACTIVE_CHANNEL, @@ -94,8 +93,6 @@ struct _NMDeviceOlpcMeshPrivate { gboolean dispose_has_run; - guint8 hw_addr[ETH_ALEN]; - GByteArray * ssid; WifiData * wifi_data; @@ -138,8 +135,6 @@ nm_device_olpc_mesh_init (NMDeviceOlpcMesh * self) priv->dispose_has_run = FALSE; priv->companion = NULL; priv->stage1_waiting = FALSE; - - memset (&priv->hw_addr, 0, sizeof (priv->hw_addr)); } static GObject* @@ -310,31 +305,6 @@ complete_connection (NMDevice *device, /****************************************************************************/ -static void -update_hw_address (NMDevice *dev) -{ - NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (dev); - NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); - gsize addrlen; - gboolean changed = FALSE; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - g_return_if_fail (addrlen == ETH_ALEN); - if (changed) - g_object_notify (G_OBJECT (dev), NM_DEVICE_OLPC_MESH_HW_ADDRESS); - } -} - -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device); - - *out_len = sizeof (priv->hw_addr); - return priv->hw_addr; -} - static NMActStageReturn act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) { @@ -476,9 +446,6 @@ get_property (GObject *object, guint prop_id, NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device); switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, ARPHRD_ETHER)); - break; case PROP_COMPANION: if (priv->companion) g_value_set_boxed (value, nm_device_get_path (priv->companion)); @@ -523,8 +490,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) parent_class->is_up = is_up; parent_class->bring_up = bring_up; parent_class->take_down = take_down; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; parent_class->check_connection_compatible = check_connection_compatible; parent_class->can_auto_connect = can_auto_connect; parent_class->complete_connection = complete_connection; @@ -535,14 +500,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) parent_class->state_changed = state_changed; /* Properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_OLPC_MESH_HW_ADDRESS, - "MAC Address", - "Hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_COMPANION, g_param_spec_boxed (NM_DEVICE_OLPC_MESH_COMPANION, @@ -637,16 +594,17 @@ static gboolean is_companion (NMDeviceOlpcMesh *self, NMDevice *other) { NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); - const guint8 *their_addr; - guint their_addr_len = 0; + const guint8 *my_addr, *their_addr; + guint their_addr_len; NMManager *manager; if (!NM_IS_DEVICE_WIFI (other)) return FALSE; + my_addr = nm_device_get_hw_address (NM_DEVICE (self), NULL); their_addr = nm_device_get_hw_address (other, &their_addr_len); if ( (their_addr_len != ETH_ALEN) - || (memcmp (priv->hw_addr, their_addr, ETH_ALEN) != 0)) + || (memcmp (my_addr, their_addr, ETH_ALEN) != 0)) return FALSE; priv->companion = other; diff --git a/src/nm-device-private.h b/src/nm-device-private.h index 3433c0e1af..1d250a4381 100644 --- a/src/nm-device-private.h +++ b/src/nm-device-private.h @@ -46,7 +46,7 @@ gboolean nm_device_hw_bring_up (NMDevice *self, gboolean wait, gboolean *no_firm void nm_device_hw_take_down (NMDevice *self, gboolean block); -gsize nm_device_read_hwaddr (NMDevice *dev, guint8 *out_buf, gsize buf_len, gboolean *out_changed); +gboolean nm_device_update_hw_address (NMDevice *self); gboolean nm_device_ip_config_should_fail (NMDevice *self, gboolean ip6); diff --git a/src/nm-device-vlan.c b/src/nm-device-vlan.c index b3d9255ef3..9ee66cd905 100644 --- a/src/nm-device-vlan.c +++ b/src/nm-device-vlan.c @@ -54,9 +54,6 @@ typedef struct { guint vlan_id; - guint8 hw_addr[NM_UTILS_HWADDR_LEN_MAX]; - guint hw_addr_len; - gboolean carrier; NMNetlinkMonitor *monitor; gulong link_connected_id; @@ -73,7 +70,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_HW_ADDRESS, PROP_CARRIER, PROP_VLAN_ID, @@ -154,31 +150,6 @@ hw_bring_up (NMDevice *dev, gboolean *no_firmware) return success; } -static void -update_hw_address (NMDevice *dev) -{ - NMDeviceVlan *self = NM_DEVICE_VLAN (dev); - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); - gsize addrlen; - gboolean changed = FALSE; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - priv->hw_addr_len = addrlen; - if (changed) - g_object_notify (G_OBJECT (self), NM_DEVICE_VLAN_HW_ADDRESS); - } -} - -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); - - *out_len = priv->hw_addr_len; - return priv->hw_addr; -} - static gboolean can_interrupt_activation (NMDevice *dev) { @@ -328,7 +299,7 @@ complete_connection (NMDevice *device, */ if (!nm_setting_vlan_get_parent (s_vlan)) { if (!nm_device_hwaddr_matches (priv->parent, connection, NULL, 0, TRUE)) { - /* FIXME: put priv->hw_addr into the connection in the appropriate + /* FIXME: put hw_addr into the connection in the appropriate * hardware-specific setting. */ g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID, @@ -346,6 +317,8 @@ match_l2_config (NMDevice *device, NMConnection *connection) NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); NMSettingVlan *s_vlan; gboolean fail_if_no_hwaddr = FALSE; + const guint8 *hw_addr; + guint hw_addr_len; s_vlan = nm_connection_get_setting_vlan (connection); g_assert (s_vlan); @@ -365,7 +338,8 @@ match_l2_config (NMDevice *device, NMConnection *connection) * address will be in. The VLAN device shouldn't have to know what kind * of interface the parent is. */ - if (!nm_device_hwaddr_matches (priv->parent, connection, priv->hw_addr, priv->hw_addr_len, fail_if_no_hwaddr)) + hw_addr = nm_device_get_hw_address (device, &hw_addr_len); + if (!nm_device_hwaddr_matches (priv->parent, connection, hw_addr, hw_addr_len, fail_if_no_hwaddr)) return FALSE; /* FIXME: any more L2 checks? */ @@ -525,13 +499,8 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object); - char *hwaddr; switch (prop_id) { - case PROP_HW_ADDRESS: - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len)); - g_value_take_string (value, hwaddr); - break; case PROP_CARRIER: g_value_set_boolean (value, priv->carrier); break; @@ -597,8 +566,6 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) object_class->dispose = dispose; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; parent_class->hw_bring_up = hw_bring_up; parent_class->can_interrupt_activation = can_interrupt_activation; parent_class->is_available = is_available; @@ -608,14 +575,6 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) parent_class->match_l2_config = match_l2_config; /* properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_VLAN_HW_ADDRESS, - "Active MAC Address", - "Currently set hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_CARRIER, g_param_spec_boolean (NM_DEVICE_VLAN_CARRIER, diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index a39e18c7c4..f1f79cdd8f 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -86,7 +86,6 @@ G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE) enum { PROP_0, - PROP_HW_ADDRESS, PROP_PERM_HW_ADDRESS, PROP_MODE, PROP_BITRATE, @@ -127,7 +126,6 @@ typedef struct Supplicant { struct _NMDeviceWifiPrivate { gboolean disposed; - guint8 hw_addr[ETH_ALEN]; /* Currently set MAC address */ guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */ guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */ @@ -203,8 +201,6 @@ static void schedule_scanlist_cull (NMDeviceWifi *self); static gboolean request_wireless_scan (gpointer user_data); -static void update_hw_address (NMDevice *dev); - /*****************************************************************/ #define NM_WIFI_ERROR (nm_wifi_error_quark ()) @@ -837,10 +833,10 @@ static gboolean _set_hw_addr (NMDeviceWifi *self, const guint8 *addr, const char *detail) { NMDevice *dev = NM_DEVICE (self); - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); const char *iface; char *mac_str = NULL; gboolean success = FALSE; + const guint8 *cur_addr = nm_device_get_hw_address (dev, NULL); g_return_val_if_fail (addr != NULL, FALSE); @@ -850,7 +846,7 @@ _set_hw_addr (NMDeviceWifi *self, const guint8 *addr, const char *detail) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); /* Do nothing if current MAC is same */ - if (!memcmp (&priv->hw_addr, addr, ETH_ALEN)) { + if (cur_addr && !memcmp (cur_addr, addr, ETH_ALEN)) { nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): no MAC address change needed", iface); g_free (mac_str); return TRUE; @@ -862,7 +858,7 @@ _set_hw_addr (NMDeviceWifi *self, const guint8 *addr, const char *detail) success = nm_system_iface_set_mac (nm_device_get_ip_ifindex (dev), (struct ether_addr *) addr); if (success) { /* MAC address succesfully changed; update the current MAC to match */ - update_hw_address (dev); + nm_device_update_hw_address (dev); nm_log_info (LOGD_DEVICE | LOGD_ETHER, "(%s): %s MAC address to %s", iface, detail, mac_str); } else { @@ -2813,21 +2809,6 @@ error: /****************************************************************************/ -static void -update_hw_address (NMDevice *dev) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (dev); - gsize addrlen; - gboolean changed = FALSE; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - g_return_if_fail (addrlen == ETH_ALEN); - if (changed) - g_object_notify (G_OBJECT (dev), NM_DEVICE_WIFI_HW_ADDRESS); - } -} - static void update_permanent_hw_address (NMDevice *dev) { @@ -2858,7 +2839,7 @@ update_permanent_hw_address (NMDevice *dev) nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): unable to read permanent MAC address (error %d)", nm_device_get_iface (dev), errno); /* Fall back to current address */ - memcpy (epaddr->data, &priv->hw_addr, ETH_ALEN); + memcpy (epaddr->data, nm_device_get_hw_address (dev, NULL), ETH_ALEN); } if (memcmp (&priv->perm_hw_addr, epaddr->data, ETH_ALEN)) { @@ -2875,37 +2856,19 @@ update_initial_hw_address (NMDevice *dev) { NMDeviceWifi *self = NM_DEVICE_WIFI (dev); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - char *mac_str = NULL; - guint8 *addr = priv->initial_hw_addr; - guint8 zero[ETH_ALEN] = {0,0,0,0,0,0}; + char *mac_str; /* This sets initial MAC address from current MAC address. It should only * be called from NMDevice constructor() to really get the initial address. */ - if (!memcmp (&priv->hw_addr, &zero, ETH_ALEN)) - update_hw_address (dev); - - if (memcmp (&priv->initial_hw_addr, &priv->hw_addr, ETH_ALEN)) - memcpy (&priv->initial_hw_addr, &priv->hw_addr, ETH_ALEN); - - mac_str = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", - addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); - + memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN); + + mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ARPHRD_ETHER); nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): read initial MAC address %s", nm_device_get_iface (dev), mac_str); - g_free (mac_str); } -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); - - *out_len = ETH_ALEN; - return priv->hw_addr; -} - static NMActStageReturn act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) { @@ -2986,7 +2949,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) if (nm_ap_get_mode (ap) == NM_802_11_MODE_INFRA) nm_ap_set_broadcast (ap, FALSE); else if (nm_ap_is_hotspot (ap)) - nm_ap_set_address (ap, (const struct ether_addr *) &priv->hw_addr); + nm_ap_set_address (ap, (const struct ether_addr *) nm_device_get_hw_address (dev, NULL)); priv->ap_list = g_slist_prepend (priv->ap_list, ap); nm_ap_export_to_dbus (ap); @@ -3396,33 +3359,14 @@ get_type_capabilities (NMDevice *dev) } -static gboolean -hwaddr_matches (NMDevice *device, - NMConnection *connection, - const guint8 *other_hwaddr, - guint other_hwaddr_len, - gboolean fail_if_no_hwaddr) +static const GByteArray * +get_connection_hw_address (NMDevice *device, + NMConnection *connection) { - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); NMSettingWireless *s_wifi; - const GByteArray *mac = NULL; s_wifi = nm_connection_get_setting_wireless (connection); - if (s_wifi) - mac = nm_setting_wireless_get_mac_address (s_wifi); - - if (mac) { - g_return_val_if_fail (mac->len == ETH_ALEN, FALSE); - if (other_hwaddr) { - g_return_val_if_fail (other_hwaddr_len == ETH_ALEN, FALSE); - if (memcmp (mac->data, other_hwaddr, mac->len) == 0) - return TRUE; - } else if (memcmp (mac->data, priv->hw_addr, mac->len) == 0) - return TRUE; - } else if (fail_if_no_hwaddr == FALSE) - return TRUE; - - return FALSE; + return s_wifi ? nm_setting_wireless_get_mac_address (s_wifi) : NULL; } static void @@ -3646,9 +3590,6 @@ get_property (GObject *object, guint prop_id, NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->hw_addr, ARPHRD_ETHER)); - break; case PROP_PERM_HW_ADDRESS: g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER)); break; @@ -3716,8 +3657,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) parent_class->is_up = is_up; parent_class->bring_up = bring_up; parent_class->take_down = take_down; - parent_class->update_hw_address = update_hw_address; - parent_class->get_hw_address = get_hw_address; parent_class->update_permanent_hw_address = update_permanent_hw_address; parent_class->update_initial_hw_address = update_initial_hw_address; parent_class->can_auto_connect = can_auto_connect; @@ -3734,20 +3673,13 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) parent_class->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout; parent_class->deactivate = deactivate; parent_class->can_interrupt_activation = can_interrupt_activation; - parent_class->hwaddr_matches = hwaddr_matches; + parent_class->get_connection_hw_address = get_connection_hw_address; parent_class->state_changed = device_state_changed; klass->scanning_allowed = scanning_allowed; /* Properties */ - g_object_class_install_property (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WIFI_HW_ADDRESS, - "Active MAC Address", - "Currently set hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_PERM_HW_ADDRESS, g_param_spec_string (NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, "Permanent MAC Address", diff --git a/src/nm-device.c b/src/nm-device.c index be5e2ed5cd..0692f3971c 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -128,6 +128,7 @@ enum { PROP_IFINDEX, PROP_AVAILABLE_CONNECTIONS, PROP_IS_MASTER, + PROP_HW_ADDRESS, LAST_PROP }; @@ -185,6 +186,8 @@ typedef struct { RfKillType rfkill_type; gboolean firmware_missing; GHashTable * available_connections; + guint8 hw_addr[NM_UTILS_HWADDR_LEN_MAX]; + guint hw_addr_len; guint32 ip4_address; @@ -489,8 +492,7 @@ constructed (GObject *object) { NMDevice *dev = NM_DEVICE (object); - if (NM_DEVICE_GET_CLASS (dev)->update_hw_address) - NM_DEVICE_GET_CLASS (dev)->update_hw_address (dev); + nm_device_update_hw_address (dev); if (NM_DEVICE_GET_CLASS (dev)->update_permanent_hw_address) NM_DEVICE_GET_CLASS (dev)->update_permanent_hw_address (dev); @@ -636,16 +638,30 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) g_free (old_ip_iface); } +static guint +nm_device_get_hw_address_length (NMDevice *dev) +{ + if (NM_DEVICE_GET_CLASS (dev)->get_hw_address_length) + return NM_DEVICE_GET_CLASS (dev)->get_hw_address_length (dev); + else + return ETH_ALEN; +} + const guint8 * nm_device_get_hw_address (NMDevice *dev, guint *out_len) { - g_return_val_if_fail (NM_IS_DEVICE (dev), NULL); - g_return_val_if_fail (out_len != NULL, NULL); - g_return_val_if_fail (*out_len == 0, NULL); + NMDevicePrivate *priv; - if (NM_DEVICE_GET_CLASS (dev)->get_hw_address) - return NM_DEVICE_GET_CLASS (dev)->get_hw_address (dev, out_len); - return NULL; + g_return_val_if_fail (NM_IS_DEVICE (dev), NULL); + priv = NM_DEVICE_GET_PRIVATE (dev); + + if (out_len) + *out_len = priv->hw_addr_len; + + if (priv->hw_addr_len == 0) + return NULL; + else + return priv->hw_addr; } /* @@ -877,8 +893,7 @@ nm_device_enslave_slave (NMDevice *dev, NMDevice *slave, NMConnection *connectio /* Ensure the device's hardware address is up-to-date; it often changes * when slaves change. */ - if (NM_DEVICE_GET_CLASS (dev)->update_hw_address) - NM_DEVICE_GET_CLASS (dev)->update_hw_address (dev); + nm_device_update_hw_address (dev); /* Restart IP configuration if we're waiting for slaves. Do this * after updating the hardware address as IP config may need the @@ -933,8 +948,7 @@ nm_device_release_one_slave (NMDevice *dev, NMDevice *slave, gboolean failed) /* Ensure the device's hardware address is up-to-date; it often changes * when slaves change. */ - if (NM_DEVICE_GET_CLASS (dev)->update_hw_address) - NM_DEVICE_GET_CLASS (dev)->update_hw_address (dev); + nm_device_update_hw_address (dev); return success; } @@ -2202,8 +2216,6 @@ dhcp4_start (NMDevice *self, NMSettingIP4Config *s_ip4; guint8 *anycast = NULL; GByteArray *tmp = NULL; - guint hwaddr_len = 0; - const guint8 *hwaddr; s_ip4 = nm_connection_get_setting_ip4_config (connection); @@ -2215,10 +2227,9 @@ dhcp4_start (NMDevice *self, g_object_unref (priv->dhcp4_config); priv->dhcp4_config = nm_dhcp4_config_new (); - hwaddr = nm_device_get_hw_address (self, &hwaddr_len); - if (hwaddr) { - tmp = g_byte_array_sized_new (hwaddr_len); - g_byte_array_append (tmp, hwaddr, hwaddr_len); + 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); } /* Begin DHCP on the interface */ @@ -2662,8 +2673,6 @@ dhcp6_start (NMDevice *self, NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; guint8 *anycast = NULL; GByteArray *tmp = NULL; - guint hwaddr_len = 0; - const guint8 *hwaddr; if (!connection) { connection = nm_device_get_connection (self); @@ -2686,10 +2695,9 @@ dhcp6_start (NMDevice *self, priv->dhcp6_ip6_config = NULL; } - hwaddr = nm_device_get_hw_address (self, &hwaddr_len); - if (hwaddr) { - tmp = g_byte_array_sized_new (hwaddr_len); - g_byte_array_append (tmp, hwaddr, hwaddr_len); + 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); } priv->dhcp6_client = nm_dhcp_manager_start_ip6 (priv->dhcp_manager, @@ -2834,8 +2842,6 @@ addrconf6_start (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMConnection *connection; gboolean success; - const guint8 *hwaddr; - guint hwaddr_len = 0; connection = nm_device_get_connection (self); g_assert (connection); @@ -2858,12 +2864,11 @@ addrconf6_start (NMDevice *self) self); } - hwaddr = nm_device_get_hw_address (self, &hwaddr_len); - g_warn_if_fail (hwaddr != NULL); + g_warn_if_fail (priv->hw_addr_len != 0); success = nm_ip6_manager_prepare_interface (priv->ip6_manager, nm_device_get_ip_ifindex (self), - hwaddr, - hwaddr_len, + priv->hw_addr, + priv->hw_addr_len, nm_connection_get_setting_ip6_config (connection), priv->ip6_accept_ra_path); if (success) { @@ -4353,8 +4358,7 @@ nm_device_hw_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) out: /* Can only get HW address of some devices when they are up */ - if (NM_DEVICE_GET_CLASS (self)->update_hw_address) - NM_DEVICE_GET_CLASS (self)->update_hw_address (self); + nm_device_update_hw_address (self); _update_ip4_address (self); return TRUE; @@ -4573,6 +4577,8 @@ set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); + const char *hw_addr; + int hw_addr_type; switch (prop_id) { case PROP_UDI: @@ -4641,6 +4647,24 @@ set_property (GObject *object, guint prop_id, case PROP_IS_MASTER: priv->is_master = g_value_get_boolean (value); break; + case PROP_HW_ADDRESS: + priv->hw_addr_len = nm_device_get_hw_address_length (NM_DEVICE (object)); + + hw_addr = g_value_get_string (value); + if (!hw_addr) + break; + if (priv->hw_addr_len == 0) { + g_warn_if_fail (*hw_addr == '\0'); + break; + } + hw_addr_type = nm_utils_hwaddr_type (priv->hw_addr_len); + g_return_if_fail (hw_addr_type != -1); + + if (!nm_utils_hwaddr_aton (hw_addr, hw_addr_type, priv->hw_addr)) { + g_warning ("Could not parse hw-address '%s'", hw_addr); + memset (priv->hw_addr, 0, sizeof (priv->hw_addr)); + } + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -4765,6 +4789,12 @@ get_property (GObject *object, guint prop_id, case PROP_IS_MASTER: g_value_set_boolean (value, priv->is_master); break; + case PROP_HW_ADDRESS: + if (priv->hw_addr_len) + g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len))); + else + g_value_set_string (value, NULL); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -4999,6 +5029,14 @@ nm_device_class_init (NMDeviceClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property + (object_class, PROP_HW_ADDRESS, + g_param_spec_string (NM_DEVICE_HW_ADDRESS, + "Hardware Address", + "Hardware address", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + /* Signals */ signals[STATE_CHANGED] = g_signal_new ("state-changed", @@ -5546,17 +5584,15 @@ nm_device_spec_match_list (NMDevice *device, const GSList *specs) static gboolean spec_match_list (NMDevice *device, const GSList *specs) { - const guint8 *hwaddr; - guint hwaddr_len = 0; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); char *hwaddr_str; gboolean matched = FALSE; if (nm_match_spec_string (specs, "*")) return TRUE; - hwaddr = nm_device_get_hw_address (device, &hwaddr_len); - if (hwaddr && hwaddr_len) { - hwaddr_str = nm_utils_hwaddr_ntoa (hwaddr, nm_utils_hwaddr_type (hwaddr_len)); + if (priv->hw_addr_len) { + hwaddr_str = nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len)); matched = nm_match_spec_hwaddr (specs, hwaddr_str); g_free (hwaddr_str); } @@ -5718,17 +5754,30 @@ nm_device_hwaddr_matches (NMDevice *device, guint other_hwaddr_len, gboolean fail_if_no_hwaddr) { - g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); - if (other_hwaddr) - g_return_val_if_fail (other_hwaddr_len > 0, FALSE); + NMDevicePrivate *priv; + const GByteArray *setting_hwaddr; + + g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + priv = NM_DEVICE_GET_PRIVATE (device); + + if (other_hwaddr) + g_return_val_if_fail (other_hwaddr_len != priv->hw_addr_len, FALSE); + + if (!NM_DEVICE_GET_CLASS (device)->get_connection_hw_address) + return FALSE; + + setting_hwaddr = NM_DEVICE_GET_CLASS (device)->get_connection_hw_address (device, connection); + if (setting_hwaddr) { + g_return_val_if_fail (setting_hwaddr->len == priv->hw_addr_len, FALSE); + + if (other_hwaddr) { + if (memcmp (setting_hwaddr->data, other_hwaddr, priv->hw_addr_len) == 0) + return TRUE; + } else if (memcmp (setting_hwaddr->data, priv->hw_addr, priv->hw_addr_len) == 0) + return TRUE; + } else if (fail_if_no_hwaddr == FALSE) + return TRUE; - if (NM_DEVICE_GET_CLASS (device)->hwaddr_matches) { - return NM_DEVICE_GET_CLASS (device)->hwaddr_matches (device, - connection, - other_hwaddr, - other_hwaddr_len, - fail_if_no_hwaddr); - } return FALSE; } @@ -5885,70 +5934,77 @@ nm_device_supports_vlans (NMDevice *device) return NM_IS_DEVICE_ETHERNET (device); } -/** - * nm_device_read_hwaddr: - * @dev: the device - * @buf: an allocated buffer which on success holds the device's hardware - * address - * @buf_len: the size of @buf - * @out_changed: on success, %TRUE if the contents of @buf are different from - * the original contents of @buf when this function was called - * - * Reads the device's hardware address from the kernel and copies it into - * @buf, returning the size of the data copied into @buf. On failure - * @buf is not modified. - * - * Returns: the size of the hardware address in bytes on success, 0 on failure - */ -gsize -nm_device_read_hwaddr (NMDevice *dev, - guint8 *buf, - gsize buf_len, - gboolean *out_changed) +gboolean +nm_device_update_hw_address (NMDevice *dev) { - struct rtnl_link *rtnl; - struct nl_addr *addr; - int idx; - gsize addrlen = 0; - const guint8 *binaddr; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (dev); + gboolean changed = FALSE; - g_return_val_if_fail (dev != NULL, 0); - g_return_val_if_fail (buf != NULL, 0); - g_return_val_if_fail (buf_len > 0, 0); + priv->hw_addr_len = nm_device_get_hw_address_length (dev); - idx = nm_device_get_ip_ifindex (dev); - g_return_val_if_fail (idx > 0, 0); + if (priv->hw_addr_len) { + struct rtnl_link *rtnl; + struct nl_addr *addr; + int idx; + gsize addrlen; + const guint8 *binaddr; - rtnl = nm_netlink_index_to_rtnl_link (idx); - if (!rtnl) { - nm_log_err (LOGD_HW | LOGD_DEVICE, - "(%s): failed to read hardware address (error %d)", - nm_device_get_iface (dev), errno); - return 0; - } + idx = nm_device_get_ip_ifindex (dev); + g_return_val_if_fail (idx > 0, FALSE); - addr = rtnl_link_get_addr (rtnl); - if (!addr) { - nm_log_err (LOGD_HW | LOGD_DEVICE, - "(%s): no hardware address?", - nm_device_get_iface (dev)); - goto out; - } + rtnl = nm_netlink_index_to_rtnl_link (idx); + if (!rtnl) { + nm_log_err (LOGD_HW | LOGD_DEVICE, + "(%s): failed to read hardware address (error %d)", + nm_device_get_iface (dev), errno); + return FALSE; + } - addrlen = nl_addr_get_len (addr); - if (addrlen > buf_len) { - nm_log_err (LOGD_HW | LOGD_DEVICE, - "(%s): hardware address is wrong length (got %zd max %zd)", - nm_device_get_iface (dev), addrlen, buf_len); - addrlen = 0; + addr = rtnl_link_get_addr (rtnl); + if (!addr) { + nm_log_err (LOGD_HW | LOGD_DEVICE, + "(%s): no hardware address?", + nm_device_get_iface (dev)); + rtnl_link_put (rtnl); + return FALSE; + } + + addrlen = nl_addr_get_len (addr); + if (addrlen != priv->hw_addr_len) { + nm_log_err (LOGD_HW | LOGD_DEVICE, + "(%s): hardware address is wrong length (got %zd, expected %d)", + nm_device_get_iface (dev), addrlen, priv->hw_addr_len); + } else { + binaddr = nl_addr_get_binary_addr (addr); + changed = memcmp (priv->hw_addr, binaddr, addrlen) ? TRUE : FALSE; + memcpy (priv->hw_addr, binaddr, addrlen); + if (changed) { + char *addrstr = nm_utils_hwaddr_ntoa (binaddr, nm_utils_hwaddr_type (addrlen)); + nm_log_dbg (LOGD_HW | LOGD_DEVICE, + "(%s): hardware address is %s", + nm_device_get_iface (dev), addrstr); + g_free (addrstr); + g_object_notify (G_OBJECT (dev), NM_DEVICE_HW_ADDRESS); + } + } + + rtnl_link_put (rtnl); } else { - binaddr = nl_addr_get_binary_addr (addr); - if (out_changed) - *out_changed = memcmp (buf, binaddr, addrlen) ? TRUE : FALSE; - memcpy (buf, binaddr, addrlen); + int i; + + /* hw_addr_len is now 0; see if hw_addr was already empty */ + for (i = 0; i < sizeof (priv->hw_addr) && !changed; i++) { + if (priv->hw_addr[i]) + changed = TRUE; + } + if (changed) { + memset (priv->hw_addr, 0, sizeof (priv->hw_addr)); + nm_log_dbg (LOGD_HW | LOGD_DEVICE, + "(%s): previous hardware address is no longer valid", + nm_device_get_iface (dev)); + g_object_notify (G_OBJECT (dev), NM_DEVICE_HW_ADDRESS); + } } -out: - rtnl_link_put (rtnl); - return addrlen; + return changed; } diff --git a/src/nm-device.h b/src/nm-device.h index c4eb375dc8..009c498e7e 100644 --- a/src/nm-device.h +++ b/src/nm-device.h @@ -57,11 +57,12 @@ #define NM_DEVICE_MANAGED "managed" #define NM_DEVICE_AUTOCONNECT "autoconnect" #define NM_DEVICE_FIRMWARE_MISSING "firmware-missing" +#define NM_DEVICE_AVAILABLE_CONNECTIONS "available-connections" #define NM_DEVICE_TYPE_DESC "type-desc" /* Internal only */ #define NM_DEVICE_RFKILL_TYPE "rfkill-type" /* Internal only */ #define NM_DEVICE_IFINDEX "ifindex" /* Internal only */ #define NM_DEVICE_IS_MASTER "is-master" /* Internal only */ -#define NM_DEVICE_AVAILABLE_CONNECTIONS "available-connections" +#define NM_DEVICE_HW_ADDRESS "hw-address" /* Internal only */ /* Internal signals */ #define NM_DEVICE_AUTH_REQUEST "auth-request" @@ -113,7 +114,7 @@ typedef struct { void (* update_hw_address) (NMDevice *self); void (* update_permanent_hw_address) (NMDevice *self); void (* update_initial_hw_address) (NMDevice *self); - const guint8 * (* get_hw_address) (NMDevice *self, guint *out_len); + guint (* get_hw_address_length) (NMDevice *self); guint32 (* get_type_capabilities) (NMDevice *self); guint32 (* get_generic_capabilities) (NMDevice *self); @@ -176,11 +177,8 @@ typedef struct { gboolean (* match_l2_config) (NMDevice *self, NMConnection *connection); - gboolean (* hwaddr_matches) (NMDevice *self, - NMConnection *connection, - const guint8 *other_hwaddr, - guint other_hwaddr_len, - gboolean fail_if_no_hwaddr); + const GByteArray * (* get_connection_hw_address) (NMDevice *self, + NMConnection *connection); gboolean (* enslave_slave) (NMDevice *self, NMDevice *slave, diff --git a/src/wimax/nm-device-wimax.c b/src/wimax/nm-device-wimax.c index 7dc592e29b..541c39dfd1 100644 --- a/src/wimax/nm-device-wimax.c +++ b/src/wimax/nm-device-wimax.c @@ -54,7 +54,6 @@ G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE) enum { PROP_0, - PROP_HW_ADDRESS, PROP_ACTIVE_NSP, PROP_CENTER_FREQ, PROP_RSSI, @@ -88,7 +87,6 @@ typedef struct { gboolean enabled; gboolean wimaxd_enabled; - guint8 hw_addr[ETH_ALEN]; guint activation_timeout_id; /* Track whether stage1 (Prepare) is completed yet or not */ @@ -355,58 +353,14 @@ hw_bring_up (NMDevice *dev, gboolean *no_firmware) return NM_DEVICE_GET_CLASS (dev)->hw_bring_up (dev, no_firmware); } -static void -update_hw_address (NMDevice *dev) +static const GByteArray * +get_connection_hw_address (NMDevice *device, + NMConnection *connection) { - NMDeviceWimax *self = NM_DEVICE_WIMAX (dev); - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); - gboolean changed = FALSE; - gsize addrlen; - - addrlen = nm_device_read_hwaddr (dev, priv->hw_addr, sizeof (priv->hw_addr), &changed); - if (addrlen) { - g_return_if_fail (addrlen == ETH_ALEN); - if (changed) - g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_HW_ADDRESS); - } -} - -static const guint8 * -get_hw_address (NMDevice *device, guint *out_len) -{ - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); - - *out_len = sizeof (priv->hw_addr); - return priv->hw_addr; -} - -static gboolean -hwaddr_matches (NMDevice *device, - NMConnection *connection, - const guint8 *other_hwaddr, - guint other_hwaddr_len, - gboolean fail_if_no_hwaddr) -{ - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); NMSettingWimax *s_wimax; - const GByteArray *mac = NULL; s_wimax = nm_connection_get_setting_wimax (connection); - if (s_wimax) - mac = nm_setting_wimax_get_mac_address (s_wimax); - - if (mac) { - g_return_val_if_fail (mac->len == ETH_ALEN, FALSE); - if (other_hwaddr) { - g_return_val_if_fail (other_hwaddr_len == ETH_ALEN, FALSE); - if (memcmp (mac->data, other_hwaddr, mac->len) == 0) - return TRUE; - } else if (memcmp (mac->data, priv->hw_addr, mac->len) == 0) - return TRUE; - } else if (fail_if_no_hwaddr == FALSE) - return TRUE; - - return FALSE; + return s_wimax ? nm_setting_wimax_get_mac_address (s_wimax) : NULL; } static gboolean @@ -414,7 +368,6 @@ check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { - NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *connection_type; @@ -443,7 +396,7 @@ check_connection_compatible (NMDevice *device, } mac = nm_setting_wimax_get_mac_address (s_wimax); - if (mac && memcmp (mac->data, &priv->hw_addr, ETH_ALEN)) { + if (mac && memcmp (mac->data, nm_device_get_hw_address (device, NULL), ETH_ALEN)) { g_set_error (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INCOMPATIBLE, "The connection's MAC address did not match this device."); @@ -479,6 +432,7 @@ complete_connection (NMDevice *device, NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMSettingWimax *s_wimax; const GByteArray *setting_mac; + const guint8 *hw_address; char *format; const char *nsp_name = NULL; NMWimaxNsp *nsp = NULL; @@ -555,9 +509,10 @@ complete_connection (NMDevice *device, g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_NETWORK_NAME, nsp_name, NULL); setting_mac = nm_setting_wimax_get_mac_address (s_wimax); + hw_address = nm_device_get_hw_address (device, NULL); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's permanent MAC */ - if (memcmp (setting_mac->data, &priv->hw_addr, ETH_ALEN)) { + if (memcmp (setting_mac->data, hw_address, ETH_ALEN)) { g_set_error (error, NM_SETTING_WIMAX_ERROR, NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY, @@ -569,9 +524,9 @@ complete_connection (NMDevice *device, const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; /* Lock the connection to this device by default */ - if (memcmp (&priv->hw_addr, null_mac, ETH_ALEN)) { + if (memcmp (hw_address, null_mac, ETH_ALEN)) { mac = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (mac, priv->hw_addr, ETH_ALEN); + g_byte_array_append (mac, hw_address, ETH_ALEN); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, mac, NULL); g_byte_array_free (mac, TRUE); } @@ -1384,9 +1339,6 @@ get_property (GObject *object, guint prop_id, NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); switch (prop_id) { - case PROP_HW_ADDRESS: - g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, ARPHRD_ETHER)); - break; case PROP_ACTIVE_NSP: if (priv->current_nsp) g_value_set_boxed (value, nm_wimax_nsp_get_dbus_path (priv->current_nsp)); @@ -1466,8 +1418,6 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *klass) device_class->take_down = take_down; device_class->hw_bring_up = hw_bring_up; - device_class->update_hw_address = update_hw_address; - device_class->get_hw_address = get_hw_address; device_class->check_connection_compatible = check_connection_compatible; device_class->check_connection_available = check_connection_available; device_class->complete_connection = complete_connection; @@ -1478,19 +1428,11 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *klass) device_class->act_stage2_config = act_stage2_config; device_class->deactivate = deactivate; device_class->set_enabled = set_enabled; - device_class->hwaddr_matches = hwaddr_matches; + device_class->get_connection_hw_address = get_connection_hw_address; device_class->state_changed = device_state_changed; /* Properties */ - g_object_class_install_property - (object_class, PROP_HW_ADDRESS, - g_param_spec_string (NM_DEVICE_WIMAX_HW_ADDRESS, - "MAC Address", - "Hardware MAC address", - NULL, - G_PARAM_READABLE)); - g_object_class_install_property (object_class, PROP_ACTIVE_NSP, g_param_spec_boxed (NM_DEVICE_WIMAX_ACTIVE_NSP, "Active NSP",