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.
This commit is contained in:
Thomas Haller 2019-05-31 10:48:47 +02:00 committed by Beniamino Galvani
parent efe602af2a
commit 23b1f8234d
7 changed files with 817 additions and 551 deletions

View file

@ -6513,6 +6513,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "disabled",
@ -6524,6 +6528,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "default",
@ -6535,6 +6543,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "disabled",
@ -6546,6 +6558,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "default",
@ -6597,6 +6613,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT,
.nick = "default",
@ -6614,6 +6634,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = NM_SETTING_TEAM_RUNNER_SYS_PRIO_DEFAULT,
.nick = "default",
@ -6625,6 +6649,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "default",
@ -6676,7 +6704,11 @@ static const NMMetaPropertyInfo *const property_infos_TEAM_PORT[] = {
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = NM_SETTING_TEAM_PORT_QUEUE_ID_DEFAULT,
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "default",
},
),
@ -6686,6 +6718,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM_PORT[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = 0,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "default",
@ -6700,6 +6736,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM_PORT[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = NM_SETTING_TEAM_PORT_LACP_PRIO_DEFAULT,
.nick = "default",
@ -6711,6 +6751,10 @@ static const NMMetaPropertyInfo *const property_infos_TEAM_PORT[] = {
.property_type = &_pt_gobject_int,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int,
.value_infos = INT_VALUE_INFOS (
{
.value.i64 = -1,
.nick = "unset",
},
{
.value.i64 = 0,
.nick = "default",

View file

@ -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);

View file

@ -734,6 +734,14 @@ G_DEFINE_TYPE (NMSettingTeam, nm_setting_team, NM_TYPE_SETTING)
/*****************************************************************************/
NMTeamSetting *
_nm_setting_team_get_team_setting (NMSettingTeam *setting)
{
return NM_SETTING_TEAM_GET_PRIVATE (setting)->team_setting;
}
/*****************************************************************************/
#define _maybe_changed(self, changed) \
nm_team_setting_maybe_changed (NM_SETTING (_NM_ENSURE_TYPE (NMSettingTeam *, self)), (const GParamSpec *const*) obj_properties, (changed))
@ -1223,19 +1231,6 @@ nm_setting_team_clear_link_watchers (NMSettingTeam *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)
{
@ -1503,6 +1498,13 @@ nm_setting_team_class_init (NMSettingTeamClass *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))
/**
* NMSettingTeam:config:
*
@ -1533,9 +1535,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT] =
g_param_spec_int (NM_SETTING_TEAM_NOTIFY_PEERS_COUNT, "", "",
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_MASTER_NOTIFY_PEERS_COUNT], "i", FALSE);
/**
* NMSettingTeam:notify-peers-interval:
@ -1546,9 +1549,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL] =
g_param_spec_int (NM_SETTING_TEAM_NOTIFY_PEERS_INTERVAL, "", "",
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_MASTER_NOTIFY_PEERS_INTERVAL], "i", FALSE);
/**
* NMSettingTeam:mcast-rejoin-count:
@ -1559,9 +1563,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT] =
g_param_spec_int (NM_SETTING_TEAM_MCAST_REJOIN_COUNT, "", "",
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_MASTER_MCAST_REJOIN_COUNT], "i", FALSE);
/**
* NMSettingTeam:mcast-rejoin-interval:
@ -1572,9 +1577,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL] =
g_param_spec_int (NM_SETTING_TEAM_MCAST_REJOIN_INTERVAL, "", "",
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_MASTER_MCAST_REJOIN_INTERVAL], "i", FALSE);
/**
* NMSettingTeam:runner:
@ -1590,6 +1596,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], "s", FALSE);
/**
* NMSettingTeam:runner-hwaddr-policy:
@ -1603,6 +1610,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], "s", FALSE);
/**
* NMSettingTeam:runner-tx-hash:
@ -1617,6 +1625,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], "as", FALSE);
/**
* NMSettingTeam:runner-tx-balancer:
@ -1630,6 +1639,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], "s", FALSE);
/**
* NMSettingTeam:runner-tx-balancer-interval:
@ -1640,9 +1650,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL] =
g_param_spec_int (NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL, "", "",
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_MASTER_RUNNER_TX_BALANCER_INTERVAL], "i", FALSE);
/**
* NMSettingTeam:runner-active:
@ -1653,9 +1664,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE] =
g_param_spec_boolean (NM_SETTING_TEAM_RUNNER_ACTIVE, "", "",
FALSE,
TRUE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], "b", FALSE);
/**
* NMSettingTeam:runner-fast-rate:
@ -1669,6 +1681,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], "b", FALSE);
/**
* NMSettingTeam:runner-sys-prio:
@ -1679,9 +1692,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO] =
g_param_spec_int (NM_SETTING_TEAM_RUNNER_SYS_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_MASTER_RUNNER_SYS_PRIO], "i", FALSE);
/**
* NMSettingTeam:runner-min-ports:
@ -1692,9 +1706,10 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
**/
obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS] =
g_param_spec_int (NM_SETTING_TEAM_RUNNER_MIN_PORTS, "", "",
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_MASTER_RUNNER_MIN_PORTS], "i", FALSE);
/**
* NMSettingTeam:runner-agg-select-policy:
@ -1708,6 +1723,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass)
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
_property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], "s", FALSE);
/**
* NMSettingTeam:link-watchers: (type GPtrArray(NMTeamLinkWatcher))
@ -1728,12 +1744,7 @@ nm_setting_team_class_init (NMSettingTeamClass *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);
/* ---dbus---
* property: interface-name

File diff suppressed because it is too large Load diff

View file

@ -96,6 +96,8 @@ struct _NMTeamSettingData {
bool is_port:1;
guint32 has_fields_mask;
union {
struct {
const GPtrArray *runner_tx_hash;
@ -185,6 +187,10 @@ nm_team_setting_value_get_string (const NMTeamSetting *self,
/*****************************************************************************/
guint32 nm_team_setting_value_reset (NMTeamSetting *self,
NMTeamAttribute team_attr,
gboolean to_default /* or else unset */);
guint32 _nm_team_setting_value_set (NMTeamSetting *self,
NMTeamAttribute team_attr,
NMValueType value_type,
@ -269,7 +275,7 @@ gboolean nm_team_setting_reset_from_dbus (NMTeamSetting *self,
GPtrArray *_nm_utils_team_link_watchers_from_variant (GVariant *value,
gboolean strict_parsing,
GError **error);
GVariant *_nm_utils_team_link_watchers_to_variant (GPtrArray *link_watchers);
GVariant *_nm_utils_team_link_watchers_to_variant (const GPtrArray *link_watchers);
/*****************************************************************************/
@ -277,4 +283,24 @@ gboolean nm_team_setting_maybe_changed (struct _NMSetting *source,
const GParamSpec *const*obj_properties,
guint32 changed);
struct _NMSettingTeam;
struct _NMSettingTeamPort;
NMTeamSetting *_nm_setting_team_get_team_setting (struct _NMSettingTeam *setting);
NMTeamSetting *_nm_setting_team_port_get_team_setting (struct _NMSettingTeamPort *setting);
NMTeamSetting *_nm_setting_get_team_setting (struct _NMSetting *setting);
/*****************************************************************************/
#include "nm-connection.h"
#include "nm-core-internal.h"
GVariant *_nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags);
void _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value,
GValue *prop_value);
#endif /* __NM_TEAM_UITLS_H__ */

View file

@ -6862,10 +6862,6 @@ test_nm_utils_team_config_equal (void)
TRUE);
/* team config */
_team_config_equal_check ("{ }",
"{ \"runner\" : { \"name\" : \"roundrobin\"} }",
FALSE,
TRUE);
_team_config_equal_check ("{ }",
"{ \"runner\" : { \"name\" : \"random\"} }",
FALSE,
@ -6889,7 +6885,7 @@ test_nm_utils_team_config_equal (void)
_team_config_equal_check ("{ \"runner\" : { \"name\" : \"lacp\"} }",
"{ \"runner\" : { \"name\" : \"lacp\", \"tx_hash\" : [ \"eth\", \"ipv4\", \"ipv6\" ] } }",
FALSE,
TRUE);
!WITH_JSON_VALIDATION);
_team_config_equal_check ("{ \"runner\" : { \"name\" : \"roundrobin\"} }",
"{ \"runner\" : { \"name\" : \"roundrobin\", \"tx_hash\" : [ \"eth\", \"ipv4\", \"ipv6\" ] } }",
FALSE,
@ -6903,7 +6899,7 @@ test_nm_utils_team_config_equal (void)
_team_config_equal_check ("{ }",
"{ \"link_watch\" : { \"name\" : \"ethtool\"} }",
TRUE,
TRUE);
!WITH_JSON_VALIDATION);
_team_config_equal_check ("{ }",
"{ \"link_watch\" : { \"name\" : \"arp_ping\"} }",
TRUE,
@ -6911,7 +6907,7 @@ test_nm_utils_team_config_equal (void)
_team_config_equal_check ("{ \"link_watch\" : { \"name\" : \"ethtool\"} }",
"{ \"link_watch\" : { \"name\" : \"arp_ping\"} }",
TRUE,
TRUE);
!WITH_JSON_VALIDATION);
_team_config_equal_check ("{ \"link_watch\" : { \"name\" : \"arp_ping\"} }",
"{ \"link_watch\" : { \"name\" : \"arp_ping\"} }",
TRUE,

View file

@ -1057,11 +1057,11 @@ static void
test_runner_roundrobin_sync_from_config (void)
{
_test_team_config_sync ("",
0, 0, 0, 0,
NM_SETTING_TEAM_RUNNER_ROUNDROBIN,
-1, -1, -1, -1,
NULL,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
NULL);
}
@ -1069,11 +1069,11 @@ static void
test_runner_broadcast_sync_from_config (void)
{
_test_team_config_sync ("{\"runner\": {\"name\": \"broadcast\"}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_BROADCAST,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
NULL);
}
@ -1081,11 +1081,11 @@ static void
test_runner_random_sync_from_config (void)
{
_test_team_config_sync ("{\"runner\": {\"name\": \"random\"}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_RANDOM,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
NULL);
}
@ -1093,12 +1093,11 @@ static void
test_runner_activebackup_sync_from_config (void)
{
_test_team_config_sync ("{\"runner\": {\"name\": \"activebackup\"}}",
NM_SETTING_TEAM_NOTIFY_PEERS_COUNT_ACTIVEBACKUP_DEFAULT, 0,
NM_SETTING_TEAM_NOTIFY_MCAST_COUNT_ACTIVEBACKUP_DEFAULT, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_ACTIVEBACKUP,
NM_SETTING_TEAM_RUNNER_HWADDR_POLICY_DEFAULT,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
NULL);
}
@ -1113,29 +1112,29 @@ test_runner_loadbalance_sync_from_config (void)
g_ptr_array_add (tx_hash, g_strdup ("ipv6"));
_test_team_config_sync ("{\"runner\": {\"name\": \"loadbalance\"}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_LOADBALANCE,
NULL,
tx_hash, NULL, NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT,
FALSE, FALSE, -1, -1, NULL,
NULL, NULL, -1,
TRUE, FALSE, -1, -1, NULL,
NULL);
_test_team_config_sync ("{\"runner\": {\"name\": \"loadbalance\", "
"\"tx_hash\": [\"eth\", \"ipv4\", \"ipv6\"]}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_LOADBALANCE,
NULL,
tx_hash, NULL, NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT,
FALSE, FALSE, -1, -1, NULL,
tx_hash, NULL, -1,
TRUE, FALSE, -1, -1, NULL,
NULL);
_test_team_config_sync ("{\"runner\": {\"name\": \"loadbalance\", \"tx_hash\": [\"eth\", \"ipv4\", \"ipv6\"], "
"\"tx_balancer\": {\"name\": \"basic\", \"balancing_interval\": 30}}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_LOADBALANCE,
NULL,
tx_hash, "basic", 30,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
NULL);
}
@ -1150,21 +1149,21 @@ test_runner_lacp_sync_from_config (void)
g_ptr_array_add (tx_hash, g_strdup ("ipv6"));
_test_team_config_sync ("{\"runner\": {\"name\": \"lacp\", \"tx_hash\": [\"eth\", \"ipv4\", \"ipv6\"]}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_LACP,
NULL,
tx_hash, NULL, NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT,
TRUE, FALSE, NM_SETTING_TEAM_RUNNER_SYS_PRIO_DEFAULT, 0,
NM_SETTING_TEAM_RUNNER_AGG_SELECT_POLICY_DEFAULT,
tx_hash, NULL, -1,
TRUE, FALSE, -1, -1,
NULL,
NULL);
_test_team_config_sync ("{\"runner\": {\"name\": \"lacp\", \"tx_hash\": [\"eth\", \"ipv4\", \"ipv6\"], "
"\"active\": false, \"fast_rate\": true, \"sys_prio\": 10, \"min_ports\": 5, "
"\"agg_select_policy\": \"port_config\"}}",
0, 0, 0, 0,
-1, -1, -1, -1,
NM_SETTING_TEAM_RUNNER_LACP,
NULL,
tx_hash, NULL, NM_SETTING_TEAM_RUNNER_TX_BALANCER_INTERVAL_DEFAULT,
tx_hash, NULL, -1,
FALSE, TRUE, 10, 5, "port_config",
NULL);
}
@ -1177,11 +1176,11 @@ test_watcher_ethtool_sync_from_config (void)
link_watchers = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_team_link_watcher_unref);
g_ptr_array_add (link_watchers, nm_team_link_watcher_new_ethtool (0, 0, NULL));
_test_team_config_sync ("{\"link_watch\": {\"name\": \"ethtool\"}}",
0, 0, 0, 0,
"roundrobin",
-1, -1, -1, -1,
NULL,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
link_watchers);
}
@ -1193,11 +1192,11 @@ test_watcher_nsna_ping_sync_from_config (void)
link_watchers = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_team_link_watcher_unref);
g_ptr_array_add (link_watchers, nm_team_link_watcher_new_nsna_ping (0, 0, 3, "target.host", NULL));
_test_team_config_sync ("{\"link_watch\": {\"name\": \"nsna_ping\", \"target_host\": \"target.host\"}}",
0, 0, 0, 0,
"roundrobin",
-1, -1, -1, -1,
NULL,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
link_watchers);
}
@ -1211,11 +1210,11 @@ test_watcher_arp_ping_sync_from_config (void)
nm_team_link_watcher_new_arp_ping (0, 0, 3, "target.host", "source.host", 0, NULL));
_test_team_config_sync ("{\"link_watch\": {\"name\": \"arp_ping\", \"target_host\": \"target.host\", "
"\"source_host\": \"source.host\"}}",
0, 0, 0, 0,
"roundrobin",
-1, -1, -1, -1,
NULL,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
link_watchers);
}
@ -1240,11 +1239,11 @@ test_multiple_watchers_sync_from_config (void)
"\"validate_active\": true, \"validate_inactive\": true, \"send_always\": true}, "
"{\"name\": \"nsna_ping\", \"init_wait\": 3, \"interval\": 6, \"missed_max\": 9, "
"\"target_host\": \"target.host\"}]}",
0, 0, 0, 0,
"roundrobin",
-1, -1, -1, -1,
NULL,
NULL,
NULL, NULL, -1,
FALSE, FALSE, -1, -1, NULL,
TRUE, FALSE, -1, -1, NULL,
link_watchers);
}
@ -1300,52 +1299,52 @@ _test_team_port_config_sync (const char *team_port_config,
static void
test_team_port_default (void)
{
_test_team_port_config_sync ("", -1, 0, FALSE, 255, 0, NULL);
_test_team_port_config_sync ("", -1, 0, FALSE, -1, -1, NULL);
}
static void
test_team_port_queue_id (void)
{
_test_team_port_config_sync ("{\"queue_id\": 3}",
3, 0, FALSE, 255, 0, NULL);
3, 0, FALSE, -1, -1, NULL);
_test_team_port_config_sync ("{\"queue_id\": 0}",
0, 0, FALSE, 255, 0, NULL);
0, 0, FALSE, -1, -1, NULL);
}
static void
test_team_port_prio (void)
{
_test_team_port_config_sync ("{\"prio\": 6}",
-1, 6, FALSE, 255, 0, NULL);
-1, 6, FALSE, -1, -1, NULL);
_test_team_port_config_sync ("{\"prio\": 0}",
-1, 0, FALSE, 255, 0, NULL);
-1, 0, FALSE, -1, -1, NULL);
}
static void
test_team_port_sticky (void)
{
_test_team_port_config_sync ("{\"sticky\": true}",
-1, 0, TRUE, 255, 0, NULL);
-1, 0, TRUE, -1, -1, NULL);
_test_team_port_config_sync ("{\"sticky\": false}",
-1, 0, FALSE, 255, 0, NULL);
-1, 0, FALSE, -1, -1, NULL);
}
static void
test_team_port_lacp_prio (void)
{
_test_team_port_config_sync ("{\"lacp_prio\": 9}",
-1, 0, FALSE, 9, 0, NULL);
-1, 0, FALSE, 9, -1, NULL);
_test_team_port_config_sync ("{\"lacp_prio\": 0}",
-1, 0, FALSE, 0, 0, NULL);
-1, 0, FALSE, 0, -1, NULL);
}
static void
test_team_port_lacp_key (void)
{
_test_team_port_config_sync ("{\"lacp_key\": 12}",
-1, 0, FALSE, 255, 12, NULL);
-1, 0, FALSE, -1, 12, NULL);
_test_team_port_config_sync ("{\"lacp_key\": 0}",
-1, 0, FALSE, 255, 0, NULL);
-1, 0, FALSE, -1, 0, NULL);
}
static void
@ -1386,20 +1385,6 @@ _check_team_setting (NMSetting *setting)
g_assert (NM_IS_SETTING_TEAM (setting) || is_port);
setting_clone = nm_setting_duplicate (setting);
if (!is_port) {
if (nm_setting_team_get_runner (NM_SETTING_TEAM (setting)) == NULL) {
/* such a setting is invalid. We must first coerce it so that it becomes
* valid. */
setting = setting_clone;
g_object_set (setting,
NM_SETTING_TEAM_RUNNER,
NM_SETTING_TEAM_RUNNER_DEFAULT,
NULL);
}
}
setting2 = g_object_new (G_OBJECT_TYPE (setting),
is_port
? NM_SETTING_TEAM_PORT_CONFIG
@ -1420,6 +1405,7 @@ _check_team_setting (NMSetting *setting)
* For that, we have to "drop" the JSON and we do that by resetting the property.
* This causes JSON to be regenerated and it's in a normalized form that will compare
* equal. */
setting_clone = nm_setting_duplicate (setting);
setting = setting_clone;
if (is_port) {
g_object_set (setting,
@ -1499,6 +1485,12 @@ test_team_setting (void)
NULL);
_check_team_setting (setting);
g_assert_cmpstr (nm_setting_team_get_config (NM_SETTING_TEAM (setting)), ==, "{ \"runner\": { \"tx_balancer\": { \"balancing_interval\": 5 }, \"sys_prio\": 10 } }");
g_object_set (setting,
NM_SETTING_TEAM_CONFIG,
"{ \"runner\": { \"tx_hash\": [ \"eth\", \"l3\" ] } }",
NULL);
_check_team_setting (setting);
}
/*****************************************************************************/