Commit graph

27911 commits

Author SHA1 Message Date
Wen Liang
a9e6aa663e aliyun: reuse ipv4 gateway address returned by metadata server
The default ipv4 gateway address of the VPC in Aliyun cloud is not the
first IP address in the CIDR subnet block, we should instead use the
ipv4 gateway address retrieved from the metadata server in
`_nmc_mangle_connection()`.

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

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

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
(cherry picked from commit 778e1f8493)
(cherry picked from commit 59633dbe11)
2021-10-05 09:35:48 +02:00
Thomas Haller
661da869b3 cloud-setup: limit number of supported interfaces to avoid overlapping table numbers
The table number is chosen as 30400 + iface_idx. That is, the range is
limited and we shouldn't handle more than 100 devices. Add a check for
that and error out.

(cherry picked from commit b68d694b78)
(cherry picked from commit 292233e16e)
2021-10-05 09:35:48 +02:00
Thomas Haller
67a83b54cd cloud-setup: process iface-datas in sorted order
The routes/rules that are configured are independent of the
order in which we process the devices. That is, because they
use the "iface_idx" for cases where there is ambiguity.

Still, it feels nicer to always process them in a defined order.

(cherry picked from commit a95ea0eb29)
(cherry picked from commit 6302cd416d)
2021-10-05 09:35:48 +02:00
Thomas Haller
48e79fb4b2 cloud-setup: track sorted list of NMCSProviderGetConfigIfaceData
Sorted by iface_idx. The iface_idx is probably something useful and
stable, provided by the provider. E.g. it's the order in which
interfaces are exposed on the meta data.

(cherry picked from commit 1c5cb9d3c2)
(cherry picked from commit 0a2ed62703)
2021-10-05 09:35:48 +02:00
Thomas Haller
c36e42dbd9 cloud-setup: add "hwaddr" to NMCSProviderGetConfigIfaceData struct
get-config() gives a NMCSProviderGetConfigResult structure, and the
main part of data is the GHashTable of MAC addresses and
NMCSProviderGetConfigIfaceData instances.

Let NMCSProviderGetConfigIfaceData also have a reference to the MAC
address. This way, I'll be able to create a (sorted) list of interface
datas, that also contain the MAC address.

(cherry picked from commit ec56fe60fb)
(cherry picked from commit cc289e5369)
2021-10-05 09:35:48 +02:00
Thomas Haller
8bad924931 cloud-setup/trivial: rename variables in Azure's _get_config_fetch_done_cb()
The previous name seem not very expressive/fitting. Naming is hard, but
I think these are better names.

(cherry picked from commit 89f3267859)
2021-10-05 09:35:48 +02:00
Thomas Haller
91ddd5f5ba cloud-setup: use _nm_utils_ascii_str_to_int64_bin() in Azure's _get_config_fetch_done_cb()
(cherry picked from commit a2fded3cee)
2021-10-05 09:35:48 +02:00
Thomas Haller
2e4b73c7fe cloud-setup: skip configuring policy routing if there is only one interface/address
nm-cloud-setup automatically configures the network. That may conflict
with what the user wants. In case the user configures some specific
setup, they are encouraged to disable nm-cloud-setup (and its
automatism).

Still, what we do by default matters, and should play as well with
user's expectations. Configuring policy routing and a higher priority
table (30400+) that hijacks the traffic can cause problems.

If the system only has one IPv4 address and one interface, then there
is no point in configuring policy routing at all. Detect that, and skip
the change in that case.

Note that of course we need to handle the case where previously multiple
IP addresses were configured and an update gives only one address. In
that case we need to clear the previously configured rules/routes. The
patch achieves this.

(cherry picked from commit 5f047968d7)
(cherry picked from commit 8bc8a0f56b)
2021-10-05 09:35:48 +02:00
Thomas Haller
2b96e9314c cloud-setup: preserve IPv4 addresses/routes/rules from profile
nm-cloud-setup automatically detects routes, addresses and rules and configures them
on the device using the emphermal Reapply() API. That is, it does not modify the
existing profile (on disk), but changes the runtime configuration only.

As such, it used to wipe otherwise statically configured IP addresses, routes and
rules. That seems unnecessary. Let's keep the configuration from the (persistent)
configuration.

There is of course the problem that nm-cloud-setup doesn't really
understand the existing IP configuration, and it can only hope that
it can be meaningfully combined with what nm-cloud-setup wants to
configure. This should cover most simple cases, for more complex setups,
the user probably should disable nm-cloud-setup and configure the
network explicitly to their liking.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/893
(cherry picked from commit 4201ee5119)
(cherry picked from commit 9541b0bea4)
2021-10-05 09:35:48 +02:00
Thomas Haller
ef7a97977a cloud-setup: count numbers of valid IPv4 addresses in get-config result
Will be used next.

(cherry picked from commit 7969ae1a82)
(cherry picked from commit ae504433f1)
2021-10-05 09:35:48 +02:00
Thomas Haller
7fcc89db6e cloud-setup: cache number of valid interfaces in get-config result
Now that we return a struct from get_config(), we can have system-wide
properties returned.

Let it count and cache the number of valid iface_datas.

Currently that is not yet used, but it will be.

(cherry picked from commit a3cd66d3fa)
(cherry picked from commit e74375fc3b)
2021-10-05 09:35:48 +02:00
Thomas Haller
b2ed9e7d5d cloud-setup: return structure for get_config() result instead of generic hash table
Returning a struct seems easier to understand, because then the result
is typed.

Also, we might return additional results, which are system wide and not
per-interface.

(cherry picked from commit 323e182768)
(cherry picked from commit c94b1c43d4)
2021-10-05 09:35:48 +02:00
Thomas Haller
2585e34e59 libnm: expose nm_ip_address_dup(), nm_ip_route_dup() API in libnm
This fixes commit 21c8a6b20e ('libnm-core, all: merge IPv4 and IPv6
address/route types'), which introduced this API but didn't export it
in the library. In practice this API is thus only usable since 1.32.0.

(cherry picked from commit 05f2a0b024)
(cherry picked from commit eea912dfb3)
2021-10-05 09:35:48 +02:00
Thomas Haller
b8bb585052 glib-aux: add _nm_utils_ascii_str_to_int64_bin() helper
(cherry picked from commit 70b7ad1a76)
2021-10-05 09:35:48 +02:00
Beniamino Galvani
d01912d2fc platform: preserve IPv6 multicast route added by kernel
Kernels < 5.11 add a route like:

  unicast ff00::/8 dev $IFACE proto boot scope global metric 256 pref medium

to allow sending and receiving IPv6 multicast traffic. Ensure it's not
removed it when we do a route sync in mode ALL.

In kernel 5.11 there were commits:

  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ceed9038b2783d14e0422bdc6fd04f70580efb4c
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a826b04303a40d52439aa141035fca5654ccaccd

After those the route looks like

  multicast ff00::/8 dev $IFACE proto kernel metric 256 pref medium

As NM ignores routes with rtm_type multicast, the code in this commit
is not needed on newer kernels.

https://bugzilla.redhat.com/show_bug.cgi?id=2004212
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/984
(cherry picked from commit 8003ca68f7)
(cherry picked from commit ce8eb446b4)
2021-09-20 10:38:46 +02:00
Beniamino Galvani
183f2a1a59 merge: branch 'bg/rh1961666'
https://bugzilla.redhat.com/show_bug.cgi?id=1961666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/966
(cherry picked from commit 9330d29a68)
(cherry picked from commit 5dfd80683d)
2021-09-07 16:29:25 +02:00
Beniamino Galvani
3565f155fb initrd: set required-timeout for default IPv4 configuration
If the kernel command-line doesn't contain an explict ip=$method,
currently the generator creates connections with both IPv4 and IPv6
set to 'auto', and both allowed to fail.

Since NM is run in configure-and-quit mode in the initrd, NM can get
an IPv4 address or an IPv6 one (or both) depending on which address
family is quicker to complete. This unpredictable behavior is not
present in the legacy module, which always does IPv4 only by default.

Set a required-timeout of 20 seconds for IPv4, so that NM will
preferably get an IPv4, or will fall back to IPv6.

See also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/729

(cherry picked from commit 0a18e97345)
(cherry picked from commit 1b9cf8c513)
2021-09-06 10:56:12 +02:00
Beniamino Galvani
65868803e0 device: use the 'required-timeout' property from IP setting
Change the logic in check_ip_state() to delay the connection ACTIVATED
state if an address family is pending and its required-timeout has not
expired.

(cherry picked from commit 35cccc41cb)
(cherry picked from commit 51e5df275c)
2021-09-06 10:56:12 +02:00
Beniamino Galvani
253de76195 all: add a new ipv{4,6}.required-timeout property
Add a new property to specify the minimum time interval in
milliseconds for which dynamic IP configuration should be tried before
the connection succeeds.

This property is useful for example if both IPv4 and IPv6 are enabled
and are allowed to fail. Normally the connection succeeds as soon as
one of the two address families completes; by setting a required
timeout for e.g. IPv4, one can ensure that even if IP6 succeeds
earlier than IPv4, NetworkManager waits some time for IPv4 before the
connection becomes active.

(cherry picked from commit cb5960cef7)
(cherry picked from commit 08ce20481c)
2021-09-06 10:56:12 +02:00
Beniamino Galvani
671dc82f94 initrd: rename NMI_WAIT_DEVICE_TIMEOUT_MS to _MSEC
(cherry picked from commit fa42ba9df2)
(cherry picked from commit f2d9f4bf66)
2021-08-20 10:48:19 +02:00
Thomas Haller
660932163f glib-aux: fix thread-safe initialization in _nm_g_source_sentinel_get_init()
Fixes: ce7c28c514 ('glib-aux: add nm_g_source_sentinel_get() util')
(cherry picked from commit 2140bbf7f5)
(cherry picked from commit c37f72acd3)
2021-08-20 10:48:19 +02:00
Thomas Haller
bd7cbd5770 glib-aux/tests: avoid coverity warning in test_nm_g_source_sentinel()
Coverity wrongly think there is a use after free in the test:

    Error: USE_AFTER_FREE (CWE-416): [#def559] [important]
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1305: alias: Assigning: "s1" = "_s". Now both point to the same storage.
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1324: freed_arg: "g_source_unref" frees "s1".
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1330: deref_after_free: Dereferencing freed pointer "s1".
    # 1328|               s2 = nm_g_source_sentinel_get(0);
    # 1329|               g_assert(s2 == s1);
    # 1330|->             g_assert_cmpint(g_atomic_int_get(&s1->ref_count), >=, 1);
    # 1331|           }
    # 1332|       }

Rework the code in the hope to avoid the false warning.

(cherry picked from commit 7825609f1f)
(cherry picked from commit c47c823c9d)
2021-08-20 10:23:03 +02:00
Thomas Haller
3a58255247 glib-aux: add nm_g_source_sentinel_get() util
This helper is useful to get a dummy GSource instance that can be
refed, unrefed and destroyed. It can act as a replacement for
a timeout source with infinite timeout.

(cherry picked from commit ce7c28c514)
2021-08-20 10:23:03 +02:00
Thomas Haller
f8645d6a86 initrd: cleanup parsing DNS in reader_parse_ip()
(cherry picked from commit e258410c87)
2021-08-20 10:23:03 +02:00
Beniamino Galvani
ce02f56356 libnm: add NM_VERSION_1_30_8 2021-08-20 09:44:18 +02:00
Beniamino Galvani
9121b961eb device: store the original MTU before force-setting it
In case the MTU is force-set (e.g. for bridges), priv->mtu_initial and
priv->ip6_mtu_initial must be initialized before changing the MTU,
otherwise the wrong value will be restored on deactivation.

Fixes: e23798a5e5 ('bridge: force (hack)-set of the MTU when explicitly set in the profile')

https://bugzilla.redhat.com/show_bug.cgi?id=1973536
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/955
(cherry picked from commit 3f42e2005a)
(cherry picked from commit 7730547721)
2021-08-06 15:41:57 +02:00
Beniamino Galvani
ca122d1a14 release: bump version to 1.30.7 (development) 2021-07-16 22:08:23 +02:00
Beniamino Galvani
427f58466b release: bump version to 1.30.6 2021-07-16 22:08:23 +02:00
Beniamino Galvani
edec742209 NEWS: update 2021-07-16 18:42:52 +02:00
Thomas Haller
9eb912ead1 libnm: fix memleak setting "ipv[46].dhcp-iaid" property
Fixes: 56a1a5426a ('all: add ipvX.dhcp-iaid properties')
(cherry picked from commit 47cdcb3ce2)
(cherry picked from commit 7aa2214014)
2021-07-16 18:40:00 +02:00
Thomas Haller
cd619a5c92 glib-aux: fix releasing thead-local GRand instance from nm_utils_random_bytes()
Fixes: b01a453ca2 ('core: add nm_utils_random_bytes() and use getrandom()')
(cherry picked from commit c127e1becc)
(cherry picked from commit 3de83dd25c)
2021-07-16 18:40:00 +02:00
Thomas Haller
46e595cb26 platform: fix releasing thead-local stack of NMPNetns instances
Fixes: 12df49f8ab ('platform: make NMPNetns thread-safe')
(cherry picked from commit b433c21ae4)
(cherry picked from commit 724ef83e06)
2021-07-16 18:40:00 +02:00
Thomas Haller
41126d256a glib-aux: fix releasing thread-local storage from nm_strerror_native()
The previous implementation was just wrong.

Fixes: e1ca3bf7ed ('shared: add nm_strerror_native() to replace strerror() and g_strerror()')
(cherry picked from commit 5bc39d9783)
(cherry picked from commit 963c395cc2)
2021-07-16 18:40:00 +02:00
Thomas Haller
cfd37f2758 ifcfg: always write ethernet.s390-options even without subchannels
For the umpteenth time: it is not ifcfg-rh writers decision to decide
what are valid configurations and only persist settings based on
some other settings.

If s390-options would only be allowed together with subchannels, then
this is alone nm_connection_verify()'s task to ensure.

Reproduce with

  $ nmcli connection add type ethernet autoconnect no con-name zz ethernet.s390-options bridge_role=primary

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

Fixes: 16bccfd672 ('core: handle s390 options more cleanly')
(cherry picked from commit d391f20730)
(cherry picked from commit b425793d90)
2021-07-16 18:40:00 +02:00
Simon McVittie
d7c6fea149 libnm: Don't crash if service tells us a new key management mode
The NetworkManager service sometimes adds new key management modes.
If it does, an older client library (perhaps in a container, or loaded
into a pre-existing process before an upgrade) shouldn't crash when
talking to a newer NetworkManager service over D-Bus.

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

Signed-off-by: Simon McVittie <smcv@collabora.com>

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

Fixes: 4c4f59674a ('2007-10-23  Dan Williams  <dcbw@redhat.com>')

(cherry picked from commit 18c76388f0)
(cherry picked from commit a90a7b2d5f)
2021-07-16 18:40:00 +02:00
Thomas Haller
5999a7b093 libnm: fix NM_SETTING_IP_CONFIG_CLASS() macro
Fixes: 3f30c6f1c2 ('libnm-core: extract NMSettingIPConfig superclass out of IP4, IP6 classes')
(cherry picked from commit 478754a504)
(cherry picked from commit 17987b7546)
2021-07-16 18:40:00 +02:00
Thomas Haller
9b3f5025a4 glib-aux: add nm_utils_thread_local_register_destroy() helper
_nm_thread_local is very neat, but when we allocate resources
we need to make sure that they are destroyed when the thread
exits.

We can use pthread_setspecific() for that, but using it is cumbersome.
Add a helper function to make that simpler.

Also, the number of possible pthread_key_t keys is limited. With this
way, we only need one key in total.

(cherry picked from commit bec4a40437)
(cherry picked from commit e83aad1972)
2021-07-16 18:40:00 +02:00
Thomas Haller
86f21d4aaf std-aux/glib-aux: move NM_AUTO_PROTECT_ERRNO() to libnm-std-aux
(cherry picked from commit 2b55408cc7)
(cherry picked from commit 309eba1078)
2021-07-16 18:40:00 +02:00
Thomas Haller
68c63af016 glib-aux: fix NM_AUTO_PROTECT_ERRNO() macro
(cherry picked from commit 95208e0655)
2021-07-16 18:40:00 +02:00
acabral
38fdbe0739 bond: support the peer_notif_delay bond option
Merge Request NetworkManager/NetworkManager!913

(cherry picked from commit e5dca403dc)
(cherry picked from commit a636c25b59)
2021-07-16 18:16:19 +02:00
Beniamino Galvani
429b07c107 core: merge branch 'bg/ipv6-pd'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/924

(cherry picked from commit fbce4e4ab0)
(cherry picked from commit c7fd0fb077)
2021-07-13 09:56:07 +02:00
Beniamino Galvani
a2fb5167ce device: start DHCPv6 when a prefix delegation is needed
If a prefix delegation is needed, currently NM restarts DHCPv6 on the
device with default route, but only if DHCPv6 was already running.

Allow the device to start DHCPv6 for a PD even if it was running
without DHCPv6.

See also: https://github.com/coreos/fedora-coreos-tracker/issues/888

(cherry picked from commit 62869621bd)
(cherry picked from commit 75b8ced29a)
2021-07-13 09:52:16 +02:00
Beniamino Galvani
b358fa3dc5 contrib: add script to test IPv6 prefix delegation
Add a script to test IPv6 prefix delegation with NM, in different
modes.

(cherry picked from commit 1e3bbdfbbb)
(cherry picked from commit cea673a273)
2021-07-13 09:52:16 +02:00
Beniamino Galvani
0fd36b7ba3 core: merge branch 'bg/rh1956793'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/917

(cherry picked from commit ec643237cd)

(cherry picked from commit a12c7f7839)
2021-07-13 09:40:17 +02:00
Beniamino Galvani
f1cdd702e3 device: send ARP announcements when there is carrier
Previously we sent announcements immediately for non-controllers, or
after the first port was attached for controllers.

This has two problems:

 - announcements can be sent when there is no carrier and they would
   be lost;

 - if a controller has a port, the port could be itself a controller;
   in that case we start sending ARPs with the fake address of the
   port. Later, when a leaf port is added to the second-level
   controller, the correct port MAC will be propagated by kernel up to
   both controllers.

To solve both problems, send ARP announcements only when the interface
has carrier. This also solves the second issue because controllers
created by NM have carrier only when there is a port with carrier.

Fixes: de1022285a ('device: do ARP announcements only after masters have a slave')

https://bugzilla.redhat.com/show_bug.cgi?id=1956793
(cherry picked from commit 1377f160ed)
(cherry picked from commit 70aeccf605)
2021-07-13 09:40:17 +02:00
Beniamino Galvani
288f774887 acd: log the MAC when announcing an IP
(cherry picked from commit 314024ea96)
(cherry picked from commit 786cd854d7)
2021-07-13 09:40:16 +02:00
Beniamino Galvani
b793925889 policy: prefer IPv4 to determine the hostname
When determining the hostname, it is preferable to evaluate devices in
a predictable order to avoid that the hostname changes between
different boots.

The current order is based first on hostname priority, then on the
presence of a best default route, and then on activation order.

The activation order is not a very strong condition, as it is
basically useless for devices that are autoactivated at boot.

As we already prefer IPv4 over IPv6 within the same connection, also
prefer it when 2 connections have the same priority and the same
default route status, to achieve better predictability.

https://bugzilla.redhat.com/show_bug.cgi?id=1970335
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/895
(cherry picked from commit 637a45e25b)
(cherry picked from commit 21051dc6d8)
2021-06-21 09:00:49 +02:00
Beniamino Galvani
85b8b07e27 merge: branch 'bg/tc-ignore'
https://bugzilla.redhat.com/show_bug.cgi?id=1928078
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/871
(cherry picked from commit 74f9272d3d)
2021-06-17 17:17:45 +02:00
Beniamino Galvani
acf0c4df2b ifcfg-rh: preserve an empty tc configuration
If the TC setting contains no qdiscs and filters, it is lost after a
write-read cycle. Fix this by adding a new property to indicate the
presence of the (empty) setting.

(cherry picked from commit 6a88d4e55c)
2021-06-17 17:07:05 +02:00
Beniamino Galvani
2a8181bcd7 core,libnm: don't touch device TC configuration by default
NetworkManager supports a very limited set of qdiscs. If users want to
configure a unsupported qdisc, they need to do it outside of
NetworkManager using tc.

The problem is that NM also removes all qdiscs and filters during
activation if the connection doesn't contain a TC setting. Therefore,
setting TC configuration outside of NM is hard because users need to
do it *after* the connection is up (for example through a dispatcher
script).

Let NM consider the presence (or absence) of a TC setting in the
connection to determine whether NM should configure (or not) qdiscs
and filters on the interface. We already do something similar for
SR-IOV configuration.

Since new connections don't have the TC setting, the new behavior
(ignore existing configuration) will be the default. The impact of
this change in different scenarios is:

 - the user previously configured TC settings via NM. This continues
   to work as before;

 - the user didn't set any qdiscs or filters in the connection, and
   expected NM to clear them from the interface during activation.
   Here there is a change in behavior, but it seems unlikely that
   anybody relied on the old one;

 - the user didn't care about qdiscs and filters; NM removed all
   qdiscs upon activation, and so the default qdisc from kernel was
   used. After this change, NM will not touch qdiscs and the default
   qdisc will be used, as before;

 - the user set a different qdisc via tc and NM cleared it during
   activation. Now this will work as expected.

So, the new default behavior seems better than the previous one.

https://bugzilla.redhat.com/show_bug.cgi?id=1928078
(cherry picked from commit a48edd0410)
2021-06-17 16:51:25 +02:00