Commit 89385bd9 authored by Thomas Haller's avatar Thomas Haller

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.
parent 6d9c3eab
This diff is collapsed.
......@@ -416,6 +416,7 @@ typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device,
GType nm_device_get_type (void);
struct _NMDedupMultiIndex *nm_device_get_multi_index (NMDevice *self);
NMNetns *nm_device_get_netns (NMDevice *self);
NMPlatform *nm_device_get_platform (NMDevice *self);
......
......@@ -910,7 +910,8 @@ static_stage3_ip4_done (NMModemBroadband *self)
data_port = mm_bearer_get_interface (self->_priv.bearer);
g_assert (data_port);
config = nm_ip4_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port));
config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port));
memset (&address, 0, sizeof (address));
address.address = address_network;
......@@ -1004,7 +1005,8 @@ stage3_ip6_done (NMModemBroadband *self)
data_port = mm_bearer_get_interface (self->_priv.bearer);
g_assert (data_port);
config = nm_ip6_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port));
config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port));
address.plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv6_config);
if (address.plen <= 128)
......
......@@ -908,7 +908,8 @@ context_property_changed (GDBusProxy *proxy,
*
* This needs discussion with upstream.
*/
priv->ip4_config = nm_ip4_config_new (0);
priv->ip4_config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
0);
/* TODO: simply if/else error logic! */
......
......@@ -30,6 +30,8 @@
#include <stdlib.h>
#include <uuid/uuid.h>
#include "nm-utils/nm-dedup-multi.h"
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#include "nm-dhcp-utils.h"
......@@ -48,6 +50,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_MULTI_IDX,
PROP_IFACE,
PROP_IFINDEX,
PROP_HWADDR,
......@@ -58,6 +61,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct _NMDhcpClientPrivate {
NMDedupMultiIndex *multi_idx;
char * iface;
int ifindex;
GByteArray * hwaddr;
......@@ -91,6 +95,14 @@ nm_dhcp_client_get_pid (NMDhcpClient *self)
return NM_DHCP_CLIENT_GET_PRIVATE (self)->pid;
}
NMDedupMultiIndex *
nm_dhcp_client_get_multi_idx (NMDhcpClient *self)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);
return NM_DHCP_CLIENT_GET_PRIVATE (self)->multi_idx;
}
const char *
nm_dhcp_client_get_iface (NMDhcpClient *self)
{
......@@ -765,13 +777,15 @@ nm_dhcp_client_handle_event (gpointer unused,
if (g_hash_table_size (str_options)) {
if (priv->ipv6) {
prefix = nm_dhcp_utils_ip6_prefix_from_options (str_options);
ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (priv->ifindex,
ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self),
priv->ifindex,
priv->iface,
str_options,
priv->priority,
priv->info_only);
} else {
ip_config = (GObject *) nm_dhcp_utils_ip4_config_from_options (priv->ifindex,
ip_config = (GObject *) nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self),
priv->ifindex,
priv->iface,
str_options,
priv->priority);
......@@ -847,6 +861,13 @@ set_property (GObject *object, guint prop_id,
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE ((NMDhcpClient *) object);
switch (prop_id) {
case PROP_MULTI_IDX:
/* construct-only */
priv->multi_idx = g_value_get_pointer (value);
if (!priv->multi_idx)
g_return_if_reached ();
nm_dedup_multi_index_ref (priv->multi_idx);
break;
case PROP_IFACE:
/* construct-only */
priv->iface = g_value_dup_string (value);
......@@ -924,6 +945,8 @@ dispose (GObject *object)
}
G_OBJECT_CLASS (nm_dhcp_client_parent_class)->dispose (object);
priv->multi_idx = nm_dedup_multi_index_unref (priv->multi_idx);
}
static void
......@@ -940,6 +963,12 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
client_class->stop = stop;
client_class->get_duid = get_duid;
obj_properties[PROP_MULTI_IDX] =
g_param_spec_pointer (NM_DHCP_CLIENT_MULTI_IDX, "", "",
G_PARAM_WRITABLE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IFACE] =
g_param_spec_string (NM_DHCP_CLIENT_INTERFACE, "", "",
NULL,
......
......@@ -38,6 +38,7 @@
#define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_PRIORITY "priority"
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
......@@ -101,6 +102,8 @@ typedef struct {
GType nm_dhcp_client_get_type (void);
struct _NMDedupMultiIndex *nm_dhcp_client_get_multi_idx (NMDhcpClient *self);
pid_t nm_dhcp_client_get_pid (NMDhcpClient *self);
const char *nm_dhcp_client_get_iface (NMDhcpClient *self);
......@@ -173,7 +176,8 @@ typedef struct {
GType (*get_type)(void);
const char *name;
const char *(*get_path) (void);
GSList *(*get_lease_ip_configs) (const char *iface,
GSList *(*get_lease_ip_configs) (struct _NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *uuid,
gboolean ipv6,
......
......@@ -25,6 +25,8 @@
#include <ctype.h>
#include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-dhcp-utils.h"
#include "nm-ip4-config.h"
#include "nm-utils.h"
......@@ -659,6 +661,7 @@ lease_validity_span (const char *str_expire, GDateTime *now)
/**
* nm_dhcp_dhclient_read_lease_ip_configs:
* @multi_idx: the multi index instance for the ip config object
* @iface: the interface name to match leases with
* @ifindex: interface index of @iface
* @contents: the contents of a dhclient leasefile
......@@ -673,7 +676,8 @@ lease_validity_span (const char *str_expire, GDateTime *now)
* #NMIP6Config objects (if @ipv6 is %TRUE) containing the lease data.
*/
GSList *
nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
nm_dhcp_dhclient_read_lease_ip_configs (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *contents,
gboolean ipv6,
......@@ -783,7 +787,7 @@ nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
address.lifetime = address.preferred = expiry;
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP;
ip4 = nm_ip4_config_new (ifindex);
ip4 = nm_ip4_config_new (multi_idx, ifindex);
nm_ip4_config_add_address (ip4, &address);
nm_ip4_config_set_gateway (ip4, gw);
......
......@@ -42,7 +42,8 @@ gboolean nm_dhcp_dhclient_save_duid (const char *leasefile,
const char *escaped_duid,
GError **error);
GSList *nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
GSList *nm_dhcp_dhclient_read_lease_ip_configs (struct _NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *contents,
gboolean ipv6,
......
......@@ -38,6 +38,8 @@
#include <arpa/inet.h>
#include <ctype.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h"
#include "nm-dhcp-dhclient-utils.h"
#include "nm-dhcp-manager.h"
......@@ -148,7 +150,8 @@ get_dhclient_leasefile (const char *iface,
}
static GSList *
nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
nm_dhcp_dhclient_get_lease_ip_configs (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *uuid,
gboolean ipv6,
......@@ -166,7 +169,7 @@ nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
&& g_file_get_contents (leasefile, &contents, NULL, NULL)
&& contents
&& contents[0])
leases = nm_dhcp_dhclient_read_lease_ip_configs (iface, ifindex, contents, ipv6, NULL);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, iface, ifindex, contents, ipv6, NULL);
g_free (leasefile);
g_free (contents);
......
......@@ -34,6 +34,8 @@
#include <fcntl.h>
#include <stdio.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-config.h"
#include "NetworkManagerUtils.h"
......@@ -152,6 +154,7 @@ client_state_changed (NMDhcpClient *client,
static NMDhcpClient *
client_start (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const GByteArray *hwaddr,
......@@ -195,6 +198,7 @@ client_start (NMDhcpManager *self,
/* And make a new one */
client = g_object_new (priv->client_factory->get_type (),
NM_DHCP_CLIENT_MULTI_IDX, multi_idx,
NM_DHCP_CLIENT_INTERFACE, iface,
NM_DHCP_CLIENT_IFINDEX, ifindex,
NM_DHCP_CLIENT_HWADDR, hwaddr,
......@@ -222,6 +226,7 @@ client_start (NMDhcpManager *self,
/* Caller owns a reference to the NMDhcpClient on return */
NMDhcpClient *
nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const GByteArray *hwaddr,
......@@ -267,7 +272,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
}
}
return client_start (self, iface, ifindex, hwaddr, uuid, priority, FALSE, NULL,
return client_start (self, multi_idx, iface, ifindex, hwaddr, uuid, priority, FALSE, NULL,
dhcp_client_id, timeout, dhcp_anycast_addr, hostname,
use_fqdn, FALSE, 0, last_ip_address, 0);
}
......@@ -275,6 +280,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
/* Caller owns a reference to the NMDhcpClient on return */
NMDhcpClient *
nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const GByteArray *hwaddr,
......@@ -299,7 +305,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
/* Always prefer the explicit dhcp-hostname if given */
hostname = dhcp_hostname ? dhcp_hostname : priv->default_hostname;
}
return client_start (self, iface, ifindex, hwaddr, uuid, priority, TRUE,
return client_start (self, multi_idx, iface, ifindex, hwaddr, uuid, priority, TRUE,
ll_addr, NULL, timeout, dhcp_anycast_addr, hostname, TRUE, info_only,
privacy, NULL, needed_prefixes);
}
......@@ -320,6 +326,7 @@ nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager, const char *hostna
GSList *
nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *uuid,
......@@ -336,7 +343,7 @@ nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
if ( priv->client_factory
&& priv->client_factory->get_lease_ip_configs)
return priv->client_factory->get_lease_ip_configs (iface, ifindex, uuid, ipv6, default_route_metric);
return priv->client_factory->get_lease_ip_configs (multi_idx, iface, ifindex, uuid, ipv6, default_route_metric);
return NULL;
}
......
......@@ -46,6 +46,7 @@ void nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager,
const char *hostname);
NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
struct _NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const GByteArray *hwaddr,
......@@ -60,6 +61,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
const char *last_ip_address);
NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
struct _NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const GByteArray *hwaddr,
......@@ -75,6 +77,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
guint needed_prefixes);
GSList * nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
struct _NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *uuid,
......
......@@ -28,6 +28,8 @@
#include <ctype.h>
#include <net/if_arp.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h"
#include "nm-dhcp-utils.h"
#include "NetworkManagerUtils.h"
......@@ -216,7 +218,8 @@ G_STMT_START { \
} G_STMT_END
static NMIP4Config *
lease_to_ip4_config (const char *iface,
lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
sd_dhcp_lease *lease,
GHashTable *options,
......@@ -244,7 +247,7 @@ lease_to_ip4_config (const char *iface,
g_return_val_if_fail (lease != NULL, NULL);
ip4_config = nm_ip4_config_new (ifindex);
ip4_config = nm_ip4_config_new (multi_idx, ifindex);
/* Address */
sd_dhcp_lease_get_address (lease, &tmp_addr);
......@@ -433,7 +436,8 @@ get_leasefile_path (const char *iface, const char *uuid, gboolean ipv6)
}
static GSList *
nm_dhcp_systemd_get_lease_ip_configs (const char *iface,
nm_dhcp_systemd_get_lease_ip_configs (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
const char *uuid,
gboolean ipv6,
......@@ -451,7 +455,7 @@ nm_dhcp_systemd_get_lease_ip_configs (const char *iface,
path = get_leasefile_path (iface, uuid, FALSE);
r = dhcp_lease_load (&lease, path);
if (r == 0 && lease) {
ip4_config = lease_to_ip4_config (iface, ifindex, lease, NULL, default_route_metric, FALSE, NULL);
ip4_config = lease_to_ip4_config (multi_idx, iface, ifindex, lease, NULL, default_route_metric, FALSE, NULL);
if (ip4_config)
leases = g_slist_append (leases, ip4_config);
sd_dhcp_lease_unref (lease);
......@@ -505,7 +509,8 @@ bound4_handle (NMDhcpSystemd *self)
_LOGD ("lease available");
options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
ip4_config = lease_to_ip4_config (iface,
ip4_config = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
iface,
nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
lease,
options,
......@@ -725,7 +730,8 @@ error:
}
static NMIP6Config *
lease_to_ip6_config (const char *iface,
lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
sd_dhcp6_lease *lease,
GHashTable *options,
......@@ -743,7 +749,7 @@ lease_to_ip6_config (const char *iface,
gint32 ts;
g_return_val_if_fail (lease, NULL);
ip6_config = nm_ip6_config_new (ifindex);
ip6_config = nm_ip6_config_new (multi_idx, ifindex);
ts = nm_utils_get_monotonic_timestamp_s ();
/* Addresses */
......@@ -830,7 +836,8 @@ bound6_handle (NMDhcpSystemd *self)
_LOGD ("lease available");
options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
ip6_config = lease_to_ip6_config (iface,
ip6_config = lease_to_ip6_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
iface,
nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
lease,
options,
......
......@@ -24,6 +24,8 @@
#include <unistd.h>
#include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-dhcp-utils.h"
#include "nm-utils.h"
#include "NetworkManagerUtils.h"
......@@ -383,7 +385,8 @@ ip4_add_domain_search (gpointer data, gpointer user_data)
}
NMIP4Config *
nm_dhcp_utils_ip4_config_from_options (int ifindex,
nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
int ifindex,
const char *iface,
GHashTable *options,
guint32 priority)
......@@ -398,7 +401,7 @@ nm_dhcp_utils_ip4_config_from_options (int ifindex,
g_return_val_if_fail (options != NULL, NULL);
ip4_config = nm_ip4_config_new (ifindex);
ip4_config = nm_ip4_config_new (multi_idx, ifindex);
memset (&address, 0, sizeof (address));
address.timestamp = nm_utils_get_monotonic_timestamp_s ();
......@@ -616,7 +619,8 @@ nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options)
}
NMIP6Config *
nm_dhcp_utils_ip6_config_from_options (int ifindex,
nm_dhcp_utils_ip6_config_from_options (NMDedupMultiIndex *multi_idx,
int ifindex,
const char *iface,
GHashTable *options,
guint32 priority,
......@@ -633,7 +637,7 @@ nm_dhcp_utils_ip6_config_from_options (int ifindex,
address.plen = 128;
address.timestamp = nm_utils_get_monotonic_timestamp_s ();
ip6_config = nm_ip6_config_new (ifindex);
ip6_config = nm_ip6_config_new (multi_idx, ifindex);
str = g_hash_table_lookup (options, "max_life");
if (str) {
......
......@@ -24,12 +24,14 @@
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
NMIP4Config *nm_dhcp_utils_ip4_config_from_options (int ifindex,
NMIP4Config *nm_dhcp_utils_ip4_config_from_options (struct _NMDedupMultiIndex *multi_idx,
int ifindex,
const char *iface,
GHashTable *options,
guint priority);
NMIP6Config *nm_dhcp_utils_ip6_config_from_options (int ifindex,
NMIP6Config *nm_dhcp_utils_ip6_config_from_options (struct _NMDedupMultiIndex *multi_idx,
int ifindex,
const char *iface,
GHashTable *options,
guint priority,
......
......@@ -24,6 +24,8 @@
#include <unistd.h>
#include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "NetworkManagerUtils.h"
#include "dhcp/nm-dhcp-dhclient-utils.h"
#include "dhcp/nm-dhcp-utils.h"
......@@ -838,6 +840,7 @@ test_interface2 (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;
......@@ -854,7 +857,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, "wlan0", -1, contents, FALSE, now);
g_assert_cmpint (g_slist_length (leases), ==, 2);
/* IP4Config #1 */
......@@ -915,6 +918,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;
......@@ -928,7 +932,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, "wlan0", -1, contents, FALSE, now);
g_assert (leases == NULL);
g_date_time_unref (now);
......@@ -938,6 +942,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;
......@@ -950,7 +955,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, "wlan0", -1, contents, FALSE, now);
g_assert (leases == NULL);
g_date_time_unref (now);
......
......@@ -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");