Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
86229a669b core: add NMDBusTrackObjPath helper
When one D-Bus object exposes (the path of) another D-Bus object,
we want that the path property gets cleared before the other
object gets unexported(). That essentially requires to register
to the "exported-changed" signal.

Add a helper struct NMDBusTrackObjPath to help with this.
2018-04-13 09:09:46 +02:00
Thomas Haller
4127f1234f settings: track connections via CList 2018-04-13 09:09:46 +02:00
Thomas Haller
0dd3e6099c core: don't unexport active-connection when settings connection disappears
When a settings-connection gets deleted, we need to bring down the
NMActiveConnection that contains it. However, we shouldn't just unexport
the active connection from D-Bus. Instead, clear the settings path.

We need to drop the path, because the connection is going away. It's a
bit ugly, that an active-connection might reference no
settings-connection. However, this only happens during shut-down.
The alternative, would be to keep the settings-connection object
in a zombie state, exported on D-Bus. However, that seems even more
confusing to me.
2018-04-13 09:09:46 +02:00
Thomas Haller
cd71ec3084 core: convert NMDBusObject's "path" property to signal "exported-changed"
The GObject property "path" exists for the sole reasons so that
other components can connect to the "notify::path" signal.

However, notifications are blocked by g_object_freeze_notify(),
and especially for NMDBusObject we want to make use of that to
combine multiple PropertiesChanged events into one.

This blocking of the signal is not desired for the case where
we wait for "notify::path". Convert that to a signal, which
will not be blocked.
2018-04-13 09:09:46 +02:00
Thomas Haller
7595b4f1c7 settings: don't let connection keep NMSettings alive
NMSettings already references NMSettingsConnection. Hence, it should not
at the same time reference itself. Arguably, during shutdown we do not properly
release all NMSettingsConnection. For example, there is no nm_settings_stop().
But that is a bug that needs fixing.

No need to keep the NMSettings instance alive here. If this is really
necessary, it needs fixing somewhere else. Besides, we know that we leak
a lot during shutdown, so this needs more work to do a clean shutdown.
2018-04-13 09:09:46 +02:00
Thomas Haller
1f3b47deea settings: reorder D-Bus events when removing settings-connection
It makes more sense to me this way.
2018-04-13 09:09:46 +02:00
Thomas Haller
ebd53888b6 core: avoid unnecessary action in NMPolicy's _deactivate_if_active()
We only need @state, after we verified that the active connection
references the right settings connection. Most of the time, that
is not the case.
2018-04-13 09:09:46 +02:00
Thomas Haller
dcbb5c07e1 core: drop unused NMConnectionProvider typedef
We dopped NMConnectionProvider a while ago. Forgot something.

Fixes: 5337003c4c
2018-04-13 09:09:46 +02:00
Thomas Haller
1b532b5fdc core: minor cleanup of nm_utils_g_value_set_strv()
Add some assertion, use an unsigned loop variable (that matches
GPtrArray.len type), and add a comment.
2018-04-13 09:09:46 +02:00
Thomas Haller
a5e9980b34 core: use nm_dbus_utils_g_value_set_object_path_from_hash() 2018-04-13 09:09:46 +02:00
Thomas Haller
de5d07392d libnm: optimize nm_simple_connection_new_clone() to not needlessly set the path
Server never sets the path, so this is entirely unused server-side.
Also NMConnection is a glib interface and stores it's private date
in the GObject's data. It's less efficient to look it up. Just
avoid it.
2018-04-13 09:09:46 +02:00
Thomas Haller
755c8bb30f settings: no longer call nm_connection_set_path() in server
It's unused.
2018-04-13 09:09:46 +02:00
Thomas Haller
b0bf9b2b9b core: explicitly pass D-Bus path to nm_utils_log_connection_diff()
No longer rely on nm_connection_get_path() being meaningful in server.
It also was wrong. During update, nm_settings_connection_update()
would call
  nm_utils_log_connection_diff (replace_connection, NM_CONNECTION (self), ...
where replace_connection has no path set, and nothing was logged.

Fix it, by explicitly passing the D-Bus path. Also, because
nm-core-utils.c should be independent of nm-dbus-object.h.
2018-04-13 09:09:46 +02:00
Thomas Haller
9efa7c7220 core: use nm_dbus_object_get_path() instead of nm_connection_get_path()
Essentially, nm_connection_get_path() mirros nm_dbus_object_get_path().
However, when cloning a simple-connection, the path also gets cloned.

I think this field doesn't belong to NMConnection in the first place,
because NMConnection is not a D-Bus object. NMSettingsConnection (in
core) and NMRemoteConnection (in libnm) is.

Don't use the misleading alias, but use nm_dbus_object_get_path()
directly.
2018-04-13 09:09:46 +02:00
Thomas Haller
efe5cf79c0 core: simplify NMActiveConnection.get_property to not create temporary GPtrArrray
Fixes: c050fb7cd2
2018-04-13 09:09:46 +02:00
Thomas Haller
fdbf696f22 settings: clear connection path when unexporting from D-Bus
At that point, the path becomes meaningless. Clear it.
2018-04-13 09:09:46 +02:00
Thomas Haller
24c3eacac6 settings/trivial: add code comments 2018-04-13 09:09:46 +02:00
Thomas Haller
f41279ca1d settings: use cleanup attribute to keep connection alive during connection_removed() 2018-04-13 09:09:46 +02:00
Thomas Haller
213323a6a7 settings: fix unrefing setting is there are no plugins loaded
This wasn't a problem, because load_plugins() can only fails
if the settings plugins fail to load, which can only happen
if you have a broken installation.
2018-04-13 09:09:46 +02:00
Thomas Haller
8c56c47bba settings: handle default-wired-connection in connection-removed signal
Don't subscribe twice to the same signal. The more subscribers a
signal has, the more confusing it gets what is happening.

We can handle also the default-wired-connection in the regular
connection-removed signal.

Note how connection_removed() is registered with
g_signal_connect_after(), but that is fine. There are few subscribers
to this signal (that don't do anything that interferes here).
Especially, since all other subscribers subscribe with the same
priority (hence, are unordered). So, moving this task explicitly
to after, does not change any ordering guarantee -- in fact, it
ensures an ordering that was undefined previously. Anyway, it
doesn't matter.
2018-04-13 09:09:46 +02:00
Thomas Haller
76df7a3088 shared: add nm_dbus_utils_get_paths_for_clist() util 2018-04-13 09:09:46 +02:00
Thomas Haller
67e06924e1 core/trivial: add code comment to NMActiveConnection's get_property() 2018-04-13 09:09:46 +02:00
Thomas Haller
d95717cdbe auth-chain: remove unused error argument 2018-04-13 09:09:46 +02:00
Thomas Haller
786adf969c manager: don't coalesce duplicate internal activations with different reasons
When combining internal activations, do that only if their reason also
matches.

Fixes: 4985ca5ada
2018-04-12 15:57:39 +02:00
Thomas Haller
69b7a76dc2 device: merge branch 'pr/92'
https://bugzilla.gnome.org/show_bug.cgi?id=795196
https://github.com/NetworkManager/NetworkManager/pull/92
2018-04-12 14:23:25 +02:00
Thomas Haller
251e5707d5 device: return early from handle_auth_or_fail() on failure
Don't do if-else, if one branch is going to return with failure.
2018-04-12 14:17:05 +02:00
Thomas Haller
d5ee549e07 device: let macsec connection fail on supplicant timeout if no secrets are required
Like for ethernet.
2018-04-12 14:17:05 +02:00
Michael Schaller
7dab990eb2 device: let Ethernet connection fail on supplicant timeout if no secrets are required
Without this patch an Ethernet connection attempt that encountered a supplicant
timeout was stuck in the needs-auth state even if it didn't require secrets.
This patch applies the respective WiFi behaviour also to Ethernet devices.

https://bugzilla.gnome.org/show_bug.cgi?id=795196
https://github.com/NetworkManager/NetworkManager/pull/92
2018-04-12 14:16:53 +02:00
Thomas Haller
f92a68c9e5 device/trivial: add code comment to nm_device_ipv4_sysctl_get_effective_uint32() 2018-04-12 13:48:12 +02:00
Beniamino Galvani
150cf44d50 device: look at 'all' rp_filter value too to determine actual value
Currently we overwrite the interface rp_filter value with 2 ("loose")
only when it is 1 ("strict") because when it is 0 ("no validation") it
is already more permissive.

So, if the value for the interface is 0 and
net/ipv4/conf/all/rp_filter is 1 (like it happens by default on Fedora
28), we don't overwrite it; since kernel considers the maximum between
{all,$dev}/rp_filter, the effective value remains 'strict'.

We should instead combine the two {all,$dev}/rp_filter, and if it's 1
overwrite the value with 2.

https://bugzilla.redhat.com/show_bug.cgi?id=1565529
2018-04-12 09:53:32 +02:00
Beniamino Galvani
ae8015b4a5 build: meson: merge branch 'bg/meson-tests'
Enable all tests when building with meson.
2018-04-12 09:21:39 +02:00
Beniamino Galvani
0136915211 build: meson: add prefix to test names
There are multiple tests with the same in different directories; add a
unique prefix to test names so that it is clear from the output which
one is running.
2018-04-12 09:21:10 +02:00
Beniamino Galvani
0c39a02ce0 build: meson: enable all tests again
Some tests were disabled because they failed when run in parallel.
Now that we use the wrapper script they succeed and can be enabled
again.
2018-04-12 09:21:10 +02:00
Beniamino Galvani
0dace9b52a build: meson: increase timeout for some tests
Some tests, when run in parallel, can take more than the default
timeout (30 seconds). Increase the timeout for them.
2018-04-12 09:21:10 +02:00
Beniamino Galvani
a2479b95c0 build: meson: use run-nm-test.sh to run tests
Like autotools, use the wrapper script 'run-nm-test.sh' that starts a
separate D-Bus session when needed.
2018-04-12 09:21:10 +02:00
Thomas Haller
3b5a522ef6 connectivity: merge branch 'th/fix-fake-connectivity-state'
https://github.com/NetworkManager/NetworkManager/pull/89
2018-04-12 08:23:29 +02:00
Thomas Haller
d0cee07a0f connectivity: fix the device's fake connectivity state
Otherwise, if connectivity checking was disabled, we would never
reset the connectivity state and leave it wrongly at UNKNOWN.

nm_device_check_connectivity_update_interval() is already called
during state-changes, so this is the right place. However,
it's far from perfect still, because we might not notice when
a default-route gets added or removed. Also, devices that are not
in ACTIVATED state, are considered with connectivity NONE. Which
might not be correct.

Fixes: 0a62a0e903
2018-04-11 12:06:36 +02:00
Thomas Haller
f48b4af850 manager: merge set_state() in nm_manager_update_state() function 2018-04-11 11:45:42 +02:00
Thomas Haller
835a5f7248 connectivity: also expose fake connectivity states to dispatcher
The fake states still encode whether the device have a default-route.
So, they are not entirely useless. Also, don't add special handling
of "#if !WITH_CONCHECK" where we don't need it.

There is no fundamental difference between compiling without connectivity
check and disabling connectivity checks.
2018-04-11 11:38:02 +02:00
Thomas Haller
8c805c943c connectivity: optmize finding best connectivty state in NMManager::device_connectivity_changed()
It doesn't get better than FULL, so we can abort the loop in that
case early.
2018-04-11 11:35:14 +02:00
Thomas Haller
8bb058386d connectivity: add connectivity-changed signal to NMDevice
NMManager very much cares about changes to the connectivity state
of the device and was therefore listening to notify::connectivity
signals. However, property changed signals can be suppressed by
g_object_freeze_notify(). That is something we even encourage for
NMDBusObject instances, because the D-Bus glue makes use of the
property changed notifications, and encourages to combine multiple
changes by freezing the signal.

Using the property changed notifications of NMDBusObject instances is
ugly. Don't do that and instead add a special signal.
2018-04-11 11:31:39 +02:00
Thomas Haller
8e8efbdc32 connectivity: only take reference in concheck_cb() if necessary
We don't need to take a reference, if we are not going to emit any signals.
2018-04-11 11:27:04 +02:00
Thomas Haller
5a6fc10000 connectivity: improve logging of completed connectivity check in device 2018-04-11 11:18:02 +02:00
Thomas Haller
f7127db8cf dhcp/systemd: ensure aligned memory access in ip6_start() for duid
It probably was no problem in practice, because very likely the
chunk of memory was aligned already.

Also, drop non helpful comment and fix whitespace.
2018-04-11 09:24:23 +02:00
Thomas Haller
84cd6aea53 connectivity: merge branch 'th/connectivity-rework'
https://github.com/NetworkManager/NetworkManager/pull/70
2018-04-10 16:02:20 +02:00
Thomas Haller
91b1af2839 connectivity: emit properties-changed about connectivity settings 2018-04-10 15:58:12 +02:00
Thomas Haller
0a62a0e903 connectivity: schedule connectivity timers per-device and probe for short outages
It might happen, that connectivitiy is lost only for a moment and
returns soon after. Based on that assumption, when we loose connectivity
we want to have a probe interval where we check for returning
connectivity more frequently.

For that, we handle tracking of the timeouts per-device.

The intervall shall start with 1 seconds, and double the interval time until
the full interval is reached. Actually, due to the implementation, it's unlikely
that we already perform the second check 1 second later. That is because commonly
the first check returns before the one second timeout is reached and bumps the
interval to 2 seconds right away.

Also, we go through extra lengths so that manual connectivity check
delay the periodic checks. By being more smart about that, we can reduce
the number of connectivity checks, but still keeping the promise to
check at least within the requested interval.

The complexity of book keeping the timeouts is remarkable. But I think
it is worth the effort and we should try hard to

 - have a connectivity state as accurate as possible. Clearly,
   connectivity checking means that we probing, so being more intelligent
   about timeout and backoff timers can result in a better connectivity
   state. The connectivity state is important because we use it for
   the default-route penaly and the GUI indicates bad connectivity.

 - be intelligent about avoiding redundant connectivity checks. While
   we want to check often to get an accurate connectivity state, we
   also want to minimize the number of HTTP requests, in case the
   connectivity is established and suppossedly stable.

Also, perform connectivity checks in every state of the device.
Even if a device is disconnected, it still might have connectivity,
for example if the user externally adds an IP address on an unmanaged
device.

https://bugzilla.gnome.org/show_bug.cgi?id=792240
2018-04-10 15:11:23 +02:00
Thomas Haller
e8e0ef6300 connectivity: reduce timeout for connectivity checks to 20 seconds
The main issue is that `nmcli networking connectivity check` uses
nm_client_check_connectivity(), which has a timeout of 25 seconds.
Using a timeout of 30 seconds server side, means that if the requests
don't complete in time, the client side will time out and abort
with a failure. That is not right.

Fix that by using a shorter timeout server side. 20 seconds is still
plenty for a small HTTP request. If the network takes longer than that,
it's fair to call that LIMITED connectivity.
2018-04-10 15:11:23 +02:00
Thomas Haller
d8a31794c8 connectivity: rework async connectivity check requests
An asynchronous request should either be cancellable or not keep
the target object alive. Preferably both.

Otherwise, it is impossible to do a controlled shutdown when terminating
NetworkManager. Currently, when NetworkManager is about to terminate,
it just quits the mainloop and essentially leaks everything. That is a
bug. If we ever want to fix that, every asynchronous request must be
cancellable in a controlled way (or it must not prevent objects from
getting disposed, where disposing the object automatically cancels the
callback).

Rework the asynchronous request for connectivity check to

- return a handle that can be used to cancel the operation.
  Cancelling is optional. The caller may choose to ignore the handle
  because the asynchronous operation does not keep the target object
  alive. That means, it is still possible to shutdown, by everybody
  giving up their reference to the target object. In which case the
  callback will be invoked during dispose() of the target object.

- also, the callback will always be invoked exactly once, and never
  synchronously from within the asynchronous start call. But during
  cancel(), the callback is invoked synchronously from within cancel().
  Note that it's only allowed to cancel an action at most once, and
  never after the callback is invoked (also not from within the callback
  itself).

- also, NMConnectivity already supports a fake handler, in case
  connectivity check is disabled via configuration. Hence, reuse
  the same code paths also when compiling without --enable-concheck.
  That means, instead of having #if WITH_CONCHECK at various callers,
  move them into NMConnectivity. The downside is, that if you build
  without concheck, there is a small overhead compared to before. The
  upside is, we reuse the same code paths when compiling with or without
  concheck.

- also, the patch synchronizes the connecitivty states. For example,
  previously `nmcli networking connectivity check` would schedule
  requests in parallel, and return the accumulated result of the individual
  requests.
  However, the global connectivity state of the manager might have have
  been the same as the answer to the explicit connecitivity check,
  because while the answer for the manual check is waiting for all
  pending checks to complete, the global connectivity state could
  already change. That is just wrong. There are not multiple global
  connectivity states at the same time, there is just one. A manual
  connectivity check should have the meaning of ensure that the global
  state is up to date, but it still should return the global
  connectivity state -- not the answers for several connectivity checks
  issued in parallel.
  This is related to commit b799de281b
  (libnm: update property in the manager after connectivity check),
  which tries to address a similar problem client side.
  Similarly, each device has a connectivity state. While there might
  be several connectivity checks per device pending, whenever a check
  completes, it can update the per-device state (and return that device
  state as result), but the immediate answer of the individual check
  might not matter. This is especially the case, when a later request
  returns earlier and obsoletes all earlier requests. In that case,
  earlier requests return with the result of the currend devices
  connectivity state.

This patch cleans up the internal API and gives a better defined behavior
to the user (thus, the simple API which simplifies implementation for the
caller). However, the implementation of getting this API right and properly
handle cancel and destruction of the target object is more complicated and
complex. But this but is not just for the sake of a nicer API. This fixes
actual issues explained above.

Also, get rid of GAsyncResult to track information about the pending request.
Instead, allocate our own handle structure, which ends up to be nicer
because it's strongly typed and has exactly the properties that are
useful to track the request. Also, it gets rid of the awkward
_finish() API by passing the relevant arguments to the callback
directly.
2018-04-10 15:11:23 +02:00
Thomas Haller
4417b8bf3e core: add nm_utils_get_monotonic_timestamp_ns_cached() helper
Add a helper function to cache the current timestamp and return
it. The caching is a performance optimization, but it serves a
much more important purpose: repeatedly getting the timestamp
likely will yield different timings. So, commonly, within a
certain context we want to get the current time once, and stick
to that as "now".
2018-04-10 15:11:23 +02:00