Commit Graph

670 Commits

Author SHA1 Message Date
Lubomir Rintel
57a26fd2aa cli/connections: decide about activation success and failure in single place
Track both device and active connections at the same time and decide
whether activation finished (either successfully or not) in a single
place, check_activated().

This makes the already too complex code path a bit more straightforward
and also makes it possible to be more reasonable about the diagnostics.

Now that the active connection signals the reason, we include it; but if
the failure is due to the device disconnection while we're activating,
include a device reason instead, since it's often more useful. Like:

Before:
  Error: Connection activation failed.

Without considering the device:
  Error: Connection activation failed: the base network connection was interrupted

After:
  Error: Connection activation failed: The Wi-Fi network could not be found
2017-03-17 10:21:19 +01:00
Lubomir Rintel
81cd300108 cli/general: avoid chopping off the last letter of master device name
...when "nmcli" is called without argument and the master device is the last
entry printed.
2017-03-16 17:11:58 +01:00
Thomas Haller
22b7282d84 all: use "unsigned" instead of "unsigned int" 2017-03-14 11:26:29 +01:00
Thomas Haller
831286df30 include: use double-quotes to include our own headers
In practice, this should only matter when there are multiple
header files with the same name. That is something we try
to avoid already, by giving headers a distinct name.

When building NetworkManager itself, we clearly want to use
double-quotes for including our own headers.
But we also want to do that in our public headers. For example:

  ./a.c
    #include <stdio.h>
    #include <nm-1.h>
    void main() {
        printf ("INCLUDED %s/nm-2.h\n", SYMB);
    }

  ./1/nm-1.h
    #include <nm-2.h>

  ./1/nm-2.h
    #define SYMB "1"

  ./2/nm-2.h
    #define SYMB "2"

$ cc -I./2 -I./1 ./a.c
$ ./a.out
INCLUDED 2/nm-2.h

Exceptions to this are
  - headers in "shared/nm-utils" that include <NetworkManager.h>. These
    headers are copied into projects and hence used like headers owned by
    those projects.
  - examples/C
2017-03-09 14:12:35 +01:00
Beniamino Galvani
d094914120 cli: support route options 2017-03-06 15:20:25 +01:00
Lubomir Rintel
9cc15d39eb tui: recommit bond, bridge and team slaves on master save
The ifcfg-rh plugin may want to update its MASTER= key accordingly for
better compatibility with the legacy network service.
2017-02-27 11:17:39 +01:00
Lubomir Rintel
c8969dbf80 tui/editor: notify the pages after the connection is saved
This will make it possible for the pages to commit slave connections
when the master connection is saved.
2017-02-27 11:17:39 +01:00
Lubomir Rintel
8fce72360e tui/edit-connection-list: add routine to recommit connections in a list
This is useful when master connections are saved potentially influencing
how slave connections are serialized.
2017-02-27 11:16:45 +01:00
Beniamino Galvani
4db7890fae cli: support dummy connections 2017-02-22 21:05:04 +01:00
Beniamino Galvani
9a215d332b cli: add support for 802-1x.auth-timeout property 2017-02-21 09:18:53 +01:00
Lubomir Rintel
ff46158d9e tui: generate names for bonds, teams and bridges
This makes it more likely that the user will end up with a master
connection that has connection.interface-name property. This makes it
possible for ifcfg plugin to specify the master in the for of device
name (as opposed to UUID) for compatibility with the legacy network
tooling.

This is equivalent to what nmcli does.

https://bugzilla.redhat.com/show_bug.cgi?id=1369091
2017-02-20 16:07:43 +01:00
Beniamino Galvani
bb72409e9f cli: support 802-1x.phase1-auth-flags 2017-02-20 14:06:14 +01:00
Beniamino Galvani
27a52989e3 cli: support the cdma.mtu property 2017-02-20 09:18:25 +01:00
Beniamino Galvani
c51232f940 cli: support the gsm.mtu property 2017-02-20 09:18:25 +01:00
Lubomir Rintel
4121e57c50 cli: add support for 802.1x certificate passwords 2017-02-17 14:24:34 +01:00
Lubomir Rintel
bc6a383dd7 cli: fix match()
Fixes: 84c484ed5b
2017-02-16 10:39:08 +01:00
Lubomir Rintel
84c484ed5b cli: make match() return boolean
Coccinelle semantic patch:

  @@
  @@
  -int
  +gboolean
          matches (...);

  @@
  expression pattern, cmd, len;
  @@
  -int
  +gboolean
          matches (...)
          {
                  ...
  -               return memcmp (pattern, cmd, len);
  +               return memcmp (pattern, cmd, len) == 0;
          }

  @@
  expression prefix, str;
  @@
  (
  -matches (prefix, str) != 0
  +!matches (prefix, str)
  |
  -matches (prefix, str) == 0
  +matches (prefix, str)
  )

  @@
  expression prefix, str;
  @@
  -(matches (prefix, str))
  +matches (prefix, str)

  @@
  expression prefix, str;
  @@
  -(!matches (prefix, str))
  +!matches (prefix, str)

spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
  --include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
2017-02-15 13:04:07 +01:00
Lubomir Rintel
1d40c5f476 cli: add nmcli g logging completion
This is sort of ugly, because it includes the domain and log levels
verbatim. They're just plain strings on the API, there's no way the
client would know which ones are valid.

On the other hand this kills one of two uses of nmc_parse_args(), which
probably means it's not a very good abstraction and maybe we should get
rid of it altogether. It is in particular unfriendly to argument
completion.
2017-02-15 11:16:19 +01:00
Lubomir Rintel
8bd7bbba02 cli: add completion for "nmcli c edit" 2017-02-15 11:16:19 +01:00
Lubomir Rintel
29bb6ae4fe cli: complete the [-][-]help arguments 2017-02-15 11:16:19 +01:00
Lubomir Rintel
1a0c779214 cli: complete VPN types 2017-02-15 11:16:19 +01:00
Lubomir Rintel
9d2290135c cli: make nmcli do its own command completion
https://bugzilla.gnome.org/show_bug.cgi?id=777328
2017-02-13 16:32:15 +01:00
Beniamino Galvani
b2146a43e5 cli: fix setting of private key password
We can't pass the password obtained from
nm_setting_802_1x_get_*private_key_password() to
nm_setting_802_1x_set_*private_key() as the latter also frees the old
password.

Fixes: afd2811028
2017-02-13 15:50:21 +01:00
Thomas Haller
dc40288849 all: use NM_CACHED_QUARK_FCN() to define cached quarks 2017-02-10 14:33:52 +01:00
Thomas Haller
ec91f950b8 nm-online: fix wrong assertion failure during nm-online
_return() assigns the return value @retval and asserts that
currently no return-value is assigned -- in order not to overwrite
a once set value.

That requires, that we call _return() and exit the main-loop right
away, without possibility to call _return() again.

However, during client_properties_changed() we easily might
receive the "notify" signal multiple times, and thus call
quit_if_connected() and _return() multiple times. That would
lead to a wrong assertion failure.

Avoid that, by disconnecting the signal handler once we reach
_return().

Fixes: f7875a42b0
2017-02-07 19:42:30 +01:00
Thomas Haller
cb365b33f3 build: fix -Wold-style-declaration warnings
libnm-core/nm-setting-bond.c:502:1: error: ‘static’ is not at beginning of declaration [-Werror=old-style-declaration]
     const static struct {
     ^~~~~

    In file included from clients/cli/common.c:32:0:
    ./clients/common/nm-vpn-helpers.h:27:1: error: ‘typedef’ is not at beginning of declaration [-Werror=old-style-declaration]
     } typedef VpnPasswordName;
    ^
2017-02-06 19:27:21 +01:00
Mickaël Thomas
5216754b1e nm-online: fix countdown to not show 0 seconds until finished
When using nm-online -t N, the countdown shows "0s" during the last second.

The countdown value should be rounded up so that "0s" is only shown when the
timeout is actually elapsed.

https://bugzilla.gnome.org/show_bug.cgi?id=778093
2017-02-03 00:10:44 +01:00
Thomas Haller
f7875a42b0 nm-online: refactor and fix nm-online
Moving nm-online to async init introduced various issues:
- with a timeout of zero, nm-online would terminate with failure
  before initializing the NMClient instance.
- add a timeout for safeguarding the async creation of NMClient
- fix adding trailing newline for the progress bar.

While at it, refactor:
- use defines for the exit codes
- don't use exit(), but instead always properly quit the mainloop
  and cleanup all resources.
- in non-quiet mode, print the result [online] or [offline] at
  the end.

Fixes: c5f17a97ea

https://bugzilla.gnome.org/show_bug.cgi?id=777914
2017-02-02 11:23:14 +01:00
Thomas Haller
34acecf544 nm-online: fix division-by-zero with zero timeout
$ nm-online -t 0
  Floating point exception (core dumped)

Fixes: c5f17a97ea

https://bugzilla.gnome.org/show_bug.cgi?id=777914
2017-01-31 00:12:48 +01:00
Lubomir Rintel
7399cf3b16 cli: add missing NULL-check
Only the connection down operation is cancellable, the other actions are not.

Fixes: 73b560c215
2017-01-29 12:56:31 +01:00
James McCoy
dbd365c3f9 nm-online: return from quit_if_connected after setting retval
c5f17a97ea changed nm-online to determine
the status asynchronously, however this introduced a regression with
"nm-online -x -q" when there is connectivity.

        if (   state == NM_STATE_CONNECTED_LOCAL
            || state == NM_STATE_CONNECTED_SITE
            || state == NM_STATE_CONNECTED_GLOBAL) {
            data->retval = 0;
            g_main_loop_quit (data->loop);
        }
    }
    if (data->exit_no_nm && (state != NM_STATE_CONNECTING)) {
        data->retval = 1;
        g_main_loop_quit (data->loop);
    }

After setting data->retval = 0 in the "state is connected" branch, the
function falls through to the "exit_no_nm and !connecting" branch,
overwriting data->retval.  This causes "nm-online -x -q" to incorrectly
report an offline state.

Adding an explicit "return;" after any state where data->retval is set
ensures that the value isn't overwritten before main() uses it.

Fixes: c5f17a97ea

https://mail.gnome.org/archives/networkmanager-list/2017-January/msg00058.html
2017-01-28 10:54:04 +01:00
Lubomir Rintel
73b560c215 cli: avoid use-after free on connection deletion
If the connection spontaneously disappears (perhaps along with the whole
daemon on crash) while we're deleting it, then the removal callback
would free up the context structure the delete operation is using.

Let's cancel the in-flight delete operations so that they won't touch
the structure after it's gone.
2017-01-27 13:33:28 +01:00
Jiří Klimeš
283758dab3 cli: fix some TAB completions for nmcli -a con add
(cherry picked from commit 1cee85f556)
2017-01-21 21:32:31 +01:00
Jiří Klimeš
e29add5f81 cli: move code around to group related functions - no functional change
* all getter/setter/describe, ... functions grouped according to properties
* sort the settings groups alphabetically

(cherry picked from commit 418733f2c1)
2017-01-21 19:56:40 +01:00
Jiří Klimeš
1298a998a1 cli: simplify property functions for allowed values with a macro
DEFINE_ALLOWED_FOR_ENUMS

(cherry picked from commit 5f90f48467)
2017-01-21 19:56:35 +01:00
Jiří Klimeš
49702826b7 cli: TAB-completion for macsec.mode in interactive editor
(cherry picked from commit 6573c2d860)
2017-01-21 19:56:29 +01:00
Jiří Klimeš
344e48da75 cli: TAB-completion for ipv6.addr-gen-mode in interactive editor
(cherry picked from commit 4d8800c876)
2017-01-21 19:56:23 +01:00
Jiří Klimeš
6397ce1fac cli: enable TAB-completion for proxy properties in interactive editor 2017-01-17 14:27:31 +01:00
Beniamino Galvani
d197c0626a cli: macsec support 2017-01-16 17:47:10 +01:00
Lubomir Rintel
b4a31174ea cli: add support for pkcs11: URI scheme on relevant properties 2017-01-06 15:56:11 +01:00
Lubomir Rintel
d5a1a09567 cli: support printing the pkcs11: URI scheme 2017-01-06 15:56:11 +01:00
Lubomir Rintel
afd2811028 cli: do not require a password when setting a PK
It results in a rather confusing behavior:

  # nmcli c modify wifi \
     802-1x.private-key /etc/pki/themostsecret.key \
     802-1x.private-key-password verystrong
  Error: failed to modify 802-1x.private-key: private key
  password not provided.

Moreover, the user might have a good reason for not specifying it on a command
liue and it's not strictly required anyway -- we'll do fine if we don't verify
a private key at addition time.
2017-01-06 15:14:46 +01:00
Lubomir Rintel
260563a7d9 all: use nm_utils_is_valid_iface_name() 2017-01-06 15:11:56 +01:00
Lubomir Rintel
c5f17a97ea nm-online: obtain NMClient asynchronously
Before:

  $ time nm-online
  real	0m0.438s
  user	0m0.192s
  sys	0m0.023s

After:

  $ time ./clients/nm-online
  real	0m0.096s
  user	0m0.060s
  sys	0m0.010s
2017-01-04 06:39:07 +01:00
Jiří Klimeš
9a1a03b08c cli: (trivial) fix a typo 2016-12-15 15:31:51 +01:00
Jiří Klimeš
f9648e39dd cli: enable TAB-completion for connection.lldp in interactive editor 2016-12-15 15:05:55 +01:00
Jiří Klimeš
8008770192 cli: enable TAB-completion for connection.metered in interactive editor 2016-12-15 15:05:55 +01:00
Jiří Klimeš
58a328aafc cli: add SLAVE field for 'nmcli con show' output
It helps listing or searching for slave connections. For example, one can do
$ nmcli -f name,uuid,type,slave connection show | awk '$NF == "bridge"'
to show all bridge slave connections.
2016-12-15 15:03:41 +01:00
Beniamino Galvani
6f3569a58a cli: remove duplicate duplicate check on nmc->complete
Fixes: a3b61303f8
2016-12-14 10:12:18 +01:00
Beniamino Galvani
20bf5ce359 cli: add DNS information to overview output
Example:

   $ nmcli
   [...]
   DNS configuration:
   	servers: 10.0.0.1
   	domains: foobar.com
   	interface: tun0
   	type: vpn

   	servers: 192.168.10.1
   	domains: home
   	interface: ens3

   	servers: fd01🔡:21
   	interface: ens3
2016-12-12 22:06:24 +01:00