From 388e53b1808ad49809392784899809631f372d4c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 8 Sep 2014 10:57:31 -0500 Subject: veth: port to internal device factory We must port NMDeviceVeth before NMDeviceEthernet because veth is an ethernet subclass and uses symbols from nm-device-ethernet.c. --- src/Makefile.am | 2 +- src/devices/nm-device-veth.c | 36 ++++++++++++++++++++++++------------ src/devices/nm-device-veth.h | 12 ++---------- src/nm-manager.c | 4 ---- src/tests/Makefile.am | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index f0b22d2e29..bc961bb524 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,6 +63,7 @@ NetworkManager_LDADD = libNetworkManager.la noinst_LTLIBRARIES = libNetworkManager.la nm_device_sources = \ + devices/nm-device-veth.c \ $(NULL) nm_device_headers = \ @@ -96,7 +97,6 @@ nm_sources = \ devices/nm-device-macvlan.c \ devices/nm-device-private.h \ devices/nm-device-tun.c \ - devices/nm-device-veth.c \ devices/nm-device-vlan.c \ devices/nm-device-vxlan.c \ \ diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index ce417be504..db29c00d2f 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -33,6 +33,7 @@ #include "nm-manager.h" #include "nm-platform.h" #include "nm-dbus-manager.h" +#include "nm-device-factory.h" #include "nm-device-veth-glue.h" @@ -98,18 +99,6 @@ get_peer (NMDeviceVeth *self) /**************************************************************/ -NMDevice * -nm_device_veth_new (NMPlatformLink *platform_device) -{ - g_return_val_if_fail (platform_device != NULL, NULL); - - return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH, - NM_DEVICE_PLATFORM_DEVICE, platform_device, - NM_DEVICE_TYPE_DESC, "Veth", - NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET, - NULL); -} - static void nm_device_veth_init (NMDeviceVeth *self) { @@ -170,3 +159,26 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_veth_object_info); } + +/*************************************************************/ + +#define NM_TYPE_VETH_FACTORY (nm_veth_factory_get_type ()) +#define NM_VETH_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VETH_FACTORY, NMVethFactory)) + +static NMDevice * +new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error) +{ + if (plink->type == NM_LINK_TYPE_VETH) { + return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VETH, + NM_DEVICE_PLATFORM_DEVICE, plink, + NM_DEVICE_TYPE_DESC, "Veth", + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET, + NULL); + } + return NULL; +} + +DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(VETH, Veth, veth, ETHERNET, \ + factory_iface->new_link = new_link; \ + ) + diff --git a/src/devices/nm-device-veth.h b/src/devices/nm-device-veth.h index 584ec8572c..51e8db45ea 100644 --- a/src/devices/nm-device-veth.h +++ b/src/devices/nm-device-veth.h @@ -36,19 +36,11 @@ G_BEGIN_DECLS #define NM_DEVICE_VETH_PEER "peer" -typedef struct { - NMDeviceEthernet parent; -} NMDeviceVeth; - -typedef struct { - NMDeviceEthernetClass parent; - -} NMDeviceVethClass; +typedef NMDeviceEthernet NMDeviceVeth; +typedef NMDeviceEthernetClass NMDeviceVethClass; GType nm_device_veth_get_type (void); -NMDevice *nm_device_veth_new (NMPlatformLink *platform_device); - G_END_DECLS #endif /* NM_DEVICE_VETH_H */ diff --git a/src/nm-manager.c b/src/nm-manager.c index cf7d2f5a9b..57d60d1891 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -45,7 +45,6 @@ #include "nm-device-bridge.h" #include "nm-device-vlan.h" #include "nm-device-generic.h" -#include "nm-device-veth.h" #include "nm-device-tun.h" #include "nm-device-macvlan.h" #include "nm-device-vxlan.h" @@ -2157,9 +2156,6 @@ platform_link_added (NMManager *self, } else nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", plink->name); break; - case NM_LINK_TYPE_VETH: - device = nm_device_veth_new (plink); - break; case NM_LINK_TYPE_TUN: case NM_LINK_TYPE_TAP: device = nm_device_tun_new (plink); diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 221d3f5704..fe76e402ad 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -99,7 +99,7 @@ TESTS = \ if ENABLE_TESTS check-local: - @for t in ; do \ + @for t in veth; 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 \ -- cgit v1.2.1