Commit Graph

33177 Commits

Author SHA1 Message Date
Beniamino Galvani
0d25ec7e4b merge: branch 'bg/macsec-offload'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1871

(cherry picked from commit 433e9a84f7)
2024-02-21 11:48:44 +01:00
Beniamino Galvani
cd1d803cb2 macsec: support the offload property
(cherry picked from commit 010c54dce9)
2024-02-21 11:48:43 +01:00
Beniamino Galvani
9a9267ad4e libnm,nmcli: add macsec.offload property
Introduce a new property to control the MACsec offload mode.

(cherry picked from commit aa418275cf)
2024-02-21 11:48:42 +01:00
Javier Sánchez Parra
6601e6bf48 nmtui: Add bond for creating bridge port interface
This commit adds the missing bond option in the nmtui interface for
creating a bridge port interface.

Resolves: https://issues.redhat.com/browse/RHEL-18158
(cherry picked from commit 279d559a12)
2024-02-21 11:48:21 +01:00
Beniamino Galvani
9a42722718 nmcli: fix crash in nmc_connection_check_deprecated()
It's not clear in which circumstances, but 'type' can be NULL as in
the following backtrace:

  nmc_connection_check_deprecated (c=c@entry=0x55d93f937610) at src/nmcli/connections.c:676
  connection_warnings (nmc=nmc@entry=0x55d93f5ae5e0 <nm_cli>, connection=connection@entry=0x55d93f937610) at src/nmcli/connections.c:5464
  add_connection_cb (client=<optimized out>, result=<optimized out>, user_data=0x55d93fc83820) at src/nmcli/connections.c:5510
  g_task_return_now (task=0x55d93fc86fd0 [GTask]) at ../gio/gtask.c:1361
  g_task_return (type=<optimized out>, task=0x55d93fc86fd0 [GTask]) at ../gio/gtask.c:1430
  g_task_return (task=0x55d93fc86fd0 [GTask], type=<optimized out>) at ../gio/gtask.c:1387
  _request_wait_complete () at /lib64/libnm.so.0
  _nm_client_notify_event_emit_parts () at /lib64/libnm.so.0
  _dbus_handle_changes_commit () at /lib64/libnm.so.0
  _nm_client_get_settings_call_cb () at /lib64/libnm.so.0
  _nm_client_dbus_call_simple_cb () at /lib64/libnm.so.0
  g_task_return_now (task=0x55d93f7bd6f0 [GTask]) at ../gio/gtask.c:1361
  g_task_return (type=<optimized out>, task=0x55d93f7bd6f0 [GTask]) at ../gio/gtask.c:1430
  g_task_return (task=0x55d93f7bd6f0 [GTask], type=<optimized out>) at ../gio/gtask.c:1387
  g_dbus_connection_call_done (source=<optimized out>, result=<optimized out>, user_data=0x55d93f7bd6f0) at ../gio/gdbusconnection.c:5895
  g_task_return_now (task=0x55d93f7bd7b0 [GTask]) at ../gio/gtask.c:1361
  complete_in_idle_cb (task=task@entry=0x55d93f7bd7b0) at ../gio/gtask.c:1375
  g_idle_dispatch (source=0x7f15b007c940, callback=0x7f15ca7e4850 <complete_in_idle_cb>, user_data=0x55d93f7bd7b0) at ../glib/gmain.c:6150
  g_main_dispatch (context=0x55d93f77cde0) at ../glib/gmain.c:3344
  g_main_context_dispatch_unlocked (context=0x55d93f77cde0) at ../glib/gmain.c:4152
  g_main_context_iterate_unlocked.isra.0 (context=0x55d93f77cde0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4217
  g_main_loop_run (loop=0x55d93f7589b0) at ../glib/gmain.c:4419
  main (argc=19, argv=0x7fff77359138) at src/nmcli/nmcli.c:1044

Fixes: f377114d6e ('cli: connection: check for deprecated features')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1872
(cherry picked from commit 416d596b31)
2024-02-21 11:48:11 +01:00
Sergey Koshelenko
d88e21ff91 ndisc: fix IPv6 address lifetimes computation
Background: when router sends router advertisement (RA) message,
NetworkManager processes it and passes data to a lower system layer.
Currently there is a problem that NetworkManager adds one second to both
valid lifetime and preferred lifetime. This happens because of the
algorithm in nm_ndisc_data_to_l3cd() function.

Let's look at an example: let current timestamp be 100450, so now_sec
variable is 100. At this moment RA message was received from the router.
The IPv6 address' valid lifetime is 200 seconds (for example), so
expiration timestamp (ndisc_addr->expiry_msec) is 300450. But after the
_nm_ndisc_lifetime_from_expiry() call, NMPlatformIP6Address lifetime
becomes 201 ((300450-(100*1000)+999)/1000). Which is wrong.

This commit fixes this behaviour by replacing
nm_utils_get_monotonic_timestamp_sec() with
nm_utils_get_monotonic_timestamp_msec() so that timestamps are
calculated more precisely.

Related issue: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1464
Merge request: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1863

(cherry picked from commit 14e7220f5f)
2024-02-21 11:48:04 +01:00
Íñigo Huguet
27c701ebfb libnmc: allow user input in ECHO mode for 2FA challenges
Depending on the type of challenge used in the 2FA authentication, the
user input doesn't need to be hidden and sometimes it's even undesired
(it makes more difficult to enter the text).

Allow to VPN plugins to indicate that a secret that is being requested
is a 2FA challenge with ECHO mode enabled:
- When using auth dialog: accept a new option "ForceEcho" that can be
  set to TRUE to enable ECHO.
- When using the fallback method: recognize the prefix
  "x-dynamic-challenge-echo". This indicate both that ECHO should be enabled
  and that this is a 2FA challenge (see previous commit).

The correct way to enable echo mode from VPN plugins is doing both
things: pass the hint prefixed with "x-dynamic-challenge-echo" and add the
option "ForceEcho=true" for the auth dialog.

An attempt to support ECHO mode from NM-openvpn was made by passing
"IsSecret=false", but it didn't work because nm-secret-agent-simple
ignores returned values for which "IsSecret=false". It's not a good idea
to start accepting them because we could break other plugins, and anyway
the challenge response is actually a secret, so it is better to keep it
as such and add this new "ForceEcho" option.

This is backwards compatible because existing plugins were not using the
tag nor the auth dialog option. Withouth them, the previous behaviour is
preserved. On the contrary, plugins that want to use this new feature
will need to bump their NM version dependency because old daemons will
not handle correctly the prefix tag.

Secret agents will need to be updated to check secret->force_echo if
they want to support this feature. Until they update, the only drawback
is that ECHO mode will be ignored and the user's input will be hidden.

Updated nmcli and nmtui to support ECHO mode.

(cherry picked from commit 2ab56e82d4)
2024-02-21 11:31:49 +01:00
Íñigo Huguet
345bd1b187 libnmc: fix secrets request on 2nd stage of 2FA authentication
Clients using nm-secret-agent-simple always asked for some default VPN
secrets, which are dependent on the VPN service, when the auth dialog
can't be used and the fallback method is used instead.

When using 2FA this has to be avoided in the 2nd step because those
default secrets were already requested and validated in the 1st step.

Fix it by adding a new "x-dynamic-challenge" prefix tag that can be used
in the hints received from the VPN plugin. This tag indicates that we
are in the 2nd step of a 2FA authentication. This way we know that we
don't have to request the default secrets this time. Note that the tag
name doesn't explicitly mention VPNs so it can be reused for other type
of connections in the future.

As the default secrets were requested always unconditionally when using
the fallback method, there is no possible workaround to this problem
that avoids having to change libnm-client.

The change is backwards compatible because VPN plugins were not using
the tag and the previous behaviour does not change if the tag is not
used. However, VPN plugins that want to properly support 2FA
aunthentication will need to bump the NM version dependency because
old daemons won't handle properly a hint with the new prefix tag.

Finally, move the macro that defines the "x-vpn-message:" tag in a public
header so it is more visible for users. It has been renamed and prefixed
with the NM_ namespace so it shouldn't collide with macros defined in
the VPN plugins.

(cherry picked from commit c5f46bae43)
2024-02-21 11:31:48 +01:00
Íñigo Huguet
3df94a4f2e sriov: allow reading empty eswitch paramaters via Devlink
Probably not all drivers and devices return all parameters. Set them to
"unknown" if they are missing and let the caller to decide what to do.

In our case, if the sriov setting has a value different to "preserve" it
will try to set it (and will probably fail). But if the missing
parameter is set to "preserve" in the sriov setting we can continue,
just ignoring it.

(cherry picked from commit 7346c5b556)
2024-02-21 11:27:36 +01:00
Íñigo Huguet
dda94d6f66 sriov: don't fail if sriov_totalvfs sysfs file is missing
If sriov_totalvfs file doesn't exist we don't need to consider it a
fatal failure. Try to create the required number of VFs as we were doing
before.

Note: at least netdevsim doesn't have sriov_totalvfs file, I don't know
if there are real drivers that neither has it.

(cherry picked from commit 27eaf34fcf)
2024-02-21 11:27:34 +01:00
Íñigo Huguet
f0133e1a5e sriov: set the devlink's eswitch inline-mode and encap-mode
Set these parameters according to the values set in the new properties
sriov.eswitch-inline-mode and sriov.eswitch-encap-mode.

The number of parameters related to SR-IOV was becoming too big.
Refactor to group them in a NMPlatformSriovParams struct and pass it
around.

(cherry picked from commit 4669f01eb0)
2024-02-21 11:27:32 +01:00
Íñigo Huguet
03aaff8fc2 devlink: get and set eswitch inline-mode and encap-mode
The setter function allow to set to "preserve" to modify only some of
them.

(cherry picked from commit bf654ef39e)
2024-02-21 11:27:31 +01:00
Íñigo Huguet
a8c4372d42 sriov: add eswitch-inline-mode and eswitch-encap-mode properties
Those are related to the eswitch mode and can be configured together.

(cherry picked from commit 8a88386e3a)
2024-02-21 11:27:30 +01:00
Íñigo Huguet
dd7810c473 platform: destroy VFs before changing the eswitch mode
It is not safe to change the eswitch mode when there are VFs already
created: it often fails, or even worse, doesn't fail immediatelly but
there are later problems with the VFs.

What is supposed to be well tested in all drivers is to change the
eswitch mode with no VFs created, and then create the VFs, so let's set
num_vfs=0 before changing the eswitch mode.

As we want to change num_vfs asynchronously in a separate thread, we
need to do a multi-step process with callbacks each time that a step
finish (before it was just set num_vfs asynchronously and invoke the
callback when it's done).

This makes link_set_sriov_params_async to become even larger and more
complex than it already was. Refactor it to make it cleaner and easier
to follow, and hopefully less error prone, and implement that multi-step
process.

(cherry picked from commit 770340627b)
2024-02-21 11:27:29 +01:00
Íñigo Huguet
1ba2b77402 sriov: set the devlink's eswitch mode
Use the new property sriov.eswitch-mode to select between legacy SRIOV
and switchdev mode.

(cherry picked from commit 837549ea94)
2024-02-21 11:27:29 +01:00
Íñigo Huguet
e9561456c9 sriov: add eswitch-mode property
Add property to allow changing the eswitch mode between legacy SRIOV and
switchdev. Allow also to set "preserve" to prevent NM from modifying the
eswitch mode.

(cherry picked from commit c61c87f8a6)
2024-02-21 11:27:29 +01:00
Íñigo Huguet
61788cf901 platform: netlink: add devlink support
Add support for Devlink, which is just another family of Generic Netlink
like nl80211. Implement get_eswitch_mode and set_eswitch_mode to allow
changing between legacy SRIOV and switchdev modes.

Devlink's purpose is to allow querying and configuring stuff related to
a piece of hardware but not to any of the usual Linux device classes.

For example, nowadays the Smart NICs normally allow to change the
eswitch mode per PF, because their hardware implements one eswitch per
PF, but future models might have a single eswitch for all the physical
and virtual ports of the NIC allowing more advanced bridge offloads.

Regarding the above example, for the moment we only support PCI network
devices with the "one eswitch per PF" model. The reason is that currently
NM only knows about netdevs so dealing with "devlink devices" that
doesn't map 1-1 with a netdev would require new mechanisms to understand
what they are and their relation with the netdevs that NM manage. We
will deal with that use cases when they arise and we have more
information about the right way to support them.

(cherry picked from commit f31d29bbb7)
2024-02-21 11:27:28 +01:00
Íñigo Huguet
c31f31acbf nm-setting: implement direct_enum as GObject property of type int
(cherry picked from commit 260865b1ac)
2024-02-21 11:20:52 +01:00
Beniamino Galvani
edca33e28f merge: branch 'bg/create-generic-devices'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1752
2024-02-21 11:20:10 +01:00
Beniamino Galvani
5978fb2b27 manager: make generic devices compatible with all link types
If a generic device is present and the name matches, it is compatible
with any link type.

For example, if a generic connection has a device-handler that creates
a dummy interface, the link is compatible with the NMDeviceGeneric.
2024-02-21 11:16:06 +01:00
Beniamino Galvani
f2613be150 core: persist state of software generic devices across restarts
When a generic connection has a custom device-handler, it always
generates a NMDeviceGeneric, even when the link that gets created is
of a type natively supported by NM. On service restart, we need to
keep track that the device is generic or otherwise a different device
type will be instantiated.
2024-02-21 11:16:05 +01:00
Beniamino Galvani
df6c35ec75 device: support creating generic devices via device-handler
If the device-handler of the generic connection is set, the connection
is virtual and the device is created by invoking the device-handler
via NetworkManager-dispatcher service.

With this change, a generic device now represents two different device
classes:

 - existing interfaces that are not natively supported or recognized
   by NetworkManager. Those devices have the `has_device_handler`
   property set to FALSE;

 - interfaces that are created by NM by invoking the device-handler;
   they have `has_device_handler` set to TRUE.
2024-02-21 11:16:05 +01:00
Beniamino Galvani
ae7ac3c8b7 examples: add example device handler dispatcher for geneve 2024-02-21 11:16:05 +01:00
Beniamino Galvani
d72f26b875 dispatcher: read device-handler's stdout into a dictionary
Device handlers need a way to pass data back to NetworkManager, such
as the ifindex and an error message. Allow them to return a dictionary
on standard output, where each line contains a "$key=$value" pair.
In the daemon, the dictionary is returned via the callback function.
2024-02-21 11:16:04 +01:00
Beniamino Galvani
ee5845063d dispatcher: support device-handler actions
"device-add" and "device-delete" actions are called for
device-handlers of generic devices. They differ from other actions in
the following aspects:

 - only one script is invoked, the one with name specified by the
   device-handler property;
 - the script is searched in the "device" subdirectory;
 - since there is only one script executed, the result and error
   string from that script are returned by NM in the callback function.
2024-02-21 11:16:04 +01:00
Beniamino Galvani
8fd0d39444 core/dispatcher: prefer the Action2() method and fall back to Action()
Call the Action2() method first, and fall back to the old Action() if
the new one is not available. This allows full interoperability
between different versions of the dispatcher service and NM.
2024-02-21 11:16:04 +01:00
Beniamino Galvani
abf0f03d25 dispatcher: add Action2() D-Bus method
Currently, the dispatcher service implements an Action() method to
dispatch events. In the next commits, we'll need to add new
parameters, which is not possible with the current signature.

Introduce a new Action2() method, similar to the existing one but with
the following changes:

 - it accepts an additional "options" input parameter of type a{sv};
 - for each script executed, it also returns a dictionary of type
   a{sv}.

The new parameters will allow to easily extend functionality in the
future without having to implement an Action3().
2024-02-21 11:16:03 +01:00
Beniamino Galvani
703efdfbbf dispatcher: refactor building the result
Introduce request_dbus_method_return() and call it whenever we need to
return a result. Don't collect the list of scripts in case the
parameters can't be parsed.
2024-02-21 11:16:03 +01:00
Beniamino Galvani
98b73e88e6 core/dispatcher: refactor nm_dispatcher_need_device()
Remove the "nm_" prefix that is usually reserved for non-static
functions. Also, use NM_IN_SET.
2024-02-21 11:16:03 +01:00
Beniamino Galvani
fa6ce51a0b core/dispatcher: factorize code
Move common code from nm_dispatcher_call_device() and
nm_dispatcher_call_device_sync() to a new function; it will also be
used in the next commits by a new variant of the function.
2024-02-21 11:16:02 +01:00
Beniamino Galvani
e686ab35b3 libnm: add generic.device-handler property
Add a new "generic.device-handler" property that specifies the name of
a dispatcher script to be invoked to add and delete the interface for
this connection.
2024-02-21 11:16:01 +01:00
Beniamino Galvani
d7c311eb85 dispatcher: pass user setting properties in the environment
Properties in the "user" setting are a convenient way to associate any
kind of user-provided metadata to connections.

However, nmcli doesn't support the user setting at the moment and
adding this feature requires a significant effort. Without nmcli
support, dispatcher scripts can only access user properties by either
parsing connection files or by using D-Bus (with or without libnm and
GObject introspection). Since both these solutions are not very
convenient, provide an alternative way: pass the properties as
environment variables.
2024-02-21 11:15:24 +01:00
Beniamino Galvani
38acb7a57d core: move functions for env variable name encoding to libnm-glib-aux
They will be used by the dispatcher service.
2024-02-21 11:15:24 +01:00
Beniamino Galvani
7b769e9e49 dispatcher: remove trailing dot from error messages
The error messages are logged by the dispatcher and passed back to
NetworkManager which also logs them. NetworkManager log messages
usually don't end with a dot: remove it.
2024-02-21 11:15:24 +01:00
Beniamino Galvani
433e9a84f7 merge: branch 'bg/macsec-offload'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1871
2024-02-21 11:10:31 +01:00
Beniamino Galvani
010c54dce9 macsec: support the offload property 2024-02-21 10:51:57 +01:00
Beniamino Galvani
aa418275cf libnm,nmcli: add macsec.offload property
Introduce a new property to control the MACsec offload mode.
2024-02-21 10:51:57 +01:00
Íñigo Huguet
09f2e1c107 merge: branch 'ih/eswitch_mode'
sriov: add support to configure the NIC's eswitch settings via Devlink

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1867
2024-02-20 15:04:31 +00:00
Íñigo Huguet
7346c5b556 sriov: allow reading empty eswitch paramaters via Devlink
Probably not all drivers and devices return all parameters. Set them to
"unknown" if they are missing and let the caller to decide what to do.

In our case, if the sriov setting has a value different to "preserve" it
will try to set it (and will probably fail). But if the missing
parameter is set to "preserve" in the sriov setting we can continue,
just ignoring it.
2024-02-20 16:01:32 +01:00
Íñigo Huguet
27eaf34fcf sriov: don't fail if sriov_totalvfs sysfs file is missing
If sriov_totalvfs file doesn't exist we don't need to consider it a
fatal failure. Try to create the required number of VFs as we were doing
before.

Note: at least netdevsim doesn't have sriov_totalvfs file, I don't know
if there are real drivers that neither has it.
2024-02-20 16:01:30 +01:00
Íñigo Huguet
4669f01eb0 sriov: set the devlink's eswitch inline-mode and encap-mode
Set these parameters according to the values set in the new properties
sriov.eswitch-inline-mode and sriov.eswitch-encap-mode.

The number of parameters related to SR-IOV was becoming too big.
Refactor to group them in a NMPlatformSriovParams struct and pass it
around.
2024-02-20 16:01:29 +01:00
Íñigo Huguet
bf654ef39e devlink: get and set eswitch inline-mode and encap-mode
The setter function allow to set to "preserve" to modify only some of
them.
2024-02-20 16:01:28 +01:00
Íñigo Huguet
8a88386e3a sriov: add eswitch-inline-mode and eswitch-encap-mode properties
Those are related to the eswitch mode and can be configured together.
2024-02-20 16:01:27 +01:00
Íñigo Huguet
770340627b platform: destroy VFs before changing the eswitch mode
It is not safe to change the eswitch mode when there are VFs already
created: it often fails, or even worse, doesn't fail immediatelly but
there are later problems with the VFs.

What is supposed to be well tested in all drivers is to change the
eswitch mode with no VFs created, and then create the VFs, so let's set
num_vfs=0 before changing the eswitch mode.

As we want to change num_vfs asynchronously in a separate thread, we
need to do a multi-step process with callbacks each time that a step
finish (before it was just set num_vfs asynchronously and invoke the
callback when it's done).

This makes link_set_sriov_params_async to become even larger and more
complex than it already was. Refactor it to make it cleaner and easier
to follow, and hopefully less error prone, and implement that multi-step
process.
2024-02-20 16:01:26 +01:00
Íñigo Huguet
837549ea94 sriov: set the devlink's eswitch mode
Use the new property sriov.eswitch-mode to select between legacy SRIOV
and switchdev mode.
2024-02-20 16:01:25 +01:00
Íñigo Huguet
c61c87f8a6 sriov: add eswitch-mode property
Add property to allow changing the eswitch mode between legacy SRIOV and
switchdev. Allow also to set "preserve" to prevent NM from modifying the
eswitch mode.
2024-02-20 16:01:25 +01:00
Íñigo Huguet
f31d29bbb7 platform: netlink: add devlink support
Add support for Devlink, which is just another family of Generic Netlink
like nl80211. Implement get_eswitch_mode and set_eswitch_mode to allow
changing between legacy SRIOV and switchdev modes.

Devlink's purpose is to allow querying and configuring stuff related to
a piece of hardware but not to any of the usual Linux device classes.

For example, nowadays the Smart NICs normally allow to change the
eswitch mode per PF, because their hardware implements one eswitch per
PF, but future models might have a single eswitch for all the physical
and virtual ports of the NIC allowing more advanced bridge offloads.

Regarding the above example, for the moment we only support PCI network
devices with the "one eswitch per PF" model. The reason is that currently
NM only knows about netdevs so dealing with "devlink devices" that
doesn't map 1-1 with a netdev would require new mechanisms to understand
what they are and their relation with the netdevs that NM manage. We
will deal with that use cases when they arise and we have more
information about the right way to support them.
2024-02-20 16:01:25 +01:00
Íñigo Huguet
cc1b970e08 merge: branch 'ih/direct_enum'
nm-setting: implement direct_enum as GObject property of type int

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1861
2024-02-20 14:50:17 +00:00
Íñigo Huguet
260865b1ac nm-setting: implement direct_enum as GObject property of type int 2024-02-20 14:50:15 +00:00
Fernando Fernandez Mancera
8d639abb2f .gitignore: include m4/build-to-host.m4
When the build environment is different from the target runtime
environment, file names may need to be converted from the build env
syntax to the target env syntax. This is handled by some generated
macros. This must be ignored by git.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2024-02-20 12:12:25 +01:00