From a27c7e3721151ba8db1920d088b5f61af4910b74 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 29 Jul 2014 22:23:25 -0500 Subject: [PATCH 1/6] ifcfg-rh: trivial: remove unused parameter --- src/settings/plugins/ifcfg-rh/reader.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index e95bcb422..cbaf0aaeb 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -4724,7 +4724,6 @@ static NMSetting * make_vlan_setting (shvarFile *ifcfg, const char *file, char **out_master, - NMSetting8021x **s_8021x, GError **error) { NMSettingVlan *s_vlan = NULL; @@ -4866,7 +4865,7 @@ vlan_connection_from_ifcfg (const char *file, } nm_connection_add_setting (connection, con_setting); - vlan_setting = make_vlan_setting (ifcfg, file, &master, &s_8021x, error); + vlan_setting = make_vlan_setting (ifcfg, file, &master, error); if (!vlan_setting) { g_object_unref (connection); return NULL; From 448254f76197fc74ebba8c2419605c64e5b2cd23 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 30 Jul 2014 15:37:31 -0500 Subject: [PATCH 2/6] ibft: add settings plugin for reading iBFT configuration (bgo #734009) Instead of handling iBFT (iSCSI Boot Firmware Table) in the ifcfg-rh plugin, create a new plugin for it. This allows all distributions to use iBFT configuration, and makes both iBFT handling and ifcfg-rh less complicated. The plugin (like the old ifcfg-rh code) creates read-only connections backed by the data exported by iscsiadm. The plugin does not support adding new connections or modifying existing connections (since the iBFT data is read-only anyway). Instead, users should change their iBFT data through the normal firmware interfaces. Unmanaged devices can be configured through NetworkManager.conf and the normal 'keyfile' mechanisms. (In the future, we'll read this data directly from the kernel's /sys/firmware/ibft/ethernetX directory instead of iscsiadm, since the kernel has all the information we need and that's where iscsiadm gets it from anyway.) https://bugzilla.gnome.org/show_bug.cgi?id=734009 --- .gitignore | 1 + configure.ac | 2 + include/nm-test-utils.h | 46 ++ po/POTFILES.in | 1 + src/settings/plugins/Makefile.am | 2 +- src/settings/plugins/ibft/Makefile.am | 40 ++ src/settings/plugins/ibft/errors.c | 34 ++ src/settings/plugins/ibft/errors.h | 29 + .../plugins/ibft/nm-ibft-connection.c | 65 ++ .../plugins/ibft/nm-ibft-connection.h | 50 ++ src/settings/plugins/ibft/plugin.c | 211 +++++++ src/settings/plugins/ibft/plugin.h | 47 ++ src/settings/plugins/ibft/reader.c | 565 ++++++++++++++++++ src/settings/plugins/ibft/reader.h | 36 ++ src/settings/plugins/ibft/tests/Makefile.am | 50 ++ .../plugins/ibft/tests/iscsiadm-test-bad-dns1 | 21 + .../plugins/ibft/tests/iscsiadm-test-bad-dns2 | 21 + .../ibft/tests/iscsiadm-test-bad-entry | 20 + .../ibft/tests/iscsiadm-test-bad-gateway | 21 + .../ibft/tests/iscsiadm-test-bad-ipaddr | 21 + .../ibft/tests/iscsiadm-test-bad-record | 18 + .../plugins/ibft/tests/iscsiadm-test-dhcp | 33 + .../plugins/ibft/tests/iscsiadm-test-static | 35 ++ .../plugins/ibft/tests/iscsiadm-test-vlan | 19 + src/settings/plugins/ibft/tests/test-ibft.c | 295 +++++++++ 25 files changed, 1682 insertions(+), 1 deletion(-) create mode 100644 src/settings/plugins/ibft/Makefile.am create mode 100644 src/settings/plugins/ibft/errors.c create mode 100644 src/settings/plugins/ibft/errors.h create mode 100644 src/settings/plugins/ibft/nm-ibft-connection.c create mode 100644 src/settings/plugins/ibft/nm-ibft-connection.h create mode 100644 src/settings/plugins/ibft/plugin.c create mode 100644 src/settings/plugins/ibft/plugin.h create mode 100644 src/settings/plugins/ibft/reader.c create mode 100644 src/settings/plugins/ibft/reader.h create mode 100644 src/settings/plugins/ibft/tests/Makefile.am create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-bad-record create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-dhcp create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-static create mode 100755 src/settings/plugins/ibft/tests/iscsiadm-test-vlan create mode 100644 src/settings/plugins/ibft/tests/test-ibft.c diff --git a/.gitignore b/.gitignore index ca36160d4..6df12700a 100644 --- a/.gitignore +++ b/.gitignore @@ -222,6 +222,7 @@ valgrind-*.log /src/dhcp-manager/tests/test-dhcp-dhclient /src/dhcp-manager/tests/test-dhcp-options /src/dnsmasq-manager/tests/test-dnsmasq-utils +/src/settings/plugins/ibft/tests/test-ibft /src/settings/plugins/ifcfg-rh/tests/network-scripts/*-Test_Write_* /src/settings/plugins/ifcfg-rh/tests/network-scripts/Test_Write_* /src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh diff --git a/configure.ac b/configure.ac index 6bc94b948..1bc73f6eb 100644 --- a/configure.ac +++ b/configure.ac @@ -843,6 +843,8 @@ src/settings/plugins/ifnet/tests/Makefile src/settings/plugins/ifcfg-rh/Makefile src/settings/plugins/ifcfg-rh/tests/Makefile src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile +src/settings/plugins/ibft/Makefile +src/settings/plugins/ibft/tests/Makefile src/settings/plugins/ifcfg-suse/Makefile src/settings/plugins/keyfile/Makefile src/settings/plugins/keyfile/tests/Makefile diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 9c8009355..0bff1c299 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -958,5 +958,51 @@ nmtst_assert_connection_unnormalizable (NMConnection *con, #endif +static inline void +nmtst_assert_ip4_address_equals (guint32 addr, const char *expected, const char *loc) +{ + guint32 addr2 = nmtst_inet4_from_string (expected); + + if (addr != addr2) + g_error ("assert: %s: ip4 address '%s' expected, but got %s", + loc, expected ? expected : "any", nm_utils_inet4_ntop (addr, NULL)); +} +#define nmtst_assert_ip4_address_equals(addr, expected) \ + nmtst_assert_ip4_address_equals (addr, expected, G_STRLOC) + +#ifdef __NM_UTILS_H__ +static inline void +nmtst_assert_hwaddr_equals (gconstpointer hwaddr1, gssize hwaddr1_len, const char *expected, const char *loc) +{ + guint8 buf2[NM_UTILS_HWADDR_LEN_MAX]; + gsize hwaddr2_len = 1; + const char *p; + gboolean success; + + g_assert (hwaddr1_len > 0 && hwaddr1_len <= NM_UTILS_HWADDR_LEN_MAX); + + g_assert (expected); + for (p = expected; *p; p++) { + if (*p == ':' || *p == '-') + hwaddr2_len++; + } + g_assert (hwaddr2_len <= NM_UTILS_HWADDR_LEN_MAX); + g_assert (nm_utils_hwaddr_aton (expected, buf2, hwaddr2_len)); + + /* Manually check the entire hardware address instead of using + * nm_utils_hwaddr_matches() because that function doesn't compare + * entire InfiniBand addresses for various (legitimate) reasons. + */ + success = (hwaddr1_len == hwaddr2_len); + if (success) + success = !memcmp (hwaddr1, buf2, hwaddr1_len); + if (!success) { + g_error ("assert: %s: hwaddr '%s' (%zd) expected, but got %s (%zd)", + loc, expected, hwaddr2_len, nm_utils_hwaddr_ntoa (hwaddr1, hwaddr1_len), hwaddr1_len); + } +} +#define nmtst_assert_hwaddr_equals(hwaddr1, hwaddr1_len, expected) \ + nmtst_assert_hwaddr_equals (hwaddr1, hwaddr1_len, expected, G_STRLOC) +#endif #endif /* __NM_TEST_UTILS_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 2c6c0e3e5..a7e75c43a 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -123,5 +123,6 @@ src/nm-config.c src/nm-logging.c src/nm-manager.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 diff --git a/src/settings/plugins/Makefile.am b/src/settings/plugins/Makefile.am index 41694e7e4..22f417107 100644 --- a/src/settings/plugins/Makefile.am +++ b/src/settings/plugins/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=keyfile example +SUBDIRS=keyfile example ibft @GNOME_CODE_COVERAGE_RULES@ diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am new file mode 100644 index 000000000..c687cf300 --- /dev/null +++ b/src/settings/plugins/ibft/Makefile.am @@ -0,0 +1,40 @@ +SUBDIRS = . tests + +@GNOME_CODE_COVERAGE_RULES@ + +pkglib_LTLIBRARIES = libnm-settings-plugin-ibft.la + +noinst_LTLIBRARIES = libibft-io.la + +libibft_io_la_SOURCES = \ + reader.c \ + reader.h \ + errors.c \ + errors.h + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/ \ + -I$(top_srcdir)/src/platform \ + -I$(top_srcdir)/src/settings \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ + -DNETWORKMANAGER_COMPILATION \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ + -DSBINDIR=\"$(sbindir)\" + +libnm_settings_plugin_ibft_la_SOURCES = \ + plugin.c \ + plugin.h \ + nm-ibft-connection.c \ + nm-ibft-connection.h + +libnm_settings_plugin_ibft_la_LDFLAGS = -module -avoid-version +libnm_settings_plugin_ibft_la_LIBADD = libibft-io.la + +CLEANFILES = $(BUILT_SOURCES) + diff --git a/src/settings/plugins/ibft/errors.c b/src/settings/plugins/ibft/errors.c new file mode 100644 index 000000000..ead26867b --- /dev/null +++ b/src/settings/plugins/ibft/errors.c @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#include +#include "errors.h" + +GQuark +ibft_plugin_error_quark (void) +{ + static GQuark error_quark = 0; + + if (G_UNLIKELY (error_quark == 0)) + error_quark = g_quark_from_static_string ("ibft-plugin-error-quark"); + return error_quark; +} + + diff --git a/src/settings/plugins/ibft/errors.h b/src/settings/plugins/ibft/errors.h new file mode 100644 index 000000000..cb3756775 --- /dev/null +++ b/src/settings/plugins/ibft/errors.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef __ERRORS_H__ +#define __ERRORS_H__ + +#define IBFT_PLUGIN_ERROR (ibft_plugin_error_quark ()) +GQuark ibft_plugin_error_quark (void); + + +#endif /* __ERRORS_H__ */ + diff --git a/src/settings/plugins/ibft/nm-ibft-connection.c b/src/settings/plugins/ibft/nm-ibft-connection.c new file mode 100644 index 000000000..2ed4679e5 --- /dev/null +++ b/src/settings/plugins/ibft/nm-ibft-connection.c @@ -0,0 +1,65 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#include +#include +#include + +#include + +#include "nm-ibft-connection.h" +#include "errors.h" +#include "reader.h" + +G_DEFINE_TYPE (NMIbftConnection, nm_ibft_connection, NM_TYPE_SETTINGS_CONNECTION) + +NMIbftConnection * +nm_ibft_connection_new (const GPtrArray *block, GError **error) +{ + NMConnection *source; + GObject *object; + + source = connection_from_block (block, error); + if (!source) + return NULL; + + object = g_object_new (NM_TYPE_IBFT_CONNECTION, NULL); + /* Update settings with what was read from iscsiadm */ + if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), + source, + FALSE, + error)) + g_clear_object (&object); + + return (NMIbftConnection *) object; +} + +/* GObject */ + +static void +nm_ibft_connection_init (NMIbftConnection *connection) +{ +} + +static void +nm_ibft_connection_class_init (NMIbftConnectionClass *ibft_connection_class) +{ +} + diff --git a/src/settings/plugins/ibft/nm-ibft-connection.h b/src/settings/plugins/ibft/nm-ibft-connection.h new file mode 100644 index 000000000..4ccebc3ce --- /dev/null +++ b/src/settings/plugins/ibft/nm-ibft-connection.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef NM_IBFT_CONNECTION_H +#define NM_IBFT_CONNECTION_H + +G_BEGIN_DECLS + +#include + +#define NM_TYPE_IBFT_CONNECTION (nm_ibft_connection_get_type ()) +#define NM_IBFT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IBFT_CONNECTION, NMIbftConnection)) +#define NM_IBFT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IBFT_CONNECTION, NMIbftConnectionClass)) +#define NM_IS_IBFT_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IBFT_CONNECTION)) +#define NM_IS_IBFT_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IBFT_CONNECTION)) +#define NM_IBFT_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IBFT_CONNECTION, NMIbftConnectionClass)) + +typedef struct { + NMSettingsConnection parent; +} NMIbftConnection; + +typedef struct { + NMSettingsConnectionClass parent; +} NMIbftConnectionClass; + +GType nm_ibft_connection_get_type (void); + +NMIbftConnection *nm_ibft_connection_new (const GPtrArray *block, + GError **error); + +G_END_DECLS + +#endif /* NM_IBFT_CONNECTION_H */ diff --git a/src/settings/plugins/ibft/plugin.c b/src/settings/plugins/ibft/plugin.c new file mode 100644 index 000000000..c8f9b589d --- /dev/null +++ b/src/settings/plugins/ibft/plugin.c @@ -0,0 +1,211 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "nm-dbus-glib-types.h" +#include "nm-system-config-interface.h" +#include "nm-settings-error.h" +#include "nm-logging.h" +#include "NetworkManagerUtils.h" + +#include "plugin.h" +#include "errors.h" +#include "reader.h" +#include "nm-ibft-connection.h" + +static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class); + +G_DEFINE_TYPE_EXTENDED (SCPluginIbft, sc_plugin_ibft, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE, + system_config_interface_init)) + +#define SC_PLUGIN_IBFT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_IBFT, SCPluginIbftPrivate)) + + +typedef struct { + GHashTable *connections; /* uuid::connection */ + gboolean initialized; +} SCPluginIbftPrivate; + +static void +read_connections (SCPluginIbft *self) +{ + SCPluginIbftPrivate *priv = SC_PLUGIN_IBFT_GET_PRIVATE (self); + GSList *blocks, *iter; + GError *error = NULL; + NMIbftConnection *connection; + + if (!read_ibft_blocks ("/sbin/iscsiadm", &blocks, &error)) { + nm_log_dbg (LOGD_SETTINGS, _("ibft: failed to read iscsiadm records: %s"), error->message); + g_error_free (error); + return; + } + + for (iter = blocks; iter; iter = iter->next) { + connection = nm_ibft_connection_new (iter->data, &error); + if (connection) { + nm_log_info (LOGD_SETTINGS, _("ibft: read connection '%s'"), + nm_connection_get_id (NM_CONNECTION (connection))); + g_hash_table_insert (priv->connections, + g_strdup (nm_connection_get_uuid (NM_CONNECTION (connection))), + connection); + } else { + nm_log_warn (LOGD_SETTINGS, _("ibft: failed to read iscsiadm record: %s"), error->message); + g_clear_error (&error); + } + } + + g_slist_free_full (blocks, (GDestroyNotify) g_ptr_array_unref); +} + +static GSList * +get_connections (NMSystemConfigInterface *config) +{ + SCPluginIbft *self = SC_PLUGIN_IBFT (config); + SCPluginIbftPrivate *priv = SC_PLUGIN_IBFT_GET_PRIVATE (self); + GSList *list = NULL; + GHashTableIter iter; + NMIbftConnection *connection; + + if (!priv->initialized) { + read_connections (self); + priv->initialized = TRUE; + } + + g_hash_table_iter_init (&iter, priv->connections); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) + list = g_slist_prepend (list, connection); + + return list; +} + +static void +init (NMSystemConfigInterface *config) +{ +} + +static void +sc_plugin_ibft_init (SCPluginIbft *self) +{ + SCPluginIbftPrivate *priv = SC_PLUGIN_IBFT_GET_PRIVATE (self); + + priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); +} + +static void +dispose (GObject *object) +{ + SCPluginIbft *self = SC_PLUGIN_IBFT (object); + SCPluginIbftPrivate *priv = SC_PLUGIN_IBFT_GET_PRIVATE (self); + + if (priv->connections) { + g_hash_table_destroy (priv->connections); + priv->connections = NULL; + } + + G_OBJECT_CLASS (sc_plugin_ibft_parent_class)->dispose (object); +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + switch (prop_id) { + case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME: + g_value_set_string (value, "iBFT"); + break; + case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO: + g_value_set_string (value, "(c) 2014 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."); + break; + case NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES: + g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_NONE); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); +} + +static void +sc_plugin_ibft_class_init (SCPluginIbftClass *req_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (req_class); + + g_type_class_add_private (req_class, sizeof (SCPluginIbftPrivate)); + + object_class->dispose = dispose; + object_class->get_property = get_property; + object_class->set_property = set_property; + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME, + NM_SYSTEM_CONFIG_INTERFACE_NAME); + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO, + NM_SYSTEM_CONFIG_INTERFACE_INFO); + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES, + NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES); + + g_object_class_override_property (object_class, + NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME, + NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); +} + +static void +system_config_interface_init (NMSystemConfigInterface *system_config_interface_class) +{ + /* interface implementation */ + system_config_interface_class->get_connections = get_connections; + system_config_interface_class->init = init; +} + +G_MODULE_EXPORT GObject * +nm_system_config_factory (void) +{ + static SCPluginIbft *singleton = NULL; + + if (!singleton) + singleton = SC_PLUGIN_IBFT (g_object_new (SC_TYPE_PLUGIN_IBFT, NULL)); + else + g_object_ref (singleton); + + return G_OBJECT (singleton); +} diff --git a/src/settings/plugins/ibft/plugin.h b/src/settings/plugins/ibft/plugin.h new file mode 100644 index 000000000..2c811359e --- /dev/null +++ b/src/settings/plugins/ibft/plugin.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef _PLUGIN_H_ +#define _PLUGIN_H_ + +#include + +#define SC_TYPE_PLUGIN_IBFT (sc_plugin_ibft_get_type ()) +#define SC_PLUGIN_IBFT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SC_TYPE_PLUGIN_IBFT, SCPluginIbft)) +#define SC_PLUGIN_IBFT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SC_TYPE_PLUGIN_IBFT, SCPluginIbftClass)) +#define SC_IS_PLUGIN_IBFT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_PLUGIN_IBFT)) +#define SC_IS_PLUGIN_IBFT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_PLUGIN_IBFT)) +#define SC_PLUGIN_IBFT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SC_TYPE_PLUGIN_IBFT, SCPluginIbftClass)) + +typedef struct _SCPluginIbft SCPluginIbft; +typedef struct _SCPluginIbftClass SCPluginIbftClass; + +struct _SCPluginIbft { + GObject parent; +}; + +struct _SCPluginIbftClass { + GObjectClass parent; +}; + +GType sc_plugin_ibft_get_type (void); + +#endif /* _PLUGIN_H_ */ + diff --git a/src/settings/plugins/ibft/reader.c b/src/settings/plugins/ibft/reader.c new file mode 100644 index 000000000..908ba6901 --- /dev/null +++ b/src/settings/plugins/ibft/reader.c @@ -0,0 +1,565 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nm-platform.h" +#include "nm-posix-signals.h" +#include "NetworkManagerUtils.h" +#include "nm-logging.h" + +#include "errors.h" +#include "reader.h" + +#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg) + +static void +iscsiadm_child_setup (gpointer user_data G_GNUC_UNUSED) +{ + /* We are in the child process here; set a different process group to + * ensure signal isolation between child and parent. + */ + pid_t pid = getpid (); + setpgid (pid, pid); + + /* + * We blocked signals in main(). We need to restore original signal + * mask for iscsiadm here so that it can receive signals. + */ + nm_unblock_posix_signals (NULL); +} + +/* Removes trailing whitespace and whitespace before and immediately after the '=' */ +static char * +remove_most_whitespace (const char *src) +{ + char *s_new, *s2; + const char *svalue; + + while (*src && g_ascii_isspace (*src)) + src++; + + svalue = strchr (src, '='); + if (!svalue || svalue == src) + return NULL; + + s_new = g_new (char, strlen (src) + 1); + + memcpy (s_new, src, svalue - src); + s_new[svalue - src] = '\0'; + g_strchomp (s_new); + + svalue++; + while (*svalue && g_ascii_isspace (*svalue)) + svalue++; + + s2 = strchr (s_new, '\0'); + s2[0] = '='; + strcpy (++s2, svalue); + g_strchomp (s2); + + return s_new; +} + +#define TAG_BEGIN "# BEGIN RECORD" +#define TAG_END "# END RECORD" + +/** + * read_ibft_blocks: + * @iscsiadm_path: path to iscsiadm program + * @out_blocks: on return if successful, a #GSList of #GPtrArray, or %NULL on + * failure + * @error: location for an error on failure + * + * Parses iscsiadm output and returns a #GSList of #GPtrArray in the @out_blocks + * argument on success, otherwise @out_blocks is set to %NULL. Each #GPtrArray + * in @out_blocks contains the lines from an iscsiadm interface block. + * + * Returns: %TRUE on success, %FALSE on errors + */ +gboolean +read_ibft_blocks (const char *iscsiadm_path, + GSList **out_blocks, + GError **error) +{ + const char *argv[4] = { iscsiadm_path, "-m", "fw", NULL }; + const char *envp[1] = { NULL }; + GSList *blocks = NULL; + char *out = NULL, *err = NULL; + gint status = 0; + char **lines = NULL, **iter; + GPtrArray *block_lines = NULL; + gboolean success = FALSE; + + g_return_val_if_fail (iscsiadm_path != NULL, FALSE); + g_return_val_if_fail (out_blocks != NULL && *out_blocks == NULL, FALSE); + + if (!g_spawn_sync ("/", (char **) argv, (char **) envp, 0, + iscsiadm_child_setup, NULL, &out, &err, &status, error)) + goto done; + + if (!WIFEXITED (status)) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: %s exited abnormally.", iscsiadm_path); + goto done; + } + + if (WEXITSTATUS (status) != 0) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: %s exited with error %d. Message: '%s'", + iscsiadm_path, WEXITSTATUS (status), err ? err : "(none)"); + goto done; + } + + nm_log_dbg (LOGD_SETTINGS, "iBFT records:\n%s", out); + + lines = g_strsplit_set (out, "\n\r", -1); + for (iter = lines; iter && *iter; iter++) { + if (!*iter[0]) + continue; + + if (!g_ascii_strncasecmp (*iter, TAG_BEGIN, STRLEN (TAG_BEGIN))) { + if (block_lines) { + PARSE_WARNING ("malformed iscsiadm record: missing END RECORD."); + g_ptr_array_unref (block_lines); + } + /* Start new record */ + block_lines = g_ptr_array_new_full (15, g_free); + } else if (!g_ascii_strncasecmp (*iter, TAG_END, STRLEN (TAG_END))) { + if (block_lines) { + if (block_lines->len) + blocks = g_slist_prepend (blocks, block_lines); + else + g_ptr_array_unref (block_lines); + block_lines = NULL; + } + } else if (block_lines) { + char *s = remove_most_whitespace (*iter); + + if (s) + g_ptr_array_add (block_lines, s); + else { + PARSE_WARNING ("malformed iscsiadm record: no = in '%s'.", *iter); + g_clear_pointer (&block_lines, g_ptr_array_unref); + } + } + } + + if (block_lines) { + PARSE_WARNING ("malformed iscsiadm record: missing # END RECORD."); + g_clear_pointer (&block_lines, g_ptr_array_unref); + } + success = TRUE; + +done: + if (lines) + g_strfreev (lines); + g_free (out); + if (success) + *out_blocks = blocks; + else + g_slist_free_full (blocks, (GDestroyNotify) g_ptr_array_unref); + return success; +} + +#define ISCSI_HWADDR_TAG "iface.hwaddress" +#define ISCSI_BOOTPROTO_TAG "iface.bootproto" +#define ISCSI_IPADDR_TAG "iface.ipaddress" +#define ISCSI_SUBNET_TAG "iface.subnet_mask" +#define ISCSI_GATEWAY_TAG "iface.gateway" +#define ISCSI_DNS1_TAG "iface.primary_dns" +#define ISCSI_DNS2_TAG "iface.secondary_dns" +#define ISCSI_VLAN_ID_TAG "iface.vlan_id" +#define ISCSI_IFACE_TAG "iface.net_ifacename" + +static const char * +match_iscsiadm_tag (const char *line, const char *tag) +{ + gsize taglen = strlen (tag); + + if (g_ascii_strncasecmp (line, tag, taglen) != 0) + return NULL; + if (line[taglen] != '=') + return NULL; + return line + taglen + 1; +} + +/** + * parse_ibft_config: + * @data: an array of iscsiadm interface block lines + * @error: return location for errors + * @...: pairs of key (const char *) : location (const char **) indicating the + * key to look for and the location to store the retrieved value in + * + * Parses an iscsiadm interface block into variables requested by the caller. + * Callers should verify the returned data is complete and valid. Returned + * strings are owned by @data and should not be used after @data is freed. + * + * Returns: %TRUE if at least , %FALSE on failure + */ +gboolean +parse_ibft_config (const GPtrArray *data, GError **error, ...) +{ + gboolean success = FALSE; + const char **out_value, *p; + va_list ap; + const char *key; + guint i; + + g_return_val_if_fail (data != NULL, FALSE); + g_return_val_if_fail (data->len > 0, FALSE); + + /* Find requested keys and populate return values */ + va_start (ap, error); + while ((key = va_arg (ap, const char *))) { + out_value = va_arg (ap, const char **); + *out_value = NULL; + for (i = 0; i < data->len; i++) { + p = match_iscsiadm_tag (g_ptr_array_index (data, i), key); + if (p) { + *out_value = p; + success = TRUE; + break; + } + } + } + va_end (ap); + + if (!success) { + g_set_error_literal (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: failed to match at least one iscsiadm block field"); + } + return success; +} + +static gboolean +ip4_setting_add_from_block (const GPtrArray *block, + NMConnection *connection, + GError **error) +{ + NMSettingIP4Config *s_ip4 = NULL; + NMIP4Address *addr; + const char *s_method = NULL; + const char *s_ipaddr = NULL; + const char *s_gateway = NULL; + const char *s_dns1 = NULL; + const char *s_dns2 = NULL; + const char *s_netmask = NULL; + guint32 ipaddr = 0; + guint32 netmask = 0; + guint32 gateway = 0; + guint32 dns1 = 0; + guint32 dns2 = 0; + guint32 prefix; + + g_assert (block); + + if (!parse_ibft_config (block, error, + ISCSI_BOOTPROTO_TAG, &s_method, + ISCSI_IPADDR_TAG, &s_ipaddr, + ISCSI_SUBNET_TAG, &s_netmask, + ISCSI_GATEWAY_TAG, &s_gateway, + ISCSI_DNS1_TAG, &s_dns1, + ISCSI_DNS2_TAG, &s_dns2, + NULL)) + goto error; + + if (!s_method) { + g_set_error_literal (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: missing " ISCSI_BOOTPROTO_TAG); + goto error; + } + + s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + + if (!g_ascii_strcasecmp (s_method, "dhcp")) { + g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + goto success; + } else if (g_ascii_strcasecmp (s_method, "static") != 0) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: unknown " ISCSI_BOOTPROTO_TAG " '%s'.", + s_method); + goto error; + } + + /* Static configuration stuff */ + g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + + /* IP address */ + if (!s_ipaddr || inet_pton (AF_INET, s_ipaddr, &ipaddr) != 1) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: invalid IP address '%s'.", + s_ipaddr); + goto error; + } + + /* Subnet/prefix */ + if (!s_netmask || inet_pton (AF_INET, s_netmask, &netmask) != 1) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: invalid subnet mask '%s'.", + s_netmask); + goto error; + } + prefix = nm_utils_ip4_netmask_to_prefix (netmask); + + if (s_gateway && inet_pton (AF_INET, s_gateway, &gateway) != 1) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: invalid IP gateway '%s'.", + s_gateway); + goto error; + } + + if (s_dns1 && inet_pton (AF_INET, s_dns1, &dns1) != 1) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: invalid DNS1 address '%s'.", + s_dns1); + goto error; + } + + if (s_dns2 && inet_pton (AF_INET, s_dns2, &dns2) != 1) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: invalid DNS2 address '%s'.", + s_dns2); + goto error; + } + + addr = nm_ip4_address_new (); + nm_ip4_address_set_address (addr, ipaddr); + nm_ip4_address_set_prefix (addr, prefix); + nm_ip4_address_set_gateway (addr, gateway); + nm_setting_ip4_config_add_address (s_ip4, addr); + nm_ip4_address_unref (addr); + + if (dns1) + nm_setting_ip4_config_add_dns (s_ip4, dns1); + if (dns2) + nm_setting_ip4_config_add_dns (s_ip4, dns2); + +success: + nm_connection_add_setting (connection, NM_SETTING (s_ip4)); + return TRUE; + +error: + g_clear_object (&s_ip4); + return FALSE; +} + +static gboolean +connection_setting_add (const GPtrArray *block, + NMConnection *connection, + const char *type, + const char *prefix, + const char *iface, + GError **error) +{ + NMSetting *s_con; + char *id, *uuid, *uuid_data; + const char *s_hwaddr = NULL, *s_ip4addr = NULL, *s_vlanid; + + if (!parse_ibft_config (block, error, + ISCSI_VLAN_ID_TAG, &s_vlanid, + ISCSI_HWADDR_TAG, &s_hwaddr, + ISCSI_IPADDR_TAG, &s_ip4addr, + NULL)) + return FALSE; + if (!s_hwaddr) { + g_set_error_literal (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: missing " ISCSI_HWADDR_TAG); + return FALSE; + } + + id = g_strdup_printf ("iBFT%s%s %s", + prefix ? " " : "", + prefix ? prefix : "", + iface); + + uuid_data = g_strdup_printf ("%s%s%s", + s_vlanid ? s_vlanid : "0", + s_hwaddr, + s_ip4addr ? s_ip4addr : "DHCP"); + uuid = nm_utils_uuid_generate_from_string (uuid_data); + g_free (uuid_data); + + s_con = nm_setting_connection_new (); + g_object_set (s_con, + NM_SETTING_CONNECTION_TYPE, type, + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_ID, id, + NM_SETTING_CONNECTION_READ_ONLY, TRUE, + NULL); + + g_free (uuid); + g_free (id); + + nm_connection_add_setting (connection, NM_SETTING (s_con)); + return TRUE; +} + +static gboolean +is_ibft_vlan_device (const GPtrArray *block) +{ + char *s_vlan_id = NULL; + + if (parse_ibft_config (block, NULL, ISCSI_VLAN_ID_TAG, &s_vlan_id, NULL)) { + g_assert (s_vlan_id); + + /* VLAN 0 is normally a valid VLAN ID, but in the iBFT case it + * means "no VLAN". + */ + if (nm_utils_ascii_str_to_int64 (s_vlan_id, 10, 1, 4095, -1) != -1) + return TRUE; + } + return FALSE; +} + +static gboolean +vlan_setting_add_from_block (const GPtrArray *block, + NMConnection *connection, + GError **error) +{ + NMSetting *s_vlan = NULL; + const char *vlan_id_str = NULL; + gint64 vlan_id = -1; + gboolean success; + + g_assert (block); + g_assert (connection); + + /* This won't fail since this function shouldn't be called unless the + * iBFT VLAN ID exists and is > 0. + */ + success = parse_ibft_config (block, NULL, ISCSI_VLAN_ID_TAG, &vlan_id_str, NULL); + g_assert (success); + g_assert (vlan_id_str); + + /* VLAN 0 is normally a valid VLAN ID, but in the iBFT case it means "no VLAN" */ + vlan_id = nm_utils_ascii_str_to_int64 (vlan_id_str, 10, 1, 4095, -1); + if (vlan_id == -1) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, "Invalid VLAN_ID '%s'", vlan_id_str); + return FALSE; + } + + s_vlan = nm_setting_vlan_new (); + g_object_set (s_vlan, NM_SETTING_VLAN_ID, (guint32) vlan_id, NULL); + nm_connection_add_setting (connection, NM_SETTING (s_vlan)); + + return TRUE; +} + +static gboolean +wired_setting_add_from_block (const GPtrArray *block, + NMConnection *connection, + GError **error) +{ + NMSetting *s_wired = NULL; + const char *hwaddr_str = NULL; + GByteArray *hwaddr; + + g_assert (block); + g_assert (connection); + + if (!parse_ibft_config (block, NULL, ISCSI_HWADDR_TAG, &hwaddr_str, NULL)) { + g_set_error_literal (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: missing " ISCSI_HWADDR_TAG); + return FALSE; + } + + hwaddr = nm_utils_hwaddr_atoba (hwaddr_str, ETH_ALEN); + if (!hwaddr) { + g_set_error (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: invalid " ISCSI_HWADDR_TAG " '%s'.", + hwaddr_str); + return FALSE; + } + + s_wired = nm_setting_wired_new (); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, hwaddr, NULL); + g_byte_array_unref (hwaddr); + + nm_connection_add_setting (connection, s_wired); + return TRUE; +} + +NMConnection * +connection_from_block (const GPtrArray *block, GError **error) +{ + NMConnection *connection = NULL; + gboolean is_vlan = FALSE; + const char *iface = NULL; + + g_assert (block); + + if (!parse_ibft_config (block, error, ISCSI_IFACE_TAG, &iface, NULL)) { + g_set_error_literal (error, IBFT_PLUGIN_ERROR, 0, + "iBFT: malformed iscsiadm record: missing " ISCSI_IFACE_TAG); + return NULL; + } + + connection = nm_simple_connection_new (); + + is_vlan = is_ibft_vlan_device (block); + if (is_vlan && !vlan_setting_add_from_block (block, connection, error)) + goto error; + + /* Always have a wired setting; for VLAN it defines the parent */ + if (!wired_setting_add_from_block (block, connection, error)) + goto error; + + if (!ip4_setting_add_from_block (block, connection, error)) + goto error; + + if (!connection_setting_add (block, + connection, + is_vlan ? NM_SETTING_VLAN_SETTING_NAME : NM_SETTING_WIRED_SETTING_NAME, + is_vlan ? "VLAN" : NULL, + iface, + error)) + goto error; + + if (!nm_connection_normalize (connection, NULL, NULL, error)) + goto error; + + return connection; + +error: + g_object_unref (connection); + return NULL; +} + diff --git a/src/settings/plugins/ibft/reader.h b/src/settings/plugins/ibft/reader.h new file mode 100644 index 000000000..0b2f22b65 --- /dev/null +++ b/src/settings/plugins/ibft/reader.h @@ -0,0 +1,36 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef __READER_H__ +#define __READER_H__ + +#include +#include + +gboolean read_ibft_blocks (const char *iscsiadm_path, + GSList **out_blocks, + GError **error); + +NMConnection *connection_from_block (const GPtrArray *block, GError **error); + +/* For testcases */ +gboolean parse_ibft_config (const GPtrArray *data, GError **error, ...) G_GNUC_NULL_TERMINATED; + +#endif /* __READER_H__ */ diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am new file mode 100644 index 000000000..62011759f --- /dev/null +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -0,0 +1,50 @@ +if ENABLE_TESTS + +@GNOME_CODE_COVERAGE_RULES@ + +AM_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(CODE_COVERAGE_CFLAGS) \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ + -I$(top_srcdir)/src/ \ + -I$(top_srcdir)/src/platform \ + -I$(top_srcdir)/src/settings \ + -I$(srcdir)/../ \ + -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ + -DNETWORKMANAGER_COMPILATION \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ + -DTEST_IBFT_DIR=\"$(abs_srcdir)\" \ + -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" + +AM_LDFLAGS = \ + $(GLIB_LIBS) \ + $(DBUS_LIBS) \ + $(CODE_COVERAGE_LDFLAGS) + +noinst_PROGRAMS = test-ibft + +test_ibft_SOURCES = \ + test-ibft.c \ + ../errors.c \ + ../reader.c + +test_ibft_LDADD = \ + $(top_builddir)/src/libNetworkManager.la + +TESTS = test-ibft + +EXTRA_DIST = \ + iscsiadm-test-dhcp \ + iscsiadm-test-static \ + iscsiadm-test-bad-ipaddr \ + iscsiadm-test-bad-gateway \ + iscsiadm-test-bad-dns1 \ + iscsiadm-test-bad-dns2 \ + iscsiadm-test-bad-entry \ + iscsiadm-test-bad-record \ + iscsiadm-test-vlan + +endif + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 new file mode 100755 index 000000000..54f02da63 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10000.500.250.1 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 new file mode 100755 index 000000000..ebd7a9caa --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = blah.foo.bar.baz +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry new file mode 100755 index 000000000..4e326048e --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry @@ -0,0 +1,20 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway new file mode 100755 index 000000000..5390a6c3d --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = bb.cc.dd.ee +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr new file mode 100755 index 000000000..b41cd1f16 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr @@ -0,0 +1,21 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = aa.bb.cc.dd +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record new file mode 100755 index 000000000..22b34e6f5 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record @@ -0,0 +1,18 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp b/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp new file mode 100755 index 000000000..556b0586e --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp @@ -0,0 +1,33 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f1 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth1 +node.name = iqn.1.2008-11.com.blahblah:iscsi1 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-static b/src/settings/plugins/ibft/tests/iscsiadm-test-static new file mode 100755 index 000000000..51711480e --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-static @@ -0,0 +1,35 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.32.72 +iface.subnet_mask = 255.255.252.0 +iface.gateway = 192.168.35.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth0 +node.name = iqn.0.2008-11.com.blahblah:iscsi0 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +# BEGIN RECORD +iface.initiatorname = iqn.pjones6 +iface.hwaddress = 00:33:21:98:b9:f1 +iface.bootproto = DHCP +iface.gateway = 10.16.52.254 +iface.primary_dns = 10.16.255.2 +iface.secondary_dns = 10.16.255.3 +iface.vlan_id = 0 +iface.net_ifacename = eth1 +node.name = iqn.1.2008-11.com.blahblah:iscsi1 +node.conn[0].address = 10.16.52.16 +node.conn[0].port = 3260 +node.boot_lun = 00000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/iscsiadm-test-vlan b/src/settings/plugins/ibft/tests/iscsiadm-test-vlan new file mode 100755 index 000000000..59b80bd03 --- /dev/null +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-vlan @@ -0,0 +1,19 @@ +#!/bin/bash + +cat << EOF +# BEGIN RECORD 6.2.0.873-21 +iface.initiatorname = iqn.2010-04.org.ipxe:d05faa97-c4be-44f6-a723-efde9aa399a0 +iface.transport_name = tcp +iface.hwaddress = 00:33:21:98:b9:f0 +iface.bootproto = STATIC +iface.ipaddress = 192.168.6.200 +iface.subnet_mask = 255.255.255.0 +iface.vlan_id = 123 +iface.net_ifacename = eth0 +node.name = iqn.2003-01.org.x:disk1 +node.conn[0].address = 192.168.6.32 +node.conn[0].port = 3260 +node.boot_lun = 01000000 +# END RECORD +EOF + diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c new file mode 100644 index 000000000..45c8d1f69 --- /dev/null +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -0,0 +1,295 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager system settings service + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "NetworkManagerUtils.h" + +#include "errors.h" +#include "reader.h" +#include "nm-logging.h" + +#include "nm-test-utils.h" + +static GPtrArray * +read_block (const char *iscsiadm_path, const char *expected_mac) +{ + GSList *blocks = NULL, *iter; + GPtrArray *block = NULL; + GError *error = NULL; + gboolean success; + + success = read_ibft_blocks (iscsiadm_path, &blocks, &error); + g_assert_no_error (error); + g_assert (success); + g_assert (blocks); + + for (iter = blocks; iter; iter = iter->next) { + const char *s_hwaddr = NULL; + + if (!parse_ibft_config (iter->data, NULL, "iface.hwaddress", &s_hwaddr, NULL)) + continue; + g_assert (s_hwaddr); + if (nm_utils_hwaddr_matches (s_hwaddr, -1, expected_mac, -1)) { + block = g_ptr_array_ref (iter->data); + break; + } + } + g_assert (block); + + g_slist_foreach (blocks, (GFunc) g_ptr_array_unref, NULL); + return block; +} + +static void +test_read_ibft_dhcp (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIP4Config *s_ip4; + GError *error = NULL; + const GByteArray *array; + const char *expected_mac_address = "00:33:21:98:b9:f1"; + GPtrArray *block; + + block = read_block (TEST_IBFT_DIR "/iscsiadm-test-dhcp", expected_mac_address); + + connection = connection_from_block (block, &error); + g_assert_no_error (error); + nmtst_assert_connection_verifies_without_normalization (connection); + + g_assert (!nm_connection_get_setting_vlan (connection)); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "iBFT eth1"); + g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); + g_assert (nm_setting_connection_get_autoconnect (s_con)); + g_assert (nm_setting_connection_get_read_only (s_con)); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + array = nm_setting_wired_get_mac_address (s_wired); + g_assert (array); + nmtst_assert_hwaddr_equals (array->data, array->len, expected_mac_address); + g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + g_object_unref (connection); +} + +static void +test_read_ibft_static (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIP4Config *s_ip4; + GError *error = NULL; + const GByteArray *array; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIP4Address *ip4_addr; + GPtrArray *block; + + block = read_block (TEST_IBFT_DIR "/iscsiadm-test-static", expected_mac_address); + + connection = connection_from_block (block, &error); + g_assert_no_error (error); + nmtst_assert_connection_verifies_without_normalization (connection); + + g_assert (!nm_connection_get_setting_vlan (connection)); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "iBFT eth0"); + g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); + g_assert (nm_setting_connection_get_autoconnect (s_con)); + g_assert (nm_setting_connection_get_read_only (s_con)); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + array = nm_setting_wired_get_mac_address (s_wired); + g_assert (array); + nmtst_assert_hwaddr_equals (array->data, array->len, expected_mac_address); + g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2); + nmtst_assert_ip4_address_equals (nm_setting_ip4_config_get_dns (s_ip4, 0), "10.16.255.2"); + nmtst_assert_ip4_address_equals (nm_setting_ip4_config_get_dns (s_ip4, 1), "10.16.255.3"); + + g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); + g_assert (ip4_addr); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.32.72"); + g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 22); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "192.168.35.254"); + + g_object_unref (connection); + g_ptr_array_unref (block); +} + +static void +test_read_ibft_malformed (gconstpointer user_data) +{ + const char *iscsiadm_path = user_data; + GSList *blocks = NULL; + GError *error = NULL; + gboolean success; + + g_assert (g_file_test (iscsiadm_path, G_FILE_TEST_EXISTS)); + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*malformed iscsiadm record*"); + + success = read_ibft_blocks (iscsiadm_path, &blocks, &error); + g_assert_no_error (error); + g_assert (success); + g_assert (blocks == NULL); + + g_test_assert_expected_messages (); +} + +static void +test_read_ibft_bad_address (gconstpointer user_data) +{ + const char *iscsiadm_path = user_data; + NMConnection *connection; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + GPtrArray *block; + GError *error = NULL; + + g_assert (g_file_test (iscsiadm_path, G_FILE_TEST_EXISTS)); + + block = read_block (iscsiadm_path, expected_mac_address); + + connection = connection_from_block (block, &error); + g_assert_error (error, IBFT_PLUGIN_ERROR, 0); + g_assert (strstr (error->message, "iBFT: malformed iscsiadm record: invalid")); + g_clear_error (&error); + g_assert (connection == NULL); + + g_ptr_array_unref (block); +} + +static void +test_read_ibft_vlan (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingVlan *s_vlan; + NMSettingIP4Config *s_ip4; + const GByteArray *array; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIP4Address *ip4_addr; + GError *error = NULL; + GPtrArray *block; + + block = read_block (TEST_IBFT_DIR "/iscsiadm-test-vlan", expected_mac_address); + + connection = connection_from_block (block, &error); + g_assert_no_error (error); + nmtst_assert_connection_verifies_without_normalization (connection); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_VLAN_SETTING_NAME); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + array = nm_setting_wired_get_mac_address (s_wired); + g_assert (array); + nmtst_assert_hwaddr_equals (array->data, array->len, expected_mac_address); + + /* ===== VLAN SETTING ===== */ + s_vlan = nm_connection_get_setting_vlan (connection); + g_assert (s_vlan); + g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 123); + g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, NULL); + g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, NULL); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 0); + + g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); + g_assert (ip4_addr); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.6.200"); + g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "0.0.0.0"); + + g_object_unref (connection); + g_ptr_array_ref (block); +} + +NMTST_DEFINE (); + +#define TPATH "/settings/plugins/ibft/" + +int main (int argc, char **argv) +{ + nmtst_init_assert_logging (&argc, &argv); + + g_test_add_func (TPATH "ibft/dhcp", test_read_ibft_dhcp); + g_test_add_func (TPATH "ibft/static", test_read_ibft_static); + g_test_add_func (TPATH "ibft/vlan", test_read_ibft_vlan); + g_test_add_data_func (TPATH "ibft/bad-record-read", TEST_IBFT_DIR "/iscsiadm-test-bad-record", test_read_ibft_malformed); + g_test_add_data_func (TPATH "ibft/bad-entry-read", TEST_IBFT_DIR "/iscsiadm-test-bad-entry", test_read_ibft_malformed); + g_test_add_data_func (TPATH "ibft/bad-ipaddr-read", TEST_IBFT_DIR "/iscsiadm-test-bad-ipaddr", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-gateway-read", TEST_IBFT_DIR "/iscsiadm-test-bad-gateway", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-dns1-read", TEST_IBFT_DIR "/iscsiadm-test-bad-dns1", test_read_ibft_bad_address); + g_test_add_data_func (TPATH "ibft/bad-dns2-read", TEST_IBFT_DIR "/iscsiadm-test-bad-dns2", test_read_ibft_bad_address); + + return g_test_run (); +} + From 7b714524b9e8fc273cc250704a2cc5654fe767d2 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 30 Jul 2014 16:25:58 -0500 Subject: [PATCH 3/6] ifcfg-rh: remove iBFT handling (use the ibft plugin instead) (bgo #734009) (rh #990480) Now that the ibft plugin handles iBFT data, no reason to do so from the ifcfg-rh plugin. https://bugzilla.gnome.org/show_bug.cgi?id=734009 --- .../plugins/ifcfg-rh/nm-ifcfg-connection.c | 4 +- src/settings/plugins/ifcfg-rh/reader.c | 292 +-------- src/settings/plugins/ifcfg-rh/reader.h | 1 - .../plugins/ifcfg-rh/tests/Makefile.am | 10 - .../ifcfg-rh/tests/iscsiadm-test-bad-dns1 | 21 - .../ifcfg-rh/tests/iscsiadm-test-bad-dns2 | 21 - .../ifcfg-rh/tests/iscsiadm-test-bad-entry | 35 -- .../ifcfg-rh/tests/iscsiadm-test-bad-gateway | 21 - .../ifcfg-rh/tests/iscsiadm-test-bad-ipaddr | 21 - .../ifcfg-rh/tests/iscsiadm-test-bad-record | 18 - .../plugins/ifcfg-rh/tests/iscsiadm-test-dhcp | 33 - .../ifcfg-rh/tests/iscsiadm-test-static | 35 -- .../tests/network-scripts/Makefile.am | 3 +- .../tests/network-scripts/ifcfg-test-ibft | 10 + .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 587 ++---------------- 15 files changed, 79 insertions(+), 1033 deletions(-) delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1 delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2 delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp delete mode 100755 src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-static create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index 463600959..c933ed848 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -117,7 +117,7 @@ nm_ifcfg_connection_new (NMConnection *source, else { char *keyfile = NULL, *routefile = NULL, *route6file = NULL; - tmp = connection_from_file (full_path, NULL, NULL, NULL, + tmp = connection_from_file (full_path, NULL, NULL, &unhandled_spec, &keyfile, &routefile, @@ -269,7 +269,7 @@ commit_changes (NMSettingsConnection *connection, * it if it's really changed. */ if (priv->path) { - reread = connection_from_file (priv->path, NULL, NULL, NULL, + reread = connection_from_file (priv->path, NULL, NULL, NULL, NULL, NULL, NULL, &error, NULL); g_clear_error (&error); diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index cbaf0aaeb..27e2df9b7 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -274,251 +274,6 @@ read_mac_address (shvarFile *ifcfg, const char *key, gsize len, return TRUE; } -static void -iscsiadm_child_setup (gpointer user_data G_GNUC_UNUSED) -{ - /* We are in the child process here; set a different process group to - * ensure signal isolation between child and parent. - */ - pid_t pid = getpid (); - setpgid (pid, pid); - - /* - * We blocked signals in main(). We need to restore original signal - * mask for iscsiadm here so that it can receive signals. - */ - nm_unblock_posix_signals (NULL); -} - -static char * -match_iscsiadm_tag (const char *line, const char *tag, gboolean *skip) -{ - char *p; - - if (g_ascii_strncasecmp (line, tag, strlen (tag))) - return NULL; - - p = strchr (line, '='); - if (!p) { - PARSE_WARNING ("malformed iscsiadm record: no = in '%s'.", line); - *skip = TRUE; - return NULL; - } - - p++; /* advance past = */ - return g_strstrip (p); -} - -#define ISCSI_HWADDR_TAG "iface.hwaddress" -#define ISCSI_BOOTPROTO_TAG "iface.bootproto" -#define ISCSI_IPADDR_TAG "iface.ipaddress" -#define ISCSI_SUBNET_TAG "iface.subnet_mask" -#define ISCSI_GATEWAY_TAG "iface.gateway" -#define ISCSI_DNS1_TAG "iface.primary_dns" -#define ISCSI_DNS2_TAG "iface.secondary_dns" - -static gboolean -fill_ip4_setting_from_ibft (shvarFile *ifcfg, - NMSettingIP4Config *s_ip4, - const char *iscsiadm_path, - GError **error) -{ - const char *argv[4] = { iscsiadm_path, "-m", "fw", NULL }; - const char *envp[1] = { NULL }; - gboolean success = FALSE, in_record = FALSE, hwaddr_matched = FALSE, skip = FALSE; - char *out = NULL, *err = NULL; - gint status = 0; - GByteArray *ifcfg_mac = NULL; - char **lines = NULL, **iter; - const char *method = NULL; - guint32 ipaddr; - guint32 gateway; - guint32 dns1; - guint32 dns2; - guint32 prefix = 0; - - g_return_val_if_fail (s_ip4 != NULL, FALSE); - g_return_val_if_fail (iscsiadm_path != NULL, FALSE); - - if (!g_spawn_sync ("/", (char **) argv, (char **) envp, 0, - iscsiadm_child_setup, NULL, &out, &err, &status, error)) - return FALSE; - - if (!WIFEXITED (status)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "%s exited abnormally.", iscsiadm_path); - goto done; - } - - if (WEXITSTATUS (status) != 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "%s exited with error %d. Message: '%s'", - iscsiadm_path, WEXITSTATUS (status), err ? err : "(none)"); - goto done; - } - - if (!read_mac_address (ifcfg, "HWADDR", ETH_ALEN, &ifcfg_mac, error)) - goto done; - /* Ensure we got a MAC */ - if (!ifcfg_mac) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Missing device MAC address (no HWADDR tag present)."); - goto done; - } - - memset (&ipaddr, 0, sizeof (ipaddr)); - memset (&gateway, 0, sizeof (gateway)); - memset (&dns1, 0, sizeof (dns1)); - memset (&dns2, 0, sizeof (dns2)); - - /* Success, lets parse the output */ - lines = g_strsplit_set (out, "\n\r", -1); - for (iter = lines; iter && *iter; iter++) { - char *p; - - if (!g_ascii_strcasecmp (*iter, "# BEGIN RECORD")) { - if (in_record) { - PARSE_WARNING ("malformed iscsiadm record: already parsing record."); - skip = TRUE; - } - } else if (!g_ascii_strcasecmp (*iter, "# END RECORD")) { - if (!skip && hwaddr_matched) { - /* Record is good; fill IP4 config with its info */ - if (!method) { - PARSE_WARNING ("malformed iscsiadm record: missing BOOTPROTO."); - goto done; - } - - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, method, NULL); - - if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { - NMIP4Address *addr; - - if (!ipaddr || !prefix) { - PARSE_WARNING ("malformed iscsiadm record: BOOTPROTO=static " - "but missing IP address or prefix."); - goto done; - } - - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ipaddr); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gateway); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); - - if (dns1) - nm_setting_ip4_config_add_dns (s_ip4, dns1); - if (dns2) - nm_setting_ip4_config_add_dns (s_ip4, dns2); - - // FIXME: DNS search domains? - } - success = TRUE; - goto done; - } - skip = FALSE; - hwaddr_matched = FALSE; - memset (&ipaddr, 0, sizeof (ipaddr)); - memset (&gateway, 0, sizeof (gateway)); - memset (&dns1, 0, sizeof (dns1)); - memset (&dns2, 0, sizeof (dns2)); - prefix = 0; - method = NULL; - } - - if (skip) - continue; - - /* HWADDR */ - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_HWADDR_TAG, &skip))) { - guint8 *ibft_mac[ETH_ALEN]; - - if (!nm_utils_hwaddr_aton (p, ibft_mac, ETH_ALEN)) { - PARSE_WARNING ("malformed iscsiadm record: invalid hwaddress."); - skip = TRUE; - continue; - } - - if (!nm_utils_hwaddr_matches (ibft_mac, ETH_ALEN, ifcfg_mac->data, ifcfg_mac->len)) { - /* This record isn't for the current device, ignore it */ - skip = TRUE; - continue; - } - - /* Success, this record is for this device */ - hwaddr_matched = TRUE; - } - - /* BOOTPROTO */ - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_BOOTPROTO_TAG, &skip))) { - if (!g_ascii_strcasecmp (p, "dhcp")) - method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; - else if (!g_ascii_strcasecmp (p, "static")) - method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - else { - PARSE_WARNING ("malformed iscsiadm record: unknown BOOTPROTO '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_IPADDR_TAG, &skip))) { - if (inet_pton (AF_INET, p, &ipaddr) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid IP address '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_SUBNET_TAG, &skip))) { - guint32 mask; - - if (inet_pton (AF_INET, p, &mask) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid subnet mask '%s'.", p); - skip = TRUE; - continue; - } - - prefix = nm_utils_ip4_netmask_to_prefix (mask); - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_GATEWAY_TAG, &skip))) { - if (inet_pton (AF_INET, p, &gateway) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid IP gateway '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_DNS1_TAG, &skip))) { - if (inet_pton (AF_INET, p, &dns1) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid DNS1 address '%s'.", p); - skip = TRUE; - continue; - } - } - - if (!skip && (p = match_iscsiadm_tag (*iter, ISCSI_DNS2_TAG, &skip))) { - if (inet_pton (AF_INET, p, &dns2) < 1) { - PARSE_WARNING ("malformed iscsiadm record: invalid DNS2 address '%s'.", p); - skip = TRUE; - continue; - } - } - } - - success = TRUE; - -done: - if (ifcfg_mac) - g_byte_array_free (ifcfg_mac, TRUE); - g_strfreev (lines); - g_free (out); - g_free (err); - return success; -} - /* Returns TRUE on missing address or valid address */ static gboolean read_ip4_address (shvarFile *ifcfg, @@ -1242,7 +997,6 @@ error: static NMSetting * make_ip4_setting (shvarFile *ifcfg, const char *network_file, - const char *iscsiadm_path, GError **error) { NMSettingIP4Config *s_ip4 = NULL; @@ -1294,16 +1048,6 @@ make_ip4_setting (shvarFile *ifcfg, method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; } else if (!g_ascii_strcasecmp (value, "static")) { method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL; - } else if (!g_ascii_strcasecmp (value, "ibft")) { - g_free (value); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, NULL); - /* iSCSI Boot Firmware Table: need to read values from the iSCSI - * firmware for this device and create the IP4 setting using those. - */ - if (fill_ip4_setting_from_ibft (ifcfg, s_ip4, iscsiadm_path, error)) - return NM_SETTING (s_ip4); - g_object_unref (s_ip4); - return NULL; } else if (!g_ascii_strcasecmp (value, "autoip")) { g_free (value); g_object_set (s_ip4, @@ -1600,7 +1344,6 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo static NMSetting * make_ip6_setting (shvarFile *ifcfg, const char *network_file, - const char *iscsiadm_path, GError **error) { NMSettingIP6Config *s_ip6 = NULL; @@ -5005,7 +4748,6 @@ NMConnection * connection_from_file (const char *filename, const char *network_file, /* for unit tests only */ const char *test_type, /* for unit tests only */ - const char *iscsiadm_path, /* for unit tests only */ char **out_unhandled, char **out_keyfile, char **out_routefile, @@ -5033,9 +4775,6 @@ connection_from_file (const char *filename, if (!network_file) network_file = SYSCONFDIR "/sysconfig/network"; - if (!iscsiadm_path) - iscsiadm_path = "/sbin/iscsiadm"; - ifcfg_name = utils_get_ifcfg_name (filename, TRUE); if (!ifcfg_name) { g_set_error (error, IFCFG_PLUGIN_ERROR, 0, @@ -5056,6 +4795,17 @@ connection_from_file (const char *filename, goto done; } + /* iBFT is handled by the iBFT settings plugin */ + bootproto = svGetValue (parsed, "BOOTPROTO", FALSE); + if (bootproto && !g_ascii_strcasecmp (bootproto, "ibft")) { + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + "Ignoring iBFT configuration"); + g_free (bootproto); + goto done; + } + type = NULL; devtype = svGetValue (parsed, "DEVICETYPE", FALSE); @@ -5150,7 +4900,7 @@ connection_from_file (const char *filename, if (!connection) goto done; - s_ip6 = make_ip6_setting (parsed, network_file, iscsiadm_path, error); + s_ip6 = make_ip6_setting (parsed, network_file, error); if (!s_ip6) { g_object_unref (connection); connection = NULL; @@ -5158,7 +4908,7 @@ connection_from_file (const char *filename, } else nm_connection_add_setting (connection, s_ip6); - s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, error); + s_ip4 = make_ip4_setting (parsed, network_file, error); if (!s_ip4) { g_object_unref (connection); connection = NULL; @@ -5192,22 +4942,6 @@ connection_from_file (const char *filename, if (s_dcb) nm_connection_add_setting (connection, s_dcb); - /* iSCSI / ibft connections are read-only since their settings are - * stored in NVRAM and can only be changed in BIOS. - */ - bootproto = svGetValue (parsed, "BOOTPROTO", FALSE); - if ( bootproto - && connection - && !g_ascii_strcasecmp (bootproto, "ibft")) { - NMSettingConnection *s_con; - - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - - g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_READ_ONLY, TRUE, NULL); - } - g_free (bootproto); - if (!nm_connection_normalize (connection, NULL, NULL, error)) { g_object_unref (connection); connection = NULL; diff --git a/src/settings/plugins/ifcfg-rh/reader.h b/src/settings/plugins/ifcfg-rh/reader.h index 371f4504f..c23e5870e 100644 --- a/src/settings/plugins/ifcfg-rh/reader.h +++ b/src/settings/plugins/ifcfg-rh/reader.h @@ -29,7 +29,6 @@ NMConnection *connection_from_file (const char *filename, const char *network_file, /* for unit tests only */ const char *test_type, /* for unit tests only */ - const char *iscsiadm_path, /* for unit tests only */ char **out_unhandled, char **out_keyfile, char **out_routefile, diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index f01dac483..e3eae4660 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -50,15 +50,5 @@ test_ifcfg_rh_utils_LDADD = \ TESTS = test-ifcfg-rh-utils test-ifcfg-rh -EXTRA_DIST = \ - iscsiadm-test-dhcp \ - iscsiadm-test-static \ - iscsiadm-test-bad-ipaddr \ - iscsiadm-test-bad-gateway \ - iscsiadm-test-bad-dns1 \ - iscsiadm-test-bad-dns2 \ - iscsiadm-test-bad-entry \ - iscsiadm-test-bad-record - endif diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1 b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1 deleted file mode 100755 index 4a6a93822..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1 +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = STATIC -iface.ipaddress = 192.168.32.72 -iface.subnet_mask = 255.255.252.0 -iface.gateway = 192.168.35.254 -iface.primary_dns = 10000.500.250.1 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2 b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2 deleted file mode 100755 index 9bd5839bd..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2 +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = STATIC -iface.ipaddress = 192.168.32.72 -iface.subnet_mask = 255.255.252.0 -iface.gateway = 192.168.35.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = blah.foo.bar.baz -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry deleted file mode 100755 index eba0ec673..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = STATIC -iface.ipaddress 192.168.32.72 -iface.subnet_mask = 255.255.252.0 -iface.gateway = 192.168.35.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f1 -iface.bootproto = DHCP -iface.gateway = 10.16.52.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth1 -node.name = iqn.1.2008-11.com.blahblah:iscsi1 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway deleted file mode 100755 index b3dc74478..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = STATIC -iface.ipaddress = aa.bb.cc.dd -iface.subnet_mask = 255.255.252.0 -iface.gateway = 192.168.35.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr deleted file mode 100755 index 92f44777b..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = STATIC -iface.ipaddress = 192.168.32.72 -iface.subnet_mask = 255.255.252.0 -iface.gateway = bb.cc.dd.ee -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record deleted file mode 100755 index a2d215fe2..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = DHCP -iface.gateway = 10.16.52.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp deleted file mode 100755 index 6de0637cb..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = DHCP -iface.gateway = 10.16.52.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f1 -iface.bootproto = DHCP -iface.gateway = 10.16.52.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth1 -node.name = iqn.1.2008-11.com.blahblah:iscsi1 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-static b/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-static deleted file mode 100755 index 99a6e7c17..000000000 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-static +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -cat << EOF -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f0 -iface.bootproto = STATIC -iface.ipaddress = 192.168.32.72 -iface.subnet_mask = 255.255.252.0 -iface.gateway = 192.168.35.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth0 -node.name = iqn.0.2008-11.com.blahblah:iscsi0 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -# BEGIN RECORD -iface.initiatorname = iqn.pjones6 -iface.hwaddress = 00:33:21:98:b9:f1 -iface.bootproto = DHCP -iface.gateway = 10.16.52.254 -iface.primary_dns = 10.16.255.2 -iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 -iface.net_ifacename = eth1 -node.name = iqn.1.2008-11.com.blahblah:iscsi1 -node.conn[0].address = 10.16.52.16 -node.conn[0].port = 3260 -node.boot_lun = 00000000 -# END RECORD -EOF - diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am index 1701aeeb3..09e47281c 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am @@ -61,8 +61,7 @@ EXTRA_DIST = \ ifcfg-test-wifi-hidden \ test_ca_cert.pem \ test1_key_and_cert.pem \ - ifcfg-test-ibft-dhcp \ - ifcfg-test-ibft-static \ + ifcfg-test-ibft \ ifcfg-test-static-routes-legacy \ route-test-static-routes-legacy \ ifcfg-test-wired-static-routes \ diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft new file mode 100644 index 000000000..d3e4edca1 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft @@ -0,0 +1,10 @@ +# Generated by dracut initrd +DEVICE="ibft0" +ONBOOT=yes +NETBOOT=yes +UUID="2aa8c19d-9744-4ca4-b74f-c37e73f2918e" +BOOTPROTO=ibft +HWADDR="00:33:21:98:b9:f0" +TYPE=Ethernet +NAME="ibft0" + diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index f835064ce..57470f0a5 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -193,7 +193,7 @@ test_read_basic (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-minimal", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -254,7 +254,7 @@ test_read_variables_corner_cases (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-variables-corner-cases-1", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -301,7 +301,7 @@ test_read_unmanaged (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-nm-controlled", - NULL, TYPE_ETHERNET, NULL, + NULL, TYPE_ETHERNET, &unhandled_spec, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); @@ -334,7 +334,7 @@ test_read_unmanaged_unrecognized (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-nm-controlled-unrecognized", - NULL, NULL, NULL, + NULL, NULL, &unhandled_spec, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); @@ -365,7 +365,7 @@ test_read_unrecognized (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-unrecognized", - NULL, NULL, NULL, + NULL, NULL, &unhandled_spec, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); @@ -412,7 +412,7 @@ test_read_wired_static (const char *file, NMIP6Address *ip6_addr; gboolean success; - connection = connection_from_file (file, NULL, TYPE_ETHERNET, NULL, + connection = connection_from_file (file, NULL, TYPE_ETHERNET, &unmanaged, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -514,7 +514,7 @@ test_read_wired_static_no_prefix (gconstpointer user_data) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*missing PREFIX, assuming*"); - connection = connection_from_file (file, NULL, TYPE_ETHERNET, NULL, NULL, + connection = connection_from_file (file, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_no_error (error); @@ -568,7 +568,6 @@ test_read_wired_dhcp (void) connection = connection_from_file (TEST_IFCFG_WIRED_DHCP, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -729,7 +728,7 @@ test_read_wired_dhcp_plus_ip (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", - NULL, TYPE_ETHERNET, NULL, NULL, + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -828,7 +827,6 @@ test_read_wired_global_gateway (void) connection = connection_from_file (TEST_IFCFG_WIRED_GLOBAL_GATEWAY, TEST_NETWORK_WIRED_GLOBAL_GATEWAY, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -955,7 +953,6 @@ test_read_wired_never_default (void) connection = connection_from_file (TEST_IFCFG_WIRED_NEVER_DEFAULT, TEST_NETWORK_WIRED_NEVER_DEFAULT, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1080,7 +1077,6 @@ test_read_wired_defroute_no (void) connection = connection_from_file (TEST_IFCFG_WIRED_DEFROUTE_NO, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1199,7 +1195,6 @@ test_read_wired_defroute_no_gatewaydev_yes (void) connection = connection_from_file (TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, TEST_NETWORK_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1330,7 +1325,6 @@ test_read_wired_static_routes (void) connection = connection_from_file (TEST_IFCFG_WIRED_STATIC_ROUTES, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1497,7 +1491,6 @@ test_read_wired_static_routes_legacy (void) connection = connection_from_file (TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1700,7 +1693,6 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id) connection = connection_from_file (file, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1861,7 +1853,6 @@ test_read_wired_ipv6_manual (void) connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_MANUAL, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2140,7 +2131,6 @@ test_read_wired_ipv6_only (void) connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_ONLY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2292,7 +2282,6 @@ test_read_wired_dhcp6_only (void) connection = connection_from_file (TEST_IFCFG_WIRED_DHCP6_ONLY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2392,7 +2381,6 @@ test_read_onboot_no (void) connection = connection_from_file (TEST_IFCFG_ONBOOT_NO, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2448,7 +2436,6 @@ test_read_noip (void) connection = connection_from_file (TEST_IFCFG_NOIP, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2504,7 +2491,6 @@ test_read_wired_8021x_peap_mschapv2 (void) connection = connection_from_file (TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2698,7 +2684,6 @@ test_read_wired_8021x_tls_secret_flags (const char *ifcfg, NMSettingSecretFlags connection = connection_from_file (ifcfg, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2755,7 +2740,7 @@ test_read_write_802_1X_subj_matches (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*missing IEEE_8021X_CA_CERT*peap*"); connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-802-1X-subj-matches", - NULL, TYPE_ETHERNET, NULL, NULL, + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_no_error (error); @@ -2789,7 +2774,7 @@ test_read_write_802_1X_subj_matches (void) /* re-read the connection for comparison */ g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*missing IEEE_8021X_CA_CERT*peap*"); - reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL, + reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); unlink (written); @@ -2838,7 +2823,7 @@ test_read_802_1x_ttls_eapgtc (void) */ connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-802-1x-ttls-eapgtc", - NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -2885,7 +2870,6 @@ test_read_wired_aliases_good (void) connection = connection_from_file (TEST_IFCFG_ALIASES_GOOD, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -3032,7 +3016,6 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id) connection = connection_from_file (base, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -3171,7 +3154,6 @@ test_read_wifi_open (void) connection = connection_from_file (TEST_IFCFG_WIFI_OPEN, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3345,7 +3327,6 @@ test_read_wifi_open_auto (void) connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_AUTO, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3428,7 +3409,6 @@ test_read_wifi_open_ssid_hex (void) connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_SSID_HEX, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3509,7 +3489,6 @@ test_read_wifi_open_ssid_bad (const char *file, const char *test) connection = connection_from_file (file, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3547,7 +3526,6 @@ test_read_wifi_open_ssid_quoted (void) connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_SSID_QUOTED, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3644,7 +3622,6 @@ test_read_wifi_wep (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3906,7 +3883,6 @@ test_read_wifi_wep_adhoc (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_ADHOC, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4153,7 +4129,6 @@ test_read_wifi_wep_passphrase (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_PASSPHRASE, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4279,7 +4254,6 @@ test_read_wifi_wep_40_ascii (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_40_ASCII, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4403,7 +4377,6 @@ test_read_wifi_wep_104_ascii (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_104_ASCII, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4528,7 +4501,6 @@ test_read_wifi_leap (void) connection = connection_from_file (TEST_IFCFG_WIFI_LEAP, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4652,7 +4624,6 @@ test_read_wifi_leap_secret_flags (const char *file, NMSettingSecretFlags expecte connection = connection_from_file (file, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4727,7 +4698,6 @@ test_read_wifi_wpa_psk (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5016,7 +4986,6 @@ test_read_wifi_wpa_psk_2 (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_2, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5108,7 +5077,6 @@ test_read_wifi_wpa_psk_unquoted (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_UNQUOTED, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5198,7 +5166,6 @@ test_read_wifi_wpa_psk_unquoted2 (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_UNQUOTED2, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5242,7 +5209,6 @@ test_read_wifi_wpa_psk_adhoc (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_ADHOC, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5420,7 +5386,6 @@ test_read_wifi_wpa_psk_hex (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK_HEX, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5562,7 +5527,6 @@ test_read_wifi_wpa_eap_tls (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_EAP_TLS, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -5703,7 +5667,6 @@ test_read_wifi_wpa_eap_ttls_tls (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_EAP_TTLS_TLS, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5858,7 +5821,6 @@ test_read_wifi_dynamic_wep_leap (void) connection = connection_from_file (TEST_IFCFG_WIFI_DYNAMIC_WEP_LEAP, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -5937,7 +5899,6 @@ test_read_wifi_wep_eap_ttls_chap (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_EAP_TTLS_CHAP, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -6084,7 +6045,7 @@ test_read_wifi_hidden (void) GError *error = NULL; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-hidden", - NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -6172,7 +6133,7 @@ test_write_wifi_hidden (void) nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ - reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL, + reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); unlink (testfile); g_assert_no_error (error); @@ -6215,7 +6176,6 @@ test_read_wired_qeth_static (void) connection = connection_from_file (TEST_IFCFG_WIRED_QETH_STATIC, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6389,7 +6349,6 @@ test_read_wired_ctc_static (void) connection = connection_from_file (TEST_IFCFG_WIRED_CTC_STATIC, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6460,7 +6419,6 @@ test_read_wifi_wep_no_keys (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_NO_KEYS, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -6570,7 +6528,6 @@ test_read_permissions (void) connection = connection_from_file (TEST_IFCFG_PERMISSIONS, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6646,7 +6603,6 @@ test_read_wifi_wep_agent_keys (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_AGENT_KEYS, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -6873,7 +6829,6 @@ test_write_wired_static (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6996,7 +6951,6 @@ test_write_wired_dhcp (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7032,7 +6986,7 @@ test_write_wired_dhcp_plus_ip (void) gboolean success = FALSE; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", - NULL, TYPE_ETHERNET, NULL, NULL, + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection != NULL); @@ -7047,7 +7001,7 @@ test_write_wired_dhcp_plus_ip (void) nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ - reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL, + reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); unlink (written); g_free (written); @@ -7078,7 +7032,7 @@ test_read_write_wired_dhcp_send_hostname (void) gboolean success = FALSE; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-send-hostname", - NULL, TYPE_ETHERNET, NULL, NULL, + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection != NULL); @@ -7107,7 +7061,7 @@ test_read_write_wired_dhcp_send_hostname (void) nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ - reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL, + reread = connection_from_file (written, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); unlink (written); g_free (written); @@ -7235,7 +7189,6 @@ test_write_wired_static_ip6_only (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7382,7 +7335,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, NULL, NULL, + NULL, NULL, NULL, NULL, &error, &ignore_error); @@ -7450,7 +7403,6 @@ test_read_write_static_routes_legacy (void) connection = connection_from_file (TEST_IFCFG_READ_WRITE_STATIC_ROUTES_LEGACY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7540,7 +7492,6 @@ test_read_write_static_routes_legacy (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile2, &routefile2, @@ -7715,7 +7666,6 @@ test_write_wired_static_routes (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7847,7 +7797,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -8032,7 +7981,6 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme, reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8234,7 +8182,6 @@ test_write_wired_aliases (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -8444,7 +8391,7 @@ test_write_gateway (void) nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ - reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL, + reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); unlink (testfile); g_assert_no_error (error); @@ -8568,7 +8515,6 @@ test_write_wifi_open (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8700,7 +8646,6 @@ test_write_wifi_open_hex_ssid (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8831,7 +8776,6 @@ test_write_wifi_wep (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8982,7 +8926,6 @@ test_write_wifi_wep_adhoc (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9123,7 +9066,6 @@ test_write_wifi_wep_passphrase (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9266,7 +9208,6 @@ test_write_wifi_wep_40_ascii (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9409,7 +9350,6 @@ test_write_wifi_wep_104_ascii (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9549,7 +9489,6 @@ test_write_wifi_leap (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9688,7 +9627,6 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9844,7 +9782,6 @@ test_write_wifi_wpa_psk (const char *name, reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9995,7 +9932,6 @@ test_write_wifi_wpa_psk_adhoc (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10161,7 +10097,6 @@ test_write_wifi_wpa_eap_tls (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10345,7 +10280,6 @@ test_write_wifi_wpa_eap_ttls_tls (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10501,7 +10435,6 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10645,7 +10578,6 @@ test_write_wifi_wpa_then_open (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10692,7 +10624,6 @@ test_write_wifi_wpa_then_open (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10844,7 +10775,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10897,7 +10827,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -11042,7 +10971,6 @@ test_write_wifi_dynamic_wep_leap (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -11088,399 +11016,6 @@ test_write_wifi_dynamic_wep_leap (void) g_object_unref (reread); } -#define TEST_IFCFG_IBFT_DHCP TEST_IFCFG_DIR"/network-scripts/ifcfg-test-ibft-dhcp" - -static void -test_read_ibft_dhcp (void) -{ - NMConnection *connection; - NMSettingConnection *s_con; - NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - char *unmanaged = NULL; - char *keyfile = NULL; - char *routefile = NULL; - char *route6file = NULL; - gboolean ignore_error = FALSE; - GError *error = NULL; - const char *tmp; - const GByteArray *array; - char expected_mac_address[ETH_ALEN] = { 0x00, 0x33, 0x21, 0x98, 0xb9, 0xf1 }; - const char *expected_id = "System test-ibft-dhcp"; - guint64 expected_timestamp = 0; - - connection = connection_from_file (TEST_IFCFG_IBFT_DHCP, - NULL, - TYPE_ETHERNET, - TEST_IFCFG_DIR "/iscsiadm-test-dhcp", - &unmanaged, - &keyfile, - &routefile, - &route6file, - &error, - &ignore_error); - ASSERT (connection != NULL, - "ibft-dhcp-read", "failed to read %s: %s", TEST_IFCFG_IBFT_DHCP, error->message); - - ASSERT (nm_connection_verify (connection, &error), - "ibft-dhcp-verify", "failed to verify %s: %s", TEST_IFCFG_IBFT_DHCP, error->message); - - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection (connection); - ASSERT (s_con != NULL, - "ibft-dhcp-verify-connection", "failed to verify %s: missing %s setting", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_CONNECTION_SETTING_NAME); - - /* ID */ - tmp = nm_setting_connection_get_id (s_con); - ASSERT (tmp != NULL, - "ibft-dhcp-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, expected_id) == 0, - "ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - - /* UUID can't be tested if the ifcfg does not contain the UUID key, because - * the UUID is generated on the full path of the ifcfg file, which can change - * depending on where the tests are run. - */ - - /* Timestamp */ - ASSERT (nm_setting_connection_get_timestamp (s_con) == expected_timestamp, - "ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s /%s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_TIMESTAMP); - - /* Autoconnect */ - ASSERT (nm_setting_connection_get_autoconnect (s_con) == TRUE, - "ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s /%s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_AUTOCONNECT); - - /* Read-only */ - ASSERT (nm_setting_connection_get_read_only (s_con) == TRUE, - "ibft-dhcp-verify-connection", "failed to verify %s: unexpected %s /%s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_READ_ONLY); - - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired (connection); - ASSERT (s_wired != NULL, - "ibft-dhcp-verify-wired", "failed to verify %s: missing %s setting", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_WIRED_SETTING_NAME); - - /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - ASSERT (array != NULL, - "ibft-dhcp-verify-wired", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "ibft-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, - "ibft-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - - ASSERT (nm_setting_wired_get_mtu (s_wired) == 0, - "ibft-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MTU); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - ASSERT (s_ip4 != NULL, - "ibft-dhcp-verify-ip4", "failed to verify %s: missing %s setting", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_IP4_CONFIG_SETTING_NAME); - - /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); - ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, - "ibft-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_DHCP, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); - - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); - g_object_unref (connection); -} - -#define TEST_IFCFG_IBFT_STATIC TEST_IFCFG_DIR"/network-scripts/ifcfg-test-ibft-static" - -static void -test_read_ibft_static (void) -{ - NMConnection *connection; - NMSettingConnection *s_con; - NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - char *unmanaged = NULL; - char *keyfile = NULL; - char *routefile = NULL; - char *route6file = NULL; - gboolean ignore_error = FALSE; - GError *error = NULL; - const char *tmp; - const GByteArray *array; - char expected_mac_address[ETH_ALEN] = { 0x00, 0x33, 0x21, 0x98, 0xb9, 0xf0 }; - const char *expected_id = "System test-ibft-static"; - guint64 expected_timestamp = 0; - const char *expected_dns1 = "10.16.255.2"; - const char *expected_dns2 = "10.16.255.3"; - guint32 addr; - const char *expected_address1 = "192.168.32.72"; - const char *expected_address1_gw = "192.168.35.254"; - NMIP4Address *ip4_addr; - - connection = connection_from_file (TEST_IFCFG_IBFT_STATIC, - NULL, - TYPE_ETHERNET, - TEST_IFCFG_DIR "/iscsiadm-test-static", - &unmanaged, - &keyfile, - &routefile, - &route6file, - &error, - &ignore_error); - ASSERT (connection != NULL, - "ibft-static-read", "failed to read %s: %s", TEST_IFCFG_IBFT_STATIC, error->message); - - ASSERT (nm_connection_verify (connection, &error), - "ibft-static-verify", "failed to verify %s: %s", TEST_IFCFG_IBFT_STATIC, error->message); - - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection (connection); - ASSERT (s_con != NULL, - "ibft-static-verify-connection", "failed to verify %s: missing %s setting", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_CONNECTION_SETTING_NAME); - - /* ID */ - tmp = nm_setting_connection_get_id (s_con); - ASSERT (tmp != NULL, - "ibft-static-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, expected_id) == 0, - "ibft-static-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - - /* UUID can't be tested if the ifcfg does not contain the UUID key, because - * the UUID is generated on the full path of the ifcfg file, which can change - * depending on where the tests are run. - */ - - /* Timestamp */ - ASSERT (nm_setting_connection_get_timestamp (s_con) == expected_timestamp, - "ibft-static-verify-connection", "failed to verify %s: unexpected %s /%s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_TIMESTAMP); - - /* Autoconnect */ - ASSERT (nm_setting_connection_get_autoconnect (s_con) == TRUE, - "ibft-static-verify-connection", "failed to verify %s: unexpected %s /%s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_AUTOCONNECT); - - /* Read-only */ - ASSERT (nm_setting_connection_get_read_only (s_con) == TRUE, - "ibft-static-verify-connection", "failed to verify %s: unexpected %s /%s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_READ_ONLY); - - /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired (connection); - ASSERT (s_wired != NULL, - "ibft-static-verify-wired", "failed to verify %s: missing %s setting", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_WIRED_SETTING_NAME); - - /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - ASSERT (array != NULL, - "ibft-static-verify-wired", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "ibft-static-verify-wired", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, - "ibft-static-verify-wired", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - - ASSERT (nm_setting_wired_get_mtu (s_wired) == 0, - "ibft-static-verify-wired", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MTU); - - /* ===== IPv4 SETTING ===== */ - - s_ip4 = nm_connection_get_setting_ip4_config (connection); - ASSERT (s_ip4 != NULL, - "ibft-static-verify-ip4", "failed to verify %s: missing %s setting", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME); - - /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); - ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, - "ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); - - /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, - "ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - - ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0, - "ibft-static-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #1", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr, - "ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - - ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0, - "ibft-static-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #2", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr, - "ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1, - "ibft-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - - /* Address #1 */ - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - ASSERT (ip4_addr, - "ibft-static-verify-ip4", "failed to verify %s: missing IP4 address #1", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == 22, - "ibft-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - ASSERT (inet_pton (AF_INET, expected_address1, &addr) > 0, - "ibft-static-verify-ip4", "failed to verify %s: couldn't convert IP address #1", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - "ibft-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - ASSERT (inet_pton (AF_INET, expected_address1_gw, &addr) > 0, - "ibft-static-verify-ip4", "failed to verify %s: couldn't convert IP address #1 gateway", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr, - "ibft-static-verify-ip4", "failed to verify %s: unexpected IP4 address #1 gateway", - TEST_IFCFG_IBFT_STATIC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); - g_object_unref (connection); -} - -static void -test_read_ibft_malformed (const char *name, const char *iscsiadm_path, gboolean expect_warning) -{ - NMConnection *connection; - char *unmanaged = NULL; - char *keyfile = NULL; - char *routefile = NULL; - char *route6file = NULL; - gboolean ignore_error = FALSE; - GError *error = NULL; - - g_assert (g_file_test (iscsiadm_path, G_FILE_TEST_EXISTS)); - - if (expect_warning) { - g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, - "*malformed iscsiadm record*"); - } - connection = connection_from_file (TEST_IFCFG_IBFT_STATIC, - NULL, - TYPE_ETHERNET, - iscsiadm_path, - &unmanaged, - &keyfile, - &routefile, - &route6file, - &error, - &ignore_error); - if (expect_warning) - g_test_assert_expected_messages (); - ASSERT (connection == NULL, - name, "unexpectedly able to read %s", TEST_IFCFG_IBFT_STATIC); - - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); -} - static void test_write_wired_qeth_dhcp (void) { @@ -11576,7 +11111,6 @@ test_write_wired_qeth_dhcp (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -11713,7 +11247,6 @@ test_write_wired_ctc_dhcp (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -11825,7 +11358,6 @@ test_write_permissions (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -11955,7 +11487,6 @@ test_write_wifi_wep_agent_keys (void) reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -12230,7 +11761,6 @@ test_read_bridge_main (void) connection = connection_from_file (TEST_IFCFG_BRIDGE_MAIN, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12363,7 +11893,6 @@ test_write_bridge_main (void) reread = connection_from_file (testfile, NULL, TYPE_BRIDGE, - NULL, &unmanaged, &keyfile, &routefile, @@ -12405,7 +11934,6 @@ test_read_bridge_component (void) connection = connection_from_file (TEST_IFCFG_BRIDGE_COMPONENT, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12518,7 +12046,6 @@ test_write_bridge_component (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12561,7 +12088,6 @@ test_read_bridge_missing_stp (void) connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bridge-missing-stp", NULL, TYPE_BRIDGE, - NULL, &unmanaged, &keyfile, &routefile, @@ -12604,7 +12130,6 @@ test_read_vlan_interface (void) connection = connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12674,7 +12199,6 @@ test_read_vlan_only_vlan_id (void) connection = connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12716,7 +12240,6 @@ test_read_vlan_only_device (void) connection = connection_from_file (TEST_IFCFG_VLAN_ONLY_DEVICE, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12749,7 +12272,7 @@ test_read_vlan_physdev (void) NMSettingVlan *s_vlan; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-physdev", - NULL, TYPE_ETHERNET, NULL, NULL, + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -12781,7 +12304,6 @@ test_write_vlan (void) connection = connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, - NULL, &unmanaged, &keyfile, &routefile, @@ -12821,7 +12343,6 @@ test_write_vlan_only_vlanid (void) connection = connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_VLAN, - NULL, &unmanaged, &keyfile, &routefile, @@ -12853,7 +12374,6 @@ test_write_vlan_only_vlanid (void) reread = connection_from_file (written, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12962,7 +12482,6 @@ test_write_ethernet_missing_ipv6 (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13002,6 +12521,19 @@ test_write_ethernet_missing_ipv6 (void) g_object_unref (reread); } +static void +test_read_ibft_ignored (void) +{ + NMConnection *connection; + GError *error = NULL; + + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-ibft", + NULL, TYPE_ETHERNET, + NULL, NULL, NULL, NULL, &error, NULL); + g_assert_no_error (error); + g_assert (connection == NULL); +} + #define TEST_IFCFG_BOND_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bond-main" static void @@ -13019,7 +12551,6 @@ test_read_bond_main (void) connection = connection_from_file (TEST_IFCFG_BOND_MAIN, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13151,7 +12682,6 @@ test_write_bond_main (void) reread = connection_from_file (testfile, NULL, TYPE_BOND, - NULL, &unmanaged, &keyfile, &routefile, @@ -13195,7 +12725,6 @@ test_read_bond_slave (void) connection = connection_from_file (TEST_IFCFG_BOND_SLAVE, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13303,7 +12832,6 @@ test_write_bond_slave (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13353,7 +12881,6 @@ test_read_infiniband (void) connection = connection_from_file (TEST_IFCFG_INFINIBAND, NULL, TYPE_INFINIBAND, - NULL, &unmanaged, &keyfile, &routefile, @@ -13517,7 +13044,6 @@ test_write_infiniband (void) reread = connection_from_file (testfile, NULL, TYPE_INFINIBAND, - NULL, &unmanaged, &keyfile, &routefile, @@ -13559,7 +13085,6 @@ test_read_bond_slave_ib (void) GError *error = NULL; connection = connection_from_file (TEST_IFCFG_BOND_SLAVE_IB, - NULL, NULL, NULL, &unmanaged, @@ -13670,7 +13195,6 @@ test_write_bond_slave_ib (void) /* re-read the connection for comparison */ reread = connection_from_file (testfile, - NULL, NULL, NULL, &unmanaged, @@ -13722,7 +13246,7 @@ test_read_dcb_basic (void) gboolean expected_pfcs[8] = { TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE }; connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -13855,7 +13379,7 @@ test_write_dcb_basic (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, NULL, NULL, + NULL, NULL, NULL, NULL, &error, &ignore_error); @@ -13880,7 +13404,7 @@ test_read_dcb_default_app_priorities (void) gboolean success; connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-default-app-priorities", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); success = nm_connection_verify (connection, &error); @@ -13911,7 +13435,7 @@ test_read_dcb_bad_booleans (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*invalid DCB_PG_STRICT value*not all 0s and 1s*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-bad-booleans", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -13928,7 +13452,7 @@ test_read_dcb_short_booleans (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*DCB_PG_STRICT value*8 characters*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-short-booleans", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -13945,7 +13469,7 @@ test_read_dcb_bad_uints (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*invalid DCB_PG_UP2TC value*not 0 - 7*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-bad-uints", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -13962,7 +13486,7 @@ test_read_dcb_short_uints (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*DCB_PG_UP2TC value*8 characters*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-short-uints", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -13979,7 +13503,7 @@ test_read_dcb_bad_percent (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*invalid DCB_PG_PCT percentage value*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-bad-percent", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -13996,7 +13520,7 @@ test_read_dcb_short_percent (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*invalid DCB_PG_PCT percentage list value*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-short-percent", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -14013,7 +13537,7 @@ test_read_dcb_pgpct_not_100 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*DCB_PG_PCT percentages do not equal 100*"); connection = connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-pgpct-not-100", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_test_assert_expected_messages (); g_assert_error (error, IFCFG_PLUGIN_ERROR, 0); @@ -14032,7 +13556,7 @@ test_read_fcoe_mode (gconstpointer user_data) char *file; file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-fcoe-%s", expected_mode); - connection = connection_from_file (file, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + connection = connection_from_file (file, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_free (file); g_assert_no_error (error); g_assert (connection); @@ -14125,7 +13649,7 @@ test_write_fcoe_mode (gconstpointer user_data) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, NULL, NULL, + NULL, NULL, NULL, NULL, &error, &ignore_error); @@ -14152,7 +13676,7 @@ test_read_team_master (void) const char *expected_config = "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -14242,7 +13766,7 @@ test_write_team_master (void) nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ - reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL, + reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); unlink (testfile); g_assert_no_error (error); @@ -14270,7 +13794,7 @@ test_read_team_port (void) const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -14365,7 +13889,7 @@ test_write_team_port (void) nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ - reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL, + reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); unlink (testfile); g_assert_no_error (error); @@ -14391,7 +13915,7 @@ test_read_team_port_empty_config (void) GError *error = NULL; connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port-empty-config", - NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, NULL, &error, NULL); + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); g_assert_no_error (error); g_assert (connection); @@ -14699,14 +14223,9 @@ int main (int argc, char **argv) test_write_ethernet_missing_ipv6 (); /* iSCSI / ibft */ - test_read_ibft_dhcp (); - test_read_ibft_static (); - test_read_ibft_malformed ("ibft-bad-record-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-record", FALSE); - test_read_ibft_malformed ("ibft-bad-entry-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-entry", TRUE); - test_read_ibft_malformed ("ibft-bad-ipaddr-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-ipaddr", TRUE); - test_read_ibft_malformed ("ibft-bad-gateway-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-gateway", TRUE); - test_read_ibft_malformed ("ibft-bad-dns1-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-dns1", TRUE); - test_read_ibft_malformed ("ibft-bad-dns2-read", TEST_IFCFG_DIR "/iscsiadm-test-bad-dns2", TRUE); + g_test_add_func (TPATH "ibft/ignored", test_read_ibft_ignored); + + /* Data Center Bridging (DCB) */ g_test_add_func (TPATH "dcb/read-basic", test_read_dcb_basic); g_test_add_func (TPATH "dcb/write-basic", test_write_dcb_basic); g_test_add_func (TPATH "dcb/default-app-priorities", test_read_dcb_default_app_priorities); From b9d8fe80858f4f0c7dd51f18daf2a2eeb85058e4 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 5 Aug 2014 13:34:52 -0500 Subject: [PATCH 4/6] ifcfg-rh: more conversions to g_assert() --- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 403 +++--------------- 1 file changed, 51 insertions(+), 352 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 57470f0a5..bcbc31e28 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -402,8 +402,6 @@ test_read_wired_static (const char *file, const char *expected_dns2 = "4.2.2.2"; guint32 addr; struct in6_addr addr6; - const char *expected_address1 = "192.168.1.5"; - const char *expected_address1_gw = "192.168.1.1"; const char *expected6_address1 = "dead:beaf::1"; const char *expected6_address2 = "dead:beaf::2"; const char *expected6_dns1 = "1:2:3:4::a"; @@ -457,10 +455,8 @@ test_read_wired_static (const char *file, ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); g_assert (ip4_addr); g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24); - g_assert_cmpint (inet_pton (AF_INET, expected_address1, &addr), >, 0); - g_assert_cmpint (nm_ip4_address_get_address (ip4_addr), ==, addr); - g_assert_cmpint (inet_pton (AF_INET, expected_address1_gw, &addr), >, 0); - g_assert_cmpint (nm_ip4_address_get_gateway (ip4_addr), ==, addr); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.1.5"); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "192.168.1.1"); /* ===== IPv6 SETTING ===== */ s_ip6 = nm_connection_get_setting_ip6_config (connection); @@ -801,9 +797,6 @@ test_read_wired_dhcp_plus_ip (void) g_object_unref (connection); } -#define TEST_IFCFG_WIRED_GLOBAL_GATEWAY TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-global-gateway" -#define TEST_NETWORK_WIRED_GLOBAL_GATEWAY TEST_IFCFG_DIR"/network-scripts/network-test-wired-global-gateway" - static void test_read_wired_global_gateway (void) { @@ -811,247 +804,69 @@ test_read_wired_global_gateway (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; - char *unmanaged = NULL; - char *keyfile = NULL; - char *routefile = NULL; - char *route6file = NULL; - gboolean ignore_error = FALSE; GError *error = NULL; - const char *tmp; - const char *expected_id = "System test-wired-global-gateway"; - guint32 addr; - const char *expected_address1 = "192.168.1.5"; - const char *expected_address1_gw = "192.168.1.2"; NMIP4Address *ip4_addr; + char *unmanaged = NULL; - connection = connection_from_file (TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - TEST_NETWORK_WIRED_GLOBAL_GATEWAY, - TYPE_ETHERNET, - &unmanaged, - &keyfile, - &routefile, - &route6file, - &error, - &ignore_error); - ASSERT (connection != NULL, - "wired-global-gateway-read", "failed to read %s: %s", TEST_IFCFG_WIRED_GLOBAL_GATEWAY, error->message); - - ASSERT (nm_connection_verify (connection, &error), - "wired-global-gateway-verify", "failed to verify %s: %s", TEST_IFCFG_WIRED_GLOBAL_GATEWAY, error->message); - - ASSERT (unmanaged == NULL, - "wired-global-gateway-verify", "failed to verify %s: unexpected unmanaged value", TEST_IFCFG_WIRED_GLOBAL_GATEWAY); + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-global-gateway", + TEST_IFCFG_DIR"/network-scripts/network-test-wired-global-gateway", + TYPE_ETHERNET, &unmanaged, NULL, NULL, NULL, &error, NULL); + nmtst_assert_connection_verifies_without_normalization (connection); + g_assert (unmanaged == NULL); /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection (connection); - ASSERT (s_con != NULL, - "wired-global-gateway-verify-connection", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_CONNECTION_SETTING_NAME); - - /* ID */ - tmp = nm_setting_connection_get_id (s_con); - ASSERT (tmp != NULL, - "wired-global-gateway-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, expected_id) == 0, - "wired-global-gateway-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-wired-global-gateway"); /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired (connection); - ASSERT (s_wired != NULL, - "wired-global-gateway-verify-wired", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_WIRED_SETTING_NAME); + g_assert (s_wired); /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config (connection); - ASSERT (s_ip4 != NULL, - "wired-global-gateway-verify-ip4", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME); - - /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); - ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, - "wired-global-gateway-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); /* Address #1 */ ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - ASSERT (ip4_addr, - "wired-global-gateway-verify-ip4", "failed to verify %s: missing IP4 address #1", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); + g_assert (ip4_addr); + g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 24); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_address (ip4_addr), "192.168.1.5"); + nmtst_assert_ip4_address_equals (nm_ip4_address_get_gateway (ip4_addr), "192.168.1.2"); - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == 24, - "wired-global-gateway-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - ASSERT (inet_pton (AF_INET, expected_address1, &addr) > 0, - "wired-global-gateway-verify-ip4", "failed to verify %s: couldn't convert IP address #1", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - "wired-global-gateway-verify-ip4", "failed to verify %s: unexpected IP4 address #1", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - ASSERT (inet_pton (AF_INET, expected_address1_gw, &addr) > 0, - "wired-global-gateway-verify-ip4", "failed to verify %s: couldn't convert IP address #1 gateway", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr, - "wired-global-gateway-verify-ip4", "failed to verify %s: unexpected IP4 address #1 gateway", - TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); g_object_unref (connection); } -#define TEST_IFCFG_WIRED_NEVER_DEFAULT TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-never-default" -#define TEST_NETWORK_WIRED_NEVER_DEFAULT TEST_IFCFG_DIR"/network-scripts/network-test-wired-never-default" - static void test_read_wired_never_default (void) { NMConnection *connection; - NMSettingConnection *s_con; - NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; NMSettingIP6Config *s_ip6; - char *unmanaged = NULL; - char *keyfile = NULL; - char *routefile = NULL; - char *route6file = NULL; - gboolean ignore_error = FALSE; GError *error = NULL; - const char *tmp; - const char *expected_id = "System test-wired-never-default"; - connection = connection_from_file (TEST_IFCFG_WIRED_NEVER_DEFAULT, - TEST_NETWORK_WIRED_NEVER_DEFAULT, - TYPE_ETHERNET, - &unmanaged, - &keyfile, - &routefile, - &route6file, - &error, - &ignore_error); - ASSERT (connection != NULL, - "wired-never-default-read", "failed to read %s: %s", TEST_IFCFG_WIRED_NEVER_DEFAULT, error->message); - - ASSERT (nm_connection_verify (connection, &error), - "wired-never-default-verify", "failed to verify %s: %s", TEST_IFCFG_WIRED_NEVER_DEFAULT, error->message); - - ASSERT (unmanaged == NULL, - "wired-never-default-verify", "failed to verify %s: unexpected unmanaged value", TEST_IFCFG_WIRED_NEVER_DEFAULT); - - /* ===== CONNECTION SETTING ===== */ - - s_con = nm_connection_get_setting_connection (connection); - ASSERT (s_con != NULL, - "wired-never-default-verify-connection", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_CONNECTION_SETTING_NAME); - - /* ID */ - tmp = nm_setting_connection_get_id (s_con); - ASSERT (tmp != NULL, - "wired-never-default-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, expected_id) == 0, - "wired-never-default-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-never-default", + TEST_IFCFG_DIR"/network-scripts/network-test-wired-never-default", + TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); + nmtst_assert_connection_verifies_without_normalization (connection); /* ===== WIRED SETTING ===== */ - - s_wired = nm_connection_get_setting_wired (connection); - ASSERT (s_wired != NULL, - "wired-never-default-verify-wired", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_WIRED_SETTING_NAME); + g_assert (nm_connection_get_setting_wired (connection)); /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config (connection); - ASSERT (s_ip4 != NULL, - "wired-never-default-verify-ip4", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP4_CONFIG_SETTING_NAME); - - /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); - ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, - "wired-never-default-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); - - ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == TRUE, - "wired-never-default-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT); - - /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 0, - "wired-never-default-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert (nm_setting_ip4_config_get_never_default (s_ip4)); + g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 0); /* ===== IPv6 SETTING ===== */ - s_ip6 = nm_connection_get_setting_ip6_config (connection); - ASSERT (s_ip6 != NULL, - "wired-never-default-verify-ip6", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP6_CONFIG_SETTING_NAME); + g_assert (s_ip6); + g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert (nm_setting_ip6_config_get_never_default (s_ip6)); - /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); - ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0, - "wired-never-default-verify-ip6", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); - - ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == TRUE, - "wired-never-default-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_NEVER_DEFAULT, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT); - - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); g_object_unref (connection); } @@ -1298,8 +1113,6 @@ test_read_wired_defroute_no_gatewaydev_yes (void) g_object_unref (connection); } -#define TEST_IFCFG_WIRED_STATIC_ROUTES TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static-routes" - static void test_read_wired_static_routes (void) { @@ -1307,158 +1120,44 @@ test_read_wired_static_routes (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; - char *unmanaged = NULL; - char *keyfile = NULL; - char *routefile = NULL; - char *route6file = NULL; - gboolean ignore_error = FALSE; GError *error = NULL; - const char *tmp; NMIP4Route *ip4_route; - guint32 addr; - const char *expected_id = "System test-wired-static-routes"; - const char *expected_dst1 = "11.22.33.0"; - const char *expected_dst2 = "44.55.66.77"; - const char *expected_gw1 = "192.168.1.5"; - const char *expected_gw2 = "192.168.1.7"; - connection = connection_from_file (TEST_IFCFG_WIRED_STATIC_ROUTES, - NULL, - TYPE_ETHERNET, - &unmanaged, - &keyfile, - &routefile, - &route6file, - &error, - &ignore_error); - - ASSERT (connection != NULL, - "wired-static-routes-read", - "failed to read %s: %s", - TEST_IFCFG_WIRED_STATIC_ROUTES, error->message); - - ASSERT (nm_connection_verify (connection, &error), - "wired-static-routes-verify", "failed to verify %s: %s", - TEST_IFCFG_WIRED_STATIC_ROUTES, error->message); - - ASSERT (unmanaged == NULL, - "wired-static-routes-verify", - "failed to verify %s: unexpected unmanaged value", - TEST_IFCFG_WIRED_STATIC_ROUTES); + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-static-routes", + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); + nmtst_assert_connection_verifies_without_normalization (connection); /* ===== CONNECTION SETTING ===== */ - s_con = nm_connection_get_setting_connection (connection); - ASSERT (s_con != NULL, - "wired-static-routes-verify-connection", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_CONNECTION_SETTING_NAME); - - /* ID */ - tmp = nm_setting_connection_get_id (s_con); - ASSERT (tmp != NULL, - "wired-static-routes-verify-connection", "failed to verify %s: missing %s / %s key", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); - ASSERT (strcmp (tmp, expected_id) == 0, - "wired-static-routes-verify-connection", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_ID); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-wired-static-routes"); /* ===== WIRED SETTING ===== */ - s_wired = nm_connection_get_setting_wired (connection); - ASSERT (s_wired != NULL, - "wired-static-routes-verify-wired", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_WIRED_SETTING_NAME); + g_assert (s_wired); /* ===== IPv4 SETTING ===== */ - s_ip4 = nm_connection_get_setting_ip4_config (connection); - ASSERT (s_ip4 != NULL, - "wired-static-routes-verify-ip4", "failed to verify %s: missing %s setting", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME); - - /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); - ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); /* Routes */ - ASSERT (nm_setting_ip4_config_get_num_routes (s_ip4) == 2, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected %s / %s key value", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); + g_assert_cmpint (nm_setting_ip4_config_get_num_routes (s_ip4), ==, 2); ip4_route = nm_setting_ip4_config_get_route (s_ip4, 0); - ASSERT (ip4_route, - "wired-static-routes-verify-ip4", "failed to verify %s: missing IP4 route #1", - TEST_IFCFG_WIRED_STATIC_ROUTES); - - ASSERT (inet_pton (AF_INET, expected_dst1, &addr) > 0, - "wired-static-routes-verify-ip4", "failed to verify %s: couldn't convert destination IP address #1", - TEST_IFCFG_WIRED_STATIC_ROUTES); - ASSERT (nm_ip4_route_get_dest (ip4_route) == addr, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_prefix (ip4_route) == 24, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected destination route #1 prefix", - TEST_IFCFG_WIRED_STATIC_ROUTES); - - ASSERT (inet_pton (AF_INET, expected_gw1, &addr) > 0, - "wired-static-routes-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #1", - TEST_IFCFG_WIRED_STATIC_ROUTES); - ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); + g_assert (ip4_route); + nmtst_assert_ip4_address_equals (nm_ip4_route_get_dest (ip4_route), "11.22.33.0"); + g_assert_cmpint (nm_ip4_route_get_prefix (ip4_route), ==, 24); + nmtst_assert_ip4_address_equals (nm_ip4_route_get_next_hop (ip4_route), "192.168.1.5"); + g_assert_cmpint (nm_ip4_route_get_metric (ip4_route), ==, 0); ip4_route = nm_setting_ip4_config_get_route (s_ip4, 1); - ASSERT (ip4_route, - "wired-static-routes-verify-ip4", "failed to verify %s: missing IP4 route #2", - TEST_IFCFG_WIRED_STATIC_ROUTES); + g_assert (ip4_route); + nmtst_assert_ip4_address_equals (nm_ip4_route_get_dest (ip4_route), "44.55.66.77"); + g_assert_cmpint (nm_ip4_route_get_prefix (ip4_route), ==, 32); + nmtst_assert_ip4_address_equals (nm_ip4_route_get_next_hop (ip4_route), "192.168.1.7"); + g_assert_cmpint (nm_ip4_route_get_metric (ip4_route), ==, 3); - ASSERT (inet_pton (AF_INET, expected_dst2, &addr) > 0, - "wired-static-routes-verify-ip4", "failed to verify %s: couldn't convert destination IP address #2", - TEST_IFCFG_WIRED_STATIC_ROUTES); - ASSERT (nm_ip4_route_get_dest (ip4_route) == addr, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_prefix (ip4_route) == 32, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected destination route #2 prefix", - TEST_IFCFG_WIRED_STATIC_ROUTES); - - ASSERT (inet_pton (AF_INET, expected_gw2, &addr) > 0, - "wired-static-routes-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #2", - TEST_IFCFG_WIRED_STATIC_ROUTES); - ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", - TEST_IFCFG_WIRED_STATIC_ROUTES, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - ASSERT (nm_ip4_route_get_metric (ip4_route) == 3, - "wired-static-routes-verify-ip4", "failed to verify %s: unexpected route metric #2", - TEST_IFCFG_WIRED_STATIC_ROUTES); - - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); g_object_unref (connection); } @@ -14083,11 +13782,11 @@ int main (int argc, char **argv) test_read_wired_dhcp (); g_test_add_func (TPATH "dhcp-plus-ip", test_read_wired_dhcp_plus_ip); g_test_add_func (TPATH "dhcp-send-hostname", test_read_write_wired_dhcp_send_hostname); - test_read_wired_global_gateway (); - test_read_wired_never_default (); + g_test_add_func (TPATH "global-gateway", test_read_wired_global_gateway); + g_test_add_func (TPATH "never-default", test_read_wired_never_default); test_read_wired_defroute_no (); test_read_wired_defroute_no_gatewaydev_yes (); - test_read_wired_static_routes (); + g_test_add_func (TPATH "routes/read-static", test_read_wired_static_routes); test_read_wired_static_routes_legacy (); test_read_wired_ipv4_manual (TEST_IFCFG_WIRED_IPV4_MANUAL_1, "System test-wired-ipv4-manual-1"); test_read_wired_ipv4_manual (TEST_IFCFG_WIRED_IPV4_MANUAL_2, "System test-wired-ipv4-manual-2"); From af13376e2bb22bc13921a2f2c39c66a476ac674d Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 19 Aug 2014 14:13:46 -0500 Subject: [PATCH 5/6] core: allow plugin/factory originated devices to assume connections This didn't previously matter because BT/WWAN/WiFi/ADSL can't easily assume existing connections due to the external helpers involved, but when we converted Team support to a plugin we now want to allow this. --- src/nm-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nm-manager.c b/src/nm-manager.c index fd7d07145..842fba998 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1908,7 +1908,7 @@ factory_device_added_cb (NMDeviceFactory *factory, NMDevice *device, gpointer user_data) { - add_device (NM_MANAGER (user_data), device, FALSE); + add_device (NM_MANAGER (user_data), device, TRUE); } static gboolean From a175ff090cac3172f9e194335fac38056e046504 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 19 Aug 2014 14:23:47 -0500 Subject: [PATCH 6/6] core: allow connection assumption on pre-configured software devices In the specific case that triggered this bug, both eth0 and eth0.123 existed and were configured before NM started, and a valid saved connection existed for eth0.123. eth0 was ordered before eth0.123 in the Platform's link list. When the end of add_devices() was reached for eth0 and system_create_virtual_devices() was called, NM created an NMDevice for the pre-existing eth0.123 link due to the saved connection, and ignored the existing configuration because system_create_virtual_device() re-calls add_device() with generate_con = FALSE. Instead, we should allow system_create_virtual_device() to call add_device() with generate_con = TRUE if the interface existed before NM created it. We only want to skip connection assumption if the device was actually just created by NM, in which case it cannot have any configuration to assume. --- src/nm-manager.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nm-manager.c b/src/nm-manager.c index 842fba998..6b8ed909a 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1078,6 +1078,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection) GSList *iter; char *iface = NULL; NMDevice *device = NULL, *parent = NULL; + gboolean nm_owned = FALSE; iface = get_virtual_iface_name (self, connection, &parent); if (!iface) { @@ -1101,6 +1102,8 @@ system_create_virtual_device (NMManager *self, NMConnection *connection) */ priv->ignore_link_added_cb++; + nm_owned = !nm_platform_link_exists (iface); + if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) { device = nm_device_bond_new_for_connection (connection); } else if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) { @@ -1127,8 +1130,14 @@ system_create_virtual_device (NMManager *self, NMConnection *connection) } if (device) { - nm_device_set_nm_owned (device); - add_device (self, device, FALSE); + if (nm_owned) + nm_device_set_nm_owned (device); + + /* If it was created by NM there's no connection to assume, but if it + * previously existed there might be one. + */ + add_device (self, device, !nm_owned); + g_object_unref (device); }