Commit Graph

30304 Commits

Author SHA1 Message Date
Ana Cabral
e2ee0e6a0d core/wwan: ensure correct conditions before signal emission
Currently, ip4 new config signal is being emitted twice, due
to the lack of a barrier to a possible situation. This
commit includes this.

This fixes a crash on NMCI tests due to an assertion failure,
now it will not go ahead in the function anymore if it is under the
undesired conditions.

The backtrace of the crashes can be found at
https://bugzilla.redhat.com/show_bug.cgi?id=2028385
2022-01-25 17:15:17 +01:00
Ana Cabral
b88ce6a317 core/wwan: fix log domain 2022-01-25 17:15:17 +01:00
Thomas Haller
c6223c5a41 contrib/rpm: fix spec file for CentOS7/RHEL7 for "Suggests:"
Seems "Suggests:" is not supported.
2022-01-25 16:12:24 +01:00
Lubomir Rintel
68f500f5ce initrd: add support for rd.znet_ifnames
This uses interface names specified rd.znet_ifnames on kernel command line
instead of automatically generated names if possible.

Accompanied by a test.

https://bugzilla.redhat.com/show_bug.cgi?id=1980387
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1070
2022-01-25 14:57:22 +01:00
Thomas Haller
a4ff07aaad systemd: update code from upstream (2022-01-24)
This is a direct dump from systemd git.

  $ git cat-file -p HEAD | sed '1,/^======$/ d' | bash -

======

SYSTEMD_DIR=../systemd
COMMIT=f338a496e48392929400916ebb0eb9819dec1e2b

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files -z :/src/libnm-systemd-core/src/ \
                :/src/libnm-systemd-shared/src/ \
                :/src/libnm-std-aux/unaligned.h | \
  xargs -0 rm -f

nm_copy_sd_shared() {
    mkdir -p "./src/libnm-systemd-shared/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/libnm-systemd-shared/$1"
}

nm_copy_sd_core() {
    mkdir -p "./src/libnm-systemd-core/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/libnm-systemd-core/$1"
}

nm_copy_sd_stdaux() {
    mkdir -p "./src/libnm-std-aux/"
    cp "$SYSTEMD_DIR/$1" "./src/libnm-std-aux/${1##*/}"
}

nm_copy_sd_core "src/libsystemd-network/arp-util.c"
nm_copy_sd_core "src/libsystemd-network/arp-util.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd_core "src/libsystemd-network/lldp-network.c"
nm_copy_sd_core "src/libsystemd-network/lldp-network.h"
nm_copy_sd_core "src/libsystemd-network/lldp-rx-internal.h"
nm_copy_sd_core "src/libsystemd-network/network-common.c"
nm_copy_sd_core "src/libsystemd-network/network-common.h"
nm_copy_sd_core "src/libsystemd-network/network-internal.c"
nm_copy_sd_core "src/libsystemd-network/network-internal.h"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd_core "src/libsystemd-network/sd-lldp-rx.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-source.h"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.h"
nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd_core "src/systemd/_sd-common.h"
nm_copy_sd_core "src/systemd/sd-dhcp-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp-option.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-option.h"
nm_copy_sd_core "src/systemd/sd-event.h"
nm_copy_sd_core "src/systemd/sd-id128.h"
nm_copy_sd_core "src/systemd/sd-ipv4acd.h"
nm_copy_sd_core "src/systemd/sd-ipv4ll.h"
nm_copy_sd_core "src/systemd/sd-lldp-rx.h"
nm_copy_sd_core "src/systemd/sd-lldp.h"
nm_copy_sd_core "src/systemd/sd-ndisc.h"
nm_copy_sd_shared "src/basic/alloc-util.c"
nm_copy_sd_shared "src/basic/alloc-util.h"
nm_copy_sd_shared "src/basic/async.h"
nm_copy_sd_shared "src/basic/cgroup-util.h"
nm_copy_sd_shared "src/basic/dns-def.h"
nm_copy_sd_shared "src/basic/env-file.c"
nm_copy_sd_shared "src/basic/env-file.h"
nm_copy_sd_shared "src/basic/env-util.c"
nm_copy_sd_shared "src/basic/env-util.h"
nm_copy_sd_shared "src/basic/errno-util.h"
nm_copy_sd_shared "src/basic/escape.c"
nm_copy_sd_shared "src/basic/escape.h"
nm_copy_sd_shared "src/basic/ether-addr-util.c"
nm_copy_sd_shared "src/basic/ether-addr-util.h"
nm_copy_sd_shared "src/basic/extract-word.c"
nm_copy_sd_shared "src/basic/extract-word.h"
nm_copy_sd_shared "src/basic/fd-util.c"
nm_copy_sd_shared "src/basic/fd-util.h"
nm_copy_sd_shared "src/basic/fileio.c"
nm_copy_sd_shared "src/basic/fileio.h"
nm_copy_sd_shared "src/basic/format-util.c"
nm_copy_sd_shared "src/basic/format-util.h"
nm_copy_sd_shared "src/basic/fs-util.c"
nm_copy_sd_shared "src/basic/fs-util.h"
nm_copy_sd_shared "src/basic/hash-funcs.c"
nm_copy_sd_shared "src/basic/hash-funcs.h"
nm_copy_sd_shared "src/basic/hashmap.c"
nm_copy_sd_shared "src/basic/hashmap.h"
nm_copy_sd_shared "src/basic/hexdecoct.c"
nm_copy_sd_shared "src/basic/hexdecoct.h"
nm_copy_sd_shared "src/basic/hostname-util.c"
nm_copy_sd_shared "src/basic/hostname-util.h"
nm_copy_sd_shared "src/basic/in-addr-util.c"
nm_copy_sd_shared "src/basic/in-addr-util.h"
nm_copy_sd_shared "src/basic/inotify-util.c"
nm_copy_sd_shared "src/basic/inotify-util.h"
nm_copy_sd_shared "src/basic/io-util.c"
nm_copy_sd_shared "src/basic/io-util.h"
nm_copy_sd_shared "src/basic/list.h"
nm_copy_sd_shared "src/basic/log.h"
nm_copy_sd_shared "src/basic/macro.h"
nm_copy_sd_shared "src/basic/memory-util.c"
nm_copy_sd_shared "src/basic/memory-util.h"
nm_copy_sd_shared "src/basic/mempool.c"
nm_copy_sd_shared "src/basic/mempool.h"
nm_copy_sd_shared "src/basic/missing_fcntl.h"
nm_copy_sd_shared "src/basic/missing_random.h"
nm_copy_sd_shared "src/basic/missing_socket.h"
nm_copy_sd_shared "src/basic/missing_stat.h"
nm_copy_sd_shared "src/basic/missing_syscall.h"
nm_copy_sd_shared "src/basic/missing_type.h"
nm_copy_sd_shared "src/basic/ordered-set.c"
nm_copy_sd_shared "src/basic/ordered-set.h"
nm_copy_sd_shared "src/basic/parse-util.c"
nm_copy_sd_shared "src/basic/parse-util.h"
nm_copy_sd_shared "src/basic/path-util.c"
nm_copy_sd_shared "src/basic/path-util.h"
nm_copy_sd_shared "src/basic/prioq.c"
nm_copy_sd_shared "src/basic/prioq.h"
nm_copy_sd_shared "src/basic/process-util.c"
nm_copy_sd_shared "src/basic/process-util.h"
nm_copy_sd_shared "src/basic/random-util.c"
nm_copy_sd_shared "src/basic/random-util.h"
nm_copy_sd_shared "src/basic/ratelimit.c"
nm_copy_sd_shared "src/basic/ratelimit.h"
nm_copy_sd_shared "src/basic/set.h"
nm_copy_sd_shared "src/basic/signal-util.c"
nm_copy_sd_shared "src/basic/signal-util.h"
nm_copy_sd_shared "src/basic/siphash24.h"
nm_copy_sd_shared "src/basic/socket-util.c"
nm_copy_sd_shared "src/basic/socket-util.h"
nm_copy_sd_shared "src/basic/sort-util.h"
nm_copy_sd_shared "src/basic/sparse-endian.h"
nm_copy_sd_shared "src/basic/stat-util.c"
nm_copy_sd_shared "src/basic/stat-util.h"
nm_copy_sd_shared "src/basic/stdio-util.h"
nm_copy_sd_shared "src/basic/string-table.c"
nm_copy_sd_shared "src/basic/string-table.h"
nm_copy_sd_shared "src/basic/string-util.c"
nm_copy_sd_shared "src/basic/string-util.h"
nm_copy_sd_shared "src/basic/strv.c"
nm_copy_sd_shared "src/basic/strv.h"
nm_copy_sd_shared "src/basic/strxcpyx.c"
nm_copy_sd_shared "src/basic/strxcpyx.h"
nm_copy_sd_shared "src/basic/time-util.c"
nm_copy_sd_shared "src/basic/time-util.h"
nm_copy_sd_shared "src/basic/tmpfile-util.c"
nm_copy_sd_shared "src/basic/tmpfile-util.h"
nm_copy_sd_shared "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/user-util.h"
nm_copy_sd_shared "src/basic/utf8.c"
nm_copy_sd_shared "src/basic/utf8.h"
nm_copy_sd_shared "src/basic/util.c"
nm_copy_sd_shared "src/basic/util.h"
nm_copy_sd_shared "src/fundamental/macro-fundamental.h"
nm_copy_sd_shared "src/fundamental/string-util-fundamental.c"
nm_copy_sd_shared "src/fundamental/string-util-fundamental.h"
nm_copy_sd_shared "src/fundamental/types-fundamental.h"
nm_copy_sd_shared "src/shared/dns-domain.c"
nm_copy_sd_shared "src/shared/dns-domain.h"
nm_copy_sd_shared "src/shared/log-link.h"
nm_copy_sd_shared "src/shared/web-util.c"
nm_copy_sd_shared "src/shared/web-util.h"
nm_copy_sd_stdaux "src/basic/unaligned.h"
2022-01-24 20:32:56 +01:00
Thomas Haller
3f0ec85634 contrib/rpm: split ifup/ifdown compat scripts to new package NetworkManager-initscripts-updown
Previously (on RHEL<=8 and Fedora<=35), NetworkManager package contains
the compat scripts nm-ifup/nm-ifdown.

If initscripts package (not network-scripts!) is installed, then a RPM
trigger links them as alternatives for the ifup/ifdown commands.

One problem is that `dnf provides /usr/sbin/ifup` lists the
NetworkManager package. Which is technically true, but on RHEL9 where
initscripts is not installed by default, `dnf install NetworkManager`
does not actually create those scripts.

Solve that by moving those scripts to a new subpackage
NetworkManager-initscripts-updown. The %post script now always creates the
alternatives links, regardless whether initscripts package is installed.

Note that on RHEL8, NetworkManager package not only Obsoletes: but also
Suggests: the new package.

The name "initscripts-updown" is chosen because in the future we might
have additonal initscripts/ifcfg related subpackages to contain the
ifcfg-rh plugin (NetworkManager-initscripts-ifcfg) or ifcfg-rh migration
tools (NetworkManager-initscripts-tools).

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1061
2022-01-24 17:40:17 +01:00
Thomas Haller
26c43e4bcc libnm/tests: fix race in test test_activate_virtual()
ERROR: src/libnm-client-impl/tests/test-nm-client - Bail out! nm:ERROR:src/libnm-client-impl/tests/test-nm-client.c:807:_dev_eth0_1_state_changed_cb: assertion failed (old_state == NM_DEVICE_STATE_PREPARE): (100 == 40)

Fixes: bc9aa72c88 ('libnm/tests: add unit test for checking dangling pointer in libnm')
2022-01-21 13:44:01 +01:00
Thomas Haller
aafd6cb524 libnm: merge branch 'th/libnm-dangling-property'
https://bugzilla.redhat.com/show_bug.cgi?id=2039331
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/896

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1064
2022-01-21 12:10:25 +01:00
Thomas Haller
2afecaf908 libnm: fix dangling pointer in public API while destructing NMClient
While (and after) NMClient gets destroyed, nm_device_get_active_connection()
gives a dangling pointer. That can lead to a crash. This probably
affects all NMLDBusPropertyO type properties.

It's not clear how to fix that best. Usually, NMClient does updates in
two phases, first it processes the D-Bus events and tracks internal
data, then it emits all GObject signals and notifications.

When an object gets removed from the NMClient cache, then the second
phase is not fully processed, because the object is already removed
from the cache. Thus, the property was not properly cleared leaving
a dangling pointer.

A simple fix is to always clear the pointer during the first phase. Note that
effectively we do the same also for NMLDBusPropertyAO (by clearing the
"pr_ao->arr"), so at least this is consistent.

Somehow it seems that we should make sure that the "second" phase gets
full processed in this case too. But it's complicated, and it's not
clear how to do that. So this solution seems fine.

https://bugzilla.redhat.com/show_bug.cgi?id=2039331
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/896
2022-01-21 12:09:45 +01:00
Thomas Haller
bc9aa72c88 libnm/tests: add unit test for checking dangling pointer in libnm
When destroying NMClient, nm_device_get_active_connection() still
return dangling pointers. Add a unit test for that bug.

Obviously, the bug currently exists, so the relevant code is commented
out.
2022-01-21 12:08:01 +01:00
Thomas Haller
1f9de38a7b tools/tests: set available-connections for vlan device in NM test stub 2022-01-21 12:08:00 +01:00
Thomas Haller
ee3e2e0bb6 glib-aux/tests: add nmtst_test_skip_slow() helper 2022-01-21 12:08:00 +01:00
Thomas Haller
eda2c5ac48 tools: support --no-make-first option in "run-nm-test.sh"
Why? Because I often use a command line like

  $ ./tools/run-nm-test.sh -m src/libnm-client-impl/tests/test-nm-client -p /libnm/device-connection-compatibility

or even alias it to a one character command `x`.
Usually I want to do the rebuild, and as `make` is so slow, it
adds noticeable time running the command. Thus, sometimes I want
to modify the command, for which I have to edit the command from the
history, or toggle two separate commands.

Add a `-M` flag that can reverse the effect of an earlier `-m`.

An "enable" flag in general should just also have a "disable" flag.
2022-01-21 12:08:00 +01:00
Thomas Haller
cb9ca67901 glib-aux: workaround maybe-uninitialized warning with LTO in nm_uuid_generate_from_string_str()
In function 'nm_uuid_unparse',
      inlined from 'nm_uuid_generate_from_string_str' at src/libnm-glib-aux/nm-uuid.c:393:12,
      inlined from 'nm_uuid_generate_from_strings.constprop' at src/libnm-glib-aux/nm-uuid.c:430:16:
  src/libnm-glib-aux/nm-uuid.h:37:12: error: 'uuid' may be used uninitialized [-Werror=maybe-uninitialized]
     37 |     return nm_uuid_unparse_case(uuid, out_str, FALSE);
        |            ^
  src/libnm-glib-aux/nm-uuid.c: In function 'nm_uuid_generate_from_strings.constprop':
  src/libnm-glib-aux/nm-uuid.c:20:1: note: by argument 1 of type 'const struct NMUuid *' to 'nm_uuid_unparse_case.constprop' declared here
     20 | nm_uuid_unparse_case(const NMUuid *uuid, char out_str[static 37], gboolean upper_case)
        | ^
  src/libnm-glib-aux/nm-uuid.c:390:12: note: 'uuid' declared here
    390 |     NMUuid uuid;
        |            ^
  lto1: all warnings being treated as errors

The problem are code paths with failed g_return*() assertions. Being in
a bad state already, they don't bother to ensure proper return values,
and with LTO the compiler might think there are valid code paths wrongly
handled. Work around.
2022-01-21 11:38:08 +01:00
Thomas Haller
3dd854eb1b device: initialize nm_auto variable in _ethtool_features_reset()
The compiler is often adament to warn about maybe-uninitialized.
2022-01-21 11:38:08 +01:00
Thomas Haller
2395bedd63 wifi/iwd: merge branch 'balrog-kun:iwd-p2p'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1017
2022-01-21 11:16:40 +01:00
Andrew Zaborowski
4822d1a1d1 iwd: Ensure WFD IE is present during activation
If the connection has wfd_ies set, we want to ensure that a WFD
connection is being established so we want to check that the target peer
also supports WFD.  For now this in the IWD backend only.

However, WFD peers will send us their WFD IEs in their Probe Responses
only if our own Probe Request contained a WFD IE, or at least that's
when the spec mandates that they include the WFD IE.  This implies that
the discovery phase (NM.Device.WifiP2P.StartFind(options) / .StopFind())
needs to know the value of the local WFD IE and include it in the Probe
Requests, which existing clients (gnome-network-displays) doesn't do and
in fact can't do because there's no API for the client to pass the WFD
IE -- that is easy to add in the options parameter though (a
dictionary).

The current situation is that with the wpa_supplicant backend we'll
sometimes see the WFD IE (when the peer is discovered from a Probe
Request that it has sent, rather than from a Probe Response) and
sometimes not, while with the IWD backend we'll never see the WFD
information because IWD assumes that the client (NM) is not interested
in seeing it if it hasn't registered the local WFD information before
starting discovery.

So, for compatibility with this existing situation and with the
wpa_supplicant backend, ignore whether the peer is a WFD peer except in
the PREPARE stage.  In PREPARE, if we have a peer compatible with the
connection being activated -- except for the WFD information -- force a
new discovery, this time passing the WFD information from the
NMSettingConnection's wfd_ies, and only progress to CONFIG if the target
peer is re-discovered as a WFD peer within 10 seconds.

We don't actually check the contents of the WFD IEs to match, e.g. we
don't check the sink/source/dual role compatibility between our and the
peer's properties, but IWD will do some of these checks later during
activation.
2022-01-21 11:16:24 +01:00
Andrew Zaborowski
524675db75 iwd: Basic WFD support for NMDeviceIwdP2P
Enable WFD clients to work with the IWD backend.
2022-01-21 11:16:24 +01:00
Andrew Zaborowski
51ef157096 iwd: Add basic P2P device class for IWD
Similarly as with wpa_supplicant, create NMDeviceIwdP2P objects for P2P
devices based on data from IWD -- not in NMWifiFactory::create_device
because that is only triggered for system netdevs and a P2P-Device
virtual interface has no netdev.  Unlike NMDeviceWifiP2P,
NMDeviceIwdP2P's iface property is a unique string that likely doesn't
match any system interface name -- in theory there doesn't need to be
any related netdev on the system (such as an Infrastructure-mode
interface) before a P2P-Device is added.

[thaller@redhat.com: modified original patch]
2022-01-21 11:16:14 +01:00
Andrew Zaborowski
6bf080a7bb wifi: Add WFD utilities needed by the IWD backend
Since the NM D-Bus API talks to the client using raw WFD IE bytes and
IWD's API wants/provides some of the actual values from the WFD IE
instead (e.g. boolean Source and Sink properties), we need to be able to
parse and build the WFD IE from those property values to do the
translation, add utilities for this.  Use one of them to build the WFD IE
property on NMWifiP2PPeer objects.

[thaller@redhat.com: modify original patch to use
  nm_g_variant_unref() and add missing #define]
2022-01-21 11:13:58 +01:00
Andrew Zaborowski
932712d73c wifi: Add IWD-specific NMWifiP2PPeer constructors
[thaller@redhat.com: modify original patch to use
  nm_g_variant_unref() and add missing #define]
2022-01-21 11:13:58 +01:00
Andrew Zaborowski
e6e3fad4e4 wifi: Check interface mode for both backends
In NMWifiFactory, move the check that prevents NMDevice's from being
created for interfaces in Monitor and other modes, out of the
wpa_supplicant-specific block so that it applies to both IWD and
wpa_supplicant.  This check allows P2P device creation to work
differently that Infrastructure, Ad-Hoc and AP modes so it's needed for
P2P support in the IWD backend.

While there change the check to list the modes that are accepted rather
than rely on some of the modes (Monitor, P2P-{Device,Client,GO}) being
bunched together as _NM_802_11_MODE_UNKNOWN.
2022-01-21 11:13:58 +01:00
Andrew Zaborowski
2e7d4aa2f7 iwd: Add nm_iwd_manager_get_netconfig_enabled
Expose the NetworkConfigurationEnabled boolean setting from IWD through
an NMIwdManager method nm_iwd_manager_get_netconfig_enabled().
2022-01-21 11:13:58 +01:00
Andrew Zaborowski
98ff7528ed iwd: Update D-Bus interface name #define for WSC
The interface name has changed in 2019 but the WSC interface has
never been used by NM.  Update #define NM_IWD_WSC_INTERFACE in
nm-iwd-manager.h accordingly.
2022-01-21 11:13:58 +01:00
Thomas Haller
87bce61bad libnm/tests: fix maybe-uninitialized warning in "test-libnmc-setting" 2022-01-20 22:34:01 +01:00
Thomas Haller
b5b9a109e1 libnm: fix bug verifying private-key for WireGuard setting
Fixes: aea47ed206 ('libnm: implement "wireguard.private-key" as direct string property')
2022-01-20 22:22:41 +01:00
Thomas Haller
6f0e22a64a libnm/tests: fix maybe-uninitialized warning in "test-setting"
In function '_nm_auto_g_free',
      inlined from 'test_tc_config_tfilter_matchall_mirred' at src/libnm-core-impl/tests/test-setting.c:2955:24:
  ./src/libnm-glib-aux/nm-macros-internal.h:58:1: error: 'str' may be used uninitialized [-Werror=maybe-uninitialized]
     58 | NM_AUTO_DEFINE_FCN_VOID0(void *, _nm_auto_g_free, g_free);
        | ^
  src/libnm-core-impl/tests/test-setting.c: In function 'test_tc_config_tfilter_matchall_mirred':
  src/libnm-core-impl/tests/test-setting.c:2955:24: note: 'str' was declared here
   2955 |     gs_free char      *str;
        |                        ^
  lto1: all warnings being treated as errors
  lto-wrapper: fatal error: gcc returned 1 exit status
2022-01-20 21:53:23 +01:00
Thomas Haller
f73088a885 platform: merge branch 'th/platform-no-bpf-filter-route'
https://bugzilla.redhat.com/show_bug.cgi?id=2037411

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1062
2022-01-20 10:34:09 +01:00
Thomas Haller
3416b00988 platform: don't put certain rtm_protocol routes in the platform cache
We need to support systems where there are hundereds of thousand routes
(e.g. BGP software).

For that, we will ignore routes that have a rtm_protocol value which was
certainly not created by NetworkManager. Before we had a BPF filer to
filter them out, but that had issues and is removed for now. Still,
don't put those routes in the platform cache and ignore them early.

Note that we still deserialize the RTM_NEWROUTE message to a NMPObject,
and don't shortcut earlier. The reason is that we should still call
delayed_action_refresh_all_in_progress() and handle the RTM_GETROUTE
response, even if the route has a different protocol. So we error out
later, shortly before putting the object in the cache. This means we
will malloc() a NMPObject and initialize it, but that is probably cheap,
compared to the first problem that the process already had to wake up
and read the netlink socket.

This restores the effective behavior of the BPF filter, albeit with a
higher overhead, as the route is rejected later. The important part for
now is that we stick to the behavior of not caching certain routes of a
certain protocol. If that can in the future be optimized (e.g. by a new
BPF filter), then we should do that. But for now that would be only a
future performance improvement, which requires new profiling first and
that has not the highest priority. Note that not caching certain routes
already should reduce the largest part of the overhead that those routes
brings. Whether this form is sufficient to reach the expected
performance goals, needs to be measured in the future.
2022-01-20 10:30:34 +01:00
Thomas Haller
c37a21ea29 Revert "platform: add bpf filter to ignore routes from routing daemons"
The socket BPF filter operates on the entire message (skb). One netlink
message (for RTM_NEWROUTE) usually contains a list of routes (struct
nlmsghdr), but the BPF filter was only looking at the first route to decide
whether to throw away the entire message. That is wrong.

This causes that we miss routes. It also means that the response to our
RTM_GETROUTE dump request could be filtered and we poll/wait (unsuccessfully)
for it:

  <trace> [1641829930.4111] platform-linux: netlink: read: wait for ACK for sequence number 26...

To get this right, the BPF filter would have to look at all routes in the
list to find out whether there are any we want to receive (and if
there are any, to pass the entire message, regardless that is might also
contain routes we want to ignore). As BPF does not support loops, that
is not trivial. Arguably, we still could do something where we look at a
bounded, unrolled number of routes, in the hope that there are not more
routes in one message that we support. The problem is that this BPF
filter is supposed to filter out massive amounts of routes, so most
messages will be filled to the brim with routes and we would have to
expect a high number of routes in the RTM_NEWROUTE that need checking.

We could still ignore routes in _new_from_nl_route(), to enter the
cache. That means, we would catch them later than with the BPF filter,
but still before a lot of the overhead of handling them. That probably
will be done next, but for now revert the commit.

This reverts commit e9ca5583e5.

https://bugzilla.redhat.com/show_bug.cgi?id=2037411
2022-01-20 10:30:30 +01:00
Thomas Haller
50dc71323b CONTRIBUTING: document style guide about naming in header files 2022-01-20 08:14:48 +01:00
Thomas Haller
c1dab5709d glib-aux/trivial: clearify code comment in nm_g_source_destroy_and_unref() 2022-01-19 18:53:44 +01:00
Thomas Haller
25aa6c0552 libnm: don't clear secrets during NMSimpleConnection:dispose()
NMConnection is an interface, implemented by NMSimpleConnection
and NMRemoteConnection. A connection is basically a set of NMSetting
instances.

Usually you would expect that one NMSetting instance only gets added to
zero or one NMConnection. It seems a bit ugly, to have one setting tracked by
multiple NMConnection. Still, technically I am not aware of a single problem
with doing that, where it not for NMSimpleConnection:dispose() to clear the
secrets.

There is no need to clear the secrets of an NMSetting, when the
NMConnection gets destroyed. Either this destroys the NMSetting instance
right away (and NMSetting's destructor will clear the secrets anyway), or
somebody else (e.g. another NMConnection instance), keeps the setting
alive. In the latter case, it is wrong to clear the secrets at
this point.

This was done since commit 6a19e68a7d ('libnm-core: clear secrets from
NMSimpleConnection and NMSettingsConnection dispose()'), but let's stop
doing that.

This also causes problems in practice, see [1].

[1] https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1099#note_1334333

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/876

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1056
2022-01-19 13:42:17 +01:00
Thomas Haller
b331606386 l3cfg: on n-acd instance-reset clear also ready ACD state
The n-acd instance gets reset in various cases, for example
when the MAC address changes or during errors.

When that happens, we also need to forget all our pending probes,
because they would reference to a now-defunct n-acd instance.

When the address is currently in state NM_L3_ACD_ADDR_STATE_READY,
we possibly have a pending probe. We need to clean that up. Handle
it the same as in the other cases. Yes, this means we forget about
that the address was ready. But a reset of the n-acd state is a dramatic
event. It warrants some drastic start-over.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2026288
See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2028422
See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1035

Fixes: 9a76b07f74 ('l3cfg: fix assertion failure')
2022-01-19 13:37:30 +01:00
Thomas Haller
4122534b6e core: merge branch 'juspence:main' (parts)
Merge a subset of merge-request 1031, with a few follow-up fixes.

See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/843

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1031
2022-01-18 19:07:27 +01:00
Thomas Haller
31dbcb81fe core: make nm_utils_get_nm_[ug]id() thread safe
While NetworkManager is of course (mostly) single threaded,
our static functions really should be thread safe.

"mostly" single threaded because we have GDBus's worker
thread, we use a thread for writing non-blocking SR-IOV sysctl,
in the past (or still?) we used a thread for async glibc resolver.

Anyway, a low-level function like must be thread safe, when it
uses global data.

Granted, the initialize-once pattern with the flag and the
int variable, is probably in many cases good enough. But it
makes me unhappy, the thought of accessing static data without
a synchronized operation.
2022-01-18 18:21:02 +01:00
Thomas Haller
b2660b7012 keyfile: for keyfile owner check allow root and euid
This partly restores the previous behavior. The point of the
file owner check is to ensure that the file cannot be read
by unpriviledged processes as it may contain secrets. If the
file is owned by root, that is considered secure (even if our
euid is different).

Possibly, if our euid is not root, then we couldn't read the
file, but that is a different problem.
2022-01-18 18:10:56 +01:00
Thomas Haller
b1a14e3398 core: move nm_main_utils_get_nm_[ug]id() to "nm-core-utils.h"
There is a hierarchy of how files include each other. "main-utils.h"
is pretty much at the bottom (one above "main.c"), in the sense that
it only includes other headers, but is not included itself (aside
"main.c").

Move the utils function to a place where its accessible from everywhere
and rename.
2022-01-18 18:10:55 +01:00
Thomas Haller
f755c7b1db core: remove unused function nm_main_utils_ensure_root() 2022-01-18 18:07:43 +01:00
Justin Spencer
604260c6ea Assert keyfiles are owned by euid, not root 2022-01-18 17:30:45 +01:00
Justin Spencer
41db8c7563 Write keyfiles as euid / egid instead of 0 / 0 (root / root) 2022-01-18 17:30:45 +01:00
Justin Spencer
3783494dfe Add helper functions to find + remember EUID / EGID, avoid many syscalls 2022-01-18 17:30:45 +01:00
Justin Spencer
2593ae2522 Remove check for running as root, but keep translations 2022-01-18 17:30:45 +01:00
Thomas Haller
c5399847f7 libnm: merge branch 'th/libnm-settings-properties-3'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1055
2022-01-18 16:54:29 +01:00
Thomas Haller
87ca5875d0 libnm: add and use _nm_setting_get_private_field() helper
All callers of _nm_setting_get_private() got the offset from the
property info. Add a wrapper _nm_setting_get_private_field() that
takes the property info. This way, it can add some assertions.
2022-01-18 16:25:24 +01:00
Thomas Haller
68b6aa64fd libnm: for embedded private structure in NMSetting set the offset to zero
Preferably, we embed the private struct in the GObject struct itself.
In the past, we didn't do that, because the struct was in public headers
and changing that would have been an ABI break. For those struct, we
still use g_type_class_add_private().

We have some structs, where the private struct is embedded. An
alternative to that would be, to not have the private struct at all,
like done for NMSettingOvsBridge.

Anyway. So for direct properties we need to capture the offset of the
field (in the private struct). We can either set the offset of the
private struct in _nm_setting_class_commit() to zero and let the field
offset include the private structure offset. Or, the offset of the
private struct is accounted during _nm_setting_class_commit().

Both approaches are basically the same. Just do it consistently. For no
particular reason, choose to set the offset of the private data to zero
for those types.
2022-01-18 16:22:45 +01:00
Thomas Haller
9cf9ab3cf0 libnm/tests: add test for direct string property of kind NMRefString
In particular, that the NMRefString gets destroyed when we destroy
all NMSetting instances.
2022-01-18 16:22:42 +01:00
Thomas Haller
d36aaf91fa libnm: make "connection.type" property a NMRefString 2022-01-18 16:22:40 +01:00
Thomas Haller
419be57dbc libnm: support direct string properties as NMRefString
Several properties like "connection.type" are enum-like and only take a few
known values. We can use a NMRefString to share their instances.

Currently nm_setting_duplicate() does not yet explicitly handle direct properties.
But it should, because it can handle them more efficiently. If it would do that, it
would be very cheap to "copy" a NMRefString. But even with the current implementation
will the result be deduplicated.
2022-01-18 16:22:38 +01:00
Thomas Haller
3b803a9d70 glib-aux: add nmtst_ref_string_find() helper
This is only for unit testing (hence the "nmtst" prefix)
to check whether a ref-string is/isn't interned.
2022-01-18 16:22:36 +01:00