Commit graph

19075 commits

Author SHA1 Message Date
Beniamino Galvani
c6eb18ee05 ifcfg-rh: persist the wep key type
The wireless-security setting has a 'wep-key-type' property that is
used to specify the WEP key type and is needed because some keys could
be interpreted both as a passphrase or a hex/ascii key.

The ifcfg-rh plugin currently stores the key type implicitly: if
wep-key-type is 'passphrase' it uses the KEY_PASSPHRASE%d variable, if
it's 'key' the KEY%d variable and when it's 'unknown' it uses either
variables depending on the detected type (preferring 'key' in case
both are compatible).

This means that some connections will be read differently from how
they were written, because once the KEY (or KEY_PASSPHRASE) is read
there is no way to know whether the 'wep-key-type' property was 'key'
(or 'passphrase') or 'unknown'.

Fix this by persisting the key type explicitly in the file. The new
variable is redundant in most cases because the variables used for
keys also determine the key type.

https://bugzilla.redhat.com/show_bug.cgi?id=1518177
2017-12-04 15:53:53 +01:00
Yifan J
797d9c4403 python: make dbus, gi examples, and debug-helper.py python3 ready
https://bugzilla.gnome.org/show_bug.cgi?id=791121
2017-12-04 11:21:40 +01:00
Beniamino Galvani
5e239d2c04 cli: don't print warnings when completing arguments
$ nmcli con add type wifi ifname wlan0 \
     wifi-sec.key-mgmt none \
     wifi-sec.wep-key0 $ascii_key \
     ssid <TAB>

 completes the line with:

  "Info:\ WEP\ key\ is\ guessed\ to\ be\ of\ '2\ \(passphrase\)'"

The environment warning function should not emit warning when
completing arguments.
2017-12-01 14:27:38 +01:00
Beniamino Galvani
6f5f1b2d29 ifcfg-rh: merge branch 'bg/ifcfg-rh-dns-rh1517794'
https://bugzilla.redhat.com/show_bug.cgi?id=1517794
2017-11-30 23:56:00 +01:00
Thomas Haller
9b08f2c61d ifcfg-rh: only open network file once when parsing connection 2017-11-30 23:54:45 +01:00
Beniamino Galvani
8379785560 ifcfg-rh: use different variables for IPv4 and IPv6 DNS options
Until now the ifcfg-rh plugin merged the values of 'ipv4.dns-options'
and 'ipv6.dns-options' and wrote the result to the RES_OPTIONS
variable. This is wrong because writing a connection and reading it
back gives a different connection compared to the original.

This behavior existed since when DNS options were introduced, but it
became more evident now that we reread the connection after write,
because after doing a:

 $ nmcli connection modify ethie ipv4.dns-options ndots:2

the connection has both ipv4.dns-options and ipv6.dns-options set. In
order to delete the option, an user has to delete it from both
settings:

 $ nmcli connection modify ethie ipv4.dns-options "" ipv6.dns-options ""

To improve this let's use different variables for IPv4 and IPv6. To
keep backwards compatibility IPv4 still uses RES_OPTIONS, while IPv6
uses a new IPV6_RES_OPTIONS variable.

https://bugzilla.redhat.com/show_bug.cgi?id=1517794
2017-11-30 23:54:45 +01:00
Beniamino Galvani
ca06f82371 clients: fix display value for dns-options
We must show the default value "(default)" when the list of
dns-options is initialized but empty.
2017-11-30 23:54:45 +01:00
Beniamino Galvani
d74e1bef36 all: replace 'inital' with 'initial'
sed -i -e 's/inital/initial/g' $(git grep -l inital)
2017-11-30 23:54:45 +01:00
Beniamino Galvani
fead82f419 tui: fix creation of open Wi-Fi connections
Commit 6a4af482f0 ("nmtui: always create ethernet settings for VLAN
and wireless security for wifi.") changed nmtui to always add the
wireless security setting to the new connection, but without
initializing it. This leads to a crash that was fixed in 40fcf67a84
("tui: fix crash creating Wi-Fi connection").

There is an additional bug: connections without authentication can't
be saved because the wireless security setting has uninitialized
fields.

To fix this, revert both patches (the first partially) because the
previous code did the right thing as it added the setting only when
needed.

Fixes: 6a4af482f0

https://bugzilla.redhat.com/show_bug.cgi?id=1518167
2017-11-30 17:22:28 +01:00
Thomas Haller
cc74cffe12 device: add "indicated" argument to nm_utils_match_connection()
The matching works fuzzy and is not reliable. That is why we store
which connection should be assumed after restart in the state file
of NetworkManager.

In that case, we don't need to do a full check (with the possibility
of a false-reject). Just check for the minimum required properties:
the type and slave-type.

Yes, if the user modifies the connection while restarting NM, then
we might wrongly assume a connection that no longer would match.
But NM should not read minds, it should do as indicated.
2017-11-30 14:47:49 +01:00
Thomas Haller
15608713c4 libnm: drop now unused helper function _nm_utils_strsplit_set() 2017-11-29 16:26:28 +01:00
Thomas Haller
a81ad3474d ifcfg-rh: replace usage of _nm_utils_strsplit_set() with nm_utils_strsplit_set() 2017-11-29 16:26:28 +01:00
Thomas Haller
d3520813e8 ifcfg-rh: avoid copy of value for "HWADDR_BLACKLIST" 2017-11-29 16:26:28 +01:00
Thomas Haller
de92e88161 shared: fix nm_utils_strsplit_set() to increase buffer size exponentially 2017-11-29 16:26:28 +01:00
Beniamino Galvani
21cfeff777 cli: exit from main loop after 'quit' editor command
When we stop processing the editor command loop (after a 'quit'
command) we must quit the GLib main loop.

https://bugzilla.redhat.com/show_bug.cgi?id=1517401
2017-11-29 11:05:04 +01:00
Thomas Haller
2e974baa15 cli: use nm_clear_g_source() util in quit() functions 2017-11-29 10:19:12 +01:00
Thomas Haller
199525ba52 core: avoid duplicate <info> logging message when sleeping/waking
<debug> [1511941494.1809] manager: Received resuming signal
  <info>  [1511941494.1809] manager: wake requested (sleeping: yes  enabled: yes)
  <info>  [1511941494.1809] manager: waking up...
2017-11-29 10:15:02 +01:00
Thomas Haller
88549b031a policy: don't schedule_activate_all() when going to sleep
This was added by cfb2af1df2, but it's
wrong. Here we reset the autoconnect-blocked-reasons when going to sleep,
not when waking up.
2017-11-29 10:15:02 +01:00
Thomas Haller
249aff6349 core: fix broken autoconnect due to wrong nm_settings_connection_autoconnect_is_blocked()
Fixes: 36ac08c092
2017-11-29 10:14:45 +01:00
Lubomir Rintel
c9db2c17aa policy: fix possible crash on deactivating connection on removal
_deactivate_if_active() takes a NMPolicy instance while the
connection_removed signal handler takes a NMPolicyPrivate pointer.
2017-11-28 13:52:12 +01:00
Thomas Haller
b6efac9ec2 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
2017-11-28 11:26:39 +01:00
Thomas Haller
2becc0a0ac 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
2017-11-28 10:53:40 +01:00
Thomas Haller
245590bacd 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.
2017-11-28 10:33:28 +01:00
Thomas Haller
e4099f6764 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
2017-11-28 10:33:26 +01:00
Thomas Haller
b595a80977 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
2017-11-28 10:33:26 +01:00
Beniamino Galvani
021d797089 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.
2017-11-28 09:37:06 +01:00
Beniamino Galvani
1e1af30d95 settings: fix clist initialization
Fixes: 310973bb64
2017-11-27 21:02:12 +01:00
Thomas Haller
2c3dccfd28 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
2017-11-27 15:50:38 +01:00
Thomas Haller
e2c8ef45ac 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
2017-11-27 15:36:02 +01:00
Thomas Haller
46af70b508 policy: use "agent-registered" signal directly from NMAgentManager instead of NMSettings 2017-11-27 15:21:58 +01:00
Thomas Haller
c3cae3d0dc core: use #define for "agent-registered" signal name 2017-11-27 15:21:58 +01:00
Thomas Haller
6ab0ff8a7c settings: use slice allocator for UpdateInfo data 2017-11-27 15:21:58 +01:00
Thomas Haller
f0147a9c47 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.
2017-11-27 15:21:58 +01:00
Thomas Haller
36ac08c092 policy: add nm_settings_connection_autoconnect_is_blocked() helper function 2017-11-27 15:21:58 +01:00
Thomas Haller
d8b4403f6b 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.
2017-11-27 15:21:58 +01:00
Thomas Haller
5e5121a483 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.
2017-11-27 15:21:58 +01:00
Thomas Haller
3a826a83df policy: only reset autoconnect-blocked-reason FAILED in activate_slave_connections()
The reasons no-secret and user-request still hold.
2017-11-27 15:21:58 +01:00
Thomas Haller
b154f29b2b 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.
2017-11-27 15:21:58 +01:00
Thomas Haller
8d2d9b0748 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.
2017-11-27 15:21:58 +01:00
Thomas Haller
ddb8713d44 policy: minor refactoring of device_state_changed() 2017-11-27 15:21:58 +01:00
Thomas Haller
40b534c5d8 policy: minor cleanup of loop in activate_slave_connections() 2017-11-27 15:21:58 +01:00
Thomas Haller
5fc4b32629 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.
2017-11-27 15:21:58 +01:00
Thomas Haller
af703ba990 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.
2017-11-27 15:21:58 +01:00
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