libnm-glib: match interface name in nm_device_connection_compatible()

Do NMSettingConnection:interface-name matching on the client side as
well, so that, eg, nm-applet does not list connections under the wrong
device.

(Also, move some return-if-fail checks from the subclass method
implementations into the wrapper function.)

https://bugzilla.gnome.org/show_bug.cgi?id=693684
This commit is contained in:
Dan Winship 2013-03-11 10:16:24 -04:00
parent c308e75b92
commit dbbec9b7d7
14 changed files with 71 additions and 34 deletions

View file

@ -89,6 +89,8 @@ global:
nm_device_connection_compatible;
nm_device_connection_valid;
nm_device_disconnect;
nm_device_error_get_type;
nm_device_error_quark;
nm_device_ethernet_error_get_type;
nm_device_ethernet_error_quark;
nm_device_ethernet_get_carrier;

View file

@ -131,7 +131,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
return FALSE;
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->connection_compatible (device, connection, error);
}
/******************************************************************/

View file

@ -165,8 +165,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
NMSettingBond *s_bond;
const char *ctype, *dev_iface_name, *bond_iface_name;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -194,7 +192,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
/* FIXME: check slaves? */
return TRUE;
return NM_DEVICE_CLASS (nm_device_bond_parent_class)->connection_compatible (device, connection, error);
}
/***********************************************************/

View file

@ -173,8 +173,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
NMSettingBridge *s_bridge;
const char *ctype, *dev_iface_name, *bridge_iface_name;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -202,7 +200,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
/* FIXME: check ports? */
return TRUE;
return NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_compatible (device, connection, error);
}
/***********************************************************/

View file

@ -182,8 +182,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
NMBluetoothCapabilities dev_caps;
NMBluetoothCapabilities bt_type;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -226,7 +224,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
return FALSE;
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_bt_parent_class)->connection_compatible (device, connection, error);
}
/************************************************************/

View file

@ -183,8 +183,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const char *ctype;
gboolean is_pppoe = FALSE;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -230,7 +228,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
}
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error);
}
/***********************************************************/

View file

@ -143,8 +143,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const GByteArray *mac;
guint8 *hwaddr, hwaddr_buf[INFINIBAND_ALEN];
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -178,7 +176,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
}
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->connection_compatible (device, connection, error);
}
/***********************************************************/

View file

@ -123,8 +123,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const char *ctype;
NMDeviceModemCapabilities current_caps;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -152,7 +150,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
return FALSE;
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error);
}
/*******************************************************************/

View file

@ -161,8 +161,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
NMSettingOlpcMesh *s_olpc_mesh;
const char *ctype;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -180,7 +178,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
return FALSE;
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_olpc_mesh_parent_class)->connection_compatible (device, connection, error);
}
/**************************************************************/

View file

@ -158,8 +158,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
NMSettingVlan *s_vlan;
const char *ctype, *dev_iface_name, *vlan_iface_name;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -191,7 +189,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
return FALSE;
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error);
}
/***********************************************************/

View file

@ -491,8 +491,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
NMDeviceWifiCapabilities wifi_caps;
const char *key_mgmt;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -554,7 +552,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
}
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->connection_compatible (device, connection, error);
}
/**************************************************************/

View file

@ -390,8 +390,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
const char *hw_str;
struct ether_addr *hw_mac;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
@ -426,7 +424,7 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro
}
}
return TRUE;
return NM_DEVICE_CLASS (nm_device_wimax_parent_class)->connection_compatible (device, connection, error);
}
/**************************************************************/

View file

@ -53,6 +53,7 @@ static void _nm_device_type_for_path_async (DBusGConnection *connection,
const char *path,
NMObjectTypeCallbackFunc callback,
gpointer user_data);
gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error);
G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT,
_nm_object_register_type_func (g_define_type_id, _nm_device_type_for_path,
@ -128,6 +129,22 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
/**
* nm_device_error_quark:
*
* Registers an error quark for #NMDevice if necessary.
*
* Returns: the error quark used for #NMDevice errors.
**/
GQuark
nm_device_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-error-quark");
return quark;
}
static void
nm_device_init (NMDevice *device)
@ -492,6 +509,8 @@ nm_device_class_init (NMDeviceClass *device_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
device_class->connection_compatible = connection_compatible;
/* properties */
/**
@ -1589,6 +1608,26 @@ nm_device_connection_valid (NMDevice *device, NMConnection *connection)
return nm_device_connection_compatible (device, connection, NULL);
}
gboolean
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 && g_strcmp0 (config_iface, device_iface) != 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INTERFACE_MISMATCH,
"The interface names of the device and the connection didn't match.");
return FALSE;
}
return TRUE;
}
/**
* nm_device_connection_compatible:
* @device: an #NMDevice to validate @connection against
@ -1613,9 +1652,11 @@ nm_device_connection_valid (NMDevice *device, NMConnection *connection)
gboolean
nm_device_connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
if (NM_DEVICE_GET_CLASS (device)->connection_compatible)
return NM_DEVICE_GET_CLASS (device)->connection_compatible (device, connection, error);
return FALSE;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return NM_DEVICE_GET_CLASS (device)->connection_compatible (device, connection, error);
}
/**

View file

@ -45,6 +45,20 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE))
#define NM_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE, NMDeviceClass))
/**
* NMDeviceError:
* @NM_DEVICE_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_ERROR_INTERFACE_MISMATCH: the interface names of the connection and the
* device mismatched
*/
typedef enum {
NM_DEVICE_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_ERROR_INTERFACE_MISMATCH, /*< nick=InterfaceMismatch >*/
} NMDeviceError;
#define NM_DEVICE_ERROR nm_device_error_quark ()
GQuark nm_device_error_quark (void);
#define NM_DEVICE_DEVICE_TYPE "device-type"
#define NM_DEVICE_UDI "udi"
#define NM_DEVICE_INTERFACE "interface"