Commit graph

13118 commits

Author SHA1 Message Date
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
Thomas Haller
6a923a5d57
device/bond: rework setting of arp_ip_target bond options
- the arp_ip_target option in the settings might not have normalized
  IP addresses or duplicates. If there would be duplicates, setting
  them twice would fail with EINVAL. Hence, first normalize them
  and make them unique.

- if what we want to set is identical to what is already set, don't
  do anything.
2020-07-10 16:42:23 +02:00
Beniamino Galvani
4d6ea18de4 device: reset SR-IOV parameters on activation failure
SR-IOV parameters are reset when deactivating a connection; do the
same also on failure.

https://bugzilla.redhat.com/show_bug.cgi?id=1819587
2020-07-10 10:19:09 +02:00
Beniamino Galvani
74ccda8a71 device: allow queuing SR-IOV operation from a callback
Keep priv->sriov.pending set during the callback set so that it
becomes possible to insert a new operation from the callback itself.
2020-07-10 10:19:09 +02:00
Beniamino Galvani
6fcb077a98 device: clear queued sriov operation on dispose
When dispose() is called, there can't be any pending operation because
they keep a reference to the device. Instead, there can be a a queued
operation not yet executed. Destroy it.
2020-07-10 10:19:09 +02:00
Beniamino Galvani
63a932b851 platform: do not rely on the presence of sriov_totalvfs sysfs file
The file doesn't exist for all interfaces that support SR-IOV. In
particular, netdevsim devices support SR-IOV but don't expose the
file.
2020-07-10 10:19:08 +02:00
Beniamino Galvani
ca3d0a8f06 initrd: generate ipv6.method=auto for ip=dhcp6
When a 'ip=auto6' option is passed to kernel, the old dracut network
module only sets accept_ra in kernel and wait for the address to
appear. Instead, with a 'ip=dhcp6' option it starts 'dhclient -6',
leaving accept_ra to the initial value (that is already 1). So
'ip=dhcp6' in practice does kernel IPv6 autoconf and DHCPv6 at the
same time, without honoring the 'Managed' flag of the router
advertisement.

It seems that the only reason to have distinct 'auto6' and 'dhcp6'
options was that network module did not support starting DHCPv6 only
when necessary based on the M flag of the RA; so the user had to
specify if DHCPv6 was needed or not.

Given that 1) NM is smarter and can start DHCPv6 only when needed by
RA; 2) DHCPv6 alone only gets a /128 address without a prefix route
and so it's not useful; then it makes sense to generate a connection
with 'ipv6.method=auto' for both 'ip=auto6' and 'ip=dhcp6'.

https://bugzilla.redhat.com/show_bug.cgi?id=1854323
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/571
2020-07-09 14:47:07 +02:00
Thomas Haller
4a7da1ca4b
shared: merge nm-glib-aux/nm-json.[hc] into nm-json-aux.[hc]
They serve a similar purpose.

Previously, nm-json-aux.h contained the virtual function table for accessing
the dynamically loaded libjansson. But there is no reason why our own
helper functions from nm-json.h cannot be there too.
2020-07-09 11:47:06 +02:00
Thomas Haller
bbb1f5df2f
libnm: always build libnm with JSON validation
We anyway load libjansson with dlopen(), and already before it could
happen that libjansson is not available. In that case, we would not
crash, but simply proceed without json validation.

Since libnm-core no longer uses libjansson directly, but only via
"nm-glib-aux/nm-json.h", we can just always compile with that, and use
it at runtime. That means, libjansson is not a build dependency for
libnm anymore, so we don't need a compile time check.

Note that if you build without libjansson, then JANSSON_SONAME is
undefined, and loading it will still fail at runtime. So, even if
we now always build with all our code enabled, it only works if you
actually build with libjansson. Still, it's simpler to drop the
conditional build, as the only benefit is a (minimally) smaller
build.
2020-07-09 11:47:06 +02:00
Antonio Cardace
3e5fc04df3
core: add dependent local routes configured by kernel
Pre-generate routes in the local table that are configured
by kernel when an ip-address is assigned to an interface.

This helps NM taking into account routes that are not to be deleted
when a connection is reapplied (or deactivated) on an interface instead of only
ignoring (when pruning) IPv6 routes having metric 0 and routes belonging
to the local table having 'kernel' as proto.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 18:01:55 +02:00
Thomas Haller
a83622f7d0
platform: skip metric-0 IPv6 routes in nm_platform_ip_route_sync()
@routes are the list of routes we want to configure. This contains
routes from DHCP and manual routes in the profile. It also contains
externally present routes, including the metric=0 routes in the local
table.

Trying to add an IPv6 route with metric zero adds instead a route with
metric 1024.

Usually, we wouldn't do that, because that route was present externally,
so it possibly is still present (in the platform cache) during sync and
we skip the addition. However, there is a race where the external route
might just disappear and we'd add a route with metric 1024.

Avoid that.
2020-07-08 17:18:44 +02:00
Antonio Cardace
c5496f7372
nm-device: change route table sync mode behaviour
NM will now sync all tables when a connection has specified
at least 1 local route in 'ipv[4|6].routes' to correctly
reconcile local routes when reapplying connections on a device.

If the connection has no local routes only the main table will be
taken into account preserving the previous NM's behaviour.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:37 +02:00
Antonio Cardace
9ecc27f6d3
platform: do not prune kernel added routes
IPv6 routes having metric 0 and routes having rt_source == kernel
are entirely managed by kernel, NM should not try to remove them.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:36 +02:00
Antonio Cardace
cd89026c5f
core: add dependent multicast route configured by kernel for IPv6
Pre-generate the device multicast route in the local table that are configured
by kernel when an ipv6-address is assigned to an interface.

This helps NM taking into account routes that are not to be deleted
when a connection is reapplied on an interface.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:36 +02:00
Antonio Cardace
04878193f7
platform: parse route type from netlink messages
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:36 +02:00
Antonio Cardace
d67ad4c86b
platform: always display route type when calling nmp_object_to_string()
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:35 +02:00
Beniamino Galvani
b9ce5ae9d7
ppp: fix taking control of link generated by kernel
NetworkManager can't control the name of the PPP interface name
created by pppd; so it has to wait for the interface to appear and
then rename it. This happens in nm_device_take_over_link() called by
nm-device-ppp.c:ppp_ifindex_set() when pppd tells NM the ifindex of
the interface that was created.

However, sometimes the initial interface name is already correct, for
example when the connection.interface-name is ppp0 and this is the
first PPP interface created.

When this happens, nm_device_update_from_platform_link() is called on
the NMDevicePPP and it sets the device ifindex. Later, when pppd
notifies NM, nm_device_take_over_link() fails because the ifindex is
already set:

 nm_device_take_over_link: assertion 'priv->ifindex <= 0' failed

Make nm_device_take_over_link() more robust to cope with this
situation.

https://bugzilla.redhat.com/show_bug.cgi?id=1849386
2020-07-08 15:10:35 +02:00
Beniamino Galvani
d0d35aa278 platform: support creation of prio qdisc
Support the creation of parameterless 'prio' qdiscs. The kernel needs
a TCA_OPTIONS attribute initialized with default values. We currently
don't support modifying the qdisc parameters.
2020-07-08 09:43:06 +02:00