Commit graph

75 commits

Author SHA1 Message Date
Thomas Haller
04aa208e9a
platform/tests: relax unit test for setting IFLA_BR_FORWARD_DELAY/forward_delay
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/665

Fixes: e9278d8659 ('platform/tests: ignore failure for adding bridge with iproute2')
(cherry picked from commit 1e81827e6f)
2021-03-12 11:20:43 +01:00
Beniamino Galvani
b4ba6e7af5 devices: fail optional-802.1X connections if supplicant disappears
802-1x.optional=yes means that NM should tolerate a failure or a
timeout of the 802.1X authentication and should keep the connection
up. Even if the authentication doesn't succeed, NM keeps the
supplicant running so that it can continue trying.

If the supplicant disappears because it crashed or was killed
externally, NM should fail the connection so that it can be retried.

The current code is wrong also because after releasing the supplicant
interface, it calls wired_auth_cond_fail() which tries to connect a
signal to priv->supplicant.iface (which is NULL).

https://bugzilla.redhat.com/show_bug.cgi?id=1934291
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/776
(cherry picked from commit 840e54a96c)
2021-03-12 09:53:56 +01:00
Beniamino Galvani
fafefc71f8 initrd: set multi-connect=single for connections with static IP
We don't want to have multiple devices up with the same static IP. Set
multi-connect=single.

https://bugzilla.redhat.com/show_bug.cgi?id=1915493
(cherry picked from commit c27626a0ce)
2021-03-12 09:53:48 +01:00
Beniamino Galvani
748d7bf15f initrd: set the bootif MAC in existing connection with ifname
If an existing connection has an interface name set and the generator
finds a BOOTIF argument, it creates a new connection for BOOTIF.

Instead, the generator should set the MAC in the existing connection;
this sounds more correct and it is what the network-legacy module
does.

https://bugzilla.redhat.com/show_bug.cgi?id=1915493
(cherry picked from commit 389575a6b1)
2021-03-12 09:53:47 +01:00
Beniamino Galvani
1bf1a902be initrd: fix may-fail for IPv6
(cherry picked from commit 5f73646524)
2021-03-12 09:53:47 +01:00
Beniamino Galvani
4c1e60549a bond: restore MAC on release only when there is a cloned MAC address
Currently we unconditionally reset the MAC to the previous value after
releasing ports. This has some disadvantages:

 - by default, after the last port is removed the bond will have one
   of the previous port's address, which could conflict with the port;

 - in some cases, changing the bond MAC is not possible. For example
   when the bond is active-backup and has fail_over_mac=1|2. In such
   case the netlink call succeeds, but the address doesn't
   change; then NM would keep waiting for some time.

Don't try to restore the MAC unless the bond connection has a cloned
MAC set.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/775
(cherry picked from commit 190fd9aa9f)
2021-03-09 10:37:54 +01:00
Beniamino Galvani
43d16d2cd6 initrd: apply the MTU from bond= argument to the bond connection
Currently the MTU specified in:

 bond=<bondname>[:<bondslaves>:[:<options>[:<mtu>]]]

gets applied to the bond ports. Instead it should be applied to the
bond itself.

Fixes: ecc074b2f8 ('initrd: add command line parser')

https://bugzilla.redhat.com/show_bug.cgi?id=1932502
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/767
(cherry picked from commit 8df3ef5063)
2021-03-08 10:33:24 +01:00
Jonathan Lebon
53473d0b79
core/dns: emit CONFIG_CHANGED signal even if caching
With systemd-resolved, NetworkManager considers `/etc/resolv.conf`
unmanaged. This breaks hostname lookups in a subtle way: when a new
connection comes online, NM will initiate the hostname lookup *before*
propagating DNS updates to systemd-resolved, which of course will cause
the request to fail. And because NM doesn't update `/etc/resolv.conf`,
it doesn't emit a `CONFIG_CHANGED` signal which would've restarted the
lookup.

Fix this by emitting a signal also when using a caching DNS plugin.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/770
(cherry picked from commit 1c0932a6e6)
2021-03-04 17:31:29 +01:00
zsien
a1223606fb
wifi: fix SpecificObject of ActiveConnection not updated after WiFi roaming
The SpecificObject property of ActiveConnection should be updated after WiFi roaming.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/768
(cherry picked from commit 29ba46b722)
2021-03-04 17:31:28 +01:00
Thomas Haller
199ac9b146
bond: avoid logging warning to set "ad_actor_system=00:00:00:00:00:00"
The bond option ad_actor_system only matters (and is available) with
mode=802.3ad.

When you create a new bond, the sysctl value will be set to "00:00:00:00:00:00".
So this seems to be a valid value, and in fact the default value for
this option. However, kernel will fail with EINVAL to set the sysctl to
"00:00:00:00:00:00". Kernel fails both if the value is already
"00:00:00:00:00:00" (i.e. setting the same value results in an error) and
it also fails otherwise (i.e. we cannot ever reset the value to
"00:00:00:00:00:00", at least not via sysfs).

Avoid the warning in the common case, where the value is already as
expected.

Otherwise, we still get the warning and won't be able to set the right
value. But this is really a limitation of the kernel API where we cannot
do anything about it (in NetworkManager).

https://bugzilla.redhat.com/show_bug.cgi?id=1923999
(cherry picked from commit 9e7af31454)
2021-02-23 14:18:33 +01:00
Beniamino Galvani
b513342427 supplicant: enable WPA3 for WPA-PSK connections
A connection with key-mgmt=wpa-psk should be able to connect to WPA,
WPA2 and WPA3 APs, choosing the best candidate automatically.

Also pass SAE (WPA3) key-mgmt to wpa_supplicant when it is supported.

For example, I now get this when connecting to a WPA2 network:
<info>  [1613749711.2915] Config: added 'key_mgmt' value 'WPA-PSK WPA-PSK-SHA256 FT-PSK SAE FT-SAE'

(cherry picked from commit f5d78c2d28)
2021-02-23 10:27:14 +01:00
Beniamino Galvani
0109328085 supplicant: print interface capabilities
(cherry picked from commit d233314ce1)
2021-02-23 10:27:14 +01:00
Beniamino Galvani
4e018bef68 supplicant: detect the SAE interface capability
There isn't a global SAE capability in wpa_supplicant, use the
per-interface one.

(cherry picked from commit f7f4db156f)
2021-02-23 10:27:14 +01:00
Jan Palus
87218ee2a9
iwd: terminate interface_order array with NULL
fixes segfault with iwd backend after upgrade to NetworkManager 1.30.0

Signed-off-by: Jan Palus <jpalus@fastmail.com>

Fixes: 43fd93d8f4 ('iwd: Order objects from g_dbus_object_manager_get_objects')
(cherry picked from commit 2e0752b1bf)
2021-02-22 13:12:55 +01:00
Thomas Haller
9e16c4cc94
platform/tests: relax check for signals in test_ip6_route()
/route/ip6: NMPlatformSignalAssert: ../src/core/platform/tests/test-route.c:449, test_ip6_route(): failure to accept signal one time: 'ip6-route-changed-added' ifindex 0 (2 times received)

(cherry picked from commit 39c3eacb7d)
2021-02-18 17:47:13 +01:00
Beniamino Galvani
329902339e initrd: support the rd.net.dhcp.retry argument
Since we always set autoconnect-retries=1, use the value of
rd.net.dhcp.retry as a multiplier for the DHCP timeout.

(cherry picked from commit 099ce63888)
2021-02-17 11:29:26 +01:00
Beniamino Galvani
772b213321 initrd: accept 'infinity' as argument to rd.net.timeout.dhcp
(cherry picked from commit 97833237bf)
2021-02-17 11:29:26 +01:00
Beniamino Galvani
936c7c9a78 initrd: set autoconnect-retries=1 and increase default DHCP timeout
By default a connection is retried 4 times before it is blocked from
autoconnecting. This means that if a user specifies an explicit DHCP
timeout in the initrd command line, NM will wait up to 4 times more.

Instead, set the "connection.autoconnect-retries" property of
connections always to 1, so that NM only waits for the time
specified.

Before this commit a default DHCP connection would take at most (45 x
4) seconds. Since the multiplier is now only 1, also increase the DHCP
timeout to have a total time of (90 x 1) seconds, which is the half
than before.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/559
(cherry picked from commit 7e126fe898)
2021-02-17 11:29:26 +01:00
Thomas Haller
2e00d161b2
wireguard: prefer last resolved IP from resolving endpoint from DNS
We periodically re-resolve the DNS name for entpoints. Since WireGuard
has no concept of being connected, we want to eventually pick up
if the DNS name resolves to a different IP address.

However, on resolution failure, we will never clear the endpoint we
already have. Thus, resolving names can only give a better endpoint,
not remove an IP address entirely.

DNS names might do Round-Robin load distribution and the name of the
endpoint might resolve to multiple IP addresses. Improve to stick to
the IP address that we already have -- provided that the IP address
is still among the new resolution result. Otherwise, we continue to
pick the first IP address that was resolved.

(cherry picked from commit 98348ee539)
2021-02-16 14:14:46 +01:00
Thomas Haller
29336aa2e2
platform: ensure NM_SOCK_ADDR_UNION_INIT_UNSPEC() fully initializes union
In C, initialization of a union does not define that excess memory
is initialized. Ensure that, by initializing the largest member of the
NMSockAddrUnion union.

(cherry picked from commit 7bf2ddf73f)
2021-02-16 14:14:46 +01:00
Thomas Haller
4113e93b3b
platform/tests: skip tests if "unshare(CLONE_NEWNET|CLONE_NEWNS)" fails
Inside a podman container (without `--priviledged`) we don't have
permissions for "unshare(CLONE_NEWNET|CLONE_NEWNS)".

It's not useful to fail tests in environments where they cannot run.
Skip them.

(cherry picked from commit ecdbb1ab84)
2021-02-15 21:18:04 +01:00
Andrew Zaborowski
210d2696a9
iwd: Fix the leaks in get_agent_request_network_path
Don't request new copies of strings from g_variant_get() to avoid
leaking memory as pointed out by Thomas Haller.

Fixes: dc0e31fb70 ('iwd: Add the wifi.iwd.autoconnect setting')
(cherry picked from commit 5ccb8ce17a)
2021-02-15 09:49:38 +01:00
Andrew Zaborowski
190ed7b2c9
iwd: Fix agent DBus method parameter types
The object path DBus type wasn't being used correctly in the parameters
signatures, fix them.
2021-02-11 16:34:09 +01:00
Andrew Zaborowski
c8b283b818
settings: Fix REASON_CLEAR_DEFAULT_WIRED comment typos 2021-02-11 16:34:08 +01:00
Thomas Haller
5ca018c0db
lldp/tests: try workaround failure with ioctl(TUNSETIFF)
On copr build, it seems possible that the ioctl fails with

  ERROR: src/core/devices/tests/test-lldp - Bail out! NetworkManager:ERROR:src/core/devices/tests/test-lldp.c:823:_test_recv_fixture_setup: assertion failed (errno == 0): (1 == 0)

(1 is EPERM). Unclear why this happens. But as it only affects the
test setup, retry a few times.
2021-02-11 16:04:46 +01:00
Thomas Haller
4b874019ad
dhcp: downgrade logging messages for DHCP to <debug>
Granted, for debugging this information is useful. However, to actually
debug an issue thoroughly, level=TRACE is anyway required. There is simply
no way how we can log useful debug information and not flood logging
messages for regular use.

For example, logging the DHCP lease options can easily print 30 lines.
And this, every time you get a lease update (e.g. every 30 minutes) and
for every interface that does DHCP.

It's simply too verbose. Downgrade the logging level.

Yes, now our default <info> level is even less useful to understand what
is going on. But the majority of time, users don't care so not spamming
the log is more important.

However, we still log the DHCP event (and the IP address) with <info>
level.
2021-02-11 14:33:32 +01:00
Thomas Haller
24abf13239
dhcp: binary search in nm_dhcp_option_find()
Let's use binary search.

Test patch:

    diff --git a/src/core/dhcp/tests/test-dhcp-utils.c b/src/core/dhcp/tests/test-dhcp-utils.c
    index 9b54e2cd0228..007993341672 100644
    --- a/src/core/dhcp/tests/test-dhcp-utils.c
    +++ b/src/core/dhcp/tests/test-dhcp-utils.c
    @@ -788,6 +788,24 @@ NMTST_DEFINE();
     int
     main(int argc, char **argv)
     {
    +    int i;
    +    guint idx;
    +    guint c;
    +
    +    idx = 0;
    +    c = 0;
    +    for (i = 0; i < 1000000; i++) {
    +        const guint option = _nm_dhcp_option_dhcp4_options[idx % G_N_ELEMENTS(_nm_dhcp_option_dhcp4_options)].option_num;
    +
    +        idx += 2010055757;
    +
    +        if (nm_dhcp_option_find(AF_INET, option)->name)
    +            c++;
    +    }
    +    g_print(">%u\n", c);
    +
    +    return 0;
    +
         nmtst_init_assert_logging(&argc, &argv, "WARN", "DEFAULT");

         g_test_add_func("/dhcp/generic-options", test_generic_options);

Build:

  CFLAGS='-O2' ./autogen.sh --with-more-asserts=0
  make -j 10 src/core/dhcp/tests/test-dhcp-utils && \
    src/core/dhcp/tests/test-dhcp-utils && \
    perf stat -r 200 -B src/core/dhcp/tests/test-dhcp-utils

Before:

 Performance counter stats for 'src/core/dhcp/tests/test-dhcp-utils' (200 runs):

             82.83 msec task-clock:u              #    0.994 CPUs utilized            ( +-  0.21% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
               579      page-faults:u             #    0.007 M/sec                    ( +-  0.03% )
       264,676,245      cycles:u                  #    3.195 GHz                      ( +-  0.06% )
       544,792,266      instructions:u            #    2.06  insn per cycle           ( +-  0.00% )
       151,624,848      branches:u                # 1830.472 M/sec                    ( +-  0.00% )
         1,083,780      branch-misses:u           #    0.71% of all branches          ( +-  0.01% )

          0.083328 +- 0.000178 seconds time elapsed  ( +-  0.21% )

After:

 Performance counter stats for 'src/core/dhcp/tests/test-dhcp-utils' (200 runs):

             39.21 msec task-clock:u              #    0.987 CPUs utilized            ( +-  0.57% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
               579      page-faults:u             #    0.015 M/sec                    ( +-  0.03% )
       115,396,123      cycles:u                  #    2.943 GHz                      ( +-  0.23% )
       137,664,630      instructions:u            #    1.19  insn per cycle           ( +-  0.00% )
        25,866,025      branches:u                #  659.597 M/sec                    ( +-  0.00% )
         1,919,616      branch-misses:u           #    7.42% of all branches          ( +-  0.12% )

          0.039717 +- 0.000227 seconds time elapsed  ( +-  0.57% )
2021-02-11 13:00:18 +01:00
Thomas Haller
1cbe926c20
dhcp: rework DHCP options to not carry around option array
Previously, we would pass around the list of options. However,

- that isn't too nice to read. Also, usually when we want to treat
  IP address families generically, then we have an addr_family argument.
  Having to first resolve the addr_family to another set of variables
  is inconvenient.

- the option array itself doesn't have enough information. For example,
  we don't know how many elements there are, we don't know which address
  family it is (unless we compare it to one of the two well known
  lists).
  For example, I'd like to do a binary search for the option. But that's
  not immediately possible, because the length is unknown.

- in practice, there are only two address families: AF_INET and
  AF_INET6. It is extremely unlikely that we will require a third
  DHCP options list, and even if we had that, the addr_family argument
  still abstracts them nicely.
  We also don't need two different lists for one DHCP type. While that
  would currently be possible (and afterwards not anymore), it would
  be wrong to do.

- also add a new accessor nm_dhcp_option_find() to find the NMDhcpOption
  instance by option number.
2021-02-11 12:26:18 +01:00
Thomas Haller
53f137af6e
dhcp/nettools: accept any number of trailing NULs in string options
https://tools.ietf.org/html/rfc2132#section-2 says:

   Options containing NVT ASCII data SHOULD NOT include a trailing NULL;
   however, the receiver of such options MUST be prepared to delete trailing
   nulls if they exist.

It speaks in plurals.
2021-02-11 09:23:20 +01:00
Thomas Haller
3b8882b978
dhcp/nettools: use NMStrBuf in lease_save() 2021-02-11 09:23:19 +01:00
Thomas Haller
4707cf5fab
dhcp/nettools: cleanup lease_parse_search_domains() 2021-02-11 09:23:19 +01:00
Thomas Haller
8366fd87b9
dhcp/nettools: make data pointer const 2021-02-11 09:23:18 +01:00
Thomas Haller
ce72563a8c
dhcp/nettools: cleanup nm_dhcp_lease_data_parse_search_list() 2021-02-11 09:23:17 +01:00
Thomas Haller
6e0d2e5850
dhcp/nettools: move nm_dhcp_lease_data_parse_search_list() to nm-dhcp-utils.c 2021-02-11 09:23:16 +01:00
Thomas Haller
67dd25a396
shared,dhcp: add _nm_utils_ip4_get_default_prefix0() helper 2021-02-11 09:23:15 +01:00
Thomas Haller
94e474fa62
dhcp/nettools: cleanup lease_parse_routes() 2021-02-11 09:23:15 +01:00
Thomas Haller
2be43d79f7
dhcp/nettools: refactor parsing of DHCP lease (ntps) 2021-02-11 09:23:14 +01:00
Thomas Haller
f986d409f9
dhcp/nettools: cleanup lease_parse_address_list() 2021-02-11 09:23:14 +01:00
Thomas Haller
30911a305f
dhcp/nettools: cleanup lease_parse_address() 2021-02-11 09:23:13 +01:00
Thomas Haller
58b3b7ec3c
dhcp/nettools: refactor parsing of DHCP lease (server-id)
No change in behavior.
2021-02-11 09:23:12 +01:00
Thomas Haller
6850e3640e
dhcp/nettools: refactor parsing of DHCP lease (broadcast)
No change in behavior.
2021-02-11 09:23:12 +01:00
Thomas Haller
a24b7287d8
dhcp/nettools: validate domain-name option (15) differently 2021-02-11 09:23:12 +01:00
Thomas Haller
94c6f3c14e
dhcp/nettools: refactor parsing of DHCP lease (domain-name)
No change in behavior.
2021-02-11 09:23:11 +01:00
Thomas Haller
6c8a9e8bd6
dhcp/nettools: validate nis-domain option (40) differently
Previously, we would check that all characters are ASCII. But we would
also accept NUL characters (and truncate on the first NUL).

Now:

- reject any NUL characters inside the string (except trailing NUL).

- accept all characters, and if necessary backslash-encode non UTF-8.
2021-02-11 09:23:11 +01:00
Thomas Haller
0c93bff179
dhcp/nettools: refactor parsing of DHCP lease (nis-domain) 2021-02-11 09:23:10 +01:00
Thomas Haller
0ef37431cf
dhcp/nettools: validate root-path option (17) to not contain any NUL characters
And make it UTF-8 (by backslash escaping).
2021-02-11 09:23:10 +01:00
Thomas Haller
f2885cdf02
dhcp/nettools: refactor parsing of DHCP lease (root-path) 2021-02-11 09:23:10 +01:00
Thomas Haller
eb16cb6563
dhcp/nettools: validate proxy-autodiscovery option (252) to not contain any NUL characters 2021-02-11 09:23:09 +01:00
Thomas Haller
8f7a2a1ea0
dhcp/nettools: refactor parsing of DHCP lease (wpad) 2021-02-11 09:23:09 +01:00
Thomas Haller
784932550c
dhcp/nettools: validate and normalize Host Name Option (12)
The hostname is in the end a string, which means it must be in a known,
sensible encoding (UTF-8). Previously, we would not ensure the encoding,
nor that the hostname was valid.

Fix that. Follow what systemd does with lease_parse_domain().

See-also: https://tools.ietf.org/html/rfc2132#section-3.14
2021-02-11 09:23:09 +01:00