Commit Graph

316 Commits

Author SHA1 Message Date
Lubomir Rintel
bd119981a1 clients: add ovs-dpdk interface support 2019-06-14 12:10:20 +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
91d8038a81 cli: fix default value for team.runner-min-ports
The default value is "1", not "0". Also, because "0" is not actually a
valid value as far as teamd is concerned. This fixes:

    $ nmcli connection add type team autoconnect no con-name t team.runner lacp team.runner-min-ports default
    Error: Failed to add 't' connection: team.runner-min-ports: value out or range

See "teamd.conf" manual:

    runner.min_ports (int)
        Specifies the minimum number of ports that must be active before asserting
        carrier in the master interface, value can be 1 – 255.

        Default: 1

This mistake probably happend because the teamd manual is wrong in older versions [1].

[1] f36c191da3

https://bugzilla.redhat.com/show_bug.cgi?id=1716987
2019-06-11 13:25:21 +02:00
Thomas Haller
dfa8ecdab8 cli: remove unnecessary workaround for clearing team link watchers and runner-tx-hash
This is fixed in libnm. Resetting the GObject property clears the list
of watchers and tx-hashes.

Since nmcli requires a libnm version >= itself, this workaround
is no longer necessary.
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
403f207fe5 cli: fix resetting default value for GObject property
This matters for properties that don't have 0/NULL/FALSE as
default value and when setting an empty property with

  $ nmcli connection modify "$PROFILE" setting.property ''

Fixes: 3c82db710f ('cli: reset default value of properties via set_fcn()')
2019-05-31 15:52:29 +02:00
Thomas Haller
74d0a5bf9a nmcli: don't validate team config in nmcli
nm_connection_verify() can already validate team settings just fine.
No need to duplicate this.
2019-05-23 18:09:49 +02:00
Beniamino Galvani
c91aad4969 cli: hide certificate blobs unless --show-secrets is passed
This restores the behavior before commit 99711579ed.

Fixes: 99711579ed ('cli: add property type for 802-1x certificate properties (pt2)').
2019-05-06 10:10:00 +02:00
Beniamino Galvani
ec4a12ecdb cli: complete 802.1x certificate file names 2019-05-06 10:10:00 +02:00
Beniamino Galvani
eb724293c2 cli: allow completing filenames
Allow the completion function to indicate that the word should be
completed as a filename by the shell.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
eac15501b2 cli: parse escape sequences when reading an 802.1x private key
In this way it become possible to specify a filename that includes one
of the delimiters.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
ee96387578 cli: fix setting private key password
Fixes: fe390556ab ('cli: add property type for 802-1x certificate properties (pt3)')
2019-05-06 10:10:00 +02:00
Thomas Haller
020c4c81d8 cli: drop GValue transform functions for strdict and implement it in _get_fcn_gobject_impl()
The only remaining GValue transform function was from GHashTable (of (str,str) type)
to string. Drop that too, and implement the conversion in _get_fcn_gobject_impl().

Note that there are few GObject properties of type GHashTable and most
of them implement their own logic. This only applies to
"802-3-ethernet.s390-options".

Also, always sort the keys. Otherwise, the output is not stable.
2019-04-25 08:20:03 +02:00
Thomas Haller
e55a45faa2 cli: drop GValue transformation of GBytes to string and implement bytes getter via _get_fcn_gobject_impl()
The g_value_register_transform_func() for handling GBytes was not actually used.
All properties of type G_TYPE_BYTES have their explit handler how to convert bytes
to string. That is good, because the implementation there was very bad (it did not
honor pretty/parsable get-type).

Also, merge _get_fcn_gobject_bytes() into _get_fcn_gobject_impl(). We
already have a generic handler that handles properties solely based on
the GObject type: _get_fcn_gobject_impl(). Just let it also handle
bytes. It's better to have fewer handlers, if they don't need special
context.
2019-04-25 08:20:03 +02:00
Thomas Haller
d4d1e5f00d cli: drop GValue transform function for G_TYPE_STRV to G_TYPE_STRING
It's ugly to modify the global behavior of glib to convert between
types. Instead, _get_fcn_gobject_impl() is perfectly capable to implement
converting a strv array to string.
2019-04-25 08:20:03 +02:00
Thomas Haller
655a920577 cli: cleanup and fix handling of unset/empty "ipv4.dns-options"
"ipv4.dns-options" and "ipv6.dns-options" are special, in that they can
be either unset/default or an empty list of options. That means, nmcli
must treat these two options differently.

For the (terse) getter, it returns "" for default and " " for empty.
The setter must likewise support and distingish between these two cases.

Cleanup the handling of such options. This only applies to properties of
type "multilist". Hence, add multilist.clear_emptyunset_fcn() handler
that indicates that the property is of that kind.

Try:

  nmcli connection modify "$PROFILE" ipv4.dns-options ''
  nmcli connection modify "$PROFILE" ipv4.dns-options ' '

and compare the output:

  nmcli connection show "$PROFILE" | sed -n '/ipv4.dns-options/ s/.*/<\0>/p'
  nmcli -t connection show "$PROFILE" | sed -n '/ipv4.dns-options/ s/.*/<\0>/p'
  nmcli -o connection show "$PROFILE" | sed -n '/ipv4.dns-options/ s/.*/<\0>/p'
2019-04-25 08:13:02 +02:00
Thomas Haller
bee4d30bec cli: add RETURN_STR_TEMPORARY() macro to "clients/common/nm-meta-setting-desc.c"
Will be used next.
2019-04-25 07:53:48 +02:00
Thomas Haller
d76f3748de cli: use escaped-tokens style for team-link-watcher list properties
The link-watcher properties are not expected to contain any special values
that require escaping. Hence, change the tokenizing from plain splitting
at ',' to escaped-tokens style is likely to not affect any existing
setups.

Still, all our properties should be handled the same way (including a
tokenizing which allows escaping to represent every possible value).
2019-04-25 07:50:59 +02:00
Thomas Haller
db9fbcee6c cli,shared: move NMTeamLinkWatcher to/from string function to "nm-libnm-core-aux.h"
to/from string functions are useful. We should be able to reuse them.
Move them to their own location.

Also, it moves independent code out of "clients/common/nm-meta-setting-desc.c"
which is already one of the largest source files we have.

Also, it makes the code unit-testable, which is obviously required
as the code has bugs.
2019-04-25 07:46:17 +02:00
Thomas Haller
284ac92eee shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-core
"libnm-core" implements common functionality for "NetworkManager" and
"libnm".

Note that clients like "nmcli" cannot access the internal API provided
by "libnm-core". So, if nmcli wants to do something that is also done by
"libnm-core", , "libnm", or "NetworkManager", the code would have to be
duplicated.

Instead, such code can be in "libnm-libnm-core-{intern|aux}.la".
Note that:

  0) "libnm-libnm-core-intern.la" is used by libnm-core itsself.
     On the other hand, "libnm-libnm-core-aux.la" is not used by
     libnm-core, but provides utilities on top of it.

  1) they both extend "libnm-core" with utlities that are not public
     API of libnm itself. Maybe part of the code should one day become
     public API of libnm. On the other hand, this is code for which
     we may not want to commit to a stable interface or which we
     don't want to provide as part of the API.

  2) "libnm-libnm-core-intern.la" is statically linked by "libnm-core"
     and thus directly available to "libnm" and "NetworkManager".
     On the other hand, "libnm-libnm-core-aux.la" may be used by "libnm"
     and "NetworkManager".
     Both libraries may be statically linked by libnm clients (like
     nmcli).

  3) it must only use glib, libnm-glib-aux.la, and the public API
     of libnm-core.
     This is important: it must not use "libnm-core/nm-core-internal.h"
     nor "libnm-core/nm-utils-private.h" so the static library is usable
     by nmcli which couldn't access these.

Note that "shared/nm-meta-setting.c" is an entirely different case,
because it behaves differently depending on whether linking against
"libnm-core" or the client programs. As such, this file must be compiled
twice.

(cherry picked from commit af07ed01c0)
2019-04-18 20:07:44 +02:00
Thomas Haller
d984b2ce4a shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"
From the files under "shared/nm-utils" we build an internal library
that provides glib-based helper utilities.

Move the files of that basic library to a new subdirectory
"shared/nm-glib-aux" and rename the helper library "libnm-core-base.la"
to "libnm-glib-aux.la".

Reasons:

 - the name "utils" is overused in our code-base. Everything's an
   "utils". Give this thing a more distinct name.

 - there were additional files under "shared/nm-utils", which are not
   part of this internal library "libnm-utils-base.la". All the files
   that are part of this library should be together in the same
   directory, but files that are not, should not be there.

 - the new name should better convey what this library is and what is isn't:
   it's a set of utilities and helper functions that extend glib with
   funcitonality that we commonly need.

There are still some files left under "shared/nm-utils". They have less
a unifying propose to be in their own directory, so I leave them there
for now. But at least they are separate from "shared/nm-glib-aux",
which has a very clear purpose.

(cherry picked from commit 80db06f768)
2019-04-18 19:57:27 +02:00
Thomas Haller
5b2d0f0f9f cli: use "escaped-tokens" style for splitting "vlan.xgress-priority-map" list
There should be little difference here, because the priority list is
(and was) never serialized with special characters like backslashes or
delimiters that require escaping.

Likewise, no working code actually tried to set such characters.

Still, drop the plain VALUE_STRSPLIT_MODE_STRIPPED and use
VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES instead. We should have
a small set of modes that we use for splitting strings.

(cherry picked from commit 7f01da917e)
2019-04-18 18:51:21 +02:00
Thomas Haller
f6237b3f24 cli: cleanup _get_fcn_vlan_xgress_priority_map()
- merge the pointless helper function vlan_priorities_to_string()
  into the only caller _get_fcn_vlan_xgress_priority_map().

- minor cleanups, like setting out-is-default if num==0, not
  based on whether we have a non-empty string. There is not difference
  in practice, because nm_setting_vlan_get_priority() never fails.
  Hence they are identical. But nm_setting_vlan_get_priority() has
  an API that allows it to fail, so we should declare the default
  depending on the number of vlan priorities.

- don't allocate the temporary GString instance if we won't need it.

- only append the delimiter if needed, and not truncate it afterwards.
  It might have even worse performance this way, but it feels more
  correct to me.

- also cache the result of nm_setting_vlan_get_num_priorities().
  NMSettingVlan's implementation is horrible and uses a GSList to
  track the list of priorities. This makes it relatively expensive
  to call get-num-priorities repeatedly (and pointless).

(cherry picked from commit bbfd366805)
2019-04-18 18:51:21 +02:00
Thomas Haller
0e54f55cd8 cli: unify set of characters to tokenize list properties
the only change in behaviour is for VALUE_STRSPLIT_MODE_MULTILIST.
Previously, we would split at " \t,", now we will also split at
the white space characters "\n\r\f".

(cherry picked from commit 7a92fb6bf4)
2019-04-18 18:51:21 +02:00
Thomas Haller
f6d73aff70 cli: refactor multilist property handling of "match.interface-names"
We had %VALUE_STRSPLIT_MODE_MULTILIST_WITH_ESCAPE, which was used
by "match.interface-names". This uses nm_utils_strsplit_set_full()
with %NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING and
_nm_utils_unescape_plain().

We want eventually to use nm_utils_escaped_tokens_split() everywhere.

We already have %VALUE_STRSPLIT_MODE_ESCAPED_TOKENS, which splits the
list at ',' (and strips whitespaces at the around the delimiter). That
differs from what %VALUE_STRSPLIT_MODE_MULTILIST_WITH_ESCAPE did, which
also considered whitespace a delimiter.

So, we need a new mode %VALUE_STRSPLIT_MODE_ESCAPED_TOKENS_WITH_SPACES
which replaces the previous mode.

Note that the previous implementation did almost the same thing. In
fact, I cannot imagine examples where they behaved differently, but
my feeling is that there might be some edge cases where this changes
behavior.

(cherry picked from commit 6093f49304)
2019-04-18 18:51:21 +02:00
Thomas Haller
53b3e3d709 cli: return early when splitting with %VALUE_STRSPLIT_MODE_STRIPPED
The reminder of the function only does (something akin to) g_strstrip().
As we split the strings are spaces to begin with, there is nothing to
strip and we can return right away.

(cherry picked from commit b74d9a0bd5)
2019-04-18 18:51:20 +02:00
Thomas Haller
55a46f91e5 cli: drop unused strsplit_with_escape mode for objlist properties
(cherry picked from commit 3f5df5ab72)
2019-04-18 18:51:20 +02:00
Thomas Haller
f4a7c2eb9e cli: assert for proper escaping when creating objlist string
(cherry picked from commit 84bd1d38df)
2019-04-18 18:51:20 +02:00
Thomas Haller
872025d27c cli: default splitting list properties with escaped-tokens style
When splitting (and concatenating) list-typed properties,
we really should use nm_utils_escaped_tokens_split()
and nm_utils_escaped_tokens_escape*().

Make that the default, and mark all properties to opt-in to the
legacy behavior.

(cherry picked from commit 5a71592087)
2019-04-18 18:51:20 +02:00
Thomas Haller
4eaff61f35 cli: fix splitting of multilist property in setter
The modes VALUE_STRSPLIT_MODE_OBJLIST* and VALUE_STRSPLIT_MODE_MULTILIST* are
different. We must use the right mode.

For example, _get_fcn_match_interface_name() concatenates the interface-names
with space. So, the tokenizer of the setter must also use space as delimiter.
VALUE_STRSPLIT_MODE_MULTILIST_WITH_ESCAPE does that correctly,
VALUE_STRSPLIT_MODE_OBJLIST_WITH_ESCAPE does not.

(cherry picked from commit 758bf32640)
2019-04-18 18:51:20 +02:00
Thomas Haller
c26a421479 cli: fix handling empty match.interface-name property
(cherry picked from commit 6bef72364d)
2019-04-18 18:51:20 +02:00
Beniamino Galvani
6ac953e9b3 all: use escaped_tokens API for bridge vlans
(cherry picked from commit 9f23c5e2de)
2019-04-18 09:53:22 +02:00
Beniamino Galvani
da204257b1 all: support bridge vlan ranges
In some cases it is convenient to specify ranges of bridge vlans, as
already supported by iproute2 and natively by kernel. With this commit
it becomes possible to add a range in this way:

 nmcli connection modify eth0-slave +bridge-port.vlans "100-200 untagged"

vlan ranges can't be PVIDs because only one PVID vlan can exist.

https://bugzilla.redhat.com/show_bug.cgi?id=1652910
(cherry picked from commit 7093515777)
2019-04-18 09:53:18 +02:00
Beniamino Galvani
ea8ed6ce16 clients: fix typos
(cherry picked from commit ea16cf59f6)
2019-04-18 09:53:16 +02:00
Thomas Haller
b583f3a482 cli: use nm_utils_escaped_tokens_*() for handling policy routes
Optimally, all list types properties in nmcli support proper escaping.
For that, we should use nm_utils_escaped_tokens_*() API.

For now, just change that for policy routes. They were just added recently,
so no change in behavior of released API.

(cherry picked from commit d59f046bb6)
2019-04-17 11:27:11 +02:00
Thomas Haller
0deb3024bc cli: add new style for tokenizing/concatenating list options in nmcli
nmcli supports list options (optlist and multilist properties).
These commonly are individual items, concatenated by a delimiter.

It should be generally possibly to express every value. That means, we
need some for of escaping mechanism for delimiters.

Currently this is all inconsistent or no escaping is supported. I intend
to fix that (which will be a change in behavior).

For now, just add yet another style of tokenzing/concatenating list
items in nmcli. This is the style to replace all other styles.

(cherry picked from commit ba956bd499)
2019-04-17 11:27:11 +02:00
Thomas Haller
53ab539dd1 cli: avoid duplicate delimiters when printing objlist property
Usually, obj_to_str_fcn() should not fail and always add something.
If not, remove the delimiter again.

(cherry picked from commit 720bc30bd9)
2019-04-17 11:27:10 +02:00
Lubomir Rintel
817b55cf06 nmcli: fix an error message when the tc qdisc kind is missing
Before:

  # nmcli c modify eth666 tc.qdiscs root
  Error: failed to modify tc.qdiscs: '(null)' is not a valid kind The valid syntax is: '[root | parent <handle>] [handle <handle>] <qdisc>'.

After:

  # nmcli c modify eth666 tc.qdiscs root
  Error: failed to modify tc.qdiscs: kind is missing. The valid syntax is: '[root | parent <handle>] [handle <handle>] <kind>'.
2019-04-12 17:30:15 +02:00
Thomas Haller
3e0366a3ff all: replace g_strsplit_set() by nm_utils_strsplit_set*() 2019-04-10 15:05:57 +02:00
Thomas Haller
84f2037648 shared: add flags argument to nm_utils_strsplit_set()
It will be useful to extend nm_utils_strsplit_set() with various
flavors and subtly different behaviors. Add a flags argument to
support these.
2019-04-10 15:05:57 +02:00
Thomas Haller
610aa5c432 cli: use nm_strstrip_avoid_copy_a() to avoid heap allocation 2019-04-04 21:01:15 +02:00
Lubomir Rintel
4ddc2bb766 clients: do not require gsm.apn
The server doesn't require it either.
2019-04-03 11:50:35 +02:00
Thomas Haller
ba59c7c3c0 cli: add support for routing rules to nmcli 2019-03-27 16:23:30 +01:00
Thomas Haller
71e40f519d cli: support escaping for splitting for objlist properties 2019-03-27 16:23:30 +01:00
Beniamino Galvani
4848ad7c77 nmcli: add bridge vlans support 2019-03-26 17:19:39 +01:00
Beniamino Galvani
96fab7b462 all: add vlan-filtering and vlan-default-pvid bridge properties 2019-03-26 17:18:29 +01:00
Thomas Haller
8b0461380f cli/trivial: add comment about partially modifying settings when failing set_fcn() 2019-03-25 09:12:33 +01:00
Thomas Haller
3a77201361 cli: workaround libnm issue for setting team.runner-tx-hash
This workaround was dropped when refactoring the property handling.
Restore the workaround (at least) until libnm is fixed.
2019-03-25 09:12:33 +01:00
Thomas Haller
a1c7b04664 nmcli: add clear_all_fcn() hook for mutllist property types 2019-03-25 09:12:33 +01:00
Thomas Haller
3a8fe7ad45 cli: consistently validate multilist options for add and remove
There is no reason to validate only in certain cases. Either we
validate, or we don't (always the same).

This is a change in behavior, but the cases should be sensible.
2019-03-25 09:12:33 +01:00