/src/settings/plugins/ifnet/tests/check_ifnet
/src/settings/plugins/ifupdown/tests/test-ifupdown
/src/settings/plugins/keyfile/tests/test-keyfile
-/src/settings/tests/test-wired-defname
/src/supplicant-manager/tests/test-supplicant-config
/src/tests/config/test-config
/src/tests/test-dcb
/src/tests/test-ip4-config
/src/tests/test-ip6-config
/src/tests/test-resolvconf-capture
+/src/tests/test-wired-defname
/vapi/*.vapi
src/devices/nm-device-bond.c
src/devices/nm-device-bridge.c
src/devices/nm-device-ethernet.c
+src/devices/nm-device-ethernet-utils.c
src/devices/nm-device-infiniband.c
src/devices/nm-device-vlan.c
src/devices/team/nm-device-team.c
src/nm-sleep-monitor-systemd.c
src/settings/plugins/ibft/plugin.c
src/settings/plugins/ifcfg-rh/reader.c
-src/settings/nm-settings-utils.c
dnsmasq-manager/tests \
platform \
rdisc \
- settings/tests \
supplicant-manager/tests \
tests
endif
devices/nm-device-bridge.h \
devices/nm-device-ethernet.c \
devices/nm-device-ethernet.h \
+ devices/nm-device-ethernet-utils.c \
+ devices/nm-device-ethernet-utils.h \
devices/nm-device-factory.c \
devices/nm-device-factory.h \
devices/nm-device-generic.c \
settings/nm-settings-connection.h \
settings/nm-settings-error.c \
settings/nm-settings-error.h \
- settings/nm-settings-utils.c \
- settings/nm-settings-utils.h \
settings/nm-settings.c \
settings/nm-settings.h \
settings/nm-system-config-interface.c \
#include <glib/gi18n.h>
#include <nm-connection.h>
-#include "nm-settings-utils.h"
+#include "nm-device-ethernet-utils.h"
char *
-nm_settings_utils_get_default_wired_name (GHashTable *connections)
+nm_device_ethernet_utils_get_default_wired_name (const GSList *connections)
{
- GHashTableIter iter;
- NMConnection *connection = NULL;
- GSList *names = NULL, *niter;
+ const GSList *iter;
char *cname = NULL;
int i = 0;
- /* Build up a list of all existing connection names for dupe checking */
- g_hash_table_iter_init (&iter, connections);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) {
- const char *id;
-
- id = nm_connection_get_id (connection);
- g_assert (id);
- names = g_slist_append (names, (gpointer) id);
- }
-
/* Find the next available unique connection name */
while (!cname && (i++ < 10000)) {
char *temp;
gboolean found = FALSE;
temp = g_strdup_printf (_("Wired connection %d"), i);
- for (niter = names; niter; niter = g_slist_next (niter)) {
- if (g_strcmp0 (niter->data, temp) == 0) {
+ for (iter = connections; iter; iter = iter->next) {
+ if (g_strcmp0 (nm_connection_get_id (NM_CONNECTION (iter->data)), temp) == 0) {
found = TRUE;
g_free (temp);
break;
if (found == FALSE)
cname = temp;
}
- g_slist_free (names);
return cname;
}
* (C) Copyright 2011 Red Hat, Inc.
*/
-#ifndef __NETWORKMANAGER_SETTINGS_UTILS_H__
-#define __NETWORKMANAGER_SETTINGS_UTILS_H__
+#ifndef __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__
+#define __NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H__
#include <glib.h>
-char *nm_settings_utils_get_default_wired_name (GHashTable *connections);
+char *nm_device_ethernet_utils_get_default_wired_name (const GSList *connections);
-#endif /* NM_SETTINGS_UTILS_H */
+#endif /* NETWORKMANAGER_DEVICE_ETHERNET_UTILS_H */
#include "nm-platform.h"
#include "nm-dcb.h"
#include "nm-settings-connection.h"
+#include "nm-config.h"
+#include "nm-device-ethernet-utils.h"
+#include "nm-connection-provider.h"
#include "nm-device-ethernet-glue.h"
return TRUE;
}
+static NMConnection *
+new_default_connection (NMDevice *self)
+{
+ NMConnection *connection;
+ const GSList *connections;
+ NMSetting *setting;
+ const char *hw_address;
+ char *defname, *uuid;
+ GByteArray *mac;
+
+ if (!nm_config_get_ethernet_can_auto_default (nm_config_get (), self))
+ return NULL;
+
+ hw_address = nm_device_get_hw_address (self);
+ if (!hw_address)
+ return NULL;
+
+ connection = nm_simple_connection_new ();
+ 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);
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (setting,
+ NM_SETTING_CONNECTION_ID, defname,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
+ NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
+ NULL);
+ g_free (uuid);
+ g_free (defname);
+
+ /* Lock the connection to the device */
+ setting = nm_setting_wired_new ();
+ nm_connection_add_setting (connection, setting);
+
+ mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
+ g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
+ g_byte_array_unref (mac);
+
+ return connection;
+}
+
static gboolean
spec_match_list (NMDevice *device, const GSList *specs)
{
parent_class->update_initial_hw_address = update_initial_hw_address;
parent_class->check_connection_compatible = check_connection_compatible;
parent_class->complete_connection = complete_connection;
+ parent_class->new_default_connection = new_default_connection;
parent_class->act_stage1_prepare = act_stage1_prepare;
parent_class->act_stage2_config = act_stage2_config;
return FALSE;
}
+NMConnection *
+nm_device_new_default_connection (NMDevice *self)
+{
+ if (NM_DEVICE_GET_CLASS (self)->new_default_connection)
+ return NM_DEVICE_GET_CLASS (self)->new_default_connection (self);
+ return NULL;
+}
+
static void
slave_state_changed (NMDevice *slave,
NMDeviceState slave_new_state,
gboolean (* component_added) (NMDevice *self, GObject *component);
gboolean (* owns_iface) (NMDevice *self, const char *iface);
+
+ NMConnection * (* new_default_connection) (NMDevice *self);
} NMDeviceClass;
gboolean nm_device_owns_iface (NMDevice *device, const char *iface);
+NMConnection *nm_device_new_default_connection (NMDevice *self);
+
G_END_DECLS
/* For testing only */
#include "nm-session-monitor.h"
#include "plugins/keyfile/plugin.h"
#include "nm-agent-manager.h"
-#include "nm-settings-utils.h"
#include "nm-connection-provider.h"
#include "nm-config.h"
#include "NetworkManagerUtils.h"
void
nm_settings_device_added (NMSettings *self, NMDevice *device)
{
- NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
NMConnection *connection;
NMSettingsConnection *added;
- NMSetting *setting;
GError *error = NULL;
- const char *hw_address;
- char *defname, *uuid;
- GByteArray *mac;
-
- if (!NM_IS_DEVICE_ETHERNET (device))
- return;
/* If the device isn't managed or it already has a default wired connection,
* ignore it.
*/
if ( !nm_device_get_managed (device)
|| g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG)
- || have_connection_for_device (self, device)
- || !nm_config_get_ethernet_can_auto_default (priv->config, device))
+ || have_connection_for_device (self, device))
return;
- hw_address = nm_device_get_hw_address (device);
- if (!hw_address)
+ connection = nm_device_new_default_connection (device);
+ if (!connection)
return;
- connection = nm_simple_connection_new ();
- setting = nm_setting_connection_new ();
- nm_connection_add_setting (connection, setting);
-
- defname = nm_settings_utils_get_default_wired_name (priv->connections);
- uuid = nm_utils_uuid_generate ();
- g_object_set (setting,
- NM_SETTING_CONNECTION_ID, defname,
- NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
- NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
- NM_SETTING_CONNECTION_UUID, uuid,
- NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
- NULL);
- g_free (uuid);
- g_free (defname);
-
- /* Lock the connection to the device */
- setting = nm_setting_wired_new ();
- nm_connection_add_setting (connection, setting);
-
- mac = nm_utils_hwaddr_atoba (hw_address, ETH_ALEN);
- g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
- g_byte_array_unref (mac);
-
/* Add the connection */
added = nm_settings_add_connection (self, connection, FALSE, &error);
g_object_unref (connection);
+++ /dev/null
-AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_srcdir)/libnm-core \
- -I$(top_builddir)/libnm-core \
- -I$(top_srcdir)/src/settings \
- -DG_LOG_DOMAIN=\""NetworkManager"\" \
- -DNETWORKMANAGER_COMPILATION \
- -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
- $(GLIB_CFLAGS)
-
-noinst_PROGRAMS = \
- test-wired-defname
-
-####### wired defname test #######
-
-test_wired_defname_SOURCES = \
- test-wired-defname.c
-
-test_wired_defname_LDADD = \
- $(top_builddir)/src/libNetworkManager.la
-
-###########################################
-
-TESTS = test-wired-defname
-I$(top_builddir)/libnm-core \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/dhcp-manager \
+ -I$(top_srcdir)/src/devices \
-I$(top_srcdir)/src \
-I$(top_builddir)/src \
-DG_LOG_DOMAIN=\""NetworkManager"\" \
test-ip4-config \
test-ip6-config \
test-dcb \
- test-resolvconf-capture
+ test-resolvconf-capture \
+ test-wired-defname
####### ip4 config test #######
test_general_with_expect_LDADD = \
$(top_builddir)/src/libNetworkManager.la
+####### wired defname test #######
+
+test_wired_defname_SOURCES = \
+ test-wired-defname.c
+
+test_wired_defname_LDADD = \
+ $(top_builddir)/src/libNetworkManager.la
+
####### secret agent interface test #######
EXTRA_DIST = test-secret-agent.py
###########################################
-TESTS = test-ip4-config test-ip6-config test-dcb test-resolvconf-capture test-general test-general-with-expect
+TESTS = \
+ test-ip4-config \
+ test-ip6-config \
+ test-dcb \
+ test-resolvconf-capture \
+ test-general \
+ test-general-with-expect \
+ test-wired-defname
#include <nm-simple-connection.h>
#include <nm-setting-connection.h>
-#include "nm-settings-utils.h"
+#include "nm-device-ethernet-utils.h"
static NMConnection *
_new_connection (const char *id)
static void
test_defname_no_connections (void)
{
- GHashTable *hash;
char *name;
- hash = g_hash_table_new (g_direct_hash, g_direct_equal);
-
- name = nm_settings_utils_get_default_wired_name (hash);
+ name = nm_device_ethernet_utils_get_default_wired_name (NULL);
g_assert_cmpstr (name, ==, "Wired connection 1");
-
- g_hash_table_destroy (hash);
}
/*******************************************/
static void
test_defname_no_conflict (void)
{
- GHashTable *hash;
+ GSList *list = NULL;
char *name;
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref);
-
- g_hash_table_insert (hash, "a", _new_connection ("asdfasdfasdfadf"));
- g_hash_table_insert (hash, "b", _new_connection ("work wifi"));
- g_hash_table_insert (hash, "c", _new_connection ("random gsm connection"));
+ list = g_slist_append (list, _new_connection ("asdfasdfasdfadf"));
+ list = g_slist_append (list, _new_connection ("work wifi"));
+ list = g_slist_append (list, _new_connection ("random gsm connection"));
- name = nm_settings_utils_get_default_wired_name (hash);
+ name = nm_device_ethernet_utils_get_default_wired_name (list);
g_assert_cmpstr (name, ==, "Wired connection 1");
- g_hash_table_destroy (hash);
+ g_slist_free_full (list, g_object_unref);
}
/*******************************************/
static void
test_defname_conflict (void)
{
- GHashTable *hash;
+ GSList *list = NULL;
char *name;
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref);
+ list = g_slist_append (list, _new_connection ("asdfasdfasdfadf"));
+ list = g_slist_append (list, _new_connection ("Wired connection 1"));
+ list = g_slist_append (list, _new_connection ("random gsm connection"));
- g_hash_table_insert (hash, "a", _new_connection ("asdfasdfasdfadf"));
- g_hash_table_insert (hash, "b", _new_connection ("Wired connection 1"));
- g_hash_table_insert (hash, "c", _new_connection ("random gsm connection"));
-
- name = nm_settings_utils_get_default_wired_name (hash);
+ name = nm_device_ethernet_utils_get_default_wired_name (list);
g_assert_cmpstr (name, ==, "Wired connection 2");
- g_hash_table_destroy (hash);
+ g_slist_free_full (list, g_object_unref);
}
/*******************************************/
static void
test_defname_multiple_conflicts (void)
{
- GHashTable *hash;
+ GSList *list = NULL;
char *name;
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_object_unref);
-
- g_hash_table_insert (hash, "a", _new_connection ("random gsm connection"));
- g_hash_table_insert (hash, "b", _new_connection ("home wifi"));
- g_hash_table_insert (hash, "c", _new_connection ("Wired connection 1"));
- g_hash_table_insert (hash, "d", _new_connection ("Wired connection 2"));
- g_hash_table_insert (hash, "e", _new_connection ("Wired connection 3"));
- g_hash_table_insert (hash, "f", _new_connection ("work wifi"));
- g_hash_table_insert (hash, "g", _new_connection ("a vpn"));
+ list = g_slist_append (list, _new_connection ("random gsm connection"));
+ list = g_slist_append (list, _new_connection ("home wifi"));
+ list = g_slist_append (list, _new_connection ("Wired connection 1"));
+ list = g_slist_append (list, _new_connection ("Wired connection 2"));
+ list = g_slist_append (list, _new_connection ("Wired connection 3"));
+ list = g_slist_append (list, _new_connection ("work wifi"));
+ list = g_slist_append (list, _new_connection ("a vpn"));
- name = nm_settings_utils_get_default_wired_name (hash);
+ name = nm_device_ethernet_utils_get_default_wired_name (list);
g_assert_cmpstr (name, ==, "Wired connection 4");
- g_hash_table_destroy (hash);
+ g_slist_free_full (list, g_object_unref);
}
/*******************************************/