mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-25 11:50:40 +01:00
fixup! core: config: implement storing to disk for Device.SetManaged()
This commit is contained in:
parent
c2e104ec22
commit
c4c9eccfcc
5 changed files with 25 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue