From bae47558ba31d1e658facd8f249a0e2d3ede1e53 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 23 Apr 2015 23:16:00 +0200 Subject: [PATCH] platform: detect TUN/TAP device in link_extract_type() independently of platform cache link_extract_type() would call tun_get_properties() to determine whether the link if a TAP or TUN device. The previous implementation would receive the ifindex, and resolve the ifname via lookup in the platform cache. This means, the call on link_extract_type() will only succeed to detect the TUN/TAP properties, if the libnl object is already in the cache. Currently that is always the case and there is no problem. It is desireable, that we can resolve the link type of an object without consulting the platform cache first. (cherry picked from commit 18d611d5d2a613204e7123fda3d3f75271722df6) --- src/platform/nm-linux-platform.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 7f309cea4f..36cbbc637a 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -120,6 +120,8 @@ return t; \ } G_STMT_END +static gboolean tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props); + /****************************************************************** * libnl unility functions and wrappers ******************************************************************/ @@ -968,7 +970,7 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, const char NMPlatformTunProperties props; guint flags; - if (nm_platform_tun_get_properties (platform, rtnl_link_get_ifindex (rtnllink), &props)) { + if (tun_get_properties_ifname (platform, rtnl_link_get_name (rtnllink), &props)) { if (!g_strcmp0 (props.mode, "tap")) return_type (NM_LINK_TYPE_TAP, "tap"); if (!g_strcmp0 (props.mode, "tun")) @@ -3064,9 +3066,8 @@ veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties } static gboolean -tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *props) +tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props) { - const char *ifname; char *path, *val; gboolean success = TRUE; @@ -3076,7 +3077,6 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties * props->owner = -1; props->group = -1; - ifname = nm_platform_link_get_name (platform, ifindex); if (!ifname || !nm_utils_iface_valid_name (ifname)) return FALSE; ifname = ASSERT_VALID_PATH_COMPONENT (ifname); @@ -3127,6 +3127,12 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties * 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] = { [IFLA_MACVLAN_MODE] = { .type = NLA_U32 }, #ifdef MACVLAN_FLAG_NOPROMISC