Commit graph

891 commits

Author SHA1 Message Date
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
Thomas Haller
5da17c689b
dns/unbound: drop deprecated "unbound" DNS plugin
The "unbound" DNS plugin was very rudimentary and is deprecated since
commit 4a2fe09853 ('man: mark [main].dns=unbound as deprecated') (Jun
2021).

It is part of dnssec-trigger tool, but the dnssec-trigger tool doesn't
actually use it. Instead it installs a dispatcher script
"/usr/lib/NetworkManager/dispatcher.d/01-dnssec-trigger".

Especially, since the plugin requires "/usr/libexec/dnssec-trigger-script",
which is provided by "dnssec-trigger" package on Fedora. At the same
time, the package provides the dispatcher script. So I don't this works
or anybody is using this.

https://mail.gnome.org/archives/networkmanager-list/2022-April/msg00002.html
2022-04-15 09:04:30 +02:00
Thomas Haller
bbbb1b7339
dns/resolved: implement update-pending flag in NMDnsSystemdResolved plugin 2022-04-15 09:04:30 +02:00
Thomas Haller
a74a517f49
dns/resolved: track pending counter for D-Bus calls in NMDnsSystemdResolved
This is used to signal that an update is pending or in progress.
For this to work, we also need to implement the stop() handle.
Otherwise, we couldn't abort pending requests, which is necessary
during shutdown (not today, but in the future).
2022-04-15 09:04:30 +02:00
Thomas Haller
2f1feb9651
dns/resolved: use GPtrArray to collect ip datas in NMDnsSystemdResolved's update()
CList is a great, simple data structure. Especially, if we can embed it
into the data we track.

Here we just create a (temporary) list of pointers. A GPtrArray is the
better data structure for that.
2022-04-15 09:04:30 +02:00
Thomas Haller
eb25c9ecd2
dns/resolved: use nm_utils_hash_to_array_with_buffer() in NMDnsSystemdResolved's update()
We copy the content of the hash table to an array, so that we can sort
the entries and they have a defined order.

We are not only interested in the keys, but the keys and the values.
Hence, use nm_utils_hash_to_array_with_buffer() which gives both at
the same time.
2022-04-15 09:04:29 +02:00
Thomas Haller
51cec67253
dns/resolved: sort dirty interfaces to prune in "nm-dns-systemd-resolved.c"
When we do something where the order makes a visible difference,
we should do it in a consistent way, that does not depend on arbitray
things. Sort the ifindexes from dirty_interfaces hash table.
2022-04-15 09:04:29 +02:00
Thomas Haller
39b68d72d3
dns/resolved: add const to parameters in "nm-dns-systemd-resolved.c" 2022-04-15 09:04:29 +02:00
Thomas Haller
4564adfb53
dns/resolved: minor cleanups in "nm-dns-systemd-resolved.c" 2022-04-15 09:04:29 +02:00
Thomas Haller
a60b971003
dns: add update-pending property to NMDnsManager 2022-04-15 09:04:29 +02:00
Thomas Haller
b7ca08e971
dns: add "update-pending" state to NMDnsPlugin
Theoretically, this should be a GObject property, and not a signal.
But then I'd  also have to implement the get_property() function,
which is more hazzle than necessary. A signal will do nicely.
2022-04-15 09:04:29 +02:00
Thomas Haller
f68230fbe9
dns: call nm_dns_plugin_stop() also for NMDnsSystemdResolved instance
Currently NMDnsSystemdResolved does not implement "stop()". That is
about to change. Make sure to call stop before unreferencing the
instance.
2022-04-15 09:04:29 +02:00
Thomas Haller
0001a2fd0c
dns: fix NMDnsPluginPrivate and drop unused fields
NM_DNS_PLUGIN_GET_PRIVATE() macro was broken. Also NMDnsPluginPrivate
contained unused fields. Fix that.

The private data is unused at the moment, but will be used next.
Hence it is fixed and not removed.
2022-04-15 09:04:28 +02:00
Thomas Haller
068ca09d16
dns: obfuscate pointer value for NMDnsPlugin logging 2022-04-15 09:04:28 +02:00
Thomas Haller
f7b41fc18c
dns: avoid printing pointer value for NMDnsManager logging statements
We avoid printing raw pointer values. Also, in this case this is a
singleton, and we only create one instance of this type.

Note that we would still have printed the pointer instance while
constructing the instances, before setting it as singleton.

Just drop this.
2022-04-15 09:04:28 +02:00
Thomas Haller
bd95a5c0ec
dns: register NMDnsPlugin instance as wait-obj for shutdown
nm_shutdown_wait_obj_register_object() today has no practical effect.
In the future it will block shutdown until the object gets destroyed.
We will want that NMDnsPlugin gets wrapped up during shut down, before
quitting.
2022-04-15 09:04:28 +02:00
Thomas Haller
54119d4105
dhcp: drop internal systemd DHCPv4 client
This is long replaced by nettools' n-dhcp4 client.
Drop it.

We still require NMDhcpSystemd for the DHCPv6 client.

Note that "[main].dhcp=systemd" now falls back to the internal client.
But this option was undocumented and internal anyway.
2022-04-14 14:51:02 +02:00
Thomas Haller
b1575e814f
dhcp: don't use systemd's dhcp_lease_load() in nettools' n-dhcp4 ip4_start() 2022-04-14 14:51:02 +02:00
Thomas Haller
197e73ac7c
dhcp/dhclient: fix setting "src" attribute for certain routes
Fixes: 2dc7a3d9f9 ('dhcp: set "src" for DHCPv4 routes')
2022-04-13 10:43:27 +02:00
Thomas Haller
8e5f60dfd3
dhcp/nettools: reword code comment in dhcp4_event_cb()
Also drop the "FIXME" tag. There is nothing to fix here.
2022-04-13 10:27:50 +02:00
Thomas Haller
cb98616e02
ndisc/tests: relex check in test_dns_solicit_loop()
Dunno why this happens. Just silence it.

  nm:ERROR:../src/core/ndisc/tests/test-ndisc-fake.c:649:test_dns_solicit_loop: assertion failed (data.counter == 3): (2 == 3)
2022-04-12 18:45:29 +02:00
谢致邦 (XIE Zhibang)
b6eb237a27
supplicant: Disable WPA3 transition mode when PMF is set to disabled
According to WPA3_Specification_v3.0 section 2.3, when operating in
WPA3-Personal transition mode an AP:

- shall set MFPC to 1, MFPR to 0.

Therefore, do not operate in WPA3-Personal transition mode when PMF is set to
disabled. This also provides a way to be compatible with some devices that are
not fully compatible with WPA3-Personal transition mode.

Signed-off-by: 谢致邦 (XIE Zhibang) <Yeking@Red54.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1186
2022-04-11 18:55:49 +02:00
Thomas Haller
a850e438a7
glib-aux/tests: avoid invalid prefix length in test_platform_ip_address_pretty_sort_cmp()
Next we are going to assert that the prefix length is valid.
The test needs to have valid prefix lengths too. Adjust.
2022-04-08 15:59:50 +02:00
Thomas Haller
b87afac8e8
all: avoid using global string buffer for to-string methods
These string functions allow to omit the string buffer. This is for
convenience, to use a global (thread-local) buffer. I think that is
error prone and we should drop that "convenience" feature.

At various places, pass a stack allocated buffer.
2022-04-08 15:59:49 +02:00