Commit graph

31904 commits

Author SHA1 Message Date
Thomas Haller 8b66865a88
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')
2023-02-08 15:15:45 +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 df228a5f8d
test-client: merge branch 'th/test-client-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1528
2023-02-08 10:50:39 +01:00
Thomas Haller 50d1c8fc16
test-client: re-enable test_monitor() test
It's fixed now. See the previous commit.
2023-02-08 10:11:21 +01:00
Thomas Haller 8548ab29ee
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.
2023-02-08 10:11:20 +01:00
Thomas Haller fc282d5e05
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.
2023-02-08 10:11:19 +01:00
Thomas Haller b32e4c941a
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.
2023-02-08 10:11:18 +01:00
Thomas Haller 4cf94f30c7
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
2023-02-08 10:11:17 +01:00
Thomas Haller 4b2ded7a4a
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().
2023-02-08 10:11:16 +01:00
Thomas Haller d3e2e9dc20
nmcli/trivial: rename monitor functions in internal header file
Identifiers in our headers should have a "nm" prefix. Rename.
2023-02-08 10:11:15 +01:00
Thomas Haller 1630009234
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.
2023-02-08 10:11:14 +01:00
Thomas Haller 6dbb215793
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.
2023-02-08 10:11:14 +01:00
Thomas Haller ee17346cee
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.
2023-02-08 10:11:13 +01:00
Thomas Haller debf78dbed
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.
2023-02-08 10:09:56 +01:00
Thomas Haller d1e6d53013
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.
2023-02-08 09:51:26 +01:00
Thomas Haller 3e574dda22
test-client: cleanup start/shutdown of stub service 2023-02-08 09:51:26 +01:00
Thomas Haller b08f7a9c19
test-client: accept yes/true/no/false for boolean arguments 2023-02-08 09:51:26 +01:00
Thomas Haller 5da7301ec9
test-client: add Util.shlex_join() helper 2023-02-08 09:51:26 +01:00
Thomas Haller b76bb7333e
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
2023-02-08 09:51:25 +01:00
Thomas Haller f6805debee
contrib: avoid using "sudo" in REQUIRED_PACKAGES scripts
It's often not installed, and usually we are already root. Avoid
using sudo.
2023-02-08 09:51:25 +01:00
Thomas Haller ea3e61047f
cli: fix leaking "value" string in ask_option()
Fixes: c5324ed285 ('nmcli: streamline connection addition')
2023-02-08 09:51:25 +01:00
Thomas Haller 5dc07174d3
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')
2023-02-08 09:51:25 +01:00
Thomas Haller 89734c7553
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')
2023-02-08 09:51:25 +01:00
Thomas Haller fb9c2c9a19
hostname: combine implementations of read_hostname() for Gentoo and Slackware 2023-02-08 09:51:25 +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