Commit graph

13538 commits

Author SHA1 Message Date
Thomas Haller
9cc242596d
libnm: allow OVS external-ids also for system interface
Note that reapply currently does not work for OVS system interface.
That is, because the code does not make it easy to implement that.
2020-12-11 09:38:16 +01:00
Thomas Haller
8cadfed2fe
wifi: fix evaluating the scanning state for wpa-supplicant
wpa_supplicant has a property "scanning" and a "state=scanning".
Previously, NetworkManager considered both parts to indicate whether
supplicant is currently scanning (if either the property or the state
indicated scanning, it took that as indication for scanning).

If NetworkManager thinks that supplicant is scanning, it suppresses
explicit "Scan" requests. That alone is not severe, because the "Scan"
request is only to trigger a scan in supplicant (which supplicant
possibly is already doing in state "scanning").

However, what is severe is that NetworkManager will also block autoconnect
while supplicant is scanning. That is because NetworkManager wants to get
a complete scan result before deciding which network to connect to.

It seems that wpa_supplicant can get into "state=scanning" and stay
there indefinitely. This prevents NetworkManager from autoactivating
a profile.

Fix that, to only honor the "scanning" property.

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

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2020-12-10 12:01:12 +01:00
Thomas Haller
d0a4661b65
keyfile: fix error message on failure to generate filename in _internal_write_connection() 2020-12-09 10:30:13 +01:00
Beniamino Galvani
e5113a7fd9 ovs: clean up interfaces from ovsdb at startup
During shutdown, NM always tries to remove from ovsdb all bridges,
ports, interfaces that it previously added. Currently NM doesn't run
the main loop during shutdown and so it's not possible to perform
asynchronous operations. In particular, the NMOvsdb singleton is
disposed in a destructor where it's not possible to send out all the
queued deletions.

The result is that NM deletes only one OVS interface, keeping the
others. This needs to be fixed, but requires a rework of the shutdown
procedure that involves many parts of NM.

Even when a better shutdown procedure will be implemented, we should
support an unclean shutdown caused by e.g. a kernel panic or a NM
crash. In these cases, the interfaces added by NM would still linger
in the ovsdb.

Delete all those interface at NM startup. If there are connections
profiles for them, NM will create them again.

https://bugzilla.redhat.com/show_bug.cgi?id=1861296
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/700
2020-12-07 13:57:17 +01:00
Thomas Haller
cd0e328f7e
l3cfg: avoid "-Werror=maybe-uninitialized" warning in _load_link()
It's not actually an issue, but the compiler might think that
we use nacd_old_addr without initialization.
2020-12-06 14:40:28 +01:00
Thomas Haller
d0643fbf3b
policy: remove unused code from "nm-policy.c" for reverse DNS lookup for hostname
By now, each NMDevice does the reverse lookup and caches the result
via nm_device_get_hostname_from_dns_lookup().

The code is no longer used in NMPolicy.

Fixes: 09c8387114 ('policy: use the hostname setting')
2020-12-04 09:32:32 +01:00
Thomas Haller
3ee35a3906
core: fix warning about unused variable in _l3_acd_data_add_all()
src/nm-l3cfg.c: In function _l3_acd_data_add_all:
    src/nm-l3cfg.c:1557:14: error: unused variable i [-Werror=unused-variable]
     1557 |     guint    i;
          |              ^
2020-12-03 14:54:15 +01:00
Beniamino Galvani
5b9479a728 policy: fix hostname lookup from DNS
Fixes: 09c8387114 ('policy: use the hostname setting')
2020-12-02 17:33:45 +01:00
Beniamino Galvani
526b484be1 dns: sd-resolved: fix hash table iteration
g_hash_table_iter_next() wants a (gpointer *), not an (int *).

Fixes: f70ee67058 ('dns: sd-resolved: reset interface configuration on deactivation')
2020-11-30 22:36:55 +01:00
Beniamino Galvani
d0df9bf0bd manager: return most recent connection in active_connection_find()
When a connection is reactivated, there could be two active
connections tracked by the manager: the deactivating one and the new
one. Ensure that we first return the most recent one so that slaves
will pick the right master.

Fixes-test: @iptunnel_gretap_doc_procedure
Fixes: dc6ec6ce7b ('core: reverse the order of active connections in the manager')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/697
2020-11-30 14:43:22 +01:00
Thomas Haller
44ebb99cfa
dns: detect support of systemd-resolved's SetLinkDefaultRoute() and avoid it
We now always use SetLinkDefaultRoute(), but that API was only added in
systemd v240 ([1]).

We could just always call the non-existing method, and ignore the
error. However, that feels ugly. Would systemd-resolved log warnings
about that? Should we suppress all messages about that failure (not
good for debugging).

Instead, make an effort to detect support of the function, and avoid
calling it. That is significantly more complicated than just always
calling the method and not care.

Note that even if systemd-resolved does not support SetLinkDefaultRoute(),
we cannot do anything smart about that. We would simply rely on
systemd-resolved (hopefully) doing the right thing automatically.
That's better and simpler than explicitly adding a "~." domain in
the fallback case.

Also, detecting support is straight forward in the common case, where
there is either success or a clear "org.freedesktop.DBus.Error.UnknownMethod"
error. In cases where there is any other failure, we don't really know.
In that case, we keep trying to use the API under the assumption that
it should work.

[1] https://github.com/systemd/systemd/commit/7 ## 7673795dcf5797491e7f785cbf5077d29a15db4
2020-11-27 10:46:42 +01:00
Thomas Haller
4fc44952f7
dns: preserve DNS settings for systemd-resolved to resend
When the DNS settings change, we update the request_queue_lst_head list,
with all the requests we want to send.

Then, send_updates() will try to send it. It might not do it right away,
if resolved is not on the bus or the D-Bus connection is not fully inialized
(meaning, we don't know the name owner yet). In those cases, we would
keep the list of requests, and send them later.

However, when sending them, we would also forget about the configuration.

That means, if you restart systemd-resolved, then the daemon drops off
the bus and reappears. I think that systemd-resolved in fact persists
the configuration during restart. So, usually the settings are still the
same after restart. However, we should do better here: if the service
appears, we should send the settings again.

This means to not forget the requests after we send them once -- at
least, until a new update replaces them.
2020-11-27 10:46:42 +01:00
Thomas Haller
42d47d1cd7
dns: minor cleanup of call_done() in "nm-dns-systemd-resolved.c" 2020-11-27 10:46:42 +01:00
Thomas Haller
8af6647cda
dns: cleanup RequestItem and track ifindex and self parameter
We will need these changes next:

- add "self" and "ifindex" fields to RequestItem struct. We will
  pass on these structs are user-data for the callbacks, so that
  we afterwards know which request completed.

- add DBUS_OP_SET_LINK_DEFAULT_ROUTE global variable. We don't
  clone the "operation" string but use string literals. However,
  string literals are not guaranteed to be deduplicated, so we
  should only compare them with strcmp(). The static variable
  avoids this: we can use pointer equality to compare it.
  This will be used next.
2020-11-27 10:26:11 +01:00
Fernando Fernandez Mancera
cd0cf9229d
veth: add support to configure veth interfaces
NetworkManager is now able to configure veth interfaces throught the
NMSettingVeth. Veth interfaces only have "peer" property.

In order to support Veth interfaces in NetworkManager the design need
to pass the following requirements:

 * Veth setting only has "peer" attribute.
 * Ethernet profiles must be applicable to Veth interfaces.
 * When creating a veth interface, the peer will be managed by
   NetworkManager but will not have a profile.
 * Veth connection can reapply only if the peer has not been modified.
 * In order to modify the veth peer, NetworkManager must deactivate the
   connection and create a new one with peer modified.

In general, it should support the basis of veth interfaces but without
breaking any existing feature or use case. The users that are using veth
interfaces as ethernet should not notice anything changed unless they
specified the veth peer setting.

Creating a Veth interface in NetworkManager is useful even without the
support for namespaces for some use cases, e.g "connecting one side of
the veth to an OVS bridge and the other side to a Linux bridge" this is
done when using OVN kubernetes [1][2]. In addition, it would provide
persistent configuration and rollback support for Veth interfaces.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1885605
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1894139

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-11-27 10:12:36 +01:00
Thomas Haller
d615b902d8
core: recognize "wifi.scan-generate-mac-address-mask" as valid "NetworkManager.conf" option
Fixes: 32f4abe90b ('config: warn about unknown keys in config files')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/595
2020-11-27 09:55:01 +01:00
Beniamino Galvani
c4beaac67b ovs: avoid ovs error when same MAC is set on a local interface and bridge
If the same MAC address is set on both the bridge connection and the
interface connection, and the interface is local, NM currently sets
the hwaddr record in both Bridge and Interface ovsdb tables. As a
result, ovs complains with error:

  bridge|ERR|interface br0: ignoring mac in Interface record (use Bridge record to set local port's mac)

Avoid this error: if the bridge and interface MACs are the same, just
set the address in the Bridge table; if they are different, give a
more detailed warning and ignore the interface MAC.

https://bugzilla.redhat.com/show_bug.cgi?id=1899745
2020-11-26 17:54:22 +01:00
Beniamino Galvani
e9e99b8677 ovs: rename variable
@interface_is_internal is a bad name. The variable indicates whether
the interface is the local interface.
2020-11-26 17:45:26 +01:00
Beniamino Galvani
b0c018830e initrd: fix parsing of ip= arguments with empty first token
The parser checks if the first token of an ip= argument is an IP
address to determine which of the two possible syntaxes is used:

 ip=<interface>:{dhcp|on|any|dhcp6|auto6}[:[<mtu>][:<macaddr>]]
 ip=<client-IP>:[<peer>]:<gateway-IP>:<netmask>:<client_hostname>:<interface>:{none|off|dhcp|on|any|dhcp6|auto6|ibft}[:[<mtu>][:<macaddr>]]

This works as long as the first token is not empty, which - according
to the dracut.cmdline man page - seems to be guaranteed.

However, the network-legacy dracut plugin accepts an empty interface
or client IP. Also, if a user needs DHCP and wants to specify a
hostname, the only possible syntax is:

 ip=::::<hostname>::dhcp

Change the parser to check the second token instead, similarly to what
the network-legacy module does [1].

[1] https://github.com/dracutdevs/dracut/blob/050/modules.d/40network/net-lib.sh#L490

https://bugzilla.redhat.com/show_bug.cgi?id=1900260
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/693
2020-11-26 17:41:40 +01:00
Thomas Haller
e7d828f6a0
trivial: fix coding style 2020-11-24 18:51:58 +01:00
Beniamino Galvani
195cbf3cee dns: fix setting systemd-resolved name servers for default route
If the interface is the DNS default route but has no domain, its name
servers were not sent to systemd-resolved. Fix this.

Fixes: ee9fab0361 ('dns: fix handling default routing domains with systemd-resolved')
2020-11-24 17:55:37 +01:00
Thomas Haller
297e84d569
dns/trivial: rename NMDnsIPConfigData to NMDnsConfigIPData
Let's try to rework and improve the implementation.

The code is already rather complicated from the start. Let's first try
to use consistent names for things. Naming is very important, so that
they follow a pattern that tells you what something does.
2020-11-24 08:53:01 +01:00
Thomas Haller
d358f96104
dns: allow sorting of NMDnsConfigData
We will rework preparing the DNS data, so that we do things that
currently "nm-dns-systemd-resolved.c" does (see InterfaceConfig).

We thus will need to access the NMDnsConfigData, which is per-ifindex.
As such, it is useful to have NMDnsConfigData in a stable order, sorted
by ifindex. As we track NMDnsConfigData in a hash table, we need to
do the sorting outside of that.

There are many ways to achive that. The solution here is to let
NMDnsConfigData also be tracked by a CList. We only need to resort
the list, when we add a new ifindex -- which should happen only seldom.
The advantage is that the sorting happens in-place and can expose
it to other uses (by providing them access to the CList head).
2020-11-24 08:53:01 +01:00
Thomas Haller
ef12e9a9e2
core: add nm_ip_config_is_ipv4() for dispatching NMIP[46]Config operations
"NM_IP_CONFIG_GET_CLASS(config)->is_ipv4" only follows a pointer (except
additional assertions in debug builds). It's thus more efficient than
NM_IS_IP4_CONFIG(), which needs to compare GType and call
nm_ip4_config_get_type().
2020-11-24 08:53:00 +01:00
Thomas Haller
41d16603f1
core: use nm_ip_config_iter_ip_route_for_each() in _get_route_table_sync_mode_stateful() 2020-11-24 08:53:00 +01:00
Thomas Haller
a25935177e
core: use nm_ip_config_iter_ip_address_for_each() in "nm-pacrunner-manager.c" 2020-11-24 08:52:59 +01:00
Thomas Haller
6f8c9d401f
dns: unify IPv4/IPv6 in get_ip_rdns_domains() 2020-11-24 08:52:59 +01:00
Thomas Haller
a1903d555b
core: add nm_utils_get_reverse_dns_domains_ip() helper 2020-11-24 08:52:59 +01:00
Thomas Haller
beda25dec0
core/trivial: rename nm_utils_get_reverse_dns_domains_ip*() functions
Let's add a nm_utils_get_reverse_dns_domains_ip() function, which can
operate on both address families. We frequently do that, but then our
address family specific functions tend to have an underscore in the name.

Rename.
2020-11-24 08:52:59 +01:00
Thomas Haller
757443d0c5
core: add nm_ip_config_iter_ip_address_for_each() macro 2020-11-24 08:52:59 +01:00
Thomas Haller
a6456fe1f4
platform: rework nm_platform_dedup_multi_iter_next_*() and add more implementations
I want to add more such accessors, because they are the base for
the corresponding for-each macros.

Add a helper macro _nm_platform_dedup_multi_iter_next() to do that,
which should make it simpler to add these nm_platform_dedup_multi_iter_next*()
functions.

Note that previously these functions were inline functions, now they are
macros. I think there is very little difference here. Also before those
functions could be entirely inlined. By using the macro the result
doesn't really change.

One difference is that we now require an "out" pointer. Previously that
was not required, but I guess it makes little sense otherwise.
2020-11-24 08:52:58 +01:00
Thomas Haller
eed23269bd
core: fix modifying connection during recheck_assume_connection()
Since commit d35d3c468a ('settings: rework tracking settings
connections and settings plugins') must settings connections not
be modified. They must be treated immutable and only updated by
replacing them with a new variant. There is even an assertion
for that.

Fix the code that attempts to modify an existing NMConnection.

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

Fixes: f2fe6c03ee ('manager: don't treat the initramfs-configured DHCP connections as generated')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/690
2020-11-24 08:49:21 +01:00
Thomas Haller
ff71bbdc42
Revert "dns: change default DNS priority of VPNs to -50"
Revert this change. One problem is that none of the current GUIs
(nm-connection-editor, gnome-control-center, plasma-nm) expose the
dns-priority option. So, users tend to have their profile value set to
0. Changing the default means for them not only a change in behavior,
but its hard to fix via the GUI.

Also, what other call DNS leaks, is Split DNS to some. Both uses make
sense, but have conflicting goals. The default cannot accommodate both
at the same time.

Also, with split DNS enabled (dnsmasq, systemd-resolved), the concern
for DNS leaks is smaller. Imagine:

  Wi-Fi profile with ipv4.dns-priority (effectively) 100, domain "example.com".
  VPN profile with ipv4.dns-priority (effectively) 50 and a default route.

That is a common setup that one gets by default (and what probably many
users have today). In such a case with split DNS enabled, the Wi-Fi's DNS
server only sees requests for "*.example.com". So, it does not leak
everything.

Hence, revert this change before 1.28.0 release to the earlier behavior.

This reverts commit af13081bec.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/688
2020-11-23 18:53:52 +01:00
Thomas Haller
937c8a4669
dns: fix accessing NULL domains.reverse array in rebuild_domain_lists()
Fixes: fbf1683c1a ('dns: more debug logging for DNS settings in rebuild_domain_lists()')
2020-11-20 22:50:31 +01:00
Thomas Haller
6802eb9af6
trivial: fix coding style 2020-11-20 19:06:28 +01:00
Thomas Haller
95017dccdd
dns: set first Domains/DefaultRoute in systemd-resolved before DNS 2020-11-20 18:28:48 +01:00
Thomas Haller
fbf1683c1a
dns: more debug logging for DNS settings in rebuild_domain_lists() 2020-11-20 18:28:48 +01:00
Thomas Haller
ee9fab0361
dns: fix handling default routing domains with systemd-resolved
We used to set "~." domains for all devices that should be used for
resolving unknown domains.

Systemd-resolved also supports setting "SetLinkDefaultRoute()".
We should only set the wildcard domain if we want that this
interface is used exclusively. Otherwise, we should only set
DefaultRoute. See ([1], [2], [3], [4]).

Otherwise the bad effect is if other components (wg-quick) want
to set exclusive DNS lookups on their link. That is achieved by
explicitly adding "~." and that is also what resolved's
`/usr/sbin/resolvconf -x` does. If NetworkManager sets "~." for
interfaces that are not important and should not be used exclusively,
then this steals the DNS requests from those external components.

In NetworkManager we know whether a link should get exclusive lookups
based on the "ipv[46].dns-priority" setting.

[1] https://www.freedesktop.org/software/systemd/man/org.freedesktop.resolve1.html
[2] https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html
[3] https://github.com/systemd/systemd/issues/17529#issuecomment-730522444
[4] https://github.com/systemd/systemd/pull/17678
2020-11-20 18:28:03 +01:00
Thomas Haller
a875d154de
dns: assert domains are unset at start of rebuild_domain_lists() 2020-11-20 16:59:56 +01:00
Thomas Haller
05f8ccc817
dns: assert that priorities in rebuild_domain_lists() are increasing
This is nm_assert(). The compiler should be able to completely eliminate
this code in production.
2020-11-20 16:59:56 +01:00
Thomas Haller
5902f1c91f
dns: cleanup handling of shadowed priorities rebuild_domain_lists()
domain_is_shadowed() only works, because we pre-sort all items. When
we call domain_is_shadowed(), then "priority" must be not smaller than
any priority already in the dictionary.

Let's add an nm_assert() for that.

While at it, I also found it ugly to rely on

  GPOINTER_TO_INT(g_hash_table_lookup(ht, domain))

returning zero to know whether the domain is tracked. While more
cumbersome, we should check whether the value is in the hash (and not).
Not whether the value does not translate to zero.

Add domain_ht_get_priority() for that.
2020-11-20 16:59:56 +01:00
Thomas Haller
d10d96a45c
dns: track NMDnsConfigData as keys of a dictionary
There is unnecessary overhead of tracking a separate
key and value in a GHashTable.

Use g_hash_table_add().
2020-11-20 16:59:56 +01:00
Thomas Haller
190eeb5e9f
dns: cleanup allocation of NMDnsConfigData and NMDnsIPConfigData 2020-11-20 16:59:56 +01:00
Beniamino Galvani
f2e51ace68 initrd: disable ipv4 and ipv6 by default for vlan parent connection
Change the generator to disable by default IP configuration for the
parent connection of a VLAN, because that is what a user would expect
and what the legacy module does. Of course if the user explicitly
configures DHCP or an address for the parent interface, that overrides
the default.

Note that now the generator always creates a connection for the parent
interface. Before this commit, it did only when there was an explicit
ip= argument for the parent interface.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/509
2020-11-20 16:35:36 +01:00
Beniamino Galvani
4aa902ecf5 initrd: fix parsing of ip= argument with dotted interface name
The command line parser looks for a dot or a colon to determine
whether the first token in a ip= argument is a IPv4 address (dot), an
IPv6 address (colon) or an interface name (none). This strategy
doesn't work for interface names containing a dot (typically VLANs).

Instead, try to parse the IPv4/IPv6 address in the token; if this
fails then consider the token as an interface name.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/581
2020-11-20 16:35:36 +01:00
Beniamino Galvani
584e9048b3 initrd: add test for prefixed address in ip= argument 2020-11-20 16:35:36 +01:00
Thomas Haller
cefefd8b6c
core: refactor nm_ethernet_address_is_valid()
The caller *always* needs to know whether the argument
is an address in binary or text from. At that point,
it's only inconvenient to require the user to either
pass "-1" or ETH_ALEN as size (nothing else was supported
anyway).

Split the function and rename.
2020-11-19 20:22:25 +01:00
Thomas Haller
42156b6010
wifi: use NMEtherAddr struct for bssid 2020-11-19 20:17:03 +01:00
Thomas Haller
07a60e859c
wifi: drop Wext handlers get_rate()/get_bssid()/get_qual() from NMWifiUtilsClass
Wext is anyway deprected. Our NMWifiUtilsClass should not have API
to accomodate it. That means, we don't need dedicated get_rate(),
get_bssid(), get_qual() hooks, when they all are only called by
get_station().

Instead, push the Wext specific code down.
2020-11-19 20:13:16 +01:00
Thomas Haller
54817e3cfd
wifi: use nm_wifi_ap_set_address_bin() in activation_success_handler() 2020-11-19 20:13:16 +01:00