Commit Graph

32561 Commits

Author SHA1 Message Date
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
Thomas Haller
fe5dfe97f9 cloud-setup: merge branch 'lr/more-cloud-setup-tests'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1606
2023-05-12 12:45:16 +02:00
Lubomir Rintel
c72e085f5c test/cloud-meta-mock: mock GCP metadata API
Not used for testing, but still might be useful for development.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
5b5ef08aee test/cloud-meta-mock: mock azure metadata API
Not used for testing, but still might be useful for development.
2023-05-12 12:42:55 +02:00
Lubomir Rintel
620a737cb7 test/cloud-meta-mock: mock aliyun metadata API
Not used for testing, but still might be useful for development.
2023-05-12 12:42:55 +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
41f0f6fec8 test/cloud-meta-mock: allow putting the resources
This reworks the cloud metadata mock server in a significant way.

Most importantly this makes it possible for the client to add and
modify the resources for later retrieval using the PUT method.
This allows the test to create the fixture for itself.

The default set of resources is still provided, so that the too remains
useful as a development aid. If that is not desirable, the --empty
parameter might be passed to cause the server to start with no
resources.
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
Thomas Haller
a206042eda cli,tui: merge branch 'dwmw2:openconnect-cli'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1625
2023-05-11 17:46:27 +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
Sabri Unal
fa715e2387 po: fix mistranslation in Turkish (tr)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1626
2023-05-11 13:15:13 +02:00
Thomas Haller
eaebce6791 bond: merge branch 'th/slb-bond-no-counters'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1623
2023-05-10 19:05:07 +02: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
Thomas Haller
fed850b5b9 glib-aux: use GModule instead of dlopen() in _inet_aton()
Using dlopen() requires us to link with libdl (at least with
some libc). That is cumbersome and was not done by all users of
libnm-glib-aux, thereby causing a linker error.

The code path is only used via nm_assert(). Use GModule instead.

Fixes: a23af8f764 ('glib-aux: avoid using inet_aton()')
2023-05-10 18:58:49 +02:00
Thomas Haller
4c48301594 device: don't reset "net.ipv6.conf.$IFACE.forwarding"
According to systemd, IPv6 forwarding is special anyway, and they only
enable forwarding for "net.ipv6.conf.all.forwarding" ([1]).

Since commit 46e63e03af ('device: announce the managed IPv6
configuration with ipv6.method=shared') we support "ipv6.method=shared"
and enable forwarding for IPv6, on the interface. Whether that makes
sense is questionable, given [1] and the claim that setting it
per-interface is not useful.

Anyway, since that change we always reset the "forwarding" sysctl to
zero, when we don't enable shared mode. That is not right, because the
user didn't explicitly ask for that (and there is no configuration
option like systemd-networkd's "IPForward=" setting to control that).

What we instead should do, not touch/reset the sysctl, unless we really
want to.

No longer set "forwarding" to zero by default. And only restore the
previous value (_dev_sysctl_save_ip6_properties()) if we actually
changed the value to "1".

[1] b8fba0cded/src/network/networkd-sysctl.c (L79)

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

Fixes: 46e63e03af ('device: announce the managed IPv6 configuration with ipv6.method=shared')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1616
2023-05-09 10:21:25 +02:00
Thomas Haller
89edca4628 gitlab-ci: remove container cleanup stages
These stages were not properly implemented and don't seem to work.
Drop them.

Note that we do want that our cached containers get collected eventually.
As these are just caches for performance reasons, that could be done with
little downsides (we can just regenerate the containers when we need them).
However, that's not done by our gitlab-ci stages. Instead, it should
be done on a project level. It's not clear whether that is actually done,
but if there is a need (because of the resources that this wastes), then
we should do that (on freedesktop.org's gitlab instance).
2023-05-09 09:53:43 +02:00
Thomas Haller
bbfd1377b4 Squashed 'src/n-dhcp4/' changes from f8fc48dc014d..b2a382ac4500
b2a382ac4500 test: use inet_pton() instead of inet_aton() in test tool
45df6a37a710 meson: no longer pass -Wl,--no-undefined explicitly
bb9bcdee5754 n-dhcp4-client: make n_dhcp4_client_set_log_level public

git-subtree-dir: src/n-dhcp4
git-subtree-split: b2a382ac4500dee1abfb7cd5acaa3678e47e9662
2023-05-09 08:53:48 +02:00
Thomas Haller
581eb33ecf n-dhcp4: re-import git-subtree for 'src/n-dhcp4'
git subtree pull --prefix src/n-dhcp4 git@github.com:nettools/n-dhcp4.git master --squash
2023-05-09 08:53:48 +02:00
Thomas Haller
7e03f9c1ba glib-aux: merge branch 'th/no-inet-aton'
See-also: https://bugs.python.org/issue37495
https://bugzilla.redhat.com/show_bug.cgi?id=2049134

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1620
2023-05-09 08:35:28 +02:00
Thomas Haller
a23af8f764 glib-aux: avoid using inet_aton()
nm_inet_parse_bin_full() supports a legacy mode for IPv4, which used
inet_aton(). This is only used by initrd reader, which parses the
kernel command line as defined by dracut. Since that dracut API is old
and not defined by us, we want to be more forgiving in case a user
specifies something that used to work in the past. In particular,
we want to parse "255.256.256.000" as netmask (which inet_pton() would
reject).

inet_aton() trips off some ABI checkers that we shouldn't use this ABI.
It was anyway only used as *additional* guard when we parsed certain
legacy formats for IPv4 addresses. We can drop that and just use our
parser.

Note that there is still an nm_assert() path, which loads inet_aton()
dynamically, just to ensure that our legacy parser implementation is in
agree with inet_aton().

https://bugzilla.redhat.com/show_bug.cgi?id=2049134
2023-05-08 15:44:49 +02:00
Thomas Haller
2b9c6fc20a glib-aux/tests: add unit test for nm_inet_parse_bin_full() 2023-05-08 13:32:20 +02:00
Thomas Haller
0670f958fe triage: only make stale issues/merge-requests with a label instead of autoclosing them
An issue/merge-requests only moves forward by a human putting effort in.
Wether the issue is open, closed, autoclosed or flagged with a "stale"
label doesn't matter in theory.

In practice, humans don't like getting their issues/merge-requests
autoclosed. Instead, add a "stale" label.

There was always a benefit of this automatic action. It tended to
generate some feedback and new action. Sometimes it even brought new
attention to the issue/merge-request to get it fixed. That is hopefully
also the case with the stale label.
2023-05-08 11:04:50 +02:00
Thomas Haller
1c904c7d27 man: qualify properties in man nm-settings-nmcli with setting name
The manual page is large. When you search for a properties, then it's
not immediately clear to which setting it belongs. You would have to
scroll up for the setting name.

This also makes sense for the nmcli manual page, because on the command
line you have to specify the full name.
2023-05-08 11:04:50 +02:00
Thomas Haller
20cf4ff31a libnm: merge branch 'th/connection-get-setting-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1618
2023-05-05 14:48:37 +02:00
Thomas Haller
429cf416fd core: add nm_settings_connection_get_setting() helper
For efficiently and conveniently lookup an NMSetting from the
NMConnection inside the NMSettingsConnection.

Note that this uses the NMMetaSettingType as lookup key. That is a novel
approach, compared to lookup by name (nm_connection_get_setting_by_name())
or GType (nm_connection_get_setting()).

Using the NMMetaSettingType enum is however faster, because it does not
require resolving the name/GType first. This is perfecly fine internal API,
we should use it.
2023-05-04 12:01:57 +02:00
Thomas Haller
db5946ac2f libnm: expose _nm_connection_get_setting_by_metatype() in internal header
We have several variants to get the NMSetting from an NMConnection. Some
of them are public API (nm_connection_get_setting(), nm_connection_get_setting_by_name()).

The most efficient way is lookup by NMMetaSettingType. Expose that as
internal API, so it can be used. The NMMetaSettingType is internal, but
it exists because it's a very useful enum. Allow others to make use of
it.

Also, add a static assert which prevents various wrong uses at compile
time, for example

  _nm_connection_get_setting_by_metatype(connection, NM_TYPE_SETTING_CONNECTION)
2023-05-04 12:01:57 +02:00
Thomas Haller
c60a4649b8 libnm: cleanup redundant nm_connection_get_setting functions
Refactor and cleanup the functions to get a setting from a connection.

As the NMConnection tracks the settings in an array indexed by
NMMetaSettingType, the most direct and efficient way is to look up via
that enum.

Previously, nm_connection_get_setting_by_name() would first look up the GType
(which already involved looking up the NMMetaSettingInfo), then based on the
GType it would look up the NMMetaSettingInfo again to get the meta_type. That
is unnecessary. Directly look up the NMMetaSettingInfo, which directly
gives the meta_type.
2023-05-04 11:47:10 +02:00
Thomas Haller
27cbf584bd libnm/trivial: rename internal connection-get-setting methods
This function will be exposed on the internal header. Rename to
_nm_connection_get_setting_by_metatype().
2023-05-04 11:42:06 +02:00