From: volth Date: Wed, 13 Jun 2018 14:12:02 +0000 (+0000) Subject: expose traffic stats to 'tinc info ___' and 'tinc dump nodes' X-Git-Tag: release-1.1pre17~15^2~1 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=72136f8418bc7e8a0a5bf3c11215aa49dc679659;p=tinc expose traffic stats to 'tinc info ___' and 'tinc dump nodes' --- diff --git a/src/info.c b/src/info.c index 652c4aeb..9ac7bbca 100644 --- a/src/info.c +++ b/src/info.c @@ -71,15 +71,16 @@ static int info_node(int fd, const char *item) { node_status_t status; long int last_state_change; long int udp_ping_rtt; + uint64_t in_packets, in_bytes, out_packets, out_bytes; while(recvline(fd, line, sizeof(line))) { - int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt); + int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld %ld %lu %lu %lu %lu", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes); if(n == 2) { break; } - if(n != 20) { + if(n != 24) { fprintf(stderr, "Unable to parse node dump from tincd.\n"); return 1; } @@ -188,6 +189,9 @@ static int info_node(int fd, const char *item) { printf("none, forwarded via %s\n", nexthop); } + printf("RX: %lu packets %lu bytes\n", in_packets, in_bytes); + printf("TX: %lu packets %lu bytes\n", out_packets, out_bytes); + // List edges printf("Edges: "); sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item); diff --git a/src/node.c b/src/node.c index c3f2ab55..6a5b747e 100644 --- a/src/node.c +++ b/src/node.c @@ -212,7 +212,7 @@ bool dump_nodes(connection_t *c) { } id[sizeof(id) - 1] = 0; - send_request(c, "%d %d %s %s %s %d %d %d %d %x %x %s %s %d %d %d %d %ld %ld", CONTROL, REQ_DUMP_NODES, + send_request(c, "%d %d %s %s %s %d %d %d %d %x %x %s %s %d %d %d %d %ld %ld %lu %lu %lu %lu", CONTROL, REQ_DUMP_NODES, n->name, id, n->hostname ? : "unknown port unknown", #ifdef DISABLE_LEGACY 0, 0, 0, @@ -221,7 +221,8 @@ bool dump_nodes(connection_t *c) { #endif n->outcompression, n->options, bitfield_to_int(&n->status, sizeof(n->status)), n->nexthop ? n->nexthop->name : "-", n->via ? n->via->name ? : "-" : "-", n->distance, - n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change, (long)n->udp_ping_rtt); + n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change, (long)n->udp_ping_rtt, + n->in_packets, n->in_bytes, n->out_packets, n->out_bytes); } return send_request(c, "%d %d", CONTROL, REQ_DUMP_NODES); diff --git a/src/tincctl.c b/src/tincctl.c index 76ff3740..af54aefb 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -1299,12 +1299,13 @@ static int cmd_dump(int argc, char *argv[]) { node_status_t status; long int last_state_change; long int udp_ping_rtt; + uint64_t in_packets, in_bytes, out_packets, out_bytes; switch(req) { case REQ_DUMP_NODES: { - int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %x %4095s %4095s %d %hd %hd %hd %ld %ld", node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt); + int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %x %4095s %4095s %d %hd %hd %hd %ld %ld %lu %lu %lu %lu", node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes); - if(n != 18) { + if(n != 22) { fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line); return 1; } @@ -1332,8 +1333,8 @@ static int cmd_dump(int argc, char *argv[]) { continue; } - printf("%s id %s at %s port %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d)", - node, id, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu); + printf("%s id %s at %s port %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d) rx %lu %lu tx %lu %lu", + node, id, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu, in_packets, in_bytes, out_packets, out_bytes); if (udp_ping_rtt != -1) printf(" rtt %ld.%03ld", udp_ping_rtt/1000, udp_ping_rtt%1000); printf("\n");