diff options
| author | Michael Biebl <biebl@debian.org> | 2011-03-18 20:17:47 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2011-03-18 20:17:47 +0100 |
| commit | e22c6e05e9ebc6cce941762020c5710b8014677b (patch) | |
| tree | 7e9fd7f8ae24a94b03f683e0cef9a346968e1e8b /system-settings/plugins/ifcfg-rh | |
| parent | a6b89d35fabd9f5934b84d7cde22e9268f92c3d3 (diff) | |
Imported Upstream version 0.8.3.998 upstream/0.8.3.998
Diffstat (limited to 'system-settings/plugins/ifcfg-rh')
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/Makefile.in | 5 | ||||
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/plugin.c | 18 | ||||
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/reader.c | 85 | ||||
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/tests/Makefile.in | 5 | ||||
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in | 5 | ||||
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 10 | ||||
| -rw-r--r-- | system-settings/plugins/ifcfg-rh/writer.c | 21 |
7 files changed, 89 insertions, 60 deletions
diff --git a/system-settings/plugins/ifcfg-rh/Makefile.in b/system-settings/plugins/ifcfg-rh/Makefile.in index 22383f92..9d79e8e9 100644 --- a/system-settings/plugins/ifcfg-rh/Makefile.in +++ b/system-settings/plugins/ifcfg-rh/Makefile.in @@ -264,6 +264,10 @@ MSGFMT_OPTS = @MSGFMT_OPTS@ MSGMERGE = @MSGMERGE@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ +NM_MICRO_VERSION = @NM_MICRO_VERSION@ +NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_VERSION = @NM_VERSION@ NSS_CFLAGS = @NSS_CFLAGS@ NSS_LIBS = @NSS_LIBS@ OBJDUMP = @OBJDUMP@ @@ -278,6 +282,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PKGCONFIG_PATH = @PKGCONFIG_PATH@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ diff --git a/system-settings/plugins/ifcfg-rh/plugin.c b/system-settings/plugins/ifcfg-rh/plugin.c index e6dfa5bc..8dce0334 100644 --- a/system-settings/plugins/ifcfg-rh/plugin.c +++ b/system-settings/plugins/ifcfg-rh/plugin.c @@ -147,7 +147,6 @@ read_one_connection (SCPluginIfcfg *plugin, const char *filename) if (nm_ifcfg_connection_get_unmanaged_spec (connection)) { PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Ignoring connection '%s' and its " "device due to NM_CONTROLLED/BRIDGE/VLAN.", cid); - g_signal_emit_by_name (plugin, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED); } else { /* Wait for the connection to become unmanaged once it knows the * UDI of it's device, if/when the device gets plugged in. @@ -218,8 +217,6 @@ connection_changed_handler (SCPluginIfcfg *plugin, g_return_if_fail (do_remove != NULL); g_return_if_fail (do_new != NULL); - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "updating %s", path); - new = (NMIfcfgConnection *) nm_ifcfg_connection_new (path, &error, &ignore_error); if (!new) { /* errors reading connection; remove it */ @@ -234,8 +231,19 @@ connection_changed_handler (SCPluginIfcfg *plugin, return; } + /* Successfully read connection changes */ + /* When the connections are the same, nothing is done */ + if (nm_connection_compare (NM_CONNECTION (connection), + NM_CONNECTION (new), + NM_SETTING_COMPARE_FLAG_EXACT)) { + g_object_unref (new); + return; + } + + PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "updating %s", path); + old_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (NM_IFCFG_CONNECTION (connection)); new_unmanaged = nm_ifcfg_connection_get_unmanaged_spec (NM_IFCFG_CONNECTION (new)); @@ -305,7 +313,9 @@ handle_connection_remove_or_new (SCPluginIfcfg *plugin, if (do_new) { connection = read_one_connection (plugin, path); if (connection) { - if (!nm_ifcfg_connection_get_unmanaged_spec (connection)) + if (nm_ifcfg_connection_get_unmanaged_spec (connection)) + g_signal_emit_by_name (plugin, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED); + else g_signal_emit_by_name (plugin, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, connection); } } diff --git a/system-settings/plugins/ifcfg-rh/reader.c b/system-settings/plugins/ifcfg-rh/reader.c index f25acc89..4ca9232a 100644 --- a/system-settings/plugins/ifcfg-rh/reader.c +++ b/system-settings/plugins/ifcfg-rh/reader.c @@ -15,7 +15,7 @@ * 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 - 2010 Red Hat, Inc. + * Copyright (C) 2008 - 2011 Red Hat, Inc. */ #include <config.h> @@ -114,7 +114,7 @@ make_connection_setting (const char *file, { NMSettingConnection *s_con; const char *ifcfg_name = NULL; - char *new_id = NULL, *uuid = NULL, *value; + char *new_id = NULL, *uuid = NULL; char *ifcfg_id; ifcfg_name = utils_get_ifcfg_name (file, TRUE); @@ -167,21 +167,6 @@ make_connection_setting (const char *file, svTrueValue (ifcfg, "ONBOOT", TRUE), NULL); - value = svGetValue (ifcfg, "LAST_CONNECT", FALSE); - if (value) { - unsigned long int tmp; - guint64 timestamp; - - errno = 0; - tmp = strtoul (value, NULL, 10); - if (errno == 0) { - timestamp = (guint64) tmp; - g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, timestamp, NULL); - } else - PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid LAST_CONNECT time"); - g_free (value); - } - return NM_SETTING (s_con); } @@ -683,12 +668,7 @@ read_one_ip4_route (shvarFile *ifcfg, /* Next hop */ if (!read_ip4_address (ifcfg, gw_tag, &tmp, error)) goto out; - if (!tmp) { - g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Missing or invalid IP4 gateway address '%d'", - tmp); - 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); /* Prefix */ @@ -891,11 +871,17 @@ error: } static NMIP6Address * -parse_full_ip6_address (const char *addr_str, GError **error) +parse_full_ip6_address (shvarFile *ifcfg, + const char *network_file, + const char *addr_str, + int i, + GError **error) { - NMIP6Address *addr; + NMIP6Address *addr = NULL; char **list; - char *ip_tag, *prefix_tag; + char *ip_val, *prefix_val; + shvarFile *network_ifcfg; + char *value = NULL; struct in6_addr tmp = IN6ADDR_ANY_INIT; gboolean success = FALSE; @@ -911,27 +897,26 @@ parse_full_ip6_address (const char *addr_str, GError **error) goto error; } - ip_tag = list[0]; - prefix_tag = list[1]; + ip_val = list[0]; + prefix_val = list[1]; addr = nm_ip6_address_new (); /* IP address */ - if (ip_tag) { - if (!parse_ip6_address (ip_tag, &tmp, error)) + if (ip_val) { + if (!parse_ip6_address (ip_val, &tmp, error)) goto error; } - nm_ip6_address_set_address (addr, &tmp); /* Prefix */ - if (prefix_tag) { + if (prefix_val) { long int prefix; errno = 0; - prefix = strtol (prefix_tag, NULL, 10); + prefix = strtol (prefix_val, NULL, 10); if (errno || prefix <= 0 || prefix > 128) { g_set_error (error, IFCFG_PLUGIN_ERROR, 0, - "Invalid IP6 prefix '%s'", prefix_tag); + "Invalid IP6 prefix '%s'", prefix_val); goto error; } nm_ip6_address_set_prefix (addr, (guint32) prefix); @@ -940,6 +925,32 @@ parse_full_ip6_address (const char *addr_str, GError **error) nm_ip6_address_set_prefix (addr, 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 = svNewFile (network_file); + 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); + } + success = TRUE; error: @@ -949,6 +960,7 @@ error: } g_strfreev (list); + g_free (value); return addr; } @@ -1167,6 +1179,7 @@ make_ip4_setting (shvarFile *ifcfg, if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) method = NM_SETTING_IP4_CONFIG_METHOD_AUTO; else if (!g_ascii_strcasecmp (value, "ibft")) { + 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. */ @@ -1511,8 +1524,8 @@ make_ip6_setting (shvarFile *ifcfg, list = g_strsplit_set (val, " ", 0); g_free (val); - for (iter = list; iter && *iter; iter++, i++) { - addr = parse_full_ip6_address (*iter, error); + for (iter = list, i = 0; iter && *iter; iter++, i++) { + addr = parse_full_ip6_address (ifcfg, network_file, *iter, i, error); if (!addr) { g_strfreev (list); goto error; diff --git a/system-settings/plugins/ifcfg-rh/tests/Makefile.in b/system-settings/plugins/ifcfg-rh/tests/Makefile.in index 5241e8ed..ee01e1f1 100644 --- a/system-settings/plugins/ifcfg-rh/tests/Makefile.in +++ b/system-settings/plugins/ifcfg-rh/tests/Makefile.in @@ -226,6 +226,10 @@ MSGFMT_OPTS = @MSGFMT_OPTS@ MSGMERGE = @MSGMERGE@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ +NM_MICRO_VERSION = @NM_MICRO_VERSION@ +NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_VERSION = @NM_VERSION@ NSS_CFLAGS = @NSS_CFLAGS@ NSS_LIBS = @NSS_LIBS@ OBJDUMP = @OBJDUMP@ @@ -240,6 +244,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PKGCONFIG_PATH = @PKGCONFIG_PATH@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in b/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in index fb89c241..54080b01 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.in @@ -149,6 +149,10 @@ MSGFMT_OPTS = @MSGFMT_OPTS@ MSGMERGE = @MSGMERGE@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ +NM_MICRO_VERSION = @NM_MICRO_VERSION@ +NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_VERSION = @NM_VERSION@ NSS_CFLAGS = @NSS_CFLAGS@ NSS_LIBS = @NSS_LIBS@ OBJDUMP = @OBJDUMP@ @@ -163,6 +167,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PKGCONFIG_PATH = @PKGCONFIG_PATH@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ diff --git a/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index bca9af12..2fbfea66 100644 --- a/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -29,8 +29,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <dbus/dbus-glib.h> - #include <nm-utils.h> #include <nm-setting-connection.h> #include <nm-setting-wired.h> @@ -5636,7 +5634,6 @@ test_write_wired_static (void) GByteArray *mac; guint32 mtu = 1492; char *uuid; - guint64 timestamp = 0x12344433L; const guint32 ip1 = htonl (0x01010103); const guint32 ip2 = htonl (0x01010105); const guint32 gw = htonl (0x01010101); @@ -5691,7 +5688,6 @@ test_write_wired_static (void) NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_CONNECTION_TIMESTAMP, timestamp, NULL); g_free (uuid); @@ -5986,7 +5982,6 @@ test_write_wired_static_ip6_only (void) static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; GByteArray *mac; char *uuid; - guint64 timestamp = 0x12344433L; struct in6_addr ip6; struct in6_addr dns6; NMIP6Address *addr6; @@ -6019,7 +6014,6 @@ test_write_wired_static_ip6_only (void) NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_CONNECTION_TIMESTAMP, timestamp, NULL); g_free (uuid); @@ -6276,7 +6270,6 @@ test_write_wired_static_routes (void) GByteArray *mac; guint32 mtu = 1492; char *uuid; - guint64 timestamp = 0x12344433L; const guint32 ip1 = htonl (0x01010103); const guint32 ip2 = htonl (0x01010105); const guint32 gw = htonl (0x01010101); @@ -6317,7 +6310,6 @@ test_write_wired_static_routes (void) NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, - NM_SETTING_CONNECTION_TIMESTAMP, timestamp, NULL); g_free (uuid); @@ -9490,11 +9482,9 @@ test_read_vlan_interface (void) int main (int argc, char **argv) { GError *error = NULL; - DBusGConnection *bus; char *base; g_type_init (); - bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); if (!nm_utils_init (&error)) FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message); diff --git a/system-settings/plugins/ifcfg-rh/writer.c b/system-settings/plugins/ifcfg-rh/writer.c index cf1e2663..456fa21c 100644 --- a/system-settings/plugins/ifcfg-rh/writer.c +++ b/system-settings/plugins/ifcfg-rh/writer.c @@ -15,7 +15,7 @@ * 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 - 2010 Red Hat, Inc. + * Copyright (C) 2009 - 2011 Red Hat, Inc. */ #include <ctype.h> @@ -143,6 +143,7 @@ write_secret_file (const char *path, success = TRUE; out: + g_free (tmppath); return success; } @@ -884,6 +885,7 @@ 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) { + tmp = NULL; if (s390_subchannels->len == 2) { tmp = g_strdup_printf ("%s,%s", (const char *) g_ptr_array_index (s390_subchannels, 0), @@ -936,20 +938,11 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) static void write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) { - char *tmp; - svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con), FALSE); svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con), FALSE); svSetValue (ifcfg, "ONBOOT", nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no", FALSE); - - svSetValue (ifcfg, "LAST_CONNECT", NULL, FALSE); - if (nm_setting_connection_get_timestamp (s_con)) { - tmp = g_strdup_printf ("%" G_GUINT64_FORMAT, nm_setting_connection_get_timestamp (s_con)); - svSetValue (ifcfg, "LAST_CONNECT", tmp, FALSE); - g_free (tmp); - } } static gboolean @@ -1407,6 +1400,13 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) 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); + inet_ntop (AF_INET6, (const void *) ip, buf, sizeof (buf)); + svSetValue (ifcfg, "IPV6_DEFAULTGW", buf, FALSE); + } } svSetValue (ifcfg, "IPV6ADDR", ip_str1->str, FALSE); @@ -1416,6 +1416,7 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) } else { svSetValue (ifcfg, "IPV6ADDR", NULL, FALSE); svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", NULL, FALSE); + svSetValue (ifcfg, "IPV6_DEFAULTGW", NULL, FALSE); } /* Write out DNS - 'DNS' key is used both for IPv4 and IPv6 */ |