Commit Graph

405 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
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
982c74abd7 cli: remove unused argument from nm_meta_selection_create_parse_list() 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
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
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
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
940979a5a6 cli: merge IPv4 and IPv6 versions of ip/dhcp config print 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
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
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
d52573d125 cli: allow specifying the connection by its filename
This is handy for users who configure NetworkManager by dropping files
into /etc.
2018-06-11 15:09:42 +02:00
Lubomir Rintel
386129d92b cli: add connection FILENAME field
This allows the user to look up the file where the connection is stored.
Useful especially for ifcfg users.

Not shown by default.
2018-06-11 15:09:30 +02:00
Lubomir Rintel
e7d70561aa cli: spawn pager on "nmcli c" and "nmcli g permsisions"
There's a couple of places where compose the output using nmc_print().
However, most of them (such as connectivity status or logging level) are
mostly one-line outputs where pager wouldn't make sense. These two stand
out.
2018-06-11 10:28:50 +02:00
Beniamino Galvani
92ebd16cee cli: fix array out-of-bounds access on command timeout
Fixes: 4b3297271e

https://bugzilla.redhat.com/show_bug.cgi?id=1573839
2018-06-05 14:49:24 +02:00
Beniamino Galvani
0aa2d252bf cli: fix active connections color
Fixes: a1b25a47b0
2018-06-01 18:10:03 +02:00
Thomas Haller
5d716defc1 cli/trivial: move code 2018-06-01 16:03:23 +02:00
Thomas Haller
68fa68b3ed cli: rework printing of general active-connection properties
use nmc_print() for the job.

Also, localize non-terse output.

Also, fix bug with

  $ nmcli c s /org/freedesktop/NetworkManager/ActiveConnection/1

if active connection #1 is invisible to the user.

Also, previously, fill_output_active_connection() wrongly tries to
write to a field that doesn't exist:

  set_val_strc (arr, 13-idx_start, s_con ? nm_setting_connection_get_slave_type (s_con) : NULL);
2018-06-01 16:03:23 +02:00
Thomas Haller
b990cee00c cli: sort active-connection for nmcli connection show $PROFILE output
There might be multiple active connections. Output them in a defined order.
2018-06-01 16:03:23 +02:00
Thomas Haller
a1b25a47b0 cli: rework printing of nmcli connection for multiple active connections
The output of `nmcli connection show` contains also information about
whether the profile is currently active, for example the device and
the current (activation) state.

Even when a profile can be activated only once (without supporting
mutiple activations at the same time), there are moments when a
connection is activating and still deactivating on another device.
NetworkManager ensures in the case with single activations that
a profile cannot be in state "activated" multiple times. But that
doesn't mean, that one profile cannot have multiple active connection
which reference it. That was already handled wrongly before, because
`nmcli connection show` would only search the first matching
active-connection. That is, it would arbitrarily pick an active
connection in case there were multiple and only show activation
state about one.
Furthermore, we will soon also add the possibility, that a profile can be
active multiple times (at the same time). Especially then, we need to
extend the output format to show all the devices on which the profile is
currently active.

Rework printing the connection list to use nmc_print(), and fix various
issues.

- as discussed, a profile may have multiple active connections at each time.
  There are only two possibilities: if a profile is active multiple
  times, show a line for each activation, or otherwise, show the
  information about multiple activations combined in one line, e.g. by
  printing "DEVICE eth0,eth1". This patch, does the former.
  We will now print a line for each active connection, to show
  all the devices and activation states in multiple lines.
  Yes, this may result in the same profile being printed multiple times.
  That is a change in behavior, and inconvenient if you do something
  like

     for UUID in $(nmcli connection show | awk '{print$2}'); do ...

  However, above is anyway wrong because it assumes that there are no
  spaces in the connection name. The proper way to do this is like

     for UUID in $(nmcli -g UUID connection show); do ...

  In the latter case, whenever a user selects a subset of fields
  (--fields, --get) which don't print information about active connections,
  these multiple lines are combined. So, above still works as expected,
  never returning duplicate UUIDs.

- if a user has no permissions to see a connection, we previously
  would print "<invisible> $NAME". No longer do this but just print
  the ID was it is reported by the active-connection. If the goal
  of this was to prevent users from accidentally access the non-existing
  connection by $NAME, then this was a bad solution, because a script
  would instead try to access "<invisible> $NAME". This is now solved
  better by hiding the active connection if the user selects "-g NAME".

- the --order option now sorts according to how the fields are shown.
  For example, with --terse mode, it will evaluate type "802-11-wireless"
  but with pretty mode it will consider "wifi". This may change the
  ordering in which connections are shown. Also, for sorting the name,
  we use g_utf8_collate() because it's unicode.
2018-06-01 16:03:23 +02:00
Thomas Haller
0cba6bf1d2 cli/trivial: move code
These helper function will be needed in the next commit to be earlier.
Helper functions like these, that operate solely on trival types (in
this case, converting an enum to a string), make generally sense to have
at the beginning of the source file. Because they themself have few/no
dependencies and are rather trivial and self contained.
2018-05-14 17:53:03 +02:00
Thomas Haller
4b3297271e cli: rework connection handling for multiple results
Functions like nmc_find_connection() and nmc_find_active_connection()
can easily find multiple matching results. For example, the
"connection.id" in NetworkManager is not enforced to be unique,
so if the user adds multiple connections with the same name,
they should be all selected.

The previous API had a @pos argument, that allowed to iterate over
the results. Change that, to return all matches in a GPtrArray.

Also, extend connection-show and other places, to anticipate that
a connection might be active multiple times in any moment.
2018-05-14 17:53:03 +02:00
Thomas Haller
4029d4df0c cli: rework converting enums to strings in "connections.c"
Also, let the enum2str function return a non-translated string.
The user may choose to call gettext() on it.
2018-05-14 17:53:03 +02:00
Thomas Haller
5e34a4b424 cli: move find_active_connection() to common.c
Beside nmc_find_connection(), which is very similar.

Also, drop unused argument @cons.
2018-05-14 17:53:03 +02:00
Thomas Haller
f0a2686545 cli: cleanup code paths in "connections.c" 2018-05-14 17:53:03 +02:00
Lubomir Rintel
bcc9e58bfe cli: allow setting the colors with terminal-colors.d(5)
The present version of the specification is somewhat unclear at times,
Unclear points were discussed with the maintainers [1] and probably
some new version will address those.

https://www.spinics.net/lists/util-linux-ng/msg15222.html

Until then here's how the implementation copes with ambiguities
(after the discussion with util-linux maintainers):

1.) It is unclear whether multiple .schem files should override each
    other or be merged. We use the overriding behavior -- take the
    highest priority one and ignore the rest.

2.) We assume "name.schem" is more specific than "@term.schem".

3.) We assume the "Color name" are to be used as aliases for the color
    sequences and translate them to ANSI escape sequences.

4.) The "Escape sequences" are of no use since the specification
    pretty much assumes an ANSI terminal and none of the sequences make
    any sense in ANSI color codes. We don't support them.
    accept that.

5.) We don't implement TERMINAL_COLORS_DEBUG because it's unspecified
    what should it do.
2018-05-10 14:36:58 +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
Lubomir Rintel
9dfe825840 cli: rework enabling and disabling colors
This actually makes very little difference at the moment, but will make
things more confortable later on, when the logic of enabling/disabling
coloring will involve terminal-colors.d(5).

Instead of deciding whether to use colors lazily with use_colors(), it's
done very early on nmcli initialization and a boolean use_colors field
is stored in the NmcConfig instance instead of the raw tristate option
of NmcColorOption type (which is now confined to nmcli.c).

Wherever the NmcColorOption was used previously, the whole NmcConfig
instance is passed around. That might seem pointless (since only the
use_colors boolean is actually used at the moment), but will be utilized
to pass around the actual color palette in future.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
56a5b27389 cli: drop --prompt-color
It's undocumented, useless, somewhat expensive in volume of code and
probably just downright stupid. We'll get a more general way to set
colors.

Hacking in some code to keep this working wouldn't be too difficult, but
it seems entirely pointless.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
f0c1efbf42 all: add and utilize nm_utils_is_separator()
It is meant to be rather similar in nature to isblank() or
g_ascii_isspace().

Sadly, isblank() is locale dependent while g_ascii_isspace() also considers
vertical whitespace as a space. That's no good for configuration files that
are strucutured into lines, which happens to be a pretty common case.
2018-05-10 14:35:52 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller
5e69b8b9f1 cli: merge IPv4 and IPv6 variants of print_dhcp_config() 2018-04-23 15:43:39 +02:00
Beniamino Galvani
e27963d17f cli: fix connections completion
Let the matching continue when we are autocompleting arguments and we
have already found 'id', 'uuid' or 'path'.

Before:

 # nmcli connection modify path<TAB>
 path

After:
 # nmcli connection modify path<TAB>
 path
 pathfinder-wifi
2018-02-13 16:09:16 +01:00
Lubomir Rintel
9bf0b32cd1 cli/connections: avoid using synchronous get_secrets()
With --ask it might call back to nmcli's agent, causing a deadlock
while the client is waiting for the response. Let's give the client
a chance to service the agent requests while waiting:

  $ nmcli --ask --show-secrets c show 'Oracle HQ'
  <hang>

This is probably still rather suboptimal and inefficient, since we
still serialize the calls and block on response. However, if we submit
multiple calls to GetSecrets, the daemon would start authorizing the
first one and fail the other ones immediately before the authorization
succeeds.

This could perhaps be addressed in the daemon, but let's settle for a
fix that's compatible with the current daemon for now.
2018-02-13 15:03:49 +01:00
Thomas Haller
e4839accf5 all: replace non-leading tabs with spaces
We commonly only allow tabs at the beginning of a line, not
afterwards. The reason for this style is so that the code
looks formated right with tabstop=4 and tabstop=8.
2018-02-07 13:32:04 +01:00
Lubomir Rintel
6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Beniamino Galvani
54c0572de3 cli: fix editor crash
Ensure @cmd_arg0 is not freed when returning it.

Fixes: 8869943594
2017-12-15 10:08:06 +01:00
Thomas Haller
5d3736ac65 cli: drop nmc_strsplit_set()
In most cases, it copies the entire strv needlessly.
We can do better.

Also, the max_tokens argument is handled wrongly (albeit
not used anywhere anymore).
2017-12-12 15:19:43 +01:00
Thomas Haller
8869943594 cli: refactor splitting of first command line argument
nmc_strsplit_set() handles max_token wrong. It cannot call
g_strsplit_set() with max_token first, and then split empty
words. You cannot use g_strsplit_set() to achieve what
nmc_strsplit_set() wants to do, unless you first split all
tokens, then them construct them together again -- thereby
loosing the delimiters.

Anyway, there are just a few caller that do essentially the same.

Refactor the code to not use nmc_strsplit_set().
2017-12-12 15:19:43 +01:00
Lubomir Rintel
92f8f30d47 clients: add tc qdisc support
What works:

  nmcli c add con-name dum0 ifname dum0 type dummy \
      tc.qdiscs 'ingress, root pfifo_fast'
  nmcli c modify dum0 -tc.qdiscs 'root pfifo_fast'
  nmcli c modify dum0 +tc.qdiscs 'root handle 666: fq_codel'
2017-12-11 10:52:23 +01:00
Beniamino Galvani
21cfeff777 cli: exit from main loop after 'quit' editor command
When we stop processing the editor command loop (after a 'quit'
command) we must quit the GLib main loop.

https://bugzilla.redhat.com/show_bug.cgi?id=1517401
2017-11-29 11:05:04 +01:00