Commit graph

34212 commits

Author SHA1 Message Date
Thomas Haller
5dc07174d3
cli: use "free()" for string from readline
Since glib 2.45, we are guaranteed that g_free() just calls free(), so
both can be used interchangeably. However, we still only depend on glib
2.40.

In any case, it's ugly to mix the two. Memory allocated by plain
malloc(), should be only freed with free(). The buffer in question comes
from readline, which allocates it using the system allocator.

Fixes: 995229181c ('cli: remove editor thread')
2023-02-08 09:51:25 +01:00
Thomas Haller
89734c7553
cli: avoid leak in readline_cb() overwriting previous line
Such leaks show up in valgrind, and are simply bugs.

Also, various callers (not all of them, which is another bug!) like to
take ownership of the returned string and free it. That means, we leave
a dangling pointer in the global variable, which is very ugly and error
prone.

Also, the callers like to free the string with g_free(), which is not
appropriate for the "rl_string" memory which was allocated by readline.
It must be freed with free(). Avoid that, by cloning the string using
the glib allocator.

Fixes: 995229181c ('cli: remove editor thread')
2023-02-08 09:51:25 +01:00
Thomas Haller
fb9c2c9a19
hostname: combine implementations of read_hostname() for Gentoo and Slackware 2023-02-08 09:51:25 +01:00
Thomas Haller
1349b850e3
platform: merge branch 'th/platform-ecmp-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1526

(cherry picked from commit 58011fe88d)
2023-02-07 14:26:47 +01:00
Thomas Haller
f71572a4bc
core: suppress onlink flag for IPv4 routes without gateway
(cherry picked from commit e59d09b053)
2023-02-07 14:26:46 +01:00
Thomas Haller
4ccca2b5bd
platform,core: better handle onlink flag for ECMP routes
The onlink flag is part of each next hop.

When NetworkManager configures ECMP routes, we won't support that. All
next hops of an ECMP route must share the same onlink flag. That is fine
and fixed by this commit.

What is not fine, is that we don't track the rtnh_flags flags in
NMPlatformIP4RtNextHop, and consequently our nmp_object_id_cmp() is
wrong.

Fixes: 5b5ce42682 ('nm-netns: track ECMP routes')
(cherry picked from commit 6ed966258c)
2023-02-07 14:26:45 +01:00
Thomas Haller
7c8ec03d5e
core: don't postpone configuring onlink ECMP routes
Also add some code comments.

Fixes: 7a844ecba9 ('netns: fix configuring onlink routes for ECMP routes')
(cherry picked from commit 6081e61d91)
2023-02-07 14:26:45 +01:00
Thomas Haller
aa15a7c55c
core: don't create dependent onlink route for onlink routes
If the route with a next hop is already onlink, we don't need to add a
direct route to the gateway.

It also wouldn't work previously, because the onlink route to the
gateway that we would add, would have no gateway and the RTNH_F_ONLINK
set. Kernel would reject that with an error. We would have to clear the
RTNH_F_ONLINK flag, if there is no gateway.

(cherry picked from commit 93b46c8906)
2023-02-07 14:26:45 +01:00
Thomas Haller
09d5c4e22e
platform: fix handling the onlink route attribute for routes without gateway
For IPv6, kernel doesn't care. If the gateway is ::, you may or may
not set the onlink attribute. But for IPv4 routes, that gets rejected:

  # ip route add 1.2.3.4/32 dev v onlink
  Error: Invalid flags for nexthop - PERVASIVE and ONLINK can not be set.

Silently suppress setting the flag in that case and ignore the user
request. After all, the effect is probably the same (that is, the route
is onlink anyway).

(cherry picked from commit 8b14849877)
2023-02-07 14:26:44 +01:00
Thomas Haller
58011fe88d
platform: merge branch 'th/platform-ecmp-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1526
2023-02-07 14:09:58 +01:00
Thomas Haller
e59d09b053
core: suppress onlink flag for IPv4 routes without gateway 2023-02-07 14:02:52 +01:00
Thomas Haller
6ed966258c
platform,core: better handle onlink flag for ECMP routes
The onlink flag is part of each next hop.

When NetworkManager configures ECMP routes, we won't support that. All
next hops of an ECMP route must share the same onlink flag. That is fine
and fixed by this commit.

What is not fine, is that we don't track the rtnh_flags flags in
NMPlatformIP4RtNextHop, and consequently our nmp_object_id_cmp() is
wrong.

Fixes: 5b5ce42682 ('nm-netns: track ECMP routes')
2023-02-07 14:02:52 +01:00
Thomas Haller
6081e61d91
core: don't postpone configuring onlink ECMP routes
Also add some code comments.

Fixes: 7a844ecba9 ('netns: fix configuring onlink routes for ECMP routes')
2023-02-07 14:02:52 +01:00
Thomas Haller
93b46c8906
core: don't create dependent onlink route for onlink routes
If the route with a next hop is already onlink, we don't need to add a
direct route to the gateway.

It also wouldn't work previously, because the onlink route to the
gateway that we would add, would have no gateway and the RTNH_F_ONLINK
set. Kernel would reject that with an error. We would have to clear the
RTNH_F_ONLINK flag, if there is no gateway.
2023-02-07 14:02:51 +01:00
Thomas Haller
8b14849877
platform: fix handling the onlink route attribute for routes without gateway
For IPv6, kernel doesn't care. If the gateway is ::, you may or may
not set the onlink attribute. But for IPv4 routes, that gets rejected:

  # ip route add 1.2.3.4/32 dev v onlink
  Error: Invalid flags for nexthop - PERVASIVE and ONLINK can not be set.

Silently suppress setting the flag in that case and ignore the user
request. After all, the effect is probably the same (that is, the route
is onlink anyway).
2023-02-07 14:02:51 +01:00
Thomas Haller
f7f0e18175
CONTRIBUTING: fix example command line about git-notes 2023-02-07 14:02:32 +01:00
Thomas Haller
41d667ba2a
po: fix marking "nm-setting-ovs-dpdk.c" for translation
Fixes: f930d55fea ('all: add support for ovs-dpdk n-rxq-desc and n-txq-desc')
(cherry picked from commit 88c08721c3)
2023-02-07 13:51:15 +01:00
Beniamino Galvani
618efd56a4
merge: branch 'bg/dns'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1506

(cherry picked from commit 6da2f3af4d)
2023-02-07 13:46:15 +01:00
Beniamino Galvani
2a0f41af03
dns: consider the dns-type and the priority when hashing DNS configs
The dns-type must be included in the hash because it contributes to
the generated composite configuration. Without this, when the type of
a configuration changes (e.g. from DEFAULT to BEST), the DNS manager
would determine that there was no change and it wouldn't call
update_dns().

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

Fixes: 8995d44a0b ('core: compare the DNS configurations before updating DNS')
(cherry picked from commit 46ccc82a81)
2023-02-07 13:46:15 +01:00
Beniamino Galvani
b14268290a
core,libnm: move enum NMDnsIPConfigType
The enum will be used outside of core/dns.

(cherry picked from commit 8a4632b56a)
2023-02-07 13:46:14 +01:00
Beniamino Galvani
a7412e2c65
core: rename and move nm_ip_config_dns_hash()
The function operates on a NML3ConfigData, rename it and move it to
the right place.

(cherry picked from commit ec0a83b224)
2023-02-07 13:46:14 +01:00
Thomas Haller
0ee784f1f0
contrib: add "git-backport-merge" script for backporting merge commits in NetworkManager
On the main branch, we commonly rebase our WIP branches to latest HEAD,
before merging them with "--no-ff". The effect is to have a merge commit
that acts as a parentheses around the set of patches.

When backporting such a branch, we should preserve that structure and
take the merge commit too. We should must use `git cherry-pick -x` to
record the commit IDs of the original patch.

This script helps with that.

Also hook it up in "contrib/scripts/nm-setup-git.sh" to create an alias
for it. This alias has the advantage, of fetching the latest version of
the script from "main" or "origin/main", so it also works on older
branches.
2023-02-03 10:37:35 +01:00
Thomas Haller
c8c2e51916
mailmap: update mailmap entry for gaoxingwang 2023-02-02 11:55:09 +01:00
Thomas Haller
5ffc9e14f9
mailmap: update mailmap entry for Fernando 2023-02-02 11:55:00 +01:00
Thomas Haller
13bd3f7526
mailmap: update mailmap entry for Ana 2023-02-02 11:50:47 +01:00
Thomas Haller
379af3e753
platform/tests: merge branch 'th/platform-cache-test-2'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1525

(cherry picked from commit 04fb042965)
2023-02-01 22:45:57 +01:00
Thomas Haller
184c7b528e
platform/tests: re-enable and fix "/route/test_cache_consistency_routes" tests
The tests failed in certain cases on gitlab-ci and were temporarily
disabled.

These issues should be fixed now and the test pass. Reenable.

(cherry picked from commit 5c324adc7c)
2023-02-01 22:45:57 +01:00
Thomas Haller
34c707ee78
platform/tests: workaround failure of nmtstp_assert_platform()
(cherry picked from commit 82e21a4906)
2023-02-01 22:45:56 +01:00
Thomas Haller
ddb5e1d50e
platform/tests: disable check for sorted IPv4 routes by weak-id
Due to a kernel bug, this assert can fail and I don't think
it can be fixed in NetworkManager. Disable the check.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2165720
(cherry picked from commit 0347dc7ddc)
2023-02-01 22:45:56 +01:00
Thomas Haller
eb73367d67
platform/tests: flush all tables in test_cache_consistency_routes() test
(cherry picked from commit 8089133f1c)
2023-02-01 22:45:56 +01:00
Thomas Haller
dedbc9ef05
platform/tests: suppress noisy output in test_cache_consistency_routes() test
(cherry picked from commit de1dccba18)
2023-02-01 22:45:56 +01:00
Thomas Haller
04fb042965
platform/tests: merge branch 'th/platform-cache-test-2'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1525
2023-02-01 22:44:09 +01:00
Thomas Haller
5c324adc7c
platform/tests: re-enable and fix "/route/test_cache_consistency_routes" tests
The tests failed in certain cases on gitlab-ci and were temporarily
disabled.

These issues should be fixed now and the test pass. Reenable.
2023-02-01 22:43:53 +01:00
Thomas Haller
82e21a4906
platform/tests: workaround failure of nmtstp_assert_platform() 2023-02-01 22:43:52 +01:00
Thomas Haller
0347dc7ddc
platform/tests: disable check for sorted IPv4 routes by weak-id
Due to a kernel bug, this assert can fail and I don't think
it can be fixed in NetworkManager. Disable the check.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2165720
2023-02-01 22:43:52 +01:00
Thomas Haller
8089133f1c
platform/tests: flush all tables in test_cache_consistency_routes() test 2023-02-01 22:43:51 +01:00
Thomas Haller
de1dccba18
platform/tests: suppress noisy output in test_cache_consistency_routes() test 2023-02-01 22:43:51 +01:00
Thomas Haller
362a96ff52
contrib: setup "systemd" in makerepo.sh script 2023-02-01 11:05:13 +01:00
Fernando Fernandez Mancera
d9d33e2acc netns: fix configuring onlink routes for ECMP routes
Kernel enforces that all nexthops must be reachable through a route.
L3Cfg is generating dependent onlink routes to solve this problem but
the IPv4 ECMP commit is happening before that.

To solve this we introduce two boolean fields "is_new" and "is_ready" to
know in which state is the L3Cfg affected. Initially, "is_new" is TRUE
and "is_ready" is FALSE. Here we schedule a commit on idle and we set
"is_new" to FALSE. When revisiting, we set "is_ready" to TRUE and then
we set the ECMP IPv4 routes.

When a reapply kicks in we reset the L3Cfg state by setting "is_new" to
TRUE.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1520
(cherry picked from commit 7a844ecba9)
2023-02-01 11:04:09 +01:00
Fernando Fernandez Mancera
79a9fcb166 l3-config-data: do not check route table to get direct routes
Kernel enforces that all route nexthop are reachable but it doesn't care
if the drect route to the nexthop is in a different route table.

(cherry picked from commit f187e63fa8)
2023-02-01 11:04:09 +01:00
Fernando Fernandez Mancera
d27a164d09 Revert "nm-netns: add onlink routes for ECMP routes"
ECMP IPv4 route nexthops requires an onlink route but we should trust
l3cfg when generating and managing such routes.

This reverts commit 737cb5d424.

(cherry picked from commit cbf70b4dca)
2023-02-01 11:04:09 +01:00
Fernando Fernandez Mancera
4073211595 Revert "l3cfg: do not add dependent routes for non-default routes"
We must trust l3cfg when generating dependent onlink routes for all kind
of routes not default routes only. This was done by
"nm_platform_ip_route_sync()" so there is not change in behaviour at
all.

"nm_platform_ip_route_sync()" could be needed for other situation where
l3cfg cannot add the dependent onlink routes, so we are not removing
that logic.

This reverts commit 6b4123db1c.

(cherry picked from commit 9c492c6fc4)
2023-02-01 11:04:09 +01:00
Thomas Haller
79c54e645c
platform/tests: merge branch 'th/platform-cache-test'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1513

(cherry picked from commit 90df190a1a)
2023-02-01 10:50:19 +01:00
Thomas Haller
a8f2625259
platform/tests: ignore ip-tunnel interfaces in nmtstp_assert_platform()
Certain ip-tunnel modules automatically create network interfaces (for
example, "ip_gre" module creates "gre0" and others).

Btw, that's not the same as `modprobe bonding max_bonds=1`, where
loading the module merely automatically creates a "bond0" interface. In
case of ip tunnel modules, these generated interfaces seem essential to
how the tunnel works, for example they cannot be deleted. I don't
understand the purpose of those interfaces, but they seem not just
regular tunnel interfaces (unlike, "bond0" which is a regular bond
interface, albeit automatically created).

Btw, if at the time when loading the module, an interface with such name
already exists, it will bump the name (for example, adding a "gre1"
interfaces, and so on). That adds to the ugliness of the whole thing,
but for our unit tests, that is no problem. Our unit tests run in a
separate netns, and we don't create conflicting interfaces. That is, an
interface named "gre0" is always the special tunnel interface and we
can/do rely on that.

Note that when the kernel module gets loaded, it adds those interfaces
to all netns. Thus, even if "test-route-linux" does not do anything with
ip tunnels, such an interface can always appear in a netns, simply by
running "test-link-linux" (or any other tool that creates a tunnel) in
parallel or even in another container.

Theoretically, we could just ensure that we load all the conflicting
ip-tunnel modules (with nmtstp_ensure_module()). There there are two
problems. First, there might be other tunnel modules that interfere but
are not covered by nmtstp_ensure_module(). Second, when kernel creates
those interfaces, it does not send correct RTM_NEWLINK notifications (a
bug), so our platform cache will not be correct, and
nmtstp_assert_platform() will fail.

The only solution is to detect and ignore those interfaces.  Also,
ignore all interfaces of link-type "unknown". Those might be from other
modules that we don't know about and that exhibit the same problem.

(cherry picked from commit e99433866d)
2023-02-01 10:50:17 +01:00
Thomas Haller
7268da807f
platform/tests: avoid recent route protocols in "/route/test_cache_consistency_routes" tests
Ubuntu 18.04 comes with iproute2-4.15.0-2ubuntu1.3. The
"/etc/iproute2/rt_protos" file from that version does not yet support
the "bgp" entry. Also the "babel" entry is only from 2014. Just choose
other entries. The point is that NetworkManager would ignore those, and
that applies to "zebra" and "bird" alike.

(cherry picked from commit 26592ebfe5)
2023-02-01 10:50:17 +01:00
Thomas Haller
487ebbe3c8
platform/tests: use nmtstp_ensure_module() in test_software_detect()
This helper function already loads the module and performs
additional checks. Use it.

(cherry picked from commit acc0cee28e)
2023-02-01 10:50:16 +01:00
Thomas Haller
30a0ea310b
platform/tests: add nmtstp_ensure_module() helper
This will make sure that the IP tunnel module is loaded. It does so by
creating (and deleting) a tunnel interface.

That is important, because those modules will create additional interfaces
that show up in `ip link` (like "gre0"), and those interfaces can interfere
with the tests.

Also add nmtstp_link_is_iptunnel_special() to detect whether an
interface is one of those special interfaces.

(cherry picked from commit 451cedf2bf)
2023-02-01 10:50:16 +01:00
Thomas Haller
19a192dbdb
platform/tests: fix nmtstp_link_{gre,ip6gre,ip6tnl,ipip}_add() to support missing parent
(cherry picked from commit 4966f9d784)
2023-02-01 10:50:15 +01:00
Thomas Haller
208218e141
gitlab-ci: use "meson test" for running unit tests
It seems that `meson test` is preferred over `ninja test`.  Also, pass
"--print-errorlogs" to meson, and pass "-v" to the build steps.

Note that `ninja test` already ends up calling `meson test
--print-errorlogs`, but it doesn't use "-v", so the logs are truncated.

(cherry picked from commit dba2fb5fff)
2023-02-01 10:50:15 +01:00
Thomas Haller
44f080879b
gitlab-ci: rerun meson test on failure with debugging
Like done for autotools. First we run the test without debugging option.
If it fails, we run it again to possibly trigger the failure again and
get better logs.

(cherry picked from commit 13d9cf75ed)
2023-02-01 10:50:15 +01:00