From 611df342afafc11eb256fcab4cdb0832066aeaa4 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 7 Mar 2013 07:44:36 -0500 Subject: [PATCH] core: make nm_device_check_connection_compatible() check interface-name If an NMConnection specifies an interface-name, it is only compatible with a device with the same iface. https://bugzilla.gnome.org/show_bug.cgi?id=693684 --- src/nm-device-adsl.c | 3 +++ src/nm-device-bond.c | 3 +++ src/nm-device-bridge.c | 3 +++ src/nm-device-bt.c | 3 +++ src/nm-device-ethernet.c | 3 +++ src/nm-device-infiniband.c | 3 +++ src/nm-device-modem.c | 3 +++ src/nm-device-olpc-mesh.c | 3 +++ src/nm-device-vlan.c | 3 +++ src/nm-device-wifi.c | 3 +++ src/nm-device.c | 24 +++++++++++++++++++++--- src/wimax/nm-device-wimax.c | 3 +++ 12 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/nm-device-adsl.c b/src/nm-device-adsl.c index f92f3c4064..e4fc2cf0eb 100644 --- a/src/nm-device-adsl.c +++ b/src/nm-device-adsl.c @@ -143,6 +143,9 @@ check_connection_compatible (NMDevice *device, NMSettingAdsl *s_adsl; const char *protocol; + if (!NM_DEVICE_CLASS (nm_device_adsl_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + if (!nm_connection_is_type (connection, NM_SETTING_ADSL_SETTING_NAME)) { g_set_error (error, NM_ADSL_ERROR, NM_ADSL_ERROR_CONNECTION_NOT_ADSL, diff --git a/src/nm-device-bond.c b/src/nm-device-bond.c index 085eda8ef1..32dd396603 100644 --- a/src/nm-device-bond.c +++ b/src/nm-device-bond.c @@ -124,6 +124,9 @@ check_connection_compatible (NMDevice *device, const char *iface; NMSettingBond *s_bond; + if (!NM_DEVICE_CLASS (nm_device_bond_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_bond = nm_connection_get_setting_bond (connection); if (!s_bond || !nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) { g_set_error (error, NM_BOND_ERROR, NM_BOND_ERROR_CONNECTION_NOT_BOND, diff --git a/src/nm-device-bridge.c b/src/nm-device-bridge.c index f9ba0f72e5..9b8719c159 100644 --- a/src/nm-device-bridge.c +++ b/src/nm-device-bridge.c @@ -124,6 +124,9 @@ check_connection_compatible (NMDevice *device, const char *iface; NMSettingBridge *s_bridge; + if (!NM_DEVICE_CLASS (nm_device_bridge_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_bridge = nm_connection_get_setting_bridge (connection); if (!s_bridge || !nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) { g_set_error (error, NM_BRIDGE_ERROR, NM_BRIDGE_ERROR_CONNECTION_NOT_BRIDGE, diff --git a/src/nm-device-bt.c b/src/nm-device-bt.c index c517e28b76..1774a4f6bb 100644 --- a/src/nm-device-bt.c +++ b/src/nm-device-bt.c @@ -170,6 +170,9 @@ check_connection_compatible (NMDevice *device, int addr_match = FALSE; guint32 bt_type; + if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c index 0655fabdf6..4c08baa326 100644 --- a/src/nm-device-ethernet.c +++ b/src/nm-device-ethernet.c @@ -553,6 +553,9 @@ check_connection_compatible (NMDevice *device, NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); NMSettingWired *s_wired; + if (!NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_wired = nm_connection_get_setting_wired (connection); if (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) { diff --git a/src/nm-device-infiniband.c b/src/nm-device-infiniband.c index a20b347e3a..d71d4ba47d 100644 --- a/src/nm-device-infiniband.c +++ b/src/nm-device-infiniband.c @@ -220,6 +220,9 @@ check_connection_compatible (NMDevice *device, NMSettingInfiniband *s_infiniband; const GByteArray *mac; + if (!NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) { g_set_error (error, NM_INFINIBAND_ERROR, diff --git a/src/nm-device-modem.c b/src/nm-device-modem.c index 0453d08036..a203fb8827 100644 --- a/src/nm-device-modem.c +++ b/src/nm-device-modem.c @@ -228,6 +228,9 @@ check_connection_compatible (NMDevice *device, { NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device); + if (!NM_DEVICE_CLASS (nm_device_modem_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + return nm_modem_check_connection_compatible (priv->modem, connection, error); } diff --git a/src/nm-device-olpc-mesh.c b/src/nm-device-olpc-mesh.c index 302383c898..076b012394 100644 --- a/src/nm-device-olpc-mesh.c +++ b/src/nm-device-olpc-mesh.c @@ -231,6 +231,9 @@ check_connection_compatible (NMDevice *device, NMSettingConnection *s_con; NMSettingOlpcMesh *s_mesh; + if (!NM_DEVICE_CLASS (nm_device_olpc_mesh_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); diff --git a/src/nm-device-vlan.c b/src/nm-device-vlan.c index a72bf1dac7..3f60178a80 100644 --- a/src/nm-device-vlan.c +++ b/src/nm-device-vlan.c @@ -248,6 +248,9 @@ check_connection_compatible (NMDevice *device, NMSettingVlan *s_vlan; const char *parent, *iface = NULL; + if (!NM_DEVICE_CLASS (nm_device_vlan_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_vlan = nm_connection_get_setting_vlan (connection); if (!s_vlan) { g_set_error (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID, diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index f0be008986..7ac2acf7af 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -1022,6 +1022,9 @@ check_connection_compatible (NMDevice *device, const GSList *mac_blacklist, *mac_blacklist_iter; const char *mode; + if (!NM_DEVICE_CLASS (nm_device_wifi_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); diff --git a/src/nm-device.c b/src/nm-device.c index 2b99e25b80..1b52a573c2 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1461,6 +1461,25 @@ nm_device_complete_connection (NMDevice *self, return success; } +static gboolean +check_connection_compatible (NMDevice *device, + NMConnection *connection, + GError **error) +{ + NMSettingConnection *s_con; + const char *config_iface, *device_iface; + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + + config_iface = nm_setting_connection_get_interface_name (s_con); + device_iface = nm_device_get_iface (device); + if (config_iface && strcmp (config_iface, device_iface) != 0) + return FALSE; + + return TRUE; +} + gboolean nm_device_check_connection_compatible (NMDevice *device, NMConnection *connection, @@ -1469,9 +1488,7 @@ nm_device_check_connection_compatible (NMDevice *device, g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); - if (NM_DEVICE_GET_CLASS (device)->check_connection_compatible) - return NM_DEVICE_GET_CLASS (device)->check_connection_compatible (device, connection, error); - return TRUE; + return NM_DEVICE_GET_CLASS (device)->check_connection_compatible (device, connection, error); } gboolean @@ -4748,6 +4765,7 @@ nm_device_class_init (NMDeviceClass *klass) klass->spec_match_list = spec_match_list; klass->can_auto_connect = can_auto_connect; + klass->check_connection_compatible = check_connection_compatible; klass->check_connection_available = check_connection_available; klass->hw_is_up = hw_is_up; klass->hw_bring_up = hw_bring_up; diff --git a/src/wimax/nm-device-wimax.c b/src/wimax/nm-device-wimax.c index f704f7b051..50033fdfae 100644 --- a/src/wimax/nm-device-wimax.c +++ b/src/wimax/nm-device-wimax.c @@ -420,6 +420,9 @@ check_connection_compatible (NMDevice *device, const char *connection_type; const GByteArray *mac; + if (!NM_DEVICE_CLASS (nm_device_wimax_parent_class)->check_connection_compatible (device, connection, error)) + return FALSE; + s_con = nm_connection_get_setting_connection (connection); g_assert (s_con);