Commit graph

13746 commits

Author SHA1 Message Date
Thomas Haller
fd69080c9b
build/meson: cleanup dependencies for libnm-systemd-shared 2021-02-28 10:42:04 +01:00
Thomas Haller
a9540fb927
build/meson: drop libnm_log_core_dep dependency 2021-02-28 10:42:04 +01:00
Thomas Haller
309dccf5f9
build/meson: cleanup libnm-glib-aux dependencies
Avoid dependencies but explicitly link the static library where it is
used.

This also fixes that we linked libnm-log-core into
libnm-settings-plugin-ifcfg-rh.so, which duplicated the symbols
while it should used them from NetworkManager.
2021-02-28 10:42:04 +01:00
Thomas Haller
2665b91288
core: rename level_desc global variable
Symbols in header files should almost always have an "nm" prefix.

That is not purely cosmetic, because core modules (like libnm-device-plugin*.so
and libnm-settings-plugin*so) should re-use the symbols of the NetworkManager
binary. For NetworkManager we generate a linker version script to only expose
the symbols that are needed. It thereby excludes symbols that don't have an "nm"
prefix.

Hence, the plugins otherwise cannot reuse the global symbol.

The only reason that we currently don't have a linker error is because
we also link the logging static library into the plugin modules. That is
wrong, because we should not duplicate these symbols.
2021-02-28 10:42:03 +01:00
Thomas Haller
bdabc9e38c
build/meson: cleanup build for c-util and nettools helper libraries
We have a number of static helper libraries. When a user is using such a
library, they need to set the include search paths (-I) and link with
the static library at the right place.

The first part, the include search path, is now trivial. We no longer
add the individual search paths but everybody uses "-I. -Isrc/".

The second part means that when we build a shared library or an
executable that uses symbols from the static library, we need to link
it. But only then, and not earlier so that not multiple intermediate
build products (static libraries too) contain the same code. Note that
for libnm-device-plugin-*.so and other core plugins it's even that
those shared modules should not themselves link with the static
helpers. Instead, the need to use the symbols from NetworkManager.

Easy enough. Previously, we would sometimes define dependencies in
meson. But as it's really simple, I think that those dependencies
obfuscate more than help. Instead drop them, and only explicitly link
where we need it. The exception is libNetworkManagerTest_dep, which
is still a dependency. Maybe that dependency is fine, as it is much
later in the process. Or maybe that will also be replaced in the future.
2021-02-28 10:41:24 +01:00
Thomas Haller
8bfe1ebcec
build/introspection: cleanup dependencies for libnmdbus in meson 2021-02-24 12:50:25 +01:00
Thomas Haller
7b48d6bd31
build: remove shared/ directory 2021-02-24 12:49:13 +01:00
Thomas Haller
635d84b896
build: remove "shared/" from include search path
There is nothing left there.
2021-02-24 12:49:06 +01:00
Thomas Haller
d6681a0429
shared: move "nm-compat.[hc]" to "src/contrib/"
"nm-compat.h" is not intended to be used by NetworkManager itself.
Instead, it's intended to be copied into the source tree of VPN plugins,
as adapter for different libnm versions.

Move it to "src/contrib/".
2021-02-24 12:49:01 +01:00
Thomas Haller
63622a147a
shared: split and move "nm-vpn-plugin-macros.h"
This file was intended to be used by VPN plugins (by copying it).
However, it was also used internally.

Split the file, and move the internally used part to libnm-glib-aux.
The part that is only there for out of tree users, moves to
"nm-compat.h".
2021-02-24 12:48:56 +01:00
Thomas Haller
ad91579bb8
shared: move "nm-vpn-editor-plugin-call.h" to "src/contrib/" 2021-02-24 12:48:51 +01:00
Thomas Haller
fa288f65f6
shared: move "nm-vpn-plugin-utils.c" to "src/contrib/"
This file is not actually to be used by NetworkManager itself.
Instead, every (glib based) VPN plugin will want something like this,
hence we have a copy here.

Move it to a new directory "src/contrib/".
2021-02-24 12:48:46 +01:00
Thomas Haller
a03a03fbe9
libnm/tests: add static helper library "src/libnm-client-test/"
This helper code is already used by several of our unit tests.
Compile it as a separate library.

Previously, the source code lingered unmotivated under "shared/",
which is confusing.
2021-02-24 12:48:42 +01:00
Thomas Haller
9bba4871f3
build: move "libnm/" to "src/" and split it
Like with "libnm-core/", split "libnm/" into different directories for
the public headers, for the implementation and for the helper "aux"
library.
2021-02-24 12:48:37 +01:00
Thomas Haller
b53c50e778
shared: move "nm-test-utils.h" to "src/libnm-glib-aux/"
"nm-test-utils.h" is a header-only, helper library for our unit tests.
It was somewhat unmotivated in "shared/nm-utils", because all tests use
it, but it was not part of a "module".

Move it to "src/libnm-glib-aux/". It fits there very well. They both
have (only) a dependency on glib.
2021-02-24 12:48:33 +01:00
Thomas Haller
3906cc9cf4
build: move c-util/nettools library from "shared/" to "src/" 2021-02-24 12:48:28 +01:00
Thomas Haller
a8c34b9dcf
build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
Thomas Haller
9dc84b32b0
build: move "shared/nm-{glib-aux,log-null,log-core}" to "src/libnm-{glib-aux,log-null,log-core}" 2021-02-24 12:48:20 +01:00
Thomas Haller
4d12a6ac3d
build: move "shared/nm-{base,udev-aux}" to "src/libnm-{base,udev-aux}" 2021-02-24 12:48:19 +01:00
Thomas Haller
174bd45344
build/meson: include meson.build for tests at the end
We want that there is a clear hierarchy and dependency between
modules/directories.

But tests sometimes break that.

For example, "shared/nm-glib-aux/tests" link against libnm-glib-aux
and libnm-log-null. But "shared/nm-log-null" depends on "shared/nm-glib-aux".
Hence, for the test there is a circular dependency.

Break that, by including all tests at the end.

The alternative would be ugly in different ways.
2021-02-24 12:48:18 +01:00
Thomas Haller
2439374457
build: move "shared/nm-platform" to "src/libnm-platform" 2021-02-24 12:48:17 +01:00
Thomas Haller
39225258d6
build: move "shared/systemd" to "src/libnm-systemd-shared" 2021-02-24 12:48:16 +01:00
Thomas Haller
b55710d6a6
shared: rename "libnm-systemd-logging-stub.la" to "libnm-log-null.la"
This is really just a different implementation of
"nm-glib-aux/nm-logging-fwd.h", that parallels libnm-log-core.

It's also not only useful to shared/systemd, but also share/nm-platform,
which also requires linking with a logging backend.
2021-02-24 12:48:16 +01:00
Wen Liang
6b50d52ed0
docs: improve manual page about ipv4.routes
Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/757
2021-02-23 22:04:16 +01:00
Thomas Haller
9e7af31454
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
2021-02-23 14:18:02 +01:00
Beniamino Galvani
f5d78c2d28 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'
2021-02-23 10:24:18 +01:00
Beniamino Galvani
d233314ce1 supplicant: print interface capabilities 2021-02-23 10:22:09 +01:00
Beniamino Galvani
f7f4db156f supplicant: detect the SAE interface capability
There isn't a global SAE capability in wpa_supplicant, use the
per-interface one.
2021-02-23 10:22:09 +01:00
Thomas Haller
5747bdb8b8
wwan: fix leaking "bearer" in connect_ready()
Fixes: 105ee6e5a9 ('device: fix crash by handling connection cancellation')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/669
2021-02-23 07:23:41 +01:00
Thomas Haller
e3a7f29e2a
iwd: make static variable in object_compare_interfaces() "const" 2021-02-22 13:15:58 +01:00
Jan Palus
2e0752b1bf
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')
2021-02-22 13:11:16 +01:00
Thomas Haller
1e81827e6f
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')
2021-02-21 20:08:13 +01:00
Georg Müller
ba8c61fe9a supplicant: disable wps in wpa supplicant if disabled in config
Before this commit, in AP mode, WPS is started by default and there is no
possibility to disable it. The methods provided as WPS sources seem to
differ from device to device. With some Wifi USB sticks running in AP mode,
the WPS config methods contain "Keypad". Then, I get a pin entry dialog on
Windows machines, even if no pin is configured.

This merge request wires the existing 802-11-wireless-security.wps-method
with wpa_supplicant's configuration to allow disabling WPS.
2021-02-19 14:34:19 +01:00
Thomas Haller
341b6e0704
all: change G_LOG_DOMAIN to "nm"
glib requires G_LOG_DOMAIN defined so that log messages are labeled
to belong to NetworkManager or libnm.

However, we don't actually want to use glib logging. Our library libnm
MUST not log anything, because it spams the user's stdout/stderr.
Instead, a library must report notable events via its API. Note that
there is also LIBNM_CLIENT_DEBUG to explicitly enable debug logging,
but that doesn't use glib logging either.

Also, the daemon does not use glib logging instead it logs to syslog.
When run with `--debug`.

Hence, it's not useful for us to define different G_LOG_DOMAIN per
library/application, because none of our libraries/applications should
use glib logging.

It also gets slightly confusing, because we have the static library like
`src/libnm-core-impl`, which is both linked into `libnm` (the library)
and `NetworkManager` (the daemon). Which logging domain should they use?

Set the G_LOG_DOMAIN to "nm" everywhere. But no longer do it via `-D`
arguments to the compiler.

See-also: https://developer.gnome.org/glib/stable/glib-Message-Logging.html#G-LOG-DOMAIN:CAPS
2021-02-18 19:46:57 +01:00
Thomas Haller
243051a8a6
libnm/build: always compile both crypto backends if library available
We want to see that both backends can actually compile -- at least,
if we have the dependencies detected.
2021-02-18 19:46:54 +01:00
Thomas Haller
fdf9614ba7
build: move "libnm-core/" to "src/" and split it
"libnm-core/" is rather complicated. It provides a static library that
is linked into libnm.so and NetworkManager. It also contains public
headers (like "nm-setting.h") which are part of public libnm API.

Then we have helper libraries ("libnm-core/nm-libnm-core-*/") which
only rely on public API of libnm-core, but are themself static
libraries that can be used by anybody who uses libnm-core. And
"libnm-core/nm-libnm-core-intern" is used by libnm-core itself.

Move "libnm-core/" to "src/". But also split it in different
directories so that they have a clearer purpose.

The goal is to have a flat directory hierarchy. The "src/libnm-core*/"
directories correspond to the different modules (static libraries and set
of headers that we have). We have different kinds of such modules because
of how we combine various code together. The directory layout now reflects
this.
2021-02-18 19:46:51 +01:00
Thomas Haller
39c3eacb7d
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)
2021-02-18 17:40:27 +01:00
Beniamino Galvani
099ce63888 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.
2021-02-17 11:20:18 +01:00
Beniamino Galvani
97833237bf initrd: accept 'infinity' as argument to rd.net.timeout.dhcp 2021-02-17 11:20:18 +01:00
Beniamino Galvani
7e126fe898 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
2021-02-17 11:20:17 +01:00
Thomas Haller
e258410c87
initrd: cleanup parsing DNS in reader_parse_ip() 2021-02-17 08:48:41 +01:00
Thomas Haller
98348ee539
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.
2021-02-16 13:58:31 +01:00
Thomas Haller
7bf2ddf73f
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.
2021-02-16 13:52:52 +01:00
Thomas Haller
ecdbb1ab84
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.
2021-02-15 21:11:13 +01:00
Andrew Zaborowski
5ccb8ce17a
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')
2021-02-12 14:36:30 +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