Commit graph

914 commits

Author SHA1 Message Date
Thomas Haller
9761e38f7e
dhcp: fix handling of NM_DHCP_STATE_NOOP
The "noop" state is almost unused, however, nm_dhcp_set_state()
has a check "if (new_state >= NM_DHCP_STATE_TIMEOUT)", so the order
of the NOOP state matters.

Fix that by reordering.

Also, just return right away from NOOP.
2022-05-16 16:37:41 +02:00
Thomas Haller
f102051a29
dhcp: drop most of NMDhcpState usage from nm_dhcp_client_handle_event()
NMDhcpState is very tied to events from dhclient. But most of these
states we don't care about, and NMDhcpClient definitely should abstract
and hide them.

We should repurpose NMDhcpState to simpler state. For that, first drop
the state from nm_dhcp_client_handle_event().

This is only the first step (which arguably makes the code more
complicated, because reason_to_state() gets spread out and the logic
happens more than once). That will be addressed next.
2022-05-16 16:37:40 +02:00
Thomas Haller
70cbf3dc1e
dhcp/trivial: add comment about nm_dhcp_utils_merge_new_dhcp6_lease() 2022-05-16 16:37:40 +02:00
Thomas Haller
8d121b17b5
dhcp: move code in "nm-dhcp-client.c"
So that it makes more sense, related parts are closer together.
2022-05-16 16:34:32 +02:00
Thomas Haller
1093e66776
dhcp: minor code cleanups in "nm-dhcp-client.c" 2022-05-16 16:34:32 +02:00
Thomas Haller
c8542a5d50
dhcp: use GSource for watching child process instead of numeric source id 2022-05-16 16:34:31 +02:00
Thomas Haller
98f7081db2
dhcp: minor cleanup in maybe_add_option()
- return early to avoid nested block.
- use NM_STR_HAS_PREFIX() over g_str_has_prefix(), because that
  can be inlined and only accepts a C literal as prefix argument.
2022-05-16 16:34:31 +02:00
Thomas Haller
cb2ab420a2
dhcp: don't assert against untrusted data in maybe_add_option() 2022-05-16 16:34:31 +02:00
Thomas Haller
668d8050a5
dhcp: cleanup bytearray_variant_to_string()
- the code comment was unclear/wrong. If something comes from an environment
  variables it is *NOT* UTF-8 safe. Also, we convert all non-ASCII characters,
  not only non UTF-8 characters.

- as we already convert the string to ASCII, the check whether it's UTF-8
  is bogus.

- using GString is unnecessary.
2022-05-16 16:34:31 +02:00
Thomas Haller
9b9c07530c
dhcp: cleanup reason_to_state() in "nm-dhcp-client.c"
- use NM_IN_STRSET_ASCII_CASE().
- don't use else block after we return.
- don't accept the "iface" argument just for logging. The caller
  can do the logging, if they wish.
2022-05-16 16:32:22 +02:00
Thomas Haller
a5a4aea2e6
wifi: support "802-1x.phase1-auth-flags=tls-allow-unsafe-renegotiation" flag
For details, read the linked sources.

This requires a new supplicant option, but it seems that supplicant
will silently ignore unrecognized options.

https://bugzilla.redhat.com/show_bug.cgi?id=2072070#c48
https://lists.infradead.org/pipermail/hostap/2022-May/040522.html
https://w1.fi/cgit/hostap/commit/?id=566ce69a8d0e64093309cbde80235aa522fbf84e

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1218
2022-05-16 12:09:11 +02:00
Beniamino Galvani
7a3774f62d dhcp: log messages about invalid DHCP options
Log messages when invalid DHCP options are found. For example:

  <info> dhcp4 (eth0): error parsing DHCP option 6 (domain_name_servers): address 0.0.0.0 is ignored
  <info> dhcp4 (eth0): error parsing DHCP option 12 (host_name): '.example.com' is not a valid DNS domain
  <info> dhcp4 (eth0): error parsing DHCP option 26 (interface_mtu): value 60 is smaller than 68

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1225
2022-05-16 09:49:06 +02:00
Thomas Haller
2875ad7e50
dhcp: fix ignoring addresses with DHCPv6 otherconf (O flag)
With O flag (otherconf mode), don't add the IPv6 addresses to the
collected lease.

An alternative would be to add it initially, but ignore it when
merging the configuration in NML3Cfg. The idea of that would be that if
the mode switches from otherconf to managed, that we already have the
address. However, depending on the mode we made a different DHCPv6
request. That means, if the mode changes we anyway cannot just use the
previous lease, because it might not contain all the information. So
it seems better to ignore the address early.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://bugzilla.redhat.com/show_bug.cgi?id=2083968
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/953

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1220
2022-05-11 19:06:00 +02:00
Thomas Haller
41df480fdd
dhcp: fix setting "-S" flag for dhclient info-only requests
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-05-11 19:03:46 +02:00
Thomas Haller
bacd3e1482
dhcp: always explicitly set request/information-request flags for internal DHCPv6 client
It seems clearer to explicitly set this always, and not rely on the
defaults.
2022-05-11 19:03:45 +02:00
Thomas Haller
6ebc622303
audit: handle error from audit_encode_nv_string()
audit_encode_nv_string() is documented that it might fail. Handle
the error.

Also, the returned string was allocated with malloc(). We must free
that with free()/nm_auto_free, not g_free()/gs_free.
2022-05-11 17:06:12 +02:00
Lubomir Rintel
b0240418b3 bridge: assume wired settings are there
We can now assert instead of checking.

Also, let's move the whole get-the-mtu part down closer to where it is
actually used.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1208
2022-05-10 21:41:19 +02:00
Lubomir Rintel
41291ef773 core/connection: ensure wired settings are around for bridges
Bridges are wired ethernet bridges, it makes sense for them to have
wired ethernet settings.

Ensuring they always exist makes reapplying the MTU changes more
convenient. The MTU for bridges is taken from wired settings, making it
impossible to change and reapply it for connections that lack them
(as reapply doesn't really cope well with addition and removal of
settings).

https://bugzilla.redhat.com/show_bug.cgi?id=2076131
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1208
2022-05-10 21:41:19 +02:00
Fernando Fernandez Mancera
62f461ebeb bond: drop _get_option_or_default() and use _get_option_normalized()
Currently nm_setting_bond_get_option_normalized() and
nm_setting_bond_get_option_or_default() are identical functions. As the
first one is exposed as public API and has a better name, let's drop the
second one.
2022-05-10 12:42:11 +02:00
Thomas Haller
9a69bc8d84
l3cfg: refresh platform cache before creating prune list during L3Cfg commit
It seems, we should make decisions based on the latest state.
Make sure to process all pending netlink events.
2022-05-09 19:21:59 +02:00
Thomas Haller
518f6124c6
l3cfg: fix clearing IPv6 temporary addresses to avoid stale addresses
IPv6 temporary addresses are configured by kernel, with the
"ipv6.ip6-privacy" setting ("use_tempaddr" sysctl) and the
IFA_F_MANAGETEMPADDR flag.

As such, the idea was that during reapply we would not remove them.
However, that is wrong.

The only case when we want to keep those addresses, is if during reapply
we are going to configure the same primary address (with mngtmpaddr
flag) again. Otherwise, theses addresses must always go away.

This is quite serious. This not only affects Reapply. Also during disconnect
we clear IP configuration via l3cfg.
Have an ethernet profile active with "ipv6.ip6-privacy". Unplug
the cable, the device disconnects but the temporary IPv6 address is not
cleared. As such, nm_device_generate_connection() will now generate
an external profile (with "ipv6.method=disabled" and no manual IP addresses).
The result is, that the device cannot properly autoconnect again,
once you replug the cable.

This is serious for disconnect. But I could not actually reproduce the
problem using reapply. That is, because during reapply we usually
toggle ipv6_disable sysctl, which drops all IPv6 addresses. I still
went through the effort of trying to preserve addresses that we still
want to have, because I am not sure whether there are cases where we
don't toggle ipv6_disable. Also, doing ipv6_disable during reapply is
bad anyway, and we might want to avoid that in the future.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-05-09 19:21:58 +02:00
Thomas Haller
532f3e34a8
glib-aux: drop nm_str_buf_init() for NM_STR_BUF_INIT()
NM_STR_BUF_INIT() and nm_str_buf_init() were pretty much redundant. Drop one of
them.

Usually our pattern is that we don't have functions that return structs.
But NM_STR_BUF_INIT() returns a struct, because it's convenient to use
with

  nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(...);

So use that variant instead.
2022-05-09 19:18:30 +02:00
Beniamino Galvani
77c8b2960a device: commit l3cfg on link change only when the device is activating
On link change, the configuration should be reapplied only when the
device is activating.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://bugzilla.redhat.com/show_bug.cgi?id=2079054
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1216
2022-05-09 14:58:57 +02:00
Beniamino Galvani
af9ed3eb2f ovs: add FIXME about cancellable operations 2022-05-03 13:19:24 +02:00
Beniamino Galvani
c503f5b214 ovs: attach port asynchronously
The attach operation needs to be asynchronous as we should wait the
result from ovsdb.

https://bugzilla.redhat.com/show_bug.cgi?id=2052441
2022-05-03 13:19:24 +02:00
Beniamino Galvani
9fcbc6b37d device: make attach_port() asynchronous
For some device types the attach-port operation doesn't complete
immediately. NMDevice needs to wait that the operation completes
before proceeding (for example, before starting stage3 for the port).

Change attach_port() so that it can return TERNARY_DEFAULT to indicate
that the operation will complete asynchronously. Most of devices are
not affected by this and can continue returning TRUE/FALSE as before
without callback.
2022-05-03 13:19:24 +02:00
Beniamino Galvani
bcc958c411 device: rename {enslave,release}_slave() to {attach,detach}_port()
Rename the enslave_slave() and release_slave() device methods to
attach_port() and detach_port().
2022-05-03 13:19:23 +02:00
Beniamino Galvani
6f6c044739 ovsdb: fix memory leak
@error was leaked when created inside the function.

While at it, remove the goto.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')
2022-05-03 13:19:23 +02:00
Beniamino Galvani
6ab5c4e578 core: save DHCP lease information in state file in /run
DHCP leases for a given interface are already exported on D-Bus
through DHCP4Config and DHCP6Config objects. It is useful to have the
same information also available on the filesystem so that it can be
easily used by scripts.

NM already saves some information about DHCP leases in /var, however
that directory can only be accessed by root, for good reasons.

Append lease options to the existing state file
/run/NetworkManager/devices/$ifindex. Contrary to /var this directory
is not persistent, but it seems more correct to expose the lease only
when it is active and not after it expired or after a reboot.

Since the file is in keyfile format, we add new [dhcp4] and [dhcp6]
sections; however, since some options have the same name for DHCPv4
and DHCPv6, we add a "dhcp4." or "dhcp6." prefix to make the parsing
by scripts (e.g. via "grep") easier.

The option name is the same we use on D-Bus. Since some DHCPv6 options
also have a "dhcp6_" prefix, the key name can contain "dhcp6" twice.

The new sections look like this:

  [dhcp4]
  dhcp4.broadcast_address=172.25.1.255
  dhcp4.dhcp_lease_time=120
  dhcp4.dhcp_server_identifier=172.25.1.4
  dhcp4.domain_name_servers=172.25.1.4
  dhcp4.domain_search=example.com
  dhcp4.expiry=1641214444
  dhcp4.ip_address=172.25.1.182
  dhcp4.next_server=172.25.1.4
  dhcp4.routers=172.25.1.4
  dhcp4.subnet_mask=255.255.255.0

  [dhcp6]
  dhcp6.dhcp6_name_servers=fd01::1
  dhcp6.dhcp6_ntp_servers=ntp.example.com
  dhcp6.ip6_address=fd01::1aa
2022-05-03 09:12:12 +02:00
Beniamino Galvani
96d8637ced core: add nm_dhcp_config_get_option_values()
Introduce a function to return an array of name-value tuples for DHCP
options.
2022-05-03 09:08:16 +02:00
Beniamino Galvani
15a4211303 dhcp: fix logging domain
Fix wrong domain when logging a lease:

  dhcp6 (veth0):   valid_lft 7200
  dhcp6 (veth0):   preferred_lft 5400
  dhcp6 (veth0):   address fd00:db8:db8::11:2233:4455
  dhcp (veth0):   domain search 'domain'
2022-05-03 09:07:29 +02:00
Beniamino Galvani
f20ac6bdc7 dhcp: improve logging for DHCPv6 merged leases
Instead of logging the event-id, which is composed from options that
are already visible in the log, it's more interesting to log that the
lease was merged.
2022-05-03 09:07:29 +02:00
Thomas Haller
6a04bcc59d
core: transfer ownership of strbuf data in _fw_nft_set()
In practice there is little difference.

Previously, "strbuf" would own the string until the end of the function,
when the "nm_auto_str_buf" cleanup attribute destroys it. In the
meantime, we would pass it on to _fw_nft_call_sync(), which in fact
won't access the string after returning.

Instead, we can just transfer ownership to the GBytes instance. That seems
more logical and safer than aliasing the buffer owned by NMStrBuf with
a g_bytes_new_static(). That way, we don't add a non-obvious restriction
on the lifetime of the string. The lifetime is now guarded by the GBytes
instance, which, could be referenced and kept alive longer.

There is also no runtime/memory overhead in doing this.
2022-05-02 16:43:42 +02:00
Fernando Fernandez Mancera
bf5927b978 l3cfg: drop NM_L3_CFG_COMMIT_TYPE_ASSUME and assume_config_once
ASSUME is causing more troubles than benefits it provides. This patch is
dropping NM_L3_CFG_COMMIT_TYPE_ASSUME and assume_config_once. NM3LCfg
will commit as if the sys-iface-state is MANAGED.

This patch is part of the effort to remove ASSUME from NetworkManager.
After ASSUME is dropped when starting NetworkManager it will take full
control of the interface, re-configuring it. The interface will be
managed from the start instead of assumed and then managed.

This will solve the situations where an interface is half-up and then a
restart happens. When NetworkManager is back it won't add the missing
addresses (which is what assume does) so the interface will fail during
the activation and will require a full activation.

https://bugzilla.redhat.com/show_bug.cgi?id=2050216
https://bugzilla.redhat.com/show_bug.cgi?id=2077605
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1196
2022-04-28 10:48:56 +02:00
Thomas Haller
6804c2ba04
device: set MTU after attaching bond port
When attaching a bond port, kernel will reset the MTU of the port ([1],
[2]). Configuring a different MTU on the port seems not a sensible
thing for the user to do.

Still, before commit e67ddd826f ('device: commit MTU during stage2')
we would first attach the bond port before setting the MTU. That
changed, and now the MTU set by kernel wins.

Btw, this change in behavior happens because we attach the port in
stage3 (ip-config), which seems an ugly thing to do.

Anyway, fix this by setting the MTU after attaching the ports, but still
in stage3.

It is probably not sensible for the user to configure a different MTU.
Still, if the user requested it by configuration, we should apply it.
Note that NetworkManager has some logic to constrain the MTU based on
the parent/child and controller/port. In many regards however, NetworkManager
does not fully understand or enforce the correct MTU and relies on the
user to configure it correctly. After all, if the user misconfigures the
MTU, the setup will have problems anyway (and in many cases neither
kernel nor NetworkManager could know that the configuration is wrong).

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/bonding/bond_main.c?h=v5.17#n3603
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/bonding/bond_main.c?h=v5.17#n4372

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

Fixes: e67ddd826f ('device: commit MTU during stage2')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1199
2022-04-27 12:53:18 +02:00
Thomas Haller
7fcfc5ccb3
all: hardcode HOST_NAME_MAX to 64
On glibc, HOST_NAME_MAX is defined as 64. Also, Linux'
sethostname() enforces that limit (__NEW_UTS_LEN). Also,
`man gethostname` comments that HOST_NAME_MAX on Linux is
64.

However, when building against musl, HOST_NAME_MAX is defined as 255.
That seems wrong. We use this limit to validate the hostname, and that
should not depend on the libc or on the compilation.

Hardcode the value to 64.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1197
2022-04-26 17:54:56 +02:00
Thomas Haller
747d7dcfe3
systemd: drop "nm-sd-utils-core.h" and nm_sd_utils_id128_get_machine()
This was only for unit testing, to check whether our reader
for "/etc/machine-id" agrees with systemd's.

That unit test was anyway flawed, because it actually accesses
the machine-id on the test system.

Anyway. Drop this. Most likely our parser is good enough, and
if we get a bug report with a defect, we can unit test against
that.
2022-04-20 12:07:04 +02:00
Thomas Haller
c4f5111920
all: use nm_hostname_is_valid() instead of systemd code 2022-04-20 12:07:04 +02:00
Thomas Haller
202d9c36c3
systemd: drop systemd path helpers from "nm-sd-utils-shared.h" adapter header
They are now unused, and replaced by nm_path*() utils in glib-aux (which
are forks of the systemd code).
2022-04-20 12:07:03 +02:00
Thomas Haller
f4c7b5b7b7
all: avoid using systemd path utils 2022-04-20 12:07:03 +02:00
Thomas Haller
82cac62fe2
systemd: drop nm_sd_utils_unbase64{char,mem}() wrappers
They are unused now.
2022-04-20 12:07:03 +02:00
Thomas Haller
3571292d97
glib-aux: treat '=' as special character in nm_unbase64char()
This will be useful.
2022-04-20 12:05:17 +02:00
Thomas Haller
b2a4d706f8
settings: use GSource instead of numeric ID in NMSettings
I find it better style to use GSource pointers for tracking pending
sources.
2022-04-20 11:53:14 +02:00
Thomas Haller
9046975a81
settings: fix assertion failure in NMSettings' _startup_complete_check()
This probably has no bad effects when building without more-asserts.

  #0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
  #1  0x00007f7ead0564a3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
  #2  0x00007f7ead009d06 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
  #3  0x00007f7eacfdc7d3 in __GI_abort () at abort.c:79
  #4  0x00007f7ead1fed4c in g_assertion_message (domain=<optimized out>, file=<optimized out>, line=<optimized out>, func=<optimized out>, message=<optimized out>) at ../glib/gtestutils.c:3065
  #5  0x00007f7ead25f98f in g_assertion_message_expr (domain=0x560964f8b7e9 "nm", file=0x560964f83da8 "src/core/settings/nm-settings.c", line=640, func=0x56096504a390 <__func__.44.lto_priv.1> "_startup_complete_check", expr=<optimized out>) at ../glib/gtestutils.c:3091
  #6  0x0000560964ed710e in _startup_complete_check (self=0x560966d1d030, now_msec=<optimized out>) at src/core/settings/nm-settings.c:640
  #7  0x0000560964ed7d9b in _startup_complete_notify_connection (self=0x560966d1d030, sett_conn=<optimized out>, forget=<optimized out>) at src/core/settings/nm-settings.c:704
  #8  0x0000560964edd070 in _connection_changed_delete (self=0x560966d1d030, storage=<optimized out>, sett_conn=0x560966cedbc0, allow_add_to_no_auto_default=<optimized out>) at src/core/settings/nm-settings.c:1244
  #9  0x0000560964edd948 in _connection_changed_process_one (update_reason=(NM_SETTINGS_CONNECTION_UPDATE_REASON_IGNORE_PERSIST_FAILURE | NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET | unknown: 0x5400), override_sett_flags=0, sett_mask=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, sett_flags=1725440360, allow_add_to_no_auto_default=0, sett_conn_entry=0x560966d1d030, self=<optimized out>) at src/core/settings/nm-settings.c:1294
  #10 _connection_changed_process_all_dirty (self=<optimized out>, allow_add_to_no_auto_default=<optimized out>, sett_flags=<optimized out>, sett_mask=<optimized out>, override_sett_flags=<optimized out>, update_reason=<optimized out>) at src/core/settings/nm-settings.c:1335
  #11 0x0000560964eeb8ec in nm_settings_delete_connection (allow_add_to_no_auto_default=648659760, sett_conn=<optimized out>, self=0x560966d1d030) at src/core/settings/nm-settings.c:2457
  #12 nm_settings_connection_delete (self=<optimized out>, allow_add_to_no_auto_default=648659760) at src/core/settings/nm-settings-connection.c:637
  #13 0x0000560964eebebd in delete_auth_cb (self=0x560966cedbc0, context=0x7f7e9c0170a0, subject=0x560966cc5ed0, error=0x0, data=<optimized out>) at src/core/settings/nm-settings-connection.c:1877
  #14 0x0000560964ec9778 in pk_auth_cb (auth_manager=<optimized out>, auth_call_id=<optimized out>, is_authorized=1, is_challenge=<optimized out>, auth_error=<optimized out>, user_data=0x560966e16980) at src/core/settings/nm-settings-connection.c:1262
  #15 0x0000560964db9a28 in _call_id_invoke_callback (error=0x0, is_challenge=0, is_authorized=1, call_id=0x560966ddeb00) at src/core/nm-auth-manager.c:180
  #16 _call_on_idle (user_data=user_data@entry=0x560966ddeb00) at src/core/nm-auth-manager.c:284
  #17 0x00007f7ead23111b in g_idle_dispatch (source=0x560966e50190, callback=0x560964db9900 <_call_on_idle>, user_data=0x560966ddeb00) at ../glib/gmain.c:5848
  #18 0x00007f7ead234d4f in g_main_dispatch (context=0x560966cd1e20) at ../glib/gmain.c:3337
  #19 g_main_context_dispatch (context=0x560966cd1e20) at ../glib/gmain.c:4055
  #20 0x00007f7ead289608 in g_main_context_iterate.constprop.0 (context=0x560966cd1e20, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4131
  #21 0x00007f7ead234463 in g_main_loop_run (loop=0x560966caf010) at ../glib/gmain.c:4329
  #22 0x0000560964cb7515 in main (argc=<optimized out>, argv=<optimized out>) at src/core/main.c:509

Fixes: 3df662f534 ('settings: rework wait-device-timeout handling and consider device compatibility')
2022-04-20 11:53:13 +02:00
Thomas Haller
80c9e2d9ec
device: prevent IP state from reaching ready while DNS update pending
The goal would be to ensure that a device cannot move to activated,
while a DNS update is still pending.

This does not really work for most cases. That is, because NMDevice does
not directly push DNS updates to NMDnsManager, instead, NMPolicy is
watching all device changes, and doing it. But when NMPolicy decides to
to that, may not be the right moment.

We really should let NMDevice (or better, NML3Cfg) directly talk to
NMDnsManager. Why not? They have all the information when new DNS
configuration is available. The only thing that NMPolicy does on top of
that, is determining which device has the best default route. NMPolicy
could continue to do that (or maybe NMDnsManager could), but the update
needs to be directly triggered by NMDevice/NML3Cfg.
2022-04-15 09:04:31 +02:00
Thomas Haller
6c27e58d8d
core: delay startup complete while we have pending DNS updates
While we have DNS updates pending, we cannot reach startup complete.
2022-04-15 09:04:31 +02:00
Thomas Haller
6e35cf4a7d
core: add nm_manager_get_dns_manager() getter
nm_dns_manager_get() is already a singleton. So users usually
can just get it whenever they need -- except during shutdown
after the singleton was destroyed. This is usually fine, because
users really should not try to get it late during shutdown.

However, if you subscribe a signal handler on the singleton, then you
will also eventually want to unsubscribe it. While the moment when you
subscribe it is clearly not during late-shutdown, it's not clear how
to ensure that the signal listener gets destroyed before the DNS manager
singleton.

So usually, whenever you are going to subscribe a signal, you need to
make sure that the target object stays alive long enough. Which may
mean to keep a reference to it.

Next, we will have NMDevice subscribe to the singleton. With above said,
that would mean that potentially every NMDevice needs to keep a
reference to the NMDnsManager. That is not best. Also, later NMManager
will face the same problem, because it will also subscribe to
NMDnsManager.

So, instead let NMManager own a reference to the NMDnsManager. This
ensures the lifetimes are properly guarded (NMDevice also references
NMManager already).

Also, access nm_dns_manager_get() lazy on first use, to only initialize
it when needed the first time (which might be quite late).
2022-04-15 09:04:30 +02:00
Thomas Haller
cef5b8dd46
dns: prevent update-pending to hang indefinitely
For example, if you have a dnsmasq service running and bound to port 53, then
NetworkManager's [main].dns=dnsmasq will fail to start. And we keep retrying
to start it. But then update pending would hang indefinitely, and devices could
not become active. That must not happen.

Give the DNS update only 5 seconds. If it's not done by then, assume we
have a problem and unblock.
2022-04-15 09:04:30 +02:00
Thomas Haller
f2abcf2082
dns/dnsmasq: implement update-pending flag in NMDnsDnsmasq plugin
We want to know when we are busy (have an update pending or on-going).
Implement that.
2022-04-15 09:04:30 +02:00
Thomas Haller
ccf0e8d327
dns/dnsmasq: use GSource for timeout in NMDnsDnsmasq 2022-04-15 09:04:30 +02:00