diff options
31 files changed, 366 insertions, 135 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3abf46cb10..dd9c96cf91 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -35,6 +35,8 @@ #include <fcntl.h> #include <linux/if_addr.h> +#include "nm-utils/nm-dedup-multi.h" + #include "nm-common-macros.h" #include "nm-device-private.h" #include "NetworkManagerUtils.h" @@ -647,12 +649,32 @@ nm_device_get_netns (NMDevice *self) 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 * nm_device_get_platform (NMDevice *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, @@ -5058,7 +5080,7 @@ ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean succes NMIP4Config *empty; 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); g_object_unref (empty); } else { @@ -5215,7 +5237,7 @@ ipv4ll_get_ip4_config (NMDevice *self, guint32 lla) NMPlatformIP4Address address; NMPlatformIP4Route route; - config = nm_ip4_config_new (nm_device_get_ip_ifindex (self)); + config = _ip4_config_new (self); g_assert (config); memset (&address, 0, sizeof (address)); @@ -5430,7 +5452,6 @@ static void ensure_con_ip4_config (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - int ip_ifindex = nm_device_get_ip_ifindex (self); NMConnection *connection; if (priv->con_ip4_config) @@ -5440,7 +5461,7 @@ ensure_con_ip4_config (NMDevice *self) if (!connection) 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_connection_get_setting_ip4_config (connection), nm_device_get_ip4_route_metric (self)); @@ -5456,7 +5477,6 @@ static void ensure_con_ip6_config (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - int ip_ifindex = nm_device_get_ip_ifindex (self); NMConnection *connection; if (priv->con_ip6_config) @@ -5466,7 +5486,7 @@ ensure_con_ip6_config (NMDevice *self) if (!connection) 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_connection_get_setting_ip6_config (connection), 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); if (commit) { ensure_con_ip4_config (self); if (priv->queued_ip4_config_id) { 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), FALSE); } @@ -5824,7 +5845,7 @@ dhcp4_state_changed (NMDhcpClient *client, connection = nm_device_get_applied_connection (self); 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_connection_get_setting_ip4_config (connection), nm_device_get_ip4_route_metric (self)); @@ -5905,6 +5926,7 @@ dhcp4_start (NMDevice *self, /* Begin DHCP on the interface */ g_warn_if_fail (priv->dhcp4.client == NULL); 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_ifindex (self), tmp, @@ -6012,7 +6034,7 @@ shared4_new_config (NMDevice *self, NMConnection *connection) 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); if (is_generated) { /* 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) { 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_connection_get_setting_ip4_config (connection), 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, priv->ndisc ? priv->ndisc_use_tempaddr : @@ -6285,7 +6307,8 @@ ip6_config_merge_and_apply (NMDevice *self, if (priv->queued_ip6_config_id) { g_clear_object (&priv->ext_ip6_config); 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), FALSE, 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 (), + nm_device_get_multi_index (self), nm_device_get_ip_iface (self), nm_device_get_ip_ifindex (self), tmp, @@ -6830,7 +6854,7 @@ nm_device_use_ip6_subnet (NMDevice *self, const NMPlatformIP6Address *subnet) NMPlatformIP6Address address = *subnet; 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. */ 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_searches (priv->ac_ip6_config); } 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) 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); 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) { /* 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)); 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), FALSE, 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); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { 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); g_object_unref (ip4_config); } 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); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { 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 * 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)); 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); } @@ -8925,7 +8950,7 @@ nm_device_reactivate_ip4_config (NMDevice *self, if (priv->ip4_state != IP_NONE) { g_clear_object (&priv->con_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, s_ip4_new, nm_device_get_ip4_route_metric (self)); @@ -8967,7 +8992,7 @@ nm_device_reactivate_ip6_config (NMDevice *self, if (priv->ip6_state != IP_NONE) { g_clear_object (&priv->con_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, s_ip6_new, 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); leases = nm_dhcp_manager_get_lease_ip_configs (nm_dhcp_manager_get (), + nm_device_get_multi_index (self), ip_iface, ip_ifindex, nm_connection_get_uuid (connection), @@ -10680,7 +10706,8 @@ update_ip4_config (NMDevice *self, gboolean initial) /* IPv4 */ 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, capture_resolv_conf); if (priv->ext_ip4_config) { @@ -10755,7 +10782,11 @@ update_ip6_config (NMDevice *self, gboolean initial) /* IPv6 */ g_clear_object (&priv->ext_ip6_config); 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) { priv->ext_ip6_config = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index fb87de896a..358b59af20 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -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); diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 4b16fb1440..819ff2a171 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -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) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index d1ad016a91..e0b45e07ca 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -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! */ diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index 0906f5beba..b08e05051d 100644 --- a/src/dhcp/nm-dhcp-client.c +++ b/src/dhcp/nm-dhcp-client.c @@ -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, diff --git a/src/dhcp/nm-dhcp-client.h b/src/dhcp/nm-dhcp-client.h index e41a59a265..890c5ff595 100644 --- a/src/dhcp/nm-dhcp-client.h +++ b/src/dhcp/nm-dhcp-client.h @@ -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, diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index 11f868e260..6b4ac1f436 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -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); diff --git a/src/dhcp/nm-dhcp-dhclient-utils.h b/src/dhcp/nm-dhcp-dhclient-utils.h index 994b1b9f02..dd276bea45 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.h +++ b/src/dhcp/nm-dhcp-dhclient-utils.h @@ -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, diff --git a/src/dhcp/nm-dhcp-dhclient.c b/src/dhcp/nm-dhcp-dhclient.c index 8a3f642a72..f9b6f879cd 100644 --- a/src/dhcp/nm-dhcp-dhclient.c +++ b/src/dhcp/nm-dhcp-dhclient.c @@ -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); diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index fff9f9ec30..42ec390860 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -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; } diff --git a/src/dhcp/nm-dhcp-manager.h b/src/dhcp/nm-dhcp-manager.h index 66fdd145db..2376ea8921 100644 --- a/src/dhcp/nm-dhcp-manager.h +++ b/src/dhcp/nm-dhcp-manager.h @@ -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, diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index b909475552..2dca9c83d8 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -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, diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c index e55a21b49a..3f17110410 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -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) { diff --git a/src/dhcp/nm-dhcp-utils.h b/src/dhcp/nm-dhcp-utils.h index 05982b166d..3cd0dbc405 100644 --- a/src/dhcp/nm-dhcp-utils.h +++ b/src/dhcp/nm-dhcp-utils.h @@ -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, diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index 2308cf75fa..e90a7976d2 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -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); diff --git a/src/dhcp/tests/test-dhcp-utils.c b/src/dhcp/tests/test-dhcp-utils.c index ffd6349361..0d4e7f78e1 100644 --- a/src/dhcp/tests/test-dhcp-utils.c +++ b/src/dhcp/tests/test-dhcp-utils.c @@ -23,6 +23,7 @@ #include <arpa/inet.h> #include <string.h> +#include "nm-utils/nm-dedup-multi.h" #include "nm-utils.h" #include "dhcp/nm-dhcp-utils.h" @@ -30,6 +31,20 @@ #include "nm-test-utils-core.h" +static NMIP4Config * +_ip4_config_from_options (int ifindex, + const char *iface, + GHashTable *options, + guint32 priority) +{ + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new (); + NMIP4Config *config; + + config = nm_dhcp_utils_ip4_config_from_options (multi_idx, ifindex, iface, options, priority); + g_assert (config); + return config; +} + typedef struct { const char *name; const char *value; @@ -86,8 +101,7 @@ test_generic_options (void) const char *expected_route2_gw = "10.1.1.1"; options = fill_table (generic_options, NULL); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); @@ -157,8 +171,7 @@ test_wins_options (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 address */ g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); @@ -184,16 +197,14 @@ test_vendor_option_metered (void) }; options = fill_table (generic_options, NULL); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert (nm_ip4_config_get_metered (ip4_config) == FALSE); g_hash_table_destroy (options); g_clear_object (&ip4_config); options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert (nm_ip4_config_get_metered (ip4_config) == TRUE); g_hash_table_destroy (options); } @@ -246,8 +257,7 @@ test_classless_static_routes_1 (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); @@ -274,8 +284,7 @@ test_classless_static_routes_2 (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); @@ -303,8 +312,7 @@ test_fedora_dhclient_classless_static_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); @@ -335,8 +343,7 @@ test_dhclient_invalid_classless_routes_1 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* IP4 routes */ @@ -366,8 +373,7 @@ test_dhcpcd_invalid_classless_routes_1 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static @@ -399,8 +405,7 @@ test_dhclient_invalid_classless_routes_2 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static @@ -432,8 +437,7 @@ test_dhcpcd_invalid_classless_routes_2 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static @@ -465,8 +469,7 @@ test_dhclient_invalid_classless_routes_3 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*ignoring invalid classless static routes*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* IP4 routes */ @@ -493,8 +496,7 @@ test_dhcpcd_invalid_classless_routes_3 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*DHCP provided invalid classless static route*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* IP4 routes */ @@ -519,8 +521,7 @@ test_dhclient_gw_in_classless_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); @@ -547,8 +548,7 @@ test_dhcpcd_gw_in_classless_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* IP4 routes */ g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); @@ -575,8 +575,7 @@ test_escaped_domain_searches (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); /* domain searches */ g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 3); @@ -602,8 +601,7 @@ test_invalid_escaped_domain_searches (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*invalid domain search*"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_test_assert_expected_messages (); /* domain searches */ @@ -623,8 +621,7 @@ test_ip4_missing_prefix (const char *ip, guint32 expected_prefix) g_hash_table_insert (options, "ip_address", (gpointer) ip); g_hash_table_remove (options, "subnet_mask"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); address = nm_ip4_config_get_address (ip4_config, 0); @@ -668,8 +665,7 @@ test_ip4_prefix_classless (void) g_hash_table_insert (options, "ip_address", "172.16.54.22"); g_hash_table_insert (options, "subnet_mask", "255.255.252.0"); - ip4_config = nm_dhcp_utils_ip4_config_from_options (1, "eth0", options, 0); - g_assert (ip4_config); + ip4_config = _ip4_config_from_options (1, "eth0", options, 0); g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); address = nm_ip4_config_get_address (ip4_config, 0); diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index f8df2b9a7f..3b60e0d64f 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -122,7 +122,8 @@ dhcp4_state_changed (NMDhcpClient *client, switch (state) { case NM_DHCP_STATE_BOUND: 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) nm_ip4_config_subtract (existing, last_config); @@ -132,7 +133,8 @@ dhcp4_state_changed (NMDhcpClient *client, if (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); break; 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; } - 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) nm_ip6_config_subtract (existing, ndisc_config); - else - ndisc_config = nm_ip6_config_new (gl.ifindex); + else { + ndisc_config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), + gl.ifindex); + } if (changed & NM_NDISC_CONFIG_GATEWAYS) { /* 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"); dhcp4_client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (), + nm_platform_get_multi_idx (NM_PLATFORM_GET), global_opt.ifname, gl.ifindex, hwaddr, diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index ae6af9c350..9ec7eebb95 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -26,6 +26,8 @@ #include <string.h> #include <arpa/inet.h> +#include "nm-utils/nm-dedup-multi.h" + #include "nm-utils.h" #include "platform/nm-platform.h" #include "platform/nm-platform-utils.h" @@ -44,6 +46,7 @@ G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); /*****************************************************************************/ NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, + PROP_MULTI_IDX, PROP_IFINDEX, PROP_ADDRESS_DATA, PROP_ADDRESSES, @@ -80,6 +83,7 @@ typedef struct { GArray *wins; GVariant *address_data_variant; GVariant *addresses_variant; + NMDedupMultiIndex *multi_idx; } NMIP4ConfigPrivate; struct _NMIP4Config { @@ -103,6 +107,12 @@ nm_ip4_config_get_ifindex (const NMIP4Config *config) 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 @@ -259,7 +269,7 @@ sort_captured_addresses (gconstpointer a, gconstpointer b) } 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; 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) return NULL; - config = nm_ip4_config_new (ifindex); + config = nm_ip4_config_new (multi_idx, ifindex); priv = NM_IP4_CONFIG_GET_PRIVATE (config); g_array_unref (priv->addresses); @@ -2467,6 +2477,13 @@ set_property (GObject *object, NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); 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: /* construct-only */ priv->ifindex = g_value_get_int (value); @@ -2496,10 +2513,11 @@ nm_ip4_config_init (NMIP4Config *config) } NMIP4Config * -nm_ip4_config_new (int ifindex) +nm_ip4_config_new (NMDedupMultiIndex *multi_idx, int ifindex) { g_return_val_if_fail (ifindex >= -1, NULL); return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, + NM_IP4_CONFIG_MULTI_IDX, multi_idx, NM_IP4_CONFIG_IFINDEX, ifindex, NULL); } @@ -2523,6 +2541,8 @@ finalize (GObject *object) g_array_unref (priv->wins); G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); + + nm_dedup_multi_index_unref (priv->multi_idx); } static void @@ -2537,6 +2557,11 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) object_class->set_property = set_property; 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] = g_param_spec_int (NM_IP4_CONFIG_IFINDEX, "", "", -1, G_MAXINT, -1, diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index ceb52ac547..1a336968fd 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -34,6 +34,7 @@ typedef struct _NMIP4ConfigClass NMIP4ConfigClass; /* internal */ +#define NM_IP4_CONFIG_MULTI_IDX "multi-idx" #define NM_IP4_CONFIG_IFINDEX "ifindex" /* public*/ @@ -54,12 +55,14 @@ typedef struct _NMIP4ConfigClass NMIP4ConfigClass; 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); +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); void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric); NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config); diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index af88b21c74..7724ad4831 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -26,6 +26,8 @@ #include <string.h> #include <arpa/inet.h> +#include "nm-utils/nm-dedup-multi.h" + #include "nm-utils.h" #include "platform/nm-platform.h" #include "platform/nm-platform-utils.h" @@ -53,6 +55,7 @@ typedef struct { GPtrArray *dns_options; GVariant *address_data_variant; GVariant *addresses_variant; + NMDedupMultiIndex *multi_idx; } NMIP6ConfigPrivate; 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) NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config, + PROP_MULTI_IDX, PROP_IFINDEX, PROP_ADDRESS_DATA, PROP_ADDRESSES, @@ -90,6 +94,12 @@ nm_ip6_config_get_ifindex (const NMIP6Config *config) 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 nm_ip6_config_set_privacy (NMIP6Config *config, NMSettingIP6ConfigPrivacy privacy) { @@ -301,7 +311,7 @@ nm_ip6_config_addresses_sort (NMIP6Config *self) } 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; 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) return NULL; - config = nm_ip6_config_new (ifindex); + config = nm_ip6_config_new (multi_idx, ifindex); priv = NM_IP6_CONFIG_GET_PRIVATE (config); g_array_unref (priv->addresses); @@ -2229,6 +2239,13 @@ set_property (GObject *object, NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); 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: /* construct-only */ priv->ifindex = g_value_get_int (value); @@ -2256,10 +2273,11 @@ nm_ip6_config_init (NMIP6Config *config) } NMIP6Config * -nm_ip6_config_new (int ifindex) +nm_ip6_config_new (NMDedupMultiIndex *multi_idx, int ifindex) { g_return_val_if_fail (ifindex >= -1, NULL); return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, + NM_IP6_CONFIG_MULTI_IDX, multi_idx, NM_IP6_CONFIG_IFINDEX, ifindex, NULL); } @@ -2271,7 +2289,8 @@ nm_ip6_config_new_cloned (const NMIP6Config *src) 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); return new; } @@ -2292,6 +2311,8 @@ finalize (GObject *object) nm_clear_g_variant (&priv->addresses_variant); G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object); + + nm_dedup_multi_index_unref (priv->multi_idx); } static void @@ -2306,6 +2327,11 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) object_class->set_property = set_property; 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] = g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "", -1, G_MAXINT, -1, diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index 557041c958..5dadf796f6 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -36,6 +36,7 @@ typedef struct _NMIP6ConfigClass NMIP6ConfigClass; /* internal */ +#define NM_IP6_CONFIG_MULTI_IDX "multi-idx" #define NM_IP6_CONFIG_IFINDEX "ifindex" /* public */ @@ -55,13 +56,15 @@ typedef struct _NMIP6ConfigClass NMIP6ConfigClass; 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); 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, NMPlatform *platform, NMRouteManager *route_manager, diff --git a/src/nm-netns.c b/src/nm-netns.c index a81aa696ee..f5e6b0014d 100644 --- a/src/nm-netns.c +++ b/src/nm-netns.c @@ -22,6 +22,8 @@ #include "nm-netns.h" +#include "nm-utils/nm-dedup-multi.h" + #include "platform/nm-platform.h" #include "platform/nmp-netns.h" #include "nm-route-manager.h" @@ -74,6 +76,12 @@ nm_netns_get_platform (NMNetns *self) 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 * nm_netns_get_default_route_manager (NMNetns *self) { diff --git a/src/nm-netns.h b/src/nm-netns.h index fd5daf47ff..ebe9d1f2a8 100644 --- a/src/nm-netns.h +++ b/src/nm-netns.h @@ -42,6 +42,8 @@ NMPNetns *nm_netns_get_platform_netns (NMNetns *self); NMRouteManager *nm_netns_get_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 ()) #endif /* __NM_NETNS_H__ */ diff --git a/src/nm-test-utils-core.h b/src/nm-test-utils-core.h index 4e8e2f98e0..8ee7205de8 100644 --- a/src/nm-test-utils-core.h +++ b/src/nm-test-utils-core.h @@ -265,13 +265,24 @@ nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP #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 * nmtst_ip4_config_clone (NMIP4Config *config) { - NMIP4Config *copy = nm_ip4_config_new (-1); + NMIP4Config *copy; - g_assert (copy); 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); return copy; } @@ -281,13 +292,24 @@ nmtst_ip4_config_clone (NMIP4Config *config) #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 * nmtst_ip6_config_clone (NMIP6Config *config) { - NMIP6Config *copy = nm_ip6_config_new (-1); + NMIP6Config *copy; - g_assert (copy); 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); return copy; } diff --git a/src/nm-types.h b/src/nm-types.h index 44b4fecbb3..36a624de8b 100644 --- a/src/nm-types.h +++ b/src/nm-types.h @@ -56,6 +56,8 @@ typedef struct _NMSleepMonitor NMSleepMonitor; typedef struct _NMLldpListener NMLldpListener; typedef struct _NMConfigDeviceStateData NMConfigDeviceStateData; +struct _NMDedupMultiIndex; + /*****************************************************************************/ typedef enum { diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 7cc582e863..80e2efd147 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -35,6 +35,7 @@ #include "nm-utils.h" #include "nm-core-internal.h" +#include "nm-utils/nm-dedup-multi.h" #include "nm-core-utils.h" #include "nm-platform-utils.h" @@ -85,6 +86,7 @@ enum { typedef struct _NMPlatformPrivate { bool log_with_ptr:1; + NMDedupMultiIndex *multi_idx; } NMPlatformPrivate; 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: * @error_code: the error code to stringify. @@ -4755,7 +4774,10 @@ static void finalize (GObject *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); } diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index b7dcb4caca..71dd7f9ff6 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -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_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__ */ diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index 6343df8bf4..104adf5475 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -409,7 +409,8 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, 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)); address.plen = 32; @@ -505,7 +506,8 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, 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)); addr.plen = 64; diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c index cd5b108903..d9afb4c6ac 100644 --- a/src/tests/test-ip4-config.c +++ b/src/tests/test-ip4-config.c @@ -36,7 +36,7 @@ build_test_config (void) NMPlatformIP4Route route; /* 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); nm_ip4_config_add_address (config, &addr); @@ -156,8 +156,8 @@ test_compare_with_source (void) NMPlatformIP4Address addr; NMPlatformIP4Route route; - a = nm_ip4_config_new (1); - b = nm_ip4_config_new (2); + a = nmtst_ip4_config_new (1); + b = nmtst_ip4_config_new (2); /* Address */ addr = *nmtst_platform_ip4_address ("1.2.3.4", NULL, 24); @@ -189,7 +189,7 @@ test_add_address_with_source (void) NMPlatformIP4Address 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 */ addr = *nmtst_platform_ip4_address ("1.2.3.4", NULL, 24); @@ -229,7 +229,7 @@ test_add_route_with_source (void) NMPlatformIP4Route 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 */ 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; - config = nm_ip4_config_new (1); + config = nmtst_ip4_config_new (1); nm_ip4_config_add_search (config, "."); nm_ip4_config_add_search (config, "foo"); diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c index 7e83625c5b..bbb3278bc9 100644 --- a/src/tests/test-ip6-config.c +++ b/src/tests/test-ip6-config.c @@ -34,7 +34,7 @@ build_test_config (void) NMIP6Config *config; /* 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_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; NMPlatformIP6Route route; - a = nm_ip6_config_new (1); - b = nm_ip6_config_new (2); + a = nmtst_ip6_config_new (1); + b = nmtst_ip6_config_new (2); /* Address */ addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64); @@ -160,7 +160,7 @@ test_add_address_with_source (void) NMPlatformIP6Address 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 */ addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64); @@ -200,7 +200,7 @@ test_add_route_with_source (void) NMPlatformIP6Route 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 */ 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; - config = nm_ip6_config_new (1); + config = nmtst_ip6_config_new (1); nm_ip6_config_add_search (config, "."); nm_ip6_config_add_search (config, "foo"); diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index ecc820685c..9a0de7ebfe 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -1046,10 +1046,14 @@ apply_parent_device_config (NMVpnConnection *self) NMIP6Config *vpn6_parent_config = NULL; if (priv->ip_ifindex > 0) { - if (priv->ip4_config) - vpn4_parent_config = nm_ip4_config_new (priv->ip_ifindex); - if (priv->ip6_config) - vpn6_parent_config = nm_ip6_config_new (priv->ip_ifindex); + if (priv->ip4_config) { + vpn4_parent_config = nm_ip4_config_new (nm_netns_get_multi_idx (priv->netns), + 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 { int ifindex; @@ -1063,11 +1067,13 @@ apply_parent_device_config (NMVpnConnection *self) * default route. */ ifindex = nm_device_get_ip_ifindex (parent_dev); 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); } 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_set_gateway (vpn6_parent_config, NULL); } @@ -1436,7 +1442,8 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) if (ip_ifindex <= 0) 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); memset (&address, 0, sizeof (address)); @@ -1595,7 +1602,8 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) if (ip_ifindex <= 0) 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); memset (&address, 0, sizeof (address)); |