summaryrefslogtreecommitdiff
path: root/src/nm-manager.c
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2018-07-06 21:09:58 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2018-08-02 16:39:44 +0200
commit060f2138ee988255f160371d2a4bc2a45f942ced (patch)
tree81a870480b1091cb510a42bd1020cdb571a998d8 /src/nm-manager.c
parentbdebb8e2cf82498c589f38bf1d6878ff43451846 (diff)
downloadNetworkManager-060f2138ee988255f160371d2a4bc2a45f942ced.tar.gz
manager: rename nm_manager_write_device_state()
Rename nm_manager_write_device_state() to nm_manager_write_device_state_all(), and split out the code to write a single device state to a new function.
Diffstat (limited to 'src/nm-manager.c')
-rw-r--r--src/nm-manager.c107
1 files changed, 58 insertions, 49 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 630180963a..b4c2b08fe0 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -5934,66 +5934,75 @@ start_factory (NMDeviceFactory *factory, gpointer user_data)
nm_device_factory_start (factory);
}
-void
-nm_manager_write_device_state (NMManager *self)
+gboolean
+nm_manager_write_device_state (NMManager *self, NMDevice *device)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- NMDevice *device;
- gs_unref_hashtable GHashTable *seen_ifindexes = NULL;
+ int ifindex;
+ gboolean managed;
+ NMConfigDeviceStateManagedType managed_type;
+ NMConnection *settings_connection;
+ const char *uuid = NULL;
+ const char *perm_hw_addr_fake = NULL;
+ gboolean perm_hw_addr_is_fake;
+ guint32 route_metric_default_aspired;
+ guint32 route_metric_default_effective;
int nm_owned;
- seen_ifindexes = g_hash_table_new (nm_direct_hash, NULL);
+ ifindex = nm_device_get_ip_ifindex (device);
+ if (ifindex <= 0)
+ return FALSE;
+ if (ifindex == 1) {
+ /* ignore loopback */
+ return FALSE;
+ }
- c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) {
- int ifindex;
- gboolean managed;
- NMConfigDeviceStateManagedType managed_type;
- NMConnection *settings_connection;
- const char *uuid = NULL;
- const char *perm_hw_addr_fake = NULL;
- gboolean perm_hw_addr_is_fake;
- guint32 route_metric_default_aspired;
- guint32 route_metric_default_effective;
-
- ifindex = nm_device_get_ip_ifindex (device);
- if (ifindex <= 0)
- continue;
- if (ifindex == 1) {
- /* ignore loopback */
- continue;
- }
+ if (!nm_platform_link_get (priv->platform, ifindex))
+ return FALSE;
- if (!nm_platform_link_get (priv->platform, ifindex))
- continue;
+ managed = nm_device_get_managed (device, FALSE);
+ if (managed) {
+ settings_connection = NM_CONNECTION (nm_device_get_settings_connection (device));
+ if (settings_connection)
+ uuid = nm_connection_get_uuid (settings_connection);
+ managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED;
+ } else if (nm_device_get_unmanaged_flags (device, NM_UNMANAGED_USER_EXPLICIT))
+ managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED;
+ else
+ managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN;
- managed = nm_device_get_managed (device, FALSE);
- if (managed) {
- settings_connection = NM_CONNECTION (nm_device_get_settings_connection (device));
- if (settings_connection)
- uuid = nm_connection_get_uuid (settings_connection);
- managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_MANAGED;
- } else if (nm_device_get_unmanaged_flags (device, NM_UNMANAGED_USER_EXPLICIT))
- managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNMANAGED;
- else
- managed_type = NM_CONFIG_DEVICE_STATE_MANAGED_TYPE_UNKNOWN;
+ perm_hw_addr_fake = nm_device_get_permanent_hw_address_full (device, FALSE, &perm_hw_addr_is_fake);
+ if (perm_hw_addr_fake && !perm_hw_addr_is_fake)
+ perm_hw_addr_fake = NULL;
+
+ nm_owned = nm_device_is_software (device) ? nm_device_is_nm_owned (device) : -1;
- perm_hw_addr_fake = nm_device_get_permanent_hw_address_full (device, FALSE, &perm_hw_addr_is_fake);
- if (perm_hw_addr_fake && !perm_hw_addr_is_fake)
- perm_hw_addr_fake = NULL;
+ route_metric_default_effective = _device_route_metric_get (self, ifindex, NM_DEVICE_TYPE_UNKNOWN,
+ TRUE, &route_metric_default_aspired);
- nm_owned = nm_device_is_software (device) ? nm_device_is_nm_owned (device) : -1;
+ return nm_config_device_state_write (ifindex,
+ managed_type,
+ perm_hw_addr_fake,
+ uuid,
+ nm_owned,
+ route_metric_default_aspired,
+ route_metric_default_effective);
+}
+
+void
+nm_manager_write_device_state_all (NMManager *self)
+{
+ NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+ gs_unref_hashtable GHashTable *seen_ifindexes = NULL;
+ NMDevice *device;
- route_metric_default_effective = _device_route_metric_get (self, ifindex, NM_DEVICE_TYPE_UNKNOWN,
- TRUE, &route_metric_default_aspired);
+ seen_ifindexes = g_hash_table_new (nm_direct_hash, NULL);
- if (nm_config_device_state_write (ifindex,
- managed_type,
- perm_hw_addr_fake,
- uuid,
- nm_owned,
- route_metric_default_aspired,
- route_metric_default_effective))
- g_hash_table_add (seen_ifindexes, GINT_TO_POINTER (ifindex));
+ c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) {
+ if (nm_manager_write_device_state (self, device)) {
+ g_hash_table_add (seen_ifindexes,
+ GINT_TO_POINTER (nm_device_get_ip_ifindex (device)));
+ }
}
nm_config_device_state_prune_unseen (seen_ifindexes);