summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libnm-core/nm-connection.c6
-rw-r--r--libnm-core/nm-core-internal.h40
-rw-r--r--libnm-core/nm-setting-connection.c3
-rw-r--r--libnm-core/nm-setting-private.h8
-rw-r--r--libnm-core/nm-setting.c54
-rw-r--r--libnm-core/nm-utils.c4
-rw-r--r--libnm-core/tests/test-general.c6
-rw-r--r--src/nm-core-utils.c2
8 files changed, 70 insertions, 53 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index 2b9a05ca19..bd5a9d8854 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) {
@@ -1639,7 +1639,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 2f4e525be2..a206daaf75 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;