Commit graph

19903 commits

Author SHA1 Message Date
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
Thomas Haller 43dee5f192 platform: minor cleanup of nm_platform_ip6_address_sync()
Drop the "delete_remaining" variable, and instead rely on the value of "i_know"
alone. Also, add a code comment explaining better what is happening.
2018-04-10 14:20:19 +02:00
Thomas Haller b50d7cc653 platform: fix IPv6 address sync after for link local addresses
Since commit 78ed0a4a23 (device: add
IPv6 link local address via merge-and-apply) we handle also IPv6 link
local addresses like regular addresses. That is, we also add them during
merge-and-apply and sync them via nm_platform_ip6_address_sync().

ip6-address-sync loops over the platform addresses, to find which
addresses shall be deleted, and which shall be deleted in order to
fix the address order/priority. At that point, we must not ignore
link-local addresses anymore, but handle them too.

Otherwise, during each resync we have link local addresses, and
platform-sync thinks that the address order is wrong. That wrongly
leads to remove most addresses and re-adding them.

Fixes: 78ed0a4a23
2018-04-10 14:09:56 +02:00
Thomas Haller 69e80d6c51 platform: merge branch 'th/platform-tun'
https://github.com/NetworkManager/NetworkManager/pull/87
2018-04-09 20:29:13 +02:00
Thomas Haller ef93f6caad platform: support creating non-persistant TUN/TAP devices
For completeness, extend the API to support non-persistant
device. That requires that nm_platform_link_tun_add()
returns the file descriptor.

While NetworkManager doesn't create such devices itself,
it recognizes the IFLA_TUN_PERSIST / IFF_PERSIST flag.
Since ip-tuntap (obviously) cannot create such devices,
we cannot add a test for how non-persistent devices look
in the platform cache. Well, we could instead add them
with ioctl directly, but instead, just extend the platform
API to allow for that.

Also, use the function from test-lldp.c to (optionally) use
nm_platform_link_tun_add() to create the tap device.
2018-04-09 20:16:31 +02:00
Thomas Haller f21ff48a84 platform/tests: extend nmtstp_wait_for_link*() to never wait
Previously, it was not (reliably) possible to use nmtstp_wait_for_link*() to
only look into the platform cache, without trying to poll the netlink
socket for events.

Add this option. Now, if the timeout is specified as zero, we never actually
read the netlink socket.

Currently, there are no callers who make use of this (by passing
a zero timeout). So, this is no change in existing behavior.
2018-04-09 20:16:31 +02:00
Thomas Haller dd2f5cf3d4 platform/tests: implement nmtstp_assert_wait_for_link() as macro
Implement nmtstp_assert_wait_for_link() and nmtstp_assert_wait_for_link_until()
as macros, based on nmtst_assert_nonnull().

This way, the assertion will report a more helpful file:line location,
instead of being somewhere nested inside test-common.c.
2018-04-09 20:16:31 +02:00
Thomas Haller 770015f512 shared/tests: add nmtst_assert_nonnull() macro
There is g_assert_nonnull(), however that doesn't return
the pointer. Returning the pointer can be convenient...
2018-04-09 20:16:30 +02:00
Thomas Haller bd8ab54b8e platform/tests: add tests for TUN/TAP handling 2018-04-09 20:16:30 +02:00
Thomas Haller 722f79c9c5 platform: workaround kernel issue for tun device for first RTM_NETLINK event
Due to a bug, the current rc-kernel will emit the first netlink
notification about tun devices before the device is initialized.

Hence, the content of the message is bogus. If the message
looks like to be this case, re-request it right away.
2018-04-09 20:16:30 +02:00
Thomas Haller f76a94668d platform: refetch TUN link when no type-specific lnk data was received
Now that kernel supports providing information about tun/tap devices
via netlink, make use of it.

Also, enable the hack that:
  - when we first see a link that has no lnk data, we refetch
    it on the assumption, that kernel just didn't send it
    the first time.

For old kernels that do not yet support tun properties on netlink,
this means that we will always refetch the link once, the first
time we see it. I think that is acceptable, and the more correct
behavior for newer kernels that do support it.
2018-04-09 20:16:30 +02:00
Thomas Haller 031e58e1cf platform: enable parsing tun/tap properties from netlink
Now that the kernel patches are merged to mainline (rc), enable accepting
tun/tap link properties from netlink.

https://bugzilla.redhat.com/show_bug.cgi?id=1547213
2018-04-09 20:16:30 +02:00
Thomas Haller e8a9bffdb0 platform: refactor fetching links in cache_on_change()
Rework the code to if-else-if, to not schedule the same
DELAYED_ACTION_TYPE_REFRESH_LINK instance multiple times.

Note that delayed_action_schedule() already would check that
no duplicates are scheduled, but we can avoid that.
2018-04-09 20:16:30 +02:00
Thomas Haller 28b5118ad2 platform: assert in nm_platform_link_tun_add() for unsupported options
It doesn't make sense that NetworkManager adds non-persist tun
devices, likewise, only the type IFF_TUN or IFF_TAP is supported.

Assert that the values are as expected.
2018-04-09 20:16:30 +02:00
Thomas Haller 01ad4f33ed platform: adjust format for nm_platform_lnk_tun_to_string() and print "persist"
Switch from "pi on|off" to optinally printing "pi" to indicate
whether the flag is set. That follows ip-tuntap syntax and is
more familiar:

    $ ip tuntap help
    Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ]
              [ mode { tun | tap } ] [ user USER ] [ group GROUP ]
              [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ] [ name NAME ]

    Where: USER  := { STRING | NUMBER }
           GROUP := { STRING | NUMBER }

Also, print the "persist" flag.
2018-04-09 20:16:30 +02:00
Thomas Haller 530b5755ad platform: fix double whitespace for tun device in nm_platform_lnk_tun_to_string() 2018-04-09 20:16:30 +02:00
Thomas Haller 84b303217e nmtst: add nmtst_get_rand_bool() util 2018-04-09 20:16:30 +02:00
Thomas Haller 4116fa1044 tools/run-nm-test.sh: add -d option to set NMTST_DEBUG=d
For convenience, by passing "-d" to tools/run-nm-test.sh,
we set NMTST_DEBUG=d (if $NMTST_DEBUG is unset previously).
2018-04-09 20:16:30 +02:00
Beniamino Galvani 7a063a91c7 core: merge branch 'bg/autoconnect-slaves-rh1548265'
https://bugzilla.redhat.com/show_bug.cgi?id=1548265
2018-04-09 10:23:26 +02:00
Beniamino Galvani 4985ca5ada manager: allow autoconnect-slaves to reconnect the same connection
When a master connection is activated and has autoconnect-slaves=yes,
we want to reactivate an existing slave connection even if it is
already active.

https://bugzilla.redhat.com/show_bug.cgi?id=1548265
2018-04-08 09:40:14 +02:00
Beniamino Galvani 43a0f47ea2 core: specify an activation reason for active connections
Specify a reason when creating active connections. The reason will be
used in the next commit to tell whether slaves must be reconnected or
not if a master has autoconnect-slaves=yes.
2018-04-08 09:40:14 +02:00
Francesco Giudici d607f28899 docs: fix typo in nm-settings-ifcfg-rh:dhcp-client-id doc
Fixes: 4b51f5b1a8
2018-04-06 18:53:49 +02:00
Thomas Haller ebe16abd88 core: fix freeing reg_data in error path of _obj_register()
Fixes: 640736ff65
2018-04-06 15:40:10 +02:00
Thomas Haller 6f088da71b core: merge branch 'th/auth-chain'
https://github.com/NetworkManager/NetworkManager/pull/86
2018-04-06 11:53:16 +02:00
Thomas Haller d0330bfa73 auth-chain: optimize tracking of user data for NMAuthChain
- instead of allocating memory separately for the @tag (key)
  and ChainData (data), store the tag also inside ChainData.
- instead of adding two separate key and value items to GHashTable,
  use g_hash_table_add(), which is optimized for this case.
2018-04-06 11:53:00 +02:00
Thomas Haller 2cda3770a3 shared: add nm_pstr_hash() and nm_pstr_equal() 2018-04-06 11:51:21 +02:00
Thomas Haller 67828918c9 auth-chain: don't compare pointers explicitly against NULL 2018-04-05 17:45:30 +02:00
Thomas Haller c984f0f283 auth-chain: split handling auth-call in idle
auth_call_complete() had two callers: once from the idle handler, and
once from pk_call_cb(). The conditions are slightly different, split
the function in two. For one, this allows to unset the obsolete
call_idle_id.
2018-04-05 17:45:30 +02:00
Thomas Haller 2a998075e5 auth-chain/trivial: move code 2018-04-05 17:45:30 +02:00
Thomas Haller 6335627e77 auth-chain: drop unused nm_auth_chain_get_data_ulong() 2018-04-05 17:45:30 +02:00
Thomas Haller 6f4d5b2dfb auth-chain: use CList for tracking pending authentication requests 2018-04-05 17:45:30 +02:00
Thomas Haller 422e326cba shared: add nm_c_list_contains_entry() helper 2018-04-05 17:45:30 +02:00
Thomas Haller 011258a086 core: drop unnecessary #if WITH_POLKIT from nm-auth-subject.h
We rely on the linker to throw away unused functions.
No need for the #if in this case.
2018-04-05 17:45:30 +02:00
Thomas Haller 3f969d3b5b ifcfg-rh: suppress warning about NM_CONTROLLED=no without restricting profile to device
NM_CONTROLLED=no has the primary use of marking devices as unmanaged.
For that to work, the ifcfg file must contain either a MAC address,
an interface-name, or s390-subchannels that match a device.

In case the profile doesn't contain such specifiers, the profile
is ignored and a warning was logged:

    <warn>  [1522849679.7866] ifcfg-rh: loading "/etc/sysconfig/network-scripts/ifcfg-ens99" fails: NM_CONTROLLED was false but device was not uniquely identified; device will be managed

Downgrade this warning to a debug message. It's not unreasonable
that a user marks a ifcfg file with NM_CONTROLLED=no, to avoid
NetworkManager handling it. Yes, that way, the user did not explicitly
mark a device as unmanaged. But NetworkManager will ignore the profile,
as the user might resonably desire. No need to warn about that.
2018-04-05 11:30:14 +02:00
Thomas Haller 95d24929aa ifcfg-rh: minor cleanup setting out_ignore_error in connection_from_file_full()
- ensure that out_ignore_error is always initialized. Though,
  in practice all callers already made sure of that.
- use NM_SET_OUT() macro.
2018-04-05 11:30:14 +02:00
Thomas Haller c4048d4d90 systemd: merge branch systemd into master 2018-04-04 17:47:22 +02:00