diff options
author | Thomas Haller <thaller@redhat.com> | 2015-05-03 10:11:31 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-05-05 23:11:08 +0200 |
commit | ad2d0a5bad2ad02cbcf5418ff6ffb26ec67d8c58 (patch) | |
tree | bbca471227ad5cf6c27506db55e9af0a271e4e49 | |
parent | e0aa65a8ab181234764d21194122bbce7936069d (diff) | |
download | NetworkManager-ad2d0a5bad2ad02cbcf5418ff6ffb26ec67d8c58.tar.gz |
platform: factor out ethtool_get_peer_ifindex() function
-rw-r--r-- | src/platform/nm-linux-platform.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index add4063a8d..8255abf4f4 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -485,6 +485,30 @@ ethtool_supports_vlans (const char *ifname) return !(features->features[block].active & (1 << bit)); } +static int +ethtool_get_peer_ifindex (const char *ifname) +{ + gs_free struct ethtool_stats *stats = NULL; + int peer_ifindex_stat; + + if (!ifname) + return 0; + + peer_ifindex_stat = ethtool_get_stringset_index (ifname, ETH_SS_STATS, "peer_ifindex"); + if (peer_ifindex_stat == -1) { + debug ("%s: peer_ifindex ethtool stat does not exist?", ifname); + return FALSE; + } + + stats = g_malloc0 (sizeof (*stats) + (peer_ifindex_stat + 1) * sizeof (guint64)); + stats->cmd = ETHTOOL_GSTATS; + stats->n_stats = peer_ifindex_stat + 1; + if (!ethtool_get (ifname, stats)) + return 0; + + return stats->data[peer_ifindex_stat]; +} + /****************************************************************** * NMPlatform types and functions ******************************************************************/ @@ -3011,26 +3035,17 @@ static gboolean veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties *props) { const char *ifname; - gs_free struct ethtool_stats *stats = NULL; - int peer_ifindex_stat; + int peer_ifindex; ifname = nm_platform_link_get_name (platform, ifindex); if (!ifname) return FALSE; - peer_ifindex_stat = ethtool_get_stringset_index (ifname, ETH_SS_STATS, "peer_ifindex"); - if (peer_ifindex_stat == -1) { - debug ("%s: peer_ifindex ethtool stat does not exist?", ifname); - return FALSE; - } - - stats = g_malloc0 (sizeof (*stats) + (peer_ifindex_stat + 1) * sizeof (guint64)); - stats->cmd = ETHTOOL_GSTATS; - stats->n_stats = peer_ifindex_stat + 1; - if (!ethtool_get (ifname, stats)) + peer_ifindex = ethtool_get_peer_ifindex (ifname); + if (peer_ifindex <= 0) return FALSE; - props->peer = stats->data[peer_ifindex_stat]; + props->peer = peer_ifindex; return TRUE; } |