Commit graph

235 commits

Author SHA1 Message Date
Thomas Haller
2fcabf5699
all: only include "libnm-glib-aux/nm-uuid.h" where needed
Don't let "nm-core-internal.h" (which is a very popular header itself)
drag in "nm-uuid.h".
2021-05-04 15:51:51 +02:00
Thomas Haller
995c78245e
glib-aux/trivial: rename NMUuid API 2021-05-04 15:51:49 +02:00
Thomas Haller
73cfc4097a
libnm,glib-aux: add and use nm_uuid_generate_random_str*() helpers 2021-05-04 15:51:45 +02:00
Thomas Haller
dd1a618745
libnm,glib-aux: move nm_utils_uuid_is_null() to "nm-uuid.h" 2021-05-04 15:51:45 +02:00
Thomas Haller
7a15144f75
glib-aux: use nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
42d67415b4
glib-aux: use nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
596bf4b91b
glib-aux: use nm_uuid_unparse() 2021-05-04 15:51:42 +02:00
Thomas Haller
05130b6e10
ifupdown: replace _str_has_prefix() by NM_STR_HAS_PREFIX() 2021-05-04 15:51:41 +02:00
Thomas Haller
21321ac736
clang-format: reformat code with clang 12
The format depends on the version of the tool. Now that Fedora 34 is
released, update to clang 12 (clang-tools-extra-12.0.0-0.3.rc1.fc34.x86_64).
2021-05-04 13:56:26 +02:00
Beniamino Galvani
23cc0bf335 manager: fix assertion failure in active_connection_find()
Active-connections in the async_op_lst are not guaranteed to have a
settings-connection. In particular, the settings-connection for an
AddAndActivate() AC is set only after the authorization succeeds. Use
the non-asserting variant of the function to fix the following
failure:

 nm_active_connection_get_settings_connection: assertion 'sett_conn' failed

 1    _g_log_abort()
 2    g_logv()
 3    g_log()
 4    _nm_g_return_if_fail_warning.constprop.14()
 5    nm_active_connection_get_settings_connection()
 6    active_connection_find()
 7    _get_activatable_connections_filter()
 8    nm_settings_get_connections_clone()
 9    nm_manager_get_activatable_connections()
 10   auto_activate_device_cb()
 11   g_idle_dispatch()
 12   g_main_context_dispatch()
 13   g_main_context_iterate.isra.21()
 14   g_main_loop_run()
 15   main()

Fixes: 33b9fa3a3c ('manager: Keep volatile/external connections while referenced by async_op_lst')

https://bugzilla.redhat.com/show_bug.cgi?id=1933719
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/834
2021-05-04 08:48:29 +02:00
Thomas Haller
ad2226eacd
core/firewalld: use changeZoneOfInterface() instead of deprecated changeZone()
`man firewalld.dbus` comments that changeZone() is deprecated.
Apparently this is the case since 0.3.3-1 (2013).

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/836
2021-05-04 08:26:42 +02:00
Beniamino Galvani
fa1f628bce core: force emission of DNS_CONFIG_CHANGED signal on SIGUSR1
If the configuration contains dns=none and resolv.conf is updated
through a dispatcher script, currently there is no way to tell NM that
the content of resolv.conf changed, so that it can restart a hostname
resolution.

Use SIGUSR1 (and SIGHUP) for that.
2021-05-03 22:13:36 +02:00
Jonas Dreßler
b876e76518 supplicant/config: Make sure PMF gets enabled with wpa-eap-suite-b-192
wpa-eap-suite-b-192 key-mgmt method uses special values for "pairwise"
and "group" ciphers, we can also handle that a few lines underneath
where those are set to make this a bit easier to read.

We currently set the supplicants PMF config (ieee80211w) inside an if
block that tries to detect whether WPA is used. That if-block doesn't
include the "wpa-eap-suite-b-192" case because we want special
"pairwise" and "group" handling for wpa-eap-suite-b-192. This means
we're currently missing to enable PMF in the "wpa-eap-suite-b-192" case,
even though it's set to REQUIRED.

Fix it by moving the "pairwise" and "group" special-casing down a bit so
we can include "wpa-eap-suite-b-192" in the "Only WPA-specific things
when using WPA" check, that will make sure ieee80211w gets set in the
wpa-eap-suite-b-192 case.
2021-04-30 07:38:20 +00:00
Jonas Dreßler
29c7debf40 supplicant/config: Remove superfluous check to disable PMF
We only set the "ieee80211w" option in the wpa_supplicant config in case
we're using WPA (see the if-block underneath), otherwise the value of
"pmf" is completely ignored. That means the override here (in case WPA
isn't used) isn't getting applied anyway, so just remove it.
2021-04-30 07:38:20 +00:00
Jonas Dreßler
dcd032055c supplicant/config: Add a comment mentioning global pmf config value
It looks a bit weird on the first glance that we do nothing when
NM_SETTING_WIRELESS_SECURITY_PMF_OPTIONAL is used. The reason for this
is that we already intialize the global option "pmf" of wpa_supplicant
to "1" (optional), so add a brief comment about that here.
2021-04-30 07:38:20 +00:00
Thomas Haller
e7b76f6757
dns/resolved: add API for ResolveAddress call
ResolveAddress is a simple D-Bus API. One might think that it does not
require much logic, and we would just make the D-Bus call directly.

However, we want to ensure that we always sent our latest DNS
configuration to systemd-resolved first, before making any D-Bus request
to resolve a name.

Also, as we D-Bus activate the service and watch the name owner, we
want to handle that. If a user resolves a name while we are still D-Bus
activating, then we need to queue the request.

This adds some complexity in the implementation. But the benefit is that
the API becomes simple from the user's point of view. The queuing and
avoiding race conditions is handled internally.

The implementation does not use standard glib patterns with GAsyncResult
GTask and GCancellable. I find implementing them correctly is more
effort and leads to a less nice API. That might be fine for public API,
which should follow glib style. But this is entirely internal, and
returning a NMDnsSystemdResolvedResolveHandle that allows cancellation
seems more convenient to me.
2021-04-28 13:20:03 +02:00
Thomas Haller
5cc6932d5a
dns/resolved: use unique D-Bus name for systemd-resolved request
As we already track the current name owner, it seems wrong to make
requests to the well-known name. It theoretically opens a race
where we would talk to the wrong systemd-resolved instance.

So far, we didn't care and it didn't make much of a difference.
Still, let's talk to the process that we expect.
2021-04-28 13:20:03 +02:00
Thomas Haller
e7d78e90a3
dns/resolved: track D-Bus owner of resolved D-Bus service 2021-04-28 13:20:03 +02:00
Thomas Haller
4285eed8eb
dns/resolved: add watchdog D-Bus activating systemd-resolved
Currently, it doesn't actually do anything (beside logging).
Will be used next.
2021-04-28 13:20:02 +02:00
Thomas Haller
8ee5ec00f9
dns/trivial: rename NMDnsSystemdResolvedPrivate.request_queue_to_send to "send_updates_waiting"
The previous name seems confusing to me.
2021-04-28 13:20:02 +02:00
Thomas Haller
92f742f66b
dns/resolved: add ensure_resolved_running() helper method
Factor out the code. We will use it next.
2021-04-28 13:20:02 +02:00
Thomas Haller
2ae5e7aa26
dhcp: set request_broadcast for devices that set udev ID_NET_DHCP_BROADCAST
For infiniband, request_broadcast is automatically (and always) enabled.
Otherwise, we usually don't enable it, and (unlike systemd-networkd),
there is currently no configuration option to enable it.

Still honor the new udev property that can indicate to enable the flag
per device.

See-also: https://github.com/systemd/systemd/pull/ ### 19346
2021-04-28 13:10:15 +02:00
Thomas Haller
4acbb0fdc9
dhcp: add client_flags argument to nm_dhcp_manager_start_ip[46]() 2021-04-28 13:10:14 +02:00
Thomas Haller
b6b38af8aa
dhcp: simplifiy tracking of client flags in client_start() 2021-04-28 13:10:14 +02:00
Thomas Haller
a5cfa6e4f4
dhcp: refactor NMDhcpClient to use client flags
The DHCP client has potentially a large number of options,
including boolean options (flags). It is cumbersome to implement
them one by one. Instead, make more prominent use of NMDhcpClientFlags.
2021-04-28 13:10:13 +02:00
Thomas Haller
48a3cebce5
core: use _nm_utils_ascii_str_to_bool() to parse boolean udev properties
Previously, we used nm_udev_utils_property_as_boolean(), which was
taken from g_udev_device_get_property_as_boolean(). That function
accepts "1" and "true" (with ASCII case insensitive).

When we parse a flag, there is no need to reject "no", "yes" or
"on"/"off" as invalid (and thus return FALSE). We have a boolean
parse method _nm_utils_ascii_str_to_bool(), which parses everything
that nm_udev_utils_property_as_boolean() accepts, and more.

Be liberal in what we accept, so use our general parse function.
2021-04-28 13:10:13 +02:00
Jonas Dreßler
77ef56714d
iwd: Don't add comments about PSK passphrase to config files
g_key_file_set_comment() has slightly weird API that will fail to set a
comment if it doesn't find the group. This is the case here since we
haven't set any strings under the [Security] group yet.

Fixing this is kind of ugly, so for now just don't add that comment in
the case where we don't have the [Security] group.
2021-04-27 19:52:48 +02:00
Jonas Dreßler
971dcc0777
iwd: Actually update iwd config in mirror_connection() if needed
There are cases where the settings didn't actually change and we just
want to ensure NM and iwd settings are in sync (one such case would be
when a setting was changed while iwd wasn't running, here we want to
synchronize all settings when starting up iwd).

We're already doing this and calling sett_conn_changed() from
mirror_connection() on all connections after adding an interface, the
actual settings synchronization code doesn't get executed though because
we're passing 0 as update_reason, which means we bail out early from
sett_conn_changed().

To make sure we actually update the iwd network configurations in that
case, too, pass UPDATE_REASON_UPDATE_NON_SECRET as the update reason to
sett_conn_changed(), which is the correct update reason in this case.
2021-04-27 19:52:48 +02:00
Jonas Dreßler
c8608d7cc3
iwd: Correctly compare autoconnected states
Quite obviously, we want to update the AutoConnect setting of the iwd
network in case the NM and iwd settings differ, not if they are the
same. So check for unequality here instead of equality, which fixes the
AutoConnect setting's synchronization.

Fixes: 4229c97012 ('iwd: Mirror NM connections to IWD network config files'):
2021-04-27 19:52:43 +02:00
Thomas Haller
43a0c6c111
core: fix assertion failure in device's activate_stage2_device_config()
Fixes: d946aa0c50 ('wired-setting: add support to accept-all-mac-addresses')
2021-04-26 21:17:18 +02:00
Andrew Zaborowski
16457cb303
settings: Drop NMSettingsConnection's system secrets cache
Apparently moving secrets between priv->connection and
priv->system_secrets in the various places throughout
NMSettingsConnection is no longer needed and has no effect on the
state of the D-Bus object or the gobject visible from outside.  It
seems that it was needed for the secrets handling in NMDevice
subclasses before the introduction of the applied connection concept
but now nm_connection_need_secrets() is called in those subclasses
directly on the applied connection object and the secrets obtained
from multiple nm_settings_connection_get_secrets calls are also
collected directly in the applied connection's settings.

Drop the system secrets cache mechanism as a cause of a minor memory
overhead, some code overhead and also a source of some unneeded gobject
signals as the connection settings were being updated.

Note: the NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS and
NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS flags in the
SettingsConnection update signals appear to only have been used by the
SettingsConnection internally to keep priv->system_secrets up to date.
They can have potential other uses in the handlers of those signals so I
kept them.  Unlike some of the other NMSettingsConnectionUpdateReason
values these are actual update *reasons* and not flags telling the
settings backends how to handle a specific change in the settings.
2021-04-23 15:00:51 +02:00
Andrew Zaborowski
d1566d7b4b
settings: Drop nm_settings_connection_clear_secrets
All usages of nm_settings_connection_clear_secrets() outside of the
NMSettingsConnection implementation were setting the
clear_cached_system_secrets parameter to FALSE which meant that the
operation was a no-op since the system-secrets cache kept a copy of the
secrets being cleared and any access to the SettingsConnection through
the D-Bus API or the class methods would behave the same as without the
call, with the exception of directly reading the settings from the
result of nm_settings_connection_get_connection().  The calls would
still generate D-Bus and gobject signals however, which were redundant.

Drop the method and its calls from the rest of NM code as not needed and
potentially confusing.  The comments preceding these calls implied that
they were needed so that the next activation attempt would be forced to
use nm_settings_connection_get_secrets() but this was the case probably
only before the applied connection concept was introduced.

Also drop two nm_active_connection_clear_secrets() uses in
NMVpnConnection, right before the teardown of the active connection,
that could only possibly have any effect if they affected the
NMSettingsConnection, but as mentioned earlier the
nm_settings_connection_clear_secrets() use inside
nm_active_connection_clear_secrets() didn't do anything and is now
removed.

The one internal use of nm_active_connection_clear_secrets() in the
D-Bus ClearSecrets() implementation is inlined.
2021-04-23 15:00:51 +02:00
Fernando Fernandez Mancera
d946aa0c50 wired-setting: add support to accept-all-mac-addresses
This patch is introducing the wired setting accept-all-mac-addresses
property. The value corresponds to the kernel flag IFF_PROMISC.

When accept-all-mac-address is enabled, the interface will accept all
the packets without checking the destination mac address.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-04-22 18:57:30 +00:00
Fernando Fernandez Mancera
1dfe536386 platform: introduce nm_platform_link_change_flags()
Having two functions like link_set_x() and link_set_nox() it is not a
good idea. This patch is introducing nm_platform_link_change_flags().

This allow flag modification directly, so the developer does not need to
define the virtual functions all the time everywhere.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-04-22 18:57:30 +00:00
Fernando Fernandez Mancera
27e37a4b17 interface-flags: expose NM_DEVICE_INTERFACE_FLAG_PROMISC
This patch is introducing NM_DEVICE_INTERFACE_FLAG_PROMISC in
interface_flags. The flag represents IFF_PROMISC kernel flag.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-04-22 18:57:30 +00:00
Aaron Barany
8acad5a20c vpn: allow IP prefix of 0 for routing rules
Allow IP prefixes of 0 for routing rules, which are used for specifying a
route for all traffic. (e.g. route all traffic by default with separate
rules to exclude specific IP ranges)

#711
2021-04-22 11:56:57 +00:00
Beniamino Galvani
d19773ecd4 manager: ensure auto default connection is deleted when a veth goes away
When the link goes away the manager keeps software devices alive as
unrealized because there is still a connection for them.

If the device is software and has a NM-generated connection, keeping
the device alive means that also the generated connection stays
alive. The result is that both stick around forever even if there is
no longer a kernel link.

Add a check to avoid this situation.

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

Fixes: cd0cf9229d ('veth: add support to configure veth interfaces')
2021-04-21 14:57:07 +02:00
Beniamino Galvani
a42682d44f device: take reference to device object before 'delete_on_deactivate'
It's not clear why currently a weak reference is needed.
2021-04-21 14:57:07 +02:00
Thomas Haller
4cbf30c5ec
platform/tests: fix wrong nm_platform_lnk_bridge_cmp() in test_software_detect()
We need to handle the case that kernel mangles the configured values. We
already do, but there was a left over nm_platform_lnk_bridge_cmp() that
is still wrong.

Related: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/665

Fixes: ce9211500e ('platform/tests: work around rounding errors for bridge values in unit tests')
2021-04-21 07:45:49 +02:00
Thomas Haller
5a6dbcefa3
core/trival: style cleanup 2021-04-20 17:25:21 +02:00
Thomas Haller
f7dec0ab1d
core: implement nm_dhcp_client_get_addr_family()
This was already forward declared in the header, but not defined.

Implement it. Will be used later.
2021-04-20 17:25:21 +02:00
Thomas Haller
5e77c67e0f
core: cleanup #include of "nm-dnsmasq-utils.c" 2021-04-20 17:25:21 +02:00
Thomas Haller
d1457410fd
core: return boolean result from nm_dbus_object_clear_and_unexport()
To indicate, whether something was cleared. This will be used later.
2021-04-20 17:25:21 +02:00
Thomas Haller
80f6f4e115
core: use NM_CAST_PPTR() for nm_dbus_object_clear_and_unexport()
This ensures that the argument is some pointer to pointer. This gives a
bit of additional compile time safety, but in general, it still casts
any pointer to pointer (because that's what we require, as most arguments
won't be of type NMDBusObject to begin with).
2021-04-20 17:25:21 +02:00
Andrew Zaborowski
26de0e02d9
iwd: Fix permissions and timestamps when writing IWD config files
NM should have been creating the IWD network config files with 0600
permission bits from the beginning since they can contain secrets.
g_key_file_save_to_file() uses 0666 which shouldn't be used even for the
temporary file before setting the final permissions.

Also try to preserve the last modification timestamp of the original
file because it is currently used by IWD when ranking networks for
autoconnect and updating it everytime NM rewrites the file could
potentially affect autoconnect priorities.
2021-04-19 18:11:12 +02:00
Andrew Zaborowski
38ac64ba62
glib-aux: Set file timestamps in nm_utils_file_set_contents
Extend nm_utils_file_set_contents to be able to optionally set the last
access + last modification times on the file being created, in addition
to the mode.
2021-04-19 18:11:11 +02:00
Andrew Zaborowski
caa1b5c60d
iwd: Clean up old vs. new secret logic
There was an attempt in the code to allow using existing system-owned
secrets based on whether the connection had ever succeeded before but
this wasn't implemented properly.  Now decide whether existing secrets
are allowed and whether to pass the REQUEST_NEW flag to the secrets
request based on the last connection timestamp and on the network
security type (PSK vs. 802.1X) to align the policy with the policy
inside IWD.

Drop a useless nm_connection_clear_secrets call on the applied
connection just before failing the connection attempt and thus
destroying the applied connection.
2021-04-19 18:11:11 +02:00
Andrew Zaborowski
260ceff28a
iwd: Add warning comment to autogenerated IWD files 2021-04-19 18:11:11 +02:00
Andrew Zaborowski
60dcb83b58
iwd: Only save system-owned secrets to IWD config
Avoid saving agent-owned secrets when converting settings connections
to IWD config files and avoid reacting to NMSettingsConnection updates
that don't seem to touch any non-secret or system-owned-secret settings.
2021-04-19 18:11:10 +02:00
Andrew Zaborowski
ee583adecf
settings: add NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET flag
Along with NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS
and NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS, which can
be used in the NMSettingConnection's "updated" handlers to track secrets
updates, add NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET so
that the handlers can tell when something other than secrets has been
updated in the connection.

It can also potentially be used in _connection_changed_update in
src/core/settings/nm-settings.c to stop emitting the
NetworkManager.Settings.Connection.Updated() dbus signal if only secrets
are being updated (on agent queries etc.) if it is deemed to be correct.
2021-04-19 18:11:10 +02:00