Commit graph

13631 commits

Author SHA1 Message Date
Beniamino Galvani
e2b4417570 core: unblock OVS interfaces when the ovsdb is ready
OVS system interfaces can start to connect even before the ovsdb is
ready. However, the connection attempt is doomed to fail and the
NMSettingsConnection gets blocked with reason FAILED.

Unblock them once the ovsdb is ready.

Ideally, NMPolicy should subscribe to the NMOvsdb::ready signal,
however NMOvsdb is in a plugin, so it's easier if NMOvsdb directly
calls a function of the core.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
c3cb177b7d ovs: set OVS interfaces as available only after ovs-ready signal
Don't allow OVS interfaces to connect until the NMOvsdb signals it's
ready. Otherwise, connection attemps can race with the initial OVS
cleanup.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
6d195f7a3f ovs: improve disconnecting devices after removal from ovsdb
Sometimes during boot the device starts an activation with reason
'assumed', then the ovs interfaces gets removed from the ovsdb. At
this point the device has an active-connection associated; it has the
activate_stage1_device_prepare() activation source scheduled, but it
is still in disconnected state.

Currently the factory doesn't recognizes that the device is activating
and allows the device to proceed even if the interface was removed
from the ovsdb. Fix this by checking the presence of an
active-connection instead.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
31d0a9524d ovs: clean up interfaces from ovsdb at startup
During shutdown, NM always tries to remove from ovsdb all bridges,
ports, interfaces that it previously added. Currently NM doesn't run
the main loop during shutdown and so it's not possible to perform
asynchronous operations. In particular, the NMOvsdb singleton is
disposed in a destructor where it's not possible to send out all the
queued deletions.

The result is that NM deletes only one OVS interface, keeping the
others. This needs to be fixed, but requires a rework of the shutdown
procedure that involves many parts of NM.

Even when a better shutdown procedure will be implemented, we should
support an unclean shutdown caused by e.g. a kernel panic or a NM
crash. In these cases, the interfaces added by NM would still linger
in the ovsdb.

Delete all those interface at NM startup. If there are connections
profiles for them, NM will create them again.

Also, NMOvsdb now emits a NM_OVSDB_READY signal and provides a
nm_ovsdb_is_ready() to allow other parts of the daemon to order
actions after the initial OVS cleanup.

https://bugzilla.redhat.com/show_bug.cgi?id=1861296
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/700
2021-01-27 16:12:42 +01:00
Beniamino Galvani
a30d744657 ovs: change reason for deactivation-on-removal
The interface was removed, so NM_DEVICE_STATE_REASON_REMOVED sounds
more correct.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
8e55efeb9d ovs: fail OVS system interfaces when the db entry gets removed
If an OVS system interface that is active in NM gets removed
externally from the ovsdb, NM doesn't notice it and keeps the
connection active.

Let the OVS factory also handle the removal message for system
interfaces. In that case, we need to match the removed interface name
to the actual device, which can be of any kind.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
c288a338f9 ovs: rework emitting signals for new/removed devices
Instead of filtering the signals in NMOvsdb, emit them all and let the
subscriber decide what to do with them.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
69400c6f91 ovs: let the factory create devices for external patch interfaces
Patch interfaces are conceptually similar to internal interfaces. Let
the factory create devices for patch interfaces created externally.
2021-01-27 16:12:42 +01:00
Beniamino Galvani
fdf390786f manager: improve error messages 2021-01-27 16:12:42 +01:00
Thomas Haller
a67c312d5d
wireguard: fix configuring larger number of allowed-ips on WireGuard link
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/640

Fixes: a5c894c35f ('platform: create wireguard netdev interface')
2021-01-27 11:33:14 +01:00
Thomas Haller
c2c8c67d8c
ndisc: rate limit number of accepted RA data to track
I don't think that the way we track RA data is correct. For example,
all data (like DNSSL) is tracked regardless of their router. That means,
if a router sends an update, we cannot prematurely expire a DNSSL list
which is no longer announced by that router. Anyway, that should be
reviewed and considered another time.

However, we also must rate limit the number of elements we track in
general. So far we would only do that for the addresses.

The limit for max_addresses, is already read by sysctl. We only limit
it further to at most 300 addresses. The 300 is arbitrarily chosen.

The limit for DNSSL and RDNSS are taken from systemd-networkd
(NDISC_DNSSL_MAX, NDISC_RDNSS_MAX), which is 64.

The limit for gateways and routes are not based on anything and just
made up.
2021-01-27 10:18:16 +01:00
Thomas Haller
3ab5f6550b
ndisc: minor cleanup of ra_timeout 2021-01-27 10:18:16 +01:00
Thomas Haller
5ba2f81d2d
ndisc: rework sending router solicitations to follow RFC7559
RFC4861 describes how to solicit routers, but this is later extended
by RFC7559 (Packet-Loss Resiliency for Router Solicitations).

Rework the scheduling of router solicitations to follow RFC7559.

Differences from RFC7559:

- the initial random delay before sending the first RS is only
  up to 250 milliseconds (instead of 1 second).

- we never completely stop sending RS, even after we receive a valid
  RA. We will still send RS every hour.

We no longer honor the sysctl variables

  - /proc/sys/net/ipv6/conf/$IFNAME/router_solicitations
  - /proc/sys/net/ipv6/conf/$IFNAME/router_solicitation_interval

I don't think having the autoconf algorithm configurable is useful.
At least not, if the configuration happens via sysctl variables.

https://tools.ietf.org/html/rfc4861#section-6.3.7
https://tools.ietf.org/html/rfc7559#section-2.1
2021-01-27 10:18:15 +01:00
Thomas Haller
6dad4a315f
ndisc/trivial: rename defines for defaults from RFC
These defaults are mentioned in RFC4861. Use a name that is the same
as in the RFC.
2021-01-27 10:18:15 +01:00
Thomas Haller
4c2035347e
ndisc: track expiry of Router Advertisements in milliseconds
Elements of RAs have a lifetime. Previously we would track both
the timestamp (when we received the RA) and the lifetime.

However, we are mainly interested in the expiry time. So tracking the
expiry in form of timestamp and lifetime is redundant and cumbersome
to use.

Consider also the cases nm_ndisc_add_address() were we mangle the expiry.
In that case, the timestamp becomes meaningless or it's not clear what
the timestamp should be.

Also, there are no real cases where we actually need the receive timestamp.
Note that when we convert the times to NMPlatformIP6Address, we again need
to synthesize a base time stamp. But here too, it's NMPlatformIP6Address
fault of doing this pointless split of timestamp and lifetime.

While at it, increase the precision to milliseconds. As we receive
lifetimes with seconds precision, one might think that seconds precision
is enough for tracking the timeouts. However it just leads to ugly
uncertainty about rounding, when we can track times with sufficient
precision without downside. For example, before configuring an
address in kernel, we also need to calculate a remaining lifetime
with a lower precision. By having the exact values, we can do so
more accurately. At least, in theory. Of course NMPlatformIP6Address
itself has only precision of seconds, we already loose the information
before. However, NMNDisc no longer has that problem.
2021-01-27 10:18:14 +01:00
Thomas Haller
03c6d8280c
ndisc: don't call solicit_routers() from clean_dns_*() functions
This was done since NDisc code was added to NetworkManager in
commit c3a4656a68 ('rdisc: libndp implementation').

Note what it does: in clean_dns_*() we will call solicit_router()
if the half-life of any entity is expired. That doesn't seem right.
Why only for dns_servers and dns_domains, but not routes, addresses
and gateways?

Also, why would the timings for when we solicit depend on when
elements expire. It is "normal" that some of them will expire.
We should solicit based on other parameters, like keeping track
of when and how to solicit.

Note that there is a change in behavior here: if we stopped
soliciting (either because we received our first RA or because
we run out of retries), then we now will never start again.
Previously this was a mechanism so that we would eventually
start soliciting again. This will be fixed in a follow-up
commit soon.
2021-01-27 10:18:14 +01:00
Thomas Haller
f892fce04f
ndisc/tests: use nmtst_main_loop_run_assert() to ensure we terminate
Otherwise, if there is a problem with the test they will run
indefinitely. Sure, meson will kill them after a while, but I
don't think autotools does, does it? Anyway, give a maximum
time to wait.
2021-01-27 10:18:14 +01:00
Thomas Haller
de9e570cb1
ndisc: mark NMIcmpv6RouterPref enum as _nm_packed
We embed values of this type in structs. Let's pack it
to only use one byte.
2021-01-27 10:18:14 +01:00
Thomas Haller
8a3310043b
ndisc: add static asserts to _route_preference_coerce()
Our internal NMIcmpv6RouterPref defines must be numerically identical
to the values in the protocol. Add a static assertion for that.
2021-01-27 10:18:13 +01:00
Roy Marples
a2abd15fe0
DHCP: Support dhcpcd-9.x
This locks NM into dhcpcd-9.3.3 as that is the first version to support
the --noconfigure option. Older versions are no longer supported by NM
because they do modify the host which is undesirable.

Due to the way dhcpcd-9 uses privilege separation and that it re-parents
itself to PID 1, the main process cannot be reaped or waited for.
So we rely on dhcpcd correctly cleaning up after itself.
A new function nm_dhcp_client_stop_watch_child() has been added
so that dhcpcd can perform similar cleanup to the equivalent stop call.

As part of this change, the STOP and STOPPED reasons are mapped to
NM_DHCP_STATE_DONE and PREINIT is mapped to a new state NM_DHCP_STATE_NOOP
which means NM should just ignore this state.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/668
2021-01-26 15:06:12 +01:00
Jonas Jelten
004980a38c
initrd: add ip=... link6 mode for link-local only address assignment
This is useful for bringing up the interface with a IPv6 link local
address only during boot, e.g. to map a NBD device from a server that is
connected directly, e.g. via thunderbolt.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/584
2021-01-26 11:35:45 +01:00
Beniamino Galvani
9c516a497e device: fix assertion failure when resolving hostname
nm_device_get_effective_ip_config_method() must called only on a
device with an applied connection. Fix assertion failure [1]:

  nm_device_get_effective_ip_config_method: assertion 'NM_IS_CONNECTION(connection)' failed

[1] http://faf.lab.eng.brq.redhat.com/faf/reports/20217/

Fixes: 09c8387114 ('policy: use the hostname setting'):
2021-01-20 18:50:09 +01:00
Thomas Haller
4e997d1b36
initrd/tests: cleanup redundant code in "test-cmdline-reader.c"
Add _parse(), _parse_cons() and _parse_con() helper macros. These
already perform assertions that are common in those cases, and thus
reduce a lot of boiler plate code.

Also, _parse_cons() is exactly about parsing connections. The next
time we add an out parameter to nmi_cmdline_reader_parse() we won't
have to adjust all the call sites where this parameter doesn't matter.
2021-01-20 16:55:10 +01:00
Adarsh J
e300138892
initrd: add support for rd.net.timeout.carrier
Add support for `carrier-wait-timeout` setting from kernel cmdline.

This will create a new `15-carrier-timeout.conf` file in
/run/NetworkManager/conf.d with the parameter value as specified.

The setting also inserts `match-device` to `*`, matching all devices.

NB: The parameter on kernel cmdline is specified in seconds. This is
done to be backwards compatible with with network-legacy module. However
the generated setting will automatically multiply specified value by
1000 and store timeout value in ms.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/730
2021-01-20 16:10:56 +01:00
Thomas Haller
a824f56441
device: if a device is not IFF_UP assume that is has carrier
A device that is not IFF_UP does not have carrier. So we don't
know the real state before we bring it up.

On the other hand, during `nmcli connection up` we check whether the
device is available. So we are blocked. The solution is to optimistically
assume that the device has carrier if it is down. We may fail later.

  $ nmcli connection add type veth con-name vv0 autoconnect no ifname vv0 peer vv1 ipv4.method shared ipv6.method shared
  $ nmcli connection up vv0
  $ nmcli device connect vv1
  Error: Failed to add/activate new connection: Connection 'vv1' is not available on device vv1 because device has no carrier
2021-01-19 16:41:50 +01:00
Thomas Haller
7c05ff1632
device: fix complete-connection for veth devices
Otherwise,

    $ nmcli device connect veth0

fails with

    Error: Failed to add/activate new connection: veth.peer: property is not specified

In complete_connection(), we should by default complete ethernet
connections, unless the caller already indicated to want a veth
profile.

Fixes: cd0cf9229d ('veth: add support to configure veth interfaces')
2021-01-19 16:41:45 +01:00
Beniamino Galvani
e2d04e18d5 device: fix stale pointer in nm_device_get_hostname_from_dns_lookup()
Fixes: 09c8387114 ('policy: use the hostname setting')

https://bugzilla.redhat.com/show_bug.cgi?id=1917713
2021-01-19 11:13:38 +01:00
Beniamino Galvani
92c494f290 all: change default value of hostname.only-from-default to false
Currently, is retrieved by default only from the device with the
default route. This is done so that in presence of multiple
connections the choice is deterministic.

However, this limitation seems confusing for users, that expect to get
an hostname even for non-default devices. Change the default and allow
any device to obtain the hostname.

Note that when there is a default route, NM still prefers that device
and so the behavior doesn't change.

The only change in behavior is that when there is no default route and
the machine doesn't have a static hostname, NM will try to get
hostname from DHCP or reverse DNS.

https://bugzilla.redhat.com/show_bug.cgi?id=1766944
2021-01-18 16:29:55 +01:00
Beniamino Galvani
af55a86a82 policy: prefer device with default route to determine the hostname
In case two devices have the same hostname-priority, prefer the one
with the best default route. In this way, even if
hostname.only-from-default is set to FALSE globally, the behavior is
similar to the past when there is a device with the default route.

Previously, NMPolicy considered only the hostname-priority and the
activation order to build the DeviceHostnameInfo list. Now it has to
consider also the presence of the default route, which depends on the
address family. Therefore, now there is a DeviceHostnameInfo for each
[device,address_family] combination.
2021-01-18 16:24:53 +01:00
Thomas Haller
e6b5f54d6d
wifi: log WPS flag of access point 2021-01-18 09:28:59 +01:00
Thomas Haller
1d04770002
wifi: fix caching ap-flags for supplicant-interface
Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/631
2021-01-18 09:27:32 +01:00
Thomas Haller
9901aeef2c
platform: move "nm-platform-utils.[hc]" to "shared/nm-platform" library
By now it has no further dependencies on libnm-core or NetworkManager core.
Make it part of "shared/nm-platform" library.
2021-01-15 11:32:53 +01:00
Thomas Haller
c0bc296a51
platform: use NMOptionBool instead of NMTernary
NMTernary is a dependency for libnm-core. Avoid it.
2021-01-15 11:32:49 +01:00
Thomas Haller
d2464c260f
core: move NMIPConfigSource from "src/nm-types.h" to "shared/nm-base" 2021-01-15 11:32:43 +01:00
Thomas Haller
874bd8994e
libnm,shared: move nm-ethtool helper to "libnm-base"
We want to use this by "shared/nm-platform", which should have
no dependency on "libnm-core".

Move "libnm-core/nm-ethtool-utils.h" to "libnm/nm-ethtool-utils.h" so
that it is only used by libnm. This file contains the defines for
the option names.

Also, symlink "libnm/nm-ethtool-utils.h" as "shared/nm-base/nm-ethtool-utils-base.h".
We want to use the same defines also internally. Since they are both
public API (must be in libnm) and should be in "shared/nm-base", this
is the way.
2021-01-15 11:32:41 +01:00
Thomas Haller
19242f56d7
libnm: split ethtool option names to a new header "libnm-core/nm-ethtool-utils.h"
We want to use these defines for option names also in "shared/nm-base"
(and in turn in "shared/nm-platform), which cannot include "libnm-core".

However, they are also public API of libnm.

To get this done, in a first step, move these defines to a new header
"libnm-core/nm-ethtool-utils.h".

Since now the name "nm-ethtool-utils.h" is taken, also rename
nm-libnm-core-intern files.
2021-01-15 11:32:39 +01:00
Thomas Haller
9a5a95e0fa
platform: remove unnecessary includes from "nm-platform-utils.c" 2021-01-15 11:32:38 +01:00
Thomas Haller
90881953ed
platform: move nm_platform_link_duplex_type_to_string() to "nm-platform-utils.c"
There should be a clear hierarchie of dependency. That is,
"nm-platform.h" may use "nm-platform-utils.h", but not the
other way around.

Move nm_platform_link_duplex_type_to_string().
2021-01-15 11:32:36 +01:00
Thomas Haller
84d67d3a4f
shared: add duplicate for NM_UTILS_HWADDR_LEN_MAX to "nm-base/nm-base.h"
We will need this in "shared/nm-platform", but we don't want
to include "libnm-core/nm-utils.h" for that.
2021-01-15 11:32:35 +01:00
Thomas Haller
126681a965
platform: move types from "nm-platform-utils.h" to nmp-base.h"
Thereby, also no longer include "nm-platform.h" and "nm-setting-wired.h"
in "nm-platform-utils.h".
2021-01-15 11:32:34 +01:00
Thomas Haller
2bb5c8b13b
platform: add duplicate of NMSettingWiredWakeOnLan to nm-base for platform
Currently src/platform depends on libnm-core. libnm-core is large
optimally we have a better separation between our code. That means
libnm-core does not depend on platform and vice versa.

However, nm-platform re-uses some enums from libnm-core for internal code.
To avoid that dependency, add _NMSettingWiredWakeOnLan as a duplicate to
nm-base/nm-base.h. nm-base can both be used by libnm-core, nm-platform
and src/platform.

The only problem is that NMSettingWiredWakeOnLan is also part of public
API of libnm. It means, we must duplicate the enum. But with several
static assertions in unit tests I think that is not a problem to do.
2021-01-15 11:32:33 +01:00
Thomas Haller
e5d2a05ad5
libnm: add "shared/nm-base/nm-base.h"
Our dependencies are complicated.

Currently "src/platform" uses parts of libnm-core and is relatively
strongly entangled with core. It would be nice to have that part
clearly independent from "src" and from "libnm-core".

Also, "src/platform/nm-platform-utils.h" uses NMEthtoolID enum, which
previously was defined in "libnm-core/nm-libnm-core-intern/nm-ethtool-utils.h".

Move that to a new place "shared/nm-base/nm-base.h".

Note that we have "libnm-core/nm-libnm-core-intern", which is
libnm/core related code which uses and is used by libnm-core.
There is a need for a library which is used by libnm-core, but
does not depend on libnm-core itself. Here comes "shared/nm-base".

Yes, many libraries. But the goal is to entangle the dependencies
and have a clear hierarchy of includes. And to have "shared/nm-platform"
independent of libnm-core.
2021-01-15 11:32:32 +01:00
Thomas Haller
31dca65e04
shared,platform: move "nmp-netns.[hc]" to shared/nm-platform 2021-01-15 11:32:31 +01:00
Thomas Haller
24c634bf57
core/logging: move "nm-logging.c" to shared/nm-log-core/libnm-log-core library
We want to move platform code to "shared/nm-platform". However, platform
code uses the logging infrastructure from the daemon, there is thus
an odd circular dependency.

Solve that by moving the "src/nm-logging.[hc]" to a new helper library
in "shared/nm-log-core".
2021-01-15 11:32:31 +01:00
Thomas Haller
c6e1327495
core: move NM_MANAGER_ERROR to shared/nm-glib-aux
"src/nm-logging.c" should be independent of libnm-core. It almost
is, except the error domain and code.

Move NM_MANAGER_ERROR to "nm-glib-aux/nm-shared-utils.h" so that
"nm-logging.c" is independent of libnm-core.
2021-01-15 11:32:30 +01:00
Thomas Haller
186f2da2fc
shared,platform: add "shared/nm-platform" library
NetworkManager core is huge. We should try to split out
parts that are independent.

Platform code is already mostly independent. But due to having it
under "src/", there is no strict separation/layering which determines
the parts that can work independently. So, while the code is mostly
independent (in practice), that is not obvious from looking at the
source tree. It thus still contributes to cognitive load.

Add a shared library "shared/nm-platform", which should have no
dependencies on libnm-core or NetworkManager core.

In a first step, move the netlink code there. More should follow.
2021-01-15 11:32:30 +01:00
Thomas Haller
05008faf6e
build/meson: add libnm_systemd_core_dep dependency 2021-01-15 11:32:29 +01:00
Thomas Haller
63e070b180
build/meson: cleanup build of test-systemd executable 2021-01-15 11:32:29 +01:00
Thomas Haller
43d4810179
shared: move nm_utils_ifname_cpy() to "shared/nm-glib-aux" 2021-01-15 11:32:28 +01:00
Thomas Haller
6aa6da2b08
shared: add _nm_utils_hwaddr_aton_exact()
This is the same as libnm's nm_utils_hwaddr_aton(), which however
is public API.

We want to use this function also without libnm(-core). Hence add
the helper to "shared/nm-glib-aux".
2021-01-15 11:32:28 +01:00