Commit graph

10026 commits

Author SHA1 Message Date
Thomas Haller
1c631bda4e 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.
2017-11-27 15:21:57 +01:00
Thomas Haller
a91dfa6a27 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.
2017-11-27 15:21:57 +01:00
Thomas Haller
3d118f5b49 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.
2017-11-27 15:21:57 +01:00
Thomas Haller
124b905f97 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.
2017-11-27 15:21:57 +01:00
Thomas Haller
3177b18aab core: log autoconnect properties of NMSettingsConnection 2017-11-27 15:21:57 +01:00
Thomas Haller
071495c754 policy: minor code cleanup in activate_slave_connections() 2017-11-27 15:21:57 +01:00
Thomas Haller
955432ca87 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.
2017-11-27 15:18:04 +01:00
Thomas Haller
4e7b05de79 policy: merge reset_autoconnect_*() functions 2017-11-27 15:18:04 +01:00
Thomas Haller
1f3f142fed core/trivial: add code comment 2017-11-27 14:04:11 +01:00
Thomas Haller
10a46c5ae2 core: merge IPv4 and IPv6 versions of nm_active_connection_get_default() 2017-11-27 14:04:11 +01:00
Thomas Haller
3a907377ac 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.
2017-11-27 14:04:11 +01:00
Thomas Haller
51531c9539 core: merge nm_settings_get_connections_sorted() with nm_settings_get_connections_clone() 2017-11-27 14:04:11 +01:00
Thomas Haller
3b874554ac 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.
2017-11-27 14:04:11 +01:00
Thomas Haller
cfb2af1df2 policy: schedule autoactivation check after reset_autoconnect_all()
When changing the autoconnect blocked settings, we must trigger a recheck-all.
2017-11-27 14:04:11 +01:00
Thomas Haller
31f70557f5 policy: avoid cloning connection list
We don't care about having a cloned list, nor do we care about
a sort order.
2017-11-27 14:04:11 +01:00
Thomas Haller
310973bb64 core: use CList for call-ids in NMSettingsConnection 2017-11-27 14:04:11 +01:00
Thomas Haller
4e11be5ecf core/trivial: unify names of internal NMSettingsConnectionCallId as "call_id" 2017-11-27 14:04:11 +01:00
Thomas Haller
fc918049de core: drop internal typedef GetSecretsInfo for NMSettingsConnectionCallId
Using an internal alias for the type is just confusing. Drop it.
2017-11-27 14:04:11 +01:00
Thomas Haller
616976d6a8 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.
2017-11-27 14:04:11 +01:00
Thomas Haller
1e572ebf87 core: replace "dup()" by "fcntl(fd, F_DUPFD_CLOEXEC, 0)" 2017-11-27 14:03:00 +01:00
Beniamino Galvani
174da8f922 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()
2017-11-27 10:01:36 +01:00
Francesco Giudici
efed5254cd 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
2017-11-24 17:36:20 +01:00
Thomas Haller
d841930d67 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
2017-11-24 17:06:42 +01:00
Thomas Haller
3369a2c0b0 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.
2017-11-24 17:06:42 +01:00
Thomas Haller
653aab70ac 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
2017-11-24 17:06:42 +01:00
Thomas Haller
a3569eddf2 core: use CList to track NMActRequestGetSecretsCallId in NMActRequest
Gives O(1) insert and remove. Also saves the overhead of the GSlice
allocation for the GSList node.
2017-11-24 16:44:28 +01:00
Thomas Haller
1cbbefcddd core/trivial: unify names of internal NMActRequestGetSecretsCallId as "call_id" 2017-11-24 16:44:28 +01:00
Thomas Haller
966ac03668 core: drop internal typedef Result for NMSecretAgentCallId
Using an internal alias for the type is just confusing. Drop it.
2017-11-24 16:44:28 +01:00
Thomas Haller
370dc8883f core: drop internal typedef GetSecretsInfo for NMSecretAgentCallId
Using an internal alias for the type is just confusing. Drop it.
2017-11-24 16:31:58 +01:00
Thomas Haller
e5e291b65f core: refactor NMActRequestGetSecretsCallId 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.
2017-11-24 16:31:29 +01:00
Thomas Haller
6cb40da2f0 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.
2017-11-24 16:24:40 +01:00
Thomas Haller
b074fd23b4 ifcfg-rh: check integer value for other bridge options 2017-11-23 18:43:49 +01:00
Thomas Haller
ff239c1652 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.
2017-11-23 18:43:48 +01:00
Thomas Haller
30ce598fb5 ifcfg-rh: fix range and size when parsing integer values in reader 2017-11-23 18:43:48 +01:00
Thomas Haller
12788db4ee ifcfg-rh/trivial: rename get_uint() to get_uint32() 2017-11-23 18:43:48 +01:00
Thomas Haller
3a67b496ca ifcfg-rh: avoid string copies in make_bridge_setting()
Also, don't g_strstrip(value) for BRIDGE_MACADDR.
2017-11-23 18:43:48 +01:00
Beniamino Galvani
fb191fc282 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
2017-11-23 18:43:48 +01:00
Beniamino Galvani
56a02c9baf ifcfg-rh: read wired properties for bridge connections
A bridge connection can have ethernet settings, read them from the
ifcfg file.
2017-11-23 18:43:48 +01:00
Thomas Haller
f76dbfc1a6 core/vpn: mark secret hints as const 2017-11-23 14:44:25 +01:00
Thomas Haller
898567adfe platform: don't return zero from nmp_object_id_hash()
There is no principle problem with returning zero has hash
value. But just don't do it. Our hash functions should not
return zero. Instead, return nm_hash_static(). This is why
the function exists.
2017-11-23 14:44:24 +01:00
Thomas Haller
f7d83e681f platform: move nmp_object_equal() to header for inline 2017-11-23 14:44:24 +01:00
Thomas Haller
6b319cd072 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.
2017-11-21 13:48:49 +01:00
Thomas Haller
7328976a02 ifcfg-rh/tests: test writing multiple bond options 2017-11-21 13:40:13 +01:00
Beniamino Galvani
62141d59cb 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
2017-11-21 13:27:59 +01:00
Beniamino Galvani
9a631a068e 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()").
2017-11-21 11:27:54 +01:00
Beniamino Galvani
a7c97d58db device: check captured IPv6 configuration in check_and_add_ipv6ll_addr()
check_and_add_ipv6ll_addr() checks whether a link-local address is
already present in priv->ip6_config and if so, it returns with no
action.

priv->ip6_config is only updated after a merge-and-apply or (in an
idle source) when the external configuration changes and so there is
no guarantee that the addresses there are up-to-date.

priv->ext_ip6_config_captured should be checked instead, because it is
updated from platform right before starting the generation of a
link-local address. Note that also linklocal6_start() already checks
the captured external configuration rather than priv->ip6_config.

https://bugzilla.redhat.com/show_bug.cgi?id=1500350
2017-11-20 10:50:13 +01:00
Thomas Haller
25267f9d27 dns: don't stat relative paths when detecting resolved use
NetworkManager daemon has no defined working directory.
It makes no sense to ever open or stat relative paths.
Just skip them.

https://bugzilla.gnome.org/show_bug.cgi?id=790446
2017-11-19 14:29:16 +01:00
Dimitri John Ledkov
e09503dcc4 dns: check for relative paths and stub-resolve.conf when detecting systemd-resolved
Fix resolved detection, the symlink target is usually relative to the
root, such that in chroots the file points to a file inside the
chroot. But keep absolute targets too, as these may have been in use
with older version of systemd. Add support for stub-resolv.conf
detection.

https://bugzilla.gnome.org/show_bug.cgi?id=790446
2017-11-19 14:25:59 +01:00
Beniamino Galvani
60334a2893 device: don't touch external devices
If a device is 'external' (which means that NM generated an in-memory
connection to only to track the device state) we should not change its
IP configuration.

https://bugzilla.redhat.com/show_bug.cgi?id=1512316
2017-11-17 18:19:32 +01:00
Beniamino Galvani
9e41ed4461 device: start managing external devices on reapply
In the next commit we will modify ipX_config_merge_and_apply to never
touch external devices. When a "reapply" call is issued on an external
device we are no longer simply tracking its state but we are actively
managing it and so its sys-iface-state must be promoted to managed.

https://bugzilla.redhat.com/show_bug.cgi?id=1512316
2017-11-17 18:19:32 +01:00