Commit graph

28030 commits

Author SHA1 Message Date
Wen Liang
2e96cdfe5e CONTRIBUTIING: add chapter describing Cscope and code structure
Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/792
2021-03-24 16:42:40 +01:00
Thomas Haller
fbabfa5e36
core: merge branch 'th/local-route-sync'
https://bugzilla.redhat.com/show_bug.cgi?id=1907661

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/790
2021-03-24 14:21:02 +01:00
Thomas Haller
557644f5e0
core: don't add dependent local route for addresses
When adding an IPv4 address, kernel automatically adds a local route.
This is done by fib_add_ifaddr(). Note that if the address is
IFA_F_SECONDARY, then the "src" is the primary address. That means, with

  nmcli connection add con-name t type ethernet ifname t autoconnect no \
     ipv4.method manual ipv6.method disabled \
     ipv4.addresses '192.168.77.10/24, 192.168.77.11/24'

we get two routes:

  "local 192.168.77.10 dev t table local proto kernel scope host src 192.168.77.10"
  "local 192.168.77.11 dev t table local proto kernel scope host src 192.168.77.10"

Our code would only generate instead:

  "local 192.168.77.10 dev t table local proto kernel scope host src 192.168.77.10"
  "local 192.168.77.11 dev t table local proto kernel scope host src 192.168.77.11"

Afterwards, this artificial route will be leaked:

    #!/bin/bash

    set -vx

    nmcli connection delete t || :
    ip link delete t || :

    ip link add name t type veth peer t-veth

    nmcli connection add con-name t type ethernet ifname t autoconnect no ipv4.method manual ipv4.addresses '192.168.77.10/24, 192.168.77.11/24' ipv6.method disabled

    nmcli connection up t

    ip route show table all dev t | grep --color '^\|192.168.77.11'

    sleep 1

    nmcli device modify t -ipv4.addresses 192.168.77.11/24

    ip route show table all dev t | grep --color '^\|192.168.77.11'

    ip route show table all dev t | grep -q 192.168.77.11 && echo "the local route 192.168.77.11 is still there, because NM adds a local route with wrong pref-src"

It will also be leaked because in the example above ipv4.route-table is
unset, so we are not in full route sync mode and the local table is not
synced.

This was introduced by commit 3e5fc04df3 ('core: add dependent local
routes configured by kernel'), but it's unclear to me why we really need
this. Drop it again and effectively revert commit 3e5fc04df3 ('core:
add dependent local routes configured by kernel').

I think this "solution" is still bad. We need to improve our route sync
approach with L3Cfg rework. For now, it's probably good enough.

https://bugzilla.redhat.com/show_bug.cgi?id=1907661
2021-03-23 22:30:32 +01:00
Thomas Haller
fe1bf4c907
core: minor cleanup in nm_platform_ip_route_get_prune_list() 2021-03-23 17:56:47 +01:00
Thomas Haller
c29d995000
core: don't add ff00::/8 unicast route to nm_ip6_config_add_dependent_routes()
This effectively reverts commit cd89026c5f ('core: add dependent
multicast route configured by kernel for IPv6').

It's not clear to me why this was done or why it would be correct.

True, kernel automatically adds multicast route like

  multicast ff00::/8 dev $IFACE table local proto kernel metric 256 pref medium

But NetworkManager ignores all multicast routes for now. So the dependent
routes cannot contain multicast routes as they are not handled. Also,
the code added a unicast route, so I don't understand why the comment
is talking about multicast.

This seems just wrong. Drop it.
2021-03-23 17:56:47 +01:00
Thomas Haller
e226b5eb82
core: add NM_IP_ROUTE_TABLE_SYNC_MODE_ALL_PRUNE mode
When we deactivate a device, we flush all IP addresses and
routes. Thus, have yet another sync mode for that. It will sync more
than "ALL".
2021-03-23 17:56:46 +01:00
Thomas Haller
f6db2c6261
core: log route-table-sync-mode in nm_device_set_ip_config() 2021-03-23 17:56:46 +01:00
Thomas Haller
5da8c073ef
core: avoid logging pointer value in nm_device_set_ip_config() 2021-03-23 17:56:46 +01:00
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
Thomas Haller
bf564937bb
wifi/iwd: merge branch 'balrog-kun:write-iwd-configs'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/695
2021-03-23 14:25:31 +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
62cd7682d9
core: merge branch 'th/routing-rule-attr-uidrange-and-type'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/788
2021-03-23 14:21:16 +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
067893f8d3
gitignore: ignore "examples/C/glib/vpn-import-libnm" 2021-03-22 21:51:36 +01:00
Thomas Haller
fd17c874eb
build: fix race due to missing dependency for libnm-core-null to "config-extra.h"
In file included from ./src/libnm-glib-aux/nm-default-glib.h:11:0,
                   from ./src/libnm-glib-aux/nm-default-glib-i18n-lib.h:13,
                   from src/libnm-log-null/nm-logging-null.c:6:
  ./src/libnm-std-aux/nm-default-std.h:32:26: fatal error: config-extra.h: No such file or directory
   #include "config-extra.h"
                            ^
  compilation terminated.
  make[1]: *** [src/libnm-log-null/src_libnm_log_null_libnm_log_null_la-nm-logging-null.lo] Error 1
2021-03-22 17:35:35 +01:00
Thomas Haller
3348901df3
examples: fix exit from "vpn-import-libnm.c" example
../examples/C/glib/vpn-import-libnm.c: In function main:
  ../examples/C/glib/vpn-import-libnm.c:72:1: error: control reaches end of non-void function [-Werror=return-type]
   }
   ^

Fixes: 905f9975d2 ('example: importing vpn with libnm')
2021-03-22 16:29:14 +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
Jagadeesh Kotra
905f9975d2
example: importing vpn with libnm
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/789
2021-03-22 15:54:07 +01:00
Thomas Haller
91bf576a43
build: fix detection of python for autotools
The goal of this code is to detect python, but prefer python3 while
also allowing the user to override the path.

That did not work in all cases, due to what seems like a bug in
AM_PATH_PYTHON(). AM_PATH_PYTHON() is documented to ignore failure
if [action-if-not-found] is given. So one might assume that:

  AM_PATH_PYTHON([3], [], [PYTHON=])
  if test -z "$PYTHON"; then
    AM_PATH_PYTHON([], [], [PYTHON=python])
  fi

first tries to look for v3, and if that fails search for any python
interpreter. That did not work however with:

  $ ./configure PYTHON=/usr/bin/python2
  ...
  checking pkg-config is at least version 0.9.0... yes
  checking whether /usr/bin/python2 version is >= 3... no
  configure: error: Python interpreter is too old

because the first AM_PATH_PYTHON() is fatal.

Work around that.

Fixes: 54a1cfa973 ('build: prefer python3 over python2 in autotools's configure script')
2021-03-22 12:31:02 +01:00
Thomas Haller
5a20d96f36
man: clarify keyfile.unmanaged-devices in man NetworkManager.conf 2021-03-20 10:43:54 +01:00
Thomas Haller
ed172287da
glib-aux: merge branch 'th/refstr-inline'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/787
2021-03-19 12:07:15 +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
9c0c0ac966
man: split NetworkManager-dispatcher(8) manual page out of NetworkManager(8)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/784
2021-03-16 17:01:53 +01:00
Thomas Haller
ed6621bdcd
CONTRIBUTING: style fixes and improve text 2021-03-16 14:29:08 +01:00
Thomas Haller
fb66bb2bcb
CONTRIBUTING: rename file to have .md extension
We should write our CONTRIBUTING files in markdown syntax, because
it's nice to read a plain text and gets nicely rendered.

However, if the file doesn't have a ".md" extension, gitlab's
web interface shows it as plain text file.

Rename the file.

This possibly breaks links like [1], but referring to a branch name
(and not a commit ID or a tag) is anyway fragile. Hence, I don't try
to fix that by adding a symlink or similar, because I think that just
makes it more confusing.

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/master/CONTRIBUTING
2021-03-16 14:00:01 +01:00
Thomas Haller
aaf2c5c2dd
man: document NOZEROCONF in man nm-settings-ifcfg-rh 2021-03-16 13:45:39 +01:00
Thomas Haller
e91acb2806
libnm/s390: Merge branch 'th/s390-option-bridge-role'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/782
2021-03-16 13:17:56 +01:00