]> git.meshlink.io Git - meshlink/commitdiff
Add per-node traffic counters.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 14 May 2011 22:42:29 +0000 (00:42 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 14 May 2011 22:42:29 +0000 (00:42 +0200)
src/device.h
src/linux/device.c
src/net.h
src/net_packet.c
src/node.h

index 5841253a088fe85f4de65c024396f37467f269bb..16a24868dc0dd79cf0c1eb388347e09f2788a602 100644 (file)
 
 extern int device_fd;
 extern char *device;
-
 extern char *iface;
 
+extern uint64_t device_in_packets;
+extern uint64_t device_in_bytes;
+extern uint64_t device_out_packets;
+extern uint64_t device_out_bytes;
+
 extern bool setup_device(void);
 extern void close_device(void);
 extern bool read_packet(struct vpn_packet_t *);
index 0cfc546ee16557c037c3e5352cbe5eb7c12a4571..111b98c671abe7fb6b2ef01bb8a8acb24d3b3a27 100644 (file)
@@ -47,8 +47,10 @@ char *iface = NULL;
 static char ifrname[IFNAMSIZ];
 static char *device_info;
 
-static uint64_t device_total_in = 0;
-static uint64_t device_total_out = 0;
+uint64_t device_in_packets = 0;
+uint64_t device_in_bytes = 0;
+uint64_t device_out_packets = 0;
+uint64_t device_out_bytes = 0;
 
 bool setup_device(void) {
        struct ifreq ifr;
@@ -166,7 +168,8 @@ bool read_packet(vpn_packet_t *packet) {
                        break;
        }
 
-       device_total_in += packet->len;
+       device_in_packets++;
+       device_in_bytes += packet->len;
 
        ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
                           device_info);
@@ -205,13 +208,14 @@ bool write_packet(vpn_packet_t *packet) {
                        break;
        }
 
-       device_total_out += packet->len;
+       device_out_packets++;
+       device_out_bytes += packet->len;
 
        return true;
 }
 
 void dump_device_stats(void) {
        logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
-       logger(LOG_DEBUG, " total bytes in:  %10"PRIu64, device_total_in);
-       logger(LOG_DEBUG, " total bytes out: %10"PRIu64, device_total_out);
+       logger(LOG_DEBUG, " total bytes in:  %10"PRIu64, device_in_bytes);
+       logger(LOG_DEBUG, " total bytes out: %10"PRIu64, device_out_bytes);
 }
index 9b625a0d9873c7a32723e55210559157c9df8ffc..d5eeb05c7269fe4b75a517730808925c86725ed2 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -131,7 +131,7 @@ extern void do_outgoing_connection(struct connection_t *);
 extern void handle_new_meta_connection(int, short, void *);
 extern int setup_listen_socket(const sockaddr_t *);
 extern int setup_vpn_in_socket(const sockaddr_t *);
-extern void send_packet(const struct node_t *, vpn_packet_t *);
+extern void send_packet(struct node_t *, vpn_packet_t *);
 extern void receive_tcppacket(struct connection_t *, char *, int);
 extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
 extern bool setup_network(void);
index ded80a2fb94272bb98eaf5a9bdcad34dce739007..7e567e99c058c24dd01ae31bcca8eb93005ebeaa 100644 (file)
@@ -236,6 +236,9 @@ static void receive_packet(node_t *n, vpn_packet_t *packet) {
        ifdebug(TRAFFIC) logger(LOG_DEBUG, "Received packet of %d bytes from %s (%s)",
                           packet->len, n->name, n->hostname);
 
+       n->in_packets++;
+       n->in_bytes += packet->len;
+
        route(n, packet);
 }
 
@@ -502,12 +505,14 @@ end:
 /*
   send a packet to the given vpn ip.
 */
-void send_packet(const node_t *n, vpn_packet_t *packet) {
+void send_packet(node_t *n, vpn_packet_t *packet) {
        node_t *via;
 
        if(n == myself) {
                if(overwrite_mac)
                         memcpy(packet->data, mymac.x, ETH_ALEN);
+               n->out_packets++;
+               n->out_bytes += packet->len;
                write_packet(packet);
                return;
        }
@@ -521,6 +526,9 @@ void send_packet(const node_t *n, vpn_packet_t *packet) {
                return;
        }
 
+       n->out_packets++;
+       n->out_bytes += packet->len;
+
        via = (packet->priority == -1 || n->via == myself) ? n->nexthop : n->via;
 
        if(via != n)
@@ -640,6 +648,9 @@ void handle_incoming_vpn_data(int sock, short events, void *data) {
 void handle_device_data(int sock, short events, void *data) {
        vpn_packet_t packet;
 
-       if(read_packet(&packet))
+       if(read_packet(&packet)) {
+               myself->in_packets++;
+               myself->in_bytes += packet.len;
                route(myself, &packet);
+       }
 }
index 4eb216f49014d2f8b9bb5520365d6ce5e8df7adc..38e0e0642d0cde3e853091079dfd6cd7738ffec7 100644 (file)
@@ -77,6 +77,11 @@ typedef struct node_t {
        length_t maxmtu;                        /* Probed maximum MTU */
        int mtuprobes;                          /* Number of probes */
        struct event mtuevent;                  /* Probe event */
+
+       uint64_t in_packets;
+       uint64_t in_bytes;
+       uint64_t out_packets;
+       uint64_t out_bytes;
 } node_t;
 
 extern struct node_t *myself;