Commit graph

31198 commits

Author SHA1 Message Date
Thomas Haller
16c0be1ada
style: various minor adjustments 2022-10-25 08:41:45 +02:00
Alexander Elbs
61a302ff6b
core: use new rerequest infrastructure
instead of always re-requesting secrets on authentication failure ask NMSetting
if this is really needed. Currently only for the case "802.1x with TLS" this
behaves differently, i.e. no re-request.
2022-10-25 08:40:09 +02:00
Alexander Elbs
2eccb21b8e
core: move rerequest decision of secrets to NMSetting
When an authentication attempt fails, NetworkManager re-requests new secrets
from agents before retrying. This is currently decided outside of the NMSetting
objects. With this change the decision if a re-request of new secrets is really
needed is moved down to the NMSetting implementations.

For the case "802.1x authentication with TLS" a certificate with password is
configured and the assumption is, that this can never be wrong and no re-request
is needed.
2022-10-25 08:40:09 +02:00
Thomas Haller
99b26bf1d8
cli: merge branch 'th/cli-fork-safety'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1420
2022-10-24 18:52:01 +02:00
Thomas Haller
619032c6d0
cli: increase buffer in pager_fallback()
The stack is large enough. Let's use a larger buffer.
2022-10-24 08:53:04 +02:00
Thomas Haller
e843a7caa2
cli: don't use unsafe functions in pager_fallback()
The pager_fallback() runs in the forked child process.
As such, it can only use functions from `man signal-safety`
or that are explicitly allowed.

We are mostly good, but g_printerr() is not allowed. It can deadlock.
Just avoid it. It's not very to print those error messages anyway.
2022-10-24 08:53:03 +02:00
Thomas Haller
a35d8ff769
cli: don't call setenv() after fork
setenv() cannot be called after fork, because it might allocate memory,
which can deadlock.

Instead, prepare the environment and use execvpe().

`man 2 fork` says:

  After a fork() in a multithreaded program, the child can safely call
  only async-signal-safe functions (see signal-safety(7)) until such time
  as it calls execve(2).

This means, we are quite strongly limited what can be done in the child
process, before exec. setenv() is not listed as async-signal-safe, obviously
because it allocates memory, and malloc() isn't async-signal-safe either.

See also glib's documentation of GSpawnChildSetupFunc ([1]) about what
can be done in the child process.

[1] 08cb200aec/glib/gspawn.h (L124)
2022-10-24 08:53:03 +02:00
Thomas Haller
b395c6959e
all: merge branch 'th/memdup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1404
2022-10-24 08:49:21 +02:00
Thomas Haller
77ea230817
glib-aux,core: use nm_memdup_nul() and nm_memcpy() 2022-10-24 08:48:11 +02:00
Thomas Haller
5e36955f0b
glib-aux: add nm_memdup_nul() helper 2022-10-24 08:48:11 +02:00
Thomas Haller
263832a455
std-aux: add nm_memcpy() helper for handling copy of zero bytes 2022-10-24 08:48:05 +02:00
Beniamino Galvani
50b6f3d6d3 core: fix setting IPv6 retrans timer
Fixes: 5c48c5d5d6 ('l3cfg: set IPv6 sysctls during NML3Cfg commit')
2022-10-21 14:56:23 +02:00
Thomas Haller
0920355227
std-aux: workaround unused variable with clang and nm_auto macro
It also can happen with clang 15 and clang 12. Just silence the warning.

The problem is of course, that we miss if a variable is really unused.
2022-10-20 21:15:56 +02:00
Michael Catanzaro
e6dac4f0b6
core: don't restrict DNS interface when performing connectivity check
Currently, when performing DNS resolution with systemd-resolved,
NetworkManager tells systemd-resolved to consider only DNS configuration
for the network interface that the connectivity check request will be
routed through. But this is not correct because DNS and routing are
configured entirely separately. For example, say we have a VPN that
receives all DNS but only a subset of routing. NetworkManager will
configure systemd-resolved with no DNS servers on any interface except
for the VPN interface, but will still route traffic through other
interfaces. This is entirely legitimate and works fine in practice,
except for the connectivity check.

To fix this, we just drop the restriction and allow systemd-resolved to
consider its full configuration, which is what gets used normally
anyway. This allows our connectivity check to match the real
configuration instead of failing spuriously.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1415
2022-10-19 21:00:47 +02:00
Thomas Haller
c715105372
glib-aux/trivial: improve code comment for NMDedupMultiIdxType 2022-10-19 16:23:15 +02:00
Beniamino Galvani
40897db056 nmcli: fix crash in "nmcli device monitor"
Fix the following crash:

  $ nmcli device monitor a
  Error: Device 'a' not found.
  Segmentation fault (core dumped)

Found by coverity:

  1. NetworkManager-1.41.3/src/nmcli/devices.c:0: scope_hint: In function 'do_devices_monitor'
  2. NetworkManager-1.41.3/src/nmcli/devices.c:2932:28: warning[-Wanalyzer-null-dereference]: dereference of NULL 'devices'
     2930|       }
     2931|
     2932|->     for (i = 0; i < devices->len; i++)
     2933|           device_watch(nmc, g_ptr_array_index(devices, i));
     2934|

Fixes: 2074b28976 ('nmcli/devices: return GPtrArray instead of GSList from get_device_list()')
2022-10-19 16:11:55 +02:00
Thomas Haller
4ffb7cba7b
glib-aux/trivial: add code comment about cleanup macros 2022-10-19 09:20:49 +02:00
Thomas Haller
c7bc4e0c67
checkpatch: suggest nm_memdup() instead of g_memdup() 2022-10-18 20:31:21 +02:00
Thomas Haller
18c9ad1045
all: use nm_memdup() instead of g_memdup()
g_memdup()'s size argument is a guint. There was CVE-2021-27219
about an integer overflow, which results in a buffer overflow.
In response to that, g_memdup2() was introduced in 2.68.

We can't use g_memdup2(), because our currently required glib
version is still 2.40.

There was no bug at those two places where g_memdup() was used.
It's just that g_memdup() is a code smell. Prevent any questions that
a reader of the code might have regarding the correctness of g_memdup()
(w.r.t. integer/buffer overflow), by not using it.

Instead use our internal nm_memdup() variant, which exactly exists for
this reason.

See-also: https://gitlab.gnome.org/GNOME/glib/-/issues/2319
2022-10-18 20:28:25 +02:00
Lubomir Rintel
37582fc384 style: fix code formatting
Fixes: b784da83d2 ('nmcli: show sriov capability in "nmcli" output')
2022-10-17 17:40:40 +02:00
Lubomir Rintel
a7ff6b647c style: fix code formatting
Fixes: 7bf46ced2e ('core/device: demote "strictly unamanged" error')
2022-10-17 17:40:40 +02:00
Lubomir Rintel
7bf46ced2e core/device: demote "strictly unamanged" error
The "device ... not available because device is strictly unmanaged" is
almost certainly the least interesting of the reasons why connection
can't be activated on a device.

Invent a new error level for it and demote it.

Before:

  Error: Connection activation failed: No suitable device found
         for this connection (device lo not available because
         device is strictly unmanaged).

After

  Error: Connection activation failed: No suitable device found
         for this connection (device eth0 not available because
         profile is not compatible with device (...)).

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1433
2022-10-17 11:43:58 +02:00
Lubomir Rintel
59b2ef50e4 core/device: make sriov setting require sriov cap
Make connections that have "sriov" setting incompatible with devices
that lack NM_DEVICE_CAP_SRIOV capability.

Otherwise applying the SR-IOV properties either fails too late, or is
ignored silently.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1432
2022-10-17 11:43:20 +02:00
Beniamino Galvani
227ae41216 platform: merge branch 'bg/sriov-bufsize'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1413
2022-10-17 10:31:04 +02:00
Beniamino Galvani
f7ac887502 platform: set custom netlink buffer size when adding SR-IOV VFs
When there are many VFs the default buffer size of 1 memory page is
not enough. Each VF can take up to ~120 bytes and so when the page
size is 4KiB at most ~34 VFs can be added.

Specify the buffer size when allocating the message.
2022-10-17 10:30:44 +02:00
Beniamino Galvani
a4767ad771 platform: add length argument to _nl_msg_new_link_full()
Add a new argument to specify the netlink buffer length.
2022-10-17 10:30:44 +02:00
Beniamino Galvani
f12d96f0fa platform: change nlmsg_alloc*() functions
Add a len argument to nlmsg_alloc() and nlmsg_alloc_simple(). After
that, nlmsg_alloc_size() can be dropped. Also, rename
nlmsg_alloc_simple() to nlmsg_alloc_new().
2022-10-17 10:30:44 +02:00
Lubomir Rintel
b784da83d2 nmcli: show sriov capability in "nmcli" output
This is sometimes interesting to know.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1431
2022-10-17 10:25:11 +02:00
Beniamino Galvani
2513503dc2 MAINTAINERS: improve documentation about backports
- clarify 'later branch'

- remove backticks from commit hashes so that they are displayed as a
  link in gitlab

- expand the section about backporting API

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1429
2022-10-17 09:53:15 +02:00
Ana Cabral
c280fe81aa merge: branch 'ac/vlan'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418
2022-10-15 16:33:54 +00:00
Ana Cabral
0a280c5a93 device: remove the possibility of inheriting the unmanaged condition from the parent of a device
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
412c7449b3 device: remove the unmanaged inheritance from the parent for macvlan devices
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
66857bafe8 device: remove the unmanaged inheritance from the parent for macsec devices
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
f1a79e97ea device: remove the unmanaged inheritance from the parent for 6lowpan devices
This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

What motivates this change are the unncessary issues brought by this
inheritance. You can see some problems described here:
https://bugzilla.redhat.com/show_bug.cgi?id=2110307#c0.
2022-10-15 18:29:10 +02:00
Ana Cabral
e2dd68b610 device: allow configuration of VLAN on an unmanaged interface
It is not possible to configure a VLAN interface on unmanaged NIC.
This forces users who only want to create a VLAN interface to take
ownership over possibly shared underlying NIC.

In OpenShift, the SR-IOV operator is currently not using
NetworkManager to configure VFs. When it starts working with a NIC,
it explicitly makes it unmanaged. Then, users cannot create a VLAN
interface on PFs managed by the operator.

This commit eliminates this issue by allowing configuring VLAN on
an interface without requesting it to be managed by NetworkManager.

This commit is part of a broader change that eliminates inheriting
the unmanaged condition from the parent of a device, for all device
types:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1418

https://bugzilla.redhat.com/show_bug.cgi?id=2110307
2022-10-15 18:29:10 +02:00
Lubomir Rintel
020c8ff2e2 team: log port config when it's set
Log the port config at trace level. Helps making debugging less
miserable.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1423
2022-10-14 22:43:08 +02:00
Lubomir Rintel
a721413d20 team: don't log failures to connect to teamd on error level
ensure_teamd_connection() is called from multiple spots. Sometimes
we call opportunistically without having started teamd (e.g. when on
update_connection() when generating a connection for teaming device that
was created) and handle the failure to connect gracefully.

Let's not pollute the logs with things on ERROR level that are not
actually serious. Replace the logging statements with DEBUG or WARN
depending on whether we expect ensure_teamd_connection() to actually
succeed.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1422
2022-10-14 22:40:56 +02:00
Lubomir Rintel
6897f6e6df team: set port configuration even if it's empty
Call teamdctl_port_config_update_raw() when we're attaching a port even
if all of team-slave setting properties are default.

This is done to ensure teamd "knows" about the port (that is,
"teamdctl ...  port present" returns success) when we're done activating
the slave connection. It will pick it up anyway from netlink, but that
can happen after the activation is done, resulting in a possible race.

Fixes-test: @remove_active_team_profile

https://bugzilla.redhat.com/show_bug.cgi?id=2102375
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1421
2022-10-14 22:25:07 +02:00
Balázs Úr
839e1ed5da
po: update Hungarian (hu) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1425
2022-10-14 19:01:24 +02:00
Thomas Haller
fd1965e7bb
libnm: merge branch 'th/nmclient-wait-shutdown'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1414
2022-10-14 17:53:38 +02:00
Thomas Haller
88724ff169
libnm: add nm_client_wait_shutdown() function for cleaning up NMClient
Add a fire-and-forget function to wait for shutdown to be complete.

It's not entirely trivial to ensure all resources of NMClient are
cleaned up. That matters only if NMClient uses a temporary GMainContext
that the user wants to release while the application continues. For
example, to do some short-lived operations an a worker thread. It's
not trivial also because glib provides no convenient API to integrate
a GMainContext in another GMainContext. We have that code as
nm_utils_g_main_context_create_integrate_source(), so add a helper
function to allow the user to do this.

The function allows to omit the callback, in which case the caller
wouldn't know when shutdown is complete. That would still be useful
however, when integrating the client's context into the caller's
context, so that the client's context gets automatically iterated
until completion.

The following test script will run out of file descriptors,
when wait_shutdown() is not used:

   #!/bin/python

   import gi

   gi.require_version("NM", "1.0")
   from gi.repository import NM, GLib

   for i in range(1200):
       print(f">>>{i}")

       ctx = GLib.MainContext()
       ctx.push_thread_default()
       nmc = NM.Client.new()
       ctx.pop_thread_default()

       def cb(unused, result, i):
           try:
               NM.Client.wait_shutdown_finish(result)
           except Exception:
               # cannot happen
               assert False
           else:
               print(f">>>>> {i} complete")

       nmc.wait_shutdown(True, None, cb, i)

       while GLib.MainContext.default().iteration(False):
           pass
2022-10-14 17:48:24 +02:00
Thomas Haller
2f5a2dc732
libnm: add "initialized-{good,bad}" flags to NMClientInstanceFlags
When using async initialization with GAsyncInitable, the user usually can
only know that initialization is complete by passing a callback.
In simple cases, that can be cumbersome.

Also expose a flag that allows to poll that information.

Reuse the existing NM_CLIENT_INSTANCE_FLAGS for that. There is an
ugliness here, that suddenly there are instance flags that cannot be
set, but are still returned by the getter. But as this is a relatively
obscure feature, it seems more lightweight to implement it this way
(instead of adding a separate property and getter function).
2022-10-14 17:37:03 +02:00
Thomas Haller
67ee036389
glib-aux/tests: add nmtst_true_once() helper 2022-10-14 17:37:02 +02:00
Beniamino Galvani
e03b8fa447 dns: merge branch 'bg/dns-sort'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1427
2022-10-14 10:34:32 +02:00
Beniamino Galvani
3cc7801779 dns: sort the ip-data list when a new element is added
In nm_dns_manager_set_ip_config() we try to avoid calling update_dns()
unless something changes, because updating DNS is expensive and can
trigger other actions such as a new hostname resolution.

When we add a new ip_data, even if the new element is equivalent to
the old one that was removed, we need to sort the list again.

Fixes: ce0a36d20f ('dns: better track l3cd changes')
https://bugzilla.redhat.com/show_bug.cgi?id=2098574
2022-10-13 17:25:21 +02:00
Beniamino Galvani
4d1ecd8d6d dns: add comment explaining the purpose of any_removed 2022-10-13 17:24:58 +02:00
gaoxingwang
2a0bbd788b
nmcli: fix typo 'exiting' -> 'existing'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1115

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1424
2022-10-12 15:41:48 +02:00
Thomas Haller
977787171e
trivial: fix indentation 2022-10-11 18:27:32 +02:00
Thomas Haller
b28c6ca30e
all: avoid "-Wunreachable-code-generic-assoc" warning with _Generic()
Clang 15 ([1], [2]) added

  Added the -Wunreachable-code-generic-assoc diagnostic flag (grouped
  under the -Wunreachable-code flag) which is enabled by default and warns
  the user about _Generic selection associations which are unreachable
  because the type specified is an array type or a qualified type.

This causes compiler warnings with various uses of _Generic():

  ../src/libnm-glib-aux/nm-shared-utils.h:2489:12: error: due to lvalue conversion of the controlling expression, association of type 'const char *const *const' will never be selected becaus
  e it is qualified [-Werror,-Wunreachable-code-generic-assoc]
      return nm_strv_find_first((const char *const *) strv->pdata, strv->len, str);
             ^
  ../src/libnm-glib-aux/nm-shared-utils.h:475:25: note: expanded from macro 'nm_strv_find_first'
      _nm_strv_find_first(NM_CAST_STRV_CC(list), (len), (needle))
                          ^
  ../src/libnm-glib-aux/nm-macros-internal.h:397:22: note: expanded from macro 'NM_CAST_STRV_CC'
                 const char *const*const: (const char *const*) (value), \
                       ^

Clang is correct.

[1] https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#improvements-to-clang-s-diagnostics
[2] https://reviews.llvm.org/D125259
2022-10-11 17:21:11 +02:00
Thomas Haller
8aa8d483f2
all: fix deprecated function declaration without a prototype
Clang 15 now (correctly) warns about this:

  ../src/libnm-core-impl/nm-vpn-plugin-info.c:201:40: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  _nm_vpn_plugin_info_get_default_dir_etc()
                                         ^
                                          void
  ../src/libnm-core-impl/nm-vpn-plugin-info.c:213:40: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  _nm_vpn_plugin_info_get_default_dir_lib()
                                         ^
                                          void
  ../src/libnm-core-impl/nm-vpn-plugin-info.c:226:41: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  _nm_vpn_plugin_info_get_default_dir_user()
                                          ^
                                           void
  ../src/libnm-core-impl/nm-vpn-plugin-info.c:315:29: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
  nm_vpn_plugin_info_list_load()
                              ^
                               void
2022-10-11 17:21:11 +02:00