summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-03-04 13:38:49 +0100
committerThomas Haller <thaller@redhat.com>2020-03-04 16:53:04 +0100
commit5477847eed9654727df5b70767a2a6498da1cb67 (patch)
treeda9a3c6a09fc0018580838e0e0ab2137e2877809
parentecb0210e7a225f2b73149229cc96ac84f93404d1 (diff)
downloadNetworkManager-5477847eed9654727df5b70767a2a6498da1cb67.tar.gz
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.
-rw-r--r--src/nm-manager.c34
-rw-r--r--src/nm-manager.h2
2 files changed, 22 insertions, 14 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 90a1562b5e..99e658f26b 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -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));
}
}
diff --git a/src/nm-manager.h b/src/nm-manager.h
index ad06e318f4..5873abd24b 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -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 */