summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/devices/bluetooth/nm-device-bt.c20
-rw-r--r--src/devices/nm-device-bridge.c7
-rw-r--r--src/devices/nm-device-ethernet.c55
-rw-r--r--src/devices/nm-device-infiniband.c17
-rw-r--r--src/devices/nm-device-vlan.c14
-rw-r--r--src/devices/nm-device.c62
-rw-r--r--src/devices/nm-device.h2
-rw-r--r--src/devices/wifi/nm-device-olpc-mesh.c9
-rw-r--r--src/devices/wifi/nm-device-wifi.c55
-rw-r--r--src/devices/wimax/nm-device-wimax.c13
-rw-r--r--src/nm-config.c9
-rw-r--r--src/nm-manager.c9
-rw-r--r--src/settings/nm-settings.c17
13 files changed, 137 insertions, 152 deletions
diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c
index 86f1325c51..f39f272202 100644
--- a/src/devices/bluetooth/nm-device-bt.c
+++ b/src/devices/bluetooth/nm-device-bt.c
@@ -60,7 +60,7 @@ typedef struct {
NMBluezDevice *bt_device;
- guint8 bdaddr[ETH_ALEN];
+ char *bdaddr;
char *name;
guint32 capabilities;
@@ -178,7 +178,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
array = nm_setting_bluetooth_get_bdaddr (s_bt);
if (!array)
return FALSE;
- if (!nm_utils_hwaddr_equal (priv->bdaddr, ETH_ALEN, array->data, array->len))
+ if (!nm_utils_hwaddr_equal (priv->bdaddr, -1, array->data, array->len))
return FALSE;
return TRUE;
@@ -320,7 +320,7 @@ complete_connection (NMDevice *device,
setting_bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt);
if (setting_bdaddr) {
/* Make sure the setting BT Address (if any) matches the device's */
- if (!nm_utils_hwaddr_equal (setting_bdaddr->data, setting_bdaddr->len, priv->bdaddr, ETH_ALEN)) {
+ if (!nm_utils_hwaddr_equal (setting_bdaddr->data, setting_bdaddr->len, priv->bdaddr, -1)) {
g_set_error_literal (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
@@ -331,9 +331,8 @@ complete_connection (NMDevice *device,
GByteArray *bdaddr;
/* Lock the connection to this device by default */
- if (!nm_utils_hwaddr_equal (priv->bdaddr, ETH_ALEN, NULL, ETH_ALEN)) {
- bdaddr = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (bdaddr, priv->bdaddr, ETH_ALEN);
+ if (!nm_utils_hwaddr_equal (priv->bdaddr, -1, NULL, ETH_ALEN)) {
+ bdaddr = nm_utils_hwaddr_atoba (priv->bdaddr, ETH_ALEN);
g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, bdaddr, NULL);
g_byte_array_free (bdaddr, TRUE);
}
@@ -1080,15 +1079,13 @@ static void
constructed (GObject *object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
- const guint8 *my_hwaddr;
- guint my_hwaddr_len = 0;
+ const char *my_hwaddr;
G_OBJECT_CLASS (nm_device_bt_parent_class)->constructed (object);
- my_hwaddr = nm_device_get_hw_address (NM_DEVICE (object), &my_hwaddr_len);
+ my_hwaddr = nm_device_get_hw_address (NM_DEVICE (object));
g_assert (my_hwaddr);
- g_assert_cmpint (my_hwaddr_len, ==, ETH_ALEN);
- memcpy (priv->bdaddr, my_hwaddr, ETH_ALEN);
+ priv->bdaddr = g_strdup (my_hwaddr);
/* Watch for BT device property changes */
g_signal_connect (priv->bt_device, "notify::" NM_BLUEZ_DEVICE_CONNECTED,
@@ -1175,6 +1172,7 @@ finalize (GObject *object)
g_free (priv->rfcomm_iface);
g_free (priv->name);
+ g_free (priv->bdaddr);
G_OBJECT_CLASS (nm_device_bt_parent_class)->finalize (object);
}
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index 4c359b0d17..91e0b5d383 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -115,12 +115,11 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
mac_address = nm_setting_bridge_get_mac_address (s_bridge);
if (mac_address) {
- guint hw_len;
- const guint8 *hw_addr;
+ const char *hw_addr;
- hw_addr = nm_device_get_hw_address (device, &hw_len);
+ hw_addr = nm_device_get_hw_address (device);
if ( !hw_addr
- || !nm_utils_hwaddr_equal (mac_address->data, mac_address->len, hw_addr, hw_len))
+ || !nm_utils_hwaddr_equal (hw_addr, -1, mac_address->data, mac_address->len))
return FALSE;
}
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 98490d5661..ab05ec72c7 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -99,7 +99,7 @@ typedef enum {
} DcbWait;
typedef struct {
- guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */
+ char * perm_hw_addr; /* Permanent MAC address */
guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */
guint32 speed;
@@ -346,7 +346,9 @@ update_permanent_hw_address (NMDevice *dev)
struct ifreq req;
struct ethtool_perm_addr *epaddr = NULL;
int fd, ret;
- const guint8 *mac;
+ const char *mac;
+
+ g_return_if_fail (priv->perm_hw_addr == NULL);
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
@@ -369,17 +371,14 @@ 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 */
- mac = nm_device_get_hw_address (dev, NULL);
+ mac = nm_device_get_hw_address (dev);
if (mac)
- memcpy (epaddr->data, mac, ETH_ALEN);
+ nm_utils_hwaddr_aton (mac, epaddr->data, ETH_ALEN);
else
memset (epaddr->data, 0, ETH_ALEN);
}
- if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, epaddr->data, ETH_ALEN)) {
- memcpy (priv->perm_hw_addr, epaddr->data, ETH_ALEN);
- g_object_notify (G_OBJECT (dev), NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
- }
+ priv->perm_hw_addr = nm_utils_hwaddr_ntoa (epaddr->data, ETH_ALEN);
g_free (epaddr);
close (fd);
@@ -390,20 +389,17 @@ update_initial_hw_address (NMDevice *dev)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
- char *mac_str;
- const guint8 *mac;
+ const char *mac;
/* This sets initial MAC address from current MAC address. It should only
* be called from NMDevice constructor() to really get the initial address.
*/
- mac = nm_device_get_hw_address (dev, NULL);
+ mac = nm_device_get_hw_address (dev);
if (mac)
- memcpy (priv->initial_hw_addr, mac, ETH_ALEN);
+ nm_utils_hwaddr_aton (mac, priv->initial_hw_addr, ETH_ALEN);
- mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN);
nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): read initial MAC address %s",
- nm_device_get_iface (dev), mac_str);
- g_free (mac_str);
+ nm_device_get_iface (dev), mac);
}
static guint32
@@ -482,7 +478,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
mac = nm_setting_wired_get_mac_address (s_wired);
- if (try_mac && mac && !nm_utils_hwaddr_equal (mac->data, mac->len, priv->perm_hw_addr, ETH_ALEN))
+ if (try_mac && mac && !nm_utils_hwaddr_equal (mac->data, mac->len, priv->perm_hw_addr, -1))
return FALSE;
/* Check for MAC address blacklist */
@@ -496,7 +492,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
}
- if (nm_utils_hwaddr_equal (addr, ETH_ALEN, priv->perm_hw_addr, ETH_ALEN))
+ if (nm_utils_hwaddr_equal (addr, ETH_ALEN, priv->perm_hw_addr, -1))
return FALSE;
}
}
@@ -1494,7 +1490,7 @@ complete_connection (NMDevice *device,
setting_mac = nm_setting_wired_get_mac_address (s_wired);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
- if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, priv->perm_hw_addr, ETH_ALEN)) {
+ if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, priv->perm_hw_addr, -1)) {
g_set_error_literal (error,
NM_SETTING_WIRED_ERROR,
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
@@ -1505,9 +1501,8 @@ complete_connection (NMDevice *device,
GByteArray *mac;
/* Lock the connection to this device by default */
- if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
- mac = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (mac, priv->perm_hw_addr, ETH_ALEN);
+ if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, -1, NULL, ETH_ALEN)) {
+ mac = nm_utils_hwaddr_atoba (priv->perm_hw_addr, ETH_ALEN);
g_object_set (G_OBJECT (s_wired), NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
g_byte_array_free (mac, TRUE);
}
@@ -1532,8 +1527,7 @@ update_connection (NMDevice *device, NMConnection *connection)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
NMSettingWired *s_wired = nm_connection_get_setting_wired (connection);
- guint maclen;
- const guint8 *mac = nm_device_get_hw_address (device, &maclen);
+ const char *mac = nm_device_get_hw_address (device);
const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS;
GByteArray *array;
GHashTableIter iter;
@@ -1547,20 +1541,18 @@ update_connection (NMDevice *device, NMConnection *connection)
/* If the device reports a permanent address, use that for the MAC address
* and the current MAC, if different, is the cloned MAC.
*/
- if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
- array = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (array, priv->perm_hw_addr, ETH_ALEN);
+ if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, -1, NULL, ETH_ALEN)) {
+ array = nm_utils_hwaddr_atoba (priv->perm_hw_addr, ETH_ALEN);
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, array, NULL);
g_byte_array_unref (array);
mac_prop = NULL;
- if (mac && !nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, mac, ETH_ALEN))
+ if (mac && !nm_utils_hwaddr_equal (priv->perm_hw_addr, -1, mac, -1))
mac_prop = NM_SETTING_WIRED_CLONED_MAC_ADDRESS;
}
- if (mac_prop && mac && maclen == ETH_ALEN) {
- array = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (array, (guint8 *) mac, maclen);
+ if (mac_prop && mac && nm_utils_hwaddr_valid (mac, ETH_ALEN)) {
+ array = nm_utils_hwaddr_atoba (mac, ETH_ALEN);
g_object_set (s_wired, mac_prop, array, NULL);
g_byte_array_unref (array);
}
@@ -1665,6 +1657,7 @@ finalize (GObject *object)
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (object);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
+ g_free (priv->perm_hw_addr);
g_clear_object (&priv->supplicant.mgr);
g_free (priv->subchan1);
g_free (priv->subchan2);
@@ -1685,7 +1678,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PERM_HW_ADDRESS:
- g_value_take_string (value, nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ETH_ALEN));
+ g_value_set_string (value, priv->perm_hw_addr);
break;
case PROP_SPEED:
g_value_set_uint (value, priv->speed);
diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c
index 269397c33b..2a978e0dd6 100644
--- a/src/devices/nm-device-infiniband.c
+++ b/src/devices/nm-device-infiniband.c
@@ -231,7 +231,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
if (s_infiniband) {
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len,
- nm_device_get_hw_address (device, NULL), INFINIBAND_ALEN))
+ nm_device_get_hw_address (device), -1))
return FALSE;
}
@@ -247,7 +247,7 @@ complete_connection (NMDevice *device,
{
NMSettingInfiniband *s_infiniband;
const GByteArray *setting_mac;
- const guint8 *hw_address;
+ const char *hw_address;
nm_utils_complete_generic (connection,
NM_SETTING_INFINIBAND_SETTING_NAME,
@@ -263,7 +263,7 @@ complete_connection (NMDevice *device,
}
setting_mac = nm_setting_infiniband_get_mac_address (s_infiniband);
- hw_address = nm_device_get_hw_address (device, NULL);
+ hw_address = nm_device_get_hw_address (device);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's MAC */
if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, hw_address, INFINIBAND_ALEN)) {
@@ -277,8 +277,7 @@ complete_connection (NMDevice *device,
GByteArray *mac;
/* Lock the connection to this device by default */
- mac = g_byte_array_sized_new (INFINIBAND_ALEN);
- g_byte_array_append (mac, hw_address, INFINIBAND_ALEN);
+ mac = nm_utils_hwaddr_atoba (hw_address, INFINIBAND_ALEN);
g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
g_byte_array_free (mac, TRUE);
}
@@ -293,8 +292,7 @@ static void
update_connection (NMDevice *device, NMConnection *connection)
{
NMSettingInfiniband *s_infiniband = nm_connection_get_setting_infiniband (connection);
- guint maclen;
- gconstpointer mac = nm_device_get_hw_address (device, &maclen);
+ const char *mac = nm_device_get_hw_address (device);
GByteArray *array;
char *mode_path, *contents = NULL;
const char *transport_mode = "datagram";
@@ -304,9 +302,8 @@ update_connection (NMDevice *device, NMConnection *connection)
nm_connection_add_setting (connection, (NMSetting *) s_infiniband);
}
- if (mac && !nm_utils_hwaddr_equal (mac, maclen, NULL, INFINIBAND_ALEN)) {
- array = g_byte_array_sized_new (maclen);
- g_byte_array_append (array, (guint8 *) mac, maclen);
+ if (mac && !nm_utils_hwaddr_equal (mac, -1, NULL, INFINIBAND_ALEN)) {
+ array = nm_utils_hwaddr_atoba (mac, INFINIBAND_ALEN);
g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, array, NULL);
g_byte_array_unref (array);
}
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index 04810e0cee..6284be77a4 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -86,14 +86,13 @@ update_initial_hw_address (NMDevice *dev)
{
NMDeviceVlan *self = NM_DEVICE_VLAN (dev);
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
- char *mac_str;
+ const char *mac_str;
- memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ mac_str = nm_device_get_hw_address (dev);
+ nm_utils_hwaddr_aton (mac_str, priv->initial_hw_addr, ETH_ALEN);
- mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN);
nm_log_dbg (LOGD_DEVICE | LOGD_VLAN, "(%s): read initial MAC address %s",
nm_device_get_iface (dev), mac_str);
- g_free (mac_str);
}
static guint32
@@ -158,8 +157,7 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw
{
NMSettingWired *s_wired;
const GByteArray *mac;
- const guint8 *device_mac;
- guint device_mac_len;
+ const char *device_mac;
s_wired = nm_connection_get_setting_wired (connection);
if (!s_wired)
@@ -169,9 +167,9 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw
if (!mac)
return !fail_if_no_hwaddr;
- device_mac = nm_device_get_hw_address (device, &device_mac_len);
+ device_mac = nm_device_get_hw_address (device);
- return nm_utils_hwaddr_equal (mac->data, mac->len, device_mac, device_mac_len);
+ return nm_utils_hwaddr_equal (mac->data, mac->len, device_mac, -1);
}
static gboolean
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index f27b085d59..9a74e3a134 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -208,7 +208,7 @@ typedef struct {
RfKillType rfkill_type;
gboolean firmware_missing;
GHashTable * available_connections;
- guint8 hw_addr[NM_UTILS_HWADDR_LEN_MAX];
+ char * hw_addr;
guint hw_addr_len;
char * physical_port_id;
@@ -6902,17 +6902,14 @@ nm_device_get_state (NMDevice *self)
/***********************************************************/
/* NMConfigDevice interface related stuff */
-const guint8 *
-nm_device_get_hw_address (NMDevice *self, guint *out_len)
+const char *
+nm_device_get_hw_address (NMDevice *self)
{
NMDevicePrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
priv = NM_DEVICE_GET_PRIVATE (self);
- if (out_len)
- *out_len = priv->hw_addr_len;
-
return priv->hw_addr_len ? priv->hw_addr : NULL;
}
@@ -6930,19 +6927,16 @@ nm_device_update_hw_address (NMDevice *self)
hwaddr = nm_platform_link_get_address (ifindex, &hwaddrlen);
g_assert (hwaddrlen <= sizeof (priv->hw_addr));
if (hwaddrlen) {
- if (hwaddrlen != priv->hw_addr_len || memcmp (priv->hw_addr, hwaddr, hwaddrlen)) {
- gs_free char *tmp_str = NULL;
-
- memcpy (priv->hw_addr, hwaddr, hwaddrlen);
+ if (!nm_utils_hwaddr_equal (priv->hw_addr, -1, hwaddr, hwaddrlen)) {
+ priv->hw_addr = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen);
- _LOGD (LOGD_HW | LOGD_DEVICE, "hardware address now %s",
- (tmp_str = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen)));
+ _LOGD (LOGD_HW | LOGD_DEVICE, "hardware address now %s", priv->hw_addr);
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
}
} else {
/* Invalid or no hardware address */
if (priv->hw_addr_len != 0) {
- memset (priv->hw_addr, 0, sizeof (priv->hw_addr));
+ g_clear_pointer (&priv->hw_addr, g_free);
_LOGD (LOGD_HW | LOGD_DEVICE,
"previous hardware address is no longer valid");
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
@@ -6955,30 +6949,30 @@ gboolean
nm_device_set_hw_addr (NMDevice *self, const guint8 *addr,
const char *detail, guint64 hw_log_domain)
{
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
char *mac_str = NULL;
gboolean success = FALSE;
- guint len;
- const guint8 *cur_addr = nm_device_get_hw_address (self, &len);
+ const char *cur_addr = nm_device_get_hw_address (self);
g_return_val_if_fail (addr != NULL, FALSE);
/* Do nothing if current MAC is same */
- if (cur_addr && nm_utils_hwaddr_equal (cur_addr, len, addr, len)) {
+ if (cur_addr && nm_utils_hwaddr_equal (cur_addr, -1, addr, priv->hw_addr_len)) {
_LOGD (LOGD_DEVICE | hw_log_domain, "no MAC address change needed");
return TRUE;
}
- mac_str = nm_utils_hwaddr_ntoa (addr, len);
+ mac_str = nm_utils_hwaddr_ntoa (addr, priv->hw_addr_len);
/* Can't change MAC address while device is up */
nm_device_take_down (self, FALSE);
- success = nm_platform_link_set_address (nm_device_get_ip_ifindex (self), addr, len);
+ success = nm_platform_link_set_address (nm_device_get_ip_ifindex (self), addr, priv->hw_addr_len);
if (success) {
/* MAC address succesfully changed; update the current MAC to match */
nm_device_update_hw_address (self);
- cur_addr = nm_device_get_hw_address (self, NULL);
- if (nm_utils_hwaddr_equal (cur_addr, len, addr, len)) {
+ cur_addr = nm_device_get_hw_address (self);
+ if (cur_addr && nm_utils_hwaddr_equal (cur_addr, -1, addr, priv->hw_addr_len)) {
_LOGI (LOGD_DEVICE | hw_log_domain, "%s MAC address to %s",
detail, mac_str);
} else {
@@ -7032,17 +7026,13 @@ static gboolean
spec_match_list (NMDevice *self, const GSList *specs)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- char *hwaddr_str;
gboolean matched = FALSE;
if (nm_match_spec_string (specs, "*"))
return TRUE;
- if (priv->hw_addr_len) {
- hwaddr_str = nm_utils_hwaddr_ntoa (priv->hw_addr, priv->hw_addr_len);
- matched = nm_match_spec_hwaddr (specs, hwaddr_str);
- g_free (hwaddr_str);
- }
+ if (priv->hw_addr_len)
+ matched = nm_match_spec_hwaddr (specs, priv->hw_addr);
if (!matched)
matched = nm_match_spec_interface_name (specs, nm_device_get_iface (self));
@@ -7277,6 +7267,7 @@ finalize (GObject *object)
_LOGD (LOGD_DEVICE, "finalize(): %s", G_OBJECT_TYPE_NAME (self));
+ g_free (priv->hw_addr);
g_slist_free_full (priv->pending_actions, g_free);
g_clear_pointer (&priv->physical_port_id, g_free);
g_free (priv->udi);
@@ -7390,14 +7381,20 @@ set_property (GObject *object, guint prop_id,
count++;
}
if (count < ETH_ALEN || count > NM_UTILS_HWADDR_LEN_MAX) {
- g_warn_if_fail (!hw_addr || *hw_addr == '\0');
+ if (hw_addr && *hw_addr) {
+ _LOGW (LOGD_DEVICE, "ignoring hardware address '%s' with unexpected length %d",
+ hw_addr, count);
+ }
break;
}
priv->hw_addr_len = count;
- if (!nm_utils_hwaddr_aton (hw_addr, priv->hw_addr, priv->hw_addr_len)) {
- g_warning ("Could not parse hw-address '%s'", hw_addr);
- memset (priv->hw_addr, 0, sizeof (priv->hw_addr));
+ g_free (priv->hw_addr);
+ if (nm_utils_hwaddr_valid (hw_addr, priv->hw_addr_len))
+ priv->hw_addr = g_strdup (hw_addr);
+ else {
+ _LOGW (LOGD_DEVICE, "could not parse hw-address '%s'", hw_addr);
+ priv->hw_addr = NULL;
}
break;
default:
@@ -7527,10 +7524,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_object (value, priv->master);
break;
case PROP_HW_ADDRESS:
- if (priv->hw_addr_len)
- g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, priv->hw_addr_len));
- else
- g_value_set_string (value, NULL);
+ g_value_set_string (value, priv->hw_addr);
break;
case PROP_HAS_PENDING_ACTION:
g_value_set_boolean (value, nm_device_has_pending_action (self));
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 47519f5fa1..17f68efdf5 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -235,7 +235,7 @@ NMDeviceType nm_device_get_device_type (NMDevice *dev);
int nm_device_get_priority (NMDevice *dev);
-const guint8 * nm_device_get_hw_address (NMDevice *dev, guint *out_len);
+const char * nm_device_get_hw_address (NMDevice *dev);
NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *dev);
NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *dev);
diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c
index 70428aef88..14e9d95490 100644
--- a/src/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/devices/wifi/nm-device-olpc-mesh.c
@@ -341,15 +341,14 @@ static gboolean
check_companion (NMDeviceOlpcMesh *self, NMDevice *other)
{
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
- const guint8 *my_addr, *their_addr;
- guint their_addr_len;
+ const char *my_addr, *their_addr;
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 (!nm_utils_hwaddr_equal (my_addr, ETH_ALEN, their_addr, their_addr_len))
+ my_addr = nm_device_get_hw_address (NM_DEVICE (self));
+ their_addr = nm_device_get_hw_address (other);
+ if (!nm_utils_hwaddr_equal (my_addr, -1, their_addr, -1))
return FALSE;
g_assert (priv->companion == NULL);
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index ed78c5c762..314813f49a 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -114,7 +114,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
struct _NMDeviceWifiPrivate {
gboolean disposed;
- guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */
+ char * perm_hw_addr; /* Permanent MAC address */
guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */
gint8 invalid_strength_counter;
@@ -839,7 +839,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
mac = nm_setting_wireless_get_mac_address (s_wireless);
- if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len, priv->perm_hw_addr, ETH_ALEN))
+ if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len, priv->perm_hw_addr, -1))
return FALSE;
/* Check for MAC address blacklist */
@@ -853,7 +853,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
}
- if (nm_utils_hwaddr_equal (addr, ETH_ALEN, priv->perm_hw_addr, ETH_ALEN))
+ if (nm_utils_hwaddr_equal (addr, ETH_ALEN, priv->perm_hw_addr, -1))
return FALSE;
}
@@ -1131,7 +1131,7 @@ complete_connection (NMDevice *device,
setting_mac = nm_setting_wireless_get_mac_address (s_wifi);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
- if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, priv->perm_hw_addr, ETH_ALEN)) {
+ if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, priv->perm_hw_addr, -1)) {
g_set_error (error,
NM_SETTING_WIRELESS_ERROR,
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
@@ -1140,14 +1140,15 @@ complete_connection (NMDevice *device,
}
} else {
GByteArray *mac;
+ guint8 perm_hw_addr[ETH_ALEN];
/* Lock the connection to this device by default if it uses a
* permanent MAC address (ie not a 'locally administered' one)
*/
- if ( !(priv->perm_hw_addr[0] & 0x02)
- && !nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
- mac = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (mac, priv->perm_hw_addr, ETH_ALEN);
+ nm_utils_hwaddr_aton (priv->perm_hw_addr, perm_hw_addr, ETH_ALEN);
+ if ( !(perm_hw_addr[0] & 0x02)
+ && !nm_utils_hwaddr_equal (perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
+ mac = nm_utils_hwaddr_atoba (priv->perm_hw_addr, ETH_ALEN);
g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MAC_ADDRESS, mac, NULL);
g_byte_array_free (mac, TRUE);
}
@@ -2561,6 +2562,8 @@ update_permanent_hw_address (NMDevice *dev)
struct ethtool_perm_addr *epaddr = NULL;
int fd, ret;
+ g_return_if_fail (priv->perm_hw_addr == NULL);
+
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
nm_log_err (LOGD_HW, "could not open control socket.");
@@ -2582,13 +2585,10 @@ 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, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ nm_utils_hwaddr_aton (nm_device_get_hw_address (dev), epaddr->data, ETH_ALEN);
}
- if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, epaddr->data, ETH_ALEN)) {
- memcpy (priv->perm_hw_addr, epaddr->data, ETH_ALEN);
- g_object_notify (G_OBJECT (dev), NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
- }
+ priv->perm_hw_addr = nm_utils_hwaddr_ntoa (epaddr->data, ETH_ALEN);
g_free (epaddr);
close (fd);
@@ -2599,17 +2599,16 @@ update_initial_hw_address (NMDevice *dev)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
- char *mac_str;
+ const 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.
*/
- memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ mac_str = nm_device_get_hw_address (dev);
+ nm_utils_hwaddr_aton (mac_str, priv->initial_hw_addr, ETH_ALEN);
- mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN);
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 NMActStageReturn
@@ -2703,8 +2702,12 @@ 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, nm_device_get_hw_address (dev, NULL));
+ else if (nm_ap_is_hotspot (ap)) {
+ guint8 addr[ETH_ALEN];
+
+ nm_utils_hwaddr_aton (nm_device_get_hw_address (dev), addr, ETH_ALEN);
+ nm_ap_set_address (ap, addr);
+ }
priv->ap_list = g_slist_prepend (priv->ap_list, ap);
nm_ap_export_to_dbus (ap);
@@ -3309,6 +3312,17 @@ dispose (GObject *object)
}
static void
+finalize (GObject *object)
+{
+ NMDeviceWifi *self = NM_DEVICE_WIFI (object);
+ NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
+
+ g_free (priv->perm_hw_addr);
+
+ G_OBJECT_CLASS (nm_device_wifi_parent_class)->finalize (object);
+}
+
+static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
@@ -3319,7 +3333,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PERM_HW_ADDRESS:
- g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->perm_hw_addr, ETH_ALEN));
+ g_value_set_string (value, priv->perm_hw_addr);
break;
case PROP_MODE:
g_value_set_uint (value, priv->mode);
@@ -3375,6 +3389,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;
+ object_class->finalize = finalize;
parent_class->bring_up = bring_up;
parent_class->update_permanent_hw_address = update_permanent_hw_address;
diff --git a/src/devices/wimax/nm-device-wimax.c b/src/devices/wimax/nm-device-wimax.c
index 69f8b8bcc3..3a101a8e31 100644
--- a/src/devices/wimax/nm-device-wimax.c
+++ b/src/devices/wimax/nm-device-wimax.c
@@ -332,7 +332,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
mac = nm_setting_wimax_get_mac_address (s_wimax);
- if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len, nm_device_get_hw_address (device, NULL), ETH_ALEN))
+ if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len, nm_device_get_hw_address (device), -1))
return FALSE;
return TRUE;
@@ -372,7 +372,7 @@ complete_connection (NMDevice *device,
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
NMSettingWimax *s_wimax;
const GByteArray *setting_mac;
- const guint8 *hw_address;
+ const char *hw_address;
char *format;
const char *nsp_name = NULL;
NMWimaxNsp *nsp = NULL;
@@ -449,10 +449,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);
+ hw_address = nm_device_get_hw_address (device);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
- if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, hw_address, ETH_ALEN)) {
+ if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, hw_address, -1)) {
g_set_error (error,
NM_SETTING_WIMAX_ERROR,
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY,
@@ -463,9 +463,8 @@ complete_connection (NMDevice *device,
GByteArray *mac;
/* Lock the connection to this device by default */
- if (!nm_utils_hwaddr_equal (hw_address, ETH_ALEN, NULL, ETH_ALEN)) {
- mac = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (mac, hw_address, ETH_ALEN);
+ if (!nm_utils_hwaddr_equal (hw_address, -1, NULL, ETH_ALEN)) {
+ mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, mac, NULL);
g_byte_array_free (mac, TRUE);
}
diff --git a/src/nm-config.c b/src/nm-config.c
index cabb10ea32..8fc78602bc 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -260,9 +260,7 @@ void
nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
{
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
- const guint8 *hwaddr;
- guint hwaddr_len;
- char *current, *hwaddr_str;
+ char *current;
GString *updated;
GError *error = NULL;
@@ -277,10 +275,7 @@ nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
g_string_append_c (updated, '\n');
}
- hwaddr = nm_device_get_hw_address (device, &hwaddr_len);
- hwaddr_str = nm_utils_hwaddr_ntoa (hwaddr, hwaddr_len);
- g_string_append (updated, hwaddr_str);
- g_free (hwaddr_str);
+ g_string_append (updated, nm_device_get_hw_address (device));
g_string_append_c (updated, '\n');
if (!g_file_set_contents (priv->no_auto_default_file, updated->str, updated->len, &error)) {
diff --git a/src/nm-manager.c b/src/nm-manager.c
index df46561260..f8d48e5824 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -845,8 +845,7 @@ static NMDevice *
get_device_from_hwaddr (NMManager *self, const GByteArray *setting_mac)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- const guint8 *device_mac;
- guint device_mac_len;
+ const char *device_mac;
GSList *iter;
if (!setting_mac)
@@ -855,8 +854,10 @@ get_device_from_hwaddr (NMManager *self, const GByteArray *setting_mac)
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
NMDevice *device = iter->data;
- device_mac = nm_device_get_hw_address (iter->data, &device_mac_len);
- if (nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, device_mac, device_mac_len))
+ device_mac = nm_device_get_hw_address (iter->data);
+ if (!device_mac)
+ continue;
+ if (nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, device_mac, -1))
return device;
}
return NULL;
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index cbb2af0bf8..3d813430b6 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -1472,12 +1472,11 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
NMSettingConnection *s_con;
NMSettingWired *s_wired;
const GByteArray *setting_mac;
- const guint8 *hwaddr;
- guint hwaddr_len = 0;
+ const char *hwaddr;
g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE);
- hwaddr = nm_device_get_hw_address (device, &hwaddr_len);
+ hwaddr = nm_device_get_hw_address (device);
/* Find a wired connection locked to the given MAC address, if any */
g_hash_table_iter_init (&iter, priv->connections);
@@ -1506,9 +1505,9 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
g_assert (s_wired != NULL);
setting_mac = nm_setting_wired_get_mac_address (s_wired);
- if (setting_mac) {
+ if (setting_mac && hwaddr) {
/* A connection mac-locked to this device */
- if (nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, hwaddr, hwaddr_len))
+ if (nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, hwaddr, -1))
return TRUE;
} else {
/* A connection that applies to any wired device */
@@ -1590,9 +1589,8 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
NMSettingsConnection *added;
NMSetting *setting;
GError *error = NULL;
- const guint8 *hw_address;
+ const char *hw_address;
char *defname, *uuid;
- guint len = 0;
GByteArray *mac;
if (!NM_IS_DEVICE_ETHERNET (device))
@@ -1607,7 +1605,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
|| !nm_config_get_ethernet_can_auto_default (priv->config, device))
return;
- hw_address = nm_device_get_hw_address (device, &len);
+ hw_address = nm_device_get_hw_address (device);
if (!hw_address)
return;
@@ -1633,8 +1631,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
setting = nm_setting_wired_new ();
nm_connection_add_setting (connection, setting);
- mac = g_byte_array_sized_new (len);
- g_byte_array_append (mac, hw_address, len);
+ mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
g_byte_array_unref (mac);