diff options
-rw-r--r-- | libnm-glib/libnm-glib.ver | 1 | ||||
-rw-r--r-- | libnm-glib/nm-device-adsl.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-bond.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-bridge.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-bt.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-ethernet.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-generic.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-infiniband.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-modem.c | 15 | ||||
-rw-r--r-- | libnm-glib/nm-device-olpc-mesh.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-team.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-vlan.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-wifi.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device-wimax.c | 7 | ||||
-rw-r--r-- | libnm-glib/nm-device.c | 19 | ||||
-rw-r--r-- | libnm-glib/nm-device.h | 6 | ||||
-rw-r--r-- | libnm-util/libnm-util.ver | 1 | ||||
-rw-r--r-- | libnm-util/nm-setting-private.h | 1 | ||||
-rw-r--r-- | libnm-util/nm-setting.c | 26 | ||||
-rw-r--r-- | libnm-util/nm-utils.c | 62 | ||||
-rw-r--r-- | libnm-util/nm-utils.h | 3 |
21 files changed, 207 insertions, 11 deletions
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver index aa6f913d04..982288e50c 100644 --- a/libnm-glib/libnm-glib.ver +++ b/libnm-glib/libnm-glib.ver @@ -143,6 +143,7 @@ global: nm_device_get_mtu; nm_device_get_physical_port_id; nm_device_get_product; + nm_device_get_setting_type; nm_device_get_state; nm_device_get_state_reason; nm_device_get_type; diff --git a/libnm-glib/nm-device-adsl.c b/libnm-glib/nm-device-adsl.c index e2db4da78f..b3f9691ee8 100644 --- a/libnm-glib/nm-device-adsl.c +++ b/libnm-glib/nm-device-adsl.c @@ -133,6 +133,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_ADSL; +} + /******************************************************************/ static void @@ -221,6 +227,7 @@ nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; /* properties */ /** diff --git a/libnm-glib/nm-device-bond.c b/libnm-glib/nm-device-bond.c index 259f4dfcc0..b2af2ec349 100644 --- a/libnm-glib/nm-device-bond.c +++ b/libnm-glib/nm-device-bond.c @@ -191,6 +191,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_bond_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_BOND; +} + static const char * get_hw_address (NMDevice *device) { @@ -298,6 +304,7 @@ nm_device_bond_class_init (NMDeviceBondClass *eth_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-bridge.c b/libnm-glib/nm-device-bridge.c index 3709814de0..c8967e2031 100644 --- a/libnm-glib/nm-device-bridge.c +++ b/libnm-glib/nm-device-bridge.c @@ -199,6 +199,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_BRIDGE; +} + static const char * get_hw_address (NMDevice *device) { @@ -306,6 +312,7 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-bt.c b/libnm-glib/nm-device-bt.c index 0de34b79d1..4c39ad049c 100644 --- a/libnm-glib/nm-device-bt.c +++ b/libnm-glib/nm-device-bt.c @@ -223,6 +223,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_bt_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_BLUETOOTH; +} + static const char * get_hw_address (NMDevice *device) { @@ -325,6 +331,7 @@ nm_device_bt_class_init (NMDeviceBtClass *bt_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-ethernet.c b/libnm-glib/nm-device-ethernet.c index 38424d2068..efdb3228c2 100644 --- a/libnm-glib/nm-device-ethernet.c +++ b/libnm-glib/nm-device-ethernet.c @@ -226,6 +226,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_WIRED; +} + static const char * get_hw_address (NMDevice *device) { @@ -332,6 +338,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-generic.c b/libnm-glib/nm-device-generic.c index fa4247be5c..2a45294f3c 100644 --- a/libnm-glib/nm-device-generic.c +++ b/libnm-glib/nm-device-generic.c @@ -157,6 +157,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_generic_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_GENERIC; +} + /***********************************************************/ static void @@ -251,6 +257,7 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) device_class->get_type_description = get_type_description; device_class->get_hw_address = get_hw_address; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; /** * NMDeviceGeneric:hw-address: diff --git a/libnm-glib/nm-device-infiniband.c b/libnm-glib/nm-device-infiniband.c index 678269d94b..b60b2d8215 100644 --- a/libnm-glib/nm-device-infiniband.c +++ b/libnm-glib/nm-device-infiniband.c @@ -178,6 +178,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_INFINIBAND; +} + static const char * get_hw_address (NMDevice *device) { @@ -275,6 +281,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *eth_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-modem.c b/libnm-glib/nm-device-modem.c index d20f4f28a6..b3b357cffa 100644 --- a/libnm-glib/nm-device-modem.c +++ b/libnm-glib/nm-device-modem.c @@ -167,6 +167,20 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + NMDeviceModemCapabilities caps; + + caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device)); + if (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE)) + return NM_TYPE_SETTING_GSM; + else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) + return NM_TYPE_SETTING_CDMA; + else + return G_TYPE_INVALID; +} + /*******************************************************************/ static void @@ -249,6 +263,7 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class) device_class->get_type_description = get_type_description; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; /** * NMDeviceModem:modem-capabilities: diff --git a/libnm-glib/nm-device-olpc-mesh.c b/libnm-glib/nm-device-olpc-mesh.c index 058727f3ce..d1789eb943 100644 --- a/libnm-glib/nm-device-olpc-mesh.c +++ b/libnm-glib/nm-device-olpc-mesh.c @@ -183,6 +183,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_olpc_mesh_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_OLPC_MESH; +} + /**************************************************************/ static void @@ -279,6 +285,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-team.c b/libnm-glib/nm-device-team.c index 0f0eb31e22..f739e1d842 100644 --- a/libnm-glib/nm-device-team.c +++ b/libnm-glib/nm-device-team.c @@ -203,6 +203,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_team_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_TEAM; +} + /***********************************************************/ static void @@ -304,6 +310,7 @@ nm_device_team_class_init (NMDeviceTeamClass *eth_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-vlan.c b/libnm-glib/nm-device-vlan.c index 07c7e1a4a9..2a84b94659 100644 --- a/libnm-glib/nm-device-vlan.c +++ b/libnm-glib/nm-device-vlan.c @@ -205,6 +205,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_VLAN; +} + static const char * get_hw_address (NMDevice *device) { @@ -306,6 +312,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *eth_class) object_class->finalize = finalize; object_class->get_property = get_property; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; /* properties */ diff --git a/libnm-glib/nm-device-wifi.c b/libnm-glib/nm-device-wifi.c index a75495adcd..e89813ea54 100644 --- a/libnm-glib/nm-device-wifi.c +++ b/libnm-glib/nm-device-wifi.c @@ -523,6 +523,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_WIRELESS; +} + static const char * get_hw_address (NMDevice *device) { @@ -704,6 +710,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class) object_class->dispose = dispose; object_class->finalize = finalize; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; wifi_class->access_point_removed = access_point_removed; diff --git a/libnm-glib/nm-device-wimax.c b/libnm-glib/nm-device-wimax.c index 39a9188c56..0b05280446 100644 --- a/libnm-glib/nm-device-wimax.c +++ b/libnm-glib/nm-device-wimax.c @@ -397,6 +397,12 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return NM_DEVICE_CLASS (nm_device_wimax_parent_class)->connection_compatible (device, connection, error); } +static GType +get_setting_type (NMDevice *device) +{ + return NM_TYPE_SETTING_WIMAX; +} + static const char * get_hw_address (NMDevice *device) { @@ -599,6 +605,7 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class) object_class->get_property = get_property; object_class->dispose = dispose; device_class->connection_compatible = connection_compatible; + device_class->get_setting_type = get_setting_type; device_class->get_hw_address = get_hw_address; wimax_class->nsp_removed = nsp_removed; diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index ebb10eeeab..43c8dd29c8 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -2260,3 +2260,22 @@ nm_device_filter_connections (NMDevice *device, const GSList *connections) return g_slist_reverse (filtered); } +/** + * nm_device_get_setting_type: + * @device: an #NMDevice + * + * Gets the (primary) #NMSetting subtype associated with connections + * that can be used on @device. + * + * Returns: @device's associated #NMSetting type + * + * Since: 0.9.10 + */ +GType +nm_device_get_setting_type (NMDevice *device) +{ + g_return_val_if_fail (NM_IS_DEVICE (device), G_TYPE_INVALID); + g_return_val_if_fail (NM_DEVICE_GET_CLASS (device)->get_setting_type != NULL, G_TYPE_INVALID); + + return NM_DEVICE_GET_CLASS (device)->get_setting_type (device); +} diff --git a/libnm-glib/nm-device.h b/libnm-glib/nm-device.h index fa37e71710..ed0f687671 100644 --- a/libnm-glib/nm-device.h +++ b/libnm-glib/nm-device.h @@ -104,11 +104,12 @@ typedef struct { const char * (*get_type_description) (NMDevice *device); const char * (*get_hw_address) (NMDevice *device); + GType (*get_setting_type) (NMDevice *device); + /* Padding for future expansion */ void (*_reserved1) (void); void (*_reserved2) (void); void (*_reserved3) (void); - void (*_reserved4) (void); } NMDeviceClass; GType nm_device_get_type (void); @@ -168,6 +169,9 @@ gboolean nm_device_connection_compatible (NMDevice *device, NMConnection *connection, GError **error); +NM_AVAILABLE_IN_0_9_10 +GType nm_device_get_setting_type (NMDevice *device); + G_END_DECLS #endif /* NM_DEVICE_H */ diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index 481de76c2a..c949bb8b5b 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -603,6 +603,7 @@ global: nm_utils_ap_mode_security_valid; nm_utils_bin2hexstr; nm_utils_deinit; + nm_utils_check_virtual_device_compatibility; nm_utils_escape_ssid; nm_utils_file_is_pkcs12; nm_utils_gvalue_hash_dup; diff --git a/libnm-util/nm-setting-private.h b/libnm-util/nm-setting-private.h index fd5f009bcd..b3a0947123 100644 --- a/libnm-util/nm-setting-private.h +++ b/libnm-util/nm-setting-private.h @@ -38,6 +38,7 @@ void _nm_register_setting (const char *name, #define _nm_register_setting(name, type, priority, error_quark) _nm_register_setting ((name ""), type, priority, error_quark) gboolean _nm_setting_is_base_type (NMSetting *setting); +gboolean _nm_setting_type_is_base_type (GType type); GType _nm_setting_lookup_setting_type (const char *name); GType _nm_setting_lookup_setting_type_by_quark (GQuark error_quark); gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b); diff --git a/libnm-util/nm-setting.c b/libnm-util/nm-setting.c index f19ef6a7b2..9407c63cce 100644 --- a/libnm-util/nm-setting.c +++ b/libnm-util/nm-setting.c @@ -199,25 +199,31 @@ _nm_setting_lookup_setting_by_type (GType type) } static guint32 -_get_setting_priority (NMSetting *setting) +_get_setting_type_priority (GType type) { - NMSettingPrivate *priv; + const SettingInfo *info; - g_return_val_if_fail (NM_IS_SETTING (setting), G_MAXUINT32); - priv = NM_SETTING_GET_PRIVATE (setting); - _ensure_setting_info (setting, priv); - return priv->info->priority; + g_return_val_if_fail (g_type_is_a (type, NM_TYPE_SETTING), G_MAXUINT32); + + info = _nm_setting_lookup_setting_by_type (type); + return info->priority; } gboolean -_nm_setting_is_base_type (NMSetting *setting) +_nm_setting_type_is_base_type (GType type) { /* Historical oddity: PPPoE is a base-type even though it's not * priority 1. It needs to be sorted *after* lower-level stuff like * WiFi security or 802.1x for secrets, but it's still allowed as a * base type. */ - return _get_setting_priority (setting) == 1 || NM_IS_SETTING_PPPOE (setting); + return _get_setting_type_priority (type) == 1 || (type == NM_TYPE_SETTING_PPPOE); +} + +gboolean +_nm_setting_is_base_type (NMSetting *setting) +{ + return _nm_setting_type_is_base_type (G_OBJECT_TYPE (setting)); } GType @@ -254,8 +260,8 @@ _nm_setting_compare_priority (gconstpointer a, gconstpointer b) { guint32 prio_a, prio_b; - prio_a = _get_setting_priority (NM_SETTING (a)); - prio_b = _get_setting_priority (NM_SETTING (b)); + prio_a = _get_setting_type_priority (G_OBJECT_TYPE (a)); + prio_b = _get_setting_type_priority (G_OBJECT_TYPE (b)); if (prio_a < prio_b) return -1; diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index b1c8df06e4..4047973b5d 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -36,6 +36,7 @@ #include "nm-utils-private.h" #include "nm-glib-compat.h" #include "nm-dbus-glib-types.h" +#include "nm-setting-private.h" #include "crypto.h" /** @@ -2327,3 +2328,64 @@ nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst) INET6_ADDRSTRLEN); } +/** + * nm_utils_check_virtual_device_compatibility: + * @virtual_type: a virtual connection type + * @other_type: a connection type to test against @virtual_type + * + * Determines if a connection of type @virtual_type can (in the + * general case) work with connections of type @other_type. + * + * If @virtual_type is %NM_TYPE_SETTING_VLAN, then this checks if + * @other_type is a valid type for the parent of a VLAN. + * + * If @virtual_type is a "master" type (eg, %NM_TYPE_SETTING_BRIDGE), + * then this checks if @other_type is a valid type for a slave of that + * master. + * + * Note that even if this returns %TRUE it is not guaranteed that + * <emphasis>every</emphasis> connection of type @other_type is + * compatible with @virtual_type; it may depend on the exact + * configuration of the two connections, or on the capabilities of an + * underlying device driver. + * + * Returns: %TRUE or %FALSE + * + * Since: 0.9.10 + */ +gboolean +nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type) +{ + g_return_val_if_fail (_nm_setting_type_is_base_type (virtual_type), FALSE); + g_return_val_if_fail (_nm_setting_type_is_base_type (other_type), FALSE); + + if (virtual_type == NM_TYPE_SETTING_BOND) { + return ( other_type == NM_TYPE_SETTING_INFINIBAND + || other_type == NM_TYPE_SETTING_WIRED + || other_type == NM_TYPE_SETTING_BRIDGE + || other_type == NM_TYPE_SETTING_BOND + || other_type == NM_TYPE_SETTING_TEAM + || other_type == NM_TYPE_SETTING_VLAN); + } else if (virtual_type == NM_TYPE_SETTING_BRIDGE) { + return ( other_type == NM_TYPE_SETTING_WIRED + || other_type == NM_TYPE_SETTING_BOND + || other_type == NM_TYPE_SETTING_TEAM + || other_type == NM_TYPE_SETTING_VLAN); + } else if (virtual_type == NM_TYPE_SETTING_TEAM) { + return ( other_type == NM_TYPE_SETTING_WIRED + || other_type == NM_TYPE_SETTING_BRIDGE + || other_type == NM_TYPE_SETTING_BOND + || other_type == NM_TYPE_SETTING_TEAM + || other_type == NM_TYPE_SETTING_VLAN); + } else if (virtual_type == NM_TYPE_SETTING_VLAN) { + return ( other_type == NM_TYPE_SETTING_WIRED + || other_type == NM_TYPE_SETTING_WIRELESS + || other_type == NM_TYPE_SETTING_BRIDGE + || other_type == NM_TYPE_SETTING_BOND + || other_type == NM_TYPE_SETTING_TEAM + || other_type == NM_TYPE_SETTING_VLAN); + } else { + g_warn_if_reached (); + return FALSE; + } +} diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h index 12b3e8de21..582600420b 100644 --- a/libnm-util/nm-utils.h +++ b/libnm-util/nm-utils.h @@ -174,6 +174,9 @@ const char *nm_utils_inet4_ntop (in_addr_t inaddr, char *dst); NM_AVAILABLE_IN_0_9_10 const char *nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type); + G_END_DECLS #endif /* NM_UTILS_H */ |