device: add nm_device_set_ip_ifindex()

This commit is contained in:
Beniamino Galvani 2018-01-08 16:31:56 +01:00
parent 1712fae6e8
commit 2507046fea
2 changed files with 55 additions and 0 deletions

View file

@ -45,6 +45,7 @@ enum NMActStageReturn {
NMSettings *nm_device_get_settings (NMDevice *self);
gboolean nm_device_set_ip_ifindex (NMDevice *self, int ifindex);
gboolean nm_device_set_ip_iface (NMDevice *self, const char *iface);
void nm_device_activate_schedule_stage3_ip_config_start (NMDevice *device);

View file

@ -1281,6 +1281,60 @@ nm_device_get_ip_ifindex (const NMDevice *self)
return priv->ip_iface ? priv->ip_ifindex : priv->ifindex;
}
gboolean
nm_device_set_ip_ifindex (NMDevice *self, int ifindex)
{
NMDevicePrivate *priv;
NMPlatform *platform;
const char *name = NULL;
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
priv = NM_DEVICE_GET_PRIVATE (self);
platform = nm_device_get_platform (self);
if (ifindex > 0) {
const NMPlatformLink *plink;
plink = nm_platform_link_get (platform, ifindex);
if (!plink) {
nm_platform_process_events (platform);
plink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
}
if (!plink) {
_LOGW (LOGD_DEVICE, "ip-ifindex: ifindex %d not found", ifindex);
return FALSE;
}
name = plink->name;
}
if (priv->ip_ifindex == ifindex)
return FALSE;
_LOGD (LOGD_DEVICE, "ip-ifindex: update ifindex to %d", ifindex);
priv->ip_ifindex = ifindex;
if (!nm_streq0 (priv->ip_iface, name)) {
_LOGD (LOGD_DEVICE, "ip-ifindex: update ip-iface to %s%s%s",
NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "NULL"));
priv->ip_iface = g_strdup (name);
_notify (self, PROP_IP_IFACE);
}
if (priv->ip_ifindex > 0) {
if (nm_platform_check_kernel_support (nm_device_get_platform (self),
NM_PLATFORM_KERNEL_SUPPORT_USER_IPV6LL))
nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ip_ifindex, TRUE);
if (!nm_platform_link_is_up (nm_device_get_platform (self), priv->ip_ifindex))
nm_platform_link_set_up (nm_device_get_platform (self), priv->ip_ifindex, NULL);
}
/* We don't care about any saved values from the old iface */
g_hash_table_remove_all (priv->ip6_saved_properties);
return TRUE;
}
/**
* nm_device_set_ip_iface:
* @self: the #NMDevice