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:
Thomas Haller
2017-06-12 08:16:47 +02:00
parent 6d9c3eab38
commit 89385bd968
31 changed files with 366 additions and 135 deletions

View File

@@ -35,6 +35,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <linux/if_addr.h> #include <linux/if_addr.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-common-macros.h" #include "nm-common-macros.h"
#include "nm-device-private.h" #include "nm-device-private.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@@ -647,12 +649,32 @@ nm_device_get_netns (NMDevice *self)
return NM_DEVICE_GET_PRIVATE (self)->netns; return NM_DEVICE_GET_PRIVATE (self)->netns;
} }
NMDedupMultiIndex *
nm_device_get_multi_index (NMDevice *self)
{
return nm_netns_get_multi_idx (nm_device_get_netns (self));
}
NMPlatform * NMPlatform *
nm_device_get_platform (NMDevice *self) nm_device_get_platform (NMDevice *self)
{ {
return nm_netns_get_platform (nm_device_get_netns (self)); return nm_netns_get_platform (nm_device_get_netns (self));
} }
static NMIP4Config *
_ip4_config_new (NMDevice *self)
{
return nm_ip4_config_new (nm_device_get_multi_index (self),
nm_device_get_ip_ifindex (self));
}
static NMIP6Config *
_ip6_config_new (NMDevice *self)
{
return nm_ip6_config_new (nm_device_get_multi_index (self),
nm_device_get_ip_ifindex (self));
}
/*****************************************************************************/ /*****************************************************************************/
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_sys_iface_state_to_str, NMDeviceSysIfaceState, NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_sys_iface_state_to_str, NMDeviceSysIfaceState,
@@ -5058,7 +5080,7 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes
NMIP4Config *empty; NMIP4Config *empty;
if (success) { if (success) {
empty = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); empty = _ip4_config_new (self);
nm_device_activate_schedule_ip4_config_result (self, empty); nm_device_activate_schedule_ip4_config_result (self, empty);
g_object_unref (empty); g_object_unref (empty);
} else { } else {
@@ -5215,7 +5237,7 @@ ipv4ll_get_ip4_config (NMDevice *self, guint32 lla)
NMPlatformIP4Address address; NMPlatformIP4Address address;
NMPlatformIP4Route route; NMPlatformIP4Route route;
config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); config = _ip4_config_new (self);
g_assert (config); g_assert (config);
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof (address));
@@ -5430,7 +5452,6 @@ static void
ensure_con_ip4_config (NMDevice *self) ensure_con_ip4_config (NMDevice *self)
{ {
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
int ip_ifindex = nm_device_get_ip_ifindex (self);
NMConnection *connection; NMConnection *connection;
if (priv->con_ip4_config) if (priv->con_ip4_config)
@@ -5440,7 +5461,7 @@ ensure_con_ip4_config (NMDevice *self)
if (!connection) if (!connection)
return; return;
priv->con_ip4_config = nm_ip4_config_new (ip_ifindex); priv->con_ip4_config = _ip4_config_new (self);
nm_ip4_config_merge_setting (priv->con_ip4_config, nm_ip4_config_merge_setting (priv->con_ip4_config,
nm_connection_get_setting_ip4_config (connection), nm_connection_get_setting_ip4_config (connection),
nm_device_get_ip4_route_metric (self)); nm_device_get_ip4_route_metric (self));
@@ -5456,7 +5477,6 @@ static void
ensure_con_ip6_config (NMDevice *self) ensure_con_ip6_config (NMDevice *self)
{ {
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
int ip_ifindex = nm_device_get_ip_ifindex (self);
NMConnection *connection; NMConnection *connection;
if (priv->con_ip6_config) if (priv->con_ip6_config)
@@ -5466,7 +5486,7 @@ ensure_con_ip6_config (NMDevice *self)
if (!connection) if (!connection)
return; return;
priv->con_ip6_config = nm_ip6_config_new (ip_ifindex); priv->con_ip6_config = _ip6_config_new (self);
nm_ip6_config_merge_setting (priv->con_ip6_config, nm_ip6_config_merge_setting (priv->con_ip6_config,
nm_connection_get_setting_ip6_config (connection), nm_connection_get_setting_ip6_config (connection),
nm_device_get_ip6_route_metric (self)); nm_device_get_ip6_route_metric (self));
@@ -5548,14 +5568,15 @@ ip4_config_merge_and_apply (NMDevice *self,
} }
} }
composite = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); composite = _ip4_config_new (self);
init_ip4_config_dns_priority (self, composite); init_ip4_config_dns_priority (self, composite);
if (commit) { if (commit) {
ensure_con_ip4_config (self); ensure_con_ip4_config (self);
if (priv->queued_ip4_config_id) { if (priv->queued_ip4_config_id) {
g_clear_object (&priv->ext_ip4_config); g_clear_object (&priv->ext_ip4_config);
priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_platform (self), priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_multi_index (self),
nm_device_get_platform (self),
nm_device_get_ip_ifindex (self), nm_device_get_ip_ifindex (self),
FALSE); FALSE);
} }
@@ -5824,7 +5845,7 @@ dhcp4_state_changed (NMDhcpClient *client,
connection = nm_device_get_applied_connection (self); connection = nm_device_get_applied_connection (self);
g_assert (connection); g_assert (connection);
manual = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); manual = _ip4_config_new (self);
nm_ip4_config_merge_setting (manual, nm_ip4_config_merge_setting (manual,
nm_connection_get_setting_ip4_config (connection), nm_connection_get_setting_ip4_config (connection),
nm_device_get_ip4_route_metric (self)); nm_device_get_ip4_route_metric (self));
@@ -5905,6 +5926,7 @@ dhcp4_start (NMDevice *self,
/* Begin DHCP on the interface */ /* Begin DHCP on the interface */
g_warn_if_fail (priv->dhcp4.client == NULL); g_warn_if_fail (priv->dhcp4.client == NULL);
priv->dhcp4.client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (), priv->dhcp4.client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (),
nm_netns_get_multi_idx (nm_device_get_netns (self)),
nm_device_get_ip_iface (self), nm_device_get_ip_iface (self),
nm_device_get_ip_ifindex (self), nm_device_get_ip_ifindex (self),
tmp, tmp,
@@ -6012,7 +6034,7 @@ shared4_new_config (NMDevice *self, NMConnection *connection)
is_generated = TRUE; is_generated = TRUE;
} }
config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); config = _ip4_config_new (self);
nm_ip4_config_add_address (config, &address); nm_ip4_config_add_address (config, &address);
if (is_generated) { if (is_generated) {
/* Remove the address lock when the object gets disposed */ /* Remove the address lock when the object gets disposed */
@@ -6173,7 +6195,7 @@ act_stage3_ip4_config_start (NMDevice *self,
} else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) { } else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) {
NMIP4Config **configs, *config; NMIP4Config **configs, *config;
config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); config = _ip4_config_new (self);
nm_ip4_config_merge_setting (config, nm_ip4_config_merge_setting (config,
nm_connection_get_setting_ip4_config (connection), nm_connection_get_setting_ip4_config (connection),
nm_device_get_ip4_route_metric (self)); nm_device_get_ip4_route_metric (self));
@@ -6273,7 +6295,7 @@ ip6_config_merge_and_apply (NMDevice *self,
} }
} }
composite = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); composite = _ip6_config_new (self);
nm_ip6_config_set_privacy (composite, nm_ip6_config_set_privacy (composite,
priv->ndisc ? priv->ndisc ?
priv->ndisc_use_tempaddr : priv->ndisc_use_tempaddr :
@@ -6285,7 +6307,8 @@ ip6_config_merge_and_apply (NMDevice *self,
if (priv->queued_ip6_config_id) { if (priv->queued_ip6_config_id) {
g_clear_object (&priv->ext_ip6_config); g_clear_object (&priv->ext_ip6_config);
g_clear_object (&priv->ext_ip6_config_captured); g_clear_object (&priv->ext_ip6_config_captured);
priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_platform (self), priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_multi_index (self),
nm_device_get_platform (self),
nm_device_get_ip_ifindex (self), nm_device_get_ip_ifindex (self),
FALSE, FALSE,
NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
@@ -6702,6 +6725,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
} }
priv->dhcp6.client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (), priv->dhcp6.client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (),
nm_device_get_multi_index (self),
nm_device_get_ip_iface (self), nm_device_get_ip_iface (self),
nm_device_get_ip_ifindex (self), nm_device_get_ip_ifindex (self),
tmp, tmp,
@@ -6830,7 +6854,7 @@ nm_device_use_ip6_subnet (NMDevice *self, const NMPlatformIP6Address *subnet)
NMPlatformIP6Address address = *subnet; NMPlatformIP6Address address = *subnet;
if (!priv->ac_ip6_config) if (!priv->ac_ip6_config)
priv->ac_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); priv->ac_ip6_config = _ip6_config_new (self);
/* Assign a ::1 address in the subnet for us. */ /* Assign a ::1 address in the subnet for us. */
address.address.s6_addr32[3] |= htonl (1); address.address.s6_addr32[3] |= htonl (1);
@@ -6860,7 +6884,7 @@ nm_device_copy_ip6_dns_config (NMDevice *self, NMDevice *from_device)
nm_ip6_config_reset_nameservers (priv->ac_ip6_config); nm_ip6_config_reset_nameservers (priv->ac_ip6_config);
nm_ip6_config_reset_searches (priv->ac_ip6_config); nm_ip6_config_reset_searches (priv->ac_ip6_config);
} else } else
priv->ac_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); priv->ac_ip6_config = _ip6_config_new (self);
if (from_device) if (from_device)
from_config = nm_device_get_ip6_config (from_device); from_config = nm_device_get_ip6_config (from_device);
@@ -7280,7 +7304,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in
g_return_if_fail (priv->act_request); g_return_if_fail (priv->act_request);
if (!priv->ac_ip6_config) if (!priv->ac_ip6_config)
priv->ac_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); priv->ac_ip6_config = _ip6_config_new (self);
if (changed & NM_NDISC_CONFIG_GATEWAYS) { if (changed & NM_NDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in neighbor discovery cache. */ /* Use the first gateway as ordered in neighbor discovery cache. */
@@ -7802,7 +7826,8 @@ act_stage3_ip6_config_start (NMDevice *self,
*/ */
nm_platform_process_events (nm_device_get_platform (self)); nm_platform_process_events (nm_device_get_platform (self));
g_clear_object (&priv->ext_ip6_config_captured); g_clear_object (&priv->ext_ip6_config_captured);
priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_platform (self), priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_multi_index (self),
nm_device_get_platform (self),
nm_device_get_ip_ifindex (self), nm_device_get_ip_ifindex (self),
FALSE, FALSE,
NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
@@ -7876,7 +7901,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self)
ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &failure_reason); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &failure_reason);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
if (!ip4_config) if (!ip4_config)
ip4_config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); ip4_config = _ip4_config_new (self);
nm_device_activate_schedule_ip4_config_result (self, ip4_config); nm_device_activate_schedule_ip4_config_result (self, ip4_config);
g_object_unref (ip4_config); g_object_unref (ip4_config);
} else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) {
@@ -7923,7 +7948,7 @@ nm_device_activate_stage3_ip6_start (NMDevice *self)
ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip6_config_start (self, &ip6_config, &failure_reason); ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip6_config_start (self, &ip6_config, &failure_reason);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
if (!ip6_config) if (!ip6_config)
ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); ip6_config = _ip6_config_new (self);
/* Here we get a static IPv6 config, like for Shared where it's /* Here we get a static IPv6 config, like for Shared where it's
* autogenerated or from modems where it comes from ModemManager. * autogenerated or from modems where it comes from ModemManager.
*/ */
@@ -8510,7 +8535,7 @@ dad6_get_pending_addresses (NMDevice *self)
nm_platform_ip6_address_to_string (pl_addr, NULL, 0)); nm_platform_ip6_address_to_string (pl_addr, NULL, 0));
if (!dad6_config) if (!dad6_config)
dad6_config = nm_ip6_config_new (ifindex); dad6_config = _ip6_config_new (self);
nm_ip6_config_add_address (dad6_config, pl_addr); nm_ip6_config_add_address (dad6_config, pl_addr);
} }
@@ -8925,7 +8950,7 @@ nm_device_reactivate_ip4_config (NMDevice *self,
if (priv->ip4_state != IP_NONE) { if (priv->ip4_state != IP_NONE) {
g_clear_object (&priv->con_ip4_config); g_clear_object (&priv->con_ip4_config);
g_clear_object (&priv->ext_ip4_config); g_clear_object (&priv->ext_ip4_config);
priv->con_ip4_config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); priv->con_ip4_config = _ip4_config_new (self);
nm_ip4_config_merge_setting (priv->con_ip4_config, nm_ip4_config_merge_setting (priv->con_ip4_config,
s_ip4_new, s_ip4_new,
nm_device_get_ip4_route_metric (self)); nm_device_get_ip4_route_metric (self));
@@ -8967,7 +8992,7 @@ nm_device_reactivate_ip6_config (NMDevice *self,
if (priv->ip6_state != IP_NONE) { if (priv->ip6_state != IP_NONE) {
g_clear_object (&priv->con_ip6_config); g_clear_object (&priv->con_ip6_config);
g_clear_object (&priv->ext_ip6_config); g_clear_object (&priv->ext_ip6_config);
priv->con_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self)); priv->con_ip6_config = _ip6_config_new (self);
nm_ip6_config_merge_setting (priv->con_ip6_config, nm_ip6_config_merge_setting (priv->con_ip6_config,
s_ip6_new, s_ip6_new,
nm_device_get_ip6_route_metric (self)); nm_device_get_ip6_route_metric (self));
@@ -10562,6 +10587,7 @@ find_ip4_lease_config (NMDevice *self,
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
leases = nm_dhcp_manager_get_lease_ip_configs (nm_dhcp_manager_get (), leases = nm_dhcp_manager_get_lease_ip_configs (nm_dhcp_manager_get (),
nm_device_get_multi_index (self),
ip_iface, ip_iface,
ip_ifindex, ip_ifindex,
nm_connection_get_uuid (connection), nm_connection_get_uuid (connection),
@@ -10680,7 +10706,8 @@ update_ip4_config (NMDevice *self, gboolean initial)
/* IPv4 */ /* IPv4 */
g_clear_object (&priv->ext_ip4_config); g_clear_object (&priv->ext_ip4_config);
priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_platform (self), priv->ext_ip4_config = nm_ip4_config_capture (nm_device_get_multi_index (self),
nm_device_get_platform (self),
ifindex, ifindex,
capture_resolv_conf); capture_resolv_conf);
if (priv->ext_ip4_config) { if (priv->ext_ip4_config) {
@@ -10755,7 +10782,11 @@ update_ip6_config (NMDevice *self, gboolean initial)
/* IPv6 */ /* IPv6 */
g_clear_object (&priv->ext_ip6_config); g_clear_object (&priv->ext_ip6_config);
g_clear_object (&priv->ext_ip6_config_captured); g_clear_object (&priv->ext_ip6_config_captured);
priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_platform (self), ifindex, capture_resolv_conf, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN); priv->ext_ip6_config_captured = nm_ip6_config_capture (nm_device_get_multi_index (self),
nm_device_get_platform (self),
ifindex,
capture_resolv_conf,
NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
if (priv->ext_ip6_config_captured) { if (priv->ext_ip6_config_captured) {
priv->ext_ip6_config = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured); priv->ext_ip6_config = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured);

View File

@@ -416,6 +416,7 @@ typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device,
GType nm_device_get_type (void); GType nm_device_get_type (void);
struct _NMDedupMultiIndex *nm_device_get_multi_index (NMDevice *self);
NMNetns *nm_device_get_netns (NMDevice *self); NMNetns *nm_device_get_netns (NMDevice *self);
NMPlatform *nm_device_get_platform (NMDevice *self); NMPlatform *nm_device_get_platform (NMDevice *self);

View File

@@ -910,7 +910,8 @@ static_stage3_ip4_done (NMModemBroadband *self)
data_port = mm_bearer_get_interface (self->_priv.bearer); data_port = mm_bearer_get_interface (self->_priv.bearer);
g_assert (data_port); 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)); memset (&address, 0, sizeof (address));
address.address = address_network; address.address = address_network;
@@ -1004,7 +1005,8 @@ stage3_ip6_done (NMModemBroadband *self)
data_port = mm_bearer_get_interface (self->_priv.bearer); data_port = mm_bearer_get_interface (self->_priv.bearer);
g_assert (data_port); 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); address.plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv6_config);
if (address.plen <= 128) if (address.plen <= 128)

View File

@@ -908,7 +908,8 @@ context_property_changed (GDBusProxy *proxy,
* *
* This needs discussion with upstream. * 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! */ /* TODO: simply if/else error logic! */

View File

@@ -30,6 +30,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include "nm-utils/nm-dedup-multi.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dhcp-utils.h" #include "nm-dhcp-utils.h"
@@ -48,6 +50,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 }; static guint signals[LAST_SIGNAL] = { 0 };
NM_GOBJECT_PROPERTIES_DEFINE_BASE ( NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_MULTI_IDX,
PROP_IFACE, PROP_IFACE,
PROP_IFINDEX, PROP_IFINDEX,
PROP_HWADDR, PROP_HWADDR,
@@ -58,6 +61,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
); );
typedef struct _NMDhcpClientPrivate { typedef struct _NMDhcpClientPrivate {
NMDedupMultiIndex *multi_idx;
char * iface; char * iface;
int ifindex; int ifindex;
GByteArray * hwaddr; GByteArray * hwaddr;
@@ -91,6 +95,14 @@ nm_dhcp_client_get_pid (NMDhcpClient *self)
return NM_DHCP_CLIENT_GET_PRIVATE (self)->pid; 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 * const char *
nm_dhcp_client_get_iface (NMDhcpClient *self) 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 (g_hash_table_size (str_options)) {
if (priv->ipv6) { if (priv->ipv6) {
prefix = nm_dhcp_utils_ip6_prefix_from_options (str_options); 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, priv->iface,
str_options, str_options,
priv->priority, priv->priority,
priv->info_only); priv->info_only);
} else { } 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, priv->iface,
str_options, str_options,
priv->priority); priv->priority);
@@ -847,6 +861,13 @@ set_property (GObject *object, guint prop_id,
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE ((NMDhcpClient *) object); NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE ((NMDhcpClient *) object);
switch (prop_id) { 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: case PROP_IFACE:
/* construct-only */ /* construct-only */
priv->iface = g_value_dup_string (value); priv->iface = g_value_dup_string (value);
@@ -924,6 +945,8 @@ dispose (GObject *object)
} }
G_OBJECT_CLASS (nm_dhcp_client_parent_class)->dispose (object); G_OBJECT_CLASS (nm_dhcp_client_parent_class)->dispose (object);
priv->multi_idx = nm_dedup_multi_index_unref (priv->multi_idx);
} }
static void static void
@@ -940,6 +963,12 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
client_class->stop = stop; client_class->stop = stop;
client_class->get_duid = get_duid; 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] = obj_properties[PROP_IFACE] =
g_param_spec_string (NM_DHCP_CLIENT_INTERFACE, "", "", g_param_spec_string (NM_DHCP_CLIENT_INTERFACE, "", "",
NULL, NULL,

View File

@@ -38,6 +38,7 @@
#define NM_DHCP_CLIENT_UUID "uuid" #define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_PRIORITY "priority" #define NM_DHCP_CLIENT_PRIORITY "priority"
#define NM_DHCP_CLIENT_TIMEOUT "timeout" #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_STATE_CHANGED "state-changed"
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated" #define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
@@ -101,6 +102,8 @@ typedef struct {
GType nm_dhcp_client_get_type (void); 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); pid_t nm_dhcp_client_get_pid (NMDhcpClient *self);
const char *nm_dhcp_client_get_iface (NMDhcpClient *self); const char *nm_dhcp_client_get_iface (NMDhcpClient *self);
@@ -173,7 +176,8 @@ typedef struct {
GType (*get_type)(void); GType (*get_type)(void);
const char *name; const char *name;
const char *(*get_path) (void); 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, int ifindex,
const char *uuid, const char *uuid,
gboolean ipv6, gboolean ipv6,

View File

@@ -25,6 +25,8 @@
#include <ctype.h> #include <ctype.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-dhcp-utils.h" #include "nm-dhcp-utils.h"
#include "nm-ip4-config.h" #include "nm-ip4-config.h"
#include "nm-utils.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: * 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 * @iface: the interface name to match leases with
* @ifindex: interface index of @iface * @ifindex: interface index of @iface
* @contents: the contents of a dhclient leasefile * @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. * #NMIP6Config objects (if @ipv6 is %TRUE) containing the lease data.
*/ */
GSList * 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, int ifindex,
const char *contents, const char *contents,
gboolean ipv6, gboolean ipv6,
@@ -783,7 +787,7 @@ nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
address.lifetime = address.preferred = expiry; address.lifetime = address.preferred = expiry;
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP; 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_add_address (ip4, &address);
nm_ip4_config_set_gateway (ip4, gw); nm_ip4_config_set_gateway (ip4, gw);

View File

@@ -42,7 +42,8 @@ gboolean nm_dhcp_dhclient_save_duid (const char *leasefile,
const char *escaped_duid, const char *escaped_duid,
GError **error); 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, int ifindex,
const char *contents, const char *contents,
gboolean ipv6, gboolean ipv6,

View File

@@ -38,6 +38,8 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h> #include <ctype.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dhcp-dhclient-utils.h" #include "nm-dhcp-dhclient-utils.h"
#include "nm-dhcp-manager.h" #include "nm-dhcp-manager.h"
@@ -148,7 +150,8 @@ get_dhclient_leasefile (const char *iface,
} }
static GSList * 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, int ifindex,
const char *uuid, const char *uuid,
gboolean ipv6, gboolean ipv6,
@@ -166,7 +169,7 @@ nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
&& g_file_get_contents (leasefile, &contents, NULL, NULL) && g_file_get_contents (leasefile, &contents, NULL, NULL)
&& contents && contents
&& contents[0]) && 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 (leasefile);
g_free (contents); g_free (contents);

View File

@@ -34,6 +34,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-config.h" #include "nm-config.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@@ -152,6 +154,7 @@ client_state_changed (NMDhcpClient *client,
static NMDhcpClient * static NMDhcpClient *
client_start (NMDhcpManager *self, client_start (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const GByteArray *hwaddr, const GByteArray *hwaddr,
@@ -195,6 +198,7 @@ client_start (NMDhcpManager *self,
/* And make a new one */ /* And make a new one */
client = g_object_new (priv->client_factory->get_type (), client = g_object_new (priv->client_factory->get_type (),
NM_DHCP_CLIENT_MULTI_IDX, multi_idx,
NM_DHCP_CLIENT_INTERFACE, iface, NM_DHCP_CLIENT_INTERFACE, iface,
NM_DHCP_CLIENT_IFINDEX, ifindex, NM_DHCP_CLIENT_IFINDEX, ifindex,
NM_DHCP_CLIENT_HWADDR, hwaddr, NM_DHCP_CLIENT_HWADDR, hwaddr,
@@ -222,6 +226,7 @@ client_start (NMDhcpManager *self,
/* Caller owns a reference to the NMDhcpClient on return */ /* Caller owns a reference to the NMDhcpClient on return */
NMDhcpClient * NMDhcpClient *
nm_dhcp_manager_start_ip4 (NMDhcpManager *self, nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const GByteArray *hwaddr, 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, dhcp_client_id, timeout, dhcp_anycast_addr, hostname,
use_fqdn, FALSE, 0, last_ip_address, 0); 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 */ /* Caller owns a reference to the NMDhcpClient on return */
NMDhcpClient * NMDhcpClient *
nm_dhcp_manager_start_ip6 (NMDhcpManager *self, nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const GByteArray *hwaddr, const GByteArray *hwaddr,
@@ -299,7 +305,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
/* Always prefer the explicit dhcp-hostname if given */ /* Always prefer the explicit dhcp-hostname if given */
hostname = dhcp_hostname ? dhcp_hostname : priv->default_hostname; 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, ll_addr, NULL, timeout, dhcp_anycast_addr, hostname, TRUE, info_only,
privacy, NULL, needed_prefixes); privacy, NULL, needed_prefixes);
} }
@@ -320,6 +326,7 @@ nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager, const char *hostna
GSList * GSList *
nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self, nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const char *uuid, const char *uuid,
@@ -336,7 +343,7 @@ nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
priv = NM_DHCP_MANAGER_GET_PRIVATE (self); priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
if ( priv->client_factory if ( priv->client_factory
&& priv->client_factory->get_lease_ip_configs) && 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; return NULL;
} }

View File

@@ -46,6 +46,7 @@ void nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager,
const char *hostname); const char *hostname);
NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager, NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
struct _NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const GByteArray *hwaddr, const GByteArray *hwaddr,
@@ -60,6 +61,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
const char *last_ip_address); const char *last_ip_address);
NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager, NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
struct _NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const GByteArray *hwaddr, const GByteArray *hwaddr,
@@ -75,6 +77,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
guint needed_prefixes); guint needed_prefixes);
GSList * nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self, GSList * nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
struct _NMDedupMultiIndex *multi_idx,
const char *iface, const char *iface,
int ifindex, int ifindex,
const char *uuid, const char *uuid,

View File

@@ -28,6 +28,8 @@
#include <ctype.h> #include <ctype.h>
#include <net/if_arp.h> #include <net/if_arp.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dhcp-utils.h" #include "nm-dhcp-utils.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@@ -216,7 +218,8 @@ G_STMT_START { \
} G_STMT_END } G_STMT_END
static NMIP4Config * static NMIP4Config *
lease_to_ip4_config (const char *iface, lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex, int ifindex,
sd_dhcp_lease *lease, sd_dhcp_lease *lease,
GHashTable *options, GHashTable *options,
@@ -244,7 +247,7 @@ lease_to_ip4_config (const char *iface,
g_return_val_if_fail (lease != NULL, NULL); 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 */ /* Address */
sd_dhcp_lease_get_address (lease, &tmp_addr); 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 * 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, int ifindex,
const char *uuid, const char *uuid,
gboolean ipv6, gboolean ipv6,
@@ -451,7 +455,7 @@ nm_dhcp_systemd_get_lease_ip_configs (const char *iface,
path = get_leasefile_path (iface, uuid, FALSE); path = get_leasefile_path (iface, uuid, FALSE);
r = dhcp_lease_load (&lease, path); r = dhcp_lease_load (&lease, path);
if (r == 0 && lease) { 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) if (ip4_config)
leases = g_slist_append (leases, ip4_config); leases = g_slist_append (leases, ip4_config);
sd_dhcp_lease_unref (lease); sd_dhcp_lease_unref (lease);
@@ -505,7 +509,8 @@ bound4_handle (NMDhcpSystemd *self)
_LOGD ("lease available"); _LOGD ("lease available");
options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); 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)), nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
lease, lease,
options, options,
@@ -725,7 +730,8 @@ error:
} }
static NMIP6Config * static NMIP6Config *
lease_to_ip6_config (const char *iface, lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex, int ifindex,
sd_dhcp6_lease *lease, sd_dhcp6_lease *lease,
GHashTable *options, GHashTable *options,
@@ -743,7 +749,7 @@ lease_to_ip6_config (const char *iface,
gint32 ts; gint32 ts;
g_return_val_if_fail (lease, NULL); 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 (); ts = nm_utils_get_monotonic_timestamp_s ();
/* Addresses */ /* Addresses */
@@ -830,7 +836,8 @@ bound6_handle (NMDhcpSystemd *self)
_LOGD ("lease available"); _LOGD ("lease available");
options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); 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)), nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
lease, lease,
options, options,

View File

@@ -24,6 +24,8 @@
#include <unistd.h> #include <unistd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-dhcp-utils.h" #include "nm-dhcp-utils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@@ -383,7 +385,8 @@ ip4_add_domain_search (gpointer data, gpointer user_data)
} }
NMIP4Config * 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, const char *iface,
GHashTable *options, GHashTable *options,
guint32 priority) guint32 priority)
@@ -398,7 +401,7 @@ nm_dhcp_utils_ip4_config_from_options (int ifindex,
g_return_val_if_fail (options != NULL, NULL); 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)); memset (&address, 0, sizeof (address));
address.timestamp = nm_utils_get_monotonic_timestamp_s (); address.timestamp = nm_utils_get_monotonic_timestamp_s ();
@@ -616,7 +619,8 @@ nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options)
} }
NMIP6Config * 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, const char *iface,
GHashTable *options, GHashTable *options,
guint32 priority, guint32 priority,
@@ -633,7 +637,7 @@ nm_dhcp_utils_ip6_config_from_options (int ifindex,
address.plen = 128; address.plen = 128;
address.timestamp = nm_utils_get_monotonic_timestamp_s (); 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"); str = g_hash_table_lookup (options, "max_life");
if (str) { if (str) {

View File

@@ -24,12 +24,14 @@
#include "nm-ip4-config.h" #include "nm-ip4-config.h"
#include "nm-ip6-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, const char *iface,
GHashTable *options, GHashTable *options,
guint priority); 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, const char *iface,
GHashTable *options, GHashTable *options,
guint priority, guint priority,

View File

@@ -24,6 +24,8 @@
#include <unistd.h> #include <unistd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "dhcp/nm-dhcp-dhclient-utils.h" #include "dhcp/nm-dhcp-dhclient-utils.h"
#include "dhcp/nm-dhcp-utils.h" #include "dhcp/nm-dhcp-utils.h"
@@ -838,6 +840,7 @@ test_interface2 (void)
static void static void
test_read_lease_ip4_config_basic (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; GError *error = NULL;
char *contents = NULL; char *contents = NULL;
gboolean success; gboolean success;
@@ -854,7 +857,7 @@ test_read_lease_ip4_config_basic (void)
/* Date from before the least expiration */ /* Date from before the least expiration */
now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32); 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); g_assert_cmpint (g_slist_length (leases), ==, 2);
/* IP4Config #1 */ /* IP4Config #1 */
@@ -915,6 +918,7 @@ test_read_lease_ip4_config_basic (void)
static void static void
test_read_lease_ip4_config_expired (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; GError *error = NULL;
char *contents = NULL; char *contents = NULL;
gboolean success; gboolean success;
@@ -928,7 +932,7 @@ test_read_lease_ip4_config_expired (void)
/* Date from *after* the lease expiration */ /* Date from *after* the lease expiration */
now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32); 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_assert (leases == NULL);
g_date_time_unref (now); g_date_time_unref (now);
@@ -938,6 +942,7 @@ test_read_lease_ip4_config_expired (void)
static void static void
test_read_lease_ip4_config_expect_failure (gconstpointer user_data) 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; GError *error = NULL;
char *contents = NULL; char *contents = NULL;
gboolean success; gboolean success;
@@ -950,7 +955,7 @@ test_read_lease_ip4_config_expect_failure (gconstpointer user_data)
/* Date from before the least expiration */ /* Date from before the least expiration */
now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1); 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_assert (leases == NULL);
g_date_time_unref (now); g_date_time_unref (now);

View File

@@ -23,6 +23,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <string.h> #include <string.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "dhcp/nm-dhcp-utils.h" #include "dhcp/nm-dhcp-utils.h"
@@ -30,6 +31,20 @@
#include "nm-test-utils-core.h" #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 { typedef struct {
const char *name; const char *name;
const char *value; const char *value;
@@ -86,8 +101,7 @@ test_generic_options (void)
const char *expected_route2_gw = "10.1.1.1"; const char *expected_route2_gw = "10.1.1.1";
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 address */ /* IP4 address */
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); 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 (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 address */ /* IP4 address */
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); 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); options = fill_table (generic_options, NULL);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_assert (nm_ip4_config_get_metered (ip4_config) == FALSE); g_assert (nm_ip4_config_get_metered (ip4_config) == FALSE);
g_hash_table_destroy (options); g_hash_table_destroy (options);
g_clear_object (&ip4_config); g_clear_object (&ip4_config);
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_assert (nm_ip4_config_get_metered (ip4_config) == TRUE); g_assert (nm_ip4_config_get_metered (ip4_config) == TRUE);
g_hash_table_destroy (options); g_hash_table_destroy (options);
} }
@@ -246,8 +257,7 @@ test_classless_static_routes_1 (void)
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 routes */ /* 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), ==, 2);
@@ -274,8 +284,7 @@ test_classless_static_routes_2 (void)
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 routes */ /* 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), ==, 2);
@@ -303,8 +312,7 @@ test_fedora_dhclient_classless_static_routes (void)
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 routes */ /* 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), ==, 2);
@@ -335,8 +343,7 @@ test_dhclient_invalid_classless_routes_1 (void)
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*ignoring invalid classless static routes*"); "*ignoring invalid classless static routes*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* IP4 routes */ /* IP4 routes */
@@ -366,8 +373,7 @@ test_dhcpcd_invalid_classless_routes_1 (void)
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*ignoring invalid classless static routes*"); "*ignoring invalid classless static routes*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* Test falling back to old-style static routes if the classless static /* 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, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*ignoring invalid classless static routes*"); "*ignoring invalid classless static routes*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* Test falling back to old-style static routes if the classless static /* 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, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*ignoring invalid classless static routes*"); "*ignoring invalid classless static routes*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* Test falling back to old-style static routes if the classless static /* 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, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*ignoring invalid classless static routes*"); "*ignoring invalid classless static routes*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* IP4 routes */ /* IP4 routes */
@@ -493,8 +496,7 @@ test_dhcpcd_invalid_classless_routes_3 (void)
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*DHCP provided invalid classless static route*"); "*DHCP provided invalid classless static route*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* IP4 routes */ /* IP4 routes */
@@ -519,8 +521,7 @@ test_dhclient_gw_in_classless_routes (void)
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 routes */ /* 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), ==, 1);
@@ -547,8 +548,7 @@ test_dhcpcd_gw_in_classless_routes (void)
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* IP4 routes */ /* 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), ==, 1);
@@ -575,8 +575,7 @@ test_escaped_domain_searches (void)
options = fill_table (generic_options, NULL); options = fill_table (generic_options, NULL);
options = fill_table (data, options); options = fill_table (data, options);
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
/* domain searches */ /* domain searches */
g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 3); 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, g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE,
"*invalid domain search*"); "*invalid domain search*");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_test_assert_expected_messages (); g_test_assert_expected_messages ();
/* domain searches */ /* 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_insert (options, "ip_address", (gpointer) ip);
g_hash_table_remove (options, "subnet_mask"); g_hash_table_remove (options, "subnet_mask");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
address = nm_ip4_config_get_address (ip4_config, 0); 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, "ip_address", "172.16.54.22");
g_hash_table_insert (options, "subnet_mask", "255.255.252.0"); g_hash_table_insert (options, "subnet_mask", "255.255.252.0");
ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert (ip4_config);
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
address = nm_ip4_config_get_address (ip4_config, 0); address = nm_ip4_config_get_address (ip4_config, 0);

View File

@@ -122,7 +122,8 @@ dhcp4_state_changed (NMDhcpClient *client,
switch (state) { switch (state) {
case NM_DHCP_STATE_BOUND: case NM_DHCP_STATE_BOUND:
g_assert (ip4_config); g_assert (ip4_config);
existing = nm_ip4_config_capture (NM_PLATFORM_GET, gl.ifindex, FALSE); existing = nm_ip4_config_capture (nm_platform_get_multi_idx (NM_PLATFORM_GET),
NM_PLATFORM_GET, gl.ifindex, FALSE);
if (last_config) if (last_config)
nm_ip4_config_subtract (existing, last_config); nm_ip4_config_subtract (existing, last_config);
@@ -132,7 +133,8 @@ dhcp4_state_changed (NMDhcpClient *client,
if (last_config) if (last_config)
g_object_unref (last_config); g_object_unref (last_config);
last_config = nm_ip4_config_new (nm_dhcp_client_get_ifindex (client)); last_config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
nm_dhcp_client_get_ifindex (client));
nm_ip4_config_replace (last_config, ip4_config, NULL); nm_ip4_config_replace (last_config, ip4_config, NULL);
break; break;
case NM_DHCP_STATE_TIMEOUT: case NM_DHCP_STATE_TIMEOUT:
@@ -177,11 +179,14 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in
ifa_flags |= IFA_F_MANAGETEMPADDR; ifa_flags |= IFA_F_MANAGETEMPADDR;
} }
existing = nm_ip6_config_capture (NM_PLATFORM_GET, gl.ifindex, FALSE, global_opt.tempaddr); existing = nm_ip6_config_capture (nm_platform_get_multi_idx (NM_PLATFORM_GET),
NM_PLATFORM_GET, gl.ifindex, FALSE, global_opt.tempaddr);
if (ndisc_config) if (ndisc_config)
nm_ip6_config_subtract (existing, ndisc_config); nm_ip6_config_subtract (existing, ndisc_config);
else else {
ndisc_config = nm_ip6_config_new (gl.ifindex); ndisc_config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
gl.ifindex);
}
if (changed & NM_NDISC_CONFIG_GATEWAYS) { if (changed & NM_NDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in neighbor discovery cache. */ /* Use the first gateway as ordered in neighbor discovery cache. */
@@ -469,6 +474,7 @@ main (int argc, char *argv[])
nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip4_property_path (global_opt.ifname, "promote_secondaries")), "1"); nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_ip4_property_path (global_opt.ifname, "promote_secondaries")), "1");
dhcp4_client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (), dhcp4_client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (),
nm_platform_get_multi_idx (NM_PLATFORM_GET),
global_opt.ifname, global_opt.ifname,
gl.ifindex, gl.ifindex,
hwaddr, hwaddr,

View File

@@ -26,6 +26,8 @@
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "platform/nm-platform.h" #include "platform/nm-platform.h"
#include "platform/nm-platform-utils.h" #include "platform/nm-platform-utils.h"
@@ -44,6 +46,7 @@ G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF);
/*****************************************************************************/ /*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config,
PROP_MULTI_IDX,
PROP_IFINDEX, PROP_IFINDEX,
PROP_ADDRESS_DATA, PROP_ADDRESS_DATA,
PROP_ADDRESSES, PROP_ADDRESSES,
@@ -80,6 +83,7 @@ typedef struct {
GArray *wins; GArray *wins;
GVariant *address_data_variant; GVariant *address_data_variant;
GVariant *addresses_variant; GVariant *addresses_variant;
NMDedupMultiIndex *multi_idx;
} NMIP4ConfigPrivate; } NMIP4ConfigPrivate;
struct _NMIP4Config { struct _NMIP4Config {
@@ -103,6 +107,12 @@ nm_ip4_config_get_ifindex (const NMIP4Config *config)
return NM_IP4_CONFIG_GET_PRIVATE (config)->ifindex; return NM_IP4_CONFIG_GET_PRIVATE (config)->ifindex;
} }
NMDedupMultiIndex *
nm_ip4_config_get_multi_idx (const NMIP4Config *config)
{
return NM_IP4_CONFIG_GET_PRIVATE (config)->multi_idx;
}
/*****************************************************************************/ /*****************************************************************************/
static gboolean static gboolean
@@ -259,7 +269,7 @@ sort_captured_addresses (gconstpointer a, gconstpointer b)
} }
NMIP4Config * NMIP4Config *
nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf) nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf)
{ {
NMIP4Config *config; NMIP4Config *config;
NMIP4ConfigPrivate *priv; NMIP4ConfigPrivate *priv;
@@ -272,7 +282,7 @@ nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resol
if (nm_platform_link_get_master (platform, ifindex) > 0) if (nm_platform_link_get_master (platform, ifindex) > 0)
return NULL; return NULL;
config = nm_ip4_config_new (ifindex); config = nm_ip4_config_new (multi_idx, ifindex);
priv = NM_IP4_CONFIG_GET_PRIVATE (config); priv = NM_IP4_CONFIG_GET_PRIVATE (config);
g_array_unref (priv->addresses); g_array_unref (priv->addresses);
@@ -2467,6 +2477,13 @@ set_property (GObject *object,
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
switch (prop_id) { 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_IFINDEX: case PROP_IFINDEX:
/* construct-only */ /* construct-only */
priv->ifindex = g_value_get_int (value); priv->ifindex = g_value_get_int (value);
@@ -2496,10 +2513,11 @@ nm_ip4_config_init (NMIP4Config *config)
} }
NMIP4Config * NMIP4Config *
nm_ip4_config_new (int ifindex) nm_ip4_config_new (NMDedupMultiIndex *multi_idx, int ifindex)
{ {
g_return_val_if_fail (ifindex >= -1, NULL); g_return_val_if_fail (ifindex >= -1, NULL);
return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG,
NM_IP4_CONFIG_MULTI_IDX, multi_idx,
NM_IP4_CONFIG_IFINDEX, ifindex, NM_IP4_CONFIG_IFINDEX, ifindex,
NULL); NULL);
} }
@@ -2523,6 +2541,8 @@ finalize (GObject *object)
g_array_unref (priv->wins); g_array_unref (priv->wins);
G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object);
nm_dedup_multi_index_unref (priv->multi_idx);
} }
static void static void
@@ -2537,6 +2557,11 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->finalize = finalize; object_class->finalize = finalize;
obj_properties[PROP_MULTI_IDX] =
g_param_spec_pointer (NM_IP4_CONFIG_MULTI_IDX, "", "",
G_PARAM_WRITABLE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IFINDEX] = obj_properties[PROP_IFINDEX] =
g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "", g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "",
-1, G_MAXINT, -1, -1, G_MAXINT, -1,

View File

@@ -34,6 +34,7 @@
typedef struct _NMIP4ConfigClass NMIP4ConfigClass; typedef struct _NMIP4ConfigClass NMIP4ConfigClass;
/* internal */ /* internal */
#define NM_IP4_CONFIG_MULTI_IDX "multi-idx"
#define NM_IP4_CONFIG_IFINDEX "ifindex" #define NM_IP4_CONFIG_IFINDEX "ifindex"
/* public*/ /* public*/
@@ -54,12 +55,14 @@ typedef struct _NMIP4ConfigClass NMIP4ConfigClass;
GType nm_ip4_config_get_type (void); GType nm_ip4_config_get_type (void);
NMIP4Config * nm_ip4_config_new (int ifindex); NMIP4Config * nm_ip4_config_new (struct _NMDedupMultiIndex *multi_idx,
int ifindex);
int nm_ip4_config_get_ifindex (const NMIP4Config *config); int nm_ip4_config_get_ifindex (const NMIP4Config *config);
struct _NMDedupMultiIndex *nm_ip4_config_get_multi_idx (const NMIP4Config *self);
NMIP4Config *nm_ip4_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf); NMIP4Config *nm_ip4_config_capture (struct _NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf);
gboolean nm_ip4_config_commit (const NMIP4Config *config, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric); gboolean nm_ip4_config_commit (const NMIP4Config *config, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric);
void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric); void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config); NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config);

View File

@@ -26,6 +26,8 @@
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "nm-utils/nm-dedup-multi.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "platform/nm-platform.h" #include "platform/nm-platform.h"
#include "platform/nm-platform-utils.h" #include "platform/nm-platform-utils.h"
@@ -53,6 +55,7 @@ typedef struct {
GPtrArray *dns_options; GPtrArray *dns_options;
GVariant *address_data_variant; GVariant *address_data_variant;
GVariant *addresses_variant; GVariant *addresses_variant;
NMDedupMultiIndex *multi_idx;
} NMIP6ConfigPrivate; } NMIP6ConfigPrivate;
struct _NMIP6Config { struct _NMIP6Config {
@@ -69,6 +72,7 @@ G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP6Config, NM_IS_IP6_CONFIG) #define NM_IP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP6Config, NM_IS_IP6_CONFIG)
NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config, NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config,
PROP_MULTI_IDX,
PROP_IFINDEX, PROP_IFINDEX,
PROP_ADDRESS_DATA, PROP_ADDRESS_DATA,
PROP_ADDRESSES, PROP_ADDRESSES,
@@ -90,6 +94,12 @@ nm_ip6_config_get_ifindex (const NMIP6Config *config)
return NM_IP6_CONFIG_GET_PRIVATE (config)->ifindex; return NM_IP6_CONFIG_GET_PRIVATE (config)->ifindex;
} }
NMDedupMultiIndex *
nm_ip6_config_get_multi_idx (const NMIP6Config *config)
{
return NM_IP6_CONFIG_GET_PRIVATE (config)->multi_idx;
}
void void
nm_ip6_config_set_privacy (NMIP6Config *config, NMSettingIP6ConfigPrivacy privacy) nm_ip6_config_set_privacy (NMIP6Config *config, NMSettingIP6ConfigPrivacy privacy)
{ {
@@ -301,7 +311,7 @@ nm_ip6_config_addresses_sort (NMIP6Config *self)
} }
NMIP6Config * NMIP6Config *
nm_ip6_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary) nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary)
{ {
NMIP6Config *config; NMIP6Config *config;
NMIP6ConfigPrivate *priv; NMIP6ConfigPrivate *priv;
@@ -315,7 +325,7 @@ nm_ip6_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resol
if (nm_platform_link_get_master (platform, ifindex) > 0) if (nm_platform_link_get_master (platform, ifindex) > 0)
return NULL; return NULL;
config = nm_ip6_config_new (ifindex); config = nm_ip6_config_new (multi_idx, ifindex);
priv = NM_IP6_CONFIG_GET_PRIVATE (config); priv = NM_IP6_CONFIG_GET_PRIVATE (config);
g_array_unref (priv->addresses); g_array_unref (priv->addresses);
@@ -2229,6 +2239,13 @@ set_property (GObject *object,
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
switch (prop_id) { 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_IFINDEX: case PROP_IFINDEX:
/* construct-only */ /* construct-only */
priv->ifindex = g_value_get_int (value); priv->ifindex = g_value_get_int (value);
@@ -2256,10 +2273,11 @@ nm_ip6_config_init (NMIP6Config *config)
} }
NMIP6Config * NMIP6Config *
nm_ip6_config_new (int ifindex) nm_ip6_config_new (NMDedupMultiIndex *multi_idx, int ifindex)
{ {
g_return_val_if_fail (ifindex >= -1, NULL); g_return_val_if_fail (ifindex >= -1, NULL);
return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG,
NM_IP6_CONFIG_MULTI_IDX, multi_idx,
NM_IP6_CONFIG_IFINDEX, ifindex, NM_IP6_CONFIG_IFINDEX, ifindex,
NULL); NULL);
} }
@@ -2271,7 +2289,8 @@ nm_ip6_config_new_cloned (const NMIP6Config *src)
g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL); g_return_val_if_fail (NM_IS_IP6_CONFIG (src), NULL);
new = nm_ip6_config_new (nm_ip6_config_get_ifindex (src)); new = nm_ip6_config_new (nm_ip6_config_get_multi_idx (src),
nm_ip6_config_get_ifindex (src));
nm_ip6_config_replace (new, src, NULL); nm_ip6_config_replace (new, src, NULL);
return new; return new;
} }
@@ -2292,6 +2311,8 @@ finalize (GObject *object)
nm_clear_g_variant (&priv->addresses_variant); nm_clear_g_variant (&priv->addresses_variant);
G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object); G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object);
nm_dedup_multi_index_unref (priv->multi_idx);
} }
static void static void
@@ -2306,6 +2327,11 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->finalize = finalize; object_class->finalize = finalize;
obj_properties[PROP_MULTI_IDX] =
g_param_spec_pointer (NM_IP6_CONFIG_MULTI_IDX, "", "",
G_PARAM_WRITABLE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IFINDEX] = obj_properties[PROP_IFINDEX] =
g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "",
-1, G_MAXINT, -1, -1, G_MAXINT, -1,

View File

@@ -36,6 +36,7 @@
typedef struct _NMIP6ConfigClass NMIP6ConfigClass; typedef struct _NMIP6ConfigClass NMIP6ConfigClass;
/* internal */ /* internal */
#define NM_IP6_CONFIG_MULTI_IDX "multi-idx"
#define NM_IP6_CONFIG_IFINDEX "ifindex" #define NM_IP6_CONFIG_IFINDEX "ifindex"
/* public */ /* public */
@@ -55,13 +56,15 @@ typedef struct _NMIP6ConfigClass NMIP6ConfigClass;
GType nm_ip6_config_get_type (void); GType nm_ip6_config_get_type (void);
NMIP6Config * nm_ip6_config_new (int ifindex); NMIP6Config * nm_ip6_config_new (struct _NMDedupMultiIndex *multi_idx, int ifindex);
NMIP6Config * nm_ip6_config_new_cloned (const NMIP6Config *src); NMIP6Config * nm_ip6_config_new_cloned (const NMIP6Config *src);
int nm_ip6_config_get_ifindex (const NMIP6Config *config); int nm_ip6_config_get_ifindex (const NMIP6Config *config);
struct _NMDedupMultiIndex *nm_ip6_config_get_multi_idx (const NMIP6Config *self);
NMIP6Config *nm_ip6_config_capture (NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary); NMIP6Config *nm_ip6_config_capture (struct _NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex,
gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
gboolean nm_ip6_config_commit (const NMIP6Config *config, gboolean nm_ip6_config_commit (const NMIP6Config *config,
NMPlatform *platform, NMPlatform *platform,
NMRouteManager *route_manager, NMRouteManager *route_manager,

View File

@@ -22,6 +22,8 @@
#include "nm-netns.h" #include "nm-netns.h"
#include "nm-utils/nm-dedup-multi.h"
#include "platform/nm-platform.h" #include "platform/nm-platform.h"
#include "platform/nmp-netns.h" #include "platform/nmp-netns.h"
#include "nm-route-manager.h" #include "nm-route-manager.h"
@@ -74,6 +76,12 @@ nm_netns_get_platform (NMNetns *self)
return NM_NETNS_GET_PRIVATE (self)->platform; return NM_NETNS_GET_PRIVATE (self)->platform;
} }
NMDedupMultiIndex *
nm_netns_get_multi_idx (NMNetns *self)
{
return nm_platform_get_multi_idx (NM_NETNS_GET_PRIVATE (self)->platform);
}
NMDefaultRouteManager * NMDefaultRouteManager *
nm_netns_get_default_route_manager (NMNetns *self) nm_netns_get_default_route_manager (NMNetns *self)
{ {

View File

@@ -42,6 +42,8 @@ NMPNetns *nm_netns_get_platform_netns (NMNetns *self);
NMRouteManager *nm_netns_get_route_manager (NMNetns *self); NMRouteManager *nm_netns_get_route_manager (NMNetns *self);
NMDefaultRouteManager *nm_netns_get_default_route_manager (NMNetns *self); NMDefaultRouteManager *nm_netns_get_default_route_manager (NMNetns *self);
struct _NMDedupMultiIndex *nm_netns_get_multi_idx (NMNetns *self);
#define NM_NETNS_GET (nm_netns_get ()) #define NM_NETNS_GET (nm_netns_get ())
#endif /* __NM_NETNS_H__ */ #endif /* __NM_NETNS_H__ */

View File

@@ -265,13 +265,24 @@ nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP
#ifdef __NETWORKMANAGER_IP4_CONFIG_H__ #ifdef __NETWORKMANAGER_IP4_CONFIG_H__
#include "nm-utils/nm-dedup-multi.h"
static inline NMIP4Config *
nmtst_ip4_config_new (int ifindex)
{
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new ();
return nm_ip4_config_new (multi_idx, ifindex);
}
static inline NMIP4Config * static inline NMIP4Config *
nmtst_ip4_config_clone (NMIP4Config *config) nmtst_ip4_config_clone (NMIP4Config *config)
{ {
NMIP4Config *copy = nm_ip4_config_new (-1); NMIP4Config *copy;
g_assert (copy);
g_assert (config); g_assert (config);
copy = nm_ip4_config_new (nm_ip4_config_get_multi_idx (config), -1);
g_assert (copy);
nm_ip4_config_replace (copy, config, NULL); nm_ip4_config_replace (copy, config, NULL);
return copy; return copy;
} }
@@ -281,13 +292,24 @@ nmtst_ip4_config_clone (NMIP4Config *config)
#ifdef __NETWORKMANAGER_IP6_CONFIG_H__ #ifdef __NETWORKMANAGER_IP6_CONFIG_H__
#include "nm-utils/nm-dedup-multi.h"
static inline NMIP6Config *
nmtst_ip6_config_new (int ifindex)
{
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new ();
return nm_ip6_config_new (multi_idx, ifindex);
}
static inline NMIP6Config * static inline NMIP6Config *
nmtst_ip6_config_clone (NMIP6Config *config) nmtst_ip6_config_clone (NMIP6Config *config)
{ {
NMIP6Config *copy = nm_ip6_config_new (-1); NMIP6Config *copy;
g_assert (copy);
g_assert (config); g_assert (config);
copy = nm_ip6_config_new (nm_ip6_config_get_multi_idx (config), -1);
g_assert (copy);
nm_ip6_config_replace (copy, config, NULL); nm_ip6_config_replace (copy, config, NULL);
return copy; return copy;
} }

View File

@@ -56,6 +56,8 @@ typedef struct _NMSleepMonitor NMSleepMonitor;
typedef struct _NMLldpListener NMLldpListener; typedef struct _NMLldpListener NMLldpListener;
typedef struct _NMConfigDeviceStateData NMConfigDeviceStateData; typedef struct _NMConfigDeviceStateData NMConfigDeviceStateData;
struct _NMDedupMultiIndex;
/*****************************************************************************/ /*****************************************************************************/
typedef enum { typedef enum {

View File

@@ -35,6 +35,7 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-utils/nm-dedup-multi.h"
#include "nm-core-utils.h" #include "nm-core-utils.h"
#include "nm-platform-utils.h" #include "nm-platform-utils.h"
@@ -85,6 +86,7 @@ enum {
typedef struct _NMPlatformPrivate { typedef struct _NMPlatformPrivate {
bool log_with_ptr:1; bool log_with_ptr:1;
NMDedupMultiIndex *multi_idx;
} NMPlatformPrivate; } NMPlatformPrivate;
G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT) G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
@@ -193,6 +195,23 @@ nm_platform_get ()
/*****************************************************************************/ /*****************************************************************************/
NMDedupMultiIndex *
nm_platform_get_multi_idx (NMPlatform *self)
{
NMPlatformPrivate *priv;
g_return_val_if_fail (NM_IS_PLATFORM (self), NULL);
priv = NM_PLATFORM_GET_PRIVATE (self);
if (G_UNLIKELY (!priv->multi_idx))
priv->multi_idx = nm_dedup_multi_index_new ();
return priv->multi_idx;
}
/*****************************************************************************/
/** /**
* _nm_platform_error_to_string: * _nm_platform_error_to_string:
* @error_code: the error code to stringify. * @error_code: the error code to stringify.
@@ -4755,7 +4774,10 @@ static void
finalize (GObject *object) finalize (GObject *object)
{ {
NMPlatform *self = NM_PLATFORM (object); NMPlatform *self = NM_PLATFORM (object);
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self);
if (priv->multi_idx)
nm_dedup_multi_index_unref (priv->multi_idx);
g_clear_object (&self->_netns); g_clear_object (&self->_netns);
} }

View File

@@ -1043,4 +1043,6 @@ gboolean nm_platform_ethtool_set_wake_on_lan (NMPlatform *self, int ifindex, NMS
gboolean nm_platform_ethtool_set_link_settings (NMPlatform *self, int ifindex, gboolean autoneg, guint32 speed, NMPlatformLinkDuplexType duplex); gboolean nm_platform_ethtool_set_link_settings (NMPlatform *self, int ifindex, gboolean autoneg, guint32 speed, NMPlatformLinkDuplexType duplex);
gboolean nm_platform_ethtool_get_link_settings (NMPlatform *self, int ifindex, gboolean *out_autoneg, guint32 *out_speed, NMPlatformLinkDuplexType *out_duplex); gboolean nm_platform_ethtool_get_link_settings (NMPlatform *self, int ifindex, gboolean *out_autoneg, guint32 *out_speed, NMPlatformLinkDuplexType *out_duplex);
struct _NMDedupMultiIndex *nm_platform_get_multi_idx (NMPlatform *self);
#endif /* __NETWORKMANAGER_PLATFORM_H__ */ #endif /* __NETWORKMANAGER_PLATFORM_H__ */

View File

@@ -409,7 +409,8 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager,
nm_clear_g_source (&priv->ppp_timeout_handler); nm_clear_g_source (&priv->ppp_timeout_handler);
config = nm_ip4_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface)); config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface));
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof (address));
address.plen = 32; address.plen = 32;
@@ -505,7 +506,8 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
nm_clear_g_source (&priv->ppp_timeout_handler); nm_clear_g_source (&priv->ppp_timeout_handler);
config = nm_ip6_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface)); config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET),
nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface));
memset (&addr, 0, sizeof (addr)); memset (&addr, 0, sizeof (addr));
addr.plen = 64; addr.plen = 64;

View File

@@ -36,7 +36,7 @@ build_test_config (void)
NMPlatformIP4Route route; NMPlatformIP4Route route;
/* Build up the config to subtract */ /* Build up the config to subtract */
config = nm_ip4_config_new (1); config = nmtst_ip4_config_new (1);
addr = *nmtst_platform_ip4_address ("192.168.1.10", "1.2.3.4", 24); addr = *nmtst_platform_ip4_address ("192.168.1.10", "1.2.3.4", 24);
nm_ip4_config_add_address (config, &addr); nm_ip4_config_add_address (config, &addr);
@@ -156,8 +156,8 @@ test_compare_with_source (void)
NMPlatformIP4Address addr; NMPlatformIP4Address addr;
NMPlatformIP4Route route; NMPlatformIP4Route route;
a = nm_ip4_config_new (1); a = nmtst_ip4_config_new (1);
b = nm_ip4_config_new (2); b = nmtst_ip4_config_new (2);
/* Address */ /* Address */
addr = *nmtst_platform_ip4_address ("1.2.3.4", NULL, 24); addr = *nmtst_platform_ip4_address ("1.2.3.4", NULL, 24);
@@ -189,7 +189,7 @@ test_add_address_with_source (void)
NMPlatformIP4Address addr; NMPlatformIP4Address addr;
const NMPlatformIP4Address *test_addr; const NMPlatformIP4Address *test_addr;
a = nm_ip4_config_new (1); a = nmtst_ip4_config_new (1);
/* Test that a higher priority source is not overwritten */ /* Test that a higher priority source is not overwritten */
addr = *nmtst_platform_ip4_address ("1.2.3.4", NULL, 24); addr = *nmtst_platform_ip4_address ("1.2.3.4", NULL, 24);
@@ -229,7 +229,7 @@ test_add_route_with_source (void)
NMPlatformIP4Route route; NMPlatformIP4Route route;
const NMPlatformIP4Route *test_route; const NMPlatformIP4Route *test_route;
a = nm_ip4_config_new (1); a = nmtst_ip4_config_new (1);
/* Test that a higher priority source is not overwritten */ /* Test that a higher priority source is not overwritten */
route = *nmtst_platform_ip4_route ("1.2.3.4", 24, "1.2.3.1"); route = *nmtst_platform_ip4_route ("1.2.3.4", 24, "1.2.3.1");
@@ -306,7 +306,7 @@ test_strip_search_trailing_dot (void)
{ {
NMIP4Config *config; NMIP4Config *config;
config = nm_ip4_config_new (1); config = nmtst_ip4_config_new (1);
nm_ip4_config_add_search (config, "."); nm_ip4_config_add_search (config, ".");
nm_ip4_config_add_search (config, "foo"); nm_ip4_config_add_search (config, "foo");

View File

@@ -34,7 +34,7 @@ build_test_config (void)
NMIP6Config *config; NMIP6Config *config;
/* Build up the config to subtract */ /* Build up the config to subtract */
config = nm_ip6_config_new (1); config = nmtst_ip6_config_new (1);
nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64)); nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64));
nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL)); nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL));
@@ -127,8 +127,8 @@ test_compare_with_source (void)
NMPlatformIP6Address addr; NMPlatformIP6Address addr;
NMPlatformIP6Route route; NMPlatformIP6Route route;
a = nm_ip6_config_new (1); a = nmtst_ip6_config_new (1);
b = nm_ip6_config_new (2); b = nmtst_ip6_config_new (2);
/* Address */ /* Address */
addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64); addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64);
@@ -160,7 +160,7 @@ test_add_address_with_source (void)
NMPlatformIP6Address addr; NMPlatformIP6Address addr;
const NMPlatformIP6Address *test_addr; const NMPlatformIP6Address *test_addr;
a = nm_ip6_config_new (1); a = nmtst_ip6_config_new (1);
/* Test that a higher priority source is not overwritten */ /* Test that a higher priority source is not overwritten */
addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64); addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64);
@@ -200,7 +200,7 @@ test_add_route_with_source (void)
NMPlatformIP6Route route; NMPlatformIP6Route route;
const NMPlatformIP6Route *test_route; const NMPlatformIP6Route *test_route;
a = nm_ip6_config_new (1); a = nmtst_ip6_config_new (1);
/* Test that a higher priority source is not overwritten */ /* Test that a higher priority source is not overwritten */
route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL); route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
@@ -327,7 +327,7 @@ test_strip_search_trailing_dot (void)
{ {
NMIP6Config *config; NMIP6Config *config;
config = nm_ip6_config_new (1); config = nmtst_ip6_config_new (1);
nm_ip6_config_add_search (config, "."); nm_ip6_config_add_search (config, ".");
nm_ip6_config_add_search (config, "foo"); nm_ip6_config_add_search (config, "foo");

View File

@@ -1046,10 +1046,14 @@ apply_parent_device_config (NMVpnConnection *self)
NMIP6Config *vpn6_parent_config = NULL; NMIP6Config *vpn6_parent_config = NULL;
if (priv->ip_ifindex > 0) { if (priv->ip_ifindex > 0) {
if (priv->ip4_config) if (priv->ip4_config) {
vpn4_parent_config = nm_ip4_config_new (priv->ip_ifindex); vpn4_parent_config = nm_ip4_config_new (nm_netns_get_multi_idx (priv->netns),
if (priv->ip6_config) priv->ip_ifindex);
vpn6_parent_config = nm_ip6_config_new (priv->ip_ifindex); }
if (priv->ip6_config) {
vpn6_parent_config = nm_ip6_config_new (nm_netns_get_multi_idx (priv->netns),
priv->ip_ifindex);
}
} else { } else {
int ifindex; int ifindex;
@@ -1063,11 +1067,13 @@ apply_parent_device_config (NMVpnConnection *self)
* default route. */ * default route. */
ifindex = nm_device_get_ip_ifindex (parent_dev); ifindex = nm_device_get_ip_ifindex (parent_dev);
if (priv->ip4_config) { if (priv->ip4_config) {
vpn4_parent_config = nm_ip4_config_new (ifindex); vpn4_parent_config = nm_ip4_config_new (nm_netns_get_multi_idx (priv->netns),
ifindex);
nm_ip4_config_merge (vpn4_parent_config, priv->ip4_config, NM_IP_CONFIG_MERGE_NO_DNS); nm_ip4_config_merge (vpn4_parent_config, priv->ip4_config, NM_IP_CONFIG_MERGE_NO_DNS);
} }
if (priv->ip6_config) { if (priv->ip6_config) {
vpn6_parent_config = nm_ip6_config_new (ifindex); vpn6_parent_config = nm_ip6_config_new (nm_netns_get_multi_idx (priv->netns),
ifindex);
nm_ip6_config_merge (vpn6_parent_config, priv->ip6_config, NM_IP_CONFIG_MERGE_NO_DNS); nm_ip6_config_merge (vpn6_parent_config, priv->ip6_config, NM_IP_CONFIG_MERGE_NO_DNS);
nm_ip6_config_set_gateway (vpn6_parent_config, NULL); nm_ip6_config_set_gateway (vpn6_parent_config, NULL);
} }
@@ -1436,7 +1442,8 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
if (ip_ifindex <= 0) if (ip_ifindex <= 0)
g_return_if_reached (); g_return_if_reached ();
config = nm_ip4_config_new (ip_ifindex); config = nm_ip4_config_new (nm_netns_get_multi_idx (priv->netns),
ip_ifindex);
nm_ip4_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN); nm_ip4_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN);
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof (address));
@@ -1595,7 +1602,8 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
if (ip_ifindex <= 0) if (ip_ifindex <= 0)
g_return_if_reached (); g_return_if_reached ();
config = nm_ip6_config_new (ip_ifindex); config = nm_ip6_config_new (nm_netns_get_multi_idx (priv->netns),
ip_ifindex);
nm_ip6_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN); nm_ip6_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN);
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof (address));