diff options
| author | Michael Biebl <biebl@debian.org> | 2024-02-22 17:21:11 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2024-02-22 17:21:11 +0100 |
| commit | bba2e4b4de668db525cbfdfc35292e5a0b51671a (patch) | |
| tree | 38d20cddfcc6f71572b9e169deefab5fa96e8d0c /src/core/devices | |
| parent | 6681f77b757bbc42ce5c8868ee9142b7ebc8c059 (diff) | |
New upstream version 1.46.0 upstream/1.46.0
Diffstat (limited to 'src/core/devices')
| -rw-r--r-- | src/core/devices/nm-device-factory.c | 17 | ||||
| -rw-r--r-- | src/core/devices/nm-device-factory.h | 2 | ||||
| -rw-r--r-- | src/core/devices/nm-device-generic.c | 343 | ||||
| -rw-r--r-- | src/core/devices/nm-device-generic.h | 3 | ||||
| -rw-r--r-- | src/core/devices/nm-device-macsec.c | 17 | ||||
| -rw-r--r-- | src/core/devices/nm-device-utils.c | 4 | ||||
| -rw-r--r-- | src/core/devices/nm-device.c | 62 |
7 files changed, 419 insertions, 29 deletions
diff --git a/src/core/devices/nm-device-factory.c b/src/core/devices/nm-device-factory.c index c97fbb57..69c2a38f 100644 --- a/src/core/devices/nm-device-factory.c +++ b/src/core/devices/nm-device-factory.c @@ -28,6 +28,10 @@ G_DEFINE_ABSTRACT_TYPE(NMDeviceFactory, nm_device_factory, G_TYPE_OBJECT) /*****************************************************************************/ +static NMDeviceFactory *generic_factory; + +/*****************************************************************************/ + static void nm_device_factory_get_supported_types(NMDeviceFactory *factory, const NMLinkType **out_link_types, @@ -66,7 +70,8 @@ nm_device_factory_create_device(NMDeviceFactory *factory, if (plink) { g_return_val_if_fail(!connection, NULL); g_return_val_if_fail(strcmp(iface, plink->name) == 0, NULL); - nm_assert(factory == nm_device_factory_manager_find_factory_for_link_type(plink->type)); + nm_assert(factory == nm_device_factory_manager_find_factory_for_link_type(plink->type) + || factory == generic_factory); } else if (connection) nm_assert(factory == nm_device_factory_manager_find_factory_for_connection(connection)); else @@ -185,6 +190,12 @@ static void __attribute__((destructor)) _cleanup(void) } NMDeviceFactory * +nm_device_factory_get_generic_factory(void) +{ + return generic_factory; +} + +NMDeviceFactory * nm_device_factory_manager_find_factory_for_link_type(NMLinkType link_type) { g_return_val_if_fail(factories_by_link, NULL); @@ -300,9 +311,12 @@ _load_internal_factory(GType factory_gtype, gpointer user_data) { gs_unref_object NMDeviceFactory *factory = NULL; + GType nm_generic_device_factory_get_type(void); factory = g_object_new(factory_gtype, NULL); _add_factory(factory, NULL, callback, user_data); + if (factory_gtype == nm_generic_device_factory_get_type()) + generic_factory = factory; } static void @@ -396,6 +410,7 @@ nm_device_factory_manager_load_factories(NMDeviceFactoryManagerFactoryFunc callb _ADD_INTERNAL(nm_bridge_device_factory_get_type); _ADD_INTERNAL(nm_dummy_device_factory_get_type); _ADD_INTERNAL(nm_ethernet_device_factory_get_type); + _ADD_INTERNAL(nm_generic_device_factory_get_type); _ADD_INTERNAL(nm_hsr_device_factory_get_type); _ADD_INTERNAL(nm_infiniband_device_factory_get_type); _ADD_INTERNAL(nm_ip_tunnel_device_factory_get_type); diff --git a/src/core/devices/nm-device-factory.h b/src/core/devices/nm-device-factory.h index fc3d9dd4..004ae9b1 100644 --- a/src/core/devices/nm-device-factory.h +++ b/src/core/devices/nm-device-factory.h @@ -234,4 +234,6 @@ NMDeviceFactory *nm_device_factory_manager_find_factory_for_connection(NMConnect void nm_device_factory_manager_for_each_factory(NMDeviceFactoryManagerFactoryFunc callback, gpointer user_data); +NMDeviceFactory *nm_device_factory_get_generic_factory(void); + #endif /* __NETWORKMANAGER_DEVICE_FACTORY_H__ */ diff --git a/src/core/devices/nm-device-generic.c b/src/core/devices/nm-device-generic.c index ead671d4..85f65246 100644 --- a/src/core/devices/nm-device-generic.c +++ b/src/core/devices/nm-device-generic.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* - * Copyright (C) 2013 Red Hat, Inc. + * Copyright (C) 2013-2023 Red Hat, Inc. */ #include "src/core/nm-default-daemon.h" @@ -10,13 +10,27 @@ #include "nm-device-private.h" #include "libnm-platform/nm-platform.h" #include "libnm-core-intern/nm-core-internal.h" +#include "nm-dispatcher.h" +#include "nm-device-factory.h" + +#define _NMLOG_DEVICE_TYPE NMDeviceGeneric +#include "devices/nm-device-logging.h" /*****************************************************************************/ -NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_TYPE_DESCRIPTION, ); +NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceGeneric, PROP_TYPE_DESCRIPTION, PROP_HAS_DEVICE_HANDLER, ); typedef struct { - const char *type_description; + const char *type_description; + bool prepare_done : 1; + bool has_device_handler : 1; + NMDispatcherCallId *dispatcher_call_id; + struct { + NMDeviceDeactivateCallback callback; + gpointer callback_data; + GCancellable *cancellable; + gulong cancellable_id; + } deactivate; } NMDeviceGenericPrivate; struct _NMDeviceGeneric { @@ -38,13 +52,151 @@ G_DEFINE_TYPE(NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) static NMDeviceCapabilities get_generic_capabilities(NMDevice *device) { - int ifindex = nm_device_get_ifindex(device); + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(device); + int ifindex = nm_device_get_ifindex(device); + NMDeviceCapabilities cap = NM_DEVICE_CAP_NONE; + + if (priv->has_device_handler) + cap |= NM_DEVICE_CAP_IS_SOFTWARE; if (ifindex > 0 && nm_platform_link_supports_carrier_detect(nm_device_get_platform(device), ifindex)) - return NM_DEVICE_CAP_CARRIER_DETECT; - else - return NM_DEVICE_CAP_NONE; + cap |= NM_DEVICE_CAP_CARRIER_DETECT; + + return cap; +} + +static void +device_add_dispatcher_cb(NMDispatcherCallId *call_id, + gpointer user_data, + gboolean success, + const char *error, + GHashTable *dict) +{ + nm_auto_unref_object NMDeviceGeneric *self = NM_DEVICE_GENERIC(user_data); + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); + NMDevice *device = NM_DEVICE(self); + NMPlatform *platform = nm_device_get_platform(device); + const NMPlatformLink *link; + int ifindex = -1; + const char *ifindex_str; + NMSettingConnection *s_con; + + nm_assert(call_id == priv->dispatcher_call_id); + priv->dispatcher_call_id = NULL; + + if (!success) { + _LOGW(LOGD_CORE, "device handler 'device-add' failed: %s", error); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED); + return; + } + + ifindex_str = g_hash_table_lookup(dict, "IFINDEX"); + if (!ifindex_str) { + _LOGW(LOGD_CORE, "device handler 'device-add' didn't return a IFINDEX key"); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED); + return; + } + + ifindex = _nm_utils_ascii_str_to_int64(ifindex_str, 10, 1, G_MAXINT32, -1); + if (ifindex < 0) { + _LOGW(LOGD_CORE, "device handler 'device-add' returned invalid ifindex '%s'", ifindex_str); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED); + return; + } + + _LOGD(LOGD_DEVICE, "device handler 'device-add' returned ifindex %d", ifindex); + + /* Check that the ifindex is valid and matches the interface name. */ + nm_platform_process_events(platform); + link = nm_platform_link_get(platform, ifindex); + if (!link) { + _LOGW(LOGD_DEVICE, + "device handler 'device-add' didn't create link with ifindex %d", + ifindex); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED); + return; + } + + s_con = nm_device_get_applied_setting(device, NM_TYPE_SETTING_CONNECTION); + nm_assert(s_con); + + if (!nm_streq(link->name, nm_setting_connection_get_interface_name(s_con))) { + _LOGW(LOGD_DEVICE, + "device handler 'device-add' created a kernel link with name '%s' instead of '%s'", + link->name, + nm_setting_connection_get_interface_name(s_con)); + nm_device_state_changed(device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED); + return; + } + + priv->prepare_done = TRUE; + nm_device_activate_schedule_stage1_device_prepare(device, FALSE); +} + +static NMActStageReturn +act_stage1_prepare(NMDevice *self, NMDeviceStateReason *out_failure_reason) +{ + NMDevice *device = NM_DEVICE(self); + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(device); + NMSettingGeneric *s_generic; + const char *type_desc; + int ifindex; + + s_generic = nm_device_get_applied_setting(device, NM_TYPE_SETTING_GENERIC); + g_return_val_if_fail(s_generic, NM_ACT_STAGE_RETURN_FAILURE); + + if (!nm_setting_generic_get_device_handler(s_generic)) + return NM_ACT_STAGE_RETURN_SUCCESS; + + if (priv->prepare_done) { + /* after we create a new interface via a device-handler, update the + * type description */ + ifindex = nm_device_get_ip_ifindex(NM_DEVICE(self)); + if (ifindex > 0) { + type_desc = nm_platform_link_get_type_name(nm_device_get_platform(device), ifindex); + if (!nm_streq0(priv->type_description, type_desc)) { + priv->type_description = type_desc; + _notify(NM_DEVICE_GENERIC(self), PROP_TYPE_DESCRIPTION); + } + } + return NM_ACT_STAGE_RETURN_SUCCESS; + } + + if (priv->dispatcher_call_id) { + nm_dispatcher_call_cancel(priv->dispatcher_call_id); + priv->dispatcher_call_id = NULL; + } + + _LOGD(LOGD_CORE, "calling device handler 'device-add'"); + if (!nm_dispatcher_call_device_handler(NM_DISPATCHER_ACTION_DEVICE_ADD, + device, + NULL, + device_add_dispatcher_cb, + g_object_ref(self), + &priv->dispatcher_call_id)) { + _LOGW(LOGD_DEVICE, "failed to call device handler 'device-add'"); + NM_SET_OUT(out_failure_reason, NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + + return NM_ACT_STAGE_RETURN_POSTPONE; +} + +static void +act_stage3_ip_config(NMDevice *device, int addr_family) +{ + nm_device_devip_set_state(device, addr_family, NM_DEVICE_IP_STATE_READY, NULL); } static const char * @@ -110,6 +262,111 @@ update_connection(NMDevice *device, NMConnection *connection) NULL); } +static gboolean +create_and_realize(NMDevice *device, + NMConnection *connection, + NMDevice *parent, + const NMPlatformLink **out_plink, + GError **error) +{ + /* The actual interface is created during stage1 once the device + * starts activating, as we need to call the dispatcher service + * which returns asynchronously */ + return TRUE; +} + +static void +deactivate_clear_data(NMDeviceGeneric *self) +{ + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); + + if (priv->dispatcher_call_id) { + nm_dispatcher_call_cancel(priv->dispatcher_call_id); + priv->dispatcher_call_id = NULL; + } + + priv->deactivate.callback = NULL; + priv->deactivate.callback_data = NULL; + g_clear_object(&priv->deactivate.cancellable); +} + +static void +device_delete_dispatcher_cb(NMDispatcherCallId *call_id, + gpointer user_data, + gboolean success, + const char *error, + GHashTable *dict) +{ + NMDeviceGeneric *self = user_data; + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); + gs_free_error GError *local = NULL; + + nm_assert(call_id == priv->dispatcher_call_id); + priv->dispatcher_call_id = NULL; + + if (success) + _LOGT(LOGD_DEVICE, "deactivate: async callback"); + else { + local = g_error_new(NM_DEVICE_ERROR, + NM_DEVICE_ERROR_FAILED, + "device handler 'device-delete' failed with error: %s", + error); + } + + priv->deactivate.callback(NM_DEVICE(self), local, priv->deactivate.callback_data); + nm_clear_g_cancellable_disconnect(priv->deactivate.cancellable, + &priv->deactivate.cancellable_id); + deactivate_clear_data(self); +} + +static void +deactivate_cancellable_cancelled(GCancellable *cancellable, NMDeviceGeneric *self) +{ + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); + gs_free_error GError *error = NULL; + + error = nm_utils_error_new_cancelled(FALSE, NULL); + priv->deactivate.callback(NM_DEVICE(self), error, priv->deactivate.callback_data); + + deactivate_clear_data(self); +} + +static void +deactivate_async(NMDevice *device, + GCancellable *cancellable, + NMDeviceDeactivateCallback callback, + gpointer callback_user_data) +{ + NMDeviceGeneric *self = NM_DEVICE_GENERIC(device); + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); + + _LOGT(LOGD_CORE, "deactivate: start async"); + + priv->prepare_done = FALSE; + + if (priv->dispatcher_call_id) { + nm_dispatcher_call_cancel(priv->dispatcher_call_id); + priv->dispatcher_call_id = NULL; + } + + g_object_ref(self); + priv->deactivate.callback = callback; + priv->deactivate.callback_data = callback_user_data; + priv->deactivate.cancellable = g_object_ref(cancellable); + priv->deactivate.cancellable_id = + g_cancellable_connect(cancellable, + G_CALLBACK(deactivate_cancellable_cancelled), + self, + NULL); + + nm_dispatcher_call_device_handler(NM_DISPATCHER_ACTION_DEVICE_DELETE, + device, + NULL, + device_delete_dispatcher_cb, + self, + &priv->dispatcher_call_id); +} + /*****************************************************************************/ static void @@ -122,6 +379,26 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) case PROP_TYPE_DESCRIPTION: g_value_set_string(value, priv->type_description); break; + case PROP_HAS_DEVICE_HANDLER: + g_value_set_boolean(value, priv->has_device_handler); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NMDeviceGeneric *self = (NMDeviceGeneric *) object; + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self); + + switch (prop_id) { + case PROP_HAS_DEVICE_HANDLER: + /* construct-only */ + priv->has_device_handler = g_value_get_boolean(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -137,16 +414,41 @@ nm_device_generic_init(NMDeviceGeneric *self) static GObject * constructor(GType type, guint n_construct_params, GObjectConstructParam *construct_params) { - GObject *object; + GObject *object; + NMDeviceGenericPrivate *priv; object = G_OBJECT_CLASS(nm_device_generic_parent_class) ->constructor(type, n_construct_params, construct_params); - nm_device_set_unmanaged_flags((NMDevice *) object, NM_UNMANAGED_BY_DEFAULT, TRUE); + priv = NM_DEVICE_GENERIC_GET_PRIVATE(object); + /* If the device is software (has a device-handler), don't set + * unmanaged-by-default so that the device can autoconnect if + * necessary. */ + if (!priv->has_device_handler) + nm_device_set_unmanaged_flags((NMDevice *) object, NM_UNMANAGED_BY_DEFAULT, TRUE); return object; } +static NMDevice * +create_device(NMDeviceFactory *factory, + const char *iface, + const NMPlatformLink *plink, + NMConnection *connection, + gboolean *out_ignore) +{ + return g_object_new(NM_TYPE_DEVICE_GENERIC, + NM_DEVICE_IFACE, + iface, + NM_DEVICE_TYPE_DESC, + "Generic", + NM_DEVICE_DEVICE_TYPE, + NM_DEVICE_TYPE_GENERIC, + NM_DEVICE_GENERIC_HAS_DEVICE_HANDLER, + TRUE, + NULL); +} + NMDevice * nm_device_generic_new(const NMPlatformLink *plink, gboolean nm_plugin_missing) { @@ -188,6 +490,7 @@ nm_device_generic_class_init(NMDeviceGenericClass *klass) object_class->constructor = constructor; object_class->get_property = get_property; + object_class->set_property = set_property; dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_generic); @@ -195,10 +498,14 @@ nm_device_generic_class_init(NMDeviceGenericClass *klass) device_class->connection_type_check_compatible = NM_SETTING_GENERIC_SETTING_NAME; device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES(NM_LINK_TYPE_ANY); - device_class->realize_start_notify = realize_start_notify; + device_class->act_stage1_prepare = act_stage1_prepare; + device_class->act_stage3_ip_config = act_stage3_ip_config; + device_class->check_connection_compatible = check_connection_compatible; + device_class->create_and_realize = create_and_realize; + device_class->deactivate_async = deactivate_async; device_class->get_generic_capabilities = get_generic_capabilities; device_class->get_type_description = get_type_description; - device_class->check_connection_compatible = check_connection_compatible; + device_class->realize_start_notify = realize_start_notify; device_class->update_connection = update_connection; obj_properties[PROP_TYPE_DESCRIPTION] = @@ -207,6 +514,18 @@ nm_device_generic_class_init(NMDeviceGenericClass *klass) "", NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - + obj_properties[PROP_HAS_DEVICE_HANDLER] = g_param_spec_boolean( + NM_DEVICE_GENERIC_HAS_DEVICE_HANDLER, + "", + "", + FALSE, + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); } + +NM_DEVICE_FACTORY_DEFINE_INTERNAL( + GENERIC, + Generic, + generic, + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_GENERIC_SETTING_NAME), + factory_class->create_device = create_device;); diff --git a/src/core/devices/nm-device-generic.h b/src/core/devices/nm-device-generic.h index f06a5bdc..07cb5447 100644 --- a/src/core/devices/nm-device-generic.h +++ b/src/core/devices/nm-device-generic.h @@ -18,7 +18,8 @@ #define NM_DEVICE_GENERIC_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericClass)) -#define NM_DEVICE_GENERIC_TYPE_DESCRIPTION "type-description" +#define NM_DEVICE_GENERIC_TYPE_DESCRIPTION "type-description" +#define NM_DEVICE_GENERIC_HAS_DEVICE_HANDLER "has-device-handler" typedef struct _NMDeviceGeneric NMDeviceGeneric; typedef struct _NMDeviceGenericClass NMDeviceGenericClass; diff --git a/src/core/devices/nm-device-macsec.c b/src/core/devices/nm-device-macsec.c index 130708bb..32fab5be 100644 --- a/src/core/devices/nm-device-macsec.c +++ b/src/core/devices/nm-device-macsec.c @@ -10,6 +10,7 @@ #include <linux/if_ether.h> #include "nm-act-request.h" +#include "nm-config.h" #include "nm-device-private.h" #include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" @@ -190,6 +191,7 @@ build_supplicant_config(NMDeviceMacsec *self, GError **error) NMConnection *connection; const char *con_uuid; guint32 mtu; + int offload; connection = nm_device_get_applied_connection(NM_DEVICE(self)); @@ -205,7 +207,20 @@ build_supplicant_config(NMDeviceMacsec *self, GError **error) g_return_val_if_fail(s_macsec, NULL); - if (!nm_supplicant_config_add_setting_macsec(config, s_macsec, error)) { + offload = nm_setting_macsec_get_offload(s_macsec); + if (offload == NM_SETTING_MACSEC_OFFLOAD_DEFAULT) { + offload = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA, + NM_CON_DEFAULT("macsec.offload"), + NM_DEVICE(self), + NM_SETTING_MACSEC_OFFLOAD_OFF, + NM_SETTING_MACSEC_OFFLOAD_MAC, + NM_SETTING_MACSEC_OFFLOAD_OFF); + } + + if (!nm_supplicant_config_add_setting_macsec(config, + s_macsec, + (NMSettingMacsecOffload) offload, + error)) { g_prefix_error(error, "macsec-setting: "); return NULL; } diff --git a/src/core/devices/nm-device-utils.c b/src/core/devices/nm-device-utils.c index 2bf24ae6..ed0a2738 100644 --- a/src/core/devices/nm-device-utils.c +++ b/src/core/devices/nm-device-utils.c @@ -127,7 +127,9 @@ NM_UTILS_LOOKUP_STR_DEFINE( NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_IP_METHOD_UNSUPPORTED, "ip-method-unsupported"), NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_SRIOV_CONFIGURATION_FAILED, "sriov-configuration-failed"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PEER_NOT_FOUND, "peer-not-found"), ); + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PEER_NOT_FOUND, "peer-not-found"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_DEVICE_HANDLER_FAILED, + "device-handler-failed"), ); NM_UTILS_LOOKUP_STR_DEFINE(nm_device_mtu_source_to_string, NMDeviceMtuSource, diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index a9e8c085..34022efb 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -137,8 +137,7 @@ typedef struct { GCancellable *cancellable; NMPlatformAsyncCallback callback; gpointer callback_data; - guint num_vfs; - NMOptionBool autoprobe; + NMPlatformSriovParams sriov_params; } SriovOp; typedef enum { @@ -7706,8 +7705,7 @@ sriov_op_start(NMDevice *self, SriovOp *op) nm_platform_link_set_sriov_params_async(nm_device_get_platform(self), priv->ifindex, - op->num_vfs, - op->autoprobe, + op->sriov_params, sriov_op_cb, op, op->cancellable); @@ -7768,11 +7766,14 @@ sriov_op_queue_op(NMDevice *self, SriovOp *op) } static void -sriov_op_queue(NMDevice *self, - guint num_vfs, - NMOptionBool autoprobe, - NMPlatformAsyncCallback callback, - gpointer callback_data) +sriov_op_queue(NMDevice *self, + guint num_vfs, + NMOptionBool autoprobe, + NMSriovEswitchMode eswitch_mode, + NMSriovEswitchInlineMode eswitch_inline_mode, + NMSriovEswitchEncapMode eswitch_encap_mode, + NMPlatformAsyncCallback callback, + gpointer callback_data) { SriovOp *op; @@ -7797,8 +7798,14 @@ sriov_op_queue(NMDevice *self, op = g_slice_new(SriovOp); *op = (SriovOp){ - .num_vfs = num_vfs, - .autoprobe = autoprobe, + .sriov_params = + (NMPlatformSriovParams){ + .num_vfs = num_vfs, + .autoprobe = autoprobe, + .eswitch_mode = (_NMSriovEswitchMode) eswitch_mode, + .eswitch_inline_mode = (_NMSriovEswitchInlineMode) eswitch_inline_mode, + .eswitch_encap_mode = (_NMSriovEswitchEncapMode) eswitch_encap_mode, + }, .callback = callback, .callback_data = callback_data, }; @@ -7823,7 +7830,14 @@ device_init_static_sriov_num_vfs(NMDevice *self) -1, -1); if (num_vfs >= 0) - sriov_op_queue(self, num_vfs, NM_OPTION_BOOL_DEFAULT, NULL, NULL); + sriov_op_queue(self, + num_vfs, + NM_OPTION_BOOL_DEFAULT, + NM_SRIOV_ESWITCH_MODE_PRESERVE, + NM_SRIOV_ESWITCH_INLINE_MODE_PRESERVE, + NM_SRIOV_ESWITCH_ENCAP_MODE_PRESERVE, + NULL, + NULL); } } @@ -10004,6 +10018,9 @@ activate_stage1_device_prepare(NMDevice *self) sriov_op_queue(self, nm_setting_sriov_get_total_vfs(s_sriov), NM_TERNARY_TO_OPTION_BOOL(autoprobe), + nm_setting_sriov_get_eswitch_mode(s_sriov), + nm_setting_sriov_get_eswitch_inline_mode(s_sriov), + nm_setting_sriov_get_eswitch_encap_mode(s_sriov), sriov_params_cb, nm_utils_user_data_pack(self, g_steal_pointer(&plat_vfs))); priv->stage1_sriov_state = NM_DEVICE_STAGE_STATE_PENDING; @@ -10880,7 +10897,16 @@ _dev_ipdhcpx_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_d case NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE: if (!notify_data->lease_update.l3cd) { + const NML3ConfigData *dhcp_l3cd = priv->l3cds[L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4)].d; + _LOGT_ipdhcp(addr_family, "lease lost"); + if (dhcp_l3cd + && nm_l3cfg_remove_config( + priv->l3cfg, + _dev_l3_config_data_tag_get(priv, L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4)), + dhcp_l3cd)) { + _dev_l3_cfg_commit(self, FALSE); + } goto lease_update_out; } @@ -16711,6 +16737,9 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, sriov_op_queue(self, 0, NM_OPTION_BOOL_TRUE, + NM_SRIOV_ESWITCH_MODE_PRESERVE, + NM_SRIOV_ESWITCH_INLINE_MODE_PRESERVE, + NM_SRIOV_ESWITCH_ENCAP_MODE_PRESERVE, sriov_reset_on_deactivate_cb, nm_utils_user_data_pack(self, GINT_TO_POINTER(reason))); } @@ -16760,7 +16789,14 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, if (priv->ifindex > 0 && (s_sriov = nm_device_get_applied_setting(self, NM_TYPE_SETTING_SRIOV))) { priv->sriov_reset_pending++; - sriov_op_queue(self, 0, NM_OPTION_BOOL_TRUE, sriov_reset_on_failure_cb, self); + sriov_op_queue(self, + 0, + NM_OPTION_BOOL_TRUE, + NM_SRIOV_ESWITCH_MODE_PRESERVE, + NM_SRIOV_ESWITCH_INLINE_MODE_PRESERVE, + NM_SRIOV_ESWITCH_ENCAP_MODE_PRESERVE, + sriov_reset_on_failure_cb, + self); break; } /* Schedule the transition to DISCONNECTED. The device can't transition |