all: remove use of struct ether_addr / ether_aton()

Lots of old code used struct ether_addr to store hardware addresses,
and ether_aton() to parse them, but more recent code generally uses
guint8 arrays, and the nm_utils_hwaddr_* methods, to be able to share
code between ETH_ALEN and INFINIBAND_ALEN cases. So update the old
code to match the new. (In many places, this ends up getting rid of
casts between struct ether_addr and guint8* anyway.)

(Also, in some places, variables were switched from struct ether_addr
to guint8[] a while back, but some code still used "&" when referring
to them even though that's unnecessary now. Clean that up.)
This commit is contained in:
Dan Winship
2014-07-07 12:04:14 -04:00
parent 0dcba8a9a0
commit ea456aaa81
28 changed files with 124 additions and 154 deletions

View File

@@ -622,9 +622,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
for (mac_blacklist_iter = priv->mac_address_blacklist; mac_blacklist_iter; for (mac_blacklist_iter = priv->mac_address_blacklist; mac_blacklist_iter;
mac_blacklist_iter = mac_blacklist_iter->next) { mac_blacklist_iter = mac_blacklist_iter->next) {
struct ether_addr addr; if (!nm_utils_hwaddr_valid (mac_blacklist_iter->data, ETH_ALEN)) {
if (!ether_aton_r (mac_blacklist_iter->data, &addr)) {
g_set_error (error, g_set_error (error,
NM_SETTING_WIRED_ERROR, NM_SETTING_WIRED_ERROR,
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY, NM_SETTING_WIRED_ERROR_INVALID_PROPERTY,

View File

@@ -799,9 +799,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
} }
for (iter = priv->mac_address_blacklist; iter; iter = iter->next) { for (iter = priv->mac_address_blacklist; iter; iter = iter->next) {
struct ether_addr addr; if (!nm_utils_hwaddr_valid (iter->data, ETH_ALEN)) {
if (!ether_aton_r (iter->data, &addr)) {
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,
@@ -813,9 +811,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
} }
for (iter = priv->seen_bssids; iter; iter = iter->next) { for (iter = priv->seen_bssids; iter; iter = iter->next) {
struct ether_addr addr; if (!nm_utils_hwaddr_valid (iter->data, ETH_ALEN)) {
if (!ether_aton_r (iter->data, &addr)) {
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,

View File

@@ -240,7 +240,7 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
const GByteArray *setting_ssid; const GByteArray *setting_ssid;
const GByteArray *ap_ssid; const GByteArray *ap_ssid;
const GByteArray *setting_bssid; const GByteArray *setting_bssid;
struct ether_addr *ap_bssid; guint8 ap_bssid[ETH_ALEN];
const char *setting_mode; const char *setting_mode;
NM80211Mode ap_mode; NM80211Mode ap_mode;
const char *setting_band; const char *setting_band;
@@ -271,12 +271,11 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
setting_bssid = nm_setting_wireless_get_bssid (s_wifi); setting_bssid = nm_setting_wireless_get_bssid (s_wifi);
if (setting_bssid && ap_bssid_str) { if (setting_bssid && ap_bssid_str) {
g_assert (setting_bssid->len == ETH_ALEN); g_assert (setting_bssid->len == ETH_ALEN);
ap_bssid = ether_aton (ap_bssid_str); if (nm_utils_hwaddr_aton (ap_bssid_str, ap_bssid, ETH_ALEN)) {
g_warn_if_fail (ap_bssid); if (memcmp (ap_bssid, setting_bssid->data, ETH_ALEN) != 0)
if (ap_bssid) {
if (memcmp (ap_bssid->ether_addr_octet, setting_bssid->data, ETH_ALEN) != 0)
return FALSE; return FALSE;
} } else
g_warn_if_reached ();
} }
/* Mode */ /* Mode */

View File

@@ -27,6 +27,7 @@
#include <nm-setting-connection.h> #include <nm-setting-connection.h>
#include <nm-setting-bluetooth.h> #include <nm-setting-bluetooth.h>
#include <nm-utils.h>
#include "nm-device-bt.h" #include "nm-device-bt.h"
#include "nm-device-private.h" #include "nm-device-private.h"
@@ -148,7 +149,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const char *ctype; const char *ctype;
const GByteArray *mac; const GByteArray *mac;
const char *hw_str; const char *hw_str;
struct ether_addr *hw_mac; guint8 hw_mac[ETH_ALEN];
NMBluetoothCapabilities dev_caps; NMBluetoothCapabilities dev_caps;
NMBluetoothCapabilities bt_type; NMBluetoothCapabilities bt_type;
@@ -172,14 +173,13 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
/* Check BT address */ /* Check BT address */
hw_str = nm_device_bt_get_hw_address (NM_DEVICE_BT (device)); hw_str = nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
if (hw_str) { if (hw_str) {
hw_mac = ether_aton (hw_str); if (!nm_utils_hwaddr_aton (hw_str, hw_mac, ETH_ALEN)) {
if (!hw_mac) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC, g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address."); "Invalid device MAC address.");
return FALSE; return FALSE;
} }
mac = nm_setting_bluetooth_get_bdaddr (s_bt); mac = nm_setting_bluetooth_get_bdaddr (s_bt);
if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) { if (mac && memcmp (mac->data, hw_mac, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MAC_MISMATCH, g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match."); "The MACs of the device and the connection didn't match.");
return FALSE; return FALSE;

View File

@@ -28,6 +28,7 @@
#include <nm-setting-connection.h> #include <nm-setting-connection.h>
#include <nm-setting-wired.h> #include <nm-setting-wired.h>
#include <nm-setting-pppoe.h> #include <nm-setting-pppoe.h>
#include <nm-utils.h>
#include "nm-device-ethernet.h" #include "nm-device-ethernet.h"
#include "nm-device-private.h" #include "nm-device-private.h"
@@ -170,21 +171,20 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
if (s_wired) { if (s_wired) {
const GByteArray *mac; const GByteArray *mac;
const char *perm_str; const char *perm_str;
struct ether_addr *perm_mac; guint8 perm_mac[ETH_ALEN];
/* FIXME: filter using s390 subchannels when they are exported over the bus */ /* FIXME: filter using s390 subchannels when they are exported over the bus */
/* Check MAC address */ /* Check MAC address */
perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
if (perm_str) { if (perm_str) {
perm_mac = ether_aton (perm_str); if (!nm_utils_hwaddr_aton (perm_str, perm_mac, ETH_ALEN)) {
if (!perm_mac) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC, g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address."); "Invalid device MAC address.");
return FALSE; return FALSE;
} }
mac = nm_setting_wired_get_mac_address (s_wired); mac = nm_setting_wired_get_mac_address (s_wired);
if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN)) { if (mac && memcmp (mac->data, perm_mac, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH, g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match."); "The MACs of the device and the connection didn't match.");
return FALSE; return FALSE;

View File

@@ -28,6 +28,7 @@
#include <nm-setting-connection.h> #include <nm-setting-connection.h>
#include <nm-setting-wireless.h> #include <nm-setting-wireless.h>
#include <nm-setting-wireless-security.h> #include <nm-setting-wireless-security.h>
#include <nm-utils.h>
#include "nm-device-wifi.h" #include "nm-device-wifi.h"
#include "nm-device-private.h" #include "nm-device-private.h"
@@ -420,7 +421,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const char *ctype; const char *ctype;
const GByteArray *mac; const GByteArray *mac;
const char *hw_str; const char *hw_str;
struct ether_addr *hw_mac; guint8 hw_mac[ETH_ALEN];
NMDeviceWifiCapabilities wifi_caps; NMDeviceWifiCapabilities wifi_caps;
const char *key_mgmt; const char *key_mgmt;
@@ -444,14 +445,13 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
/* Check MAC address */ /* Check MAC address */
hw_str = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device)); hw_str = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device));
if (hw_str) { if (hw_str) {
hw_mac = ether_aton (hw_str); if (!nm_utils_hwaddr_aton (hw_str, hw_mac, ETH_ALEN)) {
if (!hw_mac) {
g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_INVALID_DEVICE_MAC, g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address."); "Invalid device MAC address.");
return FALSE; return FALSE;
} }
mac = nm_setting_wireless_get_mac_address (s_wifi); mac = nm_setting_wireless_get_mac_address (s_wifi);
if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) { if (mac && memcmp (mac->data, hw_mac, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MAC_MISMATCH, g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match."); "The MACs of the device and the connection didn't match.");
return FALSE; return FALSE;

View File

@@ -27,6 +27,7 @@
#include <nm-setting-connection.h> #include <nm-setting-connection.h>
#include <nm-setting-wimax.h> #include <nm-setting-wimax.h>
#include <nm-utils.h>
#include "nm-device-wimax.h" #include "nm-device-wimax.h"
#include "nm-object-private.h" #include "nm-object-private.h"
@@ -324,7 +325,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const char *ctype; const char *ctype;
const GByteArray *mac; const GByteArray *mac;
const char *hw_str; const char *hw_str;
struct ether_addr *hw_mac; guint8 hw_mac[ETH_ALEN];
s_con = nm_connection_get_setting_connection (connection); s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con); g_assert (s_con);
@@ -346,14 +347,13 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
/* Check MAC address */ /* Check MAC address */
hw_str = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)); hw_str = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device));
if (hw_str) { if (hw_str) {
hw_mac = ether_aton (hw_str); if (!nm_utils_hwaddr_aton (hw_str, hw_mac, ETH_ALEN)) {
if (!hw_mac) {
g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_INVALID_DEVICE_MAC, g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address."); "Invalid device MAC address.");
return FALSE; return FALSE;
} }
mac = nm_setting_wimax_get_mac_address (s_wimax); mac = nm_setting_wimax_get_mac_address (s_wimax);
if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) { if (mac && memcmp (mac->data, hw_mac, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_MAC_MISMATCH, g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match."); "The MACs of the device and the connection didn't match.");
return FALSE; return FALSE;

View File

@@ -51,7 +51,7 @@
* *
*/ */
gboolean gboolean
nm_ethernet_address_is_valid (const struct ether_addr *test_addr) nm_ethernet_address_is_valid (const guint8 *test_addr)
{ {
guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@@ -61,19 +61,19 @@ nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
g_return_val_if_fail (test_addr != NULL, FALSE); g_return_val_if_fail (test_addr != NULL, FALSE);
/* Compare the AP address the card has with invalid ethernet MAC addresses. */ /* Compare the AP address the card has with invalid ethernet MAC addresses. */
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN)) if (!memcmp (test_addr, invalid_addr1, ETH_ALEN))
return FALSE; return FALSE;
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN)) if (!memcmp (test_addr, invalid_addr2, ETH_ALEN))
return FALSE; return FALSE;
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN)) if (!memcmp (test_addr, invalid_addr3, ETH_ALEN))
return FALSE; return FALSE;
if (!memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN)) if (!memcmp (test_addr, invalid_addr4, ETH_ALEN))
return FALSE; return FALSE;
if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */ if (test_addr[0] & 1) /* Multicast addresses */
return FALSE; return FALSE;
return TRUE; return TRUE;

View File

@@ -29,7 +29,7 @@
#include "nm-connection.h" #include "nm-connection.h"
#include "nm-platform.h" #include "nm-platform.h"
gboolean nm_ethernet_address_is_valid (const struct ether_addr *test_addr); gboolean nm_ethernet_address_is_valid (const guint8 *test_addr);
in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen); in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen);
void nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_addr *src, guint8 plen); void nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_addr *src, guint8 plen);

View File

@@ -619,7 +619,6 @@ _set_property_capabilities (NMBluezDevice *self, const char **uuids)
static void static void
_set_property_address (NMBluezDevice *self, const char *addr) _set_property_address (NMBluezDevice *self, const char *addr)
{ {
struct ether_addr *tmp;
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
if (g_strcmp0 (priv->address, addr) == 0) if (g_strcmp0 (priv->address, addr) == 0)
@@ -635,15 +634,13 @@ _set_property_address (NMBluezDevice *self, const char *addr)
return; return;
} }
tmp = ether_aton (addr); if (!nm_utils_hwaddr_aton (addr, priv->bin_address, ETH_ALEN)) {
if (!tmp) {
if (priv->address) if (priv->address)
nm_log_warn (LOGD_BT, "bluez[%s] cannot reset address from '%s' to '%s' (invalid value)", priv->path, priv->address, addr); nm_log_warn (LOGD_BT, "bluez[%s] cannot reset address from '%s' to '%s' (invalid value)", priv->path, priv->address, addr);
else else
nm_log_warn (LOGD_BT, "bluez[%s] cannot reset address from NULL to '%s' (invalid value)", priv->path, addr); nm_log_warn (LOGD_BT, "bluez[%s] cannot reset address from NULL to '%s' (invalid value)", priv->path, addr);
return; return;
} }
memcpy (priv->bin_address, tmp->ether_addr_octet, ETH_ALEN);
priv->address = g_strdup (addr); priv->address = g_strdup (addr);
g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_ADDRESS); g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_ADDRESS);
} }

View File

@@ -361,7 +361,7 @@ update_permanent_hw_address (NMDevice *dev)
errno = 0; errno = 0;
ret = ioctl (fd, SIOCETHTOOL, &req); ret = ioctl (fd, SIOCETHTOOL, &req);
errsv = errno; errsv = errno;
if ((ret < 0) || !nm_ethernet_address_is_valid ((struct ether_addr *) 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, NULL);
@@ -371,8 +371,8 @@ update_permanent_hw_address (NMDevice *dev)
memset (epaddr->data, 0, ETH_ALEN); memset (epaddr->data, 0, ETH_ALEN);
} }
if (memcmp (&priv->perm_hw_addr, epaddr->data, ETH_ALEN)) { if (memcmp (priv->perm_hw_addr, epaddr->data, ETH_ALEN)) {
memcpy (&priv->perm_hw_addr, 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_object_notify (G_OBJECT (dev), NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
} }
@@ -475,21 +475,21 @@ 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 && memcmp (mac->data, &priv->perm_hw_addr, ETH_ALEN)) if (try_mac && mac && memcmp (mac->data, priv->perm_hw_addr, ETH_ALEN))
return FALSE; return FALSE;
/* Check for MAC address blacklist */ /* Check for MAC address blacklist */
mac_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); mac_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired);
for (mac_blacklist_iter = mac_blacklist; mac_blacklist_iter; for (mac_blacklist_iter = mac_blacklist; mac_blacklist_iter;
mac_blacklist_iter = g_slist_next (mac_blacklist_iter)) { mac_blacklist_iter = g_slist_next (mac_blacklist_iter)) {
struct ether_addr addr; guint8 addr[ETH_ALEN];
if (!ether_aton_r (mac_blacklist_iter->data, &addr)) { if (!nm_utils_hwaddr_aton (mac_blacklist_iter->data, addr, ETH_ALEN)) {
g_warn_if_reached (); g_warn_if_reached ();
return FALSE; return FALSE;
} }
if (memcmp (&addr, &priv->perm_hw_addr, ETH_ALEN) == 0) if (memcmp (addr, priv->perm_hw_addr, ETH_ALEN) == 0)
return FALSE; return FALSE;
} }
} }

View File

@@ -365,7 +365,7 @@ find_active_ap (NMDeviceWifi *self,
{ {
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
int ifindex = nm_device_get_ifindex (NM_DEVICE (self)); int ifindex = nm_device_get_ifindex (NM_DEVICE (self));
struct ether_addr bssid; guint8 bssid[ETH_ALEN];
GByteArray *ssid; GByteArray *ssid;
GSList *iter; GSList *iter;
int i = 0; int i = 0;
@@ -375,13 +375,11 @@ find_active_ap (NMDeviceWifi *self,
NM80211Mode devmode; NM80211Mode devmode;
guint32 devfreq; guint32 devfreq;
nm_platform_wifi_get_bssid (ifindex, &bssid); nm_platform_wifi_get_bssid (ifindex, bssid);
_LOGD (LOGD_WIFI, "active BSSID: %02x:%02x:%02x:%02x:%02x:%02x", _LOGD (LOGD_WIFI, "active BSSID: %02x:%02x:%02x:%02x:%02x:%02x",
bssid.ether_addr_octet[0], bssid.ether_addr_octet[1], bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
bssid.ether_addr_octet[2], bssid.ether_addr_octet[3],
bssid.ether_addr_octet[4], bssid.ether_addr_octet[5]);
if (!nm_ethernet_address_is_valid (&bssid)) if (!nm_ethernet_address_is_valid (bssid))
return NULL; return NULL;
ssid = nm_platform_wifi_get_ssid (ifindex); ssid = nm_platform_wifi_get_ssid (ifindex);
@@ -403,7 +401,7 @@ find_active_ap (NMDeviceWifi *self,
/* Find this SSID + BSSID in the device's AP list */ /* Find this SSID + BSSID in the device's AP list */
for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) { for (iter = priv->ap_list; iter; iter = g_slist_next (iter)) {
NMAccessPoint *ap = NM_AP (iter->data); NMAccessPoint *ap = NM_AP (iter->data);
const struct ether_addr *ap_bssid = nm_ap_get_address (ap); const guint8 *ap_bssid = nm_ap_get_address (ap);
const GByteArray *ap_ssid = nm_ap_get_ssid (ap); const GByteArray *ap_ssid = nm_ap_get_ssid (ap);
NM80211Mode apmode; NM80211Mode apmode;
guint32 apfreq; guint32 apfreq;
@@ -412,16 +410,15 @@ find_active_ap (NMDeviceWifi *self,
ap_ssid ? "'" : "", ap_ssid ? "'" : "",
ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)", ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)",
ap_ssid ? "'" : "", ap_ssid ? "'" : "",
ap_bssid->ether_addr_octet[0], ap_bssid->ether_addr_octet[1], ap_bssid[0], ap_bssid[1], ap_bssid[2],
ap_bssid->ether_addr_octet[2], ap_bssid->ether_addr_octet[3], ap_bssid[3], ap_bssid[4], ap_bssid[5]);
ap_bssid->ether_addr_octet[4], ap_bssid->ether_addr_octet[5]);
if (ap == ignore_ap) { if (ap == ignore_ap) {
_LOGD (LOGD_WIFI, " ignored"); _LOGD (LOGD_WIFI, " ignored");
continue; continue;
} }
if (memcmp (bssid.ether_addr_octet, ap_bssid->ether_addr_octet, ETH_ALEN)) { if (memcmp (bssid, ap_bssid, ETH_ALEN)) {
_LOGD (LOGD_WIFI, " BSSID mismatch"); _LOGD (LOGD_WIFI, " BSSID mismatch");
continue; continue;
} }
@@ -473,16 +470,14 @@ find_active_ap (NMDeviceWifi *self,
* we can't match the AP based on frequency at all, just give up. * we can't match the AP based on frequency at all, just give up.
*/ */
if (match_nofreq && ((found_a_band != found_bg_band) || (devfreq == 0))) { if (match_nofreq && ((found_a_band != found_bg_band) || (devfreq == 0))) {
const struct ether_addr *ap_bssid = nm_ap_get_address (match_nofreq); const guint8 *ap_bssid = nm_ap_get_address (match_nofreq);
const GByteArray *ap_ssid = nm_ap_get_ssid (match_nofreq); const GByteArray *ap_ssid = nm_ap_get_ssid (match_nofreq);
_LOGD (LOGD_WIFI, " matched %s%s%s %02x:%02x:%02x:%02x:%02x:%02x", _LOGD (LOGD_WIFI, " matched %s%s%s %02x:%02x:%02x:%02x:%02x:%02x",
ap_ssid ? "'" : "", ap_ssid ? "'" : "",
ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)", ap_ssid ? nm_utils_escape_ssid (ap_ssid->data, ap_ssid->len) : "(none)",
ap_ssid ? "'" : "", ap_ssid ? "'" : "",
ap_bssid->ether_addr_octet[0], ap_bssid->ether_addr_octet[1], ap_bssid[0], ap_bssid[1], ap_bssid[2], ap_bssid[3], ap_bssid[4], ap_bssid[5]);
ap_bssid->ether_addr_octet[2], ap_bssid->ether_addr_octet[3],
ap_bssid->ether_addr_octet[4], ap_bssid->ether_addr_octet[5]);
active_ap = match_nofreq; active_ap = match_nofreq;
goto done; goto done;
@@ -603,15 +598,14 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap)
* current AP with it, if the current AP is adhoc. * current AP with it, if the current AP is adhoc.
*/ */
if (priv->current_ap && (nm_ap_get_mode (priv->current_ap) == NM_802_11_MODE_ADHOC)) { if (priv->current_ap && (nm_ap_get_mode (priv->current_ap) == NM_802_11_MODE_ADHOC)) {
struct ether_addr bssid = { {0x0, 0x0, 0x0, 0x0, 0x0, 0x0} }; guint8 bssid[ETH_ALEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
nm_platform_wifi_get_bssid (ifindex, &bssid); nm_platform_wifi_get_bssid (ifindex, bssid);
/* 0x02 means "locally administered" and should be OR-ed into /* 0x02 means "locally administered" and should be OR-ed into
* the first byte of IBSS BSSIDs. * the first byte of IBSS BSSIDs.
*/ */
if ( (bssid.ether_addr_octet[0] & 0x02) if ((bssid[0] & 0x02) && nm_ethernet_address_is_valid (bssid))
&& nm_ethernet_address_is_valid (&bssid)) nm_ap_set_address (priv->current_ap, bssid);
nm_ap_set_address (priv->current_ap, &bssid);
} }
new_ap = find_active_ap (self, ignore_ap, FALSE); new_ap = find_active_ap (self, ignore_ap, FALSE);
@@ -627,9 +621,9 @@ periodic_update (NMDeviceWifi *self, NMAccessPoint *ignore_ap)
} }
if (new_ap != priv->current_ap) { if (new_ap != priv->current_ap) {
const struct ether_addr *new_bssid = NULL; const guint8 *new_bssid = NULL;
const GByteArray *new_ssid = NULL; const GByteArray *new_ssid = NULL;
const struct ether_addr *old_bssid = NULL; const guint8 *old_bssid = NULL;
const GByteArray *old_ssid = NULL; const GByteArray *old_ssid = NULL;
char *old_addr = NULL, *new_addr = NULL; char *old_addr = NULL, *new_addr = NULL;
@@ -836,21 +830,21 @@ 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 && memcmp (mac->data, &priv->perm_hw_addr, ETH_ALEN)) if (mac && memcmp (mac->data, priv->perm_hw_addr, ETH_ALEN))
return FALSE; return FALSE;
/* Check for MAC address blacklist */ /* Check for MAC address blacklist */
mac_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); mac_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless);
for (mac_blacklist_iter = mac_blacklist; mac_blacklist_iter; for (mac_blacklist_iter = mac_blacklist; mac_blacklist_iter;
mac_blacklist_iter = g_slist_next (mac_blacklist_iter)) { mac_blacklist_iter = g_slist_next (mac_blacklist_iter)) {
struct ether_addr addr; guint8 addr[ETH_ALEN];
if (!ether_aton_r (mac_blacklist_iter->data, &addr)) { if (!nm_utils_hwaddr_aton (mac_blacklist_iter->data, addr, ETH_ALEN)) {
g_warn_if_reached (); g_warn_if_reached ();
continue; continue;
} }
if (memcmp (&addr, &priv->perm_hw_addr, ETH_ALEN) == 0) if (memcmp (&addr, priv->perm_hw_addr, ETH_ALEN) == 0)
return FALSE; return FALSE;
} }
@@ -1648,7 +1642,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface,
static void static void
try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) try_fill_ssid_for_hidden_ap (NMAccessPoint *ap)
{ {
const struct ether_addr *bssid; const guint8 *bssid;
const GSList *connections, *iter; const GSList *connections, *iter;
g_return_if_fail (nm_ap_get_ssid (ap) == NULL); g_return_if_fail (nm_ap_get_ssid (ap) == NULL);
@@ -1695,7 +1689,7 @@ merge_scanned_ap (NMDeviceWifi *self,
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
NMAccessPoint *found_ap = NULL; NMAccessPoint *found_ap = NULL;
const GByteArray *ssid; const GByteArray *ssid;
const struct ether_addr *bssid; const guint8 *bssid;
gboolean strict_match = TRUE; gboolean strict_match = TRUE;
/* Let the manager try to fill in the SSID from seen-bssids lists */ /* Let the manager try to fill in the SSID from seen-bssids lists */
@@ -1709,13 +1703,13 @@ merge_scanned_ap (NMDeviceWifi *self,
if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) { if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) {
/* Yay, matched it, no longer treat as hidden */ /* Yay, matched it, no longer treat as hidden */
_LOGD (LOGD_WIFI_SCAN, "matched hidden AP " MAC_FMT " => '%s'", _LOGD (LOGD_WIFI_SCAN, "matched hidden AP " MAC_FMT " => '%s'",
MAC_ARG (bssid->ether_addr_octet), MAC_ARG (bssid),
nm_utils_escape_ssid (ssid->data, ssid->len)); nm_utils_escape_ssid (ssid->data, ssid->len));
nm_ap_set_broadcast (merge_ap, FALSE); nm_ap_set_broadcast (merge_ap, FALSE);
} else { } else {
/* Didn't have an entry for this AP in the database */ /* Didn't have an entry for this AP in the database */
_LOGD (LOGD_WIFI_SCAN, "failed to match hidden AP " MAC_FMT, _LOGD (LOGD_WIFI_SCAN, "failed to match hidden AP " MAC_FMT,
MAC_ARG (bssid->ether_addr_octet)); MAC_ARG (bssid));
} }
} }
@@ -1734,7 +1728,7 @@ merge_scanned_ap (NMDeviceWifi *self,
if (found_ap) { if (found_ap) {
_LOGD (LOGD_WIFI_SCAN, "merging AP '%s' " MAC_FMT " (%p) with existing (%p)", _LOGD (LOGD_WIFI_SCAN, "merging AP '%s' " MAC_FMT " (%p) with existing (%p)",
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)",
MAC_ARG (bssid->ether_addr_octet), MAC_ARG (bssid),
merge_ap, merge_ap,
found_ap); found_ap);
@@ -1756,7 +1750,7 @@ merge_scanned_ap (NMDeviceWifi *self,
/* New entry in the list */ /* New entry in the list */
_LOGD (LOGD_WIFI_SCAN, "adding new AP '%s' " MAC_FMT " (%p)", _LOGD (LOGD_WIFI_SCAN, "adding new AP '%s' " MAC_FMT " (%p)",
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)",
MAC_ARG (bssid->ether_addr_octet), MAC_ARG (bssid),
merge_ap); merge_ap);
g_object_ref (merge_ap); g_object_ref (merge_ap);
@@ -1813,16 +1807,14 @@ cull_scan_list (NMDeviceWifi *self)
/* Remove outdated APs */ /* Remove outdated APs */
for (elt = outdated_list; elt; elt = g_slist_next (elt)) { for (elt = outdated_list; elt; elt = g_slist_next (elt)) {
NMAccessPoint *outdated_ap = NM_AP (elt->data); NMAccessPoint *outdated_ap = NM_AP (elt->data);
const struct ether_addr *bssid; const guint8 *bssid;
const GByteArray *ssid; const GByteArray *ssid;
bssid = nm_ap_get_address (outdated_ap); bssid = nm_ap_get_address (outdated_ap);
ssid = nm_ap_get_ssid (outdated_ap); ssid = nm_ap_get_ssid (outdated_ap);
_LOGD (LOGD_WIFI_SCAN, _LOGD (LOGD_WIFI_SCAN,
" removing %02x:%02x:%02x:%02x:%02x:%02x (%s%s%s)", " removing %02x:%02x:%02x:%02x:%02x:%02x (%s%s%s)",
bssid->ether_addr_octet[0], bssid->ether_addr_octet[1], bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
bssid->ether_addr_octet[2], bssid->ether_addr_octet[3],
bssid->ether_addr_octet[4], bssid->ether_addr_octet[5],
ssid ? "'" : "", ssid ? "'" : "",
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)", ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)",
ssid ? "'" : ""); ssid ? "'" : "");
@@ -2542,15 +2534,15 @@ update_permanent_hw_address (NMDevice *device)
errno = 0; errno = 0;
ret = ioctl (fd, SIOCETHTOOL, &req); ret = ioctl (fd, SIOCETHTOOL, &req);
errsv = errno; errsv = errno;
if ((ret < 0) || !nm_ethernet_address_is_valid ((struct ether_addr *) 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)", _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); memcpy (epaddr->data, nm_device_get_hw_address (device, NULL), ETH_ALEN);
} }
if (memcmp (&priv->perm_hw_addr, epaddr->data, ETH_ALEN)) { if (memcmp (priv->perm_hw_addr, epaddr->data, ETH_ALEN)) {
memcpy (&priv->perm_hw_addr, 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_object_notify (G_OBJECT (device), NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
} }
@@ -2667,7 +2659,7 @@ 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, (const struct ether_addr *) nm_device_get_hw_address (device, NULL)); nm_ap_set_address (ap, nm_device_get_hw_address (device, NULL));
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);
@@ -2998,7 +2990,7 @@ activation_success_handler (NMDevice *device)
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
int ifindex = nm_device_get_ifindex (device); int ifindex = nm_device_get_ifindex (device);
NMAccessPoint *ap; NMAccessPoint *ap;
struct ether_addr bssid = { {0x0, 0x0, 0x0, 0x0, 0x0, 0x0} }; guint8 bssid[ETH_ALEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
NMAccessPoint *tmp_ap = NULL; NMAccessPoint *tmp_ap = NULL;
NMActRequest *req; NMActRequest *req;
NMConnection *connection; NMConnection *connection;
@@ -3029,9 +3021,9 @@ activation_success_handler (NMDevice *device)
* But if activation was successful, the card will know the BSSID. Grab * But if activation was successful, the card will know the BSSID. Grab
* the BSSID off the card and fill in the BSSID of the activation AP. * the BSSID off the card and fill in the BSSID of the activation AP.
*/ */
nm_platform_wifi_get_bssid (ifindex, &bssid); nm_platform_wifi_get_bssid (ifindex, bssid);
if (!nm_ethernet_address_is_valid (nm_ap_get_address (ap))) if (!nm_ethernet_address_is_valid (nm_ap_get_address (ap)))
nm_ap_set_address (ap, &bssid); nm_ap_set_address (ap, bssid);
if (!nm_ap_get_freq (ap)) if (!nm_ap_get_freq (ap))
nm_ap_set_freq (ap, nm_platform_wifi_get_frequency (ifindex)); nm_ap_set_freq (ap, nm_platform_wifi_get_frequency (ifindex));
if (!nm_ap_get_max_bitrate (ap)) if (!nm_ap_get_max_bitrate (ap))

View File

@@ -465,7 +465,7 @@ verify_adhoc (NMSettingWirelessSecurity *s_wsec,
gboolean gboolean
nm_ap_utils_complete_connection (const GByteArray *ap_ssid, nm_ap_utils_complete_connection (const GByteArray *ap_ssid,
const guint8 ap_bssid[ETH_ALEN], const guint8 *ap_bssid,
NM80211Mode ap_mode, NM80211Mode ap_mode,
guint32 ap_flags, guint32 ap_flags,
guint32 ap_wpa_flags, guint32 ap_wpa_flags,

View File

@@ -30,7 +30,7 @@
#include <nm-setting-8021x.h> #include <nm-setting-8021x.h>
gboolean nm_ap_utils_complete_connection (const GByteArray *ssid, gboolean nm_ap_utils_complete_connection (const GByteArray *ssid,
const guint8 bssid[ETH_ALEN], const guint8 *bssid,
NM80211Mode mode, NM80211Mode mode,
guint32 flags, guint32 flags,
guint32 wpa_flags, guint32 wpa_flags,

View File

@@ -45,7 +45,7 @@ typedef struct
/* Scanned or cached values */ /* Scanned or cached values */
GByteArray * ssid; GByteArray * ssid;
struct ether_addr address; guint8 address[ETH_ALEN];
NM80211Mode mode; NM80211Mode mode;
gint8 strength; gint8 strength;
guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */ guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */
@@ -408,13 +408,9 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
nm_ap_set_ssid (ap, ssid); nm_ap_set_ssid (ap, ssid);
g_byte_array_free (ssid, TRUE); g_byte_array_free (ssid, TRUE);
} else if (!strcmp (key, "BSSID")) { } else if (!strcmp (key, "BSSID")) {
struct ether_addr addr;
if (array->len != ETH_ALEN) if (array->len != ETH_ALEN)
return; return;
memset (&addr, 0, sizeof (struct ether_addr)); nm_ap_set_address (ap, (guint8 *) array->data);
memcpy (&addr, array->data, ETH_ALEN);
nm_ap_set_address (ap, &addr);
} else if (!strcmp (key, "Rates")) { } else if (!strcmp (key, "Rates")) {
guint32 maxrate = 0; guint32 maxrate = 0;
int i; int i;
@@ -474,7 +470,7 @@ NMAccessPoint *
nm_ap_new_from_properties (const char *supplicant_path, GHashTable *properties) nm_ap_new_from_properties (const char *supplicant_path, GHashTable *properties)
{ {
NMAccessPoint *ap; NMAccessPoint *ap;
const struct ether_addr * addr; const guint8 *addr;
const char bad_bssid1[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; const char bad_bssid1[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const char bad_bssid2[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; const char bad_bssid2[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
@@ -489,8 +485,8 @@ nm_ap_new_from_properties (const char *supplicant_path, GHashTable *properties)
/* ignore APs with invalid BSSIDs */ /* ignore APs with invalid BSSIDs */
addr = nm_ap_get_address (ap); addr = nm_ap_get_address (ap);
if ( !(memcmp (addr->ether_addr_octet, bad_bssid1, ETH_ALEN)) if ( !(memcmp (addr, bad_bssid1, ETH_ALEN))
|| !(memcmp (addr->ether_addr_octet, bad_bssid2, ETH_ALEN))) { || !(memcmp (addr, bad_bssid2, ETH_ALEN))) {
g_object_unref (ap); g_object_unref (ap);
return NULL; return NULL;
} }
@@ -728,7 +724,7 @@ nm_ap_dump (NMAccessPoint *ap, const char *prefix)
prefix, prefix,
priv->ssid ? nm_utils_escape_ssid (priv->ssid->data, priv->ssid->len) : "(none)", priv->ssid ? nm_utils_escape_ssid (priv->ssid->data, priv->ssid->len) : "(none)",
ap); ap);
nm_log_dbg (LOGD_WIFI_SCAN, " BSSID " MAC_FMT, MAC_ARG (priv->address.ether_addr_octet)); nm_log_dbg (LOGD_WIFI_SCAN, " BSSID " MAC_FMT, MAC_ARG (priv->address));
nm_log_dbg (LOGD_WIFI_SCAN, " mode %d", priv->mode); nm_log_dbg (LOGD_WIFI_SCAN, " mode %d", priv->mode);
nm_log_dbg (LOGD_WIFI_SCAN, " flags 0x%X", priv->flags); nm_log_dbg (LOGD_WIFI_SCAN, " flags 0x%X", priv->flags);
nm_log_dbg (LOGD_WIFI_SCAN, " wpa flags 0x%X", priv->wpa_flags); nm_log_dbg (LOGD_WIFI_SCAN, " wpa flags 0x%X", priv->wpa_flags);
@@ -888,14 +884,16 @@ nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags)
* Get/set functions for address * Get/set functions for address
* *
*/ */
const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap) const guint8 *
nm_ap_get_address (const NMAccessPoint *ap)
{ {
g_return_val_if_fail (NM_IS_AP (ap), NULL); g_return_val_if_fail (NM_IS_AP (ap), NULL);
return &NM_AP_GET_PRIVATE (ap)->address; return NM_AP_GET_PRIVATE (ap)->address;
} }
void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr * addr) void
nm_ap_set_address (NMAccessPoint *ap, const guint8 *addr)
{ {
NMAccessPointPrivate *priv; NMAccessPointPrivate *priv;
@@ -904,8 +902,8 @@ void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr * addr)
priv = NM_AP_GET_PRIVATE (ap); priv = NM_AP_GET_PRIVATE (ap);
if (memcmp (addr, &priv->address, sizeof (priv->address))) { if (memcmp (addr, priv->address, sizeof (priv->address))) {
memcpy (&NM_AP_GET_PRIVATE (ap)->address, addr, sizeof (struct ether_addr)); memcpy (NM_AP_GET_PRIVATE (ap)->address, addr, sizeof (priv->address));
g_object_notify (G_OBJECT (ap), NM_AP_HW_ADDRESS); g_object_notify (G_OBJECT (ap), NM_AP_HW_ADDRESS);
} }
} }
@@ -1127,7 +1125,7 @@ nm_ap_check_compatible (NMAccessPoint *self,
return FALSE; return FALSE;
bssid = nm_setting_wireless_get_bssid (s_wireless); bssid = nm_setting_wireless_get_bssid (s_wireless);
if (bssid && memcmp (bssid->data, &priv->address, ETH_ALEN)) if (bssid && memcmp (bssid->data, priv->address, ETH_ALEN))
return FALSE; return FALSE;
mode = nm_setting_wireless_get_mode (s_wireless); mode = nm_setting_wireless_get_mode (s_wireless);
@@ -1181,7 +1179,7 @@ nm_ap_complete_connection (NMAccessPoint *self,
g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (connection != NULL, FALSE);
return nm_ap_utils_complete_connection (priv->ssid, return nm_ap_utils_complete_connection (priv->ssid,
priv->address.ether_addr_octet, priv->address,
priv->mode, priv->mode,
priv->flags, priv->flags,
priv->wpa_flags, priv->wpa_flags,
@@ -1224,10 +1222,10 @@ nm_ap_match_in_list (NMAccessPoint *find_ap,
for (iter = ap_list; iter; iter = g_slist_next (iter)) { for (iter = ap_list; iter; iter = g_slist_next (iter)) {
NMAccessPoint * list_ap = NM_AP (iter->data); NMAccessPoint * list_ap = NM_AP (iter->data);
const GByteArray * list_ssid = nm_ap_get_ssid (list_ap); const GByteArray * list_ssid = nm_ap_get_ssid (list_ap);
const struct ether_addr * list_addr = nm_ap_get_address (list_ap); const guint8 * list_addr = nm_ap_get_address (list_ap);
const GByteArray * find_ssid = nm_ap_get_ssid (find_ap); const GByteArray * find_ssid = nm_ap_get_ssid (find_ap);
const struct ether_addr * find_addr = nm_ap_get_address (find_ap); const guint8 * find_addr = nm_ap_get_address (find_ap);
/* SSID match; if both APs are hiding their SSIDs, /* SSID match; if both APs are hiding their SSIDs,
* let matching continue on BSSID and other properties * let matching continue on BSSID and other properties
@@ -1240,11 +1238,8 @@ nm_ap_match_in_list (NMAccessPoint *find_ap,
/* BSSID match */ /* BSSID match */
if ( (strict_match || nm_ethernet_address_is_valid (find_addr)) if ( (strict_match || nm_ethernet_address_is_valid (find_addr))
&& nm_ethernet_address_is_valid (list_addr) && nm_ethernet_address_is_valid (list_addr)
&& memcmp (list_addr->ether_addr_octet, && memcmp (list_addr, find_addr, ETH_ALEN) != 0)
find_addr->ether_addr_octet,
ETH_ALEN) != 0) {
continue; continue;
}
/* mode match */ /* mode match */
if (nm_ap_get_mode (list_ap) != nm_ap_get_mode (find_ap)) if (nm_ap_get_mode (list_ap) != nm_ap_get_mode (find_ap))

View File

@@ -78,8 +78,8 @@ void nm_ap_set_wpa_flags (NMAccessPoint *ap, NM80211ApSecurity
NM80211ApSecurityFlags nm_ap_get_rsn_flags (NMAccessPoint *ap); NM80211ApSecurityFlags nm_ap_get_rsn_flags (NMAccessPoint *ap);
void nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags); void nm_ap_set_rsn_flags (NMAccessPoint *ap, NM80211ApSecurityFlags flags);
const struct ether_addr *nm_ap_get_address (const NMAccessPoint *ap); const guint8 *nm_ap_get_address (const NMAccessPoint *ap);
void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr); void nm_ap_set_address (NMAccessPoint *ap, const guint8 *addr);
NM80211Mode nm_ap_get_mode (NMAccessPoint *ap); NM80211Mode nm_ap_get_mode (NMAccessPoint *ap);
void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode); void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode);

View File

@@ -688,7 +688,7 @@ wifi_get_capabilities (NMPlatform *platform, int ifindex, NMDeviceWifiCapabiliti
} }
static gboolean static gboolean
wifi_get_bssid (NMPlatform *platform, int ifindex, struct ether_addr *bssid) wifi_get_bssid (NMPlatform *platform, int ifindex, guint8 *bssid)
{ {
return FALSE; return FALSE;
} }

View File

@@ -3163,7 +3163,7 @@ wifi_get_capabilities (NMPlatform *platform, int ifindex, NMDeviceWifiCapabiliti
} }
static gboolean static gboolean
wifi_get_bssid (NMPlatform *platform, int ifindex, struct ether_addr *bssid) wifi_get_bssid (NMPlatform *platform, int ifindex, guint8 *bssid)
{ {
WifiData *wifi_data = wifi_get_wifi_data (platform, ifindex); WifiData *wifi_data = wifi_get_wifi_data (platform, ifindex);

View File

@@ -1266,7 +1266,7 @@ nm_platform_wifi_get_capabilities (int ifindex, NMDeviceWifiCapabilities *caps)
} }
gboolean gboolean
nm_platform_wifi_get_bssid (int ifindex, struct ether_addr *bssid) nm_platform_wifi_get_bssid (int ifindex, guint8 *bssid)
{ {
reset_error (); reset_error ();

View File

@@ -422,7 +422,7 @@ typedef struct {
gboolean (*gre_get_properties) (NMPlatform *, int ifindex, NMPlatformGreProperties *props); gboolean (*gre_get_properties) (NMPlatform *, int ifindex, NMPlatformGreProperties *props);
gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps); gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps);
gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, struct ether_addr *bssid); gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, guint8 *bssid);
GByteArray *(*wifi_get_ssid) (NMPlatform *, int ifindex); GByteArray *(*wifi_get_ssid) (NMPlatform *, int ifindex);
guint32 (*wifi_get_frequency) (NMPlatform *, int ifindex); guint32 (*wifi_get_frequency) (NMPlatform *, int ifindex);
int (*wifi_get_quality) (NMPlatform *, int ifindex); int (*wifi_get_quality) (NMPlatform *, int ifindex);
@@ -562,7 +562,7 @@ gboolean nm_platform_vxlan_get_properties (int ifindex, NMPlatformVxlanPropertie
gboolean nm_platform_gre_get_properties (int ifindex, NMPlatformGreProperties *props); gboolean nm_platform_gre_get_properties (int ifindex, NMPlatformGreProperties *props);
gboolean nm_platform_wifi_get_capabilities (int ifindex, NMDeviceWifiCapabilities *caps); gboolean nm_platform_wifi_get_capabilities (int ifindex, NMDeviceWifiCapabilities *caps);
gboolean nm_platform_wifi_get_bssid (int ifindex, struct ether_addr *bssid); gboolean nm_platform_wifi_get_bssid (int ifindex, guint8 *bssid);
GByteArray *nm_platform_wifi_get_ssid (int ifindex); GByteArray *nm_platform_wifi_get_ssid (int ifindex);
guint32 nm_platform_wifi_get_frequency (int ifindex); guint32 nm_platform_wifi_get_frequency (int ifindex);
int nm_platform_wifi_get_quality (int ifindex); int nm_platform_wifi_get_quality (int ifindex);

View File

@@ -442,7 +442,7 @@ wifi_nl80211_get_ssid (WifiData *data)
} }
static gboolean static gboolean
wifi_nl80211_get_bssid (WifiData *data, struct ether_addr *out_bssid) wifi_nl80211_get_bssid (WifiData *data, guint8 *out_bssid)
{ {
WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data; WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data;
struct nl80211_bss_info bss_info; struct nl80211_bss_info bss_info;

View File

@@ -47,7 +47,7 @@ struct WifiData {
/* Return current bitrate in Kbps */ /* Return current bitrate in Kbps */
guint32 (*get_rate) (WifiData *data); guint32 (*get_rate) (WifiData *data);
gboolean (*get_bssid) (WifiData *data, struct ether_addr *out_bssid); gboolean (*get_bssid) (WifiData *data, guint8 *out_bssid);
/* Return a signal strength percentage 0 - 100% for the current BSSID; /* Return a signal strength percentage 0 - 100% for the current BSSID;
* return -1 on errors or if not associated. * return -1 on errors or if not associated.

View File

@@ -230,7 +230,7 @@ wifi_wext_get_ssid (WifiData *data)
} }
static gboolean static gboolean
wifi_wext_get_bssid (WifiData *data, struct ether_addr *out_bssid) wifi_wext_get_bssid (WifiData *data, guint8 *out_bssid)
{ {
WifiDataWext *wext = (WifiDataWext *) data; WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq; struct iwreq wrq;
@@ -243,7 +243,7 @@ wifi_wext_get_bssid (WifiData *data, struct ether_addr *out_bssid)
wext->parent.iface, strerror (errno)); wext->parent.iface, strerror (errno));
return FALSE; return FALSE;
} }
memcpy (out_bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN); memcpy (out_bssid, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
return TRUE; return TRUE;
} }

View File

@@ -120,12 +120,12 @@ wifi_utils_get_ssid (WifiData *data)
} }
gboolean gboolean
wifi_utils_get_bssid (WifiData *data, struct ether_addr *out_bssid) wifi_utils_get_bssid (WifiData *data, guint8 *out_bssid)
{ {
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (out_bssid != NULL, FALSE); g_return_val_if_fail (out_bssid != NULL, FALSE);
memset (out_bssid, 0, sizeof (*out_bssid)); memset (out_bssid, 0, ETH_ALEN);
return data->get_bssid (data, out_bssid); return data->get_bssid (data, out_bssid);
} }

View File

@@ -50,8 +50,8 @@ guint32 wifi_utils_find_freq (WifiData *data, const guint32 *freqs);
/* Caller must free returned byte array */ /* Caller must free returned byte array */
GByteArray *wifi_utils_get_ssid (WifiData *data); GByteArray *wifi_utils_get_ssid (WifiData *data);
/* Caller must free returned byte array */ /* out_bssid must be ETH_ALEN bytes */
gboolean wifi_utils_get_bssid (WifiData *data, struct ether_addr *out_bssid); gboolean wifi_utils_get_bssid (WifiData *data, guint8 *out_bssid);
/* Returns current bitrate in Kbps */ /* Returns current bitrate in Kbps */
guint32 wifi_utils_get_rate (WifiData *data); guint32 wifi_utils_get_rate (WifiData *data);

View File

@@ -1732,15 +1732,11 @@ mac_equal (gconstpointer a, gconstpointer b)
} }
static guint8 * static guint8 *
mac_dup (const struct ether_addr *old) mac_dup (const guint8 *old)
{ {
guint8 *new;
g_return_val_if_fail (old != NULL, NULL); g_return_val_if_fail (old != NULL, NULL);
new = g_malloc0 (ETH_ALEN); return g_memdup (old, ETH_ALEN);
memcpy (new, old, ETH_ALEN);
return new;
} }
/** /**
@@ -1778,7 +1774,7 @@ nm_settings_connection_get_seen_bssids (NMSettingsConnection *connection)
**/ **/
gboolean gboolean
nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection, nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection,
const struct ether_addr *bssid) const guint8 *bssid)
{ {
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE);
g_return_val_if_fail (bssid != NULL, FALSE); g_return_val_if_fail (bssid != NULL, FALSE);
@@ -1796,7 +1792,7 @@ nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection,
**/ **/
void void
nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection, nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection,
const struct ether_addr *seen_bssid) const guint8 *seen_bssid)
{ {
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (connection);
const char *connection_uuid; const char *connection_uuid;
@@ -1856,12 +1852,12 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection,
static void static void
add_seen_bssid_string (NMSettingsConnection *self, const char *bssid) add_seen_bssid_string (NMSettingsConnection *self, const char *bssid)
{ {
struct ether_addr mac; guint8 mac[ETH_ALEN];
g_return_if_fail (bssid != NULL); g_return_if_fail (bssid != NULL);
if (ether_aton_r (bssid, &mac)) { if (nm_utils_hwaddr_aton (bssid, mac, ETH_ALEN)) {
g_hash_table_insert (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->seen_bssids, g_hash_table_insert (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->seen_bssids,
mac_dup (&mac), mac_dup (mac),
g_strdup (bssid)); g_strdup (bssid));
} }
} }

View File

@@ -141,10 +141,10 @@ void nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *conne
GSList *nm_settings_connection_get_seen_bssids (NMSettingsConnection *connection); GSList *nm_settings_connection_get_seen_bssids (NMSettingsConnection *connection);
gboolean nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection, gboolean nm_settings_connection_has_seen_bssid (NMSettingsConnection *connection,
const struct ether_addr *bssid); const guint8 *bssid);
void nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection, void nm_settings_connection_add_seen_bssid (NMSettingsConnection *connection,
const struct ether_addr *seen_bssid); const guint8 *seen_bssid);
void nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connection); void nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *connection);

View File

@@ -434,16 +434,15 @@ fill_ip4_setting_from_ibft (shvarFile *ifcfg,
/* HWADDR */ /* HWADDR */
if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_HWADDR_TAG, &skip))) { if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_HWADDR_TAG, &skip))) {
struct ether_addr *ibft_mac; guint8 *ibft_mac[ETH_ALEN];
ibft_mac = ether_aton (p); if (!nm_utils_hwaddr_aton (p, ibft_mac, ETH_ALEN)) {
if (!ibft_mac) {
PARSE_WARNING ("malformed iscsiadm record: invalid hwaddress."); PARSE_WARNING ("malformed iscsiadm record: invalid hwaddress.");
skip = TRUE; skip = TRUE;
continue; continue;
} }
if (memcmp (ifcfg_mac->data, (guint8 *) ibft_mac->ether_addr_octet, ETH_ALEN)) { if (memcmp (ifcfg_mac->data, ibft_mac, ETH_ALEN)) {
/* This record isn't for the current device, ignore it */ /* This record isn't for the current device, ignore it */
skip = TRUE; skip = TRUE;
continue; continue;
@@ -3570,13 +3569,12 @@ make_wireless_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE);
if (value) { if (value) {
char **list = NULL, **iter; char **list = NULL, **iter;
struct ether_addr addr;
list = g_strsplit_set (value, " \t", 0); list = g_strsplit_set (value, " \t", 0);
for (iter = list; iter && *iter; iter++) { for (iter = list; iter && *iter; iter++) {
if (**iter == '\0') if (**iter == '\0')
continue; continue;
if (!ether_aton_r (*iter, &addr)) { if (!nm_utils_hwaddr_valid (*iter, ETH_ALEN)) {
PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *iter); PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *iter);
continue; continue;
} }
@@ -3946,13 +3944,12 @@ make_wired_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE);
if (value) { if (value) {
char **list = NULL, **iter; char **list = NULL, **iter;
struct ether_addr addr;
list = g_strsplit_set (value, " \t", 0); list = g_strsplit_set (value, " \t", 0);
for (iter = list; iter && *iter; iter++) { for (iter = list; iter && *iter; iter++) {
if (**iter == '\0') if (**iter == '\0')
continue; continue;
if (!ether_aton_r (*iter, &addr)) { if (!nm_utils_hwaddr_valid (*iter, ETH_ALEN)) {
PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *iter); PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *iter);
continue; continue;
} }