diff options
Diffstat (limited to 'src/settings/plugins')
116 files changed, 7755 insertions, 6580 deletions
diff --git a/src/settings/plugins/Makefile.am b/src/settings/plugins/Makefile.am index 41694e7e..568da7f6 100644 --- a/src/settings/plugins/Makefile.am +++ b/src/settings/plugins/Makefile.am @@ -2,6 +2,10 @@ SUBDIRS=keyfile example @GNOME_CODE_COVERAGE_RULES@ +if CONFIG_PLUGIN_IBFT +SUBDIRS+=ibft +endif + if CONFIG_PLUGIN_IFCFG_RH SUBDIRS+=ifcfg-rh endif diff --git a/src/settings/plugins/Makefile.in b/src/settings/plugins/Makefile.in index 8c7c0bb8..1e9b0fdd 100644 --- a/src/settings/plugins/Makefile.in +++ b/src/settings/plugins/Makefile.in @@ -77,10 +77,11 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_1 = ifcfg-rh -@CONFIG_PLUGIN_IFCFG_SUSE_TRUE@am__append_2 = ifcfg-suse -@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_3 = ifupdown -@CONFIG_PLUGIN_IFNET_TRUE@am__append_4 = ifnet +@CONFIG_PLUGIN_IBFT_TRUE@am__append_1 = ibft +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_2 = ifcfg-rh +@CONFIG_PLUGIN_IFCFG_SUSE_TRUE@am__append_3 = ifcfg-suse +@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_4 = ifupdown +@CONFIG_PLUGIN_IFNET_TRUE@am__append_5 = ifnet subdir = src/settings/plugins DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -157,7 +158,7 @@ am__define_uniq_tagged_files = \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags -DIST_SUBDIRS = keyfile example ifcfg-rh ifcfg-suse ifupdown ifnet +DIST_SUBDIRS = keyfile example ibft ifcfg-rh ifcfg-suse ifupdown ifnet DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) am__relativize = \ dir0=`pwd`; \ @@ -193,6 +194,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -316,6 +319,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -335,6 +339,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -361,7 +366,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -441,7 +446,7 @@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ SUBDIRS = keyfile example $(am__append_1) $(am__append_2) \ - $(am__append_3) $(am__append_4) + $(am__append_3) $(am__append_4) $(am__append_5) all: all-recursive .SUFFIXES: diff --git a/src/settings/plugins/example/Makefile.am b/src/settings/plugins/example/Makefile.am index 8233a71f..b98f66ef 100644 --- a/src/settings/plugins/example/Makefile.am +++ b/src/settings/plugins/example/Makefile.am @@ -1,17 +1,14 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-example"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" # 'noinst' here because this is an example plugin we don't want to install @@ -27,15 +24,9 @@ libnm_settings_plugin_example_la_SOURCES = \ nm-example-connection.h \ plugin.c \ plugin.h \ - errors.c \ common.h \ reader.c \ writer.c -libnm_settings_plugin_example_la_LIBADD = \ - $(top_builddir)/src/libNetworkManager.la \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(GLIB_LIBS) - libnm_settings_plugin_example_la_LDFLAGS = -module -avoid-version diff --git a/src/settings/plugins/example/Makefile.in b/src/settings/plugins/example/Makefile.in index 26aa0a60..baa5c698 100644 --- a/src/settings/plugins/example/Makefile.in +++ b/src/settings/plugins/example/Makefile.in @@ -102,13 +102,9 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) -am__DEPENDENCIES_1 = -libnm_settings_plugin_example_la_DEPENDENCIES = \ - $(top_builddir)/src/libNetworkManager.la \ - $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) +libnm_settings_plugin_example_la_LIBADD = am_libnm_settings_plugin_example_la_OBJECTS = \ - nm-example-connection.lo plugin.lo errors.lo reader.lo \ - writer.lo + nm-example-connection.lo plugin.lo reader.lo writer.lo libnm_settings_plugin_example_la_OBJECTS = \ $(am_libnm_settings_plugin_example_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) @@ -189,6 +185,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -312,6 +310,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -331,6 +330,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -357,7 +357,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -438,18 +438,15 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-example"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" @@ -465,16 +462,10 @@ libnm_settings_plugin_example_la_SOURCES = \ nm-example-connection.h \ plugin.c \ plugin.h \ - errors.c \ common.h \ reader.c \ writer.c -libnm_settings_plugin_example_la_LIBADD = \ - $(top_builddir)/src/libNetworkManager.la \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(GLIB_LIBS) - libnm_settings_plugin_example_la_LDFLAGS = -module -avoid-version all: all-am @@ -531,7 +522,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-example-connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Plo@am__quote@ diff --git a/src/settings/plugins/example/common.h b/src/settings/plugins/example/common.h index ed0be9a7..cf209fe0 100644 --- a/src/settings/plugins/example/common.h +++ b/src/settings/plugins/example/common.h @@ -33,17 +33,6 @@ #define EXAMPLE_DIR NMCONFDIR "/example-plugin" -/* Boilerplate stuff for the plugin's error domain. Bits of the code that - * create new errors in the plugin's domain will create errors of - * type EXAMPLE_PLUGIN_ERROR like so: - * - * error = g_error_new_literal (EXAMPLE_PLUGIN_ERROR, - * <specific error number>, - * "This is a really bad error."); - */ -#define EXAMPLE_PLUGIN_ERROR (example_plugin_error_quark ()) -GQuark example_plugin_error_quark (void); - /* Prototypes for the reader/writer functions */ NMConnection *connection_from_file (const char *filename, GError **error); diff --git a/src/settings/plugins/example/errors.c b/src/settings/plugins/example/errors.c deleted file mode 100644 index 8181f8a3..00000000 --- a/src/settings/plugins/example/errors.c +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- 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. - * - * (C) Copyright 2012 Red Hat, Inc. - */ - -#include <glib.h> -#include "common.h" - -/* This is boilerplate code for defining the error domain that the plugin may - * return to NetworkManager for various operations. It just registers a - * GObject "quark" (a UUID really) for the error which allows glib to keep - * track of all the different error domains. - */ -GQuark -example_plugin_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("example-plugin-error-quark"); - - return error_quark; -} - - diff --git a/src/settings/plugins/example/nm-example-connection.c b/src/settings/plugins/example/nm-example-connection.c index e2226829..2f0b20a0 100644 --- a/src/settings/plugins/example/nm-example-connection.c +++ b/src/settings/plugins/example/nm-example-connection.c @@ -18,9 +18,11 @@ * Copyright (C) 2012 Red Hat, Inc. */ +#include "config.h" + #include <string.h> #include <glib/gstdio.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-setting-connection.h> #include <nm-utils.h> @@ -89,7 +91,7 @@ nm_example_connection_new (const char *full_path, /* Make sure we have a UUID; just a sanity check */ uuid = nm_connection_get_uuid (NM_CONNECTION (object)); if (!uuid) { - g_set_error (error, EXAMPLE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Connection in file %s had no UUID", full_path); g_object_unref (object); object = NULL; @@ -165,12 +167,7 @@ nm_example_connection_init (NMExampleConnection *connection) static void finalize (GObject *object) { - NMExampleConnectionPrivate *priv = NM_EXAMPLE_CONNECTION_GET_PRIVATE (object); - - /* Zero out any secrets so we don't leave them in memory */ - nm_connection_clear_secrets (NM_CONNECTION (object)); - - g_free (priv->path); + g_free (NM_EXAMPLE_CONNECTION_GET_PRIVATE (object)->path); G_OBJECT_CLASS (nm_example_connection_parent_class)->finalize (object); } diff --git a/src/settings/plugins/example/nm-example-connection.h b/src/settings/plugins/example/nm-example-connection.h index 6d57a1ad..ddbd7ac2 100644 --- a/src/settings/plugins/example/nm-example-connection.h +++ b/src/settings/plugins/example/nm-example-connection.h @@ -18,8 +18,8 @@ * Copyright (C) 2012 Red Hat, Inc. */ -#ifndef NM_EXAMPLE_CONNECTION_H -#define NM_EXAMPLE_CONNECTION_H +#ifndef __NETWORKMANAGER_EXAMPLE_CONNECTION_H__ +#define __NETWORKMANAGER_EXAMPLE_CONNECTION_H__ #include <nm-settings-connection.h> @@ -52,4 +52,4 @@ const char *nm_example_connection_get_path (NMExampleConnection *self); G_END_DECLS -#endif /* NM_EXAMPLE_CONNECTION_H */ +#endif /* __NETWORKMANAGER_EXAMPLE_CONNECTION_H__ */ diff --git a/src/settings/plugins/example/plugin.c b/src/settings/plugins/example/plugin.c index eea94946..9945e13b 100644 --- a/src/settings/plugins/example/plugin.c +++ b/src/settings/plugins/example/plugin.c @@ -18,11 +18,11 @@ * Copyright (C) 2012 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <sys/stat.h> #include <unistd.h> #include <sys/types.h> -#include <netinet/ether.h> #include <string.h> #include <gmodule.h> @@ -198,11 +198,8 @@ update_connection_settings_commit_cb (NMSettingsConnection *orig, GError *error, * an error here. */ if (error) { - nm_log_warn (LOGD_SETTINGS, "%s: '%s' / '%s' invalid: %d", - __func__, - error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(none)", - (error && error->message) ? error->message : "(none)", - error ? error->code : -1); + nm_log_warn (LOGD_SETTINGS, "%s: connection invalid: %s", + __func__, error->message); g_clear_error (&error); nm_settings_connection_signal_remove (orig); @@ -560,7 +557,7 @@ get_unmanaged_specs (NMSystemConfigInterface *config) ids = g_strsplit (str, ";", -1); for (i = 0; ids[i] != NULL; i++) { /* Verify unmanaged specification and add it to the list */ - if (!strncmp (ids[i], "mac:", 4) && nm_utils_hwaddr_valid (ids[i] + 4)) { + if (!strncmp (ids[i], "mac:", 4) && nm_utils_hwaddr_valid (ids[i] + 4, -1)) { specs = g_slist_append (specs, ids[i]); } else if (!strncmp (ids[i], "interface-name:", 15) && nm_utils_iface_valid_name (ids[i] + 15)) { specs = g_slist_append (specs, ids[i]); diff --git a/src/settings/plugins/example/reader.c b/src/settings/plugins/example/reader.c index 9a4cecaa..ee45440a 100644 --- a/src/settings/plugins/example/reader.c +++ b/src/settings/plugins/example/reader.c @@ -18,11 +18,12 @@ * Copyright (C) 2012 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <glib.h> #include <nm-connection.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include "common.h" diff --git a/src/settings/plugins/example/writer.c b/src/settings/plugins/example/writer.c index f0a9ea21..41e5c498 100644 --- a/src/settings/plugins/example/writer.c +++ b/src/settings/plugins/example/writer.c @@ -18,7 +18,8 @@ * Copyright (C) 2012 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <glib.h> #include <nm-connection.h> diff --git a/src/settings/plugins/ibft/Makefile.am b/src/settings/plugins/ibft/Makefile.am new file mode 100644 index 00000000..00a5d175 --- /dev/null +++ b/src/settings/plugins/ibft/Makefile.am @@ -0,0 +1,38 @@ +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 + +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/Makefile.in b/src/settings/plugins/ibft/Makefile.in new file mode 100644 index 00000000..415961df --- /dev/null +++ b/src/settings/plugins/ibft/Makefile.in @@ -0,0 +1,956 @@ +# Makefile.in generated by automake 1.13.4 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/settings/plugins/ibft +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ + $(top_srcdir)/build-aux/depcomp +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \ + $(top_srcdir)/m4/compiler_warnings.m4 \ + $(top_srcdir)/m4/gettext.m4 \ + $(top_srcdir)/m4/gnome-code-coverage.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \ + $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/m4/vapigen.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(pkglibdir)" +LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES) +libibft_io_la_LIBADD = +am_libibft_io_la_OBJECTS = reader.lo +libibft_io_la_OBJECTS = $(am_libibft_io_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +libnm_settings_plugin_ibft_la_DEPENDENCIES = libibft-io.la +am_libnm_settings_plugin_ibft_la_OBJECTS = plugin.lo \ + nm-ibft-connection.lo +libnm_settings_plugin_ibft_la_OBJECTS = \ + $(am_libnm_settings_plugin_ibft_la_OBJECTS) +libnm_settings_plugin_ibft_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) \ + $(libnm_settings_plugin_ibft_la_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libibft_io_la_SOURCES) \ + $(libnm_settings_plugin_ibft_la_SOURCES) +DIST_SOURCES = $(libibft_io_la_SOURCES) \ + $(libnm_settings_plugin_ibft_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CKDB_PATH = @CKDB_PATH@ +CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ +CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ +CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ +DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ +DBUS_LIBS = @DBUS_LIBS@ +DBUS_SYS_DIR = @DBUS_SYS_DIR@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DHCLIENT_PATH = @DHCLIENT_PATH@ +DHCPCD_PATH = @DHCPCD_PATH@ +DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ +DLLTOOL = @DLLTOOL@ +DNSMASQ_PATH = @DNSMASQ_PATH@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GENHTML = @GENHTML@ +GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GLIB_MAKEFILE = @GLIB_MAKEFILE@ +GLIB_MKENUMS = @GLIB_MKENUMS@ +GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ +GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +GUDEV_CFLAGS = @GUDEV_CFLAGS@ +GUDEV_LIBS = @GUDEV_LIBS@ +HTML_DIR = @HTML_DIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ +INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ +INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ +INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ +INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ +INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ +INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ +INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ +INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ +INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ +INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ +IPTABLES_PATH = @IPTABLES_PATH@ +IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ +IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ +KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ +LCOV = @LCOV@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDL = @LIBDL@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ +LIBM = @LIBM@ +LIBNDP_CFLAGS = @LIBNDP_CFLAGS@ +LIBNDP_LIBS = @LIBNDP_LIBS@ +LIBNL_CFLAGS = @LIBNL_CFLAGS@ +LIBNL_LIBS = @LIBNL_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ +LIBSOUP_LIBS = @LIBSOUP_LIBS@ +LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ +LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MM_GLIB_CFLAGS = @MM_GLIB_CFLAGS@ +MM_GLIB_LIBS = @MM_GLIB_LIBS@ +MOC = @MOC@ +MSGFMT = @MSGFMT@ +MSGFMT_015 = @MSGFMT_015@ +MSGMERGE = @MSGMERGE@ +NEWT_CFLAGS = @NEWT_CFLAGS@ +NEWT_LIBS = @NEWT_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ +NM_MICRO_VERSION = @NM_MICRO_VERSION@ +NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_MODIFY_SYSTEM_POLICY = @NM_MODIFY_SYSTEM_POLICY@ +NM_VERSION = @NM_VERSION@ +NSS_CFLAGS = @NSS_CFLAGS@ +NSS_LIBS = @NSS_LIBS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POLKIT_CFLAGS = @POLKIT_CFLAGS@ +POLKIT_LIBS = @POLKIT_LIBS@ +POSUB = @POSUB@ +PPPD_PATH = @PPPD_PATH@ +PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ +PPPOE_PATH = @PPPOE_PATH@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ +SED = @SED@ +SELINUX_CFLAGS = @SELINUX_CFLAGS@ +SELINUX_LIBS = @SELINUX_LIBS@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ +SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ +SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ +SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ +SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ +SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ +UDEV_DIR = @UDEV_DIR@ +USE_NLS = @USE_NLS@ +UUID_CFLAGS = @UUID_CFLAGS@ +UUID_LIBS = @UUID_LIBS@ +VALGRIND_RULES = @VALGRIND_RULES@ +VAPIGEN = @VAPIGEN@ +VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@ +VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +intltool__v_merge_options_ = @intltool__v_merge_options_@ +intltool__v_merge_options_0 = @intltool__v_merge_options_0@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +nmbinary = @nmbinary@ +nmconfdir = @nmconfdir@ +nmdatadir = @nmdatadir@ +nmrundir = @nmrundir@ +nmstatedir = @nmstatedir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +with_dhclient = @with_dhclient@ +with_dhcpcd = @with_dhcpcd@ +with_netconfig = @with_netconfig@ +with_resolvconf = @with_resolvconf@ +with_valgrind = @with_valgrind@ +SUBDIRS = . tests +pkglib_LTLIBRARIES = libnm-settings-plugin-ibft.la +noinst_LTLIBRARIES = libibft-io.la +libibft_io_la_SOURCES = \ + reader.c \ + reader.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) +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/settings/plugins/ibft/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/settings/plugins/ibft/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkglibdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkglibdir)"; \ + } + +uninstall-pkglibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \ + done + +clean-pkglibLTLIBRARIES: + -test -z "$(pkglib_LTLIBRARIES)" || rm -f $(pkglib_LTLIBRARIES) + @list='$(pkglib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libibft-io.la: $(libibft_io_la_OBJECTS) $(libibft_io_la_DEPENDENCIES) $(EXTRA_libibft_io_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libibft_io_la_OBJECTS) $(libibft_io_la_LIBADD) $(LIBS) + +libnm-settings-plugin-ibft.la: $(libnm_settings_plugin_ibft_la_OBJECTS) $(libnm_settings_plugin_ibft_la_DEPENDENCIES) $(EXTRA_libnm_settings_plugin_ibft_la_DEPENDENCIES) + $(AM_V_CCLD)$(libnm_settings_plugin_ibft_la_LINK) -rpath $(pkglibdir) $(libnm_settings_plugin_ibft_la_OBJECTS) $(libnm_settings_plugin_ibft_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-ibft-connection.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(LTLIBRARIES) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(pkglibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + clean-pkglibLTLIBRARIES mostlyclean-am + +distclean: distclean-recursive + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: install-pkglibLTLIBRARIES + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-pkglibLTLIBRARIES + +.MAKE: $(am__recursive_targets) install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ + check-am clean clean-generic clean-libtool \ + clean-noinstLTLIBRARIES clean-pkglibLTLIBRARIES cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-pkglibLTLIBRARIES install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-pkglibLTLIBRARIES + + +@GNOME_CODE_COVERAGE_RULES@ + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: 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 00000000..5459a705 --- /dev/null +++ b/src/settings/plugins/ibft/nm-ibft-connection.c @@ -0,0 +1,66 @@ +/* -*- 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 "config.h" + +#include <string.h> +#include <net/ethernet.h> +#include <netinet/ether.h> + +#include <glib/gstdio.h> + +#include "nm-ibft-connection.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 00000000..4ccebc3c --- /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 <nm-settings-connection.h> + +#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 00000000..303971e0 --- /dev/null +++ b/src/settings/plugins/ibft/plugin.c @@ -0,0 +1,210 @@ +/* -*- 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 "config.h" + +#include <string.h> +#include <unistd.h> +#include <errno.h> + +#include <gmodule.h> +#include <glib-object.h> +#include <glib/gi18n.h> +#include <gio/gio.h> + +#include <nm-setting-connection.h> + +#include "nm-dbus-glib-types.h" +#include "nm-system-config-interface.h" +#include "nm-logging.h" +#include "NetworkManagerUtils.h" + +#include "plugin.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 = NULL, *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 00000000..2c811359 --- /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 <glib-object.h> + +#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 00000000..066a79f2 --- /dev/null +++ b/src/settings/plugins/ibft/reader.c @@ -0,0 +1,558 @@ +/* -*- 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 "config.h" + +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <sys/wait.h> +#include <sys/inotify.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <unistd.h> + +#include <glib.h> +#include <glib/gi18n.h> + +#include "nm-core-internal.h" +#include "nm-platform.h" +#include "nm-posix-signals.h" +#include "NetworkManagerUtils.h" +#include "nm-logging.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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "iBFT: %s exited abnormally.", iscsiadm_path); + goto done; + } + + if (WEXITSTATUS (status) != 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "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) +{ + NMSettingIPConfig *s_ip4 = NULL; + NMIPAddress *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 netmask = 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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: missing " ISCSI_BOOTPROTO_TAG); + goto error; + } + + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + + if (!g_ascii_strcasecmp (s_method, "dhcp")) { + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + goto success; + } else if (g_ascii_strcasecmp (s_method, "static") != 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: unknown " ISCSI_BOOTPROTO_TAG " '%s'.", + s_method); + goto error; + } + + /* Static configuration stuff */ + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + + /* IP address */ + if (!s_ipaddr || !nm_utils_ipaddr_valid (AF_INET, s_ipaddr)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: invalid subnet mask '%s'.", + s_netmask); + goto error; + } + prefix = nm_utils_ip4_netmask_to_prefix (netmask); + + if (s_gateway && !nm_utils_ipaddr_valid (AF_INET, s_gateway)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: invalid IP gateway '%s'.", + s_gateway); + goto error; + } + + if (s_dns1 && !nm_utils_ipaddr_valid (AF_INET, s_dns1)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: invalid DNS1 address '%s'.", + s_dns1); + goto error; + } + + if (s_dns2 && !nm_utils_ipaddr_valid (AF_INET, s_dns2)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: invalid DNS2 address '%s'.", + s_dns2); + goto error; + } + + addr = nm_ip_address_new (AF_INET, s_ipaddr, prefix, error); + if (!addr) { + g_prefix_error (error, "iBFT: malformed iscsiadm record: "); + goto error; + } + + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); + + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, s_gateway, NULL); + + if (s_dns1) + nm_setting_ip_config_add_dns (s_ip4, s_dns1); + if (s_dns2) + nm_setting_ip_config_add_dns (s_ip4, s_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; + 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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: missing " ISCSI_HWADDR_TAG); + return FALSE; + } + + id = g_strdup_printf ("iBFT%s%s %s", + prefix ? " " : "", + prefix ? prefix : "", + iface); + + uuid = nm_utils_uuid_generate_from_strings ("ibft", + s_hwaddr, + s_vlanid ? "V" : "v", + s_vlanid ? s_vlanid : "", + s_ip4addr ? "A" : "DHCP", + s_ip4addr ? s_ip4addr : "", + NULL); + + 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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "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 = NULL; + + g_assert (block); + g_assert (connection); + + if (!parse_ibft_config (block, NULL, ISCSI_HWADDR_TAG, &hwaddr, NULL)) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: missing " ISCSI_HWADDR_TAG); + return FALSE; + } + + if (!nm_utils_hwaddr_valid (hwaddr, ETH_ALEN)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "iBFT: malformed iscsiadm record: invalid " ISCSI_HWADDR_TAG " '%s'.", + hwaddr); + return FALSE; + } + + s_wired = nm_setting_wired_new (); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, hwaddr, NULL); + + 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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "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/keyfile/errors.c b/src/settings/plugins/ibft/reader.h index e2e97690..0b2f22b6 100644 --- a/src/settings/plugins/keyfile/errors.c +++ b/src/settings/plugins/ibft/reader.h @@ -15,21 +15,22 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (C) Copyright 2008 - 2010 Red Hat, Inc. + * Copyright 2014 Red Hat, Inc. */ -#include <glib.h> -#include "common.h" +#ifndef __READER_H__ +#define __READER_H__ -GQuark -keyfile_plugin_error_quark (void) -{ - static GQuark error_quark = 0; +#include <glib.h> +#include <nm-connection.h> - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("keyfile-plugin-error-quark"); +gboolean read_ibft_blocks (const char *iscsiadm_path, + GSList **out_blocks, + GError **error); - return error_quark; -} +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 00000000..dd72220a --- /dev/null +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -0,0 +1,49 @@ +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 \ + ../reader.c + +test_ibft_LDADD = \ + $(top_builddir)/src/libNetworkManager.la + +TESTS = test-ibft + +endif + +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 + diff --git a/src/settings/plugins/ibft/tests/Makefile.in b/src/settings/plugins/ibft/tests/Makefile.in new file mode 100644 index 00000000..e2f06169 --- /dev/null +++ b/src/settings/plugins/ibft/tests/Makefile.in @@ -0,0 +1,899 @@ +# Makefile.in generated by automake 1.13.4 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2013 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +@ENABLE_TESTS_TRUE@noinst_PROGRAMS = test-ibft$(EXEEXT) +@ENABLE_TESTS_TRUE@TESTS = test-ibft$(EXEEXT) +subdir = src/settings/plugins/ibft/tests +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ + $(top_srcdir)/build-aux/depcomp +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \ + $(top_srcdir)/m4/compiler_warnings.m4 \ + $(top_srcdir)/m4/gettext.m4 \ + $(top_srcdir)/m4/gnome-code-coverage.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \ + $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/m4/vapigen.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +PROGRAMS = $(noinst_PROGRAMS) +am__test_ibft_SOURCES_DIST = test-ibft.c ../reader.c +@ENABLE_TESTS_TRUE@am_test_ibft_OBJECTS = test-ibft.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@ reader.$(OBJEXT) +test_ibft_OBJECTS = $(am_test_ibft_OBJECTS) +@ENABLE_TESTS_TRUE@test_ibft_DEPENDENCIES = \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(test_ibft_SOURCES) +DIST_SOURCES = $(am__test_ibft_SOURCES_DIST) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__tty_colors_dummy = \ + mgn= red= grn= lgn= blu= brg= std=; \ + am__color_tests=no +am__tty_colors = { \ + $(am__tty_colors_dummy); \ + if test "X$(AM_COLOR_TESTS)" = Xno; then \ + am__color_tests=no; \ + elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ + am__color_tests=yes; \ + elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ + am__color_tests=yes; \ + fi; \ + if test $$am__color_tests = yes; then \ + red='[0;31m'; \ + grn='[0;32m'; \ + lgn='[1;32m'; \ + blu='[1;34m'; \ + mgn='[0;35m'; \ + brg='[1m'; \ + std='[m'; \ + fi; \ +} +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ALL_LINGUAS = @ALL_LINGUAS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CKDB_PATH = @CKDB_PATH@ +CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ +CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ +CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ +DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ +DBUS_LIBS = @DBUS_LIBS@ +DBUS_SYS_DIR = @DBUS_SYS_DIR@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DHCLIENT_PATH = @DHCLIENT_PATH@ +DHCPCD_PATH = @DHCPCD_PATH@ +DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ +DLLTOOL = @DLLTOOL@ +DNSMASQ_PATH = @DNSMASQ_PATH@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GENHTML = @GENHTML@ +GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GLIB_MAKEFILE = @GLIB_MAKEFILE@ +GLIB_MKENUMS = @GLIB_MKENUMS@ +GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ +GREP = @GREP@ +GTKDOC_CHECK = @GTKDOC_CHECK@ +GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ +GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ +GTKDOC_MKPDF = @GTKDOC_MKPDF@ +GTKDOC_REBASE = @GTKDOC_REBASE@ +GUDEV_CFLAGS = @GUDEV_CFLAGS@ +GUDEV_LIBS = @GUDEV_LIBS@ +HTML_DIR = @HTML_DIR@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INTLLIBS = @INTLLIBS@ +INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@ +INTLTOOL_MERGE = @INTLTOOL_MERGE@ +INTLTOOL_PERL = @INTLTOOL_PERL@ +INTLTOOL_UPDATE = @INTLTOOL_UPDATE@ +INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@ +INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@ +INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@ +INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@ +INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@ +INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@ +INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@ +INTROSPECTION_LIBS = @INTROSPECTION_LIBS@ +INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ +INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ +INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ +IPTABLES_PATH = @IPTABLES_PATH@ +IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ +IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ +KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ +LCOV = @LCOV@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDL = @LIBDL@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ +LIBM = @LIBM@ +LIBNDP_CFLAGS = @LIBNDP_CFLAGS@ +LIBNDP_LIBS = @LIBNDP_LIBS@ +LIBNL_CFLAGS = @LIBNL_CFLAGS@ +LIBNL_LIBS = @LIBNL_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ +LIBSOUP_LIBS = @LIBSOUP_LIBS@ +LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@ +LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MM_GLIB_CFLAGS = @MM_GLIB_CFLAGS@ +MM_GLIB_LIBS = @MM_GLIB_LIBS@ +MOC = @MOC@ +MSGFMT = @MSGFMT@ +MSGFMT_015 = @MSGFMT_015@ +MSGMERGE = @MSGMERGE@ +NEWT_CFLAGS = @NEWT_CFLAGS@ +NEWT_LIBS = @NEWT_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ +NM_MICRO_VERSION = @NM_MICRO_VERSION@ +NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_MODIFY_SYSTEM_POLICY = @NM_MODIFY_SYSTEM_POLICY@ +NM_VERSION = @NM_VERSION@ +NSS_CFLAGS = @NSS_CFLAGS@ +NSS_LIBS = @NSS_LIBS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +POLKIT_CFLAGS = @POLKIT_CFLAGS@ +POLKIT_LIBS = @POLKIT_LIBS@ +POSUB = @POSUB@ +PPPD_PATH = @PPPD_PATH@ +PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ +PPPOE_PATH = @PPPOE_PATH@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ +SED = @SED@ +SELINUX_CFLAGS = @SELINUX_CFLAGS@ +SELINUX_LIBS = @SELINUX_LIBS@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ +SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ +SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ +SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ +SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ +SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ +UDEV_DIR = @UDEV_DIR@ +USE_NLS = @USE_NLS@ +UUID_CFLAGS = @UUID_CFLAGS@ +UUID_LIBS = @UUID_LIBS@ +VALGRIND_RULES = @VALGRIND_RULES@ +VAPIGEN = @VAPIGEN@ +VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@ +VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +intltool__v_merge_options_ = @intltool__v_merge_options_@ +intltool__v_merge_options_0 = @intltool__v_merge_options_0@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +nmbinary = @nmbinary@ +nmconfdir = @nmconfdir@ +nmdatadir = @nmdatadir@ +nmrundir = @nmrundir@ +nmstatedir = @nmstatedir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sysconfdir = @sysconfdir@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +with_dhclient = @with_dhclient@ +with_dhcpcd = @with_dhcpcd@ +with_netconfig = @with_netconfig@ +with_resolvconf = @with_resolvconf@ +with_valgrind = @with_valgrind@ +@ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ +@ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ +@ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/ \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/platform \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ +@ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ +@ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-ibft"\" \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ +@ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ +@ENABLE_TESTS_TRUE@ -DTEST_IBFT_DIR=\"$(abs_srcdir)\" \ +@ENABLE_TESTS_TRUE@ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" + +@ENABLE_TESTS_TRUE@AM_LDFLAGS = \ +@ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \ +@ENABLE_TESTS_TRUE@ $(DBUS_LIBS) \ +@ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) + +@ENABLE_TESTS_TRUE@test_ibft_SOURCES = \ +@ENABLE_TESTS_TRUE@ test-ibft.c \ +@ENABLE_TESTS_TRUE@ ../reader.c + +@ENABLE_TESTS_TRUE@test_ibft_LDADD = \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la + +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 + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/settings/plugins/ibft/tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/settings/plugins/ibft/tests/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +test-ibft$(EXEEXT): $(test_ibft_OBJECTS) $(test_ibft_DEPENDENCIES) $(EXTRA_test_ibft_DEPENDENCIES) + @rm -f test-ibft$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(test_ibft_OBJECTS) $(test_ibft_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-ibft.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +reader.o: ../reader.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT reader.o -MD -MP -MF $(DEPDIR)/reader.Tpo -c -o reader.o `test -f '../reader.c' || echo '$(srcdir)/'`../reader.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/reader.Tpo $(DEPDIR)/reader.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../reader.c' object='reader.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o reader.o `test -f '../reader.c' || echo '$(srcdir)/'`../reader.c + +reader.obj: ../reader.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT reader.obj -MD -MP -MF $(DEPDIR)/reader.Tpo -c -o reader.obj `if test -f '../reader.c'; then $(CYGPATH_W) '../reader.c'; else $(CYGPATH_W) '$(srcdir)/../reader.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/reader.Tpo $(DEPDIR)/reader.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../reader.c' object='reader.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o reader.obj `if test -f '../reader.c'; then $(CYGPATH_W) '../reader.c'; else $(CYGPATH_W) '$(srcdir)/../reader.c'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + fi; \ + echo "$${col}$$dashes$${std}"; \ + echo "$${col}$$banner$${std}"; \ + test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ + test -z "$$report" || echo "$${col}$$report$${std}"; \ + echo "$${col}$$dashes$${std}"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \ + clean-generic clean-libtool clean-noinstPROGRAMS cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + + +@ENABLE_TESTS_TRUE@@GNOME_CODE_COVERAGE_RULES@ + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1 b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 index 4a6a9382..54f02da6 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns1 +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns1 @@ -10,7 +10,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth0 node.name = iqn.0.2008-11.com.blahblah:iscsi0 node.conn[0].address = 10.16.52.16 diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2 b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 index 9bd5839b..ebd7a9ca 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-dns2 +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-dns2 @@ -10,7 +10,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth0 node.name = iqn.0.2008-11.com.blahblah:iscsi0 node.conn[0].address = 10.16.52.16 diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry index eba0ec67..4e326048 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-entry +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-entry @@ -10,26 +10,11 @@ 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.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 = 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/ibft/tests/iscsiadm-test-bad-gateway index b3dc7447..5390a6c3 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-gateway +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-gateway @@ -5,12 +5,12 @@ cat << EOF iface.initiatorname = iqn.pjones6 iface.hwaddress = 00:33:21:98:b9:f0 iface.bootproto = STATIC -iface.ipaddress = aa.bb.cc.dd +iface.ipaddress = 192.168.32.72 iface.subnet_mask = 255.255.252.0 -iface.gateway = 192.168.35.254 +iface.gateway = bb.cc.dd.ee iface.primary_dns = 10.16.255.2 iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 +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 diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr index 92f44777..b41cd1f1 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-ipaddr +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-ipaddr @@ -5,12 +5,12 @@ cat << EOF iface.initiatorname = iqn.pjones6 iface.hwaddress = 00:33:21:98:b9:f0 iface.bootproto = STATIC -iface.ipaddress = 192.168.32.72 +iface.ipaddress = aa.bb.cc.dd iface.subnet_mask = 255.255.252.0 -iface.gateway = bb.cc.dd.ee +iface.gateway = 192.168.35.254 iface.primary_dns = 10.16.255.2 iface.secondary_dns = 10.16.255.3 -iface.vlan = 0 +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 diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record index a2d215fe..22b34e6f 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-bad-record +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-bad-record @@ -8,7 +8,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth0 node.name = iqn.0.2008-11.com.blahblah:iscsi0 node.conn[0].address = 10.16.52.16 diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp b/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp index 6de0637c..556b0586 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-dhcp +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-dhcp @@ -8,7 +8,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth0 node.name = iqn.0.2008-11.com.blahblah:iscsi0 node.conn[0].address = 10.16.52.16 @@ -22,7 +22,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth1 node.name = iqn.1.2008-11.com.blahblah:iscsi1 node.conn[0].address = 10.16.52.16 diff --git a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-static b/src/settings/plugins/ibft/tests/iscsiadm-test-static index 99a6e7c1..51711480 100755 --- a/src/settings/plugins/ifcfg-rh/tests/iscsiadm-test-static +++ b/src/settings/plugins/ibft/tests/iscsiadm-test-static @@ -10,7 +10,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth0 node.name = iqn.0.2008-11.com.blahblah:iscsi0 node.conn[0].address = 10.16.52.16 @@ -24,7 +24,7 @@ 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.vlan_id = 0 iface.net_ifacename = eth1 node.name = iqn.1.2008-11.com.blahblah:iscsi1 node.conn[0].address = 10.16.52.16 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 00000000..59b80bd0 --- /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 00000000..2ff249af --- /dev/null +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -0,0 +1,292 @@ +/* -*- 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 "config.h" + +#include <stdio.h> +#include <stdarg.h> +#include <unistd.h> +#include <string.h> +#include <netinet/ether.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/socket.h> + +#include "nm-core-internal.h" +#include "NetworkManagerUtils.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; + NMSettingIPConfig *s_ip4; + GError *error = NULL; + const char *mac_address; + 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); + mac_address = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac_address); + g_assert (nm_utils_hwaddr_matches (mac_address, -1, expected_mac_address, -1)); + 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_ip_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; + NMSettingIPConfig *s_ip4; + GError *error = NULL; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIPAddress *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); + mac_address = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac_address); + g_assert (nm_utils_hwaddr_matches (mac_address, -1, expected_mac_address, -1)); + 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_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "10.16.255.2"); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "10.16.255.3"); + + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.32.72"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 22); + + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + 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; + NMSettingIPConfig *s_ip4; + const char *mac_address; + const char *expected_mac_address = "00:33:21:98:b9:f0"; + NMIPAddress *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); + mac_address = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac_address); + g_assert (nm_utils_hwaddr_matches (mac_address, -1, expected_mac_address, -1)); + + /* ===== 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); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 0); + + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.6.200"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); + + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, NULL); + + 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 (); +} + diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index c5e458af..4989f4ba 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -19,27 +19,21 @@ libifcfg_rh_io_la_SOURCES = \ reader.h \ writer.c \ writer.h \ - errors.c \ common.h \ utils.c \ utils.h AM_CPPFLAGS = \ -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/src/posix-signals \ - -I$(top_srcdir)/src/config \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(NSS_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ @@ -52,11 +46,7 @@ libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ nm-ifcfg-connection.h libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_rh_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - libifcfg-rh-io.la \ - $(GLIB_LIBS) +libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = nm-ifcfg-rh.conf diff --git a/src/settings/plugins/ifcfg-rh/Makefile.in b/src/settings/plugins/ifcfg-rh/Makefile.in index 7b1a7dda..5d396273 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.in +++ b/src/settings/plugins/ifcfg-rh/Makefile.in @@ -133,18 +133,13 @@ am__installdirs = "$(DESTDIR)$(pkglibdir)" \ "$(DESTDIR)$(dbusservicedir)" LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES) libifcfg_rh_io_la_LIBADD = -am_libifcfg_rh_io_la_OBJECTS = shvar.lo reader.lo writer.lo errors.lo \ - utils.lo +am_libifcfg_rh_io_la_OBJECTS = shvar.lo reader.lo writer.lo utils.lo libifcfg_rh_io_la_OBJECTS = $(am_libifcfg_rh_io_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -am__DEPENDENCIES_1 = -libnm_settings_plugin_ifcfg_rh_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la libifcfg-rh-io.la \ - $(am__DEPENDENCIES_1) +libnm_settings_plugin_ifcfg_rh_la_DEPENDENCIES = libifcfg-rh-io.la am_libnm_settings_plugin_ifcfg_rh_la_OBJECTS = plugin.lo \ nm-ifcfg-connection.lo libnm_settings_plugin_ifcfg_rh_la_OBJECTS = \ @@ -268,6 +263,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -391,6 +388,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -410,6 +408,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -436,7 +435,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -528,27 +527,21 @@ libifcfg_rh_io_la_SOURCES = \ reader.h \ writer.c \ writer.h \ - errors.c \ common.h \ utils.c \ utils.h AM_CPPFLAGS = \ -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/src/posix-signals \ - -I$(top_srcdir)/src/config \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(NSS_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ @@ -561,12 +554,7 @@ libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ nm-ifcfg-connection.h libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_rh_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - libifcfg-rh-io.la \ - $(GLIB_LIBS) - +libnm_settings_plugin_ifcfg_rh_la_LIBADD = libifcfg-rh-io.la dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = nm-ifcfg-rh.conf EXTRA_DIST = \ @@ -668,7 +656,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-ifcfg-connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Plo@am__quote@ diff --git a/src/settings/plugins/ifcfg-rh/common.h b/src/settings/plugins/ifcfg-rh/common.h index d9627bdd..d78f3752 100644 --- a/src/settings/plugins/ifcfg-rh/common.h +++ b/src/settings/plugins/ifcfg-rh/common.h @@ -78,9 +78,5 @@ #define KEY_DCB_PG_STRICT "DCB_PG_STRICT" #define KEY_DCB_PG_UP2TC "DCB_PG_UP2TC" -#define IFCFG_PLUGIN_ERROR (ifcfg_plugin_error_quark ()) -GQuark ifcfg_plugin_error_quark (void); - - #endif /* __COMMON_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/errors.c b/src/settings/plugins/ifcfg-rh/errors.c deleted file mode 100644 index 25039104..00000000 --- a/src/settings/plugins/ifcfg-rh/errors.c +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- 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. - * - * (C) Copyright 2008 - 2009 Red Hat, Inc. - */ - -#include <glib.h> -#include "common.h" - -GQuark -ifcfg_plugin_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("ifcfg-plugin-error-quark"); - - return error_quark; -} - - diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index 3db06f17..7596cbd5 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -18,13 +18,13 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ +#include "config.h" + #include <string.h> -#include <net/ethernet.h> -#include <netinet/ether.h> #include <glib/gstdio.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-setting-connection.h> #include <nm-setting-wired.h> #include <nm-setting-wireless.h> @@ -119,7 +119,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, @@ -145,20 +145,16 @@ nm_ifcfg_connection_new (NMConnection *source, NM_IFCFG_CONNECTION_UNMANAGED_SPEC, unmanaged_spec, NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, unrecognized_spec, NULL); - if (object) { - /* Update our settings with what was read from the file */ - if (nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), - tmp, - update_unsaved, - error)) { - /* Set the path and start monitoring */ - if (full_path) - nm_ifcfg_connection_set_path (NM_IFCFG_CONNECTION (object), full_path); - } else { - g_object_unref (object); - object = NULL; - } - } + /* Update our settings with what was read from the file */ + if (nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), + tmp, + update_unsaved, + error)) { + /* Set the path and start monitoring */ + if (full_path) + nm_ifcfg_connection_set_path (NM_IFCFG_CONNECTION (object), full_path); + } else + g_clear_object (&object); g_object_unref (tmp); g_free (unhandled_spec); @@ -271,7 +267,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); @@ -345,17 +341,6 @@ nm_ifcfg_connection_init (NMIfcfgConnection *connection) } static void -finalize (GObject *object) -{ - nm_connection_clear_secrets (NM_CONNECTION (object)); - - path_watch_stop (NM_IFCFG_CONNECTION (object)); - g_free (NM_IFCFG_CONNECTION_GET_PRIVATE (object)->path); - - G_OBJECT_CLASS (nm_ifcfg_connection_parent_class)->finalize (object); -} - -static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { @@ -394,6 +379,22 @@ get_property (GObject *object, guint prop_id, } static void +dispose (GObject *object) +{ + path_watch_stop (NM_IFCFG_CONNECTION (object)); + + G_OBJECT_CLASS (nm_ifcfg_connection_parent_class)->dispose (object); +} + +static void +finalize (GObject *object) +{ + g_free (NM_IFCFG_CONNECTION_GET_PRIVATE (object)->path); + + G_OBJECT_CLASS (nm_ifcfg_connection_parent_class)->finalize (object); +} + +static void nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class) { GObjectClass *object_class = G_OBJECT_CLASS (ifcfg_connection_class); @@ -404,6 +405,7 @@ nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class) /* Virtual methods */ object_class->set_property = set_property; object_class->get_property = get_property; + object_class->dispose = dispose; object_class->finalize = finalize; settings_class->delete = do_delete; settings_class->commit_changes = commit_changes; @@ -411,18 +413,16 @@ nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class) /* Properties */ g_object_class_install_property (object_class, PROP_UNMANAGED_SPEC, - g_param_spec_string (NM_IFCFG_CONNECTION_UNMANAGED_SPEC, - "Unmanaged spec", - "Unmanaged spec", - NULL, - G_PARAM_READWRITE)); + g_param_spec_string (NM_IFCFG_CONNECTION_UNMANAGED_SPEC, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_UNRECOGNIZED_SPEC, - g_param_spec_string (NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, - "Unrecognized spec", - "Unrecognized spec", + g_param_spec_string (NM_IFCFG_CONNECTION_UNRECOGNIZED_SPEC, "", "", NULL, - G_PARAM_READWRITE)); + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); signals[IFCFG_CHANGED] = g_signal_new ("ifcfg-changed", diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h index 47422b5d..37eacaf0 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.h @@ -18,12 +18,12 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ -#ifndef NM_IFCFG_CONNECTION_H -#define NM_IFCFG_CONNECTION_H +#ifndef __NETWORKMANAGER_IFCFG_CONNECTION_H__ +#define __NETWORKMANAGER_IFCFG_CONNECTION_H__ G_BEGIN_DECLS -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-settings-connection.h> #define NM_TYPE_IFCFG_CONNECTION (nm_ifcfg_connection_get_type ()) @@ -65,4 +65,4 @@ gboolean nm_ifcfg_connection_update (NMIfcfgConnection *self, G_END_DECLS -#endif /* NM_IFCFG_CONNECTION_H */ +#endif /* __NETWORKMANAGER_IFCFG_CONNECTION_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index 8a3f328c..2dced56b 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -21,12 +21,11 @@ * Copyright (C) 2007 - 2011 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <string.h> #include <unistd.h> #include <errno.h> -#include <net/ethernet.h> -#include <netinet/ether.h> #include <sys/types.h> #include <sys/stat.h> @@ -49,9 +48,9 @@ #include "nm-dbus-glib-types.h" #include "plugin.h" #include "nm-system-config-interface.h" -#include "nm-settings-error.h" #include "nm-config.h" #include "nm-logging.h" +#include "NetworkManagerUtils.h" #include "nm-ifcfg-connection.h" #include "nm-inotify-helper.h" @@ -143,7 +142,8 @@ _internal_new_connection (SCPluginIfcfg *self, if (local) g_propagate_error (error, local); else - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "(unknown)"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "(unknown)"); return NULL; } @@ -648,10 +648,10 @@ plugin_get_hostname (SCPluginIfcfg *plugin) hostname = svGetValue (network, "HOSTNAME", FALSE); ignore_localhost = svTrueValue (network, "NM_IGNORE_HOSTNAME_LOCALHOST", FALSE); if (ignore_localhost) { - /* Ignore a hostname of 'localhost' or 'localhost.localdomain' to preserve - * 'network' service behavior. + /* Ignore a default hostname ('localhost[6]' or 'localhost[6].localdomain[6]') + * to preserve 'network' service behavior. */ - if (hostname && (!strcmp (hostname, "localhost") || !strcmp (hostname, "localhost.localdomain"))) { + if (hostname && !nm_utils_is_specific_hostname (hostname)) { g_free (hostname); hostname = NULL; } @@ -669,12 +669,14 @@ plugin_set_hostname (SCPluginIfcfg *plugin, const char *hostname) char *hostname_eol; gboolean ret; #if HAVE_SELINUX - security_context_t se_ctx_prev, se_ctx = NULL; + security_context_t se_ctx_prev = NULL, se_ctx = NULL; struct stat file_stat = { .st_mode = 0 }; + mode_t st_mode = 0; /* Get default context for HOSTNAME_FILE and set it for fscreate */ - stat (HOSTNAME_FILE, &file_stat); - matchpathcon (HOSTNAME_FILE, file_stat.st_mode, &se_ctx); + if (stat (HOSTNAME_FILE, &file_stat) == 0) + st_mode = file_stat.st_mode; + matchpathcon (HOSTNAME_FILE, st_mode, &se_ctx); matchpathcon_fini (); getfscreatecon (&se_ctx_prev); setfscreatecon (se_ctx); @@ -790,7 +792,7 @@ impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, if (!s_con) { g_set_error (error, NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INTERNAL_ERROR, + NM_SETTINGS_ERROR_FAILED, "unable to retrieve the connection setting"); return FALSE; } @@ -799,7 +801,7 @@ impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, if (!uuid) { g_set_error (error, NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INTERNAL_ERROR, + NM_SETTINGS_ERROR_FAILED, "unable to get the UUID"); return FALSE; } @@ -808,7 +810,7 @@ impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, if (!path) { g_set_error (error, NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INTERNAL_ERROR, + NM_SETTINGS_ERROR_FAILED, "unable to get the connection D-Bus path"); return FALSE; } diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 7a616707..145a0a39 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -15,10 +15,11 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2008 - 2013 Red Hat, Inc. + * Copyright 2008 - 2014 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <stdlib.h> #include <string.h> #include <sys/types.h> @@ -29,13 +30,11 @@ #include <errno.h> #include <sys/ioctl.h> #include <unistd.h> -#include <netinet/ether.h> -#include <linux/if.h> #include <glib.h> #include <glib/gi18n.h> #include <nm-connection.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-setting-connection.h> #include <nm-setting-ip4-config.h> #include <nm-setting-vlan.h> @@ -50,7 +49,7 @@ #include <nm-setting-bridge-port.h> #include <nm-setting-dcb.h> #include <nm-setting-generic.h> -#include <nm-utils-private.h> +#include "nm-core-internal.h" #include <nm-utils.h> #include "nm-platform.h" @@ -149,7 +148,7 @@ make_connection_setting (const char *file, uuid = svGetValue (ifcfg, "UUID", FALSE); if (!uuid || !strlen (uuid)) { g_free (uuid); - uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName); + uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } g_object_set (s_con, @@ -170,8 +169,14 @@ make_connection_setting (const char *file, } /* Missing ONBOOT is treated as "ONBOOT=true" by the old network service */ - g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT, + g_object_set (s_con, + NM_SETTING_CONNECTION_AUTOCONNECT, svTrueValue (ifcfg, "ONBOOT", TRUE), + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, + (gint) svGetValueInt64 (ifcfg, "AUTOCONNECT_PRIORITY", 10, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT), NULL); value = svGetValue (ifcfg, "USERS", FALSE); @@ -246,292 +251,14 @@ make_connection_setting (const char *file, return NM_SETTING (s_con); } -static gboolean -read_mac_address (shvarFile *ifcfg, const char *key, int type, - GByteArray **array, GError **error) -{ - char *value = NULL; - - g_return_val_if_fail (ifcfg != NULL, FALSE); - g_return_val_if_fail (array != NULL, FALSE); - g_return_val_if_fail (*array == NULL, FALSE); - if (error) - g_return_val_if_fail (*error == NULL, FALSE); - - value = svGetValue (ifcfg, key, FALSE); - if (!value || !strlen (value)) { - g_free (value); - return TRUE; - } - - *array = nm_utils_hwaddr_atoba (value, type); - if (!*array) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "%s: the MAC address '%s' was invalid.", key, value); - g_free (value); - return FALSE; - } - - g_free (value); - 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", ARPHRD_ETHER, &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))) { - struct ether_addr *ibft_mac; - - ibft_mac = ether_aton (p); - if (!ibft_mac) { - PARSE_WARNING ("malformed iscsiadm record: invalid hwaddress."); - skip = TRUE; - continue; - } - - if (memcmp (ifcfg_mac->data, (guint8 *) ibft_mac->ether_addr_octet, ETH_ALEN)) { - /* 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, const char *tag, - guint32 *out_addr, + char **out_addr, GError **error) { char *value = NULL; - guint32 ip4_addr; - gboolean success = FALSE; g_return_val_if_fail (ifcfg != NULL, FALSE); g_return_val_if_fail (tag != NULL, FALSE); @@ -539,45 +266,21 @@ read_ip4_address (shvarFile *ifcfg, if (error) g_return_val_if_fail (*error == NULL, FALSE); - *out_addr = 0; + *out_addr = NULL; value = svGetValue (ifcfg, tag, FALSE); if (!value) return TRUE; - if (inet_pton (AF_INET, value, &ip4_addr) > 0) { - *out_addr = ip4_addr; - success = TRUE; + if (nm_utils_ipaddr_valid (AF_INET, value)) { + *out_addr = value; + return TRUE; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid %s IP4 address '%s'", tag, value); - } - g_free (value); - return success; -} - -/* Returns TRUE on valid address, including unspecified (::) */ -static gboolean -parse_ip6_address (const char *value, - struct in6_addr *out_addr, - GError **error) -{ - struct in6_addr ip6_addr; - - g_return_val_if_fail (value != NULL, FALSE); - g_return_val_if_fail (out_addr != NULL, FALSE); - if (error) - g_return_val_if_fail (*error == NULL, FALSE); - - *out_addr = in6addr_any; - if (inet_pton (AF_INET6, value, &ip6_addr) <= 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP6 address '%s'", value); + g_free (value); return FALSE; } - - *out_addr = ip6_addr; - return TRUE; } static char * @@ -629,19 +332,23 @@ static gboolean read_full_ip4_address (shvarFile *ifcfg, const char *network_file, gint32 which, - NMIP4Address *addr, + NMIPAddress *base_addr, + NMIPAddress **out_address, + char **out_gateway, GError **error) { char *ip_tag, *prefix_tag, *netmask_tag, *gw_tag; - guint32 tmp; + char *ip = NULL; + long prefix = 0; gboolean success = FALSE; - shvarFile *network_ifcfg; char *value; + guint32 tmp; g_return_val_if_fail (which >= -1, FALSE); g_return_val_if_fail (ifcfg != NULL, FALSE); g_return_val_if_fail (network_file != NULL, FALSE); - g_return_val_if_fail (addr != NULL, FALSE); + g_return_val_if_fail (out_address != NULL, FALSE); + g_return_val_if_fail (*out_address == NULL, FALSE); if (error) g_return_val_if_fail (*error == NULL, FALSE); @@ -651,82 +358,73 @@ read_full_ip4_address (shvarFile *ifcfg, gw_tag = get_numbered_tag ("GATEWAY", which); /* IP address */ - if (!read_ip4_address (ifcfg, ip_tag, &tmp, error)) - goto done; - if (tmp) - nm_ip4_address_set_address (addr, tmp); - else if (!nm_ip4_address_get_address (addr)) { - success = TRUE; + if (!read_ip4_address (ifcfg, ip_tag, &ip, error)) goto done; + if (!ip) { + if (base_addr) + ip = g_strdup (nm_ip_address_get_address (base_addr)); + else { + success = TRUE; + goto done; + } } /* Gateway */ - if (!read_ip4_address (ifcfg, gw_tag, &tmp, error)) - goto done; - if (tmp) - nm_ip4_address_set_gateway (addr, tmp); - else { - gboolean read_success; - - /* If no gateway in the ifcfg, try /etc/sysconfig/network instead */ - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - read_success = read_ip4_address (network_ifcfg, "GATEWAY", &tmp, error); - svCloseFile (network_ifcfg); - if (!read_success) - goto done; - nm_ip4_address_set_gateway (addr, tmp); - } + if (out_gateway && !*out_gateway) { + if (!read_ip4_address (ifcfg, gw_tag, out_gateway, error)) + goto done; } /* Prefix */ value = svGetValue (ifcfg, prefix_tag, FALSE); if (value) { - long int prefix; - errno = 0; prefix = strtol (value, NULL, 10); - if (errno || prefix <= 0 || prefix > 32) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + if (errno || prefix < 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 prefix '%s'", value); g_free (value); goto done; } - nm_ip4_address_set_prefix (addr, (guint32) prefix); g_free (value); } /* Fall back to NETMASK if no PREFIX was specified */ - if (!nm_ip4_address_get_prefix (addr)) { - if (!read_ip4_address (ifcfg, netmask_tag, &tmp, error)) + if (prefix == 0) { + if (!read_ip4_address (ifcfg, netmask_tag, &value, error)) goto done; - if (tmp) - nm_ip4_address_set_prefix (addr, nm_utils_ip4_netmask_to_prefix (tmp)); + if (value) { + inet_pton (AF_INET, value, &tmp); + prefix = nm_utils_ip4_netmask_to_prefix (tmp); + g_free (value); + } } - /* Try to autodetermine the prefix for the address' class */ - if (!nm_ip4_address_get_prefix (addr)) { - guint32 prefix = 0; + if (prefix == 0 && base_addr) + prefix = nm_ip_address_get_prefix (base_addr); - prefix = nm_utils_ip4_get_default_prefix (nm_ip4_address_get_address (addr)); - nm_ip4_address_set_prefix (addr, prefix); + /* Try to autodetermine the prefix for the address' class */ + if (prefix == 0) { + if (inet_pton (AF_INET, ip, &tmp) == 1) { + prefix = nm_utils_ip4_get_default_prefix (tmp); - value = svGetValue (ifcfg, ip_tag, FALSE); - PARSE_WARNING ("missing %s, assuming %s/%u", prefix_tag, value, prefix); - g_free (value); + PARSE_WARNING ("missing %s, assuming %s/%ld", prefix_tag, ip, prefix); + } } /* Validate the prefix */ - if (nm_ip4_address_get_prefix (addr) > 32) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Missing or invalid IP4 prefix '%d'", - nm_ip4_address_get_prefix (addr)); + if (prefix == 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP4 prefix"); goto done; } - success = TRUE; + *out_address = nm_ip_address_new (AF_INET, ip, prefix, error); + if (*out_address) + success = TRUE; done: + g_free (ip); g_free (ip_tag); g_free (prefix_tag); g_free (netmask_tag); @@ -740,12 +438,12 @@ static gboolean read_one_ip4_route (shvarFile *ifcfg, const char *network_file, guint32 which, - NMIP4Route **out_route, + NMIPRoute **out_route, GError **error) { - NMIP4Route *route; char *ip_tag, *netmask_tag, *gw_tag, *metric_tag, *value; - guint32 tmp; + char *dest = NULL, *next_hop = NULL; + gint64 prefix, metric; gboolean success = FALSE; g_return_val_if_fail (ifcfg != NULL, FALSE); @@ -755,75 +453,72 @@ read_one_ip4_route (shvarFile *ifcfg, if (error) g_return_val_if_fail (*error == NULL, FALSE); - route = nm_ip4_route_new (); - ip_tag = g_strdup_printf ("ADDRESS%u", which); netmask_tag = g_strdup_printf ("NETMASK%u", which); gw_tag = g_strdup_printf ("GATEWAY%u", which); metric_tag = g_strdup_printf ("METRIC%u", which); /* Destination */ - if (!read_ip4_address (ifcfg, ip_tag, &tmp, error)) + if (!read_ip4_address (ifcfg, ip_tag, &dest, error)) goto out; - if (!tmp) { + if (!dest) { /* Check whether IP is missing or 0.0.0.0 */ char *val; val = svGetValue (ifcfg, ip_tag, FALSE); if (!val) { - nm_ip4_route_unref (route); - route = NULL; + *out_route = NULL; success = TRUE; /* missing route = success */ goto out; } g_free (val); } - nm_ip4_route_set_dest (route, tmp); /* Next hop */ - if (!read_ip4_address (ifcfg, gw_tag, &tmp, error)) + if (!read_ip4_address (ifcfg, gw_tag, &next_hop, error)) goto out; - /* No need to check tmp, because we don't make distinction between missing GATEWAY IP and 0.0.0.0 */ - nm_ip4_route_set_next_hop (route, tmp); + /* We don't make distinction between missing GATEWAY IP and 0.0.0.0 */ /* Prefix */ - if (!read_ip4_address (ifcfg, netmask_tag, &tmp, error)) + if (!read_ip4_address (ifcfg, netmask_tag, &value, error)) goto out; - if (tmp) - nm_ip4_route_set_prefix (route, nm_utils_ip4_netmask_to_prefix (tmp)); + if (value) { + guint32 netmask; - /* Validate the prefix */ - if ( !nm_ip4_route_get_prefix (route) - || nm_ip4_route_get_prefix (route) > 32) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Missing or invalid IP4 prefix '%d'", - nm_ip4_route_get_prefix (route)); + inet_pton (AF_INET, value, &netmask); + prefix = nm_utils_ip4_netmask_to_prefix (netmask); + g_free (value); + if (prefix == 0 || netmask != nm_utils_ip4_prefix_to_netmask (prefix)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 netmask '%s' \"%s\"", netmask_tag, nm_utils_inet4_ntop (netmask, NULL)); + goto out; + } + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP4 route element '%s'", netmask_tag); goto out; } /* Metric */ value = svGetValue (ifcfg, metric_tag, FALSE); if (value) { - long int metric; - - errno = 0; - metric = strtol (value, NULL, 10); - if (errno || metric < 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + metric = nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1); + if (metric < 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 route metric '%s'", value); g_free (value); goto out; } - nm_ip4_route_set_metric (route, (guint32) metric); g_free (value); - } + } else + metric = -1; - *out_route = route; - success = TRUE; + *out_route = nm_ip_route_new (AF_INET, dest, prefix, next_hop, metric, error); + if (*out_route) + success = TRUE; out: - if (!success && route) - nm_ip4_route_unref (route); - + g_free (dest); + g_free (next_hop); g_free (ip_tag); g_free (netmask_tag); g_free (gw_tag); @@ -832,17 +527,16 @@ out: } static gboolean -read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError **error) +read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error) { char *contents = NULL; gsize len = 0; char **lines = NULL, **iter; GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; GMatchInfo *match_info; - NMIP4Route *route; - guint32 ip4_addr; - char *dest = NULL, *prefix = NULL, *metric = NULL; - long int prefix_int, metric_int; + NMIPRoute *route = NULL; + char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; + gint64 prefix_int, metric_int; gboolean success = FALSE; const char *pattern_empty = "^\\s*(\\#.*)?$"; @@ -870,9 +564,6 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError regex_via = g_regex_new (pattern_via, 0, 0, NULL); regex_metric = g_regex_new (pattern_metric, 0, 0, NULL); - /* New NMIP4Route structure */ - route = nm_ip4_route_new (); - /* Iterate through file lines */ lines = g_strsplit_set (contents, "\n\r", -1); for (iter = lines; iter && *iter; iter++) { @@ -888,22 +579,21 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError g_regex_match (regex_to2, *iter, 0, &match_info); if (!g_match_info_matches (match_info)) { g_match_info_free (match_info); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Missing IP4 route destination address in record: '%s'", *iter); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP4 route destination address in record: '%s'", *iter); goto error; } } dest = g_match_info_fetch (match_info, 1); if (!strcmp (dest, "default")) strcpy (dest, "0.0.0.0"); - if (inet_pton (AF_INET, dest, &ip4_addr) != 1) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP4 route destination address '%s'", dest); + if (!nm_utils_ipaddr_valid (AF_INET, dest)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route destination address '%s'", dest); g_free (dest); + g_match_info_free (match_info); goto error; } - nm_ip4_route_set_dest (route, ip4_addr); - g_free (dest); /* Prefix - is optional; 32 if missing */ prefix = g_match_info_fetch (match_info, 2); @@ -913,58 +603,62 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError errno = 0; prefix_int = strtol (prefix, NULL, 10); if (errno || prefix_int <= 0 || prefix_int > 32) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP4 route destination prefix '%s'", prefix); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP4 route destination prefix '%s'", prefix); + g_free (dest); g_free (prefix); goto error; } } - nm_ip4_route_set_prefix (route, (guint32) prefix_int); g_free (prefix); /* Next hop */ g_regex_match (regex_via, *iter, 0, &match_info); if (g_match_info_matches (match_info)) { - char *next_hop = g_match_info_fetch (match_info, 1); - if (inet_pton (AF_INET, next_hop, &ip4_addr) != 1) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + next_hop = g_match_info_fetch (match_info, 1); + if (!nm_utils_ipaddr_valid (AF_INET, next_hop)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 route gateway address '%s'", next_hop); g_match_info_free (match_info); + g_free (dest); g_free (next_hop); goto error; } - g_free (next_hop); } else { /* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */ - ip4_addr = 0; + next_hop = NULL; } - nm_ip4_route_set_next_hop (route, ip4_addr); g_match_info_free (match_info); /* Metric */ g_regex_match (regex_metric, *iter, 0, &match_info); - metric_int = 0; + metric_int = -1; if (g_match_info_matches (match_info)) { metric = g_match_info_fetch (match_info, 1); errno = 0; metric_int = strtol (metric, NULL, 10); if (errno || metric_int < 0) { g_match_info_free (match_info); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 route metric '%s'", metric); + g_free (dest); + g_free (next_hop); g_free (metric); goto error; } g_free (metric); } - - nm_ip4_route_set_metric (route, (guint32) metric_int); g_match_info_free (match_info); - if (!nm_setting_ip4_config_add_route (s_ip4, route)) + route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error); + if (!route) { + g_free (dest); + g_free (next_hop); + goto error; + } + if (!nm_setting_ip_config_add_route (s_ip4, route)) PARSE_WARNING ("duplicate IP4 route"); - } success = TRUE; @@ -972,7 +666,8 @@ read_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError error: g_free (contents); g_strfreev (lines); - nm_ip4_route_unref (route); + if (route) + nm_ip_route_unref (route); g_regex_unref (regex_to1); g_regex_unref (regex_to2); g_regex_unref (regex_via); @@ -986,15 +681,12 @@ parse_full_ip6_address (shvarFile *ifcfg, const char *network_file, const char *addr_str, int i, - NMIP6Address **out_address, + NMIPAddress **out_address, GError **error) { - NMIP6Address *addr = NULL; char **list; char *ip_val, *prefix_val; - shvarFile *network_ifcfg; - char *value = NULL; - struct in6_addr tmp = IN6ADDR_ANY_INIT; + long prefix; gboolean success = FALSE; g_return_val_if_fail (addr_str != NULL, FALSE); @@ -1006,77 +698,33 @@ parse_full_ip6_address (shvarFile *ifcfg, /* Split the address and prefix */ list = g_strsplit_set (addr_str, "/", 2); if (g_strv_length (list) < 1) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 address '%s'", addr_str); goto error; } ip_val = list[0]; - prefix_val = list[1]; - addr = nm_ip6_address_new (); - /* IP address */ - if (!parse_ip6_address (ip_val, &tmp, error)) - goto error; - if (IN6_IS_ADDR_UNSPECIFIED (&tmp)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP6 address '%s'", ip_val); - goto error; - } - nm_ip6_address_set_address (addr, &tmp); - - /* Prefix */ + prefix_val = list[1]; if (prefix_val) { - long int prefix; - errno = 0; prefix = strtol (prefix_val, NULL, 10); if (errno || prefix <= 0 || prefix > 128) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 prefix '%s'", prefix_val); goto error; } - nm_ip6_address_set_prefix (addr, (guint32) prefix); } else { /* Missing prefix is treated as prefix of 64 */ - nm_ip6_address_set_prefix (addr, 64); + prefix = 64; } - /* Gateway */ - tmp = in6addr_any; - value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE); - if (i != 0) { - /* We don't support gateways for IPV6ADDR_SECONDARIES yet */ - g_free (value); - value = NULL; - } - if (!value) { - /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */ - network_ifcfg = svOpenFile (network_file, NULL); - if (network_ifcfg) { - value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); - svCloseFile (network_ifcfg); - } - } - if (value) { - char *ptr; - - if ((ptr = strchr (value, '%')) != NULL) - *ptr = '\0'; /* remove %interface prefix if present */ - if (!parse_ip6_address (value, &tmp, error)) - goto error; - nm_ip6_address_set_gateway (addr, &tmp); - } - - *out_address = addr; - success = TRUE; + *out_address = nm_ip_address_new (AF_INET6, ip_val, prefix, error); + if (*out_address) + success = TRUE; error: - if (!success && addr) - nm_ip6_address_unref (addr); - g_strfreev (list); - g_free (value); return success; } @@ -1088,17 +736,16 @@ error: #define IPV6_ADDR_REGEX "[0-9A-Fa-f:.]+" static gboolean -read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **error) +read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error) { char *contents = NULL; gsize len = 0; char **lines = NULL, **iter; GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; GMatchInfo *match_info; - NMIP6Route *route; - struct in6_addr ip6_addr; - char *dest = NULL, *prefix = NULL, *metric = NULL; - long int prefix_int, metric_int; + NMIPRoute *route = NULL; + char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; + gint64 prefix_int, metric_int; gboolean success = FALSE; const char *pattern_empty = "^\\s*(\\#.*)?$"; @@ -1126,9 +773,6 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro regex_via = g_regex_new (pattern_via, 0, 0, NULL); regex_metric = g_regex_new (pattern_metric, 0, 0, NULL); - /* New NMIP6Route structure */ - route = nm_ip6_route_new (); - /* Iterate through file lines */ lines = g_strsplit_set (contents, "\n\r", -1); for (iter = lines; iter && *iter; iter++) { @@ -1144,27 +788,19 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro g_regex_match (regex_to2, *iter, 0, &match_info); if (!g_match_info_matches (match_info)) { g_match_info_free (match_info); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Missing IP6 route destination address in record: '%s'", *iter); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IP6 route destination address in record: '%s'", *iter); goto error; } } dest = g_match_info_fetch (match_info, 1); if (!g_strcmp0 (dest, "default")) { /* Ignore default route - NM handles it internally */ - g_free (dest); + g_clear_pointer (&dest, g_free); g_match_info_free (match_info); PARSE_WARNING ("ignoring manual default route: '%s' (%s)", *iter, filename); continue; } - if (inet_pton (AF_INET6, dest, &ip6_addr) != 1) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP6 route destination address '%s'", dest); - g_free (dest); - goto error; - } - nm_ip6_route_set_dest (route, &ip6_addr); - g_free (dest); /* Prefix - is optional; 128 if missing */ prefix = g_match_info_fetch (match_info, 2); @@ -1174,56 +810,60 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro errno = 0; prefix_int = strtol (prefix, NULL, 10); if (errno || prefix_int <= 0 || prefix_int > 128) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP6 route destination prefix '%s'", prefix); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 route destination prefix '%s'", prefix); + g_free (dest); g_free (prefix); goto error; } } - nm_ip6_route_set_prefix (route, (guint32) prefix_int); g_free (prefix); /* Next hop */ g_regex_match (regex_via, *iter, 0, &match_info); if (g_match_info_matches (match_info)) { - char *next_hop = g_match_info_fetch (match_info, 1); - if (inet_pton (AF_INET6, next_hop, &ip6_addr) != 1) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + next_hop = g_match_info_fetch (match_info, 1); + if (!nm_utils_ipaddr_valid (AF_INET6, next_hop)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IPv6 route nexthop address '%s'", next_hop); g_match_info_free (match_info); + g_free (dest); g_free (next_hop); goto error; } - g_free (next_hop); } else { /* Missing "via" is taken as :: */ - ip6_addr = in6addr_any; + next_hop = NULL; } - nm_ip6_route_set_next_hop (route, &ip6_addr); g_match_info_free (match_info); /* Metric */ g_regex_match (regex_metric, *iter, 0, &match_info); - metric_int = 0; + metric_int = -1; if (g_match_info_matches (match_info)) { metric = g_match_info_fetch (match_info, 1); errno = 0; metric_int = strtol (metric, NULL, 10); if (errno || metric_int < 0 || metric_int > G_MAXUINT32) { g_match_info_free (match_info); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP6 route metric '%s'", metric); + g_free (dest); + g_free (next_hop); g_free (metric); goto error; } g_free (metric); } - - nm_ip6_route_set_metric (route, (guint32) metric_int); g_match_info_free (match_info); - if (!nm_setting_ip6_config_add_route (s_ip6, route)) + route = nm_ip_route_new (AF_INET6, dest, prefix_int, next_hop, metric_int, error); + g_free (dest); + g_free (next_hop); + if (!route) + goto error; + if (!nm_setting_ip_config_add_route (s_ip6, route)) PARSE_WARNING ("duplicate IP6 route"); } @@ -1232,7 +872,8 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro error: g_free (contents); g_strfreev (lines); - nm_ip6_route_unref (route); + if (route) + nm_ip_route_unref (route); g_regex_unref (regex_to1); g_regex_unref (regex_to2); g_regex_unref (regex_via); @@ -1245,19 +886,19 @@ error: static NMSetting * make_ip4_setting (shvarFile *ifcfg, const char *network_file, - const char *iscsiadm_path, GError **error) { - NMSettingIP4Config *s_ip4 = NULL; + NMSettingIPConfig *s_ip4 = NULL; char *value = NULL; char *route_path = NULL; char *method; + char *gateway = NULL; gint32 i; shvarFile *network_ifcfg; shvarFile *route_ifcfg; gboolean never_default = FALSE; - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); /* First check if DEFROUTE is set for this device; DEFROUTE has the * opposite meaning from never-default. The default if DEFROUTE is not @@ -1297,32 +938,22 @@ 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, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, NULL); return NM_SETTING (s_ip4); } else if (!g_ascii_strcasecmp (value, "shared")) { g_free (value); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, NULL); return NM_SETTING (s_ip4); } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown BOOTPROTO '%s'", value); g_free (value); goto done; @@ -1330,11 +961,11 @@ make_ip4_setting (shvarFile *ifcfg, g_free (value); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, method, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "PEERDNS", TRUE), - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "PEERROUTES", TRUE), - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, - NM_SETTING_IP4_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV4_FAILURE_FATAL", FALSE), + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "PEERDNS", TRUE), + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "PEERROUTES", TRUE), + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV4_FAILURE_FATAL", FALSE), NULL); if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) @@ -1344,11 +975,11 @@ make_ip4_setting (shvarFile *ifcfg, if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE); if (value && strlen (value)) - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, value, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, + NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, svTrueValue (ifcfg, "DHCP_SEND_HOSTNAME", TRUE), NULL); @@ -1364,16 +995,12 @@ make_ip4_setting (shvarFile *ifcfg, * the legacy 'network' service (ifup-eth). */ for (i = -1; i < 256; i++) { - NMIP4Address *addr = NULL; + NMIPAddress *addr = NULL; - addr = nm_ip4_address_new (); - if (!read_full_ip4_address (ifcfg, network_file, i, addr, error)) { - nm_ip4_address_unref (addr); + if (!read_full_ip4_address (ifcfg, network_file, i, NULL, &addr, &gateway, error)) goto done; - } - if (!nm_ip4_address_get_address (addr)) { - nm_ip4_address_unref (addr); + if (!addr) { /* The first mandatory variable is 2-indexed (IPADDR2) * Variables IPADDR, IPADDR0 and IPADDR1 are optional */ if (i > 1) @@ -1381,39 +1008,49 @@ make_ip4_setting (shvarFile *ifcfg, continue; } - if (!nm_setting_ip4_config_add_address (s_ip4, addr)) + if (!nm_setting_ip_config_add_address (s_ip4, addr)) PARSE_WARNING ("duplicate IP4 address"); - nm_ip4_address_unref (addr); + nm_ip_address_unref (addr); } + /* Gateway */ + if (!gateway) { + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + gboolean read_success; + + read_success = read_ip4_address (network_ifcfg, "GATEWAY", &gateway, error); + svCloseFile (network_ifcfg); + if (!read_success) + goto done; + } + } + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); + /* DNS servers * Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting()) */ for (i = 1; i <= 10; i++) { char *tag; - guint32 dns; - struct in6_addr ip6_dns; tag = g_strdup_printf ("DNS%u", i); - if (!read_ip4_address (ifcfg, tag, &dns, error)) { - gboolean valid = TRUE; - - /* Ignore IPv6 addresses */ - dns = 0; - value = svGetValue (ifcfg, tag, FALSE); - if (value) - valid = parse_ip6_address (value, &ip6_dns, NULL); - g_free (value); - - if (!valid) { + value = svGetValue (ifcfg, tag, FALSE); + if (value) { + if (nm_utils_ipaddr_valid (AF_INET, value)) { + if (!nm_setting_ip_config_add_dns (s_ip4, value)) + PARSE_WARNING ("duplicate DNS server %s", tag); + } else if (nm_utils_ipaddr_valid (AF_INET6, value)) { + /* Ignore IPv6 addresses */ + } else { + PARSE_WARNING ("invalid DNS server address %s", value); g_free (tag); + g_free (value); goto done; } - g_clear_error (error); + + g_free (value); } - if (dns && !nm_setting_ip4_config_add_dns (s_ip4, dns)) - PARSE_WARNING ("duplicate DNS server %s", tag); g_free (tag); } @@ -1427,7 +1064,7 @@ make_ip4_setting (shvarFile *ifcfg, char **item; for (item = searches; *item; item++) { if (strlen (*item)) { - if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item)) + if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) PARSE_WARNING ("duplicate DNS domain '%s'", *item); } } @@ -1439,7 +1076,7 @@ make_ip4_setting (shvarFile *ifcfg, /* Static routes - route-<name> file */ route_path = utils_get_route_path (ifcfg->fileName); if (!route_path) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Could not get route file path for '%s'", ifcfg->fileName); goto done; } @@ -1450,7 +1087,7 @@ make_ip4_setting (shvarFile *ifcfg, route_ifcfg = utils_get_route_ifcfg (ifcfg->fileName, FALSE); if (route_ifcfg) { for (i = 0; i < 256; i++) { - NMIP4Route *route = NULL; + NMIPRoute *route = NULL; if (!read_one_ip4_route (route_ifcfg, network_file, i, &route, error)) { svCloseFile (route_ifcfg); @@ -1460,9 +1097,9 @@ make_ip4_setting (shvarFile *ifcfg, if (!route) break; - if (!nm_setting_ip4_config_add_route (s_ip4, route)) + if (!nm_setting_ip_config_add_route (s_ip4, route)) PARSE_WARNING ("duplicate IP4 route"); - nm_ip4_route_unref (route); + nm_ip_route_unref (route); } svCloseFile (route_ifcfg); } @@ -1472,7 +1109,7 @@ make_ip4_setting (shvarFile *ifcfg, } /* Legacy value NM used for a while but is incorrect (rh #459370) */ - if (!nm_setting_ip4_config_get_num_dns_searches (s_ip4)) { + if (!nm_setting_ip_config_get_num_dns_searches (s_ip4)) { value = svGetValue (ifcfg, "SEARCH", FALSE); if (value) { char **searches = NULL; @@ -1482,7 +1119,7 @@ make_ip4_setting (shvarFile *ifcfg, char **item; for (item = searches; *item; item++) { if (strlen (*item)) { - if (!nm_setting_ip4_config_add_dns_search (s_ip4, *item)) + if (!nm_setting_ip_config_add_dns_search (s_ip4, *item)) PARSE_WARNING ("duplicate DNS search '%s'", *item); } } @@ -1495,27 +1132,29 @@ make_ip4_setting (shvarFile *ifcfg, return NM_SETTING (s_ip4); done: + g_free (gateway); g_free (route_path); g_object_unref (s_ip4); return NULL; } static void -read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *network_file) +read_aliases (NMSettingIPConfig *s_ip4, const char *filename, const char *network_file) { GDir *dir; char *dirname, *base; shvarFile *parsed; - NMIP4Address *base_addr; + NMIPAddress *base_addr; GError *err = NULL; g_return_if_fail (s_ip4 != NULL); g_return_if_fail (filename != NULL); - base_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - if (!base_addr) + if (nm_setting_ip_config_get_num_addresses (s_ip4) == 0) return; + base_addr = nm_setting_ip_config_get_address (s_ip4, 0); + dirname = g_path_get_dirname (filename); g_return_if_fail (dirname != NULL); base = g_path_get_basename (filename); @@ -1524,7 +1163,7 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo dir = g_dir_open (dirname, 0, &err); if (dir) { const char *item; - NMIP4Address *addr; + NMIPAddress *addr; gboolean ok; while ((item = g_dir_read_name (dir))) { @@ -1573,18 +1212,19 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo continue; } - addr = nm_ip4_address_dup (base_addr); - ok = read_full_ip4_address (parsed, network_file, -1, addr, &err); + addr = NULL; + ok = read_full_ip4_address (parsed, network_file, -1, base_addr, &addr, NULL, &err); svCloseFile (parsed); if (ok) { - if (!NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, device))) + nm_ip_address_set_attribute (addr, "label", g_variant_new_string (device)); + if (!nm_setting_ip_config_add_address (s_ip4, addr)) PARSE_WARNING ("duplicate IP4 address in alias file %s", item); } else { PARSE_WARNING ("error reading IP4 address from alias file '%s': %s", full_path, err ? err->message : "no address"); g_clear_error (&err); } - nm_ip4_address_unref (addr); + nm_ip_address_unref (addr); g_free (device); g_free (full_path); @@ -1603,10 +1243,9 @@ 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; + NMSettingIPConfig *s_ip6 = NULL; char *value = NULL; char *str_value; char *route6_path = NULL; @@ -1621,7 +1260,7 @@ make_ip6_setting (shvarFile *ifcfg, char *ip6_privacy_str; NMSettingIP6ConfigPrivacy ip6_privacy_val; - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); /* First check if IPV6_DEFROUTE is set for this device; IPV6_DEFROUTE has the * opposite meaning from never-default. The default if IPV6_DEFROUTE is not @@ -1718,11 +1357,11 @@ make_ip6_setting (shvarFile *ifcfg, g_free (ip6_privacy_str); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, method, - NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "IPV6_PEERDNS", TRUE), - NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "IPV6_PEERROUTES", TRUE), - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, never_default, - NM_SETTING_IP6_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV6_FAILURE_FATAL", FALSE), + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, !svTrueValue (ifcfg, "IPV6_PEERDNS", TRUE), + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, !svTrueValue (ifcfg, "IPV6_PEERROUTES", TRUE), + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_MAY_FAIL, !svTrueValue (ifcfg, "IPV6_FAILURE_FATAL", FALSE), NM_SETTING_IP6_CONFIG_IP6_PRIVACY, ip6_privacy_val, NULL); @@ -1735,7 +1374,7 @@ make_ip6_setting (shvarFile *ifcfg, /* METHOD_AUTO may trigger DHCPv6, so save the hostname to send to DHCP */ value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE); if (value && value[0]) - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME, value, NULL); + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, value, NULL); g_free (value); } @@ -1757,26 +1396,51 @@ make_ip6_setting (shvarFile *ifcfg, list = g_strsplit_set (value, " ", 0); g_free (value); for (iter = list, i = 0; iter && *iter; iter++, i++) { - NMIP6Address *addr = NULL; + NMIPAddress *addr = NULL; if (!parse_full_ip6_address (ifcfg, network_file, *iter, i, &addr, error)) { g_strfreev (list); goto error; } - if (!nm_setting_ip6_config_add_address (s_ip6, addr)) + if (!nm_setting_ip_config_add_address (s_ip6, addr)) PARSE_WARNING ("duplicate IP6 address"); - nm_ip6_address_unref (addr); + nm_ip_address_unref (addr); } g_strfreev (list); + /* Gateway */ + if (nm_setting_ip_config_get_num_addresses (s_ip6)) { + value = svGetValue (ifcfg, "IPV6_DEFAULTGW", FALSE); + if (!value) { + /* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */ + network_ifcfg = svOpenFile (network_file, NULL); + if (network_ifcfg) { + value = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); + svCloseFile (network_ifcfg); + } + } + if (value) { + char *ptr; + if ((ptr = strchr (value, '%')) != NULL) + *ptr = '\0'; /* remove %interface prefix if present */ + if (!nm_utils_ipaddr_valid (AF_INET6, value)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IP6 address '%s'", value); + g_free (value); + goto error; + } + + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, value, NULL); + g_free (value); + } + } + /* DNS servers * Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting()) */ for (i = 1; i <= 10; i++) { char *tag; - struct in6_addr ip6_dns; - guint32 ip4_addr; tag = g_strdup_printf ("DNS%u", i); value = svGetValue (ifcfg, tag, FALSE); @@ -1785,30 +1449,28 @@ make_ip6_setting (shvarFile *ifcfg, break; /* all done */ } - ip6_dns = in6addr_any; - if (parse_ip6_address (value, &ip6_dns, NULL)) { - if (!IN6_IS_ADDR_UNSPECIFIED (&ip6_dns) && !nm_setting_ip6_config_add_dns (s_ip6, &ip6_dns)) + if (nm_utils_ipaddr_valid (AF_INET6, value)) { + if (!nm_setting_ip_config_add_dns (s_ip6, value)) PARSE_WARNING ("duplicate DNS server %s", tag); + } else if (nm_utils_ipaddr_valid (AF_INET, value)) { + /* Ignore IPv4 addresses */ } else { - /* Maybe an IPv4 address? If so ignore it */ - if (inet_pton (AF_INET, value, &ip4_addr) != 1) { - g_free (tag); - g_free (value); - PARSE_WARNING ("duplicate IP6 address"); - goto error; - } + PARSE_WARNING ("invalid DNS server address %s", value); + g_free (tag); + g_free (value); + goto error; } g_free (tag); g_free (value); } - /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIP4Config */ + /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */ /* Read static routes from route6-<interface> file */ route6_path = utils_get_route6_path (ifcfg->fileName); if (!route6_path) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Could not get route6 file path for '%s'", ifcfg->fileName); goto error; } @@ -1929,7 +1591,7 @@ read_dcb_app (shvarFile *ifcfg, if (success) success = (priority >= 0 && priority <= 7); if (!success) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid %s value '%s' (expected 0 - 7)", tmp, val); } @@ -1978,7 +1640,8 @@ read_dcb_bool_array (shvarFile *ifcfg, val = g_strstrip (val); if (strlen (val) != 8) { PARSE_WARNING ("%s value '%s' must be 8 characters long", prop, val); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "boolean array must be 8 characters"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "boolean array must be 8 characters"); goto out; } @@ -1986,7 +1649,8 @@ read_dcb_bool_array (shvarFile *ifcfg, for (i = 0; i < 8; i++) { if (val[i] != '0' && val[i] != '1') { PARSE_WARNING ("invalid %s value '%s': not all 0s and 1s", prop, val); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "invalid boolean digit"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid boolean digit"); goto out; } set_func (s_dcb, i, (val[i] == '1')); @@ -2027,7 +1691,8 @@ read_dcb_uint_array (shvarFile *ifcfg, val = g_strstrip (val); if (strlen (val) != 8) { PARSE_WARNING ("%s value '%s' must be 8 characters long", prop, val); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "uint array must be 8 characters"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "uint array must be 8 characters"); goto out; } @@ -2040,7 +1705,8 @@ read_dcb_uint_array (shvarFile *ifcfg, else { PARSE_WARNING ("invalid %s value '%s': not 0 - 7%s", prop, val, f_allowed ? " or 'f'" : ""); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "invalid uint digit"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid uint digit"); goto out; } } @@ -2081,14 +1747,16 @@ read_dcb_percent_array (shvarFile *ifcfg, split = g_strsplit_set (val, ",", 0); if (!split || (g_strv_length (split) != 8)) { PARSE_WARNING ("invalid %s percentage list value '%s'", prop, val); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "percent array must be 8 elements"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "percent array must be 8 elements"); goto out; } for (iter = split, i = 0; iter && *iter; iter++, i++) { if (!get_int (*iter, &tmp) || tmp < 0 || tmp > 100) { PARSE_WARNING ("invalid %s percentage value '%s'", prop, *iter); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "invalid percent element"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid percent element"); goto out; } set_func (s_dcb, i, (guint) tmp); @@ -2097,7 +1765,8 @@ read_dcb_percent_array (shvarFile *ifcfg, if (sum_pct && (sum != 100)) { PARSE_WARNING ("%s percentages do not equal 100%%", prop); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "invalid percentage sum"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid percentage sum"); goto out; } @@ -2146,7 +1815,8 @@ make_dcb_setting (shvarFile *ifcfg, g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, val, NULL); else { PARSE_WARNING ("invalid FCoE mode '%s'", val); - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "invalid FCoE mode"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid FCoE mode"); g_free (val); g_object_unref (s_dcb); return FALSE; @@ -2297,7 +1967,7 @@ add_one_wep_key (shvarFile *ifcfg, while (*p) { if (!g_ascii_isxdigit (*p)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid hexadecimal WEP key."); goto out; } @@ -2311,7 +1981,7 @@ add_one_wep_key (shvarFile *ifcfg, while (*p) { if (!g_ascii_isprint ((int) (*p))) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid ASCII WEP key."); goto out; } @@ -2333,7 +2003,8 @@ add_one_wep_key (shvarFile *ifcfg, g_free (key); success = TRUE; } else - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "Invalid WEP key length."); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WEP key length."); out: g_free (value); @@ -2418,7 +2089,7 @@ make_wep_setting (shvarFile *ifcfg, default_key_idx--; /* convert to [0...3] */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, default_key_idx, NULL); } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid default WEP key '%s'", value); g_free (value); goto error; @@ -2459,7 +2130,7 @@ make_wep_setting (shvarFile *ifcfg, } else if (!strcmp (lcase, "restricted")) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL); } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WEP authentication algorithm '%s'", lcase); g_free (lcase); @@ -2481,7 +2152,7 @@ make_wep_setting (shvarFile *ifcfg, auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); if (auth_alg && !strcmp (auth_alg, "shared")) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "WEP Shared Key authentication is invalid for " "unencrypted connections."); goto error; @@ -2570,7 +2241,7 @@ fill_wpa_ciphers (shvarFile *ifcfg, static char * parse_wpa_psk (shvarFile *ifcfg, const char *file, - const GByteArray *ssid, + GBytes *ssid, GError **error) { shvarFile *keys_ifcfg; @@ -2609,7 +2280,7 @@ parse_wpa_psk (shvarFile *ifcfg, /* Verify the hex PSK; 64 digits */ while (*p) { if (!g_ascii_isxdigit (*p++)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WPA_PSK (contains non-hexadecimal characters)"); goto out; } @@ -2627,7 +2298,7 @@ parse_wpa_psk (shvarFile *ifcfg, /* Length check */ if (strlen (hashed) < 8 || strlen (hashed) > 63) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WPA_PSK (passphrases must be between " "8 and 63 characters long (inclusive))"); g_free (hashed); @@ -2637,7 +2308,7 @@ parse_wpa_psk (shvarFile *ifcfg, } if (!hashed) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WPA_PSK (doesn't look like a passphrase or hex key)"); goto out; } @@ -2660,7 +2331,7 @@ eap_simple_reader (const char *eap_method, value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); if (!value) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", eap_method); return FALSE; @@ -2680,7 +2351,7 @@ eap_simple_reader (const char *eap_method, } if (!value) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_PASSWORD for EAP method '%s'.", eap_method); return FALSE; @@ -2741,7 +2412,7 @@ eap_tls_reader (const char *eap_method, value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); if (!value) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", eap_method); return FALSE; @@ -2788,7 +2459,7 @@ eap_tls_reader (const char *eap_method, } if (!privkey_password) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", pk_pw_key, eap_method); @@ -2799,7 +2470,7 @@ eap_tls_reader (const char *eap_method, /* The private key itself */ privkey = svGetValue (ifcfg, pk_key, FALSE); if (!privkey) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", pk_key, eap_method); @@ -2836,7 +2507,7 @@ eap_tls_reader (const char *eap_method, || privkey_format == NM_SETTING_802_1X_CK_FORMAT_X509) { client_cert = svGetValue (ifcfg, cli_cert_key, FALSE); if (!client_cert) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", cli_cert_key, eap_method); @@ -2912,7 +2583,7 @@ eap_peap_reader (const char *eap_method, else if (!strcmp (peapver, "1")) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "1", NULL); else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_PEAP_VERSION value '%s'", peapver); goto done; @@ -2928,7 +2599,7 @@ eap_peap_reader (const char *eap_method, inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); if (!inner_auth) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); goto done; } @@ -2948,7 +2619,7 @@ eap_peap_reader (const char *eap_method, if (!eap_tls_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) goto done; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", *iter); goto done; @@ -2961,7 +2632,7 @@ eap_peap_reader (const char *eap_method, } if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "No valid IEEE_8021X_INNER_AUTH_METHODS found."); goto done; } @@ -3015,7 +2686,7 @@ eap_ttls_reader (const char *eap_method, tmp = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); if (!tmp) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); goto done; } @@ -3047,7 +2718,7 @@ eap_ttls_reader (const char *eap_method, goto done; g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, (*iter + STRLEN ("eap-")), NULL); } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", *iter); goto done; @@ -3115,7 +2786,7 @@ eap_fast_reader (const char *eap_method, g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING, pac_prov_str, NULL); if (!pac_file && !(allow_unauth || allow_auth)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "IEEE_8021X_PAC_FILE not provided and EAP-FAST automatic PAC provisioning disabled."); goto done; } @@ -3126,7 +2797,7 @@ eap_fast_reader (const char *eap_method, inner_auth = svGetValue (ifcfg, "IEEE_8021X_INNER_AUTH_METHODS", FALSE); if (!inner_auth) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); goto done; } @@ -3142,7 +2813,7 @@ eap_fast_reader (const char *eap_method, if (!eap_simple_reader (*iter, ifcfg, keys, s_8021x, TRUE, error)) goto done; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", *iter); goto done; @@ -3155,7 +2826,7 @@ eap_fast_reader (const char *eap_method, } if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "No valid IEEE_8021X_INNER_AUTH_METHODS found."); goto done; } @@ -3205,8 +2876,7 @@ read_8021x_list_value (shvarFile *ifcfg, const char *prop_name) { char *value; - char **strv, **iter; - GSList *gslist = NULL; + char **strv; g_return_if_fail (ifcfg != NULL); g_return_if_fail (ifcfg_var_name != NULL); @@ -3217,16 +2887,8 @@ read_8021x_list_value (shvarFile *ifcfg, return; strv = g_strsplit_set (value, " \t", 0); - for (iter = strv; iter && *iter; iter++) { - if (*iter[0] == '\0') - continue; - gslist = g_slist_prepend (gslist, *iter); - } - if (gslist) { - gslist = g_slist_reverse (gslist); - g_object_set (setting, prop_name, gslist, NULL); - g_slist_free (gslist); - } + if (strv && strv[0]) + g_object_set (setting, prop_name, strv, NULL); g_strfreev (strv); g_free (value); } @@ -3245,7 +2907,7 @@ fill_8021x (shvarFile *ifcfg, value = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS", FALSE); if (!value) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_EAP_METHODS for key management '%s'", key_mgmt); return NULL; @@ -3266,7 +2928,7 @@ fill_8021x (shvarFile *ifcfg, char *lower = NULL; lower = g_ascii_strdown (*iter, -1); - while (eap->method && !found) { + while (eap->method) { if (strcmp (eap->method, lower)) goto next; @@ -3287,6 +2949,7 @@ fill_8021x (shvarFile *ifcfg, } nm_setting_802_1x_add_eap_method (s_8021x, lower); found = TRUE; + break; next: eap++; @@ -3298,7 +2961,7 @@ fill_8021x (shvarFile *ifcfg, } if (nm_setting_802_1x_get_num_eap_methods (s_8021x) == 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "No valid EAP methods found in IEEE_8021X_EAP_METHODS."); goto error; } @@ -3334,7 +2997,7 @@ error: static NMSetting * make_wpa_setting (shvarFile *ifcfg, const char *file, - const GByteArray *ssid, + GBytes *ssid, gboolean adhoc, NMSetting8021x **s_8021x, GError **error) @@ -3408,7 +3071,7 @@ make_wpa_setting (shvarFile *ifcfg, } else if (!strcmp (value, "WPA-EAP") || !strcmp (value, "IEEE8021X")) { /* Adhoc mode is mutually exclusive with any 802.1x-based authentication */ if (adhoc) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Ad-Hoc mode cannot be used with KEY_MGMT type '%s'", value); goto error; } @@ -3421,7 +3084,7 @@ make_wpa_setting (shvarFile *ifcfg, g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, lower, NULL); g_free (lower); } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown wireless KEY_MGMT type '%s'", value); goto error; } @@ -3480,7 +3143,7 @@ make_leap_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "IEEE_8021X_IDENTITY", FALSE); if (!value || !strlen (value)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing LEAP identity"); goto error; } @@ -3504,7 +3167,7 @@ error: static NMSetting * make_wireless_security_setting (shvarFile *ifcfg, const char *file, - const GByteArray *ssid, + GBytes *ssid, gboolean adhoc, NMSetting8021x **s_8021x, GError **error) @@ -3534,118 +3197,110 @@ make_wireless_security_setting (shvarFile *ifcfg, return NULL; /* unencrypted */ } +static char ** +transform_hwaddr_blacklist (const char *blacklist) +{ + char **strv, **iter; + int shift = 0; + + strv = _nm_utils_strsplit_set (blacklist, " \t", 0); + for (iter = strv; iter && *iter; iter++) { + if (shift) { + *(iter - shift) = *iter; + *iter = NULL; + } + if (!nm_utils_hwaddr_valid (*(iter - shift), ETH_ALEN)) { + PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *(iter - shift)); + g_free (*(iter - shift)); + *(iter - shift) = NULL; + shift++; + } + } + return strv; +} + static NMSetting * make_wireless_setting (shvarFile *ifcfg, GError **error) { NMSettingWireless *s_wireless; - GByteArray *array = NULL; - GSList *macaddr_blacklist = NULL; - char *value; + char *value = NULL; + gint64 chan = 0; s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); - if (read_mac_address (ifcfg, "HWADDR", ARPHRD_ETHER, &array, error)) { - if (array) { - g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, array, NULL); - g_byte_array_free (array, TRUE); - } - } else { - g_object_unref (s_wireless); - return NULL; + value = svGetValue (ifcfg, "HWADDR", FALSE); + if (value) { + value = g_strstrip (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, value, NULL); + g_free (value); } - array = NULL; - if (read_mac_address (ifcfg, "MACADDR", ARPHRD_ETHER, &array, error)) { - if (array) { - g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, array, NULL); - g_byte_array_free (array, TRUE); - } - } else { - PARSE_WARNING ("%s", (*error)->message); - g_clear_error (error); + value = svGetValue (ifcfg, "MACADDR", FALSE); + if (value) { + value = g_strstrip (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, value, NULL); + g_free (value); } value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); if (value) { - char **list = NULL, **iter; - struct ether_addr addr; + char **strv; - list = g_strsplit_set (value, " \t", 0); - for (iter = list; iter && *iter; iter++) { - if (**iter == '\0') - continue; - if (!ether_aton_r (*iter, &addr)) { - PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *iter); - continue; - } - macaddr_blacklist = g_slist_prepend (macaddr_blacklist, *iter); - } - if (macaddr_blacklist) { - macaddr_blacklist = g_slist_reverse (macaddr_blacklist); - g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, macaddr_blacklist, NULL); - g_slist_free (macaddr_blacklist); - } + strv = transform_hwaddr_blacklist (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, strv, NULL); + g_strfreev (strv); g_free (value); - g_strfreev (list); } value = svGetValue (ifcfg, "ESSID", TRUE); if (value) { - gsize ssid_len = 0, value_len = strlen (value); - char *p = value, *tmp; - char buf[33]; + GBytes *bytes = NULL; + gsize ssid_len = 0; + gsize value_len = strlen (value); - ssid_len = value_len; if ( (value_len >= 2) && (value[0] == '"') && (value[value_len - 1] == '"')) { /* Strip the quotes and unescape */ - p = value + 1; + char *p = value + 1; + value[value_len - 1] = '\0'; svUnescape (p); - ssid_len = strlen (p); + bytes = g_bytes_new (p, strlen (p)); } else if ((value_len > 2) && (strncmp (value, "0x", 2) == 0)) { /* Hex representation */ if (value_len % 2) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid SSID '%s' size (looks like hex but length not multiple of 2)", value); g_free (value); goto error; } - p = value + 2; - while (*p) { - if (!g_ascii_isxdigit (*p)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid SSID '%s' character (looks like hex SSID but '%c' isn't a hex digit)", - value, *p); - g_free (value); - goto error; - } - p++; + bytes = nm_utils_hexstr2bin (value); + if (!bytes) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid SSID '%s' (looks like hex SSID but isn't)", + value); + g_free (value); + goto error; } + } else + bytes = g_bytes_new (value, value_len); - tmp = nm_utils_hexstr2bin (value + 2, value_len - 2); - ssid_len = (value_len - 2) / 2; - memcpy (buf, tmp, ssid_len); - p = &buf[0]; - g_free (tmp); - } - + ssid_len = g_bytes_get_size (bytes); if (ssid_len > 32 || ssid_len == 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)", value, ssid_len); + g_bytes_unref (bytes); g_free (value); goto error; } - array = g_byte_array_sized_new (ssid_len); - g_byte_array_append (array, (const guint8 *) p, ssid_len); - g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, array, NULL); - g_byte_array_free (array, TRUE); + g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, bytes, NULL); + g_bytes_unref (bytes); g_free (value); } @@ -3659,11 +3314,13 @@ make_wireless_setting (shvarFile *ifcfg, if (!strcmp (lcase, "ad-hoc")) { mode = "adhoc"; + } else if (!strcmp (lcase, "ap")) { + mode = "ap"; } else if (!strcmp (lcase, "managed") || !strcmp (lcase, "auto")) { mode = "infrastructure"; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid mode '%s' (not 'Ad-Hoc', 'Managed', or 'Auto')", + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid mode '%s' (not 'Ad-Hoc', 'Ap', 'Managed', or 'Auto')", lcase); g_free (lcase); goto error; @@ -3675,39 +3332,54 @@ make_wireless_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "BSSID", FALSE); if (value) { - GByteArray *bssid; - - bssid = nm_utils_hwaddr_atoba (value, ARPHRD_ETHER); - if (!bssid) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid BSSID '%s'", value); - g_free (value); - goto error; - } - - g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, bssid, NULL); - g_byte_array_free (bssid, TRUE); + value = g_strstrip (value); + g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, value, NULL); g_free (value); } value = svGetValue (ifcfg, "CHANNEL", FALSE); if (value) { - long int chan; - errno = 0; - chan = strtol (value, NULL, 10); - if (errno || chan <= 0 || chan > 196) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + chan = nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0); + if (errno || (chan == 0)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid wireless channel '%s'", value); g_free (value); goto error; } g_object_set (s_wireless, NM_SETTING_WIRELESS_CHANNEL, (guint32) chan, NULL); + g_free (value); + } + + value = svGetValue (ifcfg, "BAND", FALSE); + if (value) { + if (!strcmp (value, "a")) { + if (chan && chan <= 14) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Band '%s' invalid for channel %u", value, (guint32) chan); + g_free (value); + goto error; + } + } else if (!strcmp (value, "bg")) { + if (chan && chan > 14) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Band '%s' invalid for channel %u", value, (guint32) chan); + g_free (value); + goto error; + } + } else { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid wireless band '%s'", value); + g_free (value); + goto error; + } + g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, value, NULL); + g_free (value); + } else if (chan > 0) { if (chan > 14) g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "a", NULL); else g_object_set (s_wireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); - g_free (value); } value = svGetValue (ifcfg, "MTU", FALSE); @@ -3717,7 +3389,7 @@ make_wireless_setting (shvarFile *ifcfg, errno = 0; mtu = strtol (value, NULL, 10); if (errno || mtu < 0 || mtu > 50000) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid wireless MTU '%s'", value); g_free (value); goto error; @@ -3748,7 +3420,7 @@ wireless_connection_from_ifcfg (const char *file, NMSetting *con_setting = NULL; NMSetting *wireless_setting = NULL; NMSetting8021x *s_8021x = NULL; - const GByteArray *ssid; + GBytes *ssid; NMSetting *security_setting = NULL; char *printable_ssid = NULL; const char *mode; @@ -3759,7 +3431,7 @@ wireless_connection_from_ifcfg (const char *file, g_return_val_if_fail (error != NULL, NULL); g_return_val_if_fail (*error == NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Wireless */ wireless_setting = make_wireless_setting (ifcfg, error); @@ -3770,9 +3442,10 @@ wireless_connection_from_ifcfg (const char *file, nm_connection_add_setting (connection, wireless_setting); ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (wireless_setting)); - if (ssid) - printable_ssid = nm_utils_ssid_to_utf8 (ssid); - else + if (ssid) { + printable_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid)); + } else printable_ssid = g_strdup_printf ("unmanaged"); mode = nm_setting_wireless_get_mode (NM_SETTING_WIRELESS (wireless_setting)); @@ -3798,18 +3471,13 @@ wireless_connection_from_ifcfg (const char *file, printable_ssid, NULL); g_free (printable_ssid); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create connection setting."); g_object_unref (connection); return NULL; } nm_connection_add_setting (connection, con_setting); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } - return connection; } @@ -3822,8 +3490,6 @@ make_wired_setting (shvarFile *ifcfg, NMSettingWired *s_wired; char *value = NULL; int mtu; - GByteArray *mac = NULL; - GSList *macaddr_blacklist = NULL; char *nettype; s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); @@ -3840,14 +3506,11 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - if (read_mac_address (ifcfg, "HWADDR", ARPHRD_ETHER, &mac, error)) { - if (mac) { - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); - } - } else { - g_object_unref (s_wired); - return NULL; + value = svGetValue (ifcfg, "HWADDR", FALSE); + if (value) { + value = g_strstrip (value); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL); + g_free (value); } value = svGetValue (ifcfg, "SUBCHANNELS", FALSE); @@ -3874,17 +3537,8 @@ make_wired_setting (shvarFile *ifcfg, if (num_chans < 2 || num_chans > 3) { PARSE_WARNING ("invalid SUBCHANNELS '%s' (%d channels, 2 or 3 expected)", value, g_strv_length (chans)); - } else { - GPtrArray *array = g_ptr_array_sized_new (num_chans); - - g_ptr_array_add (array, chans[0]); - g_ptr_array_add (array, chans[1]); - if (num_chans == 3) - g_ptr_array_add (array, chans[2]); - - g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, array, NULL); - g_ptr_array_free (array, TRUE); - } + } else + g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, chans, NULL); g_strfreev (chans); } g_free (value); @@ -3931,39 +3585,21 @@ make_wired_setting (shvarFile *ifcfg, } g_free (value); - mac = NULL; - if (read_mac_address (ifcfg, "MACADDR", ARPHRD_ETHER, &mac, error)) { - if (mac) { - g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); - } - } else { - PARSE_WARNING ("%s", (*error)->message); - g_clear_error (error); + value = svGetValue (ifcfg, "MACADDR", FALSE); + if (value) { + value = g_strstrip (value); + g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, value, NULL); + g_free (value); } value = svGetValue (ifcfg, "HWADDR_BLACKLIST", FALSE); if (value) { - char **list = NULL, **iter; - struct ether_addr addr; + char **strv; - list = g_strsplit_set (value, " \t", 0); - for (iter = list; iter && *iter; iter++) { - if (**iter == '\0') - continue; - if (!ether_aton_r (*iter, &addr)) { - PARSE_WARNING ("invalid MAC in HWADDR_BLACKLIST '%s'", *iter); - continue; - } - macaddr_blacklist = g_slist_prepend (macaddr_blacklist, *iter); - } - if (macaddr_blacklist) { - macaddr_blacklist = g_slist_reverse (macaddr_blacklist); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, macaddr_blacklist, NULL); - g_slist_free (macaddr_blacklist); - } + strv = transform_hwaddr_blacklist (value); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, strv, NULL); + g_strfreev (strv); g_free (value); - g_strfreev (list); } value = svGetValue (ifcfg, "KEY_MGMT", FALSE); @@ -3973,7 +3609,7 @@ make_wired_setting (shvarFile *ifcfg, if (!*s_8021x) goto error; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown wired KEY_MGMT type '%s'", value); goto error; } @@ -4001,11 +3637,11 @@ wired_connection_from_ifcfg (const char *file, g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (ifcfg != NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); con_setting = make_connection_setting (file, ifcfg, NM_SETTING_WIRED_SETTING_NAME, NULL, NULL); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create connection setting."); g_object_unref (connection); return NULL; @@ -4024,11 +3660,6 @@ wired_connection_from_ifcfg (const char *file, if (s_8021x) nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } - return connection; } @@ -4091,7 +3722,7 @@ parse_infiniband_p_key (shvarFile *ifcfg, g_free (ifname); if (!ret) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create InfiniBand setting."); } return ret; @@ -4105,7 +3736,6 @@ make_infiniband_setting (shvarFile *ifcfg, { NMSettingInfiniband *s_infiniband; char *value = NULL; - GByteArray *mac = NULL; int mtu; s_infiniband = NM_SETTING_INFINIBAND (nm_setting_infiniband_new ()); @@ -4122,14 +3752,11 @@ make_infiniband_setting (shvarFile *ifcfg, g_free (value); } - if (read_mac_address (ifcfg, "HWADDR", ARPHRD_INFINIBAND, &mac, error)) { - if (mac) { - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); - } - } else { - g_object_unref (s_infiniband); - return NULL; + value = svGetValue (ifcfg, "HWADDR", FALSE); + if (value) { + value = g_strstrip (value); + g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, value, NULL); + g_free (value); } if (svTrueValue (ifcfg, "CONNECTED_MODE", FALSE)) @@ -4167,11 +3794,11 @@ infiniband_connection_from_ifcfg (const char *file, g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (ifcfg != NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); con_setting = make_connection_setting (file, ifcfg, NM_SETTING_INFINIBAND_SETTING_NAME, NULL, NULL); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create connection setting."); g_object_unref (connection); return NULL; @@ -4187,11 +3814,6 @@ infiniband_connection_from_ifcfg (const char *file, } nm_connection_add_setting (connection, infiniband_setting); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } - return connection; } @@ -4232,11 +3854,10 @@ make_bond_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "DEVICE", FALSE); if (!value || !strlen (value)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "mandatory DEVICE keyword missing"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "mandatory DEVICE keyword missing"); goto error; } - - g_object_set (s_bond, NM_SETTING_BOND_INTERFACE_NAME, value, NULL); g_free (value); value = svGetValue (ifcfg, "BONDING_OPTS", FALSE); @@ -4284,11 +3905,11 @@ bond_connection_from_ifcfg (const char *file, g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (ifcfg != NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BOND_SETTING_NAME, NULL, _("Bond")); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create connection setting."); g_object_unref (connection); return NULL; @@ -4312,11 +3933,6 @@ bond_connection_from_ifcfg (const char *file, if (s_8021x) nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } - return connection; } @@ -4338,7 +3954,8 @@ read_team_config (shvarFile *ifcfg, const char *key, GError **error) */ l = strlen (value); if (l > 20000) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "%s too long (size %zd)", key, l); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "%s too long (size %zd)", key, l); g_free (value); return NULL; } @@ -4359,11 +3976,10 @@ make_team_setting (shvarFile *ifcfg, value = svGetValue (ifcfg, "DEVICE", FALSE); if (!value || !strlen (value)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "mandatory DEVICE keyword missing"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "mandatory DEVICE keyword missing"); goto error; } - - g_object_set (s_team, NM_SETTING_TEAM_INTERFACE_NAME, value, NULL); g_free (value); value = read_team_config (ifcfg, "TEAM_CONFIG", &local_err); @@ -4395,11 +4011,11 @@ team_connection_from_ifcfg (const char *file, g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (ifcfg != NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); con_setting = make_connection_setting (file, ifcfg, NM_SETTING_TEAM_SETTING_NAME, NULL, _("Team")); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create connection setting."); g_object_unref (connection); return NULL; @@ -4423,11 +4039,6 @@ team_connection_from_ifcfg (const char *file, if (s_8021x) nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } - return connection; } @@ -4511,27 +4122,22 @@ make_bridge_setting (shvarFile *ifcfg, guint32 u; gboolean stp = FALSE; gboolean stp_set = FALSE; - GByteArray *array = NULL; s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ()); value = svGetValue (ifcfg, "DEVICE", FALSE); if (!value || !strlen (value)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "mandatory DEVICE keyword missing"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "mandatory DEVICE keyword missing"); goto error; } - - g_object_set (s_bridge, NM_SETTING_BRIDGE_INTERFACE_NAME, value, NULL); g_free (value); - if (read_mac_address (ifcfg, "MACADDR", ARPHRD_ETHER, &array, error)) { - if (array) { - g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, array, NULL); - g_byte_array_free (array, TRUE); - } - } else { - PARSE_WARNING ("%s", (*error)->message); - g_clear_error (error); + value = svGetValue (ifcfg, "MACADDR", FALSE); + if (value) { + value = g_strstrip (value); + g_object_set (s_bridge, NM_SETTING_BRIDGE_MAC_ADDRESS, value, NULL); + g_free (value); } value = svGetValue (ifcfg, "STP", FALSE); @@ -4590,11 +4196,11 @@ bridge_connection_from_ifcfg (const char *file, g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (ifcfg != NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BRIDGE_SETTING_NAME, NULL, _("Bridge")); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to create connection setting."); g_object_unref (connection); return NULL; @@ -4608,11 +4214,6 @@ bridge_connection_from_ifcfg (const char *file, } nm_connection_add_setting (connection, bridge_setting); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } - return connection; } @@ -4757,8 +4358,6 @@ parse_prio_map_list (NMSettingVlan *s_vlan, static NMSetting * make_vlan_setting (shvarFile *ifcfg, const char *file, - char **out_master, - NMSetting8021x **s_8021x, GError **error) { NMSettingVlan *s_vlan = NULL; @@ -4775,7 +4374,8 @@ make_vlan_setting (shvarFile *ifcfg, errno = 0; vlan_id = (gint) g_ascii_strtoll (value, NULL, 10); if (vlan_id < 0 || vlan_id > 4096 || errno) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "Invalid VLAN_ID '%s'", value); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid VLAN_ID '%s'", value); g_free (value); return NULL; } @@ -4785,7 +4385,7 @@ make_vlan_setting (shvarFile *ifcfg, /* Need DEVICE if we don't have a separate VLAN_ID property */ iface_name = svGetValue (ifcfg, "DEVICE", FALSE); if (!iface_name && vlan_id < 0) { - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing DEVICE property; cannot determine VLAN ID."); return NULL; } @@ -4796,8 +4396,6 @@ make_vlan_setting (shvarFile *ifcfg, parent = svGetValue (ifcfg, "PHYSDEV", FALSE); if (iface_name) { - g_object_set (s_vlan, NM_SETTING_VLAN_INTERFACE_NAME, iface_name, NULL); - p = strchr (iface_name, '.'); if (p) { /* eth0.43; PHYSDEV is assumed from it if unknown */ @@ -4813,7 +4411,7 @@ make_vlan_setting (shvarFile *ifcfg, } p++; } else { - /* format like vlan43; PHYSDEV or MASTER must be set */ + /* format like vlan43; PHYSDEV must be set */ if (g_str_has_prefix (iface_name, "vlan")) p = iface_name + 4; } @@ -4824,7 +4422,7 @@ make_vlan_setting (shvarFile *ifcfg, */ vlan_id = (gint) g_ascii_strtoll (p, &end, 10); if (vlan_id < 0 || vlan_id > 4095 || end == p || *end) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to determine VLAN ID from DEVICE '%s'", iface_name); goto error; @@ -4833,14 +4431,14 @@ make_vlan_setting (shvarFile *ifcfg, } if (vlan_id < 0) { - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to determine VLAN ID from DEVICE or VLAN_ID."); goto error; } g_object_set (s_vlan, NM_SETTING_VLAN_ID, vlan_id, NULL); if (parent == NULL) { - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Failed to determine VLAN parent from DEVICE or PHYSDEV"); goto error; } @@ -4863,8 +4461,6 @@ make_vlan_setting (shvarFile *ifcfg, parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP); parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP); - if (out_master) - *out_master = svGetValue (ifcfg, "MASTER", FALSE); return (NMSetting *) s_vlan; error: @@ -4884,38 +4480,30 @@ vlan_connection_from_ifcfg (const char *file, NMSetting *wired_setting = NULL; NMSetting *vlan_setting = NULL; NMSetting8021x *s_8021x = NULL; - char *master = NULL; g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (ifcfg != NULL, NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); con_setting = make_connection_setting (file, ifcfg, NM_SETTING_VLAN_SETTING_NAME, NULL, "Vlan"); if (!con_setting) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Failed to create connection setting."); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Failed to create connection setting."); g_object_unref (connection); return NULL; } + check_if_bond_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); + check_if_team_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); 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, error); if (!vlan_setting) { g_object_unref (connection); return NULL; } nm_connection_add_setting (connection, vlan_setting); - /* Handle master interface or connection */ - if (master) { - g_object_set (con_setting, NM_SETTING_CONNECTION_MASTER, master, NULL); - g_object_set (con_setting, - NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_VLAN_SETTING_NAME, - NULL); - g_free (master); - } - wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); if (!wired_setting) { g_object_unref (connection); @@ -4925,10 +4513,6 @@ vlan_connection_from_ifcfg (const char *file, if (s_8021x) nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - if (!nm_connection_verify (connection, error)) { - g_object_unref (connection); - return NULL; - } return connection; } @@ -4943,7 +4527,7 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg, g_assert (out_spec != NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Get NAME, UUID, etc. We need to set a connection type (generic) and add * an empty type-specific setting as well, to make sure it passes @@ -5004,7 +4588,7 @@ uuid_from_file (const char *filename) uuid = svGetValue (ifcfg, "UUID", FALSE); if (!uuid || !strlen (uuid)) { g_free (uuid); - uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName); + uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } svCloseFile (ifcfg); @@ -5020,7 +4604,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) /* If there is no IPv4 config or it doesn't contain DNS searches, * read DOMAIN and put the domains into IPv6. */ - if (!s_ip4 || nm_setting_ip4_config_get_num_dns_searches (NM_SETTING_IP4_CONFIG (s_ip4)) == 0) { + if (!s_ip4 || nm_setting_ip_config_get_num_dns_searches (NM_SETTING_IP_CONFIG (s_ip4)) == 0) { /* DNS searches */ char *value = svGetValue (ifcfg, "DOMAIN", FALSE); if (value) { @@ -5029,7 +4613,7 @@ check_dns_search_domains (shvarFile *ifcfg, NMSetting *s_ip4, NMSetting *s_ip6) char **item; for (item = searches; *item; item++) { if (strlen (*item)) { - if (!nm_setting_ip6_config_add_dns_search (NM_SETTING_IP6_CONFIG (s_ip6), *item)) + if (!nm_setting_ip_config_add_dns_search (NM_SETTING_IP_CONFIG (s_ip6), *item)) PARSE_WARNING ("duplicate DNS domain '%s'", *item); } } @@ -5044,7 +4628,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, @@ -5072,12 +4655,9 @@ 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, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Ignoring connection '%s' because it's not an ifcfg file.", filename); return NULL; } @@ -5095,6 +4675,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, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignoring iBFT configuration"); + g_free (bootproto); + goto done; + } + type = NULL; devtype = svGetValue (parsed, "DEVICETYPE", FALSE); @@ -5114,7 +4705,7 @@ connection_from_file (const char *filename, device = svGetValue (parsed, "DEVICE", FALSE); if (!device) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "File '%s' had neither TYPE nor DEVICE keys.", filename); goto done; } @@ -5122,7 +4713,7 @@ connection_from_file (const char *filename, if (!strcmp (device, "lo")) { if (out_ignore_error) *out_ignore_error = TRUE; - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Ignoring loopback device config."); g_free (device); goto done; @@ -5156,7 +4747,7 @@ connection_from_file (const char *filename, if (svTrueValue (parsed, "BONDING_MASTER", FALSE) && strcasecmp (type, TYPE_BOND)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "BONDING_MASTER=yes key only allowed in TYPE=bond connections"); goto done; } @@ -5189,7 +4780,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; @@ -5197,13 +4788,13 @@ 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; goto done; } else { - read_aliases (NM_SETTING_IP4_CONFIG (s_ip4), filename, network_file); + read_aliases (NM_SETTING_IP_CONFIG (s_ip4), filename, network_file); nm_connection_add_setting (connection, s_ip4); } @@ -5231,25 +4822,7 @@ 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); - - nm_utils_normalize_connection (connection, TRUE); - - if (!nm_connection_verify (connection, error)) { + 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 371f4504..c23e5870 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/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 4e8e29ce..6c9769b2 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -23,6 +23,8 @@ * */ +#include "config.h" + #include <errno.h> #include <fcntl.h> #include <stdio.h> @@ -34,6 +36,11 @@ #include "shvar.h" +#include "NetworkManagerUtils.h" +#include "nm-logging.h" + +#define PARSE_WARNING(msg...) nm_log_warn (LOGD_SETTINGS, " " msg) + /* Open the file <name>, returning a shvarFile on success and NULL on failure. * Add a wrinkle to let the caller specify whether or not to create the file * (actually, return a structure anyway) if it doesn't exist. @@ -233,8 +240,7 @@ svEscape (const char *s) new[j++] = s[i]; } new[j++] = '"'; - new[j++] = '\0' -; + new[j++] = '\0'; g_assert (j == slen + mangle - newline + 3); return new; @@ -261,7 +267,8 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim) for (s->current = s->lineList; s->current; s->current = s->current->next) { line = s->current->data; if (!strncmp (keyString, line, len)) { - value = g_strdup (line + len); + /* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */ + value = g_strchomp (g_strdup (line + len)); if (!verbatim) svUnescape (value); break; @@ -306,6 +313,38 @@ svTrueValue (shvarFile *s, const char *key, gboolean def) return returnValue; } +/* svGetValueInt64: + * @s: fhe file + * @key: the name of the key to read + * @base: the numeric base (usually 10). Setting to 0 means "auto". Usually you want 10. + * @min: the minimum for range-check + * @max: the maximum for range-check + * @fallback: the fallback value in any error case + * + * Reads a value @key and converts it to an integer using nm_utils_ascii_str_to_int64(). + * In case of error, @errno will be set and @fallback returned. */ +gint64 +svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback) +{ + char *tmp; + gint64 result; + int errsv; + + tmp = svGetValue (s, key, FALSE); + if (!tmp) { + errno = 0; + return fallback; + } + + result = nm_utils_ascii_str_to_int64 (tmp, base, min, max, fallback); + errsv = errno; + if (errsv != 0) + PARSE_WARNING ("Error reading '%s' value '%s' as integer (%d)", key, tmp, errsv); + + g_free (tmp); + + return result; +} /* Set the variable <key> equal to the value <value>. * If <key> does not exist, and the <current> pointer is set, append diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 4cbf1a31..b2a2f263 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -63,6 +63,8 @@ char *svGetValue (shvarFile *s, const char *key, gboolean verbatim); */ gboolean svTrueValue (shvarFile *s, const char *key, gboolean def); +gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 max, gint64 fallback); + /* Set the variable <key> equal to the value <value>. * If <key> does not exist, and the <current> pointer is set, append * the key=value pair after that line. Otherwise, prepend the pair diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index e758776d..5a17ed9b 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -6,20 +6,16 @@ SUBDIRS=network-scripts AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ - -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src/ \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ - -I$(top_srcdir)/src/posix-signals \ -I$(srcdir)/../ \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ @@ -31,15 +27,10 @@ AM_LDFLAGS = \ $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) -AM_LDADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la - noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils test_ifcfg_rh_SOURCES = \ test-ifcfg-rh.c \ - ../errors.c \ ../reader.c \ ../shvar.c \ ../utils.c \ @@ -54,19 +45,9 @@ test_ifcfg_rh_utils_SOURCES = \ ../shvar.c test_ifcfg_rh_utils_LDADD = \ - $(AM_LDADD) + $(top_builddir)/src/libNetworkManager.la 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/Makefile.in b/src/settings/plugins/ifcfg-rh/tests/Makefile.in index 2018134a..f34e759d 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.in +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.in @@ -106,12 +106,11 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) -am__test_ifcfg_rh_SOURCES_DIST = test-ifcfg-rh.c ../errors.c \ - ../reader.c ../shvar.c ../utils.c ../writer.c +am__test_ifcfg_rh_SOURCES_DIST = test-ifcfg-rh.c ../reader.c \ + ../shvar.c ../utils.c ../writer.c @ENABLE_TESTS_TRUE@am_test_ifcfg_rh_OBJECTS = test-ifcfg-rh.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ errors.$(OBJEXT) reader.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ shvar.$(OBJEXT) utils.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ writer.$(OBJEXT) +@ENABLE_TESTS_TRUE@ reader.$(OBJEXT) shvar.$(OBJEXT) \ +@ENABLE_TESTS_TRUE@ utils.$(OBJEXT) writer.$(OBJEXT) test_ifcfg_rh_OBJECTS = $(am_test_ifcfg_rh_OBJECTS) @ENABLE_TESTS_TRUE@test_ifcfg_rh_DEPENDENCIES = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la @@ -125,7 +124,8 @@ am__test_ifcfg_rh_utils_SOURCES_DIST = test-ifcfg-rh-utils.c \ @ENABLE_TESTS_TRUE@ test-ifcfg-rh-utils.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ utils.$(OBJEXT) shvar.$(OBJEXT) test_ifcfg_rh_utils_OBJECTS = $(am_test_ifcfg_rh_utils_OBJECTS) -@ENABLE_TESTS_TRUE@test_ifcfg_rh_utils_DEPENDENCIES = $(AM_LDADD) +@ENABLE_TESTS_TRUE@test_ifcfg_rh_utils_DEPENDENCIES = \ +@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -261,6 +261,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -384,6 +386,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -403,6 +406,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -429,7 +433,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -511,20 +515,16 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@SUBDIRS = network-scripts @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-glib \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/ \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/logging \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/platform \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/posix-signals \ @ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ @ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ -DTEST_IFCFG_DIR=\"$(abs_srcdir)\" \ @ENABLE_TESTS_TRUE@ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \ @@ -536,13 +536,8 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@ $(DBUS_LIBS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) -@ENABLE_TESTS_TRUE@AM_LDADD = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-glib/libnm-glib.la - @ENABLE_TESTS_TRUE@test_ifcfg_rh_SOURCES = \ @ENABLE_TESTS_TRUE@ test-ifcfg-rh.c \ -@ENABLE_TESTS_TRUE@ ../errors.c \ @ENABLE_TESTS_TRUE@ ../reader.c \ @ENABLE_TESTS_TRUE@ ../shvar.c \ @ENABLE_TESTS_TRUE@ ../utils.c \ @@ -557,17 +552,7 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@ ../shvar.c @ENABLE_TESTS_TRUE@test_ifcfg_rh_utils_LDADD = \ -@ENABLE_TESTS_TRUE@ $(AM_LDADD) - -@ENABLE_TESTS_TRUE@EXTRA_DIST = \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-dhcp \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-static \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-bad-ipaddr \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-bad-gateway \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-bad-dns1 \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-bad-dns2 \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-bad-entry \ -@ENABLE_TESTS_TRUE@ iscsiadm-test-bad-record +@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la all: all-recursive @@ -627,7 +612,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shvar.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-ifcfg-rh-utils.Po@am__quote@ @@ -656,20 +640,6 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< -errors.o: ../errors.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.o -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c - -errors.obj: ../errors.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.obj -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` - reader.o: ../reader.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT reader.o -MD -MP -MF $(DEPDIR)/reader.Tpo -c -o reader.o `test -f '../reader.c' || echo '$(srcdir)/'`../reader.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/reader.Tpo $(DEPDIR)/reader.Po 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 1701aeeb..8941da3a 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am @@ -1,5 +1,6 @@ EXTRA_DIST = \ ifcfg-test-minimal \ + ifcfg-test-misc-variables \ ifcfg-test-variables-corner-cases-1 \ ifcfg-test-nm-controlled \ ifcfg-test-nm-controlled-unrecognized \ @@ -59,10 +60,12 @@ EXTRA_DIST = \ ifcfg-test-wifi-wpa-eap-ttls-tls \ keys-test-wifi-wpa-eap-ttls-tls \ ifcfg-test-wifi-hidden \ + ifcfg-test-wifi-band-a \ + ifcfg-test-wifi-band-a-channel-mismatch \ + ifcfg-test-wifi-band-bg-channel-mismatch \ 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 \ @@ -116,7 +119,8 @@ EXTRA_DIST = \ ifcfg-test-fcoe-vn2vn \ ifcfg-test-team-master \ ifcfg-test-team-port \ - ifcfg-test-team-port-empty-config + ifcfg-test-team-port-empty-config \ + ifcfg-test-vlan-trailing-spaces # make target dependencies can't have colons in their names, which ends up # meaning that we can't add the alias files to EXTRA_DIST diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in index eff763e8..aac646f8 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -378,6 +382,7 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ EXTRA_DIST = \ ifcfg-test-minimal \ + ifcfg-test-misc-variables \ ifcfg-test-variables-corner-cases-1 \ ifcfg-test-nm-controlled \ ifcfg-test-nm-controlled-unrecognized \ @@ -437,10 +442,12 @@ EXTRA_DIST = \ ifcfg-test-wifi-wpa-eap-ttls-tls \ keys-test-wifi-wpa-eap-ttls-tls \ ifcfg-test-wifi-hidden \ + ifcfg-test-wifi-band-a \ + ifcfg-test-wifi-band-a-channel-mismatch \ + ifcfg-test-wifi-band-bg-channel-mismatch \ 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 \ @@ -494,7 +501,8 @@ EXTRA_DIST = \ ifcfg-test-fcoe-vn2vn \ ifcfg-test-team-master \ ifcfg-test-team-port \ - ifcfg-test-team-port-empty-config + ifcfg-test-team-port-empty-config \ + ifcfg-test-vlan-trailing-spaces # make target dependencies can't have colons in their names, which ends up 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 00000000..d3e4edca --- /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/network-scripts/ifcfg-test-ibft-dhcp b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft-dhcp deleted file mode 100644 index abfcd6e4..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft-dhcp +++ /dev/null @@ -1,4 +0,0 @@ -# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) -DEVICE=eth0 -HWADDR=00:33:21:98:b9:f1 -BOOTPROTO=ibft diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft-static b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft-static deleted file mode 100644 index 99b02e42..00000000 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft-static +++ /dev/null @@ -1,4 +0,0 @@ -# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) -DEVICE=eth0 -HWADDR=00:33:21:98:b9:f0 -BOOTPROTO=ibft diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables new file mode 100644 index 00000000..c7892a21 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables @@ -0,0 +1,3 @@ +DEVICE=eth0 +HWADDR_BLACKLIST="00:16:41:11:22:88 00:16:41:11:22:99 XX:aa:invalid 6A:5D:5A:FA:DD:F0" + diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces new file mode 100644 index 00000000..4a31e475 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces @@ -0,0 +1,11 @@ +DEVICE="vlan201" +ONBOOT=yes +NETBOOT=yes +BOOTPROTO=none +IPADDR="10.130.70.7" +NETMASK="255.255.0.0" +TYPE=Vlan +NAME="vlan201" +VLAN=yes +PHYSDEV="enccw0.0.fb00" + diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a new file mode 100644 index 00000000..43286111 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +BAND=a +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch new file mode 100644 index 00000000..8905ba0b --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch @@ -0,0 +1,9 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=9 +BAND=a +MODE=Managed + diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch new file mode 100644 index 00000000..e02e21ad --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch @@ -0,0 +1,9 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=183 +BAND=bg +MODE=Managed + diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open index d4bb8f75..48db45b2 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open @@ -3,6 +3,7 @@ DEVICE=eth2 HWADDR=00:16:41:11:22:33 NM_CONTROLLED=yes BOOTPROTO=dhcp +AUTOCONNECT_PRIORITY=-1 ESSID=blahblah CHANNEL=1 MODE=Managed diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c index 39c81027..d82a3270 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c @@ -18,6 +18,8 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ +#include "config.h" + #include <stdio.h> #include <stdarg.h> #include <unistd.h> 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 c1b14f12..4a6940d0 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -18,12 +18,12 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ +#include "config.h" + #include <stdio.h> #include <stdarg.h> #include <unistd.h> #include <string.h> -#include <netinet/ether.h> -#include <linux/if_infiniband.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/socket.h> @@ -46,7 +46,7 @@ #include <nm-setting-serial.h> #include <nm-setting-vlan.h> #include <nm-setting-dcb.h> -#include <nm-utils-private.h> +#include "nm-core-internal.h" #include "NetworkManagerUtils.h" @@ -185,17 +185,17 @@ test_read_basic (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; const char *expected_id = "System test-minimal"; guint64 expected_timestamp = 0; 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); @@ -220,22 +220,71 @@ test_read_basic (void) g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert (memcmp (array->data, &expected_mac_address[0], ETH_ALEN) == 0); + mac = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, ETH_ALEN)); /* ===== 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_DISABLED); - g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE); /* ===== IPv6 SETTING ===== */ s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip6); - g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); - g_assert (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert (nm_setting_ip_config_get_never_default (s_ip6) == FALSE); + + g_object_unref (connection); +} + +static void +test_read_miscellaneous_variables (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + GError *error = NULL; + char *expected_mac_blacklist[3] = { "00:16:41:11:22:88", "00:16:41:11:22:99", "6a:5d:5a:fa:dd:f0" }; + int mac_blacklist_num, i; + guint64 expected_timestamp = 0; + gboolean success; + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*invalid MAC in HWADDR_BLACKLIST 'XX:aa:invalid'*"); + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-misc-variables", + NULL, TYPE_ETHERNET, NULL, NULL, NULL, NULL, &error, NULL); + g_test_assert_expected_messages (); + g_assert_no_error (error); + g_assert (connection); + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, expected_timestamp); + g_assert (nm_setting_connection_get_autoconnect (s_con)); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); + + /* MAC blacklist */ + mac_blacklist_num = nm_setting_wired_get_num_mac_blacklist_items (s_wired); + g_assert_cmpint (mac_blacklist_num, ==, 3); + for (i = 0; i < mac_blacklist_num; i++) + g_assert (nm_utils_hwaddr_matches (nm_setting_wired_get_mac_blacklist_item (s_wired, i), -1, expected_mac_blacklist[i], -1)); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE); g_object_unref (connection); } @@ -246,9 +295,9 @@ test_read_variables_corner_cases (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; const char *expected_zone = "'"; const char *expected_id = "\""; @@ -256,7 +305,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); @@ -277,16 +326,15 @@ test_read_variables_corner_cases (void) g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert (memcmp (array->data, &expected_mac_address[0], ETH_ALEN) == 0); + mac = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, ETH_ALEN)); /* ===== 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_DISABLED); - g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE); g_object_unref (connection); } @@ -303,7 +351,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); @@ -336,7 +384,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); @@ -367,7 +415,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); @@ -394,27 +442,17 @@ test_read_wired_static (const char *file, NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee }; - const char *expected_dns1 = "4.2.2.1"; - 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"; - const char *expected6_dns2 = "1:2:3:4::b"; - NMIP4Address *ip4_addr; - NMIP6Address *ip6_addr; + NMIPAddress *ip4_addr; + NMIPAddress *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); @@ -436,64 +474,57 @@ test_read_wired_static (const char *file, g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 1492); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert (memcmp (array->data, &expected_mac_address[0], ETH_ALEN) == 0); + mac = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, ETH_ALEN)); /* ===== 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 (nm_setting_ip4_config_get_may_fail (s_ip4)); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + g_assert (nm_setting_ip_config_get_may_fail (s_ip4)); /* DNS Addresses */ - g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2); - g_assert_cmpint (inet_pton (AF_INET, expected_dns1, &addr), >, 0); - g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, addr); - g_assert_cmpint (inet_pton (AF_INET, expected_dns2, &addr), >, 0); - g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, addr); + g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1"); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "4.2.2.2"); /* IP addresses */ - 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_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip_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); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5"); + + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.1"); /* ===== IPv6 SETTING ===== */ s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip6); if (expect_ip6) { - g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); - g_assert (nm_setting_ip6_config_get_may_fail (s_ip6)); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_MANUAL); + g_assert (nm_setting_ip_config_get_may_fail (s_ip6)); /* DNS Addresses */ - g_assert_cmpint (nm_setting_ip6_config_get_num_dns (s_ip6), ==, 2); - g_assert_cmpint (inet_pton (AF_INET6, expected6_dns1, &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr6)); - g_assert_cmpint (inet_pton (AF_INET6, expected6_dns2, &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6)); + g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 2); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a"); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b"); /* IP addresses */ - g_assert_cmpint (nm_setting_ip6_config_get_num_addresses (s_ip6), ==, 2); + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 2); - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0); g_assert (ip6_addr); - g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 64); - g_assert_cmpint (inet_pton (AF_INET6, expected6_address1, &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6)); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "dead:beaf::1"); - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 1); g_assert (ip6_addr); - g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 56); - g_assert_cmpint (inet_pton (AF_INET6, expected6_address2, &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6)); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "dead:beaf::2"); } else { - g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); } g_free (unmanaged); @@ -506,9 +537,9 @@ test_read_wired_static_no_prefix (gconstpointer user_data) guint32 expected_prefix = GPOINTER_TO_UINT (user_data); NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; GError *error = NULL; - NMIP4Address *ip4_addr; + NMIPAddress *ip4_addr; char *file, *expected_id; file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); @@ -516,7 +547,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); @@ -531,12 +562,12 @@ test_read_wired_static_no_prefix (gconstpointer user_data) /* ===== 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_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); - 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_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); g_assert (ip4_addr); - g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, expected_prefix); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, expected_prefix); g_free (file); g_free (expected_id); @@ -551,26 +582,22 @@ test_read_wired_dhcp (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0xee }; const char *tmp; const char *expected_id = "System test-wired-dhcp"; - const char *expected_dns1 = "4.2.2.1"; - const char *expected_dns2 = "4.2.2.2"; - guint32 addr; const char *expected_dhcp_hostname = "foobar"; connection = connection_from_file (TEST_IFCFG_WIRED_DHCP, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -630,18 +657,13 @@ test_read_wired_dhcp (void) NM_SETTING_WIRED_SETTING_NAME); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - ASSERT (array != NULL, + mac = nm_setting_wired_get_mac_address (s_wired); + ASSERT (mac != NULL, "wired-dhcp-verify-wired", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIRED_DHCP, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "wired-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_WIRED_DHCP, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "wired-dhcp-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP, NM_SETTING_WIRED_SETTING_NAME, @@ -656,59 +678,49 @@ test_read_wired_dhcp (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - tmp = nm_setting_ip4_config_get_dhcp_hostname (s_ip4); + tmp = nm_setting_ip_config_get_dhcp_hostname (s_ip4); ASSERT (tmp != NULL, "wired-dhcp-verify-ip4", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME); + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME); ASSERT (strcmp (tmp, expected_dhcp_hostname) == 0, "wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME); + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME); - ASSERT (nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) == TRUE, + ASSERT (nm_setting_ip_config_get_ignore_auto_dns (s_ip4) == TRUE, "wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS); + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS); /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2, "wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0, - "wired-dhcp-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #1", - TEST_IFCFG_WIRED_DHCP, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr, + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "4.2.2.1") == 0, "wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0, - "wired-dhcp-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #2", - TEST_IFCFG_WIRED_DHCP, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr, + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "4.2.2.2") == 0, "wired-dhcp-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", TEST_IFCFG_WIRED_DHCP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); g_free (unmanaged); g_free (keyfile); @@ -721,17 +733,15 @@ static void test_read_wired_dhcp_plus_ip (void) { NMConnection *connection; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; GError *error = NULL; - guint32 addr4; - struct in6_addr addr6; - NMIP4Address *ip4_addr; - NMIP6Address *ip6_addr; + NMIPAddress *ip4_addr; + NMIPAddress *ip6_addr; 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); @@ -742,321 +752,132 @@ test_read_wired_dhcp_plus_ip (void) /* ===== 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_assert (nm_setting_ip4_config_get_may_fail (s_ip4)); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert (nm_setting_ip_config_get_may_fail (s_ip4)); /* DNS Addresses */ - g_assert_cmpint (nm_setting_ip4_config_get_num_dns (s_ip4), ==, 2); - g_assert_cmpint (inet_pton (AF_INET, "4.2.2.1", &addr4), >, 0); - g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 0), ==, addr4); - g_assert_cmpint (inet_pton (AF_INET, "4.2.2.2", &addr4), >, 0); - g_assert_cmpint (nm_setting_ip4_config_get_dns (s_ip4, 1), ==, addr4); + g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 2); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "4.2.2.1"); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 1), ==, "4.2.2.2"); /* IP addresses */ - g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2); - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 2); + ip4_addr = nm_setting_ip_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, "1.2.3.4", &addr4), >, 0); - g_assert_cmpint (nm_ip4_address_get_address (ip4_addr), ==, addr4); - g_assert_cmpint (inet_pton (AF_INET, "1.1.1.1", &addr4), >, 0); - g_assert_cmpint (nm_ip4_address_get_gateway (ip4_addr), ==, addr4); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "1.2.3.4"); + + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1"); - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 1); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 1); g_assert (ip4_addr); - g_assert_cmpint (nm_ip4_address_get_prefix (ip4_addr), ==, 16); - g_assert_cmpint (inet_pton (AF_INET, "9.8.7.6", &addr4), >, 0); - g_assert_cmpint (nm_ip4_address_get_address (ip4_addr), ==, addr4); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 16); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "9.8.7.6"); /* ===== IPv6 SETTING ===== */ s_ip6 = nm_connection_get_setting_ip6_config (connection); 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_may_fail (s_ip6)); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert (nm_setting_ip_config_get_may_fail (s_ip6)); /* DNS Addresses */ - g_assert_cmpint (nm_setting_ip6_config_get_num_dns (s_ip6), ==, 2); - g_assert_cmpint (inet_pton (AF_INET6, "1:2:3:4::a", &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr6)); - g_assert_cmpint (inet_pton (AF_INET6, "1:2:3:4::b", &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6)); + g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 2); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "1:2:3:4::a"); + g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 1), ==, "1:2:3:4::b"); /* IP addresses */ - g_assert_cmpint (nm_setting_ip6_config_get_num_addresses (s_ip6), ==, 3); - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 3); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0); g_assert (ip6_addr); - g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 56); - g_assert_cmpint (inet_pton (AF_INET6, "1001:abba::1234", &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6)); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "1001:abba::1234"); - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 1); g_assert (ip6_addr); - g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 64); - g_assert_cmpint (inet_pton (AF_INET6, "2001:abba::2234", &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6)); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "2001:abba::2234"); - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 2); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 2); g_assert (ip6_addr); - g_assert_cmpint (nm_ip6_address_get_prefix (ip6_addr), ==, 96); - g_assert_cmpint (inet_pton (AF_INET6, "3001:abba::3234", &addr6), >, 0); - g_assert (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6)); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 96); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "3001:abba::3234"); 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) { 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; + NMSettingIPConfig *s_ip4; 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; - - connection = connection_from_file (TEST_IFCFG_WIRED_GLOBAL_GATEWAY, - TEST_NETWORK_WIRED_GLOBAL_GATEWAY, - TYPE_ETHERNET, - NULL, - &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); + NMIPAddress *ip4_addr; + char *unmanaged = NULL; - 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_ip_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); - - 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); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5"); - 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); + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.2"); - 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; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; 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, - NULL, - &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_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert (nm_setting_ip_config_get_never_default (s_ip4)); + g_assert_cmpint (nm_setting_ip_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); - - /* 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_assert (s_ip6); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert (nm_setting_ip_config_get_never_default (s_ip6)); - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); g_object_unref (connection); } @@ -1068,8 +889,8 @@ test_read_wired_defroute_no (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -1082,7 +903,6 @@ test_read_wired_defroute_no (void) connection = connection_from_file (TEST_IFCFG_WIRED_DEFROUTE_NO, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1136,18 +956,18 @@ test_read_wired_defroute_no (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wired-defroute-no-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == TRUE, + ASSERT (nm_setting_ip_config_get_never_default (s_ip4) == TRUE, "wired-defroute-no-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT); /* ===== IPv6 SETTING ===== */ @@ -1158,18 +978,18 @@ test_read_wired_defroute_no (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0, "wired-defroute-no-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == TRUE, + ASSERT (nm_setting_ip_config_get_never_default (s_ip6) == TRUE, "wired-defroute-no-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT); g_free (unmanaged); g_free (keyfile); @@ -1187,8 +1007,8 @@ test_read_wired_defroute_no_gatewaydev_yes (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -1201,7 +1021,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, @@ -1263,18 +1082,18 @@ test_read_wired_defroute_no_gatewaydev_yes (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE, + ASSERT (nm_setting_ip_config_get_never_default (s_ip4) == FALSE, "wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT); /* ===== IPv6 SETTING ===== */ @@ -1285,18 +1104,18 @@ test_read_wired_defroute_no_gatewaydev_yes (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); - ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, - "wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value", + tmp = nm_setting_ip_config_get_method (s_ip6); + ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0, + "wired-defroute-no-gatewaydev-yes-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE, - "wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value", + ASSERT (nm_setting_ip_config_get_never_default (s_ip6) == FALSE, + "wired-defroute-no-gatewaydev-yes-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT); g_free (unmanaged); g_free (keyfile); @@ -1305,168 +1124,51 @@ 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) { 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; + NMSettingIPConfig *s_ip4; 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, - NULL, - &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); + NMIPRoute *ip4_route; - 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_ip_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); - - 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); - - 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); - - 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_assert_cmpint (nm_setting_ip_config_get_num_routes (s_ip4), ==, 2); + + ip4_route = nm_setting_ip_config_get_route (s_ip4, 0); + g_assert (ip4_route); + g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "11.22.33.0"); + g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 24); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "192.168.1.5"); + g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, -1); + + ip4_route = nm_setting_ip_config_get_route (s_ip4, 1); + g_assert (ip4_route); + g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "44.55.66.77"); + g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 32); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "192.168.1.7"); + g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, 3); - g_free (unmanaged); - g_free (keyfile); - g_free (routefile); - g_free (route6file); g_object_unref (connection); } @@ -1478,7 +1180,7 @@ test_read_wired_static_routes_legacy (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -1486,20 +1188,12 @@ test_read_wired_static_routes_legacy (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - NMIP4Route *ip4_route; - guint32 addr; + NMIPRoute *ip4_route; const char *expected_id = "System test-wired-static-routes-legacy"; - const char *expected_dst1 = "21.31.41.0"; - const char *expected_dst2 = "32.42.52.62"; - const char *expected_dst3 = "43.53.0.0"; - const char *expected_gw1 = "9.9.9.9"; - const char *expected_gw2 = "8.8.8.8"; - const char *expected_gw3 = "7.7.7.7"; connection = connection_from_file (TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1559,115 +1253,43 @@ test_read_wired_static_routes_legacy (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* Routes */ - ASSERT (nm_setting_ip4_config_get_num_routes (s_ip4) == 3, + ASSERT (nm_setting_ip_config_get_num_routes (s_ip4) == 3, "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); + NM_SETTING_IP_CONFIG_ROUTES); /* Route #1 */ - ip4_route = nm_setting_ip4_config_get_route (s_ip4, 0); - ASSERT (ip4_route, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: missing IP4 route #1", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - - ASSERT (inet_pton (AF_INET, expected_dst1, &addr) > 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert destination IP address #1", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - ASSERT (nm_ip4_route_get_dest (ip4_route) == addr, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_prefix (ip4_route) == 24, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #1 prefix", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - - ASSERT (inet_pton (AF_INET, expected_gw1, &addr) > 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #1", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_metric (ip4_route) == 1, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #1 metric", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); + ip4_route = nm_setting_ip_config_get_route (s_ip4, 0); + g_assert (ip4_route != NULL); + g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "21.31.41.0"); + g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 24); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "9.9.9.9"); + g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, 1); /* Route #2 */ - ip4_route = nm_setting_ip4_config_get_route (s_ip4, 1); - ASSERT (ip4_route, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: missing IP4 route #2", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - - ASSERT (inet_pton (AF_INET, expected_dst2, &addr) > 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert destination IP address #2", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - ASSERT (nm_ip4_route_get_dest (ip4_route) == addr, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_prefix (ip4_route) == 32, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #2 prefix", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - - ASSERT (inet_pton (AF_INET, expected_gw2, &addr) > 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #2", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_metric (ip4_route) == 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #2 metric", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); + ip4_route = nm_setting_ip_config_get_route (s_ip4, 1); + g_assert (ip4_route != NULL); + g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "32.42.52.62"); + g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 32); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "8.8.8.8"); + g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, -1); /* Route #3 */ - ip4_route = nm_setting_ip4_config_get_route (s_ip4, 2); - ASSERT (ip4_route, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: missing IP4 route #3", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - - ASSERT (inet_pton (AF_INET, expected_dst3, &addr) > 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert destination IP address #3", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - ASSERT (nm_ip4_route_get_dest (ip4_route) == addr, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #3", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_prefix (ip4_route) == 16, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #3 prefix", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - - ASSERT (inet_pton (AF_INET, expected_gw3, &addr) > 0, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: couldn't convert next hop IP address #3", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); - ASSERT (nm_ip4_route_get_next_hop (ip4_route) == addr, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value #3", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES); - - ASSERT (nm_ip4_route_get_metric (ip4_route) == 3, - "wired-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected destination route #3 metric", - TEST_IFCFG_WIRED_STATIC_ROUTES_LEGACY); + ip4_route = nm_setting_ip_config_get_route (s_ip4, 2); + g_assert (ip4_route != NULL); + g_assert_cmpstr (nm_ip_route_get_dest (ip4_route), ==, "43.53.0.0"); + g_assert_cmpint (nm_ip_route_get_prefix (ip4_route), ==, 16); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip4_route), ==, "7.7.7.7"); + g_assert_cmpint (nm_ip_route_get_metric (ip4_route), ==, 3); g_free (unmanaged); g_free (keyfile); @@ -1682,7 +1304,7 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -1690,19 +1312,11 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const char *expected_address1 = "1.2.3.4"; - const char *expected_address2 = "9.8.7.6"; - const char *expected_address3 = "3.3.3.3"; - guint32 expected_prefix1 = 24; - guint32 expected_prefix2 = 16; - guint32 expected_prefix3 = 8; - NMIP4Address *ip4_addr; - guint32 addr; + NMIPAddress *ip4_addr; connection = connection_from_file (file, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1756,70 +1370,37 @@ test_read_wired_ipv4_manual (const char *file, const char *expected_id) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* IP addresses */ - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 3, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 3, "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); /* Address #1 */ - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - ASSERT (ip4_addr, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: missing IP4 address #1", - file); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix1, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #1 prefix", - file); - - ASSERT (inet_pton (AF_INET, expected_address1, &addr) > 0, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: couldn't convert IP address #1", - file); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #1", - file); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "1.2.3.4"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); /* Address #2 */ - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 1); - ASSERT (ip4_addr, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: missing IP4 address #2", - file); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix2, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #2 prefix", - file); - - ASSERT (inet_pton (AF_INET, expected_address2, &addr) > 0, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: couldn't convert IP address #2", - file); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #2", - file); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 1); + g_assert (ip4_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "9.8.7.6"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 16); /* Address #3 */ - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 2); - ASSERT (ip4_addr, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: missing IP4 address #3", - file); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix3, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #3 prefix", - file); - - ASSERT (inet_pton (AF_INET, expected_address3, &addr) > 0, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: couldn't convert IP address #3", - file); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - "wired-ipv4-manual-verify-ip4", "failed to verify %s: unexpected IP4 address #3", - file); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 2); + g_assert (ip4_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "3.3.3.3"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8); g_free (unmanaged); g_free (keyfile); @@ -1836,8 +1417,8 @@ test_read_wired_ipv6_manual (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -1846,24 +1427,14 @@ test_read_wired_ipv6_manual (void) GError *error = NULL; const char *tmp; const char *expected_id = "System test-wired-ipv6-manual"; - const char *expected_address1 = "1001:abba::1234"; - const char *expected_address2 = "2001:abba::2234"; - const char *expected_address3 = "3001:abba::3234"; - guint32 expected_prefix1 = 56; - guint32 expected_prefix2 = 64; - guint32 expected_prefix3 = 96; - const char *expected_dns1 = "1:2:3:4::a"; - const char *expected_dns2 = "1:2:3:4::b"; - NMIP6Address *ip6_addr; - NMIP6Route *ip6_route; - struct in6_addr addr; + NMIPAddress *ip6_addr; + NMIPRoute *ip6_route; g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*ignoring manual default route*"); connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_MANUAL, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -1919,54 +1490,54 @@ test_read_wired_ipv6_manual (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2, "wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* DNS search domains */ - ASSERT (nm_setting_ip4_config_get_num_dns_searches (s_ip4) == 3, + ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip4) == 3, "wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 0); + tmp = nm_setting_ip_config_get_dns_search (s_ip4, 0); ASSERT (tmp != NULL, "wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, "lorem.com") == 0, "wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); - tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 1); + tmp = nm_setting_ip_config_get_dns_search (s_ip4, 1); ASSERT (tmp != NULL, "wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, "ipsum.org") == 0, "wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); - tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 2); + tmp = nm_setting_ip_config_get_dns_search (s_ip4, 2); ASSERT (tmp != NULL, "wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, "dolor.edu") == 0, "wired-ipv6-manual-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); /* ===== IPv6 SETTING ===== */ @@ -1977,135 +1548,92 @@ test_read_wired_ipv6_manual (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE, + ASSERT (nm_setting_ip_config_get_never_default (s_ip6) == FALSE, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT); - ASSERT (nm_setting_ip6_config_get_may_fail (s_ip6) == TRUE, + ASSERT (nm_setting_ip_config_get_may_fail (s_ip6) == TRUE, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_MAY_FAIL); + NM_SETTING_IP_CONFIG_MAY_FAIL); /* IP addresses */ - ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 3, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip6) == 3, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); /* Address #1 */ - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); - ASSERT (ip6_addr, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix1, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #1 prefix", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (inet_pton (AF_INET6, expected_address1, &addr) > 0, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr), - "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0); + g_assert (ip6_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "1001:abba::1234"); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56); /* Address #2 */ - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1); - ASSERT (ip6_addr, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 address #2", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix2, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #2 prefix", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (inet_pton (AF_INET6, expected_address2, &addr) > 0, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP address #2", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr), - "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #2", - TEST_IFCFG_WIRED_IPV6_MANUAL); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 1); + g_assert (ip6_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "2001:abba::2234"); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64); /* Address #3 */ - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 2); - ASSERT (ip6_addr, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 address #3", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix3, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #3 prefix", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (inet_pton (AF_INET6, expected_address3, &addr) > 0, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP address #3", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr), - "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 address #3", - TEST_IFCFG_WIRED_IPV6_MANUAL); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 2); + g_assert (ip6_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "3001:abba::3234"); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 96); /* Routes */ - g_assert_cmpint (nm_setting_ip6_config_get_num_routes (s_ip6), ==, 2); + g_assert_cmpint (nm_setting_ip_config_get_num_routes (s_ip6), ==, 2); /* Route #1 */ - ip6_route = nm_setting_ip6_config_get_route (s_ip6, 0); + ip6_route = nm_setting_ip_config_get_route (s_ip6, 0); g_assert (ip6_route); - g_assert_cmpint (inet_pton (AF_INET6, "9876::1234", &addr), >, 0); - g_assert_cmpint (memcmp (nm_ip6_route_get_dest (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); - g_assert_cmpint (nm_ip6_route_get_prefix (ip6_route), ==, 96); - g_assert_cmpint (inet_pton (AF_INET6, "9876::7777", &addr), >, 0); - g_assert_cmpint (memcmp (nm_ip6_route_get_next_hop (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); - g_assert_cmpint (nm_ip6_route_get_metric (ip6_route), ==, 2); + g_assert_cmpstr (nm_ip_route_get_dest (ip6_route), ==, "9876::1234"); + g_assert_cmpint (nm_ip_route_get_prefix (ip6_route), ==, 96); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip6_route), ==, "9876::7777"); + g_assert_cmpint (nm_ip_route_get_metric (ip6_route), ==, 2); /* Route #2 */ - ip6_route = nm_setting_ip6_config_get_route (s_ip6, 1); + ip6_route = nm_setting_ip_config_get_route (s_ip6, 1); g_assert (ip6_route); - g_assert_cmpint (inet_pton (AF_INET6, "abbe::cafe", &addr), >, 0); - g_assert_cmpint (memcmp (nm_ip6_route_get_dest (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); - g_assert_cmpint (nm_ip6_route_get_prefix (ip6_route), ==, 64); - g_assert_cmpint (inet_pton (AF_INET6, "::", &addr), >, 0); - g_assert_cmpint (memcmp (nm_ip6_route_get_next_hop (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); - g_assert_cmpint (nm_ip6_route_get_metric (ip6_route), ==, 777); + g_assert_cmpstr (nm_ip_route_get_dest (ip6_route), ==, "abbe::cafe"); + g_assert_cmpint (nm_ip_route_get_prefix (ip6_route), ==, 64); + g_assert_cmpstr (nm_ip_route_get_next_hop (ip6_route), ==, NULL); + g_assert_cmpint (nm_ip_route_get_metric (ip6_route), ==, 777); /* DNS Addresses */ - ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 2, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr), + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET6, expected_dns2, &addr) > 0, - "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #2", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr), + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 1), "1:2:3:4::b") == 0, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value #2", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* DNS domains - none as domains are stuffed to 'ipv4' setting */ - ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 0, + ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip6) == 0, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); g_free (unmanaged); g_free (keyfile); @@ -2122,8 +1650,8 @@ test_read_wired_ipv6_only (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -2132,17 +1660,12 @@ test_read_wired_ipv6_only (void) GError *error = NULL; const char *tmp; const char *expected_id = "System test-wired-ipv6-only"; - const char *expected_address1 = "1001:abba::1234"; - guint32 expected_prefix1 = 56; - const char *expected_dns1 = "1:2:3:4::a"; - NMIP6Address *ip6_addr; - struct in6_addr addr; + NMIPAddress *ip6_addr; const char *method; connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_ONLY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2195,12 +1718,12 @@ test_read_wired_ipv6_only (void) TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME); - method = nm_setting_ip4_config_get_method (s_ip4); + method = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0, "wired-ipv6-only-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* ===== IPv6 SETTING ===== */ @@ -2211,58 +1734,44 @@ test_read_wired_ipv6_only (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* IP addresses */ - ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip6) == 1, "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); /* Address #1 */ - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); - ASSERT (ip6_addr, - "wired-ipv6-only-verify-ip6", "failed to verify %s: missing IP6 address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix1, - "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected IP6 address #1 prefix", - TEST_IFCFG_WIRED_IPV6_MANUAL); - - ASSERT (inet_pton (AF_INET6, expected_address1, &addr) > 0, - "wired-ipv6-only-verify-ip6", "failed to verify %s: couldn't convert IP address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr), - "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected IP6 address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0); + g_assert (ip6_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "1001:abba::1234"); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 56); /* DNS Addresses */ - ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 1, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 1, "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0, - "wired-ipv6-only-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #1", - TEST_IFCFG_WIRED_IPV6_MANUAL); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr), + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "1:2:3:4::a") == 0, "wired-ipv6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1", TEST_IFCFG_WIRED_IPV6_MANUAL, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* DNS domains should be in IPv6, because IPv4 is disabled */ - g_assert_cmpint (nm_setting_ip6_config_get_num_dns_searches (s_ip6), ==, 3); - g_assert_cmpstr (nm_setting_ip6_config_get_dns_search (s_ip6, 0), ==, "lorem.com"); - g_assert_cmpstr (nm_setting_ip6_config_get_dns_search (s_ip6, 1), ==, "ipsum.org"); - g_assert_cmpstr (nm_setting_ip6_config_get_dns_search (s_ip6, 2), ==, "dolor.edu"); + g_assert_cmpint (nm_setting_ip_config_get_num_dns_searches (s_ip6), ==, 3); + g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 0), ==, "lorem.com"); + g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 1), ==, "ipsum.org"); + g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip6, 2), ==, "dolor.edu"); g_free (unmanaged); g_free (keyfile); @@ -2279,8 +1788,8 @@ test_read_wired_dhcp6_only (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -2294,7 +1803,6 @@ test_read_wired_dhcp6_only (void) connection = connection_from_file (TEST_IFCFG_WIRED_DHCP6_ONLY, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2347,12 +1855,12 @@ test_read_wired_dhcp6_only (void) TEST_IFCFG_WIRED_DHCP6_ONLY, NM_SETTING_IP4_CONFIG_SETTING_NAME); - method = nm_setting_ip4_config_get_method (s_ip4); + method = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0, "wired-dhcp6-only-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP6_ONLY, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* ===== IPv6 SETTING ===== */ @@ -2363,12 +1871,12 @@ test_read_wired_dhcp6_only (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0, "wired-dhcp6-only-verify-ip6", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_DHCP6_ONLY, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -2394,7 +1902,6 @@ test_read_onboot_no (void) connection = connection_from_file (TEST_IFCFG_ONBOOT_NO, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2438,8 +1945,8 @@ static void test_read_noip (void) { NMConnection *connection; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -2450,7 +1957,6 @@ test_read_noip (void) connection = connection_from_file (TEST_IFCFG_NOIP, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2463,13 +1969,13 @@ test_read_noip (void) 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_DISABLED); - g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert (nm_setting_ip_config_get_never_default (s_ip4) == FALSE); s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip6); - g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); - g_assert (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert (nm_setting_ip_config_get_never_default (s_ip6) == FALSE); g_free (unmanaged); g_free (keyfile); @@ -2486,7 +1992,7 @@ test_read_wired_8021x_peap_mschapv2 (void) { NMConnection *connection; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSetting8021x *s_8021x; NMSetting8021x *tmp_8021x; char *unmanaged = NULL; @@ -2506,7 +2012,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, @@ -2539,12 +2044,12 @@ test_read_wired_8021x_peap_mschapv2 (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wired-8021x-peap-mschapv2-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* ===== 802.1x SETTING ===== */ s_8021x = nm_connection_get_setting_802_1x (connection); @@ -2700,7 +2205,6 @@ test_read_wired_8021x_tls_secret_flags (const char *ifcfg, NMSettingSecretFlags connection = connection_from_file (ifcfg, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2757,7 +2261,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); @@ -2786,12 +2290,12 @@ test_read_write_802_1X_subj_matches (void) g_assert (success); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* 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); @@ -2840,7 +2344,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); @@ -2869,7 +2373,7 @@ test_read_wired_aliases_good (void) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -2878,16 +2382,15 @@ test_read_wired_aliases_good (void) GError *error = NULL; const char *tmp; const char *expected_id = "System aliasem0"; - int expected_num_addresses = 4, expected_prefix = 24; + int expected_num_addresses = 4; const char *expected_address[4] = { "192.168.1.5", "192.168.1.6", "192.168.1.9", "192.168.1.99" }; const char *expected_label[4] = { NULL, "aliasem0:1", "aliasem0:2", "aliasem0:99" }; - const char *expected_gateway[4] = { "192.168.1.1", "192.168.1.1", "192.168.1.1", "192.168.1.1" }; + const char *expected_gateway = "192.168.1.1"; int i, j; connection = connection_from_file (TEST_IFCFG_ALIASES_GOOD, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -2930,74 +2433,51 @@ test_read_wired_aliases_good (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, "aliases-good-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_ALIASES_GOOD, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == expected_num_addresses, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == expected_num_addresses, "aliases-good-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_ALIASES_GOOD, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); /* Addresses */ for (i = 0; i < expected_num_addresses; i++) { - NMIP4Address *ip4_addr; - char buf[INET_ADDRSTRLEN]; - struct in_addr addr; + NMIPAddress *ip4_addr; + const char *addr; + GVariant *label; - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, i); - ASSERT (ip4_addr, - "aliases-good-verify-ip4", "failed to verify %s: missing IP4 address #%d", - TEST_IFCFG_ALIASES_GOOD, - i); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, i); + g_assert (ip4_addr != NULL); - addr.s_addr = nm_ip4_address_get_address (ip4_addr); - ASSERT (inet_ntop (AF_INET, &addr, buf, sizeof (buf)) > 0, - "aliases-good-verify-ip4", "failed to verify %s: couldn't convert IP address #%d", - TEST_IFCFG_ALIASES_GOOD, - i); + addr = nm_ip_address_get_address (ip4_addr); + g_assert (nm_utils_ipaddr_valid (AF_INET, addr)); for (j = 0; j < expected_num_addresses; j++) { - if (!g_strcmp0 (buf, expected_address[j])) + if (!g_strcmp0 (addr, expected_address[j])) break; } + g_assert (j < expected_num_addresses); - ASSERT (j < expected_num_addresses, - "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address #%d", - TEST_IFCFG_ALIASES_GOOD, - i); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix, - "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address prefix #%d", - TEST_IFCFG_ALIASES_GOOD, - i); - - if (expected_gateway[j]) { - ASSERT (inet_pton (AF_INET, expected_gateway[j], &addr) > 0, - "aliases-good-verify-ip4", "failed to verify %s: couldn't convert IP address gateway #%d", - TEST_IFCFG_ALIASES_GOOD, - i); - } else - addr.s_addr = 0; - ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr.s_addr, - "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address gateway #%d", - TEST_IFCFG_ALIASES_GOOD, - i); - - ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)), expected_label[j]) == 0, - "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d", - TEST_IFCFG_ALIASES_GOOD, - i); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); + label = nm_ip_address_get_attribute (ip4_addr, "label"); + if (expected_label[j]) + g_assert_cmpstr (g_variant_get_string (label, NULL), ==, expected_label[j]); + else + g_assert (label == NULL); expected_address[j] = NULL; - expected_gateway[j] = NULL; expected_label[j] = NULL; } + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, expected_gateway); + for (i = 0; i < expected_num_addresses; i++) { ASSERT (expected_address[i] == NULL, "aliases-good-verify-ip4", "failed to verify %s: did not find IP4 address %s", @@ -3016,7 +2496,7 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -3024,17 +2504,11 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - int expected_num_addresses = 1, expected_prefix = 24; - const char *expected_address = "192.168.1.5"; - const char *expected_label = NULL; - const char *expected_gateway = "192.168.1.1"; - NMIP4Address *ip4_addr; - struct in_addr addr; + NMIPAddress *ip4_addr; connection = connection_from_file (base, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -3078,46 +2552,28 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, "aliases-bad-verify-ip4", "failed to verify %s: unexpected %s / %s key value", base, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == expected_num_addresses, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1, "aliases-bad-verify-ip4", "failed to verify %s: unexpected %s / %s key value", base, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); /* Addresses */ - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - ASSERT (ip4_addr, - "aliases-bad-verify-ip4", "failed to verify %s: missing IP4 address", - base); - - ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0, - "aliases-bad-verify-ip4", "failed to verify %s: couldn't convert IP address", - base); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr.s_addr, - "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address", - base); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix, - "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address prefix", - base); - - ASSERT (inet_pton (AF_INET, expected_gateway, &addr) > 0, - "aliases-bad-verify-ip4", "failed to verify %s: couldn't convert IP address gateway", - base); - ASSERT (nm_ip4_address_get_gateway (ip4_addr) == addr.s_addr, - "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address gateway", - base); - - ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)), expected_label) == 0, - "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address label", - base); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.1.5"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24); + g_assert (nm_ip_address_get_attribute (ip4_addr, "label") == NULL); + + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.1.1"); g_free (keyfile); g_free (routefile); @@ -3154,7 +2610,7 @@ test_read_wifi_open (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -3162,7 +2618,8 @@ test_read_wifi_open (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; const char *expected_id = "System blahblah (test-wifi-open)"; guint64 expected_timestamp = 0; @@ -3173,7 +2630,6 @@ test_read_wifi_open (void) connection = connection_from_file (TEST_IFCFG_WIFI_OPEN, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3226,6 +2682,8 @@ test_read_wifi_open (void) NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT); + g_assert_cmpint (nm_setting_connection_get_autoconnect_priority (s_con), ==, -1); + /* ===== WIRELESS SETTING ===== */ s_wireless = nm_connection_get_setting_wireless (connection); @@ -3235,18 +2693,13 @@ test_read_wifi_open (void) NM_SETTING_WIRELESS_SETTING_NAME); /* MAC address */ - array = nm_setting_wireless_get_mac_address (s_wireless); - ASSERT (array != NULL, + mac = nm_setting_wireless_get_mac_address (s_wireless); + ASSERT (mac != NULL, "wifi-open-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_OPEN, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "wifi-open-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_WIFI_OPEN, - NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "wifi-open-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_OPEN, NM_SETTING_WIRELESS_SETTING_NAME, @@ -3258,18 +2711,18 @@ test_read_wifi_open (void) NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MTU); - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-open-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_OPEN, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-open-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_OPEN, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-open-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_OPEN, NM_SETTING_WIRELESS_SETTING_NAME, @@ -3312,12 +2765,12 @@ test_read_wifi_open (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-open-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_OPEN, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -3347,7 +2800,6 @@ test_read_wifi_open_auto (void) connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_AUTO, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3423,14 +2875,13 @@ test_read_wifi_open_ssid_hex (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; const char *expected_id = "System blahblah (test-wifi-open-ssid-hex)"; const char *expected_ssid = "blahblah"; connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_SSID_HEX, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3473,18 +2924,18 @@ test_read_wifi_open_ssid_hex (void) NM_SETTING_WIRELESS_SETTING_NAME); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-open-ssid-hex-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_OPEN_SSID_HEX, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-open-ssid-hex-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_OPEN_SSID_HEX, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-open-ssid-hex-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_OPEN_SSID_HEX, NM_SETTING_WIRELESS_SETTING_NAME, @@ -3511,7 +2962,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, @@ -3542,14 +2992,13 @@ test_read_wifi_open_ssid_quoted (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; const char *expected_id = "System foo\"bar\\ (test-wifi-open-ssid-quoted)"; const char *expected_ssid = "foo\"bar\\"; connection = connection_from_file (TEST_IFCFG_WIFI_OPEN_SSID_QUOTED, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3592,18 +3041,18 @@ test_read_wifi_open_ssid_quoted (void) NM_SETTING_WIRELESS_SETTING_NAME); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-open-ssid-quoted-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_OPEN_SSID_QUOTED, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-open-ssid-quoted-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_OPEN_SSID_QUOTED, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-open-ssid-quoted-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_OPEN_SSID_QUOTED, NM_SETTING_WIRELESS_SETTING_NAME, @@ -3625,7 +3074,7 @@ test_read_wifi_wep (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -3633,7 +3082,8 @@ test_read_wifi_wep (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; const char *expected_id = "System blahblah (test-wifi-wep)"; guint64 expected_timestamp = 0; @@ -3646,7 +3096,6 @@ test_read_wifi_wep (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3708,18 +3157,13 @@ test_read_wifi_wep (void) NM_SETTING_WIRELESS_SETTING_NAME); /* MAC address */ - array = nm_setting_wireless_get_mac_address (s_wireless); - ASSERT (array != NULL, + mac = nm_setting_wireless_get_mac_address (s_wireless); + ASSERT (mac != NULL, "wifi-wep-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_WEP, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "wifi-wep-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_WIFI_WEP, - NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "wifi-wep-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP, NM_SETTING_WIRELESS_SETTING_NAME, @@ -3733,18 +3177,18 @@ test_read_wifi_wep (void) NM_SETTING_WIRELESS_MTU); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-wep-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_WEP, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-wep-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_WEP, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-wep-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP, NM_SETTING_WIRELESS_SETTING_NAME, @@ -3865,12 +3309,12 @@ test_read_wifi_wep (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wep-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -3888,7 +3332,7 @@ test_read_wifi_wep_adhoc (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -3896,19 +3340,15 @@ test_read_wifi_wep_adhoc (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; const char *expected_id = "System blahblah (test-wifi-wep-adhoc)"; const char *expected_ssid = "blahblah"; const char *expected_mode = "adhoc"; const char *expected_wep_key0 = "0123456789abcdef0123456789"; - guint32 addr; - const char *expected_dns1 = "4.2.2.1"; - const char *expected_dns2 = "4.2.2.2"; connection = connection_from_file (TEST_IFCFG_WIFI_WEP_ADHOC, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -3963,18 +3403,18 @@ test_read_wifi_wep_adhoc (void) NM_SETTING_WIRELESS_SETTING_NAME); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-wep-adhoc-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-wep-adhoc-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-wep-adhoc-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_WIRELESS_SETTING_NAME, @@ -4083,48 +3523,38 @@ test_read_wifi_wep_adhoc (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* Ignore auto DNS */ - ASSERT (nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) == TRUE, + ASSERT (nm_setting_ip_config_get_ignore_auto_dns (s_ip4) == TRUE, "wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS); + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS); /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2, "wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0, - "wifi-wep-adhoc-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #1", - TEST_IFCFG_WIFI_WEP_ADHOC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr, + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "4.2.2.1") == 0, "wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value #1", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0, - "wifi-wep-adhoc-verify-ip4", "failed to verify %s: couldn't convert DNS IP address #2", - TEST_IFCFG_WIFI_WEP_ADHOC, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr, + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "4.2.2.2") == 0, "wifi-wep-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value #2", TEST_IFCFG_WIFI_WEP_ADHOC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); g_free (unmanaged); g_free (keyfile); @@ -4155,7 +3585,6 @@ test_read_wifi_wep_passphrase (void) connection = connection_from_file (TEST_IFCFG_WIFI_WEP_PASSPHRASE, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4281,7 +3710,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, @@ -4405,7 +3833,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, @@ -4530,7 +3957,6 @@ test_read_wifi_leap (void) connection = connection_from_file (TEST_IFCFG_WIFI_LEAP, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4654,7 +4080,6 @@ test_read_wifi_leap_secret_flags (const char *file, NMSettingSecretFlags expecte connection = connection_from_file (file, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4699,7 +4124,7 @@ test_read_wifi_wpa_psk (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -4707,7 +4132,8 @@ test_read_wifi_wpa_psk (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; const char *expected_id = "System blahblah (test-wifi-wpa-psk)"; guint64 expected_timestamp = 0; @@ -4729,7 +4155,6 @@ test_read_wifi_wpa_psk (void) connection = connection_from_file (TEST_IFCFG_WIFI_WPA_PSK, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -4791,18 +4216,13 @@ test_read_wifi_wpa_psk (void) NM_SETTING_WIRELESS_SETTING_NAME); /* MAC address */ - array = nm_setting_wireless_get_mac_address (s_wireless); - ASSERT (array != NULL, + mac = nm_setting_wireless_get_mac_address (s_wireless); + ASSERT (mac != NULL, "wifi-wpa-psk-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_WPA_PSK, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "wifi-wpa-psk-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_WIFI_WPA_PSK, - NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "wifi-wpa-psk-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_PSK, NM_SETTING_WIRELESS_SETTING_NAME, @@ -4816,18 +4236,18 @@ test_read_wifi_wpa_psk (void) NM_SETTING_WIRELESS_MTU); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-wpa-psk-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_WPA_PSK, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-wpa-psk-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_WPA_PSK, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-wpa-psk-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_PSK, NM_SETTING_WIRELESS_SETTING_NAME, @@ -4982,12 +4402,12 @@ test_read_wifi_wpa_psk (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wpa-psk-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_PSK, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -5018,7 +4438,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, @@ -5110,7 +4529,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, @@ -5200,7 +4618,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, @@ -5226,7 +4643,7 @@ test_read_wifi_wpa_psk_adhoc (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -5244,7 +4661,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, @@ -5382,12 +4798,12 @@ test_read_wifi_wpa_psk_adhoc (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wpa-psk-adhoc-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_PSK_ADHOC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -5405,7 +4821,7 @@ test_read_wifi_wpa_psk_hex (void) NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -5413,7 +4829,7 @@ test_read_wifi_wpa_psk_hex (void) gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; - const GByteArray *array; + GBytes *ssid; const char *expected_id = "System blahblah (test-wifi-wpa-psk-hex)"; const char *expected_ssid = "blahblah"; const char *expected_key_mgmt = "wpa-psk"; @@ -5422,7 +4838,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, @@ -5465,18 +4880,18 @@ test_read_wifi_wpa_psk_hex (void) NM_SETTING_WIRELESS_SETTING_NAME); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "wifi-wpa-psk-hex-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_IFCFG_WIFI_WPA_PSK_HEX, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (array->len == strlen (expected_ssid), + ASSERT (g_bytes_get_size (ssid) == strlen (expected_ssid), "wifi-wpa-psk-hex-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", TEST_IFCFG_WIFI_WPA_PSK_HEX, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - ASSERT (memcmp (array->data, expected_ssid, strlen (expected_ssid)) == 0, + ASSERT (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0, "wifi-wpa-psk-hex-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_PSK_HEX, NM_SETTING_WIRELESS_SETTING_NAME, @@ -5525,12 +4940,12 @@ test_read_wifi_wpa_psk_hex (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wpa-psk-hex-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_PSK_HEX, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -5549,7 +4964,7 @@ test_read_wifi_wpa_eap_tls (void) { NMConnection *connection; NMSettingWireless *s_wireless; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSetting8021x *s_8021x; char *unmanaged = NULL; char *keyfile = NULL; @@ -5564,7 +4979,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, @@ -5597,12 +5011,12 @@ test_read_wifi_wpa_eap_tls (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wpa-eap-tls-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_EAP_TLS, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* ===== 802.1x SETTING ===== */ s_8021x = nm_connection_get_setting_802_1x (connection); @@ -5690,7 +5104,7 @@ test_read_wifi_wpa_eap_ttls_tls (void) { NMConnection *connection; NMSettingWireless *s_wireless; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSetting8021x *s_8021x; char *unmanaged = NULL; char *keyfile = NULL; @@ -5705,7 +5119,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, @@ -5738,12 +5151,12 @@ test_read_wifi_wpa_eap_ttls_tls (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wpa-eap-ttls-tls-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WPA_EAP_TTLS_TLS, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* ===== 802.1x SETTING ===== */ s_8021x = nm_connection_get_setting_802_1x (connection); @@ -5860,7 +5273,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, @@ -5923,7 +5335,7 @@ test_read_wifi_wep_eap_ttls_chap (void) NMConnection *connection; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSetting8021x *s_8021x; char *unmanaged = NULL; char *keyfile = NULL; @@ -5939,7 +5351,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, @@ -5972,12 +5383,12 @@ test_read_wifi_wep_eap_ttls_chap (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "wifi-wep-eap-ttls-chap-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIFI_WEP_EAP_TTLS_CHAP, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* ===== 802.1x SETTING ===== */ s_wsec = nm_connection_get_setting_wireless_security (connection); @@ -6086,7 +5497,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); @@ -6115,10 +5526,10 @@ test_write_wifi_hidden (void) gboolean success; GError *error = NULL; shvarFile *f; - GByteArray *ssid; + GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -6136,8 +5547,7 @@ test_write_wifi_hidden (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, sizeof (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -6145,7 +5555,7 @@ test_write_wifi_hidden (void) NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); success = nm_connection_verify (connection, &error); g_assert_no_error (error); @@ -6171,10 +5581,124 @@ test_write_wifi_hidden (void) svCloseFile (f); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); + + /* re-read the connection for comparison */ + reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, + NULL, NULL, NULL, NULL, &error, NULL); + unlink (testfile); + g_assert_no_error (error); + g_assert (reread); + + success = nm_connection_verify (reread, &error); + g_assert_no_error (error); + g_assert (success); + + g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + + g_free (testfile); + g_object_unref (connection); + g_object_unref (reread); +} + +static void +test_read_wifi_band_a (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + gboolean success; + GError *error = NULL; + + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-band-a", + NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); + g_assert_no_error (error); + g_assert (connection); + + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); + + 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_WIRELESS_SETTING_NAME); + + s_wifi = nm_connection_get_setting_wireless (connection); + g_assert (s_wifi); + g_assert_cmpstr (nm_setting_wireless_get_band (s_wifi), ==, "a"); + + g_object_unref (connection); +} + +static void +test_write_wifi_band_a (void) +{ + NMConnection *connection, *reread; + NMSettingConnection *s_con; + NMSettingWireless *s_wifi; + char *uuid, *testfile = NULL, *val; + gboolean success; + GError *error = NULL; + shvarFile *f; + GBytes *ssid; + const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; + + connection = nm_simple_connection_new (); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new (); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + uuid = nm_utils_uuid_generate (); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "Test Write WiFi Band A", + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + g_free (uuid); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); + nm_connection_add_setting (connection, NM_SETTING (s_wifi)); + + ssid = g_bytes_new (ssid_data, sizeof (ssid_data)); + + g_object_set (s_wifi, + NM_SETTING_WIRELESS_SSID, ssid, + NM_SETTING_WIRELESS_MODE, "infrastructure", + NM_SETTING_WIRELESS_BAND, "a", + NULL); + + g_bytes_unref (ssid); + + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); + + /* Save the ifcfg */ + success = writer_new_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + &testfile, + &error); + g_assert_no_error (error); + g_assert (success); + + f = svOpenFile (testfile, &error); + g_assert_no_error (error); + g_assert (f); + + /* re-read the file to check that what key was written. */ + val = svGetValue (f, "BAND", FALSE); + g_assert (val); + g_assert_cmpstr (val, ==, "a"); + g_free (val); + svCloseFile (f); + + /* reread will be normalized, so we must normalize connection too. */ + 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); @@ -6191,6 +5715,30 @@ test_write_wifi_hidden (void) g_object_unref (reread); } +static void +test_read_wifi_band_a_channel_mismatch (void) +{ + NMConnection *connection; + GError *error = NULL; + + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch", + NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); + g_assert (connection == NULL); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); +} + +static void +test_read_wifi_band_bg_channel_mismatch (void) +{ + NMConnection *connection; + GError *error = NULL; + + connection = connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch", + NULL, TYPE_WIRELESS, NULL, NULL, NULL, NULL, &error, NULL); + g_assert (connection == NULL); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); +} + #define TEST_IFCFG_WIRED_QETH_STATIC TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-qeth-static" static void @@ -6199,7 +5747,7 @@ test_read_wired_qeth_static (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; @@ -6208,16 +5756,15 @@ test_read_wired_qeth_static (void) GError *error = NULL; const char *tmp; const char *expected_id = "System test-wired-qeth-static"; - const GByteArray *array; + const char *mac; const char *expected_channel0 = "0.0.0600"; const char *expected_channel1 = "0.0.0601"; const char *expected_channel2 = "0.0.0602"; - const GPtrArray *subchannels; + const char * const *subchannels; connection = connection_from_file (TEST_IFCFG_WIRED_QETH_STATIC, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6263,8 +5810,8 @@ test_read_wired_qeth_static (void) NM_SETTING_WIRED_SETTING_NAME); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - ASSERT (array == NULL, + mac = nm_setting_wired_get_mac_address (s_wired); + ASSERT (mac == NULL, "wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s / %s key", TEST_IFCFG_WIRED_QETH_STATIC, NM_SETTING_WIRED_SETTING_NAME, @@ -6277,24 +5824,19 @@ test_read_wired_qeth_static (void) TEST_IFCFG_WIRED_QETH_STATIC, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_SUBCHANNELS); - ASSERT (subchannels->len == 3, + ASSERT (subchannels[0] && subchannels[1] && subchannels[2] && !subchannels[3], "wired-qeth-static-verify-wired", "failed to verify %s: invalid %s / %s key (not 3 elements)", TEST_IFCFG_WIRED_QETH_STATIC, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_SUBCHANNELS); - tmp = (const char *) g_ptr_array_index (subchannels, 0); - ASSERT (strcmp (tmp, expected_channel0) == 0, + ASSERT (strcmp (subchannels[0], expected_channel0) == 0, "wired-qeth-static-verify-wired", "failed to verify %s: unexpected subchannel #0", TEST_IFCFG_WIRED_QETH_STATIC); - - tmp = (const char *) g_ptr_array_index (subchannels, 1); - ASSERT (strcmp (tmp, expected_channel1) == 0, + ASSERT (strcmp (subchannels[1], expected_channel1) == 0, "wired-qeth-static-verify-wired", "failed to verify %s: unexpected subchannel #1", TEST_IFCFG_WIRED_QETH_STATIC); - - tmp = (const char *) g_ptr_array_index (subchannels, 2); - ASSERT (strcmp (tmp, expected_channel2) == 0, + ASSERT (strcmp (subchannels[2], expected_channel2) == 0, "wired-qeth-static-verify-wired", "failed to verify %s: unexpected subchannel #2", TEST_IFCFG_WIRED_QETH_STATIC); @@ -6353,12 +5895,12 @@ test_read_wired_qeth_static (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, "wired-qeth-static-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_WIRED_QETH_STATIC, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_free (unmanaged); g_free (keyfile); @@ -6385,13 +5927,12 @@ test_read_wired_ctc_static (void) const char *expected_id = "System test-wired-ctc-static"; const char *expected_channel0 = "0.0.1b00"; const char *expected_channel1 = "0.0.1b01"; - const GPtrArray *subchannels; + const char * const *subchannels; gboolean success; connection = connection_from_file (TEST_IFCFG_WIRED_CTC_STATIC, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6420,10 +5961,10 @@ test_read_wired_ctc_static (void) /* Subchannels */ subchannels = nm_setting_wired_get_s390_subchannels (s_wired); g_assert (subchannels != NULL); - g_assert_cmpint (subchannels->len, ==, 2); + g_assert (subchannels[0] && subchannels[1] && !subchannels[2]); - g_assert_cmpstr (g_ptr_array_index (subchannels, 0), ==, expected_channel0); - g_assert_cmpstr (g_ptr_array_index (subchannels, 1), ==, expected_channel1); + g_assert_cmpstr (subchannels[0], ==, expected_channel0); + g_assert_cmpstr (subchannels[1], ==, expected_channel1); /* Nettype */ g_assert_cmpstr (nm_setting_wired_get_s390_nettype (s_wired), ==, "ctc"); @@ -6462,7 +6003,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, @@ -6572,7 +6112,6 @@ test_read_permissions (void) connection = connection_from_file (TEST_IFCFG_PERMISSIONS, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6648,7 +6187,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, @@ -6699,30 +6237,22 @@ test_write_wired_static (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4, *reread_s_ip4; - NMSettingIP6Config *s_ip6, *reread_s_ip6; - static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac; + NMSettingIPConfig *s_ip4, *reread_s_ip4; + NMSettingIPConfig *s_ip6, *reread_s_ip6; + static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; char *uuid; - const guint32 ip1 = htonl (0x01010103); - const guint32 ip2 = htonl (0x01010105); - const guint32 gw = htonl (0x01010101); - const guint32 dns1 = htonl (0x04020201); - const guint32 dns2 = htonl (0x04020202); - const guint32 prefix = 24; + const char *dns1 = "4.2.2.1"; + const char *dns2 = "4.2.2.2"; const char *dns_search1 = "foobar.com"; const char *dns_search2 = "lab.foobar.com"; const char *dns_search3 = "foobar6.com"; const char *dns_search4 = "lab6.foobar.com"; - struct in6_addr ip6, ip6_1, ip6_2; - struct in6_addr route1_dest, route2_dest, route1_nexthop, route2_nexthop; - struct in6_addr dns6_1, dns6_2; - const guint32 route1_prefix = 64, route2_prefix = 128; - const guint32 route1_metric = 99, route2_metric = 1; - NMIP4Address *addr; - NMIP6Address *addr6; - NMIP6Route *route6; + const char *dns6_1 = "fade:0102:0103::face"; + const char *dns6_2 = "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed"; + NMIPAddress *addr; + NMIPAddress *addr6; + NMIPRoute *route6; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -6732,17 +6262,7 @@ test_write_wired_static (void) char *route6file = NULL; gboolean ignore_error = FALSE; - inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6); - inet_pton (AF_INET6, "2003:1234:abcd::2", &ip6_1); - inet_pton (AF_INET6, "3003:1234:abcd::3", &ip6_2); - inet_pton (AF_INET6, "2222:aaaa:bbbb:cccc::", &route1_dest); - inet_pton (AF_INET6, "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", &route1_nexthop); - inet_pton (AF_INET6, "::", &route2_dest); - inet_pton (AF_INET6, "2222:aaaa::9999", &route2_nexthop); - inet_pton (AF_INET6, "fade:0102:0103::face", &dns6_1); - inet_pton (AF_INET6, "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed", &dns6_2); - - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -6761,96 +6281,82 @@ test_write_wired_static (void) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", NULL); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip2); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.5", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); - nm_setting_ip4_config_add_dns (s_ip4, dns1); - nm_setting_ip4_config_add_dns (s_ip4, dns2); + nm_setting_ip_config_add_dns (s_ip4, dns1); + nm_setting_ip_config_add_dns (s_ip4, dns2); - nm_setting_ip4_config_add_dns_search (s_ip4, dns_search1); - nm_setting_ip4_config_add_dns_search (s_ip4, dns_search2); + nm_setting_ip_config_add_dns_search (s_ip4, dns_search1); + nm_setting_ip_config_add_dns_search (s_ip4, dns_search2); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* Add addresses */ - addr6 = nm_ip6_address_new (); - nm_ip6_address_set_address (addr6, &ip6); - nm_ip6_address_set_prefix (addr6, 11); - nm_setting_ip6_config_add_address (s_ip6, addr6); - nm_ip6_address_unref (addr6); - - addr6 = nm_ip6_address_new (); - nm_ip6_address_set_address (addr6, &ip6_1); - nm_ip6_address_set_prefix (addr6, 22); - nm_setting_ip6_config_add_address (s_ip6, addr6); - nm_ip6_address_unref (addr6); - - addr6 = nm_ip6_address_new (); - nm_ip6_address_set_address (addr6, &ip6_2); - nm_ip6_address_set_prefix (addr6, 33); - nm_setting_ip6_config_add_address (s_ip6, addr6); - nm_ip6_address_unref (addr6); + addr6 = nm_ip_address_new (AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip6, addr6); + nm_ip_address_unref (addr6); + + addr6 = nm_ip_address_new (AF_INET6, "2003:1234:abcd::2", 22, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip6, addr6); + nm_ip_address_unref (addr6); + + addr6 = nm_ip_address_new (AF_INET6, "3003:1234:abcd::3", 33, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip6, addr6); + nm_ip_address_unref (addr6); /* Add routes */ - route6 = nm_ip6_route_new (); - nm_ip6_route_set_dest (route6, &route1_dest); - nm_ip6_route_set_prefix (route6, route1_prefix); - nm_ip6_route_set_next_hop (route6, &route1_nexthop); - nm_ip6_route_set_metric (route6, route1_metric); - nm_setting_ip6_config_add_route (s_ip6, route6); - nm_ip6_route_unref (route6); - - route6 = nm_ip6_route_new (); - nm_ip6_route_set_dest (route6, &route2_dest); - nm_ip6_route_set_prefix (route6, route2_prefix); - nm_ip6_route_set_next_hop (route6, &route2_nexthop); - nm_ip6_route_set_metric (route6, route2_metric); - nm_setting_ip6_config_add_route (s_ip6, route6); - nm_ip6_route_unref (route6); + route6 = nm_ip_route_new (AF_INET6, + "2222:aaaa:bbbb:cccc::", 64, + "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", 99, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_route (s_ip6, route6); + nm_ip_route_unref (route6); + + route6 = nm_ip_route_new (AF_INET6, "::", 128, "2222:aaaa::9999", 1, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_route (s_ip6, route6); + nm_ip_route_unref (route6); /* DNS servers */ - nm_setting_ip6_config_add_dns (s_ip6, &dns6_1); - nm_setting_ip6_config_add_dns (s_ip6, &dns6_2); + nm_setting_ip_config_add_dns (s_ip6, dns6_1); + nm_setting_ip_config_add_dns (s_ip6, dns6_2); /* DNS domains */ - nm_setting_ip6_config_add_dns_search (s_ip6, dns_search3); - nm_setting_ip6_config_add_dns_search (s_ip6, dns_search4); + nm_setting_ip_config_add_dns_search (s_ip6, dns_search3); + nm_setting_ip_config_add_dns_search (s_ip6, dns_search4); ASSERT (nm_connection_verify (connection, &error) == TRUE, "wired-static-write", "failed to verify connection: %s", @@ -6869,13 +6375,12 @@ test_write_wired_static (void) "wired-static-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -6896,10 +6401,10 @@ test_write_wired_static (void) */ reread_s_ip4 = nm_connection_get_setting_ip4_config (reread); reread_s_ip6 = nm_connection_get_setting_ip6_config (reread); - nm_setting_ip6_config_add_dns_search (reread_s_ip6, nm_setting_ip4_config_get_dns_search (reread_s_ip4, 2)); - nm_setting_ip6_config_add_dns_search (reread_s_ip6, nm_setting_ip4_config_get_dns_search (reread_s_ip4, 3)); - nm_setting_ip4_config_remove_dns_search (reread_s_ip4, 3); - nm_setting_ip4_config_remove_dns_search (reread_s_ip4, 2); + nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 2)); + nm_setting_ip_config_add_dns_search (reread_s_ip6, nm_setting_ip_config_get_dns_search (reread_s_ip4, 3)); + nm_setting_ip_config_remove_dns_search (reread_s_ip4, 3); + nm_setting_ip_config_remove_dns_search (reread_s_ip4, 2); ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE, "wired-static-write", "written and re-read connection weren't the same."); @@ -6923,8 +6428,8 @@ test_write_wired_dhcp (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -6935,7 +6440,7 @@ test_write_wired_dhcp (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -6955,15 +6460,15 @@ test_write_wired_dhcp (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33", - NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "awesome-hostname", - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, TRUE, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE, + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, "awesome-hostname", + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -6971,12 +6476,12 @@ test_write_wired_dhcp (void) (error && error->message) ? error->message : "(unknown)"); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* Save the ifcfg */ @@ -6992,13 +6497,12 @@ test_write_wired_dhcp (void) "wired-dhcp-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7034,7 +6538,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); @@ -7046,10 +6550,10 @@ test_write_wired_dhcp_plus_ip (void) g_assert (success); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + 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); @@ -7072,15 +6576,15 @@ static void test_read_write_wired_dhcp_send_hostname (void) { NMConnection *connection, *reread; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; const char * dhcp_hostname = "kamil-patka"; char *written = NULL; GError *error = NULL; 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); @@ -7090,14 +6594,14 @@ test_read_write_wired_dhcp_send_hostname (void) s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip4); g_assert (s_ip6); - g_assert (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) == TRUE); - g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec"); - g_assert_cmpstr (nm_setting_ip6_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec"); + g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == TRUE); + g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "svata-pulec"); + g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, "svata-pulec"); /* Set dhcp-send-hostname=false dhcp-hostname="kamil-patka" and write the connection. */ - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); - g_object_set (s_ip6, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); success = writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", @@ -7106,10 +6610,10 @@ test_read_write_wired_dhcp_send_hostname (void) g_assert (success); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + 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); @@ -7129,9 +6633,9 @@ test_read_write_wired_dhcp_send_hostname (void) s_ip6 = nm_connection_get_setting_ip6_config (reread); g_assert (s_ip4); g_assert (s_ip6); - g_assert (nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) == FALSE); - g_assert_cmpstr (nm_setting_ip4_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname); - g_assert_cmpstr (nm_setting_ip6_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname); + g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == FALSE); + g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname); + g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname); g_object_unref (connection); g_object_unref (reread); @@ -7144,14 +6648,12 @@ test_write_wired_static_ip6_only (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; - static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + static const char *mac = "31:33:33:37:be:cd"; char *uuid; - struct in6_addr ip6; - struct in6_addr dns6; - NMIP6Address *addr6; + const char *dns6 = "fade:0102:0103::face"; + NMIPAddress *addr6; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -7161,10 +6663,7 @@ test_write_wired_static_ip6_only (void) char *route6file = NULL; gboolean ignore_error = FALSE; - inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6); - inet_pton (AF_INET6, "fade:0102:0103::face", &dns6); - - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -7183,36 +6682,32 @@ test_write_wired_static_ip6_only (void) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); /* Add addresses */ - addr6 = nm_ip6_address_new (); - nm_ip6_address_set_address (addr6, &ip6); - nm_ip6_address_set_prefix (addr6, 11); - nm_setting_ip6_config_add_address (s_ip6, addr6); - nm_ip6_address_unref (addr6); + addr6 = nm_ip_address_new (AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip6, addr6); + nm_ip_address_unref (addr6); /* DNS server */ - nm_setting_ip6_config_add_dns (s_ip6, &dns6); + nm_setting_ip_config_add_dns (s_ip6, dns6); ASSERT (nm_connection_verify (connection, &error) == TRUE, "wired-static-ip6-only-write", "failed to verify connection: %s", @@ -7231,13 +6726,12 @@ test_write_wired_static_ip6_only (void) "wired-static-ip6-only-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7282,44 +6776,28 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; - static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + static const char *mac = "31:33:33:37:be:cd"; char *uuid; - struct in6_addr ip6; - struct in6_addr dns6; - NMIP6Address *addr6; + const char *dns6 = "fade:0102:0103::face"; + NMIPAddress *addr6; gboolean success; GError *error = NULL; char *testfile = NULL; char *id = NULL; gboolean ignore_error = FALSE; char *written_ifcfg_gateway; - char s_gateway6[INET6_ADDRSTRLEN] = { 0 }; - struct in6_addr gateway6_autovar; - const struct in6_addr *gateway6 = NULL; - - /* parsing the input argument and set the struct in6_addr "gateway6" to - * the gateway address. NULL means "do not set the gateway explicitly". */ - if (user_data) { - g_assert_cmpint (inet_pton (AF_INET6, user_data, &gateway6_autovar), ==, 1); - gateway6 = &gateway6_autovar; - } - - inet_pton (AF_INET6, "1003:1234:abcd::1", &ip6); - inet_pton (AF_INET6, "fade:0102:0103::face", &dns6); - if (gateway6) - inet_ntop (AF_INET6, gateway6, s_gateway6, sizeof (s_gateway6)); + const char *gateway6 = user_data; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); - id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? s_gateway6 : "NULL"); + id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_UUID, uuid, @@ -7333,38 +6811,33 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, gateway6, NULL); /* Add addresses */ - addr6 = nm_ip6_address_new (); - nm_ip6_address_set_address (addr6, &ip6); - nm_ip6_address_set_prefix (addr6, 11); - if (gateway6) - nm_ip6_address_set_gateway (addr6, gateway6); - nm_setting_ip6_config_add_address (s_ip6, addr6); - nm_ip6_address_unref (addr6); + addr6 = nm_ip_address_new (AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip6, addr6); + nm_ip_address_unref (addr6); /* DNS server */ - nm_setting_ip6_config_add_dns (s_ip6, &dns6); + nm_setting_ip_config_add_dns (s_ip6, dns6); g_assert (nm_connection_verify (connection, &error)); @@ -7378,13 +6851,13 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) g_assert (testfile); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, NULL, NULL, + NULL, NULL, NULL, NULL, &error, &ignore_error); @@ -7407,18 +6880,18 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) /* access the gateway from the loaded connection. */ s_ip6 = nm_connection_get_setting_ip6_config (reread); - g_assert (s_ip6 && nm_setting_ip6_config_get_num_addresses (s_ip6)==1); - addr6 = nm_setting_ip6_config_get_address (s_ip6, 0); + g_assert (s_ip6 && nm_setting_ip_config_get_num_addresses (s_ip6)==1); + addr6 = nm_setting_ip_config_get_address (s_ip6, 0); g_assert (addr6); /* assert that the gateway was written and reloaded as expected */ - if (!gateway6 || IN6_IS_ADDR_UNSPECIFIED (gateway6)) { - g_assert (IN6_IS_ADDR_UNSPECIFIED (nm_ip6_address_get_gateway (addr6))); - g_assert (written_ifcfg_gateway==NULL); + if (!gateway6 || !strcmp (gateway6, "::")) { + g_assert (nm_setting_ip_config_get_gateway (s_ip6) == NULL); + g_assert (written_ifcfg_gateway == NULL); } else { - g_assert (!IN6_IS_ADDR_UNSPECIFIED (nm_ip6_address_get_gateway (addr6))); - g_assert_cmpint (memcmp (nm_ip6_address_get_gateway (addr6), gateway6, sizeof (struct in6_addr)), ==, 0); - g_assert_cmpstr (written_ifcfg_gateway, ==, s_gateway6); + g_assert (nm_setting_ip_config_get_gateway (s_ip6) != NULL); + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, gateway6); + g_assert_cmpstr (written_ifcfg_gateway, ==, gateway6); } g_free (testfile); @@ -7435,7 +6908,7 @@ test_read_write_static_routes_legacy (void) NMConnection *connection, *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; char *testfile = NULL; char *keyfile = NULL; @@ -7452,7 +6925,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, @@ -7507,18 +6979,18 @@ test_read_write_static_routes_legacy (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "read-write-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_READ_WRITE_STATIC_ROUTES_LEGACY, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE, + ASSERT (nm_setting_ip_config_get_never_default (s_ip4) == FALSE, "read-write-static-routes-legacy-verify-ip4", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_READ_WRITE_STATIC_ROUTES_LEGACY, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT); /* Save the ifcfg; use a special different scratch dir to ensure that * we can clean up after the written connection in both the original @@ -7536,13 +7008,12 @@ test_read_write_static_routes_legacy (void) "read-write-static-routes-legacy-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile2, &routefile2, @@ -7584,26 +7055,17 @@ test_write_wired_static_routes (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; - static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; char *uuid; - const guint32 ip1 = htonl (0x01010103); - const guint32 ip2 = htonl (0x01010105); - const guint32 gw = htonl (0x01010101); - const guint32 dns1 = htonl (0x04020201); - const guint32 dns2 = htonl (0x04020202); - const guint32 route_dst1 = htonl (0x01020300); - const guint32 route_dst2= htonl (0x03020100); - const guint32 route_gw1 = htonl (0xdeadbeef); - const guint32 route_gw2 = htonl (0xcafeabbe); - const guint32 prefix = 24; + const char *dns1 = "4.2.2.1"; + const char *dns2 = "4.2.2.2"; const char *dns_search1 = "foobar.com"; const char *dns_search2 = "lab.foobar.com"; - NMIP4Address *addr; - NMIP4Route *route; + NMIPAddress *addr; + NMIPRoute *route; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -7613,7 +7075,7 @@ test_write_wired_static_routes (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -7632,66 +7094,54 @@ test_write_wired_static_routes (void) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", NULL); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip2); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.5", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); /* Write out routes */ - route = nm_ip4_route_new (); - nm_ip4_route_set_dest (route, route_dst1); - nm_ip4_route_set_prefix (route, prefix); - nm_ip4_route_set_next_hop (route, route_gw1); - nm_setting_ip4_config_add_route (s_ip4, route); - nm_ip4_route_unref (route); - - route = nm_ip4_route_new (); - nm_ip4_route_set_dest (route, route_dst2); - nm_ip4_route_set_prefix (route, prefix); - nm_ip4_route_set_next_hop (route, route_gw2); - nm_ip4_route_set_metric (route, 77); - nm_setting_ip4_config_add_route (s_ip4, route); - nm_ip4_route_unref (route); - - nm_setting_ip4_config_add_dns (s_ip4, dns1); - nm_setting_ip4_config_add_dns (s_ip4, dns2); - - nm_setting_ip4_config_add_dns_search (s_ip4, dns_search1); - nm_setting_ip4_config_add_dns_search (s_ip4, dns_search2); + route = nm_ip_route_new (AF_INET, "1.2.3.0", 24, "222.173.190.239", 0, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_route (s_ip4, route); + nm_ip_route_unref (route); + + route = nm_ip_route_new (AF_INET, "3.2.1.0", 24, "202.254.186.190", 77, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_route (s_ip4, route); + nm_ip_route_unref (route); + + nm_setting_ip_config_add_dns (s_ip4, dns1); + nm_setting_ip_config_add_dns (s_ip4, dns2); + + nm_setting_ip_config_add_dns_search (s_ip4, dns_search1); + nm_setting_ip_config_add_dns_search (s_ip4, dns_search2); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -7711,13 +7161,12 @@ test_write_wired_static_routes (void) "wired-static-routes-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7755,8 +7204,8 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; char *uuid; gboolean success; @@ -7768,7 +7217,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -7788,18 +7237,18 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* 802.1x setting */ @@ -7843,13 +7292,12 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) "wired-dhcp-8021x-peap-mschapv2write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -7910,8 +7358,8 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme, NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; char *uuid; gboolean success; @@ -7926,7 +7374,7 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme, const char *pw; char *tmp; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection != NULL); /* Connection setting */ @@ -7949,17 +7397,17 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme, nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); @@ -8028,13 +7476,12 @@ test_write_wired_8021x_tls (NMSetting8021xCKScheme scheme, g_assert (testfile != NULL); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8125,14 +7572,12 @@ test_write_wired_aliases (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *uuid; int num_addresses = 4; - guint32 ip[] = { 0x01010101, 0x01010102, 0x01010103, 0x01010104 }; + const char *ip[] = { "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" }; const char *label[] = { NULL, "alias0:2", NULL, "alias0:3" }; - const guint32 gw = htonl (0x01010101); - const guint32 prefix = 24; - NMIP4Address *addr; + NMIPAddress *addr; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -8144,7 +7589,7 @@ test_write_wired_aliases (void) shvarFile *ifcfg; int i, j; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); ASSERT (connection != NULL, "wired-aliases-write", "failed to allocate new connection"); @@ -8171,24 +7616,25 @@ test_write_wired_aliases (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); ASSERT (s_ip4 != NULL, "wired-aliases-write", "failed to allocate new %s setting", NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); for (i = 0; i < num_addresses; i++) { - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip[i]); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, label[i])); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, ip[i], 24, &error); + g_assert_no_error (error); + if (label[i]) + nm_ip_address_set_attribute (addr, "label", g_variant_new_string (label[i])); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); } ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -8236,7 +7682,6 @@ test_write_wired_aliases (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -8258,49 +7703,33 @@ test_write_wired_aliases (void) * verify the aliases manually. */ s_ip4 = nm_connection_get_setting_ip4_config (connection); - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == num_addresses, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == num_addresses, "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected %s / %s key value", testfile, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); /* Addresses */ for (i = 0; i < num_addresses; i++) { - guint32 addrbytes; + const char *addrstr; - addr = nm_setting_ip4_config_get_address (s_ip4, i); - ASSERT (addr, - "wired-aliases-write-verify-ip4", "failed to verify %s: missing IP4 address #%d", - testfile, - i); + addr = nm_setting_ip_config_get_address (s_ip4, i); + g_assert (addr != NULL); - addrbytes = nm_ip4_address_get_address (addr); + addrstr = nm_ip_address_get_address (addr); for (j = 0; j < num_addresses; j++) { - if (addrbytes == ip[j]) + if (!g_strcmp0 (addrstr, ip[j])) break; } + g_assert (j < num_addresses); - ASSERT (j < num_addresses, - "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address #%d", - testfile, - i); - - ASSERT (nm_ip4_address_get_prefix (addr) == prefix, - "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address prefix #%d", - testfile, - i); - - ASSERT (nm_ip4_address_get_gateway (addr) == gw, - "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address gateway #%d", - testfile, - i); - - ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)), label[j]) == 0, - "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d", - testfile, - i); + g_assert_cmpint (nm_ip_address_get_prefix (addr), ==, 24); + if (label[j]) + g_assert_cmpstr (g_variant_get_string (nm_ip_address_get_attribute (addr, "label"), NULL), ==, label[j]); + else + g_assert (nm_ip_address_get_attribute (addr, "label") == NULL); - ip[j] = 0; + ip[j] = NULL; } for (i = 0; i < num_addresses; i++) { @@ -8310,6 +7739,9 @@ test_write_wired_aliases (void) ip[i]); } + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1"); + g_free (testfile); g_free (keyfile); g_free (routefile); @@ -8324,20 +7756,14 @@ test_write_gateway (void) NMConnection *connection, *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *uuid, *testfile = NULL, *val; gboolean success; GError *error = NULL; shvarFile *f; - NMIP4Address *addr; - const char *ip1_str = "1.1.1.3"; - const char *ip2_str = "2.2.2.5"; - const char *gw1_str = "1.1.1.254"; - const char *gw2_str = "2.2.2.254"; - struct in_addr ip1, ip2, gw1, gw2; - const guint32 prefix = 24; + NMIPAddress *addr; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -8356,32 +7782,24 @@ test_write_gateway (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.254", + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - inet_pton (AF_INET, ip1_str, &ip1); - inet_pton (AF_INET, ip2_str, &ip2); - inet_pton (AF_INET, gw1_str, &gw1); - inet_pton (AF_INET, gw2_str, &gw2); - - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1.s_addr); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw1.s_addr); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip2.s_addr); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw2.s_addr); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "2.2.2.5", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); success = nm_connection_verify (connection, &error); g_assert_no_error (error); @@ -8402,12 +7820,12 @@ test_write_gateway (void) /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ val = svGetValue (f, "IPADDR", FALSE); g_assert (val); - g_assert_cmpstr (val, ==, ip1_str); + g_assert_cmpstr (val, ==, "1.1.1.3"); g_free (val); val = svGetValue (f, "IPADDR1", FALSE); g_assert (val); - g_assert_cmpstr (val, ==, ip2_str); + g_assert_cmpstr (val, ==, "2.2.2.5"); g_free (val); val = svGetValue (f, "IPADDR0", FALSE); @@ -8428,25 +7846,22 @@ test_write_gateway (void) val = svGetValue (f, "GATEWAY", FALSE); g_assert (val); - g_assert_cmpstr (val, ==, gw1_str); - g_free (val); - - val = svGetValue (f, "GATEWAY1", FALSE); - g_assert (val); - g_assert_cmpstr (val, ==, gw2_str); + g_assert_cmpstr (val, ==, "1.1.1.254"); g_free (val); val = svGetValue (f, "GATEWAY0", FALSE); g_assert (val == NULL); + val = svGetValue (f, "GATEWAY1", FALSE); + g_assert (val == NULL); svCloseFile (f); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + 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); @@ -8471,8 +7886,8 @@ test_write_wifi_open (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -8482,17 +7897,15 @@ test_write_wifi_open (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; + GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; - GByteArray *bssid; - const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; + const char *bssid = "11:22:33:44:55:66"; guint32 channel = 9, mtu = 1345; - GByteArray *mac; - const unsigned char mac_data[] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + const char *mac = "aa:bb:cc:dd:ee:ff"; shvarFile *ifcfg; char *tmp; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -8511,12 +7924,7 @@ test_write_wifi_open (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); - bssid = g_byte_array_sized_new (sizeof (bssid_data)); - g_byte_array_append (bssid, bssid_data, sizeof (bssid_data)); - mac = g_byte_array_sized_new (sizeof (mac_data)); - g_byte_array_append (mac, mac_data, sizeof (mac_data)); + ssid = g_bytes_new (ssid_data, sizeof (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -8528,23 +7936,21 @@ test_write_wifi_open (void) NM_SETTING_WIRELESS_MTU, mtu, NULL); - g_byte_array_free (ssid, TRUE); - g_byte_array_free (bssid, TRUE); - g_byte_array_free (mac, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -8564,13 +7970,12 @@ test_write_wifi_open (void) "wifi-open-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8621,8 +8026,8 @@ test_write_wifi_open_hex_ssid (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -8632,10 +8037,10 @@ test_write_wifi_open_hex_ssid (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; + GBytes *ssid; const unsigned char ssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -8654,29 +8059,28 @@ test_write_wifi_open_hex_ssid (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, sizeof (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -8696,13 +8100,12 @@ test_write_wifi_open_hex_ssid (void) "wifi-open-hex-ssid-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8737,8 +8140,8 @@ test_write_wifi_wep (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -8748,11 +8151,11 @@ test_write_wifi_wep (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; struct stat statbuf; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -8771,15 +8174,14 @@ test_write_wifi_wep (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -8796,18 +8198,18 @@ test_write_wifi_wep (void) nm_setting_wireless_security_set_wep_key (s_wsec, 3, "BBBBBBBBBBBBBBBBBBBBBBBBBB"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -8827,13 +8229,12 @@ test_write_wifi_wep (void) "wifi-wep-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -8880,8 +8281,8 @@ test_write_wifi_wep_adhoc (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -8891,16 +8292,13 @@ test_write_wifi_wep_adhoc (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; struct stat statbuf; - NMIP4Address *addr; - const guint32 ip1 = htonl (0x01010103); - const guint32 gw = htonl (0x01010101); - const guint32 dns1 = htonl (0x04020201); - const guint32 prefix = 24; + NMIPAddress *addr; + const char *dns1 = "4.2.2.1"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -8919,15 +8317,14 @@ test_write_wifi_wep_adhoc (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "adhoc", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -8937,28 +8334,29 @@ test_write_wifi_wep_adhoc (void) nm_setting_wireless_security_set_wep_key (s_wsec, 0, "0123456789abcdef0123456789"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", + NULL); /* IP Address */ - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); - nm_setting_ip4_config_add_dns (s_ip4, dns1); + nm_setting_ip_config_add_dns (s_ip4, dns1); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -8978,13 +8376,12 @@ test_write_wifi_wep_adhoc (void) "wifi-wep-adhoc-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9031,8 +8428,8 @@ test_write_wifi_wep_passphrase (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -9042,11 +8439,11 @@ test_write_wifi_wep_passphrase (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; struct stat statbuf; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -9065,15 +8462,14 @@ test_write_wifi_wep_passphrase (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9088,18 +8484,18 @@ test_write_wifi_wep_passphrase (void) nm_setting_wireless_security_set_wep_key (s_wsec, 0, "asdfdjaslfjasd;flasjdfl;aksdf"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -9119,13 +8515,12 @@ test_write_wifi_wep_passphrase (void) "wifi-wep-passphrase-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9172,8 +8567,8 @@ test_write_wifi_wep_40_ascii (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -9183,11 +8578,11 @@ test_write_wifi_wep_40_ascii (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah40"; + GBytes *ssid; + const char *ssid_data = "blahblah40"; struct stat statbuf; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -9206,15 +8601,14 @@ test_write_wifi_wep_40_ascii (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9231,18 +8625,18 @@ test_write_wifi_wep_40_ascii (void) nm_setting_wireless_security_set_wep_key (s_wsec, 3, "donec"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -9262,13 +8656,12 @@ test_write_wifi_wep_40_ascii (void) "wifi-wep-40-ascii-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9315,8 +8708,8 @@ test_write_wifi_wep_104_ascii (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -9326,11 +8719,11 @@ test_write_wifi_wep_104_ascii (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah104"; + GBytes *ssid; + const char *ssid_data = "blahblah104"; struct stat statbuf; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -9349,15 +8742,14 @@ test_write_wifi_wep_104_ascii (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9374,18 +8766,18 @@ test_write_wifi_wep_104_ascii (void) nm_setting_wireless_security_set_wep_key (s_wsec, 3, "thisismyascii"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -9405,13 +8797,12 @@ test_write_wifi_wep_104_ascii (void) "wifi-wep-104-ascii-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9458,8 +8849,8 @@ test_write_wifi_leap (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -9469,11 +8860,11 @@ test_write_wifi_leap (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; struct stat statbuf; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -9492,15 +8883,14 @@ test_write_wifi_leap (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9514,18 +8904,18 @@ test_write_wifi_leap (void) NULL); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -9545,13 +8935,12 @@ test_write_wifi_leap (void) "wifi-leap-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9598,8 +8987,8 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -9609,10 +8998,10 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -9633,13 +9022,12 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9655,19 +9043,19 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags) NULL); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); success = nm_connection_verify (connection, &error); @@ -9684,13 +9072,12 @@ test_write_wifi_leap_secret_flags (NMSettingSecretFlags flags) g_assert (testfile); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9739,8 +9126,8 @@ test_write_wifi_wpa_psk (const char *name, NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid, *tmp; gboolean success; GError *error = NULL; @@ -9750,12 +9137,12 @@ test_write_wifi_wpa_psk (const char *name, char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; g_return_if_fail (psk != NULL); - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -9774,15 +9161,14 @@ test_write_wifi_wpa_psk (const char *name, s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9809,18 +9195,18 @@ test_write_wifi_wpa_psk (const char *name, } /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -9840,13 +9226,12 @@ test_write_wifi_wpa_psk (const char *name, test_name, "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -9887,8 +9272,8 @@ test_write_wifi_wpa_psk_adhoc (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -9898,15 +9283,12 @@ test_write_wifi_wpa_psk_adhoc (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; - NMIP4Address *addr; - const guint32 ip1 = htonl (0x01010103); - const guint32 gw = htonl (0x01010101); - const guint32 dns1 = htonl (0x04020201); - const guint32 prefix = 24; + GBytes *ssid; + const char *ssid_data = "blahblah"; + NMIPAddress *addr; + const char *dns1 = "4.2.2.1"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -9925,8 +9307,7 @@ test_write_wifi_wpa_psk_adhoc (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, @@ -9935,7 +9316,7 @@ test_write_wifi_wpa_psk_adhoc (void) NM_SETTING_WIRELESS_BAND, "bg", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -9950,28 +9331,29 @@ test_write_wifi_wpa_psk_adhoc (void) nm_setting_wireless_security_add_group (s_wsec, "tkip"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", + NULL); /* IP Address */ - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 25, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); - nm_setting_ip4_config_add_dns (s_ip4, dns1); + nm_setting_ip_config_add_dns (s_ip4, dns1); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -9991,13 +9373,12 @@ test_write_wifi_wpa_psk_adhoc (void) "wifi-wpa-psk-adhoc-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10037,8 +9418,8 @@ test_write_wifi_wpa_eap_tls (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -10048,10 +9429,10 @@ test_write_wifi_wpa_eap_tls (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; + GBytes *ssid; const char *ssid_data = "blahblah"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -10070,15 +9451,14 @@ test_write_wifi_wpa_eap_tls (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (strlen (ssid_data)); - g_byte_array_append (ssid, (const unsigned char *) ssid_data, strlen (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -10126,18 +9506,18 @@ test_write_wifi_wpa_eap_tls (void) TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, error->message); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -10157,13 +9537,12 @@ test_write_wifi_wpa_eap_tls (void) "wifi-wpa-eap-tls-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10203,8 +9582,8 @@ test_write_wifi_wpa_eap_ttls_tls (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -10214,10 +9593,10 @@ test_write_wifi_wpa_eap_ttls_tls (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; + GBytes *ssid; const char *ssid_data = "blahblah"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -10236,15 +9615,14 @@ test_write_wifi_wpa_eap_ttls_tls (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (strlen (ssid_data)); - g_byte_array_append (ssid, (const unsigned char *) ssid_data, strlen (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -10310,18 +9688,18 @@ test_write_wifi_wpa_eap_ttls_tls (void) TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, error->message); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -10341,13 +9719,12 @@ test_write_wifi_wpa_eap_ttls_tls (void) "wifi-wpa-eap-ttls-tls-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10387,8 +9764,8 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -10398,10 +9775,10 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; + GBytes *ssid; const char *ssid_data = "blahblah"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -10420,15 +9797,14 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (strlen (ssid_data)); - g_byte_array_append (ssid, (const unsigned char *) ssid_data, strlen (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -10466,18 +9842,18 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -10497,13 +9873,12 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) "wifi-wpa-eap-ttls-mschapv2-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10542,8 +9917,8 @@ test_write_wifi_wpa_then_open (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -10553,14 +9928,14 @@ test_write_wifi_wpa_then_open (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - const unsigned char ssid_data[] = "blahblah"; + GBytes *ssid; + const char *ssid_data = "blahblah"; /* Test that writing out a WPA config then changing that to an open * config doesn't leave various WPA-related keys lying around in the ifcfg. */ - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -10582,15 +9957,14 @@ test_write_wifi_wpa_then_open (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -10611,20 +9985,20 @@ test_write_wifi_wpa_then_open (void) nm_setting_wireless_security_add_group (s_wsec, "ccmp"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); success = nm_connection_verify (connection, &error); @@ -10641,13 +10015,12 @@ test_write_wifi_wpa_then_open (void) g_assert (testfile); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10688,13 +10061,12 @@ test_write_wifi_wpa_then_open (void) keyfile = NULL; /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read it for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10735,8 +10107,8 @@ test_write_wifi_wpa_then_wep_with_perms (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -10746,15 +10118,15 @@ test_write_wifi_wpa_then_wep_with_perms (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; - GSList *perm_list = NULL; - const unsigned char ssid_data[] = "SomeSSID"; + GBytes *ssid; + char **perms; + const char *ssid_data = "SomeSSID"; /* Test that writing out a WPA config then changing that to a WEP * config works and doesn't cause infinite loop or other issues. */ - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -10763,16 +10135,16 @@ test_write_wifi_wpa_then_wep_with_perms (void) nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); - perm_list = g_slist_append (perm_list, "user:superman:"); + perms = g_strsplit ("user:superman:", ",", -1); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection 2", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, - NM_SETTING_CONNECTION_PERMISSIONS, perm_list, + NM_SETTING_CONNECTION_PERMISSIONS, perms, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); g_free (uuid); - g_slist_free (perm_list); + g_strfreev (perms); ASSERT (nm_setting_connection_get_num_permissions (s_con) == 1, "test_write_wifi_wpa_then_wep_with_perms", "unexpected failure adding valid user permisson"); @@ -10781,15 +10153,14 @@ test_write_wifi_wpa_then_wep_with_perms (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (ssid_data)); - g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -10810,20 +10181,20 @@ test_write_wifi_wpa_then_wep_with_perms (void) nm_setting_wireless_security_add_group (s_wsec, "ccmp"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); success = nm_connection_verify (connection, &error); @@ -10840,13 +10211,12 @@ test_write_wifi_wpa_then_wep_with_perms (void) g_assert (testfile); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10893,13 +10263,12 @@ test_write_wifi_wpa_then_wep_with_perms (void) keyfile = NULL; /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read it for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -10942,8 +10311,8 @@ test_write_wifi_dynamic_wep_leap (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -10953,12 +10322,12 @@ test_write_wifi_dynamic_wep_leap (void) char *routefile = NULL; char *route6file = NULL; gboolean ignore_error = FALSE; - GByteArray *ssid; + GBytes *ssid; const char *ssid_data = "blahblah"; shvarFile *ifcfg; char *tmp; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -10979,15 +10348,14 @@ test_write_wifi_dynamic_wep_leap (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (strlen (ssid_data)); - g_byte_array_append (ssid, (const unsigned char *) ssid_data, strlen (ssid_data)); + ssid = g_bytes_new (ssid_data, strlen (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -11009,19 +10377,19 @@ test_write_wifi_dynamic_wep_leap (void) NULL); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); success = nm_connection_verify (connection, &error); @@ -11038,13 +10406,12 @@ test_write_wifi_dynamic_wep_leap (void) g_assert (testfile); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -11090,399 +10457,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) { @@ -11490,10 +10464,10 @@ test_write_wired_qeth_dhcp (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; - GPtrArray *subchans; + char **subchans; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -11503,7 +10477,7 @@ test_write_wired_qeth_dhcp (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -11522,15 +10496,12 @@ test_write_wired_qeth_dhcp (void) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - subchans = g_ptr_array_sized_new (3); - g_ptr_array_add (subchans, "0.0.600"); - g_ptr_array_add (subchans, "0.0.601"); - g_ptr_array_add (subchans, "0.0.602"); + subchans = g_strsplit ("0.0.600,0.0.601,0.0.602", ",", -1); g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchans, NM_SETTING_WIRED_S390_NETTYPE, "qeth", NULL); - g_ptr_array_free (subchans, TRUE); + g_strfreev (subchans); nm_setting_wired_add_s390_option (s_wired, "portname", "FOOBAR"); nm_setting_wired_add_s390_option (s_wired, "portno", "1"); @@ -11538,20 +10509,20 @@ test_write_wired_qeth_dhcp (void) nm_setting_wired_add_s390_option (s_wired, "protocol", "blahbalh"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* Verify */ @@ -11572,13 +10543,12 @@ test_write_wired_qeth_dhcp (void) "wired-qeth-dhcp-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -11615,10 +10585,10 @@ test_write_wired_ctc_dhcp (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; - GPtrArray *subchans; + char **subchans; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -11630,7 +10600,7 @@ test_write_wired_ctc_dhcp (void) shvarFile *ifcfg; char *tmp; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -11651,30 +10621,28 @@ test_write_wired_ctc_dhcp (void) g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - subchans = g_ptr_array_sized_new (2); - g_ptr_array_add (subchans, "0.0.600"); - g_ptr_array_add (subchans, "0.0.601"); + subchans = g_strsplit ("0.0.600,0.0.601", ",", -1); g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchans, NM_SETTING_WIRED_S390_NETTYPE, "ctc", NULL); - g_ptr_array_free (subchans, TRUE); + g_strfreev (subchans); nm_setting_wired_add_s390_option (s_wired, "ctcprot", "0"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* Verify */ @@ -11709,13 +10677,12 @@ test_write_wired_ctc_dhcp (void) svCloseFile (ifcfg); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -11751,8 +10718,8 @@ test_write_permissions (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -11763,7 +10730,7 @@ test_write_permissions (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -11787,20 +10754,20 @@ test_write_permissions (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* Verify */ @@ -11821,13 +10788,12 @@ test_write_permissions (void) "permissions-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -11865,11 +10831,11 @@ test_write_wifi_wep_agent_keys (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; const char *str_ssid = "foobarbaz"; - GByteArray *ssid; + GBytes *ssid; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -11879,7 +10845,7 @@ test_write_wifi_wep_agent_keys (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection != NULL); /* Connection setting */ @@ -11896,19 +10862,19 @@ test_write_wifi_wep_agent_keys (void) g_free (uuid); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); /* Wifi setting */ @@ -11916,13 +10882,12 @@ test_write_wifi_wep_agent_keys (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (strlen (str_ssid)); - g_byte_array_append (ssid, (guint8 *) str_ssid, strlen (str_ssid)); + ssid = g_bytes_new (str_ssid, strlen (str_ssid)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* Wifi security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -11951,13 +10916,12 @@ test_write_wifi_wep_agent_keys (void) g_assert (testfile != NULL); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, - NULL, &unmanaged, &keyfile, &routefile, @@ -12005,15 +10969,15 @@ test_write_wired_pppoe (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingPPPOE *s_pppoe; - NMSettingPPP *s_ppp; + NMSettingIPConfig *s_ip4; + NMSettingPppoe *s_pppoe; + NMSettingPpp *s_ppp; char *uuid; gboolean success; GError *error = NULL; char *testfile = NULL; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -12033,15 +10997,15 @@ test_write_wired_pppoe (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* PPPoE setting */ - s_pppoe = (NMSettingPPPOE *) nm_setting_pppoe_new (); + s_pppoe = (NMSettingPppoe *) nm_setting_pppoe_new (); nm_connection_add_setting (connection, NM_SETTING (s_pppoe)); g_object_set (G_OBJECT (s_pppoe), @@ -12051,7 +11015,7 @@ test_write_wired_pppoe (void) NULL); /* PPP setting */ - s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); + s_ppp = (NMSettingPpp *) nm_setting_ppp_new (); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -12074,14 +11038,14 @@ test_write_vpn (void) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; - NMSettingVPN *s_vpn; + NMSettingIPConfig *s_ip4; + NMSettingVpn *s_vpn; char *uuid; gboolean success; GError *error = NULL; char *testfile = NULL; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -12097,7 +11061,7 @@ test_write_vpn (void) g_free (uuid); /* VPN setting */ - s_vpn = (NMSettingVPN *) nm_setting_vpn_new (); + s_vpn = (NMSettingVpn *) nm_setting_vpn_new (); nm_connection_add_setting (connection, NM_SETTING (s_vpn)); g_object_set (s_vpn, @@ -12109,11 +11073,11 @@ test_write_vpn (void) nm_setting_vpn_add_secret (s_vpn, "password", "sup3rs3cr3t"); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -12136,17 +11100,17 @@ test_write_mobile_broadband (gboolean gsm) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSettingGsm *s_gsm; NMSettingCdma *s_cdma; - NMSettingPPP *s_ppp; + NMSettingPpp *s_ppp; NMSettingSerial *s_serial; char *uuid; gboolean success; GError *error = NULL; char *testfile = NULL; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -12182,20 +11146,20 @@ test_write_mobile_broadband (gboolean gsm) g_object_set (s_serial, NM_SETTING_SERIAL_BAUD, 115200, NM_SETTING_SERIAL_BITS, 8, - NM_SETTING_SERIAL_PARITY, 'n', + NM_SETTING_SERIAL_PARITY, NM_SETTING_SERIAL_PARITY_NONE, NM_SETTING_SERIAL_STOPBITS, 1, NULL); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* PPP setting */ - s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); + s_ppp = (NMSettingPpp *) nm_setting_ppp_new (); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -12220,7 +11184,7 @@ test_read_bridge_main (void) { NMConnection *connection; NMSettingBridge *s_bridge; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 }; char *unmanaged = NULL; char *keyfile = NULL; @@ -12232,7 +11196,6 @@ test_read_bridge_main (void) connection = connection_from_file (TEST_IFCFG_BRIDGE_MAIN, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12243,22 +11206,23 @@ test_read_bridge_main (void) g_assert (nm_connection_verify (connection, &error)); g_assert_no_error (error); + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "br0"); + /* ===== Bridging SETTING ===== */ s_bridge = nm_connection_get_setting_bridge (connection); g_assert (s_bridge); - g_assert_cmpstr (nm_setting_bridge_get_interface_name (s_bridge), ==, "br0"); g_assert_cmpuint (nm_setting_bridge_get_forward_delay (s_bridge), ==, 0); g_assert (nm_setting_bridge_get_stp (s_bridge)); g_assert_cmpuint (nm_setting_bridge_get_priority (s_bridge), ==, 32744); g_assert_cmpuint (nm_setting_bridge_get_hello_time (s_bridge), ==, 7); g_assert_cmpuint (nm_setting_bridge_get_max_age (s_bridge), ==, 39); g_assert_cmpuint (nm_setting_bridge_get_ageing_time (s_bridge), ==, 235352); + /* MAC address */ - array = nm_setting_bridge_get_mac_address (s_bridge); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert (memcmp (array->data, &expected_mac_address[0], ETH_ALEN) == 0); + mac = nm_setting_bridge_get_mac_address (s_bridge); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, ETH_ALEN)); g_free (unmanaged); g_free (keyfile); @@ -12274,15 +11238,11 @@ test_write_bridge_main (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingBridge *s_bridge; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; - const guint32 ip1 = htonl (0x01010103); - const guint32 gw = htonl (0x01010101); - const guint32 prefix = 24; - NMIP4Address *addr; - static unsigned char bridge_mac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac_array; + NMIPAddress *addr; + static const char *mac = "31:33:33:37:be:cd"; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -12292,7 +11252,7 @@ test_write_bridge_main (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -12305,6 +11265,7 @@ test_write_bridge_main (void) NM_SETTING_CONNECTION_ID, "Test Write Bridge Main", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, "br0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); g_free (uuid); @@ -12314,42 +11275,36 @@ test_write_bridge_main (void) g_assert (s_bridge); nm_connection_add_setting (connection, NM_SETTING (s_bridge)); - mac_array = g_byte_array_sized_new (sizeof (bridge_mac)); - g_byte_array_append (mac_array, bridge_mac, sizeof (bridge_mac)); g_object_set (s_bridge, - NM_SETTING_BRIDGE_INTERFACE_NAME, "br0", - NM_SETTING_BRIDGE_MAC_ADDRESS, mac_array, + NM_SETTING_BRIDGE_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac_array, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - g_assert (nm_connection_verify (connection, &error)); - g_assert_no_error (error); + nmtst_assert_connection_verifies_without_normalization (connection); /* Save the ifcfg */ success = writer_new_connection (connection, @@ -12360,13 +11315,12 @@ test_write_bridge_main (void) g_assert_cmpstr (testfile, !=, NULL); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_BRIDGE, - NULL, &unmanaged, &keyfile, &routefile, @@ -12408,7 +11362,6 @@ test_read_bridge_component (void) connection = connection_from_file (TEST_IFCFG_BRIDGE_COMPONENT, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12447,8 +11400,7 @@ test_write_bridge_component (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSetting *s_port; - static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac; + static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; char *uuid; gboolean success; @@ -12460,7 +11412,7 @@ test_write_bridge_component (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -12484,14 +11436,10 @@ test_write_bridge_component (void) g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); - g_byte_array_free (mac, TRUE); /* Bridge port */ s_port = nm_setting_bridge_port_new (); @@ -12515,13 +11463,12 @@ test_write_bridge_component (void) g_assert (testfile); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12564,7 +11511,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, @@ -12575,11 +11521,12 @@ test_read_bridge_missing_stp (void) g_assert (nm_connection_verify (connection, &error)); g_assert_no_error (error); + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "br0"); + /* ===== Bridging SETTING ===== */ s_bridge = nm_connection_get_setting_bridge (connection); g_assert (s_bridge); - g_assert_cmpstr (nm_setting_bridge_get_interface_name (s_bridge), ==, "br0"); g_assert (nm_setting_bridge_get_stp (s_bridge) == FALSE); g_free (unmanaged); @@ -12607,7 +11554,6 @@ test_read_vlan_interface (void) connection = connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12622,10 +11568,11 @@ test_read_vlan_interface (void) g_free (routefile); g_free (route6file); + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan43"); + s_vlan = nm_connection_get_setting_vlan (connection); g_assert (s_vlan); - g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, "vlan43"); g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "eth9"); g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 43); g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, @@ -12677,7 +11624,6 @@ test_read_vlan_only_vlan_id (void) connection = connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12692,10 +11638,11 @@ test_read_vlan_only_vlan_id (void) g_free (routefile); g_free (route6file); + g_assert (nm_connection_get_interface_name (connection) == NULL); + s_vlan = nm_connection_get_setting_vlan (connection); g_assert (s_vlan); - g_assert (nm_setting_vlan_get_interface_name (s_vlan) == NULL); g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "eth9"); g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 43); @@ -12719,7 +11666,6 @@ test_read_vlan_only_device (void) connection = connection_from_file (TEST_IFCFG_VLAN_ONLY_DEVICE, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12734,10 +11680,11 @@ test_read_vlan_only_device (void) g_free (routefile); g_free (route6file); + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "eth0.9"); + s_vlan = nm_connection_get_setting_vlan (connection); g_assert (s_vlan); - g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, "eth0.9"); g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "eth0"); g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 9); @@ -12752,16 +11699,17 @@ 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); g_assert (nm_connection_verify (connection, &error)); + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan0.3"); + s_vlan = nm_connection_get_setting_vlan (connection); g_assert (s_vlan); - g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, "vlan0.3"); g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "eth0"); g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 3); @@ -12784,7 +11732,6 @@ test_write_vlan (void) connection = connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, - NULL, &unmanaged, &keyfile, &routefile, @@ -12824,7 +11771,6 @@ test_write_vlan_only_vlanid (void) connection = connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_VLAN, - NULL, &unmanaged, &keyfile, &routefile, @@ -12850,13 +11796,12 @@ test_write_vlan_only_vlanid (void) g_assert (success); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (written, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12891,8 +11836,8 @@ test_write_ethernet_missing_ipv6 (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -12903,7 +11848,7 @@ test_write_ethernet_missing_ipv6 (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -12926,14 +11871,14 @@ test_write_ethernet_missing_ipv6 (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33", - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, TRUE, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL); /* IP6 setting */ @@ -12959,13 +11904,12 @@ test_write_ethernet_missing_ipv6 (void) "ethernet-missing-ipv6", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -12985,12 +11929,12 @@ test_write_ethernet_missing_ipv6 (void) * the comparison can succeed. Missing IPv6 setting should have been * written out (and re-read) as Automatic IPv6. */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE, @@ -13005,6 +11949,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_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert (connection == NULL); +} + #define TEST_IFCFG_BOND_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bond-main" static void @@ -13022,7 +11979,6 @@ test_read_bond_main (void) connection = connection_from_file (TEST_IFCFG_BOND_MAIN, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13035,6 +11991,10 @@ test_read_bond_main (void) ASSERT (nm_connection_verify (connection, &error), "bond-main-read", "failed to verify %s: %s", TEST_IFCFG_BOND_MAIN, error->message); + ASSERT (g_strcmp0 (nm_connection_get_interface_name (connection), "bond0") == 0, + "bond-main", "failed to verify %s: DEVICE=%s does not match bond0", + TEST_IFCFG_BOND_MAIN, nm_connection_get_interface_name (connection)); + /* ===== Bonding SETTING ===== */ s_bond = nm_connection_get_setting_bond (connection); @@ -13043,10 +12003,6 @@ test_read_bond_main (void) TEST_IFCFG_BOND_MAIN, NM_SETTING_BOND_SETTING_NAME); - ASSERT (g_strcmp0 (nm_setting_bond_get_interface_name (s_bond), "bond0") == 0, - "bond-main", "failed to verify %s: DEVICE=%s does not match bond0", - TEST_IFCFG_BOND_MAIN, nm_setting_bond_get_interface_name (s_bond)); - ASSERT (g_strcmp0 (nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_MIIMON), "100") == 0, "bond-main", "failed to verify %s: miimon=%s does not match 100", TEST_IFCFG_BOND_MAIN, nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_MIIMON)); @@ -13065,14 +12021,11 @@ test_write_bond_main (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingBond *s_bond; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; NMSettingWired *s_wired; char *uuid; - const guint32 ip1 = htonl (0x01010103); - const guint32 gw = htonl (0x01010101); - const guint32 prefix = 24; - NMIP4Address *addr; + NMIPAddress *addr; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -13082,7 +12035,7 @@ test_write_bond_main (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -13093,6 +12046,7 @@ test_write_bond_main (void) NM_SETTING_CONNECTION_ID, "Test Write Bond Main", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, "bond0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); g_free (uuid); @@ -13105,37 +12059,30 @@ test_write_bond_main (void) s_bond = (NMSettingBond *) nm_setting_bond_new (); nm_connection_add_setting (connection, NM_SETTING (s_bond)); - g_object_set (s_bond, - NM_SETTING_BOND_INTERFACE_NAME, "bond0", - NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); - ASSERT (nm_connection_verify (connection, &error) == TRUE, - "bond-main-write", "failed to verify connection: %s", - (error && error->message) ? error->message : "(unknown)"); + nmtst_assert_connection_verifies_without_normalization (connection); /* Save the ifcfg */ success = writer_new_connection (connection, @@ -13150,13 +12097,12 @@ test_write_bond_main (void) "bond-main-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_BOND, - NULL, &unmanaged, &keyfile, &routefile, @@ -13197,12 +12143,9 @@ test_read_bond_slave (void) gboolean ignore_error = FALSE; GError *error = NULL; - g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, - "*ignoring IP4 config on slave*"); connection = connection_from_file (TEST_IFCFG_BOND_SLAVE, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13244,8 +12187,7 @@ test_write_bond_slave (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; - GByteArray *mac; + static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; char *uuid; gboolean success; @@ -13257,7 +12199,7 @@ test_write_bond_slave (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -13278,14 +12220,10 @@ test_write_bond_slave (void) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); - g_byte_array_free (mac, TRUE); ASSERT (nm_connection_verify (connection, &error) == TRUE, "bond-slave-write", "failed to verify connection: %s", @@ -13304,13 +12242,12 @@ test_write_bond_slave (void) "bond-slave-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, &unmanaged, &keyfile, &routefile, @@ -13353,14 +12290,13 @@ test_read_infiniband (void) char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[INFINIBAND_ALEN] = { 0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22 }; const char *transport_mode; connection = connection_from_file (TEST_IFCFG_INFINIBAND, NULL, TYPE_INFINIBAND, - NULL, &unmanaged, &keyfile, &routefile, @@ -13385,18 +12321,13 @@ test_read_infiniband (void) NM_SETTING_INFINIBAND_SETTING_NAME); /* MAC address */ - array = nm_setting_infiniband_get_mac_address (s_infiniband); - ASSERT (array != NULL, + mac = nm_setting_infiniband_get_mac_address (s_infiniband); + ASSERT (mac != NULL, "infiniband-verify-infiniband", "failed to verify %s: missing %s / %s key", TEST_IFCFG_INFINIBAND, NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_MAC_ADDRESS); - ASSERT (array->len == INFINIBAND_ALEN, - "infiniband-verify-infiniband", "failed to verify %s: unexpected %s / %s key value length", - TEST_IFCFG_INFINIBAND, - NM_SETTING_INFINIBAND_SETTING_NAME, - NM_SETTING_INFINIBAND_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "infiniband-verify-infiniband", "failed to verify %s: unexpected %s / %s key value", TEST_IFCFG_INFINIBAND, NM_SETTING_INFINIBAND_SETTING_NAME, @@ -13429,16 +12360,12 @@ test_write_infiniband (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; - unsigned char tmpmac[INFINIBAND_ALEN] = { 0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22 }; - GByteArray *mac; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; guint32 mtu = 65520; char *uuid; - const guint32 ip1 = htonl (0x01010103); - const guint32 gw = htonl (0x01010101); - const guint32 prefix = 24; - NMIP4Address *addr; + NMIPAddress *addr; gboolean success; GError *error = NULL; char *testfile = NULL; @@ -13448,7 +12375,7 @@ test_write_infiniband (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -13467,38 +12394,33 @@ test_write_infiniband (void) s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); nm_connection_add_setting (connection, NM_SETTING (s_infiniband)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NM_SETTING_INFINIBAND_MTU, mtu, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "connected", NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, NULL); - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, ip1); - nm_ip4_address_set_prefix (addr, prefix); - nm_ip4_address_set_gateway (addr, gw); - nm_setting_ip4_config_add_address (s_ip4, addr); - nm_ip4_address_unref (addr); + addr = nm_ip_address_new (AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip4, addr); + nm_ip_address_unref (addr); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, @@ -13518,13 +12440,12 @@ test_write_infiniband (void) "infiniband-write", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, TYPE_INFINIBAND, - NULL, &unmanaged, &keyfile, &routefile, @@ -13565,12 +12486,9 @@ test_read_bond_slave_ib (void) gboolean ignore_error = FALSE; GError *error = NULL; - g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, - "*ignoring IP4 config on slave*"); connection = connection_from_file (TEST_IFCFG_BOND_SLAVE_IB, NULL, NULL, - NULL, &unmanaged, &keyfile, &routefile, @@ -13612,11 +12530,7 @@ test_write_bond_slave_ib (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; - static unsigned char tmpmac[] = { - 0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, - 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22 - }; - GByteArray *mac; + static const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; char *uuid; gboolean success; GError *error = NULL; @@ -13627,7 +12541,7 @@ test_write_bond_slave_ib (void) char *route6file = NULL; gboolean ignore_error = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -13648,15 +12562,11 @@ test_write_bond_slave_ib (void) s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); nm_connection_add_setting (connection, NM_SETTING (s_infiniband)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); - g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NM_SETTING_INFINIBAND_MTU, 2044, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); - g_byte_array_free (mac, TRUE); ASSERT (nm_connection_verify (connection, &error) == TRUE, "bond-slave-write-ib", "failed to verify connection: %s", @@ -13675,13 +12585,12 @@ test_write_bond_slave_ib (void) "bond-slave-write-ib", "didn't get ifcfg file path back after writing connection"); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + nm_connection_normalize (connection, NULL, NULL, NULL); /* re-read the connection for comparison */ reread = connection_from_file (testfile, NULL, NULL, - NULL, &unmanaged, &keyfile, &routefile, @@ -13731,7 +12640,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); @@ -13787,8 +12696,8 @@ test_write_dcb_basic (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; gboolean success, ignore_error; guint i; char *uuid, *testfile; @@ -13799,7 +12708,7 @@ test_write_dcb_basic (void) const guint traffic_classes[8] = { 3, 4, 7, 2, 1, 0, 5, 6 }; const gboolean pfcs[8] = { TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE }; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); @@ -13817,12 +12726,12 @@ test_write_dcb_basic (void) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP stuff */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); - g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); + g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); /* DCB */ @@ -13864,7 +12773,7 @@ test_write_dcb_basic (void) reread = connection_from_file (testfile, NULL, TYPE_ETHERNET, - NULL, NULL, NULL, + NULL, NULL, NULL, NULL, &error, &ignore_error); @@ -13889,7 +12798,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); @@ -13920,10 +12829,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "invalid boolean digit")); g_assert (connection == NULL); } @@ -13937,10 +12846,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "boolean array must be 8 characters")); g_assert (connection == NULL); } @@ -13954,10 +12863,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "invalid uint digit")); g_assert (connection == NULL); } @@ -13971,10 +12880,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "uint array must be 8 characters")); g_assert (connection == NULL); } @@ -13988,10 +12897,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "invalid percent element")); g_assert (connection == NULL); } @@ -14005,10 +12914,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "percent array must be 8 elements")); g_assert (connection == NULL); } @@ -14022,10 +12931,10 @@ 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); + g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); g_assert (strstr (error->message, "invalid percentage sum")); g_assert (connection == NULL); } @@ -14041,7 +12950,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); @@ -14067,12 +12976,12 @@ test_write_fcoe_mode (gconstpointer user_data) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; gboolean success, ignore_error; char *uuid, *testfile; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); @@ -14090,12 +12999,12 @@ test_write_fcoe_mode (gconstpointer user_data) nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP stuff */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); - g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); + g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); /* DCB */ @@ -14134,7 +13043,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); @@ -14161,7 +13070,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); @@ -14169,13 +13078,14 @@ test_read_team_master (void) g_assert_no_error (error); g_assert (success); + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "team0"); + 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_TEAM_SETTING_NAME); s_team = nm_connection_get_setting_team (connection); g_assert (s_team); - g_assert_cmpstr (nm_setting_team_get_interface_name (s_team), ==, "team0"); g_assert_cmpstr (nm_setting_team_get_config (s_team), ==, expected_config); g_object_unref (connection); @@ -14188,6 +13098,8 @@ test_write_team_master (void) NMSettingConnection *s_con; NMSettingTeam *s_team; NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid, *testfile = NULL, *val; gboolean success; GError *error = NULL; @@ -14195,7 +13107,7 @@ test_write_team_master (void) const char *escaped_expected_config = "\"{ \\\"device\\\": \\\"team0\\\", \\\"link_watch\\\": { \\\"name\\\": \\\"ethtool\\\" } }\""; shvarFile *f; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -14205,6 +13117,7 @@ test_write_team_master (void) g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Master", NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_INTERFACE_NAME, "team0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); g_free (uuid); @@ -14214,7 +13127,6 @@ test_write_team_master (void) nm_connection_add_setting (connection, NM_SETTING (s_team)); g_object_set (s_team, - NM_SETTING_TEAM_INTERFACE_NAME, "team0", NM_SETTING_TEAM_CONFIG, expected_config, NULL); @@ -14222,9 +13134,25 @@ test_write_team_master (void) s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - success = nm_connection_verify (connection, &error); - g_assert_no_error (error); - g_assert (success); + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); + g_assert (s_ip4); + nm_connection_add_setting (connection, NM_SETTING (s_ip4)); + + g_object_set (s_ip4, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); + g_assert (s_ip6); + nm_connection_add_setting (connection, NM_SETTING (s_ip6)); + + g_object_set (s_ip6, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + + nmtst_assert_connection_verifies_without_normalization (connection); /* Save the ifcfg */ success = writer_new_connection (connection, @@ -14250,10 +13178,10 @@ test_write_team_master (void) svCloseFile (f); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + 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); @@ -14281,7 +13209,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); @@ -14315,7 +13243,7 @@ test_write_team_port (void) const char *escaped_expected_config = "\"{ \\\"p4p1\\\": { \\\"prio\\\": -10, \\\"sticky\\\": true } }\""; shvarFile *f; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -14373,10 +13301,10 @@ test_write_team_port (void) svCloseFile (f); /* reread will be normalized, so we must normalize connection too. */ - nm_utils_normalize_connection (connection, TRUE); + 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); @@ -14402,7 +13330,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); @@ -14415,8 +13343,11 @@ test_read_team_port_empty_config (void) g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); g_assert_cmpstr (nm_setting_connection_get_master (s_con), ==, "team0"); - /* Empty TEAM_PORT_CONFIG means no team-port setting */ - g_assert (nm_connection_get_setting_team_port (connection) == NULL); + /* Normalization adds a team-port setting */ + g_assert (nm_connection_get_setting_team_port (connection)); + + /* empty/missing config */ + g_assert (!nm_setting_team_port_get_config (nm_connection_get_setting_team_port (connection))); g_object_unref (connection); } @@ -14468,13 +13399,13 @@ test_svUnescape_assert (const char *str) } static void -test_svUnescape () +test_svUnescape (void) { int len, repeat, i, k; - GRand *rand = g_rand_new (); + GRand *r = g_rand_new (); guint32 seed = g_random_int (); - g_rand_set_seed (rand, seed); + g_rand_set_seed (r, seed); test_svUnescape_assert (""); test_svUnescape_assert ("'"); @@ -14495,16 +13426,16 @@ test_svUnescape () /* fill the entire string with random. */ for (i = 0; i < len; i++) - s[i] = g_rand_int (rand); + s[i] = g_rand_int (r); /* randomly place escape characters into the string */ - k = g_rand_int (rand) % (len); + k = g_rand_int (r) % (len); while (k-- > 0) - s[g_rand_int (rand) % len] = '\\'; + s[g_rand_int (r) % len] = '\\'; if (len > 1) { /* quote the string. */ - k = g_rand_int (rand) % (10); + k = g_rand_int (r) % (10); if (k < 4) { char quote = k < 2 ? '"' : '\''; @@ -14520,7 +13451,44 @@ test_svUnescape () g_free (s); } - g_rand_free (rand); + g_rand_free (r); +} + +static void +test_read_vlan_trailing_spaces (void) +{ + const char *testfile = TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-trailing-spaces"; + NMConnection *connection; + gboolean success; + GError *error = NULL; + NMSettingVlan *s_vlan; + char *contents = NULL; + + /* Ensure there is whitespace at the end of the VLAN interface name, + * to prevent the whitespace getting stripped off and committed mistakenly + * by something in the future. + */ + success = g_file_get_contents (testfile, &contents, NULL, &error); + g_assert_no_error (error); + g_assert (success); + g_assert (contents && contents[0]); + g_assert (strstr (contents, "DEVICE=\"vlan201\" \n")); + g_free (contents); + + connection = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL, + NULL, NULL, NULL, &error, NULL); + g_assert_no_error (error); + g_assert (connection != NULL); + + s_vlan = nm_connection_get_setting_vlan (connection); + g_assert (s_vlan); + + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan201"); + g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "enccw0.0.fb00"); + g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 201); + g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, 0); + + g_object_unref (connection); } @@ -14548,11 +13516,13 @@ int main (int argc, char **argv) nmtst_init_assert_logging (&argc, &argv); g_test_add_func (TPATH "svUnescape", test_svUnescape); + g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); g_test_add_func (TPATH "unmanaged", test_read_unmanaged); g_test_add_func (TPATH "unmanaged-unrecognized", test_read_unmanaged_unrecognized); g_test_add_func (TPATH "unrecognized", test_read_unrecognized); g_test_add_func (TPATH "basic", test_read_basic); + g_test_add_func (TPATH "miscellaneous-variables", test_read_miscellaneous_variables); g_test_add_func (TPATH "variables-corner-cases", test_read_variables_corner_cases); g_test_add_data_func (TPATH "no-prefix/8", GUINT_TO_POINTER (8), test_read_wired_static_no_prefix); g_test_add_data_func (TPATH "no-prefix/16", GUINT_TO_POINTER (16), test_read_wired_static_no_prefix); @@ -14560,18 +13530,18 @@ int main (int argc, char **argv) g_test_add_data_func (TPATH "static-ip6-only-gw/_NULL_", NULL, test_write_wired_static_ip6_only_gw); g_test_add_data_func (TPATH "static-ip6-only-gw/::", "::", test_write_wired_static_ip6_only_gw); g_test_add_data_func (TPATH "static-ip6-only-gw/2001:db8:8:4::2", "2001:db8:8:4::2", test_write_wired_static_ip6_only_gw); - g_test_add_data_func (TPATH "static-ip6-only-gw/ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255", "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255", test_write_wired_static_ip6_only_gw); + g_test_add_data_func (TPATH "static-ip6-only-gw/::ffff:255.255.255.255", "::ffff:255.255.255.255", test_write_wired_static_ip6_only_gw); test_read_wired_static (TEST_IFCFG_WIRED_STATIC, "System test-wired-static", TRUE); test_read_wired_static (TEST_IFCFG_WIRED_STATIC_BOOTPROTO, "System test-wired-static-bootproto", FALSE); 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"); @@ -14617,6 +13587,9 @@ int main (int argc, char **argv) test_read_wifi_wpa_eap_tls (); test_read_wifi_wpa_eap_ttls_tls (); test_read_wifi_wep_eap_ttls_chap (); + g_test_add_func (TPATH "wifi/read-band-a", test_read_wifi_band_a); + g_test_add_func (TPATH "wifi/read-band-a-channel-mismatch", test_read_wifi_band_a_channel_mismatch); + g_test_add_func (TPATH "wifi/read-band-bg-channel-mismatch", test_read_wifi_band_bg_channel_mismatch); g_test_add_func (TPATH "wifi/read-hidden", test_read_wifi_hidden); test_read_wired_qeth_static (); test_read_wired_ctc_static (); @@ -14697,6 +13670,7 @@ int main (int argc, char **argv) test_write_wifi_wpa_then_open (); test_write_wifi_wpa_then_wep_with_perms (); g_test_add_func (TPATH "wifi/write-hidden", test_write_wifi_hidden); + g_test_add_func (TPATH "wifi/write-band-a", test_write_wifi_band_a); test_write_wired_qeth_dhcp (); test_write_wired_ctc_dhcp (); test_write_permissions (); @@ -14707,14 +13681,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); diff --git a/src/settings/plugins/ifcfg-rh/utils.c b/src/settings/plugins/ifcfg-rh/utils.c index 8318a65d..5b9e9d79 100644 --- a/src/settings/plugins/ifcfg-rh/utils.c +++ b/src/settings/plugins/ifcfg-rh/utils.c @@ -18,9 +18,14 @@ * (C) Copyright 2008 - 2012 Red Hat, Inc. */ +#include "config.h" + #include <glib.h> #include <stdlib.h> #include <string.h> + +#include "nm-core-internal.h" + #include "utils.h" #include "shvar.h" @@ -37,7 +42,7 @@ char * utils_single_quote_string (const char *str) { - static const char const drop_chars[] = "\r\n"; /* drop CR and LF */ + static const char *drop_chars = "\r\n"; /* drop CR and LF */ static const char escape_char = '\\'; /* escape char is backslash */ static const char quote_char = '\''; /* quote char is single quote */ size_t i, slen, j = 0; diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 60af599b..f4ffffd6 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -15,9 +15,11 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2009 - 2013 Red Hat, Inc. + * Copyright 2009 - 2014 Red Hat, Inc. */ +#include "config.h" + #include <string.h> #include <sys/types.h> #include <sys/socket.h> @@ -27,7 +29,6 @@ #include <sys/stat.h> #include <unistd.h> #include <stdio.h> -#include <netinet/ether.h> #include <nm-setting-connection.h> #include <nm-setting-wired.h> @@ -39,7 +40,7 @@ #include <nm-setting-vlan.h> #include <nm-setting-team.h> #include <nm-setting-team-port.h> -#include <nm-utils-private.h> +#include "nm-core-internal.h" #include <nm-utils.h> #include "nm-logging.h" @@ -52,13 +53,6 @@ static void -svSetValue_free (shvarFile *s, const char *key, char *value, gboolean verbatim) -{ - svSetValue (s, key, value, verbatim); - g_free (value); -} - -static void save_secret_flags (shvarFile *ifcfg, const char *key, NMSettingSecretFlags flags) @@ -156,7 +150,7 @@ write_secret_file (const char *path, errno = 0; fd = mkstemp (tmppath); if (fd < 0) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not create temporary file for '%s': %d", path, errno); goto out; @@ -167,7 +161,7 @@ write_secret_file (const char *path, if (fchmod (fd, S_IRUSR | S_IWUSR)) { close (fd); unlink (tmppath); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not set permissions for temporary file '%s': %d", path, errno); goto out; @@ -178,7 +172,7 @@ write_secret_file (const char *path, if (written != len) { close (fd); unlink (tmppath); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not write temporary file for '%s': %d", path, errno); goto out; @@ -189,7 +183,7 @@ write_secret_file (const char *path, errno = 0; if (rename (tmppath, path)) { unlink (tmppath); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not rename temporary file to '%s': %d", path, errno); goto out; @@ -205,7 +199,7 @@ typedef struct ObjectType { const char *setting_key; NMSetting8021xCKScheme (*scheme_func)(NMSetting8021x *setting); const char * (*path_func) (NMSetting8021x *setting); - const GByteArray * (*blob_func) (NMSetting8021x *setting); + GBytes * (*blob_func) (NMSetting8021x *setting); const char *ifcfg_key; const char *suffix; } ObjectType; @@ -290,7 +284,7 @@ write_object (NMSetting8021x *s_8021x, { NMSetting8021xCKScheme scheme; const char *path = NULL; - const GByteArray *blob = NULL; + GBytes *blob = NULL; g_return_val_if_fail (ifcfg != NULL, FALSE); g_return_val_if_fail (objtype != NULL, FALSE); @@ -345,7 +339,7 @@ write_object (NMSetting8021x *s_8021x, new_file = utils_cert_path (ifcfg->fileName, objtype->suffix); if (!new_file) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not create file path for %s / %s", NM_SETTING_802_1X_SETTING_NAME, objtype->setting_key); return FALSE; @@ -355,13 +349,16 @@ write_object (NMSetting8021x *s_8021x, * can use paths from now on instead of pushing around the certificate * data itself. */ - success = write_secret_file (new_file, (const char *) blob->data, blob->len, &write_error); + success = write_secret_file (new_file, + (const char *) g_bytes_get_data (blob, NULL), + g_bytes_get_size (blob), + &write_error); if (success) { svSetValue (ifcfg, objtype->ifcfg_key, new_file, FALSE); g_free (new_file); return TRUE; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not write certificate/key for %s / %s: %s", NM_SETTING_802_1X_SETTING_NAME, objtype->setting_key, (write_error && write_error->message) ? write_error->message : "(unknown)"); @@ -614,7 +611,7 @@ write_wireless_security_setting (NMConnection *connection, s_wsec = nm_connection_get_setting_wireless_security (connection); if (!s_wsec) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); return FALSE; } @@ -808,49 +805,37 @@ write_wireless_setting (NMConnection *connection, { NMSettingWireless *s_wireless; char *tmp, *tmp2; - const GByteArray *ssid, *device_mac, *cloned_mac, *bssid; - const char *mode; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; + const char *mode, *bssid; + const char *device_mac, *cloned_mac; char buf[33]; guint32 mtu, chan, i; gboolean adhoc = FALSE, hex_ssid = FALSE; - const GSList *macaddr_blacklist; + const char * const *macaddr_blacklist; s_wireless = nm_connection_get_setting_wireless (connection); if (!s_wireless) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; } - svSetValue (ifcfg, "HWADDR", NULL, FALSE); device_mac = nm_setting_wireless_get_mac_address (s_wireless); - if (device_mac) { - svSetValue_free (ifcfg, "HWADDR", - nm_utils_hwaddr_ntoa_len (device_mac->data, device_mac->len), FALSE); - } + svSetValue (ifcfg, "HWADDR", device_mac, FALSE); - svSetValue (ifcfg, "MACADDR", NULL, FALSE); cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless); - if (cloned_mac) { - svSetValue_free (ifcfg, "MACADDR", - nm_utils_hwaddr_ntoa_len (cloned_mac->data, cloned_mac->len), FALSE); - } + svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE); macaddr_blacklist = nm_setting_wireless_get_mac_address_blacklist (s_wireless); - if (macaddr_blacklist) { - const GSList *iter; - GString *blacklist_str = g_string_new (NULL); + if (macaddr_blacklist[0]) { + char *blacklist_str; - for (iter = macaddr_blacklist; iter; iter = g_slist_next (iter)) { - g_string_append (blacklist_str, iter->data); - g_string_append_c (blacklist_str, ' '); - - } - if (blacklist_str->len > 0) - g_string_truncate (blacklist_str, blacklist_str->len - 1); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str->str, FALSE); - g_string_free (blacklist_str, TRUE); + blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); + svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str, FALSE); + g_free (blacklist_str); } svSetValue (ifcfg, "MTU", NULL, FALSE); @@ -863,12 +848,13 @@ write_wireless_setting (NMConnection *connection, ssid = nm_setting_wireless_get_ssid (s_wireless); if (!ssid) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; } - if (!ssid->len || ssid->len > 32) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + ssid_data = g_bytes_get_data (ssid, &ssid_len); + if (!ssid_len || ssid_len > 32) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Invalid SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; } @@ -876,8 +862,8 @@ write_wireless_setting (NMConnection *connection, /* If the SSID contains any non-printable characters, we need to use the * hex notation of the SSID instead. */ - for (i = 0; i < ssid->len; i++) { - if (!g_ascii_isprint (ssid->data[i])) { + for (i = 0; i < ssid_len; i++) { + if (!g_ascii_isprint (ssid_data[i])) { hex_ssid = TRUE; break; } @@ -887,16 +873,16 @@ write_wireless_setting (NMConnection *connection, GString *str; /* Hex SSIDs don't get quoted */ - str = g_string_sized_new (ssid->len * 2 + 3); + str = g_string_sized_new (ssid_len * 2 + 3); g_string_append (str, "0x"); - for (i = 0; i < ssid->len; i++) - g_string_append_printf (str, "%02X", ssid->data[i]); + for (i = 0; i < ssid_len; i++) + g_string_append_printf (str, "%02X", ssid_data[i]); svSetValue (ifcfg, "ESSID", str->str, TRUE); g_string_free (str, TRUE); } else { /* Printable SSIDs always get quoted */ memset (buf, 0, sizeof (buf)); - memcpy (buf, ssid->data, ssid->len); + memcpy (buf, ssid_data, ssid_len); tmp = svEscape (buf); /* svEscape will usually quote the string, but just for consistency, @@ -917,27 +903,29 @@ write_wireless_setting (NMConnection *connection, } else if (!strcmp (mode, "adhoc")) { svSetValue (ifcfg, "MODE", "Ad-Hoc", FALSE); adhoc = TRUE; + } else if (!strcmp (mode, "ap")) { + svSetValue (ifcfg, "MODE", "Ap", FALSE); } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Invalid mode '%s' in '%s' setting", mode, NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; } svSetValue (ifcfg, "CHANNEL", NULL, FALSE); + svSetValue (ifcfg, "BAND", NULL, FALSE); chan = nm_setting_wireless_get_channel (s_wireless); if (chan) { tmp = g_strdup_printf ("%u", chan); svSetValue (ifcfg, "CHANNEL", tmp, FALSE); g_free (tmp); + } else { + /* Band only set if channel is not, since channel implies band */ + svSetValue (ifcfg, "BAND", nm_setting_wireless_get_band (s_wireless), FALSE); } - svSetValue (ifcfg, "BSSID", NULL, FALSE); bssid = nm_setting_wireless_get_bssid (s_wireless); - if (bssid) { - svSetValue_free (ifcfg, "BSSID", - nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len), FALSE); - } + svSetValue (ifcfg, "BSSID", bssid, FALSE); /* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security; * otherwise there's no way to detect WEP vs. open when WEP keys aren't @@ -994,26 +982,20 @@ static gboolean write_infiniband_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) { NMSettingInfiniband *s_infiniband; - const GByteArray *mac; char *tmp; - const char *transport_mode, *parent; + const char *mac, *transport_mode, *parent; guint32 mtu; int p_key; s_infiniband = nm_connection_get_setting_infiniband (connection); if (!s_infiniband) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_INFINIBAND_SETTING_NAME); return FALSE; } - svSetValue (ifcfg, "HWADDR", NULL, FALSE); mac = nm_setting_infiniband_get_mac_address (s_infiniband); - if (mac) { - tmp = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_INFINIBAND); - svSetValue (ifcfg, "HWADDR", tmp, FALSE); - g_free (tmp); - } + svSetValue (ifcfg, "HWADDR", mac, FALSE); svSetValue (ifcfg, "MTU", NULL, FALSE); mtu = nm_setting_infiniband_get_mtu (s_infiniband); @@ -1049,50 +1031,35 @@ static gboolean write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) { NMSettingWired *s_wired; - const GByteArray *device_mac, *cloned_mac; + const char *device_mac, *cloned_mac; char *tmp; const char *nettype, *portname, *ctcprot, *s390_key, *s390_val; guint32 mtu, num_opts, i; - const GPtrArray *s390_subchannels; + const char *const *s390_subchannels; GString *str; - const GSList *macaddr_blacklist; + const char * const *macaddr_blacklist; s_wired = nm_connection_get_setting_wired (connection); if (!s_wired) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_WIRED_SETTING_NAME); return FALSE; } - svSetValue (ifcfg, "HWADDR", NULL, FALSE); device_mac = nm_setting_wired_get_mac_address (s_wired); - if (device_mac) { - svSetValue_free (ifcfg, "HWADDR", - nm_utils_hwaddr_ntoa_len (device_mac->data, device_mac->len), FALSE); - } + svSetValue (ifcfg, "HWADDR", device_mac, FALSE); - svSetValue (ifcfg, "MACADDR", NULL, FALSE); cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - if (cloned_mac) { - svSetValue_free (ifcfg, "MACADDR", - nm_utils_hwaddr_ntoa_len (cloned_mac->data, cloned_mac->len), FALSE); - } + svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE); macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); - if (macaddr_blacklist) { - const GSList *iter; - GString *blacklist_str = g_string_new (NULL); - - for (iter = macaddr_blacklist; iter; iter = g_slist_next (iter)) { - g_string_append (blacklist_str, iter->data); - g_string_append_c (blacklist_str, ' '); + if (macaddr_blacklist[0]) { + char *blacklist_str; - } - if (blacklist_str->len > 0) - g_string_truncate (blacklist_str, blacklist_str->len - 1); - svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str->str, FALSE); - g_string_free (blacklist_str, TRUE); + blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist); + svSetValue (ifcfg, "HWADDR_BLACKLIST", blacklist_str, FALSE); + g_free (blacklist_str); } svSetValue (ifcfg, "MTU", NULL, FALSE); @@ -1106,16 +1073,14 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "SUBCHANNELS", NULL, FALSE); s390_subchannels = nm_setting_wired_get_s390_subchannels (s_wired); if (s390_subchannels) { + int len = g_strv_length ((char **)s390_subchannels); + tmp = NULL; - if (s390_subchannels->len == 2) { - tmp = g_strdup_printf ("%s,%s", - (const char *) g_ptr_array_index (s390_subchannels, 0), - (const char *) g_ptr_array_index (s390_subchannels, 1)); - } else if (s390_subchannels->len == 3) { - tmp = g_strdup_printf ("%s,%s,%s", - (const char *) g_ptr_array_index (s390_subchannels, 0), - (const char *) g_ptr_array_index (s390_subchannels, 1), - (const char *) g_ptr_array_index (s390_subchannels, 2)); + if (len == 2) { + tmp = g_strdup_printf ("%s,%s", s390_subchannels[0], s390_subchannels[1]); + } else if (len == 3) { + tmp = g_strdup_printf ("%s,%s,%s", s390_subchannels[0], s390_subchannels[1], + s390_subchannels[2]); } svSetValue (ifcfg, "SUBCHANNELS", tmp, FALSE); g_free (tmp); @@ -1161,11 +1126,11 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) return TRUE; } -static GString * +static char * vlan_priority_maplist_to_stringlist (NMSettingVlan *s_vlan, NMVlanPriorityMap map) { - GSList *strlist = NULL, *iter; - GString *value = NULL; + char **strlist; + char *value; if (map == NM_VLAN_INGRESS_MAP) g_object_get (G_OBJECT (s_vlan), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, &strlist, NULL); @@ -1174,11 +1139,11 @@ vlan_priority_maplist_to_stringlist (NMSettingVlan *s_vlan, NMVlanPriorityMap ma else return NULL; - value = g_string_new (""); - for (iter = strlist; iter; iter = g_slist_next (iter)) - g_string_append_printf (value, "%s%s", value->len ? "," : "", (const char *) iter->data); - - g_slist_free_full (strlist, g_free); + if (strlist[0]) + value = g_strjoinv (",", strlist); + else + value = NULL; + g_strfreev (strlist); return value; } @@ -1191,25 +1156,25 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, NMSettingWired *s_wired; char *tmp; guint32 vlan_flags = 0; - GString *text = NULL; s_con = nm_connection_get_setting_connection (connection); if (!s_con) { - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "Missing connection setting"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing connection setting"); return FALSE; } s_vlan = nm_connection_get_setting_vlan (connection); if (!s_vlan) { - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "Missing VLAN setting"); + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing VLAN setting"); return FALSE; } svSetValue (ifcfg, "VLAN", "yes", FALSE); svSetValue (ifcfg, "TYPE", TYPE_VLAN, FALSE); - svSetValue (ifcfg, "DEVICE", nm_setting_vlan_get_interface_name (s_vlan), FALSE); + svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con), FALSE); svSetValue (ifcfg, "PHYSDEV", nm_setting_vlan_get_parent (s_vlan), FALSE); - svSetValue (ifcfg, "MASTER", nm_setting_connection_get_master (s_con), FALSE); tmp = g_strdup_printf ("%d", nm_setting_vlan_get_id (s_vlan)); svSetValue (ifcfg, "VLAN_ID", tmp, FALSE); @@ -1230,15 +1195,13 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, } else if (vlan_flags & NM_VLAN_FLAG_LOOSE_BINDING) svSetValue (ifcfg, "VLAN_FLAGS", "LOOSE_BINDING", FALSE); - text = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); - svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", text ? text->str : NULL, FALSE); - if (text) - g_string_free (text, TRUE); + tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_INGRESS_MAP); + svSetValue (ifcfg, "VLAN_INGRESS_PRIORITY_MAP", tmp, FALSE); + g_free (tmp); - text = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP); - svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", text ? text->str : NULL, FALSE); - if (text) - g_string_free (text, TRUE); + tmp = vlan_priority_maplist_to_stringlist (s_vlan, NM_VLAN_EGRESS_MAP); + svSetValue (ifcfg, "VLAN_EGRESS_PRIORITY_MAP", tmp, FALSE); + g_free (tmp); svSetValue (ifcfg, "HWADDR", NULL, FALSE); svSetValue (ifcfg, "MACADDR", NULL, FALSE); @@ -1246,24 +1209,18 @@ write_vlan_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, s_wired = nm_connection_get_setting_wired (connection); if (s_wired) { - const GByteArray *device_mac, *cloned_mac; + const char *device_mac, *cloned_mac; guint32 mtu; *wired = TRUE; device_mac = nm_setting_wired_get_mac_address (s_wired); - if (device_mac) { - tmp = nm_utils_hwaddr_ntoa (device_mac->data, ARPHRD_ETHER); - svSetValue (ifcfg, "HWADDR", tmp, FALSE); - g_free (tmp); - } + if (device_mac) + svSetValue (ifcfg, "HWADDR", device_mac, FALSE); cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired); - if (cloned_mac) { - tmp = nm_utils_hwaddr_ntoa (cloned_mac->data, ARPHRD_ETHER); - svSetValue (ifcfg, "MACADDR", tmp, FALSE); - g_free (tmp); - } + if (cloned_mac) + svSetValue (ifcfg, "MACADDR", cloned_mac, FALSE); mtu = nm_setting_wired_get_mtu (s_wired); if (mtu) { @@ -1285,14 +1242,15 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, GError **erro s_bond = nm_connection_get_setting_bond (connection); if (!s_bond) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_BOND_SETTING_NAME); return FALSE; } - iface = nm_setting_bond_get_interface_name (s_bond); + iface = nm_connection_get_interface_name (connection); if (!iface) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "Missing interface name"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing interface name"); return FALSE; } @@ -1336,14 +1294,15 @@ write_team_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) s_team = nm_connection_get_setting_team (connection); if (!s_team) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_TEAM_SETTING_NAME); return FALSE; } - iface = nm_setting_team_get_interface_name (s_team); + iface = nm_connection_get_interface_name (connection); if (!iface) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "Missing interface name"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing interface name"); return FALSE; } @@ -1379,19 +1338,20 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error const char *iface; guint32 i; GString *opts; - const GByteArray *mac; + const char *mac; char *s; s_bridge = nm_connection_get_setting_bridge (connection); if (!s_bridge) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing '%s' setting", NM_SETTING_BRIDGE_SETTING_NAME); return FALSE; } - iface = nm_setting_bridge_get_interface_name (s_bridge); + iface = nm_connection_get_interface_name (connection); if (!iface) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "Missing interface name"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "Missing interface name"); return FALSE; } @@ -1399,11 +1359,9 @@ write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error svSetValue (ifcfg, "BRIDGING_OPTS", NULL, FALSE); svSetValue (ifcfg, "STP", "no", FALSE); svSetValue (ifcfg, "DELAY", NULL, FALSE); - svSetValue (ifcfg, "MACADDR", NULL, FALSE); mac = nm_setting_bridge_get_mac_address (s_bridge); - if (mac) - svSetValue_free (ifcfg, "MACADDR", nm_utils_hwaddr_ntoa_len (mac->data, mac->len), FALSE); + svSetValue (ifcfg, "MACADDR", mac, FALSE); /* Bridge options */ opts = g_string_sized_new (32); @@ -1701,6 +1659,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) GString *str; const char *master; char *tmp; + gint i_int; svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con), FALSE); svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con), FALSE); @@ -1709,6 +1668,12 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no", FALSE); + i_int = nm_setting_connection_get_autoconnect_priority (s_con); + tmp = i_int != NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT + ? g_strdup_printf ("%d", i_int) : NULL; + svSetValue (ifcfg, "AUTOCONNECT_PRIORITY", tmp, FALSE); + g_free (tmp); + /* Permissions */ svSetValue (ifcfg, "USERS", NULL, FALSE); n = nm_setting_connection_get_num_permissions (s_con); @@ -1778,14 +1743,14 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) } static gboolean -write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError **error) +write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error) { - char dest[INET_ADDRSTRLEN]; - char next_hop[INET_ADDRSTRLEN]; + const char *dest, *next_hop; char **route_items; char *route_contents; - NMIP4Route *route; - guint32 ip, prefix, metric; + NMIPRoute *route; + guint32 prefix; + gint64 metric; guint32 i, num; gboolean success = FALSE; @@ -1794,7 +1759,7 @@ write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError g_return_val_if_fail (error != NULL, FALSE); g_return_val_if_fail (*error == NULL, FALSE); - num = nm_setting_ip4_config_get_num_routes (s_ip4); + num = nm_setting_ip_config_get_num_routes (s_ip4); if (num == 0) { unlink (filename); return TRUE; @@ -1802,28 +1767,24 @@ write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError route_items = g_malloc0 (sizeof (char*) * (num + 1)); for (i = 0; i < num; i++) { - route = nm_setting_ip4_config_get_route (s_ip4, i); - - memset (dest, 0, sizeof (dest)); - ip = nm_ip4_route_get_dest (route); - inet_ntop (AF_INET, (const void *) &ip, &dest[0], sizeof (dest)); - - prefix = nm_ip4_route_get_prefix (route); + route = nm_setting_ip_config_get_route (s_ip4, i); - memset (next_hop, 0, sizeof (next_hop)); - ip = nm_ip4_route_get_next_hop (route); - inet_ntop (AF_INET, (const void *) &ip, &next_hop[0], sizeof (next_hop)); + dest = nm_ip_route_get_dest (route); + prefix = nm_ip_route_get_prefix (route); + next_hop = nm_ip_route_get_next_hop (route); + metric = nm_ip_route_get_metric (route); - metric = nm_ip4_route_get_metric (route); - - route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, metric); + if (metric == -1) + route_items[i] = g_strdup_printf ("%s/%u via %s\n", dest, prefix, next_hop); + else + route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, (guint32) metric); } route_items[num] = NULL; route_contents = g_strjoinv (NULL, route_items); g_strfreev (route_items); if (!g_file_set_contents (filename, route_contents, -1, NULL)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Writing route file '%s' failed", filename); goto error; } @@ -1839,7 +1800,7 @@ error: static gboolean write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) { - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; const char *value; char *addr_key, *prefix_key, *netmask_key, *gw_key, *metric_key, *tmp; char *route_path = NULL; @@ -1852,7 +1813,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) s_ip4 = nm_connection_get_setting_ip4_config (connection); if (s_ip4) - method = nm_setting_ip4_config_get_method (s_ip4); + method = nm_setting_ip_config_get_method (s_ip4); /* Missing IP4 setting is assumed to be DHCP */ if (!method) @@ -1895,7 +1856,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* Temporarily create fake IP4 setting if missing; method set to DHCP above */ if (!s_ip4) { - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); fake_ip4 = TRUE; } @@ -1922,14 +1883,19 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* Write out IPADDR<n>, PREFIX<n>, GATEWAY<n> for current IP addresses * without labels. Unset obsolete NETMASK<n>. */ - num = nm_setting_ip4_config_get_num_addresses (s_ip4); + num = nm_setting_ip_config_get_num_addresses (s_ip4); for (i = n = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN]; - NMIP4Address *addr; - guint32 ip; + NMIPAddress *addr; - if (i > 0 && NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i))) - continue; + addr = nm_setting_ip_config_get_address (s_ip4, i); + + if (i > 0) { + GVariant *label; + + label = nm_ip_address_get_attribute (addr, "label"); + if (label) + continue; + } if (n == 0) { /* Instead of index 0 use un-numbered variables. @@ -1948,26 +1914,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) gw_key = g_strdup_printf ("GATEWAY%d", n); } - addr = nm_setting_ip4_config_get_address (s_ip4, i); - - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_address (addr); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (ifcfg, addr_key, &buf[0], FALSE); + svSetValue (ifcfg, addr_key, nm_ip_address_get_address (addr), FALSE); - tmp = g_strdup_printf ("%u", nm_ip4_address_get_prefix (addr)); + tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); svSetValue (ifcfg, prefix_key, tmp, FALSE); g_free (tmp); svSetValue (ifcfg, netmask_key, NULL, FALSE); - - if (nm_ip4_address_get_gateway (addr)) { - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_gateway (addr); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (ifcfg, gw_key, &buf[0], FALSE); - } else - svSetValue (ifcfg, gw_key, NULL, FALSE); + svSetValue (ifcfg, gw_key, NULL, FALSE); g_free (addr_key); g_free (prefix_key); @@ -1994,32 +1948,30 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) g_free (gw_key); } - num = nm_setting_ip4_config_get_num_dns (s_ip4); + svSetValue (ifcfg, "GATEWAY", nm_setting_ip_config_get_gateway (s_ip4), FALSE); + + num = nm_setting_ip_config_get_num_dns (s_ip4); for (i = 0; i < 254; i++) { - char buf[INET_ADDRSTRLEN + 1]; - guint32 ip; + const char *dns; addr_key = g_strdup_printf ("DNS%d", i + 1); if (i >= num) svSetValue (ifcfg, addr_key, NULL, FALSE); else { - ip = nm_setting_ip4_config_get_dns (s_ip4, i); - - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (ifcfg, addr_key, &buf[0], FALSE); + dns = nm_setting_ip_config_get_dns (s_ip4, i); + svSetValue (ifcfg, addr_key, dns, FALSE); } g_free (addr_key); } - num = nm_setting_ip4_config_get_num_dns_searches (s_ip4); + num = nm_setting_ip_config_get_num_dns_searches (s_ip4); if (num > 0) { searches = g_string_new (NULL); for (i = 0; i < num; i++) { if (i > 0) g_string_append_c (searches, ' '); - g_string_append (searches, nm_setting_ip4_config_get_dns_search (s_ip4, i)); + g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip4, i)); } svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); g_string_free (searches, TRUE); @@ -2028,7 +1980,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* DEFROUTE; remember that it has the opposite meaning from never-default */ svSetValue (ifcfg, "DEFROUTE", - nm_setting_ip4_config_get_never_default (s_ip4) ? "no" : "yes", + nm_setting_ip_config_get_never_default (s_ip4) ? "no" : "yes", FALSE); svSetValue (ifcfg, "PEERDNS", NULL, FALSE); @@ -2036,14 +1988,14 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "DHCP_CLIENT_ID", NULL, FALSE); if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "PEERDNS", - nm_setting_ip4_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes", + nm_setting_ip_config_get_ignore_auto_dns (s_ip4) ? "no" : "yes", FALSE); svSetValue (ifcfg, "PEERROUTES", - nm_setting_ip4_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes", + nm_setting_ip_config_get_ignore_auto_routes (s_ip4) ? "no" : "yes", FALSE); - value = nm_setting_ip4_config_get_dhcp_hostname (s_ip4); + value = nm_setting_ip_config_get_dhcp_hostname (s_ip4); if (value) svSetValue (ifcfg, "DHCP_HOSTNAME", value, FALSE); @@ -2051,22 +2003,22 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) * in that case, because it is NM-specific variable */ svSetValue (ifcfg, "DHCP_SEND_HOSTNAME", - nm_setting_ip4_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no", + nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) ? NULL : "no", FALSE); - value = nm_setting_ip4_config_get_dhcp_client_id (s_ip4); + value = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)); if (value) svSetValue (ifcfg, "DHCP_CLIENT_ID", value, FALSE); } svSetValue (ifcfg, "IPV4_FAILURE_FATAL", - nm_setting_ip4_config_get_may_fail (s_ip4) ? "no" : "yes", + nm_setting_ip_config_get_may_fail (s_ip4) ? "no" : "yes", FALSE); /* Static routes - route-<name> file */ route_path = utils_get_route_path (ifcfg->fileName); if (!route_path) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not get route file path for '%s'", ifcfg->fileName); goto out; } @@ -2076,18 +2028,19 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) routefile = utils_get_route_ifcfg (ifcfg->fileName, TRUE); if (!routefile) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not create route file '%s'", route_path); g_free (route_path); goto out; } g_free (route_path); - num = nm_setting_ip4_config_get_num_routes (s_ip4); + num = nm_setting_ip_config_get_num_routes (s_ip4); for (i = 0; i < 256; i++) { char buf[INET_ADDRSTRLEN]; - NMIP4Route *route; - guint32 ip, metric; + NMIPRoute *route; + guint32 netmask; + gint64 metric; addr_key = g_strdup_printf ("ADDRESS%d", i); netmask_key = g_strdup_printf ("NETMASK%d", i); @@ -2100,29 +2053,23 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (routefile, gw_key, NULL, FALSE); svSetValue (routefile, metric_key, NULL, FALSE); } else { - route = nm_setting_ip4_config_get_route (s_ip4, i); + route = nm_setting_ip_config_get_route (s_ip4, i); - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_route_get_dest (route); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (routefile, addr_key, &buf[0], FALSE); + svSetValue (routefile, addr_key, nm_ip_route_get_dest (route), FALSE); memset (buf, 0, sizeof (buf)); - ip = nm_utils_ip4_prefix_to_netmask (nm_ip4_route_get_prefix (route)); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); + netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); + inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf)); svSetValue (routefile, netmask_key, &buf[0], FALSE); - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_route_get_next_hop (route); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (routefile, gw_key, &buf[0], FALSE); + svSetValue (routefile, gw_key, nm_ip_route_get_next_hop (route), FALSE); memset (buf, 0, sizeof (buf)); - metric = nm_ip4_route_get_metric (route); - if (metric == 0) + metric = nm_ip_route_get_metric (route); + if (metric == -1) svSetValue (routefile, metric_key, NULL, FALSE); else { - tmp = g_strdup_printf ("%u", metric); + tmp = g_strdup_printf ("%u", (guint32) metric); svSetValue (routefile, metric_key, tmp, FALSE); g_free (tmp); } @@ -2157,7 +2104,7 @@ out: static void write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) { - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *base_ifcfg_dir, *base_ifcfg_name, *base_name; int i, num, base_ifcfg_name_len, base_name_len; GDir *dir; @@ -2195,17 +2142,20 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) if (!s_ip4) return; - num = nm_setting_ip4_config_get_num_addresses (s_ip4); + num = nm_setting_ip_config_get_num_addresses (s_ip4); for (i = 0; i < num; i++) { + GVariant *label_var; const char *label, *p; - char buf[INET_ADDRSTRLEN], *path, *tmp; - NMIP4Address *addr; - guint32 ip; + char *path, *tmp; + NMIPAddress *addr; shvarFile *ifcfg; - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)); - if (!label) + addr = nm_setting_ip_config_get_address (s_ip4, i); + + label_var = nm_ip_address_get_attribute (addr, "label"); + if (!label_var) continue; + label = g_variant_get_string (label_var, NULL); if ( strncmp (label, base_name, base_name_len) != 0 || label[base_name_len] != ':') continue; @@ -2223,24 +2173,13 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) svSetValue (ifcfg, "DEVICE", label, FALSE); - addr = nm_setting_ip4_config_get_address (s_ip4, i); - - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_address (addr); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (ifcfg, "IPADDR", &buf[0], FALSE); + addr = nm_setting_ip_config_get_address (s_ip4, i); + svSetValue (ifcfg, "IPADDR", nm_ip_address_get_address (addr), FALSE); - tmp = g_strdup_printf ("%u", nm_ip4_address_get_prefix (addr)); + tmp = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); svSetValue (ifcfg, "PREFIX", tmp, FALSE); g_free (tmp); - if (nm_ip4_address_get_gateway (addr)) { - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_gateway (addr); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], sizeof (buf)); - svSetValue (ifcfg, "GATEWAY", &buf[0], FALSE); - } - svWriteFile (ifcfg, 0644, NULL); svCloseFile (ifcfg); } @@ -2250,15 +2189,11 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) } static gboolean -write_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **error) +write_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error) { - char dest[INET6_ADDRSTRLEN]; - char next_hop[INET6_ADDRSTRLEN]; char **route_items; char *route_contents; - NMIP6Route *route; - const struct in6_addr *ip; - guint32 prefix, metric; + NMIPRoute *route; guint32 i, num; gboolean success = FALSE; @@ -2267,7 +2202,7 @@ write_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **err g_return_val_if_fail (error != NULL, FALSE); g_return_val_if_fail (*error == NULL, FALSE); - num = nm_setting_ip6_config_get_num_routes (s_ip6); + num = nm_setting_ip_config_get_num_routes (s_ip6); if (num == 0) { unlink (filename); return TRUE; @@ -2275,28 +2210,27 @@ write_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **err route_items = g_malloc0 (sizeof (char*) * (num + 1)); for (i = 0; i < num; i++) { - route = nm_setting_ip6_config_get_route (s_ip6, i); - - memset (dest, 0, sizeof (dest)); - ip = nm_ip6_route_get_dest (route); - inet_ntop (AF_INET6, (const void *) ip, &dest[0], sizeof (dest)); - - prefix = nm_ip6_route_get_prefix (route); + route = nm_setting_ip_config_get_route (s_ip6, i); - memset (next_hop, 0, sizeof (next_hop)); - ip = nm_ip6_route_get_next_hop (route); - inet_ntop (AF_INET6, (const void *) ip, &next_hop[0], sizeof (next_hop)); - - metric = nm_ip6_route_get_metric (route); - - route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", dest, prefix, next_hop, metric); + if (nm_ip_route_get_metric (route) == -1) { + route_items[i] = g_strdup_printf ("%s/%u via %s\n", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + nm_ip_route_get_next_hop (route)); + } else { + route_items[i] = g_strdup_printf ("%s/%u via %s metric %u\n", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + nm_ip_route_get_next_hop (route), + (guint32) nm_ip_route_get_metric (route)); + } } route_items[num] = NULL; route_contents = g_strjoinv (NULL, route_items); g_strfreev (route_items); if (!g_file_set_contents (filename, route_contents, -1, NULL)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Writing route6 file '%s' failed", filename); goto error; } @@ -2311,16 +2245,14 @@ error: static gboolean write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) { - NMSettingIP6Config *s_ip6; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip6; + NMSettingIPConfig *s_ip4; const char *value; - char *addr_key, *prefix; + char *addr_key; guint32 i, num, num4; GString *searches; - char buf[INET6_ADDRSTRLEN]; - char ipv6_defaultgw[INET6_ADDRSTRLEN]; - NMIP6Address *addr; - const struct in6_addr *ip; + NMIPAddress *addr; + const char *dns; GString *ip_str1, *ip_str2, *ip_ptr; char *route6_path; @@ -2337,7 +2269,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) return TRUE; } - value = nm_setting_ip6_config_get_method (s_ip6); + value = nm_setting_ip_config_get_method (s_ip6); g_assert (value); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { svSetValue (ifcfg, "IPV6INIT", "no", FALSE); @@ -2352,7 +2284,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); svSetValue (ifcfg, "DHCPV6C", "yes", FALSE); - hostname = nm_setting_ip6_config_get_dhcp_hostname (s_ip6); + hostname = nm_setting_ip_config_get_dhcp_hostname (s_ip6); if (hostname) svSetValue (ifcfg, "DHCP_HOSTNAME", hostname, FALSE); } else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { @@ -2370,62 +2302,47 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } /* Write out IP addresses */ - num = nm_setting_ip6_config_get_num_addresses (s_ip6); + num = nm_setting_ip_config_get_num_addresses (s_ip6); ip_str1 = g_string_new (NULL); ip_str2 = g_string_new (NULL); - ipv6_defaultgw[0] = 0; for (i = 0; i < num; i++) { if (i == 0) ip_ptr = ip_str1; else ip_ptr = ip_str2; - addr = nm_setting_ip6_config_get_address (s_ip6, i); - ip = nm_ip6_address_get_address (addr); - prefix = g_strdup_printf ("%u", nm_ip6_address_get_prefix (addr)); - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); + addr = nm_setting_ip_config_get_address (s_ip6, i); + if (i > 1) g_string_append_c (ip_ptr, ' '); /* separate addresses in IPV6ADDR_SECONDARIES */ - g_string_append (ip_ptr, buf); - g_string_append_c (ip_ptr, '/'); - g_string_append (ip_ptr, prefix); - g_free (prefix); - - /* We only support gateway for the first IP address for now */ - if (i == 0) { - ip = nm_ip6_address_get_gateway (addr); - if (!IN6_IS_ADDR_UNSPECIFIED (ip)) - inet_ntop (AF_INET6, ip, ipv6_defaultgw, sizeof (ipv6_defaultgw)); - } + g_string_append_printf (ip_ptr, "%s/%u", + nm_ip_address_get_address (addr), + nm_ip_address_get_prefix (addr)); } svSetValue (ifcfg, "IPV6ADDR", ip_str1->str, FALSE); svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str, FALSE); - svSetValue (ifcfg, "IPV6_DEFAULTGW", ipv6_defaultgw, FALSE); + svSetValue (ifcfg, "IPV6_DEFAULTGW", nm_setting_ip_config_get_gateway (s_ip6), FALSE); g_string_free (ip_str1, TRUE); g_string_free (ip_str2, TRUE); /* Write out DNS - 'DNS' key is used both for IPv4 and IPv6 */ s_ip4 = nm_connection_get_setting_ip4_config (connection); - num4 = s_ip4 ? nm_setting_ip4_config_get_num_dns (s_ip4) : 0; /* from where to start with IPv6 entries */ - num = nm_setting_ip6_config_get_num_dns (s_ip6); + num4 = s_ip4 ? nm_setting_ip_config_get_num_dns (s_ip4) : 0; /* from where to start with IPv6 entries */ + num = nm_setting_ip_config_get_num_dns (s_ip6); for (i = 0; i < 254; i++) { addr_key = g_strdup_printf ("DNS%d", i + num4 + 1); if (i >= num) svSetValue (ifcfg, addr_key, NULL, FALSE); else { - ip = nm_setting_ip6_config_get_dns (s_ip6, i); - - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); - svSetValue (ifcfg, addr_key, buf, FALSE); + dns = nm_setting_ip_config_get_dns (s_ip6, i); + svSetValue (ifcfg, addr_key, dns, FALSE); } g_free (addr_key); } /* Write out DNS domains - 'DOMAIN' key is shared for both IPv4 and IPv6 domains */ - num = nm_setting_ip6_config_get_num_dns_searches (s_ip6); + num = nm_setting_ip_config_get_num_dns_searches (s_ip6); if (num > 0) { char *ip4_domains; ip4_domains = svGetValue (ifcfg, "DOMAIN", FALSE); @@ -2433,7 +2350,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) for (i = 0; i < num; i++) { if (searches->len > 0) g_string_append_c (searches, ' '); - g_string_append (searches, nm_setting_ip6_config_get_dns_search (s_ip6, i)); + g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i)); } svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); g_string_free (searches, TRUE); @@ -2442,7 +2359,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* handle IPV6_DEFROUTE */ /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ - if (nm_setting_ip6_config_get_never_default(s_ip6)) + if (nm_setting_ip_config_get_never_default(s_ip6)) svSetValue (ifcfg, "IPV6_DEFROUTE", "no", FALSE); else svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE); @@ -2451,22 +2368,22 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValue (ifcfg, "IPV6_PEERROUTES", NULL, FALSE); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { svSetValue (ifcfg, "IPV6_PEERDNS", - nm_setting_ip6_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes", + nm_setting_ip_config_get_ignore_auto_dns (s_ip6) ? "no" : "yes", FALSE); svSetValue (ifcfg, "IPV6_PEERROUTES", - nm_setting_ip6_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes", + nm_setting_ip_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes", FALSE); } svSetValue (ifcfg, "IPV6_FAILURE_FATAL", - nm_setting_ip6_config_get_may_fail (s_ip6) ? "no" : "yes", + nm_setting_ip_config_get_may_fail (s_ip6) ? "no" : "yes", FALSE); /* IPv6 Privacy Extensions */ svSetValue (ifcfg, "IPV6_PRIVACY", NULL, FALSE); svSetValue (ifcfg, "IPV6_PRIVACY_PREFER_PUBLIC_IP", NULL, FALSE); - switch (nm_setting_ip6_config_get_ip6_privacy (s_ip6)){ + switch (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6))){ case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: svSetValue (ifcfg, "IPV6_PRIVACY", "no", FALSE); break; @@ -2484,7 +2401,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) /* Static routes go to route6-<dev> file */ route6_path = utils_get_route6_path (ifcfg->fileName); if (!route6_path) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not get route6 file path for '%s'", ifcfg->fileName); goto error; } @@ -2502,7 +2419,6 @@ error: static char * escape_id (const char *id) { - static const char const as_dash[] = "\\][|/=()!"; char *escaped = g_strdup (id); char *p = escaped; @@ -2510,7 +2426,7 @@ escape_id (const char *id) while (*p) { if (*p == ' ') *p = '_'; - else if (strchr (as_dash, *p)) + else if (strchr ("\\][|/=()!", *p)) *p = '-'; p++; } @@ -2573,7 +2489,7 @@ write_connection (NMConnection *connection, g_free (escaped); if (ifcfg_name == NULL) { - g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Failed to find usable ifcfg file name"); return FALSE; } @@ -2583,7 +2499,7 @@ write_connection (NMConnection *connection, type = nm_setting_connection_get_connection_type (s_con); if (!type) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Missing connection type!"); goto out; } @@ -2591,7 +2507,7 @@ write_connection (NMConnection *connection, if (!strcmp (type, NM_SETTING_WIRED_SETTING_NAME)) { // FIXME: can't write PPPoE at this time if (nm_connection_get_setting_pppoe (connection)) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Can't write connection type '%s'", NM_SETTING_PPPOE_SETTING_NAME); goto out; @@ -2619,7 +2535,7 @@ write_connection (NMConnection *connection, if (!write_bridge_setting (connection, ifcfg, error)) goto out; } else { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Can't write connection type '%s'", type); goto out; } @@ -2684,7 +2600,7 @@ writer_can_write_connection (NMConnection *connection, GError **error) s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "The ifcfg-rh plugin cannot write the connection '%s' (type '%s' pppoe %d)", nm_connection_get_id (connection), nm_setting_connection_get_connection_type (s_con), diff --git a/src/settings/plugins/ifcfg-suse/Makefile.am b/src/settings/plugins/ifcfg-suse/Makefile.am index d4f1cf74..46204d7d 100644 --- a/src/settings/plugins/ifcfg-suse/Makefile.am +++ b/src/settings/plugins/ifcfg-suse/Makefile.am @@ -1,14 +1,12 @@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -I${top_srcdir}/src \ -I${top_srcdir}/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-suse"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DSYSCONFDIR=\"$(sysconfdir)\" @@ -19,8 +17,3 @@ libnm_settings_plugin_ifcfg_suse_la_SOURCES = \ plugin.h libnm_settings_plugin_ifcfg_suse_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_suse_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(GLIB_LIBS) - diff --git a/src/settings/plugins/ifcfg-suse/Makefile.in b/src/settings/plugins/ifcfg-suse/Makefile.in index 5ff5bfb2..149faa3e 100644 --- a/src/settings/plugins/ifcfg-suse/Makefile.in +++ b/src/settings/plugins/ifcfg-suse/Makefile.in @@ -130,10 +130,7 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(pkglibdir)" LTLIBRARIES = $(pkglib_LTLIBRARIES) -am__DEPENDENCIES_1 = -libnm_settings_plugin_ifcfg_suse_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la $(am__DEPENDENCIES_1) +libnm_settings_plugin_ifcfg_suse_la_LIBADD = am_libnm_settings_plugin_ifcfg_suse_la_OBJECTS = plugin.lo libnm_settings_plugin_ifcfg_suse_la_OBJECTS = \ $(am_libnm_settings_plugin_ifcfg_suse_la_OBJECTS) @@ -216,6 +213,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -339,6 +338,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -358,6 +358,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -384,7 +385,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -465,15 +466,13 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -I${top_srcdir}/src \ -I${top_srcdir}/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-suse"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DSYSCONFDIR=\"$(sysconfdir)\" @@ -483,11 +482,6 @@ libnm_settings_plugin_ifcfg_suse_la_SOURCES = \ plugin.h libnm_settings_plugin_ifcfg_suse_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifcfg_suse_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(GLIB_LIBS) - all: all-am .SUFFIXES: diff --git a/src/settings/plugins/ifcfg-suse/plugin.c b/src/settings/plugins/ifcfg-suse/plugin.c index d6aa79fb..a1667f64 100644 --- a/src/settings/plugins/ifcfg-suse/plugin.c +++ b/src/settings/plugins/ifcfg-suse/plugin.c @@ -22,7 +22,8 @@ * (C) Copyright 2007 - 2008 Novell, Inc. */ -#include <config.h> +#include "config.h" + #include <string.h> #include <gmodule.h> @@ -55,17 +56,6 @@ typedef struct { char *hostname; } SCPluginIfcfgPrivate; -GQuark -ifcfg_plugin_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("ifcfg-plugin-error-quark"); - - return error_quark; -} - typedef void (*FileChangedFn) (gpointer user_data); typedef struct { @@ -148,7 +138,7 @@ hostname_is_dynamic (void) } static char * -hostname_read () +hostname_read (void) { GIOChannel *channel; char *hostname = NULL; diff --git a/src/settings/plugins/ifcfg-suse/plugin.h b/src/settings/plugins/ifcfg-suse/plugin.h index 4090a11e..24dbff95 100644 --- a/src/settings/plugins/ifcfg-suse/plugin.h +++ b/src/settings/plugins/ifcfg-suse/plugin.h @@ -46,7 +46,5 @@ struct _SCPluginIfcfgClass { GType sc_plugin_ifcfg_get_type (void); -GQuark ifcfg_plugin_error_quark (void); - #endif /* _PLUGIN_H_ */ diff --git a/src/settings/plugins/ifnet/Makefile.am b/src/settings/plugins/ifnet/Makefile.am index a22ea557..b0cfd9a1 100644 --- a/src/settings/plugins/ifnet/Makefile.am +++ b/src/settings/plugins/ifnet/Makefile.am @@ -4,21 +4,15 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ - $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" -DSBINDIR=\"$(sbindir)\" @@ -34,12 +28,7 @@ libnm_settings_plugin_ifnet_la_SOURCES = \ libnm_settings_plugin_ifnet_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifnet_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - lib-ifnet-io.la\ - $(GLIB_LIBS) \ - $(GUDEV_LIBS) +libnm_settings_plugin_ifnet_la_LIBADD = lib-ifnet-io.la lib_ifnet_io_la_SOURCES = \ net_parser.c\ @@ -49,10 +38,4 @@ lib_ifnet_io_la_SOURCES = \ net_utils.h\ net_utils.c\ wpa_parser.h\ - wpa_parser.c \ - errors.h \ - errors.c - -lib_ifnet_io_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(GLIB_LIBS) + wpa_parser.c diff --git a/src/settings/plugins/ifnet/Makefile.in b/src/settings/plugins/ifnet/Makefile.in index 6a658189..11e9297f 100644 --- a/src/settings/plugins/ifnet/Makefile.in +++ b/src/settings/plugins/ifnet/Makefile.in @@ -130,20 +130,15 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(pkglibdir)" LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES) -am__DEPENDENCIES_1 = -lib_ifnet_io_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) +lib_ifnet_io_la_LIBADD = am_lib_ifnet_io_la_OBJECTS = net_parser.lo connection_parser.lo \ - net_utils.lo wpa_parser.lo errors.lo + net_utils.lo wpa_parser.lo lib_ifnet_io_la_OBJECTS = $(am_lib_ifnet_io_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -libnm_settings_plugin_ifnet_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la lib-ifnet-io.la \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +libnm_settings_plugin_ifnet_la_DEPENDENCIES = lib-ifnet-io.la am_libnm_settings_plugin_ifnet_la_OBJECTS = nm-ifnet-connection.lo \ plugin.lo libnm_settings_plugin_ifnet_la_OBJECTS = \ @@ -266,6 +261,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -389,6 +386,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -408,6 +406,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -434,7 +433,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -516,21 +515,15 @@ with_valgrind = @with_valgrind@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/platform \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ - $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" pkglib_LTLIBRARIES = libnm-settings-plugin-ifnet.la @@ -542,13 +535,7 @@ libnm_settings_plugin_ifnet_la_SOURCES = \ plugin.h libnm_settings_plugin_ifnet_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifnet_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - lib-ifnet-io.la\ - $(GLIB_LIBS) \ - $(GUDEV_LIBS) - +libnm_settings_plugin_ifnet_la_LIBADD = lib-ifnet-io.la lib_ifnet_io_la_SOURCES = \ net_parser.c\ net_parser.h\ @@ -557,13 +544,7 @@ lib_ifnet_io_la_SOURCES = \ net_utils.h\ net_utils.c\ wpa_parser.h\ - wpa_parser.c \ - errors.h \ - errors.c - -lib_ifnet_io_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(GLIB_LIBS) + wpa_parser.c all: all-recursive @@ -659,7 +640,6 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_parser.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_parser.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_utils.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-ifnet-connection.Plo@am__quote@ diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c index 85873d5f..41baf315 100644 --- a/src/settings/plugins/ifnet/connection_parser.c +++ b/src/settings/plugins/ifnet/connection_parser.c @@ -24,27 +24,18 @@ #include <string.h> #include <arpa/inet.h> #include <stdlib.h> -#include <netinet/ether.h> #include <errno.h> #include <glib/gi18n.h> -#include <nm-setting-connection.h> -#include <nm-setting-ip4-config.h> -#include <nm-setting-ip6-config.h> -#include <nm-setting-ppp.h> -#include <nm-setting-pppoe.h> -#include <nm-setting-wired.h> -#include <nm-setting-wireless.h> -#include <nm-setting-8021x.h> -#include <nm-system-config-interface.h> -#include <nm-logging.h> -#include <nm-utils.h> +#include "nm-system-config-interface.h" +#include "nm-logging.h" +#include "nm-core-internal.h" +#include "NetworkManagerUtils.h" #include "net_utils.h" #include "wpa_parser.h" #include "connection_parser.h" #include "nm-ifnet-connection.h" -#include "errors.h" static char * connection_id_from_ifnet_name (const char *conn_name) @@ -52,8 +43,16 @@ connection_id_from_ifnet_name (const char *conn_name) int name_len = strlen (conn_name); /* Convert a hex-encoded conn_name (only used for wifi SSIDs) to human-readable one */ - if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x"))) - return nm_utils_hexstr2bin (conn_name + 2, name_len - 2); + if ((name_len > 2) && (g_str_has_prefix (conn_name, "0x"))) { + GBytes *bytes = nm_utils_hexstr2bin (conn_name); + char *buf; + + if (bytes) { + buf = g_strndup (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)); + g_bytes_unref (bytes); + return buf; + } + } return g_strdup (conn_name); } @@ -125,7 +124,7 @@ eap_simple_reader (const char *eap_method, /* identity */ value = wpa_get_value (ssid, "identity"); if (!value) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", eap_method); return FALSE; @@ -135,7 +134,7 @@ eap_simple_reader (const char *eap_method, /* password */ value = wpa_get_value (ssid, "password"); if (!value) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_PASSWORD for EAP method '%s'.", eap_method); return FALSE; @@ -177,7 +176,7 @@ eap_tls_reader (const char *eap_method, /* identity */ value = wpa_get_value (ssid, "identity"); if (!value) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_IDENTITY for EAP method '%s'.", eap_method); return FALSE; @@ -208,11 +207,11 @@ eap_tls_reader (const char *eap_method, /* Private key password */ privkey_password = wpa_get_value (ssid, - phase2 ? "private_key_passwd2" : + phase2 ? "private_key2_passwd" : "private_key_passwd"); if (!privkey_password) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD" : "IEEE_8021X_PRIVATE_KEY_PASSWORD", eap_method); @@ -222,7 +221,7 @@ eap_tls_reader (const char *eap_method, /* The private key itself */ privkey = get_cert (ssid, phase2 ? "private_key2" : "private_key", basepath); if (!privkey) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", phase2 ? "IEEE_8021X_INNER_PRIVATE_KEY" : "IEEE_8021X_PRIVATE_KEY", eap_method); @@ -255,7 +254,7 @@ eap_tls_reader (const char *eap_method, || privkey_format == NM_SETTING_802_1X_CK_FORMAT_X509) { client_cert = get_cert (ssid, phase2 ? "client_cert2" : "client_cert", basepath); if (!client_cert) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing %s for EAP method '%s'.", phase2 ? "IEEE_8021X_INNER_CLIENT_CERT" : "IEEE_8021X_CLIENT_CERT", eap_method); @@ -323,7 +322,7 @@ eap_peap_reader (const char *eap_method, g_object_set (s_8021x, NM_SETTING_802_1X_PHASE1_PEAPVER, "1", NULL); else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_PEAP_VERSION value '%s'", peapver); goto done; @@ -337,7 +336,7 @@ eap_peap_reader (const char *eap_method, inner_auth = wpa_get_value (ssid, "phase2"); if (!inner_auth) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); goto done; } @@ -358,7 +357,7 @@ eap_peap_reader (const char *eap_method, if (!eap_tls_reader (pos, ssid, s_8021x, TRUE, basepath, error)) goto done; } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", *iter); goto done; @@ -374,7 +373,7 @@ eap_peap_reader (const char *eap_method, } if (!nm_setting_802_1x_get_phase2_auth (s_8021x)) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "No valid IEEE_8021X_INNER_AUTH_METHODS found."); goto done; } @@ -423,7 +422,7 @@ eap_ttls_reader (const char *eap_method, tmp = wpa_get_value (ssid, "phase2"); if (!tmp) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_INNER_AUTH_METHODS."); goto done; } @@ -458,7 +457,7 @@ eap_ttls_reader (const char *eap_method, g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTHEAP, pos, NULL); } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown IEEE_8021X_INNER_AUTH_METHOD '%s'.", *iter); goto done; @@ -499,20 +498,20 @@ guess_connection_type (const char *conn_name) /* Reading mac address for setting connection option. * Unmanaged device mac address is required by NetworkManager*/ static gboolean -read_mac_address (const char *conn_name, GByteArray **array, GError **error) +read_mac_address (const char *conn_name, const char **mac, GError **error) { const char *value = ifnet_get_data (conn_name, "mac"); if (!value || !strlen (value)) return TRUE; - *array = nm_utils_hwaddr_atoba (value, ARPHRD_ETHER); - if (!*array) { - g_set_error (error, ifnet_plugin_error_quark (), 0, - "The MAC address '%s' was invalid.", value); + if (!nm_utils_hwaddr_valid (value, ETH_ALEN)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "The MAC address '%s' was invalid.", value); return FALSE; } + *mac = value; return TRUE; } @@ -521,7 +520,7 @@ make_wired_connection_setting (NMConnection *connection, const char *conn_name, GError **error) { - GByteArray *mac = NULL; + const char *mac = NULL; NMSettingWired *s_wired = NULL; const char *value = NULL; @@ -545,7 +544,6 @@ make_wired_connection_setting (NMConnection *connection, if (mac) { g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); } } else { g_object_unref (s_wired); @@ -555,56 +553,56 @@ make_wired_connection_setting (NMConnection *connection, nm_connection_add_setting (connection, NM_SETTING (s_wired)); } -/* add NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, - * NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID in future*/ +/* add NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, + * NM_SETTING_IP_CONFIG_DHCP_CLIENT_ID in future*/ static void make_ip4_setting (NMConnection *connection, const char *conn_name, GError **error) { - NMSettingIP4Config *ip4_setting = - NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + NMSettingIPConfig *ip4_setting = + NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); const char *value, *method = NULL; gboolean is_static_block = is_static_ip4 (conn_name); ip_block *iblock = NULL; /* set dhcp options (dhcp_xxx) */ value = ifnet_get_data (conn_name, "dhcp"); - g_object_set (ip4_setting, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, value + g_object_set (ip4_setting, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, value && strstr (value, "nodns") ? TRUE : FALSE, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, value + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, value && strstr (value, "nogateway") ? TRUE : FALSE, NULL); if (!is_static_block) { method = ifnet_get_data (conn_name, "config"); if (!method){ - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown config for %s", conn_name); g_object_unref (ip4_setting); return; } if (strstr (method, "dhcp")) g_object_set (ip4_setting, - NM_SETTING_IP4_CONFIG_METHOD, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL); else if (strstr (method, "autoip")) { g_object_set (ip4_setting, - NM_SETTING_IP4_CONFIG_METHOD, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL); nm_connection_add_setting (connection, NM_SETTING (ip4_setting)); return; } else if (strstr (method, "shared")) { g_object_set (ip4_setting, - NM_SETTING_IP4_CONFIG_METHOD, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL); + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL); nm_connection_add_setting (connection, NM_SETTING (ip4_setting)); return; } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown config for %s", conn_name); g_object_unref (ip4_setting); return; @@ -613,7 +611,7 @@ make_ip4_setting (NMConnection *connection, }else { iblock = convert_ip4_config_block (conn_name); if (!iblock) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Ifnet plugin: can't aquire ip configuration for %s", conn_name); g_object_unref (ip4_setting); @@ -622,29 +620,32 @@ make_ip4_setting (NMConnection *connection, /************** add all ip settings to the connection**********/ while (iblock) { ip_block *current_iblock; - NMIP4Address *ip4_addr = nm_ip4_address_new (); - - nm_ip4_address_set_address (ip4_addr, iblock->ip); - nm_ip4_address_set_prefix (ip4_addr, - nm_utils_ip4_netmask_to_prefix - (iblock->netmask)); - /* currently all the IPs has the same gateway */ - nm_ip4_address_set_gateway (ip4_addr, iblock->gateway); - if (iblock->gateway) + NMIPAddress *ip4_addr; + GError *local = NULL; + + ip4_addr = nm_ip_address_new (AF_INET, iblock->ip, iblock->prefix, &local); + if (iblock->next_hop) g_object_set (ip4_setting, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE, NULL); - if (!nm_setting_ip4_config_add_address (ip4_setting, ip4_addr)) - nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address"); - nm_ip4_address_unref (ip4_addr); + + if (ip4_addr) { + if (!nm_setting_ip_config_add_address (ip4_setting, ip4_addr)) + nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address"); + nm_ip_address_unref (ip4_addr); + } else { + nm_log_warn (LOGD_SETTINGS, " ignoring invalid address entry: %s", local->message); + g_clear_error (&local); + } + current_iblock = iblock; iblock = iblock->next; destroy_ip_block (current_iblock); } g_object_set (ip4_setting, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, !has_default_ip4_route (conn_name), + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, !has_default_ip4_route (conn_name), NULL); } @@ -655,7 +656,7 @@ make_ip4_setting (NMConnection *connection, get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id); if (dhcp_hostname) { g_object_set (ip4_setting, - NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); nm_log_info (LOGD_SETTINGS, "DHCP hostname: %s", dhcp_hostname); g_free (dhcp_hostname); @@ -686,7 +687,7 @@ make_ip4_setting (NMConnection *connection, for (item = searches; *item; item++) { if (strlen (*item)) { - if (!nm_setting_ip4_config_add_dns_search (ip4_setting, *item)) + if (!nm_setting_ip_config_add_dns_search (ip4_setting, *item)) nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *item); } } @@ -700,34 +701,34 @@ make_ip4_setting (NMConnection *connection, ip_block *current_iblock = iblock; const char *metric_str; char *stripped; - long int metric; - NMIP4Route *route = nm_ip4_route_new (); - - nm_ip4_route_set_dest (route, iblock->ip); - nm_ip4_route_set_next_hop (route, iblock->gateway); - nm_ip4_route_set_prefix (route, - nm_utils_ip4_netmask_to_prefix - (iblock->netmask)); + gint64 metric; + NMIPRoute *route; + GError *local = NULL; + if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL) { - metric = strtol (metric_str, NULL, 10); - nm_ip4_route_set_metric (route, (guint32) metric); + metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1); } else { metric_str = ifnet_get_global_data ("metric"); if (metric_str) { stripped = g_strdup (metric_str); strip_string (stripped, '"'); - metric = strtol (metric_str, NULL, 10); - nm_ip4_route_set_metric (route, - (guint32) metric); + metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1); g_free (stripped); - } + } else + metric = -1; } - if (!nm_setting_ip4_config_add_route (ip4_setting, route)) - nm_log_warn (LOGD_SETTINGS, "duplicate IP4 route"); - nm_log_info (LOGD_SETTINGS, "new IP4 route:%d\n", iblock->ip); - - nm_ip4_route_unref (route); + route = nm_ip_route_new (AF_INET, iblock->ip, iblock->prefix, iblock->next_hop, metric, &local); + if (route) { + if (nm_setting_ip_config_add_route (ip4_setting, route)) + nm_log_info (LOGD_SETTINGS, "new IP4 route:%s\n", iblock->ip); + else + nm_log_warn (LOGD_SETTINGS, "duplicate IP4 route"); + nm_ip_route_unref (route); + } else { + nm_log_warn (LOGD_SETTINGS, " ignoring invalid route entry: %s", local->message); + g_clear_error (&local); + } current_iblock = iblock; iblock = iblock->next; @@ -743,17 +744,17 @@ make_ip6_setting (NMConnection *connection, const char *conn_name, GError **error) { - NMSettingIP6Config *s_ip6 = NULL; + NMSettingIPConfig *s_ip6 = NULL; gboolean is_static_block = is_static_ip6 (conn_name); // used to disable IPv6 gboolean ipv6_enabled = FALSE; gchar *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; const char *value; - ip6_block *iblock; + ip_block *iblock; gboolean never_default = !has_default_ip6_route (conn_name); - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); value = ifnet_get_data (conn_name, "enable_ipv6"); if (value && is_true (value)) @@ -763,7 +764,7 @@ make_ip6_setting (NMConnection *connection, // Currently only Manual and DHCP are supported if (!ipv6_enabled) { g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); goto done; } else if (!is_static_block) { @@ -780,91 +781,98 @@ make_ip6_setting (NMConnection *connection, nm_log_info (LOGD_SETTINGS, "IPv6 for %s enabled, using %s", conn_name, method); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, method, - NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, FALSE, - NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, FALSE, - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, never_default, NULL); + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, FALSE, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, FALSE, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, NULL); /* Make manual settings */ if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { - ip6_block *current_iblock; + ip_block *current_iblock; iblock = convert_ip6_config_block (conn_name); if (!iblock) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Ifnet plugin: can't aquire ip6 configuration for %s", conn_name); goto error; } /* add all IPv6 addresses */ while (iblock) { - NMIP6Address *ip6_addr = nm_ip6_address_new (); - - nm_ip6_address_set_address (ip6_addr, iblock->ip); - nm_ip6_address_set_prefix (ip6_addr, iblock->prefix); - if (nm_setting_ip6_config_add_address (s_ip6, ip6_addr)) { - nm_log_info (LOGD_SETTINGS, "ipv6 addresses count: %d", - nm_setting_ip6_config_get_num_addresses (s_ip6)); + NMIPAddress *ip6_addr; + GError *local = NULL; + + ip6_addr = nm_ip_address_new (AF_INET6, iblock->ip, iblock->prefix, &local); + if (ip6_addr) { + if (nm_setting_ip_config_add_address (s_ip6, ip6_addr)) { + nm_log_info (LOGD_SETTINGS, "ipv6 addresses count: %d", + nm_setting_ip_config_get_num_addresses (s_ip6)); + } else { + nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP6 address"); + } + nm_ip_address_unref (ip6_addr); } else { - nm_log_warn (LOGD_SETTINGS, "ignoring duplicate IP4 address"); + nm_log_warn (LOGD_SETTINGS, " ignoring invalid address entry: %s", local->message); + g_clear_error (&local); } - nm_ip6_address_unref (ip6_addr); + current_iblock = iblock; iblock = iblock->next; - destroy_ip6_block (current_iblock); + destroy_ip_block (current_iblock); } } else if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { /* - autoconf or DHCPv6 stuff goes here */ } - // DNS Servers, set NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS TRUE here + // DNS Servers, set NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS TRUE here set_ip6_dns_servers (s_ip6, conn_name); - /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIP4Config */ + /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIPConfig */ // Add routes iblock = convert_ip6_routes_block (conn_name); if (iblock) - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, TRUE, NULL); /* Add all IPv6 routes */ while (iblock) { - ip6_block *current_iblock = iblock; + ip_block *current_iblock = iblock; const char *metric_str; char *stripped; - long int metric = 1; - NMIP6Route *route = nm_ip6_route_new (); + gint64 metric; + NMIPRoute *route; + GError *local = NULL; - nm_ip6_route_set_dest (route, iblock->ip); - nm_ip6_route_set_next_hop (route, iblock->next_hop); - nm_ip6_route_set_prefix (route, iblock->prefix); /* metric is not per routes configuration right now * global metric is also supported (metric="x") */ - if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL) { - metric = strtol (metric_str, NULL, 10); - nm_ip6_route_set_metric (route, (guint32) metric); - } else { + if ((metric_str = ifnet_get_data (conn_name, "metric")) != NULL) + metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1); + else { metric_str = ifnet_get_global_data ("metric"); if (metric_str) { stripped = g_strdup (metric_str); strip_string (stripped, '"'); - metric = strtol (metric_str, NULL, 10); - nm_ip6_route_set_metric (route, - (guint32) metric); + metric = nm_utils_ascii_str_to_int64 (metric_str, 10, 0, G_MAXUINT32, -1); g_free (stripped); } else - nm_ip6_route_set_metric (route, (guint32) 1); + metric = 1; } - if (nm_setting_ip6_config_add_route (s_ip6, route)) - nm_log_info (LOGD_SETTINGS, " new IP6 route"); - else - nm_log_warn (LOGD_SETTINGS, " duplicate IP6 route"); - nm_ip6_route_unref (route); + route = nm_ip_route_new (AF_INET6, iblock->ip, iblock->prefix, iblock->next_hop, metric, &local); + if (route) { + if (nm_setting_ip_config_add_route (s_ip6, route)) + nm_log_info (LOGD_SETTINGS, " new IP6 route"); + else + nm_log_warn (LOGD_SETTINGS, " duplicate IP6 route"); + nm_ip_route_unref (route); + } else { + nm_log_warn (LOGD_SETTINGS, " ignoring invalid route entry: %s", local->message); + g_clear_error (&local); + } current_iblock = iblock; iblock = iblock->next; - destroy_ip6_block (current_iblock); + destroy_ip_block (current_iblock); } done: @@ -882,7 +890,7 @@ make_wireless_connection_setting (const char *conn_name, NMSetting8021x **s_8021x, GError **error) { - GByteArray *array, *mac = NULL; + const char *mac = NULL; NMSettingWireless *wireless_setting = NULL; gboolean adhoc = FALSE; const char *value; @@ -904,8 +912,6 @@ make_wireless_connection_setting (const char *conn_name, g_object_set (wireless_setting, NM_SETTING_WIRELESS_MAC_ADDRESS, mac, NULL); - g_byte_array_free (mac, TRUE); - } } else { g_object_unref (wireless_setting); @@ -914,51 +920,41 @@ make_wireless_connection_setting (const char *conn_name, /* handle ssid (hex and ascii) */ if (conn_name) { + GBytes *bytes; gsize ssid_len = 0, value_len = strlen (conn_name); - const char *p; - char *tmp, *converted = NULL; ssid_len = value_len; if ((value_len > 2) && (g_str_has_prefix (conn_name, "0x"))) { /* Hex representation */ if (value_len % 2) { - g_set_error (error, ifnet_plugin_error_quark (), - 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid SSID '%s' size (looks like hex but length not multiple of 2)", conn_name); goto error; } - // ignore "0x" - p = conn_name + 2; - if (!is_hex (p)) { - g_set_error (error, - ifnet_plugin_error_quark (), - 0, - "Invalid SSID '%s' character (looks like hex SSID but '%c' isn't a hex digit)", - conn_name, *p); - goto error; + bytes = nm_utils_hexstr2bin (conn_name); + if (!bytes) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid SSID '%s' (looks like hex SSID but isn't)", + conn_name); + goto error; } - tmp = nm_utils_hexstr2bin (p, value_len - 2); - ssid_len = (value_len - 2) / 2; - converted = g_malloc0 (ssid_len + 1); - memcpy (converted, tmp, ssid_len); - g_free (tmp); - } + } else + bytes = g_bytes_new (conn_name, value_len); + ssid_len = g_bytes_get_size (bytes); if (ssid_len > 32 || ssid_len == 0) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid SSID '%s' (size %zu not between 1 and 32 inclusive)", conn_name, ssid_len); goto error; } - array = g_byte_array_sized_new (ssid_len); - g_byte_array_append (array, (const guint8 *) (converted ? converted : conn_name), ssid_len); - g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, array, NULL); - g_byte_array_free (array, TRUE); - g_free (converted); + + g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, bytes, NULL); + g_bytes_unref (bytes); } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing SSID"); goto error; } @@ -980,18 +976,14 @@ make_wireless_connection_setting (const char *conn_name, /* BSSID setting */ value = wpa_get_value (conn_name, "bssid"); if (value) { - GByteArray *bssid; - - bssid = nm_utils_hwaddr_atoba (value, ARPHRD_ETHER); - if (!bssid) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + if (!nm_utils_hwaddr_valid (value, ETH_ALEN)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid BSSID '%s'", value); goto error; } g_object_set (wireless_setting, NM_SETTING_WIRELESS_BSSID, - bssid, NULL); - g_byte_array_free (bssid, TRUE); + value, NULL); } @@ -1043,7 +1035,7 @@ make_leap_setting (const char *ssid, GError **error) value = wpa_get_value (ssid, "identity"); if (!value || !strlen (value)) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing LEAP identity"); goto error; } @@ -1085,8 +1077,8 @@ add_one_wep_key (const char *ssid, if (strlen (value) == 10 || strlen (value) == 26) { /* Hexadecimal WEP key */ if (!is_hex (value)) { - g_set_error (error, ifnet_plugin_error_quark (), - 0, "Invalid hexadecimal WEP key."); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid hexadecimal WEP key."); goto out; } converted = g_strdup (value); @@ -1097,17 +1089,17 @@ add_one_wep_key (const char *ssid, char *p = strip_string (tmp, '"'); if (!is_ascii (p)) { - g_set_error (error, ifnet_plugin_error_quark (), - 0, "Invalid ASCII WEP passphrase."); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid ASCII WEP passphrase."); g_free (tmp); goto out; } - converted = nm_utils_bin2hexstr (tmp, strlen (tmp), strlen (tmp) * 2); + converted = nm_utils_bin2hexstr (tmp, strlen (tmp), -1); g_free (tmp); } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WEP key length. Key: %s", value); goto out; } @@ -1161,7 +1153,7 @@ make_wep_setting (const char *ssid, GError **error) default_key_idx, NULL); nm_log_info (LOGD_SETTINGS, "Default key index: %d", default_key_idx); } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid default WEP key '%s'", value); goto error; } @@ -1173,19 +1165,19 @@ make_wep_setting (const char *ssid, GError **error) /* If there's a default key, ensure that key exists */ if ((default_key_idx == 1) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Default WEP key index was 2, but no valid KEY2 exists."); goto error; } else if ((default_key_idx == 2) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Default WEP key index was 3, but no valid KEY3 exists."); goto error; } else if ((default_key_idx == 3) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Default WEP key index was 4, but no valid KEY4 exists."); goto error; } @@ -1204,7 +1196,7 @@ make_wep_setting (const char *ssid, GError **error) "shared", NULL); nm_log_info (LOGD_SETTINGS, "WEP: Use shared system authentication"); } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WEP authentication algorithm '%s'", auth_alg); goto error; @@ -1218,7 +1210,7 @@ make_wep_setting (const char *ssid, GError **error) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3) && !nm_setting_wireless_security_get_wep_tx_keyidx (s_wireless_sec)) { if (auth_alg && !strcmp (auth_alg, "shared")) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "WEP Shared Key authentication is invalid for " "unencrypted connections."); goto error; @@ -1242,7 +1234,7 @@ parse_wpa_psk (const char *psk, GError **error) gboolean quoted = FALSE; if (!psk) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing WPA_PSK for WPA-PSK key management"); return NULL; } @@ -1258,9 +1250,8 @@ parse_wpa_psk (const char *psk, GError **error) if (!quoted && (strlen (psk) == 64)) { /* Verify the hex PSK; 64 digits */ if (!is_hex (psk)) { - g_set_error (error, ifnet_plugin_error_quark (), - 0, - "Invalid WPA_PSK (contains non-hexadecimal characters)"); + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid WPA_PSK (contains non-hexadecimal characters)"); goto out; } hashed = g_strdup (psk); @@ -1271,7 +1262,7 @@ parse_wpa_psk (const char *psk, GError **error) /* Length check */ if (strlen (stripped) < 8 || strlen (stripped) > 63) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WPA_PSK (passphrases must be between " "8 and 63 characters long (inclusive))"); g_free (stripped); @@ -1283,7 +1274,7 @@ parse_wpa_psk (const char *psk, GError **error) } if (!hashed) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid WPA_PSK (doesn't look like a passphrase or hex key)"); goto out; } @@ -1367,7 +1358,7 @@ fill_8021x (const char *ssid, value = wpa_get_value (ssid, "eap"); if (!value) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing IEEE_8021X_EAP_METHODS for key management '%s'", key_mgmt); return NULL; @@ -1383,7 +1374,7 @@ fill_8021x (const char *ssid, char *lower = NULL; lower = g_ascii_strdown (*iter, -1); - while (eap->method && !found) { + while (eap->method) { if (strcmp (eap->method, lower)) goto next; @@ -1404,6 +1395,7 @@ fill_8021x (const char *ssid, } nm_setting_802_1x_add_eap_method (s_8021x, lower); found = TRUE; + break; next: eap++; @@ -1417,7 +1409,7 @@ fill_8021x (const char *ssid, g_strfreev (list); if (nm_setting_802_1x_get_num_eap_methods (s_8021x) == 0) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "No valid EAP methods found in IEEE_8021X_EAP_METHODS."); goto error; } @@ -1441,7 +1433,7 @@ make_wpa_setting (const char *ssid, gboolean adhoc = FALSE; if (!exist_ssid (ssid)) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "No security info found for ssid: %s", ssid); return NULL; } @@ -1493,7 +1485,7 @@ make_wpa_setting (const char *ssid, "wpa-psk", NULL); } else if (!strcmp (value, "WPA-EAP") || !strcmp (value, "IEEE8021X")) { if (adhoc) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Ad-Hoc mode cannot be used with KEY_MGMT type '%s'", value); goto error; @@ -1507,7 +1499,7 @@ make_wpa_setting (const char *ssid, lower, NULL); g_free (lower); } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Unknown wireless KEY_MGMT type '%s'", value); goto error; } @@ -1558,7 +1550,7 @@ make_wireless_security_setting (const char *conn_name, } if (!wsec) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Can't handle security information for ssid: %s", conn_name); } @@ -1574,8 +1566,8 @@ make_pppoe_connection_setting (NMConnection *connection, const char *conn_name, GError **error) { - NMSettingPPPOE *s_pppoe; - NMSettingPPP *s_ppp; + NMSettingPppoe *s_pppoe; + NMSettingPpp *s_ppp; const char *value; s_pppoe = NM_SETTING_PPPOE (nm_setting_pppoe_new ()); @@ -1583,7 +1575,7 @@ make_pppoe_connection_setting (NMConnection *connection, /* username */ value = ifnet_get_data (conn_name, "username"); if (!value) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "ppp requires at lease a username"); return; } @@ -1599,7 +1591,7 @@ make_pppoe_connection_setting (NMConnection *connection, nm_connection_add_setting (connection, NM_SETTING (s_pppoe)); /* PPP setting */ - s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); + s_ppp = (NMSettingPpp *) nm_setting_ppp_new (); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); } @@ -1618,7 +1610,7 @@ ifnet_update_connection_from_config_block (const char *conn_name, gchar *id, *uuid; gboolean success = FALSE; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); setting = nm_connection_get_setting_connection (connection); if (!setting) { setting = NM_SETTING_CONNECTION (nm_setting_connection_new ()); @@ -1637,7 +1629,7 @@ ifnet_update_connection_from_config_block (const char *conn_name, id = connection_id_from_ifnet_name (conn_name); uuid = g_strdup (ifnet_get_data (conn_name, "uuid")); if (!uuid) - uuid = nm_utils_uuid_generate_from_string (id); + uuid = nm_utils_uuid_generate_from_string (id, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); g_object_set (setting, NM_SETTING_CONNECTION_TYPE, type, @@ -1727,7 +1719,7 @@ error: typedef NMSetting8021xCKScheme (*SchemeFunc) (NMSetting8021x * setting); typedef const char *(*PathFunc) (NMSetting8021x * setting); -typedef const GByteArray *(*BlobFunc) (NMSetting8021x * setting); +typedef GBytes *(*BlobFunc) (NMSetting8021x * setting); typedef struct ObjectType { const char *setting_key; @@ -1813,13 +1805,13 @@ static const ObjectType phase2_p12_type = { static gboolean write_object (NMSetting8021x *s_8021x, const char *conn_name, - const GByteArray *override_data, + GBytes *override_data, const ObjectType *objtype, GError **error) { NMSetting8021xCKScheme scheme; const char *path = NULL; - const GByteArray *blob = NULL; + GBytes *blob = NULL; g_return_val_if_fail (conn_name != NULL, FALSE); g_return_val_if_fail (objtype != NULL, FALSE); @@ -1867,8 +1859,8 @@ write_8021x_certs (NMSetting8021x *s_8021x, char *password = NULL; const ObjectType *otype = NULL; gboolean is_pkcs12 = FALSE, success = FALSE; - const GByteArray *blob = NULL; - GByteArray *enc_key = NULL; + GBytes *blob = NULL; + GBytes *enc_key = NULL; gchar *generated_pw = NULL; /* CA certificate */ @@ -1915,13 +1907,17 @@ write_8021x_certs (NMSetting8021x *s_8021x, * private key file, it'll be encrypted, so we don't need to re-encrypt. */ if (blob && !is_pkcs12) { + GByteArray *tmp_enc_key; + /* Encrypt the unencrypted private key with the fake password */ - enc_key = - nm_utils_rsa_key_encrypt (blob, password, &generated_pw, - error); - if (!enc_key) + tmp_enc_key = + nm_utils_rsa_key_encrypt (g_bytes_get_data (blob, NULL), g_bytes_get_size (blob), + password, &generated_pw, error); + if (!tmp_enc_key) goto out; + enc_key = g_byte_array_free_to_bytes (tmp_enc_key); + if (generated_pw) password = generated_pw; } @@ -1932,7 +1928,7 @@ write_8021x_certs (NMSetting8021x *s_8021x, goto out; if (phase2) - wpa_set_data (conn_name, "private_key_passwd2", password); + wpa_set_data (conn_name, "private_key2_passwd", password); else wpa_set_data (conn_name, "private_key_passwd", password); @@ -1958,8 +1954,8 @@ out: g_free (generated_pw); } if (enc_key) { - memset (enc_key->data, 0, enc_key->len); - g_byte_array_free (enc_key, TRUE); + memset ((gpointer) g_bytes_get_data (enc_key, NULL), 0, g_bytes_get_size (enc_key)); + g_bytes_unref (enc_key); } return success; } @@ -2073,7 +2069,7 @@ write_wireless_security_setting (NMConnection * connection, s_wsec = nm_connection_get_setting_wireless_security (connection); if (!s_wsec) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing '%s' setting", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); return FALSE; @@ -2230,8 +2226,10 @@ write_wireless_setting (NMConnection *connection, GError **error) { NMSettingWireless *s_wireless; - const GByteArray *ssid, *mac, *bssid; - const char *mode; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; + const char *mac, *bssid, *mode; char buf[33]; guint32 mtu, i; gboolean adhoc = FALSE, hex_ssid = FALSE; @@ -2239,7 +2237,7 @@ write_wireless_setting (NMConnection *connection, s_wireless = nm_connection_get_setting_wireless (connection); if (!s_wireless) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; @@ -2247,13 +2245,14 @@ write_wireless_setting (NMConnection *connection, ssid = nm_setting_wireless_get_ssid (s_wireless); if (!ssid) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; } - if (!ssid->len || ssid->len > 32) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + ssid_data = g_bytes_get_data (ssid, &ssid_len); + if (!ssid_len || ssid_len > 32) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid SSID in '%s' setting", NM_SETTING_WIRELESS_SETTING_NAME); return FALSE; @@ -2263,8 +2262,8 @@ write_wireless_setting (NMConnection *connection, * the hex notation of the SSID instead. (Because openrc doesn't * support these characters, see bug #356337) */ - for (i = 0; i < ssid->len; i++) { - if (!g_ascii_isalnum (ssid->data[i])) { + for (i = 0; i < ssid_len; i++) { + if (!g_ascii_isalnum (ssid_data[i])) { hex_ssid = TRUE; break; } @@ -2274,16 +2273,16 @@ write_wireless_setting (NMConnection *connection, GString *str; /* Hex SSIDs don't get quoted */ - str = g_string_sized_new (ssid->len * 2 + 3); + str = g_string_sized_new (ssid_len * 2 + 3); g_string_append (str, "0x"); - for (i = 0; i < ssid->len; i++) - g_string_append_printf (str, "%02X", ssid->data[i]); + for (i = 0; i < ssid_len; i++) + g_string_append_printf (str, "%02X", ssid_data[i]); update_wireless_ssid (connection, conn_name, str->str, hex_ssid); ssid_str = g_string_free (str, FALSE); } else { /* Printable SSIDs get quoted */ memset (buf, 0, sizeof (buf)); - memcpy (buf, ssid->data, ssid->len); + memcpy (buf, ssid_data, ssid_len); g_strstrip (buf); update_wireless_ssid (connection, conn_name, buf, hex_ssid); ssid_str = g_strdup (buf); @@ -2291,11 +2290,8 @@ write_wireless_setting (NMConnection *connection, ifnet_set_data (ssid_str, "mac", NULL); mac = nm_setting_wireless_get_mac_address (s_wireless); - if (mac) { - tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len); - ifnet_set_data (ssid_str, "mac", tmp); - g_free (tmp); - } + if (mac) + ifnet_set_data (ssid_str, "mac", mac); ifnet_set_data (ssid_str, "mtu", NULL); mtu = nm_setting_wireless_get_mtu (s_wireless); @@ -2320,11 +2316,8 @@ write_wireless_setting (NMConnection *connection, wpa_set_data (ssid_str, "bssid", NULL); bssid = nm_setting_wireless_get_bssid (s_wireless); - if (bssid) { - tmp = nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len); - wpa_set_data (ssid_str, "bssid", tmp); - g_free (tmp); - } + if (bssid) + wpa_set_data (ssid_str, "bssid", bssid); if (nm_connection_get_setting_wireless_security (connection)) { if (!write_wireless_security_setting @@ -2345,13 +2338,13 @@ write_wired_setting (NMConnection *connection, GError **error) { NMSettingWired *s_wired; - const GByteArray *mac; + const char *mac; char *tmp; guint32 mtu; s_wired = nm_connection_get_setting_wired (connection); if (!s_wired) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing '%s' setting", NM_SETTING_WIRED_SETTING_NAME); return FALSE; @@ -2359,11 +2352,8 @@ write_wired_setting (NMConnection *connection, ifnet_set_data (conn_name, "mac", NULL); mac = nm_setting_wired_get_mac_address (s_wired); - if (mac) { - tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len); - ifnet_set_data (conn_name, "mac", tmp); - g_free (tmp); - } + if (mac) + ifnet_set_data (conn_name, "mac", mac); ifnet_set_data (conn_name, "mtu", NULL); mtu = nm_setting_wired_get_mtu (s_wired); @@ -2381,62 +2371,45 @@ write_wired_setting (NMConnection *connection, static gboolean write_ip4_setting (NMConnection *connection, const char *conn_name, GError **error) { - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; const char *value; - char *tmp; guint32 i, num; GString *searches; GString *ips; GString *routes; GString *dns; - gboolean has_def_route = FALSE; gboolean success = FALSE; s_ip4 = nm_connection_get_setting_ip4_config (connection); if (!s_ip4) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing '%s' setting", NM_SETTING_IP4_CONFIG_SETTING_NAME); return FALSE; } routes = g_string_new (NULL); - value = nm_setting_ip4_config_get_method (s_ip4); + value = nm_setting_ip_config_get_method (s_ip4); g_assert (value); if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { - num = nm_setting_ip4_config_get_num_addresses (s_ip4); + num = nm_setting_ip_config_get_num_addresses (s_ip4); ips = g_string_new (NULL); /* IPv4 addresses */ for (i = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN + 1]; - NMIP4Address *addr; - guint32 ip; - - addr = nm_setting_ip4_config_get_address (s_ip4, i); - - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_address (addr); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], - sizeof (buf)); - g_string_append_printf (ips, "\"%s", &buf[0]); - - tmp = - g_strdup_printf ("%u", - nm_ip4_address_get_prefix (addr)); - g_string_append_printf (ips, "/%s\" ", tmp); - g_free (tmp); + NMIPAddress *addr; + + addr = nm_setting_ip_config_get_address (s_ip4, i); + + g_string_append_printf (ips, "\"%s/%u", + nm_ip_address_get_address (addr), + nm_ip_address_get_prefix (addr)); /* only the first gateway will be written */ - if (!has_def_route && nm_ip4_address_get_gateway (addr)) { - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_address_get_gateway (addr); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], - sizeof (buf)); + if (i == 0 && nm_setting_ip_config_get_gateway (s_ip4)) { g_string_append_printf (routes, - "\"default via %s\" ", - &buf[0]); - has_def_route = TRUE; + "\"default via %s\" ", + nm_setting_ip_config_get_gateway (s_ip4)); } } ifnet_set_data (conn_name, "config", ips->str); @@ -2449,19 +2422,14 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err ifnet_set_data (conn_name, "config", "dhcp"); /* DNS Servers */ - num = nm_setting_ip4_config_get_num_dns (s_ip4); + num = nm_setting_ip_config_get_num_dns (s_ip4); if (num > 0) { dns = g_string_new (NULL); for (i = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN + 1]; - guint32 ip; - - ip = nm_setting_ip4_config_get_dns (s_ip4, i); + const char *ip; - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], - sizeof (buf)); - g_string_append_printf (dns, " %s", buf); + ip = nm_setting_ip_config_get_dns (s_ip4, i); + g_string_append_printf (dns, " %s", ip); } ifnet_set_data (conn_name, "dns_servers", dns->str); g_string_free (dns, TRUE); @@ -2469,14 +2437,14 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err ifnet_set_data (conn_name, "dns_servers", NULL); /* DNS Searches */ - num = nm_setting_ip4_config_get_num_dns_searches (s_ip4); + num = nm_setting_ip_config_get_num_dns_searches (s_ip4); if (num > 0) { searches = g_string_new (NULL); for (i = 0; i < num; i++) { if (i > 0) g_string_append_c (searches, ' '); g_string_append (searches, - nm_setting_ip4_config_get_dns_search + nm_setting_ip_config_get_dns_search (s_ip4, i)); } ifnet_set_data (conn_name, "dns_search", searches->str); @@ -2485,12 +2453,12 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err ifnet_set_data (conn_name, "dns_search", NULL); /* FIXME Will be implemented when configuration supports it if (!strcmp(value, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { - value = nm_setting_ip4_config_get_dhcp_hostname(s_ip4); + value = nm_setting_ip_config_get_dhcp_hostname(s_ip4); if (value) ifnet_set_data(conn_name, "DHCP_HOSTNAME", value, FALSE); - value = nm_setting_ip4_config_get_dhcp_client_id(s_ip4); + value = nm_setting_ip_config_get_dhcp_client_id(s_ip4); if (value) ifnet_set_data(conn_name, "DHCP_CLIENT_ID", value, FALSE); @@ -2498,32 +2466,22 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err */ /* Static routes */ - num = nm_setting_ip4_config_get_num_routes (s_ip4); + num = nm_setting_ip_config_get_num_routes (s_ip4); if (num > 0) { for (i = 0; i < num; i++) { - char buf[INET_ADDRSTRLEN + 1]; - NMIP4Route *route; - guint32 ip; - - route = nm_setting_ip4_config_get_route (s_ip4, i); - - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_route_get_dest (route); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], - sizeof (buf)); - g_string_append_printf (routes, "\"%s", buf); - - tmp = - g_strdup_printf ("%u", - nm_ip4_route_get_prefix (route)); - g_string_append_printf (routes, "/%s via ", tmp); - g_free (tmp); + NMIPRoute *route; + const char *next_hop; + + route = nm_setting_ip_config_get_route (s_ip4, i); + + next_hop = nm_ip_route_get_next_hop (route); + if (!next_hop) + next_hop = "0.0.0.0"; - memset (buf, 0, sizeof (buf)); - ip = nm_ip4_route_get_next_hop (route); - inet_ntop (AF_INET, (const void *) &ip, &buf[0], - sizeof (buf)); - g_string_append_printf (routes, "%s\" ", buf); + g_string_append_printf (routes, "\"%s/%u via %s\" ", + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + next_hop); } } if (routes->len > 0) @@ -2538,19 +2496,16 @@ write_ip4_setting (NMConnection *connection, const char *conn_name, GError **err } static gboolean -write_route6_file (NMSettingIP6Config *s_ip6, const char *conn_name, GError **error) +write_route6_file (NMSettingIPConfig *s_ip6, const char *conn_name, GError **error) { - char dest[INET6_ADDRSTRLEN + 1]; - char next_hop[INET6_ADDRSTRLEN + 1]; - NMIP6Route *route; - const struct in6_addr *ip; - guint32 prefix; + NMIPRoute *route; + const char *next_hop; guint32 i, num; GString *routes_string; const char *old_routes; g_return_val_if_fail (s_ip6 != NULL, FALSE); - num = nm_setting_ip6_config_get_num_routes (s_ip6); + num = nm_setting_ip_config_get_num_routes (s_ip6); if (num == 0) { return TRUE; } @@ -2560,22 +2515,16 @@ write_route6_file (NMSettingIP6Config *s_ip6, const char *conn_name, GError **er if (old_routes) g_string_append (routes_string, "\" "); for (i = 0; i < num; i++) { - route = nm_setting_ip6_config_get_route (s_ip6, i); + route = nm_setting_ip_config_get_route (s_ip6, i); - memset (dest, 0, sizeof (dest)); - ip = nm_ip6_route_get_dest (route); - inet_ntop (AF_INET6, (const void *) ip, &dest[0], - sizeof (dest)); - - prefix = nm_ip6_route_get_prefix (route); - - memset (next_hop, 0, sizeof (next_hop)); - ip = nm_ip6_route_get_next_hop (route); - inet_ntop (AF_INET6, (const void *) ip, &next_hop[0], - sizeof (next_hop)); + next_hop = nm_ip_route_get_next_hop (route); + if (!next_hop) + next_hop = "::"; g_string_append_printf (routes_string, "\"%s/%u via %s\" ", - dest, prefix, next_hop); + nm_ip_route_get_dest (route), + nm_ip_route_get_prefix (route), + next_hop); } if (num > 0) ifnet_set_data (conn_name, "routes", routes_string->str); @@ -2587,24 +2536,21 @@ write_route6_file (NMSettingIP6Config *s_ip6, const char *conn_name, GError **er static gboolean write_ip6_setting (NMConnection *connection, const char *conn_name, GError **error) { - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip6; const char *value; - char *prefix; guint32 i, num; GString *searches; - char buf[INET6_ADDRSTRLEN + 1]; - NMIP6Address *addr; - const struct in6_addr *ip; + NMIPAddress *addr; s_ip6 = nm_connection_get_setting_ip6_config (connection); if (!s_ip6) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing '%s' setting", NM_SETTING_IP6_CONFIG_SETTING_NAME); return FALSE; } - value = nm_setting_ip6_config_get_method (s_ip6); + value = nm_setting_ip_config_get_method (s_ip6); g_assert (value); if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { ifnet_set_data (conn_name, "enable_ipv6", "false"); @@ -2638,22 +2584,16 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err if (!config) config = ""; - num = nm_setting_ip6_config_get_num_addresses (s_ip6); + num = nm_setting_ip_config_get_num_addresses (s_ip6); /* IPv6 addresses */ ip_str = g_string_new (NULL); for (i = 0; i < num; i++) { - addr = nm_setting_ip6_config_get_address (s_ip6, i); - ip = nm_ip6_address_get_address (addr); - prefix = - g_strdup_printf ("%u", - nm_ip6_address_get_prefix (addr)); - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET6, (const void *) ip, buf, - sizeof (buf)); - g_string_append_printf (ip_str, "\"%s/", buf); - g_string_append_printf (ip_str, "%s\" ", prefix); - g_free (prefix); + addr = nm_setting_ip_config_get_address (s_ip6, i); + + g_string_append_printf (ip_str, "\"%s/%u\"", + nm_ip_address_get_address (addr), + nm_ip_address_get_prefix (addr)); } tmp = g_strdup_printf ("%s\" %s", config, ip_str->str); ifnet_set_data (conn_name, "config", tmp); @@ -2662,22 +2602,20 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err } /* DNS Servers */ - num = nm_setting_ip6_config_get_num_dns (s_ip6); + num = nm_setting_ip_config_get_num_dns (s_ip6); if (num > 0) { const char *dns_servers = ifnet_get_data (conn_name, "dns_servers"); gchar *tmp; GString *dns_string = g_string_new (NULL); + const char *dns; if (!dns_servers) dns_servers = ""; for (i = 0; i < num; i++) { - ip = nm_setting_ip6_config_get_dns (s_ip6, i); + dns = nm_setting_ip_config_get_dns (s_ip6, i); - memset (buf, 0, sizeof (buf)); - inet_ntop (AF_INET6, (const void *) ip, buf, - sizeof (buf)); - if (!strstr (dns_servers, buf)) - g_string_append_printf (dns_string, "%s ", buf); + if (!strstr (dns_servers, dns)) + g_string_append_printf (dns_string, "%s ", dns); } tmp = g_strdup_printf ("%s %s", dns_servers, dns_string->str); ifnet_set_data (conn_name, "dns_servers", tmp); @@ -2686,7 +2624,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err } else /* DNS Searches */ - num = nm_setting_ip6_config_get_num_dns_searches (s_ip6); + num = nm_setting_ip_config_get_num_dns_searches (s_ip6); if (num > 0) { const char *ip4_domains; @@ -2698,7 +2636,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err const gchar *search = NULL; search = - nm_setting_ip6_config_get_dns_search (s_ip6, i); + nm_setting_ip_config_get_dns_search (s_ip6, i); if (search && !strstr (searches->str, search)) { if (searches->len > 0) g_string_append_c (searches, ' '); @@ -2716,7 +2654,7 @@ write_ip6_setting (NMConnection *connection, const char *conn_name, GError **err } static gboolean -write_pppoe_setting (const char *conn_name, NMSettingPPPOE * s_pppoe) +write_pppoe_setting (const char *conn_name, NMSettingPppoe * s_pppoe) { const gchar *value; @@ -2744,7 +2682,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection, GError **error) { NMSettingConnection *s_con; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip6; gboolean success = FALSE; const char *type; gboolean no_8021x = FALSE; @@ -2759,7 +2697,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection, type = nm_setting_connection_get_connection_type (s_con); if (!type) { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Missing connection type!"); goto out; } @@ -2775,7 +2713,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection, if (!write_wireless_setting (connection, conn_name, &no_8021x, &new_name, error)) goto out; } else if (!strcmp (type, NM_SETTING_PPPOE_SETTING_NAME)) { - NMSettingPPPOE *s_pppoe; + NMSettingPppoe *s_pppoe; /* Writing pppoe setting */ s_pppoe = nm_connection_get_setting_pppoe (connection); @@ -2785,7 +2723,7 @@ ifnet_update_parsers_by_connection (NMConnection *connection, wired = TRUE; no_8021x = TRUE; } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_NOT_SUPPORTED, "Can't write connection type '%s'", type); goto out; } @@ -2862,7 +2800,8 @@ check_unsupported_secrets (NMSetting *setting, if (flags & NM_SETTING_PARAM_SECRET) { NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - nm_setting_get_secret_flags (setting, key, &secret_flags, NULL); + if (!nm_setting_get_secret_flags (setting, key, &secret_flags, NULL)) + g_return_if_reached (); if (secret_flags != NM_SETTING_SECRET_FLAG_NONE) *unsupported_secret = TRUE; } @@ -2880,39 +2819,39 @@ ifnet_can_write_connection (NMConnection *connection, GError **error) /* If the connection is not available for all users, ignore * it as this plugin only deals with System Connections */ if (nm_setting_connection_get_num_permissions (s_con)) { - g_set_error_literal (error, IFNET_PLUGIN_ERROR, 0, + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_NOT_SUPPORTED, "The ifnet plugin does not support non-system-wide connections."); return FALSE; } - /* If the connection has flagged secrets, ignore - * it as this plugin does not deal with user agent service */ - nm_connection_for_each_setting_value (connection, - check_unsupported_secrets, - &has_unsupported_secrets); - if (has_unsupported_secrets) { - g_set_error_literal (error, IFNET_PLUGIN_ERROR, 0, - "The ifnet plugin only supports persistent system secrets."); - return FALSE; - } - /* Only support wired, wifi, and PPPoE */ if ( !nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME) && !nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME) && !nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) { - g_set_error (error, IFNET_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_NOT_SUPPORTED, "The ifnet plugin cannot write the connection '%s' (type '%s')", nm_connection_get_id (connection), nm_setting_connection_get_connection_type (s_con)); return FALSE; } + /* If the connection has flagged secrets, ignore + * it as this plugin does not deal with user agent service */ + nm_connection_for_each_setting_value (connection, + check_unsupported_secrets, + &has_unsupported_secrets); + if (has_unsupported_secrets) { + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_NOT_SUPPORTED, + "The ifnet plugin only supports persistent system secrets."); + return FALSE; + } + return TRUE; } /* get the available wired name(eth*). */ static gchar * -get_wired_name () +get_wired_name (void) { int i = 0; @@ -2929,7 +2868,7 @@ get_wired_name () /* get the available pppoe name(ppp*). */ static gchar * -get_ppp_name () +get_ppp_name (void) { int i = 0; @@ -2949,7 +2888,9 @@ static gchar * get_wireless_name (NMConnection * connection) { NMSettingWireless *s_wireless; - const GByteArray *ssid; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; gboolean hex_ssid = FALSE; gchar *result = NULL; char buf[33]; @@ -2960,12 +2901,13 @@ get_wireless_name (NMConnection * connection) return NULL; ssid = nm_setting_wireless_get_ssid (s_wireless); - if (!ssid->len || ssid->len > 32) { + ssid_data = g_bytes_get_data (ssid, &ssid_len); + if (!ssid_len || ssid_len > 32) { return NULL; } - for (i = 0; i < ssid->len; i++) { - if (!g_ascii_isprint (ssid->data[i])) { + for (i = 0; i < ssid_len; i++) { + if (!g_ascii_isprint (ssid_data[i])) { hex_ssid = TRUE; break; } @@ -2974,15 +2916,15 @@ get_wireless_name (NMConnection * connection) if (hex_ssid) { GString *str; - str = g_string_sized_new (ssid->len * 2 + 3); + str = g_string_sized_new (ssid_len * 2 + 3); g_string_append (str, "0x"); - for (i = 0; i < ssid->len; i++) - g_string_append_printf (str, "%02X", ssid->data[i]); + for (i = 0; i < ssid_len; i++) + g_string_append_printf (str, "%02X", ssid_data[i]); result = g_strdup (str->str); g_string_free (str, TRUE); } else { memset (buf, 0, sizeof (buf)); - memcpy (buf, ssid->data, ssid->len); + memcpy (buf, ssid_data, ssid_len); result = g_strdup_printf ("%s", buf); g_strstrip (result); } @@ -3031,7 +2973,7 @@ ifnet_add_new_connection (NMConnection *connection, goto out; new_type = "ppp"; } else { - g_set_error (error, ifnet_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_NOT_SUPPORTED, "Can't write connection type '%s'", type); goto out; } diff --git a/src/settings/plugins/ifnet/errors.c b/src/settings/plugins/ifnet/errors.c deleted file mode 100644 index 295db18b..00000000 --- a/src/settings/plugins/ifnet/errors.c +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- 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. - * - * (C) Copyright 2013 Red Hat, Inc. - */ - -#include <glib.h> -#include "errors.h" - -GQuark -ifnet_plugin_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("ifnet-plugin-error-quark"); - - return error_quark; -} - - diff --git a/src/settings/plugins/ifnet/errors.h b/src/settings/plugins/ifnet/errors.h deleted file mode 100644 index 52517d00..00000000 --- a/src/settings/plugins/ifnet/errors.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- 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. - * - * (C) Copyright 2013 Red Hat, Inc. - */ - -#ifndef __ERRORS_H__ -#define __ERRORS_H__ - -#include <glib.h> - -#define IFNET_PLUGIN_ERROR (ifnet_plugin_error_quark ()) -GQuark ifnet_plugin_error_quark (void); - -#endif /* __ERRORS_H__ */ - diff --git a/src/settings/plugins/ifnet/net_parser.c b/src/settings/plugins/ifnet/net_parser.c index 95add14f..1cf46fbf 100644 --- a/src/settings/plugins/ifnet/net_parser.c +++ b/src/settings/plugins/ifnet/net_parser.c @@ -19,6 +19,8 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ +#include "config.h" + #include <string.h> #include <stdio.h> #include <sys/ioctl.h> diff --git a/src/settings/plugins/ifnet/net_utils.c b/src/settings/plugins/ifnet/net_utils.c index 86ab8537..adb23c43 100644 --- a/src/settings/plugins/ifnet/net_utils.c +++ b/src/settings/plugins/ifnet/net_utils.c @@ -19,11 +19,14 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ +#include "config.h" + #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <nm-utils.h> +#include <NetworkManagerUtils.h> #include <nm-system-config-interface.h> #include <nm-logging.h> #include <nm-config.h> @@ -365,23 +368,21 @@ create_ip4_block (gchar * ip) ip_mask = g_strsplit (ip, "/", 0); length = g_strv_length (ip_mask); - if (!inet_pton (AF_INET, ip_mask[0], &tmp_ip4_addr)) + if (!nm_utils_ipaddr_valid (AF_INET, ip_mask[0])) goto error; - iblock->ip = tmp_ip4_addr; + iblock->ip = g_strdup (ip_mask[0]); prefix = ip_mask[1]; i = 0; while (i < length && g_ascii_isdigit (prefix[i])) i++; prefix[i] = '\0'; - iblock->netmask = nm_utils_ip4_prefix_to_netmask ((guint32) - atoi (ip_mask - [1])); + iblock->prefix = (guint32) atoi (ip_mask[1]); } else if (strstr (ip, "netmask")) { ip_mask = g_strsplit (ip, " ", 0); length = g_strv_length (ip_mask); - if (!inet_pton (AF_INET, ip_mask[0], &tmp_ip4_addr)) + if (!nm_utils_ipaddr_valid (AF_INET, ip_mask[0])) goto error; - iblock->ip = tmp_ip4_addr; + iblock->ip = g_strdup (ip_mask[0]); i = 0; while (i < length && !strstr (ip_mask[++i], "netmask")) ; while (i < length && ip_mask[++i][0] == '\0') ; @@ -389,39 +390,42 @@ create_ip4_block (gchar * ip) goto error; if (!inet_pton (AF_INET, ip_mask[i], &tmp_ip4_addr)) goto error; - iblock->netmask = tmp_ip4_addr; + iblock->prefix = nm_utils_ip4_netmask_to_prefix (tmp_ip4_addr); } else { g_slice_free (ip_block, iblock); if (!is_ip6_address (ip) && !strstr (ip, "dhcp")) nm_log_warn (LOGD_SETTINGS, "Can't handle ipv4 address: %s, missing netmask or prefix", ip); return NULL; } + if (iblock->prefix == 0 || iblock->prefix > 32) { + nm_log_warn (LOGD_SETTINGS, "Can't handle ipv4 address: %s, invalid prefix", ip); + goto error; + } g_strfreev (ip_mask); return iblock; error: if (!is_ip6_address (ip)) nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 address: %s", ip); g_strfreev (ip_mask); + g_free (iblock->ip); g_slice_free (ip_block, iblock); return NULL; } -static ip6_block * -create_ip6_block (gchar * ip) +static ip_block * +create_ip_block (gchar * ip) { - ip6_block *iblock = g_slice_new0 (ip6_block); + ip_block *iblock = g_slice_new0 (ip_block); gchar *dup_ip = g_strdup (ip); - struct in6_addr *tmp_ip6_addr = g_slice_new0 (struct in6_addr); gchar *prefix = NULL; if ((prefix = strstr (dup_ip, "/")) != NULL) { *prefix = '\0'; prefix++; } - if (!inet_pton (AF_INET6, dup_ip, tmp_ip6_addr)) { + if (!nm_utils_ipaddr_valid (AF_INET6, dup_ip)) goto error; - } - iblock->ip = tmp_ip6_addr; + iblock->ip = dup_ip; if (prefix) { errno = 0; iblock->prefix = strtol (prefix, NULL, 10); @@ -430,30 +434,26 @@ create_ip6_block (gchar * ip) } } else iblock->prefix = 64; - g_free (dup_ip); return iblock; error: if (!is_ip4_address (ip)) nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 address: %s", ip); - g_slice_free (ip6_block, iblock); - g_slice_free (struct in6_addr, tmp_ip6_addr); - + g_slice_free (ip_block, iblock); g_free (dup_ip); return NULL; } -static guint32 +static char * get_ip4_gateway (gchar * gateway) { gchar *tmp, *split; - guint32 tmp_ip4_addr; if (!gateway) - return 0; + return NULL; tmp = find_gateway_str (gateway); if (!tmp) { nm_log_warn (LOGD_SETTINGS, "Couldn't obtain gateway in \"%s\"", gateway); - return 0; + return NULL; } tmp = g_strdup (tmp); strip_string (tmp, ' '); @@ -463,43 +463,39 @@ get_ip4_gateway (gchar * gateway) if ((split = strstr (tmp, "\"")) != NULL) *split = '\0'; - if (!inet_pton (AF_INET, tmp, &tmp_ip4_addr)) + if (!nm_utils_ipaddr_valid (AF_INET, tmp)) goto error; - g_free (tmp); - return tmp_ip4_addr; + return tmp; error: if (!is_ip6_address (tmp)) nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 gateway: %s", tmp); g_free (tmp); - return 0; + return NULL; } -static struct in6_addr * +static char * get_ip6_next_hop (gchar * next_hop) { gchar *tmp; - struct in6_addr *tmp_ip6_addr = g_slice_new0 (struct in6_addr); if (!next_hop) - return 0; + return NULL; tmp = find_gateway_str (next_hop); if (!tmp) { nm_log_warn (LOGD_SETTINGS, "Couldn't obtain next_hop in \"%s\"", next_hop); - return 0; + return NULL; } tmp = g_strdup (tmp); strip_string (tmp, ' '); strip_string (tmp, '"'); g_strstrip (tmp); - if (!inet_pton (AF_INET6, tmp, tmp_ip6_addr)) + if (!nm_utils_ipaddr_valid (AF_INET6, tmp)) goto error; - g_free (tmp); - return tmp_ip6_addr; + return tmp; error: if (!is_ip4_address (tmp)) nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 next_hop: %s", tmp); g_free (tmp); - g_slice_free (struct in6_addr, tmp_ip6_addr); return NULL; } @@ -511,7 +507,7 @@ convert_ip4_config_block (const char *conn_name) guint length; guint i; gchar *ip; - guint32 def_gateway = 0; + char *def_gateway = NULL; const char *routes; ip_block *start = NULL, *current = NULL, *iblock = NULL; @@ -530,8 +526,8 @@ convert_ip4_config_block (const char *conn_name) iblock = create_ip4_block (ip); if (iblock == NULL) continue; - if (!iblock->gateway && def_gateway != 0) - iblock->gateway = def_gateway; + if (!iblock->next_hop && def_gateway != NULL) + iblock->next_hop = g_strdup (def_gateway); if (start == NULL) start = current = iblock; else { @@ -540,17 +536,18 @@ convert_ip4_config_block (const char *conn_name) } } g_strfreev (ipset); + g_free (def_gateway); return start; } -ip6_block * +ip_block * convert_ip6_config_block (const char *conn_name) { gchar **ipset; guint length; guint i; gchar *ip; - ip6_block *start = NULL, *current = NULL, *iblock = NULL; + ip_block *start = NULL, *current = NULL, *iblock = NULL; g_return_val_if_fail (conn_name != NULL, NULL); ipset = split_addresses (ifnet_get_data (conn_name, "config")); @@ -558,7 +555,7 @@ convert_ip6_config_block (const char *conn_name) for (i = 0; i < length; i++) { ip = ipset[i]; ip = strip_string (ip, '"'); - iblock = create_ip6_block (ip); + iblock = create_ip_block (ip); if (iblock == NULL) continue; if (start == NULL) @@ -594,7 +591,7 @@ convert_ip4_routes_block (const char *conn_name) iblock = create_ip4_block (ip); if (iblock == NULL) continue; - iblock->gateway = get_ip4_gateway (ip); + iblock->next_hop = get_ip4_gateway (ip); if (start == NULL) start = current = iblock; else { @@ -606,15 +603,14 @@ convert_ip4_routes_block (const char *conn_name) return start; } -ip6_block * +ip_block * convert_ip6_routes_block (const char *conn_name) { gchar **ipset; guint length; guint i; gchar *ip, *tmp_addr; - ip6_block *start = NULL, *current = NULL, *iblock = NULL; - struct in6_addr *tmp_ip6_addr; + ip_block *start = NULL, *current = NULL, *iblock = NULL; g_return_val_if_fail (conn_name != NULL, NULL); ipset = split_routes (ifnet_get_data (conn_name, "routes")); @@ -628,25 +624,17 @@ convert_ip6_routes_block (const char *conn_name) if (!is_ip6_address (tmp_addr)) continue; else { - tmp_ip6_addr = g_slice_new0 (struct in6_addr); - - if (inet_pton (AF_INET6, "::", tmp_ip6_addr)) { - iblock = g_slice_new0 (ip6_block); - iblock->ip = tmp_ip6_addr; - iblock->prefix = 128; - } else { - g_slice_free (struct in6_addr, - tmp_ip6_addr); - continue; - } + iblock = g_slice_new0 (ip_block); + iblock->ip = g_strdup ("::"); + iblock->prefix = 128; } } else - iblock = create_ip6_block (ip); + iblock = create_ip_block (ip); if (iblock == NULL) continue; iblock->next_hop = get_ip6_next_hop (ip); if (iblock->next_hop == NULL) { - destroy_ip6_block (iblock); + destroy_ip_block (iblock); continue; } if (start == NULL) @@ -663,26 +651,18 @@ convert_ip6_routes_block (const char *conn_name) void destroy_ip_block (ip_block * iblock) { + g_free (iblock->ip); + g_free (iblock->next_hop); g_slice_free (ip_block, iblock); } void -destroy_ip6_block (ip6_block * iblock) -{ - g_slice_free (struct in6_addr, iblock->ip); - g_slice_free (struct in6_addr, iblock->next_hop); - - g_slice_free (ip6_block, iblock); -} - -void -set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name) +set_ip4_dns_servers (NMSettingIPConfig *s_ip4, const char *conn_name) { const char *dns_servers; gchar **server_list, *stripped; guint length, i; guint32 tmp_ip4_addr; - guint32 new_dns; dns_servers = ifnet_get_data (conn_name, "dns_servers"); if (!dns_servers) @@ -694,7 +674,7 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name) length = g_strv_length (server_list); if (length) - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL); for (i = 0; i < length; i++) { g_strstrip (server_list[i]); @@ -705,15 +685,14 @@ set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name) nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]); continue; } - new_dns = tmp_ip4_addr; - if (new_dns && !nm_setting_ip4_config_add_dns (s_ip4, new_dns)) + if (!nm_setting_ip_config_add_dns (s_ip4, server_list[i])) nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]); } g_strfreev (server_list); } void -set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name) +set_ip6_dns_servers (NMSettingIPConfig *s_ip6, const char *conn_name) { const char *dns_servers; gchar **server_list, *stripped; @@ -731,7 +710,7 @@ set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name) length = g_strv_length (server_list); if (length) - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL); for (i = 0; i < length; i++) { g_strstrip (server_list[i]); @@ -742,8 +721,7 @@ set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name) nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]); continue; } - if (!IN6_IS_ADDR_UNSPECIFIED (&tmp_ip6_addr) - && !nm_setting_ip6_config_add_dns (s_ip6, &tmp_ip6_addr)) + if (!nm_setting_ip_config_add_dns (s_ip6, server_list[i])) nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]); } g_strfreev (server_list); @@ -763,30 +741,49 @@ is_managed (const char *conn_name) return TRUE; } +static char * +_has_prefix_impl (char *str, const char *prefix, gsize prefix_len) +{ + if (!g_str_has_prefix (str, prefix)) + return NULL; + str += prefix_len; + if (!g_ascii_isspace (str[0])) + return NULL; + do { + str++; + } while (g_ascii_isspace (str[0])); + return str; +} +#define _has_prefix(STR, PREFIX) _has_prefix_impl (STR, PREFIX, STRLEN (PREFIX)) + void get_dhcp_hostname_and_client_id (char **hostname, char **client_id) { const char *dhcp_client; const gchar *dhcpcd_conf = SYSCONFDIR "/dhcpcd.conf"; const gchar *dhclient_conf = SYSCONFDIR "/dhcp/dhclient.conf"; - gchar *line = NULL, *tmp = NULL, *contents = NULL; + gchar *line = NULL, *tmp = NULL, *contents = NULL, *tmp1; gchar **all_lines; guint line_num, i; + gboolean use_dhclient = FALSE; *hostname = NULL; *client_id = NULL; dhcp_client = nm_config_get_dhcp_client (nm_config_get ()); if (dhcp_client) { - if (!strcmp (dhcp_client, "dhclient")) + if (!strcmp (dhcp_client, "dhclient")) { g_file_get_contents (dhclient_conf, &contents, NULL, NULL); - else if (!strcmp (dhcp_client, "dhcpcd")) + use_dhclient = TRUE; + } else if (!strcmp (dhcp_client, "dhcpcd")) g_file_get_contents (dhcpcd_conf, &contents, NULL, NULL); } else { - if (g_file_test (dhclient_conf, G_FILE_TEST_IS_REGULAR)) + if (g_file_test (dhclient_conf, G_FILE_TEST_IS_REGULAR)) { g_file_get_contents (dhclient_conf, &contents, NULL, NULL); + use_dhclient = TRUE; + } else if (g_file_test (dhcpcd_conf, G_FILE_TEST_IS_REGULAR)) g_file_get_contents (dhcpcd_conf, &contents, NULL, NULL); @@ -797,42 +794,44 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id) line_num = g_strv_length (all_lines); for (i = 0; i < line_num; i++) { line = all_lines[i]; - // dhcpcd.conf g_strstrip (line); - if (g_str_has_prefix (line, "hostname")) { - tmp = line + strlen ("hostname"); - g_strstrip (tmp); - if (tmp[0] != '\0') - *hostname = g_strdup (tmp); - else - nm_log_info (LOGD_SETTINGS, "dhcpcd hostname not defined, ignoring"); - } else if (g_str_has_prefix (line, "clientid")) { - tmp = line + strlen ("clientid"); - g_strstrip (tmp); - if (tmp[0] != '\0') - *client_id = g_strdup (tmp); - else - nm_log_info (LOGD_SETTINGS, "dhcpcd clientid not defined, ignoring"); - } - // dhclient.conf - else if ((tmp = strstr (line, "send host-name")) != NULL) { - tmp += strlen ("send host-name"); - g_strstrip (tmp); - strip_string (tmp, ';'); - strip_string (tmp, '"'); - if (tmp[0] != '\0') - *hostname = g_strdup (tmp); - else - nm_log_info (LOGD_SETTINGS, "dhclient hostname not defined, ignoring"); - } else if ((tmp = strstr (line, "send dhcp-client-identifier")) - != NULL) { - tmp += strlen ("send dhcp-client-identifier"); - g_strstrip (tmp); - strip_string (tmp, ';'); - if (tmp[0] != '\0') - *client_id = g_strdup (tmp); - else - nm_log_info (LOGD_SETTINGS, "dhclient clientid not defined, ignoring"); + if (line[0] == '#' || line[0] == '\0') + continue; + if (!use_dhclient) { + // dhcpcd.conf + if ((tmp = _has_prefix (line, "hostname"))) { + if (tmp[0] != '\0') { + g_free (*hostname); + *hostname = g_strdup (tmp); + } else + nm_log_info (LOGD_SETTINGS, "dhcpcd hostname not defined, ignoring"); + } else if ((tmp = _has_prefix (line, "clientid"))) { + if (tmp[0] != '\0') { + g_free (*client_id); + *client_id = g_strdup (tmp); + } else + nm_log_info (LOGD_SETTINGS, "dhcpcd clientid not defined, ignoring"); + } + } else { + // dhclient.conf + if ((tmp1 = _has_prefix (line, "send"))) { + if ((tmp = _has_prefix (tmp1, "host-name"))) { + strip_string (tmp, ';'); + strip_string (tmp, '"'); + if (tmp[0] != '\0') { + g_free (*hostname); + *hostname = g_strdup (tmp); + } else + nm_log_info (LOGD_SETTINGS, "dhclient hostname not defined, ignoring"); + } else if ((tmp = _has_prefix (tmp1, "dhcp-client-identifier"))) { + strip_string (tmp, ';'); + if (tmp[0] != '\0') { + g_free (*client_id); + *client_id = g_strdup (tmp); + } else + nm_log_info (LOGD_SETTINGS, "dhclient clientid not defined, ignoring"); + } + } } } g_strfreev (all_lines); diff --git a/src/settings/plugins/ifnet/net_utils.h b/src/settings/plugins/ifnet/net_utils.h index cee71d57..d58e7ec6 100644 --- a/src/settings/plugins/ifnet/net_utils.h +++ b/src/settings/plugins/ifnet/net_utils.h @@ -31,19 +31,12 @@ #define has_default_ip6_route(conn_name) has_default_route((conn_name), &is_ip6_address) typedef struct _ip_block { - guint32 ip; - guint32 netmask; - guint32 gateway; + char *ip; + guint32 prefix; + char *next_hop; struct _ip_block *next; } ip_block; -typedef struct _ip6_block { - struct in6_addr *ip; - long int prefix; - struct in6_addr *next_hop; - struct _ip6_block *next; -} ip6_block; - gchar *read_hostname (const char *path); gboolean write_hostname (const char *path, const char *hostname); gboolean is_static_ip4 (const char *conn_name); @@ -55,14 +48,13 @@ gboolean has_default_route (const char *conn_name, gboolean (*check_fn) (const c gboolean reload_parsers (void); ip_block *convert_ip4_config_block (const char *conn_name); -ip6_block *convert_ip6_config_block (const char *conn_name); +ip_block *convert_ip6_config_block (const char *conn_name); ip_block *convert_ip4_routes_block (const char *conn_name); -ip6_block *convert_ip6_routes_block (const char *conn_name); +ip_block *convert_ip6_routes_block (const char *conn_name); void destroy_ip_block (ip_block * iblock); -void destroy_ip6_block (ip6_block * iblock); -void set_ip4_dns_servers (NMSettingIP4Config * s_ip4, const char *conn_name); -void set_ip6_dns_servers (NMSettingIP6Config * s_ip6, const char *conn_name); +void set_ip4_dns_servers (NMSettingIPConfig * s_ip4, const char *conn_name); +void set_ip6_dns_servers (NMSettingIPConfig * s_ip6, const char *conn_name); gchar *strip_string (gchar *str, gchar t); gboolean is_managed (const char *conn_name); diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.c b/src/settings/plugins/ifnet/nm-ifnet-connection.c index 478d6e32..c84ad5ed 100644 --- a/src/settings/plugins/ifnet/nm-ifnet-connection.c +++ b/src/settings/plugins/ifnet/nm-ifnet-connection.c @@ -19,15 +19,16 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ +#include "config.h" + #include <string.h> #include <glib/gstdio.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-utils.h> #include <nm-setting-wireless-security.h> #include <nm-settings-connection.h> #include <nm-system-config-interface.h> #include <nm-logging.h> -#include <nm-settings-error.h> #include "nm-ifnet-connection.h" #include "connection_parser.h" #include "net_parser.h" diff --git a/src/settings/plugins/ifnet/nm-ifnet-connection.h b/src/settings/plugins/ifnet/nm-ifnet-connection.h index 1cb67c34..baa4c07e 100644 --- a/src/settings/plugins/ifnet/nm-ifnet-connection.h +++ b/src/settings/plugins/ifnet/nm-ifnet-connection.h @@ -19,8 +19,8 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ -#ifndef NM_IFNET_CONNECTION_H -#define NM_IFNET_CONNECTION_H +#ifndef __NETWORKMANAGER_IFNET_CONNECTION_H__ +#define __NETWORKMANAGER_IFNET_CONNECTION_H__ #include <nm-settings-connection.h> #include "net_parser.h" diff --git a/src/settings/plugins/ifnet/plugin.c b/src/settings/plugins/ifnet/plugin.c index ab07b8d6..3eb1ed52 100644 --- a/src/settings/plugins/ifnet/plugin.c +++ b/src/settings/plugins/ifnet/plugin.c @@ -20,6 +20,8 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ +#include "config.h" + #include <string.h> #include <gmodule.h> @@ -29,7 +31,7 @@ #include <nm-utils.h> #include <nm-setting-connection.h> -#include "NetworkManager.h" +#include "nm-dbus-interface.h" #include "nm-system-config-interface.h" #include "nm-logging.h" #include "nm-ifnet-connection.h" diff --git a/src/settings/plugins/ifnet/tests/Makefile.am b/src/settings/plugins/ifnet/tests/Makefile.am index f66a6a3d..66409a54 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.am +++ b/src/settings/plugins/ifnet/tests/Makefile.am @@ -4,22 +4,17 @@ if ENABLE_TESTS AM_CPPFLAGS= \ -I$(srcdir)/../ \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/src/platform \ -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(CHECK_CFLAGS) \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -DTEST_WPA_SUPPLICANT_CONF='"$(srcdir)/wpa_supplicant.conf"' \ -DSYSCONFDIR=\"nonexistent\" @@ -30,8 +25,7 @@ check_ifnet_SOURCES = \ ../connection_parser.c \ ../net_parser.c \ ../net_utils.c \ - ../wpa_parser.c \ - ../errors.c + ../wpa_parser.c check_ifnet_LDFLAGS = \ $(CODE_COVERAGE_LDFLAGS) @@ -41,6 +35,8 @@ check_ifnet_LDADD = $(top_builddir)/src/libNetworkManager.la check-local: check_ifnet $(abs_builddir)/check_ifnet $(abs_srcdir) $(abs_builddir) +endif + EXTRA_DIST = \ hostname \ net \ @@ -48,5 +44,3 @@ EXTRA_DIST = \ nm-system-settings.conf \ wpa_supplicant.conf \ test_ca_cert.pem - -endif diff --git a/src/settings/plugins/ifnet/tests/Makefile.in b/src/settings/plugins/ifnet/tests/Makefile.in index cd604237..8293c869 100644 --- a/src/settings/plugins/ifnet/tests/Makefile.in +++ b/src/settings/plugins/ifnet/tests/Makefile.in @@ -104,11 +104,11 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) am__check_ifnet_SOURCES_DIST = test_all.c ../connection_parser.c \ - ../net_parser.c ../net_utils.c ../wpa_parser.c ../errors.c + ../net_parser.c ../net_utils.c ../wpa_parser.c @ENABLE_TESTS_TRUE@am_check_ifnet_OBJECTS = test_all.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ connection_parser.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ net_parser.$(OBJEXT) net_utils.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ wpa_parser.$(OBJEXT) errors.$(OBJEXT) +@ENABLE_TESTS_TRUE@ wpa_parser.$(OBJEXT) check_ifnet_OBJECTS = $(am_check_ifnet_OBJECTS) @ENABLE_TESTS_TRUE@check_ifnet_DEPENDENCIES = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la @@ -189,6 +189,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -312,6 +314,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -331,6 +334,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -357,7 +361,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -438,22 +442,17 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ @ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-glib \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/config \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/logging \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/platform \ @ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-ifnet"\" \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ $(CHECK_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(POLKIT_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ @ENABLE_TESTS_TRUE@ -DTEST_WPA_SUPPLICANT_CONF='"$(srcdir)/wpa_supplicant.conf"' \ @ENABLE_TESTS_TRUE@ -DSYSCONFDIR=\"nonexistent\" @@ -463,20 +462,19 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@ ../connection_parser.c \ @ENABLE_TESTS_TRUE@ ../net_parser.c \ @ENABLE_TESTS_TRUE@ ../net_utils.c \ -@ENABLE_TESTS_TRUE@ ../wpa_parser.c \ -@ENABLE_TESTS_TRUE@ ../errors.c +@ENABLE_TESTS_TRUE@ ../wpa_parser.c @ENABLE_TESTS_TRUE@check_ifnet_LDFLAGS = \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) @ENABLE_TESTS_TRUE@check_ifnet_LDADD = $(top_builddir)/src/libNetworkManager.la -@ENABLE_TESTS_TRUE@EXTRA_DIST = \ -@ENABLE_TESTS_TRUE@ hostname \ -@ENABLE_TESTS_TRUE@ net \ -@ENABLE_TESTS_TRUE@ net.all \ -@ENABLE_TESTS_TRUE@ nm-system-settings.conf \ -@ENABLE_TESTS_TRUE@ wpa_supplicant.conf \ -@ENABLE_TESTS_TRUE@ test_ca_cert.pem +EXTRA_DIST = \ + hostname \ + net \ + net.all \ + nm-system-settings.conf \ + wpa_supplicant.conf \ + test_ca_cert.pem all: all-am @@ -533,7 +531,6 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_parser.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_parser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net_utils.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_all.Po@am__quote@ @@ -616,20 +613,6 @@ wpa_parser.obj: ../wpa_parser.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o wpa_parser.obj `if test -f '../wpa_parser.c'; then $(CYGPATH_W) '../wpa_parser.c'; else $(CYGPATH_W) '$(srcdir)/../wpa_parser.c'; fi` -errors.o: ../errors.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.o -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c - -errors.obj: ../errors.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.obj -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` - mostlyclean-libtool: -rm -f *.lo diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c index c320ed5f..9c399128 100644 --- a/src/settings/plugins/ifnet/tests/test_all.c +++ b/src/settings/plugins/ifnet/tests/test_all.c @@ -20,6 +20,8 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ +#include "config.h" + #include <stdio.h> #include <string.h> #include <glib.h> @@ -55,7 +57,7 @@ nm_config_get_dhcp_client (NMConfig *config) } static void -test_getdata () +test_getdata (void) { ASSERT (ifnet_get_data ("eth1", "config") && strcmp (ifnet_get_data ("eth1", "config"), "( \"dhcp\" )") == 0, @@ -103,7 +105,7 @@ test_write_hostname (const char *temp_path) } static void -test_is_static () +test_is_static (void) { ASSERT (is_static_ip4 ("eth1") == FALSE, "is static", "a dhcp interface is recognized as static"); @@ -114,7 +116,7 @@ test_is_static () } static void -test_has_default_route () +test_has_default_route (void) { ASSERT (has_default_ip4_route ("eth0"), "has default route", "eth0 should have a default ipv4 route"); @@ -126,7 +128,7 @@ test_has_default_route () } static void -test_has_ip6_address () +test_has_ip6_address (void) { ASSERT (has_ip6_address ("eth2"), "has ip6 address", "eth2 should have a ipv6 address"); @@ -136,7 +138,7 @@ test_has_ip6_address () } static void -test_is_ip4_address () +test_is_ip4_address (void) { gchar *address1 = "192.168.4.232/24"; gchar *address2 = "192.168.100.{1..254}/24"; @@ -151,7 +153,7 @@ test_is_ip4_address () } static void -test_is_ip6_address () +test_is_ip6_address (void) { gchar *address1 = "4321:0:1:2:3:4:567:89ac/24"; @@ -160,43 +162,30 @@ test_is_ip6_address () } static void -check_ip_block (ip_block * iblock, gchar * ip, gchar * netmask, gchar * gateway) +check_ip_block (ip_block * iblock, gchar * ip, guint32 prefix, gchar * gateway) { - char *str; - guint32 tmp_ip4_addr; - - str = malloc (INET_ADDRSTRLEN); - tmp_ip4_addr = iblock->ip; - inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN); - ASSERT (strcmp (ip, str) == 0, "check ip", - "ip expected:%s, find:%s", ip, str); - tmp_ip4_addr = iblock->netmask; - inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN); - ASSERT (strcmp (netmask, str) == 0, "check netmask", - "netmask expected:%s, find:%s", netmask, str); - tmp_ip4_addr = iblock->gateway; - inet_ntop (AF_INET, &tmp_ip4_addr, str, INET_ADDRSTRLEN); - ASSERT (strcmp (gateway, str) == 0, "check gateway", - "gateway expected:%s, find:%s", gateway, str); - free (str); + ASSERT (strcmp (ip, iblock->ip) == 0, "check ip", + "ip expected:%s, find:%s", ip, iblock->ip); + ASSERT (prefix == iblock->prefix, "check netmask", + "prefix expected:%d, find:%d", prefix, iblock->prefix); + ASSERT (g_strcmp0 (gateway, iblock->next_hop) == 0, "check gateway", + "gateway expected:%s, find:%s", gateway, iblock->next_hop); } static void -test_convert_ipv4_config_block () +test_convert_ipv4_config_block (void) { ip_block *iblock = convert_ip4_config_block ("eth0"); ip_block *tmp = iblock; ASSERT (iblock != NULL, "convert ipv4 block", "block eth0 should not be NULL"); - check_ip_block (iblock, "202.117.16.121", "255.255.255.0", - "202.117.16.1"); + check_ip_block (iblock, "202.117.16.121", 24, "202.117.16.1"); iblock = iblock->next; destroy_ip_block (tmp); ASSERT (iblock != NULL, "convert ipv4 block", "block eth0 should have a second IP address"); - check_ip_block (iblock, "192.168.4.121", "255.255.255.0", - "202.117.16.1"); + check_ip_block (iblock, "192.168.4.121", 24, "202.117.16.1"); destroy_ip_block (iblock); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, @@ -206,7 +195,7 @@ test_convert_ipv4_config_block () ASSERT (iblock != NULL && iblock->next == NULL, "convert error IPv4 address", "should only get one address"); - check_ip_block (iblock, "192.168.4.121", "255.255.255.0", "0.0.0.0"); + check_ip_block (iblock, "192.168.4.121", 24, NULL); destroy_ip_block (iblock); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, @@ -214,17 +203,16 @@ test_convert_ipv4_config_block () iblock = convert_ip4_config_block ("eth3"); ASSERT (iblock == NULL, "convert config_block", "convert error configuration"); - destroy_ip_block (iblock); } static void -test_convert_ipv4_routes_block () +test_convert_ipv4_routes_block (void) { ip_block *iblock = convert_ip4_routes_block ("eth0"); ip_block *tmp = iblock; ASSERT (iblock != NULL, "convert ip4 routes", "should get one route"); - check_ip_block (iblock, "192.168.4.0", "255.255.255.0", "192.168.4.1"); + check_ip_block (iblock, "192.168.4.0", 24, "192.168.4.1"); iblock = iblock->next; destroy_ip_block (tmp); ASSERT (iblock == NULL, "convert ip4 routes", @@ -234,7 +222,7 @@ test_convert_ipv4_routes_block () tmp = iblock; ASSERT (iblock != NULL, "convert ip4 routes", "should get one route"); - check_ip_block (iblock, "10.0.0.0", "255.0.0.0", "192.168.0.1"); + check_ip_block (iblock, "10.0.0.0", 8, "192.168.0.1"); iblock = iblock->next; destroy_ip_block (tmp); ASSERT (iblock == NULL, "convert ip4 routes", @@ -242,7 +230,7 @@ test_convert_ipv4_routes_block () } static void -test_wpa_parser () +test_wpa_parser (void) { const char *value; @@ -261,7 +249,7 @@ test_wpa_parser () } static void -test_strip_string () +test_strip_string (void) { gchar *str = "( \"default via 202.117.16.1\" )"; gchar *result = g_strdup (str); @@ -277,7 +265,7 @@ test_strip_string () } static void -test_is_unmanaged () +test_is_unmanaged (void) { ASSERT (is_managed ("eth0"), "test_is_unmanaged", "eth0 should be managed"); @@ -286,7 +274,7 @@ test_is_unmanaged () } static void -test_new_connection () +test_new_connection (void) { GError *error = NULL; NMConnection *connection; @@ -409,7 +397,7 @@ test_add_connection (const char *basepath) } static void -test_delete_connection () +test_delete_connection (void) { GError *error = NULL; NMConnection *connection; @@ -438,7 +426,7 @@ test_delete_connection () } static void -test_missing_config () +test_missing_config (void) { GError *error = NULL; NMConnection *connection; diff --git a/src/settings/plugins/ifnet/wpa_parser.c b/src/settings/plugins/ifnet/wpa_parser.c index 748eb351..3f912da8 100644 --- a/src/settings/plugins/ifnet/wpa_parser.c +++ b/src/settings/plugins/ifnet/wpa_parser.c @@ -19,6 +19,8 @@ * Copyright (C) 1999-2010 Gentoo Foundation, Inc. */ +#include "config.h" + #include <string.h> #include <stdlib.h> #include <nm-system-config-interface.h> @@ -166,7 +168,7 @@ add_one_wep_key (GHashTable * table, int key_num, gchar * one_wep_key) /* Reading wep security information from /etc/conf.d/net. * This should not be used in future, use wpa_supplicant instead. */ static void -add_keys_from_net () +add_keys_from_net (void) { GList *names = ifnet_get_connection_names (); GList *iter = names; diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am index fd98f8fe..0ca543e3 100644 --- a/src/settings/plugins/ifupdown/Makefile.am +++ b/src/settings/plugins/ifupdown/Makefile.am @@ -4,19 +4,14 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/logging \ - -I$(top_srcdir)/src/config \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" @@ -28,10 +23,6 @@ libifupdown_io_la_SOURCES = \ parser.c \ parser.h -libifupdown_io_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(GLIB_LIBS) - pkglib_LTLIBRARIES = libnm-settings-plugin-ifupdown.la libnm_settings_plugin_ifupdown_la_SOURCES = \ @@ -41,9 +32,5 @@ libnm_settings_plugin_ifupdown_la_SOURCES = \ plugin.h libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifupdown_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - libifupdown-io.la \ - $(GLIB_LIBS) \ - $(GUDEV_LIBS) +libnm_settings_plugin_ifupdown_la_LIBADD = libifupdown-io.la diff --git a/src/settings/plugins/ifupdown/Makefile.in b/src/settings/plugins/ifupdown/Makefile.in index 50d4ca08..44596e48 100644 --- a/src/settings/plugins/ifupdown/Makefile.in +++ b/src/settings/plugins/ifupdown/Makefile.in @@ -130,18 +130,14 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(pkglibdir)" LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES) -am__DEPENDENCIES_1 = -libifupdown_io_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la $(am__DEPENDENCIES_1) +libifupdown_io_la_LIBADD = am_libifupdown_io_la_OBJECTS = interface_parser.lo parser.lo libifupdown_io_la_OBJECTS = $(am_libifupdown_io_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -libnm_settings_plugin_ifupdown_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la libifupdown-io.la \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +libnm_settings_plugin_ifupdown_la_DEPENDENCIES = libifupdown-io.la am_libnm_settings_plugin_ifupdown_la_OBJECTS = \ nm-ifupdown-connection.lo plugin.lo libnm_settings_plugin_ifupdown_la_OBJECTS = \ @@ -264,6 +260,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -387,6 +385,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -406,6 +405,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -432,7 +432,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -514,19 +514,14 @@ with_valgrind = @with_valgrind@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/logging \ - -I$(top_srcdir)/src/config \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-glib \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" @@ -537,10 +532,6 @@ libifupdown_io_la_SOURCES = \ parser.c \ parser.h -libifupdown_io_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(GLIB_LIBS) - pkglib_LTLIBRARIES = libnm-settings-plugin-ifupdown.la libnm_settings_plugin_ifupdown_la_SOURCES = \ nm-ifupdown-connection.c \ @@ -549,12 +540,7 @@ libnm_settings_plugin_ifupdown_la_SOURCES = \ plugin.h libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version -libnm_settings_plugin_ifupdown_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - libifupdown-io.la \ - $(GLIB_LIBS) \ - $(GUDEV_LIBS) - +libnm_settings_plugin_ifupdown_la_LIBADD = libifupdown-io.la all: all-recursive .SUFFIXES: diff --git a/src/settings/plugins/ifupdown/interface_parser.c b/src/settings/plugins/ifupdown/interface_parser.c index ee233c93..32d27c57 100644 --- a/src/settings/plugins/ifupdown/interface_parser.c +++ b/src/settings/plugins/ifupdown/interface_parser.c @@ -21,6 +21,7 @@ */ #include "config.h" + #include "interface_parser.h" #include <stdio.h> #include <stdlib.h> diff --git a/src/settings/plugins/ifupdown/nm-ifupdown-connection.c b/src/settings/plugins/ifupdown/nm-ifupdown-connection.c index 4e13a2b8..c6073bd7 100644 --- a/src/settings/plugins/ifupdown/nm-ifupdown-connection.c +++ b/src/settings/plugins/ifupdown/nm-ifupdown-connection.c @@ -21,14 +21,15 @@ * (C) Copyright 2007,2008 Canonical Ltd. */ +#include "config.h" + #include <string.h> #include <glib/gstdio.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-utils.h> #include <nm-setting-wireless-security.h> #include <nm-settings-connection.h> #include <nm-system-config-interface.h> -#include <nm-settings-error.h> #include <nm-logging.h> #include "nm-ifupdown-connection.h" #include "parser.h" @@ -161,9 +162,8 @@ nm_ifupdown_connection_class_init (NMIfupdownConnectionClass *ifupdown_connectio /* Properties */ g_object_class_install_property (object_class, PROP_IFBLOCK, - g_param_spec_pointer (NM_IFUPDOWN_CONNECTION_IFBLOCK, - "ifblock", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_param_spec_pointer (NM_IFUPDOWN_CONNECTION_IFBLOCK, "", "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } diff --git a/src/settings/plugins/ifupdown/nm-ifupdown-connection.h b/src/settings/plugins/ifupdown/nm-ifupdown-connection.h index 447af78a..be2ebc0a 100644 --- a/src/settings/plugins/ifupdown/nm-ifupdown-connection.h +++ b/src/settings/plugins/ifupdown/nm-ifupdown-connection.h @@ -21,8 +21,8 @@ * (C) Copyright 2008 Canonical Ltd. */ -#ifndef NM_IFUPDOWN_CONNECTION_H -#define NM_IFUPDOWN_CONNECTION_H +#ifndef __NETWORKMANAGER_IFUPDOWN_CONNECTION_H__ +#define __NETWORKMANAGER_IFUPDOWN_CONNECTION_H__ #include <nm-settings-connection.h> #include "interface_parser.h" @@ -52,4 +52,4 @@ NMIfupdownConnection *nm_ifupdown_connection_new (if_block *block); G_END_DECLS -#endif /* NM_IFUPDOWN_CONNECTION_H */ +#endif /* __NETWORKMANAGER_IFUPDOWN_CONNECTION_H__ */ diff --git a/src/settings/plugins/ifupdown/parser.c b/src/settings/plugins/ifupdown/parser.c index 91ed3e21..15081a4c 100644 --- a/src/settings/plugins/ifupdown/parser.c +++ b/src/settings/plugins/ifupdown/parser.c @@ -21,24 +21,18 @@ * (C) Copyright 2008 Canonical Ltd. */ +#include "config.h" + #include <string.h> #include <arpa/inet.h> #include <stdlib.h> #include <errno.h> - -#include <nm-connection.h> -#include <NetworkManager.h> -#include <nm-setting-connection.h> -#include <nm-setting-ip4-config.h> -#include <nm-setting-ppp.h> -#include <nm-setting-wired.h> -#include <nm-setting-wireless.h> -#include <nm-setting-8021x.h> -#include <nm-system-config-interface.h> -#include <nm-utils.h> -#include <nm-logging.h> #include <ctype.h> +#include "nm-core-internal.h" +#include "nm-system-config-interface.h" +#include "nm-logging.h" + #include "parser.h" #include "plugin.h" @@ -417,19 +411,8 @@ update_wired_setting_from_if_block(NMConnection *connection, nm_connection_add_setting(connection, NM_SETTING(s_wired)); } -static GQuark -eni_plugin_error_quark() { - static GQuark error_quark = 0; - - if(!error_quark) { - error_quark = g_quark_from_static_string ("eni-plugin-error-quark"); - } - - return error_quark; -} - static void -ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns) +ifupdown_ip4_add_dns (NMSettingIPConfig *s_ip4, const char *dns) { guint32 addr; char **list, **iter; @@ -447,7 +430,7 @@ ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns) continue; } - if (!nm_setting_ip4_config_add_dns (s_ip4, addr)) + if (!nm_setting_ip_config_add_dns (s_ip4, *iter)) nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); @@ -459,15 +442,15 @@ update_ip4_setting_from_if_block(NMConnection *connection, GError **error) { - NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new()); + NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new()); const char *type = ifparser_getkey(block, "inet"); gboolean is_static = type && !strcmp("static", type); if (!is_static) { - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); } else { - guint32 tmp_addr, tmp_mask, tmp_gw; - NMIP4Address *addr; + guint32 tmp_mask; + NMIPAddress *addr; const char *address_v; const char *netmask_v; const char *gateway_v; @@ -479,10 +462,9 @@ update_ip4_setting_from_if_block(NMConnection *connection, /* Address */ address_v = ifparser_getkey (block, "address"); - if (!address_v || !inet_pton (AF_INET, address_v, &tmp_addr)) { - g_set_error (error, eni_plugin_error_quark (), 0, - "Missing IPv4 address '%s'", - address_v ? address_v : "(none)"); + if (!address_v) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IPv4 address"); goto error; } @@ -491,13 +473,8 @@ update_ip4_setting_from_if_block(NMConnection *connection, if (netmask_v) { if (strlen (netmask_v) < 7) { netmask_int = atoi (netmask_v); - if (netmask_int > 32) { - g_set_error (error, eni_plugin_error_quark (), 0, - "Invalid IPv4 netmask '%s'", netmask_v); - goto error; - } } else if (!inet_pton (AF_INET, netmask_v, &tmp_mask)) { - g_set_error (error, eni_plugin_error_quark (), 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IPv4 netmask '%s'", netmask_v); goto error; } else { @@ -505,29 +482,30 @@ update_ip4_setting_from_if_block(NMConnection *connection, } } - /* gateway */ - gateway_v = ifparser_getkey (block, "gateway"); - if (!gateway_v) - gateway_v = address_v; /* dcbw: whaaa?? */ - if (!inet_pton (AF_INET, gateway_v, &tmp_gw)) { - g_set_error (error, eni_plugin_error_quark (), 0, - "Invalid IPv4 gateway '%s'", gateway_v); - goto error; - } - /* Add the new address to the setting */ - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, tmp_addr); - nm_ip4_address_set_prefix (addr, netmask_int); - nm_ip4_address_set_gateway (addr, tmp_gw); + addr = nm_ip_address_new (AF_INET, address_v, netmask_int, error); + if (!addr) + goto error; - if (nm_setting_ip4_config_add_address (s_ip4, addr)) { + if (nm_setting_ip_config_add_address (s_ip4, addr)) { nm_log_info (LOGD_SETTINGS, "addresses count: %d", - nm_setting_ip4_config_get_num_addresses (s_ip4)); + nm_setting_ip_config_get_num_addresses (s_ip4)); } else { nm_log_info (LOGD_SETTINGS, "ignoring duplicate IP4 address"); } - nm_ip4_address_unref (addr); + nm_ip_address_unref (addr); + + /* gateway */ + gateway_v = ifparser_getkey (block, "gateway"); + if (gateway_v) { + if (!nm_utils_ipaddr_valid (AF_INET, gateway_v)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IPv4 gateway '%s'", gateway_v); + goto error; + } + if (!nm_setting_ip_config_get_gateway (s_ip4)) + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway_v, NULL); + } nameserver_v = ifparser_getkey (block, "dns-nameserver"); ifupdown_ip4_add_dns (s_ip4, nameserver_v); @@ -535,7 +513,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, nameservers_v = ifparser_getkey (block, "dns-nameservers"); ifupdown_ip4_add_dns (s_ip4, nameservers_v); - if (!nm_setting_ip4_config_get_num_dns (s_ip4)) + if (!nm_setting_ip_config_get_num_dns (s_ip4)) nm_log_info (LOGD_SETTINGS, "No dns-nameserver configured in /etc/network/interfaces"); /* DNS searches */ @@ -546,13 +524,13 @@ update_ip4_setting_from_if_block(NMConnection *connection, g_strstrip (*iter); if (g_ascii_isspace (*iter[0])) continue; - if (!nm_setting_ip4_config_add_dns_search (s_ip4, *iter)) + if (!nm_setting_ip_config_add_dns_search (s_ip4, *iter)) nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); } - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); } nm_connection_add_setting (connection, NM_SETTING (s_ip4)); @@ -564,7 +542,7 @@ error: } static void -ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns) +ifupdown_ip6_add_dns (NMSettingIPConfig *s_ip6, const char *dns) { struct in6_addr addr; char **list, **iter; @@ -582,7 +560,7 @@ ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns) continue; } - if (!nm_setting_ip6_config_add_dns (s_ip6, &addr)) + if (!nm_setting_ip_config_add_dns (s_ip6, *iter)) nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); @@ -593,16 +571,15 @@ update_ip6_setting_from_if_block(NMConnection *connection, if_block *block, GError **error) { - NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new()); + NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new()); const char *type = ifparser_getkey(block, "inet6"); gboolean is_static = type && (!strcmp("static", type) || !strcmp("v4tunnel", type)); if (!is_static) { - g_object_set(s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); } else { - struct in6_addr tmp_addr, tmp_gw; - NMIP6Address *addr; + NMIPAddress *addr; const char *address_v; const char *prefix_v; const char *gateway_v; @@ -614,10 +591,9 @@ update_ip6_setting_from_if_block(NMConnection *connection, /* Address */ address_v = ifparser_getkey(block, "address"); - if (!address_v || !inet_pton (AF_INET6, address_v, &tmp_addr)) { - g_set_error (error, eni_plugin_error_quark (), 0, - "Missing IPv6 address '%s'", - address_v ? address_v : "(none)"); + if (!address_v) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Missing IPv6 address"); goto error; } @@ -626,29 +602,30 @@ update_ip6_setting_from_if_block(NMConnection *connection, if (prefix_v) prefix_int = g_ascii_strtoll (prefix_v, NULL, 10); - /* Gateway */ - gateway_v = ifparser_getkey (block, "gateway"); - if (!gateway_v) - gateway_v = address_v; /* dcbw: whaaa?? */ - if (!inet_pton (AF_INET6, gateway_v, &tmp_gw)) { - g_set_error (error, eni_plugin_error_quark (), 0, - "Invalid IPv6 gateway '%s'", gateway_v); - goto error; - } - /* Add the new address to the setting */ - addr = nm_ip6_address_new (); - nm_ip6_address_set_address (addr, &tmp_addr); - nm_ip6_address_set_prefix (addr, prefix_int); - nm_ip6_address_set_gateway (addr, &tmp_gw); + addr = nm_ip_address_new (AF_INET6, address_v, prefix_int, error); + if (!addr) + goto error; - if (nm_setting_ip6_config_add_address (s_ip6, addr)) { + if (nm_setting_ip_config_add_address (s_ip6, addr)) { nm_log_info (LOGD_SETTINGS, "addresses count: %d", - nm_setting_ip6_config_get_num_addresses (s_ip6)); + nm_setting_ip_config_get_num_addresses (s_ip6)); } else { nm_log_info (LOGD_SETTINGS, "ignoring duplicate IP6 address"); } - nm_ip6_address_unref (addr); + nm_ip_address_unref (addr); + + /* gateway */ + gateway_v = ifparser_getkey (block, "gateway"); + if (gateway_v) { + if (!nm_utils_ipaddr_valid (AF_INET6, gateway_v)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Invalid IPv6 gateway '%s'", gateway_v); + goto error; + } + if (!nm_setting_ip_config_get_gateway (s_ip6)) + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, gateway_v, NULL); + } nameserver_v = ifparser_getkey(block, "dns-nameserver"); ifupdown_ip6_add_dns (s_ip6, nameserver_v); @@ -656,7 +633,7 @@ update_ip6_setting_from_if_block(NMConnection *connection, nameservers_v = ifparser_getkey(block, "dns-nameservers"); ifupdown_ip6_add_dns (s_ip6, nameservers_v); - if (!nm_setting_ip6_config_get_num_dns (s_ip6)) + if (!nm_setting_ip_config_get_num_dns (s_ip6)) nm_log_info (LOGD_SETTINGS, "No dns-nameserver configured in /etc/network/interfaces"); /* DNS searches */ @@ -667,14 +644,14 @@ update_ip6_setting_from_if_block(NMConnection *connection, g_strstrip (*iter); if (isblank (*iter[0])) continue; - if (!nm_setting_ip6_config_add_dns_search (s_ip6, *iter)) + if (!nm_setting_ip_config_add_dns_search (s_ip6, *iter)) nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); } g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); } @@ -709,7 +686,7 @@ ifupdown_update_connection_from_if_block (NMConnection *connection, idstr = g_strconcat ("Ifupdown (", block->name, ")", NULL); uuid_base = idstr; - uuid = nm_utils_uuid_generate_from_string (uuid_base); + uuid = nm_utils_uuid_generate_from_string (uuid_base, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, type, NM_SETTING_CONNECTION_INTERFACE_NAME, block->name, diff --git a/src/settings/plugins/ifupdown/plugin.c b/src/settings/plugins/ifupdown/plugin.c index dcae211c..1b5642af 100644 --- a/src/settings/plugins/ifupdown/plugin.c +++ b/src/settings/plugins/ifupdown/plugin.c @@ -22,11 +22,11 @@ * (C) Copyright 2009 - 2011 Red Hat, Inc. */ +#include "config.h" + #include <string.h> #include <sys/inotify.h> -#include <net/ethernet.h> -#include <netinet/ether.h> #include <gmodule.h> #include <glib-object.h> @@ -36,13 +36,14 @@ #include "interface_parser.h" -#include "NetworkManager.h" +#include "nm-dbus-interface.h" #include "nm-system-config-interface.h" #include "nm-setting-ip4-config.h" #include "nm-setting-wireless.h" #include "nm-setting-wired.h" #include "nm-setting-ppp.h" #include "nm-utils.h" +#include "nm-core-internal.h" #include "nm-ifupdown-connection.h" #include "plugin.h" @@ -186,7 +187,6 @@ bind_device_to_connection (SCPluginIfupdown *self, GUdevDevice *device, NMIfupdownConnection *exported) { - GByteArray *mac_address; NMSettingWired *s_wired; NMSettingWireless *s_wifi; const char *iface, *address; @@ -203,8 +203,7 @@ bind_device_to_connection (SCPluginIfupdown *self, return; } - mac_address = nm_utils_hwaddr_atoba (address, ARPHRD_ETHER); - if (!mac_address) { + if (!nm_utils_hwaddr_valid (address, ETH_ALEN)) { nm_log_warn (LOGD_SETTINGS, "failed to parse MAC address '%s' for %s", address, iface); return; @@ -214,12 +213,11 @@ bind_device_to_connection (SCPluginIfupdown *self, s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported)); if (s_wired) { nm_log_info (LOGD_SETTINGS, "locking wired connection setting"); - g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL); + g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, address, NULL); } else if (s_wifi) { nm_log_info (LOGD_SETTINGS, "locking wireless connection setting"); - g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL); + g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, address, NULL); } - g_byte_array_free (mac_address, TRUE); nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), NULL, NULL); } @@ -507,9 +505,7 @@ static GSList* SCPluginIfupdown_get_connections (NMSystemConfigInterface *config) { SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); - GSList *connections = NULL; - GHashTableIter iter; - gpointer value; + GSList *connections; nm_log_info (LOGD_SETTINGS, "(%d) ... get_connections.", GPOINTER_TO_UINT(config)); @@ -518,9 +514,7 @@ SCPluginIfupdown_get_connections (NMSystemConfigInterface *config) return NULL; } - g_hash_table_iter_init (&iter, priv->connections); - while (g_hash_table_iter_next (&iter, NULL, &value)) - connections = g_slist_prepend (connections, value); + connections = _nm_utils_hash_values_to_slist (priv->connections); nm_log_info (LOGD_SETTINGS, "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections)); return connections; diff --git a/src/settings/plugins/ifupdown/plugin.h b/src/settings/plugins/ifupdown/plugin.h index ed7732b8..943b8b9f 100644 --- a/src/settings/plugins/ifupdown/plugin.h +++ b/src/settings/plugins/ifupdown/plugin.h @@ -48,6 +48,4 @@ struct _SCPluginIfupdownClass { GType sc_plugin_ifupdown_get_type (void); -GQuark ifupdown_plugin_error_quark (void); - #endif /* _PLUGIN_H_ */ diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index 160b3327..24cdd955 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -2,19 +2,15 @@ if ENABLE_TESTS AM_CPPFLAGS = \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ - -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -DTEST_ENI_DIR=\"$(abs_srcdir)\" noinst_PROGRAMS = test-ifupdown @@ -25,17 +21,14 @@ test_ifupdown_SOURCES = \ ../parser.c test_ifupdown_LDADD = \ - $(top_builddir)/src/libNetworkManager.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(top_builddir)/libnm-util/libnm-util.la \ - $(DBUS_LIBS) + $(top_builddir)/src/libNetworkManager.la TESTS = test-ifupdown +endif + EXTRA_DIST = \ test1 test2 test3 test4 test5 test6 test7 test8 test9 test11 test12 \ test13 test14 test15 test16 test17-wired-static-verify-ip4 \ test18-wired-static-verify-ip6 test19-wired-static-verify-ip4-plen \ test20-source-stanza test20-source-stanza.eth0 test20-source-stanza.eth1 - -endif diff --git a/src/settings/plugins/ifupdown/tests/Makefile.in b/src/settings/plugins/ifupdown/tests/Makefile.in index 86afefe6..6dedec00 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.in +++ b/src/settings/plugins/ifupdown/tests/Makefile.in @@ -109,12 +109,8 @@ am__test_ifupdown_SOURCES_DIST = test-ifupdown.c ../interface_parser.c \ @ENABLE_TESTS_TRUE@am_test_ifupdown_OBJECTS = test-ifupdown.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ interface_parser.$(OBJEXT) parser.$(OBJEXT) test_ifupdown_OBJECTS = $(am_test_ifupdown_OBJECTS) -am__DEPENDENCIES_1 = @ENABLE_TESTS_TRUE@test_ifupdown_DEPENDENCIES = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-glib/libnm-glib.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ -@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) +@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent @@ -211,6 +207,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -334,6 +332,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -353,6 +352,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -379,7 +379,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -460,19 +460,15 @@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-glib \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/logging \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ @ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ @ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(POLKIT_CFLAGS) \ @ENABLE_TESTS_TRUE@ -DTEST_ENI_DIR=\"$(abs_srcdir)\" @ENABLE_TESTS_TRUE@test_ifupdown_SOURCES = \ @@ -481,16 +477,13 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@ ../parser.c @ENABLE_TESTS_TRUE@test_ifupdown_LDADD = \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-glib/libnm-glib.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ -@ENABLE_TESTS_TRUE@ $(DBUS_LIBS) - -@ENABLE_TESTS_TRUE@EXTRA_DIST = \ -@ENABLE_TESTS_TRUE@ test1 test2 test3 test4 test5 test6 test7 test8 test9 test11 test12 \ -@ENABLE_TESTS_TRUE@ test13 test14 test15 test16 test17-wired-static-verify-ip4 \ -@ENABLE_TESTS_TRUE@ test18-wired-static-verify-ip6 test19-wired-static-verify-ip4-plen \ -@ENABLE_TESTS_TRUE@ test20-source-stanza test20-source-stanza.eth0 test20-source-stanza.eth1 +@ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la + +EXTRA_DIST = \ + test1 test2 test3 test4 test5 test6 test7 test8 test9 test11 test12 \ + test13 test14 test15 test16 test17-wired-static-verify-ip4 \ + test18-wired-static-verify-ip6 test19-wired-static-verify-ip4-plen \ + test20-source-stanza test20-source-stanza.eth0 test20-source-stanza.eth1 all: all-am diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index 83864287..1c100ac2 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -18,11 +18,12 @@ * */ +#include "config.h" + #include <glib.h> #include <string.h> -#include <nm-utils.h> - +#include "nm-core-internal.h" #include "nm-logging.h" #include "interface_parser.h" #include "parser.h" @@ -460,20 +461,15 @@ test17_read_static_ipv4 (const char *path) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSettingWired *s_wired; char *unmanaged = NULL; GError *error = NULL; const char* tmp; - const char *expected_address = "10.0.0.3"; const char *expected_id = "Ifupdown (eth0)"; - const char *expected_dns1 = "10.0.0.1"; - const char *expected_dns2 = "10.0.0.2"; const char *expected_search1 = "example.com"; const char *expected_search2 = "foo.example.com"; - guint32 expected_prefix = 8; - NMIP4Address *ip4_addr; - guint32 addr; + NMIPAddress *ip4_addr; #define TEST17_NAME "wired-static-verify-ip4" if_block *block = NULL; @@ -481,7 +477,7 @@ test17_read_static_ipv4 (const char *path) init_ifparser_with_file (path, file); block = ifparser_getfirst (); - connection = nm_connection_new(); + connection = nm_simple_connection_new(); ifupdown_update_connection_from_if_block(connection, block, &error); ASSERT (connection != NULL, @@ -524,10 +520,6 @@ test17_read_static_ipv4 (const char *path) /* ===== IPv4 SETTING ===== */ - ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0, - TEST17_NAME, "failed to verify %s: couldn't convert IP address #1", - file); - s_ip4 = nm_connection_get_setting_ip4_config (connection); ASSERT (s_ip4 != NULL, TEST17_NAME, "failed to verify %s: missing %s setting", @@ -535,101 +527,81 @@ test17_read_static_ipv4 (const char *path) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* IP addresses */ - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); - - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - ASSERT (ip4_addr, - TEST17_NAME, "failed to verify %s: missing IP4 address #1", - file); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix, - TEST17_NAME, "failed to verify %s: unexpected IP4 address prefix", - file); + NM_SETTING_IP_CONFIG_ADDRESSES); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - TEST17_NAME, "failed to verify %s: unexpected IP4 address: %s", - file, addr); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "10.0.0.3"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8); /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0, - TEST17_NAME, "failed to verify %s: couldn't convert DNS IP address #1", - file, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr, + ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "10.0.0.1"), TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #1", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0, - TEST17_NAME, "failed to verify %s: couldn't convert DNS IP address #2", - file, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr, + ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "10.0.0.2"), TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #2", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* DNS search domains */ - ASSERT (nm_setting_ip4_config_get_num_dns_searches (s_ip4) == 2, + ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip4) == 2, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 0); + tmp = nm_setting_ip_config_get_dns_search (s_ip4, 0); ASSERT (tmp != NULL, TEST17_NAME, "failed to verify %s: missing %s / %s key", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, expected_search1) == 0, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); - tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 1); + tmp = nm_setting_ip_config_get_dns_search (s_ip4, 1); ASSERT (tmp != NULL, TEST17_NAME, "failed to verify %s: missing %s / %s key", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, expected_search2) == 0, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); g_object_unref (connection); } @@ -639,27 +611,22 @@ test18_read_static_ipv6 (const char *path) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip6; NMSettingWired *s_wired; char *unmanaged = NULL; GError *error = NULL; const char* tmp; - const char *expected_address = "fc00::1"; const char *expected_id = "Ifupdown (myip6tunnel)"; - const char *expected_dns1 = "fc00::2"; - const char *expected_dns2 = "fc00::3"; const char *expected_search1 = "example.com"; const char *expected_search2 = "foo.example.com"; - guint32 expected_prefix = 64; - NMIP6Address *ip6_addr; - struct in6_addr addr; + NMIPAddress *ip6_addr; if_block *block = NULL; #define TEST18_NAME "wired-static-verify-ip6" const char* file = "test18-" TEST18_NAME; init_ifparser_with_file (path, file); block = ifparser_getfirst (); - connection = nm_connection_new(); + connection = nm_simple_connection_new(); ifupdown_update_connection_from_if_block(connection, block, &error); ASSERT (connection != NULL, @@ -708,11 +675,6 @@ test18_read_static_ipv6 (const char *path) /* ===== IPv6 SETTING ===== */ - ASSERT (inet_pton (AF_INET6, expected_address, &addr) > 0, - TEST18_NAME, - "failed to verify %s: couldn't convert IP address #1", - file); - s_ip6 = nm_connection_get_setting_ip6_config (connection); ASSERT (s_ip6 != NULL, TEST18_NAME, @@ -721,115 +683,85 @@ test18_read_static_ipv6 (const char *path) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, TEST18_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* IP addresses */ - ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip6) == 1, TEST18_NAME, "failed to verify %s: unexpected number of %s / %s", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES); - - ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); - ASSERT (ip6_addr, - TEST18_NAME, - "failed to verify %s: missing %s / %s #1", - file, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); - ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix, - TEST18_NAME - "failed to verify %s: unexpected %s / %s prefix", - file, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES); - - ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), - &addr), - TEST18_NAME, - "failed to verify %s: unexpected %s / %s", - file, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES); + ip6_addr = nm_setting_ip_config_get_address (s_ip6, 0); + g_assert (ip6_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip6_addr), ==, "fc00::1"); + g_assert_cmpint (nm_ip_address_get_prefix (ip6_addr), ==, 64); /* DNS Addresses */ - ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 2, TEST18_NAME, "failed to verify %s: unexpected number of %s / %s values", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0, - TEST18_NAME, - "failed to verify %s: couldn't convert DNS IP address #1", - file); - - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), - &addr), + ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "fc00::2"), TEST18_NAME, "failed to verify %s: unexpected %s / %s #1", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); - - ASSERT (inet_pton (AF_INET6, expected_dns2, &addr) > 0, - TEST18_NAME, - "failed to verify %s: couldn't convert DNS IP address #2", - file); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), - &addr), + ASSERT (!strcmp (nm_setting_ip_config_get_dns (s_ip6, 1), "fc00::3"), TEST18_NAME, "failed to verify %s: unexpected %s / %s #2", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* DNS search domains */ - ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 2, + ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip6) == 2, TEST18_NAME, "failed to verify %s: unexpected number of %s / %s values", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); - tmp = nm_setting_ip6_config_get_dns_search (s_ip6, 0); + tmp = nm_setting_ip_config_get_dns_search (s_ip6, 0); ASSERT (tmp != NULL, "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing %s / %s #1", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, expected_search1) == 0, "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected %s / %s #1", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); - tmp = nm_setting_ip6_config_get_dns_search (s_ip6, 1); + tmp = nm_setting_ip_config_get_dns_search (s_ip6, 1); ASSERT (tmp != NULL, TEST18_NAME, "failed to verify %s: missing %s / %s #2", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); ASSERT (strcmp (tmp, expected_search2) == 0, TEST18_NAME, "failed to verify %s: unexpected %s / %s #2", file, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); g_free (unmanaged); g_object_unref (connection); @@ -839,13 +771,10 @@ static void test19_read_static_ipv4_plen (const char *path) { NMConnection *connection; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *unmanaged = NULL; GError *error = NULL; - const char *expected_address = "10.0.0.3"; - guint32 expected_prefix = 8; - NMIP4Address *ip4_addr; - guint32 addr; + NMIPAddress *ip4_addr; #define TEST19_NAME "wired-static-verify-ip4-plen" if_block *block = NULL; @@ -853,7 +782,7 @@ test19_read_static_ipv4_plen (const char *path) init_ifparser_with_file (path, file); block = ifparser_getfirst (); - connection = nm_connection_new(); + connection = nm_simple_connection_new(); ifupdown_update_connection_from_if_block(connection, block, &error); ASSERT (connection != NULL, @@ -867,10 +796,6 @@ test19_read_static_ipv4_plen (const char *path) /* ===== IPv4 SETTING ===== */ - ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0, - TEST19_NAME, "failed to verify %s: couldn't convert IP address #1", - file); - s_ip4 = nm_connection_get_setting_ip4_config (connection); ASSERT (s_ip4 != NULL, TEST19_NAME, "failed to verify %s: missing %s setting", @@ -878,24 +803,16 @@ test19_read_static_ipv4_plen (const char *path) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* IP addresses */ - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 1, TEST19_NAME, "failed to verify %s: unexpected %s / %s key value", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES); + NM_SETTING_IP_CONFIG_ADDRESSES); - ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); - ASSERT (ip4_addr, - TEST19_NAME, "failed to verify %s: missing IP4 address #1", - file); - - ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix, - TEST19_NAME, "failed to verify %s: unexpected IP4 address prefix", - file); - - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, - TEST19_NAME, "failed to verify %s: unexpected IP4 address: %s", - file, addr); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr != NULL); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "10.0.0.3"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 8); g_object_unref (connection); } @@ -930,14 +847,10 @@ test20_source_stanza (const char *path) int main (int argc, char **argv) { - GError *error = NULL; - #if !GLIB_CHECK_VERSION (2, 35, 0) g_type_init (); #endif - if (!nm_utils_init (&error)) - FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message); nm_logging_setup ("WARN", "DEFAULT", NULL, NULL); g_test_init (&argc, &argv, NULL); diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index cac97e7f..079c45c3 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -4,18 +4,15 @@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" noinst_LTLIBRARIES = \ @@ -29,7 +26,6 @@ libkeyfile_io_la_SOURCES = \ reader.h \ writer.c \ writer.h \ - errors.c \ utils.c \ utils.h \ common.h @@ -45,12 +41,7 @@ libnm_settings_plugin_keyfile_la_SOURCES = \ plugin.h libnm_settings_plugin_keyfile_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - libkeyfile-io.la \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) - -libnm_settings_plugin_keyfile_la_LDFLAGS = -rdynamic + libkeyfile-io.la keyfiledir=$(sysconfdir)/NetworkManager/system-connections diff --git a/src/settings/plugins/keyfile/Makefile.in b/src/settings/plugins/keyfile/Makefile.in index 8c4d6101..8c0d11af 100644 --- a/src/settings/plugins/keyfile/Makefile.in +++ b/src/settings/plugins/keyfile/Makefile.in @@ -104,23 +104,17 @@ CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) am__DEPENDENCIES_1 = libkeyfile_io_la_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_libkeyfile_io_la_OBJECTS = reader.lo writer.lo errors.lo utils.lo +am_libkeyfile_io_la_OBJECTS = reader.lo writer.lo utils.lo libkeyfile_io_la_OBJECTS = $(am_libkeyfile_io_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -libnm_settings_plugin_keyfile_la_DEPENDENCIES = \ - $(top_builddir)/libnm-util/libnm-util.la libkeyfile-io.la \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +libnm_settings_plugin_keyfile_la_DEPENDENCIES = libkeyfile-io.la am_libnm_settings_plugin_keyfile_la_OBJECTS = \ nm-keyfile-connection.lo plugin.lo libnm_settings_plugin_keyfile_la_OBJECTS = \ $(am_libnm_settings_plugin_keyfile_la_OBJECTS) -libnm_settings_plugin_keyfile_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ - $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ - $(AM_CFLAGS) $(CFLAGS) \ - $(libnm_settings_plugin_keyfile_la_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -235,6 +229,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -358,6 +354,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -377,6 +374,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -403,7 +401,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -485,18 +483,15 @@ with_valgrind = @with_valgrind@ SUBDIRS = . tests AM_CPPFLAGS = \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/config \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" noinst_LTLIBRARIES = \ @@ -510,7 +505,6 @@ libkeyfile_io_la_SOURCES = \ reader.h \ writer.c \ writer.h \ - errors.c \ utils.c \ utils.h \ common.h @@ -525,12 +519,8 @@ libnm_settings_plugin_keyfile_la_SOURCES = \ plugin.h libnm_settings_plugin_keyfile_la_LIBADD = \ - $(top_builddir)/libnm-util/libnm-util.la \ - libkeyfile-io.la \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) + libkeyfile-io.la -libnm_settings_plugin_keyfile_la_LDFLAGS = -rdynamic keyfiledir = $(sysconfdir)/NetworkManager/system-connections all: all-recursive @@ -582,7 +572,7 @@ libkeyfile-io.la: $(libkeyfile_io_la_OBJECTS) $(libkeyfile_io_la_DEPENDENCIES) $ $(AM_V_CCLD)$(LINK) $(libkeyfile_io_la_OBJECTS) $(libkeyfile_io_la_LIBADD) $(LIBS) libnm-settings-plugin-keyfile.la: $(libnm_settings_plugin_keyfile_la_OBJECTS) $(libnm_settings_plugin_keyfile_la_DEPENDENCIES) $(EXTRA_libnm_settings_plugin_keyfile_la_DEPENDENCIES) - $(AM_V_CCLD)$(libnm_settings_plugin_keyfile_la_LINK) $(libnm_settings_plugin_keyfile_la_OBJECTS) $(libnm_settings_plugin_keyfile_la_LIBADD) $(LIBS) + $(AM_V_CCLD)$(LINK) $(libnm_settings_plugin_keyfile_la_OBJECTS) $(libnm_settings_plugin_keyfile_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -590,7 +580,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-keyfile-connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Plo@am__quote@ diff --git a/src/settings/plugins/keyfile/common.h b/src/settings/plugins/keyfile/common.h index 4faa5a84..db6569e5 100644 --- a/src/settings/plugins/keyfile/common.h +++ b/src/settings/plugins/keyfile/common.h @@ -30,8 +30,5 @@ #define VPN_SECRETS_GROUP "vpn-secrets" -#define KEYFILE_PLUGIN_ERROR (keyfile_plugin_error_quark ()) -GQuark keyfile_plugin_error_quark (void); - #endif /* __COMMON_H__ */ diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.c b/src/settings/plugins/keyfile/nm-keyfile-connection.c index 4ef761c6..c852f028 100644 --- a/src/settings/plugins/keyfile/nm-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nm-keyfile-connection.c @@ -19,9 +19,11 @@ * Copyright (C) 2008 - 2012 Red Hat, Inc. */ +#include "config.h" + #include <string.h> #include <glib/gstdio.h> -#include <NetworkManager.h> +#include <nm-dbus-interface.h> #include <nm-setting-connection.h> #include <nm-utils.h> @@ -63,7 +65,7 @@ nm_keyfile_connection_new (NMConnection *source, uuid = nm_connection_get_uuid (NM_CONNECTION (tmp)); if (!uuid) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Connection in file %s had no UUID", full_path); g_object_unref (tmp); return NULL; @@ -166,11 +168,7 @@ nm_keyfile_connection_init (NMKeyfileConnection *connection) static void finalize (GObject *object) { - NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (object); - - nm_connection_clear_secrets (NM_CONNECTION (object)); - - g_free (priv->path); + g_free (NM_KEYFILE_CONNECTION_GET_PRIVATE (object)->path); G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->finalize (object); } @@ -184,7 +182,7 @@ nm_keyfile_connection_class_init (NMKeyfileConnectionClass *keyfile_connection_c g_type_class_add_private (keyfile_connection_class, sizeof (NMKeyfileConnectionPrivate)); /* Virtual methods */ - object_class->finalize = finalize; + object_class->finalize = finalize; settings_class->commit_changes = commit_changes; settings_class->delete = do_delete; } diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.h b/src/settings/plugins/keyfile/nm-keyfile-connection.h index 07dcafcb..135bb49f 100644 --- a/src/settings/plugins/keyfile/nm-keyfile-connection.h +++ b/src/settings/plugins/keyfile/nm-keyfile-connection.h @@ -19,8 +19,8 @@ * Copyright (C) 2008 - 2012 Red Hat, Inc. */ -#ifndef NM_KEYFILE_CONNECTION_H -#define NM_KEYFILE_CONNECTION_H +#ifndef __NETWORKMANAGER_KEYFILE_CONNECTION_H__ +#define __NETWORKMANAGER_KEYFILE_CONNECTION_H__ #include <nm-settings-connection.h> @@ -52,4 +52,4 @@ void nm_keyfile_connection_set_path (NMKeyfileConnection *self, const cha G_END_DECLS -#endif /* NM_KEYFILE_CONNECTION_H */ +#endif /* __NETWORKMANAGER_KEYFILE_CONNECTION_H__ */ diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c index 10c83971..371fa47a 100644 --- a/src/settings/plugins/keyfile/plugin.c +++ b/src/settings/plugins/keyfile/plugin.c @@ -19,11 +19,11 @@ * Copyright (C) 2008 - 2013 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <sys/stat.h> #include <unistd.h> #include <sys/types.h> -#include <netinet/ether.h> #include <string.h> #include <gmodule.h> @@ -37,6 +37,7 @@ #include <nm-utils.h> #include <nm-config.h> #include <nm-logging.h> +#include "nm-core-internal.h" #include "plugin.h" #include "nm-system-config-interface.h" @@ -373,20 +374,13 @@ static GSList * get_connections (NMSystemConfigInterface *config) { SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config); - GHashTableIter iter; - gpointer data = NULL; - GSList *list = NULL; if (!priv->initialized) { setup_monitoring (config); read_connections (config); priv->initialized = TRUE; } - - g_hash_table_iter_init (&iter, priv->connections); - while (g_hash_table_iter_next (&iter, NULL, &data)) - list = g_slist_prepend (list, data); - return list; + return _nm_utils_hash_values_to_slist (priv->connections); } static gboolean @@ -496,12 +490,12 @@ get_unmanaged_specs (NMSystemConfigInterface *config) char **udis; int i; - udis = g_strsplit (str, ";", -1); + udis = g_strsplit_set (str, ";,", -1); g_free (str); for (i = 0; udis[i] != NULL; i++) { /* Verify unmanaged specification and add it to the list */ - if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4)) { + if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4, -1)) { specs = g_slist_append (specs, udis[i]); } else if (!strncmp (udis[i], "interface-name:", 15) && nm_utils_iface_valid_name (udis[i] + 15)) { specs = g_slist_append (specs, udis[i]); diff --git a/src/settings/plugins/keyfile/plugin.h b/src/settings/plugins/keyfile/plugin.h index 5f437390..48579785 100644 --- a/src/settings/plugins/keyfile/plugin.h +++ b/src/settings/plugins/keyfile/plugin.h @@ -41,8 +41,6 @@ typedef struct { GType sc_plugin_keyfile_get_type (void); -GQuark keyfile_plugin_error_quark (void); - GObject *nm_settings_keyfile_plugin_new (void); #endif /* _PLUGIN_H_ */ diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c index 735f8c28..1d2ecdad 100644 --- a/src/settings/plugins/keyfile/reader.c +++ b/src/settings/plugins/keyfile/reader.c @@ -19,27 +19,17 @@ * Copyright (C) 2008 - 2011 Red Hat, Inc. */ +#include "config.h" + #include <errno.h> #include <stdlib.h> #include <sys/stat.h> #include <unistd.h> #include <sys/types.h> -#include <dbus/dbus-glib.h> -#include <nm-setting.h> -#include <nm-setting-ip4-config.h> -#include <nm-setting-ip6-config.h> -#include <nm-setting-vpn.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-wireless.h> -#include <nm-setting-bluetooth.h> -#include <nm-setting-8021x.h> -#include <nm-utils.h> #include <arpa/inet.h> -#include <netinet/ether.h> -#include <linux/if_infiniband.h> #include <string.h> +#include "nm-core-internal.h" #include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-system-config-interface.h" @@ -47,6 +37,8 @@ #include "reader.h" #include "common.h" #include "utils.h" +#include "nm-core-internal.h" +#include "NetworkManagerUtils.h" /* Some setting properties also contain setting names, such as * NMSettingConnection's 'type' property (which specifies the base type of the @@ -119,135 +111,77 @@ get_one_int (const char *str, guint32 max_val, const char *key_name, guint32 *ou } static gpointer -build_ip4_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route) +build_address (int family, const char *address_str, guint32 plen) { - GArray *result; - guint32 addr; - guint32 address = 0; - guint32 gateway = 0; - guint32 metric = 0; - int err; + NMIPAddress *addr; + GError *error = NULL; g_return_val_if_fail (address_str, NULL); - /* Address */ - err = inet_pton (AF_INET, address_str, &addr); - if (err <= 0) { - nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv4 address '%s'", __func__, address_str); - return NULL; - } - address = addr; - - /* Gateway */ - if (gateway_str && gateway_str[0]) { - err = inet_pton (AF_INET, gateway_str, &addr); - if (err <= 0) { - nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv4 gateway '%s'", __func__, gateway_str); - return NULL; - } - gateway = addr; - } - else - gateway = 0; - - /* parse metric, default to 0 */ - if (metric_str) { - if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric)) - return NULL; + addr = nm_ip_address_new (family, address_str, plen, &error); + if (!addr) { + nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid %s address: %s", __func__, + family == AF_INET ? "IPv4" : "IPv6", + error->message); + g_error_free (error); } - result = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3 + !!route); - g_array_append_val (result, address); - g_array_append_val (result, plen); - g_array_append_val (result, gateway); - if (route) - g_array_append_val (result, metric); - - return result; + return addr; } static gpointer -build_ip6_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route) +build_route (int family, + const char *dest_str, guint32 plen, + const char *gateway_str, const char *metric_str, + const char *key_name) { - GValueArray *result; - struct in6_addr addr; - GByteArray *address; - GByteArray *gateway; + NMIPRoute *route; guint32 metric = 0; - GValue value = G_VALUE_INIT; - int err; - - g_return_val_if_fail (address_str, NULL); + GError *error = NULL; - result = g_value_array_new (3); + g_return_val_if_fail (plen, NULL); + g_return_val_if_fail (dest_str, NULL); - /* add address */ - err = inet_pton (AF_INET6, address_str, &addr); - if (err <= 0) { - nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 address '%s'", __func__, address_str); - goto error_out; - } - address = g_byte_array_new (); - g_byte_array_append (address, (guint8 *) addr.s6_addr, 16); - g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY); - g_value_take_boxed (&value, address); - g_value_array_append (result, &value); - g_value_unset (&value); - - /* add prefix length */ - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, plen); - g_value_array_append (result, &value); - g_value_unset (&value); - - /* add gateway */ + /* Next hop */ if (gateway_str && gateway_str[0]) { - err = inet_pton (AF_INET6, gateway_str, &addr); - if (err <= 0) { + if (!nm_utils_ipaddr_valid (family, gateway_str)) { /* Try workaround for routes written by broken keyfile writer. * Due to bug bgo#719851, an older version of writer would have * written "a:b:c:d::/plen,metric" if the gateway was ::, instead * of "a:b:c:d::/plen,,metric" or "a:b:c:d::/plen,::,metric" - * Try workaround by interepeting gateway_str as metric to accept such + * Try workaround by interpreting gateway_str as metric to accept such * invalid routes. This broken syntax should not be not officially * supported. **/ - if (route && !metric_str && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric)) - addr = in6addr_any; + if ( family == AF_INET6 + && !metric_str + && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric)) + gateway_str = NULL; else { - nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str); - goto error_out; + nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid gateway '%s'", __func__, gateway_str); + return NULL; } } } else - addr = in6addr_any; + gateway_str = NULL; /* parse metric, default to 0 */ if (metric_str) { if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric)) - goto error_out; + return NULL; } - gateway = g_byte_array_new (); - g_byte_array_append (gateway, (guint8 *) addr.s6_addr, 16); - g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY); - g_value_take_boxed (&value, gateway); - g_value_array_append (result, &value); - g_value_unset (&value); - - /* add metric (for routing) */ - if (route) { - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, metric); - g_value_array_append (result, &value); - g_value_unset (&value); + route = nm_ip_route_new (family, dest_str, plen, gateway_str, + metric ? (gint64) metric : -1, + &error); + if (!route) { + nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid %s route: %s", __func__, + family == AF_INET ? "IPv4" : "IPv6", + error->message); + g_error_free (error); } - return result; - -error_out: - g_value_array_free (result); - return NULL; + return route; } /* On success, returns pointer to the zero-terminated field (original @current). @@ -334,17 +268,16 @@ read_field (char **current, char **error, const char *characters, const char *de * changed. The default for IPv4 is now 24, which is the closest * IPv4 equivalent. These defaults may just as well be changed to * match the iproute2 defaults (32 for IPv4 and 128 for IPv6). - * - * The returned result is GArray for IPv4 and GValueArray for IPv6. */ static gpointer read_one_ip_address_or_route (GKeyFile *file, - const char *setting_name, - const char *key_name, - gboolean ipv6, - gboolean route) + const char *setting_name, + const char *key_name, + gboolean ipv6, + gboolean route, + char **out_gateway) { - guint32 plen; + guint32 plen = G_MAXUINT32; gpointer result; char *address_str, *plen_str, *gateway_str, *metric_str, *value, *current, *error; @@ -394,22 +327,33 @@ read_one_ip_address_or_route (GKeyFile *file, } } +#define DEFAULT_PREFIX(for_route, for_ipv6) ( (for_route) ? ( (for_ipv6) ? 128 : 24 ) : ( (for_ipv6) ? 64 : 24 ) ) + /* parse plen, fallback to defaults */ - if (plen_str) - g_return_val_if_fail (get_one_int (plen_str, ipv6 ? 128 : 32, - key_name, &plen), NULL); - else { - if (route) - plen = ipv6 ? 128 : 24; - else - plen = ipv6 ? 64 : 24; + if (plen_str) { + if (!get_one_int (plen_str, ipv6 ? 128 : 32, key_name, &plen) + || (route && plen == 0)) { + plen = DEFAULT_PREFIX (route, ipv6); + nm_log_warn (LOGD_SETTINGS, "keyfile: invalid prefix length '%s' in '%s.%s', defaulting to %d", + plen_str, setting_name, key_name, plen); + } + } else { + plen = DEFAULT_PREFIX (route, ipv6); nm_log_warn (LOGD_SETTINGS, "keyfile: Missing prefix length in '%s.%s', defaulting to %d", setting_name, key_name, plen); } /* build the appropriate data structure for NetworkManager settings */ - result = (ipv6 ? build_ip6_address_or_route : build_ip4_address_or_route) ( - key_name, address_str, plen, gateway_str, metric_str, route); + if (route) { + result = build_route (ipv6 ? AF_INET6 : AF_INET, + address_str, plen, gateway_str, metric_str, + key_name); + } else { + result = build_address (ipv6 ? AF_INET6 : AF_INET, + address_str, plen); + if (out_gateway && gateway_str) + *out_gateway = g_strdup (gateway_str); + } g_free (value); return result; @@ -427,13 +371,16 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi static const char *key_names_routes[] = { "route", "routes", NULL }; static const char *key_names_addresses[] = { "address", "addresses", NULL }; const char **key_names = routes ? key_names_routes : key_names_addresses; + char *gateway = NULL; GPtrArray *list; + GDestroyNotify free_func; int i; - G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - list = g_ptr_array_new_with_free_func ( - ipv6 ? (GDestroyNotify) g_value_array_free : (GDestroyNotify) g_array_unref); - G_GNUC_END_IGNORE_DEPRECATIONS; + if (routes) + free_func = (GDestroyNotify) nm_ip_route_unref; + else + free_func = (GDestroyNotify) nm_ip_address_unref; + list = g_ptr_array_new_with_free_func (free_func); for (i = -1; i < 1000; i++) { const char **key_basename; @@ -448,8 +395,8 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi else key_name = g_strdup (*key_basename); - item = read_one_ip_address_or_route (keyfile, setting_name, key_name, ipv6, routes); - + item = read_one_ip_address_or_route (keyfile, setting_name, key_name, ipv6, routes, + gateway ? NULL : &gateway); if (item) g_ptr_array_add (list, item); @@ -460,6 +407,11 @@ ip_address_or_route_parser (NMSetting *setting, const char *key, GKeyFile *keyfi if (list->len >= 1) g_object_set (setting, key, list, NULL); + if (gateway) { + g_object_set (setting, "gateway", gateway, NULL); + g_free (gateway); + } + g_ptr_array_unref (list); } @@ -467,7 +419,7 @@ static void ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path) { const char *setting_name = nm_setting_get_name (setting); - GArray *array = NULL; + GPtrArray *array; gsize length; char **list, **iter; int ret; @@ -476,7 +428,7 @@ ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch if (!list || !g_strv_length (list)) return; - array = g_array_sized_new (FALSE, FALSE, sizeof (guint32), length); + array = g_ptr_array_sized_new (length + 1); for (iter = list; *iter; iter++) { guint32 addr; @@ -486,14 +438,13 @@ ip4_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch continue; } - g_array_append_val (array, addr); + g_ptr_array_add (array, *iter); } - g_strfreev (list); + g_ptr_array_add (array, NULL); - if (array) { - g_object_set (setting, key, array, NULL); - g_array_unref (array); - } + g_object_set (setting, key, array->pdata, NULL); + g_ptr_array_unref (array); + g_strfreev (list); } static void @@ -509,10 +460,9 @@ ip6_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch if (!list || !g_strv_length (list)) return; - array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_byte_array_unref); + array = g_ptr_array_sized_new (length + 1); for (iter = list; *iter; iter++) { - GByteArray *byte_array; struct in6_addr addr; ret = inet_pton (AF_INET6, *iter, &addr); @@ -520,24 +470,21 @@ ip6_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const ch nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid DNS server IPv6 address '%s'", __func__, *iter); continue; } - byte_array = g_byte_array_new (); - g_byte_array_append (byte_array, (guint8 *) addr.s6_addr, 16); - g_ptr_array_add (array, byte_array); + g_ptr_array_add (array, *iter); } - g_strfreev (list); + g_ptr_array_add (array, NULL); - if (array) { - g_object_set (setting, key, array, NULL); - g_ptr_array_unref (array); - } + g_object_set (setting, key, array->pdata, NULL); + g_ptr_array_unref (array); + g_strfreev (list); } static void mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path, gsize enforce_length) { const char *setting_name = nm_setting_get_name (setting); - char *tmp_string = NULL, *p; + char *tmp_string = NULL, *p, *mac_str; gint *tmp_list; GByteArray *array = NULL; gsize length; @@ -557,7 +504,7 @@ mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, cons /* If we found enough it's probably a string-format MAC address */ array = g_byte_array_sized_new (i+1); g_byte_array_set_size (array, i+1); - if (!nm_utils_hwaddr_aton_len (tmp_string, array->data, array->len)) { + if (!nm_utils_hwaddr_aton (tmp_string, array->data, array->len)) { g_byte_array_unref (array); array = NULL; } @@ -590,13 +537,16 @@ mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, cons g_free (tmp_list); } - if (array) { - g_object_set (setting, key, array, NULL); - g_byte_array_free (array, TRUE); - } else { + if (!array) { nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid MAC address for %s / %s", __func__, setting_name, key); + return; } + + mac_str = nm_utils_hwaddr_ntoa (array->data, array->len); + g_object_set (setting, key, mac_str, NULL); + g_free (mac_str); + g_byte_array_free (array, TRUE); } static void @@ -628,11 +578,12 @@ read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key) continue; if (NM_IS_SETTING_VPN (setting)) { - if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE) && strcmp (*iter, NM_SETTING_VPN_USER_NAME)) + /* Add any item that's not a class property to the data hash */ + if (!g_object_class_find_property (G_OBJECT_GET_CLASS (setting), *iter)) nm_setting_vpn_add_data_item (NM_SETTING_VPN (setting), *iter, value); } if (NM_IS_SETTING_BOND (setting)) { - if (strcmp (*iter, NM_SETTING_BOND_INTERFACE_NAME)) + if (strcmp (*iter, "interface-name")) nm_setting_bond_add_option (NM_SETTING_BOND (setting), *iter, value); } g_free (value); @@ -655,12 +606,12 @@ unescape_semicolons (char *str) } } -static GByteArray * -get_uchar_array (GKeyFile *keyfile, - const char *setting_name, - const char *key, - gboolean zero_terminate, - gboolean unescape_semicolon) +static GBytes * +get_bytes (GKeyFile *keyfile, + const char *setting_name, + const char *key, + gboolean zero_terminate, + gboolean unescape_semicolon) { GByteArray *array = NULL; char *tmp_string; @@ -714,21 +665,21 @@ get_uchar_array (GKeyFile *keyfile, if (array->len == 0) { g_byte_array_free (array, TRUE); - array = NULL; - } - return array; + return NULL; + } else + return g_byte_array_free_to_bytes (array); } static void ssid_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path) { const char *setting_name = nm_setting_get_name (setting); - GByteArray *array; + GBytes *bytes; - array = get_uchar_array (keyfile, setting_name, key, FALSE, TRUE); - if (array) { - g_object_set (setting, key, array, NULL); - g_byte_array_free (array, TRUE); + bytes = get_bytes (keyfile, setting_name, key, FALSE, TRUE); + if (bytes) { + g_object_set (setting, key, bytes, NULL); + g_bytes_unref (bytes); } else { nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid SSID for %s / %s", __func__, setting_name, key); @@ -739,12 +690,12 @@ static void password_raw_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path) { const char *setting_name = nm_setting_get_name (setting); - GByteArray *array; + GBytes *bytes; - array = get_uchar_array (keyfile, setting_name, key, FALSE, TRUE); - if (array) { - g_object_set (setting, key, array, NULL); - g_byte_array_free (array, TRUE); + bytes = get_bytes (keyfile, setting_name, key, FALSE, TRUE); + if (bytes) { + g_object_set (setting, key, bytes, NULL); + g_bytes_unref (bytes); } else { nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid raw password for %s / %s", __func__, setting_name, key); @@ -752,7 +703,7 @@ password_raw_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, con } static char * -get_cert_path (const char *keyfile_path, GByteArray *cert_path) +get_cert_path (const char *keyfile_path, const guint8 *cert_path, gsize cert_path_len) { const char *base; char *p = NULL, *path, *dirname, *tmp; @@ -760,8 +711,8 @@ get_cert_path (const char *keyfile_path, GByteArray *cert_path) g_return_val_if_fail (keyfile_path != NULL, NULL); g_return_val_if_fail (cert_path != NULL, NULL); - base = path = g_malloc0 (cert_path->len + 1); - memcpy (path, cert_path->data, cert_path->len); + base = path = g_malloc0 (cert_path_len + 1); + memcpy (path, cert_path, cert_path_len); if (path[0] == '/') return path; @@ -794,37 +745,46 @@ has_cert_ext (const char *path) } static gboolean -handle_as_scheme (GByteArray *array, NMSetting *setting, const char *key) +handle_as_scheme (GBytes *bytes, NMSetting *setting, const char *key) { + const guint8 *data; + gsize data_len; + + data = g_bytes_get_data (bytes, &data_len); + /* It's the PATH scheme, can just set plain data */ - if ( (array->len > strlen (SCHEME_PATH)) - && g_str_has_prefix ((const char *) array->data, SCHEME_PATH) - && (array->data[array->len - 1] == '\0')) { - g_object_set (setting, key, array, NULL); + if ( (data_len > strlen (SCHEME_PATH)) + && g_str_has_prefix ((const char *) data, SCHEME_PATH) + && (data[data_len - 1] == '\0')) { + g_object_set (setting, key, bytes, NULL); return TRUE; } return FALSE; } static gboolean -handle_as_path (GByteArray *array, +handle_as_path (GBytes *bytes, NMSetting *setting, const char *key, const char *keyfile_path) { - gsize validate_len = array->len; - GByteArray *val; + const guint8 *data; + gsize data_len; + gsize validate_len; char *path; gboolean exists, success = FALSE; - if (array->len > 500 || array->len < 1) + data = g_bytes_get_data (bytes, &data_len); + if (data_len > 500 || data_len < 1) return FALSE; /* If there's a trailing NULL tell g_utf8_validate() to to until the NULL */ - if (array->data[array->len - 1] == '\0') + if (data[data_len - 1] == '\0') validate_len = -1; + else + validate_len = data_len; - if (g_utf8_validate ((const char *) array->data, validate_len, NULL) == FALSE) + if (g_utf8_validate ((const char *) data, validate_len, NULL) == FALSE) return FALSE; /* Might be a bare path without the file:// prefix; in that case @@ -832,18 +792,22 @@ handle_as_path (GByteArray *array, * relative path to the current directory. */ - path = get_cert_path (keyfile_path, array); + path = get_cert_path (keyfile_path, data, data_len); exists = g_file_test (path, G_FILE_TEST_EXISTS); if ( exists - || memchr (array->data, '/', array->len) + || memchr (data, '/', data_len) || has_cert_ext (path)) { + GByteArray *tmp; + GBytes *val; + /* Construct the proper value as required for the PATH scheme */ - val = g_byte_array_sized_new (strlen (SCHEME_PATH) + strlen (path) + 1); - g_byte_array_append (val, (const guint8 *) SCHEME_PATH, strlen (SCHEME_PATH)); - g_byte_array_append (val, (const guint8 *) path, strlen (path)); - g_byte_array_append (val, (const guint8 *) "\0", 1); + tmp = g_byte_array_sized_new (strlen (SCHEME_PATH) + strlen (path) + 1); + g_byte_array_append (tmp, (const guint8 *) SCHEME_PATH, strlen (SCHEME_PATH)); + g_byte_array_append (tmp, (const guint8 *) path, strlen (path)); + g_byte_array_append (tmp, (const guint8 *) "\0", 1); + val = g_byte_array_free_to_bytes (tmp); g_object_set (setting, key, val, NULL); - g_byte_array_free (val, TRUE); + g_bytes_unref (val); success = TRUE; /* Warn if the certificate didn't exist */ @@ -859,28 +823,78 @@ static void cert_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path) { const char *setting_name = nm_setting_get_name (setting); - GByteArray *array; + GBytes *bytes; gboolean success = FALSE; - array = get_uchar_array (keyfile, setting_name, key, TRUE, FALSE); - if (array && array->len > 0) { + bytes = get_bytes (keyfile, setting_name, key, TRUE, FALSE); + if (bytes) { /* Try as a path + scheme (ie, starts with "file://") */ - success = handle_as_scheme (array, setting, key); + success = handle_as_scheme (bytes, setting, key); /* If not, it might be a plain path */ if (success == FALSE) - success = handle_as_path (array, setting, key, keyfile_path); + success = handle_as_path (bytes, setting, key, keyfile_path); /* If neither of those two, assume blob with certificate data */ if (success == FALSE) - g_object_set (setting, key, array, NULL); + g_object_set (setting, key, bytes, NULL); } else { nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid key/cert value for %s / %s", __func__, setting_name, key); } - if (array) - g_byte_array_free (array, TRUE); + if (bytes) + g_bytes_unref (bytes); +} + +static void +parity_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path) +{ + const char *setting_name = nm_setting_get_name (setting); + NMSettingSerialParity parity; + int int_val; + char *str_val; + + /* Keyfile traditionally stored this as the ASCII value for 'E', 'o', or 'n'. + * We now accept either that or the (case-insensitive) character itself (but + * still always write it the old way, for backward compatibility). + */ + int_val = nm_keyfile_plugin_kf_get_integer (keyfile, setting_name, key, NULL); + if (!int_val) { + str_val = nm_keyfile_plugin_kf_get_string (keyfile, setting_name, key, NULL); + if (str_val) { + if (str_val[0] && !str_val[1]) + int_val = str_val[0]; + else { + /* This will hit the warning below */ + int_val = 'X'; + } + } + } + + if (!int_val) + return; + + switch (int_val) { + case 'E': + case 'e': + parity = NM_SETTING_SERIAL_PARITY_EVEN; + break; + case 'O': + case 'o': + parity = NM_SETTING_SERIAL_PARITY_ODD; + break; + case 'N': + case 'n': + parity = NM_SETTING_SERIAL_PARITY_NONE; + break; + default: + nm_log_warn (LOGD_SETTINGS, "%s: ignoring invalid value for %s / %s", + __func__, setting_name, key); + return; + } + + g_object_set (setting, key, parity, NULL); } typedef struct { @@ -906,27 +920,27 @@ static KeyParser key_parsers[] = { TRUE, mac_address_parser_ETHER }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES, + NM_SETTING_IP_CONFIG_ADDRESSES, FALSE, ip_address_or_route_parser }, { NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES, + NM_SETTING_IP_CONFIG_ADDRESSES, FALSE, ip_address_or_route_parser }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES, + NM_SETTING_IP_CONFIG_ROUTES, FALSE, ip_address_or_route_parser }, { NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ROUTES, + NM_SETTING_IP_CONFIG_ROUTES, FALSE, ip_address_or_route_parser }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS, + NM_SETTING_IP_CONFIG_DNS, FALSE, ip4_dns_parser }, { NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS, + NM_SETTING_IP_CONFIG_DNS, FALSE, ip6_dns_parser }, { NM_SETTING_WIRED_SETTING_NAME, @@ -993,6 +1007,10 @@ static KeyParser key_parsers[] = { NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, TRUE, cert_parser }, + { NM_SETTING_SERIAL_SETTING_NAME, + NM_SETTING_SERIAL_PARITY, + TRUE, + parity_parser }, { NULL, NULL, FALSE } }; @@ -1010,6 +1028,7 @@ read_one_setting_value (NMSetting *setting, { ReadInfo *info = user_data; const char *setting_name; + int errsv; GType type; GError *err = NULL; gboolean check_for_key = TRUE; @@ -1110,9 +1129,22 @@ read_one_setting_value (NMSetting *setting, uint_val = g_ascii_strtoull (tmp_str, NULL, 10); g_free (tmp_str); g_object_set (setting, key, uint_val, NULL); - } else if (type == DBUS_TYPE_G_UCHAR_ARRAY) { + } else if (type == G_TYPE_INT64) { + char *tmp_str; + gint64 int_val; + + tmp_str = nm_keyfile_plugin_kf_get_value (info->keyfile, setting_name, key, NULL); + int_val = nm_utils_ascii_str_to_int64 (tmp_str, 10, G_MININT64, G_MAXINT64, 0); + errsv = errno; + if (errsv) + nm_log_warn (LOGD_SETTINGS, "Invalid int64 value (%s)", tmp_str); + else + g_object_set (setting, key, int_val, NULL); + g_free (tmp_str); + } else if (type == G_TYPE_BYTES) { gint *tmp; GByteArray *array; + GBytes *bytes; gsize length; int i; @@ -1131,31 +1163,45 @@ read_one_setting_value (NMSetting *setting, g_byte_array_append (array, (const unsigned char *) &v, sizeof (v)); } - g_object_set (setting, key, array, NULL); - g_byte_array_free (array, TRUE); + bytes = g_byte_array_free_to_bytes (array); + g_object_set (setting, key, bytes, NULL); + g_bytes_unref (bytes); g_free (tmp); - } else if (type == DBUS_TYPE_G_LIST_OF_STRING) { + } else if (type == G_TYPE_STRV) { gchar **sa; gsize length; - int i; - GSList *list = NULL; sa = nm_keyfile_plugin_kf_get_string_list (info->keyfile, setting_name, key, &length, NULL); - for (i = 0; i < length; i++) - list = g_slist_prepend (list, sa[i]); - - list = g_slist_reverse (list); - g_object_set (setting, key, list, NULL); - - g_slist_free (list); + g_object_set (setting, key, sa, NULL); g_strfreev (sa); - } else if (type == DBUS_TYPE_G_MAP_OF_STRING) { + } else if (type == G_TYPE_HASH_TABLE) { read_hash_of_string (info->keyfile, setting, key); - } else if (type == DBUS_TYPE_G_UINT_ARRAY) { + } else if (type == G_TYPE_ARRAY) { if (!read_array_of_uint (info->keyfile, setting, key)) { nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (read): '%s/%s' : '%s'", setting_name, key, G_VALUE_TYPE_NAME (value)); } + } else if (G_VALUE_HOLDS_FLAGS (value)) { + guint64 uint_val; + + /* Flags are guint but GKeyFile has no uint reader, just uint64 */ + uint_val = nm_keyfile_plugin_kf_get_uint64 (info->keyfile, setting_name, key, &err); + if (!err) { + if (uint_val <= G_MAXUINT) + g_object_set (setting, key, (guint) uint_val, NULL); + else { + nm_log_warn (LOGD_SETTINGS, "Too large FLAGS property (read): '%s/%s' : '%s'", + setting_name, key, G_VALUE_TYPE_NAME (value)); + } + } + g_clear_error (&err); + } else if (G_VALUE_HOLDS_ENUM (value)) { + gint int_val; + + int_val = nm_keyfile_plugin_kf_get_integer (info->keyfile, setting_name, key, &err); + if (!err) + g_object_set (setting, key, (gint) int_val, NULL); + g_clear_error (&err); } else { nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (read): '%s/%s' : '%s'", setting_name, key, G_VALUE_TYPE_NAME (value)); @@ -1165,22 +1211,27 @@ read_one_setting_value (NMSetting *setting, static NMSetting * read_setting (GKeyFile *file, const char *keyfile_path, const char *group) { - NMSetting *setting; + NMSetting *setting = NULL; ReadInfo info = { file, keyfile_path }; const char *alias; + GType type; alias = nm_keyfile_plugin_get_setting_name_for_alias (group); - setting = nm_connection_create_setting (alias ? alias : group); - if (setting) + if (alias) + group = alias; + + type = nm_setting_lookup_type (group); + if (type) { + setting = g_object_new (type, NULL); nm_setting_enumerate_values (setting, read_one_setting_value, &info); - else + } else nm_log_warn (LOGD_SETTINGS, "Invalid setting name '%s'", group); return setting; } static void -read_vpn_secrets (GKeyFile *file, NMSettingVPN *s_vpn) +read_vpn_secrets (GKeyFile *file, NMSettingVpn *s_vpn) { char **keys, **iter; @@ -1197,30 +1248,6 @@ read_vpn_secrets (GKeyFile *file, NMSettingVPN *s_vpn) g_strfreev (keys); } -static void -ensure_slave_setting (NMConnection *connection) -{ - NMSettingConnection *s_con = nm_connection_get_setting_connection (connection); - const char *slave_type; - GType slave_gtype = G_TYPE_INVALID; - NMSetting *setting; - - slave_type = nm_setting_connection_get_slave_type (s_con); - if (!slave_type) - return; - - if (g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME) == 0) - slave_gtype = NM_TYPE_SETTING_BRIDGE_PORT; - else if (g_strcmp0 (slave_type, NM_SETTING_TEAM_SETTING_NAME) == 0) - slave_gtype = NM_TYPE_SETTING_TEAM_PORT; - - if (slave_gtype != G_TYPE_INVALID && !nm_connection_get_setting (connection, slave_gtype)) { - setting = (NMSetting *) g_object_new (slave_gtype, NULL); - g_assert (setting); - nm_connection_add_setting (connection, setting); - } -} - NMConnection * nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) { @@ -1234,11 +1261,10 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) gsize length; int i; gboolean vpn_secrets = FALSE; - const char *ctype; GError *verify_error = NULL; if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) { - g_set_error_literal (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error_literal (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "File did not exist or was not a regular file"); return NULL; } @@ -1246,7 +1272,7 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) bad_permissions = statbuf.st_mode & 0077; if (bad_permissions) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "File permissions (%o) were insecure", statbuf.st_mode); return NULL; @@ -1256,7 +1282,7 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error)) goto out; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); groups = g_key_file_get_groups (key_file, &length); for (i = 0; i < length; i++) { @@ -1271,36 +1297,50 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) nm_connection_add_setting (connection, setting); } - /* Make sure that we have the base device type and slave type settings - * even if the keyfile didn't include it, which can happen when the - * setting in question is all default values (like ethernet where - * the MAC address isn't given, or VLAN when the VLAN ID is zero, or - * bridge port with all default settings). - */ s_con = nm_connection_get_setting_connection (connection); - if (s_con) { - ctype = nm_setting_connection_get_connection_type (s_con); - if (ctype) { - setting = nm_connection_get_setting_by_name (connection, ctype); - if (!setting) { - NMSetting *base_setting; - GType base_setting_type; - - base_setting_type = nm_connection_lookup_setting_type (ctype); - if (base_setting_type != G_TYPE_INVALID) { - base_setting = (NMSetting *) g_object_new (base_setting_type, NULL); - g_assert (base_setting); - nm_connection_add_setting (connection, base_setting); - } - } - } + if (!s_con) { + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + } + + /* Make sure that we have 'id' even if not explictly specified in the keyfile */ + if (!nm_setting_connection_get_id (s_con)) { + char *base_name; - ensure_slave_setting (connection); + base_name = g_path_get_basename (filename); + g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL); + g_free (base_name); + } + + /* Make sure that we have 'uuid' even if not explictly specified in the keyfile */ + if (!nm_setting_connection_get_uuid (s_con)) { + char *hashed_uuid; + + hashed_uuid = nm_utils_uuid_generate_from_strings ("keyfile", filename, NULL); + g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL); + g_free (hashed_uuid); + } + + /* Make sure that we have 'interface-name' even if it was specified in the + * "wrong" (ie, deprecated) group. + */ + if ( !nm_setting_connection_get_interface_name (s_con) + && nm_setting_connection_get_connection_type (s_con)) { + char *interface_name; + + interface_name = g_key_file_get_string (key_file, + nm_setting_connection_get_connection_type (s_con), + "interface-name", + NULL); + if (interface_name) { + g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, interface_name, NULL); + g_free (interface_name); + } } /* Handle vpn secrets after the 'vpn' setting was read */ if (vpn_secrets) { - NMSettingVPN *s_vpn; + NMSettingVpn *s_vpn; s_vpn = nm_connection_get_setting_vpn (connection); if (s_vpn) @@ -1309,12 +1349,11 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error) g_strfreev (groups); - /* Verify the connection */ - if (!nm_connection_verify (connection, &verify_error)) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, - "invalid or missing connection property '%s/%s'", - verify_error ? g_type_name (nm_connection_lookup_setting_type_by_quark (verify_error->domain)) : "(unknown)", - (verify_error && verify_error->message) ? verify_error->message : "(unknown)"); + /* Normalize and verify the connection */ + if (!nm_connection_normalize (connection, NULL, NULL, &verify_error)) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "invalid connection: %s", + verify_error->message); g_clear_error (&verify_error); g_object_unref (connection); connection = NULL; diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index fae6e4ea..20b9820c 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -6,19 +6,16 @@ SUBDIRS=keyfiles AM_CPPFLAGS = \ -I$(top_srcdir)/include \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/libnm-util \ - -I$(top_builddir)/libnm-util \ - -I$(top_srcdir)/libnm-glib \ + -I$(top_srcdir)/libnm-core \ + -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/logging \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ + -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ @@ -30,13 +27,10 @@ test_keyfile_SOURCES = \ test-keyfile.c \ ../reader.c \ ../writer.c \ - ../errors.c \ ../utils.c test_keyfile_LDADD = \ $(top_builddir)/src/libNetworkManager.la \ - $(top_builddir)/libnm-glib/libnm-glib.la \ - $(top_builddir)/libnm-util/libnm-util.la \ $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) diff --git a/src/settings/plugins/keyfile/tests/Makefile.in b/src/settings/plugins/keyfile/tests/Makefile.in index f7b4b62a..8530bf8c 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.in +++ b/src/settings/plugins/keyfile/tests/Makefile.in @@ -105,16 +105,14 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) am__test_keyfile_SOURCES_DIST = test-keyfile.c ../reader.c ../writer.c \ - ../errors.c ../utils.c + ../utils.c @ENABLE_TESTS_TRUE@am_test_keyfile_OBJECTS = test-keyfile.$(OBJEXT) \ @ENABLE_TESTS_TRUE@ reader.$(OBJEXT) writer.$(OBJEXT) \ -@ENABLE_TESTS_TRUE@ errors.$(OBJEXT) utils.$(OBJEXT) +@ENABLE_TESTS_TRUE@ utils.$(OBJEXT) test_keyfile_OBJECTS = $(am_test_keyfile_OBJECTS) am__DEPENDENCIES_1 = @ENABLE_TESTS_TRUE@test_keyfile_DEPENDENCIES = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-glib/libnm-glib.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ @ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -254,6 +252,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -377,6 +377,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -396,6 +397,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -422,7 +424,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -504,19 +506,16 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@SUBDIRS = keyfiles @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-glib \ +@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-core \ +@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-core \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src \ -@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/logging \ @ENABLE_TESTS_TRUE@ -I$(top_srcdir)/src/settings \ @ENABLE_TESTS_TRUE@ -I$(srcdir)/../ \ @ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \ -@ENABLE_TESTS_TRUE@ $(POLKIT_CFLAGS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_CFLAGS) \ @ENABLE_TESTS_TRUE@ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ +@ENABLE_TESTS_TRUE@ -DNETWORKMANAGER_COMPILATION \ @ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @ENABLE_TESTS_TRUE@ -DTEST_KEYFILES_DIR=\"$(abs_srcdir)/keyfiles\" \ @ENABLE_TESTS_TRUE@ -DTEST_SCRATCH_DIR=\"$(abs_builddir)/keyfiles\" \ @@ -526,13 +525,10 @@ with_valgrind = @with_valgrind@ @ENABLE_TESTS_TRUE@ test-keyfile.c \ @ENABLE_TESTS_TRUE@ ../reader.c \ @ENABLE_TESTS_TRUE@ ../writer.c \ -@ENABLE_TESTS_TRUE@ ../errors.c \ @ENABLE_TESTS_TRUE@ ../utils.c @ENABLE_TESTS_TRUE@test_keyfile_LDADD = \ @ENABLE_TESTS_TRUE@ $(top_builddir)/src/libNetworkManager.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-glib/libnm-glib.la \ -@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \ @ENABLE_TESTS_TRUE@ $(DBUS_LIBS) \ @ENABLE_TESTS_TRUE@ $(CODE_COVERAGE_LDFLAGS) @@ -590,7 +586,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-keyfile.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@ @@ -645,20 +640,6 @@ writer.obj: ../writer.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o writer.obj `if test -f '../writer.c'; then $(CYGPATH_W) '../writer.c'; else $(CYGPATH_W) '$(srcdir)/../writer.c'; fi` -errors.o: ../errors.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.o -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errors.o `test -f '../errors.c' || echo '$(srcdir)/'`../errors.c - -errors.obj: ../errors.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errors.obj -MD -MP -MF $(DEPDIR)/errors.Tpo -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errors.Tpo $(DEPDIR)/errors.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../errors.c' object='errors.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errors.obj `if test -f '../errors.c'; then $(CYGPATH_W) '../errors.c'; else $(CYGPATH_W) '$(srcdir)/../errors.c'; fi` - utils.o: ../utils.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT utils.o -MD -MP -MF $(DEPDIR)/utils.Tpo -c -o utils.o `test -f '../utils.c' || echo '$(srcdir)/'`../utils.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/utils.Tpo $(DEPDIR)/utils.Po diff --git a/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_BT b/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_BT index cc8a9ee3..162bf72e 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_BT +++ b/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_BT @@ -16,6 +16,7 @@ apn=ISP.CINGULAR [serial] baud=115200 +parity=o [bluetooth] bdaddr=00:11:22:33:44:55 diff --git a/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain b/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain index 236cca0e..902b8427 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain +++ b/src/settings/plugins/keyfile/tests/keyfiles/ATT_Data_Connect_Plain @@ -18,3 +18,4 @@ pin=2345 [serial] baud=115200 +parity=111 diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am index 576164d2..4ca4c3fa 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am +++ b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.am @@ -21,7 +21,16 @@ KEYFILES = \ Test_Bridge_Component \ Test_New_Wired_Group_Name \ Test_New_Wireless_Group_Names \ - Test_Missing_Vlan_Setting + Test_minimal_1 \ + Test_minimal_2 \ + Test_minimal_slave_1 \ + Test_minimal_slave_2 \ + Test_minimal_slave_3 \ + Test_minimal_slave_4 \ + Test_Missing_Vlan_Setting \ + Test_Missing_ID_UUID \ + Test_Enum_Property \ + Test_Flags_Property CERTS = \ test-ca-cert.pem \ diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in index 05660e3e..bc522b1b 100644 --- a/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in +++ b/src/settings/plugins/keyfile/tests/keyfiles/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ @@ -399,7 +403,16 @@ KEYFILES = \ Test_Bridge_Component \ Test_New_Wired_Group_Name \ Test_New_Wireless_Group_Names \ - Test_Missing_Vlan_Setting + Test_minimal_1 \ + Test_minimal_2 \ + Test_minimal_slave_1 \ + Test_minimal_slave_2 \ + Test_minimal_slave_3 \ + Test_minimal_slave_4 \ + Test_Missing_Vlan_Setting \ + Test_Missing_ID_UUID \ + Test_Enum_Property \ + Test_Flags_Property CERTS = \ test-ca-cert.pem \ diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property b/src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property new file mode 100644 index 00000000..52b395b3 --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_Enum_Property @@ -0,0 +1,8 @@ +[connection] +id=Test Wired Connection IP6 +uuid=4e80a56d-c99f-4aad-a6dd-b449bc398c57 +type=802-3-ethernet + +[ipv6] +method=auto +ip6-privacy=2 diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property b/src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property new file mode 100644 index 00000000..3a46611d --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_Flags_Property @@ -0,0 +1,11 @@ +[connection] +id=Test Flags Property +uuid=05a5ec81-fa72-4b7c-9f85-4a0dfd36c84f +type=gsm + +[gsm] +number=*99# +username=username +password-flags=5 +apn=my.apn + diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_Missing_ID_UUID b/src/settings/plugins/keyfile/tests/keyfiles/Test_Missing_ID_UUID new file mode 100644 index 00000000..138380d0 --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_Missing_ID_UUID @@ -0,0 +1,9 @@ +# id and uuid keys are missing +# They will be auto-genetrated by NetworkManager + +[connection] +type=ethernet +autoconnect=true + +[802-3-ethernet] +mac-address=00:11:22:33:44:55 diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_1 b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_1 new file mode 100644 index 00000000..cac135ad --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_1 @@ -0,0 +1,2 @@ +[connection] +type=802-3-ethernet diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_2 b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_2 new file mode 100644 index 00000000..bbf2d8d6 --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_2 @@ -0,0 +1 @@ +[802-3-ethernet] diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_1 b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_1 new file mode 100644 index 00000000..d3122d53 --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_1 @@ -0,0 +1,4 @@ +[connection] +type=802-3-ethernet +master=br0 +slave-type=bridge diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_2 b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_2 new file mode 100644 index 00000000..eb1cdace --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_2 @@ -0,0 +1,7 @@ +[connection] +master=br0 + +[802-3-ethernet] + +[bridge-port] + diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_3 b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_3 new file mode 100644 index 00000000..7419e97d --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_3 @@ -0,0 +1,4 @@ +[connection] +master=br0 +slave-type=bridge +[802-3-ethernet] diff --git a/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_4 b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_4 new file mode 100644 index 00000000..626b6f68 --- /dev/null +++ b/src/settings/plugins/keyfile/tests/keyfiles/Test_minimal_slave_4 @@ -0,0 +1,4 @@ +[connection] +type=802-3-ethernet +master=br0 +[bridge-port] diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index cc57c1c3..33e3863c 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -18,29 +18,18 @@ * Copyright (C) 2008 - 2014 Red Hat, Inc. */ +#include "config.h" + #include <stdio.h> #include <stdarg.h> #include <unistd.h> #include <string.h> -#include <netinet/ether.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/socket.h> -#include <linux/if_infiniband.h> - -#include <nm-utils.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-wireless.h> -#include <nm-setting-ip4-config.h> -#include <nm-setting-ip6-config.h> -#include <nm-setting-bluetooth.h> -#include <nm-setting-serial.h> -#include <nm-setting-ppp.h> -#include <nm-setting-gsm.h> -#include <nm-setting-8021x.h> -#include <nm-setting-infiniband.h> -#include <nm-logging.h> + +#include "nm-core-internal.h" +#include "nm-logging.h" #include "reader.h" #include "writer.h" @@ -51,69 +40,42 @@ #define TEST_WIRELESS_FILE TEST_KEYFILES_DIR"/Test_Wireless_Connection" static void -check_ip4_address (NMSettingIP4Config *config, int idx, const char *address_str, int plen, const char *gateway_str) +check_ip_address (NMSettingIPConfig *config, int idx, const char *address, int plen) { - NMIP4Address *ip4 = nm_setting_ip4_config_get_address (config, idx); - guint32 address, gateway; - - g_assert (inet_pton (AF_INET, address_str, &address) == 1); - g_assert (inet_pton (AF_INET, gateway_str, &gateway) == 1); + NMIPAddress *ip4 = nm_setting_ip_config_get_address (config, idx); g_assert (ip4); - g_assert (nm_ip4_address_get_address (ip4) == address); - g_assert (nm_ip4_address_get_prefix (ip4) == plen); - g_assert (nm_ip4_address_get_gateway (ip4) == gateway); + g_assert_cmpstr (nm_ip_address_get_address (ip4), ==, address); + g_assert_cmpint (nm_ip_address_get_prefix (ip4), ==, plen); } static void -check_ip6_address (NMSettingIP6Config *config, int idx, const char *address_str, int plen, const char *gateway_str) +check_ip_route (NMSettingIPConfig *config, int idx, const char *destination, int plen, + const char *next_hop, gint64 metric) { - NMIP6Address *ip6 = nm_setting_ip6_config_get_address (config, idx); - struct in6_addr address; - struct in6_addr gateway; + NMIPRoute *route = nm_setting_ip_config_get_route (config, idx); - g_assert (inet_pton (AF_INET6, address_str, &address) == 1); - g_assert (inet_pton (AF_INET6, gateway_str, &gateway) == 1); - - g_assert (ip6); - g_assert (!memcmp (nm_ip6_address_get_address (ip6), &address, sizeof(address))); - g_assert (nm_ip6_address_get_prefix (ip6) == plen); - g_assert (!memcmp (nm_ip6_address_get_gateway (ip6), &gateway, sizeof(gateway))); + g_assert (route); + g_assert_cmpstr (nm_ip_route_get_dest (route), ==, destination); + g_assert_cmpint (nm_ip_route_get_prefix (route), ==, plen); + g_assert_cmpstr (nm_ip_route_get_next_hop (route), ==, next_hop); + g_assert_cmpint (nm_ip_route_get_metric (route), ==, metric); } -static void -check_ip4_route (NMSettingIP4Config *config, int idx, const char *destination_str, int plen, - const char *nexthop_str, int metric) +static NMConnection * +keyfile_read_connection_from_file (const char *filename) { - NMIP4Route *route = nm_setting_ip4_config_get_route (config, idx); - guint32 destination, nexthop; + GError *error = NULL; + NMConnection *connection; - g_assert (inet_pton (AF_INET, destination_str, &destination) == 1); - g_assert (inet_pton (AF_INET, nexthop_str, &nexthop) == 1); + g_assert (filename); - g_assert (route); - g_assert (nm_ip4_route_get_dest (route) == destination); - g_assert (nm_ip4_route_get_prefix (route) == plen); - g_assert (nm_ip4_route_get_next_hop (route) == nexthop); - g_assert (nm_ip4_route_get_metric (route) == metric); -} - -static void -check_ip6_route (NMSettingIP6Config *config, int idx, const char *destination_str, int plen, - const char *next_hop_str, int metric) -{ - NMIP6Route *route = nm_setting_ip6_config_get_route (config, idx); - struct in6_addr destination; - struct in6_addr next_hop; + connection = nm_keyfile_plugin_connection_from_file (filename, &error); + g_assert_no_error (error); - g_assert (inet_pton (AF_INET6, destination_str, &destination) == 1); - g_assert (inet_pton (AF_INET6, next_hop_str, &next_hop) == 1); + nmtst_assert_connection_verifies_without_normalization (connection); - g_assert (route); - g_assert (!memcmp (nm_ip6_route_get_dest (route), &destination, sizeof(destination))); - g_assert (nm_ip6_route_get_prefix (route) == plen); - g_assert (!memcmp (nm_ip6_route_get_next_hop (route), &next_hop, sizeof(next_hop))); - g_assert (nm_ip6_route_get_metric (route) == metric); + return connection; } static void @@ -122,22 +84,16 @@ test_read_valid_wired_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; const char *tmp; const char *expected_id = "Test Wired Connection"; const char *expected_uuid = "4e80a56d-c99f-4aad-a6dd-b449bc398c57"; const guint64 expected_timestamp = 6654332; guint64 timestamp; - const char *expected_dns1 = "4.2.2.1"; - const char *expected_dns2 = "4.2.2.2"; - guint32 addr; - struct in6_addr addr6; - const char *expected6_dns1 = "1111:dddd::aaaa"; - const char *expected6_dns2 = "1::cafe"; const char *expected6_dnssearch1 = "super-domain.com"; const char *expected6_dnssearch2 = "redhat.com"; const char *expected6_dnssearch3 = "gnu.org"; @@ -236,18 +192,13 @@ test_read_valid_wired_connection (void) NM_SETTING_WIRED_SETTING_NAME); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - ASSERT (array != NULL, + mac = nm_setting_wired_get_mac_address (s_wired); + ASSERT (mac != NULL, "connection-verify-wired", "failed to verify %s: missing %s / %s key", TEST_WIRED_FILE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value length", - TEST_WIRED_FILE, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_FILE, NM_SETTING_WIRED_SETTING_NAME, @@ -268,65 +219,62 @@ test_read_valid_wired_connection (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* DNS Addresses */ - ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip4) == 2, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0, - "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP address #1", - TEST_WIRED_FILE, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr, + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 0), "4.2.2.1") == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1", TEST_WIRED_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0, - "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP address #2", - TEST_WIRED_FILE, - NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr, + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip4, 1), "4.2.2.2") == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2", TEST_WIRED_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* IPv4 addresses */ - g_assert (nm_setting_ip4_config_get_num_addresses (s_ip4) == 6); - check_ip4_address (s_ip4, 0, "2.3.4.5", 24, "2.3.4.6"); - check_ip4_address (s_ip4, 1, "192.168.0.5", 24, "192.168.0.1"); - check_ip4_address (s_ip4, 2, "1.2.3.4", 16, "1.2.1.1"); - check_ip4_address (s_ip4, 3, "3.4.5.6", 16, "0.0.0.0"); - check_ip4_address (s_ip4, 4, "4.5.6.7", 24, "1.2.3.4"); - check_ip4_address (s_ip4, 5, "5.6.7.8", 24, "0.0.0.0"); + g_assert (nm_setting_ip_config_get_num_addresses (s_ip4) == 6); + check_ip_address (s_ip4, 0, "2.3.4.5", 24); + check_ip_address (s_ip4, 1, "192.168.0.5", 24); + check_ip_address (s_ip4, 2, "1.2.3.4", 16); + check_ip_address (s_ip4, 3, "3.4.5.6", 16); + check_ip_address (s_ip4, 4, "4.5.6.7", 24); + check_ip_address (s_ip4, 5, "5.6.7.8", 24); + + /* IPv4 gateway */ + ASSERT (strcmp (nm_setting_ip_config_get_gateway (s_ip4), "2.3.4.6") == 0, + "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", + TEST_WIRED_FILE, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP_CONFIG_GATEWAY); /* IPv4 routes */ - g_assert (nm_setting_ip4_config_get_num_routes (s_ip4) == 12); - check_ip4_route (s_ip4, 0, "5.6.7.8", 32, "0.0.0.0", 0); - check_ip4_route (s_ip4, 1, "1.2.3.0", 24, "2.3.4.8", 99); - check_ip4_route (s_ip4, 2, "1.1.1.2", 12, "0.0.0.0", 0); - check_ip4_route (s_ip4, 3, "1.1.1.3", 13, "0.0.0.0", 0); - check_ip4_route (s_ip4, 4, "1.1.1.4", 14, "2.2.2.4", 0); - check_ip4_route (s_ip4, 5, "1.1.1.5", 15, "2.2.2.5", 0); - check_ip4_route (s_ip4, 6, "1.1.1.6", 16, "2.2.2.6", 0); - check_ip4_route (s_ip4, 7, "1.1.1.7", 17, "0.0.0.0", 0); - check_ip4_route (s_ip4, 8, "1.1.1.8", 18, "0.0.0.0", 0); - check_ip4_route (s_ip4, 9, "1.1.1.9", 19, "0.0.0.0", 0); - check_ip4_route (s_ip4, 10, "1.1.1.10", 20, "0.0.0.0", 0); - check_ip4_route (s_ip4, 11, "1.1.1.11", 21, "0.0.0.0", 21); + g_assert (nm_setting_ip_config_get_num_routes (s_ip4) == 12); + check_ip_route (s_ip4, 0, "5.6.7.8", 32, NULL, -1); + check_ip_route (s_ip4, 1, "1.2.3.0", 24, "2.3.4.8", 99); + check_ip_route (s_ip4, 2, "1.1.1.2", 12, NULL, -1); + check_ip_route (s_ip4, 3, "1.1.1.3", 13, NULL, -1); + check_ip_route (s_ip4, 4, "1.1.1.4", 14, "2.2.2.4", -1); + check_ip_route (s_ip4, 5, "1.1.1.5", 15, "2.2.2.5", -1); + check_ip_route (s_ip4, 6, "1.1.1.6", 16, "2.2.2.6", -1); + check_ip_route (s_ip4, 7, "1.1.1.7", 17, NULL, -1); + check_ip_route (s_ip4, 8, "1.1.1.8", 18, NULL, -1); + check_ip_route (s_ip4, 9, "1.1.1.9", 19, NULL, -1); + check_ip_route (s_ip4, 10, "1.1.1.10", 20, NULL, -1); + check_ip_route (s_ip4, 11, "1.1.1.11", 21, NULL, 21); /* ===== IPv6 SETTING ===== */ @@ -337,182 +285,118 @@ test_read_valid_wired_connection (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* DNS Addresses */ - ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2, + ASSERT (nm_setting_ip_config_get_num_dns (s_ip6) == 2, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET6, expected6_dns1, &addr6) > 0, - "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP6 address #1", - TEST_WIRED_FILE, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), &addr6), + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 0), "1111:dddd::aaaa") == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); - ASSERT (inet_pton (AF_INET6, expected6_dns2, &addr6) > 0, - "connection-verify-wired", "failed to verify %s: couldn't convert DNS IP address #2", - TEST_WIRED_FILE, - NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); - ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6), + ASSERT (strcmp (nm_setting_ip_config_get_dns (s_ip6, 1), "1::cafe") == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* DNS Searches */ - ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 3, + ASSERT (nm_setting_ip_config_get_num_dns_searches (s_ip6) == 3, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); - ASSERT (!strcmp (nm_setting_ip6_config_get_dns_search (s_ip6, 0), expected6_dnssearch1), + ASSERT (!strcmp (nm_setting_ip_config_get_dns_search (s_ip6, 0), expected6_dnssearch1), "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #1", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); - ASSERT (!strcmp (nm_setting_ip6_config_get_dns_search (s_ip6, 1), expected6_dnssearch2), + NM_SETTING_IP_CONFIG_DNS_SEARCH); + ASSERT (!strcmp (nm_setting_ip_config_get_dns_search (s_ip6, 1), expected6_dnssearch2), "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #2", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); - ASSERT (!strcmp (nm_setting_ip6_config_get_dns_search (s_ip6, 2), expected6_dnssearch3), + NM_SETTING_IP_CONFIG_DNS_SEARCH); + ASSERT (!strcmp (nm_setting_ip_config_get_dns_search (s_ip6, 2), expected6_dnssearch3), "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value #3", TEST_WIRED_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS_SEARCH); + NM_SETTING_IP_CONFIG_DNS_SEARCH); /* IPv6 addresses */ - g_assert (nm_setting_ip6_config_get_num_addresses (s_ip6) == 10); - check_ip6_address (s_ip6, 0, "2:3:4:5:6:7:8:9", 64, "2:3:4:5:1:2:3:4"); - check_ip6_address (s_ip6, 1, "abcd:1234:ffff::cdde", 64, "::"); - check_ip6_address (s_ip6, 2, "1:2:3:4:5:6:7:8", 96, "::"); - check_ip6_address (s_ip6, 3, "3:4:5:6:7:8:9:0", 128, "::"); - check_ip6_address (s_ip6, 4, "3:4:5:6:7:8:9:14", 64, "::"); - check_ip6_address (s_ip6, 5, "3:4:5:6:7:8:9:15", 64, "::"); - check_ip6_address (s_ip6, 6, "3:4:5:6:7:8:9:16", 66, "::"); - check_ip6_address (s_ip6, 7, "3:4:5:6:7:8:9:17", 67, "::"); - check_ip6_address (s_ip6, 8, "3:4:5:6:7:8:9:18", 68, "::"); - check_ip6_address (s_ip6, 9, "3:4:5:6:7:8:9:19", 69, "1::09"); + g_assert (nm_setting_ip_config_get_num_addresses (s_ip6) == 10); + check_ip_address (s_ip6, 0, "2:3:4:5:6:7:8:9", 64); + check_ip_address (s_ip6, 1, "abcd:1234:ffff::cdde", 64); + check_ip_address (s_ip6, 2, "1:2:3:4:5:6:7:8", 96); + check_ip_address (s_ip6, 3, "3:4:5:6:7:8:9:0", 128); + check_ip_address (s_ip6, 4, "3:4:5:6:7:8:9:14", 64); + check_ip_address (s_ip6, 5, "3:4:5:6:7:8:9:15", 64); + check_ip_address (s_ip6, 6, "3:4:5:6:7:8:9:16", 66); + check_ip_address (s_ip6, 7, "3:4:5:6:7:8:9:17", 67); + check_ip_address (s_ip6, 8, "3:4:5:6:7:8:9:18", 68); + check_ip_address (s_ip6, 9, "3:4:5:6:7:8:9:19", 69); + + /* IPv6 gateway */ + ASSERT (strcmp (nm_setting_ip_config_get_gateway (s_ip6), "2:3:4:5:1:2:3:4") == 0, + "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", + TEST_WIRED_FILE, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP_CONFIG_GATEWAY); /* Route #1 */ - g_assert (nm_setting_ip6_config_get_num_routes (s_ip6) == 7); - check_ip6_route (s_ip6, 0, "d:e:f:0:1:2:3:4", 64, "f:e:d:c:1:2:3:4", 0); - check_ip6_route (s_ip6, 1, "a:b:c:d::", 64, "f:e:d:c:1:2:3:4", 99); - check_ip6_route (s_ip6, 2, "8:7:6:5:4:3:2:1", 128, "::", 0); - check_ip6_route (s_ip6, 3, "6:7:8:9:0:1:2:3", 126, "::", 1); - check_ip6_route (s_ip6, 4, "7:8:9:0:1:2:3:4", 125, "::", 5); - check_ip6_route (s_ip6, 5, "8:9:0:1:2:3:4:5", 124, "::", 6); - check_ip6_route (s_ip6, 6, "8:9:0:1:2:3:4:6", 123, "::", 0); + g_assert (nm_setting_ip_config_get_num_routes (s_ip6) == 7); + check_ip_route (s_ip6, 0, "d:e:f:0:1:2:3:4", 64, "f:e:d:c:1:2:3:4", -1); + check_ip_route (s_ip6, 1, "a:b:c:d::", 64, "f:e:d:c:1:2:3:4", 99); + check_ip_route (s_ip6, 2, "8:7:6:5:4:3:2:1", 128, NULL, -1); + check_ip_route (s_ip6, 3, "6:7:8:9:0:1:2:3", 126, NULL, 1); + check_ip_route (s_ip6, 4, "7:8:9:0:1:2:3:4", 125, NULL, 5); + check_ip_route (s_ip6, 5, "8:9:0:1:2:3:4:5", 124, NULL, 6); + check_ip_route (s_ip6, 6, "8:9:0:1:2:3:4:6", 123, NULL, -1); g_object_unref (connection); } static void -add_one_ip4_address (NMSettingIP4Config *s_ip4, - const char *addr, - const char *gw, - guint32 prefix) +add_one_ip_address (NMSettingIPConfig *s_ip, + const char *addr, + guint32 prefix) { - guint32 tmp; - NMIP4Address *ip4_addr; - - ip4_addr = nm_ip4_address_new (); - nm_ip4_address_set_prefix (ip4_addr, prefix); - - inet_pton (AF_INET, addr, &tmp); - nm_ip4_address_set_address (ip4_addr, tmp); - - inet_pton (AF_INET, gw, &tmp); - nm_ip4_address_set_gateway (ip4_addr, tmp); - - nm_setting_ip4_config_add_address (s_ip4, ip4_addr); - nm_ip4_address_unref (ip4_addr); -} - -static void -add_one_ip4_route (NMSettingIP4Config *s_ip4, - const char *dest, - const char *nh, - guint32 prefix, - guint32 metric) -{ - guint32 addr; - NMIP4Route *route; - - route = nm_ip4_route_new (); - nm_ip4_route_set_prefix (route, prefix); - nm_ip4_route_set_metric (route, metric); - - inet_pton (AF_INET, dest, &addr); - nm_ip4_route_set_dest (route, addr); - - inet_pton (AF_INET, nh, &addr); - nm_ip4_route_set_next_hop (route, addr); - - nm_setting_ip4_config_add_route (s_ip4, route); - nm_ip4_route_unref (route); -} - -static void -add_one_ip6_address (NMSettingIP6Config *s_ip6, - const char *addr, - guint32 prefix, - const char *gw) -{ - struct in6_addr tmp; - NMIP6Address *ip6_addr; - - ip6_addr = nm_ip6_address_new (); - nm_ip6_address_set_prefix (ip6_addr, prefix); - - inet_pton (AF_INET6, addr, &tmp); - nm_ip6_address_set_address (ip6_addr, &tmp); - - if (gw) { - inet_pton (AF_INET6, gw, &tmp); - nm_ip6_address_set_gateway (ip6_addr, &tmp); - } + NMIPAddress *ip_addr; + GError *error = NULL; - nm_setting_ip6_config_add_address (s_ip6, ip6_addr); - nm_ip6_address_unref (ip6_addr); + ip_addr = nm_ip_address_new (NM_IS_SETTING_IP4_CONFIG (s_ip) ? AF_INET : AF_INET6, + addr, prefix, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_address (s_ip, ip_addr); + nm_ip_address_unref (ip_addr); } static void -add_one_ip6_route (NMSettingIP6Config *s_ip6, - const char *dest, - const char *nh, - guint32 prefix, - guint32 metric) +add_one_ip_route (NMSettingIPConfig *s_ip, + const char *dest, + const char *nh, + guint32 prefix, + gint64 metric) { - struct in6_addr addr; - NMIP6Route *route; - - route = nm_ip6_route_new (); - nm_ip6_route_set_prefix (route, prefix); - nm_ip6_route_set_metric (route, metric); - - inet_pton (AF_INET6, dest, &addr); - nm_ip6_route_set_dest (route, &addr); - - inet_pton (AF_INET6, nh, &addr); - nm_ip6_route_set_next_hop (route, &addr); + NMIPRoute *route; + GError *error = NULL; - nm_setting_ip6_config_add_route (s_ip6, route); - nm_ip6_route_unref (route); + g_assert (prefix > 0); + route = nm_ip_route_new (NM_IS_SETTING_IP4_CONFIG (s_ip) ? AF_INET : AF_INET6, + dest, prefix, nh, metric, &error); + g_assert_no_error (error); + nm_setting_ip_config_add_route (s_ip, route); + nm_ip_route_unref (route); } @@ -522,33 +406,29 @@ test_write_wired_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; - GByteArray *mac; - unsigned char tmpmac[] = { 0x99, 0x88, 0x77, 0x66, 0x55, 0x44 }; + const char *mac = "99:88:77:66:55:44"; gboolean success; NMConnection *reread; char *testfile = NULL; GError *error = NULL; pid_t owner_grp; uid_t owner_uid; - guint32 addr; - struct in6_addr addr6; const char *dns1 = "4.2.2.1"; const char *dns2 = "4.2.2.2"; const char *address1 = "192.168.0.5"; - const char *address1_gw = "192.168.0.1"; const char *address2 = "1.2.3.4"; - const char *address2_gw = "1.2.1.1"; + const char *gw = "192.168.0.1"; const char *route1 = "10.10.10.2"; const char *route1_nh = "10.10.10.1"; const char *route2 = "1.1.1.1"; const char *route2_nh = "1.2.1.1"; const char *route3 = "2.2.2.2"; - const char *route3_nh = "0.0.0.0"; + const char *route3_nh = NULL; const char *route4 = "3.3.3.3"; - const char *route4_nh = "0.0.0.0"; + const char *route4_nh = NULL; const char *dns6_1 = "1::cafe"; const char *dns6_2 = "2::cafe"; const char *address6_1 = "abcd::beef"; @@ -563,7 +443,7 @@ test_write_wired_connection (void) const char *route6_4_nh = "::"; guint64 timestamp = 0x12345678L; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -585,66 +465,60 @@ test_write_wired_connection (void) s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, 900, NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, gw, NULL); /* Addresses */ - add_one_ip4_address (s_ip4, address1, address1_gw, 24); - add_one_ip4_address (s_ip4, address2, address2_gw, 8); + add_one_ip_address (s_ip4, address1, 24); + add_one_ip_address (s_ip4, address2, 8); /* Routes */ - add_one_ip4_route (s_ip4, route1, route1_nh, 24, 3); - add_one_ip4_route (s_ip4, route2, route2_nh, 8, 1); - add_one_ip4_route (s_ip4, route3, route3_nh, 7, 0); - add_one_ip4_route (s_ip4, route4, route4_nh, 6, 4); + add_one_ip_route (s_ip4, route1, route1_nh, 24, 3); + add_one_ip_route (s_ip4, route2, route2_nh, 8, 1); + add_one_ip_route (s_ip4, route3, route3_nh, 7, -1); + add_one_ip_route (s_ip4, route4, route4_nh, 6, 4); /* DNS servers */ - inet_pton (AF_INET, dns1, &addr); - nm_setting_ip4_config_add_dns (s_ip4, addr); - inet_pton (AF_INET, dns2, &addr); - nm_setting_ip4_config_add_dns (s_ip4, addr); + nm_setting_ip_config_add_dns (s_ip4, dns1); + nm_setting_ip_config_add_dns (s_ip4, dns2); /* IP6 setting */ - s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ()); + s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); /* Addresses */ - add_one_ip6_address (s_ip6, address6_1, 64, NULL); - add_one_ip6_address (s_ip6, address6_2, 56, NULL); + add_one_ip_address (s_ip6, address6_1, 64); + add_one_ip_address (s_ip6, address6_2, 56); /* Routes */ - add_one_ip6_route (s_ip6, route6_1, route6_1_nh, 64, 3); - add_one_ip6_route (s_ip6, route6_2, route6_2_nh, 56, 1); - add_one_ip6_route (s_ip6, route6_3, route6_3_nh, 63, 5); - add_one_ip6_route (s_ip6, route6_4, route6_4_nh, 62, 0); + add_one_ip_route (s_ip6, route6_1, route6_1_nh, 64, 3); + add_one_ip_route (s_ip6, route6_2, route6_2_nh, 56, 1); + add_one_ip_route (s_ip6, route6_3, route6_3_nh, 63, 5); + add_one_ip_route (s_ip6, route6_4, route6_4_nh, 62, -1); /* DNS servers */ - inet_pton (AF_INET6, dns6_1, &addr6); - nm_setting_ip6_config_add_dns (s_ip6, &addr6); - inet_pton (AF_INET6, dns6_2, &addr6); - nm_setting_ip6_config_add_dns (s_ip6, &addr6); + nm_setting_ip_config_add_dns (s_ip6, dns6_1); + nm_setting_ip_config_add_dns (s_ip6, dns6_2); /* DNS searches */ - nm_setting_ip6_config_add_dns_search (s_ip6, "wallaceandgromit.com"); + nm_setting_ip_config_add_dns_search (s_ip6, "wallaceandgromit.com"); /* Write out the connection */ owner_uid = geteuid (); @@ -680,8 +554,8 @@ test_read_ip6_wired_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; GError *error = NULL; const char *tmp; const char *expected_id = "Test Wired Connection IP6"; @@ -745,18 +619,18 @@ test_read_ip6_wired_connection (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_IP6_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); - ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 0, + ASSERT (nm_setting_ip_config_get_num_addresses (s_ip4) == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_IP6_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS); + NM_SETTING_IP_CONFIG_DNS); /* ===== IPv6 SETTING ===== */ @@ -767,16 +641,23 @@ test_read_ip6_wired_connection (void) NM_SETTING_IP6_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip6_config_get_method (s_ip6); + tmp = nm_setting_ip_config_get_method (s_ip6); ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_IP6_FILE, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); /* IPv6 address */ - g_assert (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1); - check_ip6_address (s_ip6, 0, "abcd:1234:ffff::cdde", 64, "abcd:1234:ffff::cdd1"); + g_assert (nm_setting_ip_config_get_num_addresses (s_ip6) == 1); + check_ip_address (s_ip6, 0, "abcd:1234:ffff::cdde", 64); + + /* IPv6 gateway */ + ASSERT (strcmp (nm_setting_ip_config_get_gateway (s_ip6), "abcd:1234:ffff::cdd1") == 0, + "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", + TEST_WIRED_IP6_FILE, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP_CONFIG_GATEWAY); g_object_unref (connection); } @@ -787,8 +668,8 @@ test_write_ip6_wired_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; NMConnection *reread; @@ -796,12 +677,11 @@ test_write_ip6_wired_connection (void) GError *error = NULL; pid_t owner_grp; uid_t owner_uid; - struct in6_addr addr6; const char *dns = "1::cafe"; const char *address = "abcd::beef"; const char *gw = "dcba::beef"; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -824,31 +704,31 @@ test_write_ip6_wired_connection (void) /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); /* IP6 setting */ - s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ()); + s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, gw, NULL); /* Addresses */ - add_one_ip6_address (s_ip6, address, 64, gw); + add_one_ip_address (s_ip6, address, 64); /* DNS servers */ - inet_pton (AF_INET6, dns, &addr6); - nm_setting_ip6_config_add_dns (s_ip6, &addr6); + nm_setting_ip_config_add_dns (s_ip6, dns); /* DNS searches */ - nm_setting_ip6_config_add_dns_search (s_ip6, "wallaceandgromit.com"); + nm_setting_ip_config_add_dns_search (s_ip6, "wallaceandgromit.com"); /* Write out the connection */ owner_uid = geteuid (); @@ -885,7 +765,7 @@ test_read_wired_mac_case (void) NMSettingConnection *s_con; NMSettingWired *s_wired; GError *error = NULL; - const GByteArray *array; + const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 }; const char *tmp; const char *expected_id = "Test Wired Connection MAC Case"; @@ -948,18 +828,13 @@ test_read_wired_mac_case (void) NM_SETTING_WIRED_SETTING_NAME); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - ASSERT (array != NULL, + mac = nm_setting_wired_get_mac_address (s_wired); + ASSERT (mac != NULL, "connection-verify-wired", "failed to verify %s: missing %s / %s key", TEST_WIRED_MAC_CASE_FILE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (array->len == ETH_ALEN, - "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value length", - TEST_WIRED_MAC_CASE_FILE, - NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS); - ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0, + ASSERT (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address)), "connection-verify-wired", "failed to verify %s: unexpected %s / %s key value", TEST_WIRED_MAC_CASE_FILE, NM_SETTING_WIRED_SETTING_NAME, @@ -977,7 +852,7 @@ test_read_mac_old_format (void) NMSettingWired *s_wired; GError *error = NULL; gboolean success; - const GByteArray *array; + const char *mac; char expected_mac[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 }; char expected_cloned_mac[ETH_ALEN] = { 0x00, 0x16, 0xaa, 0xbb, 0xcc, 0xfe }; @@ -993,16 +868,14 @@ test_read_mac_old_format (void) g_assert (s_wired); /* MAC address */ - array = nm_setting_wired_get_mac_address (s_wired); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert (memcmp (array->data, expected_mac, ETH_ALEN) == 0); + mac = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, ETH_ALEN)); /* Cloned MAC address */ - array = nm_setting_wired_get_cloned_mac_address (s_wired); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert (memcmp (array->data, expected_cloned_mac, ETH_ALEN) == 0); + mac = nm_setting_wired_get_cloned_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_cloned_mac, ETH_ALEN)); g_object_unref (connection); } @@ -1016,7 +889,7 @@ test_read_mac_ib_old_format (void) NMSettingInfiniband *s_ib; GError *error = NULL; gboolean success; - const GByteArray *array; + const char *mac; guint8 expected_mac[INFINIBAND_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90 }; @@ -1033,10 +906,9 @@ test_read_mac_ib_old_format (void) g_assert (s_ib); /* MAC address */ - array = nm_setting_infiniband_get_mac_address (s_ib); - g_assert (array); - g_assert_cmpint (array->len, ==, INFINIBAND_ALEN); - g_assert_cmpint (memcmp (array->data, expected_mac, sizeof (expected_mac)), ==, 0); + mac = nm_setting_infiniband_get_mac_address (s_ib); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); g_object_unref (connection); } @@ -1047,10 +919,10 @@ test_read_valid_wireless_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wireless; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; GError *error = NULL; - const GByteArray *array; - char expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 }; + const char *bssid; + const guint8 expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 }; const char *tmp; const char *expected_id = "Test Wireless Connection"; const char *expected_uuid = "2f962388-e5f3-45af-a62c-ac220b8f7baa"; @@ -1122,18 +994,13 @@ test_read_valid_wireless_connection (void) NM_SETTING_WIRED_SETTING_NAME); /* BSSID */ - array = nm_setting_wireless_get_bssid (s_wireless); - ASSERT (array != NULL, + bssid = nm_setting_wireless_get_bssid (s_wireless); + ASSERT (bssid != NULL, "connection-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_WIRELESS_FILE, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BSSID); - ASSERT (array->len == ETH_ALEN, - "connection-verify-wireless", "failed to verify %s: unexpected %s / %s key value length", - TEST_WIRELESS_FILE, - NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_BSSID); - ASSERT (memcmp (array->data, &expected_bssid[0], sizeof (expected_bssid)) == 0, + ASSERT (nm_utils_hwaddr_matches (bssid, -1, expected_bssid, sizeof (expected_bssid)), "connection-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_WIRELESS_FILE, NM_SETTING_WIRELESS_SETTING_NAME, @@ -1148,12 +1015,12 @@ test_read_valid_wireless_connection (void) NM_SETTING_IP4_CONFIG_SETTING_NAME); /* Method */ - tmp = nm_setting_ip4_config_get_method (s_ip4); + tmp = nm_setting_ip_config_get_method (s_ip4); ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0, "connection-verify-wireless", "failed to verify %s: unexpected %s / %s key value", TEST_WIRELESS_FILE, NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_METHOD); + NM_SETTING_IP_CONFIG_METHOD); g_object_unref (connection); } @@ -1164,12 +1031,11 @@ test_write_wireless_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wireless; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; - GByteArray *bssid; - unsigned char tmpbssid[] = { 0xaa, 0xb9, 0xa1, 0x74, 0x55, 0x44 }; - GByteArray *ssid; + const char *bssid = "aa:b9:a1:74:55:44"; + GBytes *ssid; unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 }; gboolean success; NMConnection *reread; @@ -1179,7 +1045,7 @@ test_write_wireless_connection (void) uid_t owner_uid; guint64 timestamp = 0x12344433L; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -1201,11 +1067,7 @@ test_write_wireless_connection (void) s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); nm_connection_add_setting (connection, NM_SETTING (s_wireless)); - bssid = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (bssid, &tmpbssid[0], sizeof (tmpbssid)); - - ssid = g_byte_array_sized_new (sizeof (tmpssid)); - g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); + ssid = g_bytes_new (tmpssid, sizeof (tmpssid)); g_object_set (s_wireless, NM_SETTING_WIRELESS_BSSID, bssid, @@ -1213,25 +1075,24 @@ test_write_wireless_connection (void) NM_SETTING_WIRED_MTU, 1000, NULL); - g_byte_array_free (bssid, TRUE); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ()); + s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ @@ -1268,7 +1129,9 @@ test_read_string_ssid (void) NMConnection *connection; NMSettingWireless *s_wireless; GError *error = NULL; - const GByteArray *array; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; const char *expected_ssid = "blah blah ssid 1234"; connection = nm_keyfile_plugin_connection_from_file (TEST_STRING_SSID_FILE, NULL); @@ -1287,14 +1150,15 @@ test_read_string_ssid (void) NM_SETTING_WIRELESS_SETTING_NAME); /* SSID */ - array = nm_setting_wireless_get_ssid (s_wireless); - ASSERT (array != NULL, + ssid = nm_setting_wireless_get_ssid (s_wireless); + ASSERT (ssid != NULL, "connection-verify-wireless", "failed to verify %s: missing %s / %s key", TEST_STRING_SSID_FILE, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID); - g_assert_cmpint (array->len, ==, strlen (expected_ssid)); - g_assert (memcmp (array->data, expected_ssid, array->len) == 0); + ssid_data = g_bytes_get_data (ssid, &ssid_len); + g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); + g_assert (memcmp (ssid_data, expected_ssid, ssid_len) == 0); g_object_unref (connection); } @@ -1305,9 +1169,9 @@ test_write_string_ssid (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wireless; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *uuid, *testfile = NULL, *tmp; - GByteArray *ssid; + GBytes *ssid; unsigned char tmpssid[] = { 65, 49, 50, 51, 32, 46, 92, 46, 36, 37, 126, 93 }; gboolean success; NMConnection *reread; @@ -1316,7 +1180,7 @@ test_write_string_ssid (void) uid_t owner_uid; GKeyFile *keyfile; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -1336,18 +1200,17 @@ test_write_string_ssid (void) s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); nm_connection_add_setting (connection, NM_SETTING (s_wireless)); - ssid = g_byte_array_sized_new (sizeof (tmpssid)); - g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); + ssid = g_bytes_new (tmpssid, sizeof (tmpssid)); g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, ssid, NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ @@ -1378,8 +1241,7 @@ test_write_string_ssid (void) reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); ASSERT (reread != NULL, "connection-write", "failed to re-read test connection"); - ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE, - "connection-write", "written and re-read connection weren't the same"); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); g_clear_error (&error); unlink (testfile); @@ -1398,7 +1260,9 @@ test_read_intlist_ssid (void) NMSettingWireless *s_wifi; GError *error = NULL; gboolean success; - const GByteArray *array; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; const char *expected_ssid = "blah1234"; connection = nm_keyfile_plugin_connection_from_file (TEST_INTLIST_SSID_FILE, &error); @@ -1413,10 +1277,11 @@ test_read_intlist_ssid (void) s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); - array = nm_setting_wireless_get_ssid (s_wifi); - g_assert (array != NULL); - g_assert_cmpint (array->len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (array->data, expected_ssid, strlen (expected_ssid)), ==, 0); + ssid = nm_setting_wireless_get_ssid (s_wifi); + g_assert (ssid != NULL); + ssid_data = g_bytes_get_data (ssid, &ssid_len); + g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); + g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); g_object_unref (connection); } @@ -1427,9 +1292,9 @@ test_write_intlist_ssid (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *uuid, *testfile = NULL; - GByteArray *ssid; + GBytes *ssid; unsigned char tmpssid[] = { 65, 49, 50, 51, 0, 50, 50 }; gboolean success; NMConnection *reread; @@ -1440,7 +1305,7 @@ test_write_intlist_ssid (void) gint *intlist; gsize len = 0, i; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -1462,16 +1327,15 @@ test_write_intlist_ssid (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (tmpssid)); - g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); + ssid = g_bytes_new (tmpssid, sizeof (tmpssid)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ owner_uid = geteuid (); @@ -1503,8 +1367,7 @@ test_write_intlist_ssid (void) g_assert_no_error (error); g_assert (reread); - success = nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT); - g_assert (success); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); g_clear_error (&error); unlink (testfile); @@ -1523,7 +1386,9 @@ test_read_intlike_ssid (void) NMSettingWireless *s_wifi; GError *error = NULL; gboolean success; - const GByteArray *array; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; const char *expected_ssid = "101"; connection = nm_keyfile_plugin_connection_from_file (TEST_INTLIKE_SSID_FILE, &error); @@ -1538,10 +1403,11 @@ test_read_intlike_ssid (void) s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); - array = nm_setting_wireless_get_ssid (s_wifi); - g_assert (array != NULL); - g_assert_cmpint (array->len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (array->data, expected_ssid, strlen (expected_ssid)), ==, 0); + ssid = nm_setting_wireless_get_ssid (s_wifi); + g_assert (ssid != NULL); + ssid_data = g_bytes_get_data (ssid, &ssid_len); + g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); + g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); g_object_unref (connection); } @@ -1555,7 +1421,9 @@ test_read_intlike_ssid_2 (void) NMSettingWireless *s_wifi; GError *error = NULL; gboolean success; - const GByteArray *array; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; const char *expected_ssid = "11;12;13;"; connection = nm_keyfile_plugin_connection_from_file (TEST_INTLIKE_SSID_2_FILE, &error); @@ -1570,10 +1438,11 @@ test_read_intlike_ssid_2 (void) s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); - array = nm_setting_wireless_get_ssid (s_wifi); - g_assert (array != NULL); - g_assert_cmpint (array->len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (array->data, expected_ssid, strlen (expected_ssid)), ==, 0); + ssid = nm_setting_wireless_get_ssid (s_wifi); + g_assert (ssid != NULL); + ssid_data = g_bytes_get_data (ssid, &ssid_len); + g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); + g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); g_object_unref (connection); } @@ -1584,9 +1453,9 @@ test_write_intlike_ssid (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *uuid, *testfile = NULL; - GByteArray *ssid; + GBytes *ssid; unsigned char tmpssid[] = { 49, 48, 49 }; gboolean success; NMConnection *reread; @@ -1596,7 +1465,7 @@ test_write_intlike_ssid (void) GKeyFile *keyfile; char *tmp; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -1618,16 +1487,15 @@ test_write_intlike_ssid (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (tmpssid)); - g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); + ssid = g_bytes_new (tmpssid, sizeof (tmpssid)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ owner_uid = geteuid (); @@ -1655,8 +1523,7 @@ test_write_intlike_ssid (void) g_assert_no_error (error); g_assert (reread); - success = nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT); - g_assert (success); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); g_clear_error (&error); unlink (testfile); @@ -1672,9 +1539,9 @@ test_write_intlike_ssid_2 (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; char *uuid, *testfile = NULL; - GByteArray *ssid; + GBytes *ssid; unsigned char tmpssid[] = { 49, 49, 59, 49, 50, 59, 49, 51, 59}; gboolean success; NMConnection *reread; @@ -1684,7 +1551,7 @@ test_write_intlike_ssid_2 (void) GKeyFile *keyfile; char *tmp; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -1706,16 +1573,15 @@ test_write_intlike_ssid_2 (void) g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (tmpssid)); - g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); + ssid = g_bytes_new (tmpssid, sizeof (tmpssid)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ owner_uid = geteuid (); @@ -1743,8 +1609,7 @@ test_write_intlike_ssid_2 (void) g_assert_no_error (error); g_assert (reread); - success = nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT); - g_assert (success); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); g_clear_error (&error); unlink (testfile); @@ -1765,9 +1630,10 @@ test_read_bt_dun_connection (void) NMSettingSerial *s_serial; NMSettingGsm *s_gsm; GError *error = NULL; - const GByteArray *array; - char expected_bdaddr[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; + const char *bdaddr; + const guint8 expected_bdaddr[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; const char *tmp; + NMSettingSerialParity parity; const char *expected_id = "AT&T Data Connect BT"; const char *expected_uuid = "089130ab-ce28-46e4-ad77-d44869b03d19"; const char *expected_apn = "ISP.CINGULAR"; @@ -1824,18 +1690,13 @@ test_read_bt_dun_connection (void) NM_SETTING_WIRED_SETTING_NAME); /* BDADDR */ - array = nm_setting_bluetooth_get_bdaddr (s_bluetooth); - ASSERT (array != NULL, + bdaddr = nm_setting_bluetooth_get_bdaddr (s_bluetooth); + ASSERT (bdaddr != NULL, "connection-verify-bt", "failed to verify %s: missing %s / %s key", TEST_BT_DUN_FILE, NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR); - ASSERT (array->len == ETH_ALEN, - "connection-verify-bt", "failed to verify %s: unexpected %s / %s key value length", - TEST_BT_DUN_FILE, - NM_SETTING_BLUETOOTH_SETTING_NAME, - NM_SETTING_BLUETOOTH_BDADDR); - ASSERT (memcmp (array->data, &expected_bdaddr[0], sizeof (expected_bdaddr)) == 0, + ASSERT (nm_utils_hwaddr_matches (bdaddr, -1, expected_bdaddr, sizeof (expected_bdaddr)), "connection-verify-bt", "failed to verify %s: unexpected %s / %s key value", TEST_BT_DUN_FILE, NM_SETTING_BLUETOOTH_SETTING_NAME, @@ -1909,6 +1770,13 @@ test_read_bt_dun_connection (void) TEST_BT_DUN_FILE, NM_SETTING_SERIAL_SETTING_NAME); + parity = nm_setting_serial_get_parity (s_serial); + ASSERT (parity == NM_SETTING_SERIAL_PARITY_ODD, + "connection-verify-serial", "failed to verify %s: unexpected %s / %s key value", + TEST_BT_DUN_FILE, + NM_SETTING_SERIAL_SETTING_NAME, + NM_SETTING_SERIAL_PARITY); + g_object_unref (connection); } @@ -1918,11 +1786,10 @@ test_write_bt_dun_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingBluetooth *s_bt; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSettingGsm *s_gsm; char *uuid; - GByteArray *bdaddr; - unsigned char tmpbdaddr[] = { 0xaa, 0xb9, 0xa1, 0x74, 0x55, 0x44 }; + const char *bdaddr = "aa:b9:a1:74:55:44"; gboolean success; NMConnection *reread; char *testfile = NULL; @@ -1931,7 +1798,7 @@ test_write_bt_dun_connection (void) uid_t owner_uid; guint64 timestamp = 0x12344433L; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -1953,23 +1820,18 @@ test_write_bt_dun_connection (void) s_bt = NM_SETTING_BLUETOOTH (nm_setting_bluetooth_new ()); nm_connection_add_setting (connection, NM_SETTING (s_bt)); - bdaddr = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (bdaddr, &tmpbdaddr[0], sizeof (tmpbdaddr)); - g_object_set (s_bt, NM_SETTING_BLUETOOTH_BDADDR, bdaddr, NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_DUN, NULL); - g_byte_array_free (bdaddr, TRUE); - /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* GSM setting */ @@ -1998,8 +1860,7 @@ test_write_bt_dun_connection (void) reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); ASSERT (reread != NULL, "connection-write", "failed to re-read test connection"); - ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE, - "connection-write", "written and re-read connection weren't the same"); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); g_clear_error (&error); unlink (testfile); @@ -2021,6 +1882,7 @@ test_read_gsm_connection (void) NMSettingBluetooth *s_bluetooth; GError *error = NULL; const char *tmp; + NMSettingSerialParity parity; const char *expected_id = "AT&T Data Connect"; const char *expected_apn = "ISP.CINGULAR"; const char *expected_username = "ISP@CINGULARGPRS.COM"; @@ -2158,6 +2020,13 @@ test_read_gsm_connection (void) TEST_GSM_FILE, NM_SETTING_SERIAL_SETTING_NAME); + parity = nm_setting_serial_get_parity (s_serial); + ASSERT (parity == NM_SETTING_SERIAL_PARITY_ODD, + "connection-verify-serial", "failed to verify %s: unexpected %s / %s key value", + TEST_GSM_FILE, + NM_SETTING_SERIAL_SETTING_NAME, + NM_SETTING_SERIAL_PARITY); + g_object_unref (connection); } @@ -2166,7 +2035,7 @@ test_write_gsm_connection (void) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSettingGsm *s_gsm; char *uuid; gboolean success; @@ -2177,7 +2046,7 @@ test_write_gsm_connection (void) uid_t owner_uid; guint64 timestamp = 0x12344433L; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -2196,11 +2065,11 @@ test_write_gsm_connection (void) /* IP4 setting */ - s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* GSM setting */ @@ -2215,7 +2084,6 @@ test_write_gsm_connection (void) NM_SETTING_GSM_PIN, "123456", NM_SETTING_GSM_NETWORK_ID, "254098", NM_SETTING_GSM_HOME_ONLY, TRUE, - NM_SETTING_GSM_NETWORK_TYPE, NM_SETTING_GSM_NETWORK_TYPE_PREFER_UMTS_HSPA, NULL); /* Write out the connection */ @@ -2233,8 +2101,7 @@ test_write_gsm_connection (void) reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); ASSERT (reread != NULL, "connection-write", "failed to re-read test connection"); - ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE, - "connection-write", "written and re-read connection weren't the same"); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); g_clear_error (&error); unlink (testfile); @@ -2255,7 +2122,7 @@ test_read_wired_8021x_tls_blob_connection (void) GError *error = NULL; const char *tmp; gboolean success; - const GByteArray *array; + GBytes *blob; connection = nm_keyfile_plugin_connection_from_file (TEST_WIRED_TLS_BLOB_FILE, &error); if (connection == NULL) { @@ -2292,16 +2159,16 @@ test_read_wired_8021x_tls_blob_connection (void) g_assert_cmpint (nm_setting_802_1x_get_ca_cert_scheme (s_8021x), ==, NM_SETTING_802_1X_CK_SCHEME_BLOB); /* Make sure it's not a path, since it's a blob */ - g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, + g_test_expect_message ("libnm", G_LOG_LEVEL_CRITICAL, "*assertion*scheme == NM_SETTING_802_1X_CK_SCHEME_PATH*"); tmp = nm_setting_802_1x_get_ca_cert_path (s_8021x); g_test_assert_expected_messages (); g_assert (tmp == NULL); /* Validate the path */ - array = nm_setting_802_1x_get_ca_cert_blob (s_8021x); - g_assert (array != NULL); - g_assert_cmpint (array->len, ==, 568); + blob = nm_setting_802_1x_get_ca_cert_blob (s_8021x); + g_assert (blob != NULL); + g_assert_cmpint (g_bytes_get_size (blob), ==, 568); tmp = nm_setting_802_1x_get_client_cert_path (s_8021x); g_assert_cmpstr (tmp, ==, "/home/dcbw/Desktop/certinfra/client.pem"); @@ -2504,14 +2371,14 @@ create_wired_tls_connection (NMSetting8021xCKScheme scheme) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSetting *s_wired; NMSetting8021x *s_8021x; char *uuid; gboolean success; GError *error = NULL; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection != NULL); /* Connection setting */ @@ -2528,9 +2395,9 @@ create_wired_tls_connection (NMSetting8021xCKScheme scheme) g_free (uuid); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* Wired setting */ @@ -2769,7 +2636,7 @@ test_read_infiniband_connection (void) NMSettingConnection *s_con; NMSettingInfiniband *s_ib; GError *error = NULL; - const GByteArray *array; + const char *mac; guint8 expected_mac[INFINIBAND_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90 }; @@ -2794,10 +2661,9 @@ test_read_infiniband_connection (void) s_ib = nm_connection_get_setting_infiniband (connection); g_assert (s_ib); - array = nm_setting_infiniband_get_mac_address (s_ib); - g_assert (array); - g_assert_cmpint (array->len, ==, INFINIBAND_ALEN); - g_assert_cmpint (memcmp (array->data, expected_mac, sizeof (expected_mac)), ==, 0); + mac = nm_setting_infiniband_get_mac_address (s_ib); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); g_object_unref (connection); } @@ -2808,13 +2674,10 @@ test_write_infiniband_connection (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingInfiniband *s_ib; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; - GByteArray *mac; - guint8 tmpmac[] = { 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0xab, 0xbc, - 0xcd, 0xde, 0xef, 0xf0, 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f, 0x6f, 0xba - }; + const char *mac = "99:88:77:66:55:44:ab:bc:cd:de:ef:f0:0a:1b:2c:3d:4e:5f:6f:ba"; gboolean success; NMConnection *reread; char *testfile = NULL; @@ -2822,7 +2685,7 @@ test_write_infiniband_connection (void) pid_t owner_grp; uid_t owner_uid; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -2845,26 +2708,23 @@ test_write_infiniband_connection (void) g_assert (s_ib); nm_connection_add_setting (connection, NM_SETTING (s_ib)); - mac = g_byte_array_sized_new (sizeof (tmpmac)); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); g_object_set (s_ib, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NM_SETTING_INFINIBAND_MTU, 900, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); - g_byte_array_free (mac, TRUE); /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ owner_uid = geteuid (); @@ -2895,7 +2755,7 @@ test_read_bridge_main (void) { NMConnection *connection; NMSettingConnection *s_con; - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; NMSettingBridge *s_bridge; GError *error = NULL; const char *expected_id = "Test Bridge Main"; @@ -2914,16 +2774,16 @@ test_read_bridge_main (void) g_assert (s_con); g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, expected_id); g_assert_cmpstr (nm_setting_connection_get_uuid (s_con), ==, expected_uuid); + g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "br0"); /* 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_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); /* Bridge setting */ s_bridge = nm_connection_get_setting_bridge (connection); g_assert (s_bridge); - g_assert_cmpstr (nm_setting_bridge_get_interface_name (s_bridge), ==, "br0"); g_assert_cmpuint (nm_setting_bridge_get_forward_delay (s_bridge), ==, 0); g_assert_cmpuint (nm_setting_bridge_get_stp (s_bridge), ==, TRUE); g_assert_cmpuint (nm_setting_bridge_get_priority (s_bridge), ==, 32744); @@ -2940,8 +2800,8 @@ test_write_bridge_main (void) NMConnection *connection; NMSettingConnection *s_con; NMSettingBridge *s_bridge; - NMSettingIP4Config *s_ip4; - NMSettingIP6Config *s_ip6; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; char *uuid; gboolean success; NMConnection *reread; @@ -2950,7 +2810,7 @@ test_write_bridge_main (void) pid_t owner_grp; uid_t owner_uid; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -2973,26 +2833,23 @@ test_write_bridge_main (void) g_assert (s_bridge); nm_connection_add_setting (connection, NM_SETTING (s_bridge)); - g_object_set (s_bridge, - NM_SETTING_BRIDGE_INTERFACE_NAME, "br0", - NULL); - /* IP4 setting */ - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, - NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, + NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.1", NULL); - add_one_ip4_address (s_ip4, "1.2.3.4", "1.1.1.1", 24); + add_one_ip_address (s_ip4, "1.2.3.4", 24); /* IP6 setting */ - s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); - g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); /* Write out the connection */ owner_uid = geteuid (); @@ -3025,7 +2882,7 @@ test_read_bridge_component (void) NMSettingConnection *s_con; NMSettingBridgePort *s_port; NMSettingWired *s_wired; - const GByteArray *array; + const char *mac; guint8 expected_mac[ETH_ALEN] = { 0x00, 0x22, 0x15, 0x59, 0x62, 0x97 }; GError *error = NULL; const char *expected_id = "Test Bridge Component"; @@ -3050,10 +2907,9 @@ test_read_bridge_component (void) /* 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); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert_cmpint (memcmp (array->data, expected_mac, sizeof (expected_mac)), ==, 0); + mac = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); /* BridgePort setting */ s_port = nm_connection_get_setting_bridge_port (connection); @@ -3073,8 +2929,7 @@ test_write_bridge_component (void) NMSettingBridgePort *s_port; NMSettingWired *s_wired; char *uuid; - GByteArray *mac; - guint8 tmpmac[] = { 0x99, 0x88, 0x77, 0x66, 0x55, 0x44 }; + const char *mac = "99:88:77:66:55:44"; gboolean success; NMConnection *reread; char *testfile = NULL; @@ -3082,7 +2937,7 @@ test_write_bridge_component (void) pid_t owner_grp; uid_t owner_uid; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -3106,13 +2961,10 @@ test_write_bridge_component (void) g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); - mac = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac)); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, 1300, NULL); - g_byte_array_free (mac, TRUE); /* BridgePort setting */ s_port = (NMSettingBridgePort *) nm_setting_bridge_port_new (); @@ -3151,7 +3003,7 @@ test_read_new_wired_group_name (void) { NMConnection *connection; NMSettingWired *s_wired; - const GByteArray *array; + const char *mac; guint8 expected_mac[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; GError *error = NULL; gboolean success; @@ -3168,10 +3020,9 @@ test_read_new_wired_group_name (void) g_assert (s_wired); g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 1400); - array = nm_setting_wired_get_mac_address (s_wired); - g_assert (array); - g_assert_cmpint (array->len, ==, ETH_ALEN); - g_assert_cmpint (memcmp (array->data, expected_mac, sizeof (expected_mac)), ==, 0); + mac = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac); + g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); g_object_unref (connection); } @@ -3193,7 +3044,7 @@ test_write_new_wired_group_name (void) char *s; gint mtu; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ @@ -3227,7 +3078,7 @@ test_write_new_wired_group_name (void) reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); g_assert (reread); - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); /* Look at the keyfile itself to ensure we wrote out the new group names and type */ kf = g_key_file_new (); @@ -3257,7 +3108,9 @@ test_read_new_wireless_group_names (void) NMConnection *connection; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; - const GByteArray *array; + GBytes *ssid; + const guint8 *ssid_data; + gsize ssid_len; const char *expected_ssid = "foobar"; GError *error = NULL; gboolean success; @@ -3273,10 +3126,11 @@ test_read_new_wireless_group_names (void) s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); - array = nm_setting_wireless_get_ssid (s_wifi); - g_assert (array); - g_assert_cmpint (array->len, ==, strlen (expected_ssid)); - g_assert_cmpint (memcmp (array->data, expected_ssid, array->len), ==, 0); + ssid = nm_setting_wireless_get_ssid (s_wifi); + g_assert (ssid); + ssid_data = g_bytes_get_data (ssid, &ssid_len); + g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); + g_assert_cmpint (memcmp (ssid_data, expected_ssid, ssid_len), ==, 0); g_assert_cmpstr (nm_setting_wireless_get_mode (s_wifi), ==, NM_SETTING_WIRELESS_MODE_INFRA); @@ -3297,7 +3151,7 @@ test_write_new_wireless_group_names (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; char *uuid; - GByteArray *ssid; + GBytes *ssid; unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 }; const char *expected_psk = "asdfasdfasdfa12315"; gboolean success; @@ -3309,7 +3163,7 @@ test_write_new_wireless_group_names (void) GKeyFile *kf; char *s; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Connection setting */ @@ -3328,13 +3182,12 @@ test_write_new_wireless_group_names (void) s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - ssid = g_byte_array_sized_new (sizeof (tmpssid)); - g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); + ssid = g_bytes_new (tmpssid, sizeof (tmpssid)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, NULL); - g_byte_array_free (ssid, TRUE); + g_bytes_unref (ssid); /* WiFi security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -3357,7 +3210,7 @@ test_write_new_wireless_group_names (void) reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); g_assert (reread); - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); /* Look at the keyfile itself to ensure we wrote out the new group names and type */ kf = g_key_file_new (); @@ -3410,72 +3263,357 @@ test_read_missing_vlan_setting (void) g_object_unref (connection); } +static void +test_read_missing_id_uuid (void) +{ + NMConnection *connection; + GError *error = NULL; + gboolean success; + + connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error); + g_assert_no_error (error); + g_assert (connection); + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); + + /* Ensure the ID and UUID properties are there */ + g_assert_cmpstr (nm_connection_get_id (connection), ==, "Test_Missing_ID_UUID"); + g_assert (nm_connection_get_uuid (connection)); + + g_object_unref (connection); +} + +static void +test_read_minimal (void) +{ + NMConnection *connection = NULL; + gs_unref_object NMConnection *con_archetype = NULL; + NMSettingConnection *s_con; + + con_archetype = nmtst_create_minimal_connection ("Test_minimal_x", + "a15bd68f-c32b-40b8-8d27-49e472a85919", + NM_SETTING_WIRED_SETTING_NAME, + &s_con); + nmtst_connection_normalize (con_archetype); + + + connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_1"); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connection), + NULL); + nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); + g_clear_object (&connection); + + + connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_2"); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connection), + NULL); + nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); + g_clear_object (&connection); +} + +static void +test_read_minimal_slave (void) +{ + NMConnection *connection = NULL; + gs_unref_object NMConnection *con_archetype = NULL; + NMSettingConnection *s_con; + + con_archetype = nmtst_create_minimal_connection ("Test_minimal_slave_x", + "a56b4ca5-7075-43d4-82c7-5d0cb15f7654", + NM_SETTING_WIRED_SETTING_NAME, + &s_con); + g_object_set (s_con, + NM_SETTING_CONNECTION_MASTER, "br0", + NM_SETTING_CONNECTION_SLAVE_TYPE, "bridge", + NULL); + nmtst_connection_normalize (con_archetype); + + + connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_slave_1"); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connection), + NULL); + nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); + g_clear_object (&connection); + + + connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_slave_2"); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connection), + NULL); + nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); + g_clear_object (&connection); + + connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_slave_3"); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connection), + NULL); + nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); + g_clear_object (&connection); + + connection = keyfile_read_connection_from_file (TEST_KEYFILES_DIR"/Test_minimal_slave_4"); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, nm_connection_get_id (connection), + NM_SETTING_CONNECTION_UUID, nm_connection_get_uuid (connection), + NULL); + nmtst_assert_connection_equals (con_archetype, FALSE, connection, FALSE); + g_clear_object (&connection); +} + +static void +test_read_enum_property (void) +{ + NMConnection *connection; + NMSettingIPConfig *s_ip6; + GError *error = NULL; + gboolean success; + + connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error); + g_assert_no_error (error); + g_assert (connection); + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); + + /* IPv6 setting */ + s_ip6 = nm_connection_get_setting_ip6_config (connection); + g_assert (s_ip6); + g_assert_cmpint (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6)), ==, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR); + + g_object_unref (connection); +} + +static void +test_write_enum_property (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip6; + char *uuid; + gboolean success; + NMConnection *reread; + char *testfile = NULL; + GError *error = NULL; + pid_t owner_grp; + uid_t owner_uid; + + connection = nm_simple_connection_new (); + + /* Connection setting */ + + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + uuid = nm_utils_uuid_generate (); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "Test Write Enum Property", + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, + NULL); + g_free (uuid); + + /* Wired setting */ + s_wired = NM_SETTING_WIRED (nm_setting_wired_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_wired)); + + /* IP6 setting */ + s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_ip6)); + g_object_set (s_ip6, + NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_IP6_PRIVACY, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, + NULL); + + nmtst_connection_normalize (connection); + + /* Write out the connection */ + owner_uid = geteuid (); + owner_grp = getegid (); + success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error); + g_assert_no_error (error); + g_assert (success); + g_assert (testfile); + + /* Read the connection back in and compare it to the one we just wrote out */ + reread = nm_keyfile_plugin_connection_from_file (testfile, &error); + g_assert_no_error (error); + g_assert (reread); + + nmtst_assert_connection_equals (reread, FALSE, connection, FALSE); + + unlink (testfile); + g_free (testfile); + + g_object_unref (reread); + g_object_unref (connection); +} + +static void +test_read_flags_property (void) +{ + NMConnection *connection; + NMSettingGsm *s_gsm; + GError *error = NULL; + gboolean success; + + connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error); + g_assert_no_error (error); + g_assert (connection); + success = nm_connection_verify (connection, &error); + g_assert_no_error (error); + g_assert (success); + + /* GSM setting */ + s_gsm = nm_connection_get_setting_gsm (connection); + g_assert (s_gsm); + g_assert_cmpint (nm_setting_gsm_get_password_flags (s_gsm), ==, + NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED); + + g_object_unref (connection); +} + +static void +test_write_flags_property (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSetting *s_gsm; + char *uuid; + gboolean success; + NMConnection *reread; + char *testfile = NULL; + GError *error = NULL; + pid_t owner_grp; + uid_t owner_uid; + + connection = nm_simple_connection_new (); + + /* Connection setting */ + + s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + uuid = nm_utils_uuid_generate (); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "Test Write Flags Property", + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME, + NULL); + g_free (uuid); + + /* GSM setting */ + s_gsm = nm_setting_gsm_new (); + nm_connection_add_setting (connection, s_gsm); + g_object_set (s_gsm, + NM_SETTING_GSM_NUMBER, "#99*", + NM_SETTING_GSM_APN, "myapn", + NM_SETTING_GSM_USERNAME, "adfasdfasdf", + NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED, + NULL); + + nmtst_connection_normalize (connection); + + /* Write out the connection */ + owner_uid = geteuid (); + owner_grp = getegid (); + success = nm_keyfile_plugin_write_test_connection (connection, TEST_SCRATCH_DIR, owner_uid, owner_grp, &testfile, &error); + g_assert_no_error (error); + g_assert (success); + g_assert (testfile); + + /* Read the connection back in and compare it to the one we just wrote out */ + reread = nm_keyfile_plugin_connection_from_file (testfile, &error); + g_assert_no_error (error); + g_assert (reread); + + nmtst_assert_connection_equals (reread, FALSE, connection, FALSE); + + unlink (testfile); + g_free (testfile); + + g_object_unref (reread); + g_object_unref (connection); +} + NMTST_DEFINE (); int main (int argc, char **argv) { - char *base; - nmtst_init_assert_logging (&argc, &argv); /* The tests */ - test_read_valid_wired_connection (); - test_write_wired_connection (); + g_test_add_func ("/keyfile/test_read_valid_wired_connection ", test_read_valid_wired_connection); + g_test_add_func ("/keyfile/test_write_wired_connection ", test_write_wired_connection); + + g_test_add_func ("/keyfile/test_read_ip6_wired_connection ", test_read_ip6_wired_connection); + g_test_add_func ("/keyfile/test_write_ip6_wired_connection ", test_write_ip6_wired_connection); + + g_test_add_func ("/keyfile/test_read_wired_mac_case ", test_read_wired_mac_case); + g_test_add_func ("/keyfile/test_read_mac_old_format ", test_read_mac_old_format); + g_test_add_func ("/keyfile/test_read_mac_ib_old_format ", test_read_mac_ib_old_format); - test_read_ip6_wired_connection (); - test_write_ip6_wired_connection (); + g_test_add_func ("/keyfile/test_read_valid_wireless_connection ", test_read_valid_wireless_connection); + g_test_add_func ("/keyfile/test_write_wireless_connection ", test_write_wireless_connection); - test_read_wired_mac_case (); - test_read_mac_old_format (); - test_read_mac_ib_old_format (); + g_test_add_func ("/keyfile/test_read_string_ssid ", test_read_string_ssid); + g_test_add_func ("/keyfile/test_write_string_ssid ", test_write_string_ssid); - test_read_valid_wireless_connection (); - test_write_wireless_connection (); + g_test_add_func ("/keyfile/test_read_intlist_ssid ", test_read_intlist_ssid); + g_test_add_func ("/keyfile/test_write_intlist_ssid ", test_write_intlist_ssid); - test_read_string_ssid (); - test_write_string_ssid (); + g_test_add_func ("/keyfile/test_read_intlike_ssid ", test_read_intlike_ssid); + g_test_add_func ("/keyfile/test_write_intlike_ssid ", test_write_intlike_ssid); - test_read_intlist_ssid (); - test_write_intlist_ssid (); + g_test_add_func ("/keyfile/test_read_intlike_ssid_2 ", test_read_intlike_ssid_2); + g_test_add_func ("/keyfile/test_write_intlike_ssid_2 ", test_write_intlike_ssid_2); - test_read_intlike_ssid (); - test_write_intlike_ssid (); + g_test_add_func ("/keyfile/test_read_bt_dun_connection ", test_read_bt_dun_connection); + g_test_add_func ("/keyfile/test_write_bt_dun_connection ", test_write_bt_dun_connection); - test_read_intlike_ssid_2 (); - test_write_intlike_ssid_2 (); + g_test_add_func ("/keyfile/test_read_gsm_connection ", test_read_gsm_connection); + g_test_add_func ("/keyfile/test_write_gsm_connection ", test_write_gsm_connection); - test_read_bt_dun_connection (); - test_write_bt_dun_connection (); + g_test_add_func ("/keyfile/test_read_wired_8021x_tls_blob_connection ", test_read_wired_8021x_tls_blob_connection); + g_test_add_func ("/keyfile/test_read_wired_8021x_tls_bad_path_connection ", test_read_wired_8021x_tls_bad_path_connection); - test_read_gsm_connection (); - test_write_gsm_connection (); + g_test_add_func ("/keyfile/test_read_wired_8021x_tls_old_connection ", test_read_wired_8021x_tls_old_connection); + g_test_add_func ("/keyfile/test_read_wired_8021x_tls_new_connection ", test_read_wired_8021x_tls_new_connection); + g_test_add_func ("/keyfile/test_write_wired_8021x_tls_connection_path ", test_write_wired_8021x_tls_connection_path); + g_test_add_func ("/keyfile/test_write_wired_8021x_tls_connection_blob ", test_write_wired_8021x_tls_connection_blob); - test_read_wired_8021x_tls_blob_connection (); - test_read_wired_8021x_tls_bad_path_connection (); + g_test_add_func ("/keyfile/test_read_infiniband_connection ", test_read_infiniband_connection); + g_test_add_func ("/keyfile/test_write_infiniband_connection ", test_write_infiniband_connection); - test_read_wired_8021x_tls_old_connection (); - test_read_wired_8021x_tls_new_connection (); - test_write_wired_8021x_tls_connection_path (); - test_write_wired_8021x_tls_connection_blob (); + g_test_add_func ("/keyfile/test_read_bridge_main ", test_read_bridge_main); + g_test_add_func ("/keyfile/test_write_bridge_main ", test_write_bridge_main); + g_test_add_func ("/keyfile/test_read_bridge_component ", test_read_bridge_component); + g_test_add_func ("/keyfile/test_write_bridge_component ", test_write_bridge_component); - test_read_infiniband_connection (); - test_write_infiniband_connection (); + g_test_add_func ("/keyfile/test_read_new_wired_group_name ", test_read_new_wired_group_name); + g_test_add_func ("/keyfile/test_write_new_wired_group_name ", test_write_new_wired_group_name); + g_test_add_func ("/keyfile/test_read_new_wireless_group_names ", test_read_new_wireless_group_names); + g_test_add_func ("/keyfile/test_write_new_wireless_group_names ", test_write_new_wireless_group_names); - test_read_bridge_main (); - test_write_bridge_main (); - test_read_bridge_component (); - test_write_bridge_component (); + g_test_add_func ("/keyfile/test_read_missing_vlan_setting ", test_read_missing_vlan_setting); + g_test_add_func ("/keyfile/test_read_missing_id_uuid ", test_read_missing_id_uuid); - test_read_new_wired_group_name (); - test_write_new_wired_group_name (); - test_read_new_wireless_group_names (); - test_write_new_wireless_group_names (); + g_test_add_func ("/keyfile/test_read_minimal", test_read_minimal); + g_test_add_func ("/keyfile/test_read_minimal_slave", test_read_minimal_slave); - test_read_missing_vlan_setting (); + g_test_add_func ("/keyfile/test_read_enum_property ", test_read_enum_property); + g_test_add_func ("/keyfile/test_write_enum_property ", test_write_enum_property); + g_test_add_func ("/keyfile/test_read_flags_property ", test_read_flags_property); + g_test_add_func ("/keyfile/test_write_flags_property ", test_write_flags_property); - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; + return g_test_run (); } diff --git a/src/settings/plugins/keyfile/utils.c b/src/settings/plugins/keyfile/utils.c index e2bfc38c..3361d554 100644 --- a/src/settings/plugins/keyfile/utils.c +++ b/src/settings/plugins/keyfile/utils.c @@ -18,6 +18,8 @@ * (C) Copyright 2010 Red Hat, Inc. */ +#include "config.h" + #include <glib.h> #include <stdlib.h> #include <string.h> @@ -229,6 +231,7 @@ nm_keyfile_plugin_kf_set_##stype (GKeyFile *kf, \ DEFINE_KF_WRAPPER(string, gchar*, const gchar*); DEFINE_KF_WRAPPER(integer, gint, gint); +DEFINE_KF_WRAPPER(uint64, guint64, guint64); DEFINE_KF_WRAPPER(boolean, gboolean, gboolean); DEFINE_KF_WRAPPER(value, gchar*, const gchar*); diff --git a/src/settings/plugins/keyfile/utils.h b/src/settings/plugins/keyfile/utils.h index 9a2e485b..1a7c2502 100644 --- a/src/settings/plugins/keyfile/utils.h +++ b/src/settings/plugins/keyfile/utils.h @@ -61,6 +61,7 @@ void nm_keyfile_plugin_kf_set_##stype (GKeyFile *kf, \ set_ctype value); DEFINE_KF_WRAPPER_PROTO(string, gchar*, const gchar*) DEFINE_KF_WRAPPER_PROTO(integer, gint, gint) +DEFINE_KF_WRAPPER_PROTO(uint64, guint64, guint64) DEFINE_KF_WRAPPER_PROTO(boolean, gboolean, gboolean) DEFINE_KF_WRAPPER_PROTO(value, gchar*, const gchar*) diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c index 5f3ebe25..d342e3f7 100644 --- a/src/settings/plugins/keyfile/writer.c +++ b/src/settings/plugins/keyfile/writer.c @@ -19,7 +19,8 @@ * Copyright (C) 2008 - 2012 Red Hat, Inc. */ -#include <config.h> +#include "config.h" + #include <stdlib.h> #include <sys/stat.h> #include <unistd.h> @@ -40,7 +41,6 @@ #include <nm-utils.h> #include <string.h> #include <arpa/inet.h> -#include <netinet/ether.h> #include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" @@ -98,75 +98,77 @@ write_array_of_uint (GKeyFile *file, } static void -ip4_dns_writer (GKeyFile *file, - const char *keyfile_dir, - const char *uuid, - NMSetting *setting, - const char *key, - const GValue *value) +dns_writer (GKeyFile *file, + const char *keyfile_dir, + const char *uuid, + NMSetting *setting, + const char *key, + const GValue *value) { - GArray *array; char **list; - int i, num = 0; - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)); - - array = (GArray *) g_value_get_boxed (value); - if (!array || !array->len) - return; - - list = g_new0 (char *, array->len + 1); - - for (i = 0; i < array->len; i++) { - char *buf = g_new (char, INET_ADDRSTRLEN); - guint32 addr; - - addr = g_array_index (array, guint32, i); - nm_utils_inet4_ntop (addr, buf); - list[num++] = buf; + list = g_value_get_boxed (value); + if (list && list[0]) { + nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key, + (const char **) list, g_strv_length (list)); } - - nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key, (const char **) list, num); - g_strfreev (list); } static void -write_ip4_values (GKeyFile *file, - const char *setting_name, - GPtrArray *array, - gboolean is_route) +write_ip_values (GKeyFile *file, + const char *setting_name, + GPtrArray *array, + const char *gateway, + gboolean is_route) { GString *output; - int i; - guint32 addr, gw, plen, metric; + int family, i; + const char *addr, *gw; + guint32 plen, metric; char key_name[30], *key_name_idx; if (!array->len) return; + family = !strcmp (setting_name, NM_SETTING_IP4_CONFIG_SETTING_NAME) ? AF_INET : AF_INET6; + strcpy (key_name, is_route ? "route" : "address"); key_name_idx = key_name + strlen (key_name); output = g_string_sized_new (2*INET_ADDRSTRLEN + 10); for (i = 0; i < array->len; i++) { - GArray *tuple = g_ptr_array_index (array, i); + if (is_route) { + NMIPRoute *route = array->pdata[i]; + + addr = nm_ip_route_get_dest (route); + plen = nm_ip_route_get_prefix (route); + gw = nm_ip_route_get_next_hop (route); + metric = MAX (0, nm_ip_route_get_metric (route)); + } else { + NMIPAddress *address = array->pdata[i]; - addr = g_array_index (tuple, guint32, 0); - plen = g_array_index (tuple, guint32, 1); - gw = g_array_index (tuple, guint32, 2); - metric = is_route ? g_array_index (tuple, guint32, 3) : 0; + addr = nm_ip_address_get_address (address); + plen = nm_ip_address_get_prefix (address); + gw = i == 0 ? gateway : NULL; + metric = 0; + } g_string_set_size (output, 0); - g_string_append_printf (output, "%s/%u", - nm_utils_inet4_ntop (addr, NULL), - (unsigned) plen); + g_string_append_printf (output, "%s/%u", addr, plen); if (metric || gw) { /* Older versions of the plugin do not support the form * "a.b.c.d/plen,,metric", so, we always have to write the - * gateway, even if it's 0.0.0.0. - * The current version support reading of the above form. */ - g_string_append_c (output, ','); - g_string_append (output, nm_utils_inet4_ntop (gw, NULL)); + * gateway, even if there isn't one. + * The current version supports reading of the above form. + */ + if (!gw) { + if (family == AF_INET) + gw = "0.0.0.0"; + else + gw = "::"; + } + + g_string_append_printf (output, ",%s", gw); if (metric) g_string_append_printf (output, ",%lu", (unsigned long) metric); } @@ -178,21 +180,20 @@ write_ip4_values (GKeyFile *file, } static void -ip4_addr_writer (GKeyFile *file, - const char *keyfile_dir, - const char *uuid, - NMSetting *setting, - const char *key, - const GValue *value) +addr_writer (GKeyFile *file, + const char *keyfile_dir, + const char *uuid, + NMSetting *setting, + const char *key, + const GValue *value) { GPtrArray *array; const char *setting_name = nm_setting_get_name (setting); - - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT)); + const char *gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting)); array = (GPtrArray *) g_value_get_boxed (value); if (array && array->len) - write_ip4_values (file, setting_name, array, FALSE); + write_ip_values (file, setting_name, array, gateway, FALSE); } static void @@ -207,223 +208,30 @@ ip4_addr_label_writer (GKeyFile *file, } static void -ip4_route_writer (GKeyFile *file, - const char *keyfile_dir, - const char *uuid, - NMSetting *setting, - const char *key, - const GValue *value) -{ - GPtrArray *array; - const char *setting_name = nm_setting_get_name (setting); - - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT)); - - array = (GPtrArray *) g_value_get_boxed (value); - if (array && array->len) - write_ip4_values (file, setting_name, array, TRUE); -} - -static void -ip6_dns_writer (GKeyFile *file, +gateway_writer (GKeyFile *file, const char *keyfile_dir, const char *uuid, NMSetting *setting, const char *key, const GValue *value) { - GPtrArray *array; - GByteArray *byte_array; - char **list; - int i, num = 0; - - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR)); - - array = (GPtrArray *) g_value_get_boxed (value); - if (!array || !array->len) - return; - - list = g_new0 (char *, array->len + 1); - - for (i = 0; i < array->len; i++) { - char *buf = g_new (char, INET6_ADDRSTRLEN); - - byte_array = g_ptr_array_index (array, i); - nm_utils_inet6_ntop ((const struct in6_addr *) byte_array->data, buf); - list[num++] = buf; - } - - nm_keyfile_plugin_kf_set_string_list (file, nm_setting_get_name (setting), key, (const char **) list, num); - g_strfreev (list); -} - -static void -ip6_array_to_addr (GValueArray *values, - guint32 idx, - char *buf, - struct in6_addr *out_addr) -{ - GByteArray *byte_array; - GValue *addr_val; - const struct in6_addr *addr; - - addr_val = g_value_array_get_nth (values, idx); - byte_array = g_value_get_boxed (addr_val); - addr = (const struct in6_addr *) byte_array->data; - - nm_utils_inet6_ntop (addr, buf); - - if (out_addr) - *out_addr = *addr; -} - -static char * -ip6_array_to_addr_prefix (GValueArray *values, gboolean force_write_gateway) -{ - GValue *prefix_val; - char *ret = NULL; - GString *ip6_str; - char buf[INET6_ADDRSTRLEN]; - struct in6_addr addr; - - /* address */ - ip6_array_to_addr (values, 0, buf, NULL); - - /* Enough space for the address, '/', and the prefix */ - ip6_str = g_string_sized_new ((INET6_ADDRSTRLEN * 2) + 5); - - /* prefix */ - g_string_append (ip6_str, buf); - prefix_val = g_value_array_get_nth (values, 1); - g_string_append_printf (ip6_str, "/%u", g_value_get_uint (prefix_val)); - - ip6_array_to_addr (values, 2, buf, &addr); - if (force_write_gateway || !IN6_IS_ADDR_UNSPECIFIED (&addr)) - g_string_append_printf (ip6_str, ",%s", buf); - - ret = ip6_str->str; - g_string_free (ip6_str, FALSE); - - return ret; -} - -static void -ip6_addr_writer (GKeyFile *file, - const char *keyfile_dir, - const char *uuid, - NMSetting *setting, - const char *key, - const GValue *value) -{ - GPtrArray *array; - const char *setting_name = nm_setting_get_name (setting); - int i, j; - - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS)); - - array = (GPtrArray *) g_value_get_boxed (value); - if (!array || !array->len) - return; - - for (i = 0, j = 1; i < array->len; i++) { - GValueArray *values = g_ptr_array_index (array, i); - char *key_name, *ip6_addr; - - if (values->n_values != 3) { - nm_log_warn (LOGD_SETTINGS, "%s: error writing IP6 address %d (address array " - "length %d is not 3)", __func__, i, values->n_values); - continue; - } - - /* we allow omitting the gateway if it's :: */ - ip6_addr = ip6_array_to_addr_prefix (values, FALSE); - /* Write it out */ - key_name = g_strdup_printf ("address%d", j++); - nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, ip6_addr); - g_free (key_name); - g_free (ip6_addr); - } + /* skip */ } static void -ip6_route_writer (GKeyFile *file, - const char *keyfile_dir, - const char *uuid, - NMSetting *setting, - const char *key, - const GValue *value) +route_writer (GKeyFile *file, + const char *keyfile_dir, + const char *uuid, + NMSetting *setting, + const char *key, + const GValue *value) { GPtrArray *array; const char *setting_name = nm_setting_get_name (setting); - GString *output; - int i, j; - - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE)); array = (GPtrArray *) g_value_get_boxed (value); - if (!array || !array->len) - return; - - for (i = 0, j = 1; i < array->len; i++) { - GValueArray *values = g_ptr_array_index (array, i); - char *key_name; - char *addr_str; - guint metric; - - output = g_string_new (""); - - /* Metric */ - value = g_value_array_get_nth (values, 3); - metric = g_value_get_uint (value); - - /* Address, prefix and next hop - * We allow omitting the gateway ::, if we also omit the metric - * and force writing of the gateway, if we add a non zero metric. - * The current version of the reader also supports the syntax - * "a:b:c::/plen,,metric" for a gateway ::. - * As older versions of the plugin, cannot read this form, - * we always write the gateway, whenever we also write the metric. - * But if possible, we omit them both (",::,0") or only the metric - * (",0"). - **/ - addr_str = ip6_array_to_addr_prefix (values, metric != 0); - g_string_append (output, addr_str); - g_free (addr_str); - - if (metric != 0) - g_string_append_printf (output, ",%u", metric); - - /* Write it out */ - key_name = g_strdup_printf ("route%d", j++); - nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, output->str); - g_free (key_name); - - g_string_free (output, TRUE); - } -} - - -static void -mac_address_writer (GKeyFile *file, - const char *keyfile_dir, - const char *uuid, - NMSetting *setting, - const char *key, - const GValue *value) -{ - GByteArray *array; - const char *setting_name = nm_setting_get_name (setting); - char *mac; - - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)); - - array = (GByteArray *) g_value_get_boxed (value); - if (!array || !array->len) - return; - - mac = nm_utils_hwaddr_ntoa_len (array->data, array->len); - nm_keyfile_plugin_kf_set_string (file, setting_name, key, mac); - g_free (mac); + if (array && array->len) + write_ip_values (file, setting_name, array, NULL, TRUE); } static void @@ -472,24 +280,29 @@ ssid_writer (GKeyFile *file, const char *key, const GValue *value) { - GByteArray *array; + GBytes *bytes; + const guint8 *ssid_data; + gsize ssid_len; const char *setting_name = nm_setting_get_name (setting); gboolean new_format = TRUE; unsigned int semicolons = 0; int i, *tmp_array; char *ssid; - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)); + g_return_if_fail (G_VALUE_HOLDS (value, G_TYPE_BYTES)); - array = (GByteArray *) g_value_get_boxed (value); - if (!array || !array->len) + bytes = g_value_get_boxed (value); + if (!bytes) + return; + ssid_data = g_bytes_get_data (bytes, &ssid_len); + if (ssid_len == 0) return; /* Check whether each byte is printable. If not, we have to use an * integer list, otherwise we can just use a string. */ - for (i = 0; i < array->len; i++) { - char c = array->data[i] & 0xFF; + for (i = 0; i < ssid_len; i++) { + char c = ssid_data[i] & 0xFF; if (!g_ascii_isprint (c)) { new_format = FALSE; break; @@ -499,26 +312,26 @@ ssid_writer (GKeyFile *file, } if (new_format) { - ssid = g_malloc0 (array->len + semicolons + 1); + ssid = g_malloc0 (ssid_len + semicolons + 1); if (semicolons == 0) - memcpy (ssid, array->data, array->len); + memcpy (ssid, ssid_data, ssid_len); else { /* Escape semicolons with backslashes to make strings * containing ';', such as '16;17;' unambiguous */ int j = 0; - for (i = 0; i < array->len; i++) { - if (array->data[i] == ';') + for (i = 0; i < ssid_len; i++) { + if (ssid_data[i] == ';') ssid[j++] = '\\'; - ssid[j++] = array->data[i]; + ssid[j++] = ssid_data[i]; } } nm_keyfile_plugin_kf_set_string (file, setting_name, key, ssid); g_free (ssid); } else { - tmp_array = g_new (gint, array->len); - for (i = 0; i < array->len; i++) - tmp_array[i] = (int) array->data[i]; - nm_keyfile_plugin_kf_set_integer_list (file, setting_name, key, tmp_array, array->len); + tmp_array = g_new (gint, ssid_len); + for (i = 0; i < ssid_len; i++) + tmp_array[i] = (int) ssid_data[i]; + nm_keyfile_plugin_kf_set_integer_list (file, setting_name, key, tmp_array, ssid_len); g_free (tmp_array); } } @@ -555,7 +368,7 @@ typedef struct ObjectType { NMSetting8021xCKScheme (*scheme_func) (NMSetting8021x *setting); NMSetting8021xCKFormat (*format_func) (NMSetting8021x *setting); const char * (*path_func) (NMSetting8021x *setting); - const GByteArray * (*blob_func) (NMSetting8021x *setting); + GBytes * (*blob_func) (NMSetting8021x *setting); } ObjectType; static const ObjectType objtypes[10] = { @@ -612,7 +425,8 @@ static const ObjectType objtypes[10] = { static gboolean write_cert_key_file (const char *path, - const GByteArray *data, + const guint8 *data, + gsize data_len, GError **error) { char *tmppath; @@ -627,7 +441,7 @@ write_cert_key_file (const char *path, errno = 0; fd = mkstemp (tmppath); if (fd < 0) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not create temporary file for '%s': %d", path, errno); goto out; @@ -638,18 +452,18 @@ write_cert_key_file (const char *path, if (fchmod (fd, S_IRUSR | S_IWUSR) != 0) { close (fd); unlink (tmppath); - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not set permissions for temporary file '%s': %d", path, errno); goto out; } errno = 0; - written = write (fd, data->data, data->len); - if (written != data->len) { + written = write (fd, data, data_len); + if (written != data_len) { close (fd); unlink (tmppath); - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not write temporary file for '%s': %d", path, errno); goto out; @@ -662,7 +476,7 @@ write_cert_key_file (const char *path, success = TRUE; else { unlink (tmppath); - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "Could not rename temporary file to '%s': %d", path, errno); } @@ -714,13 +528,16 @@ cert_writer (GKeyFile *file, nm_keyfile_plugin_kf_set_string (file, setting_name, key, path); } else if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) { - const GByteArray *blob; + GBytes *blob; + const guint8 *blob_data; + gsize blob_len; gboolean success; GError *error = NULL; char *new_path; blob = objtype->blob_func (NM_SETTING_802_1X (setting)); g_assert (blob); + blob_data = g_bytes_get_data (blob, &blob_len); if (objtype->format_func) { /* Get the extension for a private key */ @@ -729,7 +546,7 @@ cert_writer (GKeyFile *file, ext = "p12"; } else { /* DER or PEM format certificate? */ - if (blob->len > 2 && blob->data[0] == 0x30 && blob->data[1] == 0x82) + if (blob_len > 2 && blob_data[0] == 0x30 && blob_data[1] == 0x82) ext = "der"; } @@ -739,7 +556,7 @@ cert_writer (GKeyFile *file, new_path = g_strdup_printf ("%s/%s-%s.%s", keyfile_dir, uuid, objtype->suffix, ext); g_assert (new_path); - success = write_cert_key_file (new_path, blob, &error); + success = write_cert_key_file (new_path, blob_data, blob_len, &error); if (success) { /* Write the path value to the keyfile */ nm_keyfile_plugin_kf_set_string (file, setting_name, key, new_path); @@ -774,54 +591,33 @@ static KeyWriter key_writers[] = { { NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE, setting_alias_writer }, - { NM_SETTING_BRIDGE_SETTING_NAME, - NM_SETTING_BRIDGE_MAC_ADDRESS, - mac_address_writer }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ADDRESSES, - ip4_addr_writer }, + NM_SETTING_IP_CONFIG_ADDRESSES, + addr_writer }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, "address-labels", ip4_addr_label_writer }, { NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ADDRESSES, - ip6_addr_writer }, + NM_SETTING_IP_CONFIG_ADDRESSES, + addr_writer }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_ROUTES, - ip4_route_writer }, + NM_SETTING_IP_CONFIG_GATEWAY, + gateway_writer }, { NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_ROUTES, - ip6_route_writer }, + NM_SETTING_IP_CONFIG_GATEWAY, + gateway_writer }, { NM_SETTING_IP4_CONFIG_SETTING_NAME, - NM_SETTING_IP4_CONFIG_DNS, - ip4_dns_writer }, + NM_SETTING_IP_CONFIG_ROUTES, + route_writer }, { NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_IP6_CONFIG_DNS, - ip6_dns_writer }, - { NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_MAC_ADDRESS, - mac_address_writer }, - { NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_WIRED_CLONED_MAC_ADDRESS, - mac_address_writer }, - { NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_MAC_ADDRESS, - mac_address_writer }, - { NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, - mac_address_writer }, - { NM_SETTING_WIRELESS_SETTING_NAME, - NM_SETTING_WIRELESS_BSSID, - mac_address_writer }, - { NM_SETTING_BLUETOOTH_SETTING_NAME, - NM_SETTING_BLUETOOTH_BDADDR, - mac_address_writer }, - { NM_SETTING_INFINIBAND_SETTING_NAME, - NM_SETTING_INFINIBAND_MAC_ADDRESS, - mac_address_writer }, - { NM_SETTING_WIMAX_SETTING_NAME, - NM_SETTING_WIMAX_MAC_ADDRESS, - mac_address_writer }, + NM_SETTING_IP_CONFIG_ROUTES, + route_writer }, + { NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP_CONFIG_DNS, + dns_writer }, + { NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP_CONFIG_DNS, + dns_writer }, { NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID, ssid_writer }, @@ -896,7 +692,8 @@ write_setting_value (NMSetting *setting, if (pspec && (pspec->flags & NM_SETTING_PARAM_SECRET) && !NM_IS_SETTING_VPN (setting)) { NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - nm_setting_get_secret_flags (setting, key, &secret_flags, NULL); + if (!nm_setting_get_secret_flags (setting, key, &secret_flags, NULL)) + g_assert_not_reached (); if (secret_flags != NM_SETTING_SECRET_FLAG_NONE) return; } @@ -926,49 +723,53 @@ write_setting_value (NMSetting *setting, numstr = g_strdup_printf ("%" G_GUINT64_FORMAT, g_value_get_uint64 (value)); nm_keyfile_plugin_kf_set_value (info->keyfile, setting_name, key, numstr); g_free (numstr); + } else if (type == G_TYPE_INT64) { + char *numstr; + + numstr = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (value)); + nm_keyfile_plugin_kf_set_value (info->keyfile, setting_name, key, numstr); + g_free (numstr); } else if (type == G_TYPE_BOOLEAN) { nm_keyfile_plugin_kf_set_boolean (info->keyfile, setting_name, key, g_value_get_boolean (value)); } else if (type == G_TYPE_CHAR) { nm_keyfile_plugin_kf_set_integer (info->keyfile, setting_name, key, (int) g_value_get_schar (value)); - } else if (type == DBUS_TYPE_G_UCHAR_ARRAY) { - GByteArray *array; + } else if (type == G_TYPE_BYTES) { + GBytes *bytes; + const guint8 *data; + gsize len = 0; - array = (GByteArray *) g_value_get_boxed (value); - if (array && array->len > 0) { + bytes = g_value_get_boxed (value); + data = bytes ? g_bytes_get_data (bytes, &len) : NULL; + + if (data != NULL && len > 0) { int *tmp_array; int i; - tmp_array = g_new (gint, array->len); - for (i = 0; i < array->len; i++) - tmp_array[i] = (int) array->data[i]; + tmp_array = g_new (gint, len); + for (i = 0; i < len; i++) + tmp_array[i] = (int) data[i]; - nm_keyfile_plugin_kf_set_integer_list (info->keyfile, setting_name, key, tmp_array, array->len); + nm_keyfile_plugin_kf_set_integer_list (info->keyfile, setting_name, key, tmp_array, len); g_free (tmp_array); } - } else if (type == DBUS_TYPE_G_LIST_OF_STRING) { - GSList *list; - GSList *iter; - - list = (GSList *) g_value_get_boxed (value); - if (list) { - char **array; - int i = 0; + } else if (type == G_TYPE_STRV) { + char **array; - array = g_new (char *, g_slist_length (list)); - for (iter = list; iter; iter = iter->next) - array[i++] = iter->data; - - nm_keyfile_plugin_kf_set_string_list (info->keyfile, setting_name, key, (const gchar **const) array, i); - g_free (array); - } - } else if (type == DBUS_TYPE_G_MAP_OF_STRING) { + array = (char **) g_value_get_boxed (value); + nm_keyfile_plugin_kf_set_string_list (info->keyfile, setting_name, key, (const gchar **const) array, g_strv_length (array)); + } else if (type == G_TYPE_HASH_TABLE) { write_hash_of_string (info->keyfile, setting, key, value); - } else if (type == DBUS_TYPE_G_UINT_ARRAY) { + } else if (type == G_TYPE_ARRAY) { if (!write_array_of_uint (info->keyfile, setting, key, value)) { nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (write) '%s/%s' : '%s'", setting_name, key, g_type_name (type)); } - } else { + } else if (G_VALUE_HOLDS_FLAGS (value)) { + /* Flags are guint but GKeyFile has no uint reader, just uint64 */ + nm_keyfile_plugin_kf_set_uint64 (info->keyfile, setting_name, key, (guint64) g_value_get_flags (value)); + } else if (G_VALUE_HOLDS_ENUM (value)) + nm_keyfile_plugin_kf_set_integer (info->keyfile, setting_name, key, (gint) g_value_get_enum (value)); + else { nm_log_warn (LOGD_SETTINGS, "Unhandled setting property type (write) '%s/%s' : '%s'", setting_name, key, g_type_name (type)); } @@ -1021,11 +822,7 @@ _internal_write_connection (NMConnection *connection, } id = nm_connection_get_id (connection); - if (!id) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, - "%s.%d: connection had no ID", __FILE__, __LINE__); - return FALSE; - } + g_assert (id && *id); info.keyfile = key_file = g_key_file_new (); info.keyfile_dir = keyfile_dir; @@ -1065,7 +862,7 @@ _internal_write_connection (NMConnection *connection, * is edited to contain the same ID as the other one. * Give up. */ - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "%s.%d: could not find suitable keyfile file name (%s already used)", __FILE__, __LINE__, path); g_free (path); @@ -1082,7 +879,7 @@ _internal_write_connection (NMConnection *connection, g_file_set_contents (path, data, len, &local_err); if (local_err) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "%s.%d: error writing to file '%s': %s", __FILE__, __LINE__, path, local_err->message); g_error_free (local_err); @@ -1091,13 +888,13 @@ _internal_write_connection (NMConnection *connection, } if (chown (path, owner_uid, owner_grp) < 0) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "%s.%d: error chowning '%s': %d", __FILE__, __LINE__, path, errno); unlink (path); } else { if (chmod (path, S_IRUSR | S_IWUSR) < 0) { - g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "%s.%d: error setting permissions on '%s': %d", __FILE__, __LINE__, path, errno); unlink (path); |