Commit graph

28896 commits

Author SHA1 Message Date
Thomas Haller
b688fc3da4
libnm: use direct properties for NMSettingBluetooth 2021-07-23 17:02:02 +02:00
Thomas Haller
e399fda04c
libnm: add nm_sett_info_propert_type_direct_int32 property type 2021-07-23 17:02:02 +02:00
Thomas Haller
82e9f43289
libnm: add nm_sett_info_propert_type_direct_mac_address
A MAC address is a relatively common "type". The GObject property is of type string,
but the D-Bus type is a bytestring ("ay"). We will need a special NMSettInfoPropertType.

Note that like most implementations, the from-dbus implementation still is based
on GObject setters. This will change in the future.

Also note that the previous compare function was
_nm_setting_property_compare_fcn_default(). That is, it used to convert
the property to GVariant and compare those. The conversion to GVariant
in that case normalizes the string (e.g. it is case insensitive). Also,
only properties could be compared which were also convertible to D-Bus
(which is probably fine, because there is no guarantee the profiles that
don't verify can be compared).

The code now uses the direct comparison of the strings. That mostly
preserves the case-insensitivity of the previous comparison, because
the property setters for mac addresses all use
_nm_utils_hwaddr_canonical_or_invalid() to normalize the strings.
This is subtle, but still correct. Note that this will improve later,
by ensuring that the property setters for mac addresses automatically
perform the right normalization.
2021-07-23 17:02:01 +02:00
Thomas Haller
dc2e4d04f1
libnm: normalize mac-address properties in GObject property setter
The aim is that properties have a "type", that is, that similar
properties share a common behavior and appearance.

Most properties of type "mac-address" normalize the string in the
GObject property setter. Three don't. Let them also do that.

This is also relevant, because the compare function for mac-addresses
(_nm_setting_property_compare_fcn_default()) converts the properties
first to a "ay" GVariant. Which means the comparison is case
insensitive. Normalizing the values in the setter avoids that
inconsistency.
2021-07-23 17:02:01 +02:00
Thomas Haller
abf5d01583
glib-aux: add NM_G_PARAM_SPEC_GET_DEFAULT_INT() helper 2021-07-23 17:02:01 +02:00
Thomas Haller
faf315148b
cloud-setup,glib-aux: merge branch 'th/cloud-setup-logging'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/937
2021-07-23 16:49:20 +02:00
Thomas Haller
443f348776
glib-aux: use nm_vsprintf_buf_or_alloc() to stack allocate logging message in _nm_log_simple_printf()
Also take the timestamp first.
2021-07-23 16:43:37 +02:00
Thomas Haller
6c030ed923
glib-aux,cloud-setup: add _nm_logging_enabled*() helper API
Will also be used outside of nm-cloud-setup.
2021-07-23 16:43:37 +02:00
Thomas Haller
32b2d15021
cloud-setup: link with libnm-log-null 2021-07-23 16:43:36 +02:00
Thomas Haller
391d714b19
cloud-setup: use _nm_log_simple_printf() for plain logging 2021-07-23 16:43:36 +02:00
Thomas Haller
764ca7462f
glib-aux: add _nm_log_simple_printf() helper 2021-07-23 16:43:36 +02:00
Thomas Haller
22d6be54f3
initrd: fix handling "ip=single-dhcp:..." in reader_parse_ip()
Fixes: bf7530ccc1 ('initrd: honor "ip=single-dhcp" option as alias for "dhcp"')
2021-07-23 11:36:41 +02:00
Thomas Haller
bf7530ccc1
initrd: honor "ip=single-dhcp" option as alias for "dhcp"
This mode was added to network-legacy in [1]. NetworkManager anyway always
does DHCP in parallel, so this is basically an alias for "dhcp".
Note that network-legacy's "single-dhcp" will stop waiting for DHCP
once the first device gets an address. NetworkManager currently cannot
do that. While it runs DHCP in parallel, all devices need to settle
and there is no concept where completing one device makes the overall
"startup complete" process finish early. That could however be added.

Anyway, while not being exactly the same, it's still more useful to do
something similar instead of not working at all.

See-also: https://github.com/dracutdevs/dracut/pull/853
See-also: https://github.com/dracutdevs/dracut/pull/961
See-also: https://github.com/dracutdevs/dracut/pull/1048

[1] 4026cd3b01
2021-07-23 11:06:06 +02:00
Thomas Haller
cf1b726157
gitlab-ci: regenerate ci-templates's containers 2021-07-21 10:11:55 +02:00
Thomas Haller
4ad4db6cf1
core: merge branch 'th/external-routes-no-sync'
https://bugzilla.redhat.com/show_bug.cgi?id=1979192

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/935
2021-07-21 09:57:30 +02:00
Thomas Haller
13d749942f
platform: don't add routes that are tracked as external routes
Due to something that really should be fixed, NetworkManager merges the routes
that it wants to configure, with the routes that are configured externally.
This includes a subtract and merge dance, which is wrong.

Anyway. If we are in nm_platform_ip_route_sync(), then we never want to
actively configure a route, that we only have in the list because it is
(or was) present on the interface.

Otherwise we have a problem. Note that we make a plan which
routes/addresses to add/remove before starting. So, if we start with an
IPv4 address configured in kernel, then there is also a corresponding
local route. We would track that local route as external.
During sync, we first remove the IP address, and kernel automatically
also removes the local route. However, as we already made the plan to
keep that route, NetworkManager would wrongly configure it again.

This should fix that bug. It is anyway wrong to even try to explicitly
configure a route, that is purely in the list as being external.

https://bugzilla.redhat.com/show_bug.cgi?id=1979192#c11
2021-07-21 09:54:58 +02:00
Thomas Haller
1f1c7b82fd
platform: mark routes in NMPlatform cache as "external" 2021-07-21 09:54:58 +02:00
Thomas Haller
a6649ef87b
core: preserve "is_external" route flag during _nm_ip_config_add_obj() 2021-07-21 09:54:58 +02:00
Thomas Haller
dc0ac73780
platform: add is-external flag to NMPlatformIPRoute
We will need to track whether a route is externally added or not.
We maybe could use rt_source for that, but instead add a boolean flag.
2021-07-21 09:54:58 +02:00
Wen Liang
f3404435a9
cloud-setup: configure secondary ip in Aliyun cloud
This is a tool for automatically configuring networking in Aliyun
cloud environment.

This add a provider implementation for Aliyun that when detected fetches
the private ip addressess and the subnet prefix of IPv4 CIDR block.

Once this information is fetched from the metadata server, it instructs
NetworkManager to add private ip addressess and subnet prefix for each
interface detected.

It is inspired by SuSE's cloud-netconfig ([1], [2]) and Aliyun Instance Metadata [3].

[1] https://www.suse.com/c/multi-nic-cloud-netconfig-ec2-azure/
[2] https://github.com/SUSE-Enceladus/cloud-netconfig
[3] https://www.alibabacloud.com/help/doc-detail/49122.htm

It is also intended to work without configuration. The main point is
that you boot an image with NetworkManager and nm-cloud-setup enabled,
and it just works.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/885

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-07-19 17:41:52 +02:00
Thomas Haller
09daf5dd92
glib-aux: add nm_g_unix_signal_add_source() helper 2021-07-19 09:25:42 +02:00
Thomas Haller
7ae2f842ae
build: merge branch 'th/build-libreadline'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/930
2021-07-19 09:11:30 +02:00
Thomas Haller
55fa00f05b
build/meson: cleanup handling of libreadline build option
- add "required:false" to dependency() and find_library(),
  otherwise autodetection will fail.

- rename variable "enable_readline" to "with_readline" for
  consistency with autotools.

- with -Dlibreadline=auto, once we detect a library, update
  "with_readline" variable to reflect the detected choice.
  This will also be printed in the summary output.
  This is also important for the nmcli check
  `assert(with_readline != 'none', 'readline ...`.
2021-07-19 09:10:43 +02:00
Thomas Haller
bf86f51c9e
build: rework libreadline detection in autotools
- `m4/ax_lib_readline.m4` was already aware of "$with_readline".
  Move the entire handling of the parameter inside the AX_LIB_READLINE
  macro.
  This lets our fork of ax_lib_readline.m4 further deviate from upstream
  version, but it's already so different that this is no new problem.

- raise an error if the user requested --with-readline=libreadline|libedit
  but the library was not found.

- only allow yes|no for --with-nmcli argument. But still default to
  "yes", which will always require one libreadline library to be
  detected. In particular, don't automatically disable nmcli if
  libreadline is not available, because building without nmcli
  should be an explicit choice. That is like before.

- update the "$with_readline" variable for the "auto" case to reflect
  what was detected.
2021-07-19 09:08:06 +02:00
Thomas Haller
299117f619
all: merge branch 'th/ascii-control-chars'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/932
2021-07-19 09:06:21 +02:00
Thomas Haller
cf9e7ee5aa
libnm: use nm_ascii_is_regular() in _keyfile_key_encode()
No change in behavior.
2021-07-19 09:04:49 +02:00
Thomas Haller
fb3e6cb0dc
libnm: use nm_ascii_is_ctrl_or_del() in nm_utils_fixup_product_string() to preserve UTF-8
On architectures where "char" is signed, the check "ch < ' '" is also
TRUE for characters greater than 127 (that is, UTF-8 characters).

Let's preserve valid UTF-8 characters and don't clear them.

Also note that already before we filtered out invalid UTF-8 sequences,
so if we encounter here a character > 127, it is part of a valid UTF-8
sequence.
2021-07-19 09:04:49 +02:00
Thomas Haller
17bdd3a40d
libnm: fix clearing parentheses in nm_utils_fixup_product_string()
Previously, once in_parent was TRUE it was never reset, thus the
remainder of the string was cleared. That was most likely not intended.

If the intent really was to clear all the remainder, then the code could
have simply truncated the string at the first '('.
2021-07-19 09:04:49 +02:00
Thomas Haller
fc2f758af5
ifcfg: also ANSIC escape DEL character in ifcfg writer
This is like using nm_ascii_is_ctrl_or_del() instead of
nm_ascii_is_ctrl() in the previous version of the patch.
We thus now always will switch to ANSIC escaping if we see
a ASCII DEL character. That is probable desirable, but either
way should not make a big difference (because we can parse
the DEL character both in regular quotation and in ANSIC quotation).

The patch is however larger, to also take the opportunity to only check
for nm_ascii_is_regular() in the "fast path". The behavior is the same
as changing nm_ascii_is_ctrl() to nm_ascii_is_ctrl_or_del().
2021-07-19 09:03:52 +02:00
Thomas Haller
6841bb1b26
ifcfg: use nm_ascii_is_ctrl() helper in shvar.c
No change in behavior.
2021-07-19 08:59:34 +02:00
Thomas Haller
4b21056fde
glib-aux: also backslash escape ASCII DEL character in nm_utils_buf_utf8safe_escape() 2021-07-19 08:59:34 +02:00
Thomas Haller
83f888054b
glib-aux: fix handling ASCII control characters in nm_utils_buf_utf8safe_escape()
On architectures where "char" is signed, the check "ch < ' '" is
also TRUE for non-ASCII characters greater than 127. This is an
easy mistake to make. Fix it by using nm_ascii_is_control() which
gets this right.

It's a bug, but possibly not too bad because unnecesarily escaping
a UTF-8 characters is not a severe problem, because the user anyway must
be prepared to unescape the string.
2021-07-19 08:59:33 +02:00
Thomas Haller
5f54270d93
libnm/tests: add test for broken behavior of nm_utils_bin_utf8safe_escape() 2021-07-19 08:59:33 +02:00
Thomas Haller
5b6005d06e
glib-aux: add nm_ascii_is_ctrl() helper (and similar)
These functions have overlap with g_ascii_is*() functions.

However g_ascii_is*() (and the is* functions from <ctype.h>) are
always confusing to me, in the sense that it's not clearly stated
which characters qualify for a certain category. And review is not
easy either, because they are implemented via a table lookup.

E.g. were you aware that 127 is considered g_ascii_iscntrl()? Probably
you were, but it's not clear to see that anywhere.

The main point of our own functions is to have is easier to see how
characters get categorized, by using comparison instead of table lookup.

Also, several existing code did in fact not use the g_ascii_is*()
macros, possibly because of the (perceived) difficulty to understand
their exact meaning. As a consequence, several checks got wrong.

For example, (ch < ' ') is not a valid check for testing whether
the character is a ASCII control character, for two reasons:

 - if char is a signed type (as likely it is), then this also evaluates
   to TRUE for all non-ASCII, UTF-8 characters that are greater than
   127.

 - it does not consider DEL character (127) a control character.
2021-07-19 08:59:33 +02:00
Maxine Aubrey
bdfaa4520e
build/meson: fix when crypto libraries are built
Only do so when the dependencies are found.

Fixes: 243051a8a6 ('libnm/build: always compile both crypto backends if library available')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/934
2021-07-18 16:42:39 +02:00
Thomas Haller
9fcf532df3
libnm: merge branch 'th/setting-compare-hook'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/921
2021-07-16 13:35:58 +02:00
Thomas Haller
77d2c13e21
libnm: always set from_dbus_fcn() property hook
When looking at a property, it should always be clear how it is handled.
Also the "default" action should be an explicit hook.

Add _nm_setting_property_from_dbus_fcn_gprop() and set that as
from_dbus_fcn() callback to handle the "default" case which us
build around g_object_set_property().

While this adds lines of code, I think it makes the code easier to
understand. Basically, to convert a GVariant to a property, now all
properties call their from_dbus_fcn() handler, there is no special casing.
And the gprop-hook is only called for properties that are using
_nm_setting_property_from_dbus_fcn_gprop(). So, you can reason about
these two functions at separate layers.
2021-07-16 13:31:59 +02:00
Thomas Haller
a9ef71eb4a
libnm: pass full property meta data to from_dbus_fcn() hook 2021-07-16 13:31:59 +02:00
Thomas Haller
b34220a084
libnm: explicitly ignore to-dbus for "name" property
NM_SETTING_NAME is also a GObject property, but it's
not supposed to be serialized to/from D-Bus. It also
is irrelevant for comparison.

Hence, it's operations are all NOPs. Make an explicit property type for
that case instead of checking the GParamSpec flags.
2021-07-16 13:31:59 +02:00
Thomas Haller
1d9baa65d8
libnm: reorder code in init_from_dbus()
No functional change, just untangle the if-else-if blocks.
2021-07-16 13:31:59 +02:00
Thomas Haller
36f552c5ca
libnm: move NMSettInfoProperty.to_dbus_including_default flag
The "to_dbus_data" existed for namespacing the properties inside it.
However, such a struct adds overhead due to the alignment that it
enforces. We can share the memory needed for the bitfield by having
them beside each other.
2021-07-16 13:31:59 +02:00
Thomas Haller
9a05db61d6
libnm: drop unused NMSettInfoProperty.gprop_to_dbus_fcn() hook 2021-07-16 13:31:59 +02:00
Thomas Haller
d652e0f534
libnm: refactor to_dbus_fcn() for "ipv4.dns" property
The goal is to get rid of gprop_to_dbus_fcn() uses.

Note that there is a change in behavior. The "dns" GPtrArray in
NMSettingIPConfig is never NULL (the default of the boxed property),
thus the previous code always serialized the property, even the
empty list.

Now, empty dns properties are omitted from D-Bus.

Also, there is another change in behavior: nm_utils_ip4_dns_to_variant()
will now skip over strings that are not valid IPv4 addresses.
Previously, it would have added 0.0.0.0 (or some undefined address).
2021-07-16 13:31:59 +02:00
Thomas Haller
bb5c89e017
libnm: refactor to_dbus_fcn() for "ipv6.dns" property
The goal is to get rid of gprop_to_dbus_fcn() uses.

Note that there is a change in behavior. The "dns" GPtrArray in
NMSettingIPConfig is never NULL (the default of the boxed property),
thus the previous code always serialized the property, even the
empty list.

Now, empty dns properties are omitted from D-Bus.
2021-07-16 13:31:59 +02:00
Thomas Haller
c07f617bff
libnm: refactor to_dbus_fcn() for "wifi-sec.wep-key-type" property
The goal is to get rid of gprop_to_dbus_fcn() uses.
2021-07-16 13:31:58 +02:00
Thomas Haller
a0cf869daa
libnm: refactor to_dbus_fcn() for "serial.parity" property
The goal is to get rid of gprop_to_dbus_fcn() uses.
2021-07-16 13:31:58 +02:00
Thomas Haller
b756e058ac
libnm: implement "direct" properties for compare_fcn() 2021-07-16 13:31:58 +02:00
Thomas Haller
dee29e0c1c
libnm: add _nm_setting_compare_flags_check() helper 2021-07-16 13:31:58 +02:00
Thomas Haller
33bd052a87
libnm: special handle "name" properties compare_fcn
All settings have a "name" property. Their compare_fcn() is not interesting
and was already previously ignored. But we should not special handle it via
_nm_setting_property_compare_fcn_default().
2021-07-16 13:31:58 +02:00
Thomas Haller
c7262c2290
libnm: add special ignore function for NMSettInfoPropertType.compare_fcn() 2021-07-16 13:31:58 +02:00