Commit graph

1542 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
Beniamino Galvani
092c8f4e6a settings: fix clist initialization
Fixes: 310973bb64
(cherry picked from commit 1e1af30d95)
2017-11-27 21:05:07 +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
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
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
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
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
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
0c0e8d1961 core/trivial: add code comment
(cherry picked from commit 1f3f142fed)
2017-11-27 16:00:52 +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
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
Thomas Haller
4a7fa0c4c4 core: drop internal typedef Result for NMSecretAgentCallId
Using an internal alias for the type is just confusing. Drop it.

(cherry picked from commit 966ac03668)
2017-11-24 17:05:03 +01:00
Thomas Haller
f842831059 core: refactor NMSecretAgentCallId 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 6cb40da2f0)
2017-11-24 17:05:03 +01:00
Thomas Haller
539a2835b2 ifcfg-rh: check integer value for other bridge options
(cherry picked from commit b074fd23b4)
2017-11-24 08:29:27 +01:00
Thomas Haller
c42913f5b1 ifcfg-rh: check integer value when reading handle_bridge_option()
We cannot just call g_object_set() with an integer that is out of bound.
Otherwise, glib will warn. We can use nm_g_object_set_property*() to return
an error without asserting.

(cherry picked from commit ff239c1652)
2017-11-24 08:29:24 +01:00
Thomas Haller
3d6d54676d ifcfg-rh: fix range and size when parsing integer values in reader
(cherry picked from commit 30ce598fb5)
2017-11-24 08:29:21 +01:00
Thomas Haller
0219368a77 ifcfg-rh/trivial: rename get_uint() to get_uint32()
(cherry picked from commit 12788db4ee)
2017-11-24 08:29:19 +01:00
Thomas Haller
f147f490dd ifcfg-rh: avoid string copies in make_bridge_setting()
Also, don't g_strstrip(value) for BRIDGE_MACADDR.

(cherry picked from commit 3a67b496ca)
2017-11-24 08:29:18 +01:00
Beniamino Galvani
1d5f060098 ifcfg-rh: use distinct variables for bridge and wired mac address
Currently both bridge.mac-address and ethernet.cloned-mac-address get
written to the same MACADDR ifcfg-rh variable; the ethernet property
wins if both are present.

When one property is set and the connection is saved (and thus reread)
both properties are populated with the same value. This is wrong
because, even if the properties have the same meaning, the setting
plugin should not read something different from what was written. Also
consider that after the following steps:

 $ nmcli con mod c ethernet.cloned-mac-address 00:11:22:33:44:55
 $ nmcli con mod c ethernet.cloned-mac-address ""

the connection will still have the new mac address set in the
bridge.mac-address property, which is certainly unexpected.

In general, mapping multiple properties to the same variable is
harmful and must be avoided. Therefore, let's use a different variable
for bridge.mac-address. This changes behavior, but not so much:

 - connections that have MACADDR set will behave as before; the only
   difference will be that the MAC will be present in the wired
   setting instead of the bridge one;

 - initscripts compatibility is not relevant because MACADDR for
   bridges was a NM extension;

 - if someone creates a new connection and sets bridge.mac-address NM
   will set the BRIDGE_MACADDR property instead of MACADDR. But this
   shouldn't be a big concern as bridge.mac-address is documented as
   deprecated and should not be used for new connections.

https://bugzilla.redhat.com/show_bug.cgi?id=1516659
(cherry picked from commit fb191fc282)
2017-11-24 08:28:47 +01:00
Beniamino Galvani
3a623c2d1f ifcfg-rh: read wired properties for bridge connections
A bridge connection can have ethernet settings, read them from the
ifcfg file.

(cherry picked from commit 56a02c9baf)
2017-11-24 08:28:43 +01:00
Thomas Haller
628d292be7 ifcfg-rh: avoid duplicate lookup of bond-option in write_bond_setting()
Now that nm_setting_bond_get_option() has a stable order
(alphabetically), we no longer need to sort it.

(cherry picked from commit 6b319cd072)
2017-11-21 14:15:26 +01:00
Thomas Haller
fae12cf956 ifcfg-rh/tests: test writing multiple bond options
(cherry picked from commit 7328976a02)
2017-11-21 14:14:25 +01:00
Beniamino Galvani
0bd8b34725 settings: preserve agent-owned secrets on connection add
Settings plugins now return the connection that was reread from file
when adding a connection, which means that any agent-owned secret is
lost. Ensure that we don't forget agent-owned secrets by caching them
and readding them to the new connection returned by plugins.

Fixes: 8a1d483ca8
Fixes: b4594af55e

https://bugzilla.gnome.org/show_bug.cgi?id=789383
(cherry picked from commit 62141d59cb)
2017-11-21 13:37:53 +01:00
Beniamino Galvani
7225fdc5ae ifcfg-rh: sort bond options when writing a connection
Bond options are stored in a hash table and the order in which they
are returned by the API is not guaranteed. Sort them alphabetically so
that a connection will always be written in the same way, even if the
internal implementation of the hash table or the hashing function
changes, as it did in commit a6be2f4aa9 ("all: use nm_str_hash()
instead of g_str_hash()").

(cherry picked from commit 9a631a068e)
2017-11-21 11:29:32 +01:00
Thomas Haller
3a8a9941df core/vpn: log capabilities of secret-agent
(cherry picked from commit 96d5d66460)
2017-11-17 17:14:51 +01:00
Thomas Haller
2dcf08402c ifcfg-rh: avoid coverity false positive in write_secrets()
Comparing @secrets_keys indicates to coverity that it might be NULL.
Below, we access @secrets_keys without check, and coverity doesn't realize
that this cannot crash, because secrets_keys_n would be zero too.

Anyway, this way we safe the sorting, in case we only have
one element.

(cherry picked from commit cfdb962ebd)
2017-11-15 18:19:54 +01:00
Thomas Haller
4b890dead5 all: support route-attribute "onlink" for IPv4
Kernel doesn't support it for IPv6.

This is especially useful, if you combine static routes
with DHCP. In that case, you might want to get the device-route
to the gateway automatically, but add a static-route for it.

(cherry picked from commit 0ed49717ab)
2017-11-13 14:43:07 +01:00
Beniamino Galvani
293710434d ifcfg-rh: persist the connection type for TeamPort connections
Currently the ifcfg-rh plugin doesn't explicitly store the connection
type for team slaves and is only able to read back ethernet and vlan
connections.

Leave this unchanged for ethernet and vlan slaves, but store the TYPE
variable for other connection types (Wi-Fi and Infiniband) so that we
can properly determine their type when the connection is read.

(cherry picked from commit 29a576496e)
2017-11-06 16:46:22 +01:00
Thomas Haller
6705c71263 ifcfg-rh: use svSetValueInt64_cond() in write_connection_setting() 2017-11-02 11:41:01 +01:00
Thomas Haller
2730dc60de all: move setting 802-1x.auth-retries to connection.auth-retries
The number of authentication retires is useful also for passwords aside
802-1x settings. For example, src/devices/wifi/nm-device-wifi.c also has
a retry counter and uses a hard-coded value of 3.

Move the setting, so that it can be used in general. Although it is still
not implemented for other settings.

This is an API and ABI break.
2017-11-02 11:41:01 +01:00
Thomas Haller
53dea38834 ifcfg-rh: refactor write_object() to avoid coverity warning
Coverity detects that the "if (blob)" condition must always be true.
Reorder the code, to avoid the warning. It's a bit clearer this way
anyway.
2017-10-31 20:15:04 +01:00
Thomas Haller
1a9d4869ed policy: move nm_settings_connection_can_autoconnect() to policy
Step by step, we move all tracking of autoconnect to NMPolicy.
2017-10-31 19:35:33 +01:00
Thomas Haller
e62e52dfe1 device: handle authentication retries using 802-1x.auth-retries setting
Since commit 4a6fd0e83e (device: honor the
connection.autoconnect-retries for 802.1X) and the related bug bgo#723084,
we reuse the autoconnect-retries setting to control the retry count
for requesting passwords.

I think that is wrong. These are two different settings, we should not
reuse the autoconnect retry counter while the device is still active.

For example, the user might wish to set autoconnect-retries to infinity
(zero). In that case, we would retry indefinitly to request a password.
That could be problematic, if there is a different issue with the
connection, that makes it appear tha the password is wrong.
A full re-activation might succeed, but we would never stop retrying
to authenticate. Instead, we should have two different settings for
retrying to authenticate and to autoconnect.

This is a change in behavior compared to 1.8.
2017-10-31 19:35:33 +01:00
Thomas Haller
89e518db5a libnm,cli,ifcfg-rh: add NMSetting8021x:auth-retries property 2017-10-31 19:35:33 +01:00
Thomas Haller
18f2d272ba settings: add and use nm_settings_connection_autoconnect_retries_try_next() 2017-10-31 19:35:33 +01:00
Thomas Haller
361a199a06 device: move resetting autoconnect retries from subtype to NMDevice 2017-10-31 19:35:28 +01:00
Thomas Haller
447dc874ce config: remove nm_config_data_get_value_cached()
It has almost no callers, and it is a bit of a strange API. Let's
not cache the last accessed value inside NMConfigData. Instead, free
it right after use. It was not reused anyway, it only hangs around
as convenience for the caller.
2017-10-31 19:14:07 +01:00
Thomas Haller
ec9bff293b settings/trivial: rename settings-connection's autoconnect functions
Names like
  - nm_settings_connection_get_autoconnect_retries
  - nm_settings_connection_set_autoconnect_retries
  - nm_settings_connection_reset_autoconnect_retries
are about the same thing, but they are cumbersome to grep
because they share not a common prefix.

Rename them from SUBJECT_VERB_OBJECT to SUBJECT_OBJECT_VERB,
which sounds odd in English, but seems preferred to me.
Now you can grep for "nm_settings_connection_autoconnect_retries_" to
get all accessors of the retry count, or "nm_settings_connection_autoconnect_"
to get all accessors related to autoconnect in general.
2017-10-31 19:14:07 +01:00