Commit graph

27197 commits

Author SHA1 Message Date
Andrew Zaborowski
5d4dfcd8d2
platform: Drop nm_platform_wifi_get_{bssid,rate,quality}
These are unused now so remove them and revert most of
e0394689b3 which attempted to fix the same
issue of the platform wifi API not mapping well the nl80211 commands
resulting in redundant netlink commands being used.

In the wext driver there are still three individual getters for the
three values and nm_wifi_utils_get_station() uses either these or the
collective get_station method depending on the driver.
2020-11-19 13:38:07 +01:00
Andrew Zaborowski
27eba49691
wifi: Switch to using nm_platform_wifi_get_station
Switch NMDeviceIwd and NMDeviceWifi from nm_platform_wifi_get_bssid,
nm_platform_wifi_get_quality and nm_platform_wifi_get_rate to
nm_platform_wifi_get_station.

I also dropped the checks for the signal quality percentage range as
they're no longer necessary and in NMDeviceWifi dropped
zero-initialization of the bssid buffer before the
nm_platform_wifi_get_bssid call which not necessary either.
2020-11-19 13:38:06 +01:00
Andrew Zaborowski
e5a2520069
platform: Add a wifi_get_station utility
Merge nm_platform_wifi_get_bssid, nm_platform_wifi_get_quality,
nm_platform_wifi_get_rate into one utility, nm_platform_wifi_get_station
that uses the single NL80211_CMD_GET_STATION command dump when the
nl80211 driver is used.  With wext each function mapped to one ioctl
while with nl80211 all three can be obtained with one netlink command.
The new function should use the minimum number of calls with either
driver.
2020-11-19 13:38:06 +01:00
Thomas Haller
f37db2c2a5
wifi/iwd: merge branch 'balrog-kun:iwd-autoconnect'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/670
2020-11-19 10:12:13 +01:00
Andrew Zaborowski
8215340651
iwd: Update KnownNetwork.AutoConnect on NM connection changes
Watch NMSettingConnection's changes using the
NM_SETTINGS_CONNECTION_UPDATED_INTERNAL signal and update IWD
KnownNetwork's AutoConnect property when NMSettingConnection's
autoconnect property changes.

We will not receive "notify::" NM_SETTING_CONNECTION_AUTOCONNECT signals
normally because the NMConnection seems to be replaced with a new one in
Update2() rather than its settings changing.
2020-11-19 10:12:05 +01:00
Andrew Zaborowski
d09ba36f00
iwd: Roughly respect the NMDevice::autoconnect property
Watch the NMDevice::autoconnect property to disable IWD autoconnect if
requested by user.  We have no way to re-enable it when the device is
idle though.

Make sure to not disable IWD's autoconnect in .deactivate() if not
necessary.  There's not much we can do if we have to call
Station.Disconnect() but we can avoid calling it if unnecessary --
a slight optimization regardless of the autoconnect block flags.
Fortunately NM and IWD block autoconnect on a manual deactivation in
the same way (in MANAGED mode) and unblock it on an activation in the
same way too (in MANAGED mode).

Also if wifi.iwd.autoconnect is in use, unset
NM_DEVICE_AUTOCONNECT_BLOCKED_MANUAL_DISCONNECT under the same
conditions as IWD normally would.  This could be made optional but
with wifi.iwd.autoconnect by default we should follow IWD's autoconnect
logic.
2020-11-19 10:12:04 +01:00
Andrew Zaborowski
dc0e31fb70
iwd: Add the wifi.iwd.autoconnect setting
If this setting it true (or missing) we skip most of the D-Bus
Disconnect() calls whoe purpose was to keep IWD's internal autoconnect
mechanism always disabled.  We use the IWD's Station.State property
updates, and secrets requets through our IWD agent, to find out when IWD
is trying to connect and create "assumed" activations on the NM side to
mirror the IWD state.  This is quite complicated due to the many
possible combinations of NMDevice's state and IWD's state.  A lot of
them are "impossible" but we try to be careful to consider all the
different possibilities.

NM has a nice API for "assuming connections" but it's designed for
slightly different use cases than what we have here and for now we
created normal "managed"-type activations when assuming an IWD automatic
connection.
2020-11-19 10:12:04 +01:00
Andrew Zaborowski
43fd93d8f4
iwd: Order objects from g_dbus_object_manager_get_objects
Before we call interface_added for all interfaces and objects returned
from g_dbus_object_manager_get_objects(), order the objects based on the
interfaces present on them.  This is to avoid processing
Network.KnownNetwork properties referring to KnownNetwork objects that
we haven't processed yet, and new Station.ConnectedNetwork properties
referring to Network objects we haven't processed yet.

In NMDeviceIwd make sure we don't emit unnecessary re-checks if device
is not yet enabled because now we're always going to be adding the APs
(representing IWD Network objects) before the device is enabled, i.e.
before the nm_device_iwd_set_dbus_object() call, when NM first connects
to IWD.
2020-11-19 10:12:04 +01:00
Andrew Zaborowski
abc6177448
iwd: Create mirror connections for non-802.1X IWD known networks
Until now we'd only create mirror NMSettingsConnection objects for IWD
KnownNetwork objects of the "8021x" type in the NMIwdManager class.  Now
create mirror connections, or track existing matching
NMSettingsConnections, for every Known Network, for three reasons:

* to allow NMDeviceIwd to easily look up the NMSettingsConnection
  matching an externally-triggered connection, specifically when we let
  IWD autoconnect,
* to allow users to "forget" those Known Networks,
* to allow us to synchronize the autoconnectable property between
  NM and IWD to later allow users toggling it (not done yet).
2020-11-19 10:12:03 +01:00
Andrew Zaborowski
2198bb8293
wifi: Add NMWifiAp getters for wpa_flags/rsn_flags 2020-11-19 10:12:03 +01:00
Andrew Zaborowski
bb25112b61
iwd: Stop using _nm_utils_ssid_to_utf8()
_nm_utils_ssid_to_utf8() can be quite heavy and also has this comment:

 * Again, this function should be used for debugging and display purposes
 * _only_.

In most places that we used it, we have already validated the
connection's SSID to be valid UTF-8 so we can simply g_strndup() it now,
even in the two places where we actually only needed it for display
purposes.  And we definitely don't need or want the locale-specific
conversions done in _nm_utils_ssid_to_utf8 when the SSID is *not* utf8.

In mirror_8021x_connection we also optimize the lookup loop to avoid
validating and strdup'ing all the SSID.
2020-11-19 10:12:03 +01:00
Andrew Zaborowski
7cc5ee473e
iwd: Validate UTF-8 SSID early in check_connection_compatible/complete_connection
IWD only supports UTF-8 SSIDs internally, any BSS who's SSID doesn't
validate as UTF-8 is ignored.  There's also no way to ask IWD to connect
to such network/start AP/Adhoc etc. because SSIDs are passed as D-Bus
strings.  So validate that connection SSIDs are UTF-8 early in
check_connection_compatible/complete_connection and refactor
check_connection slightly to avoid duplication.

Since NMWifiAPs are created by us, we already know those have valid
SSIDs so once we've also checked new NMConnections in
check_connection_compatible there should be no possibility that an SSID
anywhere else in the code is not UTF8.  We should be able to treat the
GBytes values as UTF8 without redundant validation or the complex
locale-dependent conversions in _nm_utils_ssid_to_utf8.
2020-11-19 10:12:02 +01:00
Andrew Zaborowski
ca820d5f65
iwd: Never lock to BSSID in complete_connection
The AP BSSIDs created by the iwd backend are made up so never lock the
connections to them.  It probably wouldn't matter as long as the iwd
backend is used but the fake BSSID could stay in the connection
properties even if the user switches to wpa_supplicant.
2020-11-19 10:12:02 +01:00
Andrew Zaborowski
61e516bc20
iwd: Move scheduling periodic scan out of set_current_ap()
set_current_ap() would always call schedule_periodic_scan() but: first it
would do nothing when current_ap was non-NULL because we
schedule_periodic_scan makes sure not to auto-scan when connected.
Secondly state_changed() already calls schedule_periodic_scan
indirectly through set_can_scan() so normally when we disconnect and
current_ap becomes NULL we already do trigger a scan.  The only
situation where we didn't is when a connection is cancelled during
NEED_AUTH because IWD's state doesn't change, so we add a
schedule_periodic_scan() call in network_connect_cb() on error.
2020-11-19 10:12:02 +01:00
Andrew Zaborowski
221c8d75f3
iwd: Rename can_connect and iwd_connection
Rename NMDeviceIwdPrivate.can_connect to .nm_autoconnect in preparation
to also add .iwd_autoconnect.

Rename misnamed local variable iwd_connection to nm_connection, we'll
need a new iwd_connection variable later.
2020-11-19 10:12:02 +01:00
Andrew Zaborowski
08bf75f58e
iwd: Allow scanning in NM_DEVICE_STATE_NEED_AUTH
In this state, same as in DISCONNECTED or ACTIVATED, allow scanning if
IWD is in the "connected" or "disconnected" states as there's no reason
not to scan.
2020-11-19 10:12:02 +01:00
Andrew Zaborowski
7d9b37feaf
iwd: Handle the net.connman.iwd.Agent.Cancel() method
Implement a Cancel method on our IWD secrets agent DBus object.  This
results in a call to nm_device_iwd_agent_query() for the device
currently handling the request and the @invocation parameter is NULL to
signal that the current query is being cancelled.

nm_device_iwd_agent_query doesn't do much with this call just yet but
the handling will be necessary when IWD autoconnect is used by NM.
2020-11-19 10:12:02 +01:00
Thomas Haller
adaeb7a872
dns: fix _dns_manager_set_ip_config() for missing device
Fixes: 395665902b ('dns: don't apply DNS configuration for external connections')
2020-11-19 09:25:02 +01:00
Beniamino Galvani
e2eb242c07 release: bump version to 1.29.2 (development) 2020-11-18 17:01:45 +01:00
Thomas Haller
13fc9134fa
libnm/tests: add unit test for more consistency check of NMObject type information
The type information of NMObject is entirely static. And there
are certain conditions how this information should be. Add some
more checks.

We need priv_ptr_offset set if (and only if) we also have
property_ao_info or property_o_info registered.
2020-11-18 11:41:26 +01:00
Fernando Fernandez Mancera
f40ec3344d
utils: introduce new NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_20
This patch is replacing NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW
with NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_10 and
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH with
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_30. In addition it is
introducing NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_20 which is a
middle point between the existing priorities.

This new priority is needed due to Veth support incoming. It will be
used to prevent the creation a NMDeviceWired instance.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>

[thaller@redhat.com: split original patch]
2020-11-18 10:21:57 +01:00
Fernando Fernandez Mancera
23972add8c
libnm/trivial: rename enums NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_*
We will need more levels of priority. Change the naming
to make room for that.

  sed 's/NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW/NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_10/g' `git grep -l NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_ ` -i
  sed 's/NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW/NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_10/g' `git grep -l NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_ ` -i
  ./contrib/scripts/nm-code-format-container.sh

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>

[thaller@redhat.com: split original patch]
2020-11-18 10:21:57 +01:00
Thomas Haller
8dc28e4b5e
cli: replace if-else-if construct in nmc_process_connection_properties() by continue
The if-else-if constuct spans many lines and it is not easy to see that
there is no common action after the if-else-if construct.

Instead, at the end of each if-block, just "continue" the loop. This
is similar to a "return-early" apprach and it mean you don't need
to think what happens at the end of the if-block.
2020-11-18 09:56:53 +01:00
Thomas Haller
1d6c2601b0
cli: don't fail nmcli con modify $PROFILE remove $SETTING for non-existing setting
Removing a setting that is not present should not be an error. The user
asked that the profile doesn't have the requested setting, and that
should succeed (even if that results in no actual change).

Consider when you want to make a hotspot profile "open". That implies
to remove the "wifi-sec" and "802-1x" settings. But you may
not check before whether the profile is already open, and whether
it already has those settings. We should just allow

  $ nmcli connection modify "$PROFILE" remove wifi-sec remove 802-1x

to succeed, regardless whether this changes anything or not.

Likewise, if you do

  $ nmcli connection modify "$PROFILE" con-name foo
  $ nmcli connection modify "$PROFILE" con-name foo

then the second command doesn't fail with "the name is
already \"foo\"". It just succeeds.
2020-11-18 09:56:16 +01:00
Peter Hutterer
133de4ab59
gitlab CI: remove leftover comments referring to libinput
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/684
2020-11-18 08:36:13 +01:00
Thomas Haller
5ce9f0e186
man,libnm,cli: merge branch 'th/man-cli-connection-types'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/444

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/680
2020-11-17 22:21:47 +01:00
Thomas Haller
1a998153b4
man: update supported connection types in man nmcli
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/444
2020-11-17 22:19:35 +01:00
Thomas Haller
ed67e01680
man: sort supported connection types in man nmcli 2020-11-17 22:19:29 +01:00
Thomas Haller
d0ec501163
cli: assert that valid_parts are set for base types 2020-11-17 22:19:29 +01:00
Thomas Haller
9ebeeb6bf2
cli: fix shell completion for connection.type to show "ovs-{dpkg,patch}"
nmcli --complete-args connection add type ''

would not show "ovs-{dpdk,patch}", because the conditions about what
makes a base type are not consistent with what NMSettingConnection's
verify() does.

Fix that.
2020-11-17 22:19:29 +01:00
Thomas Haller
ac7915b3ce
shared/libnm: move NMSettingPriority helpers to "shared/nm-meta-setting.h" 2020-11-17 22:19:22 +01:00
Thomas Haller
7595a8f817
ovs: merge branch 'th/ovs-external-ids-2'
https://bugzilla.redhat.com/show_bug.cgi?id=1866227

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/679
2020-11-17 19:49:43 +01:00
Thomas Haller
3a0347e821
core/ovs: for now drop cancellable from ovsdbmethod call again
Currently the cancellable is not yet used. Drop it again.

However, I think the code might be useful, so I hope to revert
this commit afterwards to use it.
2020-11-17 19:49:04 +01:00
Thomas Haller
7055539c9f
core/ovs: support setting OVS external-ids
Also support reapply. During reapply we try to preserve
keys that are added externally.

However, the current implementation does not properly use transactions
to ensure there is no race here.
2020-11-17 19:49:04 +01:00
Thomas Haller
a4b13d5069
core/ovs: log external-ids of Interfaces/Ports/Bridges 2020-11-17 19:49:04 +01:00
Thomas Haller
958d7c092e
core/ovs: cleanup logging of OvsdbMethodCall
We don't need every log line repeat all the parameters
of the call. Each call should have a unique identifier
(which is NM_HASH_OBFUSCATE_PTR(call)) and only the first
message from a call contains all the details.
2020-11-17 19:49:03 +01:00
Thomas Haller
c44c8e7fbc
core/ovs: allow ovsdb calls to be cancelled
In general, providing an async API also requires the
ability to cancel requests. It's not yet used, but add
a way to handle a GCancellable.
2020-11-17 19:49:03 +01:00
Thomas Haller
8b4d77a453
core/ovs: don't fail with "cancelled" reason for disconnected ovsdb
API should fail with a "cancelled" error if (and only if)
the user cancelled the operation. An error to communicate
with OVSDB or being disconnected should fail with a different
reason.
2020-11-17 19:49:03 +01:00
Thomas Haller
2983febf39
core/ovs: track pending calls in a CList instead of GArray
GArray is nice, because it is more memory efficient and encourages
local access. However, growing the array also means that all entries
get relocated, that means, we cannot pass on a pointer to a call
instance.

Next, we will add a way to cancel operations via a GCancellable.
That means, we subscribe to the cancelled signal and need to pass
on a user-data that indicates which call got cancelled. Since with
an GArray the calls can be relocated, we would anyway need an
additional allocation (just for the user data). So, we wouldn't
actually safe anything but make the code more complicated.

As often, CList works great in this use case. Use it.
2020-11-17 19:49:03 +01:00
Thomas Haller
4303618a30
core/ovs: move definitions of structs in "nm-ovsdb.c"
It's in general nicer to have all definitions of structs and enums
a the top of the source file. As enums and structs are commonly used
by functions, it's often nice to have the enums and structs defined
first, before all functions.
2020-11-17 19:49:03 +01:00
Thomas Haller
c45041f1fc
examples: extend "ovs-external-ids.py" to support nmcli device modify
The python example is (also) used to test the feature. That is because
currently nmcli does not yet have support for ovs.external-ids and this
API is only accessible via D-Bus (or a tool like this example).
2020-11-17 19:49:03 +01:00
Thomas Haller
afd1d58af5
libnm: return NMSetting pointer from nm_setting_ovs_external_ids_new()
After discussion ([1]), it seems this is preferred.

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/669#note_682195
2020-11-17 19:49:03 +01:00
Thomas Haller
dd9c818947
shared: add NM_UTILS_ERROR_NOT_READY enum value
This is a general error code for being not ready to perform the
operation.
2020-11-17 19:49:03 +01:00
Thomas Haller
eaa48caac4
shared: add nm_g_hash_table_ref()/nm_g_hash_table_unref() helpers 2020-11-17 19:49:02 +01:00
Thomas Haller
395665902b
dns: don't apply DNS configuration for external connections
External connections are devices that are configured outside of
NetworkManager. Such devices should be mostly ignored and not
be interfered with.

Note that we tend to create external connection profiles for
such devices. That happens for example if you use wg-quick to
manage a WireGuard interface outside of NetworkManager. But it
really happens for any interface.

This generated profile has no DNS configuration. Unless we use
the systemd-resolved backend, they thus don't contribute to the DNS
settings (which is fine).

However, with systemd-resolved, NetworkManager would also reset
the DNS configuration of those external interfaces. That is clearly
wrong. NetworkManager should only care about the interfaces that it
actively manages and leave others alone.

How to reproduce: use systemd-resolved and configure an interface outside
of NetworkManager. Note that `nmcli device` shows the state as
"connected (externally)". Note that `resolvectl` shows the DNS configuration
on that external interface. Do something in NetworkManager to trigger
a DNS update (e.g. SIGHUB or reactivate a profile). Note in `resolvectl`
that the external interface's DNS configuration was wiped.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/563#note_673283
2020-11-17 18:49:58 +01:00
Thomas Haller
f1564caa15
dns: minor cleanup in update_dns() to use gsize for size
g_strv_length() returns a guint. That is not the right size for the length
of an array. Use the right size.
2020-11-17 16:55:15 +01:00
Thomas Haller
0e7e88cfc7
gitlab-ci: combine ubuntu/centos install scripts with their debian/fedora counterparts
Ubuntu/Debian and CentOS/Fedora are sufficiently similar that it's
better that we have only one variant of ".gitlab-ci/*-install.sh"
and "contrib/*/REQUIRED_PACKAGES".

This was already the case, however, we used to symlink
".gitlab-ci/centos-install.sh" to "fedora-install.sh". That
worked, but it didn't scale very well. For example, if we would follow
that pattern, we would also need a symlink "contrib/centos/REQUIRED_PACKAGES"
Or should "contrib/centos" symlink to "contrib/fedora"? That seems even
more wrong.

We already had the "distro.base_type" variable for that. Make use of
that also for the install script.
2020-11-17 13:28:18 +01:00
Thomas Haller
bef8166893
build: add make-check step to check and generate ".gitlab-ci.yml" 2020-11-17 13:19:14 +01:00
Yuri Chornoivan
41a684f630
po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/681
2020-11-17 13:13:44 +01:00
Thomas Haller
f1ff6fe8b7
gitlab-ci: install correct version of ci-templates in build script
It's not clear that ci-fairy has a stable API. Instead, we pin the
version by specifying the git commit sha.

In the build script, install the pinned version.
2020-11-17 09:48:48 +01:00