Commit graph

22852 commits

Author SHA1 Message Date
Beniamino Galvani 366f9867eb build: fix build with sanitizers
Add missing linker flags.
2019-04-12 11:19:58 +02:00
Thomas Haller 8c3fc3c503 all: merge branch 'th/strsplit-pt2'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/105
2019-04-12 11:11:53 +02:00
Thomas Haller afc258519d ifcfg-rh: refactor parsing bond options
Don't use g_strsplit_set() if all we want to do is split the
string at the first '='.
2019-04-12 11:10:18 +02:00
Thomas Haller 7887909564 ifcfg-rh: refactor parse_full_ip6_address() to use nm_utils_parse_inaddr_prefix_bin()
We already have code that parses exactly this kinds of string:
nm_utils_parse_inaddr_prefix_bin(). Use it.

Also, it doesn't use g_strsplit_set() to separate a string at the first
'/'. Total overkill.
2019-04-12 11:10:18 +02:00
Thomas Haller 0d3bf9729a dispatcher/tests: cleanup tests
- use cleanup macros everywhere.

- In particular use nm_auto_clear_variant_builder to free the
  GVariantBuilder in the error cases. Note that the error cases
  anyway are asserted against, so during a normal test run there
  was no leak. But we should not write software like that.

- use nm_utils_strsplit_set_with_empty() instead of g_strsplit_set().
  We should use our variant also in unit-tests, because that way the
  function gets more test coverage. And it likely performs better
  anyway.
2019-04-12 11:10:07 +02:00
Thomas Haller 03b6be8319 ifupdown: replace g_strsplit_set() by nm_utils_strsplit_set()
Note that nm_utils_strsplit_set() drops empty tokens (consecutive delimiters).
This is what all callers here want anyway.
2019-04-12 11:07:25 +02:00
Thomas Haller f28a618889 shared: add nm_auto_clear_variant_builder 2019-04-12 11:07:25 +02:00
Beniamino Galvani 246c2dbe9a merge: branch 'bg/unmanaged-sw-dev-rh1679230'
https://bugzilla.redhat.com/show_bug.cgi?id=1679230
https://github.com/NetworkManager/NetworkManager/pull/340
2019-04-12 10:35:09 +02:00
Beniamino Galvani c0d5b58332 core: don't realize unmanaged software devices
Currently, if user configuration or settings specify that a software
device is unmanaged, for example:

 [device-bond-unmanaged]
 match-device=interface-name:bond*
 managed=0

or

 [keyfile]
 unmanaged-devices=interface-name:bond*

and there is a connection for the device with autoconnect=yes, NM
creates the platform link and a realized device in unmanaged
state. Fix this, the device should not be realized if it is unmanaged.

https://bugzilla.redhat.com/show_bug.cgi?id=1679230
2019-04-12 10:34:20 +02:00
Beniamino Galvani adbf368511 device: allow matching device spec from any state
nm_device_spec_match_list_full() calls
nm_device_get_permanent_hw_address() which freezes the MAC address, so
currently callers must avoid the function when the device is not
completely platform-initialized.

Instead, use nm_device_get_permanent_hw_address_full() to avoid
freezing the MAC when the device is not platform-initialized. In this
way nm_device_spec_match_list_full() can be called from any state
without side effects.
2019-04-12 10:34:20 +02:00
Thomas Haller 7b6a3aaf29 cli: fix typo in nmcli usage output
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/157
2019-04-12 09:56:51 +02:00
Thomas Haller da4f229805 libnm,shared: bzero secrets on failure in nm_utils_base64secret_decode()
Now that unbase64mem_full() understands a secure flag, we can
get this right.
2019-04-12 07:39:50 +02:00
Thomas Haller d3d45fd1f9 systemd: merge branch systemd into master 2019-04-12 07:33:52 +02:00
Thomas Haller 2b1ea1613d systemd: update code from upstream (2019-04-11)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=03abeb0baf7fe97c98a98d745b75c7d33e2f632e

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

git ls-files -z :/src/systemd/src/ \
                :/shared/systemd/src/ \
                :/shared/nm-utils/unaligned.h | \
  xargs -0 rm -f

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

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

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

nm_copy_sd_core "src/libsystemd-network/arp-util.c"
nm_copy_sd_core "src/libsystemd-network/arp-util.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd_core "src/libsystemd-network/lldp-internal.h"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd_core "src/libsystemd-network/lldp-network.c"
nm_copy_sd_core "src/libsystemd-network/lldp-network.h"
nm_copy_sd_core "src/libsystemd-network/network-internal.c"
nm_copy_sd_core "src/libsystemd-network/network-internal.h"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd_core "src/libsystemd-network/sd-lldp.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-source.h"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.h"
nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd_core "src/shared/dns-domain.c"
nm_copy_sd_core "src/shared/dns-domain.h"
nm_copy_sd_core "src/systemd/_sd-common.h"
nm_copy_sd_core "src/systemd/sd-dhcp-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd_core "src/systemd/sd-event.h"
nm_copy_sd_core "src/systemd/sd-id128.h"
nm_copy_sd_core "src/systemd/sd-ipv4acd.h"
nm_copy_sd_core "src/systemd/sd-ipv4ll.h"
nm_copy_sd_core "src/systemd/sd-lldp.h"
nm_copy_sd_core "src/systemd/sd-ndisc.h"
nm_copy_sd_nmutils "src/basic/unaligned.h"
nm_copy_sd_shared "src/basic/alloc-util.c"
nm_copy_sd_shared "src/basic/alloc-util.h"
nm_copy_sd_shared "src/basic/async.h"
nm_copy_sd_shared "src/basic/env-file.c"
nm_copy_sd_shared "src/basic/env-file.h"
nm_copy_sd_shared "src/basic/env-util.c"
nm_copy_sd_shared "src/basic/env-util.h"
nm_copy_sd_shared "src/basic/errno-util.h"
nm_copy_sd_shared "src/basic/escape.c"
nm_copy_sd_shared "src/basic/escape.h"
nm_copy_sd_shared "src/basic/ether-addr-util.c"
nm_copy_sd_shared "src/basic/ether-addr-util.h"
nm_copy_sd_shared "src/basic/extract-word.c"
nm_copy_sd_shared "src/basic/extract-word.h"
nm_copy_sd_shared "src/basic/fd-util.c"
nm_copy_sd_shared "src/basic/fd-util.h"
nm_copy_sd_shared "src/basic/fileio.c"
nm_copy_sd_shared "src/basic/fileio.h"
nm_copy_sd_shared "src/basic/fs-util.c"
nm_copy_sd_shared "src/basic/fs-util.h"
nm_copy_sd_shared "src/basic/hash-funcs.c"
nm_copy_sd_shared "src/basic/hash-funcs.h"
nm_copy_sd_shared "src/basic/hashmap.c"
nm_copy_sd_shared "src/basic/hashmap.h"
nm_copy_sd_shared "src/basic/hexdecoct.c"
nm_copy_sd_shared "src/basic/hexdecoct.h"
nm_copy_sd_shared "src/basic/hostname-util.c"
nm_copy_sd_shared "src/basic/hostname-util.h"
nm_copy_sd_shared "src/basic/in-addr-util.c"
nm_copy_sd_shared "src/basic/in-addr-util.h"
nm_copy_sd_shared "src/basic/io-util.c"
nm_copy_sd_shared "src/basic/io-util.h"
nm_copy_sd_shared "src/basic/list.h"
nm_copy_sd_shared "src/basic/log.h"
nm_copy_sd_shared "src/basic/macro.h"
nm_copy_sd_shared "src/basic/memory-util.c"
nm_copy_sd_shared "src/basic/memory-util.h"
nm_copy_sd_shared "src/basic/mempool.c"
nm_copy_sd_shared "src/basic/mempool.h"
nm_copy_sd_shared "src/basic/missing_fcntl.h"
nm_copy_sd_shared "src/basic/missing_socket.h"
nm_copy_sd_shared "src/basic/missing_stat.h"
nm_copy_sd_shared "src/basic/missing_type.h"
nm_copy_sd_shared "src/basic/parse-util.c"
nm_copy_sd_shared "src/basic/parse-util.h"
nm_copy_sd_shared "src/basic/path-util.c"
nm_copy_sd_shared "src/basic/path-util.h"
nm_copy_sd_shared "src/basic/prioq.c"
nm_copy_sd_shared "src/basic/prioq.h"
nm_copy_sd_shared "src/basic/process-util.c"
nm_copy_sd_shared "src/basic/process-util.h"
nm_copy_sd_shared "src/basic/random-util.c"
nm_copy_sd_shared "src/basic/random-util.h"
nm_copy_sd_shared "src/basic/set.h"
nm_copy_sd_shared "src/basic/signal-util.h"
nm_copy_sd_shared "src/basic/siphash24.h"
nm_copy_sd_shared "src/basic/socket-util.c"
nm_copy_sd_shared "src/basic/socket-util.h"
nm_copy_sd_shared "src/basic/sort-util.h"
nm_copy_sd_shared "src/basic/sparse-endian.h"
nm_copy_sd_shared "src/basic/stat-util.c"
nm_copy_sd_shared "src/basic/stat-util.h"
nm_copy_sd_shared "src/basic/stdio-util.h"
nm_copy_sd_shared "src/basic/string-table.c"
nm_copy_sd_shared "src/basic/string-table.h"
nm_copy_sd_shared "src/basic/string-util.c"
nm_copy_sd_shared "src/basic/string-util.h"
nm_copy_sd_shared "src/basic/strv.c"
nm_copy_sd_shared "src/basic/strv.h"
nm_copy_sd_shared "src/basic/time-util.c"
nm_copy_sd_shared "src/basic/time-util.h"
nm_copy_sd_shared "src/basic/tmpfile-util.c"
nm_copy_sd_shared "src/basic/tmpfile-util.h"
nm_copy_sd_shared "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/utf8.c"
nm_copy_sd_shared "src/basic/utf8.h"
nm_copy_sd_shared "src/basic/util.c"
nm_copy_sd_shared "src/basic/util.h"
2019-04-12 07:20:42 +02:00
Beniamino Galvani a94ccc9acc clients: fix assertion when requesting gsm pin secret
[root@gsm-r5s4-01 ~]# nmcli  connection up id gsm
  **
  libnmc:ERROR:clients/common/nm-secret-agent-simple.c:171:_secret_real_new_plain: assertion failed: ((secret_type == NM_SECRET_AGENT_SECRET_TYPE_SECRET) == nm_setting_get_secret_flags (setting, property, ((void *)0), ((void *)0)))
  Aborted (core dumped)

The pin is a secret property.

https://bugzilla.redhat.com/show_bug.cgi?id=1698495
2019-04-11 13:50:09 +02:00
Thomas Haller c210ad9d26 Revert "contrib/rpm: drop --with-libnm-glib from build_clean"
Since we restored libnm-glib in commit b027723e00,
also revert this commit.

This reverts commit 0750ff1f81.
2019-04-11 11:40:20 +02:00
Thomas Haller 8aefac804c connectivity: fix build with --disable-concheck
Fixes: 2cec94bacc ('connectivity: use systemd-resolved for resolving the check endpoint')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/155
2019-04-10 21:22:22 +02:00
Thomas Haller ad77eed0d5 all: merge branch 'th/strsplit'
https://github.com/NetworkManager/NetworkManager/pull/332
2019-04-10 15:06:21 +02:00
Thomas Haller a1425a4c91 shared: pre-calculate number of tokens in nm_utils_strsplit_set_full()
Instead of growing the buffer for the tokens (and reallocating),
do one pre-run over the string and count the delimiters. This
way we know how much space we need and we don't need to
reallocate.

Interestingly, this is notably slower than the previous implementation,
because previously if would not bother determining the right number of
tokens but just over-allocate with a reasonable guess of 8 and grow the
buffer exponentially. Still, I like this better because while it may
be slower in common scenarios, it allocates the exact number of buffer
space.
2019-04-10 15:05:57 +02:00
Thomas Haller c1f340401f ifcfg-rh: various cleanups using the cleanup attribute 2019-04-10 15:05:57 +02:00
Thomas Haller 3e0366a3ff all: replace g_strsplit_set() by nm_utils_strsplit_set*() 2019-04-10 15:05:57 +02:00
Thomas Haller 34e60bf228 cli: cleanup split_required_fields_for_con_show()
- return early and use cleanup attribute for freeing memory
- use nm_utils_strsplit_set_with_empty() instead of g_strsplit_set().
2019-04-10 15:05:57 +02:00
Thomas Haller c9ca7d0637 cli: cleanup nm_vpn_openconnect_authenticate_helper() 2019-04-10 15:05:57 +02:00
Thomas Haller b33e2b72da ibft: cleanup read_connections() 2019-04-10 15:05:57 +02:00
Thomas Haller a55c10754a dcb: cleanup do_helper() in "nm-dcb.c" 2019-04-10 15:05:57 +02:00
Thomas Haller 994df9244f dhcp: cleanup nm_dhcp_dhclient_create_config() 2019-04-10 15:05:57 +02:00
Thomas Haller e072489cc6 dhcp: cleanup nm_dhcp_dhclient_read_duid() 2019-04-10 15:05:57 +02:00
Thomas Haller be4fd39ab9 dhcp: cleanup grab_request_options() 2019-04-10 15:05:57 +02:00
Thomas Haller f00d71cec1 dhcp: cleanup nm_dhcp_dhclient_save_duid() 2019-04-10 15:05:57 +02:00
Thomas Haller a15e70889c dhcp: cleanup ip4_process_dhclient_rfc3442_routes()
- use nm_utils_strsplit_set_full() instead of g_strsplit_set() to avoid allocating
  a full strv array.
- refactor the code to return early and use cleanup attribute for freeing
  memory.
- return TRUE/FALSE from process_dhclient_rfc3442_route(). It's simpler to
  understand than returning the moved pointer and a success output variable.
2019-04-10 15:05:57 +02:00
Thomas Haller 5c1f93943e shared: add NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY flag for nm_utils_strsplit_set_full()
Previously, nm_utils_strsplit_set_full() would always remove empty
tokens. Add a flag NM_UTILS_STRSPLIT_SET_FLAGS_PRESERVE_EMPTY to avoid
that.

This makes nm_utils_strsplit_set_full() return the same result as
g_strsplit_set() and a direct replacement for it -- except for "",
where we return %NULL.
2019-04-10 15:05:57 +02:00
Thomas Haller 453b3ea362 shared: refactor allowed-escaped handling in nm_utils_strsplit_set_full()
Drop the next_char() and is_delimiter() macros. They are difficult to
understand, because they both have a state-variable (escaped).
Instead, the state of whether we handle an escape or not, shall only
depend on the current line of code.
2019-04-10 15:05:57 +02:00
Thomas Haller e2217a26e7 shared: refactor lookup of delimiter tables in nm_utils_strsplit_set_full() 2019-04-10 15:05:57 +02:00
Thomas Haller ce456f5b77 all: don't accept %NULL as delimiters for nm_utils_strsplit_set()
The caller should make a conscious decision which delimiters to use.
Unfortunately, there is a variety of different demiters in use. This
should be unitfied and the callers should use one of a few specific
set of delimiters.

This could be unified by (re)using a define as delimiters, like

   strv = nm_utils_strsplit_set_full (value, MULTILIST_WITH_ESCAPE_CHARS, NM_UTILS_STRSPLIT_SET_FLAGS_ALLOW_ESCAPING);

where MULTILIST_WITH_ESCAPE_CHARS has a particular meaning that should
be reused for similar uses.

However, leaving the delimiter at NULL is not good because it's unclear who
wants that default behavior (and what the default should be). Don't allow that.

There are almost no callers that relied on this default anyway.
2019-04-10 15:05:57 +02:00
Thomas Haller 84f2037648 shared: add flags argument to nm_utils_strsplit_set()
It will be useful to extend nm_utils_strsplit_set() with various
flavors and subtly different behaviors. Add a flags argument to
support these.
2019-04-10 15:05:57 +02:00
Thomas Haller 700a32e5dd cli: fix memleak in nm_vpn_openconnect_authenticate_helper() 2019-04-10 15:05:57 +02:00
Francesco Giudici 3f62c49295 merge: branch 'fg/checkpoint-devices-rh1578335-pt2'
https://bugzilla.redhat.com/show_bug.cgi?id=1578335

https://github.com/NetworkManager/NetworkManager/pull/316
2019-04-10 10:44:18 +02:00
Francesco Giudici fd43a5b430 checkpoint: hold a reference to the NMManager object
since it is now required in the dispose (), ensure it is there
2019-04-10 10:43:09 +02:00
Francesco Giudici 0e2f7ac7b5 nm-checkpoint: drop reference to NM_DEVICE objects on removal signal
Drop the reference to the objects as soon as the devices are removed.
Move DeviceCheckpoint objects tracking removed devices to a separate
list.
2019-04-10 10:42:58 +02:00
Francesco Giudici 3555d5d844 nm-checkpoint: move logic to restore a connection to a separate function
This will soon be handy to properly restore deleted software devices.
2019-04-10 10:39:11 +02:00
Thomas Haller f5e8bbc8e0 libnm,core: enable "onlink" flags also for IPv6 routes
Previously, onlink (RTNH_F_ONLINK) did not work for IPv6.
In the meantime, this works in kernel ([1], [2]). Enable it also
in NetworkManager.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fc1e64e1092f62290d59151d16f9de0210e303c8
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=68e2ffdeb5dbf54bc3a0684aa4e73c6db8675eed

https://github.com/NetworkManager/NetworkManager/pull/337
2019-04-10 09:02:35 +02:00
Beniamino Galvani c48698d747 team: clean up state when connection to teamd fails
If NM fails to connect to teamd, it currently just sets the device
state to FAILED and waits that deactivate() is called later. However,
the 5 seconds timeout on teamd process start can hit in the meantime,
which fails with an assertion "nm_device_is_activating (device)".

Clean up the device state when the connection to teamd fails.

https://bugzilla.redhat.com/show_bug.cgi?id=1697900
2019-04-10 08:44:05 +02:00
Thomas Haller 3a2e002a2e dns,dbus: merge branch 'th/systemd-resolved-dbus-activated'
https://github.com/NetworkManager/NetworkManager/pull/336
2019-04-09 20:40:42 +02:00
Thomas Haller e04dc445ec dbus: cache GetConnectionUnixProcessID and GetConnectionUnixUser
We call GetConnectionUnixProcessID and GetConnectionUnixUser *a lot*.
And we do so synchronously. Both is a problem.

To avoid the first problem, cache the last few requests with each cached
value being valid for one second.

On a quick test, this saves 98% of the requests:

     59 GetConnectionUnixProcessID(*)
   3201 GetConnectionUnixProcessID(*) (served from cache)
     59 GetConnectionUnixUser(*)
   3201 GetConnectionUnixUser(*) (served from cache)

Note that now as we serve requests from the cache, it might be the case
that the D-Bus endpoint already disconnected. Previously, the request would
have failed but now we return the cached user-id and process-id. This
problem is mitigated by only caching the values for up to one second.
Also, it's not really a problem because we cache sender names. Those
are supposed to be unique and not repeat. So, even if the peer already
disconnected, it is still true that the corresponding PID/UID was as
we have cached it. We don't use this API for checking whether the peer
is still connected, but what UID/PID it has/had. That answer is still
correct for the cached value after the peer disconnected.
2019-04-09 20:40:18 +02:00
Thomas Haller 5d86f60526 dns: use GDBusConnection instead of GDBusProxy in "nm-dns-systemd-resolved.c"
The proxy does nothing for us, except overhead.

We can directly subscribe to "NameOwnerChanged" signals on the
GDBusConnection. Also, instead of asynchronously creating the
GDBusProxy, asynchronously call "GetNameOwner". That's what the
proxy does anyway.

GDBusConnection is actually a decent API. We don't need another layer on
top of that, for functionality that we don't use.

Also, don't use G_BUS_TYPE_SYSTEM, but use the GDBusConnection that
also the bus-manager uses. For all practical purposes, that is the
connection was want to use also in NMDnsSystemdResolved.
2019-04-09 20:40:18 +02:00
Thomas Haller 5e77b2d660 dbus: don't use GDBusProxy in NMDBusManager
Unnecessary overhead that simplifies nothing.
2019-04-09 20:40:18 +02:00
Thomas Haller 4058b01c42 dbus: remove unused function nm_dbus_manager_get_connection()
nm_dbus_manager_get_connection() was unused. Also, we already have
nm_dbus_manager_get_dbus_connection() which does the same (and is
used).
2019-04-09 20:40:18 +02:00
Thomas Haller b3a76da96d dbus/trivial: rename field for D-Bus connection/proxy in NMDBusManagerPrivate
The terms "connection" and "proxy" are used all over the place.
Rename the fields, to give them a more unique name.
2019-04-09 20:40:18 +02:00
Thomas Haller 2ab90719a2 connectivity: avoid D-Bus activating systemd-resolved when we know it's not used
Every (failed) attempt to D-Bus activate a service results in log-messages
from dbus-daemon. It must be avoided to spam the logs that way.

Let connectivity check not only ask whether systemd-resolved is enabled
(and NetworkManager would like to push information there), but also
whether it looks like the service is actually available. That is,
either it has a name-owner or it's not blocked from starting.

The previous workaround was to configure main.systemd-resolved=no
in NetworkManager.conf. But that requires explict configuration.
2019-04-09 20:40:18 +02:00
Thomas Haller 7ae434b37c dns: only update systemd-resolved when it exists
Previously, we would create the D-Bus proxy without
%G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
flag.

That means, when systemd-resolved was not available or masked, the creation
of the D-Bus proxy would fail with

  dns-sd-resolved[0x561905dc92d0]: failure to create D-Bus proxy for systemd-resolved: Error calling StartServiceByName for org.freedesktop.resolve1: GDBus.Error:org.freedesktop.systemd1.NoSuchUnit: Unit dbus-org.freedesktop.resolve1.service not found.

and never retried.

Now, when creating the D-Bus proxy don't autostart the instance.
Instead, each D-Bus call will try to poke and start the service.

There is a problem however: if systemd-resolved is not available, then
we must not constantly trying to start it, because it results in a slur
or syslog messages from dbus-daemon:

  dbus-daemon[991]: [system] Activating via systemd: service name='org.freedesktop.resolve1' unit='dbus-org.freedesktop.resolve1.service' requested by ':1.23' (uid=0 pid=1012 comm="/usr/bin/NetworkManager --no-daemon ")
  dbus-daemon[991]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.resolve1.service': Unit dbus-org.freedesktop.resolve1.service not found.
  dbus-daemon[991]: [system] Activating via systemd: service name='org.freedesktop.resolve1' unit='dbus-org.freedesktop.resolve1.service' requested by ':1.23' (uid=0 pid=1012 comm="/usr/bin/NetworkManager --no-daemon ")

Avoid that by watching the name owner.

But, since systemd-resolved is D-Bus activated, watching the name owner
alone is not enough to know whether we should try to autostart the service.

Instead:

 - if we have a name owner, assume the service runs and we send the update

 - if we have no name owner, and we did not recently try to start
   the service by name, poke it via "StartServiceByName". The idea
   is, that in total we only try this once and remember a previous
   attempt in priv->try_start_blocked.

 - if we get a name-owner, priv->try_start_blocked gets reset.
   Either it was us who started the service, or somebody else.
   Either way, we are good to send updates again.

The nice thing is that we only try once to start resolved and only
generate one logging message from dbus-daemon about failure to do so.
But still, after blocking start on failure, when somebody else starts
resolved, we notice it and start using it again.
2019-04-09 20:40:18 +02:00