diff options
| author | Michael Biebl <biebl@debian.org> | 2014-07-06 02:16:10 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2014-07-06 02:16:10 +0200 |
| commit | 33491bc4279481db8ae47213e34a6d695a0e8830 (patch) | |
| tree | 097d2b0fdff3fae6885381ae5e57a182cd8cbbba /src/settings/plugins/ifupdown | |
| parent | 59c3714a494c3b3765657c0551ad82842d98a7d2 (diff) | |
Imported Upstream version 0.9.10.0 upstream/0.9.10.0
Diffstat (limited to 'src/settings/plugins/ifupdown')
| -rw-r--r-- | src/settings/plugins/ifupdown/Makefile.am | 13 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/Makefile.in | 58 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/interface_parser.c | 96 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/nm-ifupdown-connection.c | 17 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/parser.c | 125 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/plugin.c | 131 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/Makefile.am | 22 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/Makefile.in | 198 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/test-ifupdown.c | 138 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/test20-source-stanza | 1 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/test20-source-stanza.eth0 | 2 | ||||
| -rw-r--r-- | src/settings/plugins/ifupdown/tests/test20-source-stanza.eth1 | 2 |
12 files changed, 531 insertions, 272 deletions
diff --git a/src/settings/plugins/ifupdown/Makefile.am b/src/settings/plugins/ifupdown/Makefile.am index ae07f7b0..fd98f8fe 100644 --- a/src/settings/plugins/ifupdown/Makefile.am +++ b/src/settings/plugins/ifupdown/Makefile.am @@ -1,15 +1,23 @@ SUBDIRS = . tests +@GNOME_CODE_COVERAGE_RULES@ + 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 \ + -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ + $(POLKIT_CFLAGS) \ + $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" noinst_LTLIBRARIES = libifupdown-io.la @@ -32,14 +40,9 @@ libnm_settings_plugin_ifupdown_la_SOURCES = \ plugin.c \ plugin.h -libnm_settings_plugin_ifupdown_la_CPPFLAGS = \ - $(GUDEV_CFLAGS) \ - $(AM_CPPFLAGS) - libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version libnm_settings_plugin_ifupdown_la_LIBADD = \ $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/src/logging/libnm-logging.la \ libifupdown-io.la \ $(GLIB_LIBS) \ $(GUDEV_LIBS) diff --git a/src/settings/plugins/ifupdown/Makefile.in b/src/settings/plugins/ifupdown/Makefile.in index 05629ea0..50d4ca08 100644 --- a/src/settings/plugins/ifupdown/Makefile.in +++ b/src/settings/plugins/ifupdown/Makefile.in @@ -82,7 +82,8 @@ subdir = src/settings/plugins/ifupdown 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/compiler_warnings.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 \ @@ -139,12 +140,10 @@ 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 \ - $(top_builddir)/src/logging/libnm-logging.la libifupdown-io.la \ + $(top_builddir)/libnm-util/libnm-util.la libifupdown-io.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) am_libnm_settings_plugin_ifupdown_la_OBJECTS = \ - libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo \ - libnm_settings_plugin_ifupdown_la-plugin.lo + nm-ifupdown-connection.lo plugin.lo libnm_settings_plugin_ifupdown_la_OBJECTS = \ $(am_libnm_settings_plugin_ifupdown_la_OBJECTS) libnm_settings_plugin_ifupdown_la_LINK = $(LIBTOOL) $(AM_V_lt) \ @@ -281,12 +280,15 @@ 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@ @@ -311,7 +313,6 @@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GREP = @GREP@ GTKDOC_CHECK = @GTKDOC_CHECK@ -GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ GTKDOC_MKPDF = @GTKDOC_MKPDF@ @@ -356,12 +357,16 @@ 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@ @@ -378,6 +383,8 @@ MOC = @MOC@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ +NEWT_CFLAGS = @NEWT_CFLAGS@ +NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ @@ -405,11 +412,16 @@ 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@ @@ -424,6 +436,7 @@ UDEV_BASE_DIR = @UDEV_BASE_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@ @@ -486,6 +499,7 @@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ systemdsystemunitdir = @systemdsystemunitdir@ target_alias = @target_alias@ @@ -496,17 +510,24 @@ with_dhclient = @with_dhclient@ with_dhcpcd = @with_dhcpcd@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ +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 \ + -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ + $(POLKIT_CFLAGS) \ + $(GUDEV_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" noinst_LTLIBRARIES = libifupdown-io.la @@ -527,14 +548,9 @@ libnm_settings_plugin_ifupdown_la_SOURCES = \ plugin.c \ plugin.h -libnm_settings_plugin_ifupdown_la_CPPFLAGS = \ - $(GUDEV_CFLAGS) \ - $(AM_CPPFLAGS) - libnm_settings_plugin_ifupdown_la_LDFLAGS = -module -avoid-version libnm_settings_plugin_ifupdown_la_LIBADD = \ $(top_builddir)/libnm-util/libnm-util.la \ - $(top_builddir)/src/logging/libnm-logging.la \ libifupdown-io.la \ $(GLIB_LIBS) \ $(GUDEV_LIBS) @@ -633,9 +649,9 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface_parser.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-ifupdown-connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parser.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -658,20 +674,6 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< -libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo: nm-ifupdown-connection.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Tpo -c -o libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo `test -f 'nm-ifupdown-connection.c' || echo '$(srcdir)/'`nm-ifupdown-connection.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Tpo $(DEPDIR)/libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nm-ifupdown-connection.c' object='libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifupdown_la-nm-ifupdown-connection.lo `test -f 'nm-ifupdown-connection.c' || echo '$(srcdir)/'`nm-ifupdown-connection.c - -libnm_settings_plugin_ifupdown_la-plugin.lo: plugin.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm_settings_plugin_ifupdown_la-plugin.lo -MD -MP -MF $(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Tpo -c -o libnm_settings_plugin_ifupdown_la-plugin.lo `test -f 'plugin.c' || echo '$(srcdir)/'`plugin.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Tpo $(DEPDIR)/libnm_settings_plugin_ifupdown_la-plugin.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='plugin.c' object='libnm_settings_plugin_ifupdown_la-plugin.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_settings_plugin_ifupdown_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm_settings_plugin_ifupdown_la-plugin.lo `test -f 'plugin.c' || echo '$(srcdir)/'`plugin.c - mostlyclean-libtool: -rm -f *.lo @@ -960,6 +962,8 @@ uninstall-am: uninstall-pkglibLTLIBRARIES 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/ifupdown/interface_parser.c b/src/settings/plugins/ifupdown/interface_parser.c index 38ed1479..ee233c93 100644 --- a/src/settings/plugins/ifupdown/interface_parser.c +++ b/src/settings/plugins/ifupdown/interface_parser.c @@ -25,7 +25,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <wordexp.h> +#include <libgen.h> #include "nm-utils.h" +#include "nm-logging.h" if_block* first; if_block* last; @@ -96,21 +99,33 @@ static char *join_values_with_spaces(char *dst, char **src) return(dst); } -void ifparser_init (const char *eni_file, int quiet) +static void _ifparser_source (const char *path, const char *en_dir, int quiet); + +static void +_recursive_ifparser (const char *eni_file, int quiet) { - FILE *inp = fopen (eni_file, "r"); + FILE *inp; char line[255]; int skip_to_block = 1; int skip_long_line = 0; int offs = 0; + // Check if interfaces file exists and open it + if (!g_file_test (eni_file, G_FILE_TEST_EXISTS)) { + if (!quiet) + nm_log_warn (LOGD_SETTINGS, "interfaces file %s doesn't exist\n", eni_file); + return; + } + inp = fopen (eni_file, "r"); if (inp == NULL) { if (!quiet) - g_warning ("Error: Can't open %s\n", eni_file); + nm_log_warn (LOGD_SETTINGS, "Can't open %s\n", eni_file); return; } + if (!quiet) + nm_log_info (LOGD_SETTINGS, " interface-parser: parsing file %s\n", eni_file); + - first = last = NULL; while (!feof(inp)) { char *token[128]; // 255 chars can only be split into 127 tokens @@ -128,7 +143,7 @@ void ifparser_init (const char *eni_file, int quiet) if (!feof(inp) && len > 0 && line[len-1] != '\n') { if (!skip_long_line) { if (!quiet) - g_message ("Error: Skipping over-long-line '%s...'\n", line); + nm_log_warn (LOGD_SETTINGS, "Skipping over-long-line '%s...'\n", line); } skip_long_line = 1; continue; @@ -168,22 +183,23 @@ void ifparser_init (const char *eni_file, int quiet) if (toknum < 2) { if (!quiet) { - g_message ("Error: Can't parse interface line '%s'\n", - join_values_with_spaces(value, token)); + nm_log_warn (LOGD_SETTINGS, "Can't parse interface line '%s'\n", + join_values_with_spaces(value, token)); } skip_to_block = 1; continue; } - // There are four different stanzas: - // iface, mapping, auto and allow-*. Create a block for each of them. + // There are five different stanzas: + // iface, mapping, auto, allow-* and source. + // Create a block for each of them except source. // iface stanza takes at least 3 parameters if (strcmp(token[0], "iface") == 0) { if (toknum < 4) { if (!quiet) { - g_message ("Error: Can't parse iface line '%s'\n", - join_values_with_spaces(value, token)); + nm_log_warn (LOGD_SETTINGS, "Can't parse iface line '%s'\n", + join_values_with_spaces(value, token)); } continue; } @@ -211,17 +227,71 @@ void ifparser_init (const char *eni_file, int quiet) add_block(token[0], token[i]); skip_to_block = 0; } + // source stanza takes one or more filepaths as parameters + else if (strcmp(token[0], "source") == 0) { + int i; + char *en_dir; + + skip_to_block = 0; + + if (toknum == 1) { + if (!quiet) + nm_log_warn (LOGD_SETTINGS, "Invalid source line without parameters\n"); + continue; + } + + en_dir = g_path_get_dirname (eni_file); + for (i = 1; i < toknum; ++i) + _ifparser_source (token[i], en_dir, quiet); + g_free (en_dir); + } else { if (skip_to_block) { if (!quiet) { - g_message ("Error: ignoring out-of-block data '%s'\n", - join_values_with_spaces(value, token)); + nm_log_warn (LOGD_SETTINGS, "ignoring out-of-block data '%s'\n", + join_values_with_spaces(value, token)); } } else add_data(token[0], join_values_with_spaces(value, token + 1)); } } fclose(inp); + + if (!quiet) + nm_log_info (LOGD_SETTINGS, " interface-parser: finished parsing file %s\n", eni_file); +} + +static void +_ifparser_source (const char *path, const char *en_dir, int quiet) +{ + char *abs_path; + wordexp_t we; + uint i; + + if (g_path_is_absolute (path)) + abs_path = g_strdup (path); + else + abs_path = g_build_filename (en_dir, path, NULL); + + if (!quiet) + nm_log_info (LOGD_SETTINGS, " interface-parser: source line includes interfaces file(s) %s\n", abs_path); + + /* ifupdown uses WRDE_NOCMD for wordexp. */ + if (wordexp (abs_path, &we, WRDE_NOCMD)) { + if (!quiet) + nm_log_warn (LOGD_SETTINGS, "word expansion for %s failed\n", abs_path); + } else { + for (i = 0; i < we.we_wordc; i++) + _recursive_ifparser (we.we_wordv[i], quiet); + wordfree (&we); + } + g_free (abs_path); +} + +void ifparser_init (const char *eni_file, int quiet) +{ + first = last = NULL; + _recursive_ifparser (eni_file, quiet); } void _destroy_data(if_data *ifd) diff --git a/src/settings/plugins/ifupdown/nm-ifupdown-connection.c b/src/settings/plugins/ifupdown/nm-ifupdown-connection.c index 0cc73b34..4e13a2b8 100644 --- a/src/settings/plugins/ifupdown/nm-ifupdown-connection.c +++ b/src/settings/plugins/ifupdown/nm-ifupdown-connection.c @@ -29,6 +29,7 @@ #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" @@ -60,7 +61,7 @@ nm_ifupdown_connection_new (if_block *block) static gboolean supports_secrets (NMSettingsConnection *connection, const char *setting_name) { - PLUGIN_PRINT ("SCPlugin-Ifupdown", "supports_secrets() for setting_name: '%s'", setting_name); + nm_log_info (LOGD_SETTINGS, "supports_secrets() for setting_name: '%s'", setting_name); return (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) == 0); } @@ -84,20 +85,20 @@ constructor (GType type, priv = NM_IFUPDOWN_CONNECTION_GET_PRIVATE (object); if (!priv) { - g_warning ("%s.%d - no private instance.", __FILE__, __LINE__); + nm_log_warn (LOGD_SETTINGS, "%s.%d - no private instance.", __FILE__, __LINE__); goto err; } if (!priv->ifblock) { - g_warning ("(ifupdown) ifblock not provided to constructor."); + nm_log_warn (LOGD_SETTINGS, "(ifupdown) ifblock not provided to constructor."); goto err; } if (!ifupdown_update_connection_from_if_block (NM_CONNECTION (object), priv->ifblock, &error)) { - g_warning ("%s.%d - invalid connection read from /etc/network/interfaces: (%d) %s", - __FILE__, - __LINE__, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + nm_log_warn (LOGD_SETTINGS, "%s.%d - invalid connection read from /etc/network/interfaces: (%d) %s", + __FILE__, + __LINE__, + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); goto err; } diff --git a/src/settings/plugins/ifupdown/parser.c b/src/settings/plugins/ifupdown/parser.c index d81fd84d..91ed3e21 100644 --- a/src/settings/plugins/ifupdown/parser.c +++ b/src/settings/plugins/ifupdown/parser.c @@ -36,6 +36,7 @@ #include <nm-setting-8021x.h> #include <nm-system-config-interface.h> #include <nm-utils.h> +#include <nm-logging.h> #include <ctype.h> #include "parser.h" @@ -67,9 +68,7 @@ _ifupdownplugin_guess_connection_type (if_block *block) if(!ret_type) ret_type = NM_SETTING_WIRED_SETTING_NAME; - PLUGIN_PRINT("SCPluginIfupdown", - "guessed connection type (%s) = %s", - block->name, ret_type); + nm_log_info (LOGD_SETTINGS, "guessed connection type (%s) = %s", block->name, ret_type); return ret_type; } @@ -111,15 +110,14 @@ update_wireless_setting_from_if_block(NMConnection *connection, return; } - PLUGIN_PRINT ("SCPlugin-Ifupdown", "update wireless settings (%s).", block->name); + nm_log_info (LOGD_SETTINGS, "update wireless settings (%s).", block->name); wireless_setting = NM_SETTING_WIRELESS(nm_setting_wireless_new()); while(curr) { if(strlen(curr->key) > wireless_l && !strncmp("wireless-", curr->key, wireless_l)) { const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l); - PLUGIN_PRINT ("SCPlugin-Ifupdown", "wireless setting key: %s='%s'", - newkey, curr->data); + nm_log_info (LOGD_SETTINGS, "wireless setting key: %s='%s'", newkey, curr->data); if(newkey && !strcmp("ssid", newkey)) { GByteArray *ssid; gint len = strlen(curr->data); @@ -128,7 +126,7 @@ update_wireless_setting_from_if_block(NMConnection *connection, g_byte_array_append (ssid, (const guint8 *) curr->data, len); g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); g_byte_array_free (ssid, TRUE); - PLUGIN_PRINT("SCPlugin-Ifupdown", "setting wireless ssid = %d", len); + nm_log_info (LOGD_SETTINGS, "setting wireless ssid = %d", len); } else { g_object_set(wireless_setting, newkey, curr->data, @@ -146,13 +144,13 @@ update_wireless_setting_from_if_block(NMConnection *connection, g_byte_array_append (ssid, (const guint8 *) curr->data, len); g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); g_byte_array_free (ssid, TRUE); - PLUGIN_PRINT("SCPlugin-Ifupdown", "setting wpa ssid = %d", len); + nm_log_info (LOGD_SETTINGS, "setting wpa ssid = %d", len); } else if(newkey) { g_object_set(wireless_setting, newkey, curr->data, NULL); - PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa newkey(%s)=data(%s)", newkey, curr->data); + nm_log_info (LOGD_SETTINGS, "setting wpa newkey(%s)=data(%s)", newkey, curr->data); } } curr = curr->next; @@ -240,9 +238,7 @@ string_to_glist_of_strings(const gchar* data) static void slist_free_all(gpointer slist) { - GSList *list = (GSList *) slist; - g_slist_foreach (list, (GFunc) g_free, NULL); - g_slist_free (list); + g_slist_free_full ((GSList *) slist, g_free); } static void @@ -315,7 +311,7 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, s_wireless = nm_connection_get_setting_wireless(connection); g_return_if_fail(s_wireless); - PLUGIN_PRINT ("SCPlugin-Ifupdown","update wireless security settings (%s).", block->name); + nm_log_info (LOGD_SETTINGS, "update wireless security settings (%s).", block->name); wireless_security_setting = NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new()); @@ -330,12 +326,13 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, IfupdownStrToTypeFunc type_map_func = map_by_mapping (type_mapping, curr->key+wireless_l); GFreeFunc free_func = map_by_mapping (free_type_mapping, curr->key+wireless_l); if(!newkey || !dupe_func) { - g_warning("no (wireless) mapping found for key: %s", curr->key); + nm_log_warn (LOGD_SETTINGS, "no (wireless) mapping found for key: %s", + curr->key); goto next; } property_value = (*dupe_func) (curr->data, connection); - PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wireless security key: %s=%s", - newkey, property_value); + nm_log_info (LOGD_SETTINGS, "setting wireless security key: %s=%s", + newkey, property_value); if (type_map_func) { errno = 0; @@ -367,23 +364,23 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, goto next; } property_value = (*dupe_func) (curr->data, connection); - PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa security key: %s=%s", - newkey, + nm_log_info (LOGD_SETTINGS, "setting wpa security key: %s=%s", + newkey, #ifdef DEBUG_SECRETS - property_value + property_value #else // DEBUG_SECRETS - !strcmp("key", newkey) || - !strcmp("leap-password", newkey) || - !strcmp("pin", newkey) || - !strcmp("psk", newkey) || - !strcmp("wep-key0", newkey) || - !strcmp("wep-key1", newkey) || - !strcmp("wep-key2", newkey) || - !strcmp("wep-key3", newkey) || - NULL ? - "<omitted>" : property_value + !strcmp("key", newkey) || + !strcmp("leap-password", newkey) || + !strcmp("pin", newkey) || + !strcmp("psk", newkey) || + !strcmp("wep-key0", newkey) || + !strcmp("wep-key1", newkey) || + !strcmp("wep-key2", newkey) || + !strcmp("wep-key3", newkey) || + NULL ? + "<omitted>" : property_value #endif // DEBUG_SECRETS - ); + ); if (type_map_func) { errno = 0; @@ -407,11 +404,8 @@ update_wireless_security_setting_from_if_block(NMConnection *connection, } - if(security) { - nm_connection_add_setting(connection, NM_SETTING(wireless_security_setting)); - g_object_set(s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); - } - + if (security) + nm_connection_add_setting (connection, NM_SETTING (wireless_security_setting)); } static void @@ -437,7 +431,7 @@ eni_plugin_error_quark() { static void ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns) { - struct in_addr addr; + guint32 addr; char **list, **iter; if (dns == NULL) @@ -449,15 +443,12 @@ ifupdown_ip4_add_dns (NMSettingIP4Config *s_ip4, const char *dns) if (g_ascii_isspace (*iter[0])) continue; if (!inet_pton (AF_INET, *iter, &addr)) { - PLUGIN_WARN ("SCPlugin-Ifupdown", - " warning: ignoring invalid nameserver '%s'", *iter); + nm_log_warn (LOGD_SETTINGS, " ignoring invalid nameserver '%s'", *iter); continue; } - if (!nm_setting_ip4_config_add_dns (s_ip4, addr.s_addr)) { - PLUGIN_WARN ("SCPlugin-Ifupdown", - " warning: duplicate DNS domain '%s'", *iter); - } + if (!nm_setting_ip4_config_add_dns (s_ip4, addr)) + nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); } @@ -475,7 +466,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, if (!is_static) { g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); } else { - struct in_addr tmp_addr, tmp_mask, tmp_gw; + guint32 tmp_addr, tmp_mask, tmp_gw; NMIP4Address *addr; const char *address_v; const char *netmask_v; @@ -510,7 +501,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, "Invalid IPv4 netmask '%s'", netmask_v); goto error; } else { - netmask_int = nm_utils_ip4_netmask_to_prefix (tmp_mask.s_addr); + netmask_int = nm_utils_ip4_netmask_to_prefix (tmp_mask); } } @@ -526,16 +517,17 @@ update_ip4_setting_from_if_block(NMConnection *connection, /* Add the new address to the setting */ addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, tmp_addr.s_addr); + nm_ip4_address_set_address (addr, tmp_addr); nm_ip4_address_set_prefix (addr, netmask_int); - nm_ip4_address_set_gateway (addr, tmp_gw.s_addr); + nm_ip4_address_set_gateway (addr, tmp_gw); if (nm_setting_ip4_config_add_address (s_ip4, addr)) { - PLUGIN_PRINT("SCPlugin-Ifupdown", "addresses count: %d", + nm_log_info (LOGD_SETTINGS, "addresses count: %d", nm_setting_ip4_config_get_num_addresses (s_ip4)); } else { - PLUGIN_PRINT("SCPlugin-Ifupdown", "ignoring duplicate IP4 address"); + nm_log_info (LOGD_SETTINGS, "ignoring duplicate IP4 address"); } + nm_ip4_address_unref (addr); nameserver_v = ifparser_getkey (block, "dns-nameserver"); ifupdown_ip4_add_dns (s_ip4, nameserver_v); @@ -544,7 +536,7 @@ update_ip4_setting_from_if_block(NMConnection *connection, ifupdown_ip4_add_dns (s_ip4, nameservers_v); if (!nm_setting_ip4_config_get_num_dns (s_ip4)) - PLUGIN_PRINT("SCPlugin-Ifupdown", "No dns-nameserver configured in /etc/network/interfaces"); + nm_log_info (LOGD_SETTINGS, "No dns-nameserver configured in /etc/network/interfaces"); /* DNS searches */ search_v = ifparser_getkey (block, "dns-search"); @@ -554,10 +546,8 @@ 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)) { - PLUGIN_WARN ("SCPlugin-Ifupdown", - " warning: duplicate DNS domain '%s'", *iter); - } + if (!nm_setting_ip4_config_add_dns_search (s_ip4, *iter)) + nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); } @@ -588,15 +578,12 @@ ifupdown_ip6_add_dns (NMSettingIP6Config *s_ip6, const char *dns) if (g_ascii_isspace (*iter[0])) continue; if (!inet_pton (AF_INET6, *iter, &addr)) { - PLUGIN_WARN ("SCPlugin-Ifupdown", - " warning: ignoring invalid nameserver '%s'", *iter); + nm_log_warn (LOGD_SETTINGS, " ignoring invalid nameserver '%s'", *iter); continue; } - if (!nm_setting_ip6_config_add_dns (s_ip6, &addr)) { - PLUGIN_WARN ("SCPlugin-Ifupdown", - " warning: duplicate DNS domain '%s'", *iter); - } + if (!nm_setting_ip6_config_add_dns (s_ip6, &addr)) + nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); } @@ -656,11 +643,12 @@ update_ip6_setting_from_if_block(NMConnection *connection, nm_ip6_address_set_gateway (addr, &tmp_gw); if (nm_setting_ip6_config_add_address (s_ip6, addr)) { - PLUGIN_PRINT("SCPlugin-Ifupdown", "addresses count: %d", - nm_setting_ip6_config_get_num_addresses (s_ip6)); + nm_log_info (LOGD_SETTINGS, "addresses count: %d", + nm_setting_ip6_config_get_num_addresses (s_ip6)); } else { - PLUGIN_PRINT("SCPlugin-Ifupdown", "ignoring duplicate IP6 address"); + nm_log_info (LOGD_SETTINGS, "ignoring duplicate IP6 address"); } + nm_ip6_address_unref (addr); nameserver_v = ifparser_getkey(block, "dns-nameserver"); ifupdown_ip6_add_dns (s_ip6, nameserver_v); @@ -669,7 +657,7 @@ update_ip6_setting_from_if_block(NMConnection *connection, ifupdown_ip6_add_dns (s_ip6, nameservers_v); if (!nm_setting_ip6_config_get_num_dns (s_ip6)) - PLUGIN_PRINT("SCPlugin-Ifupdown", "No dns-nameserver configured in /etc/network/interfaces"); + nm_log_info (LOGD_SETTINGS, "No dns-nameserver configured in /etc/network/interfaces"); /* DNS searches */ search_v = ifparser_getkey (block, "dns-search"); @@ -679,10 +667,8 @@ 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)) { - PLUGIN_WARN ("SCPlugin-Ifupdown", - " warning: duplicate DNS domain '%s'", *iter); - } + if (!nm_setting_ip6_config_add_dns_search (s_ip6, *iter)) + nm_log_warn (LOGD_SETTINGS, " duplicate DNS domain '%s'", *iter); } g_strfreev (list); } @@ -726,6 +712,7 @@ ifupdown_update_connection_from_if_block (NMConnection *connection, uuid = nm_utils_uuid_generate_from_string (uuid_base); g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, type, + NM_SETTING_CONNECTION_INTERFACE_NAME, block->name, NM_SETTING_CONNECTION_ID, idstr, NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_READ_ONLY, TRUE, @@ -733,8 +720,8 @@ ifupdown_update_connection_from_if_block (NMConnection *connection, NULL); g_free (uuid); - PLUGIN_PRINT("SCPlugin-Ifupdown", "update_connection_setting_from_if_block: name:%s, type:%s, id:%s, uuid: %s", - block->name, type, idstr, nm_setting_connection_get_uuid (s_con)); + nm_log_info (LOGD_SETTINGS, "update_connection_setting_from_if_block: name:%s, type:%s, id:%s, uuid: %s", + block->name, type, idstr, nm_setting_connection_get_uuid (s_con)); if (!strcmp (NM_SETTING_WIRED_SETTING_NAME, type)) update_wired_setting_from_if_block (connection, block); diff --git a/src/settings/plugins/ifupdown/plugin.c b/src/settings/plugins/ifupdown/plugin.c index a46ea2e8..dcae211c 100644 --- a/src/settings/plugins/ifupdown/plugin.c +++ b/src/settings/plugins/ifupdown/plugin.c @@ -50,6 +50,7 @@ #include "nm-inotify-helper.h" #include "nm-logging.h" +#include "nm-config.h" #include <arpa/inet.h> @@ -85,7 +86,6 @@ typedef struct { GHashTable *kernel_ifaces; gboolean unmanage_well_known; - char *conf_file; gulong inotify_event_id; int inotify_system_hostname_wd; @@ -182,13 +182,6 @@ sc_plugin_ifupdown_class_init (SCPluginIfupdownClass *req_class) } static void -ignore_cb (NMSettingsConnection *connection, - GError *error, - gpointer user_data) -{ -} - -static void bind_device_to_connection (SCPluginIfupdown *self, GUdevDevice *device, NMIfupdownConnection *exported) @@ -200,19 +193,19 @@ bind_device_to_connection (SCPluginIfupdown *self, iface = g_udev_device_get_name (device); if (!iface) { - PLUGIN_WARN ("SCPluginIfupdown", "failed to get ifname for device."); + nm_log_warn (LOGD_SETTINGS, "failed to get ifname for device."); return; } address = g_udev_device_get_sysfs_attr (device, "address"); if (!address || !strlen (address)) { - PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface); + nm_log_warn (LOGD_SETTINGS, "failed to get MAC address for %s", iface); return; } mac_address = nm_utils_hwaddr_atoba (address, ARPHRD_ETHER); if (!mac_address) { - PLUGIN_WARN ("SCPluginIfupdown", "failed to parse MAC address '%s' for %s", + nm_log_warn (LOGD_SETTINGS, "failed to parse MAC address '%s' for %s", address, iface); return; } @@ -220,15 +213,15 @@ bind_device_to_connection (SCPluginIfupdown *self, s_wired = nm_connection_get_setting_wired (NM_CONNECTION (exported)); s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported)); if (s_wired) { - PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting"); + nm_log_info (LOGD_SETTINGS, "locking wired connection setting"); g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL); } else if (s_wifi) { - PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting"); + nm_log_info (LOGD_SETTINGS, "locking wireless connection setting"); g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL); } g_byte_array_free (mac_address, TRUE); - nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL); + nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), NULL, NULL); } static void @@ -243,16 +236,15 @@ udev_device_added (SCPluginIfupdown *self, GUdevDevice *device) if (!iface || !path) return; - PLUGIN_PRINT("SCPlugin-Ifupdown", - "devices added (path: %s, iface: %s)", path, iface); + nm_log_info (LOGD_SETTINGS, "devices added (path: %s, iface: %s)", path, iface); /* if we have a configured connection for this particular iface * we want to either unmanage the device or lock it */ exported = g_hash_table_lookup (priv->connections, iface); if (!exported && !g_hash_table_lookup (priv->eni_ifaces, iface)) { - PLUGIN_PRINT("SCPlugin-Ifupdown", - "device added (path: %s, iface: %s): no ifupdown configuration found.", path, iface); + nm_log_info (LOGD_SETTINGS, "device added (path: %s, iface: %s): no ifupdown configuration found.", + path, iface); return; } @@ -276,8 +268,7 @@ udev_device_removed (SCPluginIfupdown *self, GUdevDevice *device) if (!iface || !path) return; - PLUGIN_PRINT("SCPlugin-Ifupdown", - "devices removed (path: %s, iface: %s)", path, iface); + nm_log_info (LOGD_SETTINGS, "devices removed (path: %s, iface: %s)", path, iface); if (!g_hash_table_remove (priv->kernel_ifaces, iface)) return; @@ -297,7 +288,7 @@ udev_device_changed (SCPluginIfupdown *self, GUdevDevice *device) if (!iface || !path) return; - PLUGIN_PRINT("SCPlugin-Ifupdown", "device changed (path: %s, iface: %s)", path, iface); + nm_log_info (LOGD_SETTINGS, "device changed (path: %s, iface: %s)", path, iface); if (!g_hash_table_lookup (priv->kernel_ifaces, iface)) return; @@ -338,7 +329,7 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) GHashTable *auto_ifaces; if_block *block = NULL; NMInotifyHelper *inotify_helper; - GKeyFile* keyfile; + char *value; GError *error = NULL; GList *keys, *iter; GHashTableIter con_iter; @@ -357,11 +348,11 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) if(!priv->eni_ifaces) priv->eni_ifaces = g_hash_table_new (g_str_hash, g_str_equal); - PLUGIN_PRINT("SCPlugin-Ifupdown", "init!"); + nm_log_info (LOGD_SETTINGS, "init!"); priv->client = g_udev_client_new (subsys); if (!priv->client) { - PLUGIN_WARN ("SCPlugin-Ifupdown", " error initializing libgudev"); + nm_log_warn (LOGD_SETTINGS, " error initializing libgudev"); } else g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); @@ -396,7 +387,7 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) int state = 0; char **port_ifaces; - PLUGIN_PRINT("SCPlugin-Ifupdown", "found bridge ports %s for %s", ports, block->name); + nm_log_info (LOGD_SETTINGS, "found bridge ports %s for %s", ports, block->name); port_ifaces = g_strsplit_set (ports, " \t", -1); for (i = 0; i < g_strv_length (port_ifaces); i++) { @@ -415,7 +406,7 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) continue; } if (state == 0 && strlen (token) > 0) { - PLUGIN_PRINT("SCPlugin-Ifupdown", "adding bridge port %s to eni_ifaces", token); + nm_log_info (LOGD_SETTINGS, "adding bridge port %s to eni_ifaces", token); g_hash_table_insert (priv->eni_ifaces, g_strdup (token), "known"); } } @@ -432,22 +423,22 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) /* Remove any connection for this block that was previously found */ exported = g_hash_table_lookup (priv->connections, block->name); if (exported) { - PLUGIN_PRINT("SCPlugin-Ifupdown", "deleting %s from connections", block->name); - nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL); + nm_log_info (LOGD_SETTINGS, "deleting %s from connections", block->name); + nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), NULL, NULL); g_hash_table_remove (priv->connections, block->name); } /* add the new connection */ exported = nm_ifupdown_connection_new (block); if (exported) { - PLUGIN_PRINT("SCPlugin-Ifupdown", "adding %s to connections", block->name); + nm_log_info (LOGD_SETTINGS, "adding %s to connections", block->name); g_hash_table_insert (priv->connections, block->name, exported); } - PLUGIN_PRINT("SCPlugin-Ifupdown", "adding iface %s to eni_ifaces", block->name); + nm_log_info (LOGD_SETTINGS, "adding iface %s to eni_ifaces", block->name); g_hash_table_insert (priv->eni_ifaces, block->name, "known"); } else if (!strcmp ("mapping", block->type)) { g_hash_table_insert (priv->eni_ifaces, block->name, "known"); - PLUGIN_PRINT("SCPlugin-Ifupdown", "adding mapping %s to eni_ifaces", block->name); + nm_log_info (LOGD_SETTINGS, "adding mapping %s to eni_ifaces", block->name); } next: block = block->next; @@ -461,41 +452,28 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) if (g_hash_table_lookup (auto_ifaces, block_name)) { setting = nm_connection_get_setting_connection (NM_CONNECTION (connection)); g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL); - PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect"); + nm_log_info (LOGD_SETTINGS, "autoconnect"); } } g_hash_table_destroy (auto_ifaces); - /* Read the config file to find out whether to manage interfaces */ - keyfile = g_key_file_new (); - if (!g_key_file_load_from_file (keyfile, - priv->conf_file, - G_KEY_FILE_NONE, - &error)) { - nm_log_info (LOGD_SETTINGS, "loading system config file (%s) caused error: (%d) %s", - priv->conf_file, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + /* Check the config file to find out whether to manage interfaces */ + value = nm_config_get_value (nm_config_get (), + IFUPDOWN_KEY_FILE_GROUP, IFUPDOWN_KEY_FILE_KEY_MANAGED, + &error); + if (error) { + nm_log_info (LOGD_SETTINGS, "loading system config file (%s) caused error: %s", + nm_config_get_path (nm_config_get ()), + error->message); } else { gboolean manage_well_known; error = NULL; - manage_well_known = g_key_file_get_boolean (keyfile, - IFUPDOWN_KEY_FILE_GROUP, - IFUPDOWN_KEY_FILE_KEY_MANAGED, - &error); - if (error) { - nm_log_info (LOGD_SETTINGS, "getting keyfile key '%s' in group '%s' failed: (%d) %s", - IFUPDOWN_KEY_FILE_GROUP, - IFUPDOWN_KEY_FILE_KEY_MANAGED, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); - } else - priv->unmanage_well_known = !manage_well_known; + manage_well_known = !g_strcmp0 (value, "true") || !g_strcmp0 (value, "1"); + priv->unmanage_well_known = !manage_well_known; + g_free (value); } - PLUGIN_PRINT ("SCPluginIfupdown", "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed"); - if (keyfile) - g_key_file_free (keyfile); + nm_log_info (LOGD_SETTINGS, "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed"); /* Add well-known interfaces */ keys = g_udev_client_query_by_subsystem (priv->client, "net"); @@ -518,7 +496,7 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config) g_list_free (con_list); } - PLUGIN_PRINT("SCPlugin-Ifupdown", "end _init."); + nm_log_info (LOGD_SETTINGS, "end _init."); } @@ -533,10 +511,10 @@ SCPluginIfupdown_get_connections (NMSystemConfigInterface *config) GHashTableIter iter; gpointer value; - PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections.", GPOINTER_TO_UINT(config)); + nm_log_info (LOGD_SETTINGS, "(%d) ... get_connections.", GPOINTER_TO_UINT(config)); if(priv->unmanage_well_known) { - PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections (managed=false): return empty list.", GPOINTER_TO_UINT(config)); + nm_log_info (LOGD_SETTINGS, "(%d) ... get_connections (managed=false): return empty list.", GPOINTER_TO_UINT(config)); return NULL; } @@ -544,7 +522,7 @@ SCPluginIfupdown_get_connections (NMSystemConfigInterface *config) while (g_hash_table_iter_next (&iter, NULL, &value)) connections = g_slist_prepend (connections, value); - PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections)); + nm_log_info (LOGD_SETTINGS, "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections)); return connections; } @@ -559,22 +537,24 @@ SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config) SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); GSList *specs = NULL; GHashTableIter iter; - gpointer value; + GUdevDevice *device; + const char *iface; if (!ALWAYS_UNMANAGE && !priv->unmanage_well_known) return NULL; - PLUGIN_PRINT("Ifupdown", "get unmanaged devices count: %d", + nm_log_info (LOGD_SETTINGS, "get unmanaged devices count: %d", g_hash_table_size (priv->kernel_ifaces)); g_hash_table_iter_init (&iter, priv->kernel_ifaces); - while (g_hash_table_iter_next (&iter, NULL, &value)) { - GUdevDevice *device = G_UDEV_DEVICE (value); + while (g_hash_table_iter_next (&iter, (gpointer) &iface, (gpointer) &device)) { const char *address; address = g_udev_device_get_sysfs_attr (device, "address"); if (address) specs = g_slist_append (specs, g_strdup_printf ("mac:%s", address)); + else + specs = g_slist_append (specs, g_strdup_printf ("interface-name:%s", iface)); } return specs; } @@ -598,7 +578,7 @@ update_system_hostname(NMInotifyHelper *inotify_helper, gsize hostname_file_len = 0; GError *error = NULL; - PLUGIN_PRINT ("SCPlugin-Ifupdown", "update_system_hostname"); + nm_log_info (LOGD_SETTINGS, "update_system_hostname"); if (evt && evt->wd != priv->inotify_system_hostname_wd) return; @@ -608,8 +588,8 @@ update_system_hostname(NMInotifyHelper *inotify_helper, &hostname_file_len, &error)) { nm_log_warn (LOGD_SETTINGS, "update_system_hostname() - couldn't read " - IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)", - error->code, error->message); + IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)", + error->code, error->message); return; } @@ -631,7 +611,7 @@ write_system_hostname(NMSystemConfigInterface *config, { GError *error = NULL; SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config); - PLUGIN_PRINT ("SCPlugin-Ifupdown", "write_system_hostname: %s", newhostname); + nm_log_info (LOGD_SETTINGS, "write_system_hostname: %s", newhostname); g_return_if_fail (newhostname); @@ -640,8 +620,8 @@ write_system_hostname(NMSystemConfigInterface *config, -1, &error)) { nm_log_warn (LOGD_SETTINGS, "update_system_hostname() - couldn't write hostname (%s) to " - IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)", - newhostname, error->code, error->message); + IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)", + newhostname, error->code, error->message); } else { priv->hostname = g_strdup (newhostname); } @@ -719,8 +699,6 @@ GObject__dispose (GObject *object) if (priv->eni_ifaces) g_hash_table_destroy(priv->eni_ifaces); - g_free (priv->conf_file); - if (priv->client) g_object_unref (priv->client); @@ -729,17 +707,14 @@ GObject__dispose (GObject *object) } G_MODULE_EXPORT GObject * -nm_system_config_factory (const char *config_file) +nm_system_config_factory (void) { static SCPluginIfupdown *singleton = NULL; SCPluginIfupdownPrivate *priv; if (!singleton) { singleton = SC_PLUGIN_IFUPDOWN (g_object_new (SC_TYPE_PLUGIN_IFUPDOWN, NULL)); - if (singleton) { - priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (singleton); - priv->conf_file = strdup (config_file); - } + priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (singleton); } else g_object_ref (singleton); diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index d8286867..160b3327 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -1,33 +1,41 @@ if ENABLE_TESTS -noinst_PROGRAMS = test-ifupdown - 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)/src \ + -I$(top_srcdir)/src/logging \ + -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ + -DG_LOG_DOMAIN=\""NetworkManager-ifupdown"\" \ + -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ + $(POLKIT_CFLAGS) \ -DTEST_ENI_DIR=\"$(abs_srcdir)\" +noinst_PROGRAMS = test-ifupdown + test_ifupdown_SOURCES = \ - test-ifupdown.c + test-ifupdown.c \ + ../interface_parser.c \ + ../parser.c test_ifupdown_LDADD = \ + $(top_builddir)/src/libNetworkManager.la \ $(top_builddir)/libnm-glib/libnm-glib.la \ $(top_builddir)/libnm-util/libnm-util.la \ - $(builddir)/../libifupdown-io.la \ $(DBUS_LIBS) -check-local: test-ifupdown - $(abs_builddir)/test-ifupdown +TESTS = test-ifupdown 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 + 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 7fea5c87..86afefe6 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.in +++ b/src/settings/plugins/ifupdown/tests/Makefile.in @@ -79,11 +79,13 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @ENABLE_TESTS_TRUE@noinst_PROGRAMS = test-ifupdown$(EXEEXT) +@ENABLE_TESTS_TRUE@TESTS = test-ifupdown$(EXEEXT) subdir = src/settings/plugins/ifupdown/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/compiler_warnings.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 \ @@ -102,14 +104,16 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) -am__test_ifupdown_SOURCES_DIST = test-ifupdown.c -@ENABLE_TESTS_TRUE@am_test_ifupdown_OBJECTS = test-ifupdown.$(OBJEXT) +am__test_ifupdown_SOURCES_DIST = test-ifupdown.c ../interface_parser.c \ + ../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@ $(builddir)/../libifupdown-io.la \ @ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -175,6 +179,28 @@ am__define_uniq_tagged_files = \ 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@ @@ -201,12 +227,15 @@ 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@ @@ -231,7 +260,6 @@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ GNUTLS_LIBS = @GNUTLS_LIBS@ GREP = @GREP@ GTKDOC_CHECK = @GTKDOC_CHECK@ -GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@ GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@ GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@ GTKDOC_MKPDF = @GTKDOC_MKPDF@ @@ -276,12 +304,16 @@ 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@ @@ -298,6 +330,8 @@ MOC = @MOC@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ +NEWT_CFLAGS = @NEWT_CFLAGS@ +NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ @@ -325,11 +359,16 @@ 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@ @@ -344,6 +383,7 @@ UDEV_BASE_DIR = @UDEV_BASE_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@ @@ -406,6 +446,7 @@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ systemdsystemunitdir = @systemdsystemunitdir@ target_alias = @target_alias@ @@ -416,30 +457,40 @@ 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@ -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)/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@ -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 = \ -@ENABLE_TESTS_TRUE@ test-ifupdown.c +@ENABLE_TESTS_TRUE@ test-ifupdown.c \ +@ENABLE_TESTS_TRUE@ ../interface_parser.c \ +@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@ $(builddir)/../libifupdown-io.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@ 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 all: all-am @@ -495,6 +546,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface_parser.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-ifupdown.Po@am__quote@ .c.o: @@ -518,6 +571,34 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +interface_parser.o: ../interface_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interface_parser.o -MD -MP -MF $(DEPDIR)/interface_parser.Tpo -c -o interface_parser.o `test -f '../interface_parser.c' || echo '$(srcdir)/'`../interface_parser.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interface_parser.Tpo $(DEPDIR)/interface_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../interface_parser.c' object='interface_parser.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 interface_parser.o `test -f '../interface_parser.c' || echo '$(srcdir)/'`../interface_parser.c + +interface_parser.obj: ../interface_parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interface_parser.obj -MD -MP -MF $(DEPDIR)/interface_parser.Tpo -c -o interface_parser.obj `if test -f '../interface_parser.c'; then $(CYGPATH_W) '../interface_parser.c'; else $(CYGPATH_W) '$(srcdir)/../interface_parser.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interface_parser.Tpo $(DEPDIR)/interface_parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../interface_parser.c' object='interface_parser.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 interface_parser.obj `if test -f '../interface_parser.c'; then $(CYGPATH_W) '../interface_parser.c'; else $(CYGPATH_W) '$(srcdir)/../interface_parser.c'; fi` + +parser.o: ../parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT parser.o -MD -MP -MF $(DEPDIR)/parser.Tpo -c -o parser.o `test -f '../parser.c' || echo '$(srcdir)/'`../parser.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/parser.Tpo $(DEPDIR)/parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../parser.c' object='parser.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 parser.o `test -f '../parser.c' || echo '$(srcdir)/'`../parser.c + +parser.obj: ../parser.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT parser.obj -MD -MP -MF $(DEPDIR)/parser.Tpo -c -o parser.obj `if test -f '../parser.c'; then $(CYGPATH_W) '../parser.c'; else $(CYGPATH_W) '$(srcdir)/../parser.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/parser.Tpo $(DEPDIR)/parser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../parser.c' object='parser.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 parser.obj `if test -f '../parser.c'; then $(CYGPATH_W) '../parser.c'; else $(CYGPATH_W) '$(srcdir)/../parser.c'; fi` + mostlyclean-libtool: -rm -f *.lo @@ -576,6 +657,99 @@ cscopelist-am: $(am__tagged_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'`; \ @@ -606,9 +780,8 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done -@ENABLE_TESTS_FALSE@check-local: check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) check-local + $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile $(PROGRAMS) installdirs: @@ -715,7 +888,7 @@ uninstall-am: .MAKE: check-am install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-am check-local clean \ +.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 \ @@ -730,9 +903,6 @@ uninstall-am: tags tags-am uninstall uninstall-am -@ENABLE_TESTS_TRUE@check-local: test-ifupdown -@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-ifupdown - # 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/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index 81a0c64a..83864287 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -23,10 +23,12 @@ #include <nm-utils.h> -#include "nm-test-helpers.h" +#include "nm-logging.h" #include "interface_parser.h" #include "parser.h" +#include "nm-test-utils.h" + typedef struct { char *key; char *data; @@ -48,17 +50,16 @@ expected_key_new (const char *key, const char *data) ExpectedKey *k; k = g_malloc0 (sizeof (ExpectedKey)); - g_assert (k); k->key = g_strdup (key); - g_assert (k->key); k->data = g_strdup (data); - g_assert (k->data); return k; } static void -expected_key_free (ExpectedKey *k) +expected_key_free (gpointer ptr) { + ExpectedKey *k = ptr; + g_assert (k); g_free (k->key); g_free (k->data); @@ -81,11 +82,12 @@ expected_block_new (const char *type, const char *name) } static void -expected_block_free (ExpectedBlock *b) +expected_block_free (gpointer ptr) { + ExpectedBlock *b = ptr; + g_assert (b); - g_slist_foreach (b->keys, (GFunc) expected_key_free, NULL); - g_slist_free (b->keys); + g_slist_free_full (b->keys, expected_key_free); g_free (b->type); g_free (b->name); memset (b, 0, sizeof (ExpectedBlock)); @@ -103,11 +105,7 @@ expected_block_add_key (ExpectedBlock *b, ExpectedKey *k) static Expected * expected_new (void) { - Expected *e; - - e = g_malloc0 (sizeof (Expected)); - g_assert (e); - return e; + return g_malloc0 (sizeof (Expected)); } static void @@ -122,8 +120,7 @@ static void expected_free (Expected *e) { g_assert (e); - g_slist_foreach (e->blocks, (GFunc) expected_block_free, NULL); - g_slist_free (e->blocks); + g_slist_free_full (e->blocks, expected_block_free); memset (e, 0, sizeof (Expected)); g_free (e); } @@ -476,7 +473,7 @@ test17_read_static_ipv4 (const char *path) const char *expected_search2 = "foo.example.com"; guint32 expected_prefix = 8; NMIP4Address *ip4_addr; - struct in_addr addr; + guint32 addr; #define TEST17_NAME "wired-static-verify-ip4" if_block *block = NULL; @@ -561,9 +558,9 @@ test17_read_static_ipv4 (const char *path) TEST17_NAME, "failed to verify %s: unexpected IP4 address prefix", file); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr.s_addr, + ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, TEST17_NAME, "failed to verify %s: unexpected IP4 address: %s", - file, addr.s_addr); + file, addr); /* DNS Addresses */ ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, @@ -578,7 +575,7 @@ test17_read_static_ipv4 (const char *path) NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr.s_addr, + ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #1", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, @@ -590,7 +587,7 @@ test17_read_static_ipv4 (const char *path) NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS); - ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr.s_addr, + ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr, TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #2", file, NM_SETTING_IP4_CONFIG_SETTING_NAME, @@ -848,7 +845,7 @@ test19_read_static_ipv4_plen (const char *path) const char *expected_address = "10.0.0.3"; guint32 expected_prefix = 8; NMIP4Address *ip4_addr; - struct in_addr addr; + guint32 addr; #define TEST19_NAME "wired-static-verify-ip4-plen" if_block *block = NULL; @@ -896,57 +893,96 @@ test19_read_static_ipv4_plen (const char *path) TEST19_NAME, "failed to verify %s: unexpected IP4 address prefix", file); - ASSERT (nm_ip4_address_get_address (ip4_addr) == addr.s_addr, + ASSERT (nm_ip4_address_get_address (ip4_addr) == addr, TEST19_NAME, "failed to verify %s: unexpected IP4 address: %s", - file, addr.s_addr); + file, addr); g_object_unref (connection); } +static void +test20_source_stanza (const char *path) +{ + Expected *e; + ExpectedBlock *b; -#if GLIB_CHECK_VERSION(2,25,12) -typedef GTestFixtureFunc TCFunc; -#else -typedef void (*TCFunc)(void); -#endif + e = expected_new (); + + b = expected_block_new ("auto", "eth0"); + expected_add_block (e, b); + b = expected_block_new ("iface", "eth0"); + expected_add_block (e, b); + expected_block_add_key (b, expected_key_new ("inet", "dhcp")); -#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL) + b = expected_block_new ("auto", "eth1"); + expected_add_block (e, b); + b = expected_block_new ("iface", "eth1"); + expected_add_block (e, b); + expected_block_add_key (b, expected_key_new ("inet", "dhcp")); -int main (int argc, char **argv) + init_ifparser_with_file (path, "test20-source-stanza"); + compare_expected_to_ifparser (e); + + ifparser_destroy (); + expected_free (e); +} + +int +main (int argc, char **argv) { - GTestSuite *suite; 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); - suite = g_test_get_root (); - if (0) dump_blocks (); - g_test_suite_add (suite, TESTCASE (test1_ignore_line_before_first_block, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test2_wrapped_line, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test3_wrapped_multiline_multiarg, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test4_allow_auto_is_auto, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test5_allow_auto_multiarg, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test6_mixed_whitespace, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test7_long_line, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test8_long_line_wrapped, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test9_wrapped_lines_in_block, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test11_complex_wrap, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test12_complex_wrap_split_word, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test13_more_mixed_whitespace, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test14_mixed_whitespace_block_start, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test15_trailing_space, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test16_missing_newline, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test17_read_static_ipv4, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test18_read_static_ipv6, TEST_ENI_DIR)); - g_test_suite_add (suite, TESTCASE (test19_read_static_ipv4_plen, TEST_ENI_DIR)); + g_test_add_data_func ("/ifupdate/ignore_line_before_first_block", TEST_ENI_DIR, + (GTestDataFunc) test1_ignore_line_before_first_block); + g_test_add_data_func ("/ifupdate/wrapped_line", TEST_ENI_DIR, + (GTestDataFunc) test2_wrapped_line); + g_test_add_data_func ("/ifupdate/wrapped_multiline_multiarg", TEST_ENI_DIR, + (GTestDataFunc) test3_wrapped_multiline_multiarg); + g_test_add_data_func ("/ifupdate/allow_auto_is_auto", TEST_ENI_DIR, + (GTestDataFunc) test4_allow_auto_is_auto); + g_test_add_data_func ("/ifupdate/allow_auto_multiarg", TEST_ENI_DIR, + (GTestDataFunc) test5_allow_auto_multiarg); + g_test_add_data_func ("/ifupdate/mixed_whitespace", TEST_ENI_DIR, + (GTestDataFunc) test6_mixed_whitespace); + g_test_add_data_func ("/ifupdate/long_line", TEST_ENI_DIR, + (GTestDataFunc) test7_long_line); + g_test_add_data_func ("/ifupdate/long_line_wrapped", TEST_ENI_DIR, + (GTestDataFunc) test8_long_line_wrapped); + g_test_add_data_func ("/ifupdate/wrapped_lines_in_block", TEST_ENI_DIR, + (GTestDataFunc) test9_wrapped_lines_in_block); + g_test_add_data_func ("/ifupdate/complex_wrap", TEST_ENI_DIR, + (GTestDataFunc) test11_complex_wrap); + g_test_add_data_func ("/ifupdate/complex_wrap_split_word", TEST_ENI_DIR, + (GTestDataFunc) test12_complex_wrap_split_word); + g_test_add_data_func ("/ifupdate/more_mixed_whitespace", TEST_ENI_DIR, + (GTestDataFunc) test13_more_mixed_whitespace); + g_test_add_data_func ("/ifupdate/mixed_whitespace_block_start", TEST_ENI_DIR, + (GTestDataFunc) test14_mixed_whitespace_block_start); + g_test_add_data_func ("/ifupdate/trailing_space", TEST_ENI_DIR, + (GTestDataFunc) test15_trailing_space); + g_test_add_data_func ("/ifupdate/missing_newline", TEST_ENI_DIR, + (GTestDataFunc) test16_missing_newline); + g_test_add_data_func ("/ifupdate/read_static_ipv4", TEST_ENI_DIR, + (GTestDataFunc) test17_read_static_ipv4); + g_test_add_data_func ("/ifupdate/read_static_ipv6", TEST_ENI_DIR, + (GTestDataFunc) test18_read_static_ipv6); + g_test_add_data_func ("/ifupdate/read_static_ipv4_plen", TEST_ENI_DIR, + (GTestDataFunc) test19_read_static_ipv4_plen); + g_test_add_data_func ("/ifupdate/source_stanza", TEST_ENI_DIR, + (GTestDataFunc) test20_source_stanza); return g_test_run (); } diff --git a/src/settings/plugins/ifupdown/tests/test20-source-stanza b/src/settings/plugins/ifupdown/tests/test20-source-stanza new file mode 100644 index 00000000..5cfe1730 --- /dev/null +++ b/src/settings/plugins/ifupdown/tests/test20-source-stanza @@ -0,0 +1 @@ +source test20-source-stanza.eth* diff --git a/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth0 b/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth0 new file mode 100644 index 00000000..81922cea --- /dev/null +++ b/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth0 @@ -0,0 +1,2 @@ +auto eth0 +iface eth0 inet dhcp diff --git a/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth1 b/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth1 new file mode 100644 index 00000000..b8a783f5 --- /dev/null +++ b/src/settings/plugins/ifupdown/tests/test20-source-stanza.eth1 @@ -0,0 +1,2 @@ +auto eth1 +iface eth1 inet dhcp |