Commit graph

11256 commits

Author SHA1 Message Date
Taegil Bae
4b2dc8826d meson: set RPATH for libnm_device_plugin_wwan.so
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/26
2018-10-24 09:56:46 +02:00
Taegil Bae
82b8ef2252 meson: set RPATH for libnm_device_plugin_bluetooth.so
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/26
2018-10-24 09:56:43 +02:00
Michael Biebl
8179b23d76 settings/ifupdown: fix block_name typo in initialize()
In commit f0938948bc a typo creeped in and
"block->name" got replaced by "block_name". Variable block_name is used
for a different purpose and not initialized at this point.
As a result g_str_has_prefix crashes with a segfault.

Spotted by Bernhard Übelacker <bernhardu@mailbox.org>

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911621
Fixes: f0938948bc

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/31
2018-10-23 22:58:44 +02:00
Thomas Haller
d49e88f716 Revert "keyfile: drop with_extension argument from _internal_write_connection()"
For upstream, we changed behavior here. However, I think certain
downstream don't want to do that, and revert patch "d37ad15f12 keyfile:
also add ".nmconnection" extension when writing keyfiles in /etc".

For that to make easier, keep the upstream sources closer to what
was. Revert.

This reverts commit e93d8cdb74.
2018-10-23 13:46:14 +02:00
Andrew Zaborowski
7f5957c8a7 wifi/iwd: check priv->dbus_obj in is_available
is_available would recently return true after IWD had disconnected
if a connection was active because it would check that
priv->dbus_station_proxy was non-NULL (i.e. that the DBus interface was
still visible, which it wasn't) but that check would be overridden
if the NMDevice state was activated.  Now require priv->dbus_obj to be
non-NULL, which would even be enough on its own although I'm leaving the
previous check there too to catch potential IWD states we don't support
in which priv->dbus_station_proxy is NULL without an active connection.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
75d53cc9fc wifi/iwd: add a sanity check for duplicate Networks on DBus
Sanity check networks received from the Station.GetOrderedNetworks()
DBus method.  Duplicates shouldn't happen but the code should be safe
against bogus data received over DBus.  There was a recent bug in a
library used by IWD causing occasional duplicates to be returned which
would cause invalid memory accesses reported by valgrind in NM because
g_hash_table_insert would free what we passed as the key.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
5c9a33f021 wifi/iwd: start a scan immediately after device appears
Start a new scan with 0 delay after a device goes into the disconnected
state, goes UP or freshly appears on DBus instead of waiting 10 seconds.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
bea6c40367 wifi/iwd: handle forgetting connection profiles
Watch for connection-removed events and delete corresponding IWD network
configs if found.  This mainly changes anything for 802.1X networks
where the deleted NM connections might annoyingly re-appear after a
restart.  For PSK networks though it'll make IWD forget the password
which, until now, would be remembered by IWD even if it was removed or
changed in the NM profile, which is a bug.

This is still fragile because we don't handle "connection-updated"
events so the data->mirror_connection pointer for a known network record
may after some time point to an NMSettingsConnection with a different
SSID or security type and there are corner cases where the IWD-side
profile will not be forgotten.  At least I'm trying to make sure we
don't crash and don't wrongly remove any IWD profile which could also be
annoying for complicated EAP configs.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
b98f269b91 wifi/iwd: print warning if known network exists in interface-added
Something is possibly wrong with the DBus signal handling if a newly
added KnownNetwork interface already has an entry in
priv->known_networks, but since we handle this case add a warning and
update the GDBusProxy pointer for that existing entry.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
ba52c4ea0a wifi/iwd: return existing connection from mirror_8021x_connection
interface_added expects mirror_8021x_connection() to return the pointer to
the existing connection if one exists, and NULL on error, rather than
NULL if a conneciton exists.  While touching that, add logic to return
specifically a connection with EAP method set to 'external' if one
exists even though this should not affect any other logic we have
currently.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
a9d1aaf090 wifi/iwd: use nm_act_request_get_secrets if no PSK for AP found
Some internal logic causes the secrets in a connection to be
occasionally moved to NMSettingConnection's priv->system_secrets after a
connection attempt so we need to use nm_act_request_get_secrets to get
them added to the device's settings connection and applied connection if
the PSK is missing during an AP or AdHoc mode activation (in
infrastructure mode we already do secret requests though they're cached
by IWD in most cases).

The common steps for the PSK available and unavailable scenarios is moved
from act_stage2_config to act_set_mode.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
21fc18cc33 wifi/iwd: skip creating a GVariant for DBus calls with no params
g_dbus_proxy_call and other GDBus function can accept a NULL as the
method call parameters.
2018-10-23 11:32:28 +02:00
Andrew Zaborowski
9dc1611f37 wifi/iwd: use g_variant_lookup in property change handlers
This simplifies the code by using g_variant_lookup.  In this handler
where we parse more than one property this is probably slower although
the number of string comparisons will be the same.
2018-10-23 11:32:28 +02:00
Thomas Haller
4f27164148 core: don't cast return value of nm_device_get_applied_setting() 2018-10-23 10:47:01 +02:00
Thomas Haller
af48af4671 device: return void pointer from nm_device_get_applied_setting()
Literally ever use of nm_device_get_applied_setting() requires a
cast. Just don't.
2018-10-23 10:47:01 +02:00
Thomas Haller
83acb40a86 keyfile: move and rename NM_CONFIG_KEYFILE_PATH_DEFAULT define 2018-10-23 10:37:33 +02:00
Thomas Haller
e93d8cdb74 keyfile: drop with_extension argument from _internal_write_connection()
For non-test code, we always passed TRUE.

For test code, setting with_extension is fine too, so drop the
argument.
2018-10-23 10:37:33 +02:00
Thomas Haller
c4a9f44aff initrd: use keyfile util for creating filename 2018-10-23 10:37:33 +02:00
Thomas Haller
c36b5236b6 keyfile/trivial: rename keyfile related functions
NM_CONFIG_KEYFILE_PATH_IN_MEMORY is now called NMS_KEYFILE_PATH_NAME_RUN.
This name seems odd in the current context, it will be more suitable
when we also have NMS_KEYFILE_PATH_NAME_LIB (for /usr/lib).
2018-10-23 10:36:18 +02:00
Thomas Haller
410664967b keyfile: move keyfile utilities from src/ to libnm-core/
These utilities are concerned with valid file names (as NetworkManager
daemon requires it). This is relevant for everybody who wants to write
keyfile files directly. Hence, move it to libnm-core. Still as internal
API.
2018-10-23 10:36:07 +02:00
Thomas Haller
61717cc575 initrd: use cleanup attribute and return early from output_conn() 2018-10-23 10:36:07 +02:00
Thomas Haller
3c58fc1122 core: use nm_utils_file_is_in_path() for checking paths
For one, re-use the helper function instead of re-implementing
the check at multiple places.

Also, with this duplicate path separators are accepted.
2018-10-23 10:32:53 +02:00
Thomas Haller
f90b3adc15 core: add nm_utils_file_is_in_path() for checking paths
Add a helper function for the common check whether a file is
inside a path. Also, this function handles special cases like
repeated file separators. However, as it is still entirely text
based, it also cannot recognize if two (literally) different
paths reference the same inode/file.
2018-10-23 10:32:53 +02:00
Thomas Haller
9dce4a426b systemd: fix handling special cases kill_dots and path_simplify()
Previously, paths like ".", "./", ./." would all result in an
empty path. That is wrong, one dot must be kept.

afbae3e9f2
2018-10-23 10:32:53 +02:00
Thomas Haller
eece5aff09 core: add "nm-sd-utils.h" to access system internal helper
We have a fork of a lot of useful systemd helper code.
However, until now we shyed away from using it aside from
the bits that we really need.

That means, although we have some really nice implementations
in our source-tree, we didn't use them. Either we were missing
them, or we had to re-implement them.

Add "nm-sd-utils.h" header to very carefully make internal
systemd API accessible to the rest of core.

This is not intended as a vehicle to access all of internal
API. Instead, this must be used with care, and only a hand picked
selection of functions must be exposed. Use with caution, but where it
makes sense.
2018-10-23 10:32:53 +02:00
Beniamino Galvani
d0a99176a7 initrd: cmdline-reader: fix setting uint properties
Previously a uint property was assigned with a guint64 value, which
has a different size. Fix this and add a warning when the read value
can't be converted.

Fixes: ecc074b2f8

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/66
2018-10-23 09:09:42 +02:00
Lubomir Rintel
7c7e4cf134 ndisc: mark a keep-alive variable unused
Fixed build with clang:

  src/ndisc/nm-lndp-ndisc.c:494:27: error: unused variable 'ndisc_keep_alive' [-Werror,-Wunused-variable]
        gs_unref_object NMNDisc *ndisc_keep_alive = g_object_ref (ndisc);
                                 ^
Fixes: 9aa628cedb
2018-10-22 18:23:46 +02:00
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