Commit graph

1219 commits

Author SHA1 Message Date
Thomas Haller
52dbab7d07 all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like

   GPtrArray *ptr_arr = ...

   g_clear_pointer (&ptr_arr, g_array_unref);

Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.

[1] f9a9902aac

We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.

Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.

Replace:

   sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:22:38 +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
ffa098edae all: unify spelling of "fall-through" comment for switch statements
We used "/* fall through */" and "/* fall-through */" inconsistently.
Rename to use only one variant.
2020-02-21 18:24:25 +01:00
Thomas Haller
121d446354 device: merge nm_device_get_dhcp[46]_config() to nm_device_get_dhcp_config() 2020-02-21 15:59:44 +01:00
Thomas Haller
26f208aec3 core: add common base class NMDhcpConfig for NMDhcp[46]Config and merge them
The advantage is that the API is now the same for IPv4 and IPv6: it's
all nm_dhcp_config_*() and we can (easier) treat the address family
generically.

We still need two distinct GObject types, mainly because of the
glue code for exposing the object on D-Bus as NMDBusObject. Of course,
that could be solved differently, but as it is, it's quite nice.
2020-02-21 15:59:44 +01:00
Beniamino Galvani
efc04b1285 Revert "core: create virtual device on settings changes in idle handler"
When AddConnection() or Update() terminate, the (unrealized) virtual
device should be already be available, otherwise an activation attempt
of that connection can fail.

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

This reverts commit c163207b07.
2020-02-19 10:03:58 +01:00
Beniamino Galvani
e127a82370 Revert "manager: drop devices_inited field in NManagerPrivate for devices_inited_id"
After this change the startup-complete event is reached too early,
even before priv->devices_inited_id is initialized.

This reverts commit d50856b5c6.
2020-02-17 13:30:35 +01:00
Thomas Haller
d50856b5c6 manager: drop devices_inited field in NManagerPrivate for devices_inited_id
It is redundant. Drop it.

Also, we don't need to cancel and reschedule the idle source in
nm_manager_start(). First of all, it really shouldn't be pending.
Second, contrary to a timer, when an idle source is already pending,
then the pending one will run at the right time.
2020-02-14 11:56:44 +01:00
Thomas Haller
de62da297e all: drop explicit casts from _GET_PRIVATE() macro calls
The _GET_PRIVATE() macros are all implemented based on
_NM_GET_PRIVATE(). That macro tries to be more type safe and uses
_Generic() to do the right thing. Explicitly casting is not only
unnecessary, it defeats these (static) type checks.

Don't do that.
2020-02-14 11:04:46 +01:00
Thomas Haller
cd31437024 shared: drop _STATIC variant of macros that define functions
Several macros are used to define function. They had a "_STATIC" variant,
to define the function as static.

I think those macros should not try to abstract entirely what they do.
They should not accept the function scope as argument (or have two
variants per scope). This also because it might make sense to add
additional __attribute__(()) to the function. That only works, if
the macro does not pretend to *not* define a plain function.

Instead, embrace what the function does and let the users place the
function scope as they see fit.

This also follows what is already done with

    static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
2020-02-13 17:17:07 +01:00
Thomas Haller
8c23586a77 shared: drop nm_utils_dbus_normalize_object_path() in favor of nm_dbus_path_not_empty()
They do the same thing. Unify and drop one.
2020-02-10 19:11:50 +01:00
Beniamino Galvani
ab57b575a0 manager: check for master existence before realizing the device
If we find out that no compatible master connection exists, we
shouldn't realize the slave in the first place.
2020-01-29 16:43:19 +01:00
Beniamino Galvani
336bfcabc4 manager: skip activation of a virtual device if master is missing
Don't realize a virtual device if the master is missing because in
such case the autoactivation can't start and a stale link will be
created.
2020-01-29 16:43:19 +01:00
Antonio Cardace
1e45865e4f shared: nm-auth-subject: add unix-session type 2019-12-24 10:13:51 +01:00
Antonio Cardace
0f7994328d shared: move nm-dbus-auth-subject to shared/nm-libnm-core-intern
Move it to shared as it's useful for clients as well.

Move and rename nm_dbus_manager_new_auth_subject_from_context() and
nm_dbus_manager_new_auth_subject_from_message() in nm-dbus-manager.c
as they're needed there.
2019-12-24 10:13:51 +01:00
Thomas Haller
785da51d83 core: add and indicate NM_CAPABILITY_OVS capability on D-Bus
https://bugzilla.redhat.com/show_bug.cgi?id=1785147
2019-12-21 11:33:59 +01:00
Beniamino Galvani
6c716912eb manager: create a virtual device only if the connection can autoconnect
The autoconnection for virtual devices currently works in two
phases. First we detect that there is suitable profile that can
autoconnect and we realize the device. Then, when the device becomes
'disconnected', autoconnect kicks in and starts the activation.

However, if autoconnect is blocked for a device, currently we do step
1 without step 2, leaving a stale interface around. Fix this by also
checking that autoconnect is not blocked during step 1.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/360
2019-12-15 09:36:27 +01:00
Alexey Kodanev
70ebdc7730 nm-manager: restore passing correct size to sendfile in copy_lease()
Otherwise sendfile() fails with EINVAL when the file offset
is greater than zero (pos + size > max), always on the second
iteration.

Fixes: 0c6cd07ec8 ('nm-manager: remove lease file if copying dhclient lease fails')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/359
2019-12-12 08:07:20 +01:00
Beniamino Galvani
f2dbf8fbc0 manager: forbid autoactivation of parent when it is blocked by user request
If a device is being autoactivated and requires a parent that is
blocked due to user request, the autoactivation attempt should fail
because NM shouldn't overrule the user decision.

https://bugzilla.redhat.com/show_bug.cgi?id=1765566
2019-12-11 13:46:57 +01:00
Thomas Haller
0c6cd07ec8 nm-manager: remove lease file if copying dhclient lease fails
- also use nm_auto_close and nm_close().
2019-12-11 10:05:00 +01:00
Alexey Kodanev
ce1f9e6eb9 nm-manager: fix selinux label for dhclient lease file from initramfs
When moving a lease file from initramfs directory to NetworkManager
run directory, SELinux label for that file retains tmpfs_t type.

Fix it by using sendfile() instead of rename(). That way, the
lease file will have the default type: NetworkManager_var_run_t.
Since we take ownership of the lease file, also drop it from the
old location.

* Before the patch:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:tmpfs_t:s0 dhclient-13162c00-abfb-4e28-bbfb-170187ddd044-ens3.lease

* After:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:NetworkManager_var_run_t:s0 dhclient-f47d1908-67ae-49c6-bd5e-19a690d85526-ens3.lease

Fixes: f2fe6c03ee ('manager: don't treat the initramfs-configured DHCP connections as generated')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/353
2019-12-11 09:58:45 +01:00
Thomas Haller
33754752ea core: use nm_client_permission_result_to_string() to map permission result
In NetworkManager we have NMAuthCallResult, which is really a duplicate
of NMClientPermissionResult.

Maybe NMAuthCallResult should be entirely replaced by NMClientPermissionResult.
But the name NMClientPermissionResult is a bit awkward. But then the
duplication is even more awkward... fixing this is left for another day.
2019-12-10 07:53:25 +01:00
Thomas Haller
466a4c4562 core: don't duplicate list of known permissions in impl_manager_get_permissions()
Reuse the list of all permissions and don't duplicate it.

Also, now the result of GetPermissions() on D-Bus contains the
permissions sorted by name. We get it almost for free, and it's
a nice property.
2019-12-10 07:53:25 +01:00
Thomas Haller
50a12ce2d5 core: also return unknown permission check result
For example with

  mount -o remount,rw,hidepid=1 /proc/

all permission checks will fail with an error. Internally, we map the
failure to NM_AUTH_CALL_RESULT_UNKNOWN.

    <trace> [1575645672.5958] auth: call[1069]: CheckAuthorization(org.freedesktop.NetworkManager.enable-disable-connectivity-check), subject=unix-process[pid=468316, uid=1000, start=1912881]
    <trace> [1575645672.6295] auth: call[1069]: completed: failed: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dfile_2derror_2dquark.Code4: Failed to open file “/proc/468316/status”: No such file or directory
    <debug> [1575645672.6296] manager: unknown auth chain result 0

First of all, we should not log a debug message about that (we already log the
result of permission checks separately).

Also, we should include the unknown result in the response. The permission was
checked, and omitting it from GetPermissions() result seems wrong (even if we
failed to get the result).

Note that "unknown" is now a new possible return value on D-Bus. But
see how nm_permission_result_to_client() would map such a value to
"unknown" as well. So, it's probably a fine extension of the D-Bus API.

Note that NMClient API is currently quite limited. The user won't know
whether permissions were received (and if they were received, they
could not distinguish between UNKNOWN and absent). Hence, returning
all permissions as unknown (or not at all) causes `nmcli general permissions`
to hang. The solution here is to improve NMClient API to allow the user
to know when the permissions are received. But this patch doesn't
fix the hanging of nmcli nor the limitation of NMClient's API.
2019-12-10 07:53:25 +01:00
Thomas Haller
b650d1d181 core: also check "org.freedesktop.NetworkManager.wifi.scan" permissions 2019-12-10 07:53:25 +01:00
Beniamino Galvani
a73efb059f manager: don't activate device if the parent is missing
In multiple places we currently proceed to creating a virtual device
even if the connection specifies a parent device which is
missing. This can be easily reproduced with:

  nmcli con add type vxlan ifname vxlan1 \
                vxlan.parent not-exists \
                id 43 remote 172.25.1.1

which creates a vxlan1 interface without activating any
connection. Add a check to prevent this.

https://bugzilla.redhat.com/show_bug.cgi?id=1774074
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/344
2019-11-25 08:58:27 +01:00
Lubomir Rintel
7a84388a9b manager: assume DHCP if we see a lease on taking over an initramfs connection
In general, we aren't really able to tell, but when we see a lease file
we're pretty sure that DHCP is what was going on.

https://bugzilla.redhat.com/show_bug.cgi?id=1771792
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/335

Fixes: f2fe6c03ee ('manager: don't treat the initramfs-configured DHCP connections as generated')
2019-11-18 13:35:23 +01:00
Thomas Haller
abff46cacf all: manually drop code comments with file description 2019-10-01 07:50:52 +02:00
Thomas Haller
4154d9618c bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data
This is a complete refactoring of the bluetooth code.

Now that BlueZ 4 support was dropped, the separation of NMBluezManager
and NMBluez5Manager makes no sense. They should be merged.

At that point, notice that BlueZ 5's D-Bus API is fully centered around
D-Bus's ObjectManager interface. Using that interface, we basically only
call GetManagedObjects() once and register to InterfacesAdded,
InterfacesRemoved and PropertiesChanged signals. There is no need to
fetch individual properties ever.

Note how NMBluezDevice used to query the D-Bus properties itself by
creating a GDBusProxy. This is redundant, because when using the ObjectManager
interfaces, we have all information already.

Instead, let NMBluezManager basically become the client-side cache of
all of BlueZ's ObjectManager interface. NMBluezDevice was mostly concerned
about caching the D-Bus interface's state, tracking suitable profiles
(pan_connection), and moderate between bluez and NMDeviceBt.
These tasks don't get simpler by moving them to a seprate file. Let them
also be handled by NMBluezManager.

I mean, just look how it was previously: NMBluez5Manager registers to
ObjectManager interface and sees a device appearing. It creates a
NMBluezDevice object and registers to its "initialized" and
"notify:usable" signal. In the meantime, NMBluezDevice fetches the
relevant information from D-Bus (although it was already present in the
data provided by the ObjectManager) and eventually emits these usable
and initialized signals.
Then, NMBlue5Manager emits a "bdaddr-added" signal, for which NMBluezManager
creates the NMDeviceBt instance. NMBluezManager, NMBluez5Manager and
NMBluezDevice are strongly cooperating to the point that it is simpler
to merge them.

This is not mere refactoring. This patch aims to make everything
asynchronously and always cancellable. Also, it aims to fix races
and inconsistencies of the state.

- Registering to a NAP server now waits for the response and delays
  activation of the NMDeviceBridge accordingly.

- For NAP connections we now watch the bnep0 interface in platform, and tear
  down the device when it goes away. Bluez doesn't send us a notification
  on D-Bus in that case.

- Rework establishing a DUN connection. It no longer uses blocking
  connect() and does not block until rfcomm device appears. It's
  all async now. It also watches the rfcomm file descriptor for
  POLLERR/POLLHUP to notice disconnect.

- drop nm_device_factory_emit_component_added() and instead let
  NMDeviceBt directly register to the WWan factory's "added" signal.
2019-09-23 12:47:37 +02:00
Beniamino Galvani
c1c970f1b1 libnm: export reload flags
Flags to the manager Reload() method are stable API but not exposed in
a public header. Export them.
2019-09-17 09:30:18 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Beniamino Galvani
4bd192a350 core: add defines for common authentication-related error messages
All D-Bus method call implementations use similar error messages when
authenticating requests; add defines for them to ensure the same exact
message is reused.
2019-09-05 11:41:57 +02:00
Beniamino Galvani
f07aa329b2 manager: keep device if realize() fails
system_create_virtual_device() first creates the device (unrealized)
and then, if there a connection for the device with autoconnect=yes,
creates the backing resources. If this last step fails the device
should continue to exist, even if in an unrealized state.

https://bugzilla.redhat.com/show_bug.cgi?id=1686634
2019-09-03 16:53:04 +02:00
Thomas Haller
dda3289206 shared: add nm_c_list_elem_find_first() helper macro
- add nm_c_list_elem_find_first() macro that takes a predicate
  and returns the first match.

  This macro has a non-function-like behavior, which we often try to
  avoid because macros should behave like functions. In this case it's
  however convenient, so let's do it.
  Also, despite being non-function-like, it should be pretty hard to
  use wrongly.

- rename nm_c_list_elem_find_first() to nm_c_list_elem_find_first_ptr().
2019-08-08 10:07:15 +02:00
Lubomir Rintel
f2fe6c03ee manager: don't treat the initramfs-configured DHCP connections as generated
These are special -- initramfs configured them and killed dhclient. Bad
things would happen if we let the addresses expire though.

Let's act as if initramfs actually passed the configuration to us.
It actually tries to do so by the means of writing an ifcfg file, but
that one is too broken to be useful, so the ifcfg-rh plugin ignores it.
Notably, it doesn't have the actual addresses or correct BOOTPROTO.
The generated connection is better.

Co-authored-by: Thomas Haller <thaller@redhat.com>
(cherry picked from commit acf3e0092a)
2019-08-02 12:47:45 +02:00
Thomas Haller
e32d80ea29 settings/trivial: rename NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK to NM_SETTINGS_CONNECTION_PERSIST_MODE_TO_DISK
NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK really directly corresponds to
NM_SETTINGS_UPDATE2_FLAG_TO_DISK. Rename, so that this is better reflected.
2019-07-25 22:02:00 +02:00
Thomas Haller
22c8721f35 core,libnm: add AddConnection2() D-Bus API to block autoconnect from the start
It should be possible to add a profile with autoconnect blocked form the
start. Update2() has a %NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT flag to
block autoconnect, and so we need something similar when adding a connection.

As the existing AddConnection() and AddConnectionUnsaved() API is not
extensible, add AddConnection2() that has flags and room for additional
arguments.

Then add and implement the new flag %NM_SETTINGS_ADD_CONNECTION2_FLAG_BLOCK_AUTOCONNECT
for AddConnection2().

Note that libnm's nm_client_add_connection2() API can completely replace
the existing nm_client_add_connection_async() call. In particular, it
will automatically prefer to call the D-Bus methods AddConnection() and
AddConnectionUnsaved(), in order to work with server versions older than
1.20. The purpose of this is that when upgrading the package, the
running NetworkManager might still be older than the installed libnm.
Anyway, so since nm_client_add_connection2_finish() also has a result
output, the caller needs to decide whether he cares about that result.
Hence it has an argument ignore_out_result, which allows to fallback to
the old API. One might argue that a caller who doesn't care about the
output results while still wanting to be backward compatible, should
itself choose to call nm_client_add_connection_async() or
nm_client_add_connection2(). But instead, it's more convenient if the
new function can fully replace the old one, so that the caller does not
need to switch which start/finish method to call.

https://bugzilla.redhat.com/show_bug.cgi?id=1677068
2019-07-25 15:26:49 +02:00
Iain Lane
8f8a1990ce libnm,core: Add ConnectivityCheckUri property and accessors
So that applications like GNOME Shell can hit the same URI to show the
captive portal login page.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/209
2019-07-22 21:03:09 +02:00
Thomas Haller
d35d3c468a settings: rework tracking settings connections and settings plugins
Completely rework how settings plugin handle connections and how
NMSettings tracks the list of connections.

Previously, settings plugins would return objects of (a subtype of) type
NMSettingsConnection. The NMSettingsConnection was tightly coupled with
the settings plugin. That has a lot of downsides.

Change that. When changing this basic relation how settings connections
are tracked, everything falls appart. That's why this is a huge change.
Also, since I have to largely rewrite the settings plugins, I also
added support for multiple keyfile directories, handle in-memory
connections only by keyfile plugin and (partly) use copy-on-write NMConnection
instances. I don't want to spend effort rewriting large parts while
preserving the old way, that anyway should change. E.g. while rewriting ifcfg-rh,
I don't want to let it handle in-memory connections because that's not right
long-term.

--

If the settings plugins themself create subtypes of NMSettingsConnection
instances, then a lot of knowledge about tracking connections moves
to the plugins.
Just try to follow the code what happend during nm_settings_add_connection().
Note how the logic is spread out:
 - nm_settings_add_connection() calls plugin's add_connection()
 - add_connection() creates a NMSettingsConnection subtype
 - the plugin has to know that it's called during add-connection and
   not emit NM_SETTINGS_PLUGIN_CONNECTION_ADDED signal
 - NMSettings calls claim_connection() which hocks up the new
   NMSettingsConnection instance and configures the instance
   (like calling nm_settings_connection_added()).
This summary does not sound like a lot, but try to follow that code. The logic
is all over the place.

Instead, settings plugins should have a very simple API for adding, modifying,
deleting, loading and reloading connections. All the plugin does is to return a
NMSettingsStorage handle. The storage instance is a handle to identify a profile
in storage (e.g. a particular file). The settings plugin is free to subtype
NMSettingsStorage, but it's not necessary.
There are no more events raised, and the settings plugin implements the small
API in a straightforward manner.
NMSettings now drives all of this. Even NMSettingsConnection has now
very little concern about how it's tracked and delegates only to NMSettings.

This should make settings plugins simpler. Currently settings plugins
are so cumbersome to implement, that we avoid having them. It should not be
like that and it should be easy, beneficial and lightweight to create a new
settings plugin.

Note also how the settings plugins no longer care about duplicate UUIDs.
Duplicated UUIDs are a fact of life and NMSettings must handle them. No
need to overly concern settings plugins with that.

--

NMSettingsConnection is exposed directly on D-Bus (being a subtype of
NMDBusObject) but it was also a GObject type provided by the settings
plugin. Hence, it was not possible to migrate a profile from one plugin to
another.
However that would be useful when one profile does not support a
connection type (like ifcfg-rh not supporting VPN). Currently such
migration is not implemented except for migrating them to/from keyfile's
run directory. The problem is that migrating profiles in general is
complicated but in some cases it is important to do.

For example checkpoint rollback should recreate the profile in the right
settings plugin, not just add it to persistent storage. This is not yet
properly implemented.

--

Previously, both keyfile and ifcfg-rh plugin implemented in-memory (unsaved)
profiles, while ifupdown plugin cannot handle them. That meant duplication of code
and a ifupdown profile could not be modified or made unsaved.
This is now unified and only keyfile plugin handles in-memory profiles (bgo #744711).
Also, NMSettings is aware of such profiles and treats them specially.
In particular, NMSettings drives the migration between persistent and non-persistent
storage.

Note that a settings plugins may create truly generated, in-memory profiles.
The settings plugin is free to generate and persist the profiles in any way it
wishes. But the concept of "unsaved" profiles is now something explicitly handled
by keyfile plugin. Also, these "unsaved" keyfile profiles are persisted to file system
too, to the /run directory. This is great for two reasons: first of all, all
profiles from keyfile storage in fact have a backing file -- even the
unsaved ones. It also means you can create "unsaved" profiles in /run
and load them with `nmcli connection load`, meaning there is a file
based API for creating unsaved profiles.
The other advantage is that these profiles now survive restarting
NetworkManager. It's paramount that restarting the daemon is as
non-disruptive as possible. Persisting unsaved files to /run improves
here significantly.

--

In the past, NMSettingsConnection also implemented NMConnection interface.
That was already changed a while ago and instead users call now
nm_settings_connection_get_connection() to delegate to a
NMSimpleConnection. What however still happened was that the NMConnection
instance gets never swapped but instead the instance was modified with
nm_connection_replace_settings_from_connection(), clear-secrets, etc.
Change that and treat the NMConnection instance immutable. Instead of modifying
it, reference/clone a new instance. This changes that previously when somebody
wanted to keep a reference to an NMConnection, then the profile would be cloned.
Now, it is supposed to be safe to reference the instance directly and everybody
must ensure not to modify the instance. nmtst_connection_assert_unchanging()
should help with that.
The point is that the settings plugins may keep references to the
NMConnection instance, and so does the NMSettingsConnection. We want
to avoid cloning the instances as long as they are the same.
Likewise, the device's applied connection can now also be referenced
instead of cloning it. This is not yet done, and possibly there are
further improvements possible.

--

Also implement multiple keyfile directores /usr/lib, /etc, /run (rh #1674545,
bgo #772414).

It was always the case that multiple files could provide the same UUID
(both in case of keyfile and ifcfg-rh). For keyfile plugin, if a profile in
read-only storage in /usr/lib gets modified, then it gets actually stored in
/etc (or /run, if the profile is unsaved).

--

While at it, make /etc/network/interfaces profiles for ifupdown plugin reloadable.

--

https://bugzilla.gnome.org/show_bug.cgi?id=772414
https://bugzilla.gnome.org/show_bug.cgi?id=744711
https://bugzilla.redhat.com/show_bug.cgi?id=1674545
2019-07-16 19:09:08 +02:00
Thomas Haller
dd5acc0370 core: use nm_c_list_elem_free_steal() in _delete_volatile_connection_all () 2019-07-10 12:43:06 +02:00
Beniamino Galvani
ba7b427aec manager: propagate the for-user-request flag for slaves autoconnection
If the master is activated by user, propagate the for-user-request to
slaves activations when autoconnecting slaves, so that they can manage
slaves device as needed.

Reproducer:

 ip l add eth1 type veth peer name eth2
 ip l set eth1 up
 ip l set eth2 up
 sleep 2

 echo " * Initial state"
 echo " - eth1: $(nmcli -g general.state device show eth1)"

 nmcli con add type ethernet ifname eth1 con-name slave-test+ master br-test slave-type bridge
 nmcli con add type bridge ifname br-test con-name br-test+ connection.autoconnect-slaves yes ip4 172.25.1.1/24

 nmcli con up br-test+

 echo " * After user activation"
 echo " - br-test: $(nmcli -g general.state device show br-test)"
 echo " - eth1: $(nmcli -g general.state device show eth1)"

should give:

 * Initial state
 - eth1: 10 (unmanaged)
 * After user activation
 - br-test: 100 (connected)
 - eth1: 100 (connected)
2019-07-08 13:51:30 +02:00
Thomas Haller
c163207b07 core: create virtual device on settings changes in idle handler
The callback from NMSettings about adding/updating a settings comes
from a deep call-stack already. We don't know the context of it, and
we shouldn't just right away create the profile. Instead, schedule an
action to create it in an idle handler.
2019-07-02 17:52:53 +02:00
Thomas Haller
f8a20d0a09 manager: don't consider by-user change flag for creating unrealized device
This effectively reverts commit [1].

The by-user argument is not very clear what it means. Is a "nmcli
connection load $FILENAME" a user-action? How about reload?

I don't know whether the problem that this was supposed to fix is still
present. But in any case, the condition here seems not right. It's
already hard to understand when and how we generate unrealized devices.

If the condition from commit [1] should be prevented, then it must happen
somehow differently. In the example, the offending connection is a generated
volatile profile with the device being sys-face-state "external". Of course,
we should not generate devices for such profiles nor autoactivating them.
So adding a device for a volatile connection is always wrong. Don't do that,
which should avoid the original problem.

[1] commit a8a4eb1418 ('manager: don't create the virtual devices on all connection changes')
2019-06-26 12:26:11 +02:00
Thomas Haller
d1f269ab36 core: ensure normalized connection during add-and-activate
nm_connection_verify() returns success for fully valid (normalized)
connections and also connections that are NM_SETTING_VERIFY_NORMALIZABLE.

We really want to fully normalize the profiles during add-and-activate.
2019-06-26 12:26:11 +02:00
Thomas Haller
6d4592354f settings: reorder checks in _delete_volatile_connection_do() to perform cheaper check first
Checking whether a settings connection is still tracked is a simple
c_list_is_empty(). It's faster, so do it first.
2019-06-26 12:26:11 +02:00
Thomas Haller
50e193d12c settings: use NMCListElem instead of DeleteVolatileConnectionData for tracking connections to delete
For tracking a CList of one pointer we have NMCListElem API. We don't need
to implement our own struct to hold the list pointers and the data pointer.
2019-06-26 12:26:11 +02:00
Thomas Haller
25de86abb6 manager: cleanup freeing CList in NMManager's dispose()
To unlink all elements, I find a while() loop easier to read
than c_list_for_each_*safe().
2019-06-13 16:10:53 +02:00