NetworkManager/src/libnm-core-impl/nm-setting-private.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

718 lines
41 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2011 Red Hat, Inc.
*/
#ifndef __NM_SETTING_PRIVATE_H__
#define __NM_SETTING_PRIVATE_H__
#if !((NETWORKMANAGER_COMPILATION) &NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE)
#error Cannot use this header.
#endif
#include "nm-setting.h"
#include "nm-setting-bridge.h"
#include "nm-connection.h"
#include "nm-core-enum-types.h"
#include "libnm-core-intern/nm-core-internal.h"
libnm: use NMMetaSettingInfo for tracking setting priority Previously, each (non abstract) NMSetting class had to register its name and priority via _nm_register_setting(). Note, that libnm-core.la already links against "nm-meta-setting.c", which also redundantly keeps track of the settings name and gtype as well. Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta data. The goal is to get rid of private data structures that track meta data about NMSetting classes. In this case, "registered_settings" hash. Instead, we should have one place where all this meta data is tracked. This was, it is also accessible as internal API, which can be useful (for keyfile). Note that NMSettingClass has some overlap with NMMetaSettingInfo. One difference is, that NMMetaSettingInfo is const, while NMSettingClass is only initialized during the class_init() method. Appart from that, it's mostly a matter of taste, whether we attach meta data to NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed by NMMetaSettingType. Note, that previously, _nm_register_setting() was private API. That means, no user could subclass a functioning NMSetting instance. The same is still true: NMMetaSettingInfo is internal API and users cannot access it to create their own NMSetting subclasses. But that is almost desired. libnm is not designed, to be extensible via subclassing, nor is it clear why that would be a useful thing to do. One day, we should remove the NMSetting and NMSettingClass definitions from public headers. Their only use is subclassing the types, which however does not work. While libnm-core was linking already against nm-meta-setting.c, nm_meta_setting_infos was unreferenced. So, this change increases the binary size of libnm and NetworkManager (1032 bytes). Note however that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
/*****************************************************************************/
typedef struct {
NMConnection *self;
NMSetting *settings[_NM_META_SETTING_TYPE_NUM];
/* D-Bus path of the connection, if any */
char *path;
} NMConnectionPrivate;
extern GTypeClass *_nm_simple_connection_class_instance;
extern int _nm_simple_connection_private_offset;
void _nm_connection_private_clear(NMConnectionPrivate *priv);
/*****************************************************************************/
/**
* NMSetting:
*
* The NMSetting struct contains only private data.
* It should only be accessed through the functions described below.
*/
struct _NMSetting {
GObject parent;
/* In the past, this struct was public API. Preserve ABI! */
};
struct _NMSettingClass {
GObjectClass parent;
/* In the past, this struct was public API. Preserve ABI! */
int (*verify)(NMSetting *setting, NMConnection *connection, GError **error);
gboolean (*verify_secrets)(NMSetting *setting, NMConnection *connection, GError **error);
GPtrArray *(*need_secrets)(NMSetting *setting);
int (*update_one_secret)(NMSetting *setting, const char *key, GVariant *value, GError **error);
gboolean (*get_secret_flags)(NMSetting * setting,
const char * secret_name,
NMSettingSecretFlags *out_flags,
GError ** error);
gboolean (*set_secret_flags)(NMSetting * setting,
const char * secret_name,
NMSettingSecretFlags flags,
GError ** error);
gboolean (*clear_secrets)(const struct _NMSettInfoSetting *sett_info,
const NMSettInfoProperty * property_info,
NMSetting * setting,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data);
void (*padding_1)(void);
void (*duplicate_copy_properties)(const struct _NMSettInfoSetting *sett_info,
NMSetting * src,
NMSetting * dst);
void (*enumerate_values)(const struct _NMSettInfoProperty *property_info,
NMSetting * setting,
NMSettingValueIterFn func,
gpointer user_data);
gboolean (*aggregate)(NMSetting *setting, int type_i, gpointer arg);
void (*for_each_secret)(NMSetting * setting,
const char * secret_name,
GVariant * val,
gboolean remove_non_secrets,
_NMConnectionForEachSecretFunc callback,
gpointer callback_data,
GVariantBuilder * setting_builder);
gboolean (*init_from_dbus)(NMSetting * setting,
GHashTable * keys,
GVariant * setting_dict,
GVariant * connection_dict,
guint /* NMSettingParseFlags */ parse_flags,
GError ** error);
union {
gpointer padding[1];
struct {
/* Whether NMSetting.finalize() calls _nm_setting_property_finalize_direct(). Subclasses
* need to be aware of that, and currently this is opt-in.
*
* The only reason because subclasses need to be aware of this, is that they
* otherwise might clear the properties already and leave dangling pointers.
*
* Eventually all setting classes should stop touching their direct properties
* during finalize, and always let NMSetting.finalize() handle them. */
bool finalize_direct : 1;
};
};
const struct _NMMetaSettingInfo *setting_info;
};
/*****************************************************************************/
/**
* NMSettingIPConfig:
*/
struct _NMSettingIPConfig {
NMSetting parent;
/* In the past, this struct was public API. Preserve ABI! */
};
struct _NMSettingIPConfigClass {
NMSettingClass parent;
/* In the past, this struct was public API. Preserve ABI! */
union {
gpointer _dummy;
int private_offset;
};
gpointer padding[7];
};
typedef struct {
GPtrArray *dns; /* array of IP address strings */
GPtrArray *dns_search; /* array of domain name strings */
GPtrArray *dns_options; /* array of DNS options */
GPtrArray *addresses; /* array of NMIPAddress */
GPtrArray *routes; /* array of NMIPRoute */
GPtrArray *routing_rules;
GArray * dhcp_reject_servers;
char * method;
char * gateway;
char * dhcp_hostname;
char * dhcp_iaid;
gint64 route_metric;
guint dhcp_hostname_flags;
int dns_priority;
int dad_timeout;
int dhcp_timeout;
int required_timeout;
guint32 route_table;
bool ignore_auto_routes;
bool ignore_auto_dns;
bool dhcp_send_hostname;
bool never_default;
bool may_fail;
} NMSettingIPConfigPrivate;
void _nm_setting_ip_config_private_init(gpointer self, NMSettingIPConfigPrivate *priv);
/*****************************************************************************/
NMSettingPriority _nm_setting_get_base_type_priority(NMSetting *setting);
int _nm_setting_compare_priority(gconstpointer a, gconstpointer b);
int _nmtst_nm_setting_sort(NMSetting *a, NMSetting *b);
/*****************************************************************************/
#define _nm_assert_setting_info(setting_info, gtype) \
G_STMT_START \
{ \
const NMMetaSettingInfo *_setting_info = (setting_info); \
\
if (NM_MORE_ASSERTS > 0) { \
GType _gtype = (gtype); \
\
nm_assert(_setting_info); \
nm_assert(_NM_INT_NOT_NEGATIVE(_setting_info->meta_type)); \
nm_assert(_setting_info->meta_type < _NM_META_SETTING_TYPE_NUM); \
nm_assert(_setting_info->get_setting_gtype); \
if (_gtype != 0) \
nm_assert(_setting_info->get_setting_gtype() == _gtype); \
else \
_gtype = _setting_info->get_setting_gtype(); \
nm_assert(g_type_is_a(_gtype, NM_TYPE_SETTING)); \
} \
} \
G_STMT_END
static inline const NMMetaSettingInfo *
_nm_meta_setting_info_from_class(NMSettingClass *klass)
{
const NMMetaSettingInfo *setting_info;
if (!NM_IS_SETTING_CLASS(klass))
return NULL;
setting_info = klass->setting_info;
if (!setting_info)
return NULL;
_nm_assert_setting_info(setting_info, G_OBJECT_CLASS_TYPE(klass));
return setting_info;
}
static inline const NMMetaSettingInfo *
_nm_meta_setting_info_from_gtype(GType gtype)
{
const NMMetaSettingInfo *setting_info;
setting_info = nm_meta_setting_infos_by_gtype(gtype);
if (!setting_info)
return NULL;
_nm_assert_setting_info(setting_info, gtype);
return setting_info;
}
libnm: use NMMetaSettingInfo for tracking setting priority Previously, each (non abstract) NMSetting class had to register its name and priority via _nm_register_setting(). Note, that libnm-core.la already links against "nm-meta-setting.c", which also redundantly keeps track of the settings name and gtype as well. Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta data. The goal is to get rid of private data structures that track meta data about NMSetting classes. In this case, "registered_settings" hash. Instead, we should have one place where all this meta data is tracked. This was, it is also accessible as internal API, which can be useful (for keyfile). Note that NMSettingClass has some overlap with NMMetaSettingInfo. One difference is, that NMMetaSettingInfo is const, while NMSettingClass is only initialized during the class_init() method. Appart from that, it's mostly a matter of taste, whether we attach meta data to NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed by NMMetaSettingType. Note, that previously, _nm_register_setting() was private API. That means, no user could subclass a functioning NMSetting instance. The same is still true: NMMetaSettingInfo is internal API and users cannot access it to create their own NMSetting subclasses. But that is almost desired. libnm is not designed, to be extensible via subclassing, nor is it clear why that would be a useful thing to do. One day, we should remove the NMSetting and NMSettingClass definitions from public headers. Their only use is subclassing the types, which however does not work. While libnm-core was linking already against nm-meta-setting.c, nm_meta_setting_infos was unreferenced. So, this change increases the binary size of libnm and NetworkManager (1032 bytes). Note however that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
/*****************************************************************************/
void _nm_setting_emit_property_changed(NMSetting *setting);
typedef enum NMSettingUpdateSecretResult {
NM_SETTING_UPDATE_SECRET_ERROR = FALSE,
NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED = TRUE,
NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED = 2,
} NMSettingUpdateSecretResult;
NMSettingUpdateSecretResult
_nm_setting_update_secrets(NMSetting *setting, GVariant *secrets, GError **error);
gboolean _nm_setting_clear_secrets(NMSetting * setting,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data);
/*****************************************************************************/
#define NM_SETTING_PARAM_NONE 0
/* The property of the #NMSetting should be considered during comparisons that
* use the %NM_SETTING_COMPARE_FLAG_INFERRABLE flag. Properties that don't have
* this flag, are ignored when doing an infrerrable comparison. This flag should
* be set on all properties that are read from the kernel or the system when a
* connection is generated. eg, IP addresses/routes can be read from the
* kernel, but the 'autoconnect' property cannot, so
* %NM_SETTING_IP4_CONFIG_ADDRESSES gets the INFERRABLE flag, but
* %NM_SETTING_CONNECTION_AUTOCONNECT would not.
*
* This flag should not be used with properties where the default cannot be
* read separately from the current value, like MTU or wired duplex mode.
*/
#define NM_SETTING_PARAM_INFERRABLE (1 << (4 + G_PARAM_USER_SHIFT))
/* This is a legacy property, which clients should not send to the daemon. */
#define NM_SETTING_PARAM_LEGACY (1 << (5 + G_PARAM_USER_SHIFT))
/* When a connection is active and gets modified, usually the change
* to the settings-connection does not propagate automatically to the
* applied-connection of the device. For certain properties like the
* firewall zone and the metered property, this is different.
*
* Such fields can be ignored during nm_connection_compare() with the
* NMSettingCompareFlag NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY.
*/
#define NM_SETTING_PARAM_REAPPLY_IMMEDIATELY (1 << (6 + G_PARAM_USER_SHIFT))
/* property_to_dbus() should ignore the property flags, and instead always calls to_dbus_fcn()
*/
#define NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS (1 << (7 + G_PARAM_USER_SHIFT))
extern const NMSettInfoPropertType nm_sett_info_propert_type_setting_name;
extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name;
extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i;
extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u;
extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i;
extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u;
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean;
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32;
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_string;
NMSettingVerifyResult
_nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error);
gboolean _nm_setting_verify_secret_string(const char *str,
const char *setting_name,
const char *property,
GError ** error);
libnm,core: add _nm_connection_aggregate() to replace nm_connection_for_each_setting_value() We should no longer use nm_connection_for_each_setting_value() and nm_setting_for_each_value(). It's fundamentally broken as it does not work with properties that are not backed by a GObject property and it cannot be fixed because it is public API. Add an internal function _nm_connection_aggregate() to replace it. Compare the implementation of the aggregation functionality inside libnm with the previous two checks for secret-flags that it replaces: - previous approach broke abstraction and require detailed knowledge of secret flags. Meaning, they must special case NMSettingVpn and GObject-property based secrets. If we implement a new way for implementing secrets (like we will need for WireGuard), then this the new way should only affect libnm-core, not require changes elsewhere. - it's very inefficient to itereate over all settings. It involves cloning and sorting the list of settings, and retrieve and clone all GObject properties. Only to look at secret properties alone. _nm_connection_aggregate() is supposed to be more flexible then just the two new aggregate types that perform a "find-any" search. The @arg argument and boolean return value can suffice to implement different aggregation types in the future. Also fixes the check of NMAgentManager for secret flags for VPNs (NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS). A secret for VPNs is a property that either has a secret or a secret-flag. The previous implementation would only look at present secrets and check their flags. It wouldn't check secret-flags that are NM_SETTING_SECRET_FLAG_NONE, but have no secret.
2019-01-04 11:28:27 +01:00
gboolean _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType type, gpointer arg);
gboolean _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_type);
gboolean _nm_setting_compare_flags_check(const GParamSpec * param_spec,
NMSettingCompareFlags flags,
NMSetting * set_a,
NMSetting * set_b);
NMTernary _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags);
NMTernary _nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags);
NMTernary _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags);
void _nm_setting_property_get_property_direct(GObject * object,
guint prop_id,
GValue * value,
GParamSpec *pspec);
void _nm_setting_property_set_property_direct(GObject * object,
guint prop_id,
const GValue *value,
GParamSpec * pspec);
GVariant *_nm_setting_property_to_dbus_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
NMSetting * setting,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
NMSetting * setting,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
NMSetting * setting,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
gboolean _nm_setting_property_from_dbus_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
GVariant * connection_dict,
GVariant * value,
NMSettingParseFlags parse_flags,
GError ** error);
gboolean _nm_setting_property_from_dbus_fcn_gprop(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
GVariant * connection_dict,
GVariant * value,
NMSettingParseFlags parse_flags,
GError ** error);
GVariant *_nm_setting_to_dbus(NMSetting * setting,
NMConnection * connection,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
NMSetting *_nm_setting_new_from_dbus(GType setting_type,
GVariant * setting_dict,
GVariant * connection_dict,
NMSettingParseFlags parse_flags,
GError ** error);
gboolean _nm_setting_property_is_regular_secret(NMSetting *setting, const char *secret_name);
gboolean _nm_setting_property_is_regular_secret_flags(NMSetting * setting,
const char *secret_flags_name);
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
/*****************************************************************************/
const NMSettInfoProperty *
_nm_sett_info_property_lookup_by_param_spec(const NMSettInfoSetting *sett_info,
const GParamSpec * param_spec);
static inline GArray *
_nm_sett_info_property_override_create_array_sized(guint reserved_size)
{
return g_array_sized_new(FALSE, FALSE, sizeof(NMSettInfoProperty), reserved_size);
}
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
static inline GArray *
_nm_sett_info_property_override_create_array(void)
{
/* pre-allocate a relatively large buffer to avoid frequent re-allocations.
* Note that the buffer is only short-lived and will be destroyed by
* _nm_setting_class_commit(). */
return _nm_sett_info_property_override_create_array_sized(20);
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
}
GArray *_nm_sett_info_property_override_create_array_ip_config(void);
void _nm_setting_class_commit(NMSettingClass * setting_class,
NMMetaSettingType meta_type,
const NMSettInfoSettDetail *detail,
GArray * properties_override,
gint16 private_offset);
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
libnm: add generic-data for implementing NMSetting Add a new way how NMSetting subclasses can be implemented. Currently, most NMSetting implementations realize all their properties via GObject properties. That has some downsides: - the biggest one, is the large effort to add new properties. Most of them are implemented on a one-by-one basis and they come with additional API (like native getter functions). It makes it cumbersome to add more properties. - for certain properties, it's hard to encode them entirely in a GObject property. That results in unusable API like NM_SETTING_IP_CONFIG_ADDRESSES, NM_SETTING_BOND_OPTIONS, NM_SETTING_USER_DATA. These complex valued properties only exist, because we currently always need GObject properties to even implement simple functionality. For example, nm_setting_duplicate() is entirely implemented via nm_setting_enumerate_values(), which can only iterate GObject properies. There is no reason why this is necessary. Note also how nmcli badly handles bond options and VPN data. That is only a shortcoming of nmcli and wouldn't need to be that way. But it happend, because we didn't keep an open mind that settings might be more than just accessing GObject properties. - a major point of NMSetting is to convert to/from a GVariant from the D-Bus API. As NMSetting needs to squeeze all values into the static GObject structure, there is no place to encode invalid or unknown properties. Optimally, _nm_setting_new_from_dbus() does not loose any information and a subsequent _nm_setting_to_dbus() can restore the original variant. That is interesting, because we want that an older libnm client can talk to a newer NetworkManager version. The client needs to handle unknown properties gracefully to stay forward compatible. However, it also should not just drop the properties on the floor. Note however, optimally we want that nm_setting_verify() still can reject settings that have such unknown/invalid values. So, it should be possible to create an NMSetting instance without error or loosing information. But verify() should be usable to identify such settings as invalid. They also have a few upsides. - libnm is heavily oriented around GObject. So, we generate our nm-settings manual based on the gtk-doc. Note however, how we fail to generate a useful manual for bond.options. Also note, that there is no reason we couldn't generate great documentation, even if the properties are not GObject properties. - GObject properties do give some functionality like meta-data, data binding and notification. However, the meta-data is not sufficient on its own. Note how keyfile and nmcli need extensive descriptor tables on top of GObject properties, to make this useful. Note how GObject notifications for NMSetting instances are usually not useful, aside for data binding like nmtui does. Also note how NMSettingBond already follows a different paradigm than using GObject properties. Nowdays, NMSettingBond is considered a mistake (related bug rh#1032808). Many ideas of NMSettingBond are flawed, like exposing an inferiour API that reduces everything to a string hash. Also, it only implemented the options hash inside NMSettingBond. That means, if we would consider this a good style, we would have to duplicate this approach in each new setting implementation. Add a new style to track data for NMSetting subclasses. It keeps an internal hash table with all GVariant properies. Also, the functionality is hooked into NMSetting base class, so all future subclasses that follow this way, can benefit from this. This approach has a few similiarties with NMSettingBond, but avoids its flaws. With this, we also no longer need GObject properties (if we would also implement generating useful documentation based on non-gkt-doc). They may be added as accessors if they are useful, but there is no need for them. Also, handling the properties as a hash of variants invites for a more generic approach when handling them. While we still could add accessors that operate on a one-by-one bases, this leads to a more generic usage where we apply common functionality to a set of properties. Also, this is for the moment entirely internal and an implementation detail. It's entirely up to the NMSetting subclass to make use of this new style. Also, there are little hooks for the subclass available. If they turn out to be necessary, they might be added. However, for the moment, the functionality is restricted to what is useful and necessary.
2018-07-27 10:05:40 +02:00
#define NM_SETT_INFO_SETT_GENDATA(...) \
({ \
static const NMSettInfoSettGendata _g = {__VA_ARGS__}; \
\
&_g; \
})
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
#define NM_SETT_INFO_SETT_DETAIL(...) (&((const NMSettInfoSettDetail){__VA_ARGS__}))
#define NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(_dbus_type, ...) \
{ \
.dbus_type = _dbus_type, __VA_ARGS__ \
}
#define NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(_dbus_type, ...) \
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(_dbus_type, \
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \
__VA_ARGS__)
#define NM_SETT_INFO_PROPERT_TYPE(init) \
({ \
static const NMSettInfoPropertType _g = init; \
\
&_g; \
libnm: refactor NMSettInfoProperty to save memory for simple properties In total, we register 447 property informations. Out of these, 326 are plain, GObject property based without special implementations. The NMSettInfoProperty had all function pointers directly embedded, currently this amounts to 5 function pointers and the "dbus_type" field. That means, at runtime we have 326 times trivial implementations with waste 326*6*8 bytes of NULL pointers. We can compact these by moving them to a separate structure. Before: 447 * 5 function pointers 447 * "dbus_type" pointer = 2682 pointers After: 447 * 1 pointers (for NMSettInfoProperty.property_type) 89 * 6 pointers (for the distinct NMSettInfoPropertType data) = 981 pointers So, in total this saves 13608 byes of runtime memory (on 64 bit arch). The 89 NMSettInfoPropertType instances are the remaining distinct instances. Note that every NMSettInfoProperty has a "property_type" pointer, but most of them are shared. That is because the underlying type and the operations are the same. Also nice is that the NMSettInfoPropertType are actually constant, static fields and initialized very early. This change also makes sense form a design point of view. Previously, NMSettInfoProperty contained both per-property data (the "name") but also the behavior. Now, the "behavioral" part is moved to a separate structure (where it is also shared). That means, the parts that are concerned with the type of the property (the behavior) are separate from the actual data of the property.
2019-09-22 08:53:06 +02:00
})
#define NM_SETT_INFO_PROPERT_TYPE_DBUS(_dbus_type, ...) \
NM_SETT_INFO_PROPERT_TYPE(NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(_dbus_type, __VA_ARGS__))
#define NM_SETT_INFO_PROPERT_TYPE_GPROP(_dbus_type, ...) \
NM_SETT_INFO_PROPERT_TYPE(NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(_dbus_type, __VA_ARGS__))
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
#define NM_SETT_INFO_PROPERTY(...) (&((const NMSettInfoProperty){__VA_ARGS__}))
gboolean _nm_properties_override_assert(const NMSettInfoProperty *prop_info);
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
static inline void
_nm_properties_override(GArray *properties_override, const NMSettInfoProperty *prop_info)
{
nm_assert(properties_override);
nm_assert(_nm_properties_override_assert(prop_info));
g_array_append_vals(properties_override, prop_info, 1);
}
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
#define _nm_properties_override_gobj(properties_override, \
p_param_spec, \
p_property_type, \
... /* extra NMSettInfoProperty fields */) \
_nm_properties_override((properties_override), \
NM_SETT_INFO_PROPERTY(.name = NULL, \
.param_spec = (p_param_spec), \
.property_type = (p_property_type), \
__VA_ARGS__))
#define _nm_properties_override_dbus(properties_override, p_name, p_property_type) \
_nm_properties_override( \
(properties_override), \
NM_SETT_INFO_PROPERTY(.name = ("" p_name ""), .property_type = (p_property_type), ))
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
/*****************************************************************************/
/* Define "direct" properties. These are properties that have a GParamSpec and
* NMSettInfoPropertType.direct_type != NM_VALUE_TYPE_NONE.
*
* With this, the location of the data is known at
*
* _nm_setting_get_private(setting, sett_info, property_info->direct_offset)
*
* which allows to generically handle the property operations (like get, set, compare).
*/
#define _nm_setting_property_define_direct_boolean(properties_override, \
obj_properties, \
prop_name, \
prop_id, \
default_value, \
param_flags, \
private_struct_type, \
private_struct_field, \
... /* extra NMSettInfoProperty fields */) \
G_STMT_START \
{ \
const gboolean _default_value = (default_value); \
GParamSpec * _param_spec; \
\
G_STATIC_ASSERT( \
!NM_FLAGS_ANY((param_flags), \
~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE \
| NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \
\
nm_assert(NM_IN_SET(_default_value, 0, 1)); \
\
_param_spec = \
g_param_spec_boolean("" prop_name "", \
"", \
"", \
_default_value, \
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
\
(obj_properties)[(prop_id)] = _param_spec; \
\
_nm_properties_override_gobj( \
(properties_override), \
_param_spec, \
&nm_sett_info_propert_type_direct_boolean, \
.direct_offset = \
NM_STRUCT_OFFSET_ENSURE_TYPE(bool, private_struct_type, private_struct_field), \
__VA_ARGS__); \
} \
G_STMT_END
/*****************************************************************************/
#define _nm_setting_property_define_direct_uint32(properties_override, \
obj_properties, \
prop_name, \
prop_id, \
min_value, \
max_value, \
default_value, \
param_flags, \
private_struct_type, \
private_struct_field, \
... /* extra NMSettInfoProperty fields */) \
G_STMT_START \
{ \
GParamSpec *_param_spec; \
\
G_STATIC_ASSERT( \
!NM_FLAGS_ANY((param_flags), \
~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE))); \
G_STATIC_ASSERT((min_value) <= (guint64) G_MAXUINT32); \
G_STATIC_ASSERT((max_value) <= (guint64) G_MAXUINT32); \
G_STATIC_ASSERT((default_value) <= (guint64) G_MAXUINT32); \
\
_param_spec = \
g_param_spec_uint("" prop_name "", \
"", \
"", \
(min_value), \
(max_value), \
(default_value), \
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
\
(obj_properties)[(prop_id)] = _param_spec; \
\
_nm_properties_override_gobj( \
(properties_override), \
_param_spec, \
&nm_sett_info_propert_type_direct_uint32, \
.direct_offset = \
NM_STRUCT_OFFSET_ENSURE_TYPE(guint32, private_struct_type, private_struct_field), \
__VA_ARGS__); \
} \
G_STMT_END
/*****************************************************************************/
#define _nm_setting_property_define_direct_string_full(properties_override, \
obj_properties, \
prop_name, \
prop_id, \
param_flags, \
property_type, \
private_struct_type, \
private_struct_field, \
... /* extra NMSettInfoProperty fields */) \
G_STMT_START \
{ \
GParamSpec * _param_spec; \
const NMSettInfoPropertType *_property_type = (property_type); \
\
G_STATIC_ASSERT(!NM_FLAGS_ANY((param_flags), \
~(NM_SETTING_PARAM_SECRET | NM_SETTING_PARAM_FUZZY_IGNORE \
| NM_SETTING_PARAM_INFERRABLE \
| NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \
\
nm_assert(_property_type); \
nm_assert(g_variant_type_equal(_property_type->dbus_type, "s")); \
nm_assert(_property_type->direct_type == NM_VALUE_TYPE_STRING); \
nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); \
\
_param_spec = \
g_param_spec_string("" prop_name "", \
"", \
"", \
NULL, \
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
\
(obj_properties)[(prop_id)] = _param_spec; \
\
_nm_properties_override_gobj( \
(properties_override), \
_param_spec, \
_property_type, \
.direct_offset = \
NM_STRUCT_OFFSET_ENSURE_TYPE(char *, private_struct_type, private_struct_field), \
__VA_ARGS__); \
} \
G_STMT_END
#define _nm_setting_property_define_direct_string(properties_override, \
obj_properties, \
prop_name, \
prop_id, \
param_flags, \
private_struct_type, \
private_struct_field, \
... /* extra NMSettInfoProperty fields */) \
_nm_setting_property_define_direct_string_full((properties_override), \
(obj_properties), \
prop_name, \
(prop_id), \
(param_flags), \
&nm_sett_info_propert_type_direct_string, \
private_struct_type, \
private_struct_field, \
__VA_ARGS__)
/*****************************************************************************/
gboolean _nm_setting_use_legacy_property(NMSetting * setting,
GVariant * connection_dict,
const char *legacy_property,
const char *new_property);
GPtrArray *_nm_setting_need_secrets(NMSetting *setting);
gboolean _nm_setting_should_compare_secret_property(NMSetting * setting,
NMSetting * other,
const char * secret_name,
NMSettingCompareFlags flags);
NMBridgeVlan *_nm_bridge_vlan_dup(const NMBridgeVlan *vlan);
NMBridgeVlan *_nm_bridge_vlan_dup_and_seal(const NMBridgeVlan *vlan);
gboolean _nm_utils_bridge_vlans_from_dbus(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
GVariant * connection_dict,
GVariant * value,
NMSettingParseFlags parse_flags,
GError ** error);
GVariant *_nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
NMSetting * setting,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
NMTernary _nm_setting_ip_config_compare_fcn_addresses(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags);
NMTernary _nm_setting_ip_config_compare_fcn_routes(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags);
gboolean _nm_utils_hwaddr_cloned_not_set(NMSetting * setting,
GVariant * connection_dict,
const char * property,
NMSettingParseFlags parse_flags,
GError ** error);
GVariant *_nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty * property_info,
NMConnection * connection,
NMSetting * setting,
NMConnectionSerializationFlags flags,
const NMConnectionSerializationOptions *options);
gboolean _nm_utils_hwaddr_cloned_set(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMSetting * setting,
GVariant * connection_dict,
GVariant * value,
NMSettingParseFlags parse_flags,
GError ** error);
libnm: rework setting metadata for property handling NMSetting internally already tracked a list of all proper GObject properties and D-Bus-only properties. Rework the tracking of the list, so that: - instead of attaching the data to the GType of the setting via g_type_set_qdata(), it is tracked in a static array indexed by NMMetaSettingType. This allows to find the setting-data by simple pointer arithmetic, instead of taking a look and iterating (like g_type_set_qdata() does). Note, that this is still thread safe, because the static table entry is initialized in the class-init function with _nm_setting_class_commit(). And it only accessed by following a NMSettingClass instance, thus the class constructor already ran (maybe not for all setting classes, but for the particular one that we look up). I think this makes initialization of the metadata simpler to understand. Previously, in a first phase each class would attach the metadata to the GType as setting_property_overrides_quark(). Then during nm_setting_class_ensure_properties() it would merge them and set as setting_properties_quark(). Now, during the first phase, we only incrementally build a properties_override GArray, which we finally hand over during nm_setting_class_commit(). - sort the property infos by name and do binary search. Also expose this meta data types as internal API in nm-setting-private.h. While not accessed yet, it can prove beneficial, to have direct (internal) access to these structures. Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct naming scheme. We already have 40+ subclasses of NMSetting that are called NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a new, distinct name.
2018-07-28 15:26:03 +02:00
/*****************************************************************************/
#endif /* NM_SETTING_PRIVATE_H */