summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>2016-08-10 11:54:30 +0200
committerThomas Haller <thaller@redhat.com>2016-08-17 15:50:20 +0200
commit6ed939e84176413dab4762d63d57bc848d190b54 (patch)
tree069c5265dd991135b98a454e09ed1069e99a42e0
parent3bc5c7dbc1d33a13be753ca9469d25eab569c862 (diff)
downloadNetworkManager-6ed939e84176413dab4762d63d57bc848d190b54.tar.gz
platform: add network statistics
Make network traffic statistics data available through the platform.
-rw-r--r--src/platform/nm-linux-platform.c32
-rw-r--r--src/platform/nm-platform.c19
-rw-r--r--src/platform/nm-platform.h12
3 files changed, 63 insertions, 0 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index deb6c5f977..d185f96f12 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -1476,6 +1476,15 @@ _new_from_nl_link (NMPlatform *platform, const NMPCache *cache, struct nlmsghdr
nl_info_data = li[IFLA_INFO_DATA];
}
+ if (tb[IFLA_STATS64]) {
+ struct rtnl_link_stats64 *stats = nla_data (tb[IFLA_STATS64]);
+
+ obj->link.rx_packets = stats->rx_packets;
+ obj->link.rx_bytes = stats->rx_bytes;
+ obj->link.tx_packets = stats->tx_packets;
+ obj->link.tx_bytes = stats->tx_bytes;
+ }
+
obj->link.n_ifi_flags = ifi->ifi_flags;
obj->link.connected = NM_FLAGS_HAS (obj->link.n_ifi_flags, IFF_LOWER_UP);
obj->link.arptype = ifi->ifi_type;
@@ -3732,6 +3741,7 @@ event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_event
case RTM_NEWLINK:
case RTM_NEWADDR:
case RTM_NEWROUTE:
+ case RTM_GETLINK:
cache_op = nmp_cache_update_netlink (priv->cache, obj, &obj_cache, &was_visible, cache_pre_hook, platform);
cache_post (platform, msghdr, cache_op, obj, obj_cache);
@@ -4517,6 +4527,27 @@ link_get_dev_id (NMPlatform *platform, int ifindex)
return errno ? 0 : (int) int_val;
}
+static gboolean
+link_get_stats (NMPlatform *platform, int ifindex,
+ guint64 *rx_packets, guint64 *rx_bytes,
+ guint64 *tx_packets, guint64 *tx_bytes)
+{
+ nm_auto_pop_netns NMPNetns *netns = NULL;
+ const NMPObject *obj;
+
+ obj = cache_lookup_link (platform, ifindex);
+
+ if (!obj)
+ return FALSE;
+
+ *rx_packets = obj->link.rx_packets;
+ *rx_bytes = obj->link.rx_bytes;
+ *tx_packets = obj->link.tx_packets;
+ *tx_bytes = obj->link.tx_bytes;
+
+ return TRUE;
+}
+
static int
vlan_add (NMPlatform *platform,
const char *name,
@@ -6509,6 +6540,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_get_physical_port_id = link_get_physical_port_id;
platform_class->link_get_dev_id = link_get_dev_id;
+ platform_class->link_get_stats = link_get_stats;
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
platform_class->link_get_driver_info = link_get_driver_info;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 75c85b9255..99dc00c812 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1265,6 +1265,21 @@ nm_platform_link_get_dev_id (NMPlatform *self, int ifindex)
return 0;
}
+gboolean nm_platform_link_get_stats (NMPlatform *self, int ifindex,
+ guint64 *rx_packets, guint64 *rx_bytes,
+ guint64 *tx_packets, guint64 *tx_bytes)
+{
+ _CHECK_SELF (self, klass, 0);
+
+ g_return_val_if_fail (ifindex >= 0, 0);
+
+ if (klass->link_get_stats)
+ return klass->link_get_stats (self, ifindex,
+ rx_packets, rx_bytes,
+ tx_packets, tx_bytes);
+ return FALSE;
+}
+
/**
* nm_platform_link_get_wake_onlan:
* @self: platform instance
@@ -3777,6 +3792,10 @@ int
nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
{
_CMP_SELF (a, b);
+ _CMP_FIELD (a, b, rx_packets);
+ _CMP_FIELD (a, b, rx_bytes);
+ _CMP_FIELD (a, b, tx_packets);
+ _CMP_FIELD (a, b, tx_bytes);
_CMP_FIELD (a, b, ifindex);
_CMP_FIELD (a, b, type);
_CMP_FIELD_STR (a, b, name);
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index c419855a98..19148deb4f 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -156,6 +156,12 @@ struct _NMPlatformLink {
* initialized with memset(0) has and unset value.*/
guint8 inet6_addr_gen_mode_inv;
+ /* Statistics */
+ guint64 rx_packets;
+ guint64 rx_bytes;
+ guint64 tx_packets;
+ guint64 tx_bytes;
+
/* @connected is mostly identical to (@n_ifi_flags & IFF_UP). Except for bridge/bond masters,
* where we coerce the link as disconnect if it has no slaves. */
bool connected:1;
@@ -532,6 +538,9 @@ typedef struct {
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
guint (*link_get_dev_id) (NMPlatform *, int ifindex);
+ gboolean (*link_get_stats) (NMPlatform *platform, int ifindex,
+ guint64 *rx_packets, guint64 *rx_bytes,
+ guint64 *tx_packets, guint64 *tx_bytes);
gboolean (*link_get_wake_on_lan) (NMPlatform *, int ifindex);
gboolean (*link_get_driver_info) (NMPlatform *,
int ifindex,
@@ -763,6 +772,9 @@ gboolean nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu);
char *nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex);
guint nm_platform_link_get_dev_id (NMPlatform *self, int ifindex);
+gboolean nm_platform_link_get_stats (NMPlatform *self, int ifindex,
+ guint64 *rx_packets, guint64 *rx_bytes,
+ guint64 *tx_packets, guint64 *tx_bytes);
gboolean nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex);
gboolean nm_platform_link_get_driver_info (NMPlatform *self,
int ifindex,