Commit graph

338 commits

Author SHA1 Message Date
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
Thomas Haller
881b42c454
dhcp: fix nm_dhcp_lease_data_parse_cstr() to correctly detect NUL chars
Fixes: 784932550c ('dhcp/nettools: validate and normalize Host Name Option (12)')
2021-05-27 09:56:38 +02:00
Thomas Haller
840dd8cbcd
settings: in assertion to check valid UUID use nm_uuid_is_valid_full()
In the past, the UUID was only loosely validate and would accept
forms that are not valid. This was fixed by commit 207cf3d5d4 ('libnm:
normalize "connection.uuid"'). Now the UUID is always strictly valid
and lower case.

Thus, don't use the fuzzy nm_utils_is_uuid() from libnm but the exact
check nm_uuid_is_valid_full().

Note that this is only used for assertions in the header file. We thus
don't want to drag in "libnm-glib-aux/nm-uuid.h". Instead, we forward
declare the function.

lgtm.com warns about declarations are block scope, so fix that too by
moving the declaration at file scope.
2021-05-27 09:24:00 +02:00
Thomas Haller
f18c6e7bd1
core: forward declare nm_settings_plugin_get_type() at file scope in "nm-settings-storage.h"
lgtm.com warns about function declarations inside blocks.
*sigh*. I think it's well understood what this code means, and it is not
done by accident. Still, let's make the tool happy in this case.
2021-05-27 09:17:29 +02:00
Thomas Haller
90818b5391
core: minor cleanup of integer multiplication in _sleep_duration_convert_ms_to_us()
Cast to unsigned int64. Also add parenthesis, even if not strictly
necessary.
2021-05-27 09:02:45 +02:00
Andrew Zaborowski
b86d83860e iwd: Add default "auto" value for [main].iwd-config-path
Since the [main].iwd-config-path functionality, where NM watches for
NMSettingsConnection changes and update IWD network config files with
new settings, has proven to work without issues so far, enable it by
default.  Instead of hardcoding /var/lib/iwd as the value, and since the
value can't be probed at NM compile time, query it from IWD's recently-
added D-Bus interface for settings when [main].iwd-config-path is either
missing or set to the new value "auto".
2021-05-26 16:47:04 +02:00
Andrew Zaborowski
62dc214033 iwd: Fix conversion of user certificate path in EAP settings
Fix a copy-paste error when converting NMSettingsConnection profiles to
IWD network config format.

Fixes: 9d22ae7981 ('wifi: Add utilities for writing IWD connection profiles')
2021-05-26 16:47:04 +02:00
Thomas Haller
8db23d47e4
ifcfg-rh: minor cleanup in svEscape() 2021-05-26 15:45:59 +02:00
Thomas Haller
370316fc3e
ifcfg-rh: allocate exact buffer in _escape_ansic()
Previously, we would allocate a buffer of the worst case, that is,
4 times the number of bytes, in case all of them require octal escaping.

Coverity doesn't like _escape_ansic() for another reason:

   Error: NULL_RETURNS (CWE-476): [#def298]
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: returned_null: "g_malloc" returns "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: alias: Assigning: "q" = "dest = g_malloc(strlen(source) * 4UL + 1UL + 3UL)". Both pointers are now "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:163: dereference: Incrementing a pointer which might be null: "q".
   #  161|       q = dest = g_malloc(strlen(source) * 4 + 1 + 3);
   #  162|
   #  163|->     *q++ = '$';
   #  164|       *q++ = '\'';
   #  165|

It doesn't recognize that g_malloc() shouldn't return NULL (because
we never request zero bytes).

I am not sure how to avoid that, but let's rework the code to first count
how many characters we exactly need. It think that should also help with
the coverity warning.

Doing exact allocation requires first to count the number of required
bytes. It still might be worth it, because we might keep the allocated
strings a bit longer around.
2021-05-26 15:45:59 +02:00
Thomas Haller
174f7bd27b
core: rework string handling in enslave_slave()
Coverity doesn't like the previous code:

  Error: RESOURCE_LEAK (CWE-772): [#def34] [important]
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: alloc_fn: Storage is returned from allocation function "g_strdup".
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: noescape: Resource "g_strdup(config)" is not freed or pointed-to in "g_strdelimit".
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: leaked_storage: Failing to save or free storage allocated by "g_strdup(config)" leaks it.
  #  833|                       char *sanitized_config;
  #  834|
  #  835|->                     sanitized_config = g_strdelimit(g_strdup(config), "\r\n", ' ');
  #  836|                       err = teamdctl_port_config_update_raw(priv->tdc, slave_iface, sanitized_config);
  #  837|                       g_free(sanitized_config);

Maybe this works better.
2021-05-25 13:56:42 +02:00
Thomas Haller
ff9f2d27ec
bluetooth: ensure function-like behavior of _LOG_bzobj() macro
We want that macros behave like functions, in that they evaluate all
their arguments exactly once.
2021-05-25 13:27:26 +02:00
Fernando Fernandez Mancera
38246b1802 ifcfg: fix wired reader for ACCEPT_ALL_MAC_ADDRESSES key
When the ACCEPT_ALL_MAC_ADDRESSES key is found by the wired reader, the
wired setting was not being created.

Fixes: d946aa0c50 ('wired-setting: add support to accept-all-mac-addresses')
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-05-19 08:40:41 +00:00
Beniamino Galvani
a3f35ea5cc ovs: block auto activation of ovs-interfaces until ovsdb is ready
Otherwise the device tries to activate too early and fails.
2021-05-19 10:29:11 +02:00
Beniamino Galvani
e694f2cec1 manager: fix active_connection_find()
Commit 33b9fa3a3c ("manager: Keep volatile/external connections
while referenced by async_op_lst") changed active_connection_find() to
also return active connections that are not yet activating but are
waiting authorization.

This has side effect for other callers of the function. In particular,
_get_activatable_connections_filter() should exclude only ACs that are
really active, not those waiting for authorization.

Otherwise, in ensure_master_active_connection() all the ACs waiting
authorization are missed and we might fail to find the right master
AC.

Add an argument to active_connection_find to select whether include
ACs waiting authorization.

Fixes: 33b9fa3a3c ('manager: Keep volatile/external connections while referenced by async_op_lst')

https://bugzilla.redhat.com/show_bug.cgi?id=1955101
2021-05-19 10:29:11 +02:00
Thomas Haller
aef9b95aaa
dhcp: map "static" DHCP state for dhcpcd to bound
A user might configure /etc/dhcpcd.conf to contain static fallback addresses.
In that case, the dhcpcd plugin reports the state as "static". Let's treat
that the same way as bound.

Note that this is not an officially supported or endorsed way of
configuring fallback addresses in NetworkManager. Rather, when using
DHCP plugins, the user can hack the system and make unsupported
modifications in /etc/dhcpcd.conf or /etc/dhcp. This change only makes
it a bit easier to do it.

See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/579#note_922758

https://bugzilla.gnome.org/show_bug.cgi?id=768362

Based-on-patch-by: gordonb3 <gordon@bosvangennip.nl>
2021-05-19 09:21:48 +02:00
Thomas Haller
75a64dd199
core: add nm_l3_config_data_iter_ip_{address,route}_for_each() helpers 2021-05-18 09:41:55 +02:00
Thomas Haller
4d929cc023
l3cfg: add more getters to NML3ConfigData 2021-05-18 09:41:55 +02:00
Thomas Haller
0abc14b3a0
core: remove unused best_ip_config_[46] field in NMDnsManager 2021-05-18 09:41:54 +02:00
Thomas Haller
55b722820d
l3cfg: fix nm_l3_config_data_new_clone() to make exact copy
We use the merge function to initialize the cloned instance.
Previously, merge did not always copy all properties, so the
cloned instance might not have been identical. Fix that.
2021-05-18 09:41:54 +02:00
Thomas Haller
71eefff6e7
core: return instance from nm_dhcp_lease_ref()/nm_dhcp_lease_unref() for convenience 2021-05-18 09:41:53 +02:00
Thomas Haller
4ef4201b0a
core: make IS_IPv4 variable an "int" type
gboolean is a typedef for int, so there is no difference in behavior.
However, we use IS_IPv4 as index into arrays of length two. Making
it "int" seems more approriate. Also, this is what all the other
(similar) code does.
2021-05-18 09:41:53 +02:00
Thomas Haller
bb1a495213
device: refactor dhcp-anycast-address handling for OLPC mesh device
dhcp-anycast-address is only set by OLPC mesh device. It's ugly to have
this in form of a nm_device_set_dhcp_anycast_address() method, because
that means to cache the address in NMDevice. Meaning, we have more state
in NMDevice, where it's not clear where it comes from.

Instead, whenever we need to DHCP anycast address, as the subclass to
provide it (if any). This way, it gets extracted from the currently
applied connection at the moment when it is needed. Beyond that, the
setting is not duplicated/cached in NMDevice anymore.
2021-05-18 09:41:53 +02:00
Thomas Haller
5aa7e254bd
dhcp: refactor DHCP anycast_address to be property of NMDhcpClient
Instead of passing the setting on during ip4_start()/ip6_start(), make
it a property of NMDhcpClient.

This property is currently only set by OLPC devices, and is only
implemented by NMDhcpDhclient. As such, it also does not need to change
or get reset. Hence, and immutable, construct-only property is clearer,
because we don't have to pass parameters to ip[46]_start().

Arguably, the parameter is still there, but being immutable and always
set, make it easier to reason about it.
2021-05-18 09:41:52 +02:00
Thomas Haller
98a89a05ec
core: explicitly disable ethtool.pause-autoneg when setting pause-rx/pause-tx
Kernel will coerce values like

    ethtool -A eth0 autoneg on rx off

to have autonet still on.

Also, if autoneg on the interface is enabled, then `ethtool  -A eth0 tx off`
has no effect.

In NetworkManager, the user cannot configure "autoneg on" together with
any rx/tx settings. That would render the profile invalid. However, we
also need to take care that a profile

  nmcli connection add ... ethtool.pause-autoneg ignore ethtool.pause-tx off

really means off. That means, we must coerce an unspecified autoneg
setting to "off".
2021-05-17 23:31:21 +02:00
Beniamino Galvani
e67ddd826f device: commit MTU during stage2
Currently we commit the MTU to the device when updating the IP
configuration, or when a port device is added to the controller. This
means that for a connection with DHCP, the MTU is set only after DHCP
has completed. In particular, if DHCP doesn't complete and the
connection has an infinite timeout, the MTU is never set.

_commit_mtu() tracks different sources for the MTU of a device, and
each source has a different priority. Among these sources there are
the parent link (for VLANs), a dynamic IP configuration (DHCP, PPP)
and the connection profile.

A MTU from the connection always has the highest priority and
overrides other sources.

Therefore, if the connection specifies an MTU it can be applied at
stage2, even before configuring IP addressing.

https://bugzilla.redhat.com/show_bug.cgi?id=1890234
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/859
2021-05-17 16:20:36 +02:00