platform: move nm_platform_tun_get_properties() to NMPlatform base class
This function only accesses sysctl function to retrieve the tun-properties. sysctl is already defined in the base class and equally inherited by linux and fake platform. Move the implementation there.
This commit is contained in:
@@ -714,12 +714,6 @@ veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *props)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProperties *props)
|
macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProperties *props)
|
||||||
{
|
{
|
||||||
@@ -1470,7 +1464,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
|||||||
platform_class->infiniband_get_info = infiniband_get_info;
|
platform_class->infiniband_get_info = infiniband_get_info;
|
||||||
|
|
||||||
platform_class->veth_get_properties = veth_get_properties;
|
platform_class->veth_get_properties = veth_get_properties;
|
||||||
platform_class->tun_get_properties = tun_get_properties;
|
|
||||||
platform_class->macvlan_get_properties = macvlan_get_properties;
|
platform_class->macvlan_get_properties = macvlan_get_properties;
|
||||||
platform_class->vxlan_get_properties = vxlan_get_properties;
|
platform_class->vxlan_get_properties = vxlan_get_properties;
|
||||||
platform_class->gre_get_properties = gre_get_properties;
|
platform_class->gre_get_properties = gre_get_properties;
|
||||||
|
@@ -119,7 +119,6 @@ typedef enum {
|
|||||||
DELAYED_ACTION_TYPE_MAX = __DELAYED_ACTION_TYPE_MAX -1,
|
DELAYED_ACTION_TYPE_MAX = __DELAYED_ACTION_TYPE_MAX -1,
|
||||||
} DelayedActionType;
|
} DelayedActionType;
|
||||||
|
|
||||||
static gboolean tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props);
|
|
||||||
static void delayed_action_schedule (NMPlatform *platform, DelayedActionType action_type, gpointer user_data);
|
static void delayed_action_schedule (NMPlatform *platform, DelayedActionType action_type, gpointer user_data);
|
||||||
static gboolean delayed_action_handle_all (NMPlatform *platform, gboolean read_netlink);
|
static gboolean delayed_action_handle_all (NMPlatform *platform, gboolean read_netlink);
|
||||||
static void do_request_link (NMPlatform *platform, int ifindex, const char *name, gboolean handle_delayed_action);
|
static void do_request_link (NMPlatform *platform, int ifindex, const char *name, gboolean handle_delayed_action);
|
||||||
@@ -916,7 +915,7 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, gboolean *c
|
|||||||
NMPlatformTunProperties props;
|
NMPlatformTunProperties props;
|
||||||
guint flags;
|
guint flags;
|
||||||
|
|
||||||
if (tun_get_properties_ifname (platform, rtnl_link_get_name (rtnllink), &props)) {
|
if (nm_platform_tun_get_properties_ifname (platform, rtnl_link_get_name (rtnllink), &props)) {
|
||||||
if (!g_strcmp0 (props.mode, "tap"))
|
if (!g_strcmp0 (props.mode, "tap"))
|
||||||
return NM_LINK_TYPE_TAP;
|
return NM_LINK_TYPE_TAP;
|
||||||
if (!g_strcmp0 (props.mode, "tun"))
|
if (!g_strcmp0 (props.mode, "tun"))
|
||||||
@@ -3546,76 +3545,6 @@ veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties
|
|||||||
|
|
||||||
/******************************************************************/
|
/******************************************************************/
|
||||||
|
|
||||||
static gboolean
|
|
||||||
tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props)
|
|
||||||
{
|
|
||||||
char *path, *val;
|
|
||||||
gboolean success = TRUE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (props, FALSE);
|
|
||||||
|
|
||||||
memset (props, 0, sizeof (*props));
|
|
||||||
props->owner = -1;
|
|
||||||
props->group = -1;
|
|
||||||
|
|
||||||
if (!ifname || !nm_utils_iface_valid_name (ifname))
|
|
||||||
return FALSE;
|
|
||||||
ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
|
|
||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/owner", ifname);
|
|
||||||
val = nm_platform_sysctl_get (platform, path);
|
|
||||||
g_free (path);
|
|
||||||
if (val) {
|
|
||||||
props->owner = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
|
||||||
if (errno)
|
|
||||||
success = FALSE;
|
|
||||||
g_free (val);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/group", ifname);
|
|
||||||
val = nm_platform_sysctl_get (platform, path);
|
|
||||||
g_free (path);
|
|
||||||
if (val) {
|
|
||||||
props->group = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
|
||||||
if (errno)
|
|
||||||
success = FALSE;
|
|
||||||
g_free (val);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/tun_flags", ifname);
|
|
||||||
val = nm_platform_sysctl_get (platform, path);
|
|
||||||
g_free (path);
|
|
||||||
if (val) {
|
|
||||||
gint64 flags;
|
|
||||||
|
|
||||||
flags = _nm_utils_ascii_str_to_int64 (val, 16, 0, G_MAXINT64, 0);
|
|
||||||
if (!errno) {
|
|
||||||
#ifndef IFF_MULTI_QUEUE
|
|
||||||
const int IFF_MULTI_QUEUE = 0x0100;
|
|
||||||
#endif
|
|
||||||
props->mode = ((flags & (IFF_TUN | IFF_TAP)) == IFF_TUN) ? "tun" : "tap";
|
|
||||||
props->no_pi = !!(flags & IFF_NO_PI);
|
|
||||||
props->vnet_hdr = !!(flags & IFF_VNET_HDR);
|
|
||||||
props->multi_queue = !!(flags & IFF_MULTI_QUEUE);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
g_free (val);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *props)
|
|
||||||
{
|
|
||||||
return tun_get_properties_ifname (platform, nm_platform_link_get_name (platform, ifindex), props);
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************/
|
|
||||||
|
|
||||||
static const struct nla_policy macvlan_info_policy[IFLA_MACVLAN_MAX + 1] = {
|
static const struct nla_policy macvlan_info_policy[IFLA_MACVLAN_MAX + 1] = {
|
||||||
[IFLA_MACVLAN_MODE] = { .type = NLA_U32 },
|
[IFLA_MACVLAN_MODE] = { .type = NLA_U32 },
|
||||||
#ifdef MACVLAN_FLAG_NOPROMISC
|
#ifdef MACVLAN_FLAG_NOPROMISC
|
||||||
@@ -5120,7 +5049,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
|||||||
platform_class->infiniband_get_info = infiniband_get_info;
|
platform_class->infiniband_get_info = infiniband_get_info;
|
||||||
|
|
||||||
platform_class->veth_get_properties = veth_get_properties;
|
platform_class->veth_get_properties = veth_get_properties;
|
||||||
platform_class->tun_get_properties = tun_get_properties;
|
|
||||||
platform_class->macvlan_get_properties = macvlan_get_properties;
|
platform_class->macvlan_get_properties = macvlan_get_properties;
|
||||||
platform_class->vxlan_get_properties = vxlan_get_properties;
|
platform_class->vxlan_get_properties = vxlan_get_properties;
|
||||||
platform_class->gre_get_properties = gre_get_properties;
|
platform_class->gre_get_properties = gre_get_properties;
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netlink/route/addr.h>
|
#include <netlink/route/addr.h>
|
||||||
#include <netlink/route/rtnl.h>
|
#include <netlink/route/rtnl.h>
|
||||||
|
#include <linux/if_tun.h>
|
||||||
|
|
||||||
#include "NetworkManagerUtils.h"
|
#include "NetworkManagerUtils.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
@@ -1619,6 +1620,70 @@ nm_platform_veth_get_properties (NMPlatform *self, int ifindex, NMPlatformVethPr
|
|||||||
return klass->veth_get_properties (self, ifindex, props);
|
return klass->veth_get_properties (self, ifindex, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
nm_platform_tun_get_properties_ifname (NMPlatform *self, const char *ifname, NMPlatformTunProperties *props)
|
||||||
|
{
|
||||||
|
char *path, *val;
|
||||||
|
gboolean success = TRUE;
|
||||||
|
|
||||||
|
_CHECK_SELF (self, klass, FALSE);
|
||||||
|
|
||||||
|
g_return_val_if_fail (props, FALSE);
|
||||||
|
|
||||||
|
memset (props, 0, sizeof (*props));
|
||||||
|
props->owner = -1;
|
||||||
|
props->group = -1;
|
||||||
|
|
||||||
|
if (!ifname || !nm_utils_iface_valid_name (ifname))
|
||||||
|
return FALSE;
|
||||||
|
ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
|
||||||
|
|
||||||
|
path = g_strdup_printf ("/sys/class/net/%s/owner", ifname);
|
||||||
|
val = nm_platform_sysctl_get (self, path);
|
||||||
|
g_free (path);
|
||||||
|
if (val) {
|
||||||
|
props->owner = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
||||||
|
if (errno)
|
||||||
|
success = FALSE;
|
||||||
|
g_free (val);
|
||||||
|
} else
|
||||||
|
success = FALSE;
|
||||||
|
|
||||||
|
path = g_strdup_printf ("/sys/class/net/%s/group", ifname);
|
||||||
|
val = nm_platform_sysctl_get (self, path);
|
||||||
|
g_free (path);
|
||||||
|
if (val) {
|
||||||
|
props->group = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
||||||
|
if (errno)
|
||||||
|
success = FALSE;
|
||||||
|
g_free (val);
|
||||||
|
} else
|
||||||
|
success = FALSE;
|
||||||
|
|
||||||
|
path = g_strdup_printf ("/sys/class/net/%s/tun_flags", ifname);
|
||||||
|
val = nm_platform_sysctl_get (self, path);
|
||||||
|
g_free (path);
|
||||||
|
if (val) {
|
||||||
|
gint64 flags;
|
||||||
|
|
||||||
|
flags = _nm_utils_ascii_str_to_int64 (val, 16, 0, G_MAXINT64, 0);
|
||||||
|
if (!errno) {
|
||||||
|
#ifndef IFF_MULTI_QUEUE
|
||||||
|
const int IFF_MULTI_QUEUE = 0x0100;
|
||||||
|
#endif
|
||||||
|
props->mode = ((flags & (IFF_TUN | IFF_TAP)) == IFF_TUN) ? "tun" : "tap";
|
||||||
|
props->no_pi = !!(flags & IFF_NO_PI);
|
||||||
|
props->vnet_hdr = !!(flags & IFF_VNET_HDR);
|
||||||
|
props->multi_queue = !!(flags & IFF_MULTI_QUEUE);
|
||||||
|
} else
|
||||||
|
success = FALSE;
|
||||||
|
g_free (val);
|
||||||
|
} else
|
||||||
|
success = FALSE;
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props)
|
nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props)
|
||||||
{
|
{
|
||||||
@@ -1627,7 +1692,7 @@ nm_platform_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProp
|
|||||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||||
g_return_val_if_fail (props != NULL, FALSE);
|
g_return_val_if_fail (props != NULL, FALSE);
|
||||||
|
|
||||||
return klass->tun_get_properties (self, ifindex, props);
|
return nm_platform_tun_get_properties_ifname (self, nm_platform_link_get_name (self, ifindex), props);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@@ -484,7 +484,6 @@ typedef struct {
|
|||||||
const char **mode);
|
const char **mode);
|
||||||
|
|
||||||
gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties);
|
gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties);
|
||||||
gboolean (*tun_get_properties) (NMPlatform *, int ifindex, NMPlatformTunProperties *properties);
|
|
||||||
gboolean (*macvlan_get_properties) (NMPlatform *, int ifindex, NMPlatformMacvlanProperties *props);
|
gboolean (*macvlan_get_properties) (NMPlatform *, int ifindex, NMPlatformMacvlanProperties *props);
|
||||||
gboolean (*vxlan_get_properties) (NMPlatform *, int ifindex, NMPlatformVxlanProperties *props);
|
gboolean (*vxlan_get_properties) (NMPlatform *, int ifindex, NMPlatformVxlanProperties *props);
|
||||||
gboolean (*gre_get_properties) (NMPlatform *, int ifindex, NMPlatformGreProperties *props);
|
gboolean (*gre_get_properties) (NMPlatform *, int ifindex, NMPlatformGreProperties *props);
|
||||||
@@ -684,6 +683,8 @@ gboolean nm_platform_macvlan_get_properties (NMPlatform *self, int ifindex,
|
|||||||
gboolean nm_platform_vxlan_get_properties (NMPlatform *self, int ifindex, NMPlatformVxlanProperties *props);
|
gboolean nm_platform_vxlan_get_properties (NMPlatform *self, int ifindex, NMPlatformVxlanProperties *props);
|
||||||
gboolean nm_platform_gre_get_properties (NMPlatform *self, int ifindex, NMPlatformGreProperties *props);
|
gboolean nm_platform_gre_get_properties (NMPlatform *self, int ifindex, NMPlatformGreProperties *props);
|
||||||
|
|
||||||
|
gboolean nm_platform_tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props);
|
||||||
|
|
||||||
gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps);
|
gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps);
|
||||||
gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid);
|
gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid);
|
||||||
guint32 nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex);
|
guint32 nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex);
|
||||||
|
Reference in New Issue
Block a user