Commit Graph

1539 Commits

Author SHA1 Message Date
Thomas Haller
02a0967520 libnm: fix setting error for nm_connection_update_secrets()
By convention, a function that indicates failure *MUST* set
an error.

Also, an error can only be set once.
2019-06-26 12:26:11 +02:00
Thomas Haller
d704f02119 libnm: workaround assertion failure for nmtst_connection_assert_unchanging() when disposing connection
nmtst_connection_assert_unchanging() registers to the changed signals
and asserts that they are not invoked. The purpose is that sometimes
we want to keep a reference to an NMConnection and be sure that it does
not get modified. This allows everybody to keep a reference to the very
same connection instance without cloning it -- provided they too promise
not to change it. This assert is to ensure that.

Note that NMSimpleConnection.dispose() clears the secrets and thus upon
destruction the assertion fails. At that point, the assertion is no longer
relevant, because the purpose was to ensure that no alive instances gets
modified. While destroying the instance, it's fine to modify it (nobody should
have a reference to it anymore).

This avoids the assertion failure when destroying a NMSimpleConnection with secrets
that is set with nmtst_connection_assert_unchanging().
2019-06-26 09:53:54 +02:00
Thomas Haller
1de36fad51 libnm: add NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED serialization flag
At various places we only want to serialize agent-owned secrets. Without this
flag, we need to clone the setting first, then drop the secrets, then serialize
to D-Bus. Add a serialization flag to avoid that.

The name ("with") and the meaning of the flag is chosen in a way, that
there could be multiple such flags (NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_REQUIRED),
and specifying at least one of them, would have the meaning to whitelist
flags of this kind. Specifying non of these "with" flags would have the
meaning of specifying *all*. Currently there is only one kind, so the name
and meaning is slightly counter intuitive.
2019-06-17 12:12:02 +02:00
Thomas Haller
a17453913c settings: add _nm_connection_clear_secrets_by_secret_flags() function to simplify clearing secrets 2019-06-17 12:12:02 +02:00
Thomas Haller
45013bfbff libnm: cleanup _nm_connection_ensure_normalized() and split nm_connection_normalize()
- in _nm_connection_ensure_normalized() allow also to only check that
  the UUID is as expected, without really resetting it.

- split the normalization part out of nm_connection_normalize() and
  reuse it in _nm_connection_ensure_normalized(). As we already verified
  the connnection, we know that normalization is due and don't need to
  verify again.
2019-06-17 12:12:02 +02:00
Lubomir Rintel
b93643ed85 core/ovs-interface: add support for dpdk type 2019-06-14 12:10:20 +02:00
Lubomir Rintel
a26abc797c libnm-core: add ovs-dpdk setting 2019-06-14 12:10:20 +02:00
Lubomir Rintel
f5e82796be core/ovs-interface: fix type documentation 2019-06-14 12:02:23 +02:00
Thomas Haller
954906e3d1 libnm: add _nm_connection_ensure_normalized() helper 2019-06-13 16:10:53 +02:00
Thomas Haller
1a398421ff libnm: add nmtst_connection_assert_unchanging() helper 2019-06-13 16:10:53 +02:00
Thomas Haller
ceaf64eee7 settings,libnm: move is-adhoc-wpa check to libnm
"nm-settings.c" is complex enough. Move this trivial helper function to libnm-core.
2019-06-13 16:10:53 +02:00
Thomas Haller
a63714ec1d settings,keyfile: move openconnect hack from settings to keyfile reader
VPN settings (for openconnect) can only be handled by the keyfile settings
plugin.

In any case, such special casing belongs to the settings plugin and not
"nm-settings.c". The reason is that the settings plugin already has an
intimate understanding of the content of connections, it knows which fields
exist, their meaning, etc. It makes sense special handling of
openconnect is done there.

See also commit 304d0b869b ('core: openconnect migration hack').
Unfortunately it's not clear to me why/whether this is still the
right thing to do.
2019-06-13 16:10:53 +02:00
Thomas Haller
6da5ad2962 libnm: cleanup GSList/GPtrArray to/from strv conversion 2019-06-13 16:10:53 +02:00
Thomas Haller
c165c6a671 libnm: don't assert against %NULL string in nm_utils_is_uuid()
For a "is" check, it's inconvenient to assert against the parameter
being %NULL. We should accept %NULL and just say that it's not a valid
uuid.

This relaxes previous API.
2019-06-13 16:10:53 +02:00
Beniamino Galvani
fa0f87fef7 libnm-core: change unsupported modes for arp_ip_targets bond option
If the mode is one of '802.3ad', 'tlb' or 'alb' and the connection has
both 'arp_interval' and 'arp_ip_target' options, during normalization
we remove 'arp_interval' because unsupported in the current mode. The
connection then becomes invalid because 'arp_ip_target' requires
'arp_interval'.

Since 'arp_interval' and 'arp_ip_target' are mutually dependent, the
latter should also be unsupported for those bonding modes.

https://bugzilla.redhat.com/show_bug.cgi?id=1718173
2019-06-11 18:30:18 +02:00
Beniamino Galvani
e6628fa27c ipv6: add 'disabled' method
Add a new ipv6.method value 'disabled' that completely disables IPv6
for the interface.

https://bugzilla.redhat.com/show_bug.cgi?id=1643841
2019-06-11 16:22:04 +02:00
Thomas Haller
a4c1489507 libnm: belatedly expose nm_ethtool_optname_is_feature() in libnm
Also, plan right away to backport this symbol all the way back to
1.14.8. As such, we only need to add it once, with the right linker
version "libnm_1_14_8".

But still, the symbols first appears on a major release 1.20.0.
2019-06-11 14:58:14 +02:00
Thomas Haller
356a159731 libnm: add nm_setting_ethtool_get_optnames() function
It's rather limiting if we have no API to ask NMSettingEthtool which
options are set.

Note that currently NMSettingEthtool only supports offload features.
In the future, it should also support other options like coalesce
or ring options. Hence, this returns all option names, not only
features.

If a caller needs to know whether the name is an option name, he/she
should call nm_ethtool_optname_is_feature().
2019-06-11 11:27:43 +02:00
Thomas Haller
87a73df959 all: drop empty first line from sources
git ls-files -z -- ':(exclude)src/settings/plugins/keyfile/tests/keyfiles' | xargs -0 -n1 sed -i '1 { /^$/d }'
2019-06-11 10:15:06 +02:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
We no longer add these. If you use Emacs, configure it yourself.

Also, due to our "smart-tab" usage the editor anyway does a subpar
job handling our tabs. However, on the upside every user can choose
whatever tab-width he/she prefers. If "smart-tabs" are used properly
(like we do), every tab-width will work.

No manual changes, just ran commands:

    F=($(git grep -l -e '-\*-'))
    sed '1 { /\/\* *-\*-  *[mM]ode.*\*\/$/d }'     -i "${F[@]}"
    sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}"

Check remaining lines with:

    git grep -e '-\*-'

The ultimate purpose of this is to cleanup our files and eventually use
SPDX license identifiers. For that, first get rid of the boilerplate lines.
2019-06-11 10:04:00 +02:00
Thomas Haller
d7932ee5f1 tests/trivial: rename nmtst_get_rand_int() to nmtst_get_rand_uint32()
nmtst_get_rand_int() was originally named that way, because it
calls g_rand_int(). But I think if a function returns an uint32, it
should also be named that way.

Rename.
2019-06-11 08:25:10 +02:00
Thomas Haller
fac6aea730 libnm/tests: fix team tests with "--enable-json-validation=no" 2019-06-11 08:10:03 +02:00
Thomas Haller
2d6c711d64 libnm/team: fix setting setting same JSON string
When we set the same JSON config twice in a row, the second time has
indeed no effect and we can just return right away (indicating that
no attributes changed).

However, that is not true, if we are in strict validating mode and
the JSON string just happens to be the same. In this case, we still
want to switch from strict validating mode to relaxed mode. Hence,
we should not return early but continue setting the property.
2019-06-09 13:40:28 +02:00
Thomas Haller
cd74fc28b5 libnm/team: strict validate team settings by libnm clients not sending the JSON
When parsing a NMSettingTeam/NMSettingTeamPort from GVariant, the JSON
"config" is always preferred. If that field is present, all other
attributes are ignored (aside from validating that the individual fields
are as expected).

The idea is that the JSON config anyway must contain everything that artificial
properties could. In this mode, also no validation is performed and the setting is
always accepted (regardless whether libnm thinks the setting verifies).

When a libnm client created the setting via the artificial properties,
only send them via D-Bus and exclude the JSON config. This turns on
strict validation server side.

Now we actually get validation of the settings:

  $ nmcli connection add type team team.runner-tx-hash l3
  Error: Failed to add 'team' connection: team.runner: runner-tx-hash is only allowed for runners loadbalance,lacp

this is obviously a change in behavior as previously all settings
would have been accepted, regardless whether they made sense.
2019-06-04 15:48:30 +02:00
Thomas Haller
23b1f8234d 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.
2019-06-04 15:48:15 +02:00
Thomas Haller
efe602af2a libnm/team: reorder fields in JSON output for team link watcher
The order of the fields in the JSON object does not really matter.

Note that with the recent rework the order changed. Before it was
arbitrarily, now it still is arbitrary.

Reorder again, to follow the same order as `man teamd.conf`.
2019-06-04 15:48:15 +02:00
Thomas Haller
56f45d7ba3 libnm/team: add space in JSON output for link watcher
Generate the following:

 { "runner": { "sys_prio": 10 }, "link_watch": { "name": "ethtool" } }

instead of:

 { "runner": { "sys_prio": 10 }, "link_watch": { "name": "ethtool"} }
2019-06-04 15:46:21 +02:00
Thomas Haller
30455ab1b5 libnm/keyfile: don't parse JSON config in keyfile reader twice
Commit d6ec009afd ('team: normalize invalid configuration during
load') let's keyfile reader ignore JSON configs that cannot be parsed.

Keep doing that, but don't parse the JSON twice for that.

Just set the JSON, and if the setting afterwards does not verify, reset
it to NULL. We also get a better error message and in most cases we
don't need to parse twice.
2019-05-23 18:09:49 +02:00
Thomas Haller
f229102ddf libnm: support strict parsing of team link watcher from GVariant 2019-05-23 18:09:49 +02:00
Thomas Haller
cfcc4ff7e3 libnm: implement team's _link_watcher_from_variant() reusing meta data
- re-use the existing meta-data. That is, don't duplicate the
dbus-names, the types, or the default value. Instead, parse the
settings according to these flags.

- notice and return if there are any suspicious/wrong keys in the
variant. For strict parsing, we should not silently ignore them.

- previously, the code used g_variant_lookup() to search for the
expected keys. As the number of keys that we look up is fixed, this
still had O(n). But if we want to detect and reject invalid keys,
we cannot use g_variant_lookup() but need to iterate the entire variant
once.
2019-05-23 18:09:49 +02:00
Thomas Haller
396818c35d libnm: implement team's _link_watcher_to_variant() reusing meta data 2019-05-23 18:09:49 +02:00
Thomas Haller
7f2d655a46 libnm: split creation/conversion of team link watcher from variant 2019-05-23 18:09:49 +02:00
Thomas Haller
c7e349d1ab libnm: move team link-watchers to/from variant to "nm-team-setting.c" 2019-05-23 18:09:49 +02:00
Thomas Haller
13f6f3a410 libnm: rework team handling of JSON config
Completely refactor the team/JSON handling in libnm's NMSettingTeam and
NMSettingTeamPort.

- team handling was added as rh#1398925. The goal is to have a more
  convenient way to set properties than constructing JSON. This requires
  libnm to implement the hard task of parsing JSON (and exposing well-understood
  properties) and generating JSON (based on these "artificial" properties).
  But not only libnm. In particular nmcli and the D-Bus API must make this
  "simpler" API accessible.

- since NMSettingTeam and NMSettingTeamPort are conceptually the same,
  add "libnm-core/nm-team-utils.h" and NMTeamSetting that tries to
  handle the similar code side-by-sdie.
  The setting classes now just delegate for everything to NMTeamSetting.

- Previously, there was a very fuzzy understanding of the provided
  JSON config. Tighten that up, when setting a JSON config it
  regenerates/parses all other properties and tries to make the
  best of it. When modifying any abstraction property, the entire
  JSON config gets regenerated. In particular, don't try to merge
  existing JSON config with the new fields. If the user uses the
  abstraction API, then the entire JSON gets replaced.

  For example note that nm_setting_team_add_link_watcher() would not
  be reflected in the JSON config (a bug). That only accidentally worked
  because client would serializing the changed link watcher to
  GVariant/D-Bus, then NetworkManager would set it via g_object_set(),
  which would renerate the JSON, and finally persist it to disk. But
  as far as libnm is concerned, nm_setting_team_add_link_watcher() would
  bring the settings instance in an inconsistent state where JSON and
  the link watcher property disagree. Setting any property must
  immediately update both the JSON and the abstraction API.

- when constucting a team setting from D-Bus, we would previously parse
  both "config" and abstraction properties. That is wrong. Since our
  settings plugins only support JSON, all information must be present
  in the JSON config anyway. So, when "config" is present, only the JSON
  must be parsed. In the best case, the other information is redudant and
  contributes nothing. In the worse case, they information differs
  (which might happen if the client version differs from the server
  version). As the settings plugin only supports JSON, it's wrong to
  consider redundant, differing information from D-Bus.

- we now only convert string to JSON or back when needed. Previously,
  setting a property resulted in parsing several JSON multiple times
  (per property). All operations should now scale well and be reasonably
  efficient.

- also the property-changed signals are now handled correctly. Since
  NMTeamSetting knows the current state of all attributes, it can emit
  the exact property changed signals for what changed.

- we no longer use libjansson to generate the JSON. JSON is supposed
  to be a machine readable exchange format, hence a major goal is
  to be easily handled by applications. While parsing JSON is not so
  trivial, writing a well-known set of values to JSON is.
  The advantage is that when you build libnm without libjansson support,
  then we still can convert the artificial properties to JSON.

- Requiring libjansson in libnm is a burden, because most of the time
  it is not needed (as most users don't create team configurations). With
  this change we only require it to parse the team settings (no longer to
  write them). It should be reasonably simple to use a more minimalistic
  JSON parser that is sufficient for us, so that we can get rid of the
  libjansson dependency (for libnm). This also avoids the pain that we have
  due to the symbol collision of libjansson and libjson-glib.

https://bugzilla.redhat.com/show_bug.cgi?id=1691619
2019-05-23 18:09:49 +02:00
Thomas Haller
539dfbcc42 libnm: add "libnm-core/nm-team-utils.h" 2019-05-23 18:09:49 +02:00
Thomas Haller
0cc68e1c4f libnm: add init_from_dbus() virtual function to NMSetting 2019-05-23 18:09:49 +02:00
Thomas Haller
966e0db8d7 libnm: don't duplicate NMTeamLinkWatcher and make ref thread-safe
NMTeamLinkWatcher are immutable and ref-counted.

As such, there is little reason to ever duplicate them. Just increase
the ref-count.

For this change to be safe in all cicumstances, make ref/unref of the
link watcher thread-safe. After all, NMTeamLinkWatcher is public API,
and while libnm generally is not thead-safe, the cost of this is small.
2019-05-23 18:09:49 +02:00
Thomas Haller
e923668d74 libnm: rework NMTeamLinkWatcher structure and embed strings
Don't rely on the same memory layout for the NMTeamLinkWatcher union to
hold data for the watcher types. It looks wrong and is error prone.

Also, as we no longer require the full union, we can allocate a smaller
structure for ethtool. And while at it, we can embed the strings
directly instead of allocating them separately.

The point is to have a more efficient representation (memory wise).
2019-05-23 18:09:49 +02:00
Thomas Haller
b6156e9099 libnm: add internal cmp() function for NMTeamLinkWatcher types
Add internal nm_team_link_watcher_cmp() function.

We can implement nm_team_link_watcher_equal() based on that.

This was we can sort link watchers so that nm_team_link_watchers_equal()
with ignore_order is O(n*log(n)) instead of O(n^2).

In general, as basic API cmp() functions are as much effort to implement
as equal(), but they can also be used for sorting.

In nm_team_link_watcher_cmp(), only compare the fields that are set
according to the link watcher type.
2019-05-23 18:09:49 +02:00
Thomas Haller
e28bd1289b libnm: mark NMTeamLinkWatcher arguments as const in API
NMTeamLinkWatcher is immutable, meaning there is no way to change an
existing instance (aside increasing/decreasing the ref-count).

Hence, all API is implicitly const.

Still, mark the arguments as const.
2019-05-23 18:09:49 +02:00
Thomas Haller
35c92cf582 libnm/tests: mark team tests as skipped without JSON validation
We should not just disable tests with an #if.

Instead, mark them as skipped. This way, we still compile them, and we
even run them (showing a message why they are skipped).
2019-05-23 18:09:49 +02:00
Thomas Haller
a178fbac26 libnm/tests: add tests for modifying team setting 2019-05-23 18:09:49 +02:00
Thomas Haller
49dbdae00a libnm/tests: check for identical team config in _team_config_equal_check() 2019-05-23 18:09:49 +02:00
Thomas Haller
9b0dee8e9c libnm/tests: cleanup tests 2019-05-23 18:09:49 +02:00
Thomas Haller
61b1d1e963 libnm: fix parsing "nsna_ping" team link watcher from GVariant
Fixes: ba4ce843fa ('libnm-core: add backend for GVariant de/serialization of link_watchers.')
2019-05-23 18:09:49 +02:00
Thomas Haller
aff1d66b81 Revert "libnm: don't assert for success of g_dbus_error_register_error()"
Now that unit tests no longer dynamically link against libnm/libnm.la,
and statically against the same code, we can enable this assertion
again.

This reverts commit 7a0e347b38.
2019-05-22 20:04:08 +02:00
Jonas DOREL
13be449296 doc: replace "Split DNS" with "Conditional Forwarding"
Split DNS usually refers to "Split Horizon DNS" whereas "Conditional
Forwarding" is specifically for what the documentation describes.

[thaller@redhat.com: rewrote commit message]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/143
2019-05-17 12:08:45 +02:00
Thomas Haller
bb38bfe731 libnm: mark static "eap_methods_table" array as const
This allows the linker to put the variable into read-only memory,
which is desirable here.
2019-05-16 13:43:07 +02:00
Thomas Haller
7a0e347b38 libnm: don't assert for success of g_dbus_error_register_error()
libnm/tests/test-general statically links against libnm/libnm-utils.la
and dynamically against libnm/libnm.so. Hence, _nm_utils_init() is invoked
twice, failing the assertion.

That is a bug that must be fixed. For now, just don't assert.
2019-05-15 10:37:03 +02:00
Thomas Haller
a7c812f9f9 libnm: cleanup register_error_domain() 2019-05-15 08:45:22 +02:00