Commit graph

13086 commits

Author SHA1 Message Date
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
Thomas Haller
a5133e708e
ndisc/tests: relax assertion in "test-ndisc-fake.c"
Still assertion failures:

  ERROR:../src/ndisc/tests/test-ndisc-fake.c:375:test_preference_changed_cb: assertion failed (_a->timestamp >= _ts): (9 >= 10)
2020-07-07 22:32:35 +02:00
Thomas Haller
1b408e243d
core: fix treating route metric zero of IPv6 routes special
Userspace cannot add IPv6 routes with metric 0. Trying to do that, will
be coerced by kernel to route metric 1024. For IPv4 this is different,
and metric zero is commonly allowed.

However, kernel itself can add IPv6 routes with metric zero:

  # ip -6 route show table local
  local fe80::2029:c7ff:fec9:698a dev v proto kernel metric 0 pref medium

That means, we must not treat route metric zero special for most cases.
Only, when we want to add routes (based on user configuration), we must
coerce a route metric of zero to 1024.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/563
2020-07-07 16:14:58 +02:00
Yuri Chornoivan
4e33f8cd89
all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33:46 +02:00
Beniamino Galvani
77b6ce7d04 device: don't reset the MAC without ifindex
nm_device_cleanup() can be called when the device no longer has an
ifindex. In such case, don't try to reset the MAC address as that
would lead to an assertion failure.
2020-07-06 09:44:16 +02:00
Beniamino Galvani
47ec3d14d4 ovs: also set cloned MAC address via netlink
We already set the MAC of OVS interfaces in the ovsdb. Unfortunately,
vswitchd doesn't create the interface with the given MAC from the
beginning, but first creates it with a random MAC and then changes it.

This causes a race condition: as soon as NM sees the new link, it
starts IP configuration on it and (possibly later) vswitchd will
change the MAC.

To avoid this, also set the desired MAC via netlink before starting IP
configuration.

https://bugzilla.redhat.com/show_bug.cgi?id=1852106
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/483
2020-07-06 09:44:16 +02:00
Beniamino Galvani
5d4c8521a3 ovs: set MAC address on the bridge for local interfaces
When a user creates a ovs-interface with the same name of the parent
ovs-bridge, openvswitch considers the interface as the "local
interface" [1] and assigns the MAC address of the bridge to the
interface [2].

This is confusing for users, as the cloned MAC property is ignored in
some cases, depending on the ovs-interface name.

Instead, detect when the interface is local and set the MAC from the
ovs-interface connection in the bridge table.

[1] https://github.com/openvswitch/ovs/blob/v2.13.0/vswitchd/vswitch.xml#L2546
[2] https://github.com/openvswitch/ovs/blob/v2.13.0/vswitchd/bridge.c#L4744
2020-07-06 09:44:16 +02:00
Beniamino Galvani
5fa97d7796 initrd: write the hostname to stdout with --stdout
Don't try to open /run/NetworkManager/initrd when called with
--stdout, but instead write the hostname to the standard output.

Fixes: ff70adf873 ('initrd: save hostname to a file in /run')
2020-07-03 22:08:22 +02:00
Beniamino Galvani
3023c70e4e initrd: fix generating default BOOTIF= connection
There is a bug when parsing a BOOTIF= without any existing
connection. The generated connection doesn't have wired setting and
later we try to access it:

 # nm-initrd-generator --stdout -- BOOTIF=01-50-50-00-9f-21-21
  (nm-initrd-generator:1546): libnm-CRITICAL **: ((libnm-core/nm-setting-wired.c:205)): assertion '<dropped>' failed
  (nm-initrd-generator:1546): GLib-GObject-CRITICAL **: g_object_set: assertion 'G_IS_OBJECT (object)' failed

Fix this.

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

Fixes: 25a2b6e14f ('initrd: rework command line parsing')
2020-07-03 22:08:22 +02:00
Beniamino Galvani
79f70bf5d6 initrd: fix generation of MTU and cloned-mac-address for masters
Setting a MTU or a cloned MAC for bonds/bridges/teams fails with:

 # nm-initrd-generator -- bond=bond0:eno1,eno2:mode=802.3ad
    ip=192.168.1.5::192.168.1.254:255.255.255.0:MyServer:bond0:none::01:02:03:04:05:06
    bootdev=bond0 nameserver=192.168.1.1

 <warn> cmdline-reader: 'bond' does not support setting cloned-mac-address

Fix this.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/460
2020-07-03 22:02:34 +02:00
Thomas Haller
b2f03544a7
ndisc/tests: fix assertion in "test-ndisc-fake.c"
First I wanted to fix

  test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:373:test_preference_changed_cb: assertion failed (_a->timestamp == (data->timestamp1 + 3)): (9 == 10)

but that leads to a different failure:

  test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:375:test_preference_changed_cb: assertion failed (_a->lifetime == (9)): (10 == 9)

Instead, the start and end times must match exact (in their duration),
we only allow them to be shifted by up to one second.

Fixes: 8209095ee1 ('ndisc/tests: relax the assertion in "test-ndisc-fake.c"')
2020-07-03 19:29:46 +02:00
Sayed Shah
7337ab8959
all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +02:00
Thomas Haller
8209095ee1
ndisc/tests: relax the assertion in "test-ndisc-fake.c"
test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:373:test_preference_changed_cb: assertion failed (_a->timestamp == (data->timestamp1 + 3)): (9 == 10)
2020-07-03 10:34:15 +02:00
Beniamino Galvani
2c50438987 device: restart DHCP only for devices that are active or activating
do_sleep_wake() tries to restart DHCP for all devices, even ones that
are disconnecting. When a device is disconnecting, it still has a DHCP
client instance but we shouldn't restart it because it makes no sense;
and especially, the device could be already removed.

https://bugzilla.redhat.com/show_bug.cgi?id=1852612
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/561
2020-07-03 09:31:35 +02:00
Thomas Haller
3b896cc642
ndisc/tests: make assertion checks a macro and not a function in test-ndisc-fake
By having it a function, the assertion failure does not show the line
number of the origin. Make them a macro, so that we see where exactly it
failed.
2020-07-02 16:28:49 +02:00
Beniamino Galvani
4db4801038 supplicant,device: support AP isolation
Support setting the ApIsolate property of the supplicant interface
during association and resetting it to zero during disconnection.
2020-07-01 17:36:20 +02:00
Beniamino Galvani
dbfe219d5b all: add ap-isolation property to wifi setting
Add a new 'ap-isolation' property to the wifi setting, useful to
prevent communication between wireless clients.
2020-07-01 17:36:20 +02:00
Beniamino Galvani
47817a576c ifcfg-rh: add generic shvar getter and setter for ternary variables 2020-07-01 17:36:20 +02:00
Thomas Haller
03dc759026
modem: suppress deprecated warning from libmm for MM_MODEM_CAPABILITY_LTE_ADVANCED
On Ubuntu 20.10, we build against ModemManager 1.14.0 and get a compiler warning:

  ../src/devices/wwan/nm-modem-broadband.c: In function 'try_create_connect_properties':
  ../src/devices/wwan/nm-modem-broadband.c:492:2: error: 'MMModemCapabilityDeprecated' is deprecated [-Werror=deprecated-declarations]
    492 |  if (MODEM_CAPS_3GPP (ctx->caps)) {
        |  ^~

Suppress it.

An alternative would be to drop the flag entirely. It seems the flag
was never used (and never will be used). But if that's true, there is
little harm done checking it. If it's not true, we better keep checking
for older versions.

0cd76bf1c4
2020-06-30 18:00:33 +02:00
Thomas Haller
3d542b55ed
platform/tests: avoid test failures accepting route added signals
/route/ip6: NMPlatformSignalAssert: ../src/platform/tests/test-route.c:331, test_ip6_route(): failure to accept signal [0,2] times: ip6-route-changed-added ifindex 0 (3 times received)
2020-06-30 17:23:45 +02:00
Beniamino Galvani
5423a92b0f wifi: renew dynamic IP configuration after roaming
There are some APs that require a DHCP transaction before allowing
other traffic. This is meant to improve security by preventing the use
of static addresses. Currently we don't renew DHCP after roaming to a
new AP and this can lead to broken connectivity with APs that
implement the check described above. Also, even if unlikely, the new
AP could be in a different layer 3 network and so the old address
could be no longer valid.

Renew dynamic IP configuration after we detect the supplicant decided
to roam to a new AP. Note that we only trigger a DHCP client restart;
the DHCP client already implements the logic to renew the previous
address and fall back to a full request in case of NAK or timeout.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/449
2020-06-30 17:08:56 +02:00
Thomas Haller
13327555d6
ifcfg-rh: hard code the defaults for bridge settings in write_bridge_setting()
Code like "get_setting_default_uint (s_bridge, NM_SETTING_BRIDGE_FORWARD_DELAY)" looks
up the default value of the GObject property. That default value is
known at build type. Looking it up is an unnecessary overhead, for
something that is already known.

Also, the code isn't generic (meaning, it doesn't iterate of a set of
properties names and treats them without explicitly naming each
property). If we already name the property for which we want the default
value, we can just as well name the default value.

Additionally, add an assertion that what we would look up matches
to what we think is the default.
2020-06-30 16:30:38 +02:00
Thomas Haller
58d193432d
ifcfg-rh: use guint type for handling nm_setting_bridge_get_ageing_time() return value
It returns guint, not guint32. Use the appropriate type.
2020-06-30 16:30:37 +02:00
Thomas Haller
15ec888597
ifcfg-rh: use nm_gstring_add_space_delimiter() in write_bridge_setting() 2020-06-30 16:30:34 +02:00
Beniamino Galvani
071104124b device: clean up exported IP6 config when flushing addresses
After flushing addresses and routes, it's also necessary to update the
exported IP6 configuration.

https://bugzilla.redhat.com/show_bug.cgi?id=1848888
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/551

Fixes: e302f5ff77 ('device: flush IP configuration of slaves during activation')
2020-06-28 16:57:38 +02:00
Thomas Haller
824ad6275d
libnm/match: extend syntax for match patterns with '|', '&', '!' and '\\'
For simple matches like match.interface-name, match.driver, and
match.path, arguably what we had was fine. There each element
(like "eth*") is a wildcard for a single name (like "eth1").

However, for match.kernel-command-line, the elements match individual
command line options, so we should have more flexibility of whether
a parameter is optional or mandatory. Extend the syntax for that.

- the elements can now be prefixed by either '|' or '&'. This makes
  optional or mandatory elements, respectively. The entire match
  evaluates to true if all mandatory elements match (if any) and
  at least one of the optional elements (if any).
  As before, if neither '|' nor '&' is specified, then the element
  is optional (that means, "foo" is the same as "|foo").

- the exclamation mark is still used to invert the match. If used
  alone (like "!foo") it is a shortcut for defining a mandatory match
  ("&!foo").

- the backslash can now be used to escape the special characters
  above. Basically, the special characters ('|', '&', '!') are
  stripped from the start of the element. If what is left afterwards
  is a backslash, it also gets stripped and the remainder is the
  pattern. For example, "\\&foo" has the pattern "&foo" where
  '&' is no longer treated specially. This special handling of
  the backslash is only done at the beginning of the element (after
  the optional special characters). The remaining string is part
  of the pattern, where backslashes might have their own meaning.

This change is mostly backward compatible, except for existing matches
that started with one of the special characters '|', '&', '!', and '\\'.
2020-06-26 13:29:01 +02:00
Thomas Haller
fa56e52a4f
core/tests: add unit test for nm_utils_kernel_cmdline_match_check() 2020-06-26 13:22:05 +02:00
Thomas Haller
e0f4817148
core: move matching of kernel command line to separate function 2020-06-26 13:22:04 +02:00
Thomas Haller
3b4a4bef7b
supplicant: use NMStrBuf in wifi_freqs_to_string()
And don't access global data without atomic operations.
2020-06-26 09:29:58 +02:00
Thomas Haller
652e0c843b
supplicant: use nm_streq() in "nm-supplicant-config.c" 2020-06-26 09:29:58 +02:00
Beniamino Galvani
a39eb9ac14 initrd: set ipv6.method=auto when the autoconfiguration field is 'none'
The 7th field of:

 ip=<client-IP>:[<peer>]:<gateway-IP>:<netmask>:<client_hostname>:<interface>:{none|off|dhcp|on|any|dhcp6|auto6|ibft}:[:[<mtu>][:<macaddr>]]

specifies which kind of autoconfiguration to do. 'none' and 'off' mean
static addresses.

The old network module of dracut used to leave kernel IPv6
autoconfiguration enabled when IPv4 static addresses were
configured. With NM, this corresponds to enabling IPv6 auto method.

https://bugzilla.redhat.com/show_bug.cgi?id=1848943
2020-06-24 10:37:31 +02:00
Beniamino Galvani
f6d654b18f initrd: generate connections with IPv6 method 'auto' instead of 'ignore'
When the initrd generator creates a connection with IPv6 method
'ignore', the kernel will do IPv6 autoconfiguration on the
interface. However, it is preferable to let NetworkManager configure
the interface directly instead of relying on kernel. Therefore, change
the IPv6 method to 'auto'. Note that we still set ipv6.may-fail to
'yes' so that a failure during IPv6 autoconfiguration doesn't bring
down the interface.
2020-06-24 10:37:31 +02:00
Thomas Haller
27041e9f05
core: use nm_utils_strsplit_quoted() for splitting the kernel command line
The kernel command line supports escaping and quoting (at least,
according to systemd's parser, which is our example to follow).

Use nm_utils_strsplit_quoted() which supports that.
2020-06-23 00:42:37 +02:00