mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 22:00:13 +01:00
tun: port to internal device factory
This commit is contained in:
parent
11eb99e9a7
commit
3deb3ff683
5 changed files with 36 additions and 38 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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; \
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue