Commit graph

1760 commits

Author SHA1 Message Date
Thomas Haller
c8934fbe0d device: remove macro for logging in _set_unmanaged_flags()
The macro is used exactly once. It's simpler to just write the
logging statement down as is.
2017-03-15 10:33:44 +01:00
Thomas Haller
6845b9b80a device: delay startup complete until device is initialized in platform
Udev may be slow at startup and it may take a while until the
device is visible in udev. Before that, there are no pending
actions yet because the device is still in unmanaged state.

Hack nm_device_has_pending_action() to indicate a pending action
when the platform link is not yet initialized.
We don't bother using nm_device_add_pending_action() to schedule
a proper pending-action. It is simpler this way, also we precisely
log about the state of NM_UNMANAGED_PLATFORM_INIT flag. The pending
actions are implemented in their way mostly for logging purpose to
understand what blocks a device. For NM_UNMANAGED_PLATFORM_INIT we
have sufficient logging so no need for the overhead and effort.

https://bugzilla.gnome.org/show_bug.cgi?id=779920
2017-03-15 10:33:44 +01:00
Thomas Haller
22b7282d84 all: use "unsigned" instead of "unsigned int" 2017-03-14 11:26:29 +01:00
Thomas Haller
b1eeb00937 all: use "unsigned long" instead of "long unsigned" 2017-03-14 11:23:46 +01:00
Thomas Haller
85468e39f1 device: clear deactivating_cancellable in dispose()
It is most likely not needed. Add it just to be sure.
2017-03-13 12:03:48 +01:00
Thomas Haller
ec2681d4db all: use nm_clear_g_cancellable() 2017-03-13 12:00:23 +01:00
Beniamino Galvani
c4ca123a4a device: reapply proxy configuration
In order to support a reapply of proxy configuration, remember the PAC
URL received through DHCP and merge it again with configuration from
proxy setting on reapply.
2017-03-09 21:58:28 +01:00
Beniamino Galvani
ad3fdcd90d device: allow reapply of MTU
The MTU is reapplied together with IP configuration: modify device
subclasses to announce they support the property in
can_reapply_change().
2017-03-09 21:58:28 +01:00
Beniamino Galvani
9cc9ce4bfa device: reapply connection.lldp property 2017-03-09 21:58:28 +01:00
Beniamino Galvani
3f5f5ed4eb device: ethernet: reapply link speed and wol settings 2017-03-09 21:58:28 +01:00
Thomas Haller
831286df30 include: use double-quotes to include our own headers
In practice, this should only matter when there are multiple
header files with the same name. That is something we try
to avoid already, by giving headers a distinct name.

When building NetworkManager itself, we clearly want to use
double-quotes for including our own headers.
But we also want to do that in our public headers. For example:

  ./a.c
    #include <stdio.h>
    #include <nm-1.h>
    void main() {
        printf ("INCLUDED %s/nm-2.h\n", SYMB);
    }

  ./1/nm-1.h
    #include <nm-2.h>

  ./1/nm-2.h
    #define SYMB "1"

  ./2/nm-2.h
    #define SYMB "2"

$ cc -I./2 -I./1 ./a.c
$ ./a.out
INCLUDED 2/nm-2.h

Exceptions to this are
  - headers in "shared/nm-utils" that include <NetworkManager.h>. These
    headers are copied into projects and hence used like headers owned by
    those projects.
  - examples/C
2017-03-09 14:12:35 +01:00
Beniamino Galvani
afd1bde366 device: ip-tunnel: free strings on dispose
Fixes: 570fdce93f
2017-03-09 12:05:59 +01:00
Thomas Haller
ab6e370195 all/trivial: unify construct-only property comments
Unify marking GObject properties that are G_PARAM_CONSTRUCT_ONLY
with a comment

    /* construct-only */
2017-03-08 13:47:00 +01:00
Beniamino Galvani
2eeb13d81e device: add check for NULL connection diff in check_and_reapply_connection()
Fixes: 592b211bcc
2017-03-07 09:57:45 +01:00
Beniamino Galvani
592b211bcc device: add list of changed properties to reapply audit log 2017-03-06 10:29:38 +01:00
Beniamino Galvani
2d26cce9c2 audit: add @args to device logging functions 2017-03-06 10:29:37 +01:00
Beniamino Galvani
1ba25fd19f device: bond: implement connection reapply
Only a couple of bond options (active_slave, primary) are supported at
for now.
2017-03-06 10:29:37 +01:00
Beniamino Galvani
86388f41b8 device: introduce class methods for connection reapply
Add two new methods can_reapply_change() and reapply_connection() to
the device class. In this way device subclasses can declare that they
support the changes in a given setting and take care of reapplying it.
2017-03-06 10:29:37 +01:00
Beniamino Galvani
8922f9aabe device: internally export nm_device_hash_check_invalid_keys() 2017-03-06 10:29:16 +01:00
Beniamino Galvani
8eb49639fc bond: set the active slave only after enslavement
The kernel doesn't accept an interface to be set as active_slave until
the interface is enslaved to the bond. Delay the initialization of the
property.
2017-03-06 10:29:16 +01:00
Thomas Haller
72bfe62a9a all: use stack-allocated uuid at various places
No need to create a UUID on the heap in this case.
2017-03-02 12:14:29 +01:00
Thomas Haller
405ee7cad0 device: mark uses of device's state-reason with nm_device_state_reason_check()
The state-change of a device has a reason argument, which is mostly for information
only.

There are many places in code that are the source of a state-reason.
Mostly these are calls to:
  - nm_device_state_changed()
  - nm_device_queue_state()
  - nm_device_queue_recheck_available()
  - nm_device_set_unmanaged_by_*()
  - nm_device_master_release_one_slave()
  - nm_device_ip_method_failed()
  - nm_modem_emit_prepare_result()
  - nm_modem_emit_ppp_failed()
  - nm_manager_deactivate_connection()
  - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_*);

However, there are a few places in code that look at the reason
to decide how to proceed. I think this is a bad pattern, because
cause and effect are decoupled and it gets hard to understand where
a certain reason is set and what consequences that has.

Add a nop-function nm_device_state_reason_check() to mark all uses
of the device state reason that derive decisions from it. That is,
highlight the "effect" part.
2017-02-23 17:07:28 +01:00
Thomas Haller
71a22df337 settings: refactor autoconnect-blocked-reason to use own enum
Don't reuse NMDeviceStateReason for the autoconnect-blocked-reason. There are
only two cases we care: blocked-due-to-no-secrets, blocked-otherwise.

Encode these values in a new enum type.
2017-02-23 17:00:09 +01:00
Thomas Haller
9a64168c87 all: use "static inline" keywords instead of "inline static"
Use a consistent order of "static inline". This seems the prefered
order in general, and we also use it more often already.
2017-02-23 15:28:27 +01:00
Thomas Haller
8e12396b74 modem: remove unused reason argument from nm_modem_device_state_changed()
The reason has pecular meanings during a device state change.
Let's remove the unused reason argument to reduce the noise.
2017-02-23 14:42:36 +01:00
Thomas Haller
434e7b2aa3 modem: cleanup integer types for ppp-stats signal
In practice, guint32 is identical to guint. However, that is not
guaranteed, and we should keep the types separate.
2017-02-23 12:33:41 +01:00
Thomas Haller
20b17910d0 modem: add nm_modem_emit_ppp_failed() function
... instead of emitting the signal by name.
2017-02-23 12:33:41 +01:00
Thomas Haller
0a1fd88d5a modem: add nm_modem_emit_prepare_result() function
... instead of emitting the signal by name. For one,
we get the casting of the NMDeviceStateReason enum right.
Also, emitting by the guint signal-id is faster then
emitting by name.
2017-02-23 12:33:41 +01:00
Thomas Haller
9a8f8e8a89 modem: remove unused variadic argument when emitting NM_MODEM_STATE_CHANGED signal
The signal only has two arguments, no reason.
2017-02-23 12:33:41 +01:00
Thomas Haller
42f60e30ad modem: emit signal NM_MODEM_AUTH_REQUESTED by id not name 2017-02-23 12:20:19 +01:00
Thomas Haller
6c8eac1a4c modem: use defines for signal names 2017-02-23 12:20:13 +01:00
Beniamino Galvani
9dac51d9c0 team: support the ethernet.cloned-mac-address property
The only reliable way of setting a MAC address for the team is through
the "hwaddr" property in the configuration passed to teamd. In order
to rewrite the configuration we need Jansson support; since it is
already a requirement for teamd, let the team plugin depend on it.
2017-02-23 10:07:06 +01:00
Beniamino Galvani
029a0a21ea device: split out cloned MAC decision from nm_device_hw_addr_set_cloned()
In this way, we can query the final cloned address (after special
values as 'random', 'stable', etc. have been evaluated) from
subclasses.
2017-02-23 10:05:48 +01:00
Thomas Haller
5d336aa1ed device: rename reason argument for NMDeviceDummy
And remove assertion for out-argument to be present.

Follow-up to commit 437c12fc89.
2017-02-22 21:47:12 +01:00
Thomas Haller
8b7d38c8c5 device: remove out-reason argument from device's set-ip-config
The out-reason is only set to NM_DEVICE_STATE_REASON_CONFIG_FAILED.
And there is only one caller who cares about the reason.

If we one day decide to return a more distinguished error reasons,
we can revert this patch. Until then, drop the code.
2017-02-22 21:43:04 +01:00
Thomas Haller
437c12fc89 device: rename device-state-reason argument to out_failure_reason
This argument is only relevant when the NMActStageReturn argument
indicates NM_ACT_STAGE_RETURN_FAILURE. In all other cases it is ignored.

Rename the argument to make the meaning clearer. The argument is passed
through several layers of code, it isn't obvious that this argument only
matters for the failure case. Also, the distinct name makes it easier
to distinguish from other uses of the "reason" name.

While at it, do some drive-by cleanup:

  - use g_return_*() instead of g_assert() to have a more graceful
    assertion.
  - functions like dhcp4_start() don't need to return a failure reason.
    Most callers don't care, and the caller who does can determine the
    proper reason.
  - allow omitting the out-argument via NM_SET_OUT().
2017-02-22 21:37:47 +01:00
Beniamino Galvani
b42f780e04 core: add support for dummy devices
Add support for creating dummy devices. This commit adds a D-Bus
interface 'org.freedesktop.NetworkManager.Device.Dummy' which is used
primarily for determining the device type but does not carry any
properties.
2017-02-22 21:05:04 +01:00
Thomas Haller
f93fbc76ec device: avoid assertion in nm_device_get_supplicant_timeout() for Wi-Fi connection
... without 802-1x setting.

    NetworkManager[27913]: <trace> [1487689965.7156] device[0x555555bc0060] (wlp3s0): powersave is set to 3
    NetworkManager[27913]: <info>  [1487689965.7156] Config: added 'ssid' value 'xxx'
    NetworkManager[27913]: <info>  [1487689965.7156] Config: added 'scan_ssid' value '1'
    NetworkManager[27913]: <info>  [1487689965.7156] Config: added 'bssid' value 'xxx'
    NetworkManager[27913]: <info>  [1487689965.7157] Config: added 'key_mgmt' value 'WPA-PSK'
    NetworkManager[27913]: <info>  [1487689965.7157] Config: added 'psk' value '<hidden>'
    NetworkManager[27913]: <debug> [1487689965.7157] sup-iface[0x555555be0010,wlp3s0]: assoc[0x555555ebd800]: starting association...
    NetworkManager[27913]: nm_device_get_supplicant_timeout: assertion 's_8021x' failed

    (gdb) bt
    ...
    #3  0x00007ffff4c70419 in g_return_if_fail_warning (log_domain=log_domain@entry=0x55555577610e "NetworkManager", pretty_function=pretty_function@entry=0x5555557725e0 <__func__.44436> "nm_device_get_supplicant_timeout", expression=expression@entry=0x5555557725bb "s_8021x") at gmessages.c:2536
    #4  0x000055555568af3a in nm_device_get_supplicant_timeout (self=0x555555bc0060 [NMDeviceWifi]) at src/devices/nm-device.c:12963
    #5  0x00007fffe88d7f1e in act_stage2_config (device=<optimized out>, reason=0x7fffffffe000) at src/devices/wifi/nm-device-wifi.c:2651
    #6  0x00005555556879f1 in activate_stage2_device_config (self=0x555555bc0060 [NMDeviceWifi]) at src/devices/nm-device.c:4320
    #7  0x000055555566876b in activation_source_handle_cb (self=self@entry=0x555555bc0060 [NMDeviceWifi], family=family@entry=2) at src/devices/nm-device.c:4060
    #8  0x000055555566882e in activation_source_handle_cb4 (user_data=user_data@entry=0x555555bc0060) at src/devices/nm-device.c:3997
    #9  0x00007ffff4c658e7 in g_idle_dispatch (source=0x555555e228c0, callback=0x555555668820 <activation_source_handle_cb4>, user_data=0x555555bc0060) at gmain.c:5545
    #10 0x00007ffff4c68e52 in g_main_dispatch (context=0x555555a214d0) at gmain.c:3203
    #11 0x00007ffff4c68e52 in g_main_context_dispatch (context=context@entry=0x555555a214d0) at gmain.c:3856
    #12 0x00007ffff4c691d0 in g_main_context_iterate (context=0x555555a214d0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3929
    #13 0x00007ffff4c694f2 in g_main_loop_run (loop=0x555555a1a750) at gmain.c:4125
    #14 0x00005555555821fe in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:423

Fixes: 07570e245a
2017-02-21 16:21:02 +01:00
Beniamino Galvani
4a6fd0e83e device: honor the connection.autoconnect-retries for 802.1X
NMDeviceEthernet and NMDeviceMacsec implement their own retry policy
for connection using 802.1X, and consider the credentials wrong when
the authentication fails for 3 times. In such case, they also disable
autoconnection for the device by setting the state reason NO_SECRETS.

This means that it's not possible at the moment to choose how many
times the authentication will be retried since they don't use the
standard reconnection logic.

Change NMDeviceEthernet and NMDeviceMacsec to use the number of
retries from connection.autoconnect-retries instead of a hardcoded
value to decide how many times the authentication must be restarted.
2017-02-21 09:18:53 +01:00
Beniamino Galvani
07570e245a device: add support for 802-1x.auth-timeout
Use the per-connection authentication timeout for 802.1X Ethernet,
MACsec and Wi-Fi connections. In case the value is not defined, fall
back to the global one.
2017-02-21 09:18:53 +01:00
Beniamino Galvani
f37e183442 device: apply the mtu property of gsm and cdma settings 2017-02-20 09:18:25 +01:00
Thomas Haller
35d4e8f7a0 device/wifi: fix #if check for more-logging
Fixes: ae158bf178
2017-02-19 19:15:17 +01:00
Thomas Haller
ae158bf178 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.
2017-02-17 20:32:42 +01:00
Thomas Haller
2ab2254dd7 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
2017-02-17 14:41:27 +01:00
Thomas Haller
6eaded9071 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.
2017-02-17 14:41:27 +01:00
Thomas Haller
2f9166e6b9 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.
2017-02-17 14:41:27 +01:00
Thomas Haller
257484e7ba wifi: also show the NM D-Bus path for the Wi-Fi AP in nm_wifi_ap_to_string() 2017-02-17 14:41:27 +01:00
Thomas Haller
c9dc0eba65 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.
2017-02-17 14:41:27 +01:00
Thomas Haller
e3a489180b 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().
2017-02-17 14:41:26 +01:00
Thomas Haller
29a53b1cd7 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.
2017-02-17 14:41:26 +01:00