Commit graph

27679 commits

Author SHA1 Message Date
Thomas Haller 24c634bf57
core/logging: move "nm-logging.c" to shared/nm-log-core/libnm-log-core library
We want to move platform code to "shared/nm-platform". However, platform
code uses the logging infrastructure from the daemon, there is thus
an odd circular dependency.

Solve that by moving the "src/nm-logging.[hc]" to a new helper library
in "shared/nm-log-core".
2021-01-15 11:32:31 +01:00
Thomas Haller c6e1327495
core: move NM_MANAGER_ERROR to shared/nm-glib-aux
"src/nm-logging.c" should be independent of libnm-core. It almost
is, except the error domain and code.

Move NM_MANAGER_ERROR to "nm-glib-aux/nm-shared-utils.h" so that
"nm-logging.c" is independent of libnm-core.
2021-01-15 11:32:30 +01:00
Thomas Haller 186f2da2fc
shared,platform: add "shared/nm-platform" library
NetworkManager core is huge. We should try to split out
parts that are independent.

Platform code is already mostly independent. But due to having it
under "src/", there is no strict separation/layering which determines
the parts that can work independently. So, while the code is mostly
independent (in practice), that is not obvious from looking at the
source tree. It thus still contributes to cognitive load.

Add a shared library "shared/nm-platform", which should have no
dependencies on libnm-core or NetworkManager core.

In a first step, move the netlink code there. More should follow.
2021-01-15 11:32:30 +01:00
Thomas Haller 05008faf6e
build/meson: add libnm_systemd_core_dep dependency 2021-01-15 11:32:29 +01:00
Thomas Haller 63e070b180
build/meson: cleanup build of test-systemd executable 2021-01-15 11:32:29 +01:00
Thomas Haller fd2e626b40
build: add missing dependency for config-extra.h in Makefile.am 2021-01-15 11:32:29 +01:00
Thomas Haller 27f57be076
build: add missing linking with systemd-journald library
These programs use sd_journal_sendv(), they thus need to link against
systemd library.
2021-01-15 11:32:28 +01:00
Thomas Haller 43d4810179
shared: move nm_utils_ifname_cpy() to "shared/nm-glib-aux" 2021-01-15 11:32:28 +01:00
Thomas Haller 6aa6da2b08
shared: add _nm_utils_hwaddr_aton_exact()
This is the same as libnm's nm_utils_hwaddr_aton(), which however
is public API.

We want to use this function also without libnm(-core). Hence add
the helper to "shared/nm-glib-aux".
2021-01-15 11:32:28 +01:00
Thomas Haller cda8badc57
shared/c-siphash: reimport
git subtree pull --prefix shared/c-stdaux git@github.com:c-util/c-stdaux.git master --squash
2021-01-15 11:19:04 +01:00
Thomas Haller e97c791684 Squashed 'shared/c-stdaux/' changes from ffa3dcc36533..346623b40eb8
346623b40eb8 c-stdaux: guard __builtin_choose_expr() from Coverity

git-subtree-dir: shared/c-stdaux
git-subtree-split: 346623b40eb8137cae7568a69ee42253ff098ff7
2021-01-15 11:18:21 +01:00
Thomas Haller 18cd6ef832
shared/c-siphash: reimport
git subtree pull --prefix shared/c-siphash git@github.com:c-util/c-siphash.git master --squash
2021-01-15 11:17:32 +01:00
Thomas Haller a275cfe43b Squashed 'shared/c-siphash/' changes from d8b3a7a8f40e..4918c33b65d0
4918c33b65d0 build: update submodules

git-subtree-dir: shared/c-siphash
git-subtree-split: 4918c33b65d01a9478faface8b4c89f91c390092
2021-01-15 11:17:17 +01:00
Thomas Haller 3f6a2588cd
shared/c-rbtree: reimport
git subtree pull --prefix shared/c-rbtree git@github.com:c-util/c-rbtree.git master --squash
2021-01-15 11:16:25 +01:00
Thomas Haller afdcf971bd Squashed 'shared/c-rbtree/' changes from 3162c5c04574..a3b1f80548d1
a3b1f80548d1 build: update submodules

git-subtree-dir: shared/c-rbtree
git-subtree-split: a3b1f80548d1c736208c55e9251c49ada649dd62
2021-01-15 11:14:16 +01:00
Thomas Haller d86b5d07a9
shared: merge branch 'th/enum-from-str-fix-signed'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/728
2021-01-15 09:39:32 +01:00
Thomas Haller 726a82c79d
shared: fix _nm_utils_enum_from_str_full() for negative enum values
Enums can also be negative (contrary to Flags). Fix the parsing.

  $ nmcli connection modify "$PROFILE" connection.llmnr -1
  Error: failed to modify connection.llmnr: invalid option '-1', use one of [default,no,resolve,yes].
2021-01-15 09:36:30 +01:00
Thomas Haller 88a7ec8b14
shared: avoid heap allocation in _nm_utils_enum_from_str_full()
In the vast majority of cases is the string for _nm_utils_enum_from_str_full()
short. As we duplicate it for stripping, prefer to clone it on the stack
with nm_strdup_maybe_a().
2021-01-15 09:36:30 +01:00
Thomas Haller e884ef39ed
shared: add nm_strdup_maybe_a() helper macro 2021-01-15 09:36:30 +01:00
Jonathan Lebon a1d9a79228
contrib/rpm: don't trigger udev if socket doesn't exist
On rpm-ostree systems, we don't want scriptlets to affect the running
system because a major part of the value is "background updates".
Scriptlets are run in a containerized environment where e.g. udev is not
available.

Add a check for the udev socket before triggering it to handle this.
This also helps the container use case.

This doesn't break rpm-ostree strictly, because it uses `|| :`, but it
still spams error messages during the compose. I kept the `|| :` to be
safe, but it's likely fine to remove them now.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1352154
See-also: https://src.fedoraproject.org/rpms/udisks2/pull-request/3
See-also: https://github.com/coreos/fedora-coreos-tracker/issues/703

https://src.fedoraproject.org/rpms/NetworkManager/pull-request/6
2021-01-14 22:46:35 +01:00
Thomas Haller 9ba8c32dac
contrib/rpm: add "BuildRequires: make" to SPEC file
https://fedoraproject.org/wiki/Changes/Remove_make_from_BuildRoot
2021-01-14 22:17:34 +01:00
Beniamino Galvani 07ee187cb5 initrd: fix leak in test
Fixes: 6069ef4b8b ('initrd: accept a zero-byte prefix for BOOTIF')
2021-01-14 21:48:16 +01:00
Beniamino Galvani 6069ef4b8b initrd: accept a zero-byte prefix for BOOTIF
The BOOTIF MAC address can be prefixed with a hardware address
type. Typically it is 01 (for ethernet), but the legacy network module
accepts (and strips) any byte value.

It seems wrong to take any address type without validation. In
addition to "01", also accept a zero type which, according to the
bugzilla below, is used in some configurations to mean "undefined".

While at it, also accept ':' as separator for the first byte.

https://bugzilla.redhat.com/show_bug.cgi?id=1904099
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/713
2021-01-14 19:14:01 +01:00
Thomas Haller 584e8f92f5
release: bump version to 1.29.8 (development) 2021-01-14 18:56:21 +01:00
Thomas Haller 55c5c57d1e
devices/tests: improve assert for ioctl() in _test_recv_fixture_setup()
This assert sometimes fails during copr builds. But the way
the assert was, it was hard to see what the actual problem
was.

Restructure the assert (again) to get the errno in the
test logs.
2021-01-14 18:24:38 +01:00
Yuri Chornoivan b2ff18692f
po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/727
2021-01-14 18:09:24 +01:00
Thomas Haller 010ad9eeb8
ndisc: merge branch 'th/ndisc-dns-lifetimes'
https://bugzilla.redhat.com/show_bug.cgi?id=1874743

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/725
2021-01-14 13:08:26 +01:00
Thomas Haller 68528f7af5
ndisc: don't artificially extend the lifetime of DNSSL/RDNSS options
RFCs actually expect to honor the lifetime. See for example [1].

This is just not right, and totally arbitrary. It was added
when our libndp based implementation was added, but unclear
why this was done (beyond the code comment).

[1] page 204, v6LC.2.2.25: Processing Router Advertisement DNS (Host
    only) at https://ipv6ready.org/docs/Core_Conformance_5_0_0.pdf
2021-01-14 11:48:52 +01:00
Thomas Haller 872f265859
ndisc: fix encoding DNS Search List Option in RA
The format is different than what was implemented.

Read [1] or see systemd's implementation ([2]).

[1] https://tools.ietf.org/html/rfc8106#section-5.2
[2] 65ab27211c/src/libsystemd-network/sd-radv.c (L791)

Fixes: 6387856602 ('ndisc/lndp: add ability to announce the managed IPv6 configuration')
2021-01-14 11:48:51 +01:00
Thomas Haller 8d9662e16f
ndisc: minor cleanup in send_ra()
- use size_t variable for memory sizes and guint for iterating
  over GArray.
2021-01-14 10:38:52 +01:00
Thomas Haller e3c464b56c
ndisc: pack structs for lndp options
There is no actual change in behavior, because "struct nd_opt_hdr"
as two uint8_t, so in practice this struct was always packed already.

But make it explicit, because it's clear that we use these structs
to set the binary message and they need a well defined (packed) memory
layout.
2021-01-14 10:38:52 +01:00
Thomas Haller 96d7ddc865
ndisc: add comment and static assert for struct sizes for ndisc packet layout
Obviously, there is no change in behavior. It's just an assertion.
2021-01-14 10:38:52 +01:00
Thomas Haller 5a213541ea
shared: add nm_str_buf_append_{dirty,c_len}() helpers 2021-01-14 10:38:52 +01:00
Thomas Haller cc8706f815
wireguard: delay activation while resolving DNS names for WireGuard peers to avoid race
The endpoints of WireGuard peers can be configured as DNS name, which
NetworkManager will resolve.

Since activating a profile might affect now names get resolved, we must
first resolve names before completing the activation of the WireGuard
device (and before reconfiguring DNS accordingly).

For example, if you configure exclusive DNS resolution via the WireGuard
device, and if the peer needs to be resolved via DNS, then resolving the
peer name must happen before the reconfiguration of DNS. Otherwise the
new DNS configuration will be broken due to being unable to reach the
WireGuard peer.

Fix that by waiting.

There is still an unfixed problem. If resolving any peers fails,
activation silently proceeds -- again possibly breaking the network
setup. Of course, NetworkManager will repeatedly try to re-resolve
the name, but that may never succeed if DNS would be resolved via
the VPN itself.

That is different from `wg set` which resolves hostnames and fails.
Consequently `wg-quick up` would also fail. But these are both one shot
applications, they are not around and basically let the user handle the
error (by reading the log and invoking the command again). NetworkManager
can do something different and proceed activation (as it will also
periodically re-resolve the hostnames again). Note that it's also valid
to activate a WireGuard device without any peers (and to modify the
activated device later with Reapply()). As such, having no peers (or
being unable to resolve a hostname) may be a valid configuration.

I think we should add an option/flag that when enabled will cause
the activation to fail of names cannot be resolved.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/535
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/616

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/721
2021-01-14 10:23:45 +01:00
Thomas Haller 86107b6a52
core: avoid "-Wmaybe-uninitalized" warning in link_negotiation_set()
With LTO and gcc-10.2.1-9.fc33.s390x we get:

    src/platform/nm-platform.c:3325:1: error: link_duplex may be used uninitialized in this function [-Werror=maybe-uninitialized]
     3325 | NM_UTILS_LOOKUP_STR_DEFINE(nm_platform_link_duplex_type_to_string,
          | ^
    src/devices/nm-device-ethernet.c:899: note: link_duplex was declared here
      899 |     NMPlatformLinkDuplexType link_duplex;
          |
2021-01-14 10:11:14 +01:00
Beniamino Galvani 8180b0180b device: clean up dispatcher calls when canceling an activation
Ensure the callback for dispatcher calls is not executed, or it will
resume the activation chain we want to interrupt.

https://bugzilla.redhat.com/show_bug.cgi?id=1888348
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/723
2021-01-14 09:06:17 +01:00
Thomas Haller 8e735a51b8
contrib: handle no files in "nm-code-format.sh"
Calling `clang-format` with no files means to read
stdin, it thus hangs:

   $ ./contrib/scripts/nm-code-format.sh .git

Also, the following does not work:

   $ ./contrib/scripts/nm-code-format.sh src/platform/

hangs. Seems there is a bug in `git ls-files` to not list all files:

   podman run -ti alpine:latest \
      sh -c '
         apk add git &&
         git clone https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git &&
         cd NetworkManager &&
         git checkout -B tmp cd754680a6 &&
         echo ">>>>>>BAD1: $PWD" &&
         git ls-files -- src/platform/ ":(exclude)shared/n-acd"
         echo ">>>>>>GOOD1: $PWD" &&
         git ls-files -- src/platform/ ":(exclude)shared/c-list"
         echo ">>>>>>GOOD2: $PWD" &&
         git ls-files -- src/platform ":(exclude)shared/n-acd"
         echo ">>>>>>GOOD3: $PWD" &&
         git ls-files -- src/vpn/ ":(exclude)shared/n-acd"
      '

Fixes: 9bef4ece92 ('contrib: improve nm-code-format.sh script')
2021-01-13 16:49:09 +01:00
Thomas Haller cd754680a6
src/tests: avoid "-Wmaybe-uninitialized" warning in nmtstp_acd_defender_new()
With gcc-10.2.1-9.fc33.s390x we get a (false positive) warning:

    src/platform/tests/test-common.c: In function nmtstp_acd_defender_new:
    src/platform/tests/test-common.c:2688:15: error: probe may be used uninitialized in this function [-Werror=maybe-uninitialized]
     2688 |     *defender = (NMTstpAcdDefender){
          |               ^
    src/platform/tests/test-common.c:2656:56: note: probe was declared here
     2656 |     NAcdProbe *                                        probe;
          |                                                        ^
2021-01-13 13:23:12 +01:00
Thomas Haller 9bef4ece92
contrib: improve nm-code-format.sh script
- accept directory names in the command line. In that case,
  still honor the excluded files. That is a major improvement
  for me, because I usually only want to reformat a directory
  that I know has changed and it is fast to only process some
  directories.

- pass all files at once to clang-format. For me that gives
  a significant speed improvement (about 3 times faster), although
  clang-format is only single threaded. Possibly clang-format could
  even be faster by checking files in parallel.
  In case of a style error, the script still falls back to
  iterate over all files to find the first bad file and print
  the full diff. But that is considered an unusual case.

- make it correctly work from calling it from a subdirectory.
  In that case, we only check files inside that directory --
  but still correctly honor the excluded files.
2021-01-13 12:57:48 +01:00
Thomas Haller 46da6eae6e
core: replace g_return_if_fail() with nm_assert() in nm_ip_config_iter_ip[46]_(address,route)_init()
With LTO, the compiler can see that some code paths return without
initializing the variable. But it fails to see that those are code
paths after an assertion fail. Still that can lead to
"-Wmaybe-uninitialized" warnings in the caller.

Avoid that by not using g_return_if_fail() but nm_assert().

    src/nm-ip6-config.c: In function '_nmtst_ip6_config_get_address':
    ./shared/nm-glib-aux/nm-dedup-multi.h:337:8: error: 'iter._next' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      337 |     if (!iter->_next)
          |        ^
    src/nm-ip6-config.c:1622:33: note: 'iter._next' was declared here
     1622 |     NMDedupMultiIter            iter;
          |                                 ^
    ./shared/nm-glib-aux/nm-dedup-multi.h:343:8: error: 'iter._head' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      343 |     if (iter->_next->next == iter->_head)
          |        ^
    src/nm-ip6-config.c:1622:33: note: 'iter._head' was declared here
     1622 |     NMDedupMultiIter            iter;
          |                                 ^

and more.
2021-01-13 09:46:59 +01:00
Thomas Haller 828e47f632
device: set out-argument to nm_device_get_permanent_hw_address_full() in assertion case
When compiling with LTO, the compiler can think that an
assertion failure (g_return*()) is regular code path, and
thus that the output variable is not set.

This can lead to "-Wmaybe-uninitialized" warnings in the
caller, despite this not happening in non-bug case.

Work aound that by setting the out argument.

Warning with LTO enabled and gcc-10.2.1-9.fc33.s390x:

    src/nm-config-data.c: In function nm_config_data_get_device_config:
    src/devices/nm-device.c:17454:9: error: is_fake may be used uninitialized in this function [-Werror=maybe-uninitialized]
    17454 |     m = nm_match_spec_device(specs,
          |         ^
    src/devices/nm-device.c:17444:26: note: is_fake was declared here
    17444 |     gboolean             is_fake;
          |                          ^
    src/nm-config-data.c: In function nm_config_data_get_connection_default:
    src/devices/nm-device.c:17454:9: error: is_fake may be used uninitialized in this function [-Werror=maybe-uninitialized]
    17454 |     m = nm_match_spec_device(specs,
          |         ^
    src/devices/nm-device.c:17444:26: note: is_fake was declared here
    17444 |     gboolean             is_fake;
          |                          ^
    src/devices/nm-device.c: In function nm_device_check_unrealized_device_managed:
    src/devices/nm-device.c:17454:9: error: is_fake may be used uninitialized in this function [-Werror=maybe-uninitialized]
    17454 |     m = nm_match_spec_device(specs,
          |         ^
2021-01-13 08:35:22 +01:00
Thomas Haller 54feadd2c1
lldp/tests: make assertion in _test_recv_fixture_setup() clearer
... to print the errno value on failure.
2021-01-12 21:49:31 +01:00
Thomas Haller d21bb697ad
core: avoid "-Wmaybe-uninitialized" warning in lldp_neighbor_get_raw()
src/devices/nm-lldp-listener.c: In function 'lldp_neighbor_to_variant':
  ./shared/nm-glib-aux/nm-shared-utils.h:1271:5: error: 'raw_len' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   1271 |     g_variant_builder_add(builder,
        |     ^
  src/devices/nm-lldp-listener.c:107:19: note: 'raw_len' was declared here
    107 |     gsize         raw_len;
        |                   ^
  ./shared/nm-glib-aux/nm-shared-utils.h:1271:5: error: 'raw_data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   1271 |     g_variant_builder_add(builder,
        |     ^
  src/devices/nm-lldp-listener.c:106:19: note: 'raw_data' was declared here
    106 |     gconstpointer raw_data;
        |                   ^
2021-01-12 21:49:21 +01:00
Thomas Haller f16f428b31
NEWS: update 2021-01-12 16:41:31 +01:00
Thomas Haller 63a33b3542
libnm: avoid "-Wmaybe-uninitialized" warning in nm_setting_ethtool_get_optnames()
With LTO build on s390x (Fedora 33) we get a compiler warning:

    libnm-core/nm-setting-ethtool.c: In function 'nm_setting_ethtool_get_optnames':
    libnm-core/nm-setting-ethtool.c:263:60: error: 'len' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      263 |     return len > 0 ? nm_memdup(names, sizeof(names[0]) * (((gsize) len) + 1u)) : NULL;
          |                                                            ^
    libnm-core/nm-setting-ethtool.c:257:24: note: 'len' was declared here
      257 |     guint              len;
          |                        ^
    libnm-core/nm-setting-ethtool.c: In function 'nm_setting_ethtool_get_optnames':
    libnm-core/nm-setting-ethtool.c:263:60: error: 'len' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      263 |     return len > 0 ? nm_memdup(names, sizeof(names[0]) * (((gsize) len) + 1u)) : NULL;
          |                                                            ^
    libnm-core/nm-setting-ethtool.c:257:24: note: 'len' was declared here
      257 |     guint              len;
          |                        ^
2021-01-12 16:32:59 +01:00
Thomas Haller d26fa1cd52
contrib: fix "contrib/scripts/nm-copr-build.sh" script 2021-01-12 14:53:00 +01:00
Thomas Haller 1277e4c882
contrib: add "contrib/scripts/nm-copr-build.sh" script
This will be the script used by our copr repositories ([1]) for building
the SRPM of NetworkManger from git.

[1] https://copr.fedorainfracloud.org/coprs/networkmanager/
2021-01-12 14:28:23 +01:00
Thomas Haller 55e4b0ea9c
contrib: add "contrib/scripts/nm-copr-build-nm-git-bundle.sh" script 2021-01-12 13:16:17 +01:00
Thomas Haller 478d5bdafe
shared: fix unit tests for nm_utils_get_next_realloc_size()
The change broke unit tests on 32 bit systems.

Change the code again to make it more similar to what it was
before. Now only on 64 bit systems there is any difference compared
to before. That makes it easier about reasoning for how the unit test
should be (in most cases, it is unchanged).

Fixes: 040c86f15c ('shared: avoid compiler warning for nm_utils_get_next_realloc_size() returning huge sizes')
2021-01-12 09:56:43 +01:00
Thomas Haller 4686e9baef
n-dhcp4: work around compiler warning in n_dhcp4_socket_packet_send()
With LTO enabled, the compiler might think that "len" is not initialized.
That is even a correct assumption, if the compiler does not understand the
API of sendmsg() and that sendmsg() is supposed to set a negative errno.

Work around by initializing the variable.

    shared/n-dhcp4/src/n-dhcp4-c-connection.c: In function n_dhcp4_c_connection_send_request:
    shared/n-dhcp4/src/n-dhcp4-socket.c:368:19: error: len may be used uninitialized in this function [-Werror=maybe-uninitialized]
             } else if (len != n_buf) {
                       ^
    shared/n-dhcp4/src/n-dhcp4-socket.c:351:23: note: len was declared here
             size_t n_buf, len;
                           ^
2021-01-11 19:03:28 +01:00