Commit graph

364 commits

Author SHA1 Message Date
Thomas Haller
eb083eece5
all: add NMMptcpFlags and connection.mptcp-flags property 2022-08-09 08:02:54 +02:00
Fernando Fernandez Mancera
32870d8233 libnm-utils: convert string bond opts to int
NMPlatform code for bond netlink support will use the numeric values,
therefore we need functions to convert all the string values to int.
2022-08-04 11:18:36 +02:00
Georg Müller
1d614dbded
crypto: support EC private keys
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1324
2022-08-04 09:46:06 +02:00
Thomas Haller
60404836d8
std-aux: add c_list_insert_sorted()
The strength of CList is of course to use it as a stack of queue,
and only append/remove from the front/tail.

However, since this is an intrusive list, it can also be useful to
just use it to track elements, and -- when necessary -- sort them
via c_list_sort().

If we have a sorted list, we might want to insert a new element
honoring the sort order. This function achieves that.
2022-07-28 11:05:14 +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
Beniamino Galvani
90e7afc2cd libnm,core: add support for {rto_min,quickack,advmss} route attributes 2022-06-27 11:38:43 +02:00
Thomas Haller
863b71a8fe
all: use internal _nm_utils_ip4_netmask_to_prefix()
We have two variants of the function: nm_utils_ip4_netmask_to_prefix()
and _nm_utils_ip4_netmask_to_prefix(). The former only exists because it
is public API in libnm. Internally, only use the latter.
2022-06-27 10:50:24 +02:00
Thomas Haller
05014b328f
glib-aux: add _nm_utils_ip4_netmask_to_prefix() helper
nm_utils_ip4_netmask_to_prefix() and nm_utils_ip4_prefix_to_netmask()
are public API in libnm.

We thus already have an internal implementation _nm_utils_ip4_prefix_to_netmask(),
for non-libnm users. Internally, we should never use the libnm variant.

For consistency and so that we have the helper available in
libnm-glib-aux, add _nm_utils_ip4_netmask_to_prefix().
2022-06-27 10:50:23 +02:00
Thomas Haller
7a33870bf1
libnm: assert nm_utils_ip4_prefix_to_netmask() for valid IPv4 prefix length
There was already an nm_assert() assertion. Upgrade this
to a g_return_val_if_fail(). This function is public API,
so this is potentially an API break. But it should highlight
a bug in the caller.
2022-06-27 10:50:13 +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
21a19383c8
libnm: fix compatibility of OWE-TM with unsecure profiles
A unsecure profile can be used with a OWE-TM network, in which case it
uses the non-OWE BSS.

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
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
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
cdaa99cd35
ifcfg-rh: add support for ipv4.link-local 2022-05-27 08:24:40 +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
Alex Henrie
7d8b749293
libnm: allow manually specified IP addresses to have prefix length 0
In IPv4, /0 prevents the creation of a device route, making it
effectively the same as /32. However, in IPv6, /0 makes the device route
an all-encompassing default route. This allows, for example, an 'fe80::'
link-local address to be used to communicate with any public or private
address on the local network without any additional configuration.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1232
2022-05-26 19:08:28 +02:00
Thomas Haller
3e5f0a0fa2
libnm/trivial: adjust code comment
clang-format likes to indent the comment, at the location where it was.
Move it.
2022-05-17 13:10:41 +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
7012b9001a
libnm: reject infiniband.p-key set to 0, 0x8000
Kernel does not allow this ([1], [2]).

Usually tightening the verification is a break of API. But in this case,
no user had a working configuration that is breaking. At worst, they
had a broken profile that no longer loads.

We also filter those from _infiniband_add_add_or_delete(), since [3].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/infiniband/ulp/ipoib/ipoib_main.c?id=f443e374ae131c168a065ea1748feac6b2e76613#n2394
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/infiniband/ulp/ipoib/ipoib_vlan.c?id=f443e374ae131c168a065ea1748feac6b2e76613#n116
[3] eab817d34a
2022-05-12 15:53:24 +02:00
Thomas Haller
fd5945b408
libnm: fix crash validating infiniband profiles for interface-name
A virtual infiniband profile (with p-key>=0) can also contain a
"connection.interface-name". But it is required to match the
f"{parent}.{p-key}" format.

However, such a profile can also set "mac_address" instead of "parent".
In that case, the validation code was crashing.

  nmcli connection add type infiniband \
     infiniband.p-key 6 \
     infiniband.mac-address 52:54:00:86:f4:eb:aa:aa:aa:aa:52:54:00:86:f4:eb:aa:aa:aa:aa \
     connection.interface-name aaaa

The crash was introduced by commit 99d898cf1f ('libnm: rework caching
of virtual-iface-name for infiniband setting'). Previously, it would not
have crashed, because we just called

  g_strdup_printf("%s.%04x", priv->parent, priv->p_key)

with a NULL string. It would still not have validated the connection
and passing NULL as string to printf is wrong. But in practice, it
would have worked mostly fine for users.

Fixes: 99d898cf1f ('libnm: rework caching of virtual-iface-name for infiniband setting')
2022-05-12 15:52:45 +02:00
Lubomir Rintel
41291ef773 core/connection: ensure wired settings are around for bridges
Bridges are wired ethernet bridges, it makes sense for them to have
wired ethernet settings.

Ensuring they always exist makes reapplying the MTU changes more
convenient. The MTU for bridges is taken from wired settings, making it
impossible to change and reapply it for connections that lack them
(as reapply doesn't really cope well with addition and removal of
settings).

https://bugzilla.redhat.com/show_bug.cgi?id=2076131
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1208
2022-05-10 21:41:19 +02:00
Fernando Fernandez Mancera
62f461ebeb bond: drop _get_option_or_default() and use _get_option_normalized()
Currently nm_setting_bond_get_option_normalized() and
nm_setting_bond_get_option_or_default() are identical functions. As the
first one is exposed as public API and has a better name, let's drop the
second one.
2022-05-10 12:42:11 +02:00
Olivier Gayot
928cd1cb15
nmtui: add support for activating tun/tap connections
tun/tap connections can be created using a command such as:

  $ nmcli connection add type tun ifname tun0 mode tap owner 1000

They appear in nmcli connection as TYPE "tun".

This patch adds the ability to activate and deactivate this type of
connection using nmtui.

Each connection of TYPE "tun" appears as:

  TUN/TAP (<ifname>)
  * <connection-name>

Example:

  TUN/TAP (tap0)
  * bridge-slave-tap0

  TUN/TAP (tap1)
    bridge-slave-tap1
2022-05-09 21:14:59 +02:00
Olivier Gayot
24d8980692
nm-connection.c: replace !strcmp() expressions by nm_streq() 2022-05-09 21:14:59 +02:00
Thomas Haller
532f3e34a8
glib-aux: drop nm_str_buf_init() for NM_STR_BUF_INIT()
NM_STR_BUF_INIT() and nm_str_buf_init() were pretty much redundant. Drop one of
them.

Usually our pattern is that we don't have functions that return structs.
But NM_STR_BUF_INIT() returns a struct, because it's convenient to use
with

  nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(...);

So use that variant instead.
2022-05-09 19:18:30 +02:00
Lubomir Rintel
a3174af914 libnm: fix placement of some "Since:" tags
libnm-client-impl/nm-client.c:8398: warning: multi-line since docs found
  libnm-client-impl/nm-device-macvlan.c:115: warning: multi-line since docs found
  libnm-client-impl/nm-device-vxlan.c:540: warning: multi-line since docs found
  libnm-client-impl/nm-device-vxlan.c:92: warning: multi-line since docs found
  libnm-core-impl/nm-setting-ethtool.c:41: warning: multi-line since docs found
  libnm-core-impl/nm-setting-ip-config.c:2475: warning: multi-line since docs found
  libnm-core-impl/nm-setting-ip-config.c:2504: warning: multi-line since docs found
2022-05-06 18:33:27 +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
Thomas Haller
cdc3e3fa95
libnm: use own nm_unbase64mem_full() instead of systemd's in nm_utils_base64secret_decode() 2022-04-20 12:07:03 +02:00
Thomas Haller
bb0ba779f6
keyfile: use nm_unbase64char() instead of systemd code in _write_setting_wireguard() 2022-04-20 12:06:59 +02:00
Thomas Haller
915e923928
libnm: normalize empty strings in 802-1x setting
Supplicant does not allow setting certain properties to empty values.
It also does not make sense.

Also, ifcfg-rh writer uses svSetValueStr() for these properties, so
the ifcfg plugin would always loose having hte values set to "".

Also, you couldn't enter these strings in nmcli.

It's fair to assume that it makes no sense to have these values set to
an empty value. Since we cannot just tighten up verification to reject
them, normalize them.

It also seems that some GUI now starts setting domain_suffix_match to an
empty string. Or maybe it was always doing it, and ifcfg plugin just hid
the problem? Anyway, we have users out there who set these properties to
"".

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/973
2022-04-06 13:48:04 +02:00
Thomas Haller
445e783771
libnm: fix printing NULL value in NMSetting8021x.verify() 2022-04-06 13:47:21 +02:00
Thomas Haller
79f676c83a
crypto: move nm_crypto_read_file() to "libnm-glib-aux"
It has no actual dependency on the crypto library. All it does, is
to be careful about not leaking secrets in memory. We have code
for that in libnm-glib-aux already. Move.

The goal is to reduce the number of places where we use libnm-crypto,
because that has a large dependency. libnm-glib-aux is a very light
dependency instead.
2022-03-29 11:56:04 +02:00
Thomas Haller
723e1fc76f
libnm: move dependency to libnm-crypto out of libnm-core's "nm-utils.c"
libnm-core is also used by the daemon, thus currently dragging in
libnm-crypto there. But could we ever drop that dependency?

One use of the libnm-crypto is in functions like nm_utils_file_is_certificate()
in "nm-utils.h". These are part of the public API of libnm.

But this is not used by the daemon. Move it to "libnm-client-core"
to be closer to where it's actually used.

As we have unit tests in "libnm-core-impl/tests" that test this function,
those unit tests also would need to move to "libnm-client-impl".
Instead, add the actual implementation of these function to "libnm-crypto"
and test it there.

This patch moves forward declarations from public header "nm-utils.h" to
"nm-client.h". Arguably, "nm-client.h" is not a great name, but we don't
have a general purpose header in "libnm-client-public", so use this.
Note that libnm users can only include <NetworkManager.h> and including
individual files is not supported (and even prevented). Thus moving
the declarations won't break any users.
2022-03-29 11:56:04 +02:00
Thomas Haller
901787e06f
build: move nm-crypto to separate directory "src/libnm-crypto"
libnm-core currently has a dependency on crypto libraries (either
"gnutls", "nss" or "null"). We need this huge dependency for few cases.

Move the crypto code to a separate static library"src/libnm-crypto/libnm-crypto.la".
The reasoning is that it becomes clearer where we have this dependency,
to use it more consciously, and to be better see how it's used.

We clearly need the crypto functionality in libnm. But do we also need
it in the daemon? Could we ever link the daemon without crypto libraries?

The goal of splitting the crypto part out, to better understand the
crypto dependency.
2022-03-29 11:56:04 +02:00
Thomas Haller
3a97604a27
libnm: don't depend nm-crypto on "nm-error.h"
"nm-error.h" is public API of libnm, and contains error numbers and
quarks. Clearly our "nm-crypto" implementation wants to use those
errors.

I want to move "nm-crypto" out of libnm, and as it's more basic, I think
it should not have a dependency on all of libnm-core. Also because
libnm-core currently uses nm-crypto, so there would be a circular
dependency. Which would be possible to do (libnm-core-aux-intern is
also used in such a way). But it's better avoided, to have clear
hierarchy of dependencies.

Add a version of the same error codes to libnm-base. libnm-base is a
very basic dependency (just one step above libnm-glib-aux).
2022-03-29 11:56:03 +02:00
Thomas Haller
34b4496028
libnm: no longer use "nm-utils.h" from "nm-crypto.c"
The goal is to make "nm-crypto.c" independent of libnm-core.
2022-03-29 11:56:03 +02:00
Thomas Haller
526a05d6f2
glib-aux: add _nm_utils_bin2hexstr() and use from nm_utils_bin2hexstr()
nm_utils_bin2hexstr() is part of public libnm API.
That means, if we want to use this function, we need to link with
libnm-core-impl.

This is used by "nm-crypto.c". That file is currently part of
libnm-core, but that will change.

Move the implementation to libnm-glib-aux, so that we can use this code
from all our glib-based code (because all our glib-based code is allowed
to link with libnm-glib-aux).
2022-03-29 11:56:03 +02:00
Thomas Haller
ee1467fcdb
libnm/802-1x: check is-pkcs12 only for blob certificates in verify_tls()
If the certificate is not a blob, it makes no sense to call
nm_crypto_is_pkcs12_data().
2022-03-29 11:52:38 +02:00
Thomas Haller
d3a6b9e7cc
libnm/802-1x: move need_private_key_password() to need_secrets_tls()
When a static function only has one caller, it is often simpler to not
have the code in a separate function. Drop need_private_key_password()
and move it to need_secrets_tls().
2022-03-29 11:52:37 +02:00
Thomas Haller
bcb1ab9e1c
libnm/802-1x: don't use g_warning() in need_secrets_tls()
g_warning() for unexpected scheme is not right. Either, this should be an
assertion (and never be hit), or the library should be silent about conditions
that can happen regularly.
2022-03-29 11:52:37 +02:00
Thomas Haller
e4a7b671d6
libnm/802-1x: cleanup duplicate code paths in need_secrets_tls()
I think code is easier to understand, if the difference (between phase1
and phase2) is pushed to the bottom. Having one large "if(phase2){}else{}"
at the top makes it harder to compare the two branches and see where
they differ.
2022-03-29 11:52:37 +02:00
Thomas Haller
47f2c5e5db
libnm/802-1x: cleanup need_secrets_phase2() 2022-03-29 11:52:37 +02:00
Thomas Haller
a3aec9dc5c
libnm/802-1x: reuse verify_identity() in verify_ttls() implementation 2022-03-29 11:52:37 +02:00
Thomas Haller
d5ee67981c
libnm/802-1x: simplify verify_tls() for phase1 and phase2
The checks are duplicated and verbose. Combine them.
2022-03-29 11:52:33 +02:00
Thomas Haller
782f2fa8ef
keyfile: don't require verified profile in nm_keyfile_write()
Previously, only the daemon was writing keyfiles, and it ensures
that they are always valid.

As we now have this function as public API of libnm, we should drop this
restriction and write the profile the best we can. Granted, an invalid
profile may not be expressed in keyfile format, and the result is
undefined. But make the best of it.
2022-03-28 18:27:37 +02:00
Thomas Haller
b07bf1a8bb
keyfile: add write_handle_warn() helper 2022-03-28 18:27:37 +02:00
Thomas Haller
cec1269795
keyfile: rename handle_warn() to read_handle_warn()
We will also want to warn during write.
2022-03-28 18:27:36 +02:00