Commit Graph

31516 Commits

Author SHA1 Message Date
Thomas Haller
ccbe76b81d dhcp: use nm_dhcp_option_create_options_dict() in nm_dhcp_client_handle_event()
The point of using this trivial helper function is to have one function
that is related to the construction of the options dictionary, that we
can search for.

It answers the question, where do we create a option hash (at `git grep
nm_dhcp_option_create_options_dict`).
2022-12-19 11:29:13 +01:00
Thomas Haller
492818b529 dhcp: add static-keys argument to nm_dhcp_option_create_options_dict()
This is so that we can use the same function also to create the
hash for dhclient plugin.
2022-12-19 11:29:12 +01:00
Thomas Haller
84b90fbdd3 dhcp: set effective-client-id for all DHCP plugins 2022-12-19 11:29:12 +01:00
Thomas Haller
bea72c3d6d dhcp: fix "ipv6.dhcp-duid=lease" for dhclient DHCPv6 client
The "lease" mode is unusual, because it means to prefer the DUID
configuration from the DHCP plugin over the explicit configuration in
NetworkManager. It is only for the DHCPv6 DUID and not for the IPv4
client-id. It also is only special for the "dhclient" plugin, because
with the internal plugin, this always corresponds to a generated, stable
DUID.

Commit 58287cbcc0 ('core: rework IP configuration in NetworkManager
using layer 3 configuration') broke this. The commit refactored the code
to track the effective-client-id separately. Previously, the client-id which
was read from the dhclient lease, was overwriting NMDhcpClient.client_id. But
with the refactor, it broke because nm_dhcp_client_get_effective_client_id()
was never called.

Fix that.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-12-19 11:29:11 +01:00
Thomas Haller
28d7f9b7c4 dhcp: drop NMDhcpClientClass.get_duid() hook
Note that there are no callers of nm_dhcp_client_get_effective_client_id(),
hence calling the setter had no effect. This is a bug, that we will fix
later.

But before fixing the bug, change how this works. Drop the get_duid() hook.
It's only confusing and backward.

We will keep the nm_dhcp_client_[gs]et_effective_client_id() functions.
They will be used later.
2022-12-19 11:29:11 +01:00
Thomas Haller
05ae48d64e dhcp: don't use nm_dhcp_client_get_effective_client_id() from systemd DHCPv6 client
The "effective-client-id" is handled wrongly. Step 1 to clean this up.

Note that NMDhcpClientPrivate.effective_client_id is only ever get/set
via the nm_dhcp_client_[gs]et_effective_client_id() functions.
Note that only a NMDhcpDhclient instance ever calls
nm_dhcp_client_set_effective_client_id().

Hence, for NMDhcpSystemd the effective-client-id is really just the DUID
from the config. Clean this up by not calling nm_dhcp_client_get_effective_client_id()
but use the config directly. There is no change in behavior here.
2022-12-19 11:29:11 +01:00
Thomas Haller
9073628bd6 dhcp/trivial: fix naming for internal NM_DHCP_OPTION_DHCP6_{CLIENT,SERVER}_ID enums 2022-12-19 11:29:11 +01:00
Thomas Haller
191a1c74bf core/trivial: fix indentation 2022-12-19 11:29:11 +01:00
Beniamino Galvani
37ee8ee097 merge: branch 'bg/veth-detect-existing'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1483
2022-12-19 11:15:04 +01:00
Beniamino Galvani
50f738bde5 veth: fix detection of existing interfaces in create_and_realize()
The current implementation only checks that a device with name equal
to veth.peer exists and it has a parent device; it doesn't check that
its parent is actually the device we want to create. So for example,
if the profile specifies interface-name A and peer B, while in
platform we have a veth pair {B,C}, we'll skip the interface creation
and the device will remain without a ifindex, leading to a crash
later. Fix this by adding the missing check.

While at it, don't implement the check by inspecting NMDevices but
look directly at the platform cache; that seems more robust because
devices are often updated from platform events via idle handlers and
so the information there could be outdated.

Fixes: 07e0ab48d1 ('veth: drop iface peer check during create_and_realize()')

https://bugzilla.redhat.com/show_bug.cgi?id=2129829
2022-12-19 10:47:13 +01:00
Beniamino Galvani
bdd826a044 veth: improve comment about skipping creation of interfaces 2022-12-19 10:46:32 +01:00
Thomas Haller
0da9f059e1 libnm" fix type description for LTE,5GNR modems
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1148
2022-12-19 08:34:48 +01:00
Thomas Haller
5e0b867a49 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-12-16 13:47:32 +01:00
Thomas Haller
54c68e1290 Squashed 'src/c-stdaux/' changes from c37722ff2f55..eceefe959250
eceefe959250 doc: update README.md for typography
df7e0ac7a792 build: release v1.3.0
293d76aded19 test-basic: use `non_constant_expr`
12f8380286f3 generic: handle compile time expression in _c_boolean_expr_(),_c_likely_()/_c_unlikely_()
92b25e384e3b test/basic: add tests for _c_boolean_expr_
4c1765bc0b4d test/api: move _c_always_inline_ test to generic group
fe95c7a78fe9 test/api: add missing test for _c_boolean_expr_

git-subtree-dir: src/c-stdaux
git-subtree-split: eceefe9592501bce485db62966853b361e90ec2f
2022-12-16 13:46:58 +01:00
Thomas Haller
df0dcd2141 all: merge branch 'th/wcast-align-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1480
2022-12-16 10:57:35 +01:00
Thomas Haller
2191e739ae platform: fix "-Wcast-align" warning for NMPlatformQdisc cast 2022-12-16 10:55:04 +01:00
Thomas Haller
0b1177cb18 all: use _NM_G_TYPE_CHECK_INSTANCE_CAST() for internal uses
G_TYPE_CHECK_INSTANCE_CAST() can trigger a "-Wcast-align":

    src/core/devices/nm-device-macvlan.c: In function 'parent_changed_notify':
    /usr/include/glib-2.0/gobject/gtype.h:2421:42: error: cast increases required alignment of target type [-Werror=cast-align]
     2421 | #  define _G_TYPE_CIC(ip, gt, ct)       ((ct*) ip)
          |                                          ^
    /usr/include/glib-2.0/gobject/gtype.h:501:66: note: in expansion of macro '_G_TYPE_CIC'
      501 | #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
          |                                                                  ^~~~~~~~~~~
    src/core/devices/nm-device-macvlan.h:13:6: note: in expansion of macro 'G_TYPE_CHECK_INSTANCE_CAST'
       13 |     (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DEVICE_MACVLAN, NMDeviceMacvlan))
          |      ^~~~~~~~~~~~~~~~~~~~~~~~~~

Avoid that by using _NM_G_TYPE_CHECK_INSTANCE_CAST().

This can only be done for our internal usages. The public headers
of libnm are not changed.
2022-12-16 10:55:03 +01:00
Thomas Haller
c917d5511b glib-aux: add _NM_G_TYPE_CHECK_INSTANCE_CAST() as replacement for G_TYPE_CHECK_INSTANCE_CAST() 2022-12-16 10:55:03 +01:00
Thomas Haller
2b89b2dc01 std-aux: add _NM_PTR_IS_ALIGNED() helper macro 2022-12-16 10:53:23 +01:00
Lubomir Rintel
9a67988f07 release: bump version to 1.41.7 (development) 2022-12-15 16:43:23 +01:00
Beniamino Galvani
cf11884a85 macsec: fix tracking of parent ifindex
For MACsec interfaces, kernel announces the parent ifindex in the
generic IFLA_LINK netlink attribute, which we save in
NMPlatformLink.parent. There is no need to have a dedicate member in
NMPlatformLnkMacsec.

The dedicate member was never set and during a restart of
NetworkManager the parent of the MACsec device could be unset leading
to a failed assertion:

  act_stage2_config: assertion 'parent' failed

Fixes: 85103656e9 ('platform: add support for macsec links')

https://bugzilla.redhat.com/show_bug.cgi?id=2122564
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1481
2022-12-15 16:30:29 +01:00
Beniamino Galvani
2ab01d75bb merge: branch 'pr/1482'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1482
2022-12-15 16:26:13 +01:00
Gris Ge
1a52239a1f Use NM_MANAGER_ERROR_MISSING_PLUGIN when plugin not found
When ovs plugin not installed, we got this error on dbus

    org.freedesktop.NetworkManager.Failed

It should be `org.freedesktop.NetworkManager.MissingPlugin`.

Signed-off-by: Gris Ge <fge@redhat.com>
2022-12-15 20:44:28 +08:00
Thomas Haller
f0e8b6f0e2 cloud-setup,core: merge branch 'th/cloud-setup-preserve-external-ip'
https://bugzilla.redhat.com/show_bug.cgi?id=2132754

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1476
2022-12-14 17:34:37 +01:00
Thomas Haller
911b550140 nm-cloud-setup: simplify clearing variables in retry loop
The label "try_again" is only reached by one goto. So it was correct
and sufficient to reset the state only there.

It is still error prone. The slighlty clearer approach is to clear
the state at each begin of the "try_again" step.

There should be no change in behavior.

I didn't confirm, but an optimizing compiler should (could) be able
to see that the cleanup is only necessary on retry, and generate the
same code as before. In any case, we should write code that is easier
to read, not optimize for something that a compiler should be able to
optimize itself.
2022-12-14 17:33:57 +01:00
Thomas Haller
bbd32fba15 nm-cloud-setup: refactor skipping reapply be checking for skip first
There should be no change in behavior, but this way seems nicer.
Now _nmc_mangle_connection() doesn't return FALSE, it always
will try to mangle the connection and requires the caller to
first check whether that is appropriate.

Just move some code outside of _nmc_mangle_connection() and let
the caller check for the skip first.

The point is consistency, as the caller already does some checks to
whether skip the reapply. So it should do all the checks, so that
"mangle" never fails/skips.
2022-12-14 17:33:56 +01:00
Thomas Haller
29b0420be7 nm-cloud-setup: set preserve-external-ip flag during reapply
Externally added IP addresses/routes should be preserved by
nm-cloud-setup. This allows other tools to also configure the interface
and the Reapply() call from nm-cloud-setup would not interfere
with those tools.

https://bugzilla.redhat.com/show_bug.cgi?id=2132754
2022-12-14 17:33:56 +01:00
Thomas Haller
bc6098d441 libnm: add internal nmc_client_has_{version_info_v,version_info_capability,capability}() helper
In the end, it turned out I don't need them. They still seem useful,
because they show how to use this API. In particular for how the
bitfield should be parsed.
2022-12-14 17:33:56 +01:00
Thomas Haller
a467f55bef examples: add python example for reapply 2022-12-14 17:31:17 +01:00
Thomas Haller
2c1fb50fb5 core: support flag "preserve-external-ip" for Reapply() call
Reapply() is supposed to make sure that the system (the interface)
is configured as indicated by the applied-connection. That means,
it will remove/add configuration to make the system match the requested
configuration.

Add a flag "preserve-external-ip" which relaxes this. During reapply,
IP addresses/routes that exist on the interface and which are not known
(or added) by NetworkManager will be left alone.

This will be used by nm-cloud-setup, so that it can reconfigure the
interface in a less destructive way, which does not conflict with
external `ip addr/route` calls.

Note that the previous commit just adds "VersionInfo" and the
possibility to expose capabilities (patch-level). This is not used
for the new reapply flag, because, while we might backport the
reapply flag, we won't backport the "VersionInfo" property. Exposing
new capabilities via the "VersionInfo" property will only become useful
in the future, where we can backport a capability to older NM versions
(but those that have "VersionInfo" too).
2022-12-14 17:31:16 +01:00
Thomas Haller
b88cdf2a6b device: change error code for Reapply() rejecting unsupported flags argument
Changing an error code is an API change. But, so far no flags existed,
so it's unlikely that somebody would send invalid flags or care about
the return code.
2022-12-14 17:31:16 +01:00
Thomas Haller
8bed2c9edc core: add "VersionInfo" property on D-Bus and NMClient
This exposes NM_VERSION as number (contrary to the "Version", which is a
string). That is in particular useful, because the number can be
compared with <> due to the encoding of the version.

While at it, don't make it a single number. Expose an array of numbers,
where the following numbers are a bitfield of capabilities.

Note that before commit 3c67a1ec5e ('cli: remove version check against
NM'), we used to parse the "Version" string to detect the version. As
such, the information that "VersionInfo" exposes now, was already
(somewhat) available, you just had to parse the string. The main benefit of
"VersionInfo" is that it can expose capabilities (patched behavior) in
in a lightweight bitfield. To include the numerical version there is
just useful on top.

Currently no additional capabilities are exposed. The idea is of course
to have a place in the future, where we can expose additional
capabilities. Adding a capability flag is most useful for behavior that we
backport to older branches. Otherwise, we could just check the daemon version
alone. But since we only add "VersionInfo" property only now, we cannot backport
any capability further than this, because the "VersionInfo" property itself
won't be backported. As such, this will only be useful in the future by having
a place where we can add (and backport) capabilities.

Note that there is some overlap with the existing "Capability" property
and NMCapability enum. The difference is that adding a capability via "VersionInfo"
is only one bit, and thus cheaper. Most importantly, having it cheaper means
the downsides of adding a capability flag is significantly removed. In
practice, we could live without capabilities for a long time, so they
must be very cheap for them to be worth to add. Another difference might be,
that we will want that the VersionInfo is about compile time defaults (e.g.
a certain patch/behavior that is in or not), while NM_CAPABILITY_TEAM depends on
whether the team plugin is loaded at runtime.
2022-12-14 17:31:15 +01:00
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