Commit graph

1214 commits

Author SHA1 Message Date
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
bd24e0b274 platform: support VLAN protocol
Add support for the "protocol" attribute of VLAN links.
2022-12-14 11:33: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
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
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
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
977c1e76a8
all: use nm_g_array_first()/nm_g_array_first_p() where suitable 2022-12-09 09:15:53 +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
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
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
Beniamino Galvani
1af7dc9c37 ovsdb: set port "trunks" property 2022-11-25 14:15:41 +01:00
Wen Liang
121ba23c16
device: allow autoconnect on external
In some scenarios, autoconnect should not be blocked if the device is
activated on the external connection (e.g. autoconnect on the loopback
device).

Adding the `allow_autoconnect_on_external` flag to support such
behavior.
2022-11-24 18:04:56 +01:00
Wen Liang
e8618f03d7
support loopback interface
Support managing the loopback interface through NM as the users want to
set the proper mtu for loopback interface when forwarding the packets.
Additionally, the IP addresses, DNS, route and routing rules are also
allowed to configure for the loopback connection profiles.

https://bugzilla.redhat.com/show_bug.cgi?id=2060905
2022-11-23 20:51:22 +01:00
Thomas Haller
72e92e0a2b
policy: skip external devices in build_device_hostname_infos()
We soon will handle loopback, so -- if no loopback profile is activated
in NetworkManager -- we will have an externally managed profile on
loopback. This messes up the result.

In general, external connections don't make much sense for
build_device_hostname_infos(). Ignore them.
2022-11-23 20:51:21 +01:00
Thomas Haller
da29726b07
policy: skip external devices in any_devices_active()
any_devices_active() exists to avoid hostname update when no devices are
active. See [1] and commit b07f6712e9 ('policy: check for active
devices before triggering dns update on hostname change').

Soon, we will add support for loopback device, so "lo" will
almost always be activated (either externally or actively managed by
NetworkManager).

In any case, external devices should not count here, even if they appear
activating/activated.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1344303
2022-11-23 20:51:21 +01:00
Thomas Haller
3fb8c0f614
clang-format: reformat code with clang-format 15.0.4-1.fc37
This is the version shipped in Fedora 37. As Fedora 37 is now out, the
core developers switch to it. Our gitlab-ci will also use that as base
image for the check-{patch.tree} tests and to generate the pages. There
is a need that everybody agrees on which clang-format version to use,
and that version should be the one of the currently used Fedora release.

Also update the used Fedora image in "contrib/scripts/nm-code-format-container.sh"
script.

The gitlab-ci still needs update in the following commit. The change
in isolation will break the "check-tree" test.
2022-11-23 09:17:21 +01:00
Thomas Haller
48d7d1d78e
platform: drop inline cmp() wrappers around "full" versions
We sometimes have functions foo() and foo_full(), in which case
foo() has fewer arguments and just calls foo_full(). The "full"
function here is the more powerful one, and foo() is implemented
in terms of the former.

nm_platform_ip4_route_cmp_full() and m_platform_ip4_route_cmp() inverted
that pattern. The "_full" there stands for the full comparison, to not
allowing to select the comparison type.

That inconsistency is ugly. Also, these wrappers were used at only few
places. Let's drop them.

While at it, also drop nm_platform_qdisc_cmp() and rename
nm_platform_qdisc_cmp_full(). Here cmp()/cmp_full() followed the common
pattern foo()/foo_full(), but it's still hardly used and unnecessary.
2022-11-21 17:56:48 +01:00
Fernando Fernandez Mancera
151b2bed36 platform: pass extra_hops to ip_route_add function
When adding a new route we need to consider it contains extra nexthops
i.e it is a ECMP route. As we cannot modify the NMPObject once created,
we need to pass the extra nexthops as an argument.

We cannot use the original NMPObject because normalization is happening
during when adding the route.
2022-11-21 11:19:19 +01:00
Fernando Fernandez Mancera
1bbdecf5e1 platform: manage ECMP routes
When reading from netlink an ECMP IPv4 route, we need to parse the
multiple nexthops. In order to do that, we are introducing
NMPlatformIP4RtNextHop struct.

The first nexthop information will be kept at the original
NMPlatformIP4Route and the new property n_nexthops will indicate how
many nexthops we need to consider.
2022-11-21 11:18:03 +01:00
Thomas Haller
7f218e6ac5
core/tests: relax timing in "/general/nm_utils_kill_child" test
This test is inherently fragile, as it depends on starting processes,
wait for something and kill the process. There are timings involved
that are out of control of the test. Try to adjust the timing.

  # NetworkManager-DEBUG: <debug> [1668755976.9741] kill child process test-s-4 (111487): sending SIGKILL...
  # NetworkManager-DEBUG: <debug> [1668755976.9753] kill child process test-s-4 (111487): waiting for process to terminate after sending SIGTERM (15) and SIGKILL...
  # NetworkManager-DEBUG: <debug> [1668755976.9758] kill child process test-s-4 (111487): after sending SIGTERM (15) and SIGKILL, process 111487 exited by signal 9 (5759 usec elapsed)
  Bail out! GLib:ERROR:../src/core/tests/test-core-with-expect.c:154:test_nm_utils_kill_child_sync_do: Did not see expected message NetworkManager-DEBUG: *<debug> [*] kill child process test-s-4 (*): waiting up to 1 milliseconds for process to terminate normally after sending SIGTERM (15)...
  Bail out! nm:ERROR:../src/core/tests/test-core-with-expect.c:457:test_nm_utils_kill_child: assertion failed (exit_status == 0): (6 == 0)
  --- stderr ---
  **
  GLib:ERROR:../src/core/tests/test-core-with-expect.c:154:test_nm_utils_kill_child_sync_do: Did not see expected message NetworkManager-DEBUG: *<debug> [*] kill child process test-s-4 (*): waiting up to 1 milliseconds for process to terminate normally after sending SIGTERM (15)...
  **
  nm:ERROR:../src/core/tests/test-core-with-expect.c:457:test_nm_utils_kill_child: assertion failed (exit_status == 0): (6 == 0)
  /builds/NetworkManager/NetworkManager/tools/run-nm-test.sh: line 337: 110662 Aborted                 "${NMTST_DBUS_RUN_SESSION[@]}" "${NMTST_LIBTOOL[@]}" "$NMTST_VALGRIND" --quiet --error-exitcode=$VALGRIND_ERROR --leak-check=full --gen-suppressions=all "${NMTST_SUPPRESSIONS[@]}" --num-callers=100 --log-file="$LOGFILE" "$TEST" "${TEST_ARGV[@]}"
2022-11-18 09:41:49 +01:00
Beniamino Galvani
df999d1fca macsec: allow CKN shorter than 64 characters
See wpa_supplicant commit [1]:

    macsec: Make pre-shared CKN variable length

    IEEE Std 802.1X-2010, 9.3.1 defines following restrictions for
    CKN:

    "MKA places no restriction on the format of the CKN, save that it
    comprise an integral number of octets, between 1 and 32
    (inclusive), and that all potential members of the CA use the same
    CKN. No further constraints are placed on the CKNs used with PSKs,
    ..."

    Hence do not require a 32 octet long CKN but instead allow a
    shorter CKN to be configured.

    This fixes interoperability with some Aruba switches, that do not
    accept a 32 octet long CKN (only support shorter ones).

[1] https://w1.fi/cgit/hostap/commit/?id=b678ed1efc50e8da4638d962f8eac13312a4048f
2022-11-16 10:36:39 +01:00
Beniamino Galvani
07bc5121a7 device: fix missing transition from UNAVAILABLE to DISCONNECTED
When called with update_carrier=TRUE, nm_device_bring_up_full() checks
for carrier changes and it may queue a transition to DISCONNECTED
through the following call chain:

 -> nm_device_bring_up_full()
   -> nm_device_set_carrier_from_platform()
     -> nm_device_set_carrier()
       -> carrier_changed()
         -> nm_device_queue_state()

In _set_state_full(state=UNAVAILABLE) after bringing the interface up
we also call nm_device_cleanup() which clears the enqueued state
change to DISCONNECTED. When this happens, the device remains in
UNAVAILABLE and never gets activated even if it was ready.

This was observed with macsec interfaces, but in theory can happen
with all those interfaces that get carrier immediately after being
brought up.

Avoid this issue by not checking the carrier synchronously from
_set_state_full(). The carrier change event will be processed in the
next asynchronous invocation of device_link_changed().

https://bugzilla.redhat.com/show_bug.cgi?id=2122564
2022-11-16 10:22:45 +01:00
Beniamino Galvani
9fd9eaf276 device: add "update_carrier" argument to nm_device_bring_up_full()
In some situations we need to avoid updating the carrier status
synchronously from nm_device_bring_up_full(). Add a flag for that.
2022-11-16 10:22:45 +01:00
Beniamino Galvani
861934a510 device: add nm_device_bring_up_full()
In the next commit nm_device_bring_up() will be extended with a new
argument. Most callers just want to bring up the device synchronously
and don't care about the "no_firmware" argument. Introduce a
nm_device_bring_up_full() for callers that need special behavior.
2022-11-16 10:22:44 +01:00
Beniamino Galvani
c4a7d6a06f vpn: honor the ipvX.method connection property
Currently VPNs always apply the configuration sent by the server for
both address families. So, even if users set e.g. ipv6.method=disabled,
they might end up with IPv6 configured.

Change that and apply the automatic configuration only when the method
is "auto".

This is a change in behavior and as such it might be disruptive for
users that had a method different from "auto" and expected to have the
interface configured. However, that scenario seems unlikely and can be
easily fixed by setting the right method.
2022-11-16 10:17:49 +01:00
Beniamino Galvani
b84faaefc9 vpn: remove unused variable 2022-11-16 10:17:49 +01:00
Fernando Fernandez Mancera
82009e21d2 core: set routing rule protocol properly
When creating NMPlatformRoutingRule from NMIPRouteRule object, the
protocol is being set to RTPROT_UNSPEC. According to linux kernel
documentation FRA_PROTOCOL indicates the originator of the rule.

In this case the route rule is coming from a connection and therefore
the originator of the rule is the user. The correct value is
RTPROT_STATIC which means the rule is installed by the administrator.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1457

Fixes: 3f9347745b ('core: add handling of IP routing rules to NMDevice')
2022-11-14 18:28:25 +01:00
Lubomir Rintel
5d851a3c9d merge: branch 'lr/gtk-doc'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1458
2022-11-14 16:18:33 +01:00
Thomas Haller
6c9018a29e
glib-aux: rename _nm_dbus_signal_connect{,_data}() to _nm_dbus_proxy_*()
These are helpers for GDBusProxy. I think we should avoid GDBusProxy where possible,
and these functions too. Give the function a more specific name to show that this
is only for the proxy.
2022-11-14 08:05:47 +01:00
Thomas Haller
cf6d38177f
glib-aux: drop duplicate _nm_dbus_error_has_name() for nm_dbus_error_is() 2022-11-14 08:04:16 +01:00
Thomas Haller
a7fea45adf
libnm: move "nm-dbus-utils.c" from libnm-core to libnm-glib-aux
These are just general purpose D-Bus utils, based on glib and GDBus.
They fit perfectly to libnm-glib-aux. Move the code.

Also, there is already the file "src/core/nm-dbus-utils.c", having two
files with the same name on our source tree is just confusing.
2022-11-14 08:04:06 +01:00
Lubomir Rintel
d4053a83af libnm: move nm-errors.h include away from nm-connection.h
Most users included this by accident, by including nm-connection.h. That
is not too great, becuase stuff it contains is by no means specific to
NMConnection.

Anyways, it's not like it would matter too that. I mainly care about it
being included in NetworkManager.h, so that there's one less special
case in a test that makes sure useful stuff from NetworkManager.h ends up
in gtk-doc (a separate commit).
2022-11-13 23:36:37 +01:00
Thomas Haller
c593834842
core: filter out invalid Wake-On-Lan flags
NMSettingWired does not reject invalid flags. Filter them out in wake_on_lan_enable().
In practice, it makes no difference, the unknown flags were ignored anyway.
2022-11-10 13:46:35 +01:00
Thomas Haller
4303d33727
ifcfg-rh: fix persisting all-default NMSettingEthtool with autoneg/wol flags
Fixes: 26ed9e6714 ('ifcfg-rh: fix persisting all-default NMSettingEthtool settings')
2022-11-10 13:46:34 +01:00
Thomas Haller
21661c6f71
ifcfg-rh: fix persisting ethtool options
If there were any pause options and any non-pause options,
the created setting was invalid.

I don't think it's reasonably possible to parse the broken settings.
So there is no workaround trying to read the existing broken settings
from disk. Luckily, the broken setting was just silently ignored by
the parser, so you simply could not persist certain settings.

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

Fixes: 652ddca04c ('ethtool: Introducing PAUSE support')
2022-11-10 13:45:43 +01:00
Thomas Haller
3755e6b175
ifcfg-rh/tests: add test checking persisting ethtool settings to ifcfg-rh
There are still various failures. That will be fixed next.
2022-11-10 13:44:58 +01:00
Ratchanan Srirattanamet
e34e38e744
wwan/ofono: cleanup comments and warnings in existing code 2022-11-10 07:54:24 +01:00
Ratchanan Srirattanamet
61e99ed715
wwan/ofono: fix memory leak in handle_settings()
[thaller@redhat.com: modified original patch.]

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-11-10 07:54:10 +01:00
Ratchanan Srirattanamet
f0ef4a440f
wwan/device-modem: re-check device availability after enable
It's possible that the modem is enabled outside of NM. If not
re-check, device could stay disabled throughout until something else
about the modem changes again.
2022-11-10 07:44:59 +01:00
Ratchanan Srirattanamet
2f3a0eaa0b
wwan/modem: return early if set_mm_enable is not implemented
We don't want to e.g. pre-empt the state change signal, because it's not
gonna happen.
2022-11-10 07:44:59 +01:00
Ratchanan Srirattanamet
580453d376
wwan/device-modem: disabled but not enable-able modem is unavailable
If a modem is disabled, and it has no method to enable it, then by no
mean it's "available" to NM.
2022-11-10 07:44:58 +01:00
Ratchanan Srirattanamet
f914df4f79
wwan/ofono: avoid bogus IP failure when not connecting
If modem is not at least "registered", a connection is not happening, which
means IP settings change is probably not interesting. Avoid trying to
parse it, so that we don't trigger connection failure when there isn't
one.
2022-11-10 07:44:58 +01:00
Ratchanan Srirattanamet
e7809a2bd7
wwan/ofono: clear current_octx on disconnect
This way, we won't signal failure when "PropertyChanged" signal for an
empty "Settings" eventually arrive.
2022-11-10 07:44:57 +01:00
Ratchanan Srirattanamet
5abc6f5911
wwan/ofono: also recognize connman's "Powered" property
This property "controls [oFono] whether packet radio use is allowed". It
makes sense to consider the value of FALSE to mean DISABLED.
2022-11-10 07:44:57 +01:00