Commit graph

400 commits

Author SHA1 Message Date
Thomas Haller
0c4a65929c
glib-aux: use nm_utils_gettid() instead of gettid()
I missed that we already have a gettid() wrapper. Drop the duplicated
again and use nm_utils_gettid().

Fixes: e874c5bf6b ('random: Provide missing gettid() declaration')
2021-07-08 08:31:47 +02:00
Thomas Haller
c6be3404f8
platform/tests: add assertions to nmtstp_link_bridge_normalize_jiffies_time()
This is supposed to workaround a coverity warning.
2021-07-06 09:04:37 +02:00
Björn Lindqvist
44481bd7c7
core: fail IPv6 early if disabled in kernel
Adds the following info message in case ipv6 is disabled:

    <info>  device (enp0s18f2u3): The kernel does not support IPv6.

[thaller@redhat.com: modified original patch]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/401
2021-07-05 16:27:48 +02:00
Beniamino Galvani
35cccc41cb device: use the 'required-timeout' property from IP setting
Change the logic in check_ip_state() to delay the connection ACTIVATED
state if an address family is pending and its required-timeout has not
expired.
2021-07-05 15:15:45 +02:00
Beniamino Galvani
cb5960cef7 all: add a new ipv{4,6}.required-timeout property
Add a new property to specify the minimum time interval in
milliseconds for which dynamic IP configuration should be tried before
the connection succeeds.

This property is useful for example if both IPv4 and IPv6 are enabled
and are allowed to fail. Normally the connection succeeds as soon as
one of the two address families completes; by setting a required
timeout for e.g. IPv4, one can ensure that even if IP6 succeeds
earlier than IPv4, NetworkManager waits some time for IPv4 before the
connection becomes active.
2021-07-05 15:15:44 +02:00
Thomas Haller
09fb7877a9
build: fix linking libnm-log-null into different test programs
We require these, otherwise we can get a linker error about
_nm_utils_monotonic_timestamp_initialized symbol being undefined.
2021-07-05 14:51:27 +02:00
acabral
e5dca403dc bond: support the peer_notif_delay bond option
Merge Request NetworkManager/NetworkManager!913
2021-07-01 15:20:22 -03:00
Thomas Haller
34c663ca1a
settings: cleanup left over temporary files for timestamps/seen-bssids 2021-07-01 11:21:00 +02:00
Thomas Haller
2e720a1dc8
settings: prune old entries from keyfile databases
We have two GKeyfile files (timestamps and seen-bssids).

When a profile was deleted while NetworkManager was running, then
entries were removed from these keyfiles. But if a profile disappeared
while NetworkManger was stopped, then those UUIDs piled up.
This also happens if you have temporary connections in /run and reboot.

We need a way to garbage collect entries that are no longer relevant.

As the keyfile databases only get loaded once from disk, we will prune
all UUIDs for which we have no more connection loaded, on the first time
we write out the files again.

Note what this means: if you "temporarily" remove a connection profile
(without NetworkManager noticing) and restore it later, then the additional
information might have been pruned. There is no way how NetworkManager
could know that this UUID is coming back. The alternative is what we did
before: pile them up indefinitely. That seems more problematic.
2021-07-01 11:20:34 +02:00
Thomas Haller
8278719840
settings: limit number of seen-bssids and preserve order
Previously, there was no limit how many seen-bssids are tracked.
That seems problematic, also because there is no API how to get
rid of an excessive list of entries.

We should limit the number of entries. Add an (arbitrary) limit
of 30.

But this means that we drop the surplus of entries, and for that it
seems important to keep the newest, most recently seen entries.
Previously, entries were merely sorted ASCIIbetically. Now, honor
their order (with most recently seen first).

Also, normalize the BSSIDs. From internal code, we should only get
normalize strings, but when we load them from disk, they might be bogus.
As we might cut of the list, we don't want that invalid entries
cut of valid ones. And of course, invalid entries make no sense at
all.
2021-07-01 11:17:06 +02:00
Thomas Haller
15a0271781
settings: don't populate seen-bssids list from connection profile
ifcfg-rh plugin never stored the seen bssid list to file, and
keyfile no longer does, and it's no longer parsed from GVariant.

So there is actually no way how anything could be set here.

The seen-bssids should only be populate from
"/var/lib/NetworkManager/seen-bssids". Nowhere else.
2021-07-01 11:04:22 +02:00
Thomas Haller
6c5070da55
core: set _nm_utils_is_manager_process as first thing in daemon 2021-07-01 11:04:22 +02:00
Thomas Haller
37b72e8984
hostname: cleanup file monitors in NMHostnameManager 2021-06-30 08:00:35 +02:00
Thomas Haller
05aa751957
core,glib-aux: move nm_hostname_manager_validate_hostname() to shared-utils
This function is badly named, because it has no NMHostnameManager self
argument. It's just a simple function that entirely operates on a string
argument.

Move it away from "nm-hostname-manager.h" to "libnm-glib-aux/nm-shared-utils.h".

Hostname handling is complicated enough. Simple string validation
functions should not obscure the view on the complicated parts.
2021-06-28 14:32:05 +02:00
Thomas Haller
dbe4803d84
hostname: use nm_utils_user_data_pack() instead of SetHostnameInfo struct 2021-06-28 14:32:05 +02:00
Thomas Haller
429816080e
hostname: simplify _set_hostname() code
- drop nm_hostname_manager_read_hostname() from header file.
  It's only used internally.

- inline some code and drop helper functions.
2021-06-28 14:32:05 +02:00
Thomas Haller
61d2af3518
all: use nm_{idle,timeout}_add_source() instead of g_source_attach() 2021-06-28 13:31:35 +02:00
Thomas Haller
70e5d8e5bd
all: don't explicitly include <glib-unix.h>
We get it now always by "nm-macros-internal.h".
2021-06-28 13:31:34 +02:00
Thomas Haller
b9c10512cb
device: track refresh_rate timer as GSource instead of source id
Using the guint source ID always requires an additional hash lookup
during removal to find the real source instance. Use instead the
underlying GSource instance.
2021-06-28 13:31:33 +02:00
Thomas Haller
26ed9e6714
ifcfg-rh: fix persisting all-default NMSettingEthtool settings
We somehow need to encode an NMSettingEthtool instance that has all
options unset. Previously, that would result in no "$ETHTOOL_OPTS"
variable and thus the reader would loose a previously existing setting.

Hack it by writing a bogus

  ETHTOOL_OPTS="-A $IFACE"

line.
2021-06-25 15:45:57 +02:00
Thomas Haller
ef0f9b871b
ifcfg-rh/tests: add unit test for persisting NMSettingEthtool
In particular the case with an all-default NMSettingEthtool is
currently broken. The test is checking the wrong behavior, which
will be fixed next.
2021-06-25 15:45:56 +02:00
Thomas Haller
3fdedde16f
ifcfg-rh/tests: unlink test file in _writer_new_connection_reread() if not requested 2021-06-25 15:45:56 +02:00
Thomas Haller
1ae6719cf1
ifcfg-rh/tests: evalute environment for $NMTST_IFCFG_RH_UPDATE_EXPECTED only once
It just seems ugly to call g_getenv() repeatedly. Environment variables
must not change (in a multi-threaded program after other threads start),
so determine the mode once and cache it.
2021-06-25 15:45:39 +02:00
Thomas Haller
d391f20730
ifcfg: always write ethernet.s390-options even without subchannels
For the umpteenth time: it is not ifcfg-rh writers decision to decide
what are valid configurations and only persist settings based on
some other settings.

If s390-options would only be allowed together with subchannels, then
this is alone nm_connection_verify()'s task to ensure.

Reproduce with

  $ nmcli connection add type ethernet autoconnect no con-name zz ethernet.s390-options bridge_role=primary

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

Fixes: 16bccfd672 ('core: handle s390 options more cleanly')
2021-06-25 10:50:45 +02:00
Thomas Haller
476598ca99
supplicant: suppress warning log for P2PDevice.Cancel()
A failure to cancel something is not worth a warning. It probably
just means that no operation was in progress. In my logs I always
see a warning:

    CODE_FILE=src/core/supplicant/nm-supplicant-interface.c
    CODE_LINE=391
    MESSAGE=<warn>  [1624517233.8822] sup-iface[a22b181a321ffd9b,9,wlan0]: call-p2p-cancel: failed with P2P cancel failed

Downgrade this to trace level.
2021-06-24 09:08:47 +02:00
Benjamin Berg
be7a9f8192
wifi/p2p: Use address assigned by GO when available
When we are a client in the group we may be assigned an address by the
group owner. Use this address if it is available, but only if we are in
AUTO configuration mode.
2021-06-23 20:25:26 +02:00
Benjamin Berg
b9bcd61f15
supplicant: Store assigned addr for P2P group joins
A P2P Group Owner may assign an IP address and netmask to us. Store this
address so that it can be retrieved later during the IP configuration
stage.
2021-06-23 20:25:26 +02:00
Thomas Haller
c5e7e2f694
dhcp/trivial: rename "NMDhcpClientFactory.experimental" to "NMDhcpClientFactory.undocumented"
It's not experimental. It's not officially documented. Rename.
2021-06-23 13:11:56 +02:00
Thomas Haller
eb3ef97dd0
dhcp: refactor GType handling for NMDhcpClientFactory
In NetworkManager.conf, we can only configure one "[main].dhcp="
for both address families. Consequently, NMDhcpClientFactory
represents also both address families. However, most plugins
don't support IPv4 and IPv6 together.

Thus, if a plugin does not support an address family, we fallback
to the implementation of the "internal" plugin.

Slightly rework the code how that is done. Instead of having
a "get_type()" and "get_type_per_addr_family()" callback, have
an IPv4 and IPv6 getter.
2021-06-23 13:11:56 +02:00
Thomas Haller
524114add7
dhcp: minor cleanup of DHCP plugin factory 2021-06-23 13:11:56 +02:00
Thomas Haller
9452d69465
config: avoid cloning string during nm_config_data_get_connection_default() et al.
NMConfigData is immutable and with the previous commit are the strings
already cached internally. There is no need to clone it.

Of course, the callers must not assume that the string stays alive after
a config reload (SIGHUP), where the NMConfigData might change. So they
are not always alive, but long enough for all callers to avoid cloning
the string.
2021-06-21 17:23:53 +02:00
Thomas Haller
2f9ab1d528
config: add lookup index for _match_section_infos_lookup()
Previously, we would call g_key_file_get_string(), which requires
two hash lookups (one for the group and one for the key).

We can do better. Especially since NMConfigData is immutable, it's
simple to build a lookup index of the values we have and then do binary
search.

Note that we call nm_config_data_get_connection_default() and similar
API *a lot*, so this is measurable.
2021-06-21 17:23:53 +02:00
Thomas Haller
b929caa95c
core: use nm_config_data_get_device_config_int64() for getting integer setting 2021-06-21 17:23:53 +02:00
Thomas Haller
a6c9f2518e
config: add nm_config_data_get_device_config_int64() helper 2021-06-21 17:23:53 +02:00
Beniamino Galvani
3c55db886a device: prefer IPv6 not-deprecated addresses for hostname lookup
In presence of a IPv6 deprecated address and a non-deprecated one, the
latter will be used by kernel for new connections according to RFC
6724 section 5 (Source Address Selection). Prefer it also to lookup a
hostname via reverse DNS.

While at it, also prefer non-link-local addresses over link-local
ones.
2021-06-21 10:08:27 +02:00
Beniamino Galvani
ca31cbbc74 core: add nm_ip_config_find_first_address()
Replace nm_ip6_config_find_first_address() with a version generic for
IPv4 and IPv6.
2021-06-21 10:08:27 +02:00
Beniamino Galvani
376c7f8315 libnm-platform: add nm_platform_ip_address_match()
Replace nm_platform_ip6_address_match() with a version generic for
IPv4 and IPv6.
2021-06-21 10:08:27 +02:00
Beniamino Galvani
637a45e25b policy: prefer IPv4 to determine the hostname
When determining the hostname, it is preferable to evaluate devices in
a predictable order to avoid that the hostname changes between
different boots.

The current order is based first on hostname priority, then on the
presence of a best default route, and then on activation order.

The activation order is not a very strong condition, as it is
basically useless for devices that are autoactivated at boot.

As we already prefer IPv4 over IPv6 within the same connection, also
prefer it when 2 connections have the same priority and the same
default route status, to achieve better predictability.

https://bugzilla.redhat.com/show_bug.cgi?id=1970335
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/895
2021-06-21 08:53:42 +02:00
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