mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 20:00:09 +01:00
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.
This commit is contained in:
parent
c7e9f97800
commit
a973eacb3b
8 changed files with 70 additions and 53 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue