Commit graph

15274 commits

Author SHA1 Message Date
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
Lubomir Rintel
f377114d6e cli: connection: check for deprecated features
Check if a connection uses something that is likely not to work --
either now or in future.

The ultimate decision on whether it's going to work is up to the daemon.
We just use the result to color the connection differently to provide
slight visual cue to the user.
2022-03-13 18:23:44 +01:00
Lubomir Rintel
550e3bbdd8 cli: device: color WEP APs differently in "wifi list"
Provide a visual cue suggesting that an attempt to associate with an WEP
access point might not work. Whether it actually will work up to the daemon.
2022-03-13 18:23:44 +01:00
Lubomir Rintel
422ae6bea6 cli: device: factor out checking whether an AP is a WEP one
This is going to be useful elsewhere. We're going to mark WEP APs as
deprecated.
2022-03-13 18:23:44 +01:00
Lubomir Rintel
cd7687ff60 cli: add color codes for deprecated features
Follow-up commits are going color Wi-Fi networks and connections that rely
on deprecated features differently, to provide a visual cue.

Add color definitions for those.
2022-03-13 18:23:44 +01:00
Thomas Haller
8aaee8c50c
core/device: avoid logging "%p" format and use obfuscated ptr 2022-03-13 12:08:59 +01:00
Thomas Haller
4629506b80
core/device: rename nm_device_master_release_one_slave()
We have nm_device_master_add_slave(). This should be mirrored by
nm_device_master_release_slave() (not release-one-slave).

Thereby, also rename nm_device_master_release_slaves() to
nm_device_master_release_slaves_all() to make it clearer.
2022-03-13 12:08:52 +01:00
Thomas Haller
17ac71cd58
core/device: add ReleaseSlaveType argument for nm_device_master_release_one_slave()
I find the two (dependent) booleans "configure" and "force" confusing.
nm_device_master_release_one_slave() has many callers, it's interesting
to be able to grep for the release-type. Add an enum to make this more
readable.
2022-03-13 12:08:08 +01:00
Thomas Haller
a566fd8cf4
core/device: use c_list_for_each_entry() for interating of slaves list
This convenience macro is just shorter, resulting in more(?) readable
code and less clutter.
2022-03-13 12:02:09 +01:00
Thomas Haller
53406e721d
core/trivial: rename parameter to link_changed_cb()
"info" is not a good name. Variables of this kind are usually
called "plink" or "pllink". Rename.
2022-03-13 12:02:08 +01:00
Thomas Haller
6f948fcd2e
core: use nm_dbus_manager_lookup_object_with_type()
I think this makes it clearer that we should always look for a certain
type, because NMDBusManager tracks all D-Bus objects.
2022-03-13 12:02:08 +01:00
Thomas Haller
de61722efe
core: add nm_dbus_manager_lookup_object_with_type() helper
This makes the non-obvious fact clearer, that when you look up an object
by an untrusted, user-provided path, it might not be the object type you
are looking for. In basically all cases, you need to check that the
result is of the expected type. This helper makes that clearer.
2022-03-13 12:02:07 +01:00
Thomas Haller
216c46c881
all: prefer nm wrappers to automatically attach GSource to default context
We often create the source with default priority, no destroy function and
attach it to the default context (g_main_context_default()). For that
case, we have wrapper functions like nm_g_timeout_add_source()
and nm_g_idle_add_source(). Use those.

There should be no change in behavior.
2022-03-13 11:59:42 +01:00
Thomas Haller
9b030a3988
all: change scheduling priority for idle actions to G_PRIORITY_DEFAULT_IDLE
g_idle_add() uses G_PRIORITY_DEFAULT_IDLE priority. Most of the time we don't
care much about the priority.

But at the places that this patch changes, I think that using
G_PRIORITY_DEFAULT_IDLE (and following g_idle_add()) is more correct. The
reason for this is not very strong, except that it's probably the better
choice. And the old choice was made because I didn't realize that
g_idle_add() uses another default priority. Hence, the old choice was not
for good reasons either.
2022-03-13 11:59:42 +01:00
Thomas Haller
15e8837945
glib-aux: fix priority for nm_g_idle_add_source()
nm_g_idle_add_source() is supposed to work like g_idle_add(). Use the correct
priority.

I think this causes little actual problems, because usually we don't
carefully tune the priorities and would be mostly fine with either.

Fixes: 6b18fc252d ('shared: add nm_g_{idle,timeout}_add_source() helpers')
2022-03-13 11:59:31 +01:00
Fernando Fernandez Mancera
482d99f549 bond: do not reapply when setting fail_over_mac
When a bond has ports attached kernel disallows writing
`/sys/devices/virtual/net/bond0/bonding/fail_over_mac`. NetworkManager
should fail when trying to do reapply if `fail_over_mac` needs to be
set.

https://bugzilla.redhat.com/2003214
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1143
2022-03-11 20:49:10 +01:00
Thomas Haller
ae0cc9618c
libnm: fix assertion in NMClient checking for current main context
NMClient is strongly tied to the GMainContext with which it was created.
Several operations must only be called from within the context. There
was an assertion for that.

However, creating (and init_async()) should be allowed to call not
from within the GMainContext. So if the current context has no owner
(is not acquired), then it's also OK.

Fix the assertion for that.

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2022-03-11 12:11:44 +01:00
Thomas Haller
5dc9307a34
glib-aux: add nm_g_main_context_can_acquire() helper 2022-03-11 12:10:18 +01:00
Thomas Haller
9c8a937280
core/trivial: add code comment to nm_utils_stable_id_parse() 2022-03-11 10:21:44 +01:00
Thomas Haller
8fc40206ec
core: use NM_STR_HAS_PREFIX() in nm_utils_stable_id_parse()
NM_STR_HAS_PREFIX() expands to one `strncpy()`, with the length being a
compile time constant. It's faster than calling through glib.
2022-03-11 10:09:16 +01:00
Thomas Haller
69376e20a5
core: rename nm_utils_host_id_get_timestamp_ns() to "nsec"
We change more and more to prefer "nsec" (and "usec", "msec", and "sec")
as abbreviations, instead of "ns" (and "us", "ms", "s"). Rename.
2022-03-11 09:43:02 +01:00
Thomas Haller
513c0b3f24
core/trivial: reword code comment about fake host-id timestamp 2022-03-11 09:43:02 +01:00
Thomas Haller
20060327d4
libnm/docs: add reference to secret-key in description for stable-id 2022-03-11 09:27:33 +01:00
Thomas Haller
63664719be
core/dhcp: use gs_free_error in NMDhcpDhcpcd's ip4_start()
It just seems less error prone. Use the cleanup attribute.
2022-03-09 23:14:39 +01:00
Thomas Haller
fd50323232
core/dhcp: fix uninitialized GError in NMDhcpDhcpcd's ip4_start()
Found with `git grep 'GError.*[^,)];'| grep ' *= *NULL;' -v`

Fixes: a2abd15fe0 ('DHCP: Support dhcpcd-9.x')
2022-03-09 23:14:38 +01:00
Thomas Haller
a9d521bf8c
libnm: fix uninitialized GError in NMClient's _init_start_cancel_on_idle_cb()
Found with `git grep 'GError.*[^,)];'| grep ' *= *NULL;' -v`

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2022-03-09 23:14:37 +01:00
Thomas Haller
43748d2980
core/team: fix leak and uninitialized GError in NMDeviceTeam's constructed()
Found with `git grep 'GError.*[^,)];'| grep ' *= *NULL;' -v`

Fixes: d689380cfc ('team: support operation without D-Bus')
2022-03-09 23:14:37 +01:00
Wen Liang
549761b0ad libnm: fix crash during the restart after killed
When cloud-init job (metadata service crawler) starts, it sends the
SIGTERM signal to nm-cloud-setup and force the nm-cloud-setup to
restart, however, because the error is not initialized as NULL in
`_init_start_cancelled_cb()` before it is set, nm-cloud-setup will hit
a dumped core.

TO fix it, initialize the error as NULL in `_init_start_cancelled_cb()`.

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

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')

Backtrace:

 #0  g_logv (log_domain=0x7f833a872071 "GLib", log_level=G_LOG_LEVEL_WARNING, format=<optimized out>, args=<optimized out>) at ../glib/gmessages.c:1413
 #1  0x00007f833a81f043 in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at ../glib/gmessages.c:1451
 #2  0x00007f833ab97230 in nm_utils_error_set_cancelled (is_disposing=<optimized out>, instance_name=<optimized out>, error=0x7ffff79cb980) at src/libnm-glib-aux/nm-shared-utils.c:2599
 #3  nm_utils_error_set_cancelled (is_disposing=0, instance_name=0x0, error=0x7ffff79cb980) at src/libnm-glib-aux/nm-shared-utils.c:2590
 #4  _init_start_cancelled_cb (cancellable=<optimized out>, user_data=0x5640ca292150) at src/libnm-client-impl/nm-client.c:7324
 #5  _init_start_cancelled_cb (cancellable=<optimized out>, user_data=0x5640ca292150) at src/libnm-client-impl/nm-client.c:7307
 #6  0x00007f833a93094a in _g_closure_invoke_va (param_types=0x0, n_params=<optimized out>, args=0x7ffff79cbb40, instance=0x5640ca267020, return_value=0x0, closure=0x5640ca29d430)
     at ../gobject/gclosure.c:873
 #7  g_signal_emit_valist (instance=0x5640ca267020, signal_id=<optimized out>, detail=0, var_args=var_args@entry=0x7ffff79cbb40) at ../gobject/gsignal.c:3406
 #8  0x00007f833a930a93 in g_signal_emit (instance=instance@entry=0x5640ca267020, signal_id=<optimized out>, detail=detail@entry=0) at ../gobject/gsignal.c:3553
 #9  0x00007f833a9a6475 in g_cancellable_cancel (cancellable=0x5640ca267020) at ../gio/gcancellable.c:513
 #10 g_cancellable_cancel (cancellable=0x5640ca267020) at ../gio/gcancellable.c:487
 #11 0x00005640ca1a8bd4 in sigterm_handler (user_data=0x5640ca267020) at src/nm-cloud-setup/main.c:599
 #12 0x00007f833a819d4f in g_main_dispatch (context=0x5640ca268ef0) at ../glib/gmain.c:3337
 #13 g_main_context_dispatch (context=0x5640ca268ef0) at ../glib/gmain.c:4055
 #14 0x00007f833a86e608 in g_main_context_iterate.constprop.0 (context=0x5640ca268ef0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4131
 #15 0x00007f833a819463 in g_main_loop_run (loop=0x5640ca24fdb0) at ../glib/gmain.c:4329
 #16 0x00005640ca1a6d04 in nmc_client_new_waitsync (cancellable=0x5640ca267020, out_nmc=0x7ffff79cbfa0, error=0x7ffff79cbf98, first_property_name=0x5640ca1b11db "instance-flags",
     first_property_name=0x5640ca1b11db "instance-flags") at src/libnm-client-aux-extern/nm-libnm-aux.c:129
 #17 0x00005640ca1a3863 in main (argc=1, argv=<optimized out>) at src/nm-cloud-setup/main.c:639
2022-03-09 09:24:25 -05:00
Lubomir Rintel
7f1840bbb6 libnm: fix an assert in nm_client_get_capabilities()
The length argument is optional. That makes sense, because the returned
array is NUL-terminated.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1136
2022-03-09 14:18:26 +01:00
Thomas Haller
71f53d4069
std-aux: add code comment for NM_STR_HAS_PREFIX()/NM_STR_HAS_SUFFIX() 2022-03-09 09:10:45 +01:00
Beniamino Galvani
143f7b1df7 core: preserve the domain when system hostname is truncated
Pass the full hostname to the DNS manager, so that the domain gets
added to resolv.conf even when the hostname was truncated.

Note that "hostname" argument for plugins's update() function is
currently unused. Don't remove that because it can be potentially
useful to set a global search domain based on the hostname, but change
it to carry the domain directly.
2022-03-09 08:34:26 +01:00
Beniamino Galvani
59f57e8a0b core: shorten hostname when too long
If the hostname received via DHCP is too long, shorten it.
2022-03-09 08:34:26 +01:00
Beniamino Galvani
9498702242 core: add nm_utils_shorten_hostname()
Add a function to shorten a overlong hostname, truncating it to the
first dot or 64 characters.
2022-03-09 08:34:26 +01:00
Beniamino Galvani
c41ad0ebe3 dns: drop nm_dns_manager_set_initial_hostname()
It can be replaced by nm_dns_manager_set_hostname() with
skip_update=TRUE.
2022-03-09 08:34:26 +01:00
Lubomir Rintel
a7ef068186 cli: don't ignore errors from setting property aliases
Before, we would just ignore the errors when we passed an invalid value
to a property alias:

  $ nmcli c add type ethernet mac Hello
  Connection 'ethernet-1' (242eec76-7147-411a-a50b-336cf5bc8137) successfully added.
  $ nmcli c show 242eec76-7147-411a-a50b-336cf5bc8137 |grep 802-3-ethernet.mac-address:
  802-3-ethernet.mac-address:             --

...or crash, because the GError would still be around:

  $ nmcli c add type ethernet mac Hello ethernet.mac-address World
  (process:734670): GLib-WARNING **: 14:52:51.436: GError set over the top of a previous GError or uninitialized memory.
  This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
  The overwriting error message was: Error: failed to modify 802-3-ethernet.mac-address: 'World' is not a valid Ethernet MAC.
  Error: failed to modify 802-3-ethernet.mac-address: 'Hello' is not a valid Ethernet MAC.

Now we catch it early enough:

  $ nmcli c add type ethernet mac Hello
  Error: failed to modify 802-3-ethernet.mac-address: 'Hello' is not a valid Ethernet MAC.

Fixes: 40032f4614 ('cli: fix resetting values via property alias')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1134
2022-03-08 10:15:52 +01:00
Fernando Fernandez Mancera
6430a7d70c nm-online: set the timeout upper limit to 2073600 seconds
In some situations 3600 seconds is not enough. The upper limit should be
2073600 seconds, 24 days. In addition, this limit should be documented.

https://bugzilla.redhat.com/show_bug.cgi?id=2025617
2022-03-07 14:47:30 +01:00
Emmanuel Grumbach
965c55f0da platform: add Intel vendor command to get the device from CSME
This will allow us to let CSME know that we are ready to connect and it
can remove the "OS_NOT_OWNER" rfkill.
2022-03-07 14:10:19 +02:00
Emmanuel Grumbach
526c4b3293 platform: add the plumbing to get the CSME connection info
This allows to fetch the information about the AP that CSME if connected
to. It'll allow us to connect to the exact same AP and shaving off the
scan from the connection, improving the connection time.
2022-03-07 13:55:43 +02:00
Emmanuel Grumbach
721008f1c3 linux-headers: add nl80211-vnd-intel.h kernel header
Take from include/uapi/linux/nl80211-vnd-intel.h

Linux 5.17-rc5, cfb92440ee71adcc2105b0890bb01ac3cddb8507
March 1, 2022
2022-03-07 10:55:33 +02:00
Thomas Haller
5402a72179
dhcp6: fix setting ifindex in nm_dhcp_utils_merge_new_dhcp6_lease()
nm_l3_config_data_new_clone() takes non-positive ifindex to use
the ifindex of the l3cd. But it also asserts that the ifindex
is not negative. Fix that assertion failure, by setting the ifindex
to zero.

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

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-03-07 09:11:07 +01:00
Beniamino Galvani
392daa5dab core: fall back to loading all known settings plugins
Currently it is possible to specify a list of default settings plugins
to be used when configuration doesn't contain the main.plugins key.

We want to add a mechanism that allows to automatically load any
plugin found in the plugins directory without needing
configuration. This mechanism is useful when plugins are shipped in a
different, optional subpackage, to automatically use them.

With such mechanism, the actual list of plugins will be determined
(in order of evaluation):

 1. via explicit user configuration in /etc, if any
 2. via distro configuration in /usr, if any
 3. using the build-time default, if any
 4. looking for known plugins in /usr/lib
2022-03-06 09:12:06 +01:00
Till Maas
f1b3dd4eb5
libnmc: Remove verbose logging
Don't log the failure to spawn the auth dialog. This is polluting the
terminal when using nmcli when activating an OpenVPN profile if
/usr/libexec/nm-openvpn-auth-dialog is not available. Since nmcli can
still ask for the credentials, the missing auth dialog does not block
the activation, so the "warning" level is too much. Since it is a
library, any output to the terminal is bad, therefore remove the
logging.

Signed-off-by: Till Maas <opensource@till.name>
2022-03-04 18:09:02 +01:00
Lubomir Rintel
65fdfb2500 ovs-port: fix removal of ovsdb entry if the interface goes away
Hope third time is the charm.

The idea here is to remove the OVSDB entry if the device actually went away
violently (like, the it was actually removed from the platform), but keep it if
we're shutting down.

Fixes-test: @ovs_nmstate
Fixes: 966413e78f ('ovs-port: avoid removing the OVSDB entry if we're shutting down')
Fixes: ecc73eb239 ('ovs-port: always remove the OVSDB entry on slave release')

https://bugzilla.redhat.com/show_bug.cgi?id=2055665
2022-03-04 10:31:07 +01:00
Thomas Haller
33584f2134
cli: make APInfo parameter to fill_output_access_point() const
It's helpful to control when data/state gets mutated. In particular,
when passing on a pointer via several hops. C can help with that
at compile time via "const".

But the "index" field of APInfo is actually mutable, as it counts
the lines. So most of the data is immutable, but the index.

Make APInfo const. But to do that, the mutable part must be moved to a
separate place.

Also, start with the counter initialized to zero instead of one.
It is just nicer.
2022-03-04 10:05:06 +01:00
Thomas Haller
dd42af636a
cli: change "IN-USE" property to only honor the exact access point
On the D-Bus API, the current access point is referred exactly, by its
D-Bus path. Likewise, in libnm's NMClient cache, the access point
instance is unique in representing the D-Bus object (meaning, we
can directly use pointer equality).

Let's not compare the active AP based on the BSSID. It can happen
that the scan list contains the same BSSID multiple times (for example
on different bands). In that case, the output should only highlight
one AP as in-use:

  $ nmcli device wifi list
  IN-USE  BSSID              SSID              MODE   CHAN  RATE        SIGNAL  BARS  SECURITY
  *       E4:0f:4b:2a:c3:d1  MYSSID1           Infra  6     270 Mbit/s  100     ▂▄▆█  WPA2
  *       E4:0f:4b:2a:c3:d1  MYSSID1           Infra  6     270 Mbit/s  87      ▂▄▆█  WPA2
2022-03-04 10:05:06 +01:00
Thomas Haller
caf50b96bd
cli: minor cleanup initializing APInfo in "devices.c" 2022-03-04 10:05:06 +01:00
Thomas Haller
5cf4d3c744
glib-aux: hide API g_alloca0() and g_newa0()
For one, this API is only available since 2.72, thus we must not use
it (unless we would add a compat implementation to nm-glib.h).

But also, g_alloca0() evaluates the size argument multiple times,
making it non-function like. That seems highly undesirable and error
prone.

Also, we should be very careful about alloca() and the potential
for stack overflow. We use alloca() at times, but usually with
macros that are named "*_a()" (to make the danger clearer) and compile
time checks for the size. These glib functions make this slightly
less safe.

Just prevent us from using this API.
2022-03-04 10:05:06 +01:00
Thomas Haller
98b3056604
core: preserve external ports during checkpoint rollback
When we have a bridge interface with ports attached externally (that is,
not by NetworkManager itself), then it can make sense that during
checkpoint rollback we want to keep those ports attached.

During rollback, we may need to deactivate the bridge device and
re-activate it. Implement this, by setting a flag before deactivating,
which prevents external ports to be detached. The flag gets cleared,
when the device state changes to activated (the following activation)
or unmanaged.

This is an ugly solution, for several reasons.

For one, NMDevice tracks its ports in the "slaves" list. But what
it does is ugly. There is no clear concept to understand what it
actually tacks. For example, it tracks externally added interfaces
(nm_device_sys_iface_state_is_external()) that are attached while
not being connected. But it also tracks interfaces that we want to attach
during activation (but which are not yet actually enslaved). It also tracks
slaves that have no actual netdev device (OVS). So it's not clear what this
list contains and what it should contain at any point in time. When we skip
the change of the slaves states during nm_device_master_release_slaves_all(),
it's not really clear what the effects are. It's ugly, but probably correct
enough. What would be better, if we had a clear purpose of what the
lists (or several lists) mean. E.g. a list of all ports that are
currently, physically attached vs. a list of ports we want to attach vs.
a list of OVS slaves that have no actual netdev device.

Another problem is that we attach state on the device
("activation_state_preserve_external_ports"), which should linger there
during the deactivation and reactivation. How can we be sure that we don't
leave that flag dangling there, and that the desired following activation
is the one we cared about? If the follow-up activation fails short (e.g. an
unmanaged command comes first), will we properly disconnect the slaves?
Should we even? In practice, it might be correct enough.

Also, we only implement this for bridges. I think this is where it makes
the most sense. And after all, it's an odd thing to preserve unknown,
external things during a rollback -- unknown, because we have no knowledge
about why these ports are attached and what to do with them.

Also, the change doesn't remember the ports that were attached when the
checkpoint was created. Instead, we preserve all ports that are attached
during rollback. That seems more useful and easier to implement. So we
don't actually rollback to the configuration when the checkpoint was
created. Instead, we rollback, but keep external devices.

Also, we do this now by default and introduce a flag to get the previous
behavior.

https://bugzilla.redhat.com/show_bug.cgi?id=2035519
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/ # 909
2022-03-03 11:25:14 +01:00