Commit graph

15724 commits

Author SHA1 Message Date
Thomas Haller
42a70ce1d9
c-stdaux: re-import git-subtree for 'src/c-stdaux'
git subtree pull --prefix src/c-stdaux git@github.com:c-util/c-stdaux.git main --squash
2022-07-06 10:16:01 +02:00
Thomas Haller
9d1772bd73 Squashed 'src/c-stdaux/' changes from 99fe83cd5698..1407a1fb2754
1407a1fb2754 ci: add clang to RTD scripts
8404c4ca6d06 ci: build documentation
044c65c2e134 docs: add sphinx-based API documentation
ad8449068d96 ci: use ci-c-util for macos runs
179987035687 build: adjust for v1.1.0 release
55d787178c84 build: prepare v1.1.0 release
29ca943e636a c-stdaux: avoid NULL arithmetic even in dead-code
c6358e956c29 c-stdaux: avoid NULL-dereference in constant expressions
7fab258bdf6a c-stdaux: improve kerneldoc comments
434b75a796c0 build: export 'version-scripts' configuration
33d56a6aecb9 c-stdaux: encapsulate C_EXPR_ASSERT()
aca7ee0ece60 ci: add macos run
0aa338b1f0de test: prefer pipe() over eventfd() for portability
adda5ff3e9d9 build: export cflags via pkg-config
7a8493bebc59 api: add c_memcpy()
a01615aefe48 build: prepare v1.0.0
1685fc39db3d api: provide c_memzero()
1257244f886a api: add c_memset()

git-subtree-dir: src/c-stdaux
git-subtree-split: 1407a1fb275494f9efc1abbef2fd19856fb1f43d
2022-07-06 10:15:51 +02:00
Thomas Haller
18f14d044d
c-siphash: re-import git-subtree for 'src/c-siphash'
git subtree pull --prefix src/c-siphash git@github.com:c-util/c-siphash.git main --squash
2022-07-06 10:14:28 +02:00
Thomas Haller
f852f532b0 Squashed 'src/c-siphash/' changes from 1da8a0d46bfd..04187aa367ee
04187aa367ee build: prepare v1.0.0 release
0e41909e19e1 build: use libcstdaux.version-scripts
203347c4d3e4 build: drop --no-undefined

git-subtree-dir: src/c-siphash
git-subtree-split: 04187aa367ee24dcbfb23678558b6efa31fd6511
2022-07-06 10:13:02 +02:00
Thomas Haller
8fdcd7030c
c-rbtree: re-import git-subtree for 'src/c-rbtree'
git subtree pull --prefix src/c-rbtree git@github.com:c-util/c-rbtree.git main --squash
2022-07-06 10:07:14 +02:00
Thomas Haller
49f854886e Squashed 'src/c-rbtree/' changes from eb778d39694a..e56535a5daa5
e56535a5daa5 c-rbtree: add overview comments
e1187dd4f56c c-rbtree: improve doc-strings
5c58005f4352 build: bump version
becd70d97145 build: prepare v3.1.0 release
1d865e41b95f build: use libcstdaux.version-scripts
2d4fccbc0095 build: synchronize AUTHORS
b6af0681629a meson: no longer pass -Wl,--no-undefined explicitly
7995758e8540 ci: run on macos

git-subtree-dir: src/c-rbtree
git-subtree-split: e56535a5daa598f329ad05ffb9a9f38585496f34
2022-07-06 10:06:23 +02:00
Thomas Haller
7d2bf498ca
c-list: re-import git-subtree for 'src/c-list'
git subtree pull --prefix src/c-list git@github.com:c-util/c-list.git main --squash
2022-07-06 10:04:09 +02:00
Thomas Haller
287a34990a
libnm: fix timestamp in LIBNM_CLIENT_DEBUG debug logging
Fixes: 9c01d6ca67 ('libnm: print timestamp in LIBNM_CLIENT_DEBUG debug logging')
2022-07-04 16:57:23 +02:00
Thomas Haller
ea85f6dfa3
libnm: fix "parameters" argument in nm_client_dbus_call() to be optional
It was documented to be an optional parameter. That is also in line
with g_dbus_connection_call(), which is essentially wrapped by nm_client_dbus_call().

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2022-07-04 16:57:22 +02:00
Slava Monich
8c5356cec6 supplicant: fix a memory leak
==30980== 8 bytes in 1 blocks are definitely lost in loss record 1,117 of 6,137
==30980==    at 0x4841C38: malloc (vg_replace_malloc.c:309)
==30980==    by 0x4A246C7: g_malloc (gmem.c:106)
==30980==    by 0x4A4A4BB: g_variant_get_strv (gvariant.c:1607)
==30980==    by 0x4A4CA73: g_variant_valist_get_nnp (gvariant.c:4901)
==30980==    by 0x4A4CA73: g_variant_valist_get_leaf (gvariant.c:5058)
==30980==    by 0x4A4CA73: g_variant_valist_get (gvariant.c:5239)
==30980==    by 0x4A4D11D: g_variant_get_va (gvariant.c:5502)
==30980==    by 0x4A4D1BD: g_variant_lookup (gvariant.c:989)
==30980==    by 0xE9389: parse_capabilities (nm-supplicant-interface.c:1241)
==30980==    by 0xEBF99: _properties_changed_main (nm-supplicant-interface.c:1941)
==30980==    by 0xEF549: _properties_changed (nm-supplicant-interface.c:2867)
==30980==    by 0xEF7ED: _get_all_main_cb (nm-supplicant-interface.c:2972)
==30980==    by 0x262057: _nm_dbus_connection_call_default_cb (nm-dbus-aux.c:70)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DBF43: g_task_return.part.3 (gtask.c:1285)
==30980==    by 0x4918885: g_dbus_connection_call_done (gdbusconnection.c:5765)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DB6D7: complete_in_idle_cb (gtask.c:1229)
==30980==    by 0x4A20981: g_main_dispatch (gmain.c:3325)
==30980==    by 0x4A20981: g_main_context_dispatch (gmain.c:4016)
==30980==    by 0x4A20BEF: g_main_context_iterate.isra.23 (gmain.c:4092)
==30980==    by 0x4A20E33: g_main_loop_run (gmain.c:4290)
==30980==    by 0x2C5C9: main (main.c:509)

Fixes: cd1e0193ab ('supplicant: add BIP interface capability')
2022-07-04 15:39:40 +03:00
Beniamino Galvani
fb4ac007ba wifi: wait supplicant to settle before renewing DHCP after roam
After roaming to a different AP, if we trigger a DHCP renewal while
the supplicant is still reauthenticating the REQUEST will be lost and
the client will fall back to sending a DISCOVER, potentially getting a
different address.

Wait that the supplicant state settles before renewing.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1024
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1263
2022-07-04 13:21:06 +02:00
Thomas Haller
9bfe690ab7
libnm/docs: expand documentation for wireguard.ip4-auto-default-route 2022-06-30 21:30:49 +02:00
Thomas Haller
5245fc6c75
platform: rename nmp_lookup_init_object() to nmp_lookup_init_object_by_ifindex()
In the past, nmp_lookup_init_object() could both lookup all object for a
certain ifindex, and lookup all objects of a type. That fallback path
already leads to an assertion failure fora while now, so nobody should
be using this function to lookup all objects of a certain type (for
what, we have nmp_lookup_init_obj_type()).

Now, remove the fallback path, and rename the function to what it really
does.
2022-06-30 14:08:41 +02:00
Thomas Haller
902812ce49
platform: use memset() in _nmp_object_stackinit_from_class()
NMPObject is a union. It's not clear to me that C guarnatees that
designated initializers will meaningfully set all fields to zero. Use
memset() instead.
2022-06-30 14:08:40 +02:00
Lubomir Rintel
af447c493c merge: branch 'lr/client-ask-mode'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1282
2022-06-30 11:15:18 +02:00
Lubomir Rintel
9a70d4e819 tests/client: add interactive add test 2022-06-30 10:20:44 +02:00
Lubomir Rintel
a3f0db06e4 tests/client: do not consult expected result files if no checks require them
Perhaps the test is not using call_nmcli*(), but still wants to use
@nm_test decorator to set up the mock service.
2022-06-30 10:20:44 +02:00
Lubomir Rintel
9570224e86 tests/client: add a pexpect-based test runner
Useful for testing interactive commands against a mock service.
2022-06-30 10:20:44 +02:00
Thomas Haller
e6a33c04eb
all: make "ipv6.addr-gen-mode" configurable by global default
It can be useful to choose a different "ipv6.addr-gen-mode". And it can be
useful to override the default for a set of profiles.

For example, in cloud or in a data center, stable-privacy might not be
the best choice. Add a mechanism to override the default via global defaults
in NetworkManager.conf:

  # /etc/NetworkManager/conf.d/90-ipv6-addr-gen-mode-override.conf
  [connection-90-ipv6-addr-gen-mode-override]
  match-device=type:ethernet
  ipv6.addr-gen-mode=0

"ipv6.addr-gen-mode" is a special property, because its default depends on
the component that configures the profile.

- when read from disk (keyfile and ifcfg-rh), a missing addr-gen-mode
  key means to default to "eui64".
- when configured via D-Bus, a missing addr-gen-mode property means to
  default to "stable-privacy".
- libnm's ip6-config::addr-gen-mode property defaults to
  "stable-privacy".
- when some tool creates a profile, they either can explicitly
  set the mode, or they get the default of the underlying mechanisms
  above.

  - nm-initrd-generator explicitly sets "eui64" for profiles it creates.
  - nmcli doesn' explicitly set it, but inherits the default form
    libnm's ip6-config::addr-gen-mode.
  - when NM creates a auto-default-connection for ethernet ("Wired connection 1"),
    it inherits the default from libnm's ip6-config::addr-gen-mode.

Global connection defaults only take effect when the per-profile
value is set to a special default/unset value. To account for the
different cases above, we add two such special values: "default" and
"default-or-eui64". That's something we didn't do before, but it seams
useful and easy to understand.

Also, this neatly expresses the current behaviors we already have. E.g.
if you don't specify the "addr-gen-mode" in a keyfile, "default-or-eui64"
is a pretty clear thing.

Note that usually we cannot change default values, in particular not for
libnm's properties. That is because we don't serialize the default
values to D-Bus/keyfile, so if we change the default, we change
behavior. Here we change from "stable-privacy" to "default" and
from "eui64" to "default-or-eui64". That means, the user only experiences
a change in behavior, if they have a ".conf" file that overrides the default.

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

See-also: https://github.com/coreos/fedora-coreos-tracker/issues/907

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1213
2022-06-29 07:38:48 +02:00
Thomas Haller
7f766014c5
team: specify cli-type for teamdctl_connect() to select usock/dbus
teamdctl_connect() has a parameter cli_type. If unspecified, the
library will try usock, dbus (if enabled) and zmq (if enabled).

Trying to use the unix socket if we expect to use D-Bus can be bad. For
example, it might cause SELinux denials.

As we anyway require libteam to use D-Bus, if D-Bus is available,
explicitly select the cli type.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1255
2022-06-27 14:04:40 +02:00
Beniamino Galvani
bf9a2babb4 platform: fix routing rule test failure
Since kernel 5.18 there is a stricter validation [1][2] on the tos
field of routing rules, that must not include ECN bits.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f55fbb6afb8d701e3185e31e73f5ea9503a66744
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a410a0cf98854a698a519bfbeb604145da384c0e

Fixes the following failure:

  >>> src/core/platform/tests/test-route-linux
  >>> ...
  # NetworkManager-MESSAGE: <warn>  [1656321515.6604] platform-linux: do-add-rule: failure 22 (Invalid argument - Invalid dsfield (tos): ECN bits must be 0)
  >>> failing... errno=-22, rule=[routing-rule,0x13d6e80,1,+alive,+visible; [6] 0: from all tos 0xff fwmark 0x4/0 suppress_prefixlen -459579276 action-214 protocol 255]
  >>> existing rule: * [routing-rule,0x13d71e0,2,+alive,+visible; [6] 0: from all sport 65534 lookup 10009 suppress_prefixlen 0 none]
  >>> existing rule:   [routing-rule,0x13d7280,2,+alive,+visible; [4] 0: from all fwmark 0/0x9a7e9992 ipproto 255 suppress_prefixlen 0 realms 0x00000008 none protocol 71]
  >>> existing rule:   [routing-rule,0x13d7320,2,+alive,+visible; [6] 598928157: from all suppress_prefixlen 0 none]
  >>> existing rule:   [routing-rule,0x13d73c0,2,+alive,+visible; [4] 0: from 192.192.5.200/8 lookup 254 suppress_prefixlen 0 none protocol 9]
  >>> existing rule:   [routing-rule,0x13d7460,2,+alive,+visible; [4] 0: from all ipproto 3 suppress_prefixlen 0 realms 0xffffffff none protocol 5]
  >>> existing rule:   [routing-rule,0x13d7500,2,+alive,+visible; [4] 0: from all fwmark 0x1/0 lookup 254 suppress_prefixlen 0 action-124 protocol 4]
  >>> existing rule:   [routing-rule,0x13d75a0,2,+alive,+visible; [4] 0: from all suppress_prefixlen 0 action-109]
  0:      from all fwmark 0/0x9a7e9992 ipproto ipproto-255 realms 8 none proto 71
  0:      from 192.192.5.200/8 lookup main suppress_prefixlength 0 none proto ra
  0:      from all ipproto ggp realms 65535/65535 none proto 5
  0:      from all fwmark 0x1/0 lookup main suppress_prefixlength 0 124 proto static
  0:      from all 109
  0:      from all sport 65534 lookup 10009 suppress_prefixlength 0 none
  598928157:      from all none
  Bail out! nm:ERROR:../src/core/platform/tests/test-route.c:1787:test_rule: assertion failed (r == 0): (-22 == 0)

Fixes: 5ae2431b0f ('platform/tests: add tests for handling policy routing rules')
2022-06-27 13:31:08 +02:00
Beniamino Galvani
90e7afc2cd libnm,core: add support for {rto_min,quickack,advmss} route attributes 2022-06-27 11:38:43 +02:00
Beniamino Galvani
2cc02a3a1b platform: add support for {rto_min,quickack,lock-advmss} route attributes 2022-06-27 11:38:43 +02:00
Beniamino Galvani
33f89f5978 ifcfg-rh: support reading boolean route attributes 2022-06-27 11:38:43 +02:00
Thomas Haller
ff694f42a7
dhcp/systemd: pass client instance to lease_to_ip6_config()
This makes it more consistent with nettools' lease_to_ip4_config().
The benefit of having a self pointer, is that it provides the necessary
context for logging. Without it, these functions cannot correctly log.

At this point, it's clearer to get the necessary data directly from the
DHCP client instance, instead of having the caller passing them on
(redundantly).
2022-06-27 10:53:40 +02:00
Thomas Haller
c7c57e8fb9
dhcp/nettools: log message about guessing subnet mask for IPv4 2022-06-27 10:53:40 +02:00
Thomas Haller
f0d132bda9
dhcp: add nm_dhcp_client_create_l3cd() helper 2022-06-27 10:53:39 +02:00
Thomas Haller
c06e6390a4
dhcp/nettools: normalize subnet netmask in nettools client
For an IPv4 subnet mask we expect that all the leading bits are set (no
"holes"). But _nm_utils_ip4_netmask_to_prefix() does not enforce that,
and tries to make the best of it.

In face of a netmask with holes, normalize the mask.
2022-06-27 10:53:39 +02:00
Thomas Haller
57dfa999f7
dhcp/nettools: accept missing "subnet mask" (option 1) in DHCP lease
Do the same as dhclient plugin in nm_dhcp_utils_ip4_config_from_options().

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1037
2022-06-27 10:53:36 +02:00
Thomas Haller
863b71a8fe
all: use internal _nm_utils_ip4_netmask_to_prefix()
We have two variants of the function: nm_utils_ip4_netmask_to_prefix()
and _nm_utils_ip4_netmask_to_prefix(). The former only exists because it
is public API in libnm. Internally, only use the latter.
2022-06-27 10:50:24 +02:00
Thomas Haller
05014b328f
glib-aux: add _nm_utils_ip4_netmask_to_prefix() helper
nm_utils_ip4_netmask_to_prefix() and nm_utils_ip4_prefix_to_netmask()
are public API in libnm.

We thus already have an internal implementation _nm_utils_ip4_prefix_to_netmask(),
for non-libnm users. Internally, we should never use the libnm variant.

For consistency and so that we have the helper available in
libnm-glib-aux, add _nm_utils_ip4_netmask_to_prefix().
2022-06-27 10:50:23 +02:00
Thomas Haller
7a33870bf1
libnm: assert nm_utils_ip4_prefix_to_netmask() for valid IPv4 prefix length
There was already an nm_assert() assertion. Upgrade this
to a g_return_val_if_fail(). This function is public API,
so this is potentially an API break. But it should highlight
a bug in the caller.
2022-06-27 10:50:13 +02:00
Lubomir Rintel
8e6f55ce82 platform: fix build with kernels < 5.7
Fixes: 919a61bc53 ('platform/netlink: extend nl_nlmsghdr_to_str() for genl messages')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1280
2022-06-27 09:08:00 +02:00
Thomas Haller
ae6fe90851
ifcfg-rh: fix serializing lock route attributes
The lock attribute is a boolean, it can also be FALSE. We need
to handle that case, and don't add serialize "$NAME lock 0" for them.
2022-06-27 08:29:27 +02:00
Thomas Haller
efca0b8fa6
ifcfg-rh: in get_route_attributes_string() check prefix for "lock" names
In practice, the profile probably validates, so all the
attribute names are well-known. There is thus no attribute
name that has "lock-" in the middle of the string.

Still, fix it. We want to match only at the begin of the
name.
2022-06-27 08:29:26 +02:00
Thomas Haller
3628cf4805
core: log boot-id when NetworkManager starts
In a logfile, the "is starting" message is an interesting point
that indicates when NetworkManager is starting. Include
also the boot-id in the log, so that we can know whether this
was a restart from the same boot.

Also drop the "for the first time" part.

  <info>  [1656057181.8920] NetworkManager (version 1.39.7) is starting... (after a restart, asserts:10000, boot:486b1052-4bf8-48af-8f15-f3e85c3321f6)
2022-06-27 08:28:56 +02:00
Thomas Haller
8f80f3d446
glib-aux: make code in nm_uuid_is_valid_nm() clearer
Setting `NM_SET_OUT(out_normalized, !is_normalized)` is correct, but looks
odd and required a long code comment.

Try to write the same code differently, I think it is easier to
read and requires less comment to explain.
2022-06-24 21:15:11 +02:00
Thomas Haller
e3a0157141
glib-aux: pass string length to nm_uuid_generate_from_string() in nm_uuid_is_valid_nm()
No need to recompute the length. We have it already.
Also no need to NUL terminate the string.
2022-06-24 21:15:11 +02:00
Lubomir Rintel
33688caabc merge: branch 'lr/ask-mode'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1215
2022-06-24 17:17:59 +02:00
Beniamino Galvani
f8885d0724 core: avoid stale entries in the DNS manager for non-virtual devices
_dev_l3_register_l3cds() schedules a commit, but if the device has
commit type NONE, that doesn't emit a l3cd-changed. Do it manually,
to ensure that entries are removed from the DNS manager.

Related: b86388bef3 ('core: avoid stale entries in the DNS manager')
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/995
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1268
2022-06-24 12:02:45 +02:00
Thomas Haller
f8e061d7d6
platform/netlink: expose genl_ctrl_policy policy in header 2022-06-24 11:03:40 +02:00
Thomas Haller
4f405c5a07
platform/netlink: drop nl_socket_set_ext_ack() API
We just always want to set this. No need for a setter that is only
called once.
2022-06-24 11:03:39 +02:00
Thomas Haller
9cd986ba2e
platform/netlink: simplify socket flags and use boolean fields
- replace "s_flags" field by explicit boolean fields.

- "s_msg_peek" now is simplified. Previously, we would default
  to peek, unless the user caller nl_socket_disable_msg_peek()
  or set nl_socket_set_msg_buf_size(). Simplify that. We now
  default to peek, unless NL_SOCKET_FLAGS_DISABLE_MSG_PEEK is set.

  We have no callers that call nl_socket_set_msg_buf_size(),
  so we can simplify that logic and just enable peeking by default.

- keep "s_auto_ack" field, although it is always TRUE and there
  is no API to toggle that. However, it is kept as a self-documenting
  thing, so we would know the relevant places where auto-ack matters.

- drop nl_socket_disable_msg_peek(). We have no caller of this function
  and we can set peeking in nl_socket_new(). We also don't need to
  change it after creation of the socket.
2022-06-24 11:03:38 +02:00
Thomas Haller
c09b37f3c7
platform/netlink: add flags argument to nl_socket_new()
The real purpose is that we set the socket options before bind().
For that, we need to be able to specify the flag during nl_socket_new().

Another reason is that these are common questions to ponder while
creating a netlink socket. There shouldn't be several setter functions,
just specify the flag right away. These parameters are not going to
change afterwards (at least, we don't need/use that and we don't have
API for that either).
2022-06-24 11:03:37 +02:00
Thomas Haller
919a61bc53
platform/netlink: extend nl_nlmsghdr_to_str() for genl messages
Print more details for generic netlink messages.

Also, pass the group that we obtained via NETLINK_PKTINFO.

Also, factor out simple to-string methods.
2022-06-24 11:03:36 +02:00
Thomas Haller
51b707357d
platform/netlink: add reading NETLINK_PKTINFO in nl_recv()
We will need this, for getting nl_pktinfo control messages
that contain the extended destination group number.

Also, drop NL_SOCK_PASSCRED. It was only used to not iterate over the
control messages, but doing that should be cheap.
2022-06-24 11:03:35 +02:00
Thomas Haller
39320e26cd
platform/netlink: minor cleanup in _netlink_recv_handle()
- drop "abort_parsing" variable, it was redundant.
- rename event_valid_msg(), as this is about NETLINK_ROUTE.
- rename "err" variable to "retval".
2022-06-24 11:03:35 +02:00
Thomas Haller
88df542b6b
platform/netlink: move generic code in _netlink_recv_handle()
This also applies to genl messages. Move the code.
2022-06-24 11:03:34 +02:00
Thomas Haller
b1abd3ebdd
platform/netlink: add nl_msg_lite struct to avoid allocating netlink message
There really is no need for two(!) heap allocations while parsing
the netlink message. We already have it in the buffer. Just use it.

Note that netlink attributes need to be aligned to 4 bytes. But
nlmsg_next() already ensures that, so not even for alignment purpose we
need to clone the message.

Create a new "struct nl_msg_lite" that can hold pointers to everything
we need.
2022-06-24 11:03:34 +02:00
Thomas Haller
1460adc918
platform/netlink: add const modifier for genl functions 2022-06-24 11:03:33 +02:00