Commit Graph

21076 Commits

Author SHA1 Message Date
Beniamino Galvani
53d9050b36 core: add nm_config_data_get_connection_default_int64() 2018-09-06 09:07:41 +02:00
Thomas Haller
ffea27a581 settings: merge branch 'th/settings-cleanup'
https://github.com/NetworkManager/NetworkManager/pull/190
2018-09-06 07:41:33 +02:00
Thomas Haller
3091ffa50a settings/ifupdown: use _NMLOG() macros for logging
Does not address the issues that the existing logging is much too verbose
and does not provide necessary context for what it's complaining. The
logging messages should be improved.

At least, the logging macro gives all messages a "ifupdown: " prefix.
2018-09-06 07:41:22 +02:00
Thomas Haller
7064b81bbc settings/ifupdown: various cleanup in nms-ifupdown-parser.c 2018-09-06 07:41:22 +02:00
Thomas Haller
bb273c0881 settings/ifupdown: optimize allocating parser data 2018-09-06 07:41:22 +02:00
Thomas Haller
fe018a7e81 settings/ifupdown: use c-list for data structure of ifupdown parser
We already have a linked-list implementation. Use it.
2018-09-06 07:41:22 +02:00
Thomas Haller
70350bb621 settings/ifupdown: don't use global variables for /e/n/i parser 2018-09-06 07:41:22 +02:00
Thomas Haller
6f14228cb3 settings/ifupdown: hide internal functions in "nms-ifupdown-interface-parser.h" 2018-09-06 07:41:22 +02:00
Thomas Haller
b8da0855fa settings/ifupdown: refactor string prefix matching in parser 2018-09-06 07:41:22 +02:00
Thomas Haller
de2e75e327 settings/ifupdown: use nm_streq() in parser 2018-09-06 07:41:22 +02:00
Thomas Haller
03be91f038 settings/ifupdown: adjust coding style for "nms-ifupdown-interface-parser" 2018-09-06 07:41:22 +02:00
Thomas Haller
518c7be77b settings/ifupdown: in plugin drop listening to udev for devices
Don't listen to udev to find out about devices. First of all, using udev
for this is already very wrong, because we have the platform cache.

Anyway, all that the device information is used, is pointless as well.
Drop it.

It's pointless because:

The entires in eni_ifaces are already indexed by the interface name.
Likewise, all NMIfupdownConnection set "connection.interface-name" to
restict the profile by name.
/e/n/i matches devices is by name, that's it. We don't need udev to
look up the MAC address (by name!!) to later ignore/match devices
by MAC address. Especially, because NetworkMaanger can already
restrict profiles to devices based on the interface name.
Likewise, NetworkMaanger can use the interface name for the
unmanaged-specs.
It's wrong to extend the on-disk configuration from /e/n/i with runtime
information from udev, especially, because other NetworkMaanger layers
are perfectly content using the interface name for this purpose.

Also, bind_device_to_connection() was fundamentally wrong. It's wrong
to modify the settings connection at random moments (on udev event).
If at all, that should only happen during connection load/reload.

This may have been necessary a long time ago, when unmanaged devices were
not expressed by device-match-specs, but by the HAL UDI. That was since
improved, for example by commit c9067d8fed.
2018-09-06 07:41:22 +02:00
Thomas Haller
6aa66426a4 settings/ifupdown: merge eni_ifaces and connections hashes in plugin
The "connections" hash contains a mapping of block->name (iface) to the
NMSettingsConnection. The "eni_ifaces" hash contains the name of all
blocks which are mentioned, but for which no connection was created.

Merge the two hashes. We don't need to keep track of whether a
connections was successfully created ("connections"), but the
same name also has a non-connection block. This information is
unnecessary, so one hash is enough.
2018-09-06 07:41:22 +02:00
Thomas Haller
dfadaaf7f8 settings/ifupdown: change plugin's field @unmanage_well_known to @ifupdown_managed
@unmanage_well_known directly depends on the "ifupdown.managed" setting from
NetworkManager.conf. Rename it (and invert the meaning) so that this
relation ship becomes clearer.

Also, the double negation of "if (!unmanaged_well_known)" hurts the
brain.
2018-09-06 07:41:22 +02:00
Thomas Haller
afb9fa6753 settings/ifupdown: drop unused define ALWAYS_UNMANAGE in plugin
This is only useful for testing. But since the managed flag is configurable
via NetworkManager.conf, there is no point in having a define as well. If
you want to test it, just configure it.

And if you really want to patch the code, then patch
"priv->unmanage_well_known" to be always TRUE.
2018-09-06 07:41:22 +02:00
Thomas Haller
fab0d214b7 settings/ifupdown: cleanup plugin's logging
- use _NMLOG() macro and give logging message a sensible prefix

- downgrade logging severity. Most of these messages are not
  important to warrant <info> or <warn> level.

- the logging is generally rather bad. Messages like

    "bind-to-connection: locking wired connection setting"

  don't indicate which profile is locked to which MAC address.
  TODO.
2018-09-06 07:41:22 +02:00
Thomas Haller
fb04a7b722 settings/ifupdown: cleanup plugin's get_connections() 2018-09-06 07:41:22 +02:00
Thomas Haller
f804b23b64 settings/ifupdown: cleanup parsing bridge in plugin's initialize() 2018-09-06 07:41:22 +02:00
Thomas Haller
f0509205a2 settings/ifupdown: refactor parsing loop in plugin's initialize() 2018-09-06 07:41:22 +02:00
Thomas Haller
f0938948bc settings/ifupdown: replace strcmp() usage with nm_streq()/NM_IN_STRSET() in plugin 2018-09-06 07:41:22 +02:00
Thomas Haller
553c3368ab settings/ifupdown: minor cleanup of auto-ifaces in plugin's initialize()
- use gs_unref_hashtable for managing lifetime

- only allocate the hashtable if necessary, and use g_hash_table_add()
  which is optimized by HashTable.

- actually copy the block->name that is used as key. While not
  necessary at the moment, it is very ugly how ifparser_getfirst()
  returns static data. Optimally, this would be fixed and we create
  and destroy the parser results. Hence, ensure the lifetime of
  the key.
2018-09-06 07:41:22 +02:00
Thomas Haller
42c2055a31 settings/ifupdown: cleanup lifetime and memory handling of dictionaries in plugin
- initialize the hash tables in the plugins constructor, not during
  initialize().

- let all dictionaries own a copy/reference of the keys and values, and
  properly free them when the values are removed. In general, avoid
  leaks by properly managing lifetimes.

- in @eni_ifaces, don't add a pointless dummy value "known". It has
  overhead for no benefit.
2018-09-06 07:41:22 +02:00
Thomas Haller
0ea810fa96 settings: cleanup loading settings plugins
Drop the unnecessary @list argument and various cleanups.
2018-09-06 07:41:22 +02:00
Thomas Haller
dd5244af3e settings: disconnect signals from plugins when destroying NMSettings
Currently we anyway leak everything on shutdown, so this doesn't matter.
But to be correct, we must disconnect signal handlers.
2018-09-06 07:41:22 +02:00
Thomas Haller
657b0714b8 settings: make NMSettingsPlugin a regular GObject instance and not an interface
NMSettingsPlugin was a glib interface, not a regular GObject
instance. Accordingly, settings plugins would implement this interface
instead of subclassing a parent type.

Refactor the code, and make NMSettingsPlugin a GObject type. Plugins
are now required to subclass this type.

Glib interfaces are more cumbersome than helpful. At least, unless
there is a good reason for using them.

Our settings plugins are all internal API and are entirely under
our control. It also means, this change is fine, as there are no
implementations outside of this source tree.

Using interfaces do would allow more flexibility in implementing the
settings plugin.
For example, the plugin would be able to derive from any other GObject
type, like NMKimchiRefrigerator. But why would we even? Let's not add monster
classes that implement house appliances beside NMSettingsPluginInterface.
The settings plugin should have one purpose only: being a settings plugin.
Hence, requiring it to subclass NMSettingsPlugin is more than resonable. We
don't need interfaces for this.

Now that NMSettingsPlugin is a regular object instance, it may also have
state, and potentially could provide common functionality for the plugin
implementation -- if that turns out to be useful. Arguably, an interface can
have state too, for example by attaching the state somewhere else (like
NMConnection does). But let's just say no.

On a minor note, this also avoids some tiny overhead that comes with
glib interfaces.
2018-09-06 07:41:22 +02:00
Thomas Haller
32442b2661 settings: drop unused get_plugin() checks
Nowadays, keyfile settings plugin is always loaded. Hence,
this function never returns %NULL and the checks always
evalute the the same.
2018-09-06 07:41:22 +02:00
Thomas Haller
194e7f8df6 settings: rename NMSettingsPluginInterface.init() to initialize()
The virtual function init() naturally leads to calling the wrapper
function nm_settings_plugin_init(). However, such ${TYPE}_init() functions
are generated by G_DEFINE_TYPE().

Rename to avoid the naming conflict, which will matter next, when the
interface will be converted to a regular GObject class.

Note that while these are settings plugin, there is no public
or stable API which we need to preserve.
2018-09-06 07:41:22 +02:00
Thomas Haller
122bb485ee settings: remove empty NMSettingsPluginInterface.init() implementations 2018-09-06 07:41:22 +02:00
Thomas Haller
80cb515681 settings/keyfile: always return path from nms_keyfile_writer_connection()
Previously, nms_keyfile_writer_connection() would only return @out_path, if
it differed from @existing_path. That might make sense, if we could thereby
avoid duplicating @existing_path, however, we never did that
optimization.

Just consistently always return the path, let the caller deal with this.
2018-09-06 07:41:22 +02:00
Thomas Haller
986ca94a36 libnm: assert in nm_utils_is_uuid() for valid argument
nm_utils_is_uuid() is public API. Commonly we check input arguments for such
functions with g_return_*() assertions.
2018-09-06 07:41:22 +02:00
Thomas Haller
921db9132e build: fix whitelisting c-siphash symbols in NetworkManager.ver for device plugin
NetworkManager.ver needs to whitelist symbols needed by device,
settings, and ppp plugin. Fix the generator script to also allow
using c_siphash_*() symbols. These are needed by nm_hash_*().

Without this, wifi device plugin is broken.

Fixes: ccf36ff4ce
2018-09-05 16:55:45 +02:00
Beniamino Galvani
c7c989804f core: merge branch 'bg/rh1542366'
https://bugzilla.redhat.com/show_bug.cgi?id=1542366
2018-09-05 16:50:29 +02:00
Beniamino Galvani
281974b932 manager: don't update ifindex of existing devices
When NM has to rebuild the platform cache, it first generates ADD and
then REMOVE events for the links.  So, if an interface is removed and
readded, platform will emit the ADDED event with a new ifindex while
the device with old ifindex still exists.

In such case the manager currently updates the device's ifindex but
this causes problems as the DNS manager tracks configurations by their
ifindex and so the configurations for the old device will become
stale.

Fix this by removing the device and adding it again when we detect a
change of ifindex on a device that already had valid one.

https://bugzilla.redhat.com/show_bug.cgi?id=1542366
2018-09-05 16:13:59 +02:00
Beniamino Galvani
9ed07fbb46 device: clear queued IP config sources when the device is unrealized
If the device is later realized again, we assert that there aren't any
IP config changes queued. Therefore, they must be cleared on
unrealize().
2018-09-05 16:13:59 +02:00
Beniamino Galvani
0e367d40f4 platform: fix typo
progess -> progress
2018-09-05 16:13:59 +02:00
Thomas Haller
3ec6a4479c wifi/iwd: merge branch 'balrog-kun/iwd-known-networks'
https://github.com/NetworkManager/NetworkManager/pull/183
2018-09-05 16:06:57 +02:00
Thomas Haller
0998868912 wifi/iwd: fix tracking of IWD-side known networks
- since commit d17d26887c, 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-05 15:24:04 +02:00
Thomas Haller
13d8455a7c wifi: trust eap methods from profile to be lower-case
NMSetting8021x::verify() checks the string values for eap methods.
They must all be non-NULL and are not compared case-insensitive.
2018-09-05 15:24:04 +02:00
Thomas Haller
1181f88ef1 wifi/iwd: various minor cleanups in nm-iwd-manager.c
- prefer "gsize" instead of "size_t".
2018-09-05 15:24:04 +02:00
Thomas Haller
ccf36ff4ce wifi/iwd: use NMHashState (siphash24) for hashing
We shall use nm_hash_*() functions everywhere where
we need a hash for a dictionary.
2018-09-05 15:24:04 +02:00
Thomas Haller
be875fe382 wifi/iwd: in manager's interface_added() ensure known-network ID is not 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-05 15:24:04 +02:00
Andrew Zaborowski
2c8161868e wifi/iwd: Create connections for IWD-side known networks
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-05 15:24:04 +02:00
Andrew Zaborowski
977d298c5f libnm-core: 8021x: Allow a new eap value "external"
To allow connections that mirror IWD's configured WPA-Enterprise
networks to be seen as valid by NM, add a new value for the eap key in
802-1x settings.  802-1x.eap stores EAP method names.  In the IWD
connections we don't know what EAP method is configured and we don't
have any of the other 802-1x properties that would be required for the
settings to verify.

These connections can't be activated on devices managed by wpa_supplicant.
2018-09-05 15:24:04 +02:00
Andrew Zaborowski
43ea446a50 wifi: Move get_connection_iwd_security to nm-wifi-utils.c
Make this function public.  I'm not sure if at this point it makes
much sense to add a new file for iwd-specific utilities.
While there add a way for the function to return error if security
type can't be mapped to an IWD-supported security type.
2018-09-05 15:24:04 +02:00
Andrew Zaborowski
142d83b019 wifi/iwd: Track known networks using interface-added/-removed signals
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-05 15:24:04 +02:00
Andrew Zaborowski
78303e1ab8 wifi/iwd: Convert manager.known_networks to a GHashTable 2018-09-05 15:24:04 +02:00
Andrew Zaborowski
2f941c0790 wifi/iwd: Drop nm_iwd_manager_network_connected
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-05 15:24:04 +02:00
Andrew Zaborowski
eec61a8e81 wifi/iwd: Drop usage of the KnownNetworks IWD API
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-05 15:24:04 +02:00
Andrew Zaborowski
f2be625a07 wifi/iwd: Check g_dbus_proxy_get_cached_property return values
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-09-05 15:24:04 +02:00
Beniamino Galvani
5ef8284a01 core: add test for nm_wildcard_match_check()
https://github.com/NetworkManager/NetworkManager/pull/181
2018-09-05 15:12:39 +02:00