diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2014-06-09 18:46:34 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2014-06-10 09:19:57 +0200 |
commit | 6f585ba9be1ed6004f5e025f04d6614bf1152856 (patch) | |
tree | 0f59f1878c1c39adce46bbcddec3e90beb66116c | |
parent | 3dccef663135acd6a2922678483ac99c32409d6c (diff) | |
download | NetworkManager-jk/ifcfg-rh-route6-bgo697525.tar.gz |
ifcfg-rh: accept IPv6 routes without "via" in route6 file (bgo #697525)jk/ifcfg-rh-route6-bgo697525
Routes without nexthop are legal and should be treated as a device route
(direct route).
https://bugzilla.gnome.org/show_bug.cgi?id=697525
3 files changed, 35 insertions, 49 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 540a30c774..305760188e 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -1097,7 +1097,7 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro GMatchInfo *match_info; NMIP6Route *route; struct in6_addr ip6_addr; - char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; + char *dest = NULL, *prefix = NULL, *metric = NULL; long int prefix_int, metric_int; gboolean success = FALSE; @@ -1185,22 +1185,23 @@ read_route6_file (const char *filename, NMSettingIP6Config *s_ip6, GError **erro /* 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, 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, 0, - "Invalid IP6 route gateway address '%s'", next_hop); + if (g_match_info_matches (match_info)) { + char *next_hop = g_match_info_fetch (match_info, 1); + if (inet_pton (AF_INET6, next_hop, &ip6_addr) != 1) { + g_set_error (error, IFCFG_PLUGIN_ERROR, 0, + "Invalid IPv6 route nexthop address '%s'", + next_hop); + g_match_info_free (match_info); + g_free (next_hop); + goto error; + } g_free (next_hop); - goto error; + } else { + /* Missing "via" is taken as :: */ + ip6_addr = in6addr_any; } nm_ip6_route_set_next_hop (route, &ip6_addr); - g_free (next_hop); + g_match_info_free (match_info); /* Metric */ g_regex_match (regex_metric, *iter, 0, &match_info); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual b/src/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual index 2a994c502e..b3259ab7ff 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual @@ -2,3 +2,6 @@ # default route is ignored by ifcfg-rh reader, because NM handles it internally default via dead::beaf + +# routes without "via" are valid +abbe::cafe/64 metric 777 diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 9e0706def6..0e5be5d6b2 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -1852,10 +1852,6 @@ test_read_wired_ipv6_manual (void) 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; @@ -2059,39 +2055,25 @@ test_read_wired_ipv6_manual (void) 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); - + g_assert_cmpint (nm_setting_ip6_config_get_num_routes (s_ip6), ==, 2); /* 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); + g_assert (ip6_route); + g_assert_cmpint (inet_pton (AF_INET6, "9876::1234", &addr), >, 0); + g_assert_cmpint (memcmp (nm_ip6_route_get_dest (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); + g_assert_cmpint (nm_ip6_route_get_prefix (ip6_route), ==, 96); + g_assert_cmpint (inet_pton (AF_INET6, "9876::7777", &addr), >, 0); + g_assert_cmpint (memcmp (nm_ip6_route_get_next_hop (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); + g_assert_cmpint (nm_ip6_route_get_metric (ip6_route), ==, 2); + /* Route #2 */ + ip6_route = nm_setting_ip6_config_get_route (s_ip6, 1); + g_assert (ip6_route); + g_assert_cmpint (inet_pton (AF_INET6, "abbe::cafe", &addr), >, 0); + g_assert_cmpint (memcmp (nm_ip6_route_get_dest (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); + g_assert_cmpint (nm_ip6_route_get_prefix (ip6_route), ==, 64); + g_assert_cmpint (inet_pton (AF_INET6, "::", &addr), >, 0); + g_assert_cmpint (memcmp (nm_ip6_route_get_next_hop (ip6_route), &addr, sizeof (struct in6_addr)), ==, 0); + g_assert_cmpint (nm_ip6_route_get_metric (ip6_route), ==, 777); /* DNS Addresses */ ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2, |