From a3f6af817bbd17008e2cdbe774f1bd22ec93680d Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 12 Feb 2013 17:59:37 -0500 Subject: [PATCH] core: simplify nm_device_spec_match_list() Since NMDevice has a generic get_hw_address() method now, it can do nm_device_spec_match_list() itself (for everything except ethernet, which needs to match against s390 subchannels too). https://bugzilla.gnome.org/show_bug.cgi?id=693684 --- src/nm-device-bond.c | 15 --------------- src/nm-device-bridge.c | 15 --------------- src/nm-device-ethernet.c | 12 +++--------- src/nm-device-infiniband.c | 15 --------------- src/nm-device-vlan.c | 16 ---------------- src/nm-device-wifi.c | 15 --------------- src/nm-device.c | 19 +++++++++++++++++++ 7 files changed, 22 insertions(+), 85 deletions(-) diff --git a/src/nm-device-bond.c b/src/nm-device-bond.c index 45522b7917..064011ee2e 100644 --- a/src/nm-device-bond.c +++ b/src/nm-device-bond.c @@ -223,20 +223,6 @@ complete_connection (NMDevice *device, return TRUE; } -static gboolean -spec_match_list (NMDevice *device, const GSList *specs) -{ - NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device); - char *hwaddr; - gboolean matched; - - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len)); - matched = nm_match_spec_hwaddr (specs, hwaddr); - g_free (hwaddr); - - return matched; -} - static gboolean bond_match_config (NMDevice *self, NMConnection *connection) { @@ -462,7 +448,6 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; - parent_class->spec_match_list = spec_match_list; parent_class->connection_match_config = connection_match_config; parent_class->act_stage1_prepare = act_stage1_prepare; diff --git a/src/nm-device-bridge.c b/src/nm-device-bridge.c index 1da45826ae..82e9f565a9 100644 --- a/src/nm-device-bridge.c +++ b/src/nm-device-bridge.c @@ -225,20 +225,6 @@ complete_connection (NMDevice *device, return TRUE; } -static gboolean -spec_match_list (NMDevice *device, const GSList *specs) -{ - NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device); - char *hwaddr; - gboolean matched; - - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, nm_utils_hwaddr_type (priv->hw_addr_len)); - matched = nm_match_spec_hwaddr (specs, hwaddr); - g_free (hwaddr); - - return matched; -} - static gboolean bridge_match_config (NMDevice *self, NMConnection *connection) { @@ -518,7 +504,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; - parent_class->spec_match_list = spec_match_list; parent_class->connection_match_config = connection_match_config; parent_class->act_stage1_prepare = act_stage1_prepare; diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c index 44049ccfb7..7279f191da 100644 --- a/src/nm-device-ethernet.c +++ b/src/nm-device-ethernet.c @@ -1352,17 +1352,11 @@ static gboolean spec_match_list (NMDevice *device, const GSList *specs) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device); - char *hwaddr; - gboolean matched; - hwaddr = nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER); - matched = nm_match_spec_hwaddr (specs, hwaddr); - g_free (hwaddr); + if (priv->subchannels && nm_match_spec_s390_subchannels (specs, priv->subchannels)) + return TRUE; - if (!matched && priv->subchannels) - matched = nm_match_spec_s390_subchannels (specs, priv->subchannels); - - return matched; + return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->spec_match_list (device, specs); } static NMConnection * diff --git a/src/nm-device-infiniband.c b/src/nm-device-infiniband.c index c7dcf19c87..03e37dc05d 100644 --- a/src/nm-device-infiniband.c +++ b/src/nm-device-infiniband.c @@ -332,20 +332,6 @@ complete_connection (NMDevice *device, return TRUE; } -static gboolean -spec_match_list (NMDevice *device, const GSList *specs) -{ - NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device); - char *hwaddr; - gboolean matched; - - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, ARPHRD_INFINIBAND); - matched = nm_match_spec_hwaddr (specs, hwaddr); - g_free (hwaddr); - - return matched; -} - static gboolean infiniband_match_config (NMDevice *self, NMConnection *connection) { @@ -476,7 +462,6 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass) parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->ip4_config_pre_commit = 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; diff --git a/src/nm-device-vlan.c b/src/nm-device-vlan.c index 7eb3d8d4ed..159122f504 100644 --- a/src/nm-device-vlan.c +++ b/src/nm-device-vlan.c @@ -354,21 +354,6 @@ complete_connection (NMDevice *device, return TRUE; } -static gboolean -spec_match_list (NMDevice *device, const GSList *specs) -{ - NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); - char *hwaddr; - gboolean matched; - int itype = nm_utils_hwaddr_type (priv->hw_addr_len); - - hwaddr = nm_utils_hwaddr_ntoa (priv->hw_addr, itype); - matched = nm_match_spec_hwaddr (specs, hwaddr); - g_free (hwaddr); - - return matched; -} - static gboolean vlan_match_config (NMDevice *device, NMConnection *connection) { @@ -673,7 +658,6 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) parent_class->get_best_auto_connection = get_best_auto_connection; parent_class->check_connection_compatible = check_connection_compatible; parent_class->complete_connection = complete_connection; - parent_class->spec_match_list = spec_match_list; parent_class->connection_match_config = connection_match_config; /* properties */ diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index 4f143f3366..8949a95602 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -3427,20 +3427,6 @@ get_type_capabilities (NMDevice *dev) } -static gboolean -spec_match_list (NMDevice *device, const GSList *specs) -{ - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); - char *hwaddr; - gboolean matched; - - hwaddr = nm_utils_hwaddr_ntoa (&priv->perm_hw_addr, ARPHRD_ETHER); - matched = nm_match_spec_hwaddr (specs, hwaddr); - g_free (hwaddr); - - return matched; -} - static gboolean hwaddr_matches (NMDevice *device, NMConnection *connection, @@ -3779,7 +3765,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) parent_class->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout; parent_class->deactivate = deactivate; parent_class->can_interrupt_activation = can_interrupt_activation; - parent_class->spec_match_list = spec_match_list; parent_class->hwaddr_matches = hwaddr_matches; parent_class->state_changed = device_state_changed; diff --git a/src/nm-device.c b/src/nm-device.c index 4b9b9737e3..386e5487c6 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -284,6 +284,8 @@ static gboolean nm_device_activate_ip6_config_commit (gpointer user_data); static gboolean check_connection_available (NMDevice *device, NMConnection *connection); +static gboolean spec_match_list (NMDevice *device, const GSList *specs); + static void _clear_available_connections (NMDevice *device, gboolean do_signal); static void dhcp4_cleanup (NMDevice *self, gboolean stop, gboolean release); @@ -4745,6 +4747,7 @@ nm_device_class_init (NMDeviceClass *klass) klass->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout; klass->have_any_ready_slaves = have_any_ready_slaves; + klass->spec_match_list = spec_match_list; klass->check_connection_available = check_connection_available; klass->hw_is_up = hw_is_up; klass->hw_bring_up = hw_bring_up; @@ -5470,6 +5473,22 @@ nm_device_spec_match_list (NMDevice *device, const GSList *specs) return FALSE; } +static gboolean +spec_match_list (NMDevice *device, const GSList *specs) +{ + const guint8 *hwaddr; + guint hwaddr_len = 0; + char *hwaddr_str; + gboolean matched; + + hwaddr = nm_device_get_hw_address (device, &hwaddr_len); + hwaddr_str = nm_utils_hwaddr_ntoa (hwaddr, nm_utils_hwaddr_type (hwaddr_len)); + matched = nm_match_spec_hwaddr (specs, hwaddr_str); + g_free (hwaddr_str); + + return matched; +} + static gboolean ip4_match_config (NMDevice *self, NMConnection *connection) {