diff options
author | Dan Winship <danw@gnome.org> | 2013-04-25 15:46:39 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2013-06-04 10:01:13 -0300 |
commit | add316a40377be0a5f688518ae29170aae1304a7 (patch) | |
tree | 4848106dafe6b95bdec4b5c3076f6d11667d0f2a | |
parent | 329960bc1880c95b41b6d2c04293053b0e883f47 (diff) | |
download | NetworkManager-add316a40377be0a5f688518ae29170aae1304a7.tar.gz |
platform, devices: add support for tun and tap devices
-rw-r--r-- | include/NetworkManager.h | 1 | ||||
-rw-r--r-- | introspection/Makefile.am | 1 | ||||
-rw-r--r-- | introspection/nm-device-tun.xml | 55 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/devices/nm-device-tun.c | 217 | ||||
-rw-r--r-- | src/devices/nm-device-tun.h | 61 | ||||
-rw-r--r-- | src/devices/nm-device.c | 23 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 | ||||
-rw-r--r-- | src/nm-manager.c | 5 | ||||
-rw-r--r-- | src/platform/nm-fake-platform.c | 7 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 54 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 11 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 13 | ||||
-rw-r--r-- | src/platform/tests/platform.c | 31 |
14 files changed, 472 insertions, 12 deletions
diff --git a/include/NetworkManager.h b/include/NetworkManager.h index 670a6c9b92..0c91022175 100644 --- a/include/NetworkManager.h +++ b/include/NetworkManager.h @@ -55,6 +55,7 @@ #define NM_DBUS_INTERFACE_DEVICE_BRIDGE NM_DBUS_INTERFACE_DEVICE ".Bridge" #define NM_DBUS_INTERFACE_DEVICE_GENERIC NM_DBUS_INTERFACE_DEVICE ".Generic" #define NM_DBUS_INTERFACE_DEVICE_VETH NM_DBUS_INTERFACE_DEVICE ".Veth" +#define NM_DBUS_INTERFACE_DEVICE_TUN NM_DBUS_INTERFACE_DEVICE ".Tun" #define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager.Settings" diff --git a/introspection/Makefile.am b/introspection/Makefile.am index 44804c95c4..68f6965c28 100644 --- a/introspection/Makefile.am +++ b/introspection/Makefile.am @@ -17,6 +17,7 @@ EXTRA_DIST = \ nm-device-vlan.xml \ nm-device-generic.xml \ nm-device-veth.xml \ + nm-device-tun.xml \ nm-device.xml \ nm-ip4-config.xml \ nm-ip6-config.xml \ diff --git a/introspection/nm-device-tun.xml b/introspection/nm-device-tun.xml new file mode 100644 index 0000000000..8b0f81fbc6 --- /dev/null +++ b/introspection/nm-device-tun.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="org.freedesktop.NetworkManager.Device.Tun"> + + <property name="Owner" type="x" access="read"> + <tp:docstring> + The uid of the tunnel owner, or -1 if it has no owner. + </tp:docstring> + </property> + + <property name="Group" type="x" access="read"> + <tp:docstring> + The gid of the tunnel group, or -1 if it has no owner. + </tp:docstring> + </property> + + <property name="Mode" type="s" access="read"> + <tp:docstring> + The tunnel mode, either "tun" or "tap". + </tp:docstring> + </property> + + <property name="NoPi" type="b" access="read"> + <tp:docstring> + The tunnel's "TUN_NO_PI" flag; true if no protocol info is + prepended to the tunnel packets. + </tp:docstring> + </property> + + <property name="VnetHdr" type="b" access="read"> + <tp:docstring> + The tunnel's "TUN_VNET_HDR" flag; true if the tunnel packets + include a virtio network header. + </tp:docstring> + </property> + + <property name="MultiQueue" type="b" access="read"> + <tp:docstring> + The tunnel's "TUN_TAP_MQ" flag; true if callers can connect to + the tap device multiple times, for multiple send/receive + queues. + </tp:docstring> + </property> + + <signal name="PropertiesChanged"> + <arg name="properties" type="a{sv}" tp:type="String_Variant_Map"> + <tp:docstring> + A dictionary mapping property names to variant boxed values + </tp:docstring> + </arg> + </signal> + + </interface> +</node> diff --git a/src/Makefile.am b/src/Makefile.am index 0b071fa011..c67b79456d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -83,6 +83,8 @@ nm_sources = \ devices/nm-device-olpc-mesh.c \ devices/nm-device-olpc-mesh.h \ devices/nm-device-private.h \ + devices/nm-device-tun.c \ + devices/nm-device-tun.h \ devices/nm-device-veth.c \ devices/nm-device-veth.h \ devices/nm-device-vlan.c \ @@ -313,6 +315,7 @@ glue_sources = \ nm-device-infiniband-glue.h \ nm-device-modem-glue.h \ nm-device-olpc-mesh-glue.h \ + nm-device-tun-glue.h \ nm-device-veth-glue.h \ nm-device-vlan-glue.h \ nm-device-wifi-glue.h \ diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c new file mode 100644 index 0000000000..1a31fdcd5e --- /dev/null +++ b/src/devices/nm-device-tun.c @@ -0,0 +1,217 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2013 Red Hat, Inc. + */ + +#include "config.h" + +#include <stdlib.h> +#include <string.h> + +#include "nm-device-tun.h" +#include "nm-dbus-manager.h" +#include "nm-logging.h" +#include "nm-platform.h" + +#include "nm-device-tun-glue.h" + +G_DEFINE_TYPE (NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE_GENERIC) + +#define NM_DEVICE_TUN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TUN, NMDeviceTunPrivate)) + +typedef struct { + NMPlatformTunProperties props; +} NMDeviceTunPrivate; + +enum { + PROP_0, + PROP_OWNER, + PROP_GROUP, + PROP_FLAGS, + PROP_MODE, + PROP_NO_PI, + PROP_VNET_HDR, + PROP_MULTI_QUEUE, + + LAST_PROP +}; + +static void +link_changed (NMDevice *device) +{ + NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (device); + GObject *object = G_OBJECT (device); + NMPlatformTunProperties props; + + if (!nm_platform_tun_get_properties (nm_device_get_ifindex (device), &props)) { + nm_log_warn (LOGD_HW, "(%s): could not read tun properties", + nm_device_get_iface (device)); + return; + } + + g_object_freeze_notify (object); + + if (priv->props.owner != props.owner) + g_object_notify (object, NM_DEVICE_TUN_OWNER); + if (priv->props.group != props.group) + g_object_notify (object, NM_DEVICE_TUN_GROUP); + if (g_strcmp0 (priv->props.mode, props.mode) != 0) + g_object_notify (object, NM_DEVICE_TUN_MODE); + if (priv->props.no_pi != props.no_pi) + g_object_notify (object, NM_DEVICE_TUN_NO_PI); + if (priv->props.vnet_hdr != props.vnet_hdr) + g_object_notify (object, NM_DEVICE_TUN_VNET_HDR); + if (priv->props.multi_queue != props.multi_queue) + g_object_notify (object, NM_DEVICE_TUN_MULTI_QUEUE); + + memcpy (&priv->props, &props, sizeof (NMPlatformTunProperties)); + + g_object_thaw_notify (object); +} + +/**************************************************************/ + +NMDevice * +nm_device_tun_new (const char *udi, + const char *iface, + const char *driver) +{ + g_return_val_if_fail (udi != NULL, NULL); + + return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TUN, + NM_DEVICE_UDI, udi, + NM_DEVICE_IFACE, iface, + NM_DEVICE_DRIVER, driver, + NM_DEVICE_TYPE_DESC, "Tun", + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC, + NULL); +} + +static void +nm_device_tun_init (NMDeviceTun *self) +{ +} + +static void +constructed (GObject *object) +{ + NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (object); + + nm_platform_tun_get_properties (nm_device_get_ifindex (NM_DEVICE (object)), &priv->props); + + G_OBJECT_CLASS (nm_device_tun_parent_class)->constructed (object); +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMDeviceTun *self = NM_DEVICE_TUN (object); + NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (self); + + switch (prop_id) { + case PROP_OWNER: + g_value_set_uint (value, priv->props.owner); + break; + case PROP_GROUP: + g_value_set_uint (value, priv->props.group); + break; + case PROP_MODE: + g_value_set_string (value, priv->props.mode); + break; + case PROP_NO_PI: + g_value_set_boolean (value, priv->props.no_pi); + break; + case PROP_VNET_HDR: + g_value_set_boolean (value, priv->props.vnet_hdr); + break; + case PROP_MULTI_QUEUE: + g_value_set_boolean (value, priv->props.multi_queue); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_device_tun_class_init (NMDeviceTunClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); + + g_type_class_add_private (klass, sizeof (NMDeviceTunPrivate)); + + object_class->constructed = constructed; + object_class->get_property = get_property; + + device_class->link_changed = link_changed; + + /* properties */ + g_object_class_install_property + (object_class, PROP_OWNER, + g_param_spec_int64 (NM_DEVICE_TUN_OWNER, + "Owner", + "Owner", + -1, G_MAXUINT32, -1, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_GROUP, + g_param_spec_int64 (NM_DEVICE_TUN_GROUP, + "Group", + "Group", + -1, G_MAXUINT32, -1, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_MODE, + g_param_spec_string (NM_DEVICE_TUN_MODE, + "Mode", + "Mode", + "tun", + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_NO_PI, + g_param_spec_boolean (NM_DEVICE_TUN_NO_PI, + "No Protocol Info", + "No Protocol Info", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_VNET_HDR, + g_param_spec_boolean (NM_DEVICE_TUN_VNET_HDR, + "Virtio networking header", + "Virtio networking header", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property + (object_class, PROP_MULTI_QUEUE, + g_param_spec_boolean (NM_DEVICE_TUN_MULTI_QUEUE, + "Multi-queue", + "Multi-queue", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), + G_TYPE_FROM_CLASS (klass), + &dbus_glib_nm_device_tun_object_info); +} diff --git a/src/devices/nm-device-tun.h b/src/devices/nm-device-tun.h new file mode 100644 index 0000000000..336a9792ef --- /dev/null +++ b/src/devices/nm-device-tun.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2013 Red Hat, Inc. + */ + +#ifndef NM_DEVICE_TUN_H +#define NM_DEVICE_TUN_H + +#include <glib-object.h> + +#include "nm-device-generic.h" + +G_BEGIN_DECLS + +#define NM_TYPE_DEVICE_TUN (nm_device_tun_get_type ()) +#define NM_DEVICE_TUN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_TUN, NMDeviceTun)) +#define NM_DEVICE_TUN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_TUN, NMDeviceTunClass)) +#define NM_IS_DEVICE_TUN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_TUN)) +#define NM_IS_DEVICE_TUN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_TUN)) +#define NM_DEVICE_TUN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_TUN, NMDeviceTunClass)) + +#define NM_DEVICE_TUN_OWNER "owner" +#define NM_DEVICE_TUN_GROUP "group" +#define NM_DEVICE_TUN_MODE "mode" +#define NM_DEVICE_TUN_NO_PI "no-pi" +#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; + +GType nm_device_tun_get_type (void); + +NMDevice *nm_device_tun_new (const char *udi, + const char *iface, + const char *driver); + +G_END_DECLS + +#endif /* NM_DEVICE_TUN_H */ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 2b455c1f7e..5c63da404a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -213,7 +213,6 @@ typedef struct { guint carrier_defer_id; gboolean carrier; gboolean ignore_carrier; - guint link_changed_id; /* Generic DHCP stuff */ NMDHCPManager * dhcp_manager; @@ -366,6 +365,9 @@ nm_device_init (NMDevice *self) g_signal_connect (platform, platform_ip_signals[i], G_CALLBACK (device_ip_changed), self); } + + g_signal_connect (platform, NM_PLATFORM_LINK_CHANGED, + G_CALLBACK (link_changed_cb), self); } static void @@ -556,13 +558,6 @@ constructed (GObject *object) nm_device_get_iface (NM_DEVICE (dev)), priv->carrier ? "ON" : "OFF", priv->ignore_carrier ? " (but ignored)" : ""); - - if (!device_has_capability (dev, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) { - NMPlatform *platform = nm_platform_get (); - - priv->link_changed_id = g_signal_connect (platform, "link-changed", - G_CALLBACK (link_changed_cb), dev); - } } else { /* Fake online link when carrier detection is not available. */ priv->carrier = TRUE; @@ -1094,8 +1089,15 @@ nm_device_set_carrier (NMDevice *device, gboolean carrier) static void link_changed_cb (NMPlatform *platform, int ifindex, NMPlatformLink *info, NMDevice *device) { - if (ifindex == nm_device_get_ifindex (device)) + if (ifindex != nm_device_get_ifindex (device)) + return; + + if ( device_has_capability (device, NM_DEVICE_CAP_CARRIER_DETECT) + && !device_has_capability (device, NM_DEVICE_CAP_NONSTANDARD_CARRIER)) nm_device_set_carrier (device, info->connected); + + if (NM_DEVICE_GET_CLASS (device)->link_changed) + NM_DEVICE_GET_CLASS (device)->link_changed (device); } static void @@ -4628,8 +4630,6 @@ dispose (GObject *object) } g_free (priv->ip6_privacy_tempaddr_path); - if (priv->link_changed_id) - g_signal_handler_disconnect (nm_platform_get (), priv->link_changed_id); if (priv->carrier_defer_id) { g_source_remove (priv->carrier_defer_id); priv->carrier_defer_id = 0; @@ -4664,6 +4664,7 @@ dispose (GObject *object) platform = nm_platform_get (); g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (device_ip_changed), self); + g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (link_changed_cb), self); out: G_OBJECT_CLASS (nm_device_parent_class)->dispose (object); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index bd0dfbc53f..fd9b79379d 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -192,6 +192,8 @@ typedef struct { gboolean (* have_any_ready_slaves) (NMDevice *self, const GSList *slaves); + + void (* link_changed) (NMDevice *self); } NMDeviceClass; diff --git a/src/nm-manager.c b/src/nm-manager.c index 21a20945c0..f5b4df6c14 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -53,6 +53,7 @@ #include "nm-device-adsl.h" #include "nm-device-generic.h" #include "nm-device-veth.h" +#include "nm-device-tun.h" #include "nm-system.h" #include "nm-setting-bluetooth.h" #include "nm-setting-connection.h" @@ -2292,6 +2293,10 @@ udev_device_added_cb (NMUdevManager *udev_mgr, case NM_LINK_TYPE_VETH: device = nm_device_veth_new (sysfs_path, iface, driver); break; + case NM_LINK_TYPE_TUN: + case NM_LINK_TYPE_TAP: + device = nm_device_tun_new (sysfs_path, iface, driver); + break; default: device = nm_device_generic_new (sysfs_path, iface, driver); diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index bbf68ce21c..796715d60d 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -564,6 +564,12 @@ veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties return FALSE; } +static gboolean +tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *props) +{ + return FALSE; +} + /******************************************************************/ static GArray * @@ -1022,6 +1028,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass) platform_class->vlan_set_egress_map = vlan_set_egress_map; platform_class->veth_get_properties = veth_get_properties; + platform_class->tun_get_properties = tun_get_properties; platform_class->ip4_address_get_all = ip4_address_get_all; platform_class->ip6_address_get_all = ip6_address_get_all; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index e7aab0b427..0738e9f842 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -26,6 +26,7 @@ #include <netinet/icmp6.h> #include <netinet/in.h> #include <linux/if_arp.h> +#include <linux/if_tun.h> #include <sys/ioctl.h> #include <linux/sockios.h> #include <linux/ethtool.h> @@ -271,6 +272,10 @@ type_to_string (NMLinkType type) return "dummy"; case NM_LINK_TYPE_IFB: return "ifb"; + case NM_LINK_TYPE_TAP: + return "tap"; + case NM_LINK_TYPE_TUN: + return "tun"; case NM_LINK_TYPE_VETH: return "veth"; case NM_LINK_TYPE_VLAN: @@ -328,7 +333,15 @@ link_extract_type (struct rtnl_link *rtnllink, const char **out_name) return_type (NM_LINK_TYPE_DUMMY, "dummy"); else if (!strcmp (type, "ifb")) return_type (NM_LINK_TYPE_IFB, "ifb"); - else if (!strcmp (type, "veth")) + else if (!strcmp (type, "tun")) { + NMPlatformTunProperties props; + + if ( nm_platform_tun_get_properties (rtnl_link_get_ifindex (rtnllink), &props) + && !strcmp (props.mode, "tap")) + return_type (NM_LINK_TYPE_TAP, "tap"); + else + return_type (NM_LINK_TYPE_TUN, "tun"); + } else if (!strcmp (type, "veth")) return_type (NM_LINK_TYPE_VETH, "veth"); else if (!strcmp (type, "vlan")) return_type (NM_LINK_TYPE_VLAN, "vlan"); @@ -1437,6 +1450,44 @@ veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties return TRUE; } +static gboolean +tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *props) +{ + const char *ifname; + char *path, *val; + guint32 flags; + + ifname = nm_platform_link_get_name (ifindex); + if (!ifname) + return FALSE; + + path = g_strdup_printf ("/sys/class/net/%s/owner", ifname); + val = nm_platform_sysctl_get (path); + g_free (path); + if (!val) + return FALSE; + props->owner = strtoll (val, NULL, 10); + g_free (val); + + path = g_strdup_printf ("/sys/class/net/%s/group", ifname); + val = nm_platform_sysctl_get (path); + g_free (path); + props->group = strtoll (val, NULL, 10); + g_free (val); + + path = g_strdup_printf ("/sys/class/net/%s/tun_flags", ifname); + val = nm_platform_sysctl_get (path); + g_free (path); + flags = strtoul (val, NULL, 16); + props->mode = ((flags & TUN_TYPE_MASK) == TUN_TUN_DEV) ? "tun" : "tap"; + props->no_pi = !!(flags & IFF_NO_PI); + props->vnet_hdr = !!(flags & IFF_VNET_HDR); + props->multi_queue = !!(flags & IFF_MULTI_QUEUE); + g_free (val); + + return TRUE; +} + /******************************************************************/ static int @@ -1920,6 +1971,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->vlan_set_egress_map = vlan_set_egress_map; platform_class->veth_get_properties = veth_get_properties; + platform_class->tun_get_properties = tun_get_properties; platform_class->ip4_address_get_all = ip4_address_get_all; platform_class->ip6_address_get_all = ip6_address_get_all; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 30ff000ab9..b93b115f3e 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -912,6 +912,17 @@ nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *props) return klass->veth_get_properties (platform, ifindex, props); } +gboolean +nm_platform_tun_get_properties (int ifindex, NMPlatformTunProperties *props) +{ + reset_error (); + + g_return_val_if_fail (ifindex > 0, FALSE); + g_return_val_if_fail (props != NULL, FALSE); + + return klass->tun_get_properties (platform, ifindex, props); +} + /******************************************************************/ GArray * diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 9df436d35a..0866f3cdc6 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -59,6 +59,8 @@ typedef enum { NM_LINK_TYPE_DUMMY, NM_LINK_TYPE_IFB, NM_LINK_TYPE_LOOPBACK, + NM_LINK_TYPE_TAP, + NM_LINK_TYPE_TUN, NM_LINK_TYPE_VETH, NM_LINK_TYPE_VLAN, @@ -115,6 +117,15 @@ typedef struct { int peer; } NMPlatformVethProperties; +typedef struct { + gint64 owner; + gint64 group; + const char *mode; + gboolean no_pi; + gboolean vnet_hdr; + gboolean multi_queue; +} NMPlatformTunProperties; + /******************************************************************/ /* NMPlatform abstract class and its implementations provide a layer between @@ -197,6 +208,7 @@ typedef struct { gboolean (*vlan_set_egress_map) (NMPlatform *, int ifindex, int from, int to); gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties); + gboolean (*tun_get_properties) (NMPlatform *, int ifindex, NMPlatformTunProperties *properties); GArray * (*ip4_address_get_all) (NMPlatform *, int ifindex); GArray * (*ip6_address_get_all) (NMPlatform *, int ifindex); @@ -306,6 +318,7 @@ gboolean nm_platform_vlan_set_ingress_map (int ifindex, int from, int to); gboolean nm_platform_vlan_set_egress_map (int ifindex, int from, int to); gboolean nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *properties); +gboolean nm_platform_tun_get_properties (int ifindex, NMPlatformTunProperties *properties); GArray *nm_platform_ip4_address_get_all (int ifindex); GArray *nm_platform_ip6_address_get_all (int ifindex); diff --git a/src/platform/tests/platform.c b/src/platform/tests/platform.c index a4bf4d43ec..b62c768818 100644 --- a/src/platform/tests/platform.c +++ b/src/platform/tests/platform.c @@ -352,6 +352,35 @@ do_veth_get_properties (char **argv) return FALSE; printf ("peer: %d\n", props.peer); + + return TRUE; +} + +static gboolean +do_tun_get_properties (char **argv) +{ + int ifindex = parse_ifindex (*argv++); + NMPlatformTunProperties props; + + if (!nm_platform_tun_get_properties (ifindex, &props)) + return FALSE; + + printf ("mode: %s\n", props.mode); + if (props.owner == -1) + printf ("owner: none\n"); + else + printf ("owner: %lu\n", (gulong) props.owner); + if (props.group == -1) + printf ("group: none\n"); + else + printf ("group: %lu\n", (gulong) props.group); + printf ("no-pi: "); + print_boolean (props.no_pi); + printf ("vnet-hdr: "); + print_boolean (props.vnet_hdr); + printf ("multi-queue: "); + print_boolean (props.multi_queue); + return TRUE; } @@ -641,6 +670,8 @@ static const command_t commands[] = { "<ifname/ifindex> <from> <to>" }, { "veth-get-properties", "get veth properties", do_veth_get_properties, 1, "<ifname/ifindex>" }, + { "tun-get-properties", "get tun/tap properties", do_tun_get_properties, 1, + "<ifname/ifindex>" }, { "ip4-address-get-all", "print all IPv4 addresses", do_ip4_address_get_all, 1, "<ifname/ifindex>" }, { "ip6-address-get-all", "print all IPv6 addresses", do_ip6_address_get_all, 1, "<ifname/ifindex>" }, { "ip4-address-add", "add IPv4 address", do_ip4_address_add, 2, "<ifname/ifindex> <address>/<plen>" }, |