Commit graph

362 commits

Author SHA1 Message Date
Thomas Haller
877d2b236f
core: avoid checking sort order for cached settings list
We now have a cached list of NMSettingsConnection instances,
sorted by their autoconnect priority.

However, the sort order nm_settings_connection_cmp_autoconnect_priority()
depends on various properties of the connection:

 - "connection.autoconnect" and "connection.autoconnect-priority"
 - the timestamp
 - "connection.uuid"

These properties almost never change, so it's a waste that every call
to nm_settings_get_connections_sorted_by_autoconnect_priority() needs
to check whether the sort order is still satisfied.

We can do better by tracking when the sort order might have been
destroyed and only check in those (much fewer) cases.

Note that we end up calling nm_settings_get_connections_sorted_by_autoconnect_priority()
a lot, so this makes a difference.
2021-06-18 11:20:30 +02:00
Thomas Haller
252e4a676b
core: cache GVariant for result of GetSettings()
The GetSettings() call is not the only place where we convert a
NMConnection to D-Bus. However it is one of the most prominent ones
with a measurable performance overhead.

The connection seldom changes, so it makes sense to cache it.

Note that GetSettings() is the only caller that specifies an option,
thus it's the only caller that converts a NMConnection to variant
in this particular way. That means, other callers don't benefit from
this caching and we could not cache the variant in the NMConnection
instance itself, because those callers use different parameters.
2021-06-17 17:49:44 +02:00
Thomas Haller
e7b5650eff
core: add nm_settings_get_connection_sorted_by_autoconnect_priority()
Turns out, we call nm_settings_get_connection_clone() *a lot* with sort order
nm_settings_connection_cmp_autoconnect_priority_p_with_data().

As we cache the (differently sorted) list of connections, also cache
the presorted list. The only complication is that every time we still
need to check whether the list is still sorted, because it would be
more complicated to invalidate the list when an entry changes which
affects the sort order. Still, such a check is usually successful
and requires "only" N-1 comparisons.
2021-06-17 17:48:13 +02:00
Thomas Haller
1f09e13f43
core: add nm_settings_connection_cmp_autoconnect_priority_with_data() helper 2021-06-17 17:48:13 +02:00
Thomas Haller
85df025e93
core: avoid undefined behavior comparing plain pointer values in _cmp_last_resort() 2021-06-17 17:48:11 +02:00
Beniamino Galvani
0cd20f94d0 firewall: fix double free
Fixes: 9ebdb967de ('firewall: implement masquerading for shared mode with nftables')
2021-06-15 19:40:59 +02:00
Thomas Haller
654bb92a69
firewall: use nm_g_main_context_push_thread_default_if_necessary() in _fw_nft_call_communicate_cb()
There is no need to push (and pop) the same main-context.
2021-06-15 18:25:22 +02:00
Thomas Haller
897c6a5744
firewall: fix signalling timeout error reason from _fw_nft_call()
During timeout we cancel the (internal) GCancellable. But the overall
error reason is not cancellation by the user, it's timeout. Fix
the error reason.

Fixes: 9ebdb967de ('firewall: implement masquerading for shared mode with nftables')
2021-06-15 18:15:56 +02:00
Thomas Haller
b8ae2dfa70
core/trivial: add comment about GMainContext to nm_shutdown_wait_obj_register_full() 2021-06-15 18:15:56 +02:00
Thomas Haller
79d9441567
firewall: change default for firewall-backend to "nftables""
It seems that the nftables backend works well. Let's change the default.
This will also be backported to nm-1-32 branch, for 1.32.0 release.

This reverts commit 0609f1f31c.
2021-06-14 11:17:25 +02:00
Thomas Haller
0d6c35a6d9
core: avoid accessing opaque NMSetting type
Next, NMSetting will be hidden from public headers and become an opaque type.
We cannot do typeof(*setting) anymore.
2021-06-11 22:32:12 +02:00
Beniamino Galvani
c89ac8f0c7 device: remove unused variable
Fixes: 620fbb7894 ('device: use nm_device_resolve_address()')
2021-06-11 21:58:02 +02:00
Beniamino Galvani
620fbb7894 device: use nm_device_resolve_address() 2021-06-11 21:43:12 +02:00
Beniamino Galvani
27eae4043b device: add a nm_device_resolve_address()
The new function resolve an address via DNS, first by using
systemd-resolved (disabling synthesized results) and then by spawning
the daemon helper.

Trying systemd-resolved via D-Bus before spawning the helper is
important to get a correct result. Suppose that resolv.conf points to
the local stub listener at 127.0.0.53; if NM only spawns the helper,
the helper will query the local systemd-resolved which could return a
synthesized result.

Therefore, we first query systemd-resolved with NO_SYNTHESIZE and
then, in case of error, we spawn the helper.
2021-06-11 21:43:12 +02:00
Beniamino Galvani
7285bc56a9 dns: add function to retrieve the systemd-resolved plugin instance
Now that we have nm_dns_systemd_resolved_resolve_address(), we also
need a way to obtain a reference to the plugin.
2021-06-11 21:43:12 +02:00
Beniamino Galvani
6ac21ba916 core: add infrastructure for spawning a helper process 2021-06-11 21:43:12 +02:00
Beniamino Galvani
326dde6d53 core,nm-dispatcher: use nm_utils_get_process_exit_status_desc() 2021-06-11 21:43:11 +02:00
Beniamino Galvani
9e69d921c1 dns/resolved: fix memory leak
'v_name' must be freed. Pass ownership to the result element.

Fixes: e7b76f6757 ('dns/resolved: add API for ResolveAddress call')
2021-06-11 21:43:11 +02:00
Andrew Zaborowski
35a1d89a96
iwd: Don't add connection.interface-name by default
This setting can't be handled IWD (e.g. during autoactivations performed
by IWD) and although for manual activations NM will probably check it,
there's no reason for the IWD backend to restrict new profiles to one
interface plus when running IWD the udev permanent interface naming is
likely to be broken.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/886
2021-06-10 23:30:11 +02:00
Thomas Haller
01df4a5ad0
supplicant: fix leaking handle in nm_supplicant_manager_create_interface()
Found by valgrind.

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2021-06-10 10:36:58 +02:00
Thomas Haller
6813a4fe75
bluez: fix leak of private data "conn_data_elems" in NMBluezManager
Found by valgrind.

Fixes: 4154d9618c ('bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data')
2021-06-10 10:36:58 +02:00
Thomas Haller
07002f7320
core: remove _nul_sentinel from UuidData struct
The user really must not treat UuidData.bin as a NUL terminated string.
The _nul_sentinel is not necessary. And if by chance the user makes this
fatal mistake, then UuidData.str will still be there to NUL terminate the
buffer, the content is garbage either way.

Remove the sentinel.
2021-06-08 08:24:14 +02:00
Thomas Haller
2b2c818e03
glib-aux/uuid: use NMUuid typed argument for nm_uuid_generate_from_string*()
nm_uuid_generate_from_string*() accepts an optional namespace parameter,
to seed the hashing. This previously was a UUID in string format, so it
first had to be parsed.

Rework the code to pass a NMUuid instance that can be used directly.
Also, as the type_args parameter is always of the same type, change
the argument from a void pointer to "const NMUuid *" pointer.
2021-06-08 08:24:14 +02:00
Thomas Haller
8d01bf5d80
wifi/iwd: rework warning about invalid state-dir
- always remember priv->last_state_dir that we received via
  D-Bus. Only later, during get_config_path() we will check
  whether the path is valid.

- remember in priv->warned_state_dir the full path for
  which we warned. We want to print a warning for each
  path once, if the path changes, then we also want a new
  warning. A boolean flag cannot express that.
2021-06-04 13:36:38 +02:00
Andrew Zaborowski
cd7213e27c
iwd: Enforce absolute state dir path, print warnings
Validate the state directory path, that we read from the configuration
or from IWD, to be an absolute path.  Print a warning if the value
cannot be used and is not an empty string.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/873
2021-06-04 13:09:54 +02:00
Thomas Haller
96ef5dede9
core: belatedly add [main].firewall-backend config to known options
Otherwise we see a warning:

   <warn>  [1622790097.3601] config: unknown key firewall-backend in section [main] of file /etc/NetworkManager/NetworkManager.conf

Fixes: 1da1ad9c99 ('firewall: make firewall-backend configurable via "NetworkManager.conf"')
2021-06-04 10:27:20 +02:00
Thomas Haller
6f2ae46b37
all: use nm_uuid_is_normalized() for checking valid UUID for "connection.uuid"
"connection.uuid" gets normalized. When we check for a valid UUID, we expect
it to be normalized.
2021-06-04 09:29:23 +02:00
Thomas Haller
423e83b880
keyfile: reject non-normalized UUIDs in nms_keyfile_nmmeta_check_filename()
Since commit 207cf3d5d4 ('libnm: normalize "connection.uuid"') the
"connection.uuid" is normalized to be a valid UUID and all lower case.

That means, if we have .nmmeta files on disk with a previously valid,
but now invalid UUID, the meta file is no longer going to match.

Reject such file outright as invalid. If we really wanted to preserve
backward compatibility, then we would have to also normalize the
filename when we read it. However, that means, that suddenly we might
have any number of compatible .nmmeta files that normalize to the same
UUID, like the files

  71088c75dec54119ab41be71bc10e736aaaabbbb.nmmeta
  F95D40B4-578A-5E68-8597-39392249442B.nmmeta
  f95d40b4-578a-5e68-8597-39392249442b.nmmeta

Having multiple places for the nmmeta file is complicated to handle.

Also, we often have the connection profile (and the normalized UUID)
first, and then check whether it has a .nmmeta file. If we would support
those unnormalized file names, we would have to visit all file names and
try to normalize it, to find those with a matching UUID.

Non-normalized UUIDs really should not be used and they already are not
working anymore for the .nmmeta file. This commit only outright rejects
them. This is a change in behavior, but the behavior change happened
earlier when we started normalizing "connection.uuid".
2021-06-04 09:29:22 +02:00
Thomas Haller
7e8e6836e0
keyfile: fix comparison in nms_keyfile_nmmeta_read()
"uuid" is returned from nms_keyfile_nmmeta_check_filename(),
and contains "$UUID.nmmeta". We must compare only the first
"uuid_len" bytes.

Fixes: 064544cc07 ('settings: support storing "shadowed-storage" to .nmmeta files')
2021-06-04 09:29:22 +02:00
Thomas Haller
25f4d23e13
glib-aux: change nm_uuid_is_valid_full() to nm_uuid_is_normalized_full()
Most of the time, we care about whether we have a normalized UUID.

nm_uuid_is_valid_full() only exists for a particular case where we want
to use the function in a header, without including "nm-uuid.h". In that
case, we actually also care about normalized UUIDs.
2021-06-04 09:29:22 +02:00
Beniamino Galvani
6a88d4e55c 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.
2021-06-03 09:02:07 +02:00
Beniamino Galvani
a48edd0410 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
2021-06-03 09:01:57 +02:00
Thomas Haller
8327312c51
wifi: fix parsing Microsoft Network Cost IE
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/734

Fixes: 5307b1ed73 ('wifi: guess metered flag based on Network Cost information element')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/879
2021-06-02 08:44:52 +02:00
Thomas Haller
bc05f4b750
core: avoid lgtm warning in _sleep_duration_convert_ms_to_us()
return x < G_MAXULONG ? (gulong) x : G_MAXULONG;
  ^^^ Comparison is always true because x <= 4294967295000.
2021-06-01 17:39:28 +02:00
Thomas Haller
aa76c260a7
systemd: merge branch systemd into main
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/876
2021-06-01 14:26:51 +02:00
Andrew Zaborowski
6aa8062f33 iwd: If no EAP anonymous identity set fall back to identity
Mimic the behaviour of wpa_supplicant where the "secure" identity in
TTLS and PEAP (802-1x.identity) is used as a fallback in the anonymous
identity (802-1x.anonymous_identity) if that is not provided.  This is
needed to keep the profiles compatible between the two wifi backends,
for users of poorly configured WPA-Enterprise networks that require the
user login to be sent in phase 1 or in both phases.

The code responsible for this mechanism in wpa_supplicant, at the time
of writing, is
https://w1.fi/cgit/hostap/tree/src/eap_peer/eap.c?id=c733664be9dd3763c03f2da2cb32a23775dde388#n1688
and offers no comment about the privacy implications.
2021-06-01 09:02:42 +00:00
Thomas Haller
6439c243e7
systemd: move "src/core/systemd" to "src/libnm-systemd-core"
This follows the recently introduced naming scheme and directory layout.
"libnm-systemd-core" is an independent component, and as such should no
be inside "src/core/".

Move it.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/875
2021-05-30 09:45:05 +02:00
Thomas Haller
54ada3c993
all: move "src/core/systemd/" directory to "src/libnm-systemd-core/"
Like commit 69f2699fe059 ('systemd: move "src/core/systemd" to
"src/libnm-systemd-core"').
2021-05-28 12:04:38 +02:00
Thomas Haller
8258ce6cf6
l3cfg: minor adjustments for L3Cfg code 2021-05-27 10:06:44 +02:00
Thomas Haller
1ce02ffd50
l3cfg: emit signal when NML3ConfigData changes 2021-05-27 10:06:43 +02:00
Thomas Haller
8e4b3d7367
l3cfg: use NMRefString for strings in NML3ConfigData
The entire point of NML3ConfigData is to be immutable and merging them.
"Merging" means to combine existing settings, hence NMRefString can be
used to share the same string instance.
2021-05-27 09:56:45 +02:00
Thomas Haller
11be05e6cc
l3cfg: add proxy properties to NML3ConfigData 2021-05-27 09:56:44 +02:00
Thomas Haller
cdd3745161
l3cfg: fix assertion in nm_l3_config_data_get_domains()
Sealed instances are allowed for calling the getter.
2021-05-27 09:56:43 +02:00
Thomas Haller
acfc977974
l3cfg: fix crash in nm_l3_config_data_log() by mixing up arguments 2021-05-27 09:56:43 +02:00
Thomas Haller
2d0ac5f5fe
dhcp/nettools: fix crash with empty DHCP option 40 (NIS domain name)
nm_utils_buf_utf8safe_escape() returns NULL for an empty string.

Fixes: 6c8a9e8bd6 ('dhcp/nettools: validate nis-domain option (40) differently')
2021-05-27 09:56:42 +02:00
Thomas Haller
bf9fab47ad
dhcp/systemd: handle private options 249,252 specially
nettools plugin represents the way how to do it, and other plugins
should mimic that behavior. The nettools implementation adds private
DHCP options as hex, except the options

  - 249 (Microsoft Classless Static Route)
  - 252 (Web Proxy Auto Discovery Protocol)

Adjust systemd plugin to do the same.

For 252, we now parse the "wpad" option differently. The change in
behavior is that the property is now no longer exposed as hexstring,
but as backslash escaped plain text.

For 249, the option is not implemented. But stop adding the option as
hex-string too.
2021-05-27 09:56:42 +02:00
Thomas Haller
5bbe8d2154
core/dhcp: add nm_dhcp_state_to_string() helper 2021-05-27 09:56:42 +02:00
Thomas Haller
5ce91adeff
libnm/trivial: rename _nm_keyfile_equals() to _nm_keyfile_equal() 2021-05-27 09:56:41 +02:00
Thomas Haller
1c00330a7f
glib-aux/trivial: rename nm_ref_string_equals_str() to nm_ref_string_equal_str() 2021-05-27 09:56:40 +02:00
Thomas Haller
96d9baacdb
glib-aux/trivial: rename nm_{pint,puint32}_equals() to nm_\1_equal()
Our "_equal()" methods are commonly spelled without 's'.
2021-05-27 09:56:40 +02:00