Commit graph

8896 commits

Author SHA1 Message Date
Beniamino Galvani
af4c406cea core,cli: replace wrong pattern for clearing GError
Use gs_free_error instead of gs_free.

(cherry picked from commit 65a0208ba0)
(cherry picked from commit 10ccdf4b81)
2017-06-27 09:49:15 +02:00
Thomas Haller
ca342ed61d policy: fix memleak in lookup_callback() and cancelling
When the operation is cancelled, we must not touch user_data. Note that
NM_POLICY_GET_PRIVATE() theoretically doesn't dereference the pointer
(does it?) but doing pointer arithmetic on a dangling pointer is a very
ugly thing to do.

And of course, the memleak.

Fixes: 5c716c8af8
Fixes: a2cdf63204
(cherry picked from commit 3215508293)
(cherry picked from commit f1469558c0)
2017-05-02 18:27:16 +02:00
Thomas Haller
bd72919b47 device: fix restricting Generic connection by interface-name
NMDeviceGeneric:check_connection_compatible() doesn't check for a
matching interface name. It relies on the parent implementation to
do that.

The parent implementation calls nm_manager_get_connection_iface().
That fails for NM_SETTING_GENERIC_SETTING_NAME, because that one has
no factory. Maybe this imbalance of having no factory for the Generic device
is wrong, but usually factories only match a distinct set of device
types, while the generic factory would handle them all (as last resort).

Without this, activating a generic connection might activate the
wrong interface.

(cherry picked from commit 3876b10a47)
(cherry picked from commit 753a2cc4d9)
2017-04-26 21:10:15 +02:00
Thomas Haller
4c595997f2 ifcfg: also read DEFROUTE and GATEWAY from alias files
Also accept DEFROUTE and GATEWAY when they are defined in
alias files -- provided, that they are not yet defined
in the main ifcfg file.

(cherry picked from commit 3cc00dd550)
2017-04-20 15:36:30 +02:00
Thomas Haller
be1daa4580 ifcfg: ensure ipv4.method is not "disabled" when reading IP addresses from alias files
When the main ifcfg file contains no IP addresses, the method
will be "disabled". Later, when reading IP addresses for the
aliases, we must ensure that the method is manual.

Otherwise, validation fails with

  ip.addresses: this property is not allowed for method=disabled

(cherry picked from commit a8f0d88596)
2017-04-20 15:36:25 +02:00
Dan Williams
53626395fe auth-utils: fix possibly uninitialized variables
src/nm-auth-utils.c:343:6: error: 'is_authorized' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   if (is_authorized) {
      ^
src/nm-auth-utils.c:320:11: note: 'is_authorized' was declared here
  gboolean is_authorized, is_challenge;
           ^
src/nm-auth-utils.c:346:13: error: 'is_challenge' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   } else if (is_challenge) {
             ^
src/nm-auth-utils.c:320:26: note: 'is_challenge' was declared here
  gboolean is_authorized, is_challenge;
                          ^

(cherry picked from commit 24ab2a4945)
2017-04-07 11:53:16 -05:00
Dan Williams
39d42c1774 default-route-manager: fix possibly uninitialized variable
src/nm-default-route-manager.c: In function '_ipx_update_default_route':
src/nm-default-route-manager.c:769:23: error: 'is_assumed' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    if (!default_route && !is_assumed) {
                       ^
src/nm-default-route-manager.c:763:13: note: 'is_assumed' was declared here
    gboolean is_assumed;
             ^

(cherry picked from commit 857f26dd19)
2017-04-07 11:34:07 -05:00
Thomas Haller
172f5bb2e9 default-route-manager: decryptify logging line for default-route-manager
The default route manager logs for each entry relevant information,
in a compact but cryptic way:

  default-route: entry[0/dev:0x5633d5528560:enp0s25:1:+sync]: record:add    0.0.0.0/0 via 192.168.0.1 dev 2 metric 100 mss 0 rt-src user (100)

The flag whether a route is configured or not, was only expressed
via 0|1. Change that to log instead:

  default-route: entry[0/dev:0x5633d5528560:enp0s25:+has:+sync]: record:add    0.0.0.0/0 via 192.168.0.1 dev 2 metric 100 mss 0 rt-src user (100)

(cherry picked from commit 82bfb6c46d)
2017-04-03 13:23:49 +02:00
Thomas Haller
6c7ef310b1 default-route-manager: alyways force a sync of the default route
Whenever we call update for a non-assumed, synced route, we must
force a resync with the platform. Even if according to our internal
book-keeping the route is already configured, the route may have
been removed externally. So we cannot assume that everything is
still up-to-date.

https://bugzilla.redhat.com/show_bug.cgi?id=1431268
(cherry picked from commit c3c251ea12)
2017-04-03 13:23:47 +02:00
Thomas Haller
ac515194a5 default-route-manager: use nm_cmp_uint32_p_with_data() instead of reimplementation
(cherry picked from commit 0057dc332e)
2017-04-03 13:23:45 +02:00
Thomas Haller
5e12056c9e default-route-manager: add nm_default_route_manager_resync() function
(cherry picked from commit e181956fdd)
2017-04-03 13:23:43 +02:00
Thomas Haller
27c7b786d9 default-route-manager: simplify _platform_changed_cb() handling
There is only one caller of _platform_ipx_route_changed_cb(). Inline it,
it is simpler.

(cherry picked from commit 70ab174e0e)
2017-04-03 13:23:39 +02:00
Thomas Haller
9a322b4e19 default-route-manager: simplify determining synced flag in _ipx_update_default_route()
No change in behavior at all. The same logic applies, but this should
be simpler to understand.

(cherry picked from commit 0b3ba99409)
2017-04-03 13:23:37 +02:00
Lubomir Rintel
58c9a41959 settings-connection: fix Save()
Avoid using new_settings when they are none. Also, don't shortcut when
the connection hasn't been changed -- let the settings plugin decide if
it needs to rewrite the connection.

(cherry picked from commit b47340fd3f)
2017-03-24 10:28:19 +01:00
Iain Lane
1715ec53c1 nm-manager: Use g_dbus_message_new_method_error_literal()
GLib 2.52 added a G_GNUC_PRINTF attribute to
g_dbus_message_new_method_error(). This triggered warning in
NetworkManager when built with -Wformat, which is an error when built
with -Werror=format-security. It seems that gcc isn't smart enough to
see that (foo = "bar") should be treated as a literal.

Fortunately there is a g_dbus_message_new_method_error_literal()
function which does not take printf-style arguments, and we don't need
them, so we can use that.

This patch was originally by Rico Tzschichholz <ricotz@ubuntu.com>, and
was submitted to Launchpad at

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1650972
https://bugzilla.gnome.org/show_bug.cgi?id=780444
(cherry picked from commit 6a77258f4e)
2017-03-23 13:13:16 +01:00
Dan Williams
aef9e5f8b6 ppp: only request IPV6CP when IPv6 is enabled in the connection
NM always asks pppd to run IPV6CP which will complete if the modem supports
IPv6.  If the user doesn't want IPv6 then NM just ignores the result.  But
if the host has disabled IPv6, then pppd will fail to complete the connection
because pppd tries to assign the Link-Local address to the pppX interface,
and if IPv6 is disabled that fails and terminates the PPP session.

So only request IPV6CP when the user wants IPv6 on the connection; if they
have disabled IPv6 on their host then they can simply set ipv6.method=ignore.

https://mail.gnome.org/archives/networkmanager-list/2017-March/msg00047.html
(cherry picked from commit 8d4570d28d)
2017-03-22 08:36:16 -05:00
Beniamino Galvani
427a3e5cff manager: ensure proper disposal of unrealized devices
When remove_device() is called on an already unrealized device, we
should release it from master if necessary and clear its IP
configurations to avoid leaks.

https://bugzilla.redhat.com/show_bug.cgi?id=1433303
(cherry picked from commit 2e0c3d1dac)
2017-03-21 13:30:15 +01:00
Beniamino Galvani
238fc87298 device: fail DHCPv6 if a link-local address is not present
Instead of throwing an assertion, fail DHCPv6 when a IPv6 link-local
address is not configured on the device. There are different reasons
why the assertion may fail: for example the address was removed
externally; or the device is gone (and thus the platform already
received the notification of addresses removal) but the device is still
connecting because its disposal happens in an idle callback.

None of these deserves an assertion, which should only be for
programming errors.

https://bugzilla.redhat.com/show_bug.cgi?id=1432251
(cherry picked from commit 4987ec408a)
2017-03-15 16:35:47 +01:00
Thomas Haller
5cd90717ad platform: filter out invisible links for cache lookup by name
Fixes: ad1d74d142
(cherry picked from commit f0e295d3d7)
2017-03-09 15:21:46 +01:00
Beniamino Galvani
7a05d2a228 dhcp/dhclient: parse "interface" statements
Until now any "interface" statement was ignored and any enclosed
statement for which we have a special handling was considered, even if
belonging to a different interface. This can cause wrong options to be
set in the generated dhclient configuration.

Change the code to parse "interface" statements and skip the content
if the interface doesn't match.

https://bugzilla.gnome.org/show_bug.cgi?id=778430
(cherry picked from commit d405cfd908)
2017-03-03 14:18:20 +01:00
Beniamino Galvani
f950df775f dns/resolved: consider configuration from unmanaged devices
The DNS configuration for VPN connections is associated to the VPN
device (tun, ppp, etc.) and that device can be unmanaged by NM: don't
ignore such configuration. We do the same for other DNS plugins.

https://bugzilla.gnome.org/show_bug.cgi?id=779087
(cherry picked from commit 913896721d)
2017-02-24 21:13:16 +01:00
Thomas Haller
a72ded7902 device/wifi: fix #if check for more-logging
Fixes: ae158bf178
(cherry picked from commit 35d4e8f7a0)
2017-02-19 19:16:37 +01:00
Thomas Haller
e107d0917b device/wifi: silence some logging for AP changes
We log updates of the Wi-Fi AP with a separate logging domain LOGD_WIFI_SCAN.
However, there is ony "update" message that is triggered every 6 seconds, which
becomes especially verbose.

Suppress this one and only log it when compiled --with-more-logging. And then
only log with level LOGL_TRACE, so the user still can filter this one out.

(cherry picked from commit ae158bf178)
2017-02-17 20:34:21 +01:00
Thomas Haller
f270bc34b4 device/wifi: block autoconnect while scanning is in progress
We should only start autoconnecting after the scan is complete.
Otherwise, we might activate a shared connection or pick a
connection based on an incomplete scan list.

https://bugzilla.gnome.org/show_bug.cgi?id=770938
(cherry picked from commit 2ab2254dd7)
2017-02-17 19:39:31 +01:00
Thomas Haller
4bf493fcaf device: add get_autoconnect_allowed() virtual function
It allows derived classes to override the autoconnect-allowed
state.

We already have

- NM_DEVICE_AUTOCONNECT property, which is two parts:
  - NMDevicePrivate::autoconnect_user, which is settable via
    D-Bus by the use, to allow the device to autoconnect.
  - NMDevicePrivate::autoconnect_intern, which is set by
    internal decision.
- NM_DEVICE_AUTOCONNECT_ALLOWED signal, where other devices can
  subscribe to block autoconnect. Currently that is only used
  by NMDeviceOlpcMesh.

These two make up for nm_device_autoconnect_allowed().

Add another way to allow derived classes to disable autoconnect
temporarily. This could also be achieved by having the device
subscribe to NM_DEVICE_AUTOCONNECT_ALLOWED of self, or by adding
a signal slot. But a plain function pointer seems easier.

(cherry picked from commit 6eaded9071)
2017-02-17 19:39:28 +01:00
Thomas Haller
da37c8ac6c device: separately handle NMDevice's autoconnect by user and internal decision
The NMDevice's autoconnect property is settable via D-Bus and is is
also modified by internal decision, like when no PIN is available.

Certain internal actions cause clearing the internal autoconnect flag,
but they should not override the user desicion.

For example, when NM awaks from sleep it would reenable autoconnect,
but it should not reenable it for devices where the user explicitly
said that autoconnect is to be disabled.

Similarly, activating a device alone is not yet an instruction to
re-enable autoconnect. If the user consciously disables autoconnect,
it should stay enabled. On the other hand, activating a device should
reenable autoconnect if it was blocked by internal decision.

We need to track these two flags separately, and set them accordingly.

(cherry picked from commit 2f9166e6b9)
2017-02-17 19:39:25 +01:00
Thomas Haller
b8af01b455 wifi: also show the NM D-Bus path for the Wi-Fi AP in nm_wifi_ap_to_string()
(cherry picked from commit 257484e7ba)
2017-02-17 19:39:21 +01:00
Thomas Haller
7f7bed4736 wifi: only react on AP update signal when there are actual changes
Since we emit BSS_UPDATED signal before SCAN_DONE, it is very likely
that nothing actually changed. This clutters the logs with update
messages.

Also move the added/removed logging messages inside ap_add_remove().
We would call ap_add_remove() at several places without logging the
change.

(cherry picked from commit c9dc0eba65)
2017-02-17 19:39:17 +01:00
Thomas Haller
b4fe07e96e supplicant: delay SCAN_DONE signal until all BSS are initialized
We initialize the BSS asyncronously. Don't declare SCAN_DONE
until all BSS are up.

Otherwise, especially during the very first scan we declare SCAN_DONE
when having no BSS yet. This wrongly removes the pending action
"wifi-scan", while "autoconnect" cannot happen as there are not BSS
yet. Thus we declare "startup-complete" too early.

Another issue is that we may start autoconnecting with an incomplete
scan list, and thus pick a non-preferred connections.

https://bugzilla.gnome.org/show_bug.cgi?id=777831
(cherry picked from commit e0f9677018)
2017-02-17 19:39:00 +01:00
Thomas Haller
13b17d44dc wifi: check for invalid BSSID in nm_wifi_ap_update_from_properties()
In nm_wifi_ap_new_from_properties(), we checked that the BSSID is valid
and bailed out otherwise. Since we call nm_wifi_ap_update_from_properties()
on a created BSSID, we should ensure there too that an update does not cause
the address to become invalid.

In the unlikely case where an update would change a previously valid address
to an invalid one, we would ignore the update.

Thus, move the check for addresses inside nm_wifi_ap_update_from_properties().

(cherry picked from commit e3a489180b)
2017-02-17 19:38:03 +01:00
Thomas Haller
c961c36c8f supplicant: merge NEW_BSS signal with BSS_UPDATED
Before, the NEW_BSS signal was not careful to emit the signal only when the BSS
is seen for the first time. Consequently, supplicant_iface_new_bss_cb() checked
whether it already knows about the new BSS.

Merge NEW_BSS and BSS_UPDATED. Now we emit BSS_UPDATED when either the
BSS is new or changed.

Also, in supplicant_iface_new_bss_cb() (now supplicant_iface_bss_updated_cb())
no longer constructs an @ap instance if we have a @found_ap.

In some situations there can be a value of having a separate ADD signal.
But only when there the consumers care, and if the consumers can trust that
ADD is not just an UPDATE. The only consumer doesn't care and it not not be
trusted, so merge the signals.

(cherry picked from commit 29a53b1cd7)
2017-02-17 19:38:00 +01:00
Thomas Haller
fbe98ba107 supplicant: cleanup network when cancelling "AddNetwork" request
If the assoc-request is cancelled while an "AddNetwork" request is
pending, we must cleanup the added network when the request succeeds.

The issue can also happen when NetworkManager shuts down and exits
the mainloop. This scenario is unsolved as the cleanup action
"RemoveNetwork" has no chance to run.

"AddBlob" works differently in that blogs are added with a specific name,
not like "AddNetwork", where a new D-Bus path is created. Maybe we should
also cleanup blobs that were added by us, but currently we don't.

(cherry picked from commit c47026715e)
2017-02-17 19:37:57 +01:00
Thomas Haller
a6d3d17f5e supplicant: remove unused return value from nm_supplicant_interface_request_scan()
It cannot fail, remove code that anticipates a failure of request-scan.

(cherry picked from commit dce13b6f11)
2017-02-17 19:37:55 +01:00
Thomas Haller
6ce8cf361a supplicant: use nm_clear_g_cancellable() helper
(cherry picked from commit da34034b95)
2017-02-17 19:37:52 +01:00
Thomas Haller
990810ed7c supplicant/trivial: move code around
(cherry picked from commit e16bf4f3db)
2017-02-17 19:37:17 +01:00
Thomas Haller
2735e614b7 supplicant: rework nm_supplicant_interface_set_config() to invoke result callback
Instead of having a NM_SUPPLICANT_INTERFACE_CONNECTION_ERROR signal to notify
about failures during AddNetwork/SelectNetwork, accept a callback to report
success/failure.

Thereby, rename nm_supplicant_interface_set_config() to
nm_supplicant_interface_assoc().

The async callback is guaranteed to:

 - be invoked exactly once, signalling success or failure
 - always being invoked asyncronously.

The pending request can be (synchronously) cancelled via
nm_supplicant_interface_disconnect() or by disposing the
interface instance. In those cases the callback will be invoked
too, with error code cancelled/disposing.

(cherry picked from commit 66c45d0fdc)
2017-02-17 19:37:15 +01:00
Thomas Haller
051fd25fc6 wifi: introduce enum type NMSupplicantInterfaceState instead of plain int
Also change the signature of the NM_SUPPLICANT_INTERFACE_STATE signal,
to have three "int" type arguments. Thereby also fix the subscribers
to this signal that wrongly had type guint32, instead of guint
(which happens to be the same underlying type, so no real problem).

https://mail.gnome.org/archives/networkmanager-list/2017-February/msg00021.html
(cherry picked from commit 5a03de7051)
2017-02-17 19:37:06 +01:00
Beniamino Galvani
78f2ab7cb8 dhcp: dhclient: reset the request list if conf file contains 'request'
After commit 2049e97d9e ("dhcp: refactor parsing of 'request' and
'also request' options") NM parses all the existing 'request' and
'also request' from the original configuration file and appends them
as 'also request' to avoid duplicates and conflicts.

So if the original file contains 'request x' (which means "request
only option x instead of builtin defaults"), we would translate it
into 'also request x', which appends the option to the builtin
defaults, causing duplicates in the DHCP request as dhclient seems not
smart enough to sanitize the list by itself.

To fix this, ensure that the request list is reset if the
configuration file contains a 'request'.

Fixes: 2049e97d9e

https://bugzilla.gnome.org/show_bug.cgi?id=778430
(cherry picked from commit f71e1379d6)
2017-02-14 11:37:11 +01:00
Thomas Haller
8b95169791 device/wifi: prevent clearing pending wifi scan action during inactive supplicant
<debug> [1486325858.0691] device[0x563b8fba42e0] (wlp3s0): wifi-scan: scan-done callback: successful
    <debug> [1486325858.0692] device[0x563b8fba42e0] (wlp3s0): wifi-scan: scheduled in 23 seconds (interval now 33 seconds)
    <debug> [1486325858.0692] device[0x563b8fba42e0] (wlp3s0): remove_pending_action (0): 'wifi-scan'
    <trace> [1486325858.0692] properties-changed[0x563b8fba42e0]: ignoring notification for prop has-pending-action on type NMDeviceWifi
    <debug> [1486325858.0692] manager: check_if_startup_complete returns FALSE because of enp0s25
    <info>  [1486325858.0697] device (wlp3s0): supplicant interface state: ready -> inactive
    <debug> [1486325858.0698] device[0x563b8fba42e0] (wlp3s0): wifi-scan: scanning requested
    <debug> [1486325858.0698] device[0x563b8fba42e0] (wlp3s0): wifi-scan: (0) probe scanning SSID <hidden>
    <debug> [1486325858.0698] device[0x563b8fba42e0] (wlp3s0): wifi-scan: (1) probe scanning SSID "aaa"
    <trace> [1486325858.0699] device[0x563b8fba42e0] (wlp3s0): set-hw-addr: no MAC address change needed (2A:71:5D:54:85:1F)
    <debug> [1486325858.0699] device[0x563b8fba42e0] (wlp3s0): add_pending_action (1): 'wifi-scan'

(cherry picked from commit 94127d3f9e)
2017-02-10 14:47:18 +01:00
Thomas Haller
29b6ba0cd4 device/wifi: don't emit wrong SCAN_DONE signal when "Scan" request completes
scan_request_cb() handles the answer from the D-Bus "Scan" method.
At that point, the scan is not yet done, it merely started. It is
wrong to already signal SCAN_DONE.

The only place where we want to signal SCAN_DONE is when we actually
receive the "ScanDone" D-Bus signal.

(cherry picked from commit 75356841fb)
2017-02-10 14:47:18 +01:00
Thomas Haller
9977609b7a device/wifi: first emit NEW_BSS signals before SCAN_DONE
In the SCAN_DONE handler, NMDeviceWifi resets the flag that indicates
that a current scan request is pending. We need to first obtain the
new APs (NEW_BSS) before signalling SCAN_DONE.

(cherry picked from commit 40a4cc5b2d)
2017-02-10 14:47:18 +01:00
Thomas Haller
442ea0348d device/wifi: don't reschedule idle handler for schedule_ap_list_dump()
(cherry picked from commit e4a9942ba8)
2017-02-10 14:47:18 +01:00
Thomas Haller
f9c95bdd23 device/wifi: cache GObject property "scanning"
Cache the value for accessing the GObject property
NM_DEVICE_WIFI_SCANNING.

Re-evaluating the property every time by checking the
supplicant interface is ugly because it might change
under the hood. It should only change if (and only if)
we emit a notify changed signal.

Also, avoid accessing
  nm_supplicant_interface_get_scanning (priv->sup_iface)
without checking whether priv->sup_iface is not NULL.

(cherry picked from commit 4e84472b47)
2017-02-10 14:47:18 +01:00
Thomas Haller
a57a1940c2 device/wifi/trivial: reorder code in "nm-device-wifi.c"
(cherry picked from commit 1b7f03d1a5)
2017-02-10 14:47:18 +01:00
Thomas Haller
b8f3039d87 device/wifi: give wifi-scan related logging message common prefix
Add a prefix "wifi-scan: " to related logging messages for easier searching
the logfiles.

(cherry picked from commit a2798c18b6)
2017-02-10 14:47:18 +01:00
Thomas Haller
023bceb41c device/wifi: ensure consistent timestamp for dumping Wi-Fi AP
When we dump a list of APs, determine one timestamp for "now",
instead of re-evaluating it every time.

This ensures that all APs are printed with the same understanding
of the current timestamp.

(cherry picked from commit 5e4d13271c)
2017-02-10 14:47:18 +01:00
Thomas Haller
1272f3cc04 device/wifi: log scanning related messages with LOGD_WIFI instead of LOGD_WIFI_SCAN
LOGD_WIFI_SCAN is there to avoid flodding the log with continous scan
results. It should not be used for messages related to scheduling scan
requests.

This is especially important, because LOGD_WIFI_SCAN domain is not
included in LOGD_DEFAULT.

(cherry picked from commit d5657d003c)
2017-02-10 14:47:18 +01:00
Thomas Haller
36196b5a82 device/wifi: refactor logging of Wi-Fi AP by preserving logging context of device
The _LOGD() macros of NMDeviceWifi print a logging context for each
line, that is, they add a prefix with the device name.

Replace nm_wifi_ap_dump() by nm_wifi_ap_to_string() and let device
log a message about the AP.

Also, update the format for printing the AP. Now, all fields are
separated by space.

(cherry picked from commit d98fa31ddd)
2017-02-10 14:47:18 +01:00
Thomas Haller
8b455abab2 device: cleanup handling queued state change in NMDevice
- no longer bother clearing .state and .reason when the .id
  field is unset. The fields just don't matter and no user
  accesses these fields when the glib source id is not set.
- unify logging and give them all a prefix "queue-state[%s, %s, %u]: ".
- drop nm_device_queued_state_peek(), it only had one caller,
  thus inline the trivial check.
- make nm_device_queued_state_clear() a static function
  queued_state_clear()
- rename queued_set_state() to queued_state_set().

(cherry picked from commit 96b167cd97)
2017-02-10 14:47:18 +01:00
Thomas Haller
57111e356d device/trivial: reorder defines in "nm-device.c"
Reorder code to be like in other source files:
- first includes and generic defines
- then various helper structs
- then GObject related declarations, with first signal and property
  enums, then the private data, then the G_DEFINE_TYPE() itself.
- finally, forward declarations for functions.

(cherry picked from commit f97d8b86fb)
2017-02-10 14:47:18 +01:00