mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 07:08:02 +02:00
core: update data types of some hwaddr properties
Now that we have nm_utils_hwaddr_matches() for comparing addresses (even when one is a string and the other binary), there are now places where it's more convenient to store hardware addresses as strings rather than binary, since we want them in string form for most non-comparison purposes. So update for that. In particular, this also changes nm_device_get_hw_address() to return a string. Also, simplify the update_permanent_hw_address() implementations by assuming that they will only be called once. (Since they will.)
This commit is contained in:
parent
44b9a8708b
commit
b019348fdd
13 changed files with 139 additions and 152 deletions
|
|
@ -63,7 +63,7 @@ typedef struct {
|
||||||
|
|
||||||
NMBluezDevice *bt_device;
|
NMBluezDevice *bt_device;
|
||||||
|
|
||||||
guint8 bdaddr[ETH_ALEN];
|
char *bdaddr;
|
||||||
char *name;
|
char *name;
|
||||||
guint32 capabilities;
|
guint32 capabilities;
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
array = nm_setting_bluetooth_get_bdaddr (s_bt);
|
array = nm_setting_bluetooth_get_bdaddr (s_bt);
|
||||||
if (!array)
|
if (!array)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!nm_utils_hwaddr_matches (priv->bdaddr, ETH_ALEN, array->data, array->len))
|
if (!nm_utils_hwaddr_matches (priv->bdaddr, -1, array->data, array->len))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
@ -323,7 +323,7 @@ complete_connection (NMDevice *device,
|
||||||
setting_bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt);
|
setting_bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt);
|
||||||
if (setting_bdaddr) {
|
if (setting_bdaddr) {
|
||||||
/* Make sure the setting BT Address (if any) matches the device's */
|
/* Make sure the setting BT Address (if any) matches the device's */
|
||||||
if (!nm_utils_hwaddr_matches (setting_bdaddr->data, setting_bdaddr->len, priv->bdaddr, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (setting_bdaddr->data, setting_bdaddr->len, priv->bdaddr, -1)) {
|
||||||
g_set_error_literal (error,
|
g_set_error_literal (error,
|
||||||
NM_SETTING_BLUETOOTH_ERROR,
|
NM_SETTING_BLUETOOTH_ERROR,
|
||||||
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
|
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
|
||||||
|
|
@ -334,9 +334,8 @@ complete_connection (NMDevice *device,
|
||||||
GByteArray *bdaddr;
|
GByteArray *bdaddr;
|
||||||
|
|
||||||
/* Lock the connection to this device by default */
|
/* Lock the connection to this device by default */
|
||||||
if (!nm_utils_hwaddr_matches (priv->bdaddr, ETH_ALEN, NULL, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (priv->bdaddr, -1, NULL, ETH_ALEN)) {
|
||||||
bdaddr = g_byte_array_sized_new (ETH_ALEN);
|
bdaddr = nm_utils_hwaddr_atoba (priv->bdaddr, ETH_ALEN);
|
||||||
g_byte_array_append (bdaddr, priv->bdaddr, ETH_ALEN);
|
|
||||||
g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, bdaddr, NULL);
|
g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, bdaddr, NULL);
|
||||||
g_byte_array_free (bdaddr, TRUE);
|
g_byte_array_free (bdaddr, TRUE);
|
||||||
}
|
}
|
||||||
|
|
@ -1069,15 +1068,13 @@ static void
|
||||||
constructed (GObject *object)
|
constructed (GObject *object)
|
||||||
{
|
{
|
||||||
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
|
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
|
||||||
const guint8 *my_hwaddr;
|
const char *my_hwaddr;
|
||||||
guint my_hwaddr_len = 0;
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (nm_device_bt_parent_class)->constructed (object);
|
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 (my_hwaddr);
|
||||||
g_assert_cmpint (my_hwaddr_len, ==, ETH_ALEN);
|
priv->bdaddr = g_strdup (my_hwaddr);
|
||||||
memcpy (priv->bdaddr, my_hwaddr, ETH_ALEN);
|
|
||||||
|
|
||||||
/* Watch for BT device property changes */
|
/* Watch for BT device property changes */
|
||||||
g_signal_connect (priv->bt_device, "notify::" NM_BLUEZ_DEVICE_CONNECTED,
|
g_signal_connect (priv->bt_device, "notify::" NM_BLUEZ_DEVICE_CONNECTED,
|
||||||
|
|
@ -1164,6 +1161,7 @@ finalize (GObject *object)
|
||||||
|
|
||||||
g_free (priv->rfcomm_iface);
|
g_free (priv->rfcomm_iface);
|
||||||
g_free (priv->name);
|
g_free (priv->name);
|
||||||
|
g_free (priv->bdaddr);
|
||||||
|
|
||||||
G_OBJECT_CLASS (nm_device_bt_parent_class)->finalize (object);
|
G_OBJECT_CLASS (nm_device_bt_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,11 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
|
|
||||||
mac_address = nm_setting_bridge_get_mac_address (s_bridge);
|
mac_address = nm_setting_bridge_get_mac_address (s_bridge);
|
||||||
if (mac_address) {
|
if (mac_address) {
|
||||||
guint hw_len;
|
const char *hw_addr;
|
||||||
const guint8 *hw_addr;
|
|
||||||
|
|
||||||
hw_addr = nm_device_get_hw_address (device, &hw_len);
|
hw_addr = nm_device_get_hw_address (device);
|
||||||
if ( !hw_addr
|
if ( !hw_addr
|
||||||
|| !nm_utils_hwaddr_matches (mac_address->data, mac_address->len, hw_addr, hw_len))
|
|| !nm_utils_hwaddr_matches (hw_addr, -1, mac_address->data, mac_address->len))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ typedef enum {
|
||||||
} DcbWait;
|
} DcbWait;
|
||||||
|
|
||||||
typedef struct {
|
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) */
|
guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */
|
||||||
|
|
||||||
guint32 speed;
|
guint32 speed;
|
||||||
|
|
@ -339,7 +339,9 @@ update_permanent_hw_address (NMDevice *dev)
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
struct ethtool_perm_addr *epaddr = NULL;
|
struct ethtool_perm_addr *epaddr = NULL;
|
||||||
int fd, ret, errsv;
|
int fd, ret, errsv;
|
||||||
const guint8 *mac;
|
const char *mac;
|
||||||
|
|
||||||
|
g_return_if_fail (priv->perm_hw_addr == NULL);
|
||||||
|
|
||||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
|
@ -362,17 +364,14 @@ update_permanent_hw_address (NMDevice *dev)
|
||||||
if ((ret < 0) || !nm_ethernet_address_is_valid (epaddr->data)) {
|
if ((ret < 0) || !nm_ethernet_address_is_valid (epaddr->data)) {
|
||||||
_LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address (error %d)", errsv);
|
_LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address (error %d)", errsv);
|
||||||
/* Fall back to current address */
|
/* Fall back to current address */
|
||||||
mac = nm_device_get_hw_address (dev, NULL);
|
mac = nm_device_get_hw_address (dev);
|
||||||
if (mac)
|
if (mac)
|
||||||
memcpy (epaddr->data, mac, ETH_ALEN);
|
nm_utils_hwaddr_aton (mac, epaddr->data, ETH_ALEN);
|
||||||
else
|
else
|
||||||
memset (epaddr->data, 0, ETH_ALEN);
|
memset (epaddr->data, 0, ETH_ALEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_utils_hwaddr_matches (priv->perm_hw_addr, ETH_ALEN, epaddr->data, ETH_ALEN)) {
|
priv->perm_hw_addr = nm_utils_hwaddr_ntoa (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);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (epaddr);
|
g_free (epaddr);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
@ -383,18 +382,16 @@ update_initial_hw_address (NMDevice *dev)
|
||||||
{
|
{
|
||||||
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
|
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
|
||||||
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
||||||
gs_free char *tmp_str = NULL;
|
const char *mac;
|
||||||
const guint8 *mac;
|
|
||||||
|
|
||||||
/* This sets initial MAC address from current MAC address. It should only
|
/* This sets initial MAC address from current MAC address. It should only
|
||||||
* be called from NMDevice constructor() to really get the initial address.
|
* 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)
|
if (mac)
|
||||||
memcpy (priv->initial_hw_addr, mac, ETH_ALEN);
|
nm_utils_hwaddr_aton (mac, priv->initial_hw_addr, ETH_ALEN);
|
||||||
|
|
||||||
_LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s",
|
_LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s", mac);
|
||||||
(tmp_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint32
|
static guint32
|
||||||
|
|
@ -473,7 +470,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
mac = nm_setting_wired_get_mac_address (s_wired);
|
mac = nm_setting_wired_get_mac_address (s_wired);
|
||||||
if (try_mac && mac && !nm_utils_hwaddr_matches (mac->data, mac->len, priv->perm_hw_addr, ETH_ALEN))
|
if (try_mac && mac && !nm_utils_hwaddr_matches (mac->data, mac->len, priv->perm_hw_addr, -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Check for MAC address blacklist */
|
/* Check for MAC address blacklist */
|
||||||
|
|
@ -487,7 +484,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nm_utils_hwaddr_matches (addr, ETH_ALEN, priv->perm_hw_addr, ETH_ALEN))
|
if (nm_utils_hwaddr_matches (addr, ETH_ALEN, priv->perm_hw_addr, -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1462,7 +1459,7 @@ complete_connection (NMDevice *device,
|
||||||
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||||
if (setting_mac) {
|
if (setting_mac) {
|
||||||
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
|
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
|
||||||
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, priv->perm_hw_addr, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, priv->perm_hw_addr, -1)) {
|
||||||
g_set_error_literal (error,
|
g_set_error_literal (error,
|
||||||
NM_SETTING_WIRED_ERROR,
|
NM_SETTING_WIRED_ERROR,
|
||||||
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
|
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,
|
||||||
|
|
@ -1473,9 +1470,8 @@ complete_connection (NMDevice *device,
|
||||||
GByteArray *mac;
|
GByteArray *mac;
|
||||||
|
|
||||||
/* Lock the connection to this device by default */
|
/* Lock the connection to this device by default */
|
||||||
if (!nm_utils_hwaddr_matches (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (priv->perm_hw_addr, -1, NULL, ETH_ALEN)) {
|
||||||
mac = g_byte_array_sized_new (ETH_ALEN);
|
mac = nm_utils_hwaddr_atoba (priv->perm_hw_addr, ETH_ALEN);
|
||||||
g_byte_array_append (mac, priv->perm_hw_addr, ETH_ALEN);
|
|
||||||
g_object_set (G_OBJECT (s_wired), NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
g_object_set (G_OBJECT (s_wired), NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
||||||
g_byte_array_free (mac, TRUE);
|
g_byte_array_free (mac, TRUE);
|
||||||
}
|
}
|
||||||
|
|
@ -1500,8 +1496,7 @@ update_connection (NMDevice *device, NMConnection *connection)
|
||||||
{
|
{
|
||||||
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
|
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
|
||||||
NMSettingWired *s_wired = nm_connection_get_setting_wired (connection);
|
NMSettingWired *s_wired = nm_connection_get_setting_wired (connection);
|
||||||
guint maclen;
|
const char *mac = nm_device_get_hw_address (device);
|
||||||
const guint8 *mac = nm_device_get_hw_address (device, &maclen);
|
|
||||||
const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS;
|
const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS;
|
||||||
GByteArray *array;
|
GByteArray *array;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
|
|
@ -1515,20 +1510,18 @@ update_connection (NMDevice *device, NMConnection *connection)
|
||||||
/* If the device reports a permanent address, use that for the MAC address
|
/* If the device reports a permanent address, use that for the MAC address
|
||||||
* and the current MAC, if different, is the cloned MAC.
|
* and the current MAC, if different, is the cloned MAC.
|
||||||
*/
|
*/
|
||||||
if (!nm_utils_hwaddr_matches (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (priv->perm_hw_addr, -1, NULL, ETH_ALEN)) {
|
||||||
array = g_byte_array_sized_new (ETH_ALEN);
|
array = nm_utils_hwaddr_atoba (priv->perm_hw_addr, ETH_ALEN);
|
||||||
g_byte_array_append (array, priv->perm_hw_addr, ETH_ALEN);
|
|
||||||
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, array, NULL);
|
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, array, NULL);
|
||||||
g_byte_array_unref (array);
|
g_byte_array_unref (array);
|
||||||
|
|
||||||
mac_prop = NULL;
|
mac_prop = NULL;
|
||||||
if (mac && !nm_utils_hwaddr_matches (priv->perm_hw_addr, ETH_ALEN, mac, ETH_ALEN))
|
if (mac && !nm_utils_hwaddr_matches (priv->perm_hw_addr, -1, mac, -1))
|
||||||
mac_prop = NM_SETTING_WIRED_CLONED_MAC_ADDRESS;
|
mac_prop = NM_SETTING_WIRED_CLONED_MAC_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mac_prop && mac && maclen == ETH_ALEN) {
|
if (mac_prop && mac && nm_utils_hwaddr_valid (mac, ETH_ALEN)) {
|
||||||
array = g_byte_array_sized_new (ETH_ALEN);
|
array = nm_utils_hwaddr_atoba (mac, ETH_ALEN);
|
||||||
g_byte_array_append (array, (guint8 *) mac, maclen);
|
|
||||||
g_object_set (s_wired, mac_prop, array, NULL);
|
g_object_set (s_wired, mac_prop, array, NULL);
|
||||||
g_byte_array_unref (array);
|
g_byte_array_unref (array);
|
||||||
}
|
}
|
||||||
|
|
@ -1633,6 +1626,7 @@ finalize (GObject *object)
|
||||||
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (object);
|
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (object);
|
||||||
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
g_free (priv->perm_hw_addr);
|
||||||
g_clear_object (&priv->supplicant.mgr);
|
g_clear_object (&priv->supplicant.mgr);
|
||||||
g_free (priv->subchan1);
|
g_free (priv->subchan1);
|
||||||
g_free (priv->subchan2);
|
g_free (priv->subchan2);
|
||||||
|
|
@ -1653,7 +1647,7 @@ get_property (GObject *object, guint prop_id,
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_PERM_HW_ADDRESS:
|
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;
|
break;
|
||||||
case PROP_SPEED:
|
case PROP_SPEED:
|
||||||
g_value_set_uint (value, priv->speed);
|
g_value_set_uint (value, priv->speed);
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
if (s_infiniband) {
|
if (s_infiniband) {
|
||||||
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
||||||
if (mac && !nm_utils_hwaddr_matches (mac->data, mac->len,
|
if (mac && !nm_utils_hwaddr_matches (mac->data, mac->len,
|
||||||
nm_device_get_hw_address (device, NULL), INFINIBAND_ALEN))
|
nm_device_get_hw_address (device), -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,7 +225,7 @@ complete_connection (NMDevice *device,
|
||||||
{
|
{
|
||||||
NMSettingInfiniband *s_infiniband;
|
NMSettingInfiniband *s_infiniband;
|
||||||
const GByteArray *setting_mac;
|
const GByteArray *setting_mac;
|
||||||
const guint8 *hw_address;
|
const char *hw_address;
|
||||||
|
|
||||||
nm_utils_complete_generic (connection,
|
nm_utils_complete_generic (connection,
|
||||||
NM_SETTING_INFINIBAND_SETTING_NAME,
|
NM_SETTING_INFINIBAND_SETTING_NAME,
|
||||||
|
|
@ -241,7 +241,7 @@ complete_connection (NMDevice *device,
|
||||||
}
|
}
|
||||||
|
|
||||||
setting_mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
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) {
|
if (setting_mac) {
|
||||||
/* Make sure the setting MAC (if any) matches the device's MAC */
|
/* Make sure the setting MAC (if any) matches the device's MAC */
|
||||||
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, hw_address, INFINIBAND_ALEN)) {
|
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, hw_address, INFINIBAND_ALEN)) {
|
||||||
|
|
@ -255,8 +255,7 @@ complete_connection (NMDevice *device,
|
||||||
GByteArray *mac;
|
GByteArray *mac;
|
||||||
|
|
||||||
/* Lock the connection to this device by default */
|
/* Lock the connection to this device by default */
|
||||||
mac = g_byte_array_sized_new (INFINIBAND_ALEN);
|
mac = nm_utils_hwaddr_atoba (hw_address, 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_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
|
||||||
g_byte_array_free (mac, TRUE);
|
g_byte_array_free (mac, TRUE);
|
||||||
}
|
}
|
||||||
|
|
@ -271,8 +270,7 @@ static void
|
||||||
update_connection (NMDevice *device, NMConnection *connection)
|
update_connection (NMDevice *device, NMConnection *connection)
|
||||||
{
|
{
|
||||||
NMSettingInfiniband *s_infiniband = nm_connection_get_setting_infiniband (connection);
|
NMSettingInfiniband *s_infiniband = nm_connection_get_setting_infiniband (connection);
|
||||||
guint maclen;
|
const char *mac = nm_device_get_hw_address (device);
|
||||||
gconstpointer mac = nm_device_get_hw_address (device, &maclen);
|
|
||||||
GByteArray *array;
|
GByteArray *array;
|
||||||
char *mode_path, *contents = NULL;
|
char *mode_path, *contents = NULL;
|
||||||
const char *transport_mode = "datagram";
|
const char *transport_mode = "datagram";
|
||||||
|
|
@ -282,9 +280,8 @@ update_connection (NMDevice *device, NMConnection *connection)
|
||||||
nm_connection_add_setting (connection, (NMSetting *) s_infiniband);
|
nm_connection_add_setting (connection, (NMSetting *) s_infiniband);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mac && !nm_utils_hwaddr_matches (mac, maclen, NULL, INFINIBAND_ALEN)) {
|
if (mac && !nm_utils_hwaddr_matches (mac, -1, NULL, INFINIBAND_ALEN)) {
|
||||||
array = g_byte_array_sized_new (maclen);
|
array = nm_utils_hwaddr_atoba (mac, INFINIBAND_ALEN);
|
||||||
g_byte_array_append (array, (guint8 *) mac, maclen);
|
|
||||||
g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, array, NULL);
|
g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, array, NULL);
|
||||||
g_byte_array_unref (array);
|
g_byte_array_unref (array);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,12 @@ update_initial_hw_address (NMDevice *dev)
|
||||||
{
|
{
|
||||||
NMDeviceVlan *self = NM_DEVICE_VLAN (dev);
|
NMDeviceVlan *self = NM_DEVICE_VLAN (dev);
|
||||||
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
||||||
gs_free char *mac_str = NULL;
|
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);
|
||||||
|
|
||||||
_LOGD (LOGD_DEVICE | LOGD_VLAN, "read initial MAC address %s",
|
_LOGD (LOGD_DEVICE | LOGD_VLAN, "read initial MAC address %s", mac_str);
|
||||||
(mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint32
|
static guint32
|
||||||
|
|
@ -158,8 +158,7 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw
|
||||||
{
|
{
|
||||||
NMSettingWired *s_wired;
|
NMSettingWired *s_wired;
|
||||||
const GByteArray *mac;
|
const GByteArray *mac;
|
||||||
const guint8 *device_mac;
|
const char *device_mac;
|
||||||
guint device_mac_len;
|
|
||||||
|
|
||||||
s_wired = nm_connection_get_setting_wired (connection);
|
s_wired = nm_connection_get_setting_wired (connection);
|
||||||
if (!s_wired)
|
if (!s_wired)
|
||||||
|
|
@ -169,9 +168,9 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw
|
||||||
if (!mac)
|
if (!mac)
|
||||||
return !fail_if_no_hwaddr;
|
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_matches (mac->data, mac->len, device_mac, device_mac_len);
|
return nm_utils_hwaddr_matches (mac->data, mac->len, device_mac, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ typedef struct {
|
||||||
RfKillType rfkill_type;
|
RfKillType rfkill_type;
|
||||||
gboolean firmware_missing;
|
gboolean firmware_missing;
|
||||||
GHashTable * available_connections;
|
GHashTable * available_connections;
|
||||||
guint8 hw_addr[NM_UTILS_HWADDR_LEN_MAX];
|
char * hw_addr;
|
||||||
guint hw_addr_len;
|
guint hw_addr_len;
|
||||||
char * physical_port_id;
|
char * physical_port_id;
|
||||||
|
|
||||||
|
|
@ -6892,17 +6892,14 @@ nm_device_get_state (NMDevice *self)
|
||||||
/***********************************************************/
|
/***********************************************************/
|
||||||
/* NMConfigDevice interface related stuff */
|
/* NMConfigDevice interface related stuff */
|
||||||
|
|
||||||
const guint8 *
|
const char *
|
||||||
nm_device_get_hw_address (NMDevice *self, guint *out_len)
|
nm_device_get_hw_address (NMDevice *self)
|
||||||
{
|
{
|
||||||
NMDevicePrivate *priv;
|
NMDevicePrivate *priv;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
|
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
|
||||||
priv = NM_DEVICE_GET_PRIVATE (self);
|
priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
|
|
||||||
if (out_len)
|
|
||||||
*out_len = priv->hw_addr_len;
|
|
||||||
|
|
||||||
return priv->hw_addr_len ? priv->hw_addr : NULL;
|
return priv->hw_addr_len ? priv->hw_addr : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6920,19 +6917,16 @@ nm_device_update_hw_address (NMDevice *self)
|
||||||
hwaddr = nm_platform_link_get_address (ifindex, &hwaddrlen);
|
hwaddr = nm_platform_link_get_address (ifindex, &hwaddrlen);
|
||||||
g_assert (hwaddrlen <= sizeof (priv->hw_addr));
|
g_assert (hwaddrlen <= sizeof (priv->hw_addr));
|
||||||
if (hwaddrlen) {
|
if (hwaddrlen) {
|
||||||
if (hwaddrlen != priv->hw_addr_len || memcmp (priv->hw_addr, hwaddr, hwaddrlen)) {
|
if (!nm_utils_hwaddr_matches (priv->hw_addr, -1, hwaddr, hwaddrlen)) {
|
||||||
gs_free char *tmp_str = NULL;
|
priv->hw_addr = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen);
|
||||||
|
|
||||||
memcpy (priv->hw_addr, hwaddr, hwaddrlen);
|
_LOGD (LOGD_HW | LOGD_DEVICE, "hardware address now %s", priv->hw_addr);
|
||||||
|
|
||||||
_LOGD (LOGD_HW | LOGD_DEVICE, "hardware address now %s",
|
|
||||||
(tmp_str = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen)));
|
|
||||||
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
|
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Invalid or no hardware address */
|
/* Invalid or no hardware address */
|
||||||
if (priv->hw_addr_len != 0) {
|
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,
|
_LOGD (LOGD_HW | LOGD_DEVICE,
|
||||||
"previous hardware address is no longer valid");
|
"previous hardware address is no longer valid");
|
||||||
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
|
g_object_notify (G_OBJECT (self), NM_DEVICE_HW_ADDRESS);
|
||||||
|
|
@ -6945,30 +6939,30 @@ gboolean
|
||||||
nm_device_set_hw_addr (NMDevice *self, const guint8 *addr,
|
nm_device_set_hw_addr (NMDevice *self, const guint8 *addr,
|
||||||
const char *detail, guint64 hw_log_domain)
|
const char *detail, guint64 hw_log_domain)
|
||||||
{
|
{
|
||||||
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
char *mac_str = NULL;
|
char *mac_str = NULL;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
guint len;
|
const char *cur_addr = nm_device_get_hw_address (self);
|
||||||
const guint8 *cur_addr = nm_device_get_hw_address (self, &len);
|
|
||||||
|
|
||||||
g_return_val_if_fail (addr != NULL, FALSE);
|
g_return_val_if_fail (addr != NULL, FALSE);
|
||||||
|
|
||||||
/* Do nothing if current MAC is same */
|
/* Do nothing if current MAC is same */
|
||||||
if (cur_addr && nm_utils_hwaddr_matches (cur_addr, len, addr, len)) {
|
if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, priv->hw_addr_len)) {
|
||||||
_LOGD (LOGD_DEVICE | hw_log_domain, "no MAC address change needed");
|
_LOGD (LOGD_DEVICE | hw_log_domain, "no MAC address change needed");
|
||||||
return TRUE;
|
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 */
|
/* Can't change MAC address while device is up */
|
||||||
nm_device_take_down (self, FALSE);
|
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) {
|
if (success) {
|
||||||
/* MAC address succesfully changed; update the current MAC to match */
|
/* MAC address succesfully changed; update the current MAC to match */
|
||||||
nm_device_update_hw_address (self);
|
nm_device_update_hw_address (self);
|
||||||
cur_addr = nm_device_get_hw_address (self, NULL);
|
cur_addr = nm_device_get_hw_address (self);
|
||||||
if (nm_utils_hwaddr_matches (cur_addr, len, addr, len)) {
|
if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, priv->hw_addr_len)) {
|
||||||
_LOGI (LOGD_DEVICE | hw_log_domain, "%s MAC address to %s",
|
_LOGI (LOGD_DEVICE | hw_log_domain, "%s MAC address to %s",
|
||||||
detail, mac_str);
|
detail, mac_str);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -7022,17 +7016,13 @@ static gboolean
|
||||||
spec_match_list (NMDevice *self, const GSList *specs)
|
spec_match_list (NMDevice *self, const GSList *specs)
|
||||||
{
|
{
|
||||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
char *hwaddr_str;
|
|
||||||
gboolean matched = FALSE;
|
gboolean matched = FALSE;
|
||||||
|
|
||||||
if (nm_match_spec_string (specs, "*"))
|
if (nm_match_spec_string (specs, "*"))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (priv->hw_addr_len) {
|
if (priv->hw_addr_len)
|
||||||
hwaddr_str = nm_utils_hwaddr_ntoa (priv->hw_addr, priv->hw_addr_len);
|
matched = nm_match_spec_hwaddr (specs, priv->hw_addr);
|
||||||
matched = nm_match_spec_hwaddr (specs, hwaddr_str);
|
|
||||||
g_free (hwaddr_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!matched)
|
if (!matched)
|
||||||
matched = nm_match_spec_interface_name (specs, nm_device_get_iface (self));
|
matched = nm_match_spec_interface_name (specs, nm_device_get_iface (self));
|
||||||
|
|
@ -7267,6 +7257,7 @@ finalize (GObject *object)
|
||||||
|
|
||||||
_LOGD (LOGD_DEVICE, "finalize(): %s", G_OBJECT_TYPE_NAME (self));
|
_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_slist_free_full (priv->pending_actions, g_free);
|
||||||
g_clear_pointer (&priv->physical_port_id, g_free);
|
g_clear_pointer (&priv->physical_port_id, g_free);
|
||||||
g_free (priv->udi);
|
g_free (priv->udi);
|
||||||
|
|
@ -7380,14 +7371,20 @@ set_property (GObject *object, guint prop_id,
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (count < ETH_ALEN || count > NM_UTILS_HWADDR_LEN_MAX) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->hw_addr_len = count;
|
priv->hw_addr_len = count;
|
||||||
if (!nm_utils_hwaddr_aton (hw_addr, priv->hw_addr, priv->hw_addr_len)) {
|
g_free (priv->hw_addr);
|
||||||
g_warning ("Could not parse hw-address '%s'", hw_addr);
|
if (nm_utils_hwaddr_valid (hw_addr, priv->hw_addr_len))
|
||||||
memset (priv->hw_addr, 0, sizeof (priv->hw_addr));
|
priv->hw_addr = g_strdup (hw_addr);
|
||||||
|
else {
|
||||||
|
_LOGW (LOGD_DEVICE, "could not parse hw-address '%s'", hw_addr);
|
||||||
|
priv->hw_addr = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -7517,10 +7514,7 @@ get_property (GObject *object, guint prop_id,
|
||||||
g_value_set_object (value, priv->master);
|
g_value_set_object (value, priv->master);
|
||||||
break;
|
break;
|
||||||
case PROP_HW_ADDRESS:
|
case PROP_HW_ADDRESS:
|
||||||
if (priv->hw_addr_len)
|
g_value_set_string (value, priv->hw_addr);
|
||||||
g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->hw_addr, priv->hw_addr_len));
|
|
||||||
else
|
|
||||||
g_value_set_string (value, NULL);
|
|
||||||
break;
|
break;
|
||||||
case PROP_HAS_PENDING_ACTION:
|
case PROP_HAS_PENDING_ACTION:
|
||||||
g_value_set_boolean (value, nm_device_has_pending_action (self));
|
g_value_set_boolean (value, nm_device_has_pending_action (self));
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ NMDeviceType nm_device_get_device_type (NMDevice *dev);
|
||||||
|
|
||||||
int nm_device_get_priority (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);
|
NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *dev);
|
||||||
NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *dev);
|
NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *dev);
|
||||||
|
|
|
||||||
|
|
@ -341,15 +341,14 @@ static gboolean
|
||||||
check_companion (NMDeviceOlpcMesh *self, NMDevice *other)
|
check_companion (NMDeviceOlpcMesh *self, NMDevice *other)
|
||||||
{
|
{
|
||||||
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
|
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
|
||||||
const guint8 *my_addr, *their_addr;
|
const char *my_addr, *their_addr;
|
||||||
guint their_addr_len;
|
|
||||||
|
|
||||||
if (!NM_IS_DEVICE_WIFI (other))
|
if (!NM_IS_DEVICE_WIFI (other))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
my_addr = nm_device_get_hw_address (NM_DEVICE (self), NULL);
|
my_addr = nm_device_get_hw_address (NM_DEVICE (self));
|
||||||
their_addr = nm_device_get_hw_address (other, &their_addr_len);
|
their_addr = nm_device_get_hw_address (other);
|
||||||
if (!nm_utils_hwaddr_matches (my_addr, ETH_ALEN, their_addr, their_addr_len))
|
if (!nm_utils_hwaddr_matches (my_addr, -1, their_addr, -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
g_assert (priv->companion == NULL);
|
g_assert (priv->companion == NULL);
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
||||||
struct _NMDeviceWifiPrivate {
|
struct _NMDeviceWifiPrivate {
|
||||||
gboolean disposed;
|
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) */
|
guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */
|
||||||
|
|
||||||
gint8 invalid_strength_counter;
|
gint8 invalid_strength_counter;
|
||||||
|
|
@ -828,7 +828,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
mac = nm_setting_wireless_get_mac_address (s_wireless);
|
mac = nm_setting_wireless_get_mac_address (s_wireless);
|
||||||
if (mac && !nm_utils_hwaddr_matches (mac->data, mac->len, priv->perm_hw_addr, ETH_ALEN))
|
if (mac && !nm_utils_hwaddr_matches (mac->data, mac->len, priv->perm_hw_addr, -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Check for MAC address blacklist */
|
/* Check for MAC address blacklist */
|
||||||
|
|
@ -842,7 +842,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nm_utils_hwaddr_matches (addr, ETH_ALEN, priv->perm_hw_addr, ETH_ALEN))
|
if (nm_utils_hwaddr_matches (addr, ETH_ALEN, priv->perm_hw_addr, -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1120,7 +1120,7 @@ complete_connection (NMDevice *device,
|
||||||
setting_mac = nm_setting_wireless_get_mac_address (s_wifi);
|
setting_mac = nm_setting_wireless_get_mac_address (s_wifi);
|
||||||
if (setting_mac) {
|
if (setting_mac) {
|
||||||
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
|
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
|
||||||
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, priv->perm_hw_addr, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, priv->perm_hw_addr, -1)) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_SETTING_WIRELESS_ERROR,
|
NM_SETTING_WIRELESS_ERROR,
|
||||||
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
|
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
|
||||||
|
|
@ -1129,14 +1129,15 @@ complete_connection (NMDevice *device,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GByteArray *mac;
|
GByteArray *mac;
|
||||||
|
guint8 perm_hw_addr[ETH_ALEN];
|
||||||
|
|
||||||
/* Lock the connection to this device by default if it uses a
|
/* Lock the connection to this device by default if it uses a
|
||||||
* permanent MAC address (ie not a 'locally administered' one)
|
* permanent MAC address (ie not a 'locally administered' one)
|
||||||
*/
|
*/
|
||||||
if ( !(priv->perm_hw_addr[0] & 0x02)
|
nm_utils_hwaddr_aton (priv->perm_hw_addr, perm_hw_addr, ETH_ALEN);
|
||||||
&& !nm_utils_hwaddr_matches (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
|
if ( !(perm_hw_addr[0] & 0x02)
|
||||||
mac = g_byte_array_sized_new (ETH_ALEN);
|
&& !nm_utils_hwaddr_matches (perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
|
||||||
g_byte_array_append (mac, priv->perm_hw_addr, 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_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MAC_ADDRESS, mac, NULL);
|
||||||
g_byte_array_free (mac, TRUE);
|
g_byte_array_free (mac, TRUE);
|
||||||
}
|
}
|
||||||
|
|
@ -2513,6 +2514,8 @@ update_permanent_hw_address (NMDevice *device)
|
||||||
struct ethtool_perm_addr *epaddr = NULL;
|
struct ethtool_perm_addr *epaddr = NULL;
|
||||||
int fd, ret, errsv;
|
int fd, ret, errsv;
|
||||||
|
|
||||||
|
g_return_if_fail (priv->perm_hw_addr == NULL);
|
||||||
|
|
||||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
_LOGE (LOGD_HW, "could not open control socket.");
|
_LOGE (LOGD_HW, "could not open control socket.");
|
||||||
|
|
@ -2535,13 +2538,10 @@ update_permanent_hw_address (NMDevice *device)
|
||||||
_LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address (error %d)",
|
_LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address (error %d)",
|
||||||
errsv);
|
errsv);
|
||||||
/* Fall back to current address */
|
/* Fall back to current address */
|
||||||
memcpy (epaddr->data, nm_device_get_hw_address (device, NULL), ETH_ALEN);
|
nm_utils_hwaddr_aton (nm_device_get_hw_address (device), epaddr->data, ETH_ALEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_utils_hwaddr_matches (priv->perm_hw_addr, ETH_ALEN, epaddr->data, ETH_ALEN)) {
|
priv->perm_hw_addr = nm_utils_hwaddr_ntoa (epaddr->data, ETH_ALEN);
|
||||||
memcpy (priv->perm_hw_addr, epaddr->data, ETH_ALEN);
|
|
||||||
g_object_notify (G_OBJECT (device), NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (epaddr);
|
g_free (epaddr);
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
@ -2552,16 +2552,15 @@ update_initial_hw_address (NMDevice *device)
|
||||||
{
|
{
|
||||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||||
char *mac_str = NULL;
|
const char *mac_str;
|
||||||
|
|
||||||
/* This sets initial MAC address from current MAC address. It should only
|
/* This sets initial MAC address from current MAC address. It should only
|
||||||
* be called from NMDevice constructor() to really get the initial address.
|
* be called from NMDevice constructor() to really get the initial address.
|
||||||
*/
|
*/
|
||||||
memcpy (priv->initial_hw_addr, nm_device_get_hw_address (device, NULL), ETH_ALEN);
|
mac_str = nm_device_get_hw_address (device);
|
||||||
|
nm_utils_hwaddr_aton (mac_str, priv->initial_hw_addr, ETH_ALEN);
|
||||||
|
|
||||||
_LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s",
|
_LOGD (LOGD_DEVICE | LOGD_ETHER, "read initial MAC address %s", mac_str);
|
||||||
(mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN)));
|
|
||||||
g_free (mac_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMActStageReturn
|
static NMActStageReturn
|
||||||
|
|
@ -2655,8 +2654,12 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
|
||||||
|
|
||||||
if (nm_ap_get_mode (ap) == NM_802_11_MODE_INFRA)
|
if (nm_ap_get_mode (ap) == NM_802_11_MODE_INFRA)
|
||||||
nm_ap_set_broadcast (ap, FALSE);
|
nm_ap_set_broadcast (ap, FALSE);
|
||||||
else if (nm_ap_is_hotspot (ap))
|
else if (nm_ap_is_hotspot (ap)) {
|
||||||
nm_ap_set_address (ap, nm_device_get_hw_address (device, NULL));
|
guint8 addr[ETH_ALEN];
|
||||||
|
|
||||||
|
nm_utils_hwaddr_aton (nm_device_get_hw_address (device), addr, ETH_ALEN);
|
||||||
|
nm_ap_set_address (ap, addr);
|
||||||
|
}
|
||||||
|
|
||||||
priv->ap_list = g_slist_prepend (priv->ap_list, ap);
|
priv->ap_list = g_slist_prepend (priv->ap_list, ap);
|
||||||
nm_ap_export_to_dbus (ap);
|
nm_ap_export_to_dbus (ap);
|
||||||
|
|
@ -3246,6 +3249,17 @@ dispose (GObject *object)
|
||||||
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
|
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (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
|
static void
|
||||||
get_property (GObject *object, guint prop_id,
|
get_property (GObject *object, guint prop_id,
|
||||||
GValue *value, GParamSpec *pspec)
|
GValue *value, GParamSpec *pspec)
|
||||||
|
|
@ -3257,7 +3271,7 @@ get_property (GObject *object, guint prop_id,
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_PERM_HW_ADDRESS:
|
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;
|
break;
|
||||||
case PROP_MODE:
|
case PROP_MODE:
|
||||||
g_value_set_uint (value, priv->mode);
|
g_value_set_uint (value, priv->mode);
|
||||||
|
|
@ -3313,6 +3327,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
|
||||||
object_class->get_property = get_property;
|
object_class->get_property = get_property;
|
||||||
object_class->set_property = set_property;
|
object_class->set_property = set_property;
|
||||||
object_class->dispose = dispose;
|
object_class->dispose = dispose;
|
||||||
|
object_class->finalize = finalize;
|
||||||
|
|
||||||
parent_class->bring_up = bring_up;
|
parent_class->bring_up = bring_up;
|
||||||
parent_class->update_permanent_hw_address = update_permanent_hw_address;
|
parent_class->update_permanent_hw_address = update_permanent_hw_address;
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
mac = nm_setting_wimax_get_mac_address (s_wimax);
|
mac = nm_setting_wimax_get_mac_address (s_wimax);
|
||||||
if (mac && !nm_utils_hwaddr_matches (mac->data, mac->len, nm_device_get_hw_address (device, NULL), ETH_ALEN))
|
if (mac && !nm_utils_hwaddr_matches (mac->data, mac->len, nm_device_get_hw_address (device), -1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
@ -372,7 +372,7 @@ complete_connection (NMDevice *device,
|
||||||
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
|
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
|
||||||
NMSettingWimax *s_wimax;
|
NMSettingWimax *s_wimax;
|
||||||
const GByteArray *setting_mac;
|
const GByteArray *setting_mac;
|
||||||
const guint8 *hw_address;
|
const char *hw_address;
|
||||||
char *format;
|
char *format;
|
||||||
const char *nsp_name = NULL;
|
const char *nsp_name = NULL;
|
||||||
NMWimaxNsp *nsp = 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);
|
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);
|
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) {
|
if (setting_mac) {
|
||||||
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
|
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
|
||||||
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, hw_address, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, hw_address, -1)) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_SETTING_WIMAX_ERROR,
|
NM_SETTING_WIMAX_ERROR,
|
||||||
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY,
|
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY,
|
||||||
|
|
@ -463,9 +463,8 @@ complete_connection (NMDevice *device,
|
||||||
GByteArray *mac;
|
GByteArray *mac;
|
||||||
|
|
||||||
/* Lock the connection to this device by default */
|
/* Lock the connection to this device by default */
|
||||||
if (!nm_utils_hwaddr_matches (hw_address, ETH_ALEN, NULL, ETH_ALEN)) {
|
if (!nm_utils_hwaddr_matches (hw_address, -1, NULL, ETH_ALEN)) {
|
||||||
mac = g_byte_array_sized_new (ETH_ALEN);
|
mac = nm_utils_hwaddr_atoba (hw_address, 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_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, mac, NULL);
|
||||||
g_byte_array_free (mac, TRUE);
|
g_byte_array_free (mac, TRUE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -260,9 +260,7 @@ void
|
||||||
nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
|
nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
|
||||||
{
|
{
|
||||||
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
|
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
|
||||||
const guint8 *hwaddr;
|
char *current;
|
||||||
guint hwaddr_len;
|
|
||||||
char *current, *hwaddr_str;
|
|
||||||
GString *updated;
|
GString *updated;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
|
@ -277,10 +275,7 @@ nm_config_set_ethernet_no_auto_default (NMConfig *config, NMDevice *device)
|
||||||
g_string_append_c (updated, '\n');
|
g_string_append_c (updated, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
hwaddr = nm_device_get_hw_address (device, &hwaddr_len);
|
g_string_append (updated, nm_device_get_hw_address (device));
|
||||||
hwaddr_str = nm_utils_hwaddr_ntoa (hwaddr, hwaddr_len);
|
|
||||||
g_string_append (updated, hwaddr_str);
|
|
||||||
g_free (hwaddr_str);
|
|
||||||
g_string_append_c (updated, '\n');
|
g_string_append_c (updated, '\n');
|
||||||
|
|
||||||
if (!g_file_set_contents (priv->no_auto_default_file, updated->str, updated->len, &error)) {
|
if (!g_file_set_contents (priv->no_auto_default_file, updated->str, updated->len, &error)) {
|
||||||
|
|
|
||||||
|
|
@ -845,8 +845,7 @@ static NMDevice *
|
||||||
get_device_from_hwaddr (NMManager *self, const GByteArray *setting_mac)
|
get_device_from_hwaddr (NMManager *self, const GByteArray *setting_mac)
|
||||||
{
|
{
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||||
const guint8 *device_mac;
|
const char *device_mac;
|
||||||
guint device_mac_len;
|
|
||||||
GSList *iter;
|
GSList *iter;
|
||||||
|
|
||||||
if (!setting_mac)
|
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)) {
|
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
|
||||||
NMDevice *device = iter->data;
|
NMDevice *device = iter->data;
|
||||||
|
|
||||||
device_mac = nm_device_get_hw_address (iter->data, &device_mac_len);
|
device_mac = nm_device_get_hw_address (iter->data);
|
||||||
if (nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, device_mac, device_mac_len))
|
if (!device_mac)
|
||||||
|
continue;
|
||||||
|
if (nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, device_mac, -1))
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -1472,12 +1472,11 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
NMSettingWired *s_wired;
|
NMSettingWired *s_wired;
|
||||||
const GByteArray *setting_mac;
|
const GByteArray *setting_mac;
|
||||||
const guint8 *hwaddr;
|
const char *hwaddr;
|
||||||
guint hwaddr_len = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE);
|
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 */
|
/* Find a wired connection locked to the given MAC address, if any */
|
||||||
g_hash_table_iter_init (&iter, priv->connections);
|
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);
|
g_assert (s_wired != NULL);
|
||||||
|
|
||||||
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||||
if (setting_mac) {
|
if (setting_mac && hwaddr) {
|
||||||
/* A connection mac-locked to this device */
|
/* A connection mac-locked to this device */
|
||||||
if (nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, hwaddr, hwaddr_len))
|
if (nm_utils_hwaddr_matches (setting_mac->data, setting_mac->len, hwaddr, -1))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
/* A connection that applies to any wired device */
|
/* A connection that applies to any wired device */
|
||||||
|
|
@ -1590,9 +1589,8 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
|
||||||
NMSettingsConnection *added;
|
NMSettingsConnection *added;
|
||||||
NMSetting *setting;
|
NMSetting *setting;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
const guint8 *hw_address;
|
const char *hw_address;
|
||||||
char *defname, *uuid;
|
char *defname, *uuid;
|
||||||
guint len = 0;
|
|
||||||
GByteArray *mac;
|
GByteArray *mac;
|
||||||
|
|
||||||
if (!NM_IS_DEVICE_ETHERNET (device))
|
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))
|
|| !nm_config_get_ethernet_can_auto_default (priv->config, device))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hw_address = nm_device_get_hw_address (device, &len);
|
hw_address = nm_device_get_hw_address (device);
|
||||||
if (!hw_address)
|
if (!hw_address)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -1633,8 +1631,7 @@ nm_settings_device_added (NMSettings *self, NMDevice *device)
|
||||||
setting = nm_setting_wired_new ();
|
setting = nm_setting_wired_new ();
|
||||||
nm_connection_add_setting (connection, setting);
|
nm_connection_add_setting (connection, setting);
|
||||||
|
|
||||||
mac = g_byte_array_sized_new (len);
|
mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
|
||||||
g_byte_array_append (mac, hw_address, len);
|
|
||||||
g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
|
||||||
g_byte_array_unref (mac);
|
g_byte_array_unref (mac);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue