2014-07-24 08:53:33 -04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2011 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#ifndef __NM_SETTING_PRIVATE_H__
|
|
|
|
|
#define __NM_SETTING_PRIVATE_H__
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE)
|
|
|
|
|
#error Cannot use this header.
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
#include "nm-setting.h"
|
2014-08-06 19:35:31 -04:00
|
|
|
#include "nm-connection.h"
|
2014-08-07 17:19:40 -04:00
|
|
|
#include "nm-core-enum-types.h"
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2014-08-11 18:10:43 +02:00
|
|
|
#include "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
|
|
|
/*****************************************************************************/
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2017-06-01 13:43:52 +02:00
|
|
|
NMSettingPriority _nm_setting_get_base_type_priority (NMSetting *setting);
|
|
|
|
|
NMSettingPriority _nm_setting_type_get_base_type_priority (GType type);
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
int _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
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
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
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,
|
2014-08-16 10:09:48 -04:00
|
|
|
GVariant *secrets,
|
2014-07-24 08:53:33 -04:00
|
|
|
GError **error);
|
|
|
|
|
gboolean _nm_setting_clear_secrets (NMSetting *setting);
|
|
|
|
|
gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
|
|
|
|
|
NMSettingClearSecretsWithFlagsFn func,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
/* 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))
|
|
|
|
|
|
2014-11-14 11:46:19 -05:00
|
|
|
/* This is a legacy property, which clients should not send to the daemon. */
|
|
|
|
|
#define NM_SETTING_PARAM_LEGACY (1 << (5 + G_PARAM_USER_SHIFT))
|
|
|
|
|
|
2015-09-18 17:21:34 +02:00
|
|
|
/* 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))
|
|
|
|
|
|
2014-08-16 10:09:48 -04:00
|
|
|
GVariant *_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *property);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
|
|
|
|
NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
|
2014-10-21 22:30:31 -04:00
|
|
|
NMConnection *connection,
|
|
|
|
|
GError **error);
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2015-11-10 14:36:20 +01:00
|
|
|
gboolean _nm_setting_verify_secret_string (const char *str,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
const char *property,
|
|
|
|
|
GError **error);
|
|
|
|
|
|
2014-07-07 17:05:10 +02:00
|
|
|
gboolean _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_type);
|
|
|
|
|
|
2014-08-16 10:09:48 -04:00
|
|
|
GVariant *_nm_setting_to_dbus (NMSetting *setting,
|
libnm-core: add dbus-only properties to NMSettingClass
Add _nm_setting_class_add_dbus_only_property(), for declaring
properties that appear in the D-Bus serialization, but which don't
correspond to GObject properties.
Since some property overrides will require examining settings other
than the setting that they are on (eg, the value of
802-11-wireless.security depends on whether an
NMSettingWirelessSecurity setting is present, and
NMSettingConnection:interface-name might sometimes be set from, eg,
bond.interface-name), we also update _nm_setting_to_dbus() to take the
full NMConnection as an argument, and _nm_setting_new_from_dbus() to
take the full connection hash.
Additionally, with some deprecated properties, we'll want to validate
them on construction, but we don't need to keep the value around after
that. So allow _nm_setting_new_from_dbus() to return a verification
error directly, so we don't need to store the value until the verify()
call.
2014-07-29 18:25:10 -04:00
|
|
|
NMConnection *connection,
|
2014-08-06 19:35:31 -04:00
|
|
|
NMConnectionSerializationFlags flags);
|
2014-08-04 11:23:11 -04:00
|
|
|
|
2014-08-06 19:35:31 -04:00
|
|
|
NMSetting *_nm_setting_new_from_dbus (GType setting_type,
|
2014-08-16 10:09:48 -04:00
|
|
|
GVariant *setting_dict,
|
|
|
|
|
GVariant *connection_dict,
|
libnm-core: allow strict and relaxed error behavior for _nm_setting_new_from_dbus()
In some situations, we want strict checking of errors, for example when
NetworkManager receives a new connection from a client, the connection
must make sense as a whole (and since NetworkManager service is backward
compatible to the clients and not the other way around, there is no
excuse for sending invalid data to the server).
In other situations, we want a best-effort behavior. Like when
NetworkManager sends a connection to its clients, those clients
want to extract as many properties as they understand, but in order
to be forward compatible against newer server versions, invalid
or unknown properties must be accepted.
Previously, a mixture of both was done. Some issues caused a failure
to create a new NMSetting, other invalid parts were just silently
ignored or triggered a g_warning() in glib.
Now allow for both. When doing strict-validation, be more strict and
reject all unknown properties and catch when the user sets an invalid
argument. On the other hand, allow for a best-effort mode that
effectively cannot fail and will return a new NMSetting instance.
For now, add NMSettingParseFlags so that the caller can choose the
old behavior, strict parsing, or best effort.
This patch doesn't have any externally visible change except that
no more g_warnings will be emitted.
2016-03-18 13:42:50 +01:00
|
|
|
NMSettingParseFlags parse_flags,
|
libnm-core: add dbus-only properties to NMSettingClass
Add _nm_setting_class_add_dbus_only_property(), for declaring
properties that appear in the D-Bus serialization, but which don't
correspond to GObject properties.
Since some property overrides will require examining settings other
than the setting that they are on (eg, the value of
802-11-wireless.security depends on whether an
NMSettingWirelessSecurity setting is present, and
NMSettingConnection:interface-name might sometimes be set from, eg,
bond.interface-name), we also update _nm_setting_to_dbus() to take the
full NMConnection as an argument, and _nm_setting_new_from_dbus() to
take the full connection hash.
Additionally, with some deprecated properties, we'll want to validate
them on construction, but we don't need to keep the value around after
that. So allow _nm_setting_new_from_dbus() to return a verification
error directly, so we don't need to store the value until the verify()
call.
2014-07-29 18:25:10 -04:00
|
|
|
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
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static inline GArray *
|
|
|
|
|
_nm_sett_info_property_override_create_array (void)
|
|
|
|
|
{
|
|
|
|
|
return g_array_new (FALSE, FALSE, sizeof (NMSettInfoProperty));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GArray *_nm_sett_info_property_override_create_array_ip_config (void);
|
|
|
|
|
|
|
|
|
|
void _nm_setting_class_commit_full (NMSettingClass *setting_class,
|
|
|
|
|
NMMetaSettingType meta_type,
|
|
|
|
|
const NMSettInfoSettDetail *detail,
|
|
|
|
|
GArray *properties_override);
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
_nm_setting_class_commit (NMSettingClass *setting_class,
|
|
|
|
|
NMMetaSettingType meta_type)
|
|
|
|
|
{
|
|
|
|
|
_nm_setting_class_commit_full (setting_class, meta_type, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define NM_SETT_INFO_SETT_DETAIL(...) \
|
|
|
|
|
(&((const NMSettInfoSettDetail) { \
|
|
|
|
|
__VA_ARGS__ \
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
#define NM_SETT_INFO_PROPERTY(...) \
|
|
|
|
|
(&((const NMSettInfoProperty) { \
|
|
|
|
|
__VA_ARGS__ \
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
void _properties_override_add_struct (GArray *properties_override,
|
|
|
|
|
const NMSettInfoProperty *prop_info);
|
|
|
|
|
|
|
|
|
|
void _properties_override_add__helper (GArray *properties_override,
|
|
|
|
|
NMSettInfoProperty *prop_info);
|
|
|
|
|
|
|
|
|
|
#define _properties_override_add(properties_override, \
|
|
|
|
|
...) \
|
|
|
|
|
(_properties_override_add_struct (properties_override, \
|
|
|
|
|
NM_SETT_INFO_PROPERTY (__VA_ARGS__)))
|
|
|
|
|
|
|
|
|
|
void _properties_override_add_dbus_only (GArray *properties_override,
|
|
|
|
|
const char *property_name,
|
|
|
|
|
const GVariantType *dbus_type,
|
|
|
|
|
NMSettingPropertySynthFunc synth_func,
|
|
|
|
|
NMSettingPropertySetFunc set_func);
|
|
|
|
|
|
|
|
|
|
void _properties_override_add_override (GArray *properties_override,
|
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
|
const GVariantType *dbus_type,
|
|
|
|
|
NMSettingPropertyGetFunc get_func,
|
|
|
|
|
NMSettingPropertySetFunc set_func,
|
|
|
|
|
NMSettingPropertyNotSetFunc not_set_func);
|
|
|
|
|
|
|
|
|
|
void _properties_override_add_transform (GArray *properties_override,
|
|
|
|
|
GParamSpec *param_spec,
|
|
|
|
|
const GVariantType *dbus_type,
|
|
|
|
|
NMSettingPropertyTransformToFunc to_dbus,
|
|
|
|
|
NMSettingPropertyTransformFromFunc from_dbus);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2014-07-30 10:46:24 -04:00
|
|
|
|
2014-11-14 11:46:19 -05:00
|
|
|
gboolean _nm_setting_use_legacy_property (NMSetting *setting,
|
|
|
|
|
GVariant *connection_dict,
|
|
|
|
|
const char *legacy_property,
|
|
|
|
|
const char *new_property);
|
|
|
|
|
|
2014-10-07 08:46:36 +02:00
|
|
|
GPtrArray *_nm_setting_need_secrets (NMSetting *setting);
|
|
|
|
|
|
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
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
#endif /* NM_SETTING_PRIVATE_H */
|