Commit Graph

25152 Commits

Author SHA1 Message Date
Thomas Haller
a8442c8243 man: show example for nmcli --ask device wifi connect in nmcli-example manual 2020-03-06 09:48:58 +01:00
Auke Kok
425293b13c man: show example for nmcli device wifi connect in nmcli-example manual
Add the only important example that this file should have

All other examples are nice. But when you install a console-only
machine and read the NM man pages, you are none the wiser, because
something as simple like this isn't covered in the man pages.

I've seen other users complain about it, and I've torn my hair out
over this several times.

[thaller@redhat.com: changed subject line of patch]
2020-03-06 09:48:58 +01:00
Thomas Haller
c5a6e07d07 core: merge branch 'th/prune-device-state-files'
https://bugzilla.redhat.com/show_bug.cgi?id=1810153

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/429
2020-03-04 16:58:11 +01:00
Thomas Haller
332df7a58e core: periodically cleanup unused device state files from /run
Otherwise, we only prune unused files when the service terminates.
Usually, NetworkManager service doesn't get restarted before shutdown
of the system (nor should it be). That means, if you create (and
destroy) a large number of software devices, the state files pile
up.

From time to time, go through the files on disk and delete those that
are no longer relevant.

In this case, "from time to time" means after we write/update state
files 100 times.
2020-03-04 16:53:15 +01:00
Thomas Haller
5477847eed core: return ifindex from nm_manager_write_device_state()
nm_manager_write_device_state() writes the device state to a file. The ifindex
is here important, because that is the identifier for the device and is also
used as file name. Return the ifindex that was used, instead of letting the
caller reimplement the knowledge which ifindex was used.
2020-03-04 16:53:04 +01:00
Thomas Haller
ecb0210e7a core/trivial: rename nm_config_device_state_prune_unseen() to nm_config_device_state_prune_stale()
It's just a more fitting name after the previous change.
2020-03-04 16:52:57 +01:00
Thomas Haller
ad9e748816 core: cleanup nm_config_device_state_prune_unseen() and accept NMPlatform for skipping pruning 2020-03-04 16:48:09 +01:00
Thomas Haller
627b543a37 dns: cleanup update_dns() for returning error
It was not very clear whether update_dns() would always set the error
output variable if (and only if) it would return false.

Rework the code to make it clearer.
2020-03-04 15:48:01 +01:00
Thomas Haller
abafea8682 dns: use gs_free_error for clearing error from update_dns()
Not using cleanup attribute is error prone.

In theory, a function should only return a GError if (and only if) it
signals a failure. However, for example in commit 324f67956a ('dns:
ensure to log a warning when writing /etc/resolv.conf fails') due to
a bug we was violated. In that case, it resulted in a leak.

Avoid explicit frees and use the gs_free_error cleanup attribute
instead. That would also work correctly in face of such a bug and in
general it seems preferable to explicitly assign ownership to auto
variables on the stack.
2020-03-04 15:45:16 +01:00
Thomas Haller
324f67956a dns: ensure to log a warning when writing /etc/resolv.conf fails
When setting "main.rc-manager=symlink" (the default) and /etc/resolv.conf
is a file, NetworkManager tries to write the file directly. When that fails,
we need to make sure to propagate the error so that we log a warning about that.

With this change:

    <debug> [1583320004.3122] dns-mgr: update-dns: updating plugin systemd-resolved
    <trace> [1583320004.3123] dns-sd-resolved[f9e3febb7424575d]: send-updates: start 8 requests
    <trace> [1583320004.3129] dns-mgr: update-resolv-no-stub: '/var/run/NetworkManager/no-stub-resolv.conf' successfully written
    <trace> [1583320004.3130] dns-mgr: update-resolv-conf: write to /etc/resolv.conf failed (rc-manager=symlink, $ERROR_REASON)
    <trace> [1583320004.3132] dns-mgr: update-resolv-conf: write internal file /var/run/NetworkManager/resolv.conf succeeded
    <trace> [1583320004.3133] dns-mgr: current configuration: [{ [...] }]
    <warn>  [1583320004.3133] dns-mgr: could not commit DNS changes: $ERROR_REASON
    <info>  [1583320004.3134] device (eth0): Activation: successful, device activated.

https://bugzilla.redhat.com/show_bug.cgi?id=1809181
2020-03-04 12:15:25 +01:00
Thomas Haller
0549351111 dhcp: clean source on dispatch failure (fix leak)
The GSource must also be unrefed. Also, first clear the field
before invoking callbacks to the upper layers.

Fixes: 843d696e46 ('dhcp: clean source on dispatch failure')
2020-03-03 09:53:17 +01:00
Beniamino Galvani
843d696e46 dhcp: clean source on dispatch failure
Fix the following warning:

 NetworkManager[1524461]: Source ID 3844 was not found when attempting to remove it

 g_logv (log_domain=0x7f2816fa676e "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7ffe697374d0) at gmessages.c:1391
 g_log (log_domain=log_domain@entry=0x7f2816fa676e "GLib", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7f2816fae240 "Source ID %u was not found when attempting to remove it") at gmessages.c:1432
 g_source_remove (tag=519) at gmain.c:2352
 nm_clear_g_source (id=<optimized out>) at ./shared/nm-glib-aux/nm-macros-internal.h:1198
 dispose (object=0x55f7289b1ca0) at src/dhcp/nm-dhcp-nettools.c:1433
 g_object_unref (_object=<optimized out>) at gobject.c:3303
 g_object_unref (_object=0x55f7289b1ca0) at gobject.c:3232
 dhcp4_cleanup (self=self@entry=0x55f728af3b20, cleanup_type=cleanup_type@entry=CLEANUP_TYPE_DECONFIGURE, release=release@entry=0) at src/devices/nm-device.c:7565
 ...

Fixes: 45521b1b38 ('dhcp: nettools: move to failed state if event dispatch fails')
2020-03-03 09:34:04 +01:00
Beniamino Galvani
105abf27c1 Revert "dispatcher/systemd: order NetworkManager-dispatcher.service Before=NetworkManager.service"
The 'Before' dependency between NM-dispatcher and NM causes a deadlock
when stopping the NM service. When terminating, NM wants to D-Bus
activate NM-dispatcher to synchronously handle pre-down events; but
NM-dispatcher start is ordered after NM shutdown due to the following
behavior described in systemd.unit(5) man page:

  Given two units with any ordering dependency between them, if one
  unit is shut down and the other is started up, the shutdown is
  ordered before the start-up. It doesn't matter if the ordering
  dependency is After= or Before=, in this case. It also doesn't
  matter which of the two is shut down, as long as one is shut down
  and the other is started up; the shutdown is ordered before the
  start-up in all cases.

So, NM is waiting NM-dispatcher to start and NM-dispatcher is queued
by systemd, waiting that NM is stopped. The result is a 90 seconds
delay, after which systemd kills NM and continues.

The dependency was added so that during shutdown NM-dispatcher would
be stopped after NM. I don't think it worked as expected because
NM-dispatcher is not supposed to be active most of the times, and so
it doesn't need a dependency that delays its stop after NM.

This reverts commit acc335aad4.
2020-03-02 17:47:29 +01:00
Thomas Haller
4087024a9b shared: move assertion in _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE()
Move the assertion for valid LIST first. It only checks static data,
and regardless of the entry_cmd, it should be done first.

Fixes: f4d12f7b59 ('shared: add NM_UTILS_STRING_TABLE_LOOKUP_STRUCT_DEFINE() macro for lookup of structs')
2020-03-02 16:20:50 +01:00
Thomas Haller
8b63fd8cc0 shared: fix handling %NULL argument in nm_ref_string_equals_str()
Fixes: 190a8ed425 ('shared: add nm_ref_string_equals_str() helper')
2020-03-02 15:49:41 +01:00
Thomas Haller
30e90b0d95 license: add Tambet to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-March/msg00000.html
2020-03-02 12:33:46 +01:00
Antonio Cardace
50da785be1 nm-setting-bond: fix '[up|down]delay', 'miimon' validation
Just looking at the hashtable entry of 'updelay' and 'downdelay' options
is wrong, we have to inspect their values to check if they're
actually enabled or not.

Otherwise bond connections with valid settings will fail
when created:

$ nmcli c add type bond ifname bond99 bond.options miimon=0,updelay=0,mode=0
Error: Failed to add 'bond-bond99' connection: bond.options: 'updelay' option requires 'miimon' option to be set

Also add unit tests.

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

Fixes: d595f7843e ('libnm: add libnm/libnm-core (part 1)')
2020-02-28 15:45:34 +01:00
Thomas Haller
7625e2483f license: add Pavel to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-February/msg00040.html
2020-02-28 08:45:44 +01:00
Thomas Haller
e9ca7eee2c device/trivial: move code around
Or patterns is to have the property get/set functions before
the object's create/destroy code. Move it.
2020-02-26 18:25:27 +01:00
Thomas Haller
32ea8a3e36 device: merge branch 'th/device-cleanup-properties' 2020-02-26 18:05:00 +01:00
Thomas Haller
0622ad5a91 device/trivial: rename property enums for statistics properties of NMDevice
The name of the property name should resemble the define for the
name.
2020-02-26 18:04:01 +01:00
Thomas Haller
4bff811b75 device/trivial: add comment about NMDevice properties writable from D-Bus
These are special. Their setter gets called via D-Bus' SetProperty.
Mark them with a comment.
2020-02-26 18:03:44 +01:00
Thomas Haller
acb9615060 device: don't make NM_DEVICE_(IP|DHCP)(4|6)_CONFIG properties writable
It's not necessary, nor used, nor actually implemented.
2020-02-26 17:54:15 +01:00
Thomas Haller
5c00980c13 device: don't make NM_DEVICE_DRIVER_VERSION property writable 2020-02-26 17:54:15 +01:00
Thomas Haller
e347886a5f device: don't make NM_DEVICE_FIRMWARE_VERSION property writable 2020-02-26 17:54:15 +01:00
Thomas Haller
8d5c4b26e4 device: don't make NM_DEVICE_FIRMWARE_MISSING property writable
It's not necessary nor used.
2020-02-26 17:54:15 +01:00
Thomas Haller
13059ff784 device: don't make NM_DEVICE_IP4_ADDRESS property writable
It's not necessary nor used.
2020-02-26 17:54:15 +01:00
Thomas Haller
b9f6283c80 libnm,all: merge branch 'th/libnm-interface-name-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/416
2020-02-26 17:52:22 +01:00
Thomas Haller
3efe070dfc libnm: validate "connection.interface-name" at one place only
Don't spread the validation for the interface name between multiple
places. There should be one place only, so when you search for how
this property gets verified, you can find the single place.

That requires to move the special handling for OVS interfaces to
NMSettingConnection.
Since we already have _nm_setting_ovs_interface_verify_interface_type(),
that is easy.
2020-02-26 17:51:14 +01:00
Thomas Haller
294de8487e shared: add NMU_IFACE_OVS_OR_KERNEL for nm_utils_ifname_valid()
Depending on the type, OVS interfaces also have a corresponding netdev
in kernel (e.g. type "internal" does, type "patch" does not).

Such a case is neither NMU_IFACE_OVS nor NMU_IFACE_KERNEL (alone). There should
be a special type to represent those cases.

Add NMU_IFACE_OVS_OR_KERNEL for that.
2020-02-26 17:51:14 +01:00
Thomas Haller
807cddc754 shared: add NMU_IFACE_ANY for nm_utils_ifname_valid()
nm_utils_ifname_valid() is to validate "connection.interface-name"
property. But the exact validation depends on the connection type.

Add "NMU_IFACE_ANY" to validate the name to check whether it would be
valid for any connection type.

This is for completeness and for places where the caller might not know
the connection type.
2020-02-26 17:51:14 +01:00
Thomas Haller
a11edd4a82 libnm: always return normalized-type from _nm_setting_ovs_interface_verify_interface_type()
We should return the chosen type whenever we can verify the setting.
Previously, the normalized-type output argument was only set when
normalization was actually necessary.

On most cases, the caller cares whether the setting verifies and which
interface type is chosen. It's much less likely that a caller cares
only about the normalized-type if normalization is actually necessary.

Whenever we return TRUE (indicating that the setting is valid), also
return the chosen interface-type.
2020-02-26 17:51:14 +01:00
Thomas Haller
07b7c82d04 libnm: allow _nm_setting_ovs_interface_verify_interface_type() without NMSettingOvsInterface instance
_nm_setting_ovs_interface_verify_interface_type() does verify and
normalize both. Especially for verify, it's useful to run the operation
without having a NMSettingOvsInterface instance, because we might
want to know how normalization would react, if we had a
NMSettingOvsInterface instance.

Allow for that.
2020-02-26 17:51:14 +01:00
Thomas Haller
aa6bc2868d ifcfg-rh: use nm_utils_ifname_valid() for validating interface-name in reader
Maybe the reader should not try to add its own validation. It
could just read the value, set it in the profile, and let
nm_connection_verify() handle it.

However:

 - in this form the code only logs a warning about invalid setting.
   If we let it come to nm_connection_verify(), the connection profile
   will be entirely rejected. I think this makes sense, because ifcfg
   files may be edited by the user and we don't know what is out there.

 - it's nicer to show a warning that specifically mentions the DEVICE=
   variable. There error message we get from nm_connection_verify()
   is no longer aware of ifcfg peculiarities.

Instead: use the appropriate validation function.
2020-02-26 17:51:13 +01:00
Thomas Haller
de19631e9f libnm: remove redundant check from "nm-setting-bond.c"'s validate_ifname() 2020-02-26 17:51:13 +01:00
Thomas Haller
f725209bb4 settings: simplify property setter from GVariant to NMSettingConnection:interface-name
The interface-name property has several deprecated aliases, like
"bridge.interface-name". For backward compatibility, we keep handling
them.

In particular, the "missing_from_dbus_fcn" handler is set. This handles
the case where GVariant only contains the deprecated form, but not
"connection.interface-name".

Previously, from_dbus_fcn() would check whether the deprecated form was
present, and -- only if that form was invalid -- prefer it. The idea was
to fail validation if the deprecated property was invalid.

I think that is not necessary. Just completely ignore the deprecated property,
if the new property is present.

What might make sense is to check whether the deprecated and the new
form are both present, that they are identical. However, I don't think
that is worth the effort.
2020-02-26 17:51:13 +01:00
Thomas Haller
47a654d398 clients: use nm_utils_ifname_valid() to validate interface name in nm_vpn_wireguard_import()
We use the filename of the imported .conf file for "connection.interface-name".
That follows what `wg-quick` does.

However, we also validate that the interface name is valid UTF-8
(otherwise -- as it currently is -- the setting couldn't be send via
D-Bus). As such, we have stricter requirements.

We want to fail early and tell the user when the filename is unsuitable.
Failing later gives a worse user experience, because the failure message
about invalid "connection.interface-name" wouldn't make it clear that
the filename is wrong.

Use the appropriate function to validate "connection.interface-name".

Before:

    $ touch $'./a\344b.conf'
    $ nmcli connection import type wireguard file $'./a\344b.conf'
    Error: failed to import './a?b.conf': Failed to create WireGuard connection: connection.interface-name: 'a?b': interface name must be UTF-8 encoded.

Now:

    $ nmcli connection import type wireguard file $'./a\344b.conf'
    Error: failed to import './a?b.conf': The name of the WireGuard config must be a valid interface name followed by ".conf".
2020-02-26 17:51:13 +01:00
Thomas Haller
41480d48ae libnm: don't validate "connection.interface-name" from "nm-setting-infiniband.c"'s verify()
There should not be multiple places to validate the interface-name.

The check in "nm-setting-infiniband.c" is unnecessary and wrong.

It's unnecessary, because _nm_connection_verify() takes care to
first verify the NMSettingConnection instance.

It's wrong, because it does not check the property the same way as
NMSettingConnection does (e.g. it does not check for valid UTF-8).
2020-02-26 17:51:13 +01:00
Thomas Haller
74e2203e19 libnm: in find_virtual_interface_name() ensure return value stays alive
It's not clear that the returned string is still valid after we
unref the GVariant that contains it. Also return the reference to
the variant.
2020-02-26 17:51:13 +01:00
Thomas Haller
f3dd41ad7e libnm: validate settings in _nm_connection_verify() in defined order
Fully sort the settings in _nm_connection_verify(). Previously, only the
NMSettingConnection instance was sorted first (as required). The remaining
settings were in undefined order. That means, we would validate settings
in undefined order, and if multiple settings have an issue, the reported
error would be undefined.

Instead, use nm_connection_get_settings() which fully sorts the settings
(and of course, sorts NMSettingConnection first as we require it).

Also, this way we no longer need to allocate multiple GSList instances
but only malloc() one array large enough to contain all settings.
2020-02-26 17:51:13 +01:00
Thomas Haller
0718098dcb libnm: use nm_utils_hash_values_to_array() to implement nm_connection_get_settings() 2020-02-26 17:51:13 +01:00
Thomas Haller
d4d9e9e7bb shared: reject reserved names from "connection.interface-name"
"all" and "default" never works.

"bonding_masters" works if you unload the bonding module. Well,
that should not really be called working...

Reject these names.
2020-02-26 17:51:13 +01:00
Thomas Haller
ef567805bb shared: reject '%' from nm_utils_ifname_valid() for kernel names
Generally, it's dangerous to reject values that were accepted
previously. This will lead to NetworkManager being unable to load
a profile from disk, which was loadable previously.

On the other hand, kernel would not have treated this setting as
it was intended. So, I would argue that the such a setting was not
working (as intended) anyway.

We can only hope that users don't configure arbitrary interface names.
It generally isn't a good idea to do, so "breaking" such things is less
of a concern.
2020-02-26 17:51:13 +01:00
Thomas Haller
b15a9b3dc4 supplicant: allocate blobs hash table lazily for supplicant config
It's very unlikely that we have actual blobs for a Wi-Fi network.
That is because the settings plugins (keyfile, ifcfg-rh) convert
blobs to files on disk when writing the profile. So, you can only
have them by editing the files directly to contain blobs.

At that point, don't always create the GHashTable for blobs.
2020-02-26 12:27:36 +01:00
Thomas Haller
9add51ef16 license: add Sigfox to RELICENSE.md
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/365
2020-02-24 15:56:52 +01:00
Beniamino Galvani
47f81864ba ovs: merge branch 'bg/ovs-no-bridge-rh1797696'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/422
https://bugzilla.redhat.com/show_bug.cgi?id=1797696
2020-02-24 15:02:06 +01:00
Beniamino Galvani
c5c49995b1 ovs: fail port enslavement when the bridge device is not found
Fail the enslavement of the ovs port if the bridge device is not
found, instead of generating assertions and potentially crash later.

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

Fixes: 101e65d2bb ('ovs: allow changing mac address of bridges and interfaces')
2020-02-24 15:00:46 +01:00
Beniamino Galvani
c8b5a3f91a ovs: fail port enslavement when the bridge AC is not found
The previous code tried to get the bridge active connection and it
used the port active connection instead in case of failure. This
doesn't seem right, as in nm-ovsdb.c the bridge AC is used to get the
bridge settings (including the uuid, interface name, and cloned mac).

In case of failure getting the bridge AC we should just fail.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')
2020-02-24 15:00:46 +01:00
Beniamino Galvani
5a7b83ea0a n-dhcp4: keep trying after a failure in send()
Currently if an error is encountered during a send() of a message, the
client fails and there is no possibility of recover, since no timers
are armed after a failed event dispatch. An easy way to reproduce a
failure is to add a firewall rule like:

  iptables -A OUTPUT -p udp --dport 67 -j REJECT

which makes the send() fail with EPERM during the renew. In such case,
the client should continue (failing) until it reaches the rebind phase
at T2, when it will be able to renew the lease using the packet
socket.

In general, a failure to send a packet should not cause the failure of
the client.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/419
https://bugzilla.redhat.com/show_bug.cgi?id=1806516
2020-02-24 14:58:33 +01:00
Beniamino Galvani
910267cf5f n-dhcp4: fix logging macro
The level can be a complex expression, don't use it directly in the
macro.
2020-02-24 14:58:24 +01:00