Commit graph

31211 commits

Author SHA1 Message Date
Wen Liang
58fe839967 merge: branch 'wl/nm-1-40-vpn-backport'
vpn: fix routing rules and custom routing table support in vpn conenctions

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2102
2025-01-07 15:25:27 +00:00
Wen Liang
49a8b0650f vpn: fix routing rules support in vpn conenctions
This commit introduces the ability to manage routing rules specifically
for VPN connections. These rules allow finer control over traffic
routing by enabling the specification of policy-based routing for
traffic over the VPN.

- Updated the connection backend to apply rules during VPN activation.
- Ensured proper cleanup of routing rules upon VPN deactivation.

This enhancement improves VPN usability in scenarios requiring advanced
routing configurations, such as split tunneling and traffic
prioritization.

Resolves: https://issues.redhat.com/browse/RHEL-70160
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2092
https://gitlab.freedesktop.org/NetworkManager/NetworkManager-ci/-/merge_requests/1842
(cherry picked from commit 308e34a501)
(cherry picked from commit a24b347e93)
(cherry picked from commit b5c46f8a8d)
(cherry picked from commit 7824d5e5ae)
(cherry picked from commit f5e8217f77)
(cherry picked from commit dcbe04ef5f)
2025-01-07 10:17:17 -05:00
Gris Ge
2aadb5dcb0 vpn: Place gateway route to table defined in ipvx.route-table
Previously, NM create direct route to gateway to main(254) route table
regardless `ipvx.route-table` value.

Fixed by setting `NMPlatformIP4Route.table_any` to `TRUE`.

Resolves: https://issues.redhat.com/browse/RHEL-69901

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 6d06286f1d)
(cherry picked from commit 29f23d3519)
(cherry picked from commit 0dc07c5ca4)
(cherry picked from commit 6a04a966c2)
(cherry picked from commit 70060d84f2)
(cherry picked from commit b92a07713c)
2025-01-07 10:13:09 -05:00
Beniamino Galvani
7573f61eed libnm-core: avoid compiler warnings in team settings
GCC 14 with LTO complains with:

  In function 'nm_team_link_watcher_new_ethtool',
      inlined from 'nm_team_link_watcher_new_ethtool' at src/libnm-core-impl/nm-setting-team.c:106:1:
  src/libnm-core-impl/nm-setting-team.c:130:33: error: array subscript 'struct NMTeamLinkWatcher[0]' is partly outside array bounds of 'unsigned char[16]' [-Werror=array-bounds=]
    130 |     watcher->ref_count          = 1;
        |                                 ^
  src/libnm-core-impl/nm-setting-team.c:128:15: note: object of size 16 allocated by 'g_malloc'
    128 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |               ^

even if the warning is disabled via pragma directives in that
code. This looks like the following GCC bug:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80922

saying

  We do not track warning options (and thus optimize pragmas /
  attributes) across LTO because they are not saved in the function
  specific optimization flag section.

We use a (NMTeamLinkWatcher *) to point to a memory area that is
shorter than the struct, because depending on the watcher type we need
to store different parameters; in this way we can save few bytes of
memory for some watcher types. However, this often breaks when
upgrading the compiler; instead just allocate the full struct.

(cherry picked from commit d369f55192)
(cherry picked from commit efa1d0e173)
(cherry picked from commit b60c1a6d25)
(cherry picked from commit 55efc8afe3)
2024-10-02 11:00:41 +02:00
Thomas Haller
2ce6ab499f libnm: avoid "-Walloc-size" warning in nm_team_link_watcher_new_ethtool()
gcc-14.0.1-0.2.fc40 warns:

    CC       src/libnm-core-impl/libnm_core_impl_la-nm-setting-team.lo
  ../src/libnm-core-impl/nm-setting-team.c: In function nm_team_link_watcher_new_ethtool:
  ../src/libnm-core-impl/nm-setting-team.c:127:13: error: allocation of insufficient size 16 for type NMTeamLinkWatcher with size 48 [-Werror=alloc-size]
    127 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |             ^

(cherry picked from commit 5715feebe7)
(cherry picked from commit eaa3a4e396)
(cherry picked from commit 571273f71c)
(cherry picked from commit c6643546f4)
2024-10-02 11:00:35 +02:00
Thomas Haller
c6f3ba0239 core: ignore unused result warning of audit_log_user_message()
Affects build on rawhide (audit-libs-4.0-8.fc40):

    src/core/nm-audit-manager.c: In function 'nm_audit_log':
    src/core/nm-audit-manager.c:188:9: error: ignoring return value of 'audit_log_user_message' declared with attribute 'warn_unused_result' [-Werror=unused-result]
      188 |         audit_log_user_message(priv->auditd_fd,
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      189 |                                AUDIT_USYS_CONFIG,
          |                                ~~~~~~~~~~~~~~~~~~
      190 |                                build_message(&strbuf, BACKEND_AUDITD, fields),
          |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      191 |                                NULL,
          |                                ~~~~~
      192 |                                NULL,
          |                                ~~~~~
      193 |                                NULL,
          |                                ~~~~~
      194 |                                success);
          |                                ~~~~~~~~

86bfa9bf4f
(cherry picked from commit ced0cf8005)
(cherry picked from commit 52ab487fd6)
(cherry picked from commit 09340c75c4)
(cherry picked from commit 88cde9d921)
2024-10-02 10:56:21 +02:00
Stanislas FAYE
992f719410 test: disable vlan_xgress unit test
Disable the vlan_xgress unit test which was failing.
This test is currently being work and is going to be fixed soon.

(cherry picked from commit 6e30e37ebe)
(cherry picked from commit b409d8f1d6)
(cherry picked from commit 43c4595045)
2024-10-02 10:55:36 +02:00
Thomas Haller
4222b3e196 config/tests: fix test failure in "/config/set-values"
GKeyfile changed something about how to handle invalid escape sequences.
As we don't want to test GKeyfile (per-se), just adjust to test to not
hit the problem.

This would fail with glib2-2.79.1-1.fc40:

  # ./tools/run-nm-test.sh -m src/core/tests/config/test-config -p /config/set-values
  TAP version 13
  # random seed: R02Sb8afff1ec38ca5a1b7713e8c40eb4f56
  # Start of config tests
  # GLib-GIO-DEBUG: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ?gio-vfs?
  # (src/core/tests/config/test-config.c:1107) invalid value in config-data .intern.with-whitespace.key2 = (null) (instead of " b c\,  d  ")
  ./tools/run-nm-test.sh: line 307: 245847 Trace/breakpoint trap   (core dumped) "${NMTST_DBUS_RUN_SESSION[@]}" "$TEST" "${TEST_ARGV[@]}"
  exec "src/core/tests/config/test-config" failed with exit code 133

(cherry picked from commit 7f2a32fa11)
(cherry picked from commit 1803520a7a)
(cherry picked from commit 0c9c387ebe)
(cherry picked from commit 5eb6f18ddb)
2024-10-02 10:55:30 +02:00
Thomas Haller
27718babe6 libnm: use flexible array member in NMUtilsStrStrDictKey
Otherwise, gcc-14.0.1-0.2.fc40 warns:

  ../src/libnm-core-impl/nm-utils.c: In function _nm_utils_strstrdictkey_create:
  ../src/libnm-core-impl/nm-utils.c:5076:16: error: allocation of insufficient size '1' for type 'NMUtilsStrStrDictKey' {aka 'struct _NMUtilsStrStrDictKey'} with size '2' [-Werror=alloc-size]
   5076 |         return g_malloc0(1);
        |                ^~~~~~~~~~~~

(cherry picked from commit 63ab0d926d)
(cherry picked from commit 157c2ffeee)
(cherry picked from commit 52eaa64ea1)
(cherry picked from commit 3487127c7d)
2024-10-02 10:55:22 +02:00
Thomas Haller
f23e0e438f libnm: avoid "-Wnonnull-compare warnings with "static" array declarator
With a static array, we indicate that the argument must not be NULL.
Gcc-14.0.1-0.2.fc40 now warns against that:

    CC       src/libnm-base/libnm_base_la-nm-base.lo
  In file included from ../src/libnm-std-aux/nm-default-std.h:102,
                   from ../src/libnm-glib-aux/nm-default-glib.h:11,
                   from ../src/libnm-glib-aux/nm-default-glib-i18n-lib.h:13,
                   from ../src/libnm-base/nm-base.c:3:
  ../src/libnm-base/nm-base.c: In function 'nm_net_devname_infiniband':
  ../src/libnm-std-aux/nm-std-aux.h:191:12: error: 'nonnull' argument 'name' compared to NULL [-Werror=nonnull-compare]
    191 |         if (expr)                      \
        |            ^
  ../src/libnm-std-aux/nm-std-aux.h:202:27: note: in expansion of macro '_NM_BOOLEAN_EXPR_IMPL'
    202 |                           _NM_BOOLEAN_EXPR_IMPL(NM_UNIQ, expr))
        |                           ^~~~~~~~~~~~~~~~~~~~~
  ../src/libnm-glib-aux/nm-macros-internal.h:1693:31: note: in expansion of macro 'NM_BOOLEAN_EXPR'
   1693 | #define _G_BOOLEAN_EXPR(expr) NM_BOOLEAN_EXPR(expr)
        |                               ^~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gmacros.h:1244:43: note: in expansion of macro '_G_BOOLEAN_EXPR'
   1244 | #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
        |                                           ^~~~~~~~~~~~~~~
  /usr/include/glib-2.0/glib/gmessages.h:656:9: note: in expansion of macro 'G_LIKELY'
    656 |     if (G_LIKELY (expr)) \
        |         ^~~~~~~~
  ../src/libnm-base/nm-base.c:57:5: note: in expansion of macro 'g_return_val_if_fail'
     57 |     g_return_val_if_fail(name, NULL);
        |     ^~~~~~~~~~~~~~~~~~~~

  ../src/libnm-core-impl/nm-setting-wireguard.c: In function '_nm_wireguard_peer_set_public_key_bin':
  ../src/libnm-core-impl/nm-setting-wireguard.c:316:8: error: 'nonnull' argument 'public_key' compared to NULL [-Werror=nonnull-compare]
    316 |     if (!public_key)
        |        ^

Convert these checks to an nm_assert() to suppress the warning.

(cherry picked from commit 7a031eef5d)
(cherry picked from commit aeaba8a2a1)
(cherry picked from commit 0df8bf56ad)
(cherry picked from commit 54fe3adf5e)
2024-10-02 10:55:16 +02:00
Thomas Haller
2ec49dd76e build: workaround -Wno-calloc-transposed-args warning in systemd code
Upstream systemd fixed this compiler warning. What really needs to be
done, is re-importing the upstream code.

In the meantime, suppress the warning that hits on GCC 14.

This is a temporary workaround!

See-also: fdd84270df
(cherry picked from commit b1016e3be8)
(cherry picked from commit df879e6950)
(cherry picked from commit fd63580c7c)
(cherry picked from commit 5f4dad89a9)
2024-10-02 10:55:10 +02:00
Thomas Haller
007f838f54 build: use "-Wno-nonnull-compare" for building systemd
systemd uses that too. We cannot enable compiler warnings that
upstream doesn't want to support.

See-also: b59bce308d
(cherry picked from commit ad22a96da9)
(cherry picked from commit 4c66cce980)
(cherry picked from commit 24363ade54)
(cherry picked from commit 1673c995d9)
2024-10-02 10:55:02 +02:00
Fernando Fernandez Mancera
dc2f05ae91 daemon-helper: fix warning about unused variable 2024-10-02 10:41:27 +02:00
Beniamino Galvani
54bee733de docs: document the hostname management workflow
(cherry picked from commit 543ebef32b)
(cherry picked from commit 9f09d4d364)
(cherry picked from commit ff81488583)
(cherry picked from commit 524febf271)
(cherry picked from commit db4975733b)
2024-08-20 11:41:02 +02:00
Beniamino Galvani
8aaae05f21 core: also use /etc/hosts for hostname resolution
Before introducing the hostname lookup via nm-daemon-helper and
systemd-resolved, we used GLib's GResolver which internally relies on
the libc resolver and generally also returns results from /etc/hosts.

With the new mechanism we only ask to systemd-resolved (with
NO_SYNTHESIZE) or perform the lookup via the "dns" NSS module. In both
ways, /etc/hosts is not evaluated.

Since users relied on having the hostname resolved via /etc/hosts,
restore that behavior. Now, after trying the resolution via
systemd-resolved and the "dns" NSS module, we also try via the "files"
NSS module which reads /etc/hosts.

Fixes: 27eae4043b ('device: add a nm_device_resolve_address()')
(cherry picked from commit 410afccb32)
(cherry picked from commit cb54fe7ce9)
(cherry picked from commit e3861be845)
(cherry picked from commit cfe840784c)
(cherry picked from commit 16946905a6)
2024-08-20 11:38:34 +02:00
Beniamino Galvani
cabef041c8 nm-daemon-helper: add "service" argument
Introduce a new argument to specify a comma-separated list of NSS
services to use for the "resolve-address" command. For now only accept
"dns" and "files"; the latter can be used to do a lookup into
/etc/hosts.

Note that previously the command failed in presence of extra
arguments. Therefore, when downgrading NetworkManager without
restarting the service, the previously-installed version of the daemon
(newer) would spawn the helper with the extra argument, and the
newly-installed version of the helper (older) would fail. This issue
only impacts hostname resolution and can be fixed by just restarting
the daemon.

In the upgrade path everything works as before, with the only
difference that the helper will use by default both "dns" and "files"
services.

Don't strictly check for the absence of extra arguments, so that in
the future we can introduce more arguments without necessarily break
the downgrade path.

(cherry picked from commit 229bebfae9)
(cherry picked from commit c36a74f698)
(cherry picked from commit e86ddd9fc5)
(cherry picked from commit 717db10a9d)
(cherry picked from commit f549bdd9c1)
2024-08-20 11:37:26 +02:00
Beniamino Galvani
48f8fa662d crypto: regenerate PKCS#12 certificates
The PKCS#12 certificates are using SHA1 and RC2-40, which are deprecated;
regenerate them with:

 $ openssl pkcs12 -export -in test_key_and_cert.pem -inkey test_key_and_cert.pem -certfile test_ca_cert.pem -name "test-pkcs12" -out test-cert.p12
 (key: test)

 $ openssl pkcs12 -export -in test2_key_and_cert.pem -inkey test2_key_and_cert.pem -certfile test2_ca_cert.pem -name "test2-pkcs12" -out test2-cert.p12
 (key: 12345testing)

Before:
 $ openssl pkcs12 -info -in test-cert.p12
 MAC: sha1, Iteration 2048
 MAC length: 20, salt length: 8
 PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048

After:
 $ openssl pkcs12 -info -in test-cert.p12
 MAC: sha256, Iteration 2048
 MAC length: 32, salt length: 8
 PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
(cherry picked from commit 0d657af256)
2024-06-28 13:21:35 +02:00
Beniamino Galvani
98b1dba100 release.sh: update version check
(cherry picked from commit cfc3f3fed7)
(cherry picked from commit 39c0e8cf30)
(cherry picked from commit 01a03c7a5a)
(cherry picked from commit f5e0d856f7)
2024-06-24 13:43:53 +02:00
Wen Liang
a4b997b2ec device: use subnet when the applied connection has IPv6 method shared
We should use the IPv6 subnet when we have an applied connection
stored on the downlink device, and the IPv6 method should be "shared"
for that applied connection. It does not make sense to register l3cd
and set router config for ndisc instance when the downlink device is
already deactivated.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1880
Resolves: https://issues.redhat.com/browse/RHEL-17350

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
(cherry picked from commit 15901a7489)
(cherry picked from commit 86fbfb3806)
(cherry picked from commit 546dd70178)
(cherry picked from commit 74f2c591ec)
2024-05-02 15:15:40 +02:00
Yuki Inoguchi
f407868ee2 device: disable IPv6 in NetworkManager when disabled in kernel
When IPv6 is disabled in kernel but ipv6.method is set to auto, NetworkManager repeatedly attempts
IPv6 configuration internally, resulting in unnecessary warning messages being output infinitely.

  platform-linux: do-add-ip6-address[2: fe80::5054:ff:fe7c:4293]: failure 95 (Operation not supported)
  ipv6ll[e898db403d9b5099,ifindex=2]: changed: no IPv6 link local address to retry after Duplicate Address Detection failures (back off)
  platform-linux: do-add-ip6-address[2: fe80::5054:ff:fe7c:4293]: failure 95 (Operation not supported)
  ipv6ll[e898db403d9b5099,ifindex=2]: changed: no IPv6 link local address to retry after Duplicate Address Detection failures (back off)
  platform-linux: do-add-ip6-address[2: fe80::5054:ff:fe7c:4293]: failure 95 (Operation not supported)
  ipv6ll[e898db403d9b5099,ifindex=2]: changed: no IPv6 link local address to retry after Duplicate Address Detection failures (back off)

To prevent this issue, let's disable IPv6 in NetworkManager when it is disabled in the kernel.

In order to do it in activate_stage3_ip_config() only once during activation,
the firewall initialization needed to be moved earlier. Otherwise, the IPv6 disablement could occur
twice during activation because activate_stage3_ip_config() is also executed from subsequent of fw_change_zone().

(cherry picked from commit 50a6386c3b)
(cherry picked from commit 4a9cf4c1dd)
(cherry picked from commit ffef5a4748)
Solved some conflicts due to missing 61e1027cc7 ('device: preserve the DHCP lease during reapply')
2024-02-09 15:47:57 +01:00
Gris Ge
37bd70034f device: do not set MAC address on iface with index <=0
The `nm_device_hw_addr_reset()` should only set MAC address on NIC
with valid(>0) interface index.

The failure was found by `ovs_mtu` test of NMCI, failed to reproduce
the original problem (`ovs_mtu` test of NMCI) with 100 times retry.
And no trace log found for original test failure, hence cannot tell why
`nm_device_hw_addr_reset()` been invoked with iface index 0.

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 215bc15255)
(cherry picked from commit 21f1e5cdc7)
2023-12-04 11:49:53 +01:00
Gris Ge
c9a6e501b6 merge: branch 'nm-1-40'
[nm-1.40] [RFE] dispatch `dns-change` dispatcher event

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1759
2023-10-19 08:12:15 +00:00
Gris Ge
e74a349e1e dispatch dns-change dispatcher event
Introducing new dispatcher event -- `dns-change` which will be emitted when
DNS configuration changed(even in `dns=none` mode). This is to solve two
use cases:
 * Invoke dispatch script for DNS changes triggered by the global DNS
   API.

 * Do not invoke [OpenShift resolv-prepender][1] for non-DNS changes.

Bug reference: https://issues.redhat.com/browse/RHEL-1671

[1]: https://github.com/openshift/machine-config-operator/blob/master/templates/common/on-prem/files/resolv-prepender.yaml

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a1db61ebc9)
(cherry picked from commit 3cdce71b95)
(cherry picked from commit 9ae535c61a)
2023-10-18 15:03:13 +08:00
Gris Ge
cd9ebfd2bb emit DNS CONFIG_CHANGED signal even dns=none
Instruct the `NMDnsManager` to emit `CONFIG_CHANGED` signal even
`dns=none` or failed to modify `/etc/resolv.conf`.

The `NMPolicy` will only update hostname when DNS is managed.

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a847ba8075)
(cherry picked from commit d10f20fd01)
(cherry picked from commit e0f3a91a95)
2023-10-18 14:59:43 +08:00
Fernando Fernandez Mancera
401f153dfb manager: allow controller activation if device is deactivating
When activating a port connection it will require the controller
connection is active or a valid controller device candidate is available
for activation.

One of the conditions we consider for a controller device to be a valid
candidate for the connection is that it is not active, therefore we
should also consider as valid a device that is currently deactivating.
Otherwise, we could fail during the port activation just because the
deactivation of the controller device candidate didn't finish yet.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1693
(cherry picked from commit fb362e0583)
(cherry picked from commit 43f244ef2e)
2023-10-04 12:02:21 +02:00
Fernando Fernandez Mancera
04ef92fc12 Revert "bond,bridge,team: use uuid for con.master when generating connection"
This reverts commit 836d7511e8.
2023-10-04 12:01:12 +02:00
Fernando Fernandez Mancera
8c0f262549 utils: extend connection matching function for UUID in controller
When matching two connections one might be using UUID and the other one
could be using interface-name for the controller property. When
recovering from a fresh start NM does not have any context and when
generating a connection we are using UUID as the controller.

It is always hard to guess what is the right candidate to pick but at
least something NM can do is checking if the UUID matches a connection
with the same controller interface-name. If there are no other
conflicts, then we can assume that is a good canditate to activate.

This is a follow up to `dc254f90e2b306700a0b81f7194e9b0438c62f4c`.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1684
(cherry picked from commit 5b8fdd25ab)
(cherry picked from commit 5ca93db692)
2023-07-13 13:27:12 +02:00
Thomas Haller
cf5d8a41e3 libnm: merge branch 'th/connection-get-setting-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1618

(cherry picked from commit 20cf4ff31a)

(cherry picked from commit 4f6ba7f601)
2023-07-13 13:27:04 +02:00
Thomas Haller
c2cf898c19 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.

(cherry picked from commit 429cf416fd)
(cherry picked from commit 10e493bbe8)
2023-07-13 13:27:04 +02:00
Thomas Haller
1cd4f675c8 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)

(cherry picked from commit db5946ac2f)
(cherry picked from commit 50b6c2d622)
2023-07-13 13:27:04 +02:00
Thomas Haller
58fd65c37e 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.

(cherry picked from commit c60a4649b8)
(cherry picked from commit eebbd36270)
2023-07-13 13:27:04 +02:00
Thomas Haller
3922761238 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().

(cherry picked from commit 27cbf584bd)
(cherry picked from commit c194db5755)
2023-07-13 13:27:04 +02:00
Beniamino Galvani
9cb9dfa77b dns: fix tracking of best ip config
When a IP configuration has type "best", it is the configuration with
the best (lowest) metric default route for the specific address
family. Therefore, there can be only one best configuration for
address family.

When a new configuration is added as best, make sure it is the only
one for the address family.

This reverts commit 0abc14b3a0.

Fixes: 0abc14b3a0 ('core: remove unused best_ip_config_[46] field in NMDnsManager')

https://lists.freedesktop.org/archives/networkmanager/2023-June/000123.html
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1331
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1683
(cherry picked from commit 646e041523)
(cherry picked from commit 2ddb4e5942)
2023-06-29 15:20:47 +02:00
Thomas Haller
a33c4c1f51
ppp: merge branch 'th/pppd-so-rename'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1312

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1660

(cherry picked from commit 6f9f90417e)

(cherry picked from commit 695b60a6cc)
2023-06-28 13:25:10 +02:00
Thomas Haller
5b421193fe
ppp/autotools: add missing check for symbols of libnm-ppp-plugin
(cherry picked from commit 0a7145a061)
(cherry picked from commit 8083bf1c7d)
2023-06-28 13:25:09 +02:00
Thomas Haller
21f96f7357
ppp: fix plugin name for "rp-pppoe.so" with ppp 2.5
Between ppp 2.4.8 and 2.4.9, "rp-pppoe.so" was renamed to "pppoe.so" (and a
symlink created). Between 2.4.9 and 2.5.0, the symlink was dropped.

See-also: b2c36e6c0e

I guess, NetworkManager always meant to use ppp's "(rp-)pppoe.so"
plugin, and never the library from the rp-pppoe project.
If a user actually wants to use the plugin from rp-pppoe project, then
this is going to break.

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

Fixes: afe80171b2 ('ppp: move ppp code to "nm-pppd-compat.c"')
(cherry picked from commit 84e21d8bbc)
(cherry picked from commit 1c736a44b4)
2023-06-28 13:25:09 +02:00
Thomas Haller
de39f67d72
ppp: detect the ppp version in the configure script
Previously, the ppp version was only detected (and used) at one place,
in "nm-pppd-compat.c", after including the ppp headers. That was nice
and easy.

However, with that way, we could only detect it after including ppp
headers, and given the ugliness of ppp headers, we only want to include
them in "nm-pppd-compat.c" (and nowhere else).

In particular, 'nm-pppd-compat.c" uses symbols from the ppp daemon, it
thus can only be linked into a ppp plugin, not in NetworkManager core
itself. But at some places we will need to know the ppp version, outside
of the ppp plugin and "nm-pppd-compat.c".

Additionally, detect it at configure time and place it in "config.h".
There is a static assert that we are in agreement with the two ways of
detection.

(cherry picked from commit 3e66c0bde1)
(cherry picked from commit 65756dca7f)
2023-06-28 13:25:09 +02:00
Gris Ge
2695396939 setting-connection: Unblock autoconnect upon finish of Reapply
The activation of a connection will clear the block of autoconnect,
we should do the same for reapply.

Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 0486efd358)
(cherry picked from commit 18ce5f43bd)
2023-06-27 19:57:55 +08:00
Thomas Haller
533310ca09
platform/tests: skip test_netns_bind_to_path() test on failure
Our copr builds start to fail, since the copr builds updated to Fedora
38 ([1]).

  ERROR: src/core/platform/tests/test-link-linux - Bail out! nm:ERROR:src/core/platform/tests/test-link.c:3486:test_netns_bind_to_path: assertion failed (nmtstp_run_command("ip netns exec " P_NETNS_BINDNAME " true") == 0): (65280 == 0)

The cause is not understood, but it seems not worth investigating.
Just skip the test.

[1] https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/KOR3HE2VHHIPDBLDLXTYRMON6JQXCHMW/#J4K5VB5SA6I5P2ZLI65OHNQ6X7SINSHA

(cherry picked from commit 8dfca3d552)
(cherry picked from commit e06432cc7f)
2023-06-13 16:00:08 +02:00
Thomas Haller
edf23f434e
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.

(cherry picked from commit 1a0fa85397)
(cherry picked from commit c66ae93415)
2023-06-13 16:00:04 +02:00
Thomas Haller
d2e1c8bee0
cloud-setup: merge branch 'th/cloud-setup-fix-cancellation'
https://bugzilla.redhat.com/show_bug.cgi?id=2207812

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1654

(cherry picked from commit 7e6a6dd275)

(cherry picked from commit 268819367e)
2023-06-12 11:20:11 +02:00
Thomas Haller
5cc38d1c6b
cloud-setup: clear error variable in nmcs_device_reapply()
This is rather bad, because if we reach the "goto again" case,
the error variable is not cleared. Subsequently passing the
error location to nm_device_reapply_finish() will trigger a glib
warning.

Fixes: 29b0420be7 ('nm-cloud-setup: set preserve-external-ip flag during reapply')
(cherry picked from commit c70a5470be)
(cherry picked from commit 98be3dd5ac)
2023-06-12 11:20:10 +02:00
Thomas Haller
fe243025e5
cloud-setup: fix terminating in the middle of reconfiguring the system
Once we start reconfiguring the system, we need to finish on all
interfaces. Otherwise, we might reconfigure some interfaces, abort
and leave the network broken. When that happens, a subsequent run
might also be unable to recover, because we are unable to reach the
HTTP meta data service.

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

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')
(cherry picked from commit dab114f038)
(cherry picked from commit 0a033798ac)
2023-06-12 11:20:10 +02:00
Thomas Haller
b0ba72b4ac
device: only remember "forwarding" sysctl the first time in _dev_ipac6_start()
Fixes: 4c48301594 ('device: don't reset "net.ipv6.conf.$IFACE.forwarding"')
(cherry picked from commit 6050da93bd)
(cherry picked from commit 707febe83b)
2023-06-12 11:19:56 +02:00
Thomas Haller
d008eb154e
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
(cherry picked from commit 4c48301594)
(cherry picked from commit f578051b40)
2023-06-12 10:44:40 +02:00
Thomas Haller
9e92709ca8
platform/tests: fix infiniband_partition_delete() in fake platform
Fixes: 9c323261ea ('platform: use nm_utils_new_infiniband_name()')
(cherry picked from commit 6b28c2867b)
(cherry picked from commit 26e789bdcf)
2023-06-08 10:46:18 +02:00
Thomas Haller
beb83e8e38
cloud-setup: fix _aliyun_base() initializing base URL
Fixes: f3404435a9 ('cloud-setup: configure secondary ip in Aliyun cloud')
(cherry picked from commit 62104477c3)
(cherry picked from commit c6977592c3)
2023-06-08 10:46:18 +02:00
Thomas Haller
b96980b129
ppp: merge branch 'th/ppp25'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1272
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1558

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1607

(cherry picked from commit 5df19f5b26)

(cherry picked from commit d4b1cb7276)
2023-06-05 11:44:56 +02:00
Thomas Haller
a45806f982
ppp: move ppp code to "nm-pppd-compat.c"
Using the ppp code is rather ugly.

Historically, the pppd headers don't follow a good naming convention,
and define things that cause conflicts with our headers:

  /usr/include/pppd/patchlevel.h:#define VERSION          "2.4.9"
  /usr/include/pppd/pppd.h:typedef unsigned char  bool;

Hence we had to include the pppd headers in certain order, and be
careful.

ppp 2.5 changes API and cleans that up. But since we need to support
also old versions, it does not immediately simplify anything.

Only include "pppd" headers in "nm-pppd-compat.c" and expose a wrapper
API from "nm-pppd-compat.h". The purpose is that "nm-pppd-compat.h"
exposes clean names, while all the handling of ppp is in the source
file.

(cherry picked from commit afe80171b2)
(cherry picked from commit facd2ae916)
2023-06-05 11:44:56 +02:00
Eivind Næss
cc1771cfef
ppp, adding support for compiling against pppd-2.5.0
This change does the following
* Adding in nm-pppd-compat.h to mask details regarding different
  versions of pppd.
* Fix the nm-pppd-plugin.c regarding differences in API between
  2.4.9 (current) and latet pppd 2.5.0 in master branch
* Additional fixes to the configure.ac to appropriately set defines used
  for compilation

(cherry picked from commit 8469c09a50)
(cherry picked from commit 521f936567)
2023-06-05 11:44:55 +02:00