Commit graph

11271 commits

Author SHA1 Message Date
Thomas Haller
b9eb264efe device: add "dhcp-plugin" match spec for device
The need for this is the following:

"ipv4.dhcp-client-id" can be specified via global connection defaults.
In absence of any configuration in NetworkManager, the default depends
on the DHCP client plugin. In case of "dhclient", the default further
depends on /etc/dhcp.

For "internal" plugin, we may very well want to change the default
client-id to "mac" by universally installing a configuration
snippet

    [connection-use-mac-client-id]
    ipv4.dhcp-client-id=mac

However, if we the user happens to enable "dhclient" plugin, this also
forces the client-id and overrules configuration from /etc/dhcp. The real
problem is, that dhclient can be configured via means outside of NetworkManager,
so our defaults shall not overwrite defaults from /etc/dhcp.

With the new device spec, we can avoid this issue:

    [connection-dhcp-client-id]
    match-device=except:dhcp-plugin:dhclient
    ipv4.dhcp-client-id=mac

This will be part of the solution for rh#1640494. Note that merely
dropping a configuration snippet is not yet enough. More fixes for
DHCP will follow. Also, bug rh#1640494 may have alternative solutions
as well. The nice part of this new feature is that it is generally
useful for configuring connection defaults and not specifically for
the client-id issue.

Note that this match spec is per-device, although the plugin is selected
globally. That makes some sense, because in the future we may or may not
configure the DHCP plugin per-device or per address family.

https://bugzilla.redhat.com/show_bug.cgi?id=1640494
2018-11-01 11:17:12 +01:00
Thomas Haller
5f4d8ffa79 core/tests: allow to reset singleton instantiations for testing
Most singletons can only be instantiated once (unless NM_DEFINE_SINGLETON_ALLOW_MULTIPLE
is defined). Otherwise, an assertion will be triggered if the singleton is destroyed
and another instance is requested.

For testing, we want to create multiple singleton instances and being able to reset
the singleton getter. Add a function for that.
2018-10-31 11:40:37 +01:00
Thomas Haller
3648c58bc5 systemd: merge branch systemd into master 2018-10-28 09:31:31 +01:00
Thomas Haller
5437448a64 systemd: update code from upstream (2018-10-27)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=e6b538d06680857fb25e2a6da94fc416bb2340f5

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/unaligned.h | \
  xargs -d '\n' rm -f

nm_copy_sd() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_shared() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd "src/basic/alloc-util.c"
nm_copy_sd "src/basic/alloc-util.h"
nm_copy_sd "src/basic/async.h"
nm_copy_sd "src/basic/env-util.c"
nm_copy_sd "src/basic/env-util.h"
nm_copy_sd "src/basic/escape.c"
nm_copy_sd "src/basic/escape.h"
nm_copy_sd "src/basic/ether-addr-util.c"
nm_copy_sd "src/basic/ether-addr-util.h"
nm_copy_sd "src/basic/extract-word.c"
nm_copy_sd "src/basic/extract-word.h"
nm_copy_sd "src/basic/fileio.c"
nm_copy_sd "src/basic/fileio.h"
nm_copy_sd "src/basic/fd-util.c"
nm_copy_sd "src/basic/fd-util.h"
nm_copy_sd "src/basic/fs-util.c"
nm_copy_sd "src/basic/fs-util.h"
nm_copy_sd "src/basic/hash-funcs.c"
nm_copy_sd "src/basic/hash-funcs.h"
nm_copy_sd "src/basic/hashmap.c"
nm_copy_sd "src/basic/hashmap.h"
nm_copy_sd "src/basic/hexdecoct.c"
nm_copy_sd "src/basic/hexdecoct.h"
nm_copy_sd "src/basic/hostname-util.c"
nm_copy_sd "src/basic/hostname-util.h"
nm_copy_sd "src/basic/in-addr-util.c"
nm_copy_sd "src/basic/in-addr-util.h"
nm_copy_sd "src/basic/io-util.c"
nm_copy_sd "src/basic/io-util.h"
nm_copy_sd "src/basic/list.h"
nm_copy_sd "src/basic/log.h"
nm_copy_sd "src/basic/macro.h"
nm_copy_sd "src/basic/mempool.h"
nm_copy_sd "src/basic/mempool.c"
nm_copy_sd "src/basic/parse-util.c"
nm_copy_sd "src/basic/parse-util.h"
nm_copy_sd "src/basic/path-util.c"
nm_copy_sd "src/basic/path-util.h"
nm_copy_sd "src/basic/prioq.h"
nm_copy_sd "src/basic/prioq.c"
nm_copy_sd "src/basic/process-util.h"
nm_copy_sd "src/basic/process-util.c"
nm_copy_sd "src/basic/random-util.c"
nm_copy_sd "src/basic/random-util.h"
nm_copy_sd "src/basic/refcnt.h"
nm_copy_sd "src/basic/set.h"
nm_copy_sd "src/basic/signal-util.h"
nm_copy_sd "src/basic/siphash24.h"
nm_copy_sd "src/basic/socket-util.c"
nm_copy_sd "src/basic/socket-util.h"
nm_copy_sd "src/basic/sparse-endian.h"
nm_copy_sd "src/basic/stat-util.c"
nm_copy_sd "src/basic/stat-util.h"
nm_copy_sd "src/basic/stdio-util.h"
nm_copy_sd "src/basic/string-table.c"
nm_copy_sd "src/basic/string-table.h"
nm_copy_sd "src/basic/string-util.c"
nm_copy_sd "src/basic/string-util.h"
nm_copy_sd "src/basic/strv.c"
nm_copy_sd "src/basic/strv.h"
nm_copy_sd "src/basic/time-util.c"
nm_copy_sd "src/basic/time-util.h"
nm_copy_sd "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/unaligned.h"
nm_copy_sd "src/basic/utf8.c"
nm_copy_sd "src/basic/utf8.h"
nm_copy_sd "src/basic/util.c"
nm_copy_sd "src/basic/util.h"
nm_copy_sd "src/libsystemd-network/arp-util.c"
nm_copy_sd "src/libsystemd-network/arp-util.h"
nm_copy_sd "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-network.c"
nm_copy_sd "src/libsystemd-network/dhcp-option.c"
nm_copy_sd "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd "src/libsystemd-network/lldp-internal.h"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd "src/libsystemd-network/lldp-network.c"
nm_copy_sd "src/libsystemd-network/lldp-network.h"
nm_copy_sd "src/libsystemd-network/network-internal.c"
nm_copy_sd "src/libsystemd-network/network-internal.h"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd "src/libsystemd-network/sd-lldp.c"
nm_copy_sd "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd "src/shared/dns-domain.c"
nm_copy_sd "src/shared/dns-domain.h"
nm_copy_sd "src/systemd/_sd-common.h"
nm_copy_sd "src/systemd/sd-dhcp6-client.h"
nm_copy_sd "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd "src/systemd/sd-dhcp-client.h"
nm_copy_sd "src/systemd/sd-dhcp-lease.h"
nm_copy_sd "src/systemd/sd-event.h"
nm_copy_sd "src/systemd/sd-ndisc.h"
nm_copy_sd "src/systemd/sd-id128.h"
nm_copy_sd "src/systemd/sd-ipv4acd.h"
nm_copy_sd "src/systemd/sd-ipv4ll.h"
nm_copy_sd "src/systemd/sd-lldp.h"
2018-10-27 22:43:21 +02:00
Lennart Poettering
58423902ce dhcp6: prefer offsetof() over sizeof() for structs with undefined sizes
This doesn't change anything in the generated source, but I think makes
semantically more sense, as these structures have undefined size, and we
only want to know the size up to the data field in these cases.

(cherry picked from commit 20b55f853847378b85561a4e299604d27b5cd25b)
2018-10-27 22:03:01 +02:00
Lennart Poettering
01ca2053bb dhcp6: make sure we have enough space for the DHCP6 option header
Fixes a vulnerability originally discovered by Felix Wilhelm from
Google.

CVE-2018-15688
LP: #1795921
https://bugzilla.redhat.com/show_bug.cgi?id=1639067

(cherry picked from commit 4dac5eaba4e419b29c97da38a8b1f82336c2c892)
2018-10-27 22:03:01 +02:00
Lennart Poettering
05872d554f dhcp6: reduce whitespace a bit
(cherry picked from commit 990668aa4cf04ea1c05791af97b1c05080378016)
2018-10-27 22:03:01 +02:00
Lennart Poettering
2dddf5924a dhcp6: split assert_return() to be more debuggable when hit
(cherry picked from commit 3c290c03167cf9334cb419035587ff3057940eee)
2018-10-27 22:03:01 +02:00
Lennart Poettering
d49a036afe dhcp6: constify things where we can
(cherry picked from commit e0a18b74a3b54bd9383b827139cea0df606e4378)
2018-10-27 22:03:01 +02:00
Li Song
915c2f675a sd-dhcp: remove unreachable route after rebinding return NAK
(cherry picked from commit cc3981b1272b9ce37e7d734a7b2f42e84acac535)
2018-10-27 22:03:01 +02:00
Yu Watanabe
83f849ae79 sd-dhcp6: drop empty 'error' label
(cherry picked from commit aae1fa5cc8a49e5071c7e089b186f52bac0da613)
2018-10-27 22:03:01 +02:00
Yu Watanabe
50403cccee sd-dhcp6: make dhcp6_option_parse_domainname() not store empty domain
This improves performance of fuzzer.
C.f. oss-fuzz#11019.

(cherry picked from commit 3c72b6ed4252e7ff5f7704bfe44557ec197b47fa)
2018-10-27 22:03:01 +02:00
Yu Watanabe
1990a3efab sd-dhcp6: do not update serverid when ENOMEM
(cherry picked from commit 33d367589581a9f46fe291181ef2b30b812e5cb3)
2018-10-27 22:03:01 +02:00
Yu Watanabe
a7137ce0ce sd-dhcp6: coding style cleanups
(cherry picked from commit da07cf358231caca214da5d4f161b06e713586be)
2018-10-27 22:03:01 +02:00
Yu Watanabe
373cbfc8c6 sd-dhcp6: fix argument and error handling of dhcp6_option_parse_status()
(cherry picked from commit 91c43f3978fa7c8341550b9ca279e460ba7e74e6)
2018-10-27 22:03:01 +02:00
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