diff options
Diffstat (limited to 'src/dhcp/tests')
| -rw-r--r-- | src/dhcp/tests/test-dhcp-dhclient.c | 84 | ||||
| -rw-r--r-- | src/dhcp/tests/test-dhcp-utils.c | 140 |
2 files changed, 124 insertions, 100 deletions
diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index 5816932b..f2e1f321 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -23,6 +23,9 @@ #include <string.h> #include <unistd.h> #include <arpa/inet.h> +#include <linux/rtnetlink.h> + +#include "nm-utils/nm-dedup-multi.h" #include "NetworkManagerUtils.h" #include "dhcp/nm-dhcp-dhclient-utils.h" @@ -35,10 +38,14 @@ #define DEBUG 1 +static const int IFINDEX = 5; +static const guint32 ROUTE_TABLE = RT_TABLE_MAIN; +static const guint32 ROUTE_METRIC = 100; + static void test_config (const char *orig, const char *expected, - gboolean ipv6, + int addr_family, const char *hostname, guint32 timeout, gboolean use_fqdn, @@ -57,7 +64,7 @@ test_config (const char *orig, } new = nm_dhcp_dhclient_create_config (iface, - ipv6, + addr_family, client_id, anycast_addr, hostname, @@ -106,7 +113,7 @@ static const char *orig_missing_expected = \ static void test_orig_missing (void) { - test_config (NULL, orig_missing_expected, FALSE, NULL, 0, FALSE, NULL, NULL, "eth0", NULL); + test_config (NULL, orig_missing_expected, AF_INET, NULL, 0, FALSE, NULL, NULL, "eth0", NULL); } /*****************************************************************************/ @@ -135,7 +142,7 @@ static void test_override_client_id (void) { test_config (override_client_id_orig, override_client_id_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, "11:22:33:44:55:66", NULL, "eth0", @@ -164,7 +171,7 @@ static void test_quote_client_id (void) { test_config (NULL, quote_client_id_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, "1234", NULL, "eth0", @@ -193,7 +200,7 @@ static void test_ascii_client_id (void) { test_config (NULL, ascii_client_id_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, "qb:cd:ef:12:34:56", NULL, "eth0", @@ -222,7 +229,7 @@ static void test_hex_single_client_id (void) { test_config (NULL, hex_single_client_id_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, "ab:cd:e:12:34:56", NULL, "eth0", @@ -259,7 +266,7 @@ test_existing_hex_client_id (void) new_client_id = g_bytes_new (bytes, sizeof (bytes)); test_config (existing_hex_client_id_orig, existing_hex_client_id_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, new_client_id, "eth0", @@ -299,7 +306,7 @@ test_existing_ascii_client_id (void) memcpy (buf + 1, EACID, NM_STRLEN (EACID)); new_client_id = g_bytes_new (buf, sizeof (buf)); test_config (existing_ascii_client_id_orig, existing_ascii_client_id_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, new_client_id, "eth0", @@ -328,7 +335,7 @@ static void test_fqdn (void) { test_config (NULL, fqdn_expected, - FALSE, "foo.bar.com", 0, + AF_INET, "foo.bar.com", 0, TRUE, NULL, NULL, "eth0", @@ -368,7 +375,7 @@ test_fqdn_options_override (void) { test_config (fqdn_options_override_orig, fqdn_options_override_expected, - FALSE, "example2.com", 0, + AF_INET, "example2.com", 0, TRUE, NULL, NULL, "eth0", @@ -401,7 +408,7 @@ static void test_override_hostname (void) { test_config (override_hostname_orig, override_hostname_expected, - FALSE, "blahblah", 0, FALSE, + AF_INET, "blahblah", 0, FALSE, NULL, NULL, "eth0", @@ -418,7 +425,6 @@ static const char *override_hostname6_expected = \ "# Merged from /path/to/dhclient.conf\n" "\n" "send fqdn.fqdn \"blahblah.local\"; # added by NetworkManager\n" - "send fqdn.encoded on;\n" "send fqdn.server-update on;\n" "\n" "also request dhcp6.name-servers;\n" @@ -430,7 +436,7 @@ static void test_override_hostname6 (void) { test_config (override_hostname6_orig, override_hostname6_expected, - TRUE, "blahblah.local", 0, TRUE, + AF_INET6, "blahblah.local", 0, TRUE, NULL, NULL, "eth0", @@ -442,6 +448,9 @@ test_override_hostname6 (void) static const char *nonfqdn_hostname6_expected = \ "# Created by NetworkManager\n" "\n" + "send fqdn.fqdn \"blahblah\"; # added by NetworkManager\n" + "send fqdn.server-update on;\n" + "\n" "also request dhcp6.name-servers;\n" "also request dhcp6.domain-search;\n" "also request dhcp6.client-id;\n" @@ -450,9 +459,9 @@ static const char *nonfqdn_hostname6_expected = \ static void test_nonfqdn_hostname6 (void) { - /* Non-FQDN hostname can't be used with dhclient */ + /* Non-FQDN hostname can now be used with dhclient */ test_config (NULL, nonfqdn_hostname6_expected, - TRUE, "blahblah", 0, TRUE, + AF_INET6, "blahblah", 0, TRUE, NULL, NULL, "eth0", @@ -487,7 +496,7 @@ static void test_existing_alsoreq (void) { test_config (existing_alsoreq_orig, existing_alsoreq_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, NULL, "eth0", @@ -525,7 +534,7 @@ static void test_existing_req (void) { test_config (existing_req_orig, existing_req_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, NULL, "eth0", @@ -564,7 +573,7 @@ static void test_existing_multiline_alsoreq (void) { test_config (existing_multiline_alsoreq_orig, existing_multiline_alsoreq_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, NULL, "eth0", @@ -778,7 +787,7 @@ static void test_interface1 (void) { test_config (interface1_orig, interface1_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, NULL, "eth0", @@ -823,7 +832,7 @@ static void test_interface2 (void) { test_config (interface2_orig, interface2_expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, NULL, "eth1", @@ -877,7 +886,7 @@ test_config_req_intf (void) "\n"; test_config (orig, expected, - FALSE, NULL, 0, FALSE, + AF_INET, NULL, 0, FALSE, NULL, NULL, "eth0", @@ -889,6 +898,7 @@ test_config_req_intf (void) static void test_read_lease_ip4_config_basic (void) { + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); GError *error = NULL; char *contents = NULL; gboolean success; @@ -905,7 +915,7 @@ test_read_lease_ip4_config_basic (void) /* Date from before the least expiration */ now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32); - leases = nm_dhcp_dhclient_read_lease_ip_configs ("wlan0", -1, contents, FALSE, now); + leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now); g_assert_cmpint (g_slist_length (leases), ==, 2); /* IP4Config #1 */ @@ -914,19 +924,19 @@ test_read_lease_ip4_config_basic (void) /* Address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1); - g_assert (inet_aton ("192.168.1.180", (struct in_addr *) &expected_addr)); - addr = nm_ip4_config_get_address (config, 0); + expected_addr = nmtst_inet4_from_string ("192.168.1.180"); + addr = _nmtst_ip4_config_get_address (config, 0); g_assert_cmpint (addr->address, ==, expected_addr); g_assert_cmpint (addr->peer_address, ==, expected_addr); g_assert_cmpint (addr->plen, ==, 24); /* Gateway */ - g_assert (inet_aton ("192.168.1.1", (struct in_addr *) &expected_addr)); - g_assert_cmpint (nm_ip4_config_get_gateway (config), ==, expected_addr); + expected_addr = nmtst_inet4_from_string ("192.168.1.1"); + g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr); /* DNS */ g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 1); - g_assert (inet_aton ("192.168.1.1", (struct in_addr *) &expected_addr)); + expected_addr = nmtst_inet4_from_string ("192.168.1.1"); g_assert_cmpint (nm_ip4_config_get_nameserver (config, 0), ==, expected_addr); g_assert_cmpint (nm_ip4_config_get_num_domains (config), ==, 0); @@ -937,21 +947,21 @@ test_read_lease_ip4_config_basic (void) /* Address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1); - g_assert (inet_aton ("10.77.52.141", (struct in_addr *) &expected_addr)); - addr = nm_ip4_config_get_address (config, 0); + expected_addr = nmtst_inet4_from_string ("10.77.52.141"); + addr = _nmtst_ip4_config_get_address (config, 0); g_assert_cmpint (addr->address, ==, expected_addr); g_assert_cmpint (addr->peer_address, ==, expected_addr); g_assert_cmpint (addr->plen, ==, 8); /* Gateway */ - g_assert (inet_aton ("10.77.52.254", (struct in_addr *) &expected_addr)); - g_assert_cmpint (nm_ip4_config_get_gateway (config), ==, expected_addr); + expected_addr = nmtst_inet4_from_string ("10.77.52.254"); + g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr); /* DNS */ g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 2); - g_assert (inet_aton ("8.8.8.8", (struct in_addr *) &expected_addr)); + expected_addr = nmtst_inet4_from_string ("8.8.8.8"); g_assert_cmpint (nm_ip4_config_get_nameserver (config, 0), ==, expected_addr); - g_assert (inet_aton ("8.8.4.4", (struct in_addr *) &expected_addr)); + expected_addr = nmtst_inet4_from_string ("8.8.4.4"); g_assert_cmpint (nm_ip4_config_get_nameserver (config, 1), ==, expected_addr); /* Domains */ @@ -966,6 +976,7 @@ test_read_lease_ip4_config_basic (void) static void test_read_lease_ip4_config_expired (void) { + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); GError *error = NULL; char *contents = NULL; gboolean success; @@ -979,7 +990,7 @@ test_read_lease_ip4_config_expired (void) /* Date from *after* the lease expiration */ now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32); - leases = nm_dhcp_dhclient_read_lease_ip_configs ("wlan0", -1, contents, FALSE, now); + leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now); g_assert (leases == NULL); g_date_time_unref (now); @@ -989,6 +1000,7 @@ test_read_lease_ip4_config_expired (void) static void test_read_lease_ip4_config_expect_failure (gconstpointer user_data) { + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); GError *error = NULL; char *contents = NULL; gboolean success; @@ -1001,7 +1013,7 @@ test_read_lease_ip4_config_expect_failure (gconstpointer user_data) /* Date from before the least expiration */ now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1); - leases = nm_dhcp_dhclient_read_lease_ip_configs ("wlan0", -1, contents, FALSE, now); + leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now); g_assert (leases == NULL); g_date_time_unref (now); diff --git a/src/dhcp/tests/test-dhcp-utils.c b/src/dhcp/tests/test-dhcp-utils.c index ffd63493..72f31191 100644 --- a/src/dhcp/tests/test-dhcp-utils.c +++ b/src/dhcp/tests/test-dhcp-utils.c @@ -22,7 +22,9 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> +#include <linux/rtnetlink.h> +#include "nm-utils/nm-dedup-multi.h" #include "nm-utils.h" #include "dhcp/nm-dhcp-utils.h" @@ -30,6 +32,20 @@ #include "nm-test-utils-core.h" +static NMIP4Config * +_ip4_config_from_options (int ifindex, + const char *iface, + GHashTable *options, + guint32 route_metric) +{ + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); + NMIP4Config *config; + + config = nm_dhcp_utils_ip4_config_from_options (multi_idx, ifindex, iface, options, RT_TABLE_MAIN, route_metric); + g_assert (config); + return config; +} + typedef struct { const char *name; const char *value; @@ -41,7 +57,7 @@ fill_table (const Option *test_options, GHashTable *table) const Option *opt; if (!table) - table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); + table = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, NULL); for (opt = test_options; opt->name; opt++) g_hash_table_insert (table, (gpointer) opt->name, (gpointer) opt->value); return table; @@ -86,12 +102,11 @@ test_generic_options (void) const char *expected_route2_gw = "10.1.1.1"; options = fill_table (generic_options, NULL); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); - address = nm_ip4_config_get_address (ip4_config, 0); + address = _nmtst_ip4_config_get_address (ip4_config, 0); g_assert (inet_pton (AF_INET, expected_addr, &tmp) > 0); g_assert (address->address == tmp); g_assert (address->peer_address == tmp); @@ -99,7 +114,7 @@ test_generic_options (void) /* Gateway */ g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0); - g_assert (nm_ip4_config_get_gateway (ip4_config) == tmp); + g_assert (nmtst_ip4_config_get_gateway (ip4_config) == tmp); g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 0); @@ -118,10 +133,10 @@ test_generic_options (void) g_assert (nm_ip4_config_get_nameserver (ip4_config, 1) == tmp); /* Routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); /* Route #1 */ - route = nm_ip4_config_get_route (ip4_config, 0); + route = _nmtst_ip4_config_get_route (ip4_config, 0); g_assert (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0); g_assert (route->network == tmp); g_assert (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0); @@ -130,14 +145,18 @@ test_generic_options (void) g_assert_cmpint (route->metric, ==, 0); /* Route #2 */ - route = nm_ip4_config_get_route (ip4_config, 1); - g_assert (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0); - g_assert (route->network == tmp); - g_assert (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0); - g_assert (route->gateway == tmp); + route = _nmtst_ip4_config_get_route (ip4_config, 1); + g_assert (route->network == nmtst_inet4_from_string (expected_route2_dest)); + g_assert (route->gateway == nmtst_inet4_from_string (expected_route2_gw)); g_assert_cmpint (route->plen, ==, 32); g_assert_cmpint (route->metric, ==, 0); + route = _nmtst_ip4_config_get_route (ip4_config, 2); + g_assert (route->network == nmtst_inet4_from_string ("0.0.0.0")); + g_assert (route->gateway == nmtst_inet4_from_string ("192.168.1.1")); + g_assert_cmpint (route->plen, ==, 0); + g_assert_cmpint (route->metric, ==, 0); + g_hash_table_destroy (options); } @@ -157,12 +176,11 @@ test_wins_options (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); - address = nm_ip4_config_get_address (ip4_config, 0); + address = _nmtst_ip4_config_get_address (ip4_config, 0); g_assert (address); g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 2); g_assert (inet_pton (AF_INET, expected_wins1, &tmp) > 0); @@ -184,16 +202,14 @@ test_vendor_option_metered (void) }; options = fill_table (generic_options, NULL); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert (nm_ip4_config_get_metered (ip4_config) == FALSE); g_hash_table_destroy (options); g_clear_object (&ip4_config); options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert (nm_ip4_config_get_metered (ip4_config) == TRUE); g_hash_table_destroy (options); } @@ -210,7 +226,7 @@ ip4_test_route (NMIP4Config *ip4_config, g_assert (expected_prefix <= 32); - route = nm_ip4_config_get_route (ip4_config, route_num); + route = _nmtst_ip4_config_get_route (ip4_config, route_num); g_assert (inet_pton (AF_INET, expected_dest, &tmp) > 0); g_assert (route->network == tmp); g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0); @@ -226,7 +242,7 @@ ip4_test_gateway (NMIP4Config *ip4_config, const char *expected_gw) g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0); - g_assert (nm_ip4_config_get_gateway (ip4_config) == tmp); + g_assert (nmtst_ip4_config_get_gateway (ip4_config) == tmp); } static void @@ -246,13 +262,13 @@ test_classless_static_routes_1 (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 8); + ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); g_hash_table_destroy (options); } @@ -274,13 +290,13 @@ test_classless_static_routes_2 (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 8); + ip4_test_route (ip4_config, 2, "0.0.0.0", expected_route1_gw, 0); g_hash_table_destroy (options); } @@ -303,13 +319,13 @@ test_fedora_dhclient_classless_static_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 25); ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 7); + ip4_test_route (ip4_config, 2, "0.0.0.0", expected_route1_gw, 0); /* Gateway */ ip4_test_gateway (ip4_config, expected_gateway); @@ -335,13 +351,13 @@ test_dhclient_invalid_classless_routes_1 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, "0.0.0.0", expected_route1_gw, 0); g_hash_table_destroy (options); } @@ -366,16 +382,16 @@ test_dhcpcd_invalid_classless_routes_1 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static * routes are invalid. */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); + ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); g_hash_table_destroy (options); } @@ -399,16 +415,16 @@ test_dhclient_invalid_classless_routes_2 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static * routes are invalid. */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); + ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); g_hash_table_destroy (options); } @@ -432,8 +448,7 @@ test_dhcpcd_invalid_classless_routes_2 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static @@ -441,9 +456,10 @@ test_dhcpcd_invalid_classless_routes_2 (void) */ /* Routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); + ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0); g_hash_table_destroy (options); } @@ -465,13 +481,13 @@ test_dhclient_invalid_classless_routes_3 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, "0.0.0.0", expected_route1_gw, 0); g_hash_table_destroy (options); } @@ -493,13 +509,13 @@ test_dhcpcd_invalid_classless_routes_3 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*DHCP provided invalid classless static route*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, "0.0.0.0", expected_route1_gw, 0); g_hash_table_destroy (options); } @@ -519,12 +535,12 @@ test_dhclient_gw_in_classless_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, "0.0.0.0", "192.2.3.4", 0); /* Gateway */ ip4_test_gateway (ip4_config, expected_gateway); @@ -547,12 +563,12 @@ test_dhcpcd_gw_in_classless_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ - g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, "0.0.0.0", "192.2.3.4", 0); /* Gateway */ ip4_test_gateway (ip4_config, expected_gateway); @@ -575,8 +591,7 @@ test_escaped_domain_searches (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* domain searches */ g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 3); @@ -602,8 +617,7 @@ test_invalid_escaped_domain_searches (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*invalid domain search*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* domain searches */ @@ -623,11 +637,10 @@ test_ip4_missing_prefix (const char *ip, guint32 expected_prefix) g_hash_table_insert (options, "ip_address", (gpointer) ip); g_hash_table_remove (options, "subnet_mask"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); - address = nm_ip4_config_get_address (ip4_config, 0); + address = _nmtst_ip4_config_get_address (ip4_config, 0); g_assert (address); g_assert_cmpint (address->plen, ==, expected_prefix); @@ -668,11 +681,10 @@ test_ip4_prefix_classless (void) g_hash_table_insert (options, "ip_address", "172.16.54.22"); g_hash_table_insert (options, "subnet_mask", "255.255.252.0"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); - address = nm_ip4_config_get_address (ip4_config, 0); + address = _nmtst_ip4_config_get_address (ip4_config, 0); g_assert (address); g_assert_cmpint (address->plen, ==, 22); |