Commit graph

11229 commits

Author SHA1 Message Date
Thomas Haller
43b28e06ed test/meson: increase timeout for some tests
During gitlab-ci, some tests may take a long time. Increase
the default timeout.
2018-10-22 16:16:52 +02:00
Thomas Haller
8d6d7c48f9 core/trivial: fix whitespace 2018-10-22 14:03:11 +02:00
Thomas Haller
948abdb84d platform/tests: extend timeout for link-linux tests with meson
Our gitlab CI sometimes takes a long time with the
"/link/create-many-links/1000" test.
2018-10-22 13:42:20 +02:00
Jan Alexander Steffens (heftig)
e0b168d6a8 meson: Fix platform tests
All platform tests were run twice with the `linux` platform, instead of
`fake` and `linux`, as expected.
2018-10-22 13:19:15 +02:00
Thomas Haller
581be6b8d2 platform/tests: fix test-nmp-object when running on system without udev
Fix the test, to check that the nmp-object was deleted. It is
no longer visible and no longer alive.
2018-10-22 13:19:15 +02:00
Thomas Haller
cfc0565604 platform/tests: don't compare dangling pointer in "test-nmp-object.c"
This wouldn't even dereference the dangling pointer, but
merely comparing it for pointer equality. Still, it's actually
undefined behavior. Avoid it.
2018-10-22 13:17:53 +02:00
Sven Schwermer
1913a4d259 ppp: check ppp status against correct type
ppp_status is of type NMPPPStatus whereas PHASE_RUNNING is pppd's type.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/28
2018-10-22 10:53:16 +02:00
Thomas Haller
d37ad15f12 keyfile: also add ".nmconnection" extension when writing keyfiles in /etc
This is a change in behavior regarding the filename that we choose when
writing files to "/etc/NetworkManager/system-connections/".
2018-10-19 15:17:51 +02:00
Thomas Haller
4ca7fa7f4a initrd: add .nmconnection extension when writing keyfiles
initrd does not use keyfile API from "src/settings/plugins/keyfile",
hence it does not use nms_keyfile_utils_escape_filename() to add
the ".nmconnection" file extension.

I think that is problematic, because it also misses escapings which
are necessary so that NetworkManager will accept the file.

Anyway, the proper solution here would be to move the keyfile utility
functions to libnm-core, alongside base keyfile API. That way, it
could be used by initrd generator.

For now, just dirty fix the generated filename.

Fixes: 648c256b90
2018-10-19 11:55:06 +02:00
Thomas Haller
648c256b90 keyfile: write keyfiles to "/run" directory with ".nmconnection" file suffix
For profiles in "/etc/NetworkManager/system-connections", we did not enforce
that the keyfiles have a special suffix, nor did we generate the
filenames in such a manner. In hindsight, I think that was a mistake.

Recently we added "/run/NetworkManager/system-connections" as additional
keyfile directory. Enforce a suffix and write keyfiles with such a name.

In principle, we could also start writing keyfiles in /etc with the
same suffix. But let's not do that, because we anyway cannot enforce
it.

An ugly part is, that during `nmcli connection load` we need to
determine whether the to-be-loaded connection is under /etc or /run.
Preferably, we would allow any kind of symlinking as what matters
is the file object (inode) and not the path. Anyway, we don't do
that but compare plain paths. That means, paths which are not
in an expected form, will be rejected. In particular, the paths
starting with "/run/..." and "/var/run/..." will be treated differently,
and one of them will be rejected.

Note that ifcfg-rh plugin strictly enforces that the path
starts with IFCFG_DIR as well. So, while this is a breaking
change for keyfile, I think it's reasonable.
2018-10-18 18:34:19 +02:00
Thomas Haller
636516e708 logging: make nm-logging.c independent of other core components
"nm-logging.c" now no longer depends on anything particularly special
from NM core.
2018-10-18 12:16:55 +02:00
Thomas Haller
a6add8175a shared: move nm_utils_get_monotonic_timestamp*() to shared/nm-utils.
This is independent functionality that only depends on linux API
and glib.

Note how "nm-logging" uses this for getting the timestamps. This
makes "nm-logging.c" itself dependen on "src/nm-core-utils.c",
for little reason.
2018-10-18 12:16:55 +02:00
Thomas Haller
884ed15261 core: move logging of monotonic-timestamp to "nm-logging.c"
This makes monotonic-timestamp handling independent of "nm-logging.c".
2018-10-18 12:16:55 +02:00
Thomas Haller
2af1dc1d28 dhcp: log client-id of DHCP instance 2018-10-18 09:13:27 +02:00
Thomas Haller
0cb8bed23c core: ignore unmanaged devices for explicit activation request depending on multi-connect
When a device is unmanaged, an explicit activation request can
still activate it. In particular, that is the case for

  $ nmcli connection up "$PROFILE" ifname "$DEVICE"

It is also the case, for plain

  $ nmcli connection up "$PROFILE"

where NetworkManager searches for a suitable device -- depending on
multi-connect setting of the profile.

The idea is, that a profile with "multi-connect=single" is expected
to sufficently and uniquely match a device, based on matching properties
like "connection.interface-name". In that case, an explicit activation
request from the user shows the intent to manage the device.
Note that it's hard to understand whether the profile really uniquely
selects a particular device. For example, if the profile doesn't specify
"connection.interface-name", it might still uniquely identify
an ethernet device, if you only have one such device.

On the other hand, with "connection.multi-connect" other than "single",
it is very much expected that the profile does not strictly match
one device.

Change the behavior here for multi-connect profiles. This allows the
user to block individual devices from activation via

  $ nmcli device set "$DEVICE" managed not

A subsequent

  $ nmcli connection up "$MULTI_PROFILE"

will not consider "$DEVICE" as suitable candidate for activation.

Likewise, in the future we may want to add a

  $ nmcli connection up --all "$MULTI_PROFILE"

command, to activate the profile on all suitable device.
In that case again, unmanaged devices probably also should be skipped
for multi-connect profiles.

https://bugzilla.redhat.com/show_bug.cgi?id=1639254
2018-10-17 15:22:56 +02:00
Thomas Haller
920346a5b9 device: add and use overrule-unmanaged flag for nm_device_check_connection_available()
This flag is more granular in whether to consider the connection
available or not. We probably should never check for the combined
flag NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST directly, but
always explicitly for the relevant parts.

Also, improve the error message, to indicate whether the device is
strictly unmanaged or whether it could be overruled.
2018-10-17 15:06:52 +02:00
Thomas Haller
5412fd389b device: cleanup checking device avilability for ignoring carrier
The flags NMDeviceCheckConAvailableFlags and NMDeviceCheckDevAvailableFlags
both control whether a device appears available (either, available in
general, or related to a particular profile).

Also, both flag types strictly increase availability. Meaning: more flags,
more available.

There is some overlap between the flags, however they still have
their own distinct parts.

Improve the mapping from NMDeviceCheckConAvailableFlags to
NMDeviceCheckDevAvailableFlags, by picking exactly the flags
that are relevant.
2018-10-17 15:06:52 +02:00
Thomas Haller
e6523fbbbc core/trivial: add code comment for NMDeviceCheckDevAvailableFlags and NMDeviceCheckConAvailableFlags 2018-10-17 15:06:52 +02:00
Thomas Haller
c37b028aba core/trivial: add code comment for nm_manager_get_best_device_for_connection() 2018-10-17 15:06:52 +02:00
Thomas Haller
45913c11df core: fix checking multi-connect flag in nm_manager_get_best_device_for_connection()
We should not check @sett_conn, but @connection.

Fixes: 09719bc479
2018-10-17 14:38:07 +02:00
Thomas Haller
47146b4be3 modem: cleanup nm_modem_deactivate_async()
- fix stopping ppp-manager. Previously, we would take a reference
  to priv->ppp_manager to cancel it later. However, deactivate_cleanup()
  is called first, which already issues nm_ppp_manager_stop().
  Thereby, not using a callback and not waiting for the operation
  to complete.

- get rid of this "step" state machine. There are litterally two steps
  that need to be performed asynchornously. Instead chain the calls.

- it is now obviously visible, that the async callback never completes
  synchronously upon being called (provided that all async operations
  that it calls themself have this behavior -- which they should).
2018-10-17 13:03:50 +02:00
Thomas Haller
dd4968fa16 ppp: make ppp-manager cancellable via GCancellable
Previously nm_ppp_manager_stop() would return a handle which
makes it easy to cancel the operation.

However, sometimes, we may want to cancel an operation based on
an GCancellable. So, extend nm_ppp_manager_stop() to hook it
with a cancellable.

Essentially, move the code from nm-modem.c to nm-ppp-manager-call.c,
where it belongs and where the functionality gets available to every
component.
2018-10-17 13:03:50 +02:00
Thomas Haller
9b935fad9b modem: don't use GAsyncResult pattern for disconnecting modem
We should not use GAsyncResult. At least, not for internal API.

It's more cumbersome then helpful, in my opinion. It requires
this awkward async_finish() pattern.

Instead, let the caller pass a suitable callback of the right type.
2018-10-17 13:03:50 +02:00
Thomas Haller
fadcc16b26 bluez: make connect operation (partially) cancellable and drop GAsyncResult pattern
All operations must be cancellable in a timely manner, otherwise, the objects
hang during shutdown.

Also, get rid of the GAsyncResult pattern. It is more cumbersome than
helpful.

There are still several issues, marked by FIXME comments.
2018-10-17 13:03:50 +02:00
Thomas Haller
09719bc479 core: improve selection of device when activating profile on any device
With

  $ nmcli connection up "$PROFILE" ifname "$DEVICE"

it's clear that the user means the particular device. That also
is taken as a indication to make $DEVICE as managed, in case it was
unmanaged before. So, this command implies a previous

  $ nmcli device set $DEVICE managed yes

On the other hand, if the user just issues

  $ nmcli connection up "$PROFILE"

without a particular device, then we should prefer devices which
are marked as managed instead of unmanaged once.

Likewise, we should consider the device's state when selecting
a device. This means, when activating a profile which is activatable on
multiple devices, it will now prefer devices which are not already
active. The exception to this is that if the profile itself is already
active (and multi-connect "single"), then it will prefer to re-activate
the profile on the same device. This was done previously already. What's
new is that if the the profile is not multi-connect "single", the said
exception no longer applies, and we prefer to activate the profile on a
hitherto unactivated device.

https://bugzilla.redhat.com/show_bug.cgi?id=1639254

https://github.com/NetworkManager/NetworkManager/pull/232
2018-10-17 11:10:31 +02:00
Beniamino Galvani
567e277e64 dhcp: don't start grace period if the client is not running
We shouldn't start a grace period when the client is not running.
2018-10-15 14:05:23 +02:00
Beniamino Galvani
0a25b90813 dhcp: introduce terminated dhcp-state
When the client terminates, we really don't care if it exited cleanly,
with an error or killed by a signal. We expect the client to never
exit and so all these situations are equally bad for us. Introduce a
new TERMINATED state instead of reusing existing FAIL or DONE states,
which are set when receiving particular events from the client.
2018-10-15 14:05:23 +02:00
Beniamino Galvani
81aa1a3bb3 dhcp: reset @was_active on cleanup
The @was_active flag indicates that we started DHCP on an assumed
connection. The idea is that if DHCP succeeded before, any failure
must be treated like a renewal failure (and so it should start a grace
period) rather than a failure in getting an initial lease (which fails
the IP method).

When we clean up the DHCP instance, the flag must be reset to FALSE,
otherwise it will be potentially considered for other connections.
2018-10-15 14:05:23 +02:00
Beniamino Galvani
54064144d4 dhcp: log whether the client was active
It is useful to understand why the grace period was started.
2018-10-15 14:05:23 +02:00
Beniamino Galvani
37274a16a1 dhcp6: fix handling of failure events
The effect of a DHCPv6 failure should depend only on current IP state.
This in the analogous of commit bd63d39252 ("dhcp: fix handling of
failure events") for IPv6.
2018-10-15 14:05:23 +02:00
Thomas Haller
8c6629b356 ndisc: don't update dad_counter for addresses in router config
I am not sure, we ever call complete_address() for router-configurations.
Maybe not, so the dad-counter is never incremented and does not matter either.

If we however do, then we certainly want to preserve the DAD counter
when the address is already tracked.
2018-10-13 17:11:52 +02:00
Thomas Haller
27be3e0338 ndisc: fix updating address lifetime on Router Announcement according to RFC4862
This is a denial-of-service protection, where a malicious router
advertisement can expire the addresses.

See-also: 6554550f35
See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1796622
2018-10-13 17:11:52 +02:00
Thomas Haller
b086535cb7 ndisc: handle integer overflows better for lifetime handling
we use get_expiry() to compare two lifetimes. Note, that previously,
it would correctly truncate the calculated expiry at G_MAXINT32-1.

However, that means, that two different lifetimes that both lie
more than 68 years in the future would compare equal.

Fix that, but extending the range to int64, so that no overflow
can happen.
2018-10-13 17:11:52 +02:00
Thomas Haller
9d0a138ef0 ndisc: minor refactoring loop in nm_ndisc_add_address()
No change in behavior. Just don't do so much work inside
the deeper nesting of the loop.
2018-10-13 17:11:52 +02:00
Thomas Haller
23c417854a ndisc: only generate address interface identifer after checking existing prefix
RFC4862 5.5.3, points d) and e) make it clear, that the list of
addresses should be compared based on the prefix.

  d)  If the prefix advertised is not equal to the prefix of an
    address configured by stateless autoconfiguration already in the
    list of addresses associated with the interface (where "equal"
    means the two prefix lengths are the same and the first prefix-
    length bits of the prefixes are identical), and if the Valid
    Lifetime is not 0, form an address (and add it to the list) by
    combining the advertised prefix with an interface identifier of
    the link as follows:

That means, we should not initialize the interface identifier first
(via complete_address()) and then search for the full address.

See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3
2018-10-13 17:11:52 +02:00
Thomas Haller
700b04d0de ndisc: ensure we skip unspecified IPv6 address in ndisc_set_router_config()
Later, nm_ndisc_add_address() asserts that the address is not an
unspecified address. Skip it, just to be sure.
2018-10-13 17:11:52 +02:00
Thomas Haller
43c3c259c8 ndisc: ignore addresses with preferred lifetime larger than lifetime
Previously, we would coerce the value so that preferred is the same
as lifetime. However, RFC4862 5.5.3.c) says:

  c)  If the preferred lifetime is greater than the valid lifetime,
    silently ignore the Prefix Information option.  A node MAY wish to
    log a system management error in this case.

See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3
2018-10-13 17:11:52 +02:00
Lubomir Rintel
02958bba80 all: remove \n endings from log calls
The extra newlines look bad when logging to the console.

https://github.com/NetworkManager/NetworkManager/pull/223
2018-10-12 14:34:58 +02:00
Lubomir Rintel
08225c5e96 devices/olpc: don't assert we're waiting for companion on device_added_cb()
We're hooking the signal on construction, but we only queue a pending
action on reaching UNAVAILABLE state. The signal could fire in between:

  <info>  [1539282167.9666] manager: (msh0): new 802.11 OLPC Mesh device (/org/freedesktop/NetworkManager/Devices/4)
  <info>  [1539282168.1440] manager: (wlan0): new 802.11 WiFi device (/org/freedesktop/NetworkManager/Devices/5)
  <info>  [1539282168.1831] device (msh0): found companion WiFi device wlan0
  <warn>  [1539282168.2110] device (msh0): remove_pending_action (1): 'waiting-for-companion' not pending
  file src/devices/nm-device.c: line 13966 (<dropped>): should not be reached

https://github.com/NetworkManager/NetworkManager/pull/229
2018-10-12 12:56:19 +02:00
Thomas Haller
cec7ade86c wwan: don't assume DNS info is always available for IPv6
See also "5df024f57a wwan: don't assume DNS info is always available"
which does the same for IPv4.
2018-10-12 00:00:43 +02:00
Andrew Zaborowski
b3dad27a4a wifi/iwd: use KnownNetwork DBus properties on Network objects
Instead of walking through the list all known networks and comparing
name & SSIDs to judge whether a network is an IWD KnownNetwork, look at
the Network.KnownNetwork pre-IWD-0.8 property.
2018-10-11 16:07:15 +02:00
Andrew Zaborowski
2fff4e14b4 wifi/iwd: always update can_connect in state_changed
Ensure priv->can_connect is up to date on IWD state changed.  If we
exited the function early priv->can_connect would sometimes be wrongly
TRUE and we'd start a new autoconnect too early after IP configuration
had failed for example.
2018-10-11 16:07:15 +02:00
Andrew Zaborowski
979c632e11 wifi/iwd: add Ad-hoc mode support 2018-10-11 16:07:15 +02:00
Andrew Zaborowski
a6f13d3c69 wifi/iwd: add AP mode support
Handle AP mode connections by setting the Mode property on IWD's Device
interface to "ap" (which will make the Station interface go away, the
Powered property -- normally controlled by set_enabled -- to switch to
FALSE and back to TRUE, and then the AccessPoint interface to appear)
and then calling the AccessPoint.Start method.  This is all done in the
CONFIG phase in NM.  We also attempt to always set Mode back to
"station" and wait for the Station interface to reappear before going to
the NM DISCONNECTED state.  All this complicates the code a little.

While making the necessary changes simplify a lot of the checks which
are implied by other things we've checked already, for example
priv->can_scan and priv->can_connect can now only be TRUE when device is
powered up and in station mode (Station interface is present) so we can
skip other checks.  Also assume that check_connection_compatible has
been called before other methods are called so we can skip multiple
connection mode checks and checks that a IWD KnownNetwork exsists for
EAP connections.

act_stage1_prepare and act_stage2_config now borrow more code from
nm-device-wifi.c because both backend now handle multiple modes.
2018-10-11 16:07:15 +02:00
Andrew Zaborowski
6e95029b09 wifi/iwd: use nm_utils_error_is_cancelled consistently
Use nm_utils_error_is_cancelled instead of checking
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED), set
consider_is_disposing false.  Also use the DBUS_INTERFACE_PROPERTIES
macro.
2018-10-11 16:07:15 +02:00
Andrew Zaborowski
6e1935eb21 wifi/iwd: free variants returned by g_dbus_proxy_call_finish
Make sure we g_variant_unref() the values returned from
g_dbus_proxy_call_finish.  In get_ordered_networks_cb also make sure we
don't access the NMDeviceIwd data until after we know the call has not
been cancelled.  Switch from _nm_dbus_proxy_call_finish to
g_dbus_proxy_call_finish where we don't care about the variant type
returned.
2018-10-11 16:07:15 +02:00
Andrew Zaborowski
178af02678 wifi: skip nm_platform_wifi_get_capabilities/get_mode for IWD backend
Only call nm_platform_wifi_get_capabilities and
nm_platform_wifi_get_mode with the wpa_supplicant backend.  They're used
to initialize the wireless-capabilities property and to skip creating
NMDevices for interfaces in unknown wifi mode which IWD handles already.
2018-10-11 16:07:15 +02:00
Andrew Zaborowski
7a6d5ab5a2 wifi/iwd: set capabilities property based on IWD support
Parse the Adapter.SupportedModes dbus property and set the
gobject property wireless-capabilities based on that.
2018-10-11 16:07:15 +02:00
Thomas Haller
98ec56c670 ndisc: always emit changed signal if an ndisc parameter changes
Note how the nm_ndisc_add_*() return a boolean to indicate whether
anything changes. That is taken to decide whether to emit a changed
signal.

Previously, we would not consider all fields which are exposed
as public API.

Note that nm-ip6-config.c would care about the lifetime of NMNDiscAddress.
For that, nm_ndisc_add_address() would correctly consider a change of
the lifetime as relevant. So, this was for the most part not broken.
However, for example nm_ndisc_add_route() would ignore changes to the
gateway.

Always signal changes if anything changes at all. It's more correct
and robust.
2018-10-11 05:56:18 +02:00
Thomas Haller
4f78d82fcd ndisc/trivial: move code 2018-10-11 05:56:18 +02:00