core: pass NMDedupMultiIndex instance to NMIP4Config and other
NMIP4Config, NMIP6Config, and NMPlatform shall share one NMDedupMultiIndex instance. For that, pass an NMDedupMultiIndex instance to NMPlatform and NMNetns. NMNetns than passes it on to NMDevice, NMDhcpClient, NMIP4Config and NMIP6Config. So currently NMNetns is the access point to the shared NMDedupMultiIndex instance, and it gets it from it's NMPlatform instance. The NMDedupMultiIndex instance is really a singleton, we don't want multiple instances of it. However, for testing, instead of adding a singleton instance, pass the instance explicitly around.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nm-utils/nm-dedup-multi.h"
|
||||
#include "nm-utils.h"
|
||||
|
||||
#include "dhcp/nm-dhcp-utils.h"
|
||||
@@ -30,6 +31,20 @@
|
||||
|
||||
#include "nm-test-utils-core.h"
|
||||
|
||||
static NMIP4Config *
|
||||
_ip4_config_from_options (int ifindex,
|
||||
const char *iface,
|
||||
GHashTable *options,
|
||||
guint32 priority)
|
||||
{
|
||||
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, priority);
|
||||
g_assert (config);
|
||||
return config;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *value;
|
||||
@@ -86,8 +101,7 @@ 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);
|
||||
@@ -157,8 +171,7 @@ 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);
|
||||
@@ -184,16 +197,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);
|
||||
}
|
||||
@@ -246,8 +257,7 @@ 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);
|
||||
@@ -274,8 +284,7 @@ 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);
|
||||
@@ -303,8 +312,7 @@ 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);
|
||||
@@ -335,8 +343,7 @@ 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 */
|
||||
@@ -366,8 +373,7 @@ 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
|
||||
@@ -399,8 +405,7 @@ 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
|
||||
@@ -432,8 +437,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
|
||||
@@ -465,8 +469,7 @@ 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 */
|
||||
@@ -493,8 +496,7 @@ 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 */
|
||||
@@ -519,8 +521,7 @@ 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);
|
||||
@@ -547,8 +548,7 @@ 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);
|
||||
@@ -575,8 +575,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 +601,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,8 +621,7 @@ 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);
|
||||
@@ -668,8 +665,7 @@ 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);
|
||||
|
Reference in New Issue
Block a user