Commit graph

9303 commits

Author SHA1 Message Date
Beniamino Galvani
b72b8ef34c connectivity: fix memory leak
Fixes: 9d43869e47
(cherry picked from commit 7204472de5)
2017-07-19 22:16:46 +02:00
Beniamino Galvani
e80163c713 dns: perform the public-suffix check only for the hostname-derived domain
The DNS manager drops from the search list domains that are public
suffixes to prevent a possible domain hijack when using two-labels
hostnames [1].

This is a problem now that every single-label domain can be a TLD
since this means that such domains can't be used in the search list.

While it's useful to apply such restriction to the domain
automatically derived from the system hostname, it seems wrong to drop
domains specified by users in the configuration or provided by DHCP.

This commit keeps the public-suffix check only for the
hostname-derived domain

[1] https://bugzilla.redhat.com/show_bug.cgi?id=812394

https://bugzilla.redhat.com/show_bug.cgi?id=1404350
(cherry picked from commit 5aa22ed8c9)
2017-07-17 17:04:28 +02:00
Thomas Haller
beeb8df9ac dhcp/tests: add test parsing dhclient config
(cherry picked from commit 0c23191b01)
2017-07-10 11:55:54 +02:00
Jonathan Kang
7200906a62 dhcp/dhclient: improve "interface" statement parsing
In commit d405cfd908, parsing "interface"
statement is introduced. But it leads to uncommplete parsing of the
"request" entry, if one of the lines in "request" entry is prefixed with
word "interface". For example, the default configuration of openSUSE
distribution:

request subnet-mask, broadcast-address, routers,
	rfc3442-classless-static-routes,
	interface-mtu, host-name, domain-name, domain-search,
	domain-name-servers, nis-domain, nis-servers,
	nds-context, nds-servers, nds-tree-name,
	netbios-name-servers, netbios-dd-server,
	netbios-node-type, netbios-scope, ntp-servers;

Fixes: d405cfd908

https://bugzilla.opensuse.org/show_bug.cgi?id=1047004
https://mail.gnome.org/archives/networkmanager-list/2017-July/msg00015.html
(cherry picked from commit 3646ed083d)
2017-07-10 11:55:52 +02:00
Lubomir Rintel
61b1ab2fcd ifcfg: drop an unused variable
(cherry picked from commit 0d71c0569f)
2017-07-07 13:44:30 +02:00
Beniamino Galvani
75fb2897d7 checkpoint: disconnect device before reactivation during rollback
Since commit 0922a17738 ("manager: avoid that auto-activations
preempt user activations") the manager doesn't allow a internal
activation to disconnect the same connection already active on the
device.  Thus, during a rollback we must ensure that the device is
deactivated before.

Fixes: 0922a17738
(cherry picked from commit 348959cfa2)
2017-07-05 11:19:55 +02:00
Beniamino Galvani
10ccdf4b81 core,cli: replace wrong pattern for clearing GError
Use gs_free_error instead of gs_free.

(cherry picked from commit 65a0208ba0)
2017-06-27 09:46:09 +02:00
Beniamino Galvani
4b21a00ae2 bond: ignore miimon option only when it is zero
The default value for miimon, when missing in the setting, is 0 if
arp_interval is != 0, and 100 otherwise. So, when generating a
connection, let's ignore miimon=0 (which means that miimon is
disabled) and accept any other value. Adding miimon=100 does not cause
any harm to the connection assumption.

While at it, slightly improve the code: ignore_if_zero() is not useful
for 'updelay','downdelay','arp_interval' because zero is their default
value, so introduce a new function that checks if the value is the
default (and specially handles 'miimon').

Reported-by: Taketo Kabe <rkabe@vega.pgw.jp>

https://bugzilla.redhat.com/show_bug.cgi?id=1463077
(cherry picked from commit 92fc109183)
2017-06-23 11:28:15 +02:00
Francesco Giudici
cf726a51b9 manager: when a connection is upped on a device, do an early update of its internal state
When a user forces up a connection on a device, mark earlier the
device as managed: this would allow proper clean-up on the device also
when it was previously unmanaged or assumed.
This would avoid skipping IPv6LL address generation when instead it was
needed.

Fixes: adbf383628

https://bugzilla.redhat.com/show_bug.cgi?id=1452046
(cherry picked from commit d4a033c4ad)
2017-06-21 16:15:59 +02:00
Beniamino Galvani
2236c3c728 manager: avoid that auto-activations preempt user activations
In _internal_activate_device(), we try to find an existing master AC
for the slave AC, and we create a new one in case of failure. The
master AC may already exist, but it may not be detected by
find_master() because it is undergoing authorization.

The result is that we auto-activate the master when there is already a
user activation in place, and the auto-activation will cancel the user
one. This is bad, as user-activation should always have precedence.

To fix this, introduce a last-minute check before activating internal
connections.

https://bugzilla.redhat.com/show_bug.cgi?id=1450219
(cherry picked from commit 0922a17738)
2017-06-19 16:00:57 +02:00
Thomas Haller
24f4caebec dns: don't clone DNS configs list for nm_dns_plugin_update()
No need to clone the list anymore. Unfortunately, GPtrArray is not NULL
terminated (without extra effort), so we have to pass on the GPtrArray
instance for the length.

(cherry picked from commit 19a98c6f61)
2017-06-19 15:15:49 +02:00
Thomas Haller
4c81a447cc dns: fix negative ipv4.dns-priority for systemd-resolved
A negative ipv4.dns-priority and ipv6.dns-priority has the meaning to configure
the DNS information of the connection exclusively. With systemd-resolved, that means
we must explicitly unset the configuration from other interfaces.

https://bugzilla.gnome.org/show_bug.cgi?id=783569
(cherry picked from commit 70792e51d9)
2017-06-19 15:15:49 +02:00
Thomas Haller
6ac67655be dns: make configs argument to update a const pointer
(cherry picked from commit d582176939)
2017-06-19 15:15:49 +02:00
Thomas Haller
08d8b38a81 dns/systemd: remove unused device lookup in add_interface_configuration()
(cherry picked from commit 1c9285b06e)
2017-06-19 15:15:49 +02:00
Thomas Haller
8887970713 dns: add helper method to get DNS priority from NMDnsIPConfigData
(cherry picked from commit c818e46d48)
2017-06-19 15:15:49 +02:00
Thomas Haller
c464e111a4 dns: minor refactoring in _collect_resolv_conf_data()
The code was correct previously, but it was confusing to me,
because

  - once @skip gets set to TRUE, it stays TRUE for the rest
    of the loop.
  - in each additional skipped iteration, it would still set
    plugin_confs[i] to NULL. Which is not wrong, but confusing.
  - it would set "prev_prio = prio;" in each iteration.
    After @skip is set to TRUE, that doesn't matter anymore,
    but is confusing. Before @skip is set to TRUE it also
    doesn't really matter to set it more then once, because
    we only care about the very first priority.
  - @skip sounded to me like the current iteration would
    be skipped. But really all remaining will be skipped too.

(cherry picked from commit aa347182bb)
2017-06-19 15:15:49 +02:00
Thomas Haller
368c7329f8 device: fix taking over device after modifying external connection
For externally managed interfaces, we create an in-memory connection
and keep the device with sys-iface-state=external.

When the user actively modifies the connection, we persist it to
storage. But we also must take over managing the device.

One problem is that nm_device_reapply() errors out if the device
is still activating. It's unclear how to reapply the connection
while the device is in the process of activation. So, if the user
modifies the created connection very quickly, reapplying the settings
will fail.

https://bugzilla.redhat.com/show_bug.cgi?id=1462223
(cherry picked from commit 10c0632df0)
2017-06-19 15:02:11 +02:00
Thomas Haller
08c58c759a core: fix registering notify-flags hook in NMActiveConnection
We react on changes to NMSettingsConnection.flags, so that we can update
from an external activation to a managed one.

However, previously we would only register the _settings_connection_notify_flags
callback during _set_settings_connection(). So, if via constructor properties
we first set PROP_SETTINGS_CONNECTION and later PROP_ACTIVATION_TYPE, we wouldn't
register the callback.

(cherry picked from commit b84da25713)
2017-06-19 15:02:11 +02:00
Thomas Haller
653ba8b759 core: log changes to NMSettingsConnection's flags
(cherry picked from commit 2656ba8d1d)
2017-06-19 15:02:11 +02:00
Beniamino Galvani
9819ffe7d4 core: sort addresses in captured IPv4 configuration
When IPv4 addresses are synchronized to platform, the order of IPv4
addresses matters because the first address is considered the primary
one. Thus, nm_ip4_config_capture() should put the primary address as
first, otherwise during synchronization addresses will be removed and
added back with a different primary/secondary role.

https://bugzilla.redhat.com/show_bug.cgi?id=1459813
(cherry picked from commit b6fa87a4c0)
2017-06-13 23:36:07 +02:00
Thomas Haller
588841f2e0 device: don't set MTU of device unless explicitly configured
Since commit 2b51d3967 "device: merge branch 'th/device-mtu-bgo777251'",
we always set the MTU for certain device types during activation. Even
if the MTU is neither specified via the connection nor other means, like
DHCP.

Revert that change. On activation, if nothing explicitly configures the
MTU, leave it unchanged. This is like what we do with ethernet's
cloned-mac-address, which has a default value "preserve".
So, as last resort the default value for MTU is now 0 (don't change),
instead of depending on the device type.

Note that you also can override the default value in global
configuration via NetworkManager.conf.

This behavior makes sense, because whenever NM actively resets the MTU,
it remembers the previous value and restores it when deactivating
the connection. That wasn't implemented before 2b51d3967, and the
MTU would depend on which connection was previously active. That
is no longer an issue as the MTU gets reset when deactivating.

https://bugzilla.redhat.com/show_bug.cgi?id=1460760
(cherry picked from commit 4ca3002b86)
2017-06-13 15:27:21 +02:00
Thomas Haller
1b954fe09b ppp: fix cancelling timeout when pppd process exits
Otherwise, we get pppd_timed_out() later, which will
emit a DEAD state change at unexpected times.

(cherry picked from commit b9af32b056)
2017-06-09 16:16:42 +02:00
Thomas Haller
b87327a5fe ppp: cleanup logging pppd exit reason in ppp_watch_cb
- don't use assert but be more graceful with g_return_if_fail().
- in case of failure, don't log a debug message after the warning.
  One message is sufficient, drop "pppd pid %d cleaned up".
- print GPid type as long long.
- increase log level to warning. pppd dying unexpectedly warrants a
  warning.

(cherry picked from commit 250e723951)
2017-06-09 16:16:42 +02:00
Thomas Haller
38b5d356de ppp: don't log newlines
(cherry picked from commit a814b96ebf)
2017-06-09 16:16:42 +02:00
Thomas Haller
ccda61b6fc ppp: refactor ppp_exit_code() to split out error to string conversion
ppp_exit_code() does too much or too little. Either it should log
about all reasons why pppd exited, including signals, or it should
just do the status to string conversion. Split it.

(cherry picked from commit 3f64910b52)
2017-06-09 16:16:42 +02:00
Thomas Haller
105ef99cbf ppp/trivial: fix whitespace
(cherry picked from commit 5c5fbe0a9f)
2017-06-09 16:16:42 +02:00
Thomas Haller
620adbcc7b ppp: inline and drop trivial function remove_timeout_handler()
(cherry picked from commit 0f16649ba2)
2017-06-09 16:16:42 +02:00
Thomas Haller
5e656b5872 ppp: unexport NMPPPManager instance on dispose()
Let's explicitly unexports on dispose(). Probably that already
happened, because NMExportedObject asserts that it is unexported
during !quitting.

During quitting, we probably don't tear down the manager.

Anyway, we should always unexport.

(cherry picked from commit f07dca941d)
2017-06-09 16:16:39 +02:00
Thomas Haller
2aa4239cba ppp: cast int argument for variadic g_signal_emit(NM_PPP_MANAGER_STATE_CHANGE) call
(cherry picked from commit 7b5251b35c)
2017-06-09 16:16:39 +02:00
Beniamino Galvani
6a4774b1a8 device: apply route metric penality only when the default route exists
It's useless (and in some cases also harmful) to commit the
configuration to update the default route metric when the device has
no default route. Also, don't commit configuration for externally
activated devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1459604
(cherry picked from commit aa099906f9)
2017-06-09 13:54:04 +02:00
Thomas Haller
78ff06c539 device: suppress logging and return error reason from nm_device_generate_connection()
Don't log in a function that basically just inspects state, without
mutating it. Instead, pass the reason why a connection could not be
generated to the caller so that we have one sensible log message.

(cherry picked from commit 0c26ffd638)
2017-06-08 22:02:13 +02:00
Thomas Haller
70b4684d7e manager: cleanup logging message during recheck_assume_connection()/get_existing_connection()
recheck_assume_connection() calls get_existing_connection(). We want *one* logging
message telling what's happening. Let get_existing_connection() log "assume:"
messages and remove duplicate messages from recheck_assume_connection().

(cherry picked from commit 962f8f42d9)
2017-06-08 22:01:19 +02:00
Thomas Haller
c254277f40 device: remove logging for emitting RECHECK_ASSUME signal
The device's RECHECK_ASSUME signal has only NMManager as subscriber
and it immediately calls recheck_assume_connection().

With the previous commit, recheck_assume_connection() always logs
a debug message, so we don't need this duplicate message anymore.

(cherry picked from commit cc47a6a8b2)
2017-06-08 22:01:19 +02:00
Thomas Haller
7e2d64a8b2 manager: add more logging to recheck_assume_connection()
and give all lines a logging prefix.

(cherry picked from commit 94534e0327)
2017-06-08 22:01:19 +02:00
Thomas Haller
01fd9df6e5 manager: add "rfkill" prefix to related logging messages
(cherry picked from commit dd53c879d2)
2017-06-08 22:01:19 +02:00
Thomas Haller
36b99ccf5f manager: add logging macro _NMLOG3() for logging connection messages
It unifies the way how we print the logging prefix, but also it
passes the con_uuid down for structured logging.

(cherry picked from commit 6962f14d4a)
2017-06-08 22:01:19 +02:00
Thomas Haller
22bf75162d manager: add logging macro _NMLOG2() for logging device messages
It unifies the way how we print the logging prefix, but also it
passes the ifname down for structured logging.

(cherry picked from commit 1f6078bcf5)
2017-06-08 22:01:19 +02:00
Thomas Haller
c5812a5fb9 logging: add LOG3 macros
(cherry picked from commit 2ae891b592)
2017-06-08 22:01:19 +02:00
Thomas Haller
e0b7a44062 device: expose nm_device_state_to_str() function for NMDeviceState
(cherry picked from commit 4b15df2656)
2017-06-08 22:01:16 +02:00
Thomas Haller
60ce882419 device: rework device's _NMLOG() logging macro
- if the interface-name is NULL, print [null], to distinguish
  it from (ifname).
- evaluate the ifname only once.

(cherry picked from commit f10b958806)
2017-06-08 22:00:56 +02:00
Thomas Haller
06db38b91d manager: fix preserving assume state during activation
Originally 850c977 "device: track system interface state in NMDevice",
intended that a connection can only be assumed initially when seeing
a device for the first time. Assuming a connection later was to be
prevented by setting device's sys-iface-state to MANAGED.

That changed too much in behavior, because we used to assume external
connections also when they are activated later on. So this was attempted
to get fixed by
  - acf1067 nm-manager: try assuming connections on managed devices
  - b6b7d90 manager: avoid generating in memory connections during startup for managed devices

It's probably just wrong to prevent assuming connections based on the
sys-iface-state. So drop the check for sys-iface-state from
recheck_assume_connection(). Now, we can assume anytime on managed,
disconnected interfaces, like previously.
Btw, note that priv->startup is totally wrong to check there, because
priv->startup has the sole purpose of tracking startup-complete property.
Startup, as far as NMManager is concerned, is platform_query_devices().

However, the problem is that we only assume connections (contrary to
doing external activation) when we have a connection-uuid from the state
file or with guess-assume during startup.

When assuming a master device, it can fail with

  (nm-bond): ignoring generated connection (IPv6LL-only and not in master-slave relationship)

thus, for internal reason the device cannot be assumed yet.

Fix that by attatching the assume-state to the device, so that on multiple
recheck_assume_connection() calls we still try to assume. Whenever we try
to assume the connection and it fails due to external reasons (like, the connection
no longer matching), we clear the assume state, so that we only try as
long as there are internal reasons why assuming fails.

https://bugzilla.redhat.com/show_bug.cgi?id=1452062
(cherry picked from commit 729de7d7f0)
2017-06-08 22:00:56 +02:00
Thomas Haller
122be86c58 core: allow assuming connections on "nm-owned" software devices
Especially now we load the nm-owned flag from run-state. We very much want to
assume connections on such devices.

(cherry picked from commit 6a7b51f79b)
2017-06-08 22:00:56 +02:00
Thomas Haller
8e25de8ab3 device: only set nm-owned from statefile during initial setup
The state file should only be read initially when NM starts, that is:
during NMManager's platform_query_devices().

At all later points, for example when a software device gets destroyed
and re-realized, the state file is clearly no longer relevant.

Hence, pass the set-nm-owned flag from NMManager to realize_start_setup().

This is very much the same as with the NM_UNMANAGED_FLAG_USER_EXPLICT flag,
which we also read from the state-file.

(cherry picked from commit d83848be9d)
2017-06-08 22:00:56 +02:00
Beniamino Galvani
333ed6ee2a manager: restore the previous persistent nm-owned state of devices
After a daemon restart, any software device is considered !nm-owned,
even if it was created by NM. Therefore, a device stays around even if
the connection which created it gets deactivated or deleted.

Fix this by remembering the previous nm-owned state in the device
state file.

https://bugzilla.redhat.com/show_bug.cgi?id=1376199
(cherry picked from commit cf9ba271e6)
2017-06-08 21:57:36 +02:00
Beniamino Galvani
a42f3b92b7 config: allow persisting the device nm-owned state
(cherry picked from commit 3fbbbb62f0)
2017-06-08 21:57:36 +02:00
Beniamino Galvani
84273a3516 device: rename priv->is_nm_owned to priv->nm_owned
Only a matter of taste, but nm_device_get_is_nm_owned() sounds
strange.

(cherry picked from commit 8cce037bf8)
2017-06-08 21:57:36 +02:00
Beniamino Galvani
dc1c8c22cc device: check connectivity on the IP interface
curl must bind to the interface that has IP configuration, not the
underlying device. Without this commit, connectivity check fails on
certain connection types (PPPoE, WWAN).

Fixes: 9d43869e47
(cherry picked from commit c66995ad4d)
2017-06-08 11:23:07 +02:00
Beniamino Galvani
a3a792dd22 bond: check for NULL bond mode value in update_connection()
Don't crash if the bond mode can't be read from sysfs - for example
when the interface disappears. The generated connection will be bogus,
but at that point it doesn't matter because the in-memory connection
will be destroyed.

Fixes: 056a973a4f

https://bugzilla.redhat.com/show_bug.cgi?id=1459580
(cherry picked from commit 5600a27c2a)
2017-06-08 09:45:50 +02:00
Thomas Haller
fcbcd1aa87 device: mark device as sys-iface-state=external when assuming connection
Since commit 74dac5f (nm-manager: try assuming connections on managed devices),
and commit f4226e7 (manager: avoid generating in memory connections
during startup for managed devices), recheck_assume_connection() also
assumes connections on devices that are currently not in sys-iface-state
"external".

That is correct, as also for fully managed devices (which are currently
in disconnected state), we want to assume external connections. However,
when doing that, we must reset the sys-iface-state to external.

https://bugzilla.redhat.com/show_bug.cgi?id=1457242
(cherry picked from commit 02e7476e9f)
2017-06-05 18:31:31 +02:00
Beniamino Galvani
61817661c8 bond: add only supported options to the generated connection
Upstream commit [1] changed in the kernel the default value of
tlb_dynamic_lb bond from 1 to 0 when the mode is not tlb. This is not
wrong, as the option value doesn't really matter for other modes, but
it breaks the connection matching because we read back a 0 value when
we expect a default of 1.

Fix this in a generic way by ignoring altogether options that are not
relevant for the current bond mode, because they are removed from the
connection during normalization.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8b426dc54cf4056984bab7dfa48c92ee79a46434

https://bugzilla.redhat.com/show_bug.cgi?id=1457909
(cherry picked from commit 056a973a4f)
2017-06-05 17:54:11 +02:00