core: pass ifindex as parameter to nm_ip6_config_new()

This commit is contained in:
Lubomir Rintel 2015-02-27 16:49:42 +01:00
parent 84f54f0a5f
commit f981407a02
13 changed files with 84 additions and 60 deletions

View file

@ -702,7 +702,7 @@ nmtst_ip4_config_clone (NMIP4Config *config)
inline static NMIP6Config *
nmtst_ip6_config_clone (NMIP6Config *config)
{
NMIP6Config *copy = nm_ip6_config_new ();
NMIP6Config *copy = nm_ip6_config_new (-1);
g_assert (copy);
g_assert (config);

View file

@ -2874,9 +2874,7 @@ ensure_con_ipx_config (NMDevice *self)
return;
priv->con_ip4_config = nm_ip4_config_new (ip_ifindex);
priv->con_ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (priv->con_ip6_config, nm_device_get_ifindex (self));
priv->con_ip6_config = nm_ip6_config_new (ip_ifindex);
nm_ip4_config_merge_setting (priv->con_ip4_config,
nm_connection_get_setting_ip4_config (connection),
@ -3521,8 +3519,7 @@ ip6_config_merge_and_apply (NMDevice *self,
const struct in6_addr *gateway;
/* If no config was passed in, create a new one */
composite = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (composite, nm_device_get_ifindex (self));
composite = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
ensure_con_ipx_config (self);
g_assert (composite);
@ -4112,10 +4109,8 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self)
g_return_if_fail (priv->act_request);
if (!priv->ac_ip6_config) {
priv->ac_ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (priv->ac_ip6_config, nm_device_get_ifindex (self));
}
if (!priv->ac_ip6_config)
priv->ac_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
if (changed & NM_RDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in router discovery cache. */
@ -4619,8 +4614,7 @@ act_stage3_ip6_config_start (NMDevice *self,
ret = linklocal6_start (self);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
/* New blank config; LL address is already in priv->ext_ip6_config */
*out_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (*out_config, nm_device_get_ifindex (self));
*out_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
g_assert (*out_config);
}
} else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
@ -4632,8 +4626,7 @@ act_stage3_ip6_config_start (NMDevice *self,
ret = NM_ACT_STAGE_RETURN_POSTPONE;
} else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0) {
/* New blank config */
*out_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (*out_config, nm_device_get_ifindex (self));
*out_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
g_assert (*out_config);
ret = NM_ACT_STAGE_RETURN_SUCCESS;
@ -6042,7 +6035,7 @@ nm_device_set_ip6_config (NMDevice *self,
gboolean has_changes = FALSE;
gboolean success = TRUE;
NMDeviceStateReason reason_local = NM_DEVICE_STATE_REASON_NONE;
int ip_ifindex;
int ip_ifindex, config_ifindex;
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
@ -6050,6 +6043,12 @@ nm_device_set_ip6_config (NMDevice *self,
ip_iface = nm_device_get_ip_iface (self);
ip_ifindex = nm_device_get_ip_ifindex (self);
if (new_config) {
config_ifindex = nm_ip6_config_get_ifindex (new_config);
if (config_ifindex > 0)
g_return_val_if_fail (ip_ifindex == config_ifindex, FALSE);
}
old_config = priv->ip6_config;
/* Always commit to nm-platform to update lifetimes */

View file

@ -197,10 +197,8 @@ modem_ip6_config_result (NMModem *modem,
/* Re-enable IPv6 on the interface */
nm_device_ipv6_sysctl_set (device, "disable_ipv6", "0");
if (config) {
nm_ip6_config_set_ifindex (config, nm_device_get_ifindex (device));
if (config)
nm_device_set_wwan_ip6_config (device, config);
}
if (do_slaac == FALSE) {
if (got_config)

View file

@ -800,6 +800,7 @@ stage3_ip6_done (NMModemBroadband *self)
{
GError *error = NULL;
NMIP6Config *config = NULL;
const char *data_port;
const gchar *address_string;
NMPlatformIP6Address address;
NMModemIPMethod ip_method;
@ -837,7 +838,9 @@ stage3_ip6_done (NMModemBroadband *self)
nm_log_info (LOGD_MB, "(%s): IPv6 base configuration:",
nm_modem_get_uid (NM_MODEM (self)));
config = nm_ip6_config_new ();
data_port = mm_bearer_get_interface (self->priv->bearer);
g_assert (data_port);
config = nm_ip6_config_new (nm_platform_link_get_ifindex (data_port));
address.plen = mm_bearer_ip_config_get_prefix (self->priv->ipv6_config);
nm_ip6_config_add_address (config, &address);

View file

@ -617,8 +617,7 @@ nm_dhcp_utils_ip6_config_from_options (int ifindex,
iface, (const char *) key, (const char *) value);
}
ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (ip6_config, ifindex);
ip6_config = nm_ip6_config_new (ifindex);
str = g_hash_table_lookup (options, "max_life");
if (str) {

View file

@ -135,8 +135,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da
ifa_flags |= IFA_F_MANAGETEMPADDR;
}
ip6_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (ip6_config, ifindex);
ip6_config = nm_ip6_config_new (ifindex);
if (changed & NM_RDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in router discovery cache. */
@ -231,8 +230,7 @@ rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, gpointer user_da
if (last_config) {
g_object_unref (last_config);
last_config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (last_config, ifindex);
last_config = nm_ip6_config_new (ifindex);
nm_ip6_config_replace (last_config, ip6_config, NULL);
}
}

View file

@ -83,6 +83,7 @@ static GParamSpec *obj_properties[LAST_PROP] = { NULL, };
NMIP4Config *
nm_ip4_config_new (int ifindex)
{
g_return_val_if_fail (ifindex >= -1, NULL);
return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG,
NM_IP4_CONFIG_IFINDEX, ifindex,
NULL);
@ -108,6 +109,12 @@ nm_ip4_config_get_dbus_path (const NMIP4Config *config)
return priv->path;
}
int
nm_ip4_config_get_ifindex (const NMIP4Config *config)
{
return NM_IP4_CONFIG_GET_PRIVATE (config)->ifindex;
}
static gboolean
same_prefix (guint32 address1, guint32 address2, int plen)
{

View file

@ -59,6 +59,8 @@ GType nm_ip4_config_get_type (void);
NMIP4Config * nm_ip4_config_new (int ifindex);
int nm_ip4_config_get_ifindex (const NMIP4Config *config);
/* D-Bus integration */
void nm_ip4_config_export (NMIP4Config *config);
const char * nm_ip4_config_get_dbus_path (const NMIP4Config *config);

View file

@ -56,6 +56,7 @@ typedef struct {
enum {
PROP_0,
PROP_IFINDEX,
PROP_ADDRESS_DATA,
PROP_ADDRESSES,
PROP_ROUTE_DATA,
@ -72,9 +73,12 @@ static GParamSpec *obj_properties[LAST_PROP] = { NULL, };
NMIP6Config *
nm_ip6_config_new (void)
nm_ip6_config_new (int ifindex)
{
return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG, NULL);
g_return_val_if_fail (ifindex >= -1, NULL);
return (NMIP6Config *) g_object_new (NM_TYPE_IP6_CONFIG,
NM_IP6_CONFIG_IFINDEX, ifindex,
NULL);
}
void
@ -97,19 +101,14 @@ nm_ip6_config_get_dbus_path (const NMIP6Config *config)
return priv->path;
}
/******************************************************************/
void
nm_ip6_config_set_ifindex (NMIP6Config *config, int ifindex)
int
nm_ip6_config_get_ifindex (const NMIP6Config *config)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
g_return_if_fail (priv->ifindex == 0);
g_assert (priv->routes->len == 0);
priv->ifindex = ifindex;
return NM_IP6_CONFIG_GET_PRIVATE (config)->ifindex;
}
/******************************************************************/
static gboolean
same_prefix (const struct in6_addr *address1, const struct in6_addr *address2, int plen)
{
@ -314,9 +313,8 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co
if (nm_platform_link_get_master (ifindex) > 0)
return NULL;
config = nm_ip6_config_new ();
config = nm_ip6_config_new (ifindex);
priv = NM_IP6_CONFIG_GET_PRIVATE (config);
nm_ip6_config_set_ifindex (config, ifindex);
g_array_unref (priv->addresses);
g_array_unref (priv->routes);
@ -904,7 +902,7 @@ nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relev
/* ifindex */
if (src_priv->ifindex != dst_priv->ifindex) {
nm_ip6_config_set_ifindex (dst, src_priv->ifindex);
dst_priv->ifindex = src_priv->ifindex;
has_minor_changes = TRUE;
}
@ -1748,6 +1746,9 @@ get_property (GObject *object, guint prop_id,
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
case PROP_IFINDEX:
g_value_set_int (value, priv->ifindex);
break;
case PROP_ADDRESS_DATA:
{
GPtrArray *addresses = g_ptr_array_new ();
@ -1930,6 +1931,24 @@ get_property (GObject *object, guint prop_id,
}
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
case PROP_IFINDEX:
priv->ifindex = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
{
@ -1939,9 +1958,16 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
/* virtual methods */
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->finalize = finalize;
/* properties */
obj_properties[PROP_IFINDEX] =
g_param_spec_int (NM_IP6_CONFIG_IFINDEX, "", "",
-1, G_MAXINT, -1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDRESS_DATA] =
g_param_spec_boxed (NM_IP6_CONFIG_ADDRESS_DATA, "", "",
DBUS_TYPE_NM_IP_ADDRESSES,

View file

@ -42,6 +42,7 @@ typedef struct {
GObjectClass parent;
} NMIP6ConfigClass;
#define NM_IP6_CONFIG_IFINDEX "ifindex"
#define NM_IP6_CONFIG_ADDRESS_DATA "address-data"
#define NM_IP6_CONFIG_ROUTE_DATA "route-data"
#define NM_IP6_CONFIG_GATEWAY "gateway"
@ -56,9 +57,9 @@ typedef struct {
GType nm_ip6_config_get_type (void);
NMIP6Config * nm_ip6_config_new (void);
NMIP6Config * nm_ip6_config_new (int ifindex);
void nm_ip6_config_set_ifindex (NMIP6Config *config, int ifindex);
int nm_ip6_config_get_ifindex (const NMIP6Config *config);
/* D-Bus integration */
void nm_ip6_config_export (NMIP6Config *config);

View file

@ -651,8 +651,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager,
remove_timeout_handler (manager);
config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (config, nm_platform_link_get_ifindex (priv->ip_iface));
config = nm_ip6_config_new (nm_platform_link_get_ifindex (priv->ip_iface));
memset (&addr, 0, sizeof (addr));
addr.plen = 64;

View file

@ -36,8 +36,7 @@ build_test_config (void)
NMIP6Config *config;
/* Build up the config to subtract */
config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (config, 1);
config = nm_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"));
@ -130,10 +129,8 @@ test_compare_with_source (void)
NMPlatformIP6Address addr;
NMPlatformIP6Route route;
a = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (a, 1);
b = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (b, 2);
a = nm_ip6_config_new (1);
b = nm_ip6_config_new (2);
/* Address */
addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64);
@ -165,8 +162,7 @@ test_add_address_with_source (void)
NMPlatformIP6Address addr;
const NMPlatformIP6Address *test_addr;
a = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (a, 1);
a = nm_ip6_config_new (1);
/* Test that a higher priority source is not overwritten */
addr = *nmtst_platform_ip6_address ("1122:3344:5566::7788", NULL, 64);
@ -206,8 +202,7 @@ test_add_route_with_source (void)
NMPlatformIP6Route route;
const NMPlatformIP6Route *test_route;
a = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (a, 1);
a = nm_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");

View file

@ -895,10 +895,8 @@ apply_parent_device_config (NMVpnConnection *connection)
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 ();
nm_ip6_config_set_ifindex (vpn6_parent_config, priv->ip_ifindex);
}
if (priv->ip6_config)
vpn6_parent_config = nm_ip6_config_new (priv->ip_ifindex);
if (priv->ip_ifindex <= 0) {
/* If the VPN didn't return a network interface, it is a route-based
@ -1337,8 +1335,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy,
return;
}
config = nm_ip6_config_new ();
nm_ip6_config_set_ifindex (config, priv->ip_ifindex);
config = nm_ip6_config_new (priv->ip_ifindex);
memset (&address, 0, sizeof (address));
address.plen = 128;