Commit 763f2f1d authored by Dan Williams's avatar Dan Williams

core: expose device's IP interface when activated

Lets apps find out what the actual kernel interface name is for the
device so they can do fun stuff with it.
parent 69f25ca5
......@@ -9,7 +9,15 @@
</property>
<property name="Interface" type="s" access="read">
<tp:docstring>
The network interface offered by the device.
The name of the device's control (and often data) interface.
</tp:docstring>
</property>
<property name="IpInterface" type="s" access="read">
<tp:docstring>
The name of the device's data interface when available. This property
may not refer to the actual data interface until the device has
successfully established a data connection, indicated by the device's
State becoming ACTIVATED.
</tp:docstring>
</property>
<property name="Driver" type="s" access="read">
......
......@@ -1448,8 +1448,6 @@ real_deactivate_quickly (NMDevice *device)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
nm_device_set_ip_iface (device, NULL);
if (priv->pending_ip4_config) {
g_object_unref (priv->pending_ip4_config);
priv->pending_ip4_config = NULL;
......
......@@ -90,7 +90,15 @@ nm_device_interface_init (gpointer g_iface)
"Interface",
"Interface",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_string (NM_DEVICE_INTERFACE_IP_IFACE,
"IP Interface",
"IP Interface",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
......
......@@ -49,6 +49,7 @@ typedef enum
#define NM_DEVICE_INTERFACE_UDI "udi"
#define NM_DEVICE_INTERFACE_IFACE "interface"
#define NM_DEVICE_INTERFACE_IP_IFACE "ip-interface"
#define NM_DEVICE_INTERFACE_DRIVER "driver"
#define NM_DEVICE_INTERFACE_CAPABILITIES "capabilities"
#define NM_DEVICE_INTERFACE_IP4_ADDRESS "ip4-address"
......@@ -69,6 +70,7 @@ typedef enum {
NM_DEVICE_INTERFACE_PROP_UDI = NM_DEVICE_INTERFACE_PROP_FIRST,
NM_DEVICE_INTERFACE_PROP_IFACE,
NM_DEVICE_INTERFACE_PROP_IP_IFACE,
NM_DEVICE_INTERFACE_PROP_DRIVER,
NM_DEVICE_INTERFACE_PROP_CAPABILITIES,
NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS,
......
......@@ -388,11 +388,12 @@ void
nm_device_set_ip_iface (NMDevice *self, const char *iface)
{
NMDevicePrivate *priv;
char *old_ip_iface;
g_return_if_fail (NM_IS_DEVICE (self));
priv = NM_DEVICE_GET_PRIVATE (self);
g_free (priv->ip_iface);
old_ip_iface = priv->ip_iface;
priv->ip_ifindex = 0;
priv->ip_iface = g_strdup (iface);
......@@ -402,6 +403,11 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface)
nm_log_warn (LOGD_HW, "(%s): failed to look up interface index", iface);
}
}
/* Emit change notification */
if (g_strcmp0 (old_ip_iface, priv->ip_iface))
g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_IP_IFACE);
g_free (old_ip_iface);
}
......@@ -2746,6 +2752,8 @@ nm_device_deactivate_quickly (NMDevice *self)
dnsmasq_cleanup (self);
aipd_cleanup (self);
nm_device_set_ip_iface (self, NULL);
/* Turn off router advertisements until they are needed */
if (priv->ip6_accept_ra_path)
nm_utils_do_sysctl (priv->ip6_accept_ra_path, "0\n");
......@@ -3387,6 +3395,8 @@ set_property (GObject *object, guint prop_id,
}
}
break;
case NM_DEVICE_INTERFACE_PROP_IP_IFACE:
break;
case NM_DEVICE_INTERFACE_PROP_DRIVER:
priv->driver = g_strdup (g_value_get_string (value));
break;
......@@ -3436,6 +3446,12 @@ get_property (GObject *object, guint prop_id,
case NM_DEVICE_INTERFACE_PROP_IFACE:
g_value_set_string (value, priv->iface);
break;
case NM_DEVICE_INTERFACE_PROP_IP_IFACE:
if ((state == NM_DEVICE_STATE_ACTIVATED) || (state == NM_DEVICE_STATE_IP_CONFIG))
g_value_set_string (value, nm_device_get_ip_iface (self));
else
g_value_set_string (value, NULL);
break;
case NM_DEVICE_INTERFACE_PROP_IFINDEX:
g_value_set_int (value, priv->ifindex);
break;
......@@ -3540,6 +3556,10 @@ nm_device_class_init (NMDeviceClass *klass)
NM_DEVICE_INTERFACE_PROP_IFACE,
NM_DEVICE_INTERFACE_IFACE);
g_object_class_override_property (object_class,
NM_DEVICE_INTERFACE_PROP_IP_IFACE,
NM_DEVICE_INTERFACE_IP_IFACE);
g_object_class_override_property (object_class,
NM_DEVICE_INTERFACE_PROP_IFINDEX,
NM_DEVICE_INTERFACE_IFINDEX);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment