Commit graph

959 commits

Author SHA1 Message Date
Dominique Martinet
6991333bc0 ppp-manager: ip6: fix dns not being used
ipv6 DNS received on ppp interface were being ignored because their
priority was not set.
Fix this by using default priority in impl_ppp_manager_set_ip6_config(),
as was done for ip4_config in b2e559fab2 ("core: initialize l3cd
dns-priority for ppp and wwan")

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1022
2022-06-09 14:21:10 +00:00
Thomas Haller
431d139d15
dispatcher: log duration of dispatcher call
Yes, we anyway log the timestamps for every log message. So one could
always calculate the offset. However, when you read a logfile, it can be
cumbersome to stop looking at where you currently are to find the
start/end of a call. For convenience, log the duration explicitly.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1251
2022-06-09 13:23:35 +02:00
Beniamino Galvani
f69a1cc874 device: fix memory leak
l3cd instances must be removed from the old l3cfg before calling
_cleanup_ip_pre(). Otherwise, _cleanup_ip_pre() unregisters them from
the device, and later _dev_l3_register_l3cds(self, l3cfg_old, FALSE,
FALSE) does nothing because the device doesn't have any l3cd.

Previously the l3cds would linger in the l3cfg, keeping a reference to
it and causing a memory leak; the leak was not detected by valgrind
because the l3cfg was still referenced by the NMNetns.

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

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1252
2022-06-09 09:37:24 +02:00
Thomas Haller
8e86cfb8ab
l3cfg: fix comparing "has-dns-priority" flag in nm_l3_config_data_cmp_full()
Fixes: cb29244552 ('core: support compare flags in nm_l3_config_data_cmp_full()')
2022-06-09 08:53:34 +02:00
Thomas Haller
fb2b35b068
ifcfg: set errno for svGetValueEnum() to detect unset values 2022-06-07 09:55:39 +02:00
Thomas Haller
fe7bdaa7e4
wifi: fix crash in NMDeviceWifi.check_connection_compatible() checking WEP capability
https://bugzilla.redhat.com/show_bug.cgi?id=2092782

Fixes: feee84aac4 ('wifi: mark WEP connections incompatible if supplicant lacks capability')
2022-06-02 13:25:10 +02:00
Thomas Haller
240ec7f891
dhcp: implement ACD (address collision detection) for DHCPv4
This was working for internal plugin in the past, but broken by l3cfg
rework with 1.36. Re-add it. Not it also works with dhclient. For other
plugins, it's not really working, because we can't decline.

Now NMDhcpClient does ACD (using NML3Cfg) and abstracts that from
the caller (NMDevice).

It is complicated. Because there is state involved, meaning, we need
to remember the current state for ACD and react on and handle a
multitude of events. Getting this right, is non-trivial.

What we want is that if ACD fails, we decline the lease (and don't use
it).

https://bugzilla.redhat.com/show_bug.cgi?id=1713380
2022-06-01 10:37:44 +02:00
Thomas Haller
156d84217c
dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin
dhclient itself doesn't do ACD. However, it expects the dhclient-script
to exit with non-zero status, which causes dhclient to send a DECLINE.

`man dhclient-script`:

  BOUND:
     Before actually configuring the address, dhclient-script should
     somehow ARP for it and exit with a nonzero status if it receives a
     reply. In this case, the client will send a DHCPDECLINE  message  to
     the server and acquire a different address.   This may also be done in
     the RENEW, REBIND, or REBOOT states, but is not required, and indeed may
     not be desirable.

See also Fedora's dhclient-script ([1]).

https://gitlab.isc.org/isc-projects/dhcp/-/issues/67#note_97226
33226f2d76/client/dhclient.c (L1652)

[1] a8f6fd046f/f/dhclient-script (_878)

https://bugzilla.redhat.com/show_bug.cgi?id=1713380
2022-05-31 18:32:36 +02:00
Thomas Haller
0f6df633fa
dhcp: minor cleanup of accept/decline functions in "nm-dhcp-client.c"
- assign the result of NM_DHCP_CLIENT_GET_CLASS() to a local variable.
  It feels nicer to only call the macro once. Of course, the macro
  expands to plain pointer dereferences, so there is little difference
  in terms of executed code.

- handle the default case with no virtual function first.
2022-05-31 18:32:36 +02:00
Thomas Haller
4f13383460
dhcp/nettools: pop n-dhcp4 events after select/accept/decline to process logging events 2022-05-31 18:32:36 +02:00
Thomas Haller
8f8839dd2a
dhcp/nettools: add helper function dhcp4_event_pop_all_events()
Will be used next.
2022-05-31 18:32:35 +02:00
Thomas Haller
85b15e02fd
dhcp/nettools: cleanup logging for dhcp4_event_handle()
It's pretty pointless to log

  <trace> [1653389116.6288] dhcp4 (br0): client event 7
  <debug> [1653389116.6288] dhcp4 (br0): received OFFER of 192.168.121.110 from 192.168.121.1

where the obscure event #7 is only telling you that we are going
to log something.  Handle logging events first.

In general, drop the "client event %d" message and make sure that all
code paths log something (useful), so we can see in the log that the
event was reached.
2022-05-31 18:32:35 +02:00
Thomas Haller
52a0fe584c
dhcp/nettools: better track currently granted lease
When we accept/decline a lease, then that only works if we are in state
GRANTED. n-dhcp4 API also requires us, to provide the exact lease, that
we were announced earlier.

As such, we need to make sure that we don't accept/decline in the wrong
state. That means, to keep track of what we are doing more carefully.

The functions _dhcp_client_accept()/_dhcp_client_decline() now take
a l3cd argument, the one that we announced earlier. And we check that it
still matches.
2022-05-31 18:32:35 +02:00
Thomas Haller
4a256092ee
dhcp: move accept/decline function inside "nm-dhcp-client.c"
They are no longer used from outside, NMDhcpClient fully handles this.
Make them static and internal.

Also, decline is currently unused. It will be used soon, with ACD
support.
2022-05-31 18:32:35 +02:00
Thomas Haller
31c52545ed
dhcp: add and use _NMLOG() macro for "nm-dhcp-manager.c" 2022-05-31 18:32:35 +02:00
Thomas Haller
1760cea47c
dhcp: improve warning logging for dhcp4_event_handle() failure 2022-05-31 18:32:34 +02:00
Thomas Haller
479562815c
dhcp: ensure a valid DHCPv4 lease has an address for dhclient
The same check is also for nettools' n-dhcp4 client. It's useful to
being able to rely on certain things, like that an DHCPv4 lease always
has exactly one address (not equal to 0.0.0.0).
2022-05-31 18:32:34 +02:00
Thomas Haller
9abcf3a53c
dhcp/trivial: rename connect_l3cfg_notify() to l3_cfg_notify_check_connected()
The function subscribes a callback l3_cfg_notify_cb(). Rename so that
related functions have a clearly related name.
2022-05-31 18:32:34 +02:00
Thomas Haller
7db07faa5e
dhcp: replace switch in l3_cfg_notify_cb() with if blocks
The l3_cfg_notify_cb() handler is used for different purposes, and
different events will be considered.

Usually a switch statement is very nice for enums, especially if all
enum values should be handled (because the compiler can warn about
unhandled cases). In this case, not all events are supposed to be
handled. At this point, it seems nicer to just use an if block. It
better composes.

The compiler should be able to optimize both variants to the same
result. In any case, checking some integers for equality is in any case
going to be efficient.
2022-05-31 18:32:34 +02:00
Thomas Haller
e756533002
dhcp: move addr-family specific data to union in NMDhcpClientPrivate 2022-05-31 18:32:34 +02:00
Thomas Haller
05cc160494
dhcp/trivial: drop obsolete code comment
This is done already.
2022-05-31 18:32:34 +02:00
Thomas Haller
cd09f3d364
dhcp: fix logging of event in _nm_dhcp_client_notify() 2022-05-31 18:32:34 +02:00
Thomas Haller
d60ba91c87
core: move NM_ACD_TIMEOUT_MAX_MSEC define to "nm-l3cfg.h" header for reuse 2022-05-31 18:32:34 +02:00
Thomas Haller
f9d601ef06
device: initialize full v4/v6 union of NMDhcpClientConfig in _dev_ipdhcpx_start()
I think the previous was technically correct in any case too.
Still change it, because I feel with union and struct initialization,
we should always explicitly pick one union member that we fully
initialize.
2022-05-31 18:32:34 +02:00
Thomas Haller
8df3cb1355
core: fix unused variable in _write_hostname_on_idle_cb()
Fixes: 4dc3f3da17 ('core/hostname: avoid blocking calls in NMHostnameManager setting static hostname')
2022-05-30 18:46:40 +02:00
Thomas Haller
4dc3f3da17
core/hostname: avoid blocking calls in NMHostnameManager setting static hostname
Of course, blocking and synchronous code is much simpler. But it's also
fundamentally wrong to block while we talk to systemd-hostnamed.

Refactor to use async operations.
2022-05-30 16:56:38 +02:00
Thomas Haller
c9fcd30758
core: minor cleanup in hostname code 2022-05-30 16:56:38 +02:00
Thomas Haller
442b6630de
core: fix unsetting static hostname via empty argument
This was broken for a very long time, since 6a60dc2fe9 ('settings:
validate hostnames from D-Bus (bgo #711179)') from October 2013.

But there is really no reason to use this API, as we have
systemd-hostnamed.

https://bugzilla.redhat.com/show_bug.cgi?id=2090946
2022-05-30 16:56:38 +02:00
Alex Henrie
0004a408ae
device: introduce ipv6.mtu property
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1003

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1231
2022-05-27 08:51:44 +02:00
Adrian Freihofer
cdaa99cd35
ifcfg-rh: add support for ipv4.link-local 2022-05-27 08:24:40 +02:00
Adrian Freihofer
cbde63a493
settings: add ipv4.link-local flag
Introduction of a new setting ipv4.link-local, which enables
link-local IP addresses concurrently with other IP address assignment
implementations such as dhcp or manually.
No way is implemented to obtain a link-local address as a fallback when
dhcp does not respond (as dhcpd does, for example). This could be be
added later.

To maintain backward compatibility with ipv4.method ipv4.link-local has
lower priority than ipv4.method. This results in:
* method=link-local overrules link-local=disabled
* method=disabled overrules link-local=enabled

Furthermore, link-local=auto means that method defines whether
link-local is enabled or disabled:
* method=link-local --> link-local=enabled
* else --> link-local=disabled

The upside is, that this implementation requires no normalization.
Normalization is confusing to implement, because to get it really
right, we probably should support normalizing link-local based on
method, but also vice versa. And since the method affects how other
properties validate/normalize, it's hard to normalize that one, so that
the result makes sense. Normalization is also often not great to the
user, because it basically means to modify the profile based on other
settings.

The downside is that the auto flag becomes API and exists because
we need backward compatibility with ipv4.method.
We would never add this flag, if we would redesign "ipv4.method"
(by replacing by per-method-specific settings).

Defining a default setting for ipv4.link-local in the global
configuration is also supported.
The default setting for the new property can be "default", since old
users upgrading to a new version that supports ipv4.link-local will not
have configured the global default in NetworkManager.conf. Therefore,
they will always use the expected "auto" default unless they change
their configuration.

Co-Authored-By: Thomas Haller <thaller@redhat.com>
2022-05-27 08:24:28 +02:00
Alex Henrie
7d8b749293
libnm: allow manually specified IP addresses to have prefix length 0
In IPv4, /0 prevents the creation of a device route, making it
effectively the same as /32. However, in IPv6, /0 makes the device route
an all-encompassing default route. This allows, for example, an 'fe80::'
link-local address to be used to communicate with any public or private
address on the local network without any additional configuration.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1006

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1232
2022-05-26 19:08:28 +02:00
Beniamino Galvani
e5868f21ec dns: detect more quickly when systemd-resolved can't be D-Bus activated
Pass a callback and a 4-second timeout to the "StartServiceByName()"
D-Bus call, so that we can detect any failure immediately.

In this way when systemd-resolved fails to start at boot (for example
because it's masked), nm-online doesn't need to wait those additional
4 seconds due to the fixed timeout source.

Fixes-test: @nm_online_wait_for_delayed_device

https://bugzilla.redhat.com/show_bug.cgi?id=2083332
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1233
2022-05-25 16:03:12 +02:00
Fernando Fernandez Mancera
bc6e28e585 ovsdb: do not set the device as DEACTIVATING if it is DISCONNECTED
During the deactivation of ovs interfaces, ovsdb receives the command to
remove the interface but for OVS system ports the device won't
disappear.

When reconnecting, ovsdb will update first the status and it will notice
that the OVS system interface was removed and it will set the status as
DEACTIVATING. This is incorrect if the status is already DEACTIVATING,
DISCONNECTED, UNMANAGED or UNAVAILABLE because it will block the
activation of the interface.

https://bugzilla.redhat.com/show_bug.cgi?id=2080236
2022-05-25 15:51:43 +02:00
Thomas Haller
0634dfd510
platform: avoid struct alignment issue for NMPlatformIP4Address
On m68k we get a static assertion, that NMPlatformIP4Address.address
is not at the same offset as NMPlatformIPAddress.address_ptr.

On most architectures, the bitfields fits in a gap between the fields,
but not on m68k, where integers are 2-byte aligned.
2022-05-19 16:11:34 +02:00
Beniamino Galvani
9bc7278da3 device: don't require a hardware address for DHCPv6
DHCPv4 requires a hardware address, while DHCPv6 does not.

Anyway, the DHCP manager already checks that an address is available
when needed, so drop the check here.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1228
2022-05-17 18:14:11 +02:00
Thomas Haller
7f943f5fa6
dhcp: merge nm_dhcp_client_start_ip4() and nm_dhcp_client_start_ip6() implementations
As almost always, there is a point in keeping IPv4 and IPv6 implementations
similar. Behave different where there is an actual difference, at the bottom
of the stack.
2022-05-16 16:37:45 +02:00
Thomas Haller
2b8aeba06d
dhcp: move code in "nm-dhcp-client.c" (2) 2022-05-16 16:37:44 +02:00
Thomas Haller
ea13cff76c
dhcp: assert that resources are freed in NMDhcpClient.dispose() 2022-05-16 16:37:44 +02:00
Thomas Haller
600467b96f
dhcp: minor cleanup in config_init() 2022-05-16 16:37:43 +02:00
Thomas Haller
f0ec297739
dhcp: use packed strv array for NMDhcpClientConfig.reject_servers
No need to do it otherwise.
2022-05-16 16:37:43 +02:00
Thomas Haller
892cde1436
dhcp: remove assertion in nm_dhcp_client_handle_event()
Technically, g_warn_if_reached() may not be an assertion, according to
glib. However, there is G_DEBUG=fatal-warnings and we want to run with
that.

So this is an assertion to us. Also, logging to stderr/stdout is not a
useful thing to the daemon. Don't do this. Especially, since it depends
on user provided (untrusted) input.
2022-05-16 16:37:42 +02:00
Thomas Haller
9097679aad
dhcp: move code in nm_dhcp_client_handle_event() 2022-05-16 16:37:42 +02:00
Thomas Haller
802f343d9f
dhcp: drop NMDhcpState enum
It's unused now.
2022-05-16 16:37:41 +02:00
Thomas Haller
97e65e4b50
dhcp: rename/refactor nm_dhcp_client_set_state() to be notifications
Optimally we want stateless, pure code. Obviously, NMDhcpClient needs to
keep state to know what it's doing. However, we should well encapsulate
the state inside NMDhcpClient, and only accept events/notifications that
mutate the internal state according to certain rules.

Having a function public set_state(self, new_state) means that other
components (subclasses of NMDhcpClient) can directly mangle the state.
That means, you no longer need to only reason about the internal state
of NMDhcpClient (and the events/notifications/state-changes that it
implements). You also need to reason that other components take part of
maintaining that internal state.

Rename nm_dhcp_client_set_state() to nm_dhcp_client_notify(). Also, add
a new enum NMDhcpClientEventType with notification/event types.

In practice, this is only renaming. But naming is important, because it
suggests the reader how to think about the code.
2022-05-16 16:37:41 +02:00
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