From 686425adcef5c81a3e72e6aa143fd267e3cb2212 Mon Sep 17 00:00:00 2001 From: Jirka Klimes Date: Tue, 5 Jan 2010 19:05:01 -0600 Subject: [PATCH] ifcfg-rh: add IPv6 addressing and routes support (rh #523288) --- system-settings/plugins/ifcfg-rh/common.h | 1 + .../plugins/ifcfg-rh/nm-ifcfg-connection.c | 19 +- system-settings/plugins/ifcfg-rh/reader.c | 478 ++++++++++- system-settings/plugins/ifcfg-rh/reader.h | 1 + .../tests/network-scripts/Makefile.am | 4 +- .../ifcfg-test-static-routes-legacy | 1 + .../ifcfg-test-wired-defroute-no | 4 + ...fcfg-test-wired-defroute-no-gatewaydev-yes | 4 + .../ifcfg-test-wired-ipv6-manual | 18 + .../ifcfg-test-wired-never-default | 3 +- .../network-scripts/ifcfg-test-wired-static | 7 +- ...work-test-wired-defroute-no-gatewaydev-yes | 1 + .../network-test-wired-never-default | 3 + .../route6-test-wired-ipv6-manual | 1 + .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 780 +++++++++++++++++- system-settings/plugins/ifcfg-rh/utils.c | 19 +- system-settings/plugins/ifcfg-rh/utils.h | 2 + system-settings/plugins/ifcfg-rh/writer.c | 225 ++++- system-settings/plugins/ifcfg-rh/writer.h | 1 - 19 files changed, 1553 insertions(+), 19 deletions(-) create mode 100644 system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual create mode 100644 system-settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual diff --git a/system-settings/plugins/ifcfg-rh/common.h b/system-settings/plugins/ifcfg-rh/common.h index d5931c8967..f5ab1c896d 100644 --- a/system-settings/plugins/ifcfg-rh/common.h +++ b/system-settings/plugins/ifcfg-rh/common.h @@ -26,6 +26,7 @@ #define IFCFG_TAG "ifcfg-" #define KEYS_TAG "keys-" #define ROUTE_TAG "route-" +#define ROUTE6_TAG "route6-" #define BAK_TAG ".bak" #define TILDE_TAG "~" diff --git a/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index 0abf6d4565..b54bc8af21 100644 --- a/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -63,6 +63,9 @@ typedef struct { char *routefile; int routefile_wd; + char *route6file; + int route6file_wd; + char *udi; char *unmanaged; } NMIfcfgConnectionPrivate; @@ -93,7 +96,7 @@ files_changed_cb (NMInotifyHelper *ih, NMIfcfgConnection *self = NM_IFCFG_CONNECTION (user_data); NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - if ((evt->wd != priv->file_wd) && (evt->wd != priv->keyfile_wd) && (evt->wd != priv->routefile_wd)) + if ((evt->wd != priv->file_wd) && (evt->wd != priv->keyfile_wd) && (evt->wd != priv->routefile_wd) && (evt->wd != priv->route6file_wd)) return; /* push the event up to the plugin */ @@ -111,11 +114,12 @@ nm_ifcfg_connection_new (const char *filename, char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; NMInotifyHelper *ih; g_return_val_if_fail (filename != NULL, NULL); - tmp = connection_from_file (filename, NULL, NULL, NULL, &unmanaged, &keyfile, &routefile, error, ignore_error); + tmp = connection_from_file (filename, NULL, NULL, NULL, &unmanaged, &keyfile, &routefile, &route6file, error, ignore_error); if (!tmp) return NULL; @@ -145,6 +149,9 @@ nm_ifcfg_connection_new (const char *filename, priv->routefile = routefile; priv->routefile_wd = nm_inotify_helper_add_watch (ih, routefile); + priv->route6file = route6file; + priv->route6file_wd = nm_inotify_helper_add_watch (ih, route6file); + return NM_IFCFG_CONNECTION (object); } @@ -176,7 +183,6 @@ update (NMSettingsConnectionInterface *connection, IFCFG_DIR, priv->filename, priv->keyfile, - priv->routefile, &error)) { callback (connection, error, user_data); g_error_free (error); @@ -199,6 +205,9 @@ do_delete (NMSettingsConnectionInterface *connection, if (priv->routefile) g_unlink (priv->routefile); + if (priv->route6file) + g_unlink (priv->route6file); + return parent_settings_connection_iface->delete (connection, callback, user_data); } @@ -243,6 +252,10 @@ finalize (GObject *object) if (priv->routefile_wd >= 0) nm_inotify_helper_remove_watch (ih, priv->routefile_wd); + g_free (priv->route6file); + if (priv->route6file_wd >= 0) + nm_inotify_helper_remove_watch (ih, priv->route6file_wd); + G_OBJECT_CLASS (nm_ifcfg_connection_parent_class)->finalize (object); } diff --git a/system-settings/plugins/ifcfg-rh/reader.c b/system-settings/plugins/ifcfg-rh/reader.c index 0bb89bc150..62cba2068a 100644 --- a/system-settings/plugins/ifcfg-rh/reader.c +++ b/system-settings/plugins/ifcfg-rh/reader.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -494,6 +495,31 @@ read_ip4_address (shvarFile *ifcfg, return success; } +static gboolean +parse_ip6_address (const char *value, + struct in6_addr *out_addr, + GError **error) +{ + struct in6_addr ip6_addr; + gboolean success = FALSE; + + g_return_val_if_fail (value != NULL, FALSE); + g_return_val_if_fail (out_addr != NULL, FALSE); + g_return_val_if_fail (error != NULL, FALSE); + g_return_val_if_fail (*error == NULL, FALSE); + + *out_addr = in6addr_any; + + if (inet_pton (AF_INET6, value, &ip6_addr) > 0) { + *out_addr = ip6_addr; + success = TRUE; + } else { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Invalid IP6 address '%s'", value); + } + return success; +} + static NMIP4Address * read_full_ip4_address (shvarFile *ifcfg, const char *network_file, @@ -851,6 +877,227 @@ error: return success; } +static NMIP6Address * +parse_full_ip6_address (const char *addr_str, GError **error) +{ + NMIP6Address *addr; + char **list; + char *ip_tag, *prefix_tag; + struct in6_addr tmp = IN6ADDR_ANY_INIT; + gboolean success = FALSE; + + g_return_val_if_fail (addr_str != NULL, NULL); + g_return_val_if_fail (error != NULL, NULL); + g_return_val_if_fail (*error == NULL, NULL); + + /* Split the adddress and prefix */ + list = g_strsplit_set (addr_str, "/", 2); + if (g_strv_length (list) < 1) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Invalid IP6 address '%s'", addr_str); + goto error; + } + + ip_tag = list[0]; + prefix_tag = list[1]; + + addr = nm_ip6_address_new (); + /* IP address */ + if (ip_tag) { + if (!parse_ip6_address (ip_tag, &tmp, error)) + goto error; + } + + nm_ip6_address_set_address (addr, &tmp); + + /* Prefix */ + if (prefix_tag) { + long int prefix; + + errno = 0; + prefix = strtol (prefix_tag, NULL, 10); + if (errno || prefix <= 0 || prefix > 128) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Invalid IP6 prefix '%s'", prefix_tag); + 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); + } + + success = TRUE; + +error: + if (!success) { + nm_ip6_address_unref (addr); + addr = NULL; + } + + g_strfreev (list); + return addr; +} + +/* IPv6 address is very complex to describe completely by a regular expression, + * so don't try to, rather use looser syntax to comprise all possibilities + * NOTE: The regexes below don't describe all variants allowed by 'ip route add', + * namely destination IP without 'to' keyword is recognized just at line start. + */ +#define IPV6_ADDR_REGEX "[0-9A-Fa-f:.]+" + +static gboolean +read_route6_file (const char *filename, NMSettingIP6Config *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, *next_hop = NULL, *metric = NULL; + long int prefix_int, metric_int; + gboolean success = FALSE; + + const char *pattern_empty = "^\\s*(\\#.*)?$"; + const char *pattern_to1 = "^\\s*(" IPV6_ADDR_REGEX "|default)" /* IPv6 or 'default' keyword */ + "(?:/(\\d{1,2}))?"; /* optional prefix */ + const char *pattern_to2 = "to\\s+(" IPV6_ADDR_REGEX "|default)" /* IPv6 or 'default' keyword */ + "(?:/(\\d{1,2}))?"; /* optional prefix */ + const char *pattern_via = "via\\s+(" IPV6_ADDR_REGEX ")"; /* IPv6 of gateway */ + const char *pattern_metric = "metric\\s+(\\d+)"; /* metric */ + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (s_ip6 != NULL, FALSE); + g_return_val_if_fail (error != NULL, FALSE); + g_return_val_if_fail (*error == NULL, FALSE); + + /* Read the route file */ + if (!g_file_get_contents (filename, &contents, &len, NULL)) + return FALSE; + + if (len == 0) { + g_free (contents); + return FALSE; + } + + /* Create regexes for pieces to be matched */ + regex_to1 = g_regex_new (pattern_to1, 0, 0, NULL); + regex_to2 = g_regex_new (pattern_to2, 0, 0, NULL); + 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++) { + + /* Skip empty lines */ + if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) + continue; + + /* Destination */ + g_regex_match (regex_to1, *iter, 0, &match_info); + if (!g_match_info_matches (match_info)) { + g_match_info_free (match_info); + 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_quark (), 0, + "Missing IP6 route destination address in record: '%s'", *iter); + goto error; + } + } + dest = g_match_info_fetch (match_info, 1); + g_match_info_free (match_info); + if (!strcmp (dest, "default")) + strcpy (dest, "::"); + if (inet_pton (AF_INET6, dest, &ip6_addr) != 1) { + g_set_error (error, ifcfg_plugin_error_quark (), 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); + prefix_int = 128; + if (prefix) { + errno = 0; + prefix_int = strtol (prefix, NULL, 10); + if (errno || prefix_int < 0 || prefix_int > 128) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Invalid IP6 route destination prefix '%s'", prefix); + 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)) { + g_match_info_free (match_info); + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Missing IP6 route gateway address in record: '%s'", *iter); + goto error; + } + next_hop = g_match_info_fetch (match_info, 1); + g_match_info_free (match_info); + if (inet_pton (AF_INET6, next_hop, &ip6_addr) != 1) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Invalid IP6 route gateway address '%s'", next_hop); + g_free (next_hop); + goto error; + } + nm_ip6_route_set_next_hop (route, &ip6_addr); + g_free (next_hop); + + /* Metric */ + g_regex_match (regex_metric, *iter, 0, &match_info); + metric_int = 0; + 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_quark (), 0, + "Invalid IP6 route metric '%s'", metric); + 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)) + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate IP6 route"); + } + + success = TRUE; + +error: + g_free (contents); + g_strfreev (lines); + nm_ip6_route_unref (route); + g_regex_unref (regex_to1); + g_regex_unref (regex_to2); + g_regex_unref (regex_via); + g_regex_unref (regex_metric); + + return success; +} + static NMSetting * make_ip4_setting (shvarFile *ifcfg, @@ -990,16 +1237,31 @@ make_ip4_setting (shvarFile *ifcfg, g_free (value); } - /* DNS servers */ + /* DNS servers + * Pick up just IPv4 addresses (IPv6 addresses are taken by make_ip6_setting()) + */ for (i = 1, tmp_success = TRUE; i <= 10 && tmp_success; i++) { char *tag; guint32 dns; + struct in6_addr ip6_dns; + GError *tmp_err = NULL; tag = g_strdup_printf ("DNS%u", i); tmp_success = read_ip4_address (ifcfg, tag, &dns, error); if (!tmp_success) { - g_free (tag); - goto error; + /* if it's IPv6, don't exit */ + dns = 0; + value = svGetValue (ifcfg, tag, FALSE); + if (value) { + tmp_success = parse_ip6_address (value, &ip6_dns, &tmp_err); + g_clear_error (&tmp_err); + g_free (value); + } + if (!tmp_success) { + g_free (tag); + goto error; + } + g_clear_error (error); } if (dns && !nm_setting_ip4_config_add_dns (s_ip4, dns)) @@ -1091,6 +1353,202 @@ error: return NULL; } +static NMSetting * +make_ip6_setting (shvarFile *ifcfg, + const char *network_file, + const char *iscsiadm_path, + GError **error) +{ + NMSettingIP6Config *s_ip6 = NULL; + char *value = NULL; + char *str_value; + char *route6_path = NULL; + gboolean bool_value, ipv6forwarding, ipv6_autoconf; + char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL; + guint32 i; + shvarFile *network_ifcfg; + gboolean never_default = FALSE, tmp_success; + + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + if (!s_ip6) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Could not allocate IP6 setting"); + return NULL; + } + + /* Is IPV6 enabled? Set method to "ignored", when not enabled */ + str_value = svGetValue (ifcfg, "IPV6INIT", FALSE); + bool_value = svTrueValue (ifcfg, "IPV6INIT", FALSE); + if (!str_value) { + network_ifcfg = svNewFile (network_file); + if (network_ifcfg) { + bool_value = svTrueValue (network_ifcfg, "IPV6INIT", FALSE); + svCloseFile (network_ifcfg); + } + } + g_free (str_value); + + if (!bool_value) { + /* IPv6 is disabled */ + g_object_set (s_ip6, + NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NULL); + return NM_SETTING (s_ip6); + } + + /* 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 + * specified is IPV6_DEFROUTE=yes which means that this connection can be used + * as a default route + */ + never_default = !svTrueValue (ifcfg, "IPV6_DEFROUTE", TRUE); + + /* Then check if IPV6_DEFAULTGW or IPV6_DEFAULTDEV is specified; + * they are global and override IPV6_DEFROUTE + * When both are set, the device specified in IPV6_DEFAULTGW takes preference. + */ + network_ifcfg = svNewFile (network_file); + if (network_ifcfg) { + char *ipv6_defaultgw, *ipv6_defaultdev; + char *default_dev = NULL; + + /* Get the connection ifcfg device name and the global default route device */ + value = svGetValue (ifcfg, "DEVICE", FALSE); + ipv6_defaultgw = svGetValue (network_ifcfg, "IPV6_DEFAULTGW", FALSE); + ipv6_defaultdev = svGetValue (network_ifcfg, "IPV6_DEFAULTDEV", FALSE); + + if (ipv6_defaultgw) { + default_dev = strchr (ipv6_defaultgw, '%'); + if (default_dev) + default_dev++; + } + if (!default_dev) + default_dev = ipv6_defaultdev; + + /* If there was a global default route device specified, then only connections + * for that device can be the default connection. + */ + if (default_dev && value) + never_default = !!strcmp (value, default_dev); + + g_free (ipv6_defaultgw); + g_free (ipv6_defaultdev); + g_free (value); + svCloseFile (network_ifcfg); + } + + /* Find out method property */ + ipv6forwarding = svTrueValue (ifcfg, "IPV6FORWARDING", FALSE); + ipv6_autoconf = svTrueValue (ifcfg, "IPV6_AUTOCONF", !ipv6forwarding); + + if (ipv6_autoconf) + method = NM_SETTING_IP6_CONFIG_METHOD_AUTO; + else { + /* IPV6_AUTOCONF=no and no IPv6 address -> method 'link-local' */ + str_value = svGetValue (ifcfg, "IPV6ADDR", FALSE); + if (!str_value) + str_value = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE); + + if (!str_value) + method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; + g_free (str_value); + } + /* TODO - handle other methods */ + + 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, + NULL); + + if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + NMIP6Address *addr; + char *val; + char *ipv6addr, *ipv6addr_secondaries; + char **list = NULL, **iter; + + ipv6addr = svGetValue (ifcfg, "IPV6ADDR", FALSE); + ipv6addr_secondaries = svGetValue (ifcfg, "IPV6ADDR_SECONDARIES", FALSE); + + val = g_strjoin (ipv6addr && ipv6addr_secondaries ? " " : NULL, + ipv6addr ? ipv6addr : "", + ipv6addr_secondaries ? ipv6addr_secondaries : "", + NULL); + g_free (ipv6addr); + g_free (ipv6addr_secondaries); + + list = g_strsplit_set (val, " ", 0); + g_free (val); + for (iter = list; iter && *iter; iter++, i++) { + addr = parse_full_ip6_address (*iter, error); + if (!addr) { + g_strfreev (list); + goto error; + } + + if (!nm_setting_ip6_config_add_address (s_ip6, addr)) + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate IP6 address"); + nm_ip6_address_unref (addr); + } + g_strfreev (list); + } else if (!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { + /* TODO - autoconf or DHCPv6 stuff goes here */ + } + + /* DNS servers + * Pick up just IPv6 addresses (IPv4 addresses are taken by make_ip4_setting()) + */ + for (i = 1, tmp_success = TRUE; i <= 10 && tmp_success; i++) { + char *tag; + struct in6_addr ip6_dns; + + ip6_dns = in6addr_any; + tag = g_strdup_printf ("DNS%u", i); + value = svGetValue (ifcfg, tag, FALSE); + if (value) + tmp_success = parse_ip6_address (value, &ip6_dns, error); + + if (!tmp_success) { + struct in_addr ip4_addr; + if (inet_pton (AF_INET, value, &ip4_addr) != 1) { + g_free (tag); + g_free (value); + goto error; + } + /* ignore error - it is IPv4 address */ + tmp_success = TRUE; + g_clear_error (error); + } + + if (!IN6_IS_ADDR_UNSPECIFIED (&ip6_dns) && !nm_setting_ip6_config_add_dns (s_ip6, &ip6_dns)) + PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: duplicate DNS server %s", tag); + g_free (tag); + g_free (value); + } + + /* DNS searches ('DOMAIN' key) are read by make_ip4_setting() and included in NMSettingIP4Config */ + + /* Read static routes from route6- file */ + route6_path = utils_get_route6_path (ifcfg->fileName); + if (!route6_path) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Could not get route6 file path for '%s'", ifcfg->fileName); + goto error; + } + + read_route6_file (route6_path, s_ip6, error); + g_free (route6_path); + if (error && *error) + goto error; + + return NM_SETTING (s_ip6); + +error: + g_object_unref (s_ip6); + return NULL; +} + static gboolean add_one_wep_key (shvarFile *ifcfg, const char *shvar_key, @@ -2575,13 +3033,14 @@ connection_from_file (const char *filename, char **unmanaged, char **keyfile, char **routefile, + char **route6file, GError **error, gboolean *ignore_error) { NMConnection *connection = NULL; shvarFile *parsed; char *type, *nmc = NULL, *bootproto; - NMSetting *s_ip4; + NMSetting *s_ip4, *s_ip6; const char *ifcfg_name = NULL; gboolean nm_controlled = TRUE; @@ -2592,6 +3051,8 @@ connection_from_file (const char *filename, g_return_val_if_fail (*keyfile == NULL, NULL); g_return_val_if_fail (routefile != NULL, NULL); g_return_val_if_fail (*routefile == NULL, NULL); + g_return_val_if_fail (route6file != NULL, NULL); + g_return_val_if_fail (*route6file == NULL, NULL); /* Non-NULL only for unit tests; normally use /etc/sysconfig/network */ if (!network_file) @@ -2694,6 +3155,14 @@ connection_from_file (const char *filename, nm_connection_add_setting (connection, s_ip4); } + s_ip6 = make_ip6_setting (parsed, network_file, iscsiadm_path, error); + if (*error) { + g_object_unref (connection); + connection = NULL; + goto done; + } else if (s_ip6) + nm_connection_add_setting (connection, s_ip6); + /* iSCSI / ibft connections are read-only since their settings are * stored in NVRAM and can only be changed in BIOS. */ @@ -2716,6 +3185,7 @@ connection_from_file (const char *filename, *keyfile = utils_get_keys_path (filename); *routefile = utils_get_route_path (filename); + *route6file = utils_get_route6_path (filename); done: svCloseFile (parsed); diff --git a/system-settings/plugins/ifcfg-rh/reader.h b/system-settings/plugins/ifcfg-rh/reader.h index a5df59c632..2a031977dc 100644 --- a/system-settings/plugins/ifcfg-rh/reader.h +++ b/system-settings/plugins/ifcfg-rh/reader.h @@ -33,6 +33,7 @@ NMConnection *connection_from_file (const char *filename, char **unmanaged, char **keyfile, char **routefile, + char **route6file, GError **error, gboolean *ignore_error); diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am index 7d55382709..78ac04d487 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am @@ -52,7 +52,9 @@ EXTRA_DIST = \ ifcfg-test-wired-static-routes \ route-test-wired-static-routes \ ifcfg-test-wired-static-routes-legacy \ - route-test-wired-static-routes-legacy + route-test-wired-static-routes-legacy \ + ifcfg-test-wired-ipv6-manual \ + route6-test-wired-ipv6-manual check-local: @for f in $(EXTRA_DIST); do \ diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy index 606f56b798..2173729d17 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy @@ -7,5 +7,6 @@ BOOTPROTO=dhcp DEFROUTE=yes UUID=ba60d05a-7898-820d-c2db-427a88f8f2a5 ONBOOT=yes +IPV6INIT=no PEERDNS=yes PEERROUTES=yes diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no index 266fe1eebd..fe8b15b29a 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no @@ -9,3 +9,7 @@ NM_CONTROLLED=yes PEERDNS=yes DEFROUTE=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=no + diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes index ede2927301..3cf4323dd2 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes @@ -9,3 +9,7 @@ NM_CONTROLLED=yes PEERDNS=yes DEFROUTE=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=no + diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual new file mode 100644 index 0000000000..4be4044f18 --- /dev/null +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual @@ -0,0 +1,18 @@ +# Intel Corporation 82567LM Gigabit Network Connection +TYPE=Ethernet +DEVICE=eth2 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DNS1=10.2.0.4 +DNS2=10.2.0.5 +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +DOMAIN="lorem.com ipsum.org dolor.edu" +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR="1001:abba::1234/56" +IPV6ADDR_SECONDARIES="2001:abba::2234/64 3001:abba::3234/96" diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default index c059253075..12d5b5e635 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default @@ -7,4 +7,5 @@ ONBOOT=yes USERCTL=yes NM_CONTROLLED=yes PEERDNS=yes - +IPV6INIT=yes +IPV6_AUTOCONF=yes diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static index 7faf49bdae..c8315f45d3 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static @@ -5,7 +5,6 @@ HWADDR=00:11:22:33:44:ee BOOTPROTO=none ONBOOT=yes USERCTL=yes -IPV6INIT=no MTU=1492 NM_CONTROLLED=yes DNS1=4.2.2.1 @@ -13,3 +12,9 @@ DNS2=4.2.2.2 IPADDR=192.168.1.5 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes b/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes index b5579c67d4..0d6a302f12 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes @@ -1 +1,2 @@ GATEWAYDEV=eth0 +IPV6_DEFAULTDEV=eth0 diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default b/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default index b5579c67d4..9a292679a1 100644 --- a/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default @@ -1 +1,4 @@ GATEWAYDEV=eth0 +# when devices in IPV6_DEFAULTDEV and IPV6_DEFAULTGW don't match the one in IPV6_DEFAULTGW is prefered +IPV6_DEFAULTDEV=eth4 +IPV6_DEFAULTGW=2001::1234%eth0 diff --git a/system-settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual b/system-settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual new file mode 100644 index 0000000000..ae4e47ae55 --- /dev/null +++ b/system-settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual @@ -0,0 +1 @@ +9876::1234/96 via 9876::7777 metric 2 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 5c899acbda..88ce1fffe9 100644 --- a/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -187,6 +188,7 @@ test_read_minimal (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -202,6 +204,7 @@ test_read_minimal (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -319,6 +322,7 @@ test_read_unmanaged (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -334,6 +338,7 @@ test_read_unmanaged (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -430,9 +435,11 @@ test_read_wired_static (const char *file, const char *expected_id) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *unmanaged = FALSE; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const GByteArray *array; @@ -441,9 +448,15 @@ test_read_wired_static (const char *file, const char *expected_id) const char *expected_dns1 = "4.2.2.1"; const char *expected_dns2 = "4.2.2.2"; struct in_addr 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; connection = connection_from_file (file, NULL, @@ -452,6 +465,7 @@ test_read_wired_static (const char *file, const char *expected_id) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -617,6 +631,89 @@ test_read_wired_static (const char *file, const char *expected_id) NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_ADDRESSES); + if (!strcmp (expected_id, "System test-wired-static")) { + /* ===== IPv6 SETTING ===== */ + + s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG)); + ASSERT (s_ip6 != NULL, + "wired-static-verify-ip6", "failed to verify %s: missing %s setting", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME); + + /* Method */ + tmp = nm_setting_ip6_config_get_method (s_ip6); + ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, + "wired-static-verify-ip6", "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_METHOD); + + /* DNS Addresses */ + ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2, + "wired-static-verify-ip6", "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS); + + ASSERT (inet_pton (AF_INET6, expected6_dns1, &addr6) > 0, + "wired-static-verify-ip6", "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), &addr6), + "wired-static-verify-ip6", "failed to verify %s: unexpected %s / %s key value #1", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS); + + ASSERT (inet_pton (AF_INET6, expected6_dns2, &addr6) > 0, + "wired-static-verify-ip6", "failed to verify %s: couldn't convert DNS IP address #2", + file); + ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), &addr6), + "wired-static-verify-ip6", "failed to verify %s: unexpected %s / %s key value #2", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS); + + ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 2, + "wired-static-verify-ip6", "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_ADDRESSES); + + /* Address #1 */ + ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); + ASSERT (ip6_addr, + "wired-static-verify-ip6", "failed to verify %s: missing IP6 address #1", + file); + + ASSERT (nm_ip6_address_get_prefix (ip6_addr) == 64, + "wired-static-verify-ip6", "failed to verify %s: unexpected IP6 address #1 prefix", + file); + + ASSERT (inet_pton (AF_INET6, expected6_address1, &addr6) > 0, + "wired-static-verify-ip6", "failed to verify %s: couldn't convert IP address #1", + file); + ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6), + "wired-static-verify-ip6", "failed to verify %s: unexpected IP6 address #1", + file); + + /* Address #2 */ + ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 1); + ASSERT (ip6_addr, + "wired-static-verify-ip6", "failed to verify %s: missing IP6 address #2", + file); + + ASSERT (nm_ip6_address_get_prefix (ip6_addr) == 56, + "wired-static-verify-ip6", "failed to verify %s: unexpected IP6 address #2 prefix", + file); + + ASSERT (inet_pton (AF_INET6, expected6_address2, &addr6) > 0, + "wired-static-verify-ip6", "failed to verify %s: couldn't convert IP address #2", + file); + ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), &addr6), + "wired-static-verify-ip6", "failed to verify %s: unexpected IP6 address #2", + file); + } + g_object_unref (connection); } @@ -632,6 +729,7 @@ test_read_wired_dhcp (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const GByteArray *array; @@ -650,6 +748,7 @@ test_read_wired_dhcp (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -802,6 +901,7 @@ test_read_wired_global_gateway (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -818,6 +918,7 @@ test_read_wired_global_gateway (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -923,9 +1024,11 @@ test_read_wired_never_default (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -938,6 +1041,7 @@ test_read_wired_never_default (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -1007,6 +1111,28 @@ test_read_wired_never_default (void) NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DNS); + /* ===== IPv6 SETTING ===== */ + + s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG)); + 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_object_unref (connection); } @@ -1019,9 +1145,11 @@ test_read_wired_defroute_no (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1034,6 +1162,7 @@ test_read_wired_defroute_no (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -1096,6 +1225,28 @@ test_read_wired_defroute_no (void) NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT); + /* ===== IPv6 SETTING ===== */ + + s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG)); + ASSERT (s_ip6 != NULL, + "wired-defroute-no-verify-ip6", "failed to verify %s: missing %s setting", + TEST_IFCFG_WIRED_DEFROUTE_NO, + 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-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); + + ASSERT (nm_setting_ip6_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); + g_object_unref (connection); } @@ -1109,9 +1260,11 @@ test_read_wired_defroute_no_gatewaydev_yes (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1124,6 +1277,7 @@ test_read_wired_defroute_no_gatewaydev_yes (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -1194,6 +1348,28 @@ test_read_wired_defroute_no_gatewaydev_yes (void) NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT); + /* ===== IPv6 SETTING ===== */ + + s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG)); + ASSERT (s_ip6 != NULL, + "wired-defroute-no-gatewaydev-yes-verify-ip6", "failed to verify %s: missing %s setting", + TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, + 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", + TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_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", + TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_NEVER_DEFAULT); + g_object_unref (connection); } @@ -1209,6 +1385,7 @@ test_read_wired_static_routes (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1227,6 +1404,7 @@ test_read_wired_static_routes (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); @@ -1355,6 +1533,7 @@ test_read_wired_static_routes (void) g_free (keyfile); g_free (routefile); + g_free (route6file); g_object_unref (connection); } @@ -1370,6 +1549,7 @@ test_read_wired_static_routes_legacy (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1390,6 +1570,7 @@ test_read_wired_static_routes_legacy (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); @@ -1557,6 +1738,300 @@ test_read_wired_static_routes_legacy (void) g_free (keyfile); g_free (routefile); + g_free (route6file); + g_object_unref (connection); +} + +#define TEST_IFCFG_WIRED_IPV6_MANUAL TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-ipv6-manual" + +static void +test_read_wired_ipv6_manual (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; + char *unmanaged = NULL; + char *keyfile = NULL; + char *routefile = NULL; + char *route6file = NULL; + gboolean ignore_error = FALSE; + GError *error = NULL; + const char *tmp; + const char *expected_id = "System test-wired-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_route1_dest = "9876::1234"; + guint32 expected_route1_prefix = 96; + const char *expected_route1_nexthop = "9876::7777"; + guint32 expected_route1_metric = 2; + 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; + + connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_MANUAL, + NULL, + TYPE_ETHERNET, + NULL, + &unmanaged, + &keyfile, + &routefile, + &route6file, + &error, + &ignore_error); + ASSERT (connection != NULL, + "wired-ipv6-manual-read", "failed to read %s: %s", TEST_IFCFG_WIRED_IPV6_MANUAL, error->message); + + ASSERT (nm_connection_verify (connection, &error), + "wired-ipv6-manual-verify", "failed to verify %s: %s", TEST_IFCFG_WIRED_IPV6_MANUAL, error->message); + + ASSERT (unmanaged == FALSE, + "wired-ipv6-manual-verify", "failed to verify %s: unexpected unmanaged value", TEST_IFCFG_WIRED_IPV6_MANUAL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); + ASSERT (s_con != NULL, + "wired-ipv6-manual-verify-connection", "failed to verify %s: missing %s setting", + TEST_IFCFG_WIRED_IPV6_MANUAL, + NM_SETTING_CONNECTION_SETTING_NAME); + + /* ID */ + tmp = nm_setting_connection_get_id (s_con); + ASSERT (tmp != NULL, + "wired-ipv6-manual-verify-connection", "failed to verify %s: missing %s / %s key", + TEST_IFCFG_WIRED_IPV6_MANUAL, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_ID); + ASSERT (strcmp (tmp, expected_id) == 0, + "wired-ipv6-manual-verify-connection", "failed to verify %s: unexpected %s / %s key value", + TEST_IFCFG_WIRED_IPV6_MANUAL, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_ID); + + /* ===== WIRED SETTING ===== */ + + s_wired = NM_SETTING_WIRED (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED)); + ASSERT (s_wired != NULL, + "wired-ipv6-manual-verify-wired", "failed to verify %s: missing %s setting", + TEST_IFCFG_WIRED_IPV6_MANUAL, + NM_SETTING_WIRED_SETTING_NAME); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG)); + ASSERT (s_ip4 != NULL, + "wired-ipv6-manual-verify-ip4", "failed to verify %s: missing %s setting", + TEST_IFCFG_WIRED_IPV6_MANUAL, + NM_SETTING_IP4_CONFIG_SETTING_NAME); + + /* DNS Addresses */ + ASSERT (nm_setting_ip4_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); + + /* DNS search domains */ + ASSERT (nm_setting_ip4_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); + + tmp = nm_setting_ip4_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); + 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); + + tmp = nm_setting_ip4_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); + 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); + + tmp = nm_setting_ip4_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); + 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); + + /* ===== IPv6 SETTING ===== */ + + s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG)); + ASSERT (s_ip6 != NULL, + "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing %s setting", + TEST_IFCFG_WIRED_IPV6_MANUAL, + NM_SETTING_IP6_CONFIG_SETTING_NAME); + + /* Method */ + tmp = nm_setting_ip6_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); + + ASSERT (nm_setting_ip6_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); + + /* IP addresses */ + ASSERT (nm_setting_ip6_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); + + /* 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); + + /* 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); + + /* 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); + + /* Routes */ + ASSERT (nm_setting_ip6_config_get_num_routes (s_ip6) == 1, + "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_ROUTES); + + /* Route #1 */ + ip6_route = nm_setting_ip6_config_get_route (s_ip6, 0); + ASSERT (ip6_route, + "wired-ipv6-manual-verify-ip6", "failed to verify %s: missing IP6 route #1", + TEST_IFCFG_WIRED_IPV6_MANUAL); + + ASSERT (inet_pton (AF_INET6, expected_route1_dest, &addr) > 0, + "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP route dest #1", + TEST_IFCFG_WIRED_IPV6_MANUAL); + ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_route_get_dest (ip6_route), &addr), + "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 route dest #1", + TEST_IFCFG_WIRED_IPV6_MANUAL); + + ASSERT (nm_ip6_route_get_prefix (ip6_route) == expected_route1_prefix, + "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 route #1 prefix", + TEST_IFCFG_WIRED_IPV6_MANUAL); + + ASSERT (inet_pton (AF_INET6, expected_route1_nexthop, &addr) > 0, + "wired-ipv6-manual-verify-ip6", "failed to verify %s: couldn't convert IP route next_hop #1", + TEST_IFCFG_WIRED_IPV6_MANUAL); + ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_route_get_next_hop (ip6_route), &addr), + "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 route next hop #1", + TEST_IFCFG_WIRED_IPV6_MANUAL); + + ASSERT (nm_ip6_route_get_metric (ip6_route) == expected_route1_metric, + "wired-ipv6-manual-verify-ip6", "failed to verify %s: unexpected IP6 route #1 metric", + TEST_IFCFG_WIRED_IPV6_MANUAL); + + /* DNS Addresses */ + ASSERT (nm_setting_ip6_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); + + 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), + "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); + + 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), + "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); + + /* DNS domains - none as domains are stuffed to 'ipv4' setting */ + ASSERT (nm_setting_ip6_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); + + g_free (keyfile); + g_free (routefile); + g_free (route6file); g_object_unref (connection); } @@ -1570,6 +2045,7 @@ test_read_onboot_no (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; @@ -1580,6 +2056,7 @@ test_read_onboot_no (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -1623,6 +2100,7 @@ test_read_wired_8021x_peap_mschapv2 (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1639,6 +2117,7 @@ test_read_wired_8021x_peap_mschapv2 (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -1805,6 +2284,7 @@ test_read_wifi_open (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1823,6 +2303,7 @@ test_read_wifi_open (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -1980,6 +2461,7 @@ test_read_wifi_open_auto (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -1993,6 +2475,7 @@ test_read_wifi_open_auto (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -2056,6 +2539,7 @@ test_read_wifi_open_ssid_hex (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -2070,6 +2554,7 @@ test_read_wifi_open_ssid_hex (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -2135,6 +2620,7 @@ test_read_wifi_open_ssid_bad (const char *file, const char *test) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; @@ -2145,6 +2631,7 @@ test_read_wifi_open_ssid_bad (const char *file, const char *test) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection == NULL, test, "unexpected success reading %s", file); @@ -2162,6 +2649,7 @@ test_read_wifi_open_ssid_quoted (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -2176,6 +2664,7 @@ test_read_wifi_open_ssid_quoted (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -2247,6 +2736,7 @@ test_read_wifi_wep (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -2266,6 +2756,7 @@ test_read_wifi_wep (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -2510,6 +3001,7 @@ test_read_wifi_wep_adhoc (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -2529,6 +3021,7 @@ test_read_wifi_wep_adhoc (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -2771,6 +3264,7 @@ test_read_wifi_leap (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -2785,6 +3279,7 @@ test_read_wifi_leap (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -2906,6 +3401,7 @@ test_read_wifi_wpa_psk (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -2935,6 +3431,7 @@ test_read_wifi_wpa_psk (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -3218,6 +3715,7 @@ test_read_wifi_wpa_psk_unquoted (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -3231,6 +3729,7 @@ test_read_wifi_wpa_psk_unquoted (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -3314,6 +3813,7 @@ test_read_wifi_wpa_psk_unquoted2 (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; @@ -3328,6 +3828,7 @@ test_read_wifi_wpa_psk_unquoted2 (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection == NULL, @@ -3348,6 +3849,7 @@ test_read_wifi_wpa_psk_adhoc (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -3365,6 +3867,7 @@ test_read_wifi_wpa_psk_adhoc (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -3534,6 +4037,7 @@ test_read_wifi_wpa_psk_hex (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -3550,6 +4054,7 @@ test_read_wifi_wpa_psk_hex (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -3686,6 +4191,7 @@ test_read_wifi_wpa_eap_tls (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp, *password; @@ -3699,6 +4205,7 @@ test_read_wifi_wpa_eap_tls (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -3830,6 +4337,7 @@ test_read_wifi_wpa_eap_ttls_tls (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp, *password; @@ -3843,6 +4351,7 @@ test_read_wifi_wpa_eap_ttls_tls (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -3996,6 +4505,7 @@ test_read_wifi_wep_eap_ttls_chap (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -4010,6 +4520,7 @@ test_read_wifi_wep_eap_ttls_chap (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -4148,7 +4659,8 @@ test_write_wired_static (void) NMConnection *reread; NMSettingConnection *s_con; NMSettingWired *s_wired; - NMSettingIP4Config *s_ip4; + NMSettingIP4Config *s_ip4, *reread_s_ip4; + NMSettingIP6Config *s_ip6, *reread_s_ip6; static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; GByteArray *mac; guint32 mtu = 1492; @@ -4162,15 +4674,35 @@ test_write_wired_static (void) const guint32 prefix = 24; 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 = 0; + const guint32 route1_metric = 99, route2_metric = 1; NMIP4Address *addr; + NMIP6Address *addr6; + NMIP6Route *route6; gboolean success; GError *error = NULL; char *testfile = NULL; char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + 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 (); ASSERT (connection != NULL, "wired-static-write", "failed to allocate new connection"); @@ -4239,6 +4771,61 @@ test_write_wired_static (void) nm_setting_ip4_config_add_dns_search (s_ip4, dns_search1); nm_setting_ip4_config_add_dns_search (s_ip4, dns_search2); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wired-static-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, + 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); + + /* 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); + + /* DNS servers */ + nm_setting_ip6_config_add_dns (s_ip6, &dns6_1); + nm_setting_ip6_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); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wired-static-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -4263,6 +4850,7 @@ test_write_wired_static (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -4273,10 +4861,27 @@ test_write_wired_static (void) ASSERT (nm_connection_verify (reread, &error), "wired-static-write-reread-verify", "failed to verify %s: %s", testfile, error->message); + /* FIXME: currently DNS domains from IPv6 setting are stored in 'DOMAIN' key in ifcfg-file + * However after re-reading they are dropped into IPv4 setting. + * So, in order to comparison succeeded, move DNS domains back to IPv6 setting. + */ + reread_s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (reread, NM_TYPE_SETTING_IP4_CONFIG)); + reread_s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (reread, NM_TYPE_SETTING_IP6_CONFIG)); + 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); + ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE, "wired-static-write", "written and re-read connection weren't the same."); + if (route6file) + unlink (route6file); + g_free (testfile); + g_free (keyfile); + g_free (routefile); + g_free (route6file); g_object_unref (connection); g_object_unref (reread); } @@ -4289,6 +4894,7 @@ test_write_wired_dhcp (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -4296,6 +4902,7 @@ test_write_wired_dhcp (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; connection = nm_connection_new (); @@ -4344,6 +4951,17 @@ test_write_wired_dhcp (void) "wired-dhcp-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wired-dhcp-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, + NULL); + /* Save the ifcfg */ success = writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", @@ -4364,6 +4982,7 @@ test_write_wired_dhcp (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -4397,6 +5016,8 @@ test_read_write_static_routes_legacy (void) char *keyfile2 = NULL; char *routefile = NULL; char *routefile2 = NULL; + char *route6file = NULL; + char *route6file2 = NULL; gboolean ignore_error = FALSE; gboolean success; GError *error = NULL; @@ -4409,6 +5030,7 @@ test_read_write_static_routes_legacy (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -4495,10 +5117,12 @@ test_read_write_static_routes_legacy (void) &unmanaged, &keyfile2, &routefile2, + &route6file2, &error, &ignore_error); unlink (testfile); unlink (routefile2); + unlink (route6file2); ASSERT (reread != NULL, "read-write-static-routes-legacy-reread", "failed to read %s: %s", testfile, error->message); @@ -4517,6 +5141,8 @@ test_read_write_static_routes_legacy (void) g_free (keyfile2); g_free (routefile); g_free (routefile2); + g_free (route6file); + g_free (route6file2); g_object_unref (connection); g_object_unref (reread); } @@ -4529,6 +5155,7 @@ test_write_wired_static_routes (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd }; GByteArray *mac; guint32 mtu = 1492; @@ -4554,6 +5181,7 @@ test_write_wired_static_routes (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; connection = nm_connection_new (); @@ -4640,6 +5268,15 @@ test_write_wired_static_routes (void) nm_setting_ip4_config_add_dns_search (s_ip4, dns_search1); nm_setting_ip4_config_add_dns_search (s_ip4, dns_search2); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wired-dhcp-8021x-peap-mschapv2write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wired-static-routes-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -4664,6 +5301,7 @@ test_write_wired_static_routes (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -4684,6 +5322,7 @@ test_write_wired_static_routes (void) g_free (testfile); g_free (keyfile); g_free (routefile); + g_free (route6file); g_object_unref (connection); g_object_unref (reread); } @@ -4696,6 +5335,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; NMSetting8021x *s_8021x; char *uuid; gboolean success; @@ -4704,6 +5344,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; connection = nm_connection_new (); @@ -4742,6 +5383,15 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wired-dhcp-8021x-peap-mschapv2write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + /* 802.1x setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); ASSERT (s_8021x != NULL, @@ -4792,6 +5442,7 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -4822,6 +5473,7 @@ test_write_wifi_open (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -4829,6 +5481,7 @@ test_write_wifi_open (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -4895,6 +5548,15 @@ test_write_wifi_open (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-open-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-open-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -4919,6 +5581,7 @@ test_write_wifi_open (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -4945,6 +5608,7 @@ test_write_wifi_open_hex_ssid (void) NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -4952,6 +5616,7 @@ test_write_wifi_open_hex_ssid (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }; @@ -5002,6 +5667,15 @@ test_write_wifi_open_hex_ssid (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-open-hex-ssid-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-open-hex-ssid-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5026,6 +5700,7 @@ test_write_wifi_open_hex_ssid (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5053,6 +5728,7 @@ test_write_wifi_wep (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -5060,6 +5736,7 @@ test_write_wifi_wep (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = "blahblah"; @@ -5129,6 +5806,15 @@ test_write_wifi_wep (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-wep-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-wep-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5153,6 +5839,7 @@ test_write_wifi_wep (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5192,6 +5879,7 @@ test_write_wifi_wep_adhoc (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -5199,6 +5887,7 @@ test_write_wifi_wep_adhoc (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = "blahblah"; @@ -5276,6 +5965,15 @@ test_write_wifi_wep_adhoc (void) nm_setting_ip4_config_add_dns (s_ip4, dns1); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-wep-adhoc-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-wep-adhoc-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5300,6 +5998,7 @@ test_write_wifi_wep_adhoc (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5339,6 +6038,7 @@ test_write_wifi_leap (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -5346,6 +6046,7 @@ test_write_wifi_leap (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = "blahblah"; @@ -5412,6 +6113,15 @@ test_write_wifi_leap (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-leap-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-leap-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5436,6 +6146,7 @@ test_write_wifi_leap (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5480,6 +6191,7 @@ test_write_wifi_wpa_psk (const char *name, NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid, *tmp; gboolean success; GError *error = NULL; @@ -5487,6 +6199,7 @@ test_write_wifi_wpa_psk (const char *name, char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = "blahblah"; @@ -5567,6 +6280,15 @@ test_write_wifi_wpa_psk (const char *name, g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + test_name, "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, test_name, "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5591,6 +6313,7 @@ test_write_wifi_wpa_psk (const char *name, &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5624,6 +6347,7 @@ test_write_wifi_wpa_psk_adhoc (void) NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -5631,6 +6355,7 @@ test_write_wifi_wpa_psk_adhoc (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const unsigned char ssid_data[] = "blahblah"; @@ -5714,6 +6439,15 @@ test_write_wifi_wpa_psk_adhoc (void) nm_setting_ip4_config_add_dns (s_ip4, dns1); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-wpa-psk-adhoc-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-wpa-psk-adhoc-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5738,6 +6472,7 @@ test_write_wifi_wpa_psk_adhoc (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5770,6 +6505,7 @@ test_write_wifi_wpa_eap_tls (void) NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -5777,6 +6513,7 @@ test_write_wifi_wpa_eap_tls (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const char *ssid_data = "blahblah"; @@ -5879,6 +6616,15 @@ test_write_wifi_wpa_eap_tls (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-wpa-eap-tls-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-wpa-eap-tls-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -5903,6 +6649,7 @@ test_write_wifi_wpa_eap_tls (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -5935,6 +6682,7 @@ test_write_wifi_wpa_eap_ttls_tls (void) NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -5942,6 +6690,7 @@ test_write_wifi_wpa_eap_ttls_tls (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const char *ssid_data = "blahblah"; @@ -6062,6 +6811,15 @@ test_write_wifi_wpa_eap_ttls_tls (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-wpa-eap-ttls-tls-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-wpa-eap-ttls-tls-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -6086,6 +6844,7 @@ test_write_wifi_wpa_eap_ttls_tls (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -6118,6 +6877,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; char *uuid; gboolean success; GError *error = NULL; @@ -6125,6 +6885,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GByteArray *ssid; const char *ssid_data = "blahblah"; @@ -6217,6 +6978,15 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + /* IP6 setting */ + s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); + ASSERT (s_ip6 != NULL, + "wifi-wpa-eap-ttls-mschapv2-write", "failed to allocate new %s setting", + NM_SETTING_IP6_CONFIG_SETTING_NAME); + 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, NULL); + ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-wpa-eap-ttls-mschapv2-write", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); @@ -6241,6 +7011,7 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); unlink (testfile); @@ -6275,6 +7046,7 @@ test_read_ibft_dhcp (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -6290,6 +7062,7 @@ test_read_ibft_dhcp (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -6408,6 +7181,7 @@ test_read_ibft_static (void) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; const char *tmp; @@ -6429,6 +7203,7 @@ test_read_ibft_static (void) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection != NULL, @@ -6613,6 +7388,7 @@ test_read_ibft_malformed (const char *name, const char *iscsiadm_path) char *unmanaged = NULL; char *keyfile = NULL; char *routefile = NULL; + char *route6file = NULL; gboolean ignore_error = FALSE; GError *error = NULL; @@ -6623,6 +7399,7 @@ test_read_ibft_malformed (const char *name, const char *iscsiadm_path) &unmanaged, &keyfile, &routefile, + &route6file, &error, &ignore_error); ASSERT (connection == NULL, @@ -6925,6 +7702,7 @@ int main (int argc, char **argv) test_read_wired_defroute_no_gatewaydev_yes (); test_read_wired_static_routes (); test_read_wired_static_routes_legacy (); + test_read_wired_ipv6_manual (); test_read_onboot_no (); test_read_wired_8021x_peap_mschapv2 (); test_read_wifi_open (); diff --git a/system-settings/plugins/ifcfg-rh/utils.c b/system-settings/plugins/ifcfg-rh/utils.c index 3194c2157b..211458bec8 100644 --- a/system-settings/plugins/ifcfg-rh/utils.c +++ b/system-settings/plugins/ifcfg-rh/utils.c @@ -149,7 +149,8 @@ utils_should_ignore_file (const char *filename, gboolean only_ifcfg) if (only_ifcfg == FALSE) { if ( !strncmp (base, KEYS_TAG, strlen (KEYS_TAG)) - || !strncmp (base, ROUTE_TAG, strlen (ROUTE_TAG))) + || !strncmp (base, ROUTE_TAG, strlen (ROUTE_TAG)) + || !strncmp (base, ROUTE6_TAG, strlen (ROUTE6_TAG))) is_other = TRUE; } @@ -208,6 +209,8 @@ utils_get_ifcfg_name (const char *file, gboolean only_ifcfg) name = start + strlen (KEYS_TAG); else if (!strncmp (start, ROUTE_TAG, strlen (ROUTE_TAG))) name = start + strlen (ROUTE_TAG); + else if (!strncmp (start, ROUTE6_TAG, strlen (ROUTE6_TAG))) + name = start + strlen (ROUTE6_TAG); } return name; @@ -259,6 +262,12 @@ utils_get_route_path (const char *parent) return utils_get_extra_path (parent, ROUTE_TAG); } +char * +utils_get_route6_path (const char *parent) +{ + return utils_get_extra_path (parent, ROUTE6_TAG); +} + shvarFile * utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create) { @@ -291,9 +300,15 @@ utils_get_route_ifcfg (const char *parent, gboolean should_create) return utils_get_extra_ifcfg (parent, ROUTE_TAG, should_create); } +shvarFile * +utils_get_route6_ifcfg (const char *parent, gboolean should_create) +{ + return utils_get_extra_ifcfg (parent, ROUTE6_TAG, should_create); +} + /* Finds out if route file has new or older format * Returns TRUE - new syntax (ADDRESS=a.b.c.d ...), error opening file or empty - * FALSE - legacy syntax (1.2.3.0/24 via 11.22.33.44) + * FALSE - older syntax, i.e. argument to 'ip route add' (1.2.3.0/24 via 11.22.33.44) */ gboolean utils_has_route_file_new_syntax (const char *filename) diff --git a/system-settings/plugins/ifcfg-rh/utils.h b/system-settings/plugins/ifcfg-rh/utils.h index 00dbcdcc97..d5e3a13354 100644 --- a/system-settings/plugins/ifcfg-rh/utils.h +++ b/system-settings/plugins/ifcfg-rh/utils.h @@ -38,10 +38,12 @@ gboolean utils_should_ignore_file (const char *filename, gboolean only_ifcfg); char *utils_get_ifcfg_path (const char *parent); char *utils_get_keys_path (const char *parent); char *utils_get_route_path (const char *parent); +char *utils_get_route6_path (const char *parent); shvarFile *utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create); shvarFile *utils_get_keys_ifcfg (const char *parent, gboolean should_create); shvarFile *utils_get_route_ifcfg (const char *parent, gboolean should_create); +shvarFile *utils_get_route6_ifcfg (const char *parent, gboolean should_create); gboolean utils_has_route_file_new_syntax (const char *filename); diff --git a/system-settings/plugins/ifcfg-rh/writer.c b/system-settings/plugins/ifcfg-rh/writer.c index 8a54855cb5..767c352435 100644 --- a/system-settings/plugins/ifcfg-rh/writer.c +++ b/system-settings/plugins/ifcfg-rh/writer.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -855,8 +856,10 @@ write_route_file_legacy (const char *filename, NMSettingIP4Config *s_ip4, GError g_return_val_if_fail (*error == NULL, FALSE); num = nm_setting_ip4_config_get_num_routes (s_ip4); - if (num == 0) + if (num == 0) { + unlink (filename); return TRUE; + } route_items = g_malloc0 (sizeof (char*) * (num + 1)); for (i = 0; i < num; i++) { @@ -1117,6 +1120,213 @@ out: return success; } +static gboolean +write_route6_file (const char *filename, NMSettingIP6Config *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; + guint32 i, num; + gboolean success = FALSE; + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (s_ip6 != NULL, FALSE); + 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); + if (num == 0) { + unlink (filename); + return TRUE; + } + + 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); + + 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); + } + 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_quark (), 0, + "Writing route6 file '%s' failed", filename); + goto error; + } + + success = TRUE; + +error: + g_free (route_contents); + return success; +} + +static gboolean +write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) +{ + NMSettingIP6Config *s_ip6; + NMSettingIP4Config *s_ip4; + const char *value; + char *addr_key, *prefix; + guint32 i, num, num4; + GString *searches; + char buf[INET6_ADDRSTRLEN]; + NMIP6Address *addr; + const struct in6_addr *ip; + GString *ip_str1, *ip_str2, *ip_ptr; + char *route6_path; + + s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG); + if (!s_ip6) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Missing '%s' setting", NM_SETTING_IP6_CONFIG_SETTING_NAME); + return FALSE; + } + + value = nm_setting_ip6_config_get_method (s_ip6); + g_assert (value); + if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + svSetValue (ifcfg, "IPV6INIT", "no", FALSE); + return TRUE; + } + else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { + svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); + svSetValue (ifcfg, "IPV6_AUTOCONF", "yes", FALSE); + } + else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); + svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); + } + else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { + svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); + svSetValue (ifcfg, "IPV6_AUTOCONF", "no", FALSE); + } + else if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_SHARED)) { + svSetValue (ifcfg, "IPV6INIT", "yes", FALSE); + /* TODO */ + } + + if (!strcmp (value, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + /* Write out IP addresses */ + num = nm_setting_ip6_config_get_num_addresses (s_ip6); + + ip_str1 = g_string_new (NULL); + ip_str2 = g_string_new (NULL); + 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)); + 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); + } + + svSetValue (ifcfg, "IPV6ADDR", ip_str1->str, FALSE); + svSetValue (ifcfg, "IPV6ADDR_SECONDARIES", ip_str2->str, 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 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG); + 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); + 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); + } + 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); + if (num > 0) { + char *ip4_domains; + ip4_domains = svGetValue (ifcfg, "DOMAIN", FALSE); + searches = g_string_new (ip4_domains); + 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)); + } + svSetValue (ifcfg, "DOMAIN", searches->str, FALSE); + g_string_free (searches, TRUE); + g_free (ip4_domains); + } + + /* handle IPV6_DEFROUTE */ + /* IPV6_DEFROUTE has the opposite meaning from 'never-default' */ + if (nm_setting_ip6_config_get_never_default(s_ip6)) + svSetValue (ifcfg, "IPV6_DEFROUTE", "no", FALSE); + else + svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE); + + svSetValue (ifcfg, "IPV6_PEERDNS", NULL, FALSE); + 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", + FALSE); + + svSetValue (ifcfg, "IPV6_PEERROUTES", + nm_setting_ip6_config_get_ignore_auto_routes (s_ip6) ? "no" : "yes", + FALSE); + } + + /* Static routes go to route6- file */ + route6_path = utils_get_route6_path (ifcfg->fileName); + if (!route6_path) { + g_set_error (error, ifcfg_plugin_error_quark (), 0, + "Could not get route6 file path for '%s'", ifcfg->fileName); + goto error; + } + write_route6_file (route6_path, s_ip6, error); + g_free (route6_path); + if (error && *error) + goto error; + + return TRUE; + +error: + return FALSE; +} + static char * escape_id (const char *id) { @@ -1142,11 +1352,11 @@ write_connection (NMConnection *connection, const char *ifcfg_dir, const char *filename, const char *keyfile, - const char *routefile, char **out_filename, GError **error) { NMSettingConnection *s_con; + NMSettingIP6Config *s_ip6; gboolean success = FALSE; shvarFile *ifcfg = NULL; char *ifcfg_name = NULL; @@ -1216,6 +1426,12 @@ write_connection (NMConnection *connection, if (!write_ip4_setting (connection, ifcfg, error)) goto out; + s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG); + if (s_ip6) { + if (!write_ip6_setting (connection, ifcfg, error)) + goto out; + } + write_connection_setting (s_con, ifcfg); if (svWriteFile (ifcfg, 0644)) { @@ -1243,7 +1459,7 @@ writer_new_connection (NMConnection *connection, char **out_filename, GError **error) { - return write_connection (connection, ifcfg_dir, NULL, NULL, NULL, out_filename, error); + return write_connection (connection, ifcfg_dir, NULL, NULL, out_filename, error); } gboolean @@ -1251,9 +1467,8 @@ writer_update_connection (NMConnection *connection, const char *ifcfg_dir, const char *filename, const char *keyfile, - const char *routefile, GError **error) { - return write_connection (connection, ifcfg_dir, filename, keyfile, routefile, NULL, error); + return write_connection (connection, ifcfg_dir, filename, keyfile, NULL, error); } diff --git a/system-settings/plugins/ifcfg-rh/writer.h b/system-settings/plugins/ifcfg-rh/writer.h index 2762705312..edeac0cccc 100644 --- a/system-settings/plugins/ifcfg-rh/writer.h +++ b/system-settings/plugins/ifcfg-rh/writer.h @@ -34,7 +34,6 @@ gboolean writer_update_connection (NMConnection *connection, const char *ifcfg_dir, const char *filename, const char *keyfile, - const char *routefile, GError **error); #endif /* _WRITER_H_ */