Commit graph

28619 commits

Author SHA1 Message Date
Thomas Haller
bb8481f101
libnm: special handle serialization to D-Bus for "wifi.seen-bssid"
"wifi.seen-bssid" is an unusual property, therefore very ugly due to the
inconsistency.

It is not a regular user configuration that makes sense to store to
disk or modify by the user. It gets populated by the daemon, and
stored in "/var/lib/NetworkManager/seen-bssids" file.

As such, how to convert this to/from D-Bus needs special handling.

This means, that the to/from D-Bus functions will only serialize the
property when the seen-bssids are specified via
NMConnectionSerializationOptions, which is what the daemon does.
Also, the daemon ignores seen-bssids when parsing the variant.

This has the odd effect that when the client converts a setting to
GVariant, the seen-bssids gets lost. That means, a conversion to GVariant
and back looses information. I think that is OK in this case, because the
main point of to/from D-Bus is not to have a lossless GVariant representation
of a setting, but to transfer the setting via D-Bus between client and
daemon. And transferring seen-bssids via D-Bus makes only sense from the daemon
to the client.

(cherry picked from commit 4a4f214722)
2021-07-01 11:33:56 +02:00
Thomas Haller
36eacd8528
libnm/keyfile: ignore [wifi].seen-bssids for keyfile
"seen-bssids" primarily gets stored to "/var/lib/NetworkManager/seen-bssids",
it's not a regular property.

We want this property to be serialized/deserialized to/from GVariant,
because we expose these settings on the API like a property of the
profile. But it cannot be modified via nmcli, it cannot be stored
to ifcfg files, and it makes not sense to store it to keyfile either.

Stop doing that.

(cherry picked from commit d9ebcc8646)
2021-07-01 11:33:56 +02:00
Thomas Haller
9e1d29d437
core: set _nm_utils_is_manager_process as first thing in daemon
(cherry picked from commit 6c5070da55)
2021-07-01 11:33:56 +02:00
Thomas Haller
29d64f148e
glib-aux: use NM_AUTO_PROTECT_ERRNO() in nm_auto_close and nm_auto_fclose
(cherry picked from commit f9f453994b)
2021-07-01 11:33:56 +02:00
Thomas Haller
309eba1078
std-aux/glib-aux: move NM_AUTO_PROTECT_ERRNO() to libnm-std-aux
(cherry picked from commit 2b55408cc7)
2021-07-01 11:33:56 +02:00
Thomas Haller
db744d2296
release: bump version to 1.32.3 (development) 2021-06-30 18:13:10 +02:00
Thomas Haller
bf1b09702e
release: bump version to 1.32.2 2021-06-30 18:13:10 +02:00
Thomas Haller
1216acefe8
NEWS: update 2021-06-30 17:14:31 +02:00
Thomas Haller
6a578faa24
libnm: document nm_ip_routing_rule_[gs]et_uid_range() as unusable
Fixes: 972d1ba046 ('libnm,core: support "uidrange" parameter for routing rules'):
2021-06-30 17:14:31 +02:00
Thomas Haller
af199191e6
libnm: fix crash in nm_ip_routing_rule_from_string()
import gi
    gi.require_version("NM", "1.0")
    from gi.repository import NM

    r = NM.IPRoutingRule.from_string('priority 10 type blackhole', NM.IPRoutingRuleAsStringFlags.AF_INET)
    r.to_string(NM.IPRoutingRuleAsStringFlags.NONE)

    r = NM.IPRoutingRule.from_string('priority 10 blackhole', NM.IPRoutingRuleAsStringFlags.AF_INET)
    r.to_string(NM.IPRoutingRuleAsStringFlags.NONE)

    r= NM.IPRoutingRule.from_string('priority 10 bogus', NM.IPRoutingRuleAsStringFlags.AF_INET)
    # CRASH

Fixes: e922404990 ('libnm,core: support "prohibit"/"blackhole"/"unreachable" type routing rules')
(cherry picked from commit 668c90dbb8)
2021-06-30 17:14:31 +02:00
Thomas Haller
7adbda7348
n-dhcp4: avoid maybe-uninitialized warning in n_dhcp4_c_connection_dispatch_io()
On RHEL-8.5, s390x with gcc-8.5.0-2.el8, we get a compiler warning:

  $ CFLAGS='-O2 -Werror=maybe-uninitialized' meson build
  ...
  cc -Isrc/libndhcp4-private.a.p -Isrc -I../src -Isubprojects/c-list/src -I../subprojects/c-list/src -Isubprojects/c-siphash/src -I../subprojects/c-siphash/src -Isubprojects/c-stdaux/src -I../subprojects/c-stdaux/src -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c11 -g -D_GNU_SOURCE -O2 -Werror=maybe-uninitialized -fPIC -fvisibility=hidden -fno-common -MD -MQ src/libndhcp4-private.a.p/n-dhcp4-c-connection.c.o -MF src/libndhcp4-private.a.p/n-dhcp4-c-connection.c.o.d -o src/libndhcp4-private.a.p/n-dhcp4-c-connection.c.o -c ../src/n-dhcp4-c-connection.c
  ../src/n-dhcp4-c-connection.c: In function ‘n_dhcp4_c_connection_dispatch_io’:
  ../src/n-dhcp4-c-connection.c:1151:17: error: ‘type’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
           uint8_t type;
                   ^~~~

https://github.com/nettools/n-dhcp4/pull/24
(cherry picked from commit 3a4822c52c)
2021-06-30 17:14:30 +02:00
Thomas Haller
9541b0bea4
cloud-setup: preserve IPv4 addresses/routes/rules from profile
nm-cloud-setup automatically detects routes, addresses and rules and configures them
on the device using the emphermal Reapply() API. That is, it does not modify the
existing profile (on disk), but changes the runtime configuration only.

As such, it used to wipe otherwise statically configured IP addresses, routes and
rules. That seems unnecessary. Let's keep the configuration from the (persistent)
configuration.

There is of course the problem that nm-cloud-setup doesn't really
understand the existing IP configuration, and it can only hope that
it can be meaningfully combined with what nm-cloud-setup wants to
configure. This should cover most simple cases, for more complex setups,
the user probably should disable nm-cloud-setup and configure the
network explicitly to their liking.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/893
(cherry picked from commit 4201ee5119)
2021-06-30 08:05:16 +02:00
Julian Wiedmann
f1196cb26e
nm-initrd-generator: document support for rd.znet option
rd.znet support was added with commit 11d4412ee1 ("process s390
specific device info from rd.znet parameter in nm-initrd-generator").

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>

https://github.com/NetworkManager/NetworkManager/pull/362
(cherry picked from commit 6bc6d45925)
2021-06-28 14:02:00 +02:00
Thomas Haller
0e6d4a99db
ifcfg-rh: merge branch 'th/ifcfg-fix-empty-ethtool'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/905

(cherry picked from commit f9040c3cca)
2021-06-28 13:30:33 +02:00
Thomas Haller
364bc8d737
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.

(cherry picked from commit 26ed9e6714)
2021-06-28 13:30:32 +02:00
Thomas Haller
e78d9535a8
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.

(cherry picked from commit ef0f9b871b)
2021-06-28 13:30:31 +02:00
Thomas Haller
85ddfc8959
ifcfg-rh/tests: unlink test file in _writer_new_connection_reread() if not requested
(cherry picked from commit 3fdedde16f)
2021-06-28 13:30:31 +02:00
Thomas Haller
842db82686
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.

(cherry picked from commit 1ae6719cf1)
2021-06-28 13:30:31 +02:00
Thomas Haller
b425793d90
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')
(cherry picked from commit d391f20730)
2021-06-25 11:26:34 +02:00
Thomas Haller
b5de7b2e48
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.

(cherry picked from commit 476598ca99)
2021-06-24 11:15:04 +02:00
Thomas Haller
056f69198f
gitlab-ci: bump tag for cached container images
This results in a rebuild of the containers, which is a good idea as we
didn't do that for a while.

(cherry picked from commit aba1754a80)
2021-06-23 21:08:15 +02:00
Thomas Haller
0432c2bcdb
trivial: fix code formatting
Fixes: ac090edd87 ('libnm: add type enum for handling gprop differences in to_dbus_fcn')
(cherry picked from commit 6ac304b673)
2021-06-23 14:58:53 +02:00
Thomas Haller
11fd85b3e1
libnm: merge branch 'th/setting-to-dbus-fcn'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/900

(cherry picked from commit 74996782eb)
2021-06-23 13:02:34 +02:00
Thomas Haller
17fab764fc
libnm: use _nm_setting_property_define_string() for string NMSetting properties
(cherry picked from commit a3eb2c7026)
2021-06-23 13:02:30 +02:00
Thomas Haller
2e93f82746
libnm: use _nm_setting_property_define_boolean() for boolean NMSetting properties
(cherry picked from commit 22edf34ba3)
2021-06-23 13:02:28 +02:00
Thomas Haller
1cc3b9c753
libnm: use new including_default flag and boolean getter for "ethernet.auto-negotiate" property
(cherry picked from commit d5c4378cdf)
2021-06-23 13:02:27 +02:00
Thomas Haller
4cea3e4f44
libnm: add flag to control whether to_dbus_fcn() should handle default values
Usually, properties that are set to their default are not serialized on
D-Bus. That is, to_dbus_fcn() returns NULL.

In some cases, we explicitly want to always serialize the property. For
example, if we changed behavior and the libnm default value changed.
Then we want that the message on D-Bus is always clear about the used
value and not rely on the default value on the receiving side.

(cherry picked from commit acc3a66bf2)
2021-06-23 13:02:26 +02:00
Thomas Haller
b20941215e
libnm: extend to_dbus_fcn() property type for efficiently converting string property
(cherry picked from commit e435fdfedf)
2021-06-23 13:02:24 +02:00
Thomas Haller
7598eb6228
libnm: extend to_dbus_fcn() property type for efficiently converting boolean property
Most of our NMSetting properties are based around GObject properties,
and thus the tooling to convert a NMSetting to/from GVariant consists
of getting/setting a GValue.

We can do better.

For most of such properties we also define a C getter function, which
we can call with less overhead. All we need is to hook the C getter with
the property meta data.

As example, implement it for "connection.autoconnect".

The immediate goal of this is to reduce the overhead of to_dbus. But
note that also for comparison of two properties, there is the default
implementation which is used by the majority of properties. This
implementation converts the properties first to GVariant (via
to_dbus_fcn) and then compares the variants. What this commit also does,
is to hook up the property meta data with the C-getters. This is one step
towards also more efficiently compare properties using the naive C
getters. Likewise, the keyfile writer use g_object_get_property().
It also could do better.

(cherry picked from commit a832781a8a)
2021-06-23 13:02:23 +02:00
Thomas Haller
8416c42b9d
libnm: move gprop_to_dbus_fcn hook to NMSettInfoProperty
For each property we have meta data in form of NMSettInfoProperty.
Each meta data also has a NMSettInfoProperty.property_type
(NMSettInfoPropertType).

The property type is supposed to define common behaviors for properties,
while the property meta data has individual properties. The idea is that
several properties can share the same property-type, and that
per-property meta data is part of NMSettInfoProperty.

The distinction is not very strong, but note that all remaining uses
of NMSettInfoPropertType.gprop_to_dbus_fcn were part of a property
type that was only used for one single property. That lack of
reusability hints to a wrong use.

Move gprop_to_dbus_fcn to the property meta data as a new field
NMSettInfoProperty.to_dbus_data.

Note that NMSettInfoPropertType.gprop_from_dbus_fcn still suffers from
the same problem. But the from-dbus side is not yet addressed.

(cherry picked from commit 54cab39ac9)
2021-06-23 13:02:22 +02:00
Thomas Haller
7af962b330
libnm: change "nm_sett_info_propert_type_mac_address" to use gprop_type for to_dbus_fcn()
(cherry picked from commit ed57990b58)
2021-06-23 13:02:21 +02:00
Thomas Haller
7f21fbad31
libnm: change "nm_sett_info_propert_type_strdict" to use gprop_type for to_dbus_fcn()
(cherry picked from commit 6d39014660)
2021-06-23 13:02:20 +02:00
Thomas Haller
97a25c5965
libnm: change "nm_sett_info_propert_type_dcb_au" to use gprop_type for to_dbus_fcn()
(cherry picked from commit 8c0a8a6d9b)
2021-06-23 13:02:19 +02:00
Thomas Haller
3dfd563601
libnm: add type enum for handling gprop differences in to_dbus_fcn
For GBytes, GEnum, GFlags and others, we need special converters from the
default GObject properties to GVariant.

Previously, those were implemented by providing a special
gprop_to_dbus_fcn hook. But gprop_to_dbus_fcn should move
from NMSettInfoPropertType to NMSettInfoProperty, because it's
usually a per-property meta data, and not a per-property-type meta data.
The difference is whether the meta data can be shared between different
properties (of the same "type).

In these cases, this extra information is indeed part of the type.
We want to have a generic NM_SETT_INFO_PROPERT_TYPE_GPROP() property
(using _nm_setting_property_to_dbus_fcn_gprop()), but then we would like
to distinguish between special cases. So this was fine.

However, I find the approach of providing a gprop_to_dbus_fcn in this
case cumbersome. It makes it harder to understand what happens. Instead,
introduce a new "gprop_type" for the different types that
_nm_setting_property_to_dbus_fcn_gprop() can handle.

This new "gprop_type" is extra data of the property type, so
introduce a new field "typdata_to_dbus".

(cherry picked from commit ac090edd87)
2021-06-23 13:02:19 +02:00
Thomas Haller
d2e0a8cc0e
libnm: add and use NM_SETT_INFO_PROPERT_TYPE_*_INIT() macros
The advantage is that we use similar macros for initializing the
static structs like

   const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address;

and the ad-hoc locations that use NM_SETT_INFO_PROPERT_TYPE().

The former exist for property types that are used more than once.
The latter exist for convenience, where a property type is implemented
at only one place.

Also, there are few direct references to _nm_setting_property_to_dbus_fcn_gprop().
all users use NM_SETT_INFO_PROPERT_TYPE_GPROP() or
NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT().

(cherry picked from commit 6fc2e03677)
2021-06-23 13:02:18 +02:00
Thomas Haller
0d95b3c300
libnm: add and use NM_SETT_INFO_PROPERT_TYPE_DBUS() macro
(cherry picked from commit 69597a67c1)
2021-06-23 13:02:17 +02:00
Thomas Haller
db9ae06cfd
libnm: let all property types implement to_dbus_fcn() handler
If a property can be converted to D-Bus, then always set the
to_dbus_fcn() handler. The only caller of to_dbus_fcn() is
property_to_dbus(), so this means that property_to_dbus()
has no more default implementation and always delegates to
to_dbus_fcn().

The code is easier to understand if all properties implement
to_dbus_fcn() the same way.

Also, there is supposed to be a split between NMSettInfoProperty (info about
the property) and NMSettInfoPropertType (the type). The idea is that
each property (obviously) requires its distinct NMSettInfoProperty, but
they can share a common type implementation.
With NMSettInfoPropertType.gprop_to_dbus_fcn that is often violated because
many properties that implement NMSettInfoPropertType.gprop_to_dbus_fcn
require a special type implementation. As such, gprop_to_dbus_fcn should
be part of the property info and not the property type. The first step towards
that is unifying all properties to use to_dbus_fcn().

(cherry picked from commit c161439b73)
2021-06-23 13:02:17 +02:00
Thomas Haller
e4898f98e0
libnm: add NM_SETTING_PARAM_NONE define
This completes other NM_SETTING_PARAM_* flags.

(cherry picked from commit c54be51f99)
2021-06-23 13:02:16 +02:00
Thomas Haller
1ebef50603
libnm: drop unused parameter "ignored_default" from property_to_dbus()
(cherry picked from commit 4065158491)
2021-06-23 13:02:16 +02:00
Thomas Haller
3e58861336
libnm: simplify assertions for valid NMSettInfoProperty
(cherry picked from commit 21638c54b0)
2021-06-23 13:02:16 +02:00
Thomas Haller
d19c0937d4
libnm: expose internal helper nm_utils_hwaddr_to_dbus()
(cherry picked from commit 8081e39ab6)
2021-06-23 13:02:15 +02:00
Thomas Haller
445d01e2c6
glib-aux: add NM_G_PARAM_SPEC_GET_DEFAULT_STRING() helper
(cherry picked from commit 87229b22ae)
2021-06-23 13:02:15 +02:00
Thomas Haller
d99e20e436
glib-aux: add nm_g_variant_singleton_s_empty() helper
(cherry picked from commit e2defd0115)
2021-06-23 13:02:15 +02:00
Thomas Haller
b33ba1ef5c
glib-aux: add nm_g_variant_singleton_b() helper
(cherry picked from commit edb31252cc)
2021-06-23 13:02:15 +02:00
Thomas Haller
aa1be0559d
config: merge branch 'th/config-match-lookup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/894

(cherry picked from commit 3e7a589972)
2021-06-21 17:31:07 +02:00
Thomas Haller
e1d28afe4b
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.

(cherry picked from commit 9452d69465)
2021-06-21 17:31:06 +02:00
Thomas Haller
ba2a6ee384
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.

(cherry picked from commit 2f9ab1d528)
2021-06-21 17:31:06 +02:00
Thomas Haller
34e4364558
core: use nm_config_data_get_device_config_int64() for getting integer setting
(cherry picked from commit b929caa95c)
2021-06-21 17:31:05 +02:00
Thomas Haller
6bbf1b14c9
config: add nm_config_data_get_device_config_int64() helper
(cherry picked from commit a6c9f2518e)
2021-06-21 17:31:05 +02:00
Thomas Haller
cc5a0f517e
glib-aux: cleanup nm_utils_named_value_clear_with_g_free() implementation
(cherry picked from commit 42ba464380)
2021-06-21 17:31:05 +02:00