core: return ifindex from nm_manager_write_device_state()

nm_manager_write_device_state() writes the device state to a file. The ifindex
is here important, because that is the identifier for the device and is also
used as file name. Return the ifindex that was used, instead of letting the
caller reimplement the knowledge which ifindex was used.
This commit is contained in:
Thomas Haller 2020-03-04 13:38:49 +01:00
parent ecb0210e7a
commit 5477847eed
2 changed files with 22 additions and 14 deletions

View file

@ -1516,7 +1516,7 @@ manager_device_state_changed (NMDevice *device,
NM_DEVICE_STATE_UNMANAGED,
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_ACTIVATED))
nm_manager_write_device_state (self, device);
nm_manager_write_device_state (self, device, NULL);
if (NM_IN_SET (new_state,
NM_DEVICE_STATE_UNAVAILABLE,
@ -6484,7 +6484,7 @@ start_factory (NMDeviceFactory *factory, gpointer user_data)
}
gboolean
nm_manager_write_device_state (NMManager *self, NMDevice *device)
nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifindex)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
int ifindex;
@ -6500,6 +6500,8 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device)
const char *next_server = NULL;
const char *root_path = NULL;
NM_SET_OUT (out_ifindex, 0);
ifindex = nm_device_get_ip_ifindex (device);
if (ifindex <= 0)
return FALSE;
@ -6540,15 +6542,19 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device)
next_server = nm_dhcp_config_get_option (dhcp_config, "next_server");
}
return nm_config_device_state_write (ifindex,
managed_type,
perm_hw_addr_fake,
uuid,
nm_owned,
route_metric_default_aspired,
route_metric_default_effective,
next_server,
root_path);
if (!nm_config_device_state_write (ifindex,
managed_type,
perm_hw_addr_fake,
uuid,
nm_owned,
route_metric_default_aspired,
route_metric_default_effective,
next_server,
root_path))
return FALSE;
NM_SET_OUT (out_ifindex, ifindex);
return TRUE;
}
void
@ -6561,9 +6567,11 @@ nm_manager_write_device_state_all (NMManager *self)
preserve_ifindexes = g_hash_table_new (nm_direct_hash, NULL);
c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) {
if (nm_manager_write_device_state (self, device)) {
int ifindex;
if (nm_manager_write_device_state (self, device, &ifindex)) {
g_hash_table_add (preserve_ifindexes,
GINT_TO_POINTER (nm_device_get_ip_ifindex (device)));
GINT_TO_POINTER (ifindex));
}
}

View file

@ -103,7 +103,7 @@ NMSettingsConnection **nm_manager_get_activatable_connections (NMManager *manage
guint *out_len);
void nm_manager_write_device_state_all (NMManager *manager);
gboolean nm_manager_write_device_state (NMManager *manager, NMDevice *device);
gboolean nm_manager_write_device_state (NMManager *manager, NMDevice *device, int *out_ifindex);
/* Device handling */