summaryrefslogtreecommitdiff
path: root/src/devices/wifi/nm-iwd-manager.c
AgeCommit message (Collapse)AuthorFilesLines
2018-11-29all: say Wi-Fi instead of "wifi" or "WiFi"Lubomir Rintel1-1/+1
Correct the spelling across the *entire* tree, including translations, comments, etc. It's easier that way. Even the places where it's not exposed to the user, such as tests, so that we learn how is it spelled correctly.
2018-10-23wifi/iwd: handle forgetting connection profilesAndrew Zaborowski1-13/+77
Watch for connection-removed events and delete corresponding IWD network configs if found. This mainly changes anything for 802.1X networks where the deleted NM connections might annoyingly re-appear after a restart. For PSK networks though it'll make IWD forget the password which, until now, would be remembered by IWD even if it was removed or changed in the NM profile, which is a bug. This is still fragile because we don't handle "connection-updated" events so the data->mirror_connection pointer for a known network record may after some time point to an NMSettingsConnection with a different SSID or security type and there are corner cases where the IWD-side profile will not be forgotten. At least I'm trying to make sure we don't crash and don't wrongly remove any IWD profile which could also be annoying for complicated EAP configs.
2018-10-23wifi/iwd: print warning if known network exists in interface-addedAndrew Zaborowski1-2/+5
Something is possibly wrong with the DBus signal handling if a newly added KnownNetwork interface already has an entry in priv->known_networks, but since we handle this case add a warning and update the GDBusProxy pointer for that existing entry.
2018-10-23wifi/iwd: return existing connection from mirror_8021x_connectionAndrew Zaborowski1-7/+25
interface_added expects mirror_8021x_connection() to return the pointer to the existing connection if one exists, and NULL on error, rather than NULL if a conneciton exists. While touching that, add logic to return specifically a connection with EAP method set to 'external' if one exists even though this should not affect any other logic we have currently.
2018-09-19wifi/iwd: don't save secrets in mirror NM connectionsAndrew Zaborowski1-1/+10
When creating the mirror 802.1x connections for IWD 802.1x profiles set the NM_SETTING_SECRET_FLAG_NOT_SAVED flag on the secrets that may at some point be requested from our agent. The saved secrets could not be used anyway because of our use of NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW in nm_device_iwd_agent_query. But also try to respect whatever secret caching policy has been configured in the IWD profile for those secrets, IWD would be responsible for storing them if it was allowed in the profile.
2018-09-19wifi/iwd: access Network objects through ObjectManagerAndrew Zaborowski1-0/+15
In two places stop using g_dbus_proxy_new_* to create whole new interface proxy objects for net.connman.iwd.Network as this will normally have a huge overhead compared to asking the ObjectManager client that we already have in NMIwdManager for those proxies. dbus-monitor shows that for each network path returned by GetOrderedNetworks () -- and we call it every 10 or 20 seconds and may get many dozens of networks back -- gdbus would do the following each time: org.freedesktop.DBus.AddMatch("member=PropertiesChanged") org.freedesktop.DBus.StartServiceByName("net.connman.iwd") org.freedesktop.DBus.GetNameOwner("net.connman.iwd") org.freedesktop.DBus.Properties.GetAll("net.connman.iwd.Network") org.freedesktop.DBus.RemoveMatch("member=PropertiesChanged")
2018-09-07wifi/iwd: fix leaking agent DBus objectsAndrew Zaborowski1-22/+31
Make sure we free our IWD agent objects whenever we're freeing the IWD Object Manager. We're registering those objects on the same DBus connection as the Object Manager so that they're visible to IWD, and our only reference to that connection is through priv->object_manager so even though the connection isn't changing when we free the object manager and create a new one, we still need to free the agent object. We could maybe keep a reference to the connection, but I'm not sure there's any warranty that it doesn't get closed. We could also use nm_dbus_manager_get_connection (nm_dbus_manager_get ()) and only register and free the agent once, since it happens to be the same connection but it'd perhaps be a hack to rely on this.
2018-09-05wifi/iwd: fix tracking of IWD-side known networksThomas Haller1-55/+66
- since commit d17d26887c69c8c3adcd6003a7ceea16b4eecd14, a NMSettingsConnection no longer "is-a" NMConnection. Instead, we must call nm_settings_connection_get_connection() to obtain the NMConnection instance. Adjust this in mirror_8021x_connection() - don't leak "ssid" in mirror_8021x_connection() - move deletion of the mirror-connection to known_network_data_free(). Previously, we must have made sure that every g_hash_table_remove() and g_hash_table_insert()(!!) first deletes the mirror connection. Likewise, in got_object_manager() when we call g_hash_table_remove_all(), delete created mirror connections. - rework interface_added() to make it robust against calling interface_added() more than once without removing the interface in between. Essentially, this just means that we first look into "priv->known_networks" to see whether the @id is already tracked. And if so, delete an existing mirror-connection as necessary.
2018-09-05wifi/iwd: various minor cleanups in nm-iwd-manager.cThomas Haller1-13/+15
- prefer "gsize" instead of "size_t".
2018-09-05wifi/iwd: use NMHashState (siphash24) for hashingThomas Haller1-1/+6
We shall use nm_hash_*() functions everywhere where we need a hash for a dictionary.
2018-09-05wifi/iwd: in manager's interface_added() ensure known-network ID is not ↵Thomas Haller1-1/+1
wrongly destroyed Calling g_hash_table_insert() with a key which is already hashed will destroy the *new* key. Since @id is used below, that would be use after free. Fixes: d635caf940551f8f5b52683b8379a1f81c58f8fc
2018-09-05wifi/iwd: Create connections for IWD-side known networksAndrew Zaborowski1-1/+126
IWD's mechanism for connecting to EAP networks requires a network config file to be present in IWD's storage. NM and its clients however won't allow a connection to be attempted until a valid NMConnection is created on the NM side for the network. To avoid duplicating the settings from the IWD-side profiles in NM, automatically create NMSettingConnections for EAP networks preconfigured on the IWD side, unless a matching connection already exists. These connections will use the "external" EAP method to mean their EAP settings can't be modified through NM, also they won't be valid for devices configured to use the wpa_supplicant backend unfortunately. Those nm-generated connections can be modified by NM users (makes sense for settings not related to the wifi authentication) in which case they get saved as normal profiles and will not be recreated as nm-generated connections on the next run. I want to additionally handle deleting connections from NM clients so that they're also forgotten by IWD, in a later patch.
2018-09-05wifi/iwd: Track known networks using interface-added/-removed signalsAndrew Zaborowski1-22/+95
The known networks hash table is indexed by the (ssid, security) tuple for fast lookups both on DBus signals related to an IWD known network and local NMConnection signals such as on removal.
2018-09-05wifi/iwd: Convert manager.known_networks to a GHashTableAndrew Zaborowski1-19/+39
2018-09-05wifi/iwd: Drop nm_iwd_manager_network_connectedAndrew Zaborowski1-16/+0
There's no need anymore for NMIwdManager to know when a network has been connected to, InterfaceAdded signals are now emitted when a network is saved as a Known Network.
2018-09-05wifi/iwd: Drop usage of the KnownNetworks IWD APIAndrew Zaborowski1-88/+0
Before 0.5 IWD has changed the known networks API to expose separate objects for each known network and dropped the KnownNetworks manager-like interface so stop using that interface. Following patches will add tracking of the known networks through ObjectManager.
2018-09-05wifi/iwd: Check g_dbus_proxy_get_cached_property return valuesAndrew Zaborowski1-30/+35
Instead of passing the return values to g_variant_get_string or g_variant_boolean and then checking the return value of that call, add wrappers that first check's whether the variant is non-NULL and of the right type. g_variant_get_string doesn't allow a NULL parameter and will also never return NULL according to the docs. For the State property we assume a state "unknown" and emit a warning if the property can't be read, "unknown" is also a string in IWD itself which would be returned if something went really wrong. In any case this shouldn't happen. [thaller@redhat.com: fix missing initialization of nm_auto() variable interfaces.]
2018-07-13wifi/ifd: Allow D-Bus activation to launch iwdJan Alexander Steffens (heftig)1-1/+1
iwd does not ship activation configuration yet; until then we simply fail the way we already do. https://bugzilla.gnome.org/show_bug.cgi?id=796805
2018-07-11all: don't use gchar/gshort/gint/glong but C typesThomas Haller1-14/+14
We commonly don't use the glib typedefs for char/short/int/long, but their C types directly. $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l 587 $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l 21114 One could argue that using the glib typedefs is preferable in public API (of our glib based libnm library) or where it clearly is related to glib, like during g_object_set (obj, PROPERTY, (gint) value, NULL); However, that argument does not seem strong, because in practice we don't follow that argument today, and seldomly use the glib typedefs. Also, the style guide for this would be hard to formalize, because "using them where clearly related to a glib" is a very loose suggestion. Also note that glib typedefs will always just be typedefs of the underlying C types. There is no danger of glib changing the meaning of these typedefs (because that would be a major API break of glib). A simple style guide is instead: don't use these typedefs. No manual actions, I only ran the bash script: FILES=($(git ls-files '*.[hc]')) sed -i \ -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \ -e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \ -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \ "${FILES[@]}"
2018-06-22wifi/iwd: downgrade error levels for agent-request failuresThomas Haller1-6/+6
<error> level is for something really bad happening. When another party (iwd in this case) sends a D-Bus request that we cannot meaningfully handle, that is hardly reason to warn about. <debug> level is enough in this case. Also, give all messages a common prefix "agent-request" so that we have something to grep for. (cherry picked from commit aef5110fa60ab4c6ceb14b91a2e5ca04f529219f)
2018-06-22wifi/iwd: fix leaking name-owner in agent_dbus_method_cb()Thomas Haller1-2/+3
(cherry picked from commit 412a1fb46d4257f49b07b6aed262904506777d1e)
2018-06-22wifi/iwd: don't check return value for nm_utils_random_bytes()Thomas Haller1-9/+2
nm_utils_random_bytes() will always try its best to give some random numbers. A failure only means, that the kernel interfaces get_random() or /dev/urandom failed to provide good randomness. We don't really need good random numbers here, so no need to handle a failure. (cherry picked from commit 44cd60e82077a8f90511b8534ee12cf3ff182ff9)
2018-06-22iwd: handle new secret request types from IWD agentAndrew Zaborowski1-56/+62
The IWD DBus interface currently (https://git.kernel.org/pub/scm/network/wireless/iwd.git/tree/doc/agent-api.txt?id=38952813dddd776f66d2ed5e88eca9a892964c06) knows about 3 secret types related to 802.1x authentication in addition to the PSK secret request. Add support for the new methods and the new secret types in NM's implementation of the IWD secret agent. Note that the secret types are mapped to NMSetting8021x property keys and they are then sent to the NM Secret Agent in the hints parameter to GetSecrets, this will need support in the NM clients as the exact usage of the hints parameter is specified a little ambiguously, but this seems to be one of the permitted usages. Rework the IWD agent interface info initialization to use NM convenience macros. (cherry picked from commit 74d9e04a66dce87cddee6476cdbd244e83ae6379)
2018-04-30all: remove consecutive empty linesBeniamino Galvani1-1/+0
Normalize coding style by removing consecutive empty lines from C sources and headers. https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-04device/trival: rename NMIwdManagerPrivate.nm_manager field to "manager"Thomas Haller1-9/+9
Similar cases of such a field are named "manager". Also, internal names shall not have an "nm" prefix, contrary to names in a header file, which shall have such a prefix.
2018-04-04core: add macro for iterating CList of devices of NMManagerThomas Haller1-8/+6
I find it slightly nicer and explict. Also, the list elements are strictly speaking private, we should better not explicitly use them outside of NMManager/NMDevice. The macro hides this.
2018-03-27core: track devices in manager via embedded CListThomas Haller1-5/+4
Instead of using a GSList for tracking the devices, use a CList. I think a CList is in most cases the more suitable data structure then GSList: - you can find out in O(1) whether the object is linked. That is nice, for example to assert in NMDevice's destructor that the object was unlinked, and we will use that later in nm_manager_get_device_by_path(). - you can unlink the element in O(1) and you can unlink the element without having access to the link's head - Contrary to GSList, this does not require an extra slice allocation for the link node. It quite possibliy consumes slightly less memory because the CList structure is embedded in a struct that we already allocate. Even if slice allocation would be perfect to only consume 2*sizeof(gpointer) for the link note, it would at most be as-good as CList. Quite possibly, there is an overhead though. - CList possibly has better memory locality, because the link structure and the data are close to each other. Something which could be seen as disavantage, is that with CList one device can only be tracked in one NMManager instance at a time. But that is fine. There exists only one NMManager instance for now, and even if we would ever introduce multiple managers, we probably would not associate one NMDevice instance with multiple managers. The advantages are arguably not huge, but CList is IMHO clearly the more suited data structure. No need to stick to a suboptimal data structure for the job. Refactor it.
2018-03-05iwd: fix device-added signal handler signatureAndrew Zaborowski1-2/+2
This bug was not causing a crash for me because of the !IS_NM_DEVICE_IWD check and because my glib version probably had the assertion within NM_IWD_MANAGER_GET_PRIVATE disabled. While there, change the g_signal_connect line to use the macro for the signal name.
2018-03-05iwd: Only request secrets on request from IWDAndrew Zaborowski1-12/+5
Remove the code (mostly copied from nm-device-wifi.c) that handles checking if the secrets were provided and requesting missing secrets before starting a connection attempt. Instead, request secrets when we're asked for them by IWD through its agent interface. This happens while the dbus Connect call is running. We change the NMDevice from the CONFIG state to NEED_AUTH and then change back to CONFIG once we sent the secrets back to IWD. The current code would require the secrets only based on whether a network is a KnownNetwork but IWD may need a new passwords even for KnownNetworks if the last connection attempt has failed.
2018-02-09wifi/iwd: make NMIwdManager:dispose() reentrantThomas Haller1-2/+4
Theoretically, dispose() could be called multiple times.
2018-02-09iwd: avoid duplicate nm_device_iwd_set_dbus_object callAndrew Zaborowski1-0/+3
Avoid calling nm_device_iwd_set_dbus_object (device, NULL) if the dbus_object was NULL already. Apparently gdbus guarantees that a name-owner notification either has a NULL old owner or a NULL new owner but can also have both old and new owner NULL.
2018-02-09iwd: recreate GDbusObjectManagerClient on reconnectAndrew Zaborowski1-21/+27
Reuse the apparent workaround from libnm/nm-client.c in which the GDbusObjectManagerClient is recreated every time the name owner pops up, instead of creating it once and using that object forever. Resubscribe to all the signals on the new object. The initial GDbusObjectManager we create is only used to listed for the name-owner changes. There's nothing in gdbus docs that justifies doing that but there doesn't seem to be any way to reliably receive all the signals from the dbus service the normal way. The signals do appear on dbus-monitor and the gdbus apparently subscribes to those signals with AddMatch() correctly but they sometimes won't be received by the client code, unless this workaround is applied. While making changes to got_object_manager, don't destroy the cancellable there as it is supposed to be used throughout the NMIwdManager life.
2018-02-09iwd: keep reference to NMManager, disconnect signalsAndrew Zaborowski1-14/+11
Disconnect from NMManager signals in our cleanup, make sure the NMManager singleton is not destroyed before we are by keeping a reference until we've disconnected from its signals.
2017-12-21iwd: Track IWD Known NetworksAndrew Zaborowski1-15/+159
Keep a list of IWD's Known Networks which are networks that have their configurations stored by IWD including the secrets, either because they have been connected to before or because they were preprovisioned on the machine.
2017-12-13devices/wifi: Register an IWD PSK agent on dbusAndrew Zaborowski1-1/+205
Add the PSK agent support to support PSK networks. Note that the PSK itself will be saved by IWD on the first successful connection to the network and will not be updated when it is changed by the user on the NM side, this still needs fixing like a bunch of other problems. [bgalvani@redhat.com: fix checking return value of nm_utils_random_bytes()]
2017-12-13devices/wifi: Track IWD devices, match to NMDeviceIwd objectsAndrew Zaborowski1-0/+348
Add the NMIwdManager singleton to be responsible for matching NMDeviceIwd objects created from platform devices, to IWD Device dbus objects when they appear/disappear.