diff --git a/po/POTFILES.in b/po/POTFILES.in index 20bd8f253a..1474ae715e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,6 +5,7 @@ src/core/NetworkManagerUtils.c src/core/devices/adsl/nm-device-adsl.c src/core/devices/bluetooth/nm-bluez-manager.c src/core/devices/bluetooth/nm-device-bt.c +src/core/devices/nm-device.c src/core/devices/nm-device-6lowpan.c src/core/devices/nm-device-bond.c src/core/devices/nm-device-bridge.c diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index bd8eaea2ec..d6e7a0c8c6 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -14905,6 +14905,7 @@ set_managed(NMDevice *self, gboolean managed, NMDeviceManagedFlags flags, GError nm_device_get_iface(self)); if (!nm_config_set_device_managed(nm_manager_get_config(priv->manager), + self, nm_device_get_iface(self), nm_device_get_permanent_hw_address(self), managed_to_disk, @@ -14922,6 +14923,7 @@ set_managed(NMDevice *self, gboolean managed, NMDeviceManagedFlags flags, GError * we would set the runtime state correctly, but get an unexpected state * after a reboot. */ nm_config_set_device_managed(nm_manager_get_config(priv->manager), + self, nm_device_get_iface(self), nm_device_get_permanent_hw_address(self), managed_to_disk_old, diff --git a/src/core/nm-config.c b/src/core/nm-config.c index 45614c5fb4..9f173e2e9f 100644 --- a/src/core/nm-config.c +++ b/src/core/nm-config.c @@ -2113,6 +2113,7 @@ nm_config_get_device_managed(NMConfig *self, const char *ifname) /** * nm_config_set_device_managed: * @self: the NMConfig instance + * @device: the NMDevice instance associated with this config change * @ifname: the interface name * @hwaddr: the hardware address * @managed: the managed state to set @@ -2130,6 +2131,7 @@ nm_config_get_device_managed(NMConfig *self, const char *ifname) */ gboolean nm_config_set_device_managed(NMConfig *self, + NMDevice *device, const char *ifname, const char *hwaddr, NMTernary managed, @@ -2138,7 +2140,8 @@ nm_config_set_device_managed(NMConfig *self, { NMConfigPrivate *priv; g_autoptr(GKeyFile) keyfile = NULL; - gs_free char *group = NULL; + gs_free char *group_by_name = NULL; + gs_free char *group_by_mac = NULL; gs_free char *match_value = NULL; gboolean changed = FALSE; @@ -2146,14 +2149,17 @@ nm_config_set_device_managed(NMConfig *self, g_return_val_if_fail(NM_CONFIG_GET_PRIVATE(self)->config_data, FALSE); g_return_val_if_fail(ifname && hwaddr, FALSE); - priv = NM_CONFIG_GET_PRIVATE(self); - keyfile = nm_config_data_clone_keyfile_intern(priv->config_data); - group = g_strdup_printf(NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_DEVICE "-%s", ifname); + priv = NM_CONFIG_GET_PRIVATE(self); + keyfile = nm_config_data_clone_keyfile_intern(priv->config_data); + group_by_name = g_strdup_printf(NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_DEVICE "-%s", ifname); + group_by_mac = + g_strdup_printf(NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN_DEVICE ".by-mac.%s", hwaddr); - /* Remove existing configs. Search them only by group name [.intern.device-*]. In + /* Remove existing configs. Search them by group name [.intern.device-*] or [.intern.device.by-mac.*]. In * the intern file, 'device' sections are only used for this purpose, so we won't remove * any other device's config. */ - if (g_key_file_remove_group(keyfile, group, NULL)) + if (g_key_file_remove_group(keyfile, group_by_name, NULL) + || g_key_file_remove_group(keyfile, group_by_mac, NULL)) changed = TRUE; /* If the new state is not explicitly TRUE of FALSE, we only remove the configs */ @@ -2166,8 +2172,14 @@ nm_config_set_device_managed(NMConfig *self, else match_value = g_strdup_printf("interface-name:=%s", ifname); - g_key_file_set_value(keyfile, group, NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE, match_value); - g_key_file_set_value(keyfile, group, NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED, managed ? "1" : "0"); + g_key_file_set_value(keyfile, + by_mac ? group_by_mac : group_by_name, + NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE, + match_value); + g_key_file_set_value(keyfile, + by_mac ? group_by_mac : group_by_name, + NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED, + managed ? "1" : "0"); changed = TRUE; done: diff --git a/src/core/nm-config.h b/src/core/nm-config.h index 6f33246ca8..bf9e922f39 100644 --- a/src/core/nm-config.h +++ b/src/core/nm-config.h @@ -144,6 +144,7 @@ void nm_config_set_connectivity_check_enabled(NMConfig *self, gboolean enabled); NMTernary nm_config_get_device_managed(NMConfig *self, const char *ifname); gboolean nm_config_set_device_managed(NMConfig *self, + NMDevice *device, const char *ifname, const char *hwaddr, NMTernary managed, diff --git a/src/libnm-core-public/nm-dbus-interface.h b/src/libnm-core-public/nm-dbus-interface.h index 74bf204a44..72b04b9ec9 100644 --- a/src/libnm-core-public/nm-dbus-interface.h +++ b/src/libnm-core-public/nm-dbus-interface.h @@ -1251,8 +1251,7 @@ typedef enum /*< flags >*/ { * @NM_DEVICE_MANAGED_FLAGS_TO_DISK: to also persist the device managed state to disk. * @NM_DEVICE_MANAGED_FLAGS_BY_MAC: to match the device by MAC address, not by name. * This option only makes sense together with %NM_DEVICE_MANAGED_FLAGS_TO_DISK. - * @NM_DEVICE_MANAGED_FLAGS_CLEAR_DISK: to clear the managed flag from disk. Implies - * %NM_DEVICE_MANAGED_FLAGS_TO_DISK. + * @NM_DEVICE_MANAGED_FLAGS_CLEAR_DISK: to clear the managed flag from disk. * @NM_DEVICE_MANAGED_FLAGS_SET_ADMIN_STATE: to set the administrative state of the * device to up if the managed state is TRUE, and down if the managed state is FALSE. * If the flag is not set, the administrative state is not changed.