From eff0e0d1233d834403accad29cb7ec05ea4f915b Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 19 May 2020 21:26:53 +0200 Subject: [PATCH] device: add mechanism to call stage1 for external or assumed devices Usually stage1 is skipped for external or assumed devices. Add a mechanism to call stage1 for all devices, similarly to what was already done for stage2. --- src/devices/nm-device.c | 22 +++++++++++++--------- src/devices/nm-device.h | 5 +++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index e6fe97493a..dc46d3f7cc 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6960,6 +6960,7 @@ activate_stage1_device_prepare (NMDevice *self) NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS; NMActiveConnection *active; NMActiveConnection *master; + NMDeviceClass *klass; priv->v4_route_table_initialized = FALSE; priv->v6_route_table_initialized = FALSE; @@ -7033,18 +7034,21 @@ activate_stage1_device_prepare (NMDevice *self) } /* Assumed connections were already set up outside NetworkManager */ - if (!nm_device_sys_iface_state_is_external_or_assume (self)) { - NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self); + klass = NM_DEVICE_GET_CLASS (self); - if (klass->act_stage1_prepare_set_hwaddr_ethernet) { - if (!nm_device_hw_addr_set_cloned (self, - nm_device_get_applied_connection (self), - FALSE)) { - nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_CONFIG_FAILED); - return; - } + if ( klass->act_stage1_prepare_set_hwaddr_ethernet + && !nm_device_sys_iface_state_is_external_or_assume (self)) { + if (!nm_device_hw_addr_set_cloned (self, + nm_device_get_applied_connection (self), + FALSE)) { + nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + return; } + } + if ( klass->act_stage1_prepare_also_for_external_or_assume + || !nm_device_sys_iface_state_is_external_or_assume (self)) { + nm_assert (!klass->act_stage1_prepare_also_for_external_or_assume || klass->act_stage1_prepare); if (klass->act_stage1_prepare) { NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 8d51c707dd..fa6559fd60 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -445,9 +445,10 @@ typedef struct _NMDeviceClass { gboolean (* set_platform_mtu) (NMDevice *self, guint32 mtu); - /* Controls, whether to call act_stage2_config() callback also for assuming - * a device or for external activations. In this case, act_stage2_config() must + /* Control whether to call stage1 and stage2 callbacks also for assuming + * a device or for external activations. In this case, the callback must * take care not to touch the device's configuration. */ + bool act_stage1_prepare_also_for_external_or_assume:1; bool act_stage2_config_also_for_external_or_assume:1; bool act_stage1_prepare_set_hwaddr_ethernet:1;