Commit Graph

845 Commits

Author SHA1 Message Date
Beniamino Galvani
d868788ee4 cli: fix autocompletion for connection commands
Autocompletion doesn't work in some cases because we present a prompt
ending with ":", but compare it with the string without ":" in the
autocomplete function. Fix this.

While at it, also add missing colon after prompt where needed.
2018-08-27 15:14:01 +02:00
Beniamino Galvani
1669377110 cli: fix connection type completion on connection add
The array returned by the completion function follows a special
convention. If the first element is set, it is used as the
completion. Otherwise, the remaining entries are the possible
completions.

_meta_abstract_complete() just returned an array of matching words and
so the first element was always used as completion. Instead, we must
use rl_completion_matches() to generate the array passing a generator
function.

https://bugzilla.redhat.com/show_bug.cgi?id=1588952
2018-08-27 15:14:01 +02:00
Beniamino Galvani
9b9dce9486 all: add 'match' setting
Add a new 'match' setting containing properties to match a connection
to devices. At the moment only the interface-name property is present
and, contrary to connection.interface-name, it allows the use of
wildcards.
2018-08-11 09:41:07 +02:00
Beniamino Galvani
6a51d393b2 shared: add @allow_escaping argument to @nm_utils_strsplit_set 2018-08-11 09:41:07 +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
d70dcb16da cli: fix nmc_setting_get_valid_properties() to use setting metadata
Not all properties that we want to handle in nmcli are actual GObject
properties. For the moment that was the case, but that's about to change.

This is a change in behavior with respect of the order in which
properties are reported. For example, print_setting_description()
now prints the property descriptions in a different order. However,
one might argue that this order makes more sense because:

  - it's the same order as properties are listed in
    "nm-meta-setting-desc.c". At that place, we have explict
    control over the order and set it intentionally to suite
    our needs best. The order of the GObject properties is
    much less well defined.

  - the order from "nm-meta-setting-desc.c" is used at several other
    places. So, it makes sense to use the same order everywhere.
2018-08-10 10:38:19 +02:00
Beniamino Galvani
c955d91d4b cli: remove assertion in nmc_device_state_to_color()
nmcli should not fail when the state device state is > ACTIVATED.
Just return an unknown color code like we used to do, and like we do
for connections.

Fixes: 31aa2cfe29

https://bugzilla.gnome.org/show_bug.cgi?id=796834
2018-08-10 10:10:51 +02:00
Thomas Haller
982c74abd7 cli: remove unused argument from nm_meta_selection_create_parse_list() 2018-07-25 17:08:37 +02:00
Thomas Haller
41810aad48 cli: don't explicitly unset out_to_free argument in NMMetaType.get_nested()
The virtual function NMMetaType.get_nested() has only one caller:
nm_meta_abstract_info_get_nested(). That caller makes sure to
always pass in an @out_to_free argument, and that it is initialized
to NULL.
2018-07-25 17:08:37 +02:00
Thomas Haller
07ea00074b cli: drop local variable multiline in _print_do()
The local variable was just a copy of the (unchanging)
configuration nmc_config->multiline_output.

It is complicated enough to understand how nmc_config->print_output
and nmc_config->multiline_output affects nmc_print(). Don't use an
alias when referencing to nmc_config->multiline_output because it
hides where the value is used and where it causes a difference.
2018-07-25 17:08:37 +02:00
Thomas Haller
66e5f13307 cli: simplify tracking of parent column in PrintDataCol structure
PrintDataCol contains a reference to the parent structure, for which
it was created. Previously, that was expressed via the "parent_idx"
field, which is an index into the list of all PrintDataCol entries.

That is inconvenient. Resolve the index to the actual pointer.

Note that during _output_selection_append() we still need to use
the index instead of resolving the pointer right away. That is because
_output_selection_append() grows the GArray into which the parent_idx
pointers to. So, obtaining the real pointer at that point would result
in using a dangling pointer later on.

Introduce a new step _output_selection_complete() which converts the
index into the actual pointer.
2018-07-25 17:08:37 +02:00
Thomas Haller
ac07cbb98b cli: minor cleanup explicitly checking print_output
The print-output knows three modes: NORMAL, PRETTY, TERSE.
Never compare whether a mode is != a particular mode.

Instead, always explicitly check for the modes for which we enable a
particular behavior.

The effect is, that we always do something when the mode is set to a
particular value. We don't ever do something, if the mode is not set to
a particular value. Consistently opt-in is easier to understand.
2018-07-25 17:08:37 +02:00
Thomas Haller
8f037a11f4 cli: minor cleanup evaluating print_output
The print-output knows three modes: NORMAL, PRETTY, TERSE.
Instead of using local variables "pretty" and "terse",
check for the output mode directly.

Note how we have tree modes, so mapping them to two boolean
variables is confusing. Especially at one place where we did:
  pretty = (nmc_config->print_output != NMC_PRINT_TERSE);
while at other places:
  pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
2018-07-25 17:08:37 +02:00
Thomas Haller
e912ca7622 cli: minor cleanup in _print_data_cell_clear_text()
It wasn't entirely clear what this was doing.

Like before, free and clear the text pointers.
However, also always reset the text_format back to PLAIN.
2018-07-25 17:08:37 +02:00
Thomas Haller
9c51ebc298 cli: fix skipping columns with all default-values
The header-cell is the header for a column with possibly many
rows.

We must not set:
  header_cell->skip = nmc_config->overview && is_default;
for a particular cell, because it does not take into accound
the neighbouring rows. It is only correct, if there is only
one row.

Invert the logical meaning and rename "strip" to "to_print".
Each cell then can opt-in, whether it needs to be printed.
Only if no cell opts-in, it will be skipped.

Fixes: 9a19bbcb2f
2018-07-25 17:08:37 +02:00
Thomas Haller
e0570ae8d6 cli: don't translate device state in --terse mode 2018-07-25 17:08:37 +02:00
Thomas Haller
a75ab799e4 build: create "config-extra.h" header instead of passing directory variables via CFLAGS
1) the command line gets shorter. I frequently run `make V=1` to see
   the command line arguments for the compiler, and there is a lot
   of noise.

2) define each of these variables at one place. This makes it easy
   to verify that for all compilation units, a particular
   define has the same value. Previously that was not obvious or
   even not the case (see commit e5d1a71396
   and commit d63cf1ef2f).
   The point is to avoid redundancy.

3) not all compilation units need all defines. In fact, most modules
   would only need a few of these defines. We aimed to pass the necessary
   minium of defines to each compilation unit, but that was non-obvious
   to get right and often we set a define that wasn't used. See for example
   "src_settings_plugins_ibft_cppflags" which needlessly had "-DSYSCONFDIR".
   This question is now entirely avoided by just defining all variables in
   a header. We don't care to find the minimum, because every component
   gets anyway all defines from the header.

4) this also avoids the situation, where a module that previously did
   not use a particular define gets modified to require it. Previously,
   that would have required to identify the missing define, and add
   it to the CFLAGS of the complation unit. Since every compilation
   now includes "config-extra.h", all defines are available everywhere.

5) the fact that each define is now available in all compilation units
   could be perceived as a downside. But it isn't, because these defines
   should have a unique name and one specific value. Defining the same
   name with different values, or refer to the same value by different
   names is a bug, not a desirable feature. Since these defines should
   be unique accross the entire tree, there is no problem in providing
   them to every compilation unit.

6) the reason why we generate "config-extra.h" this way, instead of using
   AC_DEFINE() in configure.ac, is due to the particular handling of
   autoconf for directory variables. See [1].
   With meson, it would be trivial to put them into "config.h.meson".
   While that is not easy with autoconf, the "config-extra.h" workaround
   seems still preferable to me.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
2018-07-17 17:46:39 +02:00
Beniamino Galvani
a2f12994b7 cli: add support for configuring SR-IOV 2018-07-11 16:16:22 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
d7b643f66f cli/trivial: move code 2018-07-09 15:43:55 +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
Thomas Haller
918be83493 cli: rework printing of "wired" and "wifi" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
d6949a2924 cli: rework printing of "capabilities" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
2fc475ccdf cli: rework printing of "connections" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
e771153c0a cli: don't translate device details in terse mode
https://bugzilla.gnome.org/show_bug.cgi?id=794329
2018-07-09 15:43:55 +02:00
Thomas Haller
6f8f7ad597 cli: rework enum-to-string function to not return translated text
There are cases, where we need the untranslated text.

There is no change of behavior of this patch, because all
callers now explicitly call gettext().
2018-07-09 15:43:55 +02:00
Thomas Haller
fede017001 cli: rework printing of "general" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
283b1d18b7 cli: rework printing of device status 2018-07-09 15:43:55 +02:00
Thomas Haller
940979a5a6 cli: merge IPv4 and IPv6 versions of ip/dhcp config print 2018-07-09 15:43:55 +02:00
Thomas Haller
bddf482fa1 cli/trivial: move code 2018-07-09 15:43:55 +02:00
Thomas Haller
ff273b8221 cli: drop duplicate IPv6 property metadata 2018-07-09 15:43:55 +02:00
Thomas Haller
096ac93f8a cli: rework printing of dhcp options 2018-07-09 15:43:55 +02:00
Thomas Haller
59ea03cc08 cli: rework printing of vpn active-connection properties
use nmc_print() for the job.
2018-07-09 15:43:55 +02:00
Lubomir Rintel
29636535b2 client: support 6lowpan setting 2018-06-26 16:21:55 +02:00
Lubomir Rintel
5da77c0e2c client: support wpan setting 2018-06-26 16:21:55 +02:00
Thomas Haller
94ecdc0cb9 cli: rework check-colors to first evaluate enabled/disabled
With --color=auto, coloring is enabled based on the .enable/.disable
termcolors files.

Likewise, when we enable coloring, we parse the color palette from the
.schem termcolors files.

The termcolors files are searched by finding the best match depending
on the terminal and application name. Note, that if we find a matching
file like "nmcli@xterm.enable" we still allow loading the palette from
a less specific file like "nmcli.schem" and vice versa. That was already
done before.

Previously, the search was done by calling several layers of functions, and having
in/out arguments "color_option" and "p_palette_buffer". in/out paramters
here seems confusing to me, as they are state that gets modified and carried
along.

Instead, rework the functions to clearly separate between input
and output arguments.

Also, in the auto-case, check_colors() now first determines whether
coloring is enabled, before even starting loading the palette.
This avoids loading the palette until we are sure that we need it.
2018-06-26 11:32:39 +02:00
Thomas Haller
0a82ace5b0 cli: only modify color platte when parsing is successful in parse_color_scheme()
If the palette cannot be parsed successfully, it should not partially
be modifid.
2018-06-26 11:32:39 +02:00
Thomas Haller
dbc5eefedb cli: drop unused color_option argument from check_colors_file() 2018-06-26 11:32:39 +02:00
Thomas Haller
0be07d0815 cli: avoid passing NmCli to set_color() functions
The NmCli variables is essentially a global variable of *everything*.
The set_color() function and its helpers only need a particular
part of it. Instead, of passing the entire global state to them,
only pass what they need.

It makes it clearer which parts are actually relevant. Turns out,
it only actually touches a resonable small part of the global state.
2018-06-26 11:32:39 +02:00
Francesco Giudici
20a8bc9e34 cli: list the 'print' command in the welcome message of the editor
https://bugzilla.redhat.com/show_bug.cgi?id=1588995
2018-06-21 16:56:50 +02:00
Thomas Haller
56a0488bba tests: improve NetworkManager stub service for Wi-Fi scanning
Now that nmcli initiates a scan before displaying Wi-Fi networks,
the stub service must properly support that as well.

For the moment, the stub service chooses "now" as LastScan timestamp.
This causes nmcli not to trigger a new scan, because nmcli gives
unstable output if multiple nmcli processes in parallel race to
trigger a Wi-Fi scan. That should be fixed.
2018-06-18 10:56:50 +02:00
Lubomir Rintel
5269aba7b4 cli: utilize nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Lubomir Rintel
07fd0502f6 wifi: expose LastScan as milliseconds not seconds
This doesn't wrap around in 68 years of uptime and is consistent with
o.fd.NM.Checkpoint.Created.
2018-06-15 16:23:30 +02:00
Thomas Haller
4e7ae3da6e cli: fix printing multi-line output when there is nothing to print
When a property getter returns an empty/missing strv-array, in multi-line
mode we should not print any lines.

To get that right, we must mark the cell as STRV type, even if there is no value
provided.

Previously, with text_out_flags having NM_META_ACCESSOR_GET_OUT_FLAGS_STRV
and value being NULL, we would not set
  cell->text_format = PRINT_DATA_CELL_FORMAT_TYPE_STRV;
and thus, later on the value would be treated as a missing (plain)
string.
2018-06-15 11:48:16 +02:00
Thomas Haller
dba41ee1e1 cli: return NULL strv array from _ip_config_get_routes() if there are no routes
The property getter for certain properties tries to return
a strv array.

In this case, the result should be identical, whether an
empty strv array or NULL is returned.

Let _ip_config_get_routes() return %NULL if there are no routes.
This should have no practical difference, but it actually exposes
a bug in "cli/common/utils.c", which was previously hidden by
not commonly returning %NULL. This bug will be fixed in the
next commit.
2018-06-15 11:48:16 +02:00
Andrew Zaborowski
140ada3aad cli: Actually add passwords to the AddAndActivateConnection arguments
Check the wpa_flags and rsn_flags values to see if the network needs the
password added to the 802-11-wireless-security settings.  The current
ap_flags check alone would only trigger the password to be sent for WEP
networks.  Also remove unneeded initialization of the three variables.
2018-06-13 15:59:48 +02:00
Lubomir Rintel
2a7a36494a cli: drop an unused variable
clients/cli/connections.c:1909:3: error: unused variable 'out_indices' [-Werror,-Wunused-variable]
                NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
                ^
2018-06-13 15:58:20 +02:00
Lubomir Rintel
34412a8d3d cli/devices: rescan the Wi-Fi network if the AP list is not fresh enough 2018-06-13 14:48:23 +02:00
Lubomir Rintel
ca29761212 cli/devices: parse "nmcli d wifi list" arguments with next_arg()
For no reason at all.
2018-06-13 14:44:42 +02:00