Commit graph

1486 commits

Author SHA1 Message Date
Thomas Haller
d59f046bb6 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.
2019-04-17 11:11:21 +02:00
Thomas Haller
ba956bd499 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.
2019-04-17 11:11:21 +02:00
Thomas Haller
720bc30bd9 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.
2019-04-17 11:09:28 +02:00
Thomas Haller
f4afb38bd9 cli: fix crash in split_required_fields_for_con_show()
Depending on the architecture (calling convention), function
arguments are evaluated in one order or the other.

https://bugzilla.redhat.com/show_bug.cgi?id=1700409

Fixes: 34e60bf228 ('cli: cleanup split_required_fields_for_con_show()')
2019-04-16 16:00:32 +02:00
Thomas Haller
43d93e7c1f cli: tab complete only full D-Bus paths if there is no prefix
When tab completing connections by path name without any already
typed parts, only suggest full D-Bus paths. The numbers are duplicate
and not preferred.

Before:

    $ nmcli connection show path <TAB>
    Display all 118 possibilities? (y or n)
    1                                            46                                           /org/freedesktop/NetworkManager/Settings/29
    10                                           47                                           /org/freedesktop/NetworkManager/Settings/3
    11                                           48                                           /org/freedesktop/NetworkManager/Settings/30
    12                                           49                                           /org/freedesktop/NetworkManager/Settings/31
    13                                           5                                            /org/freedesktop/NetworkManager/Settings/32

Afterwards:

    $ nmcli connection show path <TAB>
    /org/freedesktop/NetworkManager/Settings/1   /org/freedesktop/NetworkManager/Settings/28  /org/freedesktop/NetworkManager/Settings/46
    ...

and

    $ nmcli connection modify path 4<TAB>
    4   40  41  42  43  44  45  46  47  48  49
2019-04-15 20:50:50 +02:00
Thomas Haller
68bd018a88 cli: prefer matching connections by "uuid" instead of "id"
Scripts should refer to connections by UUID. That means, whenever a
UUID matches, that is really what the user wants. The specifier "uuid"
must have precedence over "id" (and all others). That means, we must
search all connections.

For example:

    $ UUIDS=($(nmcli -g TYPE,UUID connection show | sed -n 's/802-11-wireless://p'))
    $ nmcli -f connection.id,connection.uuid connection show "${UUIDS[@]}"

in this case we must preferrably match by UUID, regardless of whether
a "connection.id" exists.

Note that if you have:

    $ nmcli connection show | grep fdf7b2d2-2858-3938-9b14-7f1b514a9a00
    b                                     fdf7b2d2-2858-3938-9b14-7f1b514a9a00  ethernet   --
    fdf7b2d2-2858-3938-9b14-7f1b514a9a00  ab9f3891-3420-335e-89da-f14c1b94c540  ethernet   --

then certain commands will still select all matching connections:

    $ nmcli -f connection.id,connection.uuid --mode multiline connection show fdf7b2d2-2858-3938-9b14-7f1b514a9a00
    connection.id:                          fdf7b2d2-2858-3938-9b14-7f1b514a9a00
    connection.uuid:                        ab9f3891-3420-335e-89da-f14c1b94c540

    connection.id:                          b
    connection.uuid:                        fdf7b2d2-2858-3938-9b14-7f1b514a9a00

This only makes a difference for commands that must pick only one profile:

    $ nmcli connection modify fdf7b2d2-2858-3938-9b14-7f1b514a9a00 con-name new-name
2019-04-15 20:50:50 +02:00
Thomas Haller
87d16e935c cli: drop unnecessary NULL sentinel from nmc_complete_strings()
Since commit 62b939de4e ('cli: add nmc_complete_strv() which takes a
string array for completion that may contain NULL'), the sentinel is
no longer needed.
2019-04-15 20:50:50 +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
Beniamino Galvani
2fe9141960 clients: disable asan leak detection in client tests
Leak detection adds unhelpful messages to the stderr of nmcli, making
tests fail. For example:

 =================================================================
 ==17156==ERROR: LeakSanitizer: detected memory leaks

 Direct leak of 256 byte(s) in 2 object(s) allocated from:
     #0 0x7f08c7e27c88 in realloc (/lib64/libasan.so.5+0xefc88)
     #1 0x7f08c7546e7d in g_realloc (/lib64/libglib-2.0.so.0+0x54e7d)
2019-04-12 11:19:58 +02:00
Thomas Haller
7b6a3aaf29 cli: fix typo in nmcli usage output
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/157
2019-04-12 09:56:51 +02:00
Beniamino Galvani
a94ccc9acc clients: fix assertion when requesting gsm pin secret
[root@gsm-r5s4-01 ~]# nmcli  connection up id gsm
  **
  libnmc:ERROR:clients/common/nm-secret-agent-simple.c:171:_secret_real_new_plain: assertion failed: ((secret_type == NM_SECRET_AGENT_SECRET_TYPE_SECRET) == nm_setting_get_secret_flags (setting, property, ((void *)0), ((void *)0)))
  Aborted (core dumped)

The pin is a secret property.

https://bugzilla.redhat.com/show_bug.cgi?id=1698495
2019-04-11 13:50:09 +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
34e60bf228 cli: cleanup split_required_fields_for_con_show()
- return early and use cleanup attribute for freeing memory
- use nm_utils_strsplit_set_with_empty() instead of g_strsplit_set().
2019-04-10 15:05:57 +02:00
Thomas Haller
c9ca7d0637 cli: cleanup nm_vpn_openconnect_authenticate_helper() 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
700a32e5dd cli: fix memleak in nm_vpn_openconnect_authenticate_helper() 2019-04-10 15:05:57 +02:00
Thomas Haller
a77c5d18c4 cli: fix missing newline for printing error message about "Connection deletion failed"
$ nmcli connection delete Wired\ connection\ 1
  Error: Connection deletion failed: Insufficient privilegesError: not all connections deleted.
2019-04-05 20:25:28 +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
Lubomir Rintel
ee73c560b9 secret-agent-simple: pass hints to the auth dialog 2019-04-03 08:57:10 +02:00
Lubomir Rintel
6021ddb349 secret-agent-simple: get rid of an extra variable 2019-04-03 08:57:10 +02:00
Lubomir Rintel
5d481b9210 secret-agent-simple: replace a char array with a GPtrArray
This will make it easier to dynamically add more options.
2019-04-03 08:57:10 +02:00
Beniamino Galvani
5b5a768b69 clients: only ask secrets for settings that require them
When nmcli needs secrets for a connection it asks them for every known
setting. nmtui is a bit smarter and asks them only for settings that
actually exist in the connection. Make a step further and let clients
ask secrets only for setting that exist *and* have any secret
property. This decreases the number of D-Bus calls when editing or
showing a connection with secrets.

https://bugzilla.redhat.com/show_bug.cgi?id=1506536
https://github.com/NetworkManager/NetworkManager/pull/327
2019-04-02 11:20:28 +02:00
Lubomir Rintel
9c9c8c68ff cli: fix a crash on "nmcli d wifi hotspot"
Call the correct _finish() function for
nm_client_add_and_activate_connection_async(). add_and_activate_cb()
somewhat confusingly alternates between two different ones depending on
whether info->create is set.

Fixes: 3593237527 ('cli: reuse connections in nmcli dev wifi con')
https://github.com/NetworkManager/NetworkManager/pull/326
2019-04-02 09:09:54 +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
Thomas Haller
598ecbc482 cli: fix accepting %NULL value for '+' modifier
I find it questionable, how nmcli likes to coerce the empty input to
NULL to indicate resetting the value. If nmcli would like to set a
default, it should use a different way of signalling that. Anyway, the
assertion was too strict.

    $ nmcli connection modify "$PROFILE" +ipv4.addresses ''
2019-03-27 16:12:15 +01:00
Beniamino Galvani
b1d5f11b3d cli: add lldp output tests
Check the result of 'nmcli device lldp' command.
2019-03-27 10:17:39 +01:00
Beniamino Galvani
4848ad7c77 nmcli: add bridge vlans support 2019-03-26 17:19:39 +01:00
Beniamino Galvani
a680bedf94 libnm-core: add vlans property to bridge setting 2019-03-26 17:18:29 +01:00
Beniamino Galvani
1e5b0788bc libnm-core: add vlans property to bridge-port setting 2019-03-26 17:18:29 +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
7dcf368cf0 cli: freeze/thaw property changed signals in nmc_setting_set_property()
Setting one property might affect multiple properties.
For example, setting a team property might also emit property changed
signal for "team.config".

Or, one property might be modified multiple times. For example list
properties may first clear the property, then append multiple elements.
Or a list property might remove multiple elements.

Combine these signals via g_object_freeze_notify() and
g_object_thaw_notify().
2019-03-25 09:12:33 +01:00
Thomas Haller
d3343b241f cli/trivial: add FIXME comment about how wrong editor_init_existing_connection() is 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
Thomas Haller
96c4f51208 cli: distinguish between resetting GObject property to default and NULL
Most GObject properties default to FALSE/NULL/0. In that case, there
is no difference between setting the default or clearing the value.

During

     if (_SET_FCN_DO_RESET_DEFAULT (property_info, modifier, value))
         return _gobject_property_reset_default (setting, property_info->property_name);

it is correct to reset the default.

However for list-typed properties, we want to clear the list. So,
it should be

     if (_SET_FCN_DO_SET_ALL (modifier, value))
         _gobject_property_reset (setting, property_info->property_name, FALSE);
2019-03-25 09:12:33 +01:00
Thomas Haller
166e04799d cli: accept ',' as delimiter for match.interface-names
"match.interface-names" is the only property that uses VALUE_STRSPLIT_MODE_MULTILIST_WITH_ESCAPE.

    $ nmcli connection modify "$PROFILE" match.interface-name ' 5, \,\  4\,  '

results in

    [match]
    interface-name=5;, ;4,;

and

    $ echo ">$(nmcli -g match.interface-name -escape=no connection show "$PROFILE")<"
    >5 \,\  4\,<

Yes, plain --get leads to a wrong double-escaping:

    $ echo ">$(nmcli -g match.interface-name connection show "$PROFILE")<"
    >5 \\,\\  4\\,<
2019-03-25 09:12:33 +01:00
Thomas Haller
65c8c19fa7 cli: don't support removing sriov vfs by index
The VFs already can be parsed as plain number (to indicate the
ifindex). We should not also support accepting the plain number
as index to be removed.

Fixes: a2f12994b7 ('cli: add support for configuring SR-IOV')
2019-03-25 09:12:33 +01:00
Thomas Haller
70bad5c74d cli: support list of indexes for removing objlist property
$ nmcli connection modify "$PROFILE" -ipv4.addresses 1,3

Already before, nmcli would support removing items by index. But only
one number was supported.

- indexes are zero based (as before).

- duplicate indexes or indexes out of bounds are silently ignored.

Maybe certain properties should not support removal by index.
2019-03-25 09:12:33 +01:00
Thomas Haller
28f0153350 cli: cleanup parsing of VLAN ingress/egress priority map
Use new ValueStrsplitMode "VALUE_STRSPLIT_MODE_STRIPPED".

Note that this is not exactly what we did before. For example, empty
tokens are now silently removed.

Also, we accept now whitespace as separators.
2019-03-25 09:12:33 +01:00
Thomas Haller
c0d83ef522 cli: refactor splitting the string when parsing the property values
Have one function that gets all the nonesense right. "nonesense", because
we have inconsistent behaviors, and the function is supposed to help with
that.
2019-03-25 09:12:33 +01:00
Thomas Haller
e2c95014c2 cli: merge remove-by-value and add functions of objlist property types 2019-03-25 09:12:33 +01:00
Thomas Haller
18fac0407e cli: merge set_fcn() and remove_fcn()
set_fcn() and remove_fcn() are strongly related. They should accept
arguments in the same format, hence the parsing of the arguments should
be done at one place.

In fact, previously the parsing was separate, leading to ugly
inconsistencies:

  $ nmcli connection modify "$PROFILE" +vpn.data x=y
  $ nmcli connection modify "$PROFILE" -vpn.data x=y
  Error: failed to remove a value from vpn.data: invalid option 'x=y'.

or

  $ nmcli connection modify "$PROFILE" +ipv4.addresses 192.168.1.5/24,192.168.2.5/24
  $ nmcli connection modify "$PROFILE" -ipv4.addresses 192.168.1.5/24,192.168.2.5/24
  Error: failed to remove a value from ipv4.addresses: invalid prefix '24,192.168.2.5/24'; <1-32> allowed.

Let set_fcn() handle set-default, set-all, add, and subtract.
2019-03-25 09:12:33 +01:00
Thomas Haller
eb0cfefe52 cli: allow resetting all values via set_fcn() property handler
Previously, set_fcn() could only append values. Now, pass on the modifier
so that it may append, set all, or reset the default.

These operations are strongly related and should be handled by the same
set_fcn() function.
2019-03-25 09:12:33 +01:00
Thomas Haller
22382c4e82 cli: implement remove-fcn for objlist types 2019-03-25 09:12:33 +01:00
Thomas Haller
923a79554c cli: implement add-fcn for objlist types 2019-03-25 09:12:33 +01:00
Thomas Haller
2a50729c6f cli: add clear-all-fcn for objlist properties 2019-03-25 09:12:33 +01:00