Commit graph

127 commits

Author SHA1 Message Date
Lubomir Rintel
d3d1cd2b3e nmcli: move an assignment down to where the value needed
It's happier there. No change in behavior.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1317
2022-07-29 13:07:38 +02:00
Lubomir Rintel
a3ce5aa50e nmcli: do not assume active connection has a settings connection
The reproducer for another problem tripped an assertion failure:

  $ nmcli con del act-conn
  Connection 'act-conn' (...) successfully deleted.
  $ nmcli con down another-conn

  (process:94552): nm-CRITICAL **: 17:07:21.170: ((src/libnm-client-impl/nm-remote-connection.c:593)): assertion '<dropped>' failed
  Connection 'another-conn' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
  $

What happens is that the second invocation, when resolving the
connection name into a NMRemoteConnection object, assumes an active
connection has a settings connection.

This assumption is likely to be wrong immediately after deleting a
connection was active, before giving the active connection enough time
to fully deactivate.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1317
2022-07-29 13:07:34 +02:00
Christian Glombek
f00e747beb
libnm-client: Add public nm_conn_wireguard_import() func
This commit moves the `nm_vpn_wireguard_import()` function
implementation from `libnmc-base` to `libnm-client-impl`, renaming it to
`nm_conn_wireguard_import()`.

A new `nm_conn_utils` header file is added in `libnm-client-public`.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1031

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1299
2022-07-21 14:53:26 +02:00
Thomas Haller
d8a4b3bec2
all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update gitlab-ci to f36 2022-07-06 11:06:53 +02:00
Thomas Haller
9bfe690ab7
libnm/docs: expand documentation for wireguard.ip4-auto-default-route 2022-06-30 21:30:49 +02:00
Thomas Haller
e6a33c04eb
all: make "ipv6.addr-gen-mode" configurable by global default
It can be useful to choose a different "ipv6.addr-gen-mode". And it can be
useful to override the default for a set of profiles.

For example, in cloud or in a data center, stable-privacy might not be
the best choice. Add a mechanism to override the default via global defaults
in NetworkManager.conf:

  # /etc/NetworkManager/conf.d/90-ipv6-addr-gen-mode-override.conf
  [connection-90-ipv6-addr-gen-mode-override]
  match-device=type:ethernet
  ipv6.addr-gen-mode=0

"ipv6.addr-gen-mode" is a special property, because its default depends on
the component that configures the profile.

- when read from disk (keyfile and ifcfg-rh), a missing addr-gen-mode
  key means to default to "eui64".
- when configured via D-Bus, a missing addr-gen-mode property means to
  default to "stable-privacy".
- libnm's ip6-config::addr-gen-mode property defaults to
  "stable-privacy".
- when some tool creates a profile, they either can explicitly
  set the mode, or they get the default of the underlying mechanisms
  above.

  - nm-initrd-generator explicitly sets "eui64" for profiles it creates.
  - nmcli doesn' explicitly set it, but inherits the default form
    libnm's ip6-config::addr-gen-mode.
  - when NM creates a auto-default-connection for ethernet ("Wired connection 1"),
    it inherits the default from libnm's ip6-config::addr-gen-mode.

Global connection defaults only take effect when the per-profile
value is set to a special default/unset value. To account for the
different cases above, we add two such special values: "default" and
"default-or-eui64". That's something we didn't do before, but it seams
useful and easy to understand.

Also, this neatly expresses the current behaviors we already have. E.g.
if you don't specify the "addr-gen-mode" in a keyfile, "default-or-eui64"
is a pretty clear thing.

Note that usually we cannot change default values, in particular not for
libnm's properties. That is because we don't serialize the default
values to D-Bus/keyfile, so if we change the default, we change
behavior. Here we change from "stable-privacy" to "default" and
from "eui64" to "default-or-eui64". That means, the user only experiences
a change in behavior, if they have a ".conf" file that overrides the default.

https://bugzilla.redhat.com/show_bug.cgi?id=1743161
https://bugzilla.redhat.com/show_bug.cgi?id=2082682

See-also: https://github.com/coreos/fedora-coreos-tracker/issues/907

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1213
2022-06-29 07:38:48 +02:00
Lubomir Rintel
cd2945f223 nmcli/connections: fix setting ifname with "--ask c add"
We almost always do the wrong thing in interactive add:

The software devices generally require an interactive name, but we don't
insist of asking for them; treating them as optional:

  $ nmcli -a c add type dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]

For some interface types (bridges, bonds, ...) we make up a name, presumably
for historical reasons. But we don't give the user an option to modify
them:

  $ nmcli -a c add type bridge
  <not asking for interface name at all>
  There are 9 optional settings for Bridge device.
  Do you want to provide them? (yes/no) [yes]

This fixes the above use cases -- still set the default, but be sure to
ask:

  $ nmcli -a c add type dummy
  Interface name:

  $ nmcli -a c add type bridge
  Interface name [nm-bridge1]:

Beautiful.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
647e255362 nmcli/connections: make sure the connection has a base setting
Do the same bookkeeping as would happen upon setting the "type" option
when the connection has a connection.type set upon its addition.

Otherwise the --ask mode is sad:

  $ nmcli --ask c add connection.type team
  ** nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Bail out! nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Aborted (core dumped)
2022-06-24 00:30:04 +02:00
Lubomir Rintel
e3fa6dfd7f nmcli/connections: factor out code run after new connection's type is set
After the connection's type is set, some bookkeeping is necessary for
the interactive (--ask) mode: appropriate setting need to be added and
options enabled.

Currently it happens in an option setter; which runs when the "type"
options is present on the command line, or the value is set in a
response to interactive mode:

  $ nmcli --ask c add type team

  $ nmcli --ask c add
  Connection type: team

But not when the property is set directly:

  $ nmcli --ask c add connection.type team
  ** nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Bail out! nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Aborted (core dumped)

This doesn't fix the issue -- a followup commit (hopefully) will.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
b171dcec0d nmcli/connections: use the current value in default in ask_option()
For new connections, this ensures the value in square brackets on
interactive add are always correct.

Apart from that, this allows us to initialize some non-default values
before asking (such as making up an interface name for some software
devices), and inform the user about what we picked:

  Interface name [nm-bridge]:
2022-06-24 00:30:04 +02:00
Lubomir Rintel
ad7ac866db nmcli/connections: don't ask to ask with --ask
This is slightly annoying:

  $ nmcli -a c add type ethernet
  There is 1 optional setting for General settings.

No point in asking if there's just one option. Just ask right away:

  $ nmcli -a c add type ethernet
  Interface name:
2022-06-24 00:30:04 +02:00
Lubomir Rintel
69e65a9b0e nmcli/connections: make sure the connection has a type
We use it before we validate the connection, thus need to check if it's
actually there.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
cf62f0e3a1 nmcli/connections: make enable_options() always enable an option 2022-06-24 00:30:04 +02:00
Lubomir Rintel
6fee8aa454 nmcli/connections: make opts argument to enable_options() optional
This makes things slightly less annoying when dealing with options that
map nicely to properties (unlike bridge options).
2022-06-24 00:30:04 +02:00
Lubomir Rintel
a5e099d008 nmcli/connections: allow empty lists with "--ask c add"
The interactive add is not too enthusiastic about not providing a value
in a list.

That is before on getting an empty line in ask_option() we take a
shortcut instead of dispatching to set_option(). That way we skip
setting the PROPERTY_INF_FLAG_DISABLED flag, causing the option to
be included in questionnaire_one_optional()'s info list.

There's no reason to avoid calling set_option() if we don't get a value;
set_option() handles NULL value just fine.

  $ nmcli -a c add
  Connection type: dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]
  Interface name [*]: lala
  There are 2 optional settings for IPv4 protocol.
  Do you want to provide them? (yes/no) [yes]
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  ...
2022-06-24 00:30:04 +02:00
Lubomir Rintel
d51140d2ab nmcli/connections: do not remove a bond option unless reset is allowed
If we're setting an option with no value given and no reset allowed,
let's just set the default value.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
0cb971d1d6 nmcli/connections: pass allow_reset to check_and_set() callback
Like the regular set_option() handler, the special ones also need to
know whether to reset an option or keep the value.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
0e2ddfd071 nmcli/devices: fix a crash
This is not good:

  $ nmcli device delete nm-bond
  Segmentation fault (core dumped)

Fixes: 5f9d2927ed ("nmcli/devices: use GPtrArray from get_device_list() directly")
2022-06-23 15:12:19 +02:00
Lubomir Rintel
9f9c82f39b merge: branch 'lr/nmcli-checkpoint'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1207
2022-06-23 11:49:48 +02:00
Thomas Haller
3ee61f0913
libnm/docs: add comment about background scanning to wifi.bssid property 2022-06-21 10:36:05 +02:00
David Bauer
02e35f5b20
nmcli: distinguish OWE-TM from OWE BSS
Distinguish a OWE-TM enabled BSS (which itself is unencrypted) from the
OWE BSS actually employing encryption.

Signed-off-by: David Bauer <mail@david-bauer.net>
2022-06-17 19:50:40 +02:00
Thomas Haller
612528af89
libnm/docs: elaborate how ipv4.dns-search/ipv6.dns-search works 2022-06-17 19:32:41 +02:00
Thomas Haller
7cfa8a01cd
cli: reformat file to look better
Comments on the same line as field names are not rendered well by clang-format.
Even if manually edited, it seems not a preferable way to comment on a field.
Move the comment in the line before.
2022-06-16 11:02:20 +02:00
Fernando Fernandez Mancera
87eb61c864 libnm: support wait-activation-delay property
The property wait-activation-delay will delay the activation of an
interface the specified amount of milliseconds. Please notice that it
could be delayed some milliseconds more due to other events in
NetworkManager.

This could be used in multiple scenarios where the user needs to define
an arbitrary delay e.g LACP bond configure where the LACP negotiation
takes a few seconds and traffic is not allowed, so they would like to
use nm-online and a setting configured with this new property to wait
some seconds. Therefore, when nm-online is finished, LACP bond should be
ready to receive traffic.

The delay will happen right before the device is ready to be activated.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1248

https://bugzilla.redhat.com/show_bug.cgi?id=2008337
2022-06-16 02:14:21 +02:00
Lubomir Rintel
1c17e55627 nmcli/devices: add "checkpoint" command
This is an interface to the Checkpoint/Restore functionality that's
available for quite some time. It runs a command with a checkpoint taken
and rolls back unless success is confirmed before the checkpoint times
out:

  $ nmcli dev checkpoint eth0 -- nmcli dev dis eth0
  Device 'eth0' successfully disconnected.
  Type "Yes" to commit the changes: No
  Checkpoint was removed.

The details about how it's used are documented in nmcli(1) and
nmcli-examples(7).
2022-06-15 12:26:08 +02:00
Lubomir Rintel
47eaf963e3 nmcli: be less insistant on exiting when readline() gets no input
When the input ends, we indeed eventually want to shut down.

Nevertheless, it might be that we terminated the input *because* we're
already shutting down and want do do our cleanup. Let's not take the
shortcut to nmc_exit() in case the main loop is no longer running.

This doesn't affect existing uses of nmc_readline(), but will be useful
in a future patch.
2022-06-15 12:13:26 +02:00
Lubomir Rintel
5f9d2927ed nmcli/devices: use GPtrArray from get_device_list() directly
This makes get_device_list() return an array of NMDevices with a
reference taken and a destroy notifier that unhooks disconnect_state_cb,
so that it could replace the GSList of the same utility used by
disconnect/delete commands.

Suggested-by: Thomas Haller <thaller@redhat.com>
2022-06-15 12:13:26 +02:00
Lubomir Rintel
2074b28976 nmcli/devices: return GPtrArray instead of GSList from get_device_list()
A pointer array is slightly more efficient here, since we don't really
need the ability to insert elements in the middle. In fact, we'd prefer
if we could just add to the end, so that we'd spare some callers from a
need to do a g_slist_reverse().

Even though that alone being a good reason to use a GPtrArray instead of
GSList, I'm doing this for so that I could actually use the returned value
as-is in a call to nm_client_checkpoint_create() in a future patch.
2022-06-15 12:13:26 +02:00
Lubomir Rintel
767afeffd8 nmcli/devices: make get_device_list() terminate on "--"
Don't consider "--" a device name. Instead, treat it as a signal to stop
reading the device list.

If a caller expects nothing beyond the device names, it now has to
check.
2022-06-15 12:13:26 +02:00
Lubomir Rintel
d576f4df44 nmcli/devices: make get_device_list() shift argc/argv
Prior to this patch, get_device_list() would give the caller no clue
about how many options did it consume. That is okay -- it would always
process all argument until the end, so the no callers would really care.

In a further patch, I'd like to allow termination of the device name
list (with a "--" arguments), so it will be possible to specify further
arguments.

Let's change the protype of this routine to use pointers to argc/argv,
that it will be possible to adjust them.
2022-06-15 12:13:26 +02:00
Ryosuke YASUOKA
7d499c4da6
nmcli: add nmcli gen reload usage
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1257

Signed-off-by: Ryosuke Yasuoka <yasuoka0830@gmail.com>
2022-06-15 08:16:33 +02:00
Alex Henrie
0004a408ae
device: introduce ipv6.mtu property
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1003

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1231
2022-05-27 08:51:44 +02:00
Adrian Freihofer
cbde63a493
settings: add ipv4.link-local flag
Introduction of a new setting ipv4.link-local, which enables
link-local IP addresses concurrently with other IP address assignment
implementations such as dhcp or manually.
No way is implemented to obtain a link-local address as a fallback when
dhcp does not respond (as dhcpd does, for example). This could be be
added later.

To maintain backward compatibility with ipv4.method ipv4.link-local has
lower priority than ipv4.method. This results in:
* method=link-local overrules link-local=disabled
* method=disabled overrules link-local=enabled

Furthermore, link-local=auto means that method defines whether
link-local is enabled or disabled:
* method=link-local --> link-local=enabled
* else --> link-local=disabled

The upside is, that this implementation requires no normalization.
Normalization is confusing to implement, because to get it really
right, we probably should support normalizing link-local based on
method, but also vice versa. And since the method affects how other
properties validate/normalize, it's hard to normalize that one, so that
the result makes sense. Normalization is also often not great to the
user, because it basically means to modify the profile based on other
settings.

The downside is that the auto flag becomes API and exists because
we need backward compatibility with ipv4.method.
We would never add this flag, if we would redesign "ipv4.method"
(by replacing by per-method-specific settings).

Defining a default setting for ipv4.link-local in the global
configuration is also supported.
The default setting for the new property can be "default", since old
users upgrading to a new version that supports ipv4.link-local will not
have configured the global default in NetworkManager.conf. Therefore,
they will always use the expected "auto" default unless they change
their configuration.

Co-Authored-By: Thomas Haller <thaller@redhat.com>
2022-05-27 08:24:28 +02:00
Thomas Haller
a5a4aea2e6
wifi: support "802-1x.phase1-auth-flags=tls-allow-unsafe-renegotiation" flag
For details, read the linked sources.

This requires a new supplicant option, but it seems that supplicant
will silently ignore unrecognized options.

https://bugzilla.redhat.com/show_bug.cgi?id=2072070#c48
https://lists.infradead.org/pipermail/hostap/2022-May/040522.html
https://w1.fi/cgit/hostap/commit/?id=566ce69a8d0e64093309cbde80235aa522fbf84e

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1218
2022-05-16 12:09:11 +02:00
Thomas Haller
7062de9219
build/meson: use "rename" directive for installing nmcli bash completion
Otherwise, `ninja -C build uninstall` tries to delete "nmcli-completion",
when the file got renamed to "nmcli".

We depend on meson 0.47.2 already.
2022-05-13 16:15:18 +02:00
Lubomir Rintel
3d82380e4d nmcli/devices: fix sorting of APs
Sort WEP access points as intended -- down, not up.

Fixes: 550e3bbdd8 ('cli: device: color WEP APs differently in "wifi list"')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1224
2022-05-12 14:37:29 +02:00
Lubomir Rintel
bf9a11f7c7 nmcli/devices: check connection created with "wifi connect"
We want to warn the user if they're connecting to an insecure network:

  $ nmcli d wifi
  IN-USE  BSSID              SSID             MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
          BA:00:6A:3C:C2:09  Secured Network  Infra  2     54 Mbit/s  100     ▂▄▆█  WPA3
          FA:7C:46:CC:9F:BE  Ye Olde Wlan     Infra  1     54 Mbit/s  100     ▂▄▆█  WEP
  $ nmcli d wifi connect 'Ye Olde Wlan'
  Warning: WEP encryption is known to be insecure.
  ...

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1224
2022-05-12 14:37:25 +02:00
Lubomir Rintel
2dbbea3f10 nmcli/connections: export nmc_connection_check_deprecated()
It's going to be useful with "nmcli dev wifi connect" that also creates
a connection that should be checked.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1224
2022-05-12 14:37:18 +02:00
Thomas Haller
3d6b6aa317
core: change the priority order in static "ipv6.addresses"
The order of addresses matters. For "ipv4.addresses", the list
contains the primary address first. For "ipv6.addresses", the
order was reverted. This was also documented behavior.

The previous patch just changed behavior with respect to relative order
of static IPv6 addresses and autoconf6/DHCPv6. As we seem in the mood
for changing behavior, here is another one.

Now the addresses are interpreted in an order consistent with IPv4 and
how one might expect: preferred addresses first.
2022-04-27 15:50:55 +02:00
Lubomir Rintel
6fa1323ce5 nmcli: add --offline option for "add" and "modify"
This adds a global "--offline" option and allows its use with "add" and
"modify" commands. The "add" looks like this:

  $ nmcli --offline conn add type ethernet ens3 ipv4.dns 192.168.1.1 \
      >output.nmconnection

The "modify" is essentially implementing what's been suggested by
Beniamino in bugzilla ticked (referred to below):

  $ nmcli --offline connection modify ens3 ipv4.dns 192.168.1.1 \
      <input.nmconnection >output.nmconnection

Other commands don't support the argument at the moment:

  $ nmcli --offline c up ens3
  Error: 'up' command doesn't support --offline mode.

https://bugzilla.redhat.com/show_bug.cgi?id=1361145
2022-04-19 14:12:42 +02:00
Lubomir Rintel
438f52b459 nmcli/trivial: consistently order the options in process_command_line()
Make the order of nmc_complete_strings() arguments consistent with the
multi-way conditional below. Doesn't have any effect, just ensures the
ommisions and mistakes are hopefully easier to spot.
2022-04-19 14:12:20 +02:00
Lubomir Rintel
2a0231469f nmcli.h: tidy up boolean struct members
Use bitfields to save a few bytes. This involves swapping gboolean for
bool and some reordering in order to get them grouped together.

The patch looks horrible, because clang-format decides to put itself and
seem to go out of its way to make this whole file look idiotic.
What can you do.
2022-04-19 14:12:20 +02:00
Beniamino Galvani
e51b4ca5fe cli: indicate missing radio hardware in "nmcli radio"
When no radio hardware is present in the system, "nmcli radio"
currently displays:

  WIFI-HW  WIFI     WWAN-HW  WWAN
  enabled  enabled  enabled  enabled

which is misleading. Use the new RadioFlags property to display
"missing" in the *-HW columns when there is no hardware for the
given radio technology.

https://bugzilla.redhat.com/show_bug.cgi?id=1996918
2022-03-29 09:34:07 +02:00
Lubomir Rintel
aba3401df0 cli: remove one more g_assert()
I pushed accidentally pushed commit 9702310f25 ('clients: bulk removal
of g_assert*() statements') earlier than I intended, without addressing
one more case introduced by preceding merge. Fix it now.

Fixes: 9702310f25 ('clients: bulk removal of g_assert*() statements')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1166
2022-03-28 15:04:07 +02:00
Lubomir Rintel
8dbe6fa0d5 merge: branch 'lr/conn-migrate'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1146
https://bugzilla.redhat.com/show_bug.cgi?id=2059608
2022-03-28 15:00:45 +02:00
Lubomir Rintel
1aa9c80b9b cli: add "connection migrate" subcommand
This is used to move a connection to a different settings plugin.
2022-03-28 14:59:30 +02:00
Lubomir Rintel
9702310f25 clients: bulk removal of g_assert*() statements
Assertions should be done in tests. If we detect an unexpected situation
at runtime, we shall fail more gracefully than crashing right away.
2022-03-28 13:51:44 +02:00
Lubomir Rintel
c7ab380a5c cli: fix handling of erroneous connections in "delete"
If we can't find a connection for any reason other than that it doesn't
exist, we should error out immediately and consistently, regardless of
whether we already encountered a non-existent connection.
2022-03-28 13:29:28 +02:00
Lubomir Rintel
e39e5d9372 cli: fix up help string for "delete"
Make it obvious that we can delete more connections in one go.
2022-03-28 13:29:28 +02:00
Thomas Haller
aaf2155023
libnm/docs: fix documentation for "proxy.pac-script" 2022-03-21 15:21:37 +01:00