Commit graph

16845 commits

Author SHA1 Message Date
Thomas Haller
eaa2188119
cloud-setup: refactor handling of environment variables
Previously, there was NMCS_ENV_VARIABLE() macro. That macro did nothing,
it merely acted as something to grep for, when searching the source for
which environment variables nm-cloud-setup honors. That is an
interesting thing to know, because nm-cloud-setup is configured via
environment variables.

Change that. Instead add a define for each environment variable. You can
now instead grep for "NMCS_ENV_" to find them all.
2023-05-22 17:26:18 +02:00
Thomas Haller
62104477c3
cloud-setup: fix _aliyun_base() initializing base URL
Fixes: f3404435a9 ('cloud-setup: configure secondary ip in Aliyun cloud')
2023-05-22 17:26:18 +02:00
Thomas Haller
77fd4d5f0e
test-cloud-meta-mock: update default MAC address for test-cloud-meta-mock.py
Choose a MAC address that is easily recognizable. And where you can
see which is mac1 and mac2.
2023-05-22 17:24:55 +02:00
Thomas Haller
1a0fa85397
platform/tests: check errno on failure to umount() in test_netns_bind_to_path()
The umount() call failed in a test. Rework the assertion, so
we might see the errno of the problem.
2023-05-22 13:06:35 +02:00
Thomas Haller
dcfcb55166
tests: increase timeout for check-local-tests-cloud-setup test with meson
Fixes: d89d42bf23 ('tests/client: test nm-cloud-setup')
2023-05-19 16:02:29 +02:00
Thomas Haller
63cc5b3104
docs: don't generate <description> tag in "gen-metadata-nm-settings-nmcli"
"gen-metadata-nm-settings-nmcli" previously printed the <description>.
But that tag is not very useful for further processing.

For the most part it itself comes from "src/libnmc-setting/settings-docs.h",
which is generated (but lost formatting information already to be
suitable for where it's used).

Some parts are original texts from "src/libnmc-setting/nm-meta-setting-desc.c",
like TEAM_DESCRIBE_MESSAGE. However those text are also not really suitable
for any other purpose.

Rename the tag, so that the tools that process "gen-metadata-nm-settings-nmcli.xml"
don't use it.

The file "gen-metadata-nm-settings-nmcli.xml" is currently only used to
generate "man/nm-settings-docs-nmcli.xml", and that file slightly
changes with this patch. However, the manual page which is generated by
"man/nm-settings-docs-nmcli.xml" does not change.
2023-05-19 12:52:00 +02:00
Thomas Haller
5d58792848
libnm: add nmcli specific documentation override for "ipv6.addr-gen-mode" 2023-05-19 12:51:59 +02:00
Thomas Haller
b90e7a2c6c
libnm: add "description:" for overrides with doctext
If we have an override with "description-docbook:", we soon will require that
there is also an accompanying "description:", for plain uses.

The text is copied from what otherwise gets merged (it comes from the gir file).
2023-05-19 12:51:59 +02:00
Thomas Haller
92e32c4b7a
libnm/docs: reword documentation for "ipv6.{addr-gen-mode,token}" 2023-05-19 12:51:58 +02:00
Thomas Haller
bcadcc173a
core: improve logging of used IPv6 interface identifier 2023-05-19 12:51:58 +02:00
Thomas Haller
c275d24637
clang-format: reformat code with clang-format 16.0.2-1.fc38
This is the version shipped in Fedora 38. As Fedora 38 is now out, the
core developers switch to it. Our gitlab-ci will also use that as base
image for the check-{patch.tree} tests and to generate the pages. There
is a need that everybody agrees on which clang-format version to use,
and that version should be the one of the currently used Fedora release.

Also update the used Fedora image in "contrib/scripts/nm-code-format-container.sh"
script.

The gitlab-ci still needs update in the following commit. This change
in isolation will break the "check-tree" test.
2023-05-19 10:53:13 +02:00
Beniamino Galvani
93430627c2 team: don't try to connect to teamd in update_connection()
In constructed(), NMDevice starts watching the D-Bus name owner or
monitoring the unix socket, and so it is always aware if teamd is
running. When it is, NMDevice connects to it and initializes
priv->tdc.

It is not useful to try to connect to teamd in update_connection()
because warnings will be generated by NM and by libteam if teamd is
not running. As explained above the connection is always initialized
when teamd is available, and so we can just check priv->tdc.

Fixes: ab586236e3 ('core: implement update_connection() for Team')

https://bugzilla.redhat.com/show_bug.cgi?id=2182029
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1631
2023-05-16 13:18:36 +02:00
Thomas Haller
7a6257d446
libnm: drop duplicate line from "libnm.ver" 2023-05-15 16:32:50 +02:00
Fernando Fernandez Mancera
bc0818fe13 libnm: adjust symbol versioning of bond port prio in 1.40.20
This ABI was backported all the way to 1.42.8 and 1.40.20 and to rhel-8.9.
Move the ABI to a separate symbol version, which we have in all those
versions.
2023-05-15 15:16:49 +02:00
Fernando Fernandez Mancera
9b8220c9fa tests: adjust test-gir.py to allow extra elements in section name 2023-05-15 15:16:49 +02:00
Thomas Haller
efc14fcbec
test-client: drop TestNmClient base class from tests
With the unit test framework, we define special methods, like setUp()
and test_*(). This is documented, but not obvious.

Previously, TestNmClient was the base class for our tests classes, and
it provided some functionality (and state). It was utterly confusing how
pieces fit together.

Instead, move the state to a new class NMTestContext(). That contains
most of the code from TestNmClient. Drop TestNmClient and let the test
classes directly descend from unittest.TestCase.

The difference is, when you now look at a certain test (test_001()), you
can easier understand which code runs when. First, the test class has a
setUp() method which runs, but that method is now trivial without extra
context. Second, there is the @nm_test attribute that wraps the
function. But that's it. It's all at one place, and we delegate instead
of inherit.
2023-05-15 14:59:58 +02:00
Thomas Haller
50f97307c5
test-client: move TestNmClient.ReplaceTextConUuid() to NMStubServer
The goal is to make the base class TestNmClient smaller because it
contains a lot of state, and with inheritance it's hard to follow what
happens.
2023-05-15 14:59:58 +02:00
Thomas Haller
1c32b59ebd
test-client: move TestNmClient.{cmd_construct_argv,_env}() to Util.cmd_create_{argv,env}()
These two are stateless method, and even not only work for nmcli, but also for
nm-cloud-setup. Move to the Util class, as static methods.
2023-05-15 14:59:58 +02:00
Thomas Haller
7ecb659743
test-client: move skip functions to Util class
They can both be used as decorators and called plainly.
2023-05-15 14:59:58 +02:00
Thomas Haller
d1e6edcb7b
test-client: move static function from TestNmClient._read_expected() to Util.file_read_expected()
Static, state-less functions are great. Keep them separate from TestNmClient which
has lots of state.
2023-05-15 14:59:58 +02:00
Beniamino Galvani
53ba9f4701 ipv6ll: don't regenerate the address when it's removed externally
Currently if the IPv6 link-local address is removed after it passed
DAD, NetworkManager tries to generate a new link-local address. If
this fails, which is always the case for EUI64, ipv6ll is considered
as failed and the connection can go down (depending on may-fail).

This is particularly bad for virtual interfaces because if somebody
removes the link-local address, the activation can fail and destroy
the interface, breaking all services that require it. Also, it's a
change in behavior introduced in 1.36.0.

It seems that a better approach here is to re-add the address that was
removed externally.

Fixes: aa070fb821 ('core: add NML3IPv6LL helper')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1622
2023-05-15 10:23:39 +02:00
Beniamino Galvani
5e3bef6ae9 manager: use the right reason for managing devices after wake/reenable
When managing the interface after wake/reenable, the reason determines
whether the device will be sys-iface-state=managed or external.

Commit 5a9a7623c5 ('core: set STATE_REASON_CONNECTION_ASSUMED when
waking up') changed the reason from 'now-managed' to
'connection-assumed'; the effect was that devices that were fully
managed before sleeping become external after a wake up. For example:

  $ nmcli connection add type ethernet ifname enp1s0
  Connection 'ethernet-enp1s0' (47fcd81e-bf00-4c02-b25b-354894f5657e) successfully added.
  $ nmcli device | grep enp1s0
  enp1s0  ethernet  connected               ethernet-enp1s0
  $ nmcli networking off
  $ nmcli device | grep enp1s0
  enp1s0  ethernet  unmanaged    --
  $ nmcli networking on
  $ nmcli device | grep enp1s0
  enp1s0  ethernet  unavailable  --

Set the correct reason during wake up so that the previous state is
restored.

Fixes: 5a9a7623c5 ('core: set STATE_REASON_CONNECTION_ASSUMED when waking up')
https://bugzilla.redhat.com/show_bug.cgi?id=2193422
2023-05-15 10:11:16 +02:00
Beniamino Galvani
1494774bd1 device: add functions to get and set sys-iface-state before sleep 2023-05-15 10:10:42 +02:00
Thomas Haller
c0c8eb347d
libnmc: fix openconnect option "--cafile" in nm_vpn_openconnect_authenticate_helper()
Fixes: 97f2a368f1 ('libnmc-base: add supported options for OpenConnect CLI authentication')
2023-05-12 13:25:58 +02:00
Thomas Haller
a8ba0ea4c7
libnmc: drop redundant defines for array lengths
- use G_N_ELEMENTS() macro instead of having separate defines. The separate
  defines mean that when we check g_return_val_if_fail(oc_argc <= OC_ARGS_MAX, FALSE)
  that we must double check that OC_ARGS_MAX is really the size of the array
  that we want to check.

- replace g_return_val_if_fail() with nm_assert(). In this case, it should be
  very clear by review that the buffer is indeed large enough and the assertion
  holds. Use nm_assert().

- use unsigned integer for the loop variables. While int theoretically
  might exploit undefined behavior of signed overflow, we should instead
  use unsigned at places where it's appropriate (for example, those
  variables are compared against G_N_ELEMENTS() which gives a size_t type.

- declare auto variables on separate lines.

- make the global variable oc_property_args static and const. The const
  means the linker will put it into read-only memory, so we would get
  a crash on accidental modification.
2023-05-12 12:48:00 +02:00
Thomas Haller
62d742625d
tui: cleanup secrets_requested() function to use cleanup attribute
No explicit unref/free. Resources should be owned by somebody, like an
auto variable with a cleanup attribute.
2023-05-12 12:48:00 +02:00
Lubomir Rintel
b93ebb9be9
test/client: test cloud-setup GCP support 2023-05-12 12:42:55 +02:00
Lubomir Rintel
79f6a7da56
cloud-setup/gcp: add ability to redirect metadata API requests
A different host can be specified with (undocumented, private)
NM_CLOUD_SETUP_GCP_HOST environment variable.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
661545efcd
test/client: test cloud-setup azure support 2023-05-12 12:42:55 +02:00
Lubomir Rintel
515e69df3a
cloud-setup/azure: add ability to redirect metadata API requests
A different host can be specified with (undocumented, private)
NM_CLOUD_SETUP_AZURE_HOST environment variable.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
1f310abfd8
test/client: test cloud-setup aliyun support 2023-05-12 12:42:55 +02:00
Lubomir Rintel
6a1dd3b0f8
test-client: use a test fixture from the test
Don't rely on resources provided by mock metadata server by default,
create the from within the test instead.

This allows for more flexibility, but the locality of the test fixture
relative to the tests makes the test more legible.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
e56df68464
test-client: factor out the test device setup
We're going to reuse the setup for tests of other cloud providers.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
0667209913
test-client: hardcode the cloud-setup mac addresses
We rely on the predictable but random MAC addresses. Hardcode them
instead -- the mock service also hardcodes them.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
63452e886f
test: fix file description passing to cloud-setup mock service
The pass_fds file descriptor is *after* the dup2. Always 3.
2023-05-12 12:42:54 +02:00
Lubomir Rintel
2e8ff9f8a0
Revert "client/tests: don't do dup2() dance to pass file descriptor to "tools/test-cloud-meta-mock.py""
This changed the fd passing protocol making it not compatible with
systemd-socket-activate(1).

This reverts commit 342ee618c7.
2023-05-12 12:42:54 +02:00
Thomas Haller
751ee63e61
test-client: cleanup after test on failure
Otherwise, the following tests will fail too.
2023-05-12 12:42:54 +02:00
Thomas Haller
cb51aee21c
test-client: increase context in pexecpt failure for debugging
When a pexpect check fails, we want to see the full content of the
buffer, so we can better see where it went wrong. Increase the context
that is printed in the error message.
2023-05-12 12:42:54 +02:00
Thomas Haller
0888ed93f7
cloud-init: fix leaking iproutes for GCP provider
The routes in iproutes were leaked (and ownership stolen
in _nmc_mangle_connection(), leaving dangling pointers).

Fix that by using a GPtrArray instead.
2023-05-12 12:42:54 +02:00
Thomas Haller
302a5cebe4
libnm-core: add internal _nm_ip_route_ref() helper
For some reason, nm_ip_route_ref() does not return the referenced instance,
making it cumbersome to use. Add a helper.
2023-05-12 12:42:49 +02:00
David Woodhouse
ddce34054e libnmc-base: fix port extraction for openconnect auth
With old versions of openconnect we need to extract the port# from the
initial URL and then append it to the hostname we eventually get back.

Using strrchr(gw, ':') isn't going to work right with IPv6 literals,
ad we should also be dropping any path element.

So switch to using an int for the port instead of a string, and import a
cut-down variant of openconnect's internal_parse_url() which does
*largely* the same thing with strrchr() but is saved by using the 'end'
value returned from strtol() and insisting that the port is the very
end of the host part of the URL.
2023-05-11 13:15:53 +01:00
David Woodhouse
f791b98284 libnmc-base: report explicit error if not gateway configured for openconnect
Rather than letting openconnect run, and whine that there's no gateway,
and making the user scroll up past the openconnect usage information,
give them an explicit error.
2023-05-11 13:15:53 +01:00
David Woodhouse
db7ea2e5d4 nmtui: do not prompt for secrets if openconnect already provided them
While we're at it, kill the separate openconnect_authenticate() function
since it barely does anything any more and it wants visibility to both
's_vpn' and 'success' variables in the caller.
2023-05-11 13:15:53 +01:00
David Woodhouse
715921a1fd nmcli, nmtui: reduce duplication around openconnect auth helper
Pull a bunch of stuff into nm_vpn_openconnect_authenticate_helper() that
both callers were doing for themselves, and make its API a bit simpler.
It's given the NMSettingVpn and the GPtrArray of secrets, and it simply
succeeds or fails.
2023-05-11 13:15:53 +01:00
David Woodhouse
97f2a368f1 libnmc-base: add supported options for OpenConnect CLI authentication
Ideally, we wouldn't have this hard-coded in NetworkManager itself; we
would invoke a tool to do it for us, like the GUI auth-dialog, which
can live in the NetworkManager-openconnect repository and be kept up
to date as new options are added.

To start with though, let's bring it into sync. We don't add new options
that often, and this will cover the majority of use cases.
2023-05-11 13:15:53 +01:00
David Woodhouse
f8d82c7f10 nmcli, nmtui: update authentication for OpenConnect
Since OpenConnect 8.20, 'openconnect --authenticate' will return the
full gateway URL, including the hostname and the path. This allows
servers behind SNI-based proxies to work. To ensure we end up at the
same IP address even behind round-robin DNS, there is a separate
--resolve argument.

Update nmcli/nmtui to use this, as NetworkManager-openconnect does.

Shift some of the logic into the nm_vpn_openconnect_authenticate_helper()
function instead of duplicating it in the callers.

Also, pass the correct protocol in rather than only supporting Cisco
AnyConnect.
2023-05-11 13:15:53 +01:00
Thomas Haller
a20d4a7a91
core/tests: add test for nm_firewall_nft_stdio_mlag()
If only to hit some of the code paths in our test, and to have valgrind
check (some of) the code paths.
2023-05-10 19:03:40 +02:00
Thomas Haller
2c716f04f9
bond: don't configure "counter" on nft rules for slb-bonding/mlag
Counters are convenient for debugging, but have a performance overhead.
Configure them only when debug logging in NetworkManager is enabled.
2023-05-10 19:03:40 +02:00
Thomas Haller
3c3938406d
glib-aux: add nmtst_assert_cmpmem() helper
g_assert_cmpmem() exists, but it does not print the actual buffer
content on test failure.  It is useful to see what actually failed in
the test output.

Also, nmtst_assert_cmpmem() prints a backslash escaped output, that you
can unescape in the terminal with `echo -e`. You can also directly copy
and paste the output to C source code.
2023-05-10 19:03:36 +02:00
Thomas Haller
c26a94e955
glib-aux: add NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_DOUBLE_QUOTE flag to escape double quotes
This is useful when printing a string for debugging. Then we can
printf("v=\"%s\"", utf8safe_escaped_text), which can be safely unescaped
with `echo -e`.
2023-05-10 19:02:04 +02:00