Commit graph

28708 commits

Author SHA1 Message Date
Beniamino Galvani
69cd16e458 core: persist the bootfile from DHCP
The bootfile location is needed by the anaconda dracut module; write
it to the device state file.

(cherry picked from commit 9a09c02012)
2021-07-27 09:44:28 +02:00
Beniamino Galvani
b77a5bb7b0 dhcp: nettools: parse the filename and the bootfile-name option
(cherry picked from commit 3c79944e15)
2021-07-27 09:44:28 +02:00
Beniamino Galvani
50e65f8ce4 n-dhcp4: add an accessor for the file name in the lease
The name of the boot file can be either in option 67 or in a field of
the DHCP header. Add an accessor for the one from the DHCP header.

(cherry picked from commit 6a1349c5fb)
2021-07-27 09:44:28 +02:00
Beniamino Galvani
a4acfef3aa n-dhcp4: fix n_dhcp4_client_lease_get_server_identifier()
N_DHCP4_E_MALFORMED is an internal error code, replace it with
N_DHCP4_E_INTERNAL. Also, remove extra spaces.

(cherry picked from commit be6997d127)
2021-07-27 09:44:28 +02:00
Beniamino Galvani
667f2a5d76 dhcp: add internal option for the boot file name
Add an internal option that specifies the boot file name from the DHCP
header. The option name 'filename' is the same as exposed by dhclient.

(cherry picked from commit 0994a444e5)
2021-07-27 09:44:28 +02:00
Beniamino Galvani
5f85f1631b dhcp: escape control characters in DHCP options
Control characters (DEL (=127) or those below 32) could cause undesired
effects when a client displays or parses DHCP options. Escape them.

(cherry picked from commit 0c10e4f8b6)
2021-07-27 09:44:28 +02:00
Beniamino Galvani
8481470557 initrd: support infiniband pkeys
Introduce a new "ib.pkey=<parent>.<pkey>" command line argument to
create a Infiniband partition.

The new connection has IPv4 and IPv6 enabled by default. Unlike for
VLANs, the generator doesn't create a connection for the parent
Infiniband interface.

See also: https://github.com/dracutdevs/dracut/pull/1538

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/884
(cherry picked from commit 9060c14ccf)
2021-07-27 09:08:11 +02:00
Thomas Haller
c880b9eab9
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

(cherry picked from commit bf7530ccc1)
2021-07-23 11:09:01 +02:00
Thomas Haller
d2075ac770
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

(cherry picked from commit 4ad4db6cf1)
2021-07-21 10:09:10 +02:00
Thomas Haller
6ee7be690e
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
(cherry picked from commit 13d749942f)
2021-07-21 10:09:09 +02:00
Thomas Haller
d009ee54ec
platform: mark routes in NMPlatform cache as "external"
(cherry picked from commit 1f1c7b82fd)
2021-07-21 10:09:09 +02:00
Thomas Haller
ed30b717ae
core: preserve "is_external" route flag during _nm_ip_config_add_obj()
(cherry picked from commit a6649ef87b)
2021-07-21 10:09:09 +02:00
Thomas Haller
643f9a3997
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.

(cherry picked from commit dc0ac73780)
2021-07-21 10:09:09 +02:00
Thomas Haller
a09d26ccfd
release: bump version to 1.32.5 (development) 2021-07-20 17:02:22 +02:00
Thomas Haller
9c3fc0aca8
release: bump version to 1.32.4 2021-07-20 17:02:22 +02:00
Thomas Haller
03f4ebb889
cloud-setup: add nmcs_utils_uri_complete_interned() for constructing URI for _ec2_base()
(cherry picked from commit c6fefce8a4)
2021-07-20 16:12:34 +02:00
Thomas Haller
8b6b7a4a76
cloud-setup: fix constructing URL from NM_CLOUD_SETUP_EC2_HOST in _ec2_base()
(cherry picked from commit 78adf4796e)
2021-07-20 16:12:33 +02:00
Thomas Haller
d37a8b9db3
cloud-setup: drop unnecessary check in_detect_get_meta_data_done_cb()
(cherry picked from commit 791bb88646)
2021-07-20 16:12:31 +02:00
Thomas Haller
34c90f2d1a
NEWS: update 2021-07-20 15:58:00 +02:00
Thomas Haller
2f8b722c2b
libnm: mark symbols in libnm_1_32_4 linker symbol version as global
I think this has no effect in practice. But do it for consistency.
2021-07-20 15:57:59 +02:00
Wen Liang
243cf5a873
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>
(cherry picked from commit f3404435a9)
2021-07-19 17:49:53 +02:00
Thomas Haller
b2ef9f01fc
all: merge branch 'th/ascii-control-chars'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/932

(cherry picked from commit 299117f619)
2021-07-19 09:14:44 +02:00
Thomas Haller
4e64d4af1e
libnm: use nm_ascii_is_regular() in _keyfile_key_encode()
No change in behavior.

(cherry picked from commit cf9e7ee5aa)
2021-07-19 09:14:44 +02:00
Thomas Haller
e03587f9b0
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.

(cherry picked from commit fb3e6cb0dc)
2021-07-19 09:14:43 +02:00
Thomas Haller
e3cfd14851
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 '('.

(cherry picked from commit 17bdd3a40d)
2021-07-19 09:14:43 +02:00
Thomas Haller
8d70dd5477
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().

(cherry picked from commit fc2f758af5)
2021-07-19 09:14:43 +02:00
Thomas Haller
9e40072fd0
ifcfg: use nm_ascii_is_ctrl() helper in shvar.c
No change in behavior.

(cherry picked from commit 6841bb1b26)
2021-07-19 09:14:43 +02:00
Thomas Haller
199db653d1
glib-aux: also backslash escape ASCII DEL character in nm_utils_buf_utf8safe_escape()
(cherry picked from commit 4b21056fde)
2021-07-19 09:14:43 +02:00
Thomas Haller
4230b4c618
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.

(cherry picked from commit 83f888054b)
2021-07-19 09:14:43 +02:00
Thomas Haller
77c2ff8922
libnm/tests: add test for broken behavior of nm_utils_bin_utf8safe_escape()
(cherry picked from commit 5f54270d93)
2021-07-19 09:14:43 +02:00
Thomas Haller
5ef24e8d0b
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.

(cherry picked from commit 5b6005d06e)
2021-07-19 09:14:42 +02:00
Thomas Haller
ed26a3ce51
gitlab-ci: regenerate ci-templates's containers
(cherry picked from commit 8dddb7544f)
2021-07-18 17:47:00 +02:00
Maxine Aubrey
64461fb44a
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
(cherry picked from commit bdfaa4520e)
2021-07-18 16:44:17 +02:00
Thomas Haller
d8706caef2
firewall/nftables: only configure "ip" address familiar for masquerading
nftables' "inet" family is both for IPv4 and IPv6, while we only want
to configure rules for IPv4.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/760

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/928
(cherry picked from commit b49a168935)
2021-07-15 15:16:02 +02:00
Thomas Haller
d718fdfe26
ifcfg: merge branch 'th/ifcfg-warn-invalid'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/925

(cherry picked from commit a9f48129df)
2021-07-15 10:10:18 +02:00
Thomas Haller
99423a6698
ifcfg: log messages about invalid an unrecognized lines in ifcfg files
Problems of this patch:

- the code does not differentiate between an ifcfg file and an alias
  file. Different shell variables are honored however depending on the
  context and the warning should reflect that.

- there are no warnings about /etc/sysconfig/network. The main problem
  is that we read this file for every ifcfg file we parse, and we would
  need to ratelimit the number of warnings. Another problem is that
  the file likely contains keys that we intentionally don't support.
  We would need a new way to omit warnings about those lines.

Example:

    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=dhcp
    DEFROUTE=yes
    STABLE_ID=$'xxx\xF4yy'
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    XX=foo
    XX1=foo'
    '
    IPV6_AUTOCONF=yes xxxx
    IPV6_DEFROUTE=yesx
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=xxx
    UUID=9d8ed7ff-3cdd-4336-9e26-3e978dc87102
    ONBOOT=no

  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:6: key STABLE_ID does not contain valid UTF-8 and is treated as ""
  <debug> [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:9: key XX is unknown and ignored
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:10: key XX1 is badly quoted and is treated as ""
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:11: invalid line ignored
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:12: key IPV6_AUTOCONF is badly quoted and is treated as ""
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:13: key IPV6_DEFROUTE is duplicated and the early occurrence ignored

https://bugzilla.redhat.com/show_bug.cgi?id=1959656
(cherry picked from commit 41be0c8fde)
2021-07-15 10:10:17 +02:00
Thomas Haller
5d7a79f01e
ifcfg: reject non-UTF-8 at the lowest layer when reading shell variable
ifcfg files are a text format. It makes no sense to ever accept
non-UTF-8 blobs. If binary data is to be encoded in a ifcfg file, then
the upper layers must escape/encode it in valid UTF-8.

Let svUnescape() silently reject any binary "text". This will lead to treat such
strings as empty strings "". This is no different than some invalid
quoting: the string is not parsable as (UTF-8) text and will be treated
as such.

This is potentially a breaking change. But the benefit is that all the
upper layers can rely on only getting valid UTF-8 strings. For example,
a non-UTF-8 string cannot be converted to a "s" GVariant (of course not,
it's not a string). But our nm_connection_verify() commonly does not
check that all strings are in fact valid UTF-8. So a user who edits
an ifcfg file could inject non-valid strings, and cause assertion
failures later on.

It's actually easy to provoke a crash (or at least an assertion failure)
by writing an ifcfg file with certain keys as binary.

Note that you can either reproduce the binary files by writing non-UTF-8
"strings" dirctly, or by using \x, \u, or \U escape sequences.

Note that also '\0' gets rejected and renders the string as invalid
(i.e. as empty). Before the returned string would have been simply
truncated and the rest ignored. Such NUL bytes can only be produced
using the escape sequences, because the ifcfg reader already (silently)
truncates the file on the first binary NUL.

(cherry picked from commit 7c9b0d68e4)
2021-07-15 10:10:17 +02:00
Thomas Haller
15d2cfe751
ifcfg: ANSIC escape non-UTF-8 "strings" and preserve valid unicode
Note that previously the check

    if (s[slen] < ' ') {
        ...
        return (*to_free = _escape_ansic(s));
    }

would be TRUE for all UTF-8 characters if `char` is signed. That means,
depending on the compiler, we would always ANSI escape all UTF-8
characters. With this patch, we no longer do that!
Instead, valid unicode gets now preserved (albeit quoted).

On the other hand, always ANSIC escape invalid UTF-8 (regardless of the
compiler). ifcfg-rh is really a text based format. If a caller wants to store
binary data, they need to escape it first, for example with some own escaping
scheme, base64 or bin2hexstr.

A caller passing a non-text to svEscape() is likely a bug already and
they should have not done that.

Still, let svEscape() handle that by using ANSIC escaping. That works
as far as escaping is concerned, but likely later will be a problem
during unescaping, when the reader expects a valid UTF-8 string.
svEscape() is in no place to signal a sensible error, so proceed the
best it can, by escaping.

(cherry picked from commit 5877928b46)
2021-07-15 10:10:17 +02:00
Thomas Haller
c5f8173072
glib-aux: add nm_str_buf_utf8_validate() helper
(cherry picked from commit b15dfe0365)
2021-07-15 10:10:17 +02:00
Thomas Haller
bbfdbf5f76
device/dhcp: avoid crash by not starting DHCPv6 client without ifindex
https://bugzilla.redhat.com/show_bug.cgi?id=1973199
(cherry picked from commit 85f53f43e9)
2021-07-14 18:27:15 +02:00
Thomas Haller
d525a3b795
glib-aux: avoid compiler warning about ignoring getrandom() result
src/libnm-glib-aux/nm-random-utils.c:112:12: error: ignoring return value of 'getrandom' declared with attribute 'warn_unused_result' [-Werror=unused-result]

Fixes: 18597e33cb ('glib-aux: also use getrandom() for seeding pseudo random generator')
(cherry picked from commit 11d59f81cf)
2021-07-14 12:05:02 +02:00
Thomas Haller
20e3975fd2
device: avoid crash setting VPN config during unrealize
During nm_device_unrealize(), we first clear the device's ifindex. Then
we call _set_state_full(NM_DEVICE_STATE_UNMANAGED).

NMVpnConnection are subclasses of NMActiveConnection, it is that way
connected to NM_DEVICE_STATE_CHANGED signal. And this leads to a call
to _set_vpn_state(), which then calls nm_device_replace_vpn6_config()
to unregister the config. Thereby an assertion fails because the
ifindex no longer matches.

Fix that by relaxing the assertion. Also, don't apply the IP
configuration in unexpected device states.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/927
(cherry picked from commit 63a248ecb2)
2021-07-13 17:25:05 +02:00
Thomas Haller
22594864e8
core/wwan: avoid assertion failure in modem_ip{4,6}_config_result()
NMDeviceModem has priv->modem set from construction to dispose, and
the NM_MODEM_IP4_CONFIG_RESULT/NM_MODEM_IP6_CONFIG_RESULT signals
connected all the time.

On the other hand, NMModem may hook up to NMPPPManager's
NM_PPP_MANAGER_SIGNAL_IP{4,6}_CONFIG signals, which emit the
config-results signals. And PPP manager emits the config signals
from impl_ppp_manager_set_ip{4,6}_config().

That means, at any moment can be a D-Bus calls, which leads to emitting
those signals and calling into modem_ip4_config_result() and
modem_ip6_config_result().

At least, it's not clear from review what would prevent that from
happening. If you cannot easily verify that certain conditions are
satisfied, then this is not the place to assert, but to handle the case
as something that can happen regularly.

Handle signals in the unexpected state by ignoring them.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/926
(cherry picked from commit fa786e1f46)
2021-07-13 17:15:03 +02:00
Thomas Haller
a8d5c346bd
glib-aux: cleanup handling of getrandom() and handle EAGAIN
- the return value of getrandom() is ssize_t.
- handle EAGAIN to indicate low entropy.
- treat a return value of zero the same as any other
  low "n", by falling back to bad random bytes.

(cherry picked from commit 416f97c5a9)
2021-07-13 17:06:40 +02:00
Thomas Haller
2a9dd6c2e5
glib-aux: also use getrandom() for seeding pseudo random generator
It's worth a try.

Also, drop STATIC_SALT.

(cherry picked from commit 18597e33cb)
2021-07-13 17:06:40 +02:00
Thomas Haller
bb3da1e01c
glib-aux: merge branch 'th/bad-random-bytes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/922

(cherry picked from commit 5eb1b706fc)
2021-07-13 14:34:10 +02:00
Thomas Haller
e427f53b8f
glib-aux: add getrandom() syscall wrapper as fallback
We make an effort to get a better fallback case with
_bad_random_bytes().

Also make an effort to get good randomness in the first place. Even if
we compile against libc headers that don't provide getrandom(). Also,
this isn't really ugly, because for a long time glibc was reluctant to
add getrandom() wrapper and using syscall() was the way to go.

(cherry picked from commit 05a6936bef)
2021-07-13 14:33:33 +02:00
Thomas Haller
f84ebc4611
glib-aux: simplify logic in nm_utils_random_bytes()
There should be no change in behavior.

(cherry picked from commit 62c60653a7)
2021-07-13 14:32:45 +02:00
Thomas Haller
139fc5c81e
glib-aux: rework fallback random generator to use sha256
nm_utils_random_bytes() tries to get good randomness. If it fails, we still
try our own approach, but also signal that the returned numbers are bad.
In practice, none of the callers cares about the return value, because they
wouldn't know what to do in case of bad randomness (abort() is not an
option and retry is not expected to help and sending an email to the
admin isn't gonna help either). So the fallback case really should try
its best.

The fallback case depends on a good random seed and a good pseudorandom
number generator.

Getting a good seed is in reality impossible, after kernel let us down.
That is part of the problem, but we try our best.

The other part is to use a cryptographic pseudorandom number generator.
GRand uses a Mersenne Twister, so that is not good enough. In this low
level code we also cannot call gnutls/nss, because usually we don't have
that dependency. Maybe we could copy&paste the chacha20 implementation,
it's simple enough and a compatible license. That might be good, but
instead cock our own by adding some sha256 into the mix. This is
fallback code after all, and we want to try hard, but not *that* hard to
add chacha20 to NetworkManager.

So, what we do is to use a well seeded GRand instance, and XOR that
output with a sha256 digest of the state. It's probably slow, but
performance is not the issue in this code path.

(cherry picked from commit c22c3ce9f9)
2021-07-13 14:32:45 +02:00
Ana Cabral
033d000d33 nmcli: include 'searches' field for nmcli device show
Merge Request !919

(cherry picked from commit 34b499f1ef)
2021-07-13 08:14:06 -03:00