From f387614b918a3ce4315176e8f82bbb3bd7f8b405 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 16:48:19 +0200 Subject: [PATCH 01/16] core: print the connection.type in nm_utils_log_connection_diff() --- src/nm-core-utils.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 4da1fb2c68..4448529d67 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2432,12 +2432,26 @@ nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base, if (!name) name = ""; - connection_diff_are_same = nm_connection_diff (connection, diff_base, NM_SETTING_COMPARE_FLAG_EXACT | NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT, &connection_diff); + connection_diff_are_same = nm_connection_diff (connection, diff_base, + NM_SETTING_COMPARE_FLAG_EXACT | NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT, + &connection_diff); if (connection_diff_are_same) { - if (diff_base) - nm_log (level, domain, NULL, NULL, "%sconnection '%s' (%p/%s and %p/%s): no difference", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), diff_base, G_OBJECT_TYPE_NAME (diff_base)); - else - nm_log (level, domain, NULL, NULL, "%sconnection '%s' (%p/%s): no properties set", prefix, name, connection, G_OBJECT_TYPE_NAME (connection)); + const char *t1, *t2; + + t1 = nm_connection_get_connection_type (connection); + if (diff_base) { + t2 = nm_connection_get_connection_type (diff_base); + nm_log (level, domain, NULL, NULL, + "%sconnection '%s' (%p/%s/%s%s%s and %p/%s/%s%s%s): no difference", + prefix, name, + connection, G_OBJECT_TYPE_NAME (connection), NM_PRINT_FMT_QUOTE_STRING (t1), + diff_base, G_OBJECT_TYPE_NAME (diff_base), NM_PRINT_FMT_QUOTE_STRING (t2)); + } else { + nm_log (level, domain, NULL, NULL, + "%sconnection '%s' (%p/%s/%s%s%s): no properties set", + prefix, name, + connection, G_OBJECT_TYPE_NAME (connection), NM_PRINT_FMT_QUOTE_STRING (t1)); + } g_assert (!connection_diff); return; } @@ -2471,12 +2485,20 @@ nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base, if (print_header) { GError *err_verify = NULL; const char *path = nm_connection_get_path (connection); + const char *t1, *t2; + t1 = nm_connection_get_connection_type (connection); if (diff_base) { - nm_log (level, domain, NULL, NULL, "%sconnection '%s' (%p/%s < %p/%s)%s%s%s:", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), diff_base, G_OBJECT_TYPE_NAME (diff_base), + t2 = nm_connection_get_connection_type (diff_base); + nm_log (level, domain, NULL, NULL, "%sconnection '%s' (%p/%s/%s%s%s < %p/%s/%s%s%s)%s%s%s:", + prefix, name, + connection, G_OBJECT_TYPE_NAME (connection), NM_PRINT_FMT_QUOTE_STRING (t1), + diff_base, G_OBJECT_TYPE_NAME (diff_base), NM_PRINT_FMT_QUOTE_STRING (t2), NM_PRINT_FMT_QUOTED (path, " [", path, "]", "")); } else { - nm_log (level, domain, NULL, NULL, "%sconnection '%s' (%p/%s):%s%s%s", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), + nm_log (level, domain, NULL, NULL, "%sconnection '%s' (%p/%s/%s%s%s):%s%s%s", + prefix, name, + connection, G_OBJECT_TYPE_NAME (connection), NM_PRINT_FMT_QUOTE_STRING (t1), NM_PRINT_FMT_QUOTED (path, " [", path, "]", "")); } print_header = FALSE; From 11d852a14895404f1a954b55674353a14c1b35a2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 17:03:46 +0200 Subject: [PATCH 02/16] core: minor refactoring condition in validate_activation_request() --- src/nm-manager.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/nm-manager.c b/src/nm-manager.c index f4976cc037..e902a3e3dc 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3724,10 +3724,11 @@ validate_activation_request (NMManager *self, device = nm_manager_get_best_device_for_connection (self, connection, TRUE, NULL); if (!device && !vpn) { - gboolean is_software = nm_connection_is_virtual (connection); + gs_free char *iface = NULL; - /* VPN and software-device connections don't need a device yet */ - if (!is_software) { + /* VPN and software-device connections don't need a device yet, + * but non-virtual connections do ... */ + if (!nm_connection_is_virtual (connection)) { g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE, @@ -3735,17 +3736,12 @@ validate_activation_request (NMManager *self, goto error; } - if (is_software) { - char *iface; + /* Look for an existing device with the connection's interface name */ + iface = nm_manager_get_connection_iface (self, connection, NULL, error); + if (!iface) + goto error; - /* Look for an existing device with the connection's interface name */ - iface = nm_manager_get_connection_iface (self, connection, NULL, error); - if (!iface) - goto error; - - device = find_device_by_iface (self, iface, connection, NULL); - g_free (iface); - } + device = find_device_by_iface (self, iface, connection, NULL); } if ((!vpn || device_path) && !device) { @@ -3840,8 +3836,8 @@ impl_manager_activate_connection (NMManager *self, connection = nm_settings_get_connection_by_path (priv->settings, connection_path); if (!connection) { error = g_error_new_literal (NM_MANAGER_ERROR, - NM_MANAGER_ERROR_UNKNOWN_CONNECTION, - "Connection could not be found."); + NM_MANAGER_ERROR_UNKNOWN_CONNECTION, + "Connection could not be found."); goto error; } } else { From c7e9f97800ed350340e38371ac38cad590136516 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 13:48:34 +0200 Subject: [PATCH 03/16] libnm/trivial: rename _nm_register_setting function to _nm_register_setting_impl Avoid having the function _nm_register_setting() shadowed by a macro of the same name, but different behavior/arguments. --- libnm-core/nm-setting-private.h | 8 ++++---- libnm-core/nm-setting.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 3d6e2d4d86..471de323a6 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -27,13 +27,13 @@ #include "nm-core-internal.h" -void _nm_register_setting (const char *name, - const GType type, - const guint32 priority); +void _nm_register_setting_impl (const char *name, + const GType type, + const guint32 priority); #define _nm_register_setting(name, priority) \ G_STMT_START { \ - _nm_register_setting (NM_SETTING_ ## name ## _SETTING_NAME "", g_define_type_id, priority); \ + _nm_register_setting_impl ("" NM_SETTING_ ## name ## _SETTING_NAME "", g_define_type_id, priority); \ } G_STMT_END guint32 _nm_setting_get_base_type_priority (NMSetting *setting); diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 530dd0147a..7cad544ae2 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -118,7 +118,7 @@ _ensure_registered_constructor (void) /*****************************************************************************/ /* - * _nm_register_setting: + * _nm_register_setting_impl: * @name: the name of the #NMSetting object to register * @type: the #GType of the #NMSetting * @priority: the sort priority of the setting, see below @@ -151,9 +151,9 @@ _ensure_registered_constructor (void) * 10: NMSettingUser */ void -(_nm_register_setting) (const char *name, - const GType type, - const guint32 priority) +_nm_register_setting_impl (const char *name, + const GType type, + const guint32 priority) { SettingInfo *info; From a973eacb3b2811ba977f1d2b36633a5c814b74e8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 13:43:52 +0200 Subject: [PATCH 04/16] libnm: add enum for setting priorities Using plain numbers make it cumbersome to grep for setting types by priority. The only downside is, that with the enum values it is no longer obvious which value has higher or lower priority. Also, introduce NM_SETTING_PRIORITY_INVALID. This is what _nm_setting_type_get_base_type_priority() returns. For the moment it still has the same numerical value 0 as before. Later, that shall be distinct from NM_SETTING_PRIORITY_CONNECTION. --- libnm-core/nm-connection.c | 6 ++-- libnm-core/nm-core-internal.h | 40 +++++++++++++++++++++- libnm-core/nm-setting-connection.c | 3 +- libnm-core/nm-setting-private.h | 8 ++--- libnm-core/nm-setting.c | 54 +++++++++--------------------- libnm-core/nm-utils.c | 4 +-- libnm-core/tests/test-general.c | 6 ++-- src/nm-core-utils.c | 2 +- 8 files changed, 70 insertions(+), 53 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 309df782a9..4dd77a8b4d 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -585,12 +585,12 @@ _nm_connection_find_base_type_setting (NMConnection *connection) NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection); GHashTableIter iter; NMSetting *setting = NULL, *s_iter; - guint32 setting_prio, s_iter_prio; + NMSettingPriority setting_prio, s_iter_prio; g_hash_table_iter_init (&iter, priv->settings); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &s_iter)) { s_iter_prio = _nm_setting_get_base_type_priority (s_iter); - if (!s_iter_prio) + if (s_iter_prio == NM_SETTING_PRIORITY_INVALID) continue; if (setting) { @@ -1670,7 +1670,7 @@ nm_connection_is_type (NMConnection *connection, const char *type) if (!setting) return FALSE; - return !!_nm_setting_get_base_type_priority (setting); + return _nm_setting_get_base_type_priority (setting) != NM_SETTING_PRIORITY_INVALID; } static int diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 102cd6575f..2591c10928 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -142,7 +142,45 @@ NMConnection *_nm_simple_connection_new_from_dbus (GVariant *dict, NMSettingParseFlags parse_flags, GError **error); -guint32 _nm_setting_get_setting_priority (NMSetting *setting); +/* + * A setting's priority should roughly follow the OSI layer model, but it also + * controls which settings get asked for secrets first. Thus settings which + * relate to things that must be working first, like hardware, should get a + * higher priority than things which layer on top of the hardware. For example, + * the GSM/CDMA settings should provide secrets before the PPP setting does, + * because a PIN is required to unlock the device before PPP can even start. + * Even settings without secrets should be assigned the right priority. + * + * 0: reserved for the Connection setting + * + * 1,2: hardware-related settings like Ethernet, Wi-Fi, InfiniBand, Bridge, etc. + * These priority 1 settings are also "base types", which means that at least + * one of them is required for the connection to be valid, and their name is + * valid in the 'type' property of the Connection setting. + * + * 3: hardware-related auxiliary settings that require a base setting to be + * successful first, like Wi-Fi security, 802.1x, etc. + * + * 4: hardware-independent settings that are required before IP connectivity + * can be established, like PPP, PPPoE, etc. + * + * 5: IP-level stuff + * + * 10: NMSettingUser + */ +typedef enum { /*< skip >*/ + NM_SETTING_PRIORITY_CONNECTION = 0, + NM_SETTING_PRIORITY_HW_BASE = 1, + NM_SETTING_PRIORITY_HW_NON_BASE = 2, + NM_SETTING_PRIORITY_HW_AUX = 3, + NM_SETTING_PRIORITY_AUX = 4, + NM_SETTING_PRIORITY_IP = 5, + NM_SETTING_PRIORITY_USER = 10, + + NM_SETTING_PRIORITY_INVALID = 0, +} NMSettingPriority; + +NMSettingPriority _nm_setting_get_setting_priority (NMSetting *setting); gboolean _nm_setting_get_property (NMSetting *setting, const char *name, GValue *value); diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 257d6621af..86b8fd41bc 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -926,7 +926,8 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) } base_type = nm_setting_lookup_type (priv->type); - if (base_type == G_TYPE_INVALID || !_nm_setting_type_get_base_type_priority (base_type)) { + if ( base_type == G_TYPE_INVALID + || _nm_setting_type_get_base_type_priority (base_type) == NM_SETTING_PRIORITY_INVALID) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 471de323a6..30e2a160e4 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -28,16 +28,16 @@ #include "nm-core-internal.h" void _nm_register_setting_impl (const char *name, - const GType type, - const guint32 priority); + GType type, + NMSettingPriority priority); #define _nm_register_setting(name, priority) \ G_STMT_START { \ _nm_register_setting_impl ("" NM_SETTING_ ## name ## _SETTING_NAME "", g_define_type_id, priority); \ } G_STMT_END -guint32 _nm_setting_get_base_type_priority (NMSetting *setting); -guint32 _nm_setting_type_get_base_type_priority (GType type); +NMSettingPriority _nm_setting_get_base_type_priority (NMSetting *setting); +NMSettingPriority _nm_setting_type_get_base_type_priority (GType type); gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b); typedef enum NMSettingUpdateSecretResult { diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 7cad544ae2..a574449f58 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -60,7 +60,7 @@ G_DEFINE_ABSTRACT_TYPE (NMSetting, nm_setting, G_TYPE_OBJECT) typedef struct { const char *name; GType type; - guint32 priority; + NMSettingPriority priority; } SettingInfo; typedef struct { @@ -121,39 +121,14 @@ _ensure_registered_constructor (void) * _nm_register_setting_impl: * @name: the name of the #NMSetting object to register * @type: the #GType of the #NMSetting - * @priority: the sort priority of the setting, see below + * @priority: the sort priority of the setting, see #NMSettingPriority * * INTERNAL ONLY: registers a setting's internal properties with libnm. - * - * A setting's priority should roughly follow the OSI layer model, but it also - * controls which settings get asked for secrets first. Thus settings which - * relate to things that must be working first, like hardware, should get a - * higher priority than things which layer on top of the hardware. For example, - * the GSM/CDMA settings should provide secrets before the PPP setting does, - * because a PIN is required to unlock the device before PPP can even start. - * Even settings without secrets should be assigned the right priority. - * - * 0: reserved for the Connection setting - * - * 1,2: hardware-related settings like Ethernet, Wi-Fi, InfiniBand, Bridge, etc. - * These priority 1 settings are also "base types", which means that at least - * one of them is required for the connection to be valid, and their name is - * valid in the 'type' property of the Connection setting. - * - * 3: hardware-related auxiliary settings that require a base setting to be - * successful first, like Wi-Fi security, 802.1x, etc. - * - * 4: hardware-independent settings that are required before IP connectivity - * can be established, like PPP, PPPoE, etc. - * - * 5: IP-level stuff - * - * 10: NMSettingUser */ void _nm_register_setting_impl (const char *name, - const GType type, - const guint32 priority) + GType type, + NMSettingPriority priority) { SettingInfo *info; @@ -171,7 +146,7 @@ _nm_register_setting_impl (const char *name, } g_return_if_fail (g_hash_table_lookup (registered_settings_by_type, &type) == NULL); - if (priority == 0) + if (priority == NM_SETTING_PRIORITY_CONNECTION) g_assert_cmpstr (name, ==, NM_SETTING_CONNECTION_SETTING_NAME); info = g_slice_new0 (SettingInfo); @@ -189,7 +164,7 @@ _nm_setting_lookup_setting_by_type (GType type) return g_hash_table_lookup (registered_settings_by_type, &type); } -static guint32 +static NMSettingPriority _get_setting_type_priority (GType type) { const SettingInfo *info; @@ -200,7 +175,7 @@ _get_setting_type_priority (GType type) return info->priority; } -guint32 +NMSettingPriority _nm_setting_get_setting_priority (NMSetting *setting) { NMSettingPrivate *priv; @@ -211,10 +186,10 @@ _nm_setting_get_setting_priority (NMSetting *setting) return priv->info->priority; } -guint32 +NMSettingPriority _nm_setting_type_get_base_type_priority (GType type) { - guint32 priority; + NMSettingPriority priority; /* Historical oddity: PPPoE is a base-type even though it's not * priority 1. It needs to be sorted *after* lower-level stuff like @@ -222,13 +197,16 @@ _nm_setting_type_get_base_type_priority (GType type) * base type. */ priority = _get_setting_type_priority (type); - if (priority == 1 || priority == 2 || (type == NM_TYPE_SETTING_PPPOE)) + if ( NM_IN_SET (priority, + NM_SETTING_PRIORITY_HW_BASE, + NM_SETTING_PRIORITY_HW_NON_BASE) + || type == NM_TYPE_SETTING_PPPOE) return priority; else - return 0; + return NM_SETTING_PRIORITY_INVALID; } -guint32 +NMSettingPriority _nm_setting_get_base_type_priority (NMSetting *setting) { return _nm_setting_type_get_base_type_priority (G_OBJECT_TYPE (setting)); @@ -259,7 +237,7 @@ nm_setting_lookup_type (const char *name) gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b) { - guint32 prio_a, prio_b; + NMSettingPriority prio_a, prio_b; prio_a = _nm_setting_get_setting_priority ((NMSetting *) a); prio_b = _nm_setting_get_setting_priority ((NMSetting *) b); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 8f08c1b566..c52948bd7b 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3896,8 +3896,8 @@ _nm_utils_inet6_is_token (const struct in6_addr *in6addr) gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type) { - g_return_val_if_fail (_nm_setting_type_get_base_type_priority (virtual_type), FALSE); - g_return_val_if_fail (_nm_setting_type_get_base_type_priority (other_type), FALSE); + g_return_val_if_fail (_nm_setting_type_get_base_type_priority (virtual_type) != NM_SETTING_PRIORITY_INVALID, FALSE); + g_return_val_if_fail (_nm_setting_type_get_base_type_priority (other_type) != NM_SETTING_PRIORITY_INVALID, FALSE); if (virtual_type == NM_TYPE_SETTING_BOND) { return ( other_type == NM_TYPE_SETTING_INFINIBAND diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index cc8c6bd7f7..b8c3dc8e12 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -3492,7 +3492,7 @@ _test_connection_normalize_type_normalizable_setting (const char *type, base_type = nm_setting_lookup_type (type); g_assert (base_type != G_TYPE_INVALID); - g_assert (_nm_setting_type_get_base_type_priority (base_type)); + g_assert (_nm_setting_type_get_base_type_priority (base_type) != NM_SETTING_PRIORITY_INVALID); con = nmtst_create_minimal_connection (id, NULL, NULL, &s_con); @@ -3522,7 +3522,7 @@ _test_connection_normalize_type_unnormalizable_setting (const char *type) base_type = nm_setting_lookup_type (type); g_assert (base_type != G_TYPE_INVALID); - g_assert (_nm_setting_type_get_base_type_priority (base_type)); + g_assert (_nm_setting_type_get_base_type_priority (base_type) != NM_SETTING_PRIORITY_INVALID); con = nmtst_create_minimal_connection (id, NULL, NULL, &s_con); @@ -3545,7 +3545,7 @@ _test_connection_normalize_type_normalizable_type (const char *type, base_type = nm_setting_lookup_type (type); g_assert (base_type != G_TYPE_INVALID); - g_assert (_nm_setting_type_get_base_type_priority (base_type)); + g_assert (_nm_setting_type_get_base_type_priority (base_type) != NM_SETTING_PRIORITY_INVALID); con = nmtst_create_minimal_connection (id, NULL, NULL, &s_con); diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 4448529d67..8b330a5a0d 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2292,7 +2292,7 @@ _log_connection_sort_hashes_fcn (gconstpointer a, gconstpointer b) { const LogConnectionSettingData *v1 = a; const LogConnectionSettingData *v2 = b; - guint32 p1, p2; + NMSettingPriority p1, p2; NMSetting *s1, *s2; s1 = v1->setting ? v1->setting : v1->diff_base_setting; From 488029d74b6d25abc857e46067cf63588a5dbbe5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 13:43:52 +0200 Subject: [PATCH 05/16] libnm: use enum for setting priorities --- libnm-core/nm-setting-8021x.c | 2 +- libnm-core/nm-setting-adsl.c | 2 +- libnm-core/nm-setting-bluetooth.c | 2 +- libnm-core/nm-setting-bond.c | 2 +- libnm-core/nm-setting-bridge-port.c | 2 +- libnm-core/nm-setting-bridge.c | 2 +- libnm-core/nm-setting-cdma.c | 2 +- libnm-core/nm-setting-connection.c | 2 +- libnm-core/nm-setting-dcb.c | 2 +- libnm-core/nm-setting-dummy.c | 2 +- libnm-core/nm-setting-generic.c | 2 +- libnm-core/nm-setting-gsm.c | 2 +- libnm-core/nm-setting-infiniband.c | 2 +- libnm-core/nm-setting-ip-tunnel.c | 2 +- libnm-core/nm-setting-ip4-config.c | 2 +- libnm-core/nm-setting-ip6-config.c | 2 +- libnm-core/nm-setting-macsec.c | 2 +- libnm-core/nm-setting-macvlan.c | 2 +- libnm-core/nm-setting-olpc-mesh.c | 2 +- libnm-core/nm-setting-ppp.c | 2 +- libnm-core/nm-setting-pppoe.c | 2 +- libnm-core/nm-setting-proxy.c | 2 +- libnm-core/nm-setting-serial.c | 2 +- libnm-core/nm-setting-team-port.c | 2 +- libnm-core/nm-setting-team.c | 2 +- libnm-core/nm-setting-tun.c | 2 +- libnm-core/nm-setting-user.c | 2 +- libnm-core/nm-setting-vlan.c | 2 +- libnm-core/nm-setting-vpn.c | 2 +- libnm-core/nm-setting-vxlan.c | 2 +- libnm-core/nm-setting-wimax.c | 2 +- libnm-core/nm-setting-wired.c | 2 +- libnm-core/nm-setting-wireless-security.c | 2 +- libnm-core/nm-setting-wireless.c | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c index c791cf1fa3..0050a7420b 100644 --- a/libnm-core/nm-setting-8021x.c +++ b/libnm-core/nm-setting-8021x.c @@ -61,7 +61,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSetting8021x, nm_setting_802_1x, NM_TYPE_SETTING, - _nm_register_setting (802_1X, 3)) + _nm_register_setting (802_1X, NM_SETTING_PRIORITY_HW_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_802_1X) #define NM_SETTING_802_1X_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_802_1X, NMSetting8021xPrivate)) diff --git a/libnm-core/nm-setting-adsl.c b/libnm-core/nm-setting-adsl.c index 8198a72a1d..8be288b668 100644 --- a/libnm-core/nm-setting-adsl.c +++ b/libnm-core/nm-setting-adsl.c @@ -38,7 +38,7 @@ */ G_DEFINE_TYPE_WITH_CODE (NMSettingAdsl, nm_setting_adsl, NM_TYPE_SETTING, - _nm_register_setting (ADSL, 1)) + _nm_register_setting (ADSL, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_ADSL) #define NM_SETTING_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_ADSL, NMSettingAdslPrivate)) diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c index 26f41d62ce..6daf857ecb 100644 --- a/libnm-core/nm-setting-bluetooth.c +++ b/libnm-core/nm-setting-bluetooth.c @@ -44,7 +44,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingBluetooth, nm_setting_bluetooth, NM_TYPE_SETTING, - _nm_register_setting (BLUETOOTH, 2)) + _nm_register_setting (BLUETOOTH, NM_SETTING_PRIORITY_HW_NON_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BLUETOOTH) #define NM_SETTING_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothPrivate)) diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 5c58697100..9b35d8cd75 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -43,7 +43,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING, - _nm_register_setting (BOND, 1)) + _nm_register_setting (BOND, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND) #define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate)) diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index ba297b70d4..9a90da1cd9 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -41,7 +41,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingBridgePort, nm_setting_bridge_port, NM_TYPE_SETTING, - _nm_register_setting (BRIDGE_PORT, 4)) + _nm_register_setting (BRIDGE_PORT, NM_SETTING_PRIORITY_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE_PORT) #define NM_SETTING_BRIDGE_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortPrivate)) diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index 7cfa7eb83b..c9cd01389e 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -39,7 +39,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingBridge, nm_setting_bridge, NM_TYPE_SETTING, - _nm_register_setting (BRIDGE, 1)) + _nm_register_setting (BRIDGE, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE) #define NM_SETTING_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE, NMSettingBridgePrivate)) diff --git a/libnm-core/nm-setting-cdma.c b/libnm-core/nm-setting-cdma.c index b267ba63dd..6317895159 100644 --- a/libnm-core/nm-setting-cdma.c +++ b/libnm-core/nm-setting-cdma.c @@ -38,7 +38,7 @@ */ G_DEFINE_TYPE_WITH_CODE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING, - _nm_register_setting (CDMA, 1)) + _nm_register_setting (CDMA, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CDMA) #define NM_SETTING_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CDMA, NMSettingCdmaPrivate)) diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 86b8fd41bc..a0a7efe02e 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -46,7 +46,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING, - _nm_register_setting (CONNECTION, 0)) + _nm_register_setting (CONNECTION, NM_SETTING_PRIORITY_CONNECTION)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CONNECTION) #define NM_SETTING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionPrivate)) diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index 93f82199a2..7c9a0c7508 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -41,7 +41,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingDcb, nm_setting_dcb, NM_TYPE_SETTING, - _nm_register_setting (DCB, 3)) + _nm_register_setting (DCB, NM_SETTING_PRIORITY_HW_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DCB) #define NM_SETTING_DCB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_DCB, NMSettingDcbPrivate)) diff --git a/libnm-core/nm-setting-dummy.c b/libnm-core/nm-setting-dummy.c index d23f0a3054..4b3c41f03a 100644 --- a/libnm-core/nm-setting-dummy.c +++ b/libnm-core/nm-setting-dummy.c @@ -35,7 +35,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingDummy, nm_setting_dummy, NM_TYPE_SETTING, - _nm_register_setting (DUMMY, 1)) + _nm_register_setting (DUMMY, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DUMMY) /** diff --git a/libnm-core/nm-setting-generic.c b/libnm-core/nm-setting-generic.c index 09edeb6e1b..96f26ac2a1 100644 --- a/libnm-core/nm-setting-generic.c +++ b/libnm-core/nm-setting-generic.c @@ -37,7 +37,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingGeneric, nm_setting_generic, NM_TYPE_SETTING, - _nm_register_setting (GENERIC, 1)) + _nm_register_setting (GENERIC, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_GENERIC) #define NM_SETTING_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_GENERIC, NMSettingGenericPrivate)) diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c index be32b852ed..1cca34017d 100644 --- a/libnm-core/nm-setting-gsm.c +++ b/libnm-core/nm-setting-gsm.c @@ -39,7 +39,7 @@ */ G_DEFINE_TYPE_WITH_CODE (NMSettingGsm, nm_setting_gsm, NM_TYPE_SETTING, - _nm_register_setting (GSM, 1)) + _nm_register_setting (GSM, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_GSM) #define NM_SETTING_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_GSM, NMSettingGsmPrivate)) diff --git a/libnm-core/nm-setting-infiniband.c b/libnm-core/nm-setting-infiniband.c index 6ab6ac11b5..8c49849a7b 100644 --- a/libnm-core/nm-setting-infiniband.c +++ b/libnm-core/nm-setting-infiniband.c @@ -38,7 +38,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingInfiniband, nm_setting_infiniband, NM_TYPE_SETTING, - _nm_register_setting (INFINIBAND, 1)) + _nm_register_setting (INFINIBAND, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_INFINIBAND) #define NM_SETTING_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_INFINIBAND, NMSettingInfinibandPrivate)) diff --git a/libnm-core/nm-setting-ip-tunnel.c b/libnm-core/nm-setting-ip-tunnel.c index 4589f766af..7e1737fc3b 100644 --- a/libnm-core/nm-setting-ip-tunnel.c +++ b/libnm-core/nm-setting-ip-tunnel.c @@ -31,7 +31,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingIPTunnel, nm_setting_ip_tunnel, NM_TYPE_SETTING, - _nm_register_setting (IP_TUNNEL, 1)) + _nm_register_setting (IP_TUNNEL, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP_TUNNEL) #define NM_SETTING_IP_TUNNEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP_TUNNEL, NMSettingIPTunnelPrivate)) diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 3c54dfa96f..79d72cc96e 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -51,7 +51,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingIP4Config, nm_setting_ip4_config, NM_TYPE_SETTING_IP_CONFIG, - _nm_register_setting (IP4_CONFIG, 5)) + _nm_register_setting (IP4_CONFIG, NM_SETTING_PRIORITY_IP)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG) #define NM_SETTING_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigPrivate)) diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 93301d20cd..ed24533092 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -52,7 +52,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingIP6Config, nm_setting_ip6_config, NM_TYPE_SETTING_IP_CONFIG, - _nm_register_setting (IP6_CONFIG, 5)) + _nm_register_setting (IP6_CONFIG, NM_SETTING_PRIORITY_IP)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP6_CONFIG) #define NM_SETTING_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_IP6_CONFIG, NMSettingIP6ConfigPrivate)) diff --git a/libnm-core/nm-setting-macsec.c b/libnm-core/nm-setting-macsec.c index c818f07fce..7a8a5a34ad 100644 --- a/libnm-core/nm-setting-macsec.c +++ b/libnm-core/nm-setting-macsec.c @@ -41,7 +41,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingMacsec, nm_setting_macsec, NM_TYPE_SETTING, - _nm_register_setting (MACSEC, 1)) + _nm_register_setting (MACSEC, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_MACSEC) #define NM_SETTING_MACSEC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_MACSEC, NMSettingMacsecPrivate)) diff --git a/libnm-core/nm-setting-macvlan.c b/libnm-core/nm-setting-macvlan.c index f5edc6e842..d684e58dc6 100644 --- a/libnm-core/nm-setting-macvlan.c +++ b/libnm-core/nm-setting-macvlan.c @@ -40,7 +40,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingMacvlan, nm_setting_macvlan, NM_TYPE_SETTING, - _nm_register_setting (MACVLAN, 1)) + _nm_register_setting (MACVLAN, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_MACVLAN) #define NM_SETTING_MACVLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_MACVLAN, NMSettingMacvlanPrivate)) diff --git a/libnm-core/nm-setting-olpc-mesh.c b/libnm-core/nm-setting-olpc-mesh.c index eba29c9242..783d143f75 100644 --- a/libnm-core/nm-setting-olpc-mesh.c +++ b/libnm-core/nm-setting-olpc-mesh.c @@ -40,7 +40,7 @@ static void nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting); G_DEFINE_TYPE_WITH_CODE (NMSettingOlpcMesh, nm_setting_olpc_mesh, NM_TYPE_SETTING, - _nm_register_setting (OLPC_MESH, 1)) + _nm_register_setting (OLPC_MESH, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OLPC_MESH) #define NM_SETTING_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshPrivate)) diff --git a/libnm-core/nm-setting-ppp.c b/libnm-core/nm-setting-ppp.c index 05b5233031..32900c8463 100644 --- a/libnm-core/nm-setting-ppp.c +++ b/libnm-core/nm-setting-ppp.c @@ -36,7 +36,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingPpp, nm_setting_ppp, NM_TYPE_SETTING, - _nm_register_setting (PPP, 4)) + _nm_register_setting (PPP, NM_SETTING_PRIORITY_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPP) #define NM_SETTING_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPP, NMSettingPppPrivate)) diff --git a/libnm-core/nm-setting-pppoe.c b/libnm-core/nm-setting-pppoe.c index 5dcc708ec1..f72ee27385 100644 --- a/libnm-core/nm-setting-pppoe.c +++ b/libnm-core/nm-setting-pppoe.c @@ -39,7 +39,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingPppoe, nm_setting_pppoe, NM_TYPE_SETTING, - _nm_register_setting (PPPOE, 4)) + _nm_register_setting (PPPOE, NM_SETTING_PRIORITY_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPPOE) #define NM_SETTING_PPPOE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPPOE, NMSettingPppoePrivate)) diff --git a/libnm-core/nm-setting-proxy.c b/libnm-core/nm-setting-proxy.c index ad417f7721..58a2208031 100644 --- a/libnm-core/nm-setting-proxy.c +++ b/libnm-core/nm-setting-proxy.c @@ -40,7 +40,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingProxy, nm_setting_proxy, NM_TYPE_SETTING, - _nm_register_setting (PROXY, 5)) + _nm_register_setting (PROXY, NM_SETTING_PRIORITY_IP)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PROXY) #define NM_SETTING_PROXY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PROXY, NMSettingProxyPrivate)) diff --git a/libnm-core/nm-setting-serial.c b/libnm-core/nm-setting-serial.c index bb592c080a..e0da89aa79 100644 --- a/libnm-core/nm-setting-serial.c +++ b/libnm-core/nm-setting-serial.c @@ -38,7 +38,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING, - _nm_register_setting (SERIAL, 3)) + _nm_register_setting (SERIAL, NM_SETTING_PRIORITY_HW_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_SERIAL) #define NM_SETTING_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_SERIAL, NMSettingSerialPrivate)) diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 8dd3da097c..c030966579 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -40,7 +40,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingTeamPort, nm_setting_team_port, NM_TYPE_SETTING, - _nm_register_setting (TEAM_PORT, 4)) + _nm_register_setting (TEAM_PORT, NM_SETTING_PRIORITY_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM_PORT) #define NM_SETTING_TEAM_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortPrivate)) diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index e83ce309a4..1f509baa1e 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -38,7 +38,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingTeam, nm_setting_team, NM_TYPE_SETTING, - _nm_register_setting (TEAM, 1)) + _nm_register_setting (TEAM, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM) #define NM_SETTING_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM, NMSettingTeamPrivate)) diff --git a/libnm-core/nm-setting-tun.c b/libnm-core/nm-setting-tun.c index 62e9ef145f..dab407bdd6 100644 --- a/libnm-core/nm-setting-tun.c +++ b/libnm-core/nm-setting-tun.c @@ -39,7 +39,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingTun, nm_setting_tun, NM_TYPE_SETTING, - _nm_register_setting (TUN, 1)) + _nm_register_setting (TUN, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TUN) #define NM_SETTING_TUN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TUN, NMSettingTunPrivate)) diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 71d738910a..6c1d152aa9 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -64,7 +64,7 @@ struct _NMSettingUserClass { }; G_DEFINE_TYPE_WITH_CODE (NMSettingUser, nm_setting_user, NM_TYPE_SETTING, - _nm_register_setting (USER, 10)) + _nm_register_setting (USER, NM_SETTING_PRIORITY_USER)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_USER) #define NM_SETTING_USER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMSettingUser, NM_IS_SETTING_USER) diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index ab1c54651f..f9c6e02d66 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -42,7 +42,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingVlan, nm_setting_vlan, NM_TYPE_SETTING, - _nm_register_setting (VLAN, 1)) + _nm_register_setting (VLAN, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VLAN) #define NM_SETTING_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VLAN, NMSettingVlanPrivate)) diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index b9d9fd5273..6b42e0c7a6 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -44,7 +44,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingVpn, nm_setting_vpn, NM_TYPE_SETTING, - _nm_register_setting (VPN, 1)) + _nm_register_setting (VPN, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VPN) #define NM_SETTING_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VPN, NMSettingVpnPrivate)) diff --git a/libnm-core/nm-setting-vxlan.c b/libnm-core/nm-setting-vxlan.c index 1ce62ad5a3..4be6a236f9 100644 --- a/libnm-core/nm-setting-vxlan.c +++ b/libnm-core/nm-setting-vxlan.c @@ -37,7 +37,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingVxlan, nm_setting_vxlan, NM_TYPE_SETTING, - _nm_register_setting (VXLAN, 1)) + _nm_register_setting (VXLAN, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VXLAN) #define NM_SETTING_VXLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VXLAN, NMSettingVxlanPrivate)) diff --git a/libnm-core/nm-setting-wimax.c b/libnm-core/nm-setting-wimax.c index f893cbdcfe..dbfb46e4c8 100644 --- a/libnm-core/nm-setting-wimax.c +++ b/libnm-core/nm-setting-wimax.c @@ -43,7 +43,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingWimax, nm_setting_wimax, NM_TYPE_SETTING, - _nm_register_setting (WIMAX, 1)) + _nm_register_setting (WIMAX, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIMAX) #define NM_SETTING_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIMAX, NMSettingWimaxPrivate)) diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 9b6d7bb9ef..ee7ddf88c8 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -41,7 +41,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingWired, nm_setting_wired, NM_TYPE_SETTING, - _nm_register_setting (WIRED, 1)) + _nm_register_setting (WIRED, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRED) #define NM_SETTING_WIRED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRED, NMSettingWiredPrivate)) diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c index ef840322b2..efe77820d4 100644 --- a/libnm-core/nm-setting-wireless-security.c +++ b/libnm-core/nm-setting-wireless-security.c @@ -54,7 +54,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingWirelessSecurity, nm_setting_wireless_security, NM_TYPE_SETTING, - _nm_register_setting (WIRELESS_SECURITY, 3)) + _nm_register_setting (WIRELESS_SECURITY, NM_SETTING_PRIORITY_HW_AUX)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS_SECURITY) #define NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurityPrivate)) diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index 4c0bc5d6f7..e26bbfd62e 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -41,7 +41,7 @@ **/ G_DEFINE_TYPE_WITH_CODE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING, - _nm_register_setting (WIRELESS, 1)) + _nm_register_setting (WIRELESS, NM_SETTING_PRIORITY_HW_BASE)) NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS) #define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate)) From 837a8c1ca5bd3ec391d228c6a5725c85bc4a1c55 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 14:26:41 +0200 Subject: [PATCH 06/16] libnm: distinguish INVALID priority setting from NM_SETTING_PRIORITY_CONNECTION --- libnm-core/nm-core-internal.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 2591c10928..271d71ebde 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -151,33 +151,34 @@ NMConnection *_nm_simple_connection_new_from_dbus (GVariant *dict, * because a PIN is required to unlock the device before PPP can even start. * Even settings without secrets should be assigned the right priority. * - * 0: reserved for the Connection setting + * 0: reserved for invalid * - * 1,2: hardware-related settings like Ethernet, Wi-Fi, InfiniBand, Bridge, etc. + * 1: reserved for the Connection setting + * + * 2,3: hardware-related settings like Ethernet, Wi-Fi, InfiniBand, Bridge, etc. * These priority 1 settings are also "base types", which means that at least * one of them is required for the connection to be valid, and their name is * valid in the 'type' property of the Connection setting. * - * 3: hardware-related auxiliary settings that require a base setting to be + * 4: hardware-related auxiliary settings that require a base setting to be * successful first, like Wi-Fi security, 802.1x, etc. * - * 4: hardware-independent settings that are required before IP connectivity + * 5: hardware-independent settings that are required before IP connectivity * can be established, like PPP, PPPoE, etc. * - * 5: IP-level stuff + * 6: IP-level stuff * * 10: NMSettingUser */ typedef enum { /*< skip >*/ - NM_SETTING_PRIORITY_CONNECTION = 0, - NM_SETTING_PRIORITY_HW_BASE = 1, - NM_SETTING_PRIORITY_HW_NON_BASE = 2, - NM_SETTING_PRIORITY_HW_AUX = 3, - NM_SETTING_PRIORITY_AUX = 4, - NM_SETTING_PRIORITY_IP = 5, - NM_SETTING_PRIORITY_USER = 10, - NM_SETTING_PRIORITY_INVALID = 0, + NM_SETTING_PRIORITY_CONNECTION = 1, + NM_SETTING_PRIORITY_HW_BASE = 2, + NM_SETTING_PRIORITY_HW_NON_BASE = 3, + NM_SETTING_PRIORITY_HW_AUX = 4, + NM_SETTING_PRIORITY_AUX = 5, + NM_SETTING_PRIORITY_IP = 6, + NM_SETTING_PRIORITY_USER = 10, } NMSettingPriority; NMSettingPriority _nm_setting_get_setting_priority (NMSetting *setting); From 1d6b717401e42f3cc96e08e7e7ca807e90f73135 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 14:31:25 +0200 Subject: [PATCH 07/16] libnm: downgrade assertions in _nm_register_setting_impl() to nm_assert() This is entirely internal API. We have unit tests that execute these code paths. No need to have these assertions in production code. --- libnm-core/nm-setting.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index a574449f58..16e987cae4 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -132,22 +132,17 @@ _nm_register_setting_impl (const char *name, { SettingInfo *info; - g_return_if_fail (name != NULL && *name); - g_return_if_fail (type != G_TYPE_INVALID); - g_return_if_fail (type != G_TYPE_NONE); + nm_assert (name && *name); + nm_assert (!NM_IN_SET (type, G_TYPE_INVALID, G_TYPE_NONE)); + nm_assert (priority != NM_SETTING_PRIORITY_INVALID); _ensure_registered (); - if (G_LIKELY ((info = g_hash_table_lookup (registered_settings, name)))) { - g_return_if_fail (info->type == type); - g_return_if_fail (info->priority == priority); - g_return_if_fail (g_strcmp0 (info->name, name) == 0); - return; - } - g_return_if_fail (g_hash_table_lookup (registered_settings_by_type, &type) == NULL); + nm_assert (!g_hash_table_lookup (registered_settings, name)); + nm_assert (!g_hash_table_lookup (registered_settings_by_type, &type)); - if (priority == NM_SETTING_PRIORITY_CONNECTION) - g_assert_cmpstr (name, ==, NM_SETTING_CONNECTION_SETTING_NAME); + nm_assert ( priority != NM_SETTING_PRIORITY_CONNECTION + || nm_streq (name, NM_SETTING_CONNECTION_SETTING_NAME)); info = g_slice_new0 (SettingInfo); info->type = type; From 88c2ccfb4c20cd1b4e34b31991f446b2f052478a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 14:48:54 +0200 Subject: [PATCH 08/16] libnm: avoid assertion with invalid connections in _nm_connection_find_base_type_setting() Functions should behave gracefully with connections that don't verify. Especially, as _normalize_connection_type() calls _nm_connection_find_base_type_setting() precisely with an unknown connection.type. --- libnm-core/nm-connection.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 4dd77a8b4d..e2f51dfb96 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -598,11 +598,14 @@ _nm_connection_find_base_type_setting (NMConnection *connection) continue; } else if (s_iter_prio == setting_prio) { NMSettingConnection *s_con = nm_connection_get_setting_connection (connection); + const char *type; - if (!s_con) - return NULL; - return nm_connection_get_setting_by_name (connection, - nm_setting_connection_get_connection_type (s_con)); + if (s_con) { + type = nm_setting_connection_get_connection_type (s_con); + if (type) + return nm_connection_get_setting_by_name (connection, type); + } + return NULL; } } setting = s_iter; From c292f3ed859b0e57a6d52d066c7068f567c570fd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 17:54:32 +0200 Subject: [PATCH 09/16] device: hide nm_device_factory_get_supported_types() function The simple link-types/setting-types mechanism doesn't really cut it because for the bluetooth NAP connection.type is "bluetooth", but it shall be primarily handled by the bridge factory. It's internal API that allows for a basic matching of the factory. It is however not sophisticated enough for the full complexity. Make it as internal API only. --- src/devices/nm-device-factory.c | 2 +- src/devices/nm-device-factory.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index a2447ad66d..1c16e1b782 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -60,7 +60,7 @@ nm_device_factory_emit_component_added (NMDeviceFactory *factory, GObject *compo return consumed; } -void +static void nm_device_factory_get_supported_types (NMDeviceFactory *factory, const NMLinkType **out_link_types, const char *const**out_setting_types) diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h index 836af5f522..0c590f657a 100644 --- a/src/devices/nm-device-factory.h +++ b/src/devices/nm-device-factory.h @@ -178,10 +178,6 @@ typedef NMDeviceFactory * (*NMDeviceFactoryCreateFunc) (GError **error); /*****************************************************************************/ -void nm_device_factory_get_supported_types (NMDeviceFactory *factory, - const NMLinkType **out_link_types, - const char *const**out_setting_types); - const char *nm_device_factory_get_connection_parent (NMDeviceFactory *factory, NMConnection *connection); From c74a6b305c30f573e264da6c24c88faa75e9f584 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 18:24:43 +0200 Subject: [PATCH 10/16] device: remove duplicate check for NMDeviceFactory's _add_factory() The duplicate check is based only on the link-types and setting-types. However, that doesn't really cut it because in case of bluetooth NAP connections, NMBridgeDeviceFactory is responsible for the connection, although connection.type is "bluetooth". This is only here to catch loading invalid plugins. But at the point where we load an invalid plugin, the process is hosed. This is at best an assertion, but rather pointless really. --- src/devices/nm-device-factory.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 1c16e1b782..c09212cddb 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -331,12 +331,10 @@ nm_device_factory_manager_for_each_factory (NMDeviceFactoryManagerFactoryFunc ca static gboolean _add_factory (NMDeviceFactory *factory, - gboolean check_duplicates, const char *path, NMDeviceFactoryManagerFactoryFunc callback, gpointer user_data) { - NMDeviceFactory *found = NULL; const NMLinkType *link_types = NULL; const char *const*setting_types = NULL; int i; @@ -345,16 +343,6 @@ _add_factory (NMDeviceFactory *factory, g_return_val_if_fail (factories_by_setting, FALSE); nm_device_factory_get_supported_types (factory, &link_types, &setting_types); - if (check_duplicates) { - found = find_factory (link_types, setting_types); - if (found) { - nm_log_warn (LOGD_PLATFORM, "Loading device plugin failed: multiple plugins " - "for same type (using '%s' instead of '%s')", - (char *) g_object_get_qdata (G_OBJECT (found), plugin_path_quark ()), - path); - return FALSE; - } - } g_object_set_qdata_full (G_OBJECT (factory), plugin_path_quark (), g_strdup (path), g_free); for (i = 0; link_types && link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) @@ -376,7 +364,7 @@ _load_internal_factory (GType factory_gtype, NMDeviceFactory *factory; factory = (NMDeviceFactory *) g_object_new (factory_gtype, NULL); - _add_factory (factory, FALSE, "internal", callback, user_data); + _add_factory (factory, "internal", callback, user_data); } void @@ -451,7 +439,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call } g_clear_error (&error); - _add_factory (factory, TRUE, g_module_name (plugin), callback, user_data); + _add_factory (factory, g_module_name (plugin), callback, user_data); g_object_unref (factory); } From abdf9a3673657bc543f8f454b51ac35c7d6a44c5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 14:55:41 +0200 Subject: [PATCH 11/16] all: change handling of connection.type for bluetooth NAP and in general Branch f9b1bc16e9e691ab89caf883f33d94be72364671 added bluetooth NAP support. A NAP connection is of connection.type "bluetooth", but it also has a "bridge" setting. Also, it is primarily handled by NMDeviceBridge and NMBridgeDeviceFactory (with help from NMBluezManager). However, don't let nm_connection_get_connection_type() and nm_connnection_is_type() lie about what the connection.type is. The type is "bluetooth" for most purposes -- at least, as far as the client is concerned (and the public API of libnm). This restores previous API behavior, where nm_connection_get_connection_type() and nm_connection_is_type() would be simple accessors to the "connection.type" property. Only a few places care about the bridge aspect, and those places need special treatment. For example NMDeviceBridge needs to be fully aware that it can handle bluetooth NAP connection. That is nothing new: if you handle a connection of any type, you must know which fields matter and what they mean. It's not enough that nm_connection_get_connection_type() for bluetooth NAP connectins is claiming to be a bridge. Counter examples, where the original behavior is right: src/nm-manager.c- g_set_error (error, src/nm-manager.c- NM_MANAGER_ERROR, src/nm-manager.c- NM_MANAGER_ERROR_FAILED, src/nm-manager.c- "NetworkManager plugin for '%s' unavailable", src/nm-manager.c: nm_connection_get_connection_type (connection)); the correct message is: "no bluetooth plugin available", not "bridge". src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: if ( ( nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: && !nm_connection_get_setting_pppoe (connection)) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: || nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: || nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: || nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: || nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c: || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c- return TRUE; the correct behavior is for ifcfg-rh plugin to reject bluetooth NAP connections, not proceed and store it. --- clients/common/nm-secret-agent-simple.c | 35 +++++--- libnm-core/nm-connection.c | 30 +++---- libnm/nm-device-bridge.c | 11 ++- libnm/nm-device-bt.c | 10 ++- src/devices/bluetooth/nm-bluez-device.c | 4 + src/devices/nm-device-bridge.c | 10 ++- src/devices/nm-device-factory.c | 110 ++++++++---------------- 7 files changed, 102 insertions(+), 108 deletions(-) diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index 97bbf0d02a..0faf68a567 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -543,23 +543,30 @@ request_secrets_from_ui (NMSecretAgentSimpleRequest *request) TRUE); g_ptr_array_add (secrets, secret); } else if (nm_connection_is_type (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { - NMSetting *setting; + NMSetting *setting = NULL; - setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_GSM_SETTING_NAME); - if (!setting) - setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_CDMA_SETTING_NAME); + setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME); + if ( setting + && !nm_streq0 (nm_setting_bluetooth_get_connection_type (NM_SETTING_BLUETOOTH (setting)), NM_SETTING_BLUETOOTH_TYPE_NAP)) { + setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_GSM_SETTING_NAME); + if (!setting) + setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_CDMA_SETTING_NAME); + } - title = _("Mobile broadband network password"); - msg = g_strdup_printf (_("A password is required to connect to '%s'."), - nm_connection_get_id (request->connection)); + if (setting) { + title = _("Mobile broadband network password"); + msg = g_strdup_printf (_("A password is required to connect to '%s'."), + nm_connection_get_id (request->connection)); - secret = nm_secret_agent_simple_secret_new (_("Password"), - setting, - "password", - NULL, - NULL, - TRUE); - g_ptr_array_add (secrets, secret); + secret = nm_secret_agent_simple_secret_new (_("Password"), + setting, + "password", + NULL, + NULL, + TRUE); + g_ptr_array_add (secrets, secret); + } else + ok = FALSE; } else if (nm_connection_is_type (request->connection, NM_SETTING_VPN_SETTING_NAME)) { NMSettingConnection *s_con; diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index e2f51dfb96..a5a4643750 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -1664,16 +1664,9 @@ nm_connection_to_dbus (NMConnection *connection, gboolean nm_connection_is_type (NMConnection *connection, const char *type) { - NMSetting *setting; + g_return_val_if_fail (type, FALSE); - g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); - g_return_val_if_fail (type != NULL, FALSE); - - setting = nm_connection_get_setting_by_name (connection, type); - if (!setting) - return FALSE; - - return _nm_setting_get_base_type_priority (setting) != NM_SETTING_PRIORITY_INVALID; + return nm_streq0 (type, nm_connection_get_connection_type (connection)); } static int @@ -1902,19 +1895,22 @@ nm_connection_get_id (NMConnection *connection) * nm_connection_get_connection_type: * @connection: the #NMConnection * - * Returns: the connection's base type. + * A shortcut to return the type from the connection's #NMSettingConnection. + * + * Returns: the type from the connection's 'connection' setting **/ const char * nm_connection_get_connection_type (NMConnection *connection) { - NMSetting *setting; + NMSettingConnection *s_con; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - setting = _nm_connection_find_base_type_setting (connection); - if (!setting) + s_con = nm_connection_get_setting_connection (connection); + if (!s_con) return NULL; - return nm_setting_get_name (setting); + + return nm_setting_connection_get_connection_type (s_con); } /** @@ -1949,10 +1945,12 @@ nm_connection_is_virtual (NMConnection *connection) NMSettingInfiniband *s_ib; s_ib = nm_connection_get_setting_infiniband (connection); - g_return_val_if_fail (s_ib != NULL, FALSE); - return nm_setting_infiniband_get_virtual_interface_name (s_ib) != NULL; + return s_ib && nm_setting_infiniband_get_virtual_interface_name (s_ib); } + if (nm_streq (type, NM_SETTING_BLUETOOTH_SETTING_NAME)) + return !!_nm_connection_get_setting_bluetooth_for_nap (connection); + return FALSE; } diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c index 55f09a20fa..27f362b2d6 100644 --- a/libnm/nm-device-bridge.c +++ b/libnm/nm-device-bridge.c @@ -107,9 +107,14 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro return FALSE; if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) { - g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, - _("The connection was not a bridge connection.")); - return FALSE; + if ( _nm_connection_get_setting_bluetooth_for_nap (connection) + && nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { + /* a bluetooth NAP setting is a compatible connection for a bridge. */ + } else { + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + _("The connection was not a bridge connection.")); + return FALSE; + } } /* FIXME: check ports? */ diff --git a/libnm/nm-device-bt.c b/libnm/nm-device-bt.c index 0fcd28b9e8..a47e39580f 100644 --- a/libnm/nm-device-bt.c +++ b/libnm/nm-device-bt.c @@ -131,12 +131,19 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->connection_compatible (device, connection, error)) return FALSE; - if (!nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { + if ( !nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME) + || !(s_bt = nm_connection_get_setting_bluetooth (connection))) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not a Bluetooth connection.")); return FALSE; } + if (nm_streq0 (nm_setting_bluetooth_get_connection_type (s_bt), NM_SETTING_BLUETOOTH_TYPE_NAP)) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + _("The connection is of Bluetooth NAP type.")); + return FALSE; + } + /* Check BT address */ hw_addr = nm_device_bt_get_hw_address (NM_DEVICE_BT (device)); if (hw_addr) { @@ -145,7 +152,6 @@ connection_compatible (NMDevice *device, NMConnection *connection, GError **erro _("Invalid device Bluetooth address.")); return FALSE; } - s_bt = nm_connection_get_setting_bluetooth (connection); setting_addr = nm_setting_bluetooth_get_bdaddr (s_bt); if (setting_addr && !nm_utils_hwaddr_matches (setting_addr, -1, hw_addr, -1)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index e42f6533da..af3ab77f9f 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -343,6 +343,10 @@ connection_compatible (NMBluezDevice *self, NMConnection *connection) return FALSE; bt_type = nm_setting_bluetooth_get_connection_type (s_bt); + + if (nm_streq (bt_type, NM_SETTING_BLUETOOTH_TYPE_NAP)) + return FALSE; + if ( g_str_equal (bt_type, NM_SETTING_BLUETOOTH_TYPE_DUN) && !(priv->capabilities & NM_BT_CAPABILITY_DUN)) return FALSE; diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 166e1bdd27..6a0d383c3c 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -136,9 +136,17 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) return FALSE; s_bridge = nm_connection_get_setting_bridge (connection); - if (!s_bridge || !nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) + if (!s_bridge) return FALSE; + if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) { + if ( nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME) + && _nm_connection_get_setting_bluetooth_for_nap (connection)) { + /* a bluetooth NAP connection is handled by the bridge */ + } else + return FALSE; + } + mac_address = nm_setting_bridge_get_mac_address (s_bridge); if (mac_address && nm_device_is_real (device)) { const char *hw_addr; diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index c09212cddb..d0ad791acb 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -30,6 +30,8 @@ #include "platform/nm-platform.h" #include "nm-utils.h" +#include "nm-core-internal.h" +#include "nm-setting-bluetooth.h" #define PLUGIN_PREFIX "libnm-device-plugin-" @@ -90,56 +92,26 @@ nm_device_factory_create_device (NMDeviceFactory *factory, GError **error) { NMDeviceFactoryClass *klass; - const NMLinkType *link_types = NULL; - const char *const*setting_types = NULL; - int i; NMDevice *device; gboolean ignore = FALSE; g_return_val_if_fail (factory, NULL); g_return_val_if_fail (iface && *iface, NULL); - g_return_val_if_fail (plink || connection, NULL); - g_return_val_if_fail (!plink || !connection, NULL); - - nm_device_factory_get_supported_types (factory, &link_types, &setting_types); - - NM_SET_OUT (out_ignore, FALSE); - if (plink) { + g_return_val_if_fail (!connection, NULL); g_return_val_if_fail (strcmp (iface, plink->name) == 0, NULL); - - for (i = 0; link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) { - if (plink->type == link_types[i]) - break; - } - - if (link_types[i] == NM_LINK_TYPE_UNKNOWN) { - g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, - "Device factory %s does not support link type %s (%d)", - G_OBJECT_TYPE_NAME (factory), - plink->kind, plink->type); - return NULL; - } - } else if (connection) { - for (i = 0; setting_types && setting_types[i]; i++) { - if (nm_connection_is_type (connection, setting_types[i])) - break; - } - - if (!setting_types[i]) { - g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, - "Device factory %s does not support connection type %s", - G_OBJECT_TYPE_NAME (factory), - nm_connection_get_connection_type (connection)); - return NULL; - } - } + nm_assert (factory == nm_device_factory_manager_find_factory_for_link_type (plink->type)); + } else if (connection) + nm_assert (factory == nm_device_factory_manager_find_factory_for_connection (connection)); + else + g_return_val_if_reached (NULL); klass = NM_DEVICE_FACTORY_GET_CLASS (factory); if (!klass->create_device) { g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, "Device factory %s cannot manage new devices", G_OBJECT_TYPE_NAME (factory)); + NM_SET_OUT (out_ignore, FALSE); return NULL; } @@ -252,51 +224,45 @@ _cleanup (void) g_clear_pointer (&factories_by_setting, g_hash_table_unref); } -static NMDeviceFactory * -find_factory (const NMLinkType *needle_link_types, - const char *const*needle_setting_types) -{ - NMDeviceFactory *found; - guint i; - - g_return_val_if_fail (factories_by_link, NULL); - g_return_val_if_fail (factories_by_setting, NULL); - - /* NMLinkType search */ - for (i = 0; needle_link_types && needle_link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) { - found = g_hash_table_lookup (factories_by_link, GUINT_TO_POINTER (needle_link_types[i])); - if (found) - return found; - } - - /* NMSetting name search */ - for (i = 0; needle_setting_types && needle_setting_types[i]; i++) { - found = g_hash_table_lookup (factories_by_setting, needle_setting_types[i]); - if (found) - return found; - } - - return NULL; -} - NMDeviceFactory * nm_device_factory_manager_find_factory_for_link_type (NMLinkType link_type) { - const NMLinkType ltypes[2] = { link_type, NM_LINK_TYPE_NONE }; + g_return_val_if_fail (factories_by_link, NULL); - if (link_type == NM_LINK_TYPE_UNKNOWN) - return NULL; - g_return_val_if_fail (link_type > NM_LINK_TYPE_UNKNOWN, NULL); - return find_factory (ltypes, NULL); + return g_hash_table_lookup (factories_by_link, GUINT_TO_POINTER (link_type)); } NMDeviceFactory * nm_device_factory_manager_find_factory_for_connection (NMConnection *connection) { - const char *const stypes[2] = { nm_connection_get_connection_type (connection), NULL }; + const char *type; - g_assert (stypes[0]); - return find_factory (NULL, stypes); + g_return_val_if_fail (factories_by_setting, NULL); + + type = nm_connection_get_connection_type (connection); + + if ( nm_streq (type, NM_SETTING_BLUETOOTH_SETTING_NAME) + && _nm_connection_get_setting_bluetooth_for_nap (connection)) { + /* for Bluetooth NAP connections, we return the bridge factory + * instead of the bluetooth factory. + * + * In a way, this is a hack. The more orthodox solution would + * be that device factories don't only announce supported setting + * types, but instead match on a full fledged NMConnection. + * + * However, our device-factories are known at compile time. + * There is no need to keep this generic. We *know* which + * factory to choose. Making this generic would not make it + * cleaner. */ + if (!g_hash_table_lookup (factories_by_setting, type)) { + /* we need both the bluetooth and the bridge factory + * to make this work. */ + return NULL; + } + type = NM_SETTING_BRIDGE_SETTING_NAME; + } + + return g_hash_table_lookup (factories_by_setting, type); } void From 4c094adfb7216dccb14f5ba3783a33809562390a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Jun 2017 21:06:17 +0200 Subject: [PATCH 12/16] libnm: streamline functions in nm-connection.c Functions call each other, like nm_connection_get_id() nm_connection_get_setting_connection() nm_connection_get_setting() Along the way, each function asserts that the input argument is of type NMConnection via g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); Avoid such duplicate assertions when we already verifyied the input argument. For example, in case of nm_connection_get_id(), don't check just call nm_connection_get_setting_connection() right away. It already asserts. The downside is, that the assertion no longer fails in the function that immediately called it. But these are assertions after all. --- libnm-core/nm-connection.c | 214 +++++++++++++------------------------ libnm-core/nm-setting.c | 2 +- 2 files changed, 76 insertions(+), 140 deletions(-) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index a5a4643750..e41e6b6662 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -93,10 +93,16 @@ _setting_release (gpointer key, gpointer value, gpointer user_data) static void _nm_connection_add_setting (NMConnection *connection, NMSetting *setting) { - NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection); - const char *name = G_OBJECT_TYPE_NAME (setting); + NMConnectionPrivate *priv; + const char *name; NMSetting *s_old; + nm_assert (NM_IS_CONNECTION (connection)); + nm_assert (NM_IS_SETTING (setting)); + + priv = NM_CONNECTION_GET_PRIVATE (connection); + name = G_OBJECT_TYPE_NAME (setting); + if ((s_old = g_hash_table_lookup (priv->settings, (gpointer) name))) g_signal_handlers_disconnect_by_func (s_old, setting_changed_cb, connection); g_hash_table_insert (priv->settings, (gpointer) name, setting); @@ -160,6 +166,24 @@ nm_connection_remove_setting (NMConnection *connection, GType setting_type) _nm_connection_remove_setting (connection, setting_type); } +static gpointer +_connection_get_setting (NMConnection *connection, GType setting_type) +{ + nm_assert (NM_IS_CONNECTION (connection)); + nm_assert (g_type_is_a (setting_type, NM_TYPE_SETTING)); + + return g_hash_table_lookup (NM_CONNECTION_GET_PRIVATE (connection)->settings, + g_type_name (setting_type)); +} + +static gpointer +_connection_get_setting_check (NMConnection *connection, GType setting_type) +{ + g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); + + return _connection_get_setting (connection, setting_type); +} + /** * nm_connection_get_setting: * @connection: a #NMConnection @@ -174,11 +198,9 @@ nm_connection_remove_setting (NMConnection *connection, GType setting_type) NMSetting * nm_connection_get_setting (NMConnection *connection, GType setting_type) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (g_type_is_a (setting_type, NM_TYPE_SETTING), NULL); - return (NMSetting *) g_hash_table_lookup (NM_CONNECTION_GET_PRIVATE (connection)->settings, - g_type_name (setting_type)); + return _connection_get_setting_check (connection, setting_type); } /** @@ -198,11 +220,9 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name) GType type; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - g_return_val_if_fail (name != NULL, NULL); type = nm_setting_lookup_type (name); - - return type ? nm_connection_get_setting (connection, type) : NULL; + return type ? _connection_get_setting (connection, type) : NULL; } static gboolean @@ -1704,7 +1724,7 @@ nm_connection_for_each_setting_value (NMConnection *connection, guint i, size; g_return_if_fail (NM_IS_CONNECTION (connection)); - g_return_if_fail (func != NULL); + g_return_if_fail (func); priv = NM_CONNECTION_GET_PRIVATE (connection); @@ -1778,10 +1798,7 @@ nm_connection_set_path (NMConnection *connection, const char *path) priv = NM_CONNECTION_GET_PRIVATE (connection); g_free (priv->path); - priv->path = NULL; - - if (path) - priv->path = g_strdup (path); + priv->path = g_strdup (path); } /** @@ -1819,10 +1836,7 @@ nm_connection_get_interface_name (NMConnection *connection) { NMSettingConnection *s_con; - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - s_con = nm_connection_get_setting_connection (connection); - return s_con ? nm_setting_connection_get_interface_name (s_con) : NULL; } @@ -1860,13 +1874,8 @@ nm_connection_get_uuid (NMConnection *connection) { NMSettingConnection *s_con; - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - s_con = nm_connection_get_setting_connection (connection); - if (!s_con) - return NULL; - - return nm_setting_connection_get_uuid (s_con); + return s_con ? nm_setting_connection_get_uuid (s_con) : NULL; } /** @@ -1882,13 +1891,8 @@ nm_connection_get_id (NMConnection *connection) { NMSettingConnection *s_con; - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - s_con = nm_connection_get_setting_connection (connection); - if (!s_con) - return NULL; - - return nm_setting_connection_get_id (s_con); + return s_con ? nm_setting_connection_get_id (s_con) : NULL; } /** @@ -1904,13 +1908,8 @@ nm_connection_get_connection_type (NMConnection *connection) { NMSettingConnection *s_con; - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - s_con = nm_connection_get_setting_connection (connection); - if (!s_con) - return NULL; - - return nm_setting_connection_get_connection_type (s_con); + return s_con ? nm_setting_connection_get_connection_type (s_con) : NULL; } /** @@ -1925,9 +1924,11 @@ nm_connection_get_connection_type (NMConnection *connection) gboolean nm_connection_is_virtual (NMConnection *connection) { - const char *type = nm_connection_get_connection_type (connection); + const char *type; - g_return_val_if_fail (type != NULL, FALSE); + type = nm_connection_get_connection_type (connection); + if (!type) + return FALSE; if ( !strcmp (type, NM_SETTING_BOND_SETTING_NAME) || !strcmp (type, NM_SETTING_DUMMY_SETTING_NAME) @@ -1971,10 +1972,11 @@ nm_connection_get_virtual_device_description (NMConnection *connection) const char *type; const char *iface = NULL, *display_type = NULL; - iface = nm_connection_get_interface_name (connection); - type = nm_connection_get_connection_type (connection); - g_return_val_if_fail (type != NULL, FALSE); + if (!type) + return NULL; + + iface = nm_connection_get_interface_name (connection); if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME)) display_type = _("Bond"); @@ -2009,9 +2011,7 @@ nm_connection_get_virtual_device_description (NMConnection *connection) NMSetting8021x * nm_connection_get_setting_802_1x (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSetting8021x *) nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_802_1X); } /** @@ -2025,9 +2025,7 @@ nm_connection_get_setting_802_1x (NMConnection *connection) NMSettingBluetooth * nm_connection_get_setting_bluetooth (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_BLUETOOTH); } /** @@ -2041,9 +2039,7 @@ nm_connection_get_setting_bluetooth (NMConnection *connection) NMSettingBond * nm_connection_get_setting_bond (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingBond *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BOND); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_BOND); } /** @@ -2057,9 +2053,7 @@ nm_connection_get_setting_bond (NMConnection *connection) NMSettingTeam * nm_connection_get_setting_team (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingTeam *) nm_connection_get_setting (connection, NM_TYPE_SETTING_TEAM); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_TEAM); } /** @@ -2073,9 +2067,7 @@ nm_connection_get_setting_team (NMConnection *connection) NMSettingTeamPort * nm_connection_get_setting_team_port (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingTeamPort *) nm_connection_get_setting (connection, NM_TYPE_SETTING_TEAM_PORT); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_TEAM_PORT); } /** @@ -2089,9 +2081,7 @@ nm_connection_get_setting_team_port (NMConnection *connection) NMSettingBridge * nm_connection_get_setting_bridge (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingBridge *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BRIDGE); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_BRIDGE); } /** @@ -2105,9 +2095,7 @@ nm_connection_get_setting_bridge (NMConnection *connection) NMSettingCdma * nm_connection_get_setting_cdma (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingCdma *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CDMA); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_CDMA); } /** @@ -2121,9 +2109,7 @@ nm_connection_get_setting_cdma (NMConnection *connection) NMSettingConnection * nm_connection_get_setting_connection (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_CONNECTION); } /** @@ -2137,9 +2123,7 @@ nm_connection_get_setting_connection (NMConnection *connection) NMSettingDcb * nm_connection_get_setting_dcb (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingDcb *) nm_connection_get_setting (connection, NM_TYPE_SETTING_DCB); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_DCB); } /** @@ -2155,9 +2139,7 @@ nm_connection_get_setting_dcb (NMConnection *connection) NMSettingDummy * nm_connection_get_setting_dummy (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingDummy *) nm_connection_get_setting (connection, NM_TYPE_SETTING_DUMMY); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_DUMMY); } /** @@ -2171,9 +2153,7 @@ nm_connection_get_setting_dummy (NMConnection *connection) NMSettingGeneric * nm_connection_get_setting_generic (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingGeneric *) nm_connection_get_setting (connection, NM_TYPE_SETTING_GENERIC); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_GENERIC); } /** @@ -2187,9 +2167,7 @@ nm_connection_get_setting_generic (NMConnection *connection) NMSettingGsm * nm_connection_get_setting_gsm (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingGsm *) nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_GSM); } /** @@ -2203,9 +2181,7 @@ nm_connection_get_setting_gsm (NMConnection *connection) NMSettingInfiniband * nm_connection_get_setting_infiniband (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingInfiniband *) nm_connection_get_setting (connection, NM_TYPE_SETTING_INFINIBAND); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_INFINIBAND); } /** @@ -2224,9 +2200,7 @@ nm_connection_get_setting_infiniband (NMConnection *connection) NMSettingIPConfig * nm_connection_get_setting_ip4_config (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingIPConfig *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_IP4_CONFIG); } /** @@ -2242,9 +2216,7 @@ nm_connection_get_setting_ip4_config (NMConnection *connection) NMSettingIPTunnel * nm_connection_get_setting_ip_tunnel (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingIPTunnel *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP_TUNNEL); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_IP_TUNNEL); } /** @@ -2263,9 +2235,7 @@ nm_connection_get_setting_ip_tunnel (NMConnection *connection) NMSettingIPConfig * nm_connection_get_setting_ip6_config (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingIPConfig *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_IP6_CONFIG); } /** @@ -2281,9 +2251,7 @@ nm_connection_get_setting_ip6_config (NMConnection *connection) NMSettingMacsec * nm_connection_get_setting_macsec (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingMacsec *) nm_connection_get_setting (connection, NM_TYPE_SETTING_MACSEC); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_MACSEC); } /** @@ -2299,9 +2267,7 @@ nm_connection_get_setting_macsec (NMConnection *connection) NMSettingMacvlan * nm_connection_get_setting_macvlan (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingMacvlan *) nm_connection_get_setting (connection, NM_TYPE_SETTING_MACVLAN); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_MACVLAN); } /** @@ -2315,9 +2281,7 @@ nm_connection_get_setting_macvlan (NMConnection *connection) NMSettingOlpcMesh * nm_connection_get_setting_olpc_mesh (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingOlpcMesh *) nm_connection_get_setting (connection, NM_TYPE_SETTING_OLPC_MESH); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_OLPC_MESH); } /** @@ -2331,9 +2295,7 @@ nm_connection_get_setting_olpc_mesh (NMConnection *connection) NMSettingPpp * nm_connection_get_setting_ppp (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingPpp *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_PPP); } /** @@ -2347,9 +2309,7 @@ nm_connection_get_setting_ppp (NMConnection *connection) NMSettingPppoe * nm_connection_get_setting_pppoe (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingPppoe *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_PPPOE); } /** @@ -2365,9 +2325,7 @@ nm_connection_get_setting_pppoe (NMConnection *connection) NMSettingProxy * nm_connection_get_setting_proxy (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingProxy *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PROXY); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_PROXY); } /** @@ -2381,9 +2339,7 @@ nm_connection_get_setting_proxy (NMConnection *connection) NMSettingSerial * nm_connection_get_setting_serial (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingSerial *) nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_SERIAL); } /** @@ -2399,9 +2355,7 @@ nm_connection_get_setting_serial (NMConnection *connection) NMSettingTun * nm_connection_get_setting_tun (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingTun *) nm_connection_get_setting (connection, NM_TYPE_SETTING_TUN); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_TUN); } /** @@ -2415,9 +2369,7 @@ nm_connection_get_setting_tun (NMConnection *connection) NMSettingVpn * nm_connection_get_setting_vpn (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingVpn *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_VPN); } /** @@ -2433,9 +2385,7 @@ nm_connection_get_setting_vpn (NMConnection *connection) NMSettingVxlan * nm_connection_get_setting_vxlan (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingVxlan *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VXLAN); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_VXLAN); } /** @@ -2449,9 +2399,7 @@ nm_connection_get_setting_vxlan (NMConnection *connection) NMSettingWimax * nm_connection_get_setting_wimax (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingWimax *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_WIMAX); } /** @@ -2465,9 +2413,7 @@ nm_connection_get_setting_wimax (NMConnection *connection) NMSettingWired * nm_connection_get_setting_wired (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingWired *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_WIRED); } /** @@ -2481,9 +2427,7 @@ nm_connection_get_setting_wired (NMConnection *connection) NMSettingAdsl * nm_connection_get_setting_adsl (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingAdsl *) nm_connection_get_setting (connection, NM_TYPE_SETTING_ADSL); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_ADSL); } /** @@ -2497,9 +2441,7 @@ nm_connection_get_setting_adsl (NMConnection *connection) NMSettingWireless * nm_connection_get_setting_wireless (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_WIRELESS); } /** @@ -2513,9 +2455,7 @@ nm_connection_get_setting_wireless (NMConnection *connection) NMSettingWirelessSecurity * nm_connection_get_setting_wireless_security (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); } /** @@ -2529,9 +2469,7 @@ nm_connection_get_setting_wireless_security (NMConnection *connection) NMSettingBridgePort * nm_connection_get_setting_bridge_port (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingBridgePort *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BRIDGE_PORT); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_BRIDGE_PORT); } /** @@ -2545,9 +2483,7 @@ nm_connection_get_setting_bridge_port (NMConnection *connection) NMSettingVlan * nm_connection_get_setting_vlan (NMConnection *connection) { - g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - return (NMSettingVlan *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VLAN); + return _connection_get_setting_check (connection, NM_TYPE_SETTING_VLAN); } NMSettingBluetooth * @@ -2586,7 +2522,7 @@ nm_connection_get_private (NMConnection *connection) key = NM_CACHED_QUARK ("NMConnectionPrivate"); priv = g_object_get_qdata ((GObject *) connection, key); - if (!priv) { + if (G_UNLIKELY (!priv)) { priv = g_slice_new0 (NMConnectionPrivate); g_object_set_qdata_full ((GObject *) connection, key, priv, (GDestroyNotify) nm_connection_private_free); diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 16e987cae4..3e2ee3debc 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -221,7 +221,7 @@ nm_setting_lookup_type (const char *name) { SettingInfo *info; - g_return_val_if_fail (name != NULL, G_TYPE_INVALID); + g_return_val_if_fail (name, G_TYPE_INVALID); _ensure_registered (); From 113e8ad6e633e2ca34e7bb05eb92850dd0b9cd20 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 3 Jun 2017 13:31:46 +0200 Subject: [PATCH 13/16] device: inline bluetooth function in nm-device-bridge.c The 3 bluetooth NAP hooks are called each only once. Inline them. It is still very easy to understand where the bluetooth related functions are invoked: grep for nm_bt_vtable_network_server. In deactivate(), don't bother checking whether the current active connection is a bluetooth type. Just always call unregister_bridge(). It's fast, and does nothing in case the bridge isn't registered. I change it because I disagree with the previous naming. For example bt_network_server_available() would not only call is_available(). Instead, it checks whether the connection can activate regarding availability of the bluetooth connection (meaning, it returns TRUE if it's not a bluetooth connection or if the bluez manager gives green light). In the bridge case, it doesn't check any network-server availability. There is already a function with a meaningful name for this behavior: check_connection_available(). Same with bt_network_server_register(). It would indicate success, if the applied connection is not a bluetooth connection. In cases, where it didn't actually register anything. A function called bt_network_server_register() should only return success if it actually registered anything. --- src/devices/nm-device-bridge.c | 82 ++++++++++++---------------------- 1 file changed, 29 insertions(+), 53 deletions(-) diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 6a0d383c3c..58400211b2 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -51,52 +51,6 @@ G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE) const NMBtVTableNetworkServer *nm_bt_vtable_network_server = NULL; -static gboolean -bt_network_server_available (NMConnection *connection) -{ - NMSettingBluetooth *s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); - - if (!s_bt) - return TRUE; - if (!nm_bt_vtable_network_server) - return FALSE; - return nm_bt_vtable_network_server->is_available (nm_bt_vtable_network_server, - nm_setting_bluetooth_get_bdaddr (s_bt)); -} - -static gboolean -bt_network_server_register (NMDevice *self) -{ - NMConnection *connection = nm_device_get_applied_connection (self); - NMSettingBluetooth *s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); - - if (!s_bt) - return TRUE; - if (!nm_bt_vtable_network_server) - return FALSE; - return nm_bt_vtable_network_server->register_bridge (nm_bt_vtable_network_server, - nm_setting_bluetooth_get_bdaddr (s_bt), - self); -} - -static void -bt_network_server_unregister (NMDevice *self) -{ - NMConnection *connection = nm_device_get_applied_connection (self); - NMSettingBluetooth *s_bt; - - if (!connection) - return; - s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); - if (!s_bt) - return; - - if (!nm_bt_vtable_network_server) - return; - nm_bt_vtable_network_server->unregister_bridge (nm_bt_vtable_network_server, - self); -} - /*****************************************************************************/ static NMDeviceCapabilities @@ -117,8 +71,14 @@ check_connection_available (NMDevice *device, NMDeviceCheckConAvailableFlags flags, const char *specific_object) { - if (!bt_network_server_available (connection)) - return FALSE; + NMSettingBluetooth *s_bt; + + s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); + if (s_bt) { + return nm_bt_vtable_network_server + && nm_bt_vtable_network_server->is_available (nm_bt_vtable_network_server, + nm_setting_bluetooth_get_bdaddr (s_bt)); + } /* Connections are always available because the carrier state is determined * by the bridge port carrier states, not the bridge's state. @@ -388,10 +348,21 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) static NMActStageReturn act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) { - if (!bt_network_server_register (device)) { - /* The HCI we could use is no longer present. */ - *out_failure_reason = NM_DEVICE_STATE_REASON_REMOVED; - return NM_ACT_STAGE_RETURN_FAILURE; + NMConnection *connection; + NMSettingBluetooth *s_bt; + + connection = nm_device_get_applied_connection (device); + + s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); + if (s_bt) { + if ( !nm_bt_vtable_network_server + || !nm_bt_vtable_network_server->register_bridge (nm_bt_vtable_network_server, + nm_setting_bluetooth_get_bdaddr (s_bt), + device)) { + /* The HCI we could use is no longer present. */ + *out_failure_reason = NM_DEVICE_STATE_REASON_REMOVED; + return NM_ACT_STAGE_RETURN_FAILURE; + } } return NM_ACT_STAGE_RETURN_SUCCESS; @@ -400,7 +371,12 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) static void deactivate (NMDevice *device) { - bt_network_server_unregister (device); + if (nm_bt_vtable_network_server) { + /* always call unregister. It does nothing if the device + * isn't registered as a hotspot bridge. */ + nm_bt_vtable_network_server->unregister_bridge (nm_bt_vtable_network_server, + device); + } } static gboolean From 40a295564775bb6a719d36286439e6498a283f58 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 3 Jun 2017 13:44:52 +0200 Subject: [PATCH 14/16] bluetooth: split _find_network_server() in two functions Instead of having a complex _find_network_server() function with several arguments, split it. Having multiple optional arguments to a find() function is fine, if all arguments consistently narrow down the search. For example nmp_cache_lookup_link_full(), where each argument is optional, and it restricts the search. For _find_network_server() that was not the case, because setting "addr" and "device" together would be non-sensical. --- src/devices/bluetooth/nm-bluez5-manager.c | 43 +++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index 83028a2c85..ded308464f 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -93,30 +93,37 @@ typedef struct { CList network_servers; } NetworkServer; -static NetworkServer* -_find_network_server (NMBluez5Manager *self, - const gchar *path, const gchar *addr, NMDevice *device) +static NetworkServer * +_find_network_server (NMBluez5Manager *self, const char *path, NMDevice *device) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NetworkServer *network_server; - CList *iter; - c_list_for_each (iter, &priv->network_servers) { - network_server = c_list_entry (iter, NetworkServer, network_servers); + nm_assert (path || NM_IS_DEVICE (device)); - /* Device and path matches are exact. */ - if ( (path && !strcmp (network_server->path, path)) - || (device && network_server->device == device)) - return network_server; + c_list_for_each_entry (network_server, &priv->network_servers, network_servers) { + if (path && !nm_streq (network_server->path, path)) + continue; + if (device && network_server->device != device) + continue; + return network_server; + } + return NULL; +} +static NetworkServer * +_find_network_server_for_addr (NMBluez5Manager *self, const char *addr) +{ + NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); + NetworkServer *network_server; + + c_list_for_each_entry (network_server, &priv->network_servers, network_servers) { /* The address lookups need a server not assigned to a device * and tolerate an empty address as a wildcard for "any". */ - if ( (!path && !device) - && !network_server->device - && (!addr || !strcmp (network_server->addr, addr))) + if ( !network_server->device + && (!addr || nm_streq (network_server->addr, addr))) return network_server; } - return NULL; } @@ -163,7 +170,7 @@ network_server_is_available (const NMBtVTableNetworkServer *vtable, { NMBluez5Manager *self = NETWORK_SERVER_VTABLE_GET_NM_BLUEZ5_MANAGER (vtable); - return !!_find_network_server (self, NULL, addr, NULL); + return !!_find_network_server_for_addr (self, addr); } static gboolean @@ -173,7 +180,7 @@ network_server_register_bridge (const NMBtVTableNetworkServer *vtable, { NMBluez5Manager *self = NETWORK_SERVER_VTABLE_GET_NM_BLUEZ5_MANAGER (vtable); NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); - NetworkServer *network_server = _find_network_server (self, NULL, addr, NULL); + NetworkServer *network_server = _find_network_server_for_addr (self, addr); if (!network_server) { /* The device checked that a network server is available, before @@ -205,7 +212,7 @@ network_server_unregister_bridge (const NMBtVTableNetworkServer *vtable, NMDevice *device) { NMBluez5Manager *self = NETWORK_SERVER_VTABLE_GET_NM_BLUEZ5_MANAGER (vtable); - NetworkServer *network_server = _find_network_server (self, NULL, NULL, device); + NetworkServer *network_server = _find_network_server (self, NULL, device); if (network_server) _network_server_unregister (self, network_server); @@ -218,7 +225,7 @@ network_server_removed (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *s { NetworkServer *network_server; - network_server = _find_network_server (self, path, NULL, NULL); + network_server = _find_network_server (self, path, NULL); if (!network_server) return; From 6ecf78a19bfc1bc92344dbb37cc1a0c816aa7b92 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 3 Jun 2017 13:48:48 +0200 Subject: [PATCH 15/16] bluetooth/trivial: rename NetworkServer's network_servers field The list field should have a unique name and not the same as the list head. This avoids c_list_link_before (&priv->network_servers, &network_server->network_servers); c_list_for_each_entry (network_server, &priv->network_servers, network_servers) { --- src/devices/bluetooth/nm-bluez5-manager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index ded308464f..a203d6229d 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -90,7 +90,7 @@ typedef struct { char *path; char *addr; NMDevice *device; - CList network_servers; + CList lst_ns; } NetworkServer; static NetworkServer * @@ -101,7 +101,7 @@ _find_network_server (NMBluez5Manager *self, const char *path, NMDevice *device) nm_assert (path || NM_IS_DEVICE (device)); - c_list_for_each_entry (network_server, &priv->network_servers, network_servers) { + c_list_for_each_entry (network_server, &priv->network_servers, lst_ns) { if (path && !nm_streq (network_server->path, path)) continue; if (device && network_server->device != device) @@ -117,7 +117,7 @@ _find_network_server_for_addr (NMBluez5Manager *self, const char *addr) NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NetworkServer *network_server; - c_list_for_each_entry (network_server, &priv->network_servers, network_servers) { + c_list_for_each_entry (network_server, &priv->network_servers, lst_ns) { /* The address lookups need a server not assigned to a device * and tolerate an empty address as a wildcard for "any". */ if ( !network_server->device @@ -158,7 +158,7 @@ static void _network_server_free (NMBluez5Manager *self, NetworkServer *network_server) { _network_server_unregister (self, network_server); - c_list_unlink (&network_server->network_servers); + c_list_unlink (&network_server->lst_ns); g_free (network_server->path); g_free (network_server->addr); g_slice_free (NetworkServer, network_server); @@ -250,7 +250,7 @@ network_server_added (GDBusProxy *proxy, const gchar *path, const char *addr, NM network_server = g_slice_new0 (NetworkServer); network_server->path = g_strdup (path); network_server->addr = g_strdup (addr); - c_list_link_before (&priv->network_servers, &network_server->network_servers); + c_list_link_before (&priv->network_servers, &network_server->lst_ns); _LOGI ("NAP: added interface %s", addr); @@ -543,7 +543,7 @@ dispose (GObject *object) CList *iter, *safe; c_list_for_each_safe (iter, safe, &priv->network_servers) - _network_server_free (self, c_list_entry (iter, NetworkServer, network_servers)); + _network_server_free (self, c_list_entry (iter, NetworkServer, lst_ns)); if (priv->proxy) { g_signal_handlers_disconnect_by_func (priv->proxy, G_CALLBACK (name_owner_changed_cb), self); From c855ebf9435c86fefb99aa8b990c24f9c29412ac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 3 Jun 2017 14:06:25 +0200 Subject: [PATCH 16/16] bluetooth: assert against registering same device multiple times --- src/devices/bluetooth/nm-bluez5-manager.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index a203d6229d..af2ff0cdf5 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -182,6 +182,9 @@ network_server_register_bridge (const NMBtVTableNetworkServer *vtable, NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NetworkServer *network_server = _find_network_server_for_addr (self, addr); + nm_assert (NM_IS_DEVICE (device)); + nm_assert (!_find_network_server (self, NULL, device)); + if (!network_server) { /* The device checked that a network server is available, before * starting the activation, but for some reason it no longer is.