Commit graph

13135 commits

Author SHA1 Message Date
Thomas Haller
1a4cc800f6
platform: add nmp_object_indirect_id_*() helpers 2020-07-31 08:53:04 +02:00
Thomas Haller
14fa487a60
platform: add static assertion to check NMPlatformIP{Address,Route} struct layout 2020-07-31 08:53:04 +02:00
Thomas Haller
7eb94b7dcc
platform: add nm_platform_ip_route_get_gateway() helper 2020-07-31 08:53:04 +02:00
Thomas Haller
1e3f5b7c01
platform: add NMP_OBJECT_TYPE_IP_ADDRESS()/NMP_OBJECT_TYPE_IP_ROUTE() macros 2020-07-31 08:53:04 +02:00
Beniamino Galvani
76a6a30577 dhcp6: don't require a hardware address
The systemd DHCPv6 client requires a hardware address only to
determine the IAID; NM always overrides the IAID with its own and
therefore the hwaddr is not used.

Removing such requirement allows DHCPv6 to run over PPP, which is
useful with DHCPv6-PD to get a prefix from the ISP.

To test this, I set up a server with pppoe-server, radvd and the Wide
DHCPv6 server providing an address and a prefix. On the client, NM was
able to obtain a prefix using both dhcp=dhclient and dhcp=systemd.

Note that if there is no hardware address and you specify
ipv6.dhcp-duid=ll or ipv6.dhcp-iaid=mac, a warning will be emitted and
NM will use a random DUID/IAID.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/478
2020-07-29 18:08:53 +02:00
Thomas Haller
cfbaa2d8eb
device: fix emitting unnecessary PROP_IFINDEX notification in NMDevice
Fixes: ea1f0fc0a6 ('device: let NMDevice track a NML3Cfg instance for each ifindex')
2020-07-29 17:21:10 +02:00
Thomas Haller
99f096577c
l3cfg: add flags for NML3ConfigData
Add a flags parameter. That is useful to bundle multiple simple boolean
properties, without need to implement individual accessors.
2020-07-28 16:03:51 +02:00
Thomas Haller
d9547e8452
l3cfg: make NML3ConfigData ref/unref functions const
NML3ConfigData is supposed to be used as immutable, ref-counted type.
You create it once, initialize it, seal it, and pass (immutable) references
around.

In such a scheme, having ref/unref functions not operate on const pointers
is a major inconvenience.
2020-07-24 16:12:23 +02:00
Thomas Haller
a2a69a2dab
l3cfg: add more API to NML3ConfigData 2020-07-24 16:12:23 +02:00
Thomas Haller
6aa338edd4
l3cfg: tie NML3ConfigData to an ifindex
NML3ConfigData tracks IP addresses and routes. In their current form, these
types (NMPObject) always have an ifindex and there is no sensible way to have
an NMPObject (for routes or addresses) that have a wildcard ifindex.

Honor that by also tying NML3ConfigData to an ifindex. In most cases, the
user knows the ifindex before and can create it. On the unlikely case where
the user doesn't know the ifindex, we should add a new nm_l3_config_data_clone()
function, which allows migrating the setting from one ifindex to another.
2020-07-24 16:12:23 +02:00
Thomas Haller
5f23d691bf
l3cfg: add nm_l3_config_data_new_from_platform() for capturing settings
It basically does what nm_ip4_config_capture() and
nm_ip6_config_capture() does.
2020-07-24 16:12:22 +02:00
Thomas Haller
b44f7dce40
core: add nm_platform_dedup_multi_iter_next_*() helpers to "nmp-object.h"
This code is not specific to "nm-ip4-config.h"/"nm-ip6-config.h".
It applies to everybody who wants to iterate over a dedup-multi-index of
certain NMPObjects. Move it.
2020-07-24 16:10:05 +02:00
Thomas Haller
67bfcb49c9
core: use nm_platform_ip[46]_address_pretty_sort_cmp() in "nm-ip[46]-config.c" 2020-07-24 16:10:04 +02:00
Thomas Haller
83bc1e8d60
platform: use NM_CMP_*() macros in nm_platform_ip[46]_address_pretty_sort_cmp()
They ensure to consistently return -1, 0, 1. Also, I think they are
easier to understand.

What is in general hard to understand, whether a comparison sorts
ascending or descending. The macros maybe make that easier too, but it's
still confusing. That's why we have a test.
2020-07-24 16:10:04 +02:00
Thomas Haller
d7608f32a6
platform: add nm_platform_ip[46]_address_pretty_sort_cmp()
This is the code from _addresses_sort_cmp() in "nm-ip[46]-config.h"
and will replace it soon.
2020-07-24 16:10:04 +02:00
Thomas Haller
be655e6ed1
core: read "disable_ipv6" sysctl before nm_ip6_config_create_setting()
First of all, the entire nm_device_generate_connection() and
nm_ip._config_create_setting() approach is fundamentally flawed. You
cannot generate sensible configuration by reading IP addresses from
an interface. Anyway, that's what we still sometimes do, and we possibly
should do it less and less.

It's ugly that nm_ip6_config_capture() would read the "disable_ipv6"
sysctl value and cache it in NMIP6Config. Only so that it can be use
much later during nm_ip6_config_create_setting().

Instead, read the sysctl value shortly before it's needed.
2020-07-24 16:03:15 +02:00
Thomas Haller
b15c85cf8b
core: move nm_utils_ip4_address_is_link_local() to header file
It's so simple, let's move it so it can be inlined.
2020-07-24 16:03:15 +02:00
Beniamino Galvani
9c09dcedaf device: downgrade warning about IPv6 MTU if IPv6 is disabled
If IPv6 is disabled, changing the IPv6 MTU fails and NM complains with
a warning. Since this error is expected and doesn't do any harm,
downgrade the logging level to DEBUG.

Since IPv6 kernel support can be built as a module, we have to check
the existence of /proc/sys/net/ipv6 every time. Instead of checking it
and then setting the MTU (adding one /proc access for everyone), just try
to set the MTU; in case of failure, determine the reason for the error.

https://bugzilla.redhat.com/show_bug.cgi?id=1840989
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/585
2020-07-24 13:41:31 +02:00
Thomas Haller
a1dbaf5799
l3cfg: add NML3ConfigData
Currently NMIP4Config and NMIP6Config both track the data to be
configured, they expose properties on D-Bus, and they have logic for
capturing and applying settings to platform.

We will split that.

- NMIP4Config and NMIP6Config will expose data on D-Bus.

- NML3Cfg will have the logic for handling IP configuration.

- NML3ConfigData will track data to be configured.

NML3ConfigData mirrors NMIP4Config/NMIP6Config in many aspects. For now,
this duplicates a lot of code. More will be done later. Eventually,
NMIP4Config/NMIP6Config will drop the duplicated functionality.
2020-07-23 15:29:25 +02:00
Thomas Haller
6e8a987763
l3cfg: add nm_l3cfg_property_emit_register() API
The NML3Cfg instance tracks and prepares the IP configuration.
However, that is also partly exposed on other objects, like
NMIP4Config's "route-data" property.

Add an API, so that NMIP4Config can register itself to be notified
when something relevant changes.

This is an alternative to standard GObject properties and signals. They
often seem more effort than worth. That is, because in this case,
NMIP4Config.route-data has no other task then to re-emit the signal.
So, to implement that with GObject properties/signals, we would have to
add a property/signal to NML3Cfg, subscribe to it from NMIP4Config,
and remit the signal. An alternative is to bind properties, but that
would still be quite some extra code, and unclear that it would be
simpler. Not to mention the overhead, as bindings are themself full
GObject instances, that register to and emit signals by name.
2020-07-23 15:29:25 +02:00
Thomas Haller
2eb5639a30
l3cfg: add NML3CfgPrivate data
We have several fields in the header file, so that the frequently used accessors
can be inlined. However, we also want some private data. Add a structure for that.
2020-07-23 15:29:25 +02:00
Thomas Haller
62ea998d32
l3cfg: track ifname in NML3Cfg 2020-07-23 15:29:25 +02:00
Thomas Haller
b5c563329a
l3cfg: notify NML3Cfg about NMPlatform changes in an idle handler
We need to react to platform changes. Also, we usually want to delay the
reaction to an idle handler.

Instead of subscribing each NML3Cfg instance itself to platform changes,
let only NMNetns do that. The goal is of course that each platform event
only needs to notify the NML3Cfg instance, which collects the events and
schedules them on the idle handler.
2020-07-23 15:29:25 +02:00
Thomas Haller
ea1f0fc0a6
device: let NMDevice track a NML3Cfg instance for each ifindex 2020-07-23 15:29:25 +02:00
Thomas Haller
88d057978d
core: add "nm-l3cfg.[hc]" 2020-07-23 15:29:24 +02:00
Thomas Haller
d32074e2b6
device: simplify device_ip_link_changed() for setting ip_iface
_ip_iface_update() only had one caller. The code is simpler to
understand by inlining it.

Also, it is relevant where and how we set ip_iface_ and ip_ifindex_
fields. Keep the places few and easily understandable.
2020-07-23 15:29:24 +02:00
Thomas Haller
5c273efb36
core: use nm_utils_parse_inaddr_prefix_bin() in nm_utils_ip_route_attribute_to_platform()
We already have an implementation for parsing an address/plen string.
Use it.
2020-07-23 15:29:24 +02:00
Thomas Haller
4127c88ad2
core: move _nm_ip_config_merge_route_attributes() to "NetworkManagerUtils.c"
and rename to nm_utils_ip_route_attribute_to_platform(). The function is independent
from NMIP4Config. We also will use it outside of NMIP4Config. Also, "NetworkManagerUtils.c"
already has similar functions that parse libnm structures to internal structures.
2020-07-23 15:29:24 +02:00
Thomas Haller
348d721b3f
core: use nmp_object_ip_route_is_best_defaut_route() in NMIP4Config 2020-07-23 15:29:24 +02:00
Thomas Haller
3f771c55ac
core: use nmp_object_ref_set() instead of _nm_ip_config_best_default_route_set()
_nm_ip_config_best_default_route_set() doesn't really do anything
special. Use the generic helper function for the same job.

Also because NMIP4Config in the current form will be replaced by
something else, and this code needs to change.
2020-07-23 15:29:24 +02:00
Thomas Haller
84d93315d8
platform: add nmp_object_ip_route_is_best_defaut_route() helper 2020-07-23 15:29:24 +02:00
Thomas Haller
d4b7a3c27e
platform: add nmp_object_ref_set() helper 2020-07-23 15:29:24 +02:00
Thomas Haller
04be1dbd80
platform: add NMP_OBJECT_GET_ADDR_FAMILY() helper 2020-07-23 15:29:23 +02:00
Thomas Haller
bc3439d14f
platform: add nmp_object_link_get_ifname() helper 2020-07-23 15:29:23 +02:00
Thomas Haller
e9b84221de
device: emit rx-bytes/tx-bytes change notification together
This also groups the PropertiesChanged signal on D-Bus.
2020-07-23 15:29:22 +02:00
Thomas Haller
2a1bac6b8a
core: fix selecting of best-default-route to consider only unicast routes
Fixes: 5d0d13f570 ('platform: add support for local routes')
2020-07-21 18:13:45 +02:00
Thomas Haller
5035687a7b
core: only expose "type unicast" routes on D-Bus
Currently, we would not mark non-unicast routes with their type, so they
would wrongly appear as unicast routes in the D-Bus API.

That is wrong. For now, just hide them.

Fixes: 5d0d13f570 ('platform: add support for local routes')
2020-07-21 13:52:26 +02:00
Beniamino Galvani
725fed01cf policy: block connection from autoconnect in case of failed dependency
A connection that fails due to dependency-failed is not able to
reconnect until the master connection activates again; when this
happens, the master clears the blocked reason for all its slaves in
activate_slave_connections() and tries to reconnect them. For this to
work, the slave should be marked as blocked when it fails with
dependency-failed.
2020-07-21 09:00:53 +02:00
Beniamino Galvani
fe2d93980b manager: fix race condition when resuming from sleep
If the device state change (to disconnected or unmanaged) triggered by
a sleep event happens after the wake, the devices becomes wrongly
unmanaged and it's necessary to manually manage it again, or restart
NM.

During the wake event we should disconnect the device_sleep_cb()
callback for all devices because we don't want to react to state
changes anymore; in particular we don't need to detect when the device
becomes disconnected to unmanage it.
2020-07-21 09:00:52 +02:00
Thomas Haller
6f29ed9f3f
device: fix setting %NULL iface in nm_device_update_from_platform_link()
Fixes: f004e7b1a7 ('device: mark ifindex/iface fields of NMDevicePrivate as const')
2020-07-20 16:11:48 +02:00
Thomas Haller
cb4fb0ac06
core: use nm_streq*() instead of strcmp() in "nm-device.c" and "nm-manager.c" 2020-07-20 13:55:22 +02:00
Thomas Haller
f004e7b1a7
device: mark ifindex/iface fields of NMDevicePrivate as const
"nm-device.c" is large and complicated. It's hard to find relevant places
that modify the ifindex,ip_ifindex,iface,ip_iface fields.

Mark them as const, to make that easier.
2020-07-19 12:38:17 +02:00
Thomas Haller
3f140afdfc
all: add trailing semicolon to NM_DEFINE_SINGLETON_REGISTER() 2020-07-19 12:15:41 +02:00
Thomas Haller
ba42189bb9
all: add trailing semicolon to NM_UTILS_LOOKUP_DEFINE()/NM_GOBJECT_PROPERTIES_DEFINE*() 2020-07-19 12:12:58 +02:00
Thomas Haller
b17e3cf707
all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Beniamino Galvani
0911d2a4ee core: fix check on master active-connection failure
The previous check was never satisfied, as the device is assigned to
the active-connection and realized early. Instead, check the
master_ready flag, which tells if the master is ready and, therefore,
if the slave has already been added to the master.

Before this commit, in some cases a device didn't detect that the
master failed and kept waiting forever.

https://bugzilla.redhat.com/show_bug.cgi?id=1845018
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/568
2020-07-17 08:56:28 +02:00
Beniamino Galvani
26e97fcd0d team: perform cleanup immediately when connecting to teamd fails
When NM fails to connect to teamd during an activation, it sets the
device state to FAILED. Eventually the device will become DISCONNECTED
and will call the ->deactivate() method that will perform the cleanup
of timers, teamd process and teamdctl instance.

However, in this way, when the device is DISCONNECTED timers are still
armed and can be triggered in the wrong state. Instead, perform the
cleanup immediately on failure.

https://bugzilla.redhat.com/show_bug.cgi?id=1856723
2020-07-16 09:36:26 +02:00
Antonio Cardace
d342af1925
core: fix generation of dependent local routes for VRFs
When using VRF devices we must pre-generate dependent local
routes in the VRF's table otherwise they will be incorrectly added
to the local table instead.

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

Fixes: a199cd2a7d ('core: add dependent local routes configured by kernel')
2020-07-15 10:57:49 +02:00
Thomas Haller
f0a39b517e
bond: avoid setting "active_slave" option without interface enslaved
Kernel will reject setting "active_slave", if the interface is not enslaved or not
up. We already handle that by setting the option whenever we enslave an interface.
However, we also must not set it initially, otherwise we get an ugly error log message:

    NetworkManager[939]: <debug> [1594709143.7459] platform-linux: sysctl: setting net:/sys/class/net/bond99/bonding/active_slave to eth1 (current value is )
    NetworkManager[939]: <error> [1594709143.7459] platform-linux: sysctl: failed to set bonding/active_slave to eth1: (22) Invalid argument
    NetworkManager[939]: <warn>  [1594709143.7460] device (bond99): failed to set bonding attribute active_slave to eth1
    ...
    kernel: bond99: (slave eth1): Device is not bonding slave
    kernel: bond99: option active_slave: invalid value (eth1)

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1856640

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/577
2020-07-14 19:13:39 +02:00
Thomas Haller
3a25b3bfc7
bond: log only skipped bond options if they are set in the profile 2020-07-10 16:45:37 +02:00