DECLARE_VERBOSE_LEVEL (ulvpn, INFO);
+typedef struct {
+ unsigned int rx;
+ unsigned int tx;
+} stat_fd_t;
+
+stat_fd_t stat_tun_fd = { 0, 0 };
+stat_fd_t stat_udp_fd = { 0, 0 };
+stat_fd_t stat_blk_fd = { 0, 0 };
+stat_fd_t stat_red_fd = { 0, 0 };
+int raise_stat_sig = 0;
+
void sig_handler (int sig)
{
switch (sig) {
case SIGTERM:
stop = 1;
break;
+ case SIGUSR1:
+ printf ("tun: RX %9d TX %9d\nudp: RX %9d TX %9d\nblk: RX %9d TX %9d\nred: RX %9d TX %9d\n",
+ stat_tun_fd.rx, stat_tun_fd.tx, stat_udp_fd.rx,
+ stat_udp_fd.tx, stat_blk_fd.rx, stat_blk_fd.tx,
+ stat_red_fd.rx, stat_red_fd.tx);
+ fflush (stdout);
+ raise_stat_sig = 1;
+ break;
}
}
/* signals */
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
+ signal(SIGUSR1, sig_handler);
/* main loop */
int rc = 0;
}
if (-1 == select (max_fd + 1, &readset, NULL, NULL, NULL)) {
- if (!stop) {
+ if (raise_stat_sig) {
+ raise_stat_sig = 0;
+ } else if (!stop) {
VERBOSE (ulvpn, ERROR, PRINTF ("select error\n"));
rc = 2;
}
if (FD_ISSET (tun_fd, &readset)) {
uint8_t buffer[MAXPAYLOAD] = {0};
int rxlen = MAPEC_Receive (tun_fd, buffer, sizeof (buffer));
+ stat_tun_fd.rx++;
if (rxlen < 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when receiving from tun\n"));
} else {
} else {
VERBOSE (ulvpn, DEBUG, PRINTF ("packing %d bytes\n", txlen));
seqtx = MOREP_Send (txred_fd, 0x00, buffer, txlen);
+ stat_red_fd.tx++;
if (seqtx < 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when sending to CM red\n"));
} else {
}
} else if (udp_fd >= 0) {
int txlen = MAPEC_Send (udp_fd, buffer, rxlen);
+ stat_udp_fd.tx++;
if (txlen <= 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when sending to udp\n"));
} else {
} else if (FD_ISSET (udp_fd, &readset)) {
uint8_t buffer[MAXPAYLOAD] = {0};
int rxlen = MAPEC_Receive (udp_fd, buffer, sizeof (buffer));
+ stat_udp_fd.rx++;
if (rxlen < 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when receiving from udp\n"));
} else {
} else {
VERBOSE (ulvpn, DEBUG, PRINTF ("packing %d bytes\n", txlen));
seqtx = MOREP_Send (txblack_fd, 0x02, buffer, txlen);
+ stat_blk_fd.tx++;
if (seqtx < 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when sending to CM black\n"));
} else {
}
} else if (tun_fd >= 0) {
int txlen = MAPEC_Send (tun_fd, buffer, rxlen);
+ stat_tun_fd.tx++;
if (txlen <= 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when sending to tun\n"));
} else {
uint8_t msgtype = -1;
int rxlen = 0;
seqrx = MOREP_Receive (rxblack_fd, &msgtype, buffer, &rxlen);
+ stat_blk_fd.rx++;
if (seqrx == -2) {
continue;
}
} else {
VERBOSE (ulvpn, DEBUG, PRINTF ("depacking %d bytes\n", txlen));
txlen = MAPEC_Send (udp_fd, buffer, txlen);
+ stat_udp_fd.tx++;
if (txlen <= 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when sending to udp\n"));
} else {
uint8_t msgtype = -1;
int rxlen = 0;
seqrx = MOREP_Receive (rxred_fd, &msgtype, buffer, &rxlen);
+ stat_red_fd.rx++;
if (seqrx == -2) {
continue;
}
} else {
VERBOSE (ulvpn, DEBUG, PRINTF ("depacking %d bytes\n", txlen));
txlen = MAPEC_Send (tun_fd, buffer, txlen);
+ stat_tun_fd.tx++;
if (txlen <= 0) {
VERBOSE (ulvpn, WARNING, PRINTF ("error when sending to tun\n"));
} else {