Commit graph

31715 commits

Author SHA1 Message Date
Thomas Haller
edd4f4eaad
release: bump version to 1.42.1 (development) 2023-02-10 09:14:28 +01:00
Thomas Haller
119ed52038
release: bump version to 1.42.0 2023-02-10 09:14:28 +01:00
Thomas Haller
d452ecc3e7
NEWS: update 2023-02-10 09:02:17 +01:00
Thomas Haller
6e7fb78b18
glib-aux: drop usage of malloc_usable_size() in nm_free_secret()
The idea of nm_free_secret() is to clear the secrets from memory. That
surely is some layer of extra snake oil, because we tend to pass secrets
via D-Bus, where the memory gets passed down to (D-Bus) libraries which
have no idea to keep it private. Still...

But turns out, malloc_usable_size() might not actually be usable for
this. Read the discussion at [1].

Stop using malloc_usable_size(), which seems unfortunate.

There is probably no secret relevant data after the NUL byte anyway,
because we tend to create such strings once, and don't rewrite/truncate
them afterwards (which would leave secrets behind as garbage).

Note that systemd's erase_and_free() still uses malloc_usable_size()
([2]) but the macro foo to get that right is terrifying ([3]).

[1] https://github.com/systemd/systemd/issues/22801#issuecomment-1343041481
[2] 11c0f0659e/src/basic/memory-util.h (L101)
[3] 7929e180aa

Fixes: d63cd26e60 ('shared: improve nm_free_secret() to clear entire memory buffer')
(cherry picked from commit 8b66865a88)
2023-02-09 14:08:13 +01:00
Lubomir Rintel
769c55b2de
NEWS: update
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1521
(cherry picked from commit 479e4dbfee)
2023-02-09 13:05:25 +01:00
Thomas Haller
5bc7789c4a
NEWS: update 2023-02-08 20:52:24 +01:00
Thomas Haller
9a940630df
dispatcher: merge branch 'dylanvanassche:method-change-dispatch'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1311

(cherry picked from commit 3fd28a11d4)
2023-02-08 20:51:08 +01:00
Dylan Van Assche
e20eb72fe7
man: NetworkManager-dispatcher: document reapply action
NetworkManager dispatcher will now run dispatcher scripts with 'reapply'
as action as well. Each time the connection is reapplied on a device,
this action is triggered. Document this action in the documentation.

(cherry picked from commit 0e3d2c367c)
2023-02-08 20:51:07 +01:00
Dylan Van Assche
7a3b5de314
nm-dispatcher: dispatch on reapply
Trigger a dispatcher event when a connection is reapplied on a NM device.
Some devices such as phones have already a DHCP client running for accepting
connections when they are plugged into USB to transfer data over SSH.
When NetworkManager switches the connection IP method to shared,
it spawns a dnsmasq process to handle DHCP and DNS for that connection.
However, a dispatcher event is needed to disable the external DHCP server
for these USB connections as NetworkManager's dnsmasq handles them now.
Moreover, when the connection method is switched to a different mode,
the external DHCP server needs to be spawned again to make sure that
SSH connections are still possible to the device.

To achieve this, add a new NetworkManager Dispatcher event
'reapply' which is triggered when a connection is reapplied on a NM
device. This way, a dispatcher script can handle the case above by
inspecting the IP method in the dispatcher script.

(cherry picked from commit cef880c66f)
2023-02-08 20:51:07 +01:00
Thomas Haller
54ddd45311
test-client: merge branch 'th/test-client-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1528

(cherry picked from commit df228a5f8d)
2023-02-08 10:53:45 +01:00
Thomas Haller
2f846eea0d
test-client: re-enable test_monitor() test
It's fixed now. See the previous commit.

(cherry picked from commit 50d1c8fc16)
2023-02-08 10:53:07 +01:00
Thomas Haller
323c60e4cd
test-client: fix race in test_monitor() test
During srv_shutdown() we do

  p.stdin.close()
  p.kill()

Usually, the kill wins and the service just drops off the bus:

  libnm-dbus[3201919]: <debug> [438617.45324] nmclient[40f7938626f3f5f0]: name owner changed: ":1.1" -> (null)
  libnm-dbus[3201919]: <debug> [438617.45332] nmclient[40f7938626f3f5f0]: release all

at which point all objects in NMClient get destroyed and the signals get
emitted in the order:

  libnm-dbus[3201919]: <trace> [438617.45574] nmclient[40f7938626f3f5f0]: [nmclient] emit "device-removed" signal for /org/freedesktop/NetworkManager/Devices/1
  nmcli[out]: eth0: device removed
  libnm-dbus[3201919]: <trace> [438617.45590] nmclient[40f7938626f3f5f0]: [nmclient] emit "any-device-removed" signal for /org/freedesktop/NetworkManager/Devices/1
  libnm-dbus[3201919]: <trace> [438617.45593] nmclient[40f7938626f3f5f0]: [nmclient] emit "connection-removed" signal for /org/freedesktop/NetworkManager/Settings/Connectio>
  nmcli[out]: con-1: connection profile removed

However, sometimes the stub service notices that stdin was closed and it
sends signals about shutting down:

  libnm-dbus[3201061]: <trace> [438226.44965] nmclient[401639659459c316]: interfaces-removed: [/org/freedesktop/NetworkManager/Settings] receive interface remove event for >
  libnm-dbus[3201061]: <trace> [438226.44966] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager/Settings]: changed-type 0x01 linked
  libnm-dbus[3201061]: <trace> [438226.44967] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager/Settings]: changed-type 0x01 consumed
  libnm-dbus[3201061]: <trace> [438226.44968] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager/Settings]: changed-type 0x02 linked
  libnm-dbus[3201061]: <trace> [438226.44969] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager/Settings]: unregister NMClient from D-Bus object
  libnm-dbus[3201061]: <trace> [438226.44971] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager/Settings]: drop D-Bus instance
  libnm-dbus[3201061]: <trace> [438226.44971] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager/Settings]: set D-Bus object state unlinked
  libnm-dbus[3201061]: <trace> [438226.44972] nmclient[401639659459c316]: [nmclient] emit "connection-removed" signal for /org/freedesktop/NetworkManager/Settings/Connectio>
  nmcli[out]: con-1: connection profile removed
  libnm-dbus[3201061]: <trace> [438226.44992] nmclient[401639659459c316]: interfaces-removed: [/org/freedesktop/NetworkManager] receive interface remove event for interface>
  libnm-dbus[3201061]: <trace> [438226.44994] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager]: changed-type 0x01 linked
  libnm-dbus[3201061]: <trace> [438226.44995] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager]: changed-type 0x01 consumed
  libnm-dbus[3201061]: <trace> [438226.44996] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager]: changed-type 0x02 linked
  libnm-dbus[3201061]: <trace> [438226.44998] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager]: unregister NMClient from D-Bus object
  libnm-dbus[3201061]: <trace> [438226.44999] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager]: drop D-Bus instance
  libnm-dbus[3201061]: <trace> [438226.45000] nmclient[401639659459c316]: [/org/freedesktop/NetworkManager]: set D-Bus object state unlinked
  libnm-dbus[3201061]: <trace> [438226.45001] nmclient[401639659459c316]: [nmclient] emit "device-removed" signal for /org/freedesktop/NetworkManager/Devices/1
  nmcli[out]: eth0: device removed
  libnm-dbus[3201061]: <trace> [438226.45005] nmclient[401639659459c316]: [nmclient] emit "any-device-removed" signal for /org/freedesktop/NetworkManager/Devices/1
  nmcli[out]: NetworkManager is stopped
  libnm-dbus[3201061]: <debug> [438226.45545] nmclient[401639659459c316]: name owner changed: ":1.1" -> (null)
  libnm-dbus[3201061]: <debug> [438226.45550] nmclient[401639659459c316]: release all

The fix is to accept the events in any order.

(cherry picked from commit 8548ab29ee)
2023-02-08 10:53:06 +01:00
Thomas Haller
07c0680ff6
test-client: randomly kill or close the stub test service
The test stub service watches stdin, and if it gets closed the service
will shut down. Note that the service does not catch any signals, so
sending a signal will kill the service right away.

The previous code first closed stdin, and then killed the process.
That can result in different outcomes on D-Bus. Usually the signal
gets received first, and the test service just drops off the bus.
Sometimes it notices the closing of stdin and shuts actively down.

That can make a difference, especially for the test_monitor() test which
runs the monitor while stopping the service.

We could just always kill the stub service to get consistent behavior.
However, that doesn't seem very useful. Instead, randomize the behavior
to easier see how the behavior differs.

(cherry picked from commit fc282d5e05)
2023-02-08 10:53:06 +01:00
Thomas Haller
899372480e
nmcli: replace all uses of g_print()/g_printerr() with nmc_print()/nmc_printerr()
The main purpose is to simplify printf debugging and manual testing.  We
can now trivially patch the code so that all output from nmcli gets
(additionally) written to a file. That is useful when debugging a unit
test in "test-client.py". Thereby we can duplicate all messages via
nm_utils_print(), which is in sync with the debug messages from libnm
and which honors LIBNM_CLIENT_DEBUG_FILE.

(cherry picked from commit b32e4c941a)
2023-02-08 10:53:06 +01:00
Thomas Haller
61100788e7
nmcli: add nmc_print()/nmc_printerr() macros
These will replace the direct calls to g_print()/g_printerr() in nmcli.
There are two purposes.

1) the new macros embody the concept of "printing something from nmcli".
   It means, we can `git grep` for those functions, and find all the
   relevant places, without hitting the irrelevant ones (e.g. tests that
   also use g_print()).

2) by having one place, we can trivially change it. That is useful for
   printf debugging. For example, "test-client.py" runs nmcli and
   captures and compares the output.  With libnm we can set
   LIBNM_CLIENT_DEBUG and LIBNM_CLIENT_DEBUG_FILE to print libnm debug
   messages to a file. But we cannot trivially synchronize the messages
   from nmcli with that output (also because they are consumed by the test
   and not immediately accessible). This would be easy, if we temporarily
   could patch nmc_print*() to also log to nm_utils_print(). The new macros
   will allow doing that at one place.

For example, patch the "#if 0" and run:

  $ LIBNM_CLIENT_DEBUG=trace \
    LIBNM_CLIENT_DEBUG_FILE='xxx.%p' \
    NMTST_USE_VALGRIND=1 \
    LIBTOOL="/bin/sh ./libtool"
    ./src/tests/client/test-client.sh -- -k monitor

(cherry picked from commit 4cf94f30c7)
2023-02-08 10:53:06 +01:00
Thomas Haller
a791078798
nmcli/trivial: rename nmc_print() to nmc_print_table()
nmc_print() will be used for something else. Rename. Also,
nmc_print_table() is the better name anyway because the function does  a
lot of formatting and not simple printf().

(cherry picked from commit 4b2ded7a4a)
2023-02-08 10:53:06 +01:00
Thomas Haller
6298b32281
nmcli/trivial: rename monitor functions in internal header file
Identifiers in our headers should have a "nm" prefix. Rename.

(cherry picked from commit d3e2e9dc20)
2023-02-08 10:53:06 +01:00
Thomas Haller
1a9892620e
test-client: pass LIBNM_CLIENT_DEBUG to nmcli
For debugging libnm, LIBNM_CLIENT_DEBUG can be very useful.

As the tests compare stdout/stderr from nmcli with expected output, just
enabling it will break the tests. However, in combination with
LIBNM_CLIENT_DEBUG_FILE this can be very useful.

Preserve and pass on the environment variables, if set.

(cherry picked from commit 1630009234)
2023-02-08 10:53:06 +01:00
Thomas Haller
6adca24ee1
libnm: support LIBNM_CLIENT_DEBUG_FILE to print debug logging to file
With LIBNM_CLIENT_DEBUG we get debug logging for libnm, either to stdout
or to stderr.

"test-client.py" runs nmcli as a unit test. It thereby catches stdout
and stderr. That means, LIBNM_CLIENT_DEBUG would break the tests.

Now honor the LIBNM_CLIENT_DEBUG_FILE environment variable to specify a
file to which the debug logs get written. The pattern "%p" is replaced
by the process id.

As before, nm_utils_print(0, ...) also honors this environment variable
and uses the same logging destination.

(cherry picked from commit 6dbb215793)
2023-02-08 10:53:06 +01:00
Thomas Haller
0694ecfcc5
test-client: cleanup imports
Sort imports by name. Also avoid "from signal import SIGINT". I find
it ugly to import names in the current namespace. "SIGINT" should be
refered to by its full name, including the package/namespace.

(cherry picked from commit ee17346cee)
2023-02-08 10:53:05 +01:00
Thomas Haller
ba5cbedd2c
test-client: add valgrind support for call_nmcli_pexpect() tests
This will allow to find some memory leaks and memory corruptions.

The bulk of the nmcli calls are still not hooked up with valgrind.
Since we call nmcli a thousand time, we could not just run valgrind with
all of them. We would have instead to enable it randomly. This is
more work.

(cherry picked from commit debf78dbed)
2023-02-08 10:53:05 +01:00
Thomas Haller
0e13811a4b
test-client: drop unused NmTestBase base class
The base class is not used, and it's not clear that it would be useful.
Sure, we could extend "test-client.py" will various non-nmcli tests. That
might make sense. And then it might make sense to have more unit test classes.
So far, we don't need that. Drop the unused base class NmTestBase.

(cherry picked from commit d1e6d53013)
2023-02-08 10:53:05 +01:00
Thomas Haller
05e5a2fefd
test-client: cleanup start/shutdown of stub service
(cherry picked from commit 3e574dda22)
2023-02-08 10:53:05 +01:00
Thomas Haller
c9951d5d32
test-client: accept yes/true/no/false for boolean arguments
(cherry picked from commit b08f7a9c19)
2023-02-08 10:53:05 +01:00
Thomas Haller
d0896a13ee
test-client: add Util.shlex_join() helper
(cherry picked from commit 5da7301ec9)
2023-02-08 10:53:05 +01:00
Thomas Haller
ec454f924c
test-client: pass extra argument in "test-client.sh" to python test
For example:

  $ src/tests/client/test-client.sh -- TestNmcli.test_004
  $ src/tests/client/test-client.sh -- -k monitor

(cherry picked from commit b76bb7333e)
2023-02-08 10:53:05 +01:00
Thomas Haller
3520ff8f79
contrib: avoid using "sudo" in REQUIRED_PACKAGES scripts
It's often not installed, and usually we are already root. Avoid
using sudo.

(cherry picked from commit f6805debee)
2023-02-08 10:53:03 +01:00
Thomas Haller
e60ff37f79
cli: fix leaking "value" string in ask_option()
Fixes: c5324ed285 ('nmcli: streamline connection addition')
(cherry picked from commit ea3e61047f)
2023-02-08 10:52:45 +01:00
Thomas Haller
633c734255
cli: use "free()" for string from readline
Since glib 2.45, we are guaranteed that g_free() just calls free(), so
both can be used interchangeably. However, we still only depend on glib
2.40.

In any case, it's ugly to mix the two. Memory allocated by plain
malloc(), should be only freed with free(). The buffer in question comes
from readline, which allocates it using the system allocator.

Fixes: 995229181c ('cli: remove editor thread')
(cherry picked from commit 5dc07174d3)
2023-02-08 10:52:45 +01:00
Thomas Haller
de87340b2f
cli: avoid leak in readline_cb() overwriting previous line
Such leaks show up in valgrind, and are simply bugs.

Also, various callers (not all of them, which is another bug!) like to
take ownership of the returned string and free it. That means, we leave
a dangling pointer in the global variable, which is very ugly and error
prone.

Also, the callers like to free the string with g_free(), which is not
appropriate for the "rl_string" memory which was allocated by readline.
It must be freed with free(). Avoid that, by cloning the string using
the glib allocator.

Fixes: 995229181c ('cli: remove editor thread')
(cherry picked from commit 89734c7553)
2023-02-08 10:52:45 +01:00
Thomas Haller
6e2fc9b554
hostname: combine implementations of read_hostname() for Gentoo and Slackware
(cherry picked from commit fb9c2c9a19)
2023-02-08 10:52:44 +01:00
Thomas Haller
1349b850e3
platform: merge branch 'th/platform-ecmp-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1526

(cherry picked from commit 58011fe88d)
2023-02-07 14:26:47 +01:00
Thomas Haller
f71572a4bc
core: suppress onlink flag for IPv4 routes without gateway
(cherry picked from commit e59d09b053)
2023-02-07 14:26:46 +01:00
Thomas Haller
4ccca2b5bd
platform,core: better handle onlink flag for ECMP routes
The onlink flag is part of each next hop.

When NetworkManager configures ECMP routes, we won't support that. All
next hops of an ECMP route must share the same onlink flag. That is fine
and fixed by this commit.

What is not fine, is that we don't track the rtnh_flags flags in
NMPlatformIP4RtNextHop, and consequently our nmp_object_id_cmp() is
wrong.

Fixes: 5b5ce42682 ('nm-netns: track ECMP routes')
(cherry picked from commit 6ed966258c)
2023-02-07 14:26:45 +01:00
Thomas Haller
7c8ec03d5e
core: don't postpone configuring onlink ECMP routes
Also add some code comments.

Fixes: 7a844ecba9 ('netns: fix configuring onlink routes for ECMP routes')
(cherry picked from commit 6081e61d91)
2023-02-07 14:26:45 +01:00
Thomas Haller
aa15a7c55c
core: don't create dependent onlink route for onlink routes
If the route with a next hop is already onlink, we don't need to add a
direct route to the gateway.

It also wouldn't work previously, because the onlink route to the
gateway that we would add, would have no gateway and the RTNH_F_ONLINK
set. Kernel would reject that with an error. We would have to clear the
RTNH_F_ONLINK flag, if there is no gateway.

(cherry picked from commit 93b46c8906)
2023-02-07 14:26:45 +01:00
Thomas Haller
09d5c4e22e
platform: fix handling the onlink route attribute for routes without gateway
For IPv6, kernel doesn't care. If the gateway is ::, you may or may
not set the onlink attribute. But for IPv4 routes, that gets rejected:

  # ip route add 1.2.3.4/32 dev v onlink
  Error: Invalid flags for nexthop - PERVASIVE and ONLINK can not be set.

Silently suppress setting the flag in that case and ignore the user
request. After all, the effect is probably the same (that is, the route
is onlink anyway).

(cherry picked from commit 8b14849877)
2023-02-07 14:26:44 +01:00
Thomas Haller
41d667ba2a
po: fix marking "nm-setting-ovs-dpdk.c" for translation
Fixes: f930d55fea ('all: add support for ovs-dpdk n-rxq-desc and n-txq-desc')
(cherry picked from commit 88c08721c3)
2023-02-07 13:51:15 +01:00
Beniamino Galvani
618efd56a4
merge: branch 'bg/dns'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1506

(cherry picked from commit 6da2f3af4d)
2023-02-07 13:46:15 +01:00
Beniamino Galvani
2a0f41af03
dns: consider the dns-type and the priority when hashing DNS configs
The dns-type must be included in the hash because it contributes to
the generated composite configuration. Without this, when the type of
a configuration changes (e.g. from DEFAULT to BEST), the DNS manager
would determine that there was no change and it wouldn't call
update_dns().

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

Fixes: 8995d44a0b ('core: compare the DNS configurations before updating DNS')
(cherry picked from commit 46ccc82a81)
2023-02-07 13:46:15 +01:00
Beniamino Galvani
b14268290a
core,libnm: move enum NMDnsIPConfigType
The enum will be used outside of core/dns.

(cherry picked from commit 8a4632b56a)
2023-02-07 13:46:14 +01:00
Beniamino Galvani
a7412e2c65
core: rename and move nm_ip_config_dns_hash()
The function operates on a NML3ConfigData, rename it and move it to
the right place.

(cherry picked from commit ec0a83b224)
2023-02-07 13:46:14 +01:00
Thomas Haller
379af3e753
platform/tests: merge branch 'th/platform-cache-test-2'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1525

(cherry picked from commit 04fb042965)
2023-02-01 22:45:57 +01:00
Thomas Haller
184c7b528e
platform/tests: re-enable and fix "/route/test_cache_consistency_routes" tests
The tests failed in certain cases on gitlab-ci and were temporarily
disabled.

These issues should be fixed now and the test pass. Reenable.

(cherry picked from commit 5c324adc7c)
2023-02-01 22:45:57 +01:00
Thomas Haller
34c707ee78
platform/tests: workaround failure of nmtstp_assert_platform()
(cherry picked from commit 82e21a4906)
2023-02-01 22:45:56 +01:00
Thomas Haller
ddb5e1d50e
platform/tests: disable check for sorted IPv4 routes by weak-id
Due to a kernel bug, this assert can fail and I don't think
it can be fixed in NetworkManager. Disable the check.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2165720
(cherry picked from commit 0347dc7ddc)
2023-02-01 22:45:56 +01:00
Thomas Haller
eb73367d67
platform/tests: flush all tables in test_cache_consistency_routes() test
(cherry picked from commit 8089133f1c)
2023-02-01 22:45:56 +01:00
Thomas Haller
dedbc9ef05
platform/tests: suppress noisy output in test_cache_consistency_routes() test
(cherry picked from commit de1dccba18)
2023-02-01 22:45:56 +01:00
Fernando Fernandez Mancera
d9d33e2acc netns: fix configuring onlink routes for ECMP routes
Kernel enforces that all nexthops must be reachable through a route.
L3Cfg is generating dependent onlink routes to solve this problem but
the IPv4 ECMP commit is happening before that.

To solve this we introduce two boolean fields "is_new" and "is_ready" to
know in which state is the L3Cfg affected. Initially, "is_new" is TRUE
and "is_ready" is FALSE. Here we schedule a commit on idle and we set
"is_new" to FALSE. When revisiting, we set "is_ready" to TRUE and then
we set the ECMP IPv4 routes.

When a reapply kicks in we reset the L3Cfg state by setting "is_new" to
TRUE.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1520
(cherry picked from commit 7a844ecba9)
2023-02-01 11:04:09 +01:00
Fernando Fernandez Mancera
79a9fcb166 l3-config-data: do not check route table to get direct routes
Kernel enforces that all route nexthop are reachable but it doesn't care
if the drect route to the nexthop is in a different route table.

(cherry picked from commit f187e63fa8)
2023-02-01 11:04:09 +01:00