Commit Graph

84 Commits

Author SHA1 Message Date
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
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
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
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
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
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
c26a421479 cli: fix handling empty match.interface-name property
(cherry picked from commit 6bef72364d)
2019-04-18 18:51:20 +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
71e40f519d cli: support escaping for splitting for objlist properties 2019-03-27 16:23:30 +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
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
Thomas Haller
ad15b2505b cli: add objlist property type and implement get_fcn() for all types 2019-03-25 09:12:33 +01:00
Thomas Haller
126348d4be cli: implement team:runner-tx-hash as multilist property 2019-03-25 09:12:33 +01:00
Thomas Haller
1b1ef52ff8 cli: implement match:interface-names as multilist property 2019-03-25 09:12:33 +01:00
Thomas Haller
b63620e67c cli: implement DNS property as multilist type 2019-03-25 09:12:32 +01:00
Thomas Haller
d9c8794338 cli: support validating multilist entries for remove-by-value 2019-03-25 09:12:32 +01:00
Thomas Haller
3d1206e878 cli: make get_with_default property-type-data generally available
A property-info can only have one property-typ-data. That means,
all functions (get_fcn(), set_fcn()) need to either take not
property-typ-data, or they must all accept the same.

That made it hard to mix _get_fcn_nmc_with_default() with setters
that do require a certain property-typ-data. Instead, move the
is_default_func() to the general portion, and let _get_fcn_gobject()
handle it.
2019-03-25 09:12:32 +01:00
Thomas Haller
180925ff0c cli: implement DNS search property as multilist type 2019-03-25 09:12:32 +01:00
Thomas Haller
df0d5f8dee cli: add property type for 802-1x certificate properties (pt1) 2019-03-25 09:12:32 +01:00
Thomas Haller
e58ec47d1b cli: implement NM_SETTING_VPN_DATA with the optionlist setter 2019-03-25 09:12:32 +01:00
Thomas Haller
bcee2d7cc9 cli: add optionlist setter for bond options 2019-03-25 09:12:32 +01:00
Thomas Haller
05080816f0 cli/dcb: merge DCB uint setters 2019-03-25 09:12:32 +01:00
Thomas Haller
1fa1b01546 cli/dcb: rework DCB uint getters 2019-03-25 09:12:32 +01:00
Thomas Haller
ca38ce95ee cli/dcb: merge handling NM_SETTING_DCB_PRIORITY_FLOW_CONTROL and NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH 2019-03-25 09:12:32 +01:00
Thomas Haller
74f922b64f cli: implement str-list-multi properties as property type and not via macros
Instead of using a macro to define the individual set/remove functions,
add a new property type _pt_multilist.

This way, we have more the concept of a property having a type, instead
of a property having a set of handlers how to implement something.

Also, this is only the first step. There are several similar properties
that also can be implemented as the same type.
2019-03-25 09:12:32 +01:00
Thomas Haller
cb5a81399a cli: don't interpret value as index too early for nmc_setting_remove_property_option()
Not all implementations support having the value being an index.
For example, the implementations that are done via DEFINE_REMOVER_OPTION() macro.

The meaning of the "value" string must not be determined by
nmc_setting_remove_property_option(). It's up to the implementation
to decide whether to allow an index and how to interpret it.
2019-03-25 09:12:32 +01:00
Thomas Haller
0e7e8adc12 cli: rework NM_SETTING_802_1X_PASSWORD_RAW property functions to operate on generic GBytes
Rework the explicit implementation of NM_SETTING_802_1X_PASSWORD_RAW
handling to generically handle GBytes properties.

Note that the NM_SETTING_802_1X_PASSWORD_RAW setter accepts a legacy
format where hex-words are separated by space. I don't think we want
to support this format for new options.

So, there are two possibilities:

1) either leave _set_fcn_802_1x_password_raw() as-is, with the special
   handling.

2) interpret a property-data gobject_bytes.legacy_format.

1) seems to make more sense, because there is only one such property,
and we won't use this for new properties. However let's do 2), because
it shows nicely the two styles side-by-side. In other words, let's
password-raw also be a _pt_gobject_bytes typed property, with some
special legacy handling. Instead, of having it an entirely separate
property type (with a different setter implementation). I think it's
better to have the parts where they differ pushed down (the "stack") as
much as possible.
2019-02-22 14:04:13 +01:00
Thomas Haller
a600b3a3b2 cli: fix handling uint64 connection property "serial.send-delay"
libnm currently has only one GObject property of type uint64:
"serial.send-delay". However, it's broken because uint64 handling
is not implemented.

    $ nmcli connection add type gsm autoconnect no con-name t ifname '*' apn 'xyz' serial.baud 5
    Connection 't' (4c929f17-9fda-41d6-8f90-897f6d46b078) successfully added.

    $ nmcli connection show t
    ...
    ipv6.dhcp-duid:                         --
    ipv6.dhcp-send-hostname:                yes
    ipv6.dhcp-hostname:                     --
    ipv6.token:                             --

    (process:14016): libnmc-CRITICAL **: 14:08:32.591: file clients/common/nm-meta-setting-desc.c: line 811 (_get_fcn_gobject_int): should not be reached
    serial.baud:                            5
    serial.bits:                            8
    serial.parity:                          none
    serial.stopbits:                        1
    serial.send-delay:                      --
    gsm.number:                             *99#
    ...

    $ nmcli connection add type gsm autoconnect no con-name t ifname '*' apn 'xyz' serial.baud 5 serial.send-delay 100

    (process:14852): libnmc-CRITICAL **: 14:12:24.259: file clients/common/nm-meta-setting-desc.c: line 1131 (_set_fcn_gobject_int): should not be reached
    Segmentation fault (core dumped)

Fixes: b6d9bdcee8
2018-10-17 16:22:34 +02:00
luz.paz
f985b6944a docs: misc. typos
Found via `codespell -q 3 --skip="*.po"`

https://github.com/NetworkManager/NetworkManager/pull/203
2018-09-15 09:08:03 +02:00
Thomas Haller
582ee91145 cli: add functionality to hide properties from output
Historically, nmcli printed all fields during operations like
`nmcli connection show "$PROFILE"`. As we supported more and
more options, this resulted in a verbose output, of most properties
just being the default values.

To counter that, we added the '-overview' option. When given,
it would hide options that are set at their default. This option
was not the default, to preserve established behavior.

However, for new options, we can afford to hide them. Add a mechanism,
that property getters can mark their value to be hidden. At the moment,
there is no way to show these properties. However, we could add a
'-verbose' option, with the opposite meaning of '-overview'. Anyway,
that does not seem necessary at the moment.

Hiding properties from output is only acceptable for new properties
(otherwise we badly change behavior), and if the properties are set
at their default values (otherwise, we hide important information).
2018-08-10 10:38:19 +02:00
Thomas Haller
df30651b89 libnm, cli, ifcfg-rh: add NMSettingEthtool setting
Note that in NetworkManager API (D-Bus, libnm, and nmcli),
the features are called "feature-xyz". The "feature-" prefix
is used, because NMSettingEthtool possibly will gain support
for options that are not only -K|--offload|--features, for
example -C|--coalesce.

The "xzy" suffix is either how ethtool utility calls the feature
("tso", "rx"). Or, if ethtool utility specifies no alias for that
feature, it's the name from kernel's ETH_SS_FEATURES ("tx-tcp6-segmentation").
If possible, we prefer ethtool utility's naming.

Also note, how the features "feature-sg", "feature-tso", and
"feature-tx" actually refer to multiple underlying kernel features
at once. This too follows what ethtool utility does.

The functionality is not yet implemented server-side.
2018-08-10 10:38:19 +02:00
Thomas Haller
ba350a3495 cli: add additional user-data argument to get_fcn()
The function nmc_print() receives a list of "targets". These are essentially
the rows that should be printed (while the "fields" list represents the columns).

When filling the cells with values, it calles repeatedly get_fcn() on the
column descriptors (fields), by passing each row (target).

The caller must be well aware that the fields and targets are
compatible. For example, in some cases the targets are NMDevice
instances and the target type must correspond to what get_fcn()
expects.

Add another user-data pointer that is passed on along with the
targets. That is useful, if we have a list of targets/rows, but
pass in additional data that applies to all rows alike.

It is still unused.
2018-07-09 15:43:55 +02:00
Lubomir Rintel
5da77c0e2c client: support wpan setting 2018-06-26 16:21:55 +02:00
Lubomir Rintel
31aa2cfe29 cli: use a palette to implement coloring
This basically replaces the (NMMetaTermColor, NMMetaTermFormat) combo
with NMMetaColor that describes the colored element semantically as
opposed to storing the raw attributes.

A (currently static) paletted is used to translate the semantic color
code to the actual ANSI controle sequence. This matches what
terminal-colors.d(5) schemes use, making it convenient to implement
customizable palettes.
2018-05-10 14:36:58 +02:00
Beniamino Galvani
aca671fff0 all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
Beniamino Galvani
1f2319dcb9 clients: change nm_meta_abstract_info_get() to report defaults
Return a boolean to indicate whether the value is the default one, so
that the caller can choose to hide it.
2018-04-13 17:02:55 +02:00
Beniamino Galvani
8b4bb725d7 clients: meta: add enum getter-only nicks
Add a new a new field to enum type descriptors that specify a list of
nicks valid only for getter functions. It is useful when the get
function must return a string different from the enum nick and that
string can't be used to set a value.
2018-04-13 17:02:55 +02:00
Thomas Haller
343c967e66 clients: make meta data subtypes of NMObjBaseInst
Yes, this wastes 4 times an unused GType instance
in the class structure.
2017-07-05 14:22:10 +02:00
Beniamino Galvani
46d2168393 clients: reorder properties of connection setting
The order matters for the 'nmcli connection show' output and for the
interactive mode of nmcli. Users should not rely on the order in both
cases, but since we have an extensive test suite for the interactive
mode, restore the order as it was in 1.8.
2017-06-22 15:01:15 +02:00
Lubomir Rintel
aedeb3cbf4 clients: add support for Bluetooth NAP type 2017-05-31 20:17:42 +02:00
Thomas Haller
c72a07a604 clients: implement wifi-sec.wep-key-type as enum property
This way, we get tab completion for the enum values, and
can reuse existing code.

This requires a pre-set-notify hook, that is invoked before
setting the property.
2017-05-23 13:37:10 +02:00
Thomas Haller
e086cf1887 clients: add value_infos for int getter
This allows to implement a pretty alias for numbers,
like "default" for 0.
2017-05-23 13:37:10 +02:00
Thomas Haller
b6d9bdcee8 clients: combine int property setters
Instead of having 3 implementations for setting an int (int, uint, int64), combine
them. Also, make them more configurable by allowing to specify min/max/base, outside
of GParamSpec.
2017-05-23 13:37:10 +02:00