diff --git a/src/devices/nm-device-ethernet-utils.c b/src/devices/nm-device-ethernet-utils.c index d034ddfc77..298e6dff95 100644 --- a/src/devices/nm-device-ethernet-utils.c +++ b/src/devices/nm-device-ethernet-utils.c @@ -25,30 +25,26 @@ #include "nm-device-ethernet-utils.h" char * -nm_device_ethernet_utils_get_default_wired_name (const GSList *connections) +nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connections) { - const GSList *iter; - char *cname = NULL; - int i = 0; + char *temp; + guint j; + int i; /* Find the next available unique connection name */ - while (!cname && (i++ < 10000)) { - char *temp; - gboolean found = FALSE; - + for (i = 1; i <= 10000; i++) { temp = g_strdup_printf (_("Wired connection %d"), i); - for (iter = connections; iter; iter = iter->next) { - if (g_strcmp0 (nm_connection_get_id (NM_CONNECTION (iter->data)), temp) == 0) { - found = TRUE; + for (j = 0; connections[j]; j++) { + if (nm_streq0 (nm_connection_get_id (connections[j]), temp)) { g_free (temp); - break; + goto next; } } - - if (found == FALSE) - cname = temp; + return temp; +next: + ; } - return cname; + return NULL; } diff --git a/src/devices/nm-device-ethernet-utils.h b/src/devices/nm-device-ethernet-utils.h index 31d645d851..197d0a9ea4 100644 --- a/src/devices/nm-device-ethernet-utils.h +++ b/src/devices/nm-device-ethernet-utils.h @@ -19,8 +19,6 @@ #ifndef __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__ #define __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__ -#include "nm-default.h" - -char *nm_device_ethernet_utils_get_default_wired_name (const GSList *connections); +char *nm_device_ethernet_utils_get_default_wired_name (NMConnection *const *connections); #endif /* NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H */ diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index d27f7dcaf1..96cc6db34e 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -21,6 +21,8 @@ #include "nm-default.h" +#include "nm-device-ethernet.h" + #include #include #include @@ -29,7 +31,6 @@ #include -#include "nm-device-ethernet.h" #include "nm-device-private.h" #include "nm-activation-request.h" #include "NetworkManagerUtils.h" @@ -44,7 +45,7 @@ #include "nm-settings-connection.h" #include "nm-config.h" #include "nm-device-ethernet-utils.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-device-factory.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" @@ -1435,7 +1436,7 @@ static NMConnection * new_default_connection (NMDevice *self) { NMConnection *connection; - const GSList *connections; + NMSettingsConnection *const*connections; NMSetting *setting; const char *hw_address; gs_free char *defname = NULL; @@ -1453,8 +1454,8 @@ new_default_connection (NMDevice *self) setting = nm_setting_connection_new (); nm_connection_add_setting (connection, setting); - connections = nm_connection_provider_get_connections (nm_connection_provider_get ()); - defname = nm_device_ethernet_utils_get_default_wired_name (connections); + connections = nm_settings_get_connections (nm_device_get_settings (self), NULL); + defname = nm_device_ethernet_utils_get_default_wired_name ((NMConnection *const*) connections); if (!defname) return NULL; diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c index 089b10352c..785010ebfa 100644 --- a/src/devices/nm-device-ip-tunnel.c +++ b/src/devices/nm-device-ip-tunnel.c @@ -20,19 +20,20 @@ #include "nm-default.h" +#include "nm-device-ip-tunnel.h" + #include #include #include #include #include -#include "nm-device-ip-tunnel.h" #include "nm-device-private.h" #include "nm-manager.h" #include "nm-platform.h" #include "nm-device-factory.h" #include "nm-core-internal.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-ip4-config.h" @@ -385,8 +386,8 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), - setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), + setting_parent); if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index c431fe891c..c5443ecd23 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -20,11 +20,12 @@ #include "nm-default.h" +#include "nm-device-macvlan.h" + #include -#include "nm-device-macvlan.h" #include "nm-device-private.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-manager.h" #include "nm-platform.h" @@ -488,7 +489,7 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); if (parent_connection && nm_device_check_connection_compatible (priv->parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 1f81ed0eab..418ae2d9ca 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -42,6 +42,8 @@ enum NMActStageReturn { #define NM_DEVICE_CAP_INTERNAL_MASK 0xc0000000 +NMSettings *nm_device_get_settings (NMDevice *self); + void nm_device_set_ip_iface (NMDevice *self, const char *iface); void nm_device_activate_schedule_stage3_ip_config_start (NMDevice *device); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index eb6527de8e..95f36298f5 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -20,15 +20,16 @@ #include "nm-default.h" +#include "nm-device-vlan.h" + #include -#include "nm-device-vlan.h" #include "nm-manager.h" #include "nm-utils.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-enum-types.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-ip4-config.h" #include "nm-platform.h" @@ -515,7 +516,7 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); if (parent_connection && nm_device_check_connection_compatible (priv->parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index d308d47abc..f3dfbd9ef5 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -20,9 +20,10 @@ #include "nm-default.h" +#include "nm-device-vxlan.h" + #include -#include "nm-device-vxlan.h" #include "nm-device-private.h" #include "nm-manager.h" #include "nm-platform.h" @@ -30,7 +31,7 @@ #include "nm-device-factory.h" #include "nm-setting-vxlan.h" #include "nm-setting-wired.h" -#include "nm-connection-provider.h" +#include "nm-settings.h" #include "nm-activation-request.h" #include "nm-ip4-config.h" @@ -411,8 +412,8 @@ update_connection (NMDevice *device, NMConnection *connection) NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ - parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), - setting_parent); + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), + setting_parent); if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) new_parent = NULL; } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 9fa026b4c0..1726687825 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -550,6 +550,12 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_reason_to_string, NMDeviceStateReason, /***********************************************************/ +NMSettings * +nm_device_get_settings (NMDevice *self) +{ + return NM_DEVICE_GET_PRIVATE (self)->settings; +} + static void init_ip4_config_dns_priority (NMDevice *self, NMIP4Config *config) { diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 95a89eab32..c2df72482c 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -21,13 +21,14 @@ #include "nm-default.h" +#include "nm-device-wifi.h" + #include #include #include #include #include "nm-device.h" -#include "nm-device-wifi.h" #include "nm-device-private.h" #include "nm-utils.h" #include "NetworkManagerUtils.h" @@ -45,8 +46,9 @@ #include "nm-platform.h" #include "nm-auth-utils.h" #include "nm-settings-connection.h" -#include "nm-enum-types.h" +#include "nm-settings.h" #include "nm-connection-provider.h" +#include "nm-enum-types.h" #include "nm-core-internal.h" #include "nm-config.h" @@ -1224,7 +1226,7 @@ build_hidden_probe_list (NMDeviceWifi *self) if (G_UNLIKELY (nullssid == NULL)) nullssid = g_byte_array_new (); - connections = nm_connection_provider_get_best_connections (nm_connection_provider_get (), + connections = nm_connection_provider_get_best_connections ((NMConnectionProvider *) nm_device_get_settings ((NMDevice *) self), max_scan_ssids - 1, NM_SETTING_WIRELESS_SETTING_NAME, NULL, @@ -1456,10 +1458,12 @@ schedule_ap_list_dump (NMDeviceWifi *self) } static void -try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) +try_fill_ssid_for_hidden_ap (NMDeviceWifi *self, + NMAccessPoint *ap) { const char *bssid; - const GSList *connections, *iter; + NMSettingsConnection *const*connections; + guint i; g_return_if_fail (nm_ap_get_ssid (ap) == NULL); @@ -1468,9 +1472,9 @@ try_fill_ssid_for_hidden_ap (NMAccessPoint *ap) /* Look for this AP's BSSID in the seen-bssids list of a connection, * and if a match is found, copy over the SSID */ - connections = nm_connection_provider_get_connections (nm_connection_provider_get ()); - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMConnection *connection = NM_CONNECTION (iter->data); + connections = nm_settings_get_connections (nm_device_get_settings ((NMDevice *) self), NULL); + for (i = 0; connections[i]; i++) { + NMConnection *connection = (NMConnection *) connections[i]; NMSettingWireless *s_wifi; s_wifi = nm_connection_get_setting_wireless (connection); @@ -1520,7 +1524,7 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, ssid = nm_ap_get_ssid (ap); if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) { /* Try to fill the SSID from the AP database */ - try_fill_ssid_for_hidden_ap (ap); + try_fill_ssid_for_hidden_ap (self, ap); ssid = nm_ap_get_ssid (ap); if (ssid && (nm_utils_is_empty_ssid (ssid->data, ssid->len) == FALSE)) { diff --git a/src/tests/test-wired-defname.c b/src/tests/test-wired-defname.c index bed1bb5ad1..3ae3a19d95 100644 --- a/src/tests/test-wired-defname.c +++ b/src/tests/test-wired-defname.c @@ -41,12 +41,28 @@ _new_connection (const char *id) /*******************************************/ +static char * +_get_default_wired_name (GSList *list) +{ + gs_free NMConnection **v = NULL; + guint l, i; + + l = g_slist_length (list); + v = g_new0 (NMConnection *, l + 1); + for (i = 0; list; list = list->next, i++) + v[i] = NM_CONNECTION (list->data); + g_assert (i == l); + return nm_device_ethernet_utils_get_default_wired_name (v); +} + +/*******************************************/ + static void test_defname_no_connections (void) { gs_free char *name = NULL; - name = nm_device_ethernet_utils_get_default_wired_name (NULL); + name = _get_default_wired_name (NULL); g_assert_cmpstr (name, ==, "Wired connection 1"); } @@ -62,7 +78,7 @@ test_defname_no_conflict (void) list = g_slist_append (list, _new_connection ("work wifi")); list = g_slist_append (list, _new_connection ("random gsm connection")); - name = nm_device_ethernet_utils_get_default_wired_name (list); + name = _get_default_wired_name (list); g_assert_cmpstr (name, ==, "Wired connection 1"); g_slist_free_full (list, g_object_unref); @@ -80,7 +96,7 @@ test_defname_conflict (void) list = g_slist_append (list, _new_connection ("Wired connection 1")); list = g_slist_append (list, _new_connection ("random gsm connection")); - name = nm_device_ethernet_utils_get_default_wired_name (list); + name = _get_default_wired_name (list); g_assert_cmpstr (name, ==, "Wired connection 2"); g_slist_free_full (list, g_object_unref); @@ -102,7 +118,7 @@ test_defname_multiple_conflicts (void) list = g_slist_append (list, _new_connection ("work wifi")); list = g_slist_append (list, _new_connection ("a vpn")); - name = nm_device_ethernet_utils_get_default_wired_name (list); + name = _get_default_wired_name (list); g_assert_cmpstr (name, ==, "Wired connection 4"); g_slist_free_full (list, g_object_unref);