summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-05-03 10:06:27 +0200
committerThomas Haller <thaller@redhat.com>2015-06-05 16:52:50 +0200
commit4be9394864f7df42c64048f01a00484047fadb4f (patch)
tree1f7a91416c8bb878c4ca49cce24e195eea356244
parent2b8f3331d76497433b761bfa1c15640de28692f5 (diff)
downloadNetworkManager-4be9394864f7df42c64048f01a00484047fadb4f.tar.gz
platform: factor out ethtool_supports_vlans() function
-rw-r--r--src/platform/nm-linux-platform.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 54c8ca59c1..9368f18799 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -492,6 +492,35 @@ ethtool_supports_carrier_detect (const char *ifname)
return ethtool_get (ifname, &edata);
}
+static gboolean
+ethtool_supports_vlans (const char *ifname)
+{
+ gs_free struct ethtool_gfeatures *features = NULL;
+ int idx, block, bit, size;
+
+ if (!ifname)
+ return FALSE;
+
+ idx = ethtool_get_stringset_index (ifname, ETH_SS_FEATURES, "vlan-challenged");
+ if (idx == -1) {
+ debug ("vlan-challenged ethtool feature does not exist?");
+ return FALSE;
+ }
+
+ block = idx / 32;
+ bit = idx % 32;
+ size = block + 1;
+
+ features = g_malloc0 (sizeof (*features) + size * sizeof (struct ethtool_get_features_block));
+ features->cmd = ETHTOOL_GFEATURES;
+ features->size = size;
+
+ if (!ethtool_get (ifname, features))
+ return FALSE;
+
+ return !(features->features[block].active & (1 << bit));
+}
+
/******************************************************************
* NMPlatform types and functions
******************************************************************/
@@ -2772,35 +2801,12 @@ static gboolean
link_supports_vlans (NMPlatform *platform, int ifindex)
{
auto_nl_object struct rtnl_link *rtnllink = link_get (platform, ifindex);
- const char *name = nm_platform_link_get_name (platform, ifindex);
- gs_free struct ethtool_gfeatures *features = NULL;
- int idx, block, bit, size;
/* Only ARPHRD_ETHER links can possibly support VLANs. */
if (!rtnllink || rtnl_link_get_arptype (rtnllink) != ARPHRD_ETHER)
return FALSE;
- if (!name)
- return FALSE;
-
- idx = ethtool_get_stringset_index (name, ETH_SS_FEATURES, "vlan-challenged");
- if (idx == -1) {
- debug ("vlan-challenged ethtool feature does not exist?");
- return FALSE;
- }
-
- block = idx / 32;
- bit = idx % 32;
- size = block + 1;
-
- features = g_malloc0 (sizeof (*features) + size * sizeof (struct ethtool_get_features_block));
- features->cmd = ETHTOOL_GFEATURES;
- features->size = size;
-
- if (!ethtool_get (name, features))
- return FALSE;
-
- return !(features->features[block].active & (1 << bit));
+ return ethtool_supports_vlans (rtnl_link_get_name (rtnllink));
}
static gboolean