Commit graph

31484 commits

Author SHA1 Message Date
Thomas Haller
de322afcd9
glib-aux: add nm_g_array_append_val()
g_array_append_val() takes the pointer of the macro argument, that only works
with lvalues. Add nm_g_array_append_val()
2022-12-14 17:31:15 +01:00
Beniamino Galvani
73267b4d60 merge: branch 'bg/vlan-proto'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1473
2022-12-14 11:35:18 +01:00
Beniamino Galvani
ddcb21eb47 device: support the VLAN protocol option 2022-12-14 11:33:03 +01:00
Beniamino Galvani
d380024d7b ifcfg-rh: support the vlan.protocol property 2022-12-14 11:33:03 +01:00
Beniamino Galvani
1bbde12e57 libnm,nmcli: add vlan.protocol property
Introduce a "vlan.protocol" property that specifies the protocol of a
VLAN, which controls the tag (EtherType) used for encapsulation.

Regular VLANs use 802.1Q (tag 0x8100). To implement VLAN stacking it's
sometimes useful to have 802.1ad VLANs with tag 0x88A8.

The property is a string instead of e.g. an enum because this allows
maximum flexibility in the future. For example, it becomes possible to
specify an arbitrary number in case if the kernel ever allows it.
2022-12-14 11:33:03 +01:00
Beniamino Galvani
bd24e0b274 platform: support VLAN protocol
Add support for the "protocol" attribute of VLAN links.
2022-12-14 11:33:03 +01:00
Thomas Haller
8febb15bfe
contrib: fix duplicate package in "contrib/scripts/nm-in-container.sh" script 2022-12-14 10:07:23 +01:00
Thomas Haller
052ed480a6
platform: fix "-Wcast-align" warning on i686 in nmp_object_ref()
With gcc-12.2.1-4.fc37 on i686 we get:

  ./src/libnm-platform/nmp-object.h: In function 'nmp_object_ref':
  ./src/libnm-platform/nmp-object.h:626:12: error: cast increases required alignment of target type [-Werror=cast-align]
    626 |     return (const NMPObject *) nm_dedup_multi_obj_ref((const NMDedupMultiObj *) obj);
        |            ^
  cc1: all warnings being treated as errors

Work around that be increasing the alignment of NMDedupMultiObj.
It has no downsides, because we usually put a NMDedupMultiObj in heap
allocated memory, which is already suitably aligned. Or we put it on
the stack, where wasting a few bytes for the alignment doesn't matter.
We basically never embed NMDedupMultiObj in an array where the increase
of alignment would waste additional space.
2022-12-14 09:46:33 +01:00
Thomas Haller
63b34ac78a
std-aux: allow nesting of NM_CAST_ALIGN() macros
To support:

    return NM_CAST_ALIGN(const NMPObject,
                         nm_dedup_multi_obj_ref(NM_CAST_ALIGN(const NMDedupMultiObj, obj)));
2022-12-14 09:40:02 +01:00
Thomas Haller
2219302545
libnm: use stack-buffer to construct string in nm_ip_routing_rule_to_string()
There are two benefits:

- the returned (allocated) string will have exactly the required
  length and no excess buffer that was used to build the string.

- the string is (most likely) short enough to fit in 488 bytes on the
  stack. There is no re-allocation necessary to grow the buffer.
2022-12-12 16:14:52 +01:00
Thomas Haller
26e7f707c5
glib-aux: add nm_str_buf_dup_str() helper 2022-12-12 16:04:03 +01:00
Thomas Haller
e3d3b001e0
core: fix returning invalid pointer from nm_netns_l3cfg_get()
The code isn't actually used outside of tests.

Fixes: 15f5d10352 ('l3cfg: add nm_netns_get_l3cfg() accessor')
2022-12-09 18:10:02 +01:00
Thomas Haller
135bbcc0e4
examples: fix handling "--last" argument in "examples/python/gi/checkpoint.py"
Fixes: 3ce3ed4c92 ('examples: improve finding last checkpoint in "checkpoint.py"')
2022-12-09 10:16:36 +01:00
Thomas Haller
176f1928d4
all: merge branch 'th/wcast-align'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1474
2022-12-09 09:27:47 +01:00
Thomas Haller
68afa83c1c
build: enable "-Wcast-align" warning
It seems useful and might show something relevant.
2022-12-09 09:15:56 +01:00
Thomas Haller
68db517808
systemd: fix various "-Wcast-align=strict" warnings
This will also be addressed (differently) in systemd ([1]).

[1] https://github.com/systemd/systemd/pull/25636
2022-12-09 09:15:56 +01:00
Thomas Haller
36f8de25c4
all: fix various "-Wcast-align=strict" warnings
The warning "-Wcast-align=strict" seems useful and will be enabled
next. Fix places that currently cause the warning by using the
new macro NM_CAST_ALIGN(). This macro also nm_assert()s that the alignment
is correct.
2022-12-09 09:15:56 +01:00
Thomas Haller
4ecd25a139
std-aux: add NM_CAST_ALIGN() helper 2022-12-09 09:15:55 +01:00
Thomas Haller
1bf73642dc
all: fix "-Wcast-align=strict" warnings for GArray casts
GArray.data is a char pointer. Most of the time we track other data in
a GArray. Casting that pointer can trigger "-Wcast-align=strict"
warnings.

Avoid them. Most of the time, instead use the nm_g_array*() helpers,
which also assert that the expected element size is correct.
2022-12-09 09:15:55 +01:00
Thomas Haller
67ee711743
glib-aux: make nm_utils_ipv6_{addr_set_interface_identifier,interface_identifier_get_from_addr}() inline
They are trivial wrappers around memcpy(). Make them inline.
2022-12-09 09:15:55 +01:00
Thomas Haller
6996fa64b6
platform: ensure all NMPlatform* structs have same alignment
We put all these structs inside the tagged union NMPObject.
Also, in a sense NMPlatformObject is the base "type" of all
these structs, meaning, it should be able to up and downcast.

Ensure the alignment matches.

This helps to avoid "-Wcast-align" warnings when trying to cast
a (NMPlatformObject*) to another (NMPlatformXXX *) type. Something
we commonly do.
2022-12-09 09:15:54 +01:00
Thomas Haller
4ae5f7f76b
platform: move "struct _NMPlatformObject" to "nmp-plobj.h"
All our platform structs should move there. For now, just move
struct _NMPlatformObject because it will be needed there.
2022-12-09 09:15:54 +01:00
Thomas Haller
977c1e76a8
all: use nm_g_array_first()/nm_g_array_first_p() where suitable 2022-12-09 09:15:53 +01:00
Thomas Haller
cfc6e63403
glib-aux: add nm_g_array_first_p() and fix nm_g_array_index_p() with NULL array
nm_g_array_first_p() is a convenient helper to get the pointer to
the first index. But this one should also accept that the array is NULL,
has array->data as NULL or is empty.
2022-12-09 09:15:53 +01:00
Thomas Haller
afac3d8102
glib-aux/tests: fix bogus cast in _nmtst_connection_normalize_v()
Fixes: 0da0293f7e ('nmtst: add nmtst_connection_normalize() function')
2022-12-06 17:10:44 +01:00
Thomas Haller
373cbcb749
libnm-base: fix bogus and unnecessary cast in nm_ethtool_data_get_by_optname()
Fixes: df30651b89 ('libnm, cli, ifcfg-rh: add NMSettingEthtool setting')
2022-12-06 17:10:44 +01:00
Thomas Haller
3f04778df2
ndisc: fix iterating arrays in calc_pre_expiry_rs_msec()
Fixes: de6d069dce ('ndisc: send router solicitations before expiry')
2022-12-06 17:10:43 +01:00
Thomas Haller
21887f88fa
modem: fix unalined access in stage3_ip_config_start()
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-12-06 17:10:43 +01:00
Thomas Haller
5d86db699b
core: check hardware address length in nm_utils_get_ipv6_interface_identifier()
nm_utils_get_ipv6_interface_identifier() has non-obvious requirements on
the hardware address. If the caller passes a wrong length, it will
trigger an assertion or even cause out of bound read. This would mean
that the caller needs to carefully check the length. Such requirements
on the caller are wrong.

Also, in practice the hardware length comes from platform/kernel. We
don't want to trust that what kernel tells us always has the required
address length, so the caller would always have to double check before
calling the function.

Instead, handle unexpected address lengths.

Fixes: e2270040c0 ('core: use Interface Identifiers for IPv6 SLAAC addresses')
Fixes: 1d396e9972 ('core-utils: use 64-bit WPAN address for a 6LoWPAN IID')
2022-12-06 17:10:42 +01:00
Thomas Haller
53d1d8ba91
core: fix out-of-bounds for nm_utils_get_ipv6_interface_identifier()
For link type NM_LINK_TYPE_6LOWPAN, nm_utils_get_ipv6_interface_identifier()
expects 8 bytes hardware address. It even just accesses the buffer
without checking (that needs to be fixed too).

For 6lowpan devices, the caller might construct a fake ethernet MAC
address, which is only 6 bytes long. So wrong.

Fixes: 49844ea55f ('device: generate pseudo 48-bit address from the WPAN short one')
2022-12-06 17:10:42 +01:00
Thomas Haller
0f4114c27c
core: fix possible unaligned access in nm_utils_get_ipv6_interface_identifier()
Fixes: e2270040c0 ('core: use Interface Identifiers for IPv6 SLAAC addresses')
2022-12-06 17:10:41 +01:00
Thomas Haller
07ef13b9cc
all: merge branch 'th/unreachable-asserts'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1470
2022-12-06 17:09:38 +01:00
Thomas Haller
4753358dd5
std-aux: mark failures of nm_assert() as unreachable code
- with nm_assert(), if the argument is a compile time constant
  always check it (regardless of NDEBUG, G_DISABLE_ASSERT)
  and mark the failure as _nm_unreachable_code(). We do this,
  even if we usually would not evaluate run time checks with
  NDEBUG/G_DISABLE_ASSERT.

- with nm_assert_se(), if assertions are disabled with NDEBUG
  and G_DISABLE_ASSERT, still mark the path as _nm_unreachable_code().
2022-12-06 17:03:04 +01:00
Thomas Haller
06931221b5
std-aux: mark _nm_assert_fail() as _nm_unreachable_code() with NDEBUG/G_DISABLE_ASSERT
This is useful, because it can avoid compiler warnings that are
emitted if the compiler things that the code can be reached.
_nm_assert_fail() can clearly never be reached (unless a bug happens).

When compiling we can disable assertion checks with
NDEBUG/G_DISABLE_ASSERT, but if we know that an assertion must not be
hit (for example with nm_assert_not_reached()) then we still want to
mark the path as unreachable, even if assert() does not abort the
process.
2022-12-06 17:03:04 +01:00
Thomas Haller
5ac5d7f8c3
std-aux: add _nm_unreachable_code() macro to wrap __builtin_unreachable()
This is a GCC-ism, but clang and all our current compiler support it.
2022-12-06 17:03:04 +01:00
Thomas Haller
fffdb14887
std-aux: make NM_BOOLEAN_EXPR() a constant expression for constant arguments
This allows the compiler to see that nm_assert(0) is unreachable code.
That is because nm_assert(0) calls NM_LIKELY(0), which calls
NM_BOOLEAN_EXPR(0). The latter was a statement expression, which
to the compiler was not a constant expression. Hence, this may trigger
compiler warnings about uninitialized variables.

Let NM_BOOLEAN_EXPR() to be constant, if the arguments are.

This can avoid compiler warnings in some cases.

Note that __builtin_choose_expr(__builtin_constant_p(...), ...) does
not properly work with gcc 4.8 ([1]). Hence only do macro shenanigans
with a newer gcc. Then entire point of NM_BOOLEAN_EXPR() is anyway
to preserve the "-Wparentheses" warning (while only evaluating the
argument once, being safe with nested invocations, propagate constness).
If we don't care about "-Wparentheses", it should be the same as
(!!(expr)). We can ignore that on non-recent gcc.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449
2022-12-06 17:03:03 +01:00
Thomas Haller
7483dfd7c4
std-aux: fix _NM_ASSERT_FAIL_ENABLED for plain assert() and NDEBUG
Fixes: 8e3299498d ('std-aux,glib-aux: rework nm_assert() implementations')
2022-12-06 17:02:37 +01:00
Thomas Haller
08262ce372
glib-aux: merge branch 'th/g-clear-pointer'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1475
2022-12-06 17:00:43 +01:00
Thomas Haller
78c8a5d016
glib-aux: reimplement g_clear_pointer() from glib 2.58+ in "nm-glib.h" compat header
Glib 2.58+ improved the implementation of the g_clear_pointer() macro,
and indirectly of g_clear_object(), which uses it.

Note that we don't use the 2.58+ version, because our GLIB_VERSION_MAX_ALLOWED
is too old.

Also note that we don't use g_clear_pointer() directly. Instead, we have
and use nm_clear_pointer() everywhere.

Still, it would be nice if also g_clear_object() uses the improved
variant. Arguably, this is less relevant, because g_clear_object() calls
g_unref_object() which accepts a void pointer and thus there isn't much
type-safety to gain. Still, there is a small gain, so do it.

We could:

 1) replace all uses of g_clear_object() with nm_clear_g_object() and outlaw
   both g_clear_object() and g_clear_pointer(). This is what's done for
   nm_clear_pointer(), which should be used instead of g_clear_pointer().
   The advantage is that we don't monkey-patch glib (which might surprise users).
   The disadvantage is that g_clear_pointer() is well known, while nm_clear_pointer()
   is not. This is mitigated by the fact that nm_clear_pointer() behaves very similar
   to g_clear_pointer() and in all cases where you legally could use
   g_clear_pointer(), nm_clear_pointer() works to the same effect (but not vice
   versa).

 2) silently redefine the glib helper to use our improved implementation. This is
    done for g_clear_error(), which is redefined to nm_clear_error().
    The advantage is that it appears as if we would use glib functionality.
    The disadvantage is that this is not exactly the glib variant.
    This too is mitigated by the fact that our patched g_clear_error()
    should work the same, wherever you can legally use glib's variant (but not
    vice versa).

Let's do 2).

In this case, let g_clear_pointer() behaves exactly like glib 2.58+'s variant,
and not like nm_clear_pointer(). This is to reduce any potential surprise.

nm_clear_pointer() is still better. Still use that over
g_clear_pointer(). This change is for g_clear_object().
2022-12-06 16:57:19 +01:00
Thomas Haller
8cb739031d
device: use correct field "l3cfg_" to clear in dispose()
The fields "l3cfg" and "l3cfg_" are union aliases. One of them is const,
the other is not. The idea is that all places that modify the field need
to use the special name "l3cfg_", and grepping for that will lead you to
all the relevant places.

This mistake happened, because g_clear_object() casts constness away.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-12-06 16:56:55 +01:00
Thomas Haller
37e130232d
dhcp: fix crash in "nm-dhcp-helper" passing NULL to g_dbus_connection_flush_sync()
"connection" variable might be NULL, which fails an assertion in
g_dbus_connection_flush_sync(). Consequently, "error_flush" is also
NULL which leads to a crash of "nm-dhcp-helper".

Reported-by: Jules Maselbas <jmaselbas@zdiv.net>

Fixes: 240ec7f891 ('dhcp: implement ACD (address collision detection) for DHCPv4')
2022-12-05 22:01:41 +01:00
Thomas Haller
8fd73f2be2
po: unify license message in translation files
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1150

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1472
2022-12-05 17:43:41 +01:00
Thomas Haller
2eca11bcba
loopback: reject setting "slave-type"/"master" for "loopback" profiles
A loopback interface cannot be attached to a controller interface (in kernel).

Also, we have special handling for the loopback address 127.0.0.1. It's
not clear how that should behave when the loopback device would be
attached to another interface.

Just reject such configuration as invalid.

Fixes: e8618f03d7 ('support loopback interface')
2022-12-01 13:24:18 +01:00
Thomas Haller
a14d65d06f
release: bump version to 1.41.6 (development) 2022-11-30 15:48:53 +01:00
Thomas Haller
3515324e90
libnm: workaround compiler warning in nm_sock_addr_endpoint_new()
gcc-12.2.1_git20220924-r4 (on Alpine Linux) warns:

  ../src/libnm-core-impl/nm-utils.c: In function 'nm_sock_addr_endpoint_new':
  ../src/libnm-core-impl/nm-utils.c:168:18: error: 'port' may be used uninitialized [-Werror=maybe-uninitialized]
    168 |         ep->port = port;
        |         ~~~~~~~~~^~~~~~
  ../src/libnm-core-impl/nm-utils.c:150:25: note: 'port' was declared here
    150 |     guint16             port;
        |                         ^~~~

Workaround.

Fixes: 713e879d76 ('libnm: add NMSockAddrEndpoint API')
2022-11-30 08:49:07 +01:00
Thomas Haller
2ac903e6ce
c-stdaux: revert "generic: use _c_likely_() in c_assert()"
The change that c_assert() now uses a runtime construct
_c_boolean_expr() causes a "-Wsometimes-uninitialized" warning
with clang ([1]). Revert the patch for now.

This reverts c-stdaux commit [2].

[1] https://github.com/c-util/c-stdaux/pull/11#issuecomment-1331233011
[2] 2cda8dc53a
2022-11-29 21:10:06 +01:00
Thomas Haller
c33a95e6f6
gitlab-ci: ignore failure to install "python-setuptools" on debian
python-setuptools is now gone from debian:testing ([1], [2]):

    Package python-setuptools is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package 'python-setuptools' has no installation candidate

This package is entirely optional. Fix the failure by ignoring any failure to
install the package.

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=938168
[2] https://tracker.debian.org/news/1391360/python-setuptools-removed-from-testing/
2022-11-29 19:54:19 +01:00
Piotr Łobacz
da18683524
devices/wifi: Use sae as main key-mgmt method for networks supporting WPA2 and WPA3
Networks which are working in hybrid mode - WPA2-PSK/WPA3-SAE are offering
two completly different encryption standards. In that case the default mode
should be set to "sae". Setting to "wpa-psk" is a downgrade in security
and should be only allowed if key-mgmt is set to it.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1455
2022-11-29 13:12:28 +01:00
Thomas Haller
81c1168a2d
gitlab-ci: add comment about how to regenerate ".gitlab-ci.yml" 2022-11-29 08:31:38 +01:00
Thomas Haller
41ffdac4e3
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-11-28 10:37:02 +01:00