Commit graph

15321 commits

Author SHA1 Message Date
Thomas Haller
cec1269795
keyfile: rename handle_warn() to read_handle_warn()
We will also want to warn during write.
2022-03-28 18:27:36 +02:00
Thomas Haller
cfe594903e
keyfile: simplify code path in write_setting_value()
Avoid nested blocks. Check one condition after the other and handle it.
2022-03-28 18:27:36 +02:00
Thomas Haller
a0db72bf6d
keyfile: use nm_setting_8021x_scheme_vtable_by_setting_key() helper in cert_writer() 2022-03-28 18:27:36 +02:00
Thomas Haller
e965aa2536
libnm: add nm_setting_8021x_scheme_vtable_by_setting_key() helper
Add function to lookup the vtable by name. Implement a binary search.
2022-03-28 18:27:36 +02:00
Thomas Haller
22dcfb3a67
libnm: fix update of cached option names in nm_setting_option_set()
This is severe. We cache the list of names, and we must invalidate the
cache when the names change. Otherwise, out-of-bound access and crash.

Fixes: d0192b698e ('libnm: add nm_setting_option_set(), nm_setting_option_get_boolean(), nm_setting_option_set_boolean()')
Fixes: 150af44e10 ('libnm: add nm_setting_option_get_uint32(), nm_setting_option_set_uint32()')
2022-03-28 18:27:35 +02:00
Thomas Haller
681926ad43
glib-aux: make nm_gobject_notify_together_full() macro more robust
If __VA_ARGS__ contains odd arguments, it's not clear that N_ARG() gives
the same as the array initialization. Add a static assert that the
numbers agree to catch wrong usage of the macro.

For example:

    nm_gobject_notify_together(setting, a, b, );
2022-03-28 18:27:35 +02:00
Lubomir Rintel
aba3401df0 cli: remove one more g_assert()
I pushed accidentally pushed commit 9702310f25 ('clients: bulk removal
of g_assert*() statements') earlier than I intended, without addressing
one more case introduced by preceding merge. Fix it now.

Fixes: 9702310f25 ('clients: bulk removal of g_assert*() statements')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1166
2022-03-28 15:04:07 +02:00
Lubomir Rintel
8dbe6fa0d5 merge: branch 'lr/conn-migrate'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1146
https://bugzilla.redhat.com/show_bug.cgi?id=2059608
2022-03-28 15:00:45 +02:00
Lubomir Rintel
1aa9c80b9b cli: add "connection migrate" subcommand
This is used to move a connection to a different settings plugin.
2022-03-28 14:59:30 +02:00
Lubomir Rintel
9702310f25 clients: bulk removal of g_assert*() statements
Assertions should be done in tests. If we detect an unexpected situation
at runtime, we shall fail more gracefully than crashing right away.
2022-03-28 13:51:44 +02:00
Lubomir Rintel
c7ab380a5c cli: fix handling of erroneous connections in "delete"
If we can't find a connection for any reason other than that it doesn't
exist, we should error out immediately and consistently, regardless of
whether we already encountered a non-existent connection.
2022-03-28 13:29:28 +02:00
Lubomir Rintel
e39e5d9372 cli: fix up help string for "delete"
Make it obvious that we can delete more connections in one go.
2022-03-28 13:29:28 +02:00
Lubomir Rintel
82d16789a5 settings-connection: add a "plugin" argument to Update2()
This will allow migrating a connection. If specified, the connection will
be confined to a particular settings plugin when written back. If the
plugin differs from the existing one, it will be removed from the old one.
2022-03-28 13:29:28 +02:00
Lubomir Rintel
f4f165f945 settings: add "plugin" argument to AddAndActivate2()
This will confine a newly added connection to a particular settings
plugin.
2022-03-28 13:29:28 +02:00
Daisuke Matsuda
fc2fab99b2
platform: add log detail for ENODEV at do_delete_object()
Deactivation of a NIC invokes deletion of qdisc. An ENODEV error can
be generated on deactivation of a virtual NIC when the kernel driver
has already deleted the device along with the qdisc.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1165
2022-03-28 10:52:01 +02:00
Thomas Haller
b1b1ee8cc4
libnm/tests: test that nm_vpn_service_plugin_read_vpn_details() does not consume "QUIT" command 2022-03-28 10:40:00 +02:00
Thomas Haller
6235815248
libnm: handle NUL characters in nm_vpn_service_plugin_read_vpn_details() and fix test
We expect to read NUL terminated strings. Upon NUL, we should do
something. Treat it as a line break.

Fixes: 8ae9cf4698 ('Revert "libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()"')
2022-03-28 10:36:05 +02:00
Bryan Jacobs
8ae9cf4698
Revert "libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()"
This partially reverts commit 4a9fcb0fc3, which replaced one-byte
reads with buffered ones in the VPN service plugin.

Unfortunately the buffering means that commands coming after the magic
"DONE" string were being pulled into the buffer. Secrets agents expect
a "QUIT" to come after the "DONE", and since with buffering "QUIT" was
in the buffer, this led to a twenty-second delay on every VPN
connection using a secrets manager.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1164

Fixes: 4a9fcb0fc3 ('libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()')
2022-03-28 09:39:13 +02:00
Christian Eggers
f6ec6ef364
core: create GMainLoop after daemonizing
The GMainLoop instance (and the default GMainContext singleton) is not
required for trivial operations like --print-config, --version or
--help). If running as SysV daemon, the event file descriptor is
unnecessarily dup'ed from the parent to the child process.

Signed-off-by: Christian Eggers <ceggers@arri.de>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1160
2022-03-22 13:43:41 +01:00
Thomas Haller
0614017ac6
dnsmasq/shared: drop "--dhcp-lease-max=50" option
It's not clear why this option is set or why it's necessary. It was
set ever since.

Note that we automatically determines the DHCP range
nm_dnsmasq_utils_get_range(), and with /24 subnets (or larger)
the range spans up to 244 addresses.

With such a DHCP range it doesn't seem to make sense to limit the
number of leases to 50. It also doesn't seem to make sense to limit it
at all. Drop this.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1156
2022-03-21 17:14:17 +01:00
Thomas Haller
aaf2155023
libnm/docs: fix documentation for "proxy.pac-script" 2022-03-21 15:21:37 +01:00
Thomas Haller
6b191d6ea7
dhcp: simplify nm_dhcp_client_set_effective_client_id()
The "take" parameter of _set_effective_client_id() was always "FALSE". Drop it.
Also, drop _set_effective_client_id() and just call nm_dhcp_client_set_effective_client_id()
directly.
2022-03-21 13:09:28 +01:00
Thomas Haller
874403b588
dhcp: use nm_g_bytes_equal0() in _set_effective_client_id() 2022-03-21 13:04:52 +01:00
Beniamino Galvani
9ac143d2d5 dhcp: fix memory leak
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-20 17:30:39 +01:00
Thomas Haller
b3192d2d46
device: allow reapply for changed "connection.autoconnect-slaves" property
We list the properties that can be reapplied, and reject the reapply
operation for any other changes. The idea is that usually reapply
of a property requires an explicit implementation (or may not make
sense).

"connection.autoconnect-slaves" is something that takes effect when
activating the master device. It does not matter when the device
is already active, thus there is no need to reject the reapply
operation.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1150
2022-03-18 15:36:43 +01:00
Thomas Haller
14b9a9bd9d
connectivity: fix constructing hosts list for CURLOPT_RESOLVE
Curl's CURLOPT_RESOLVE expects one list entry per host. That
documentation ([1]) also makes that clear that the form is
"[+]HOST:PORT:ADDRESS[,ADDRESS]".

The way we constructed the list, only the last entry was honored:

  <trace> [1647551393.5362] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:18.159.254.57' to curl resolve list
  <trace> [1647551393.5363] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:152.19.134.142' to curl resolve list
  <trace> [1647551393.5363] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:18.192.40.85' to curl resolve list
  ...
  <trace> [1647551393.5366] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:85.236.55.6' to curl resolve list
  <trace> [1647551393.5366] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:38.145.60.20' to curl resolve list
  ...
  <trace> [1647551393.5415] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:18.159.254.57 to DNS cache\012
  <trace> [1647551393.5416] connectivity: (eth0,IPv4,25) libcurl: == Info: RESOLVE fedoraproject.org:80 is - old addresses discarded!\012
  <trace> [1647551393.5416] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:152.19.134.142 to DNS cache\012
  <trace> [1647551393.5417] connectivity: (eth0,IPv4,25) libcurl: == Info: RESOLVE fedoraproject.org:80 is - old addresses discarded!\012
  ...
  <trace> [1647551393.5422] connectivity: (eth0,IPv4,25) libcurl: == Info: RESOLVE fedoraproject.org:80 is - old addresses discarded!\012
  <trace> [1647551393.5423] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:38.145.60.20 to DNS cache\012
  <trace> [1647551393.5424] connectivity: (eth0,IPv4,25) libcurl: == Info: Hostname fedoraproject.org was found in DNS cache\012
  <trace> [1647551393.5424] connectivity: (eth0,IPv4,25) libcurl: == Info:   Trying 38.145.60.20:80...\012

There are two possible fixes. Either join all addresses in one
entry, or use the '+' modifier. Do the former.

Now we get:

  <trace> [1647551967.0378] connectivity: (eth0,IPv4,25) set curl resolve list to 'fedoraproject.org:80:38.145.60.21,152.19.134.142,152...
  ...
  <trace> [1647551967.0559] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:38.145.60.21,152.19.134.142,152.1...
  <trace> [1647551967.0560] connectivity: (eth0,IPv4,25) libcurl: == Info: Hostname fedoraproject.org was found in DNS cache\012
  <trace> [1647551967.0561] connectivity: (eth0,IPv4,25) libcurl: == Info:   Trying 38.145.60.21:80...\012

[1] https://curl.se/libcurl/c/CURLOPT_RESOLVE.html

Reported-by: Bastien Nocera <hadess@hadess.net>

Fixes: 2cec94bacc ('connectivity: use systemd-resolved for resolving the check endpoint')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/648#note_1301596

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1153
2022-03-18 15:02:42 +01:00
Bastien Nocera
4e6b18e595 connectivity: Add debug to curl queries
Add debug output when we use curl to make queries.

References: https://curl.se/libcurl/c/debug.html
2022-03-17 20:41:31 +00:00
Thomas Haller
18d0ab14bc
device: drop unused variable and avoid compiler warning
../src/core/devices/nm-device-ethernet.c:1164:35: error: unused variable error [-Werror,-Wunused-variable]
              gs_free_error GError *error    = NULL;
                                    ^

Fixes: aa9b5e28eb ('ethernet: fix setting ip-ifindex for PPPoE connections')
2022-03-17 19:31:29 +01:00
Lubomir Rintel
feee84aac4 wifi: mark WEP connections incompatible if supplicant lacks capability
This allows us to reject activation of WEP profiles very early,
also providing a reasonable error code to the client:

  $ nmcli d wifi connect test
  Error: Failed to add/activate new connection: wpa_supplicant does not support WEP encryption
2022-03-17 12:44:53 +01:00
Lubomir Rintel
41d03a1b17 supplicant: check whether WEP is available
Since version 2.10, it's possible to build wpa_supplicant without WEP
support. In fact, it's disabled by default. Regrettably, there's no
indication in that version as to whether WEP is enabled or not.

A patch has been sent upstream that exposes the information on D-Bus:
https://patchwork.ozlabs.org/project/hostap/patch/20220307085446.706024-1-lkundrak@v3.sk/

This makes use of the above to indicate presence or absence of WEP
support.
2022-03-17 12:44:53 +01:00
Lubomir Rintel
91f076d235 supplicant: add a comment about extending NMSupplCapType
We've failed to amend logging in relevant places twice. Let's add a
hopefully helpful remark.
2022-03-17 12:44:53 +01:00
Lubomir Rintel
78c937cb23 supplicant: log WPA-EAP-SUITE-B-192 capability
Fixes: e874ccc917 ('wifi: add WPA-EAP-SUITE-B-192 support')
2022-03-17 12:44:53 +01:00
Thomas Haller
47519659ed
glib-aux: reword code comments for nm_utils_buf_utf8safe_{,un}escape() 2022-03-17 12:28:56 +01:00
Thomas Haller
ca9c67565a
connectivity: use GSource instead of source id for tracking timeout/idle source
I think we should move away from using the source-ids.

Having a "GSource*" pointer makes it clearer what this is, compared to a
guint source ID. Also, g_source_remove() always needs to first do a hash
lookup (with locking) to resolve the source ID to the GSource. This is
unnecessary.
2022-03-17 10:27:33 +01:00
Thomas Haller
63d68e7f42
connectivity: minor cleanup resolve_cb() to use nm_utils_addr_family_to_size()
And change code so that clang-format produces nicer alignment.
2022-03-17 10:10:41 +01:00
Thomas Haller
593d08db81
connectivity: skip unexpected addr family from resolved response
In practice, systemd-resolved will give us always AF_INET/AF_INET6. Still,
check for that.
2022-03-17 10:10:22 +01:00
Beniamino Galvani
118561e284 n-dhcp4: discard NAKs from other servers in SELECTING
I got a report of a scenario where multiple servers reply to a REQUEST
in SELECTING, and all servers send NAKs except the one which sent the
offer, which replies with a ACK. In that scenario, n-dhcp4 is not able
to obtain a lease because it restarts from INIT as soon as the first
NAK is received. For comparison, dhclient can get a lease because it
ignores all NAKs in SELECTING.

Arguably, the network is misconfigured there, but it would be great if
n-dhcp4 could still work in such scenario.

According to RFC 2131, ACK and NAK messages from server must contain a
server-id option. The RFC doesn't explicitly say that the client
should check the option, but I think it's a reasonable thing to do, at
least for NAKs.

This patch stores the server-id of the REQUEST in SELECTING, and
compares it with the server-id from NAKs, to discard other servers'
replies.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1144
2022-03-17 09:46:15 +01:00
Beniamino Galvani
c65ae9b1db core/tests: fix tests for nm_utils_shorten_hostname()
The test currently fails on systems where HOST_NAME_MAX != 64 (for
example, Alpine Linux). Update the test to not assume a predefined
maximum length.

Fixes: 9498702242 ('core: add nm_utils_shorten_hostname()')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1149
2022-03-16 11:24:02 +01:00
Beniamino Galvani
aa9b5e28eb ethernet: fix setting ip-ifindex for PPPoE connections
When a NMDevice is involved in a PPPoE activation, it means that the
connection has connection.interface-name=<ethernet-interface>. In such
case, the ppp ifindex should be set as ip-ifindex of the ethernet
device.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-16 10:43:46 +01:00
Beniamino Galvani
7b2bea7ceb ethernet: don't do DHCPv4 on PPPoE
It's not going to work.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-16 10:43:46 +01:00
Beniamino Galvani
041df05f3c ppp: allow autoconf6 when ipv6.method is 'auto'
PPP supports IPv6 autoconfiguration.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-16 10:43:46 +01:00
Thomas Haller
2ffa6f7693
libnm/doc: clarify behavior for autoconnect in man nm-settings 2022-03-16 10:10:13 +01:00
Thomas Haller
f307e12080
std-aux: cast NM_IN_SET_SET() operands to "int" for "-Wbitwise-instead-of-logical" warning
Clang 14 has a new warning "-Wbitwise-instead-of-logical", and it warns
about our usage with NM_IN_SET_SE()/NM_IN_STRSET_SE(). It complains that we
are using '|' with boolean operands. Which is true (and intended), as we bitwise-or
the result of the '==' comparisons.

Work around the warning by casting the operands to "int". Note that
in C, the comparison operators have already a type "int", so this cast
should not result in any changes in the compiled code.

    ../src/libnm-core-impl/tests/test-general.c:9415:17: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        _ASSERT(2, !NM_IN_SET_SE(-1, G(1), G(2)));
        ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../src/libnm-std-aux/nm-std-aux.h:800:30: note: expanded from macro 'NM_IN_SET_SE'
    #define NM_IN_SET_SE(x, ...) _NM_IN_SET(|, typeof(x), x, __VA_ARGS__)
                                 ^
    ../src/libnm-std-aux/nm-std-aux.h:789:39: note: expanded from macro '_NM_IN_SET'
            !!(NM_VA_ARGS_FOREACH(, , op, _NM_IN_SET_OP, __VA_ARGS__)); \
                                          ^
    ../src/libnm-std-aux/nm-std-aux.h:772:20: note: expanded from macro 'NM_VA_ARGS_FOREACH'
                       op,                                                   \
                       ^
    note: (skipping 7 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
    ../src/libnm-glib-aux/nm-macros-internal.h:1603:47: note: expanded from macro '_G_BOOLEAN_EXPR'
    #define _G_BOOLEAN_EXPR(expr) NM_BOOLEAN_EXPR(expr)
                                  ~~~~~~~~~~~~~~~~^~~~~
    ../src/libnm-std-aux/nm-std-aux.h:167:62: note: expanded from macro 'NM_BOOLEAN_EXPR'
    #define NM_BOOLEAN_EXPR(expr) _NM_BOOLEAN_EXPR_IMPL(NM_UNIQ, expr)
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
    ../src/libnm-std-aux/nm-std-aux.h:161:13: note: expanded from macro '_NM_BOOLEAN_EXPR_IMPL'
            if (expr)                      \
                ^~~~
    ../src/libnm-core-impl/tests/test-general.c:9415:17: note: cast one or both operands to int to silence this warning
    ../src/libnm-std-aux/nm-std-aux.h:800:30: note: expanded from macro 'NM_IN_SET_SE'
    #define NM_IN_SET_SE(x, ...) _NM_IN_SET(|, typeof(x), x, __VA_ARGS__)
                                 ^
    ../src/libnm-std-aux/nm-std-aux.h:789:39: note: expanded from macro '_NM_IN_SET'
            !!(NM_VA_ARGS_FOREACH(, , op, _NM_IN_SET_OP, __VA_ARGS__)); \
                                          ^
2022-03-16 00:57:17 +01:00
Thomas Haller
45d2537116
glib-aux: restrict NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER workaround to gcc 12.0.1
This was a bug in gcc 12 (<= 12.0.1). Restrict the macro further
for when we disable the warning.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2056613
2022-03-14 13:51:29 +01:00
Thomas Haller
1d6080827b
coding-style: fix formatting 2022-03-14 13:01:06 +01:00
Beniamino Galvani
5abb113386 wifi: ignore disabled frequencies
Frequencies with the 'disabled' flag are supported by the driver but
disabled in the current regulatory domain. Don't add them to the list
of supported frequencies since they are not usable.

This is especially needed since commit f18bf17dea ('wifi: cleanup
ensure_hotspot_frequency()'), as now NetworkManager explicitly sets a
random, stable channel for Wi-Fi hotspots. If the choosen channel is
disabled, the hotspot fails to start.

Disabled channels are displayed in the 'iw phy' output as '(disabled)':

                [...]
                Frequencies:
                        * 2412 MHz [1] (30.0 dBm)
                        * 2417 MHz [2] (30.0 dBm)
                        * 2422 MHz [3] (30.0 dBm)
                        * 2427 MHz [4] (30.0 dBm)
                        * 2432 MHz [5] (30.0 dBm)
                        * 2437 MHz [6] (30.0 dBm)
                        * 2442 MHz [7] (30.0 dBm)
                        * 2447 MHz [8] (30.0 dBm)
                        * 2452 MHz [9] (30.0 dBm)
                        * 2457 MHz [10] (30.0 dBm)
                        * 2462 MHz [11] (30.0 dBm)
                        * 2467 MHz [12] (disabled)
                        * 2472 MHz [13] (disabled)
                        * 2484 MHz [14] (disabled)

Note that currently NM loads the list only at startup and therefore,
in case of a change of regulatory domain, a restart of the daemon is
needed to have the list updated. This needs to be improved.

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

Fixes: f18bf17dea ('wifi: cleanup ensure_hotspot_frequency()')
2022-03-14 08:50:28 +01:00
Beniamino Galvani
3a41f6539e platform: rework initialization of wifi frequencies
Iterate only once over the netlink array, and realloc the buffer when
needed.
2022-03-14 08:50:28 +01:00
Lubomir Rintel
5b4b00b8d2 cli: connection: check for deprecated features on "add"/"modify"
If the user happens to create a WiMax or Wi-Fi WEP connection they get a
warning.
2022-03-13 18:23:44 +01:00
Lubomir Rintel
061c342474 cli: connection: check for warnings after "modify"
Run the same checks after "nmcli c modify" as we do for "nmcli c add".
That is -- warn if the resulting connection has a connection ID
collision.
2022-03-13 18:23:44 +01:00
Lubomir Rintel
b3f79ac366 cli: connection: factor out warning from "add" callback
We sometimes emit warnings after a connection is added. Currently
there's a warning when the connection ID collides with another one (and
a suggestion to use an UUID instead).

Let's move the check into a separate routine, so that we can reuse it
elsewhere, such as on connection "modify" (in a following commit).
2022-03-13 18:23:44 +01:00