diff options
author | Thomas Haller <thaller@redhat.com> | 2019-05-31 10:48:47 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2019-06-04 15:48:15 +0200 |
commit | 23b1f8234ded35b2debfc16e60f6fbebaf2b61e2 (patch) | |
tree | 9a2f65148d206bbef3746b334dff84279ccf9406 /libnm-core/nm-setting-team-port.c | |
parent | efe602af2a5df9d0cb157be3ef91ae4c9ecc5f44 (diff) | |
download | NetworkManager-23b1f8234ded35b2debfc16e60f6fbebaf2b61e2.tar.gz |
libnm/team: fix handling default values and stricter validate team config
For each artifical team property we need to track whether it was
explicitly set (i.e., present in JSON/GVariant or set by the user
via NMSettingTeam/NMSettingTeamPort API).
--
As a plus, libnm is now no longer concerned with the underling default values
that teamd uses. For example, the effective default value for "notify_peers.count"
depends on the selected runner. But libnm does not need to care, it only cares
wheher the property is set in JSON or not. This also means that the default (e.g. as
interesting to `nmcli -o con show $PROFILE`) is independent from other properties
(like the runner).
Also change the default value for the GObject properties of
NMSettingTeam and NMSettingTeamPort to indicate the "unset" value.
For most properties, the default value is a special value that is
not a valid configuration itself.
For some properties the default value is itself a valid value, namely,
"runner.active", "runner.fast_rate", "port.sticky" and "port.prio".
As far as NMTeamSetting is concerned, it distinguishes between unset
value and set value (including the default value). That means,
when it parses a JSON or GVariant, it will remember whether the property
was present or not.
When using API of NMSettingTeam/NMSettingTeamPort to set a property to the
default value, it marks the property as unset. For example, setting
NM_SETTING_TEAM_RUNNER_ACTIVE to TRUE (the default), means that the
value will not be serialized to JSON/GVariant. For the above 4
properties (where the default value is itself a valid value) this is a
limitation of libnm API, as it does not allow to explicitly set
'"runner": { "active": true }'. See SET_FIELD_MODE_SET_UNLESS_DEFAULT,
Note that changing the default value for properties of NMSetting is problematic,
because it changes behavior for how settings are parsed from keyfile/GVariant.
For team settings that's not the case, because if a JSON "config" is
present, all other properties are ignore. Also, we serialize properties
to JSON/GVariant depending on whether it's marked as present, and not
whether the value is set to the default (_nm_team_settings_property_to_dbus()).
--
While at it, sticter validate the settings. Note that if a setting is
initialized from JSON, the strict validation is not not performed. That
means, such a setting will always validate, regardless whether the values
in JSON are invalid according to libnm. Only when using the extended
properties, strict validation is turned on.
Note that libnm serializes the properties to GVariant both as JSON "config"
and extended properties. Since when parsing a setting from GVariant will
prefer the "config" (if present), in most cases also validation is
performed.
Likewise, settings plugins (keyfile, ifcfg-rh) only persist the JSON
config to disk. When loading a setting from file, strict validation is
also not performed.
The stricter validation only happens if as last operation one of the
artificial properties was set, or if the setting was created from a
GVariant that has no "config" field.
--
This is a (another) change in behavior.
Diffstat (limited to 'libnm-core/nm-setting-team-port.c')
-rw-r--r-- | libnm-core/nm-setting-team-port.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 22cbdb6703..504798c163 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -54,6 +54,14 @@ G_DEFINE_TYPE (NMSettingTeamPort, nm_setting_team_port, NM_TYPE_SETTING) /*****************************************************************************/ +NMTeamSetting * +_nm_setting_team_port_get_team_setting (NMSettingTeamPort *setting) +{ + return NM_SETTING_TEAM_PORT_GET_PRIVATE (setting)->team_setting; +} + +/*****************************************************************************/ + #define _maybe_changed(self, changed) \ nm_team_setting_maybe_changed (NM_SETTING (_NM_ENSURE_TYPE (NMSettingTeamPort *, self)), (const GParamSpec *const*) obj_properties, (changed)) @@ -289,19 +297,6 @@ nm_setting_team_port_clear_link_watchers (NMSettingTeamPort *setting) 0)); } -static GVariant * -team_link_watchers_to_dbus (const GValue *prop_value) -{ - return _nm_utils_team_link_watchers_to_variant (g_value_get_boxed (prop_value)); -} - -static void -team_link_watchers_from_dbus (GVariant *dbus_value, - GValue *prop_value) -{ - g_value_take_boxed (prop_value, _nm_utils_team_link_watchers_from_variant (dbus_value, FALSE, NULL)); -} - static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { @@ -556,6 +551,13 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; +#define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ + _properties_override_add ((_properties_override), \ + .param_spec = (_param_spec), \ + .dbus_type = G_VARIANT_TYPE (""_variant_type""), \ + .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ + .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL)) + /** * NMSettingTeamPort:config: * @@ -587,9 +589,10 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) **/ obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID] = g_param_spec_int (NM_SETTING_TEAM_PORT_QUEUE_ID, "", "", - G_MININT32, G_MAXINT32, 0, + G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], "i", FALSE); /** * NMSettingTeamPort:prio: @@ -603,6 +606,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], "i", FALSE); /** * NMSettingTeamPort:sticky: @@ -616,6 +620,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], "b", FALSE); /** * NMSettingTeamPort:lacp-prio: @@ -626,9 +631,10 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) **/ obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO] = g_param_spec_int (NM_SETTING_TEAM_PORT_LACP_PRIO, "", "", - G_MININT32, G_MAXINT32, 0, + G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], "i", FALSE); /** * NMSettingTeamPort:lacp-key: @@ -639,9 +645,10 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) **/ obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY] = g_param_spec_int (NM_SETTING_TEAM_PORT_LACP_KEY, "", "", - G_MININT32, G_MAXINT32, 0, + G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], "i", FALSE); /** * NMSettingTeamPort:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -662,12 +669,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], - G_VARIANT_TYPE ("aa{sv}"), - team_link_watchers_to_dbus, - team_link_watchers_from_dbus); + _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], "aa{sv}", TRUE); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); |