Commit graph

28511 commits

Author SHA1 Message Date
Thomas Haller
1ccfde7ee6
libnm/tests: add test for NM_NARG() with 120 parameters 2021-06-08 08:24:11 +02:00
Thomas Haller
f98d47f77d
glib-aux: implement varidic macros NM_UTILS_{LOOKUP,ENUM2STR}_DEFINE() with NM_VA_ARGS_JOIN()
The previous implementation of these macros simply relied on the
__VA_ARGS__ to be expended and joined with ','. That make that work
inside the switch statement, the macros expanded to

   switch (val) {
       (void) 0, (void) 0;
   case 0x1:
       s = " ""value" "";
       break;
       (void) 0, (void) 0;
   };

Those NOP statements cause lgtm.com to complain "Dead code due to goto
or break statement".

Implement these macros differently using NM_VA_ARGS_JOIN().
2021-06-08 08:24:11 +02:00
Thomas Haller
0ed95698fd
std-aux: implement NM_IN_SET()/NM_IN_STRSET() via NM_VA_ARGS_FOREACH() 2021-06-08 08:24:11 +02:00
Thomas Haller
34a521e2d6
std-aux: add NM_VA_ARGS_JOIN() helper macro
We have variadic macros like NM_UTILS_ENUM2STR() that create a switch
statement. Their implementation relies on the way how __VA_ARGS__
gets expanded to a comma separated list. But that implementation is
not great. Let's instead add (and later use) NM_VA_ARGS_JOIN() which
can join variadic arguments by a configurable separator.
2021-06-08 08:24:11 +02:00
Thomas Haller
dadaba9ab6
std-aux: add NM_VA_ARGS_FOREACH() helper macro 2021-06-08 08:24:10 +02:00
Thomas Haller
9823ae75e5
std-aux: add _NM_MACRO_IDENTITY(), _NM_MACRO_CALL2(), _NM_MACRO_SELECT_FIRST()
_NM_MACRO_CALL2() is needed, because we cannot call _NM_MACRO_CALL() inside
_NM_MACRO_CALL().
2021-06-08 08:24:10 +02:00
Thomas Haller
2c3abc7bcb
std-aux,glib-aux: move NM_NARG() and _NM_MACRO_CALL() to lib-std-aux 2021-06-08 08:24:10 +02:00
Thomas Haller
bea061affc
glib-aux: extend NM_NARG() macro for more arguments 2021-06-08 08:24:10 +02:00
Thomas Haller
89a10ddf89
std-aux: add NM_BIT() macro 2021-06-08 08:24:10 +02:00
Thomas Haller
4d6edd8419
docs: explain GObject properties in CONTRIBUTING.md 2021-06-07 18:08:23 +02:00
Thomas Haller
ddd6587a6f
libnm: assert initialization in _NM_OBJECT_CLASS_INIT_FIELD_INFO()
_NM_OBJECT_CLASS_INIT_FIELD_INFO() is a bit odd, because it defines a
static variable and initialized it at the moment when being "called".
This is in fact correct, because this code only gets called from inside
the _class_init() function, which is executed at most once.

Add an assertion to ensure that the static variables is not yet
initialized.
2021-06-07 17:33:02 +02:00
Thomas Haller
b92d8f5a2d
release: bump version to 1.33.0 (development) 2021-06-04 18:10:32 +02:00
Thomas Haller
be89b39828
release: bump version to 1.31.90 (1.32-rc1) 2021-06-04 18:03:56 +02:00
Thomas Haller
d18172bb2b
NEWS: update 2021-06-04 17:07:09 +02:00
Thomas Haller
b4a7330629
NEWS: update 2021-06-04 13:52:27 +02:00
Beniamino Galvani
fa832c6590 NEWS: update 2021-06-04 13:43:11 +02:00
Thomas Haller
8d01bf5d80
wifi/iwd: rework warning about invalid state-dir
- always remember priv->last_state_dir that we received via
  D-Bus. Only later, during get_config_path() we will check
  whether the path is valid.

- remember in priv->warned_state_dir the full path for
  which we warned. We want to print a warning for each
  path once, if the path changes, then we also want a new
  warning. A boolean flag cannot express that.
2021-06-04 13:36:38 +02:00
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
ebab9a32dc
NEWS: update 2021-06-04 10:11:51 +02:00
Thomas Haller
9784956442
NEWS: update 2021-06-04 10:04:26 +02:00
Peter van der Velde
91f31a2665
vapi: Update NM-1.0.metadata to include WireGuard declarations
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/874
2021-06-04 10:03:13 +02:00
Thomas Haller
0d928c670d
all: merge branch 'th/uuid-normalize'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/880
2021-06-04 09:47:30 +02:00
Thomas Haller
3699c31eb1
libnm/tests: add test for normalizing "connection.secondaries" 2021-06-04 09:42:38 +02:00
Thomas Haller
890df48d14
libnm: verify and normalize "connection.secondaries"
So far, we didn't verify the secondary connections at all.
But these really are supposed to be UUIDs.

As we now also normalize "connection.uuid" to be in a strict
format, the user might have profiles with non-normalized UUIDs.
In that case, the "connection.uuid" would be normalized, but
"connection.secondaries" no longer matches. We can fix that by
also normalizing "connection.secondaries". OK, this is not a very good
reason, because it's unlikely to affect any users in practice ('though
it's easy to reproduce).

A better reason is that the secondary setting really should be well
defined and verified. As we didn't do that so far, we cannot simply
outright reject invalid settings. What this patch does instead, is
silently changing the profile to only contain valid settings.
That has it's own problems, like that the user setting an invalid
value does not get an error nor the desired(?) outcome.
But of all the bad choices, normalizing seems the most sensible
one.

Note that in practice, most client applications don't rely on setting
arbitrary (invalid) "UUIDs". They simply expect to be able to set valid
UUIDs, which they still are. For example, nm-connection-editor presents
a drop down list of VPN profile, and nmcli also resolves connection IDs
to the UUID. That is, clients already have an intimate understanding of
this setting, and don't blindly set arbitrary values. Hence, this
normalization is unlikely to hit users in practice. But what it gives
is the guarantee that a verified connection only contains valid UUIDs.

Now all UUIDs will be normalized, invalid entries removed, and the list
made unique.
2021-06-04 09:29:25 +02:00
Thomas Haller
3acf62f8be
libnm: use GArray to track "connection.secondaries" property instead of GSList
GSList requires an additional allocation for the container struct for each
element. Also, it does not have O(1) direct access. It's a pretty bad
data structure, especially if the underlying data is in form of a strv
array.

Use a GArray instead and the nm_strvarray_*() helpers.
2021-06-04 09:29:24 +02:00
Thomas Haller
92136135ad
libnm: don't reject empty strings in add/remove API
For example for NM_SETTING_CONNECTION_SECONDARIES, the user can set
the GObject property to a string list that includes empty strings.

The C accessors (add/remove-by-value) should also accept any strings that
are accepted otherwise. Asserting against empty strings is wrong. If the
setting wants to reject empty strings, then it should use verify().
2021-06-04 09:29:24 +02:00
Thomas Haller
46533cd15f
libnm: use nm_strvarray_get_strv_non_empty_dup() in "nm-setting-match.c" 2021-06-04 09:29:24 +02:00
Thomas Haller
75c6c4abf8
libnm: use nm_strvarray_get_idx() in "nm-setting-match.c" 2021-06-04 09:29:23 +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
Thomas Haller
6ce7b3ca0f
glib-aux: add nm_uuid_is_valid_normalized() helper 2021-06-04 09:29:21 +02:00
Thomas Haller
8c6be1909f
glib-aux: add nm_strvarray_get_strv_non_empty_dup() helper 2021-06-04 09:29:21 +02:00
Thomas Haller
851267b6e7
glib-aux: add nm_strvarray_find_first() helper 2021-06-04 09:29:21 +02:00
Thomas Haller
b0acbe504f
glib-aux: add nm_strvarray_get_idx() helper 2021-06-04 09:29:21 +02:00
Thomas Haller
a266bc15b2
glib-aux: add nm_strv_has_duplicate() helper 2021-06-04 09:29:21 +02:00
Thomas Haller
9a0f3f3e09
glib-aux: add nm_utils_strv_dup_shallow_maybe_a() helper 2021-06-04 09:29:12 +02:00
Beniamino Galvani
74f9272d3d merge: branch 'bg/tc-ignore'
https://bugzilla.redhat.com/show_bug.cgi?id=1928078
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/871
2021-06-03 09:10:49 +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
04ae0d905c
NEWS: update 2021-06-02 23:13:59 +02:00
Thomas Haller
5d50e7d78d
Revert "libnm: introduce the new get_ports() in bridge/bond API"
Let's instead add a generic nm_device_get_ports() function.
Also, only adding new API is maybe not sufficient. We should
at the same time deprecate and alias the D-Bus API, like was done
for commit 067a3d6c08 ('nm-device: expose via D-Bus the 'hw-address'
property').

This reverts commit 754143f4e8.
2021-06-02 12:05:26 +02:00
Fernando Fernandez Mancera
754143f4e8
libnm: introduce the new get_ports() in bridge/bond API
This patch is introducing get_ports() in bridge and bond API. In
addition, the existing get_slaves() functions are being marked as
deprecated.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/878
2021-06-02 09:20:29 +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
bae22a45d8
lgtm: suppress lgtm[cpp/duplicate-include-guard] warning in ethtool header
lgtm.com doesn't like this:

  Query pack:com.lgtm/cpp-queries
  Query ID:cpp/duplicate-include-guard

  Using the same include guard macro in more than one header file may
  cause unexpected behavior from the compiler.

both for src/libnm-base/nm-ethtool-utils-base.h and
src/libnm-client-public/nm-ethtool-utils.h. But this is intentional,
because these two files are supposed to be identical (but compiled
twice, under different context).

Suppress the warning.
2021-06-01 17:54:07 +02:00
Thomas Haller
dd4cccbe66
lgtm: suppress [cpp/alloca-in-loop] warnings for lgtm.com
The warning is not right. There is no unguarded number of alloca()
calls inside a loop. Suppress the warnings.
2021-06-01 17:45:39 +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
ecd5d07b3a
glib-aux: move forward declaration of inet_ntop() out of function scope
lgtm.com doesn't like this:

  Query pack:com.lgtm/cpp-queries
  Query ID:cpp/function-in-block

  Functions should always be declared at file scope. It is confusing
  to declare a function at block scope, and the visibility of the function
  is not what would be expected.
2021-06-01 17:32:33 +02:00