Commit 13c8d2c5 authored by Dan Williams's avatar Dan Williams
Browse files

core: add NMDevice hwaddr_matches() class method

Match the device's hardware address with a connection.
parent c1a66936
......@@ -45,6 +45,7 @@
#include "nm-device-bt-glue.h"
#include "NetworkManagerUtils.h"
#include "nm-enum-types.h"
#include "nm-utils.h"
#define BLUETOOTH_DUN_UUID "dun"
#define BLUETOOTH_NAP_UUID "nap"
......@@ -373,6 +374,33 @@ real_get_generic_capabilities (NMDevice *dev)
return NM_DEVICE_CAP_NM_SUPPORTED;
}
static gboolean
hwaddr_matches (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
NMSettingBluetooth *s_bt;
const GByteArray *mac = NULL;
gboolean matches = FALSE;
GByteArray *devmac;
s_bt = nm_connection_get_setting_bluetooth (connection);
if (s_bt)
mac = nm_setting_bluetooth_get_bdaddr (s_bt);
if (mac) {
devmac = nm_utils_hwaddr_atoba (priv->bdaddr, ARPHRD_ETHER);
g_return_val_if_fail (devmac != NULL, FALSE);
g_return_val_if_fail (devmac->len == mac->len, FALSE);
matches = (memcmp (mac->data, devmac->data, mac->len) == 0) ? TRUE : FALSE;
g_byte_array_free (devmac, TRUE);
return matches;
} else if (fail_if_no_hwaddr == FALSE)
return TRUE;
return FALSE;
}
/*****************************************************************************/
/* IP method PPP */
......@@ -1095,6 +1123,7 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
device_class->act_stage3_ip4_config_start = real_act_stage3_ip4_config_start;
device_class->check_connection_compatible = real_check_connection_compatible;
device_class->complete_connection = real_complete_connection;
device_class->hwaddr_matches = hwaddr_matches;
/* Properties */
g_object_class_install_property
......
......@@ -1526,6 +1526,32 @@ connection_match_config (NMDevice *self, const GSList *connections)
return match;
}
static gboolean
hwaddr_matches (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
NMSettingWired *s_wired;
const guint8 *devaddr;
const GByteArray *mac = NULL;
int devtype;
devtype = nm_device_wired_get_hwaddr_type (NM_DEVICE_WIRED (device));
devaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (device));
g_return_val_if_fail (devaddr != NULL, FALSE);
s_wired = nm_connection_get_setting_wired (connection);
if (s_wired)
mac = nm_setting_wired_get_mac_address (s_wired);
if (mac) {
g_return_val_if_fail (mac->len == ETH_ALEN, FALSE);
if (memcmp (mac->data, devaddr, mac->len) == 0)
return TRUE;
} else if (fail_if_no_hwaddr == FALSE)
return TRUE;
return FALSE;
}
static void
dispose (GObject *object)
{
......@@ -1611,6 +1637,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
parent_class->deactivate = real_deactivate;
parent_class->spec_match_list = spec_match_list;
parent_class->connection_match_config = connection_match_config;
parent_class->hwaddr_matches = hwaddr_matches;
/* properties */
g_object_class_install_property
......
......@@ -394,6 +394,32 @@ connection_match_config (NMDevice *self, const GSList *connections)
return match;
}
static gboolean
hwaddr_matches (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
NMSettingInfiniband *s_ib;
const guint8 *devaddr;
const GByteArray *mac = NULL;
int devtype;
devtype = nm_device_wired_get_hwaddr_type (NM_DEVICE_WIRED (device));
devaddr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (device));
g_return_val_if_fail (devaddr != NULL, FALSE);
s_ib = nm_connection_get_setting_infiniband (connection);
if (s_ib)
mac = nm_setting_infiniband_get_mac_address (s_ib);
if (mac) {
g_return_val_if_fail (mac->len == INFINIBAND_ALEN, FALSE);
if (memcmp (mac->data, devaddr, mac->len) == 0)
return TRUE;
} else if (fail_if_no_hwaddr == FALSE)
return TRUE;
return FALSE;
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
......@@ -448,6 +474,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
parent_class->ip4_config_pre_commit = real_ip4_config_pre_commit;
parent_class->spec_match_list = spec_match_list;
parent_class->connection_match_config = connection_match_config;
parent_class->hwaddr_matches = hwaddr_matches;
/* properties */
g_object_class_install_property
......
......@@ -2927,6 +2927,27 @@ spec_match_list (NMDevice *device, const GSList *specs)
return matched;
}
static gboolean
hwaddr_matches (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
NMSettingWireless *s_wifi;
const GByteArray *mac = NULL;
s_wifi = nm_connection_get_setting_wireless (connection);
if (s_wifi)
mac = nm_setting_wireless_get_mac_address (s_wifi);
if (mac) {
g_return_val_if_fail (mac->len == ETH_ALEN, FALSE);
if (memcmp (mac->data, priv->hw_addr, mac->len) == 0)
return TRUE;
} else if (fail_if_no_hwaddr == FALSE)
return TRUE;
return FALSE;
}
static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
......@@ -3235,6 +3256,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
parent_class->deactivate = real_deactivate;
parent_class->can_interrupt_activation = real_can_interrupt_activation;
parent_class->spec_match_list = spec_match_list;
parent_class->hwaddr_matches = hwaddr_matches;
klass->scanning_allowed = scanning_allowed;
......
......@@ -4323,6 +4323,19 @@ nm_device_connection_match_config (NMDevice *device, const GSList *connections)
return NULL;
}
gboolean
nm_device_hwaddr_matches (NMDevice *device,
NMConnection *connection,
gboolean fail_if_no_hwaddr)
{
g_return_val_if_fail (device != NULL, FALSE);
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
if (NM_DEVICE_GET_CLASS (device)->hwaddr_matches)
return NM_DEVICE_GET_CLASS (device)->hwaddr_matches (device, connection, fail_if_no_hwaddr);
return FALSE;
}
void
nm_device_set_dhcp_timeout (NMDevice *device, guint32 timeout)
{
......
......@@ -154,6 +154,10 @@ typedef struct {
gboolean (* spec_match_list) (NMDevice *self, const GSList *specs);
NMConnection * (* connection_match_config) (NMDevice *self, const GSList *connections);
gboolean (* hwaddr_matches) (NMDevice *self,
NMConnection *connection,
gboolean fail_if_no_hwaddr);
} NMDeviceClass;
......@@ -207,6 +211,10 @@ gboolean nm_device_can_assume_connections (NMDevice *device);
NMConnection * nm_device_connection_match_config (NMDevice *device,
const GSList *connections);
gboolean nm_device_hwaddr_matches (NMDevice *device,
NMConnection *connection,
gboolean fail_if_no_hwaddr);
gboolean nm_device_spec_match_list (NMDevice *device, const GSList *specs);
gboolean nm_device_is_activating (NMDevice *dev);
......
......@@ -409,6 +409,27 @@ real_update_hw_address (NMDevice *dev)
close (fd);
}
static gboolean
hwaddr_matches (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
{
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device);
NMSettingWimax *s_wimax;
const GByteArray *mac = NULL;
s_wimax = nm_connection_get_setting_wimax (connection);
if (s_wimax)
mac = nm_setting_wimax_get_mac_address (s_wimax);
if (mac) {
g_return_val_if_fail (mac->len == ETH_ALEN, FALSE);
if (memcmp (mac->data, priv->hw_addr.ether_addr_octet, mac->len) == 0)
return TRUE;
} else if (fail_if_no_hwaddr == FALSE)
return TRUE;
return FALSE;
}
static gboolean
real_check_connection_compatible (NMDevice *device,
NMConnection *connection,
......@@ -1483,6 +1504,7 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *klass)
device_class->act_stage2_config = real_act_stage2_config;
device_class->deactivate = real_deactivate;
device_class->set_enabled = real_set_enabled;
device_class->hwaddr_matches = hwaddr_matches;
/* Properties */
g_object_class_install_property
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment