Commit graph

18964 commits

Author SHA1 Message Date
Thomas Haller
bf7661189e c-list: re-import latest version of c-list.h from upstream
Most notably, it renames
  c_list_unlink_init() -> c_list_unlink()
  c_list_unlink() -> c_list_unlink_stale()

  $ sed -e 's/\<c_list_unlink\>/c_list_unlink_old/g' \
        -e 's/\<c_list_unlink_init\>/c_list_unlink/g' \
        -e 's/\<c_list_unlink_old\>/c_list_unlink_stale/g' \
        $(git grep -l c_list_unlink -- ':(exclude)shared/nm-utils/c-list.h') \
        -i

(cherry picked from commit b6efac9ec2)
2017-11-28 12:04:15 +01:00
Thomas Haller
eb95d6bbbb device: merge branch 'th/device-carrier-wait-timeout'
https://bugzilla.redhat.com/show_bug.cgi?id=1483343
https://bugzilla.redhat.com/show_bug.cgi?id=1487702
https://bugzilla.redhat.com/show_bug.cgi?id=1515027
https://bugzilla.gnome.org/show_bug.cgi?id=784854

(cherry picked from commit 2becc0a0ac)
2017-11-28 10:56:39 +01:00
Thomas Haller
27e38c77dd device: use same values for carrier-wait and carrier-defer time
Waiting for carrier on startup is probably the same times that carrier
needs, e.g. on an MTU change. Use the same timing.

Note, that as carrier-wait-timeout is no configurable, this
configuration applies to both -- as the manual page already
claims to do.

(cherry picked from commit 245590bacd)
2017-11-28 10:56:22 +01:00
Thomas Haller
d8b786570c device: extend carrier lost defer time after MTU change
Commit a17195b844 already tried to fix the
bug, but it did so wrongly. We must not increase the carrier-wait-time,
but the carrier-defer-time.

Keep the increase of carrier-wait-time too, and increase both timeouts
after a MTU change.

https://bugzilla.redhat.com/show_bug.cgi?id=1487702
https://bugzilla.gnome.org/show_bug.cgi?id=784854
(cherry picked from commit e4099f6764)
2017-11-28 10:56:22 +01:00
Thomas Haller
d67eeec5ef device: make carrier-wait-timeout configurable per device
As this depends on the particular host configuration, it's hard to find
a default that suits everybody. At least make it configurable per-device.

https://bugzilla.redhat.com/show_bug.cgi?id=1483343
https://bugzilla.redhat.com/show_bug.cgi?id=1515027
(cherry picked from commit b595a80977)
2017-11-28 10:56:22 +01:00
Beniamino Galvani
d23e050ef5 cli: do completion only when needed on 'nmcli con down'
$ nmcli connection down p
 path
 Connection 'p' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

Don't do completion when not requested.

(cherry picked from commit 021d797089)
2017-11-28 09:38:48 +01:00
Beniamino Galvani
092c8f4e6a settings: fix clist initialization
Fixes: 310973bb64
(cherry picked from commit 1e1af30d95)
2017-11-27 21:05:07 +01:00
Thomas Haller
49c22d23ef core: merge branch 'th/user-block-autoconnect-rh1401515'
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1401515
https://bugzilla.gnome.org/show_bug.cgi?id=790571

(cherry picked from commit 2c3dccfd28)
2017-11-27 16:07:55 +01:00
Thomas Haller
118b9f2978 core: fix race of blocking autoconnect for no-secrets when a new secret-agent registers
When activation of the connection fails with no-secrets, we block
autoconnect due to that. However, NMPolicy also unblocks such
autoconnect, whenever a new secret-agent registers. The reason
is obviously, that the new secret-agent might be able to provide
the previously missing secrets.

However, there is a race between
  - making the secret request, failing activation and blocking autoconnect
  - new secret-agent registers

If the secret-agent registers after making the request, but before we
block autoconnect, then autoconnect stays blocked.

  [1511468634.5759] device (wlp4s0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
  [1511468634.5772] device (wlp4s0): No agents were available for this request.
  [1511468638.4082] agent-manager: req[0x55ea7e58a5d0, :1.32/org.kde.plasma.networkmanagement/1000]: agent registered
  [1511468638.4082] policy: re-enabling autoconnect for all connections with failed secrets
  [1511468664.6280] device (wlp4s0): state change: need-auth -> failed (reason 'no-secrets', sys-iface-state: 'managed')
  [1511468664.6287] policy: connection 'tuxmobil' now blocked from autoconnect due to no secrets

Note the long timing between making the secret request and the
activation failure. This race already existed before, but now with
WPS push-button method enabled by default, the duraction of the
activation is much longer and the race is easy to hit.

https://bugzilla.gnome.org/show_bug.cgi?id=790571
(cherry picked from commit e2c8ef45ac)
2017-11-27 16:00:53 +01:00
Thomas Haller
37ac96cb55 policy: use "agent-registered" signal directly from NMAgentManager instead of NMSettings
(cherry picked from commit 46af70b508)
2017-11-27 16:00:53 +01:00
Thomas Haller
44cd35c16c core: use #define for "agent-registered" signal name
(cherry picked from commit c3cae3d0dc)
2017-11-27 16:00:53 +01:00
Thomas Haller
64af67b90f settings: use slice allocator for UpdateInfo data
(cherry picked from commit 6ab0ff8a7c)
2017-11-27 16:00:53 +01:00
Thomas Haller
d0039b5521 policy: avoid false positives for checking for autoactivation
We want to only check for autoconnect all, if something happend that
makes it possible that we can autoconnect now (while we couldn't
previously).

It's not a real problem to check more often then strictly necessary.
But add a check to rule out a few false-positives to avoid the
overhead of checking all devices for autoconnect.

(cherry picked from commit f0147a9c47)
2017-11-27 16:00:53 +01:00
Thomas Haller
01dbbf1404 policy: add nm_settings_connection_autoconnect_is_blocked() helper function
(cherry picked from commit 36ac08c092)
2017-11-27 16:00:53 +01:00
Thomas Haller
d4530effb8 policy: don't clear autoconnect-blocked-reason user-request on internal reasons
reset_autoconnect_all() as two callers with only_no_secrets=FALSE:

  - sleeping_changed() when NM returns from sleep.

  - when device changes to state DISCONNECTED with reason
    CARRIER.

In both cases, this should not overwrite a previous decision by
the user that the connection should not autoconnect.

(cherry picked from commit d8b4403f6b)
2017-11-27 16:00:53 +01:00
Thomas Haller
76560639ba policy: only selectively schedule autoconnect check in activate_slave_connections()
schedule_activate_all() is expensive. It iterates over all devices, and asks
them to autoactivated (which might involve iterating over all connections for
each device). Avoid it if nothing changed.

(cherry picked from commit 5e5121a483)
2017-11-27 16:00:52 +01:00
Thomas Haller
632bb9524e policy: only reset autoconnect-blocked-reason FAILED in activate_slave_connections()
The reasons no-secret and user-request still hold.

(cherry picked from commit 3a826a83df)
2017-11-27 16:00:52 +01:00
Thomas Haller
4d8fcebd2e policy: only reset no-secrets autoconnect block flag when secret agent registers
The other blocked reasons still hold. If autoconnect was blocked for
other reasons then no-secrets, a secret agent should not unblock them
all.

(cherry picked from commit b154f29b2b)
2017-11-27 16:00:52 +01:00
Thomas Haller
78d619fc9d policy: track autoconnect-blocked-reasons as flags
Extend the enum and API to use flags for the blocked reasons.
A connection is blocked from autoconnect if it has any reason
set.

There is no behavioral change in this patch beyond that, because
where we previously would set blocked-reason NONE, we would still
clear all flags, and not only a particular one.

Later of course, we want to set and clear individual flags
independently.

(cherry picked from commit 8d2d9b0748)
2017-11-27 16:00:52 +01:00
Thomas Haller
c8de52e281 policy: minor refactoring of device_state_changed()
(cherry picked from commit ddb8713d44)
2017-11-27 16:00:52 +01:00
Thomas Haller
c956bc5154 policy: minor cleanup of loop in activate_slave_connections()
(cherry picked from commit 40b534c5d8)
2017-11-27 16:00:52 +01:00
Thomas Haller
655d9f7961 policy: fix logging about autoconnect retries number
NMPolicy printed

  policy: connection 'a' failed to autoconnect; 1 tries left
  settings-connection[0x55a485553b60,ab9f3891-3420-335e-89da-f14c1b94c540]: autoconnect: retries set 0

That is, it claimed there was one more try, when in fact there wasn't.

(cherry picked from commit 5fc4b32629)
2017-11-27 16:00:52 +01:00
Thomas Haller
d737438a19 core: cache "autoconnect-retries-default" in NMConfigData
It's not ever going to change(*), and NMPolicy calls reset() a lot.
No need to lookup the configuration in the GKeyFile every time.

(*) per NMConfigData instance. The config may be reloaded, in which
case NMConfig creates a new NMConfigData instance, but the NMConfigData
instance itself is immutable.

(cherry picked from commit af703ba990)
2017-11-27 16:00:52 +01:00
Thomas Haller
3c488f456a core: use #define for "autoconnect-retries-default" config
All our known configuration keys should have a #define, so that
all keys are collected in the header file.

(cherry picked from commit 1c631bda4e)
2017-11-27 16:00:52 +01:00
Thomas Haller
1e63d9bed5 core: don't explicitly unset autoconnect retry counter
NMPolicy would at various time call nm_settings_connection_autoconnect_retries_reset()
followed by nm_settings_connection_autoconnect_retries_get().

This resulted in two logging messages, first to indicate that the value
was unset, and then reset it to the value from configuration. While that
is correct, it causes a lot of verbose logging. Especially for all connections
which autoconnect retry counter didn't actually change.

The advantage of that was, that we only loaded the actual value when we
need it the first time (during get()). That means, the user could reload
the configuration, and the value would be loaded and cached at a later
pointer.

However, the duplicate logging was annoying, but we still want to see
a message about the resetting.

So, now during reset load the value setting from NetworkManager.conf
and set it right away. Skip the intermediate UNSET value. In most
cases nothing changed now, and we don't log anything for most
connections.

(cherry picked from commit a91dfa6a27)
2017-11-27 16:00:52 +01:00
Thomas Haller
fff56e2316 policy: don't log GError code
Our GError codes are mostly meaningless, only the message is interesting.
And our messages should anyway be unique, so that one could understand
which was the corresponding error code (by inspecting the source code).

While at it, use gs_free_error.

(cherry picked from commit 3d118f5b49)
2017-11-27 16:00:52 +01:00
Thomas Haller
e6d1931fe7 policy: move setting autoconnect retries to a separate function
Note that for the

  if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_NO_SECRETS)

case we no longer do the

  if (nm_settings_connection_autoconnect_retries_get (connection) == 0)

check. But that is fine, because we only skip schedling a reset_connections_retries()
action. But note, that that previously we also would never actually
scheudle a new timeout, because

  - either nm_settings_connection_autoconnect_retries_get (connection) != 0
  - or the retries count was zero, in which case we already have a
    reset_connections_retries action pending (from the time when we
    set it to zero.

So, there is no change in behavior at all except dropping of a redundant
logging line.

(cherry picked from commit 124b905f97)
2017-11-27 16:00:52 +01:00
Thomas Haller
b38fef7ecb core: log autoconnect properties of NMSettingsConnection
(cherry picked from commit 3177b18aab)
2017-11-27 16:00:52 +01:00
Thomas Haller
a508d0ad5c policy: minor code cleanup in activate_slave_connections()
(cherry picked from commit 071495c754)
2017-11-27 16:00:52 +01:00
Thomas Haller
99fc77c7b0 settings/trivial: rename nm_settings_connection_autoconnect_retries_blocked_until()
NMSettingsConnection has 3 properties that are related to autoconnect:
  - autoconnect_retries
  - autoconnect_blocked_until
  - autoconnect_blocked_reason

autoconnect_blocked_reason is entirely independent from the other two.
A connection have have autoconnect blocked via a blocked-reason, but the
retry count is not affected by that. The retry count is an independent
mechanism, that may additionally prevent autoconnect.

However autoconnect_retries and autoconnect_retries_blocked_until are
strongly related. The latter is set if and only if autoconnect_retries is
at zero.

Rename to reflect that better.

(cherry picked from commit 955432ca87)
2017-11-27 16:00:52 +01:00
Thomas Haller
e683801bd2 policy: merge reset_autoconnect_*() functions
(cherry picked from commit 4e7b05de79)
2017-11-27 16:00:52 +01:00
Thomas Haller
0c0e8d1961 core/trivial: add code comment
(cherry picked from commit 1f3f142fed)
2017-11-27 16:00:52 +01:00
Thomas Haller
f988bbe613 core: merge IPv4 and IPv6 versions of nm_active_connection_get_default()
(cherry picked from commit 10a46c5ae2)
2017-11-27 16:00:52 +01:00
Thomas Haller
274a609a4b core: track NMActiveConnection in manager with CList
Using CList, we embed the list element in NMActiveConnection struct
itself. That means for example, that you couldn't track a
NMActiveConnection more then once. But we anyway never want that.

The advantage is, that removing an active connection from the list
is O(1), and we safe additional GSlice allocations for each node
element.

(cherry picked from commit 3a907377ac)
2017-11-27 16:00:48 +01:00
Thomas Haller
4b8afb752d core: merge nm_settings_get_connections_sorted() with nm_settings_get_connections_clone()
(cherry picked from commit 51531c9539)
2017-11-27 15:59:58 +01:00
Thomas Haller
bfd4a70cc3 policy: use CList to track pending_activation_checks
This makes link and unlink operations O(1) and safes an additional
GSlice allocation for each GSList node.

(cherry picked from commit 3b874554ac)
2017-11-27 15:59:58 +01:00
Thomas Haller
59886a85e3 policy: schedule autoactivation check after reset_autoconnect_all()
When changing the autoconnect blocked settings, we must trigger a recheck-all.

(cherry picked from commit cfb2af1df2)
2017-11-27 15:59:58 +01:00
Thomas Haller
1a28926b22 policy: avoid cloning connection list
We don't care about having a cloned list, nor do we care about
a sort order.

(cherry picked from commit 31f70557f5)
2017-11-27 15:59:58 +01:00
Thomas Haller
bf6f63b9ad core: use CList for call-ids in NMSettingsConnection
(cherry picked from commit 310973bb64)
2017-11-27 15:59:58 +01:00
Thomas Haller
2af8036b58 core/trivial: unify names of internal NMSettingsConnectionCallId as "call_id"
(cherry picked from commit 4e11be5ecf)
2017-11-27 15:59:58 +01:00
Thomas Haller
adca290d31 core: drop internal typedef GetSecretsInfo for NMSettingsConnectionCallId
Using an internal alias for the type is just confusing. Drop it.

(cherry picked from commit fc918049de)
2017-11-27 15:59:58 +01:00
Thomas Haller
2addde633c core: refactor NMSettingsConnectionCallId typedef not to be a pointer to struct
Typedefs to structs are fine, but a typedef for a pointer seems confusing to
me. Let's avoid it.

(cherry picked from commit 616976d6a8)
2017-11-27 15:59:58 +01:00
Thomas Haller
06ac0b6d96 core/vpn: mark secret hints as const
(cherry picked from commit f76dbfc1a6)
2017-11-27 15:59:39 +01:00
Thomas Haller
f000c76be4 core: replace "dup()" by "fcntl(fd, F_DUPFD_CLOEXEC, 0)"
(cherry picked from commit 1e572ebf87)
2017-11-27 14:03:51 +01:00
Beniamino Galvani
a792a7f9c3 ifcfg-rh: close file descriptor only when necessary
If the file was read-only, we already closed it.

This fixes the following valgrind warnings:

 Warning: invalid file descriptor -1 in syscall close()

(cherry picked from commit 174da8f922)
2017-11-27 10:19:29 +01:00
Francesco Giudici
9c634e13c3 device: update device mtu from ip interface when required
If the tracked device is a control device only (has no network interface)
like in the case of a cdc-wdm device, get the mtu from the ip interface
(the exposed wwan network interface in this case).

https://bugzilla.redhat.com/show_bug.cgi?id=1460217
(cherry picked from commit efed5254cd)
2017-11-24 17:38:14 +01:00
Thomas Haller
af4fbf97f5 device: merge branch 'th/shared-mode-failure-bgo790726'
https://bugzilla.gnome.org/show_bug.cgi?id=790726

(cherry picked from commit 3d0c5b3bb8)
2017-11-24 17:14:05 +01:00
Thomas Haller
a6b388d7d5 device: only set ip_forward sysctl if necessary
/proc/sys might be read-only but we want to set it for
enabling shared mode.

Check first if the sysctl already has the expected value,
and if so, do nothing.

https://bugzilla.gnome.org/show_bug.cgi?id=790726
(cherry picked from commit d841930d67)
2017-11-24 17:13:45 +01:00
Thomas Haller
26ca80ebf5 device: return and log failure reason for start_sharing()
Also downgrade a few intermediate error logging messages
for failures that happen while start_sharing(). A debug
message is enough in this case, because we propagate now
the error to the caller, which logs a warning anyway.

(cherry picked from commit 3369a2c0b0)
2017-11-24 17:13:45 +01:00
Thomas Haller
1725c7136f platform: preserve errno in nm_platform_sysctl_get_int_checked()
It's not clear whether free() changes errno. Be sure about it.

https://bugzilla.gnome.org/show_bug.cgi?id=790726
(cherry picked from commit 653aab70ac)
2017-11-24 17:13:45 +01:00