Commit Graph

497 Commits

Author SHA1 Message Date
Beniamino Galvani
2d347e7e17 cli: don't wait for connection change on update failure
When saving a connection, we wait the connection-changed signal before
proceeding to ensure that the remote connection is up to date.
However, no signal is emitted if the update fails and so we shouldn't
wait for it.

Fixes: a370faeb59 ('cli: wait for changed signal after updating a connection'):

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/124
https://bugzilla.redhat.com/show_bug.cgi?id=1702203
2019-04-24 16:18:25 +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
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
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
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
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
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
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
649968632e cli: merge remove-property, reset-property and set-property
It's fundamentally wrong to have separate "remove_fcn" and "set_fcn"
implementations. Set, reset, add, and remove are all similar, and should
be implemented in a similar manner.

Merge the implementations all in set-property, which now can:

 - reset the value (value == NULL && modifier == '\0')
 - set a value     (value != NULL && modifier == '\0')
 - add a value     (value != NULL && modifier == '+')
 - remove a value  (value != NULL && modifier == '-')

The real problem is that remove_fcn() behaves fundamentally different
from set_fcn(). You can do "+setting.property value1,value2" but you
cannot remove them the same way. That is because most remove_fcn()
implementations don't expect a list of values. But it's also because of
the unnatural split between set_fcn() and remove_fcn().

The next commit will merge set_fcn(), remove_fcn() and reset property.
This commit just merges them all in nmc_setting_set_property().
2019-03-25 09:12:32 +01:00
Thomas Haller
f24ada398a cli: drop nmc_property_set_default_value()
It's wrong to pretend that all properties are GObject based. Drop
nmc_property_set_default_value() and use nmc_setting_reset_property()
instead.
2019-03-25 09:12:32 +01:00
Thomas Haller
7b5d514aef cli: implement nmc_setting_reset_property() based on nmc_setting_set_property()
"reset" is just a special case of "set". We can keep nmc_setting_reset_property() as a convenience
function, but it must be implemented based on nmc_setting_set_property().

Also, reset only used nmc_property_set_default_value(), which only works
with GObject based properties. It's wrong to assume that all properties
are GObject based. By implementing it based via nmc_setting_set_property()
we can fix this (later).
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
a6ee43d1c1 cli/wireguard: add import functionality for WireGuard
Support importing ".conf" files as `wg-quick up` supports it.

`wg-quick` parses several options under "[Interface]" and
passes the remainder to `wg setconf`.

The PreUp/PreDown/PostUp/PostDown options are of course not supported.

"Table" for the moment behaves different.

(cherry picked from commit a3a8583c31)
2019-03-07 22:22:39 +01:00
Thomas Haller
4a137f919b cli: fix completion for nmcli connection import
If we already specified "type" or "file", don't offer it for
completion again.

  $ nmcli connection import type openvpn <TAB>
  file  type

(cherry picked from commit fea0f4a5ea)
2019-03-07 22:22:39 +01:00
Thomas Haller
b521f426ab libnm,cli: add NMSettingWireGuard
For now only add the core settings, no peers' data.

To support peers and the allowed-ips of the peers is more complicated
and will be done later. It's more complicated because these are nested
lists (allowed-ips) inside a list (peers). That is quite unusual and to
conveniently support that in D-Bus API, in keyfile format, in libnm,
and nmcli, is a effort.
Also, it's further complicated by the fact that each peer has a secret (the
preshared-key). Thus we probably need secret flags for each peer, which
is a novelty as well (until now we require a fixed set of secrets per
profile that is well known).
2019-02-22 11:00:10 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Thomas Haller
65884733ec all: minor coding style fixes (space before parentheses) 2019-02-11 15:22:57 +01:00
Thomas Haller
e357d15023 Revert "cli: verify connections before sending them over to daemon"
Just calling nm_connection_verify() is not correct. We need
nm_connection_normalize() because otherwise we miss out on places
where we have common normalization steps implemented to fix a
connection. This is also what server-side is done.

Revert the patch, as it breaks CI tests.

I wonder also whether this is the right place. There are already
several places in "clients/cli/connections.c" that call verify()
and normalize(). These places should be unified so that there is
one place where we complete the connection. And it probably should be
done as a separate step before the add_new_connection()/update_connection()
calls.

This reverts commit ca58bcca0c.
2019-02-06 11:51:38 +01:00
Lubomir Rintel
ca58bcca0c cli: verify connections before sending them over to daemon
This way we generate the error messages on the client side and therefore
can localize them.
2019-02-05 10:20:30 +01:00
Thomas Haller
93c848ca03 clients: don't tread secret agent as NMSecretAgentOld
Most of the times we actually need a NMSecretAgentSimple typed pointer.
This way, need need to cast less.

But even if we would need to cast more, it's better to have pointers
point to the actual type, not merely to avoid shortcomings of C.
2019-02-05 08:27:42 +01:00
Thomas Haller
09090f2669 wifi-p2p: rename Wi-Fi P2P
After renaming the files, also rename all the content
to follow the "Wi-Fi P2P" naming scheme.
2019-02-01 17:02:57 +01:00
Benjamin Berg
42e60e327f core: Add basic P2P Wi-Fi Settings
The support is rather basic and only allows connecting to a specific
peer. However, this is actually already enough for many usecases.
2019-01-27 23:45:11 +01:00
Lubomir Rintel
def03fd7cf cli/connections: improve sort by active connections
When sorting the active connections, use the same policy as "nmcli" and
"nmcli d", not just the connection state. It looks better that way.
2018-11-21 11:46:22 +01:00
Lubomir Rintel
13d2d332dd cli: deduplicate active connections sort
Both connections and devices need to sort active connections. Make the
more sensible policy default.
2018-11-21 11:46:22 +01:00
Lubomir Rintel
522fd14251 cli/connections: export nmc_active_connection_cmp()
To be able to sensibly sort devices we want to be able to sort their
active connections. Currently it's implemented redundantly.
2018-11-21 11:46:21 +01:00
Beniamino Galvani
a370faeb59 cli: wait for changed signal after updating a connection
In editor_menu_main(), after saving a connection we wait that the
Update2() D-Bus call returns and then we copy the NMRemoteConnection
instance over to @connection.

This assumes that when Update2() returns the remote connection
instance is already updated with new settings. Indeed, on server side
the NMSettingsConnection first emits the "Updated" signal and then
returns to Update2(). However, the Updated signal doesn't include the
new setting values and so libnm has to fire an asynchronous
nmdbus_settings_connection_call_get_setting() to fetch the new
settings, which terminates after the Update2().

So, to be sure that the remote connection got updated we have also to
listen to the connection-changed signal, which is always emitted after
an update.

https://bugzilla.redhat.com/show_bug.cgi?id=1546805
2018-11-20 15:16:53 +01:00
Beniamino Galvani
096eef61d4 cli: editor: reload secrets after updating connection
Connection secrets are lost after calling
nm_connection_replace_settings_from_connection() because @con_tmp
doesn't contain secrets; refetch them like we do when starting the
editor.
2018-11-20 15:15:58 +01:00
Beniamino Galvani
2ee2305ed8 cli: fix memory leak 2018-10-22 08:43:44 +02:00
Beniamino Galvani
c0fc85f3c4 cli: check we have an active connection before showing hint
If the activation fails even before the active connection instance is
created, we get the following:

 $ nmcli connection up vpn1
 libnm-CRITICAL **: nm_active_connection_get_connection: assertion 'NM_IS_ACTIVE_CONNECTION (connection)' failed
 nmcli-CRITICAL **: active_connection_hint: assertion 'connection' failed
 Error: Connection activation failed: Not authorized to control networking.

Check that we have an active connection before showing the hint.

Fixes: bc6c042d54
2018-10-11 18:40:54 +02:00
Thomas Haller
86502bef9c cli: don't needlessly cast function pointer for rl_attempted_completion_function 2018-10-10 09:55:45 +02:00
Thomas Haller
5d684597c4 cli: don't access global nm_cli variable from nmc_setting_set_property() 2018-10-10 09:55:45 +02:00
Thomas Haller
99d3b6930b cli: don't use global variable nm_cli in nmc_terminal_spawn_pager()
print_required_fields() still accesses the global variable.
We can only move the uses of globals up the call-stack, one
bit at a time.
2018-10-10 09:55:45 +02:00
Thomas Haller
411243c654 cli: don't use global nm_cli in nmc_readline_*()
Globals are bad. Don't let nmc_readline_helper() access
nm_cli.

Instead, pass nmc_config along. nmc_config albeit being
a complex struct, is much more begning:

  - the configuration nmc_config is initialized early on
    and afterwards immutable.
  - it only contains simple fields, which affect the behavior.
  - it's not a global. While passing around the complex configuration
    struct, it is clear that all callpaths don't access additional
    global information.
2018-10-10 09:55:45 +02:00
Thomas Haller
0be65a4b78 cli: don't pass complex info argument to active_connection_hint()
Untangle the amount or agruments passed to active_connection_hint().
2018-10-10 09:55:45 +02:00
Beniamino Galvani
09d0e5590c cli: fix memory leak
activate_connection_editor_cb() must free @info and unref the device.
2018-10-09 09:58:27 +02:00
Beniamino Galvani
d091cbdc2f cli: fix cleanup after activation from editor
progress_activation_editor_cb() is called multiple times every 120
milliseconds and it must free resources only the last time.

Fixes: f0a2686545

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/51
2018-10-09 09:58:27 +02:00
Lubomir Rintel
c21b4c3d0a cli: add support for wpan.page and wpan.channel properties 2018-10-07 15:46:02 +02:00
Lubomir Rintel
bc6c042d54 cli: advise the user to consult logs when a connection fails to activate
Error: Connection activation failed: no valid VPN secrets.
  Hint: use 'journalctl -xe NM_CONNECTION=0dd048e5-e84b-4e96-9142-61b3e73f1c69 + NM_DEVICE=eth0' to get more details.
2018-10-01 10:26:05 +02:00
Thomas Haller
20a7e489ee all: pass O_CLOEXEC flag to g_mkstemp() 2018-09-21 10:39:30 +02:00
Thomas Haller
5f66700b4a cli: adjust error message about incompatible connection/device
# nmcli connection up w ifname w
  Error: device 'w' not compatible with connection 'w':The connection was not an Ethernet or PPPoE connection..
2018-09-20 16:06:42 +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
6bfab6796f cli: fix reading "vpn.secrets.*" from passwd-file
Due to a bug, we required VPN secrets to be prefixed with
"vpn.secret." instead of "vpn.secrets.". This was a change
in behavior with 1.12.0 release.

Fix it, to restore the old behavior. For backward compatibility
to the broken behavior, adjust parse_passwords() to treat accept
that as well.

https://bugzilla.redhat.com/show_bug.cgi?id=1628833
https://github.com/NetworkManager/NetworkManager/pull/201

Fixes: 0601b5d725
(cherry picked from commit 5815ae8c60)
2018-09-14 15:17:53 +02:00
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