Add per-node traffic counters.
This commit is contained in:
parent
ffa3a443b9
commit
f5843e7d64
5 changed files with 34 additions and 10 deletions
|
@ -25,9 +25,13 @@
|
||||||
|
|
||||||
extern int device_fd;
|
extern int device_fd;
|
||||||
extern char *device;
|
extern char *device;
|
||||||
|
|
||||||
extern char *iface;
|
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 bool setup_device(void);
|
||||||
extern void close_device(void);
|
extern void close_device(void);
|
||||||
extern bool read_packet(struct vpn_packet_t *);
|
extern bool read_packet(struct vpn_packet_t *);
|
||||||
|
|
|
@ -47,8 +47,10 @@ char *iface = NULL;
|
||||||
static char ifrname[IFNAMSIZ];
|
static char ifrname[IFNAMSIZ];
|
||||||
static char *device_info;
|
static char *device_info;
|
||||||
|
|
||||||
static uint64_t device_total_in = 0;
|
uint64_t device_in_packets = 0;
|
||||||
static uint64_t device_total_out = 0;
|
uint64_t device_in_bytes = 0;
|
||||||
|
uint64_t device_out_packets = 0;
|
||||||
|
uint64_t device_out_bytes = 0;
|
||||||
|
|
||||||
bool setup_device(void) {
|
bool setup_device(void) {
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
@ -166,7 +168,8 @@ bool read_packet(vpn_packet_t *packet) {
|
||||||
break;
|
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,
|
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Read packet of %d bytes from %s", packet->len,
|
||||||
device_info);
|
device_info);
|
||||||
|
@ -205,13 +208,14 @@ bool write_packet(vpn_packet_t *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_total_out += packet->len;
|
device_out_packets++;
|
||||||
|
device_out_bytes += packet->len;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_device_stats(void) {
|
void dump_device_stats(void) {
|
||||||
logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
|
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 in: %10"PRIu64, device_in_bytes);
|
||||||
logger(LOG_DEBUG, " total bytes out: %10"PRIu64, device_total_out);
|
logger(LOG_DEBUG, " total bytes out: %10"PRIu64, device_out_bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ extern void do_outgoing_connection(struct connection_t *);
|
||||||
extern void handle_new_meta_connection(int, short, void *);
|
extern void handle_new_meta_connection(int, short, void *);
|
||||||
extern int setup_listen_socket(const sockaddr_t *);
|
extern int setup_listen_socket(const sockaddr_t *);
|
||||||
extern int setup_vpn_in_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 receive_tcppacket(struct connection_t *, char *, int);
|
||||||
extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
|
extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
|
||||||
extern bool setup_network(void);
|
extern bool setup_network(void);
|
||||||
|
|
|
@ -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)",
|
ifdebug(TRAFFIC) logger(LOG_DEBUG, "Received packet of %d bytes from %s (%s)",
|
||||||
packet->len, n->name, n->hostname);
|
packet->len, n->name, n->hostname);
|
||||||
|
|
||||||
|
n->in_packets++;
|
||||||
|
n->in_bytes += packet->len;
|
||||||
|
|
||||||
route(n, packet);
|
route(n, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,12 +505,14 @@ end:
|
||||||
/*
|
/*
|
||||||
send a packet to the given vpn ip.
|
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;
|
node_t *via;
|
||||||
|
|
||||||
if(n == myself) {
|
if(n == myself) {
|
||||||
if(overwrite_mac)
|
if(overwrite_mac)
|
||||||
memcpy(packet->data, mymac.x, ETH_ALEN);
|
memcpy(packet->data, mymac.x, ETH_ALEN);
|
||||||
|
n->out_packets++;
|
||||||
|
n->out_bytes += packet->len;
|
||||||
write_packet(packet);
|
write_packet(packet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -521,6 +526,9 @@ void send_packet(const node_t *n, vpn_packet_t *packet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n->out_packets++;
|
||||||
|
n->out_bytes += packet->len;
|
||||||
|
|
||||||
via = (packet->priority == -1 || n->via == myself) ? n->nexthop : n->via;
|
via = (packet->priority == -1 || n->via == myself) ? n->nexthop : n->via;
|
||||||
|
|
||||||
if(via != n)
|
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) {
|
void handle_device_data(int sock, short events, void *data) {
|
||||||
vpn_packet_t packet;
|
vpn_packet_t packet;
|
||||||
|
|
||||||
if(read_packet(&packet))
|
if(read_packet(&packet)) {
|
||||||
|
myself->in_packets++;
|
||||||
|
myself->in_bytes += packet.len;
|
||||||
route(myself, &packet);
|
route(myself, &packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,11 @@ typedef struct node_t {
|
||||||
length_t maxmtu; /* Probed maximum MTU */
|
length_t maxmtu; /* Probed maximum MTU */
|
||||||
int mtuprobes; /* Number of probes */
|
int mtuprobes; /* Number of probes */
|
||||||
struct event mtuevent; /* Probe event */
|
struct event mtuevent; /* Probe event */
|
||||||
|
|
||||||
|
uint64_t in_packets;
|
||||||
|
uint64_t in_bytes;
|
||||||
|
uint64_t out_packets;
|
||||||
|
uint64_t out_bytes;
|
||||||
} node_t;
|
} node_t;
|
||||||
|
|
||||||
extern struct node_t *myself;
|
extern struct node_t *myself;
|
||||||
|
|
Loading…
Add table
Reference in a new issue