Commit graph

13892 commits

Author SHA1 Message Date
Thomas Haller
87f2c7bc6c
config: use nm_streq() instead of strcmp() 2021-03-23 14:26:56 +01:00
Thomas Haller
3f07bda2a7
wifi: minor cleanup in "nm-wifi-utils.c" 2021-03-23 14:26:38 +01:00
Andrew Zaborowski
4229c97012
iwd: Mirror NM connections to IWD network config files
Watch for NMSettingConnection changes and creation signals and convert
them to IWD format and write them to the configured IWD profile storage
directory.  The logic is off by default and gets enabled when the new
iwd-config-path setting in nm.conf's [main] group is set to a path to
an existing directory.

The idea here is that when a user edits an NM connection profile, the
change is immediately mirrored in IWD since IWD watches its
configuration directory using inotify.  This way NM clients can be used
to edit 802.1x settings, the PSK passphrase or the SSID -- changes that
would previously not take effect with the IWD backend.

Some precautions are taken to not make connections owned by a user
available to other users, such connections are not converted at all.
In all other cases where a connection cannot be converted sufficiently
well to the IWD format, for various reasons, we also give up and not
mirror these connections.

Due to IWD limitations and design differences with NM this logic has
many problems where it may not do its task properly.  It's meant to work
on a best-effort and "better than nothing" basis, but it should be safe
in that it shouldn't delete users data or reveal secrets, etc.  The most
obvious limitation is that there can be multiple NM connections
referring to the same SSID+Security tuple and only one IWD profile can
exist because the filename is based on only the SSID+Security type.  We
already had one NM connection selected for each IWD KnownNetwork and
referenced by a pointer, so we ignore changes in NM connections other
than that selected one.
2021-03-23 14:24:42 +01:00
Andrew Zaborowski
9d22ae7981
wifi: Add utilities for writing IWD connection profiles
Add code that can take an NMConnection and convert it to the IWD
network config file format so as to be able to mirror NM connection
profiles to IWD connection profiles and make basic editing IWD
profile possible from nm-connection-editor.  The focus here is on 802.1x
settings.
2021-03-23 14:24:42 +01:00
Thomas Haller
e922404990
libnm,core: support "prohibit"/"blackhole"/"unreachable" type routing rules 2021-03-23 14:19:39 +01:00
Thomas Haller
972d1ba046
libnm,core: support "uidrange" parameter for routing rules 2021-03-23 14:19:38 +01:00
Thomas Haller
ba72d5a7e7
libnm: use binary search to lookup D-Bus info for routing-rules 2021-03-23 14:19:38 +01:00
Thomas Haller
945612cc5d
all: use nm_net_aux_rtnl_rtntype_{n2a,a2n}() helpers 2021-03-23 14:19:38 +01:00
Thomas Haller
0ef94bd1f0
base: add nm_net_aux_rtnl_rtntype_{n2a,a2n}() helpers 2021-03-23 14:19:37 +01:00
Thomas Haller
5852cd2252
base: add "nm-net-aux.c" helper 2021-03-23 14:19:37 +01:00
Thomas Haller
95208e0655
glib-aux: fix NM_AUTO_PROTECT_ERRNO() macro 2021-03-23 14:19:37 +01:00
Thomas Haller
54edfc6139
libnm: improve detection for C11 _Generic() support
Older gcc doesn't like this:

  ../src/libnm-core-impl/nm-setting-wired.c:132:49: error: controlling expression type 'const char *const [31]' not compatible with any generic association type
             && (nm_utils_strv_find_binary_search(valid_s390_opts,
                                                  ^~~~~~~~~~~~~~~
  ../src/libnm-glib-aux/nm-shared-utils.h:2033:60: note: expanded from macro 'nm_utils_strv_find_binary_search'
          const char *const *const _strv   = NM_CAST_STRV_CC(strv);     \
                                                             ^
  ../src/libnm-glib-aux/nm-macros-internal.h:706:21: note: expanded from macro 'NM_CAST_STRV_CC'
          (_Generic ((value), \
                      ^
2021-03-22 15:54:47 +01:00
Thomas Haller
33a69bbde6
refstr: be extra careful about calling memcpy() with dangling pointer 2021-03-19 12:05:08 +01:00
Thomas Haller
4f935d1d6b
refstr: add NM_REF_STRING_UPCAST() helper
Imaging you track a list of NMRefString instances. You could
directly expose them as strv array, but then you need a way
from the string back to the NMRefString instance.

That's easy to do. Add NM_REF_STRING_UPCAST() for that.
2021-03-19 12:05:08 +01:00
Thomas Haller
8ba67aa705
refstr: use nm_assert_nm_ref_string() in NM_IS_REF_STRING() 2021-03-19 12:05:08 +01:00
Thomas Haller
19d4027824
refstr: inline nm_ref_string_{ref,unref}()
In the fast path, ref/unref is just a atomic increment/decrement of an
integer. Let's inline that.
2021-03-19 12:05:08 +01:00
Thomas Haller
bec8928341
refstr: drop internal struct RefString and pack NMRefString
Previously, NMRefString was the public part of the struct, while
there was an internal RefString struct with private fields.
That might make sense if we would need to preserve some stable ABI, but
we don't because this is all internal (unstable) API. It also might
make sense to hide fields, but in practice that is not necessary
because the leading underscore is indicator enough that these are
private fields that are not supposed to be touched (unless you really
know what you do). So, drop RefString and move all fields in the public
NMRefString. The advantage is that we can later inline certain trivial
functions, that we otherwise couldn't.

Also, drop the "str" pointer and only use the "str" array field. The
pointer existed so that during nm_ref_string_new_len() we could create
a lookup needle with external str pointer. That is now solved
differently by using "len == G_MAXSIZE" as indicator that this is
a special lookup instance. The advantage is that we save one pointer
field per NMRefString, that we reduce the redundancy of the data, and
that we don't need the additional indirection.
2021-03-19 12:05:08 +01:00
Thomas Haller
51ff2865c3
refstr: drop "const" from argument of NM_IS_REF_STRING()
NMRefString has only const fields itself, and all operations (except
ref/unref) don't mutate the instance. As such, the type is already
immutable, and using "const" is redundant and unnecessary.

Drop "const" from all API of NMRefString.
2021-03-19 12:05:08 +01:00
Thomas Haller
571fdaafac
tests/client: rework error handling in "test-client.sh" script
The script runs with "set -e", as such `cmd && r=ok` seems wrong.
It worked apparently, but I don't understand why. Anyway, change
it.

Fixes: e643703418 ('tests/client: run "test-client.py" also for meson')
2021-03-19 11:43:19 +01:00
Thomas Haller
c2265dd8a9
Revert "tests/client: increase timeout to wait for process"
This didn't help and was not necessary. Instead, there was an issue
that is fixed now.

This reverts commit b4c25f9131.
2021-03-19 11:35:18 +01:00
Thomas Haller
489c5f8cd8
tests/client: ensure that we run nmcli before client tests for LTO (again)
See also commit 00e3fc036a ('clients/tests: ensure that we run nmcli
before client tests for LTO').

With the latest rework that code was dropped and tests (with LTO) are
broken as they hit a timeout (aside taking much longer).

Fixes: e643703418 ('tests/client: run "test-client.py" also for meson')
2021-03-19 11:35:18 +01:00
Thomas Haller
db773fd54e
dispatcher: set G_LOG_DOMAIN to "nm-dispatcher"
Originally, we would define G_LOG_DOMAIN via CFLAGS arguments.
Since commit 341b6e0704 ('all: change G_LOG_DOMAIN to "nm"') we would
instead set it in source and uniformly define it as "nm".

The reasons are that most parts of our source should not use g_log() directly,
and there is an aim to avoid special CFLAGS to simplify the build setup.

However, dispatcher indeed uses g_log() for logging, so the value there
is important.

Fix that, but this time by setting the define in source not via
CFLAGS.

Fixes: 341b6e0704 ('all: change G_LOG_DOMAIN to "nm"')
2021-03-18 16:54:00 +01:00
Thomas Haller
008302aa4e
all: use NM_IW_ESSID_MAX_SIZE define instead of literally 32 2021-03-18 11:38:21 +01:00
Thomas Haller
cd00b04099
libnm: expose NM_IW_ESSID_MAX_SIZE define 2021-03-18 11:30:56 +01:00
Andrew Zaborowski
1708e9a3cc
iwd: Don't call IWD methods when device unmanaged
When using IWD-side autoconnect mode (current default), in .deactivate()
and .deactivate_async() refrain from commanding IWD to actually
disconnect until the device is managed.  Likely the device is already
disconnected but in any case it's up to IWD to decide in this mode.

Calling IWD device's .Disconnect() D-Bus method has the side effect of
disabling autoconnect and doing this while NM is still in platform-init
was unexpectedly leaving the device without autoconnect after
platform-init was done, according to user reports.

Fixes: dc0e31fb70 ('iwd: Add the wifi.iwd.autoconnect setting')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/786
2021-03-18 10:28:38 +01:00
Thomas Haller
758fbd7aac
glib-aux: use g_cancellable_connection() in nm_utils_invoke_on_idle() and cleanup
Use g_cancellable_connect(). That approach better handles the case where the
cancellable is already cancelled. Theoretically, we could extend that
approach further and make it thread-safe, but in the current form is
nm_utils_invoke_on_idle() not thread-safe.

While at it, also cleanup duplicate code during completion.
2021-03-18 10:23:46 +01:00
Thomas Haller
b4c25f9131
tests/client: increase timeout to wait for process
We now get unit test failures hitting this timeout. That is
likely a new bug introduced somewhere, but to rule out that
the timeout is simply too short, increase it.
2021-03-17 10:57:52 +01:00
Beniamino Galvani
0f8fe3c76b initrd: fix crash parsing empty rd.znet argument
Ignore a rd.znet argument without subchannels. When using net.ifnames
(the default), subchannels are used to build the interface name, which
is required to match the right connection.

With net.ifnames=0 the interface name is build using a prefix and a
global counter and therefore in theory it is possible to omit
subchannels. However, without subchannels there won't be a udev rule
that renames the interface and so it can't work.

https://bugzilla.redhat.com/show_bug.cgi?id=1931284
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/783
2021-03-17 10:02:09 +01:00
Thomas Haller
c91dfb850e
initrd: avoid cloning string in reader_parse_rd_znet()
The code did:

   key    = g_strndup(tmp, val - tmp);
   val[0] = '\0';

That is pointless. If we strndup the key, we don't need to truncate
the string at the '='. It might be nicer not to mutate the input string,
however, the entire code with "argument" parsing is about mutating the
input string, so that is something we apparently are fine with.

As such, don't clone the string anymore.
2021-03-16 11:58:09 +01:00
Thomas Haller
bb132cd6de
libnm: verify ethernet.s390-options.bridge_role value
I don't want to fix this for all "ethernet.s390-options" options,
but at least strictly validate the newly introduced option.
2021-03-16 11:56:31 +01:00
Thomas Haller
a9e4d020cb
shared/tests: add nmtst_rand_select_str() helper 2021-03-16 11:56:29 +01:00
Thomas Haller
b377a7d0c9
trivial: fix whitespace for comments in "libnm-glib-aux/nm-macros-internal.h" 2021-03-16 09:58:48 +01:00
Thomas Haller
6e4cdae256
all: split "range" variant of nm_utils_ptrarray_find_binary_search()
nm_utils_ptrarray_find_binary_search() had two additional output
arguments: the first and last index -- in case the sorted list contains
duplicates.

That's nice, and was used in the past. But now, those output arguments
are no longer used.

So drop them from nm_utils_ptrarray_find_binary_search().

Actually, we could now also drop the previous variant
nm_utils_ptrarray_find_binary_search_range(), as it's only used by unit
tests. However, although not rocket science, getting this right is not
entirely trivial, so lets keep the code in case we need it again.
2021-03-16 09:55:49 +01:00
Thomas Haller
7fde244ed2
libnm: don't assert against valid s390-option keys in nm_setting_wired_add_s390_option()
Asserting against user input is not nice, because it always requires the
caller to check the value first. Don't do that.

Also, don't even check. You can set NM_SETTING_WIRED_S390_OPTIONS
property to any values (except duplicated keys). The C add function
should not be more limited than that. This is also right because
we have verify() which checks for valid settings. And it does so beyond
only checking the keys.

So you could set NM_SETTING_WIRED_S390_OPTIONS properties to invalid
keys. And you could use nm_setting_wired_add_s390_option() to set
invalid values. No need to let nm_setting_wired_add_s390_option() check
for valid keys.
2021-03-16 09:55:49 +01:00
Thomas Haller
74a4ee16f5
initrd: silently ignore invalid "ethernet.s390-options" 2021-03-16 09:55:48 +01:00
Thomas Haller
e25c458b6f
libnm: add _nm_setting_wired_is_valid_s390_option_value() validation function 2021-03-16 09:55:48 +01:00
Thomas Haller
ddc41d427a
libnm: add internal _nm_setting_wired_is_valid_s390_option() helper 2021-03-16 09:55:48 +01:00
Thomas Haller
fb0ac2e700
libnm: cleanup nm_setting_wired_add_s390_option()
- integers are unsigned. Mark the constants as such.

- assert that we don't overflow G_MAXUINT32. Note that
  nm_setting_wired_get_s390_option()'s index argument
  is of type guint32. So with that API you cannot track
  more than G_MAXUINT32 elements.

- use nm_utils_strdup_reset(). It's less code, but it's
  also self-assignment safe (contrary to the previous code).
2021-03-16 09:55:48 +01:00
Thomas Haller
9f93b0495b
libnm: improve error message for verify() failure for ethernet.s390-options 2021-03-16 09:55:48 +01:00
Thomas Haller
1794d80028
libnm: mark option parameters for nm_setting_wired_get_num_s390_options() as (allow-none) 2021-03-16 09:55:48 +01:00
Thomas Haller
dccfe1df34
libnm: use nm_utils_strv_find_binary_search() in valid_s390_opts_check() 2021-03-16 09:55:48 +01:00
Thomas Haller
b9d73cfb2d
libnm: only check once for valid static array in valid_s390_opts_check()
No need to check every time. The buffer is a const global buffer,
so checking it once is enough.
2021-03-16 09:55:48 +01:00
Thomas Haller
80c98b60da
libnm: make list of valid s390s options const
A const global variable is stored in immutable memory.
You thus get a crash trying to modify it, which is desirable.

The user is really not supposed to modify this buffer,
even if nm_setting_wired_get_valid_s390_options() wrongly
returns a non-const pointer.
2021-03-16 09:55:48 +01:00
Thomas Haller
ec6e9f0cac
core: minor cleanup in NMDeviceEthernet:update_connection() to set s390 options
We should have variables of the correct type and cast where necessary,
and not use void pointers.
2021-03-16 09:55:47 +01:00
Thomas Haller
07610da4ca
shared: add mutable union field NMUtilsNamedValue.{name,value_str}_mutable
NMUtilsNamedValue is a generic tuple that we use for different purposes.
Often we require a mutable string, so add a union alias for that case.
2021-03-16 09:55:47 +01:00
Thomas Haller
ca869bff9f
shared: add nm_utils_strv_find_binary_search() helper 2021-03-16 09:55:47 +01:00
Thomas Haller
e4aa3f4b2d
libnm: add "bridge_role" option to "ethernet.s390-options"
https://bugzilla.redhat.com/show_bug.cgi?id=1935842
2021-03-16 09:02:07 +01:00
Wen Liang
ec3e2561a8
libnm/doc: document the type of each LLDP attribute of libnm
Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/777
2021-03-15 17:40:14 +01:00
Thomas Haller
e643703418
tests/client: run "test-client.py" also for meson 2021-03-15 17:10:56 +01:00
Thomas Haller
019bc3233a
client/tests: move "clients/tests/test-client.py" to "src/tests/client/"
Note that "test-client.py" currently only tests nmcli. But what it does
is to spawn test-networkmanager-service.py and run nmcli against it.

As such, it could really be used to test any NetworkManager client
against the stub service. Hence this test is not under
"src/nmcli/tests", but under "src/tests/client/" where it is more
general.
2021-03-15 17:10:55 +01:00