summaryrefslogtreecommitdiff
path: root/src/rtnl.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-01-05 06:59:20 -0800
committerMarcel Holtmann <marcel@holtmann.org>2010-01-05 06:59:20 -0800
commitf33303b557c1c12313c42372fdd173c4e69ddef0 (patch)
tree1191ef752ba20b221a57043100e8bf6bbfbd9286 /src/rtnl.c
parentf2af98906f063a65f2933e6133a293c344a1f011 (diff)
downloadconnman-f33303b557c1c12313c42372fdd173c4e69ddef0.tar.gz
connman-f33303b557c1c12313c42372fdd173c4e69ddef0.tar.bz2
connman-f33303b557c1c12313c42372fdd173c4e69ddef0.zip
Add support for exporting basic interface statistics
Diffstat (limited to 'src/rtnl.c')
-rw-r--r--src/rtnl.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/rtnl.c b/src/rtnl.c
index 2137788a..12ebdcbe 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -242,9 +242,9 @@ static const char *operstate2str(unsigned char operstate)
static void extract_link(struct ifinfomsg *msg, int bytes,
struct ether_addr *address, const char **ifname,
- unsigned int *mtu, unsigned char *operstate)
+ unsigned int *mtu, unsigned char *operstate,
+ struct rtnl_link_stats *stats)
{
- struct rtnl_link_stats stats;
struct rtattr *attr;
for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes);
@@ -263,12 +263,9 @@ static void extract_link(struct ifinfomsg *msg, int bytes,
*mtu = *((unsigned int *) RTA_DATA(attr));
break;
case IFLA_STATS:
- memcpy(&stats, RTA_DATA(attr),
+ if (stats != NULL)
+ memcpy(stats, RTA_DATA(attr),
sizeof(struct rtnl_link_stats));
- connman_info("%s {RX} %d packets %d bytes", *ifname,
- stats.rx_packets, stats.rx_bytes);
- connman_info("%s {TX} %d packets %d bytes", *ifname,
- stats.tx_packets, stats.tx_bytes);
break;
case IFLA_OPERSTATE:
if (operstate != NULL)
@@ -285,27 +282,30 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
{
struct ether_addr address = {{ 0, 0, 0, 0, 0, 0 }};
struct ether_addr compare = {{ 0, 0, 0, 0, 0, 0 }};
+ struct rtnl_link_stats stats;
unsigned char operstate = 0xff;
const char *ifname = NULL;
unsigned int mtu = 0;
char str[18];
GSList *list;
- extract_link(msg, bytes, &address, &ifname, &mtu, &operstate);
+ memset(&stats, 0, sizeof(stats));
+ extract_link(msg, bytes, &address, &ifname, &mtu, &operstate, &stats);
snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
address.ether_addr_octet[0],
- address.ether_addr_octet[1],
- address.ether_addr_octet[2],
- address.ether_addr_octet[3],
- address.ether_addr_octet[4],
- address.ether_addr_octet[5]);
+ address.ether_addr_octet[1],
+ address.ether_addr_octet[2],
+ address.ether_addr_octet[3],
+ address.ether_addr_octet[4],
+ address.ether_addr_octet[5]);
switch (type) {
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK:
case ARPHRD_NONE:
- __connman_ipconfig_newlink(index, type, flags, str, mtu);
+ __connman_ipconfig_newlink(index, type, flags,
+ str, mtu, &stats);
break;
}
@@ -342,11 +342,13 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
static void process_dellink(unsigned short type, int index, unsigned flags,
unsigned change, struct ifinfomsg *msg, int bytes)
{
+ struct rtnl_link_stats stats;
unsigned char operstate = 0xff;
const char *ifname = NULL;
GSList *list;
- extract_link(msg, bytes, NULL, &ifname, NULL, &operstate);
+ memset(&stats, 0, sizeof(stats));
+ extract_link(msg, bytes, NULL, &ifname, NULL, &operstate, &stats);
if (operstate != 0xff)
connman_info("%s {dellink} index %d operstate %u <%s>",
@@ -374,7 +376,7 @@ static void process_dellink(unsigned short type, int index, unsigned flags,
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK:
case ARPHRD_NONE:
- __connman_ipconfig_dellink(index);
+ __connman_ipconfig_dellink(index, &stats);
break;
}
}
@@ -1049,6 +1051,11 @@ static int send_getroute(void)
return queue_request(req);
}
+int __connman_rtnl_request_update(void)
+{
+ return send_getlink();
+}
+
int __connman_rtnl_init(void)
{
struct sockaddr_nl addr;