Commit graph

1338 commits

Author SHA1 Message Date
Thomas Haller
dc1cf48b86 core: add support for tracking Device times Profile in NMManager
This will be used next, to track the per-device, per-profile autoconnect
state.
2023-02-22 22:38:03 +00:00
Thomas Haller
20f791d8fe core: expose accessors to NMManager in NMSettings, NMSettingsConnection, NMDevice
We should avoid using the NM_MANAGER_GET singleton. Everybody already
has a manager instance. Expose it and allow to use it.
2023-02-22 22:38:03 +00:00
Thomas Haller
a08214f60d
wwan: workaround missing mm_modem_3gpp_set_initial_eps_bearer_settings() API
This was introduced only in MM 1.10. This breaks build on Centos7.

Fixes: c52999ee90 ('wwan: Set initial EPS bearer settings')
2023-02-21 18:04:23 +01:00
Fernando Fernandez Mancera
d2ca44ffc6 all: add new "ipv[46].replace-local-rule" setting
This setting allows the user to remove the local route rule that is
autogenerated for both IPv4 and IPv6. By default, NetworkManager won't
touch the local route rule.
2023-02-21 15:36:38 +01:00
Beniamino Galvani
4138be6a5a device: skip DNS resolution for tentative IPv6 addresses
A tentative IPv6 address can still fail DAD, so don't use it to
resolve the hostname via DNS. Furthermore, tentative addresses can't
be used to contact the nameserver and so the resolution will fail if
there is no other valid IPv6 address. Wait that the address becomes
non-tentative.
2023-02-21 13:46:55 +01:00
Beniamino Galvani
d65702803c core: print stderr from nm-daemon-helper
Currently the only way to return an error code from the daemon helper
is via the process exit code, but that is not enough to fully describe
an error from getaddrinfo(); in fact, the function returns a EAI_*
error code and when the value is EAI_SYSTEM, the error code is
returned in errno.

At the moment, any messages printed to stderr by the helper goes to NM
stderr; instead, we want to capture it and pass it through the logging
mechanism of NM, so that it can be filtered according to level and
domain.
2023-02-21 13:46:54 +01:00
Beniamino Galvani
7037aa66c6 device: improve logging for hostname-from-dns events
Improve logging:
 - log only when something changes
 - print the new resolver state, instead of the old one
 - rename state "in-progress" to "started"
 - log when the resolver state is reset due to DNS changes
2023-02-21 13:46:54 +01:00
Beniamino Galvani
961824d43b core: change buffer allocation size for the daemon helper
Use slightly more efficient sizes.
2023-02-21 13:46:54 +01:00
Thomas Haller
2fe4313b92
dhcp: log used DHCP IAID as hexstr
This is also the format that we will use to expose it in the lease
information. It's the format that dhclient uses.
2023-02-21 09:20:51 +01:00
Thomas Haller
07f1789725
dhcp: add the DHCPv6 IAID to the lease information
We already get the IAID from the dhclient environment. This is actually
rather useful, because dhclient plugin does not support setting the
value (that is, what we request in "config.v6.iaid" is not actually
used). Already previously, was the IAID for dhclient present in the
lease information. Now also normalize/verify it.

Expose the used IAID also with the internal (systemd) plugin. There we
explicitly set the IAID and know it.
2023-02-21 09:20:51 +01:00
Thomas Haller
5a05ba398b
dhcp: add "static_key" argument to nm_dhcp_option_add_option() etc.
Our lease is tracked in a plain string dictionary. For dhclient plugin
and similar, the keys are received via the environment, they are thus
unlimited. For the internal plugins they are known at compile time and
static strings. We thus sometimes need to clone the string, and
sometimes not.

Unfortunately, we cannot ask the GHashTable whether it has a free
function for the key, so we need to explicitly tell it. Add a parameter
for that.
2023-02-21 09:13:09 +01:00
Thomas Haller
69106d0aef
core: reuse _nm_utils_iaid_verify() for parsing
There should be one function for parsing the string. Use it everywhere.

Also, because we will accept specifying the IAID as hex string so the
same parsing code should be used everywhere.
2023-02-21 09:12:59 +01:00
Beniamino Galvani
d403ac3d40 device: update address in nm_device_update_from_platform_link()
When a software device is deactivated, normally we schedule a idle
task to unrealize the device (delete_on_deactivate). However, if a new
activation is enqueued on the same device (and that implies that the
new profile is compatible with the device), then the idle task is not
scheduled and the device will normally transition to the different
states (disconnected, prepare, config, etc.).

For ovs-interfaces, we remove the db entry on disconnect and that
makes the link go away; however, we don't clear the hw_addr* fields of
the device struct.

When the new link appears, we try to set the new cloned MAC but the
stale hw_addr field indicates that it's already set. Avoid this
problem by updating the address as soon as the link appears.

https://bugzilla.redhat.com/show_bug.cgi?id=2168477
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1532
2023-02-20 17:35:35 +01:00
Sven Schwermer
c52999ee90
wwan: Set initial EPS bearer settings
Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
2023-02-20 12:59:41 +01:00
Beniamino Galvani
a839395e30 dispatcher: fix constructing the IPv4 nameserver variable
Use the value of the address instead of its pointer.

Fixes: c68e148b02 ('core: extend NML3ConfigData:nameserver to track DNS as string')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1217
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1539
2023-02-20 09:36:30 +01:00
Wen Liang
af677542b5 dbus: deprecate the NMActiveConnection Master property
To embrace the inclusive language, deprecate the NMActiveConnection
Master property and in favor of the NMActiveConnection Controller
property.
2023-02-16 11:04:14 -05:00
Ratchanan Srirattanamet
08a38ed619
wwan/ofono: fix a couple of logic errors in update_connection_list()
- Only consider preferred context of "internet" type. There can be
  multiple preferred contexts of multiple types, and we care about
  "internet" type only.
- Don't check for "internet+mms" type. It turns out that "internet+mms"
  isn't a thing in oFono, and is used to represent "internet" context
  with MMSC in the lomiri-system-setting's UI only.

Fixes: 9fc72bf75d ('wwan/ofono: create connections based on available contexts')
Bug-UBports: https://gitlab.com/ubports/development/core/packaging/network-manager/-/issues/3
2023-02-16 16:42:39 +01:00
Beniamino Galvani
27ad228df1 device: preserve assume state if updating port fails
If we fail to update the port connection, don't forget the assume
state but try again later. This helps when assuming a team connection
and its ports: the ports may fail to generate a connection because
teamd was not started yet; in that case we need to try again.

https://bugzilla.redhat.com/show_bug.cgi?id=2092215
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1523
2023-02-13 15:46:02 +01:00
Dylan Van Assche
cef880c66f
nm-dispatcher: dispatch on reapply
Trigger a dispatcher event when a connection is reapplied on a NM device.
Some devices such as phones have already a DHCP client running for accepting
connections when they are plugged into USB to transfer data over SSH.
When NetworkManager switches the connection IP method to shared,
it spawns a dnsmasq process to handle DHCP and DNS for that connection.
However, a dispatcher event is needed to disable the external DHCP server
for these USB connections as NetworkManager's dnsmasq handles them now.
Moreover, when the connection method is switched to a different mode,
the external DHCP server needs to be spawned again to make sure that
SSH connections are still possible to the device.

To achieve this, add a new NetworkManager Dispatcher event
'reapply' which is triggered when a connection is reapplied on a NM
device. This way, a dispatcher script can handle the case above by
inspecting the IP method in the dispatcher script.
2023-02-08 17:08:35 +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
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
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
Beniamino Galvani
46ccc82a81 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')
2023-02-01 09:00:56 +01:00
Beniamino Galvani
8a4632b56a core,libnm: move enum NMDnsIPConfigType
The enum will be used outside of core/dns.
2023-02-01 09:00:56 +01:00
Beniamino Galvani
ec0a83b224 core: rename and move nm_ip_config_dns_hash()
The function operates on a NML3ConfigData, rename it and move it to
the right place.
2023-02-01 09:00:56 +01:00
Fernando Fernandez Mancera
7a844ecba9 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
2023-01-31 17:55:53 +01:00
Thomas Haller
6e96d71731
all: use nm_random_*() instead of g_random_*()
g_random_*() is based on GRand, which is not a CSPRNG. Instead, rely on
kernel to give us good random numbers, which is what nm_random_*() does.

Note that nm_random_*() calls getrandom() (or reads /dev/urandom), which
most likely is slower than GRand. It doesn't matter for our uses though.

It is cumbersome to review all uses of g_rand_*() whether their usage of
a non-cryptographically secure generator is appropriate. Instead, just
always use an appropriate function, thereby avoiding this question. Even
glib documentation refers to reading "/dev/urandom" as alternative. Which
is what nm_random_*() does. These days, it seems unnecessary to not use
the best random generator available, unless it's not fast enough or you
need a stable/seedable stream of random numbers.

In particular in nmcli, we used g_random_int_range() to generate
passwords. That is not appropriate. Sure, it's *only* for the hotspot,
but still.
2023-01-30 10:51:13 +01:00
Thomas Haller
e99433866d
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.
2023-01-30 08:19:51 +01:00
Thomas Haller
26592ebfe5
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.
2023-01-30 08:19:51 +01:00
Thomas Haller
acc0cee28e
platform/tests: use nmtstp_ensure_module() in test_software_detect()
This helper function already loads the module and performs
additional checks. Use it.
2023-01-30 08:19:50 +01:00
Thomas Haller
451cedf2bf
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.
2023-01-30 08:19:50 +01:00
Thomas Haller
4966f9d784
platform/tests: fix nmtstp_link_{gre,ip6gre,ip6tnl,ipip}_add() to support missing parent 2023-01-30 08:19:50 +01:00
Thomas Haller
14b1a7ba30
l3cfg/tests: temporarily disable failing tests "/l3cfg/$N"
Seems this test fails easily under gitlab-ci, if we set NMTST_SEED_RAND
to something else than "0". There is nothing particular special about
"0", except that a randomly different code paths are chosen.

A randomized test that doesn't pass on all systems with all random
paths, is broken. Disable for now. Needs to be fixed.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2165141
2023-01-30 08:18:44 +01:00
Fernando Fernandez Mancera
9934be52cd device: use NMUnmanFlagOp enum members instead of literals
Replace TRUE or FALSE for their NMUnmanFlagOp enum member. It is more
intuitive for newcomers so they can understand what is being set without
looking at the values or function logic.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1516
2023-01-27 14:47:31 +01:00
Michael Biebl
8132045d5f
nmcli: fix typos in nmcli output
Spotted by lintian:
  I: network-manager: spelling-error-in-binary writting writing [usr/bin/nmcli]
  I: network-manager: spelling-error-in-binary wihout without [usr/lib/x86_64-linux-gnu/NetworkManager/1.40.12/libnm-device-plugin-wifi.so]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1515
2023-01-27 08:00:02 +01:00
Fernando Fernandez Mancera
f187e63fa8 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.
2023-01-26 11:10:08 +01:00
Fernando Fernandez Mancera
cbf70b4dca 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.
2023-01-26 11:10:08 +01:00
Fernando Fernandez Mancera
9c492c6fc4 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.
2023-01-26 11:07:00 +01:00
Lubomir Rintel
1f0d1d78d2 dns-manager: always apply options from [global-dns]
Currently, the use of [global-dns] section for setting DNS options is
conditioned on presence of a nameserver in a [global-dns-domain-*] section.
Attempt to use the section for options alone results in an error:

  [global-dns]
  options=timeout:1

Or via D-Bus API:

  # busctl set-property org.freedesktop.NetworkManager \
      /org/freedesktop/NetworkManager org.freedesktop.NetworkManager \
      GlobalDnsConfiguration 'a{sv}' 2 \
          "options" as 1 "timeout:1" \
          "domains" a{sv} 0
  ...
  Nov 24 13:15:21 zmok.local NetworkManager[501184]: <debug> [1669292121.3904]
      manager: set global DNS failed with error: Global
      DNS configuration is missing the default domain

The insistence on existence of [global-dns-domain-*] would make sense if
other [global-dns-domain-...] sections were present.

However, the user might only want to set the options in resolv.conf and
still use connection-provide nameservers for the actual resolving.

Lift the limitation by allowing the [global-dns] to be used alone, while
still insist on [global-dns-domain-*] being there in presence of other
domain-specific options.

https://bugzilla.redhat.com/show_bug.cgi?id=2019306
2023-01-26 09:02:16 +01:00
Lubomir Rintel
de1c06daab config: fix a reversed conditional
This effectively makes [*global-dns-domain-*] sections in configuration be
ignored unless [*global-dns] is also present. This happens because
nm_config_keyfile_has_global_dns_config() mixes the group names up and
attempts to loop up [.intern.global-dns-domain-*] in user configuration and
[global-dns-domain-*] in the internal one.

Fixes: da0ded4927 ('config: drop global-dns.enable option in favor of .config.enable')
2023-01-26 09:02:16 +01:00
Lubomir Rintel
051819a78e config-data: style fix 2023-01-26 09:02:16 +01:00
Lubomir Rintel
f2f806f77d dns-manager: style fix 2023-01-26 09:02:16 +01:00
Alexander Lochmann
11832e2ba3 ndisc: Accept routes from on-link prefixes form ra
It is possible that an ra leads to two routes having
the same prefix as well as the same prefix length.
One of them, however, refers to the on-link prefix,
and the other one to a route from the route information field.
(Moreover, they might have different route preferences.)
Hence, if both routes differ in the on-link property,
both are added, and the route from the route information
option receives a metric penalty.
Fixed #1163.
2023-01-23 16:50:08 +00:00