libnm-glib: add support for TUN devices
authorBeniamino Galvani <bgalvani@redhat.com>
Tue, 10 Nov 2015 21:03:57 +0000 (22:03 +0100)
committerBeniamino Galvani <bgalvani@redhat.com>
Wed, 25 Nov 2015 10:39:57 +0000 (11:39 +0100)
Since libnm is the preferred way to interact with NM now, we don't
want to add new device types to libnm-glib.

Make libnm-glib recognize TUN devices as generic ones and modify
NMDeviceGeneric to use the correct D-Bus interface based on the actual
device type.

introspection/nm-device-tun.xml
libnm-glib/nm-device-generic.c
libnm-glib/nm-device.c
libnm-util/NetworkManager.h

index 8b0f81f..2b3ae2f 100644 (file)
       </tp:docstring>
     </property>
 
+    <property name="HwAddress" type="s" access="read">
+      <tp:docstring>
+        Hardware address of the device.
+      </tp:docstring>
+    </property>
+
     <signal name="PropertiesChanged">
         <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
             <tp:docstring>
index a17a673..a7b2fa0 100644 (file)
@@ -184,15 +184,41 @@ register_properties (NMDeviceGeneric *device)
                                        property_info);
 }
 
+static const char *
+_device_type_to_interface (NMDeviceType type)
+{
+       switch (type) {
+       case NM_DEVICE_TYPE_GENERIC:
+               return NM_DBUS_INTERFACE_DEVICE_GENERIC;
+       case NM_DEVICE_TYPE_TUN:
+               return NM_DBUS_INTERFACE_DEVICE_TUN;
+       default:
+               return NULL;
+       }
+}
+
 static void
 constructed (GObject *object)
 {
        NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
+       NMDeviceType type;
+       DBusGConnection *connection;
+       const char *path, *interface;
 
        G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object);
 
-       priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_GENERIC);
-       register_properties (NM_DEVICE_GENERIC (object));
+       g_object_get (object,
+                     NM_OBJECT_DBUS_CONNECTION, &connection,
+                     NM_OBJECT_DBUS_PATH, &path,
+                     NULL);
+
+       type = _nm_device_type_for_path (connection, path);
+       interface = _device_type_to_interface (type);
+
+       if (interface) {
+               priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, interface);
+               register_properties (NM_DEVICE_GENERIC (object));
+       }
 }
 
 static void
index 7731183..aac94fb 100644 (file)
@@ -320,6 +320,7 @@ _nm_device_gtype_from_dtype (NMDeviceType dtype)
        case NM_DEVICE_TYPE_VLAN:
                return NM_TYPE_DEVICE_VLAN;
        case NM_DEVICE_TYPE_GENERIC:
+       case NM_DEVICE_TYPE_TUN:
                return NM_TYPE_DEVICE_GENERIC;
        default:
                g_warning ("Unknown device type %d", dtype);
index d83e4ab..71862c4 100644 (file)
@@ -151,6 +151,7 @@ typedef enum {
  * @NM_DEVICE_TYPE_ADSL: ADSL modem
  * @NM_DEVICE_TYPE_BRIDGE: a bridge master interface
  * @NM_DEVICE_TYPE_TEAM: a team master interface
+ * @NM_DEVICE_TYPE_TUN: a TUN/TAP interface
  *
  * #NMDeviceType values indicate the type of hardware represented by
  * an #NMDevice.
@@ -174,6 +175,7 @@ typedef enum {
        NM_DEVICE_TYPE_BRIDGE     = 13,
        NM_DEVICE_TYPE_GENERIC    = 14,
        NM_DEVICE_TYPE_TEAM       = 15,
+       NM_DEVICE_TYPE_TUN        = 16,
 } NMDeviceType;
 
 /**