summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* team: don't try to connect to teamd in update_connection()bg/team-avoid-dbus-errorBeniamino Galvani2023-05-161-16/+2
| | | | | | | | | | | | | | | | | 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: ab586236e36b ('core: implement update_connection() for Team') https://bugzilla.redhat.com/show_bug.cgi?id=2182029 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1631
* libnm: drop duplicate line from "libnm.ver"Thomas Haller2023-05-151-1/+0
|
* libnm: adjust symbol versioning of bond port prio in 1.40.20ff/bond_port_version_symbolFernando Fernandez Mancera2023-05-152-2/+8
| | | | | | 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.
* tests: adjust test-gir.py to allow extra elements in section nameFernando Fernandez Mancera2023-05-151-13/+5
|
* test-client: drop TestNmClient base class from testsThomas Haller2023-05-151-62/+74
| | | | | | | | | | | | | | | | | | | | 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.
* test-client: move TestNmClient.ReplaceTextConUuid() to NMStubServerThomas Haller2023-05-151-11/+19
| | | | | | 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.
* test-client: move TestNmClient.{cmd_construct_argv,_env}() to ↵Thomas Haller2023-05-151-99/+110
| | | | | | | 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.
* test-client: move skip functions to Util classThomas Haller2023-05-151-19/+49
| | | | They can both be used as decorators and called plainly.
* test-client: move static function from TestNmClient._read_expected() to ↵Thomas Haller2023-05-151-29/+29
| | | | | | | Util.file_read_expected() Static, state-less functions are great. Keep them separate from TestNmClient which has lots of state.
* ipv6ll: don't regenerate the address when it's removed externallybg/ipv6ll-removedBeniamino Galvani2023-05-151-11/+19
| | | | | | | | | | | | | | | | | | 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: aa070fb82190 ('core: add NML3IPv6LL helper') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1622
* manager: use the right reason for managing devices after wake/reenablebg/wake-assume-rh2193422Beniamino Galvani2023-05-151-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | When managing the interface after wake/reenable, the reason determines whether the device will be sys-iface-state=managed or external. Commit 5a9a7623c5a4 ('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: 5a9a7623c5a4 ('core: set STATE_REASON_CONNECTION_ASSUMED when waking up') https://bugzilla.redhat.com/show_bug.cgi?id=2193422
* device: add functions to get and set sys-iface-state before sleepBeniamino Galvani2023-05-152-1/+27
|
* libnmc: fix openconnect option "--cafile" in ↵th/client-secrets-cleanupThomas Haller2023-05-121-1/+1
| | | | | | nm_vpn_openconnect_authenticate_helper() Fixes: 97f2a368f154 ('libnmc-base: add supported options for OpenConnect CLI authentication')
* libnmc: drop redundant defines for array lengthsThomas Haller2023-05-121-9/+8
| | | | | | | | | | | | | | | | | | | | | | - 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.
* tui: cleanup secrets_requested() function to use cleanup attributeThomas Haller2023-05-121-11/+5
| | | | | No explicit unref/free. Resources should be owned by somebody, like an auto variable with a cleanup attribute.
* test/client: test cloud-setup GCP supportLubomir Rintel2023-05-121-0/+61
|
* cloud-setup/gcp: add ability to redirect metadata API requestsLubomir Rintel2023-05-121-7/+31
| | | | | A different host can be specified with (undocumented, private) NM_CLOUD_SETUP_GCP_HOST environment variable.
* test/client: test cloud-setup azure supportLubomir Rintel2023-05-121-0/+86
|
* cloud-setup/azure: add ability to redirect metadata API requestsLubomir Rintel2023-05-121-1/+23
| | | | | A different host can be specified with (undocumented, private) NM_CLOUD_SETUP_AZURE_HOST environment variable.
* test/client: test cloud-setup aliyun supportLubomir Rintel2023-05-121-0/+90
|
* test-client: use a test fixture from the testLubomir Rintel2023-05-121-2/+41
| | | | | | | | 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.
* test-client: factor out the test device setupLubomir Rintel2023-05-121-3/+1
| | | | We're going to reuse the setup for tests of other cloud providers.
* test-client: hardcode the cloud-setup mac addressesLubomir Rintel2023-05-121-2/+2
| | | | | We rely on the predictable but random MAC addresses. Hardcode them instead -- the mock service also hardcodes them.
* test: fix file description passing to cloud-setup mock serviceLubomir Rintel2023-05-121-1/+1
| | | | The pass_fds file descriptor is *after* the dup2. Always 3.
* Revert "client/tests: don't do dup2() dance to pass file descriptor to ↵Lubomir Rintel2023-05-121-1/+5
| | | | | | | | | "tools/test-cloud-meta-mock.py"" This changed the fd passing protocol making it not compatible with systemd-socket-activate(1). This reverts commit 342ee618c75b350cf5cccf49f2bade85c5dfa3ea.
* test-client: cleanup after test on failureThomas Haller2023-05-121-1/+9
| | | | Otherwise, the following tests will fail too.
* test-client: increase context in pexecpt failure for debuggingThomas Haller2023-05-121-0/+2
| | | | | | 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.
* cloud-init: fix leaking iproutes for GCP providerThomas Haller2023-05-124-13/+14
| | | | | | | The routes in iproutes were leaked (and ownership stolen in _nmc_mangle_connection(), leaving dangling pointers). Fix that by using a GPtrArray instead.
* libnm-core: add internal _nm_ip_route_ref() helperThomas Haller2023-05-121-0/+7
| | | | | For some reason, nm_ip_route_ref() does not return the referenced instance, making it cumbersome to use. Add a helper.
* libnmc-base: fix port extraction for openconnect authDavid Woodhouse2023-05-111-3/+44
| | | | | | | | | | | | | | 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.
* libnmc-base: report explicit error if not gateway configured for openconnectDavid Woodhouse2023-05-111-2/+10
| | | | | | 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.
* nmtui: do not prompt for secrets if openconnect already provided themDavid Woodhouse2023-05-111-38/+25
| | | | | | 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.
* nmcli, nmtui: reduce duplication around openconnect auth helperDavid Woodhouse2023-05-114-133/+69
| | | | | | | 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.
* libnmc-base: add supported options for OpenConnect CLI authenticationDavid Woodhouse2023-05-111-5/+85
| | | | | | | | | | 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.
* nmcli, nmtui: update authentication for OpenConnectDavid Woodhouse2023-05-114-43/+99
| | | | | | | | | | | | | | | | 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.
* core/tests: add test for nm_firewall_nft_stdio_mlag()Thomas Haller2023-05-101-0/+122
| | | | | If only to hit some of the code paths in our test, and to have valgrind check (some of) the code paths.
* bond: don't configure "counter" on nft rules for slb-bonding/mlagThomas Haller2023-05-103-20/+34
| | | | | Counters are convenient for debugging, but have a performance overhead. Configure them only when debug logging in NetworkManager is enabled.
* glib-aux: add nmtst_assert_cmpmem() helperThomas Haller2023-05-101-0/+48
| | | | | | | | | | 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.
* glib-aux: add NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_DOUBLE_QUOTE flag to escape ↵Thomas Haller2023-05-102-10/+19
| | | | | | | | 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`.
* glib-aux: use GModule instead of dlopen() in _inet_aton()Thomas Haller2023-05-101-8/+8
| | | | | | | | | | 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: a23af8f76469 ('glib-aux: avoid using inet_aton()')
* device: don't reset "net.ipv6.conf.$IFACE.forwarding"Thomas Haller2023-05-091-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to systemd, IPv6 forwarding is special anyway, and they only enable forwarding for "net.ipv6.conf.all.forwarding" ([1]). Since commit 46e63e03af58 ('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] https://github.com/systemd/systemd/blob/b8fba0cded2c3e14fe8c0b52aae3ecf2c9fa718e/src/network/networkd-sysctl.c#L79 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/923 Fixes: 46e63e03af58 ('device: announce the managed IPv6 configuration with ipv6.method=shared') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1616
* n-dhcp4: re-import git-subtree for 'src/n-dhcp4'Thomas Haller2023-05-093-2/+2
|\ | | | | | | git subtree pull --prefix src/n-dhcp4 git@github.com:nettools/n-dhcp4.git master --squash
| * Squashed 'src/n-dhcp4/' changes from f8fc48dc014d..b2a382ac4500Thomas Haller2023-05-093-2/+2
| | | | | | | | | | | | | | | | | | 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
* | glib-aux: avoid using inet_aton()Thomas Haller2023-05-084-40/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | glib-aux/tests: add unit test for nm_inet_parse_bin_full()Thomas Haller2023-05-081-0/+116
| |
* | core: add nm_settings_connection_get_setting() helperThomas Haller2023-05-042-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | libnm: expose _nm_connection_get_setting_by_metatype() in internal headerThomas Haller2023-05-042-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* | libnm: cleanup redundant nm_connection_get_setting functionsThomas Haller2023-05-042-43/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | libnm/trivial: rename internal connection-get-setting methodsThomas Haller2023-05-041-41/+40
| | | | | | | | | | This function will be exposed on the internal header. Rename to _nm_connection_get_setting_by_metatype().
* | core: only trigger recheck when something changes in ↵Thomas Haller2023-05-041-3/+2
| | | | | | | | | | | | | | activate_slave_connections() We need to detect when nothing relevant changes, and shortcut doing things when they are unnecessary.