summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-device-tun.c53
-rw-r--r--src/devices/nm-device-tun.h12
-rw-r--r--src/nm-manager.c5
-rw-r--r--src/tests/Makefile.am2
5 files changed, 36 insertions, 38 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 252d653775..62a4aa55ef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,6 +69,7 @@ nm_device_sources = \
devices/nm-device-gre.c \
devices/nm-device-infiniband.c \
devices/nm-device-macvlan.c \
+ devices/nm-device-tun.c \
devices/nm-device-veth.c \
devices/nm-device-vlan.c \
devices/nm-device-vxlan.c \
@@ -98,7 +99,6 @@ nm_sources = \
devices/nm-device-generic.h \
devices/nm-device-logging.h \
devices/nm-device-private.h \
- devices/nm-device-tun.c \
\
dhcp-manager/nm-dhcp-client.c \
dhcp-manager/nm-dhcp-client.h \
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index 030c2e23bf..81442274a0 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -28,6 +28,7 @@
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-platform.h"
+#include "nm-device-factory.h"
#include "nm-device-tun-glue.h"
@@ -110,27 +111,6 @@ delay_tun_get_properties_cb (gpointer user_data)
/**************************************************************/
-NMDevice *
-nm_device_tun_new (NMPlatformLink *platform_device)
-{
- const char *mode = NULL;
-
- g_return_val_if_fail (platform_device != NULL, NULL);
-
- if (platform_device->type == NM_LINK_TYPE_TUN)
- mode = "tun";
- else if (platform_device->type == NM_LINK_TYPE_TAP)
- mode = "tap";
- g_return_val_if_fail (mode != NULL, NULL);
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN,
- NM_DEVICE_PLATFORM_DEVICE, platform_device,
- NM_DEVICE_TYPE_DESC, "Tun",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
- NM_DEVICE_TUN_MODE, mode,
- NULL);
-}
-
static void
nm_device_tun_init (NMDeviceTun *self)
{
@@ -282,3 +262,34 @@ nm_device_tun_class_init (NMDeviceTunClass *klass)
G_TYPE_FROM_CLASS (klass),
&dbus_glib_nm_device_tun_object_info);
}
+
+
+/*************************************************************/
+
+#define NM_TYPE_TUN_FACTORY (nm_tun_factory_get_type ())
+#define NM_TUN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_TUN_FACTORY, NMTunFactory))
+
+static NMDevice *
+new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
+{
+ const char *mode = NULL;
+
+ if (plink->type == NM_LINK_TYPE_TUN)
+ mode = "tun";
+ else if (plink->type == NM_LINK_TYPE_TAP)
+ mode = "tap";
+ else
+ return NULL;
+
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "Tun",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
+ NM_DEVICE_TUN_MODE, mode,
+ NULL);
+}
+
+DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(TUN, Tun, tun, GENERIC, \
+ factory_iface->new_link = new_link; \
+ )
+
diff --git a/src/devices/nm-device-tun.h b/src/devices/nm-device-tun.h
index 0ff1db1eca..393c58018f 100644
--- a/src/devices/nm-device-tun.h
+++ b/src/devices/nm-device-tun.h
@@ -41,19 +41,11 @@ G_BEGIN_DECLS
#define NM_DEVICE_TUN_VNET_HDR "vnet-hdr"
#define NM_DEVICE_TUN_MULTI_QUEUE "multi-queue"
-typedef struct {
- NMDeviceGeneric parent;
-} NMDeviceTun;
-
-typedef struct {
- NMDeviceGenericClass parent;
-
-} NMDeviceTunClass;
+typedef NMDeviceGeneric NMDeviceTun;
+typedef NMDeviceGenericClass NMDeviceTunClass;
GType nm_device_tun_get_type (void);
-NMDevice *nm_device_tun_new (NMPlatformLink *platform_device);
-
G_END_DECLS
#endif /* NM_DEVICE_TUN_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index f608e5e1e3..cf0849b5d8 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -40,7 +40,6 @@
#include "nm-vpn-manager.h"
#include "nm-device.h"
#include "nm-device-generic.h"
-#include "nm-device-tun.h"
#include "nm-setting-connection.h"
#include "nm-setting-wireless.h"
#include "nm-setting-vpn.h"
@@ -2106,10 +2105,6 @@ platform_link_added (NMManager *self,
if (device == NULL) {
switch (plink->type) {
- case NM_LINK_TYPE_TUN:
- case NM_LINK_TYPE_TAP:
- device = nm_device_tun_new (plink);
- break;
case NM_LINK_TYPE_WWAN_ETHERNET:
/* WWAN pseudo-ethernet interfaces are handled automatically by
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 4bea114786..07bdee5bcc 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -99,7 +99,7 @@ TESTS = \
if ENABLE_TESTS
check-local:
- @for t in bond bridge ethernet gre infiniband macvlan veth vlan vxlan; do \
+ @for t in bond bridge ethernet gre infiniband macvlan tun veth vlan vxlan; do \
# Ensure the device subclass factory registration constructors exist \
# which could inadvertently break if src/Makefile.am gets changed \
if ! LC_ALL=C nm $(top_builddir)/src/NetworkManager | LC_ALL=C grep -q "register_device_factory_internal_$$t" ; then \