luci-mod-status: luci-bwc: use 64bit traffic counters

Fixes: #2659
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-07-19 21:50:48 +02:00
parent 8aad613f1a
commit e50edeeb03

View file

@ -16,6 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define _BSD_SOURCE
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -26,6 +28,7 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <endian.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -47,9 +50,9 @@
#define DB_LD_FILE DB_PATH "/load" #define DB_LD_FILE DB_PATH "/load"
#define IF_SCAN_PATTERN \ #define IF_SCAN_PATTERN \
" %[^ :]:%u %u" \ " %[^ :]:%" SCNu64 " %" SCNu64 \
" %*d %*d %*d %*d %*d %*d" \ " %*u %*u %*u %*u %*u %*u" \
" %u %u" " %" SCNu64 " %" SCNu64
#define LD_SCAN_PATTERN \ #define LD_SCAN_PATTERN \
"%f %f %f" "%f %f %f"
@ -63,10 +66,10 @@ struct file_map {
struct traffic_entry { struct traffic_entry {
uint32_t time; uint32_t time;
uint32_t rxb; uint64_t rxb;
uint32_t rxp; uint64_t rxp;
uint32_t txb; uint64_t txb;
uint32_t txp; uint64_t txp;
}; };
struct conn_entry { struct conn_entry {
@ -190,7 +193,7 @@ static int init_file(char *path, int esize)
static inline uint32_t timeof(void *entry) static inline uint32_t timeof(void *entry)
{ {
return ntohl(((struct traffic_entry *)entry)->time); return be32toh(((struct traffic_entry *)entry)->time);
} }
static int update_file(const char *path, void *entry, int esize) static int update_file(const char *path, void *entry, int esize)
@ -296,7 +299,7 @@ static void iw_close(void *iw)
static int update_ifstat( static int update_ifstat(
const char *ifname, uint32_t rxb, uint32_t rxp, uint32_t txb, uint32_t txp const char *ifname, uint64_t rxb, uint64_t rxp, uint64_t txb, uint64_t txp
) { ) {
char path[1024]; char path[1024];
@ -316,11 +319,11 @@ static int update_ifstat(
} }
} }
e.time = htonl(time(NULL)); e.time = htobe32(time(NULL));
e.rxb = htonl(rxb); e.rxb = htobe64(rxb);
e.rxp = htonl(rxp); e.rxp = htobe64(rxp);
e.txb = htonl(txb); e.txb = htobe64(txb);
e.txp = htonl(txp); e.txp = htobe64(txp);
return update_file(path, &e, sizeof(struct traffic_entry)); return update_file(path, &e, sizeof(struct traffic_entry));
} }
@ -346,8 +349,8 @@ static int update_radiostat(
} }
} }
e.time = htonl(time(NULL)); e.time = htobe32(time(NULL));
e.rate = htons(rate); e.rate = htobe16(rate);
e.rssi = rssi; e.rssi = rssi;
e.noise = noise; e.noise = noise;
@ -374,10 +377,10 @@ static int update_cnstat(uint32_t udp, uint32_t tcp, uint32_t other)
} }
} }
e.time = htonl(time(NULL)); e.time = htobe32(time(NULL));
e.udp = htonl(udp); e.udp = htobe32(udp);
e.tcp = htonl(tcp); e.tcp = htobe32(tcp);
e.other = htonl(other); e.other = htobe32(other);
return update_file(path, &e, sizeof(struct conn_entry)); return update_file(path, &e, sizeof(struct conn_entry));
} }
@ -402,10 +405,10 @@ static int update_ldstat(uint16_t load1, uint16_t load5, uint16_t load15)
} }
} }
e.time = htonl(time(NULL)); e.time = htobe32(time(NULL));
e.load1 = htons(load1); e.load1 = htobe16(load1);
e.load5 = htons(load5); e.load5 = htobe16(load5);
e.load15 = htons(load15); e.load15 = htobe16(load15);
return update_file(path, &e, sizeof(struct load_entry)); return update_file(path, &e, sizeof(struct load_entry));
} }
@ -413,7 +416,7 @@ static int update_ldstat(uint16_t load1, uint16_t load5, uint16_t load15)
static int run_daemon(void) static int run_daemon(void)
{ {
FILE *info; FILE *info;
uint32_t rxb, txb, rxp, txp; uint64_t rxb, txb, rxp, txp;
uint32_t udp, tcp, other; uint32_t udp, tcp, other;
uint16_t rate; uint16_t rate;
uint8_t rssi, noise; uint8_t rssi, noise;
@ -521,7 +524,7 @@ static int run_daemon(void)
if (strstr(line, "TIME_WAIT")) if (strstr(line, "TIME_WAIT"))
continue; continue;
if ((strstr(line, "src=127.0.0.1 ") && strstr(line, "dst=127.0.0.1 ")) if ((strstr(line, "src=127.0.0.1 ") && strstr(line, "dst=127.0.0.1 "))
|| (strstr(line, "src=::1 ") && strstr(line, "dst=::1 "))) || (strstr(line, "src=::1 ") && strstr(line, "dst=::1 ")))
continue; continue;
@ -610,11 +613,11 @@ static int run_dump_ifname(const char *ifname)
if (!e->time) if (!e->time)
continue; continue;
printf("[ %u, %u, %" PRIu32 printf("[ %" PRIu32 ", %" PRIu64 ", %" PRIu64
", %u, %u ]%s\n", ", %" PRIu64 ", %" PRIu64 " ]%s\n",
ntohl(e->time), be32toh(e->time),
ntohl(e->rxb), ntohl(e->rxp), be64toh(e->rxb), be64toh(e->rxp),
ntohl(e->txb), ntohl(e->txp), be64toh(e->txb), be64toh(e->txp),
((i + sizeof(struct traffic_entry)) < m.size) ? "," : ""); ((i + sizeof(struct traffic_entry)) < m.size) ? "," : "");
} }
@ -646,9 +649,9 @@ static int run_dump_radio(const char *ifname)
if (!e->time) if (!e->time)
continue; continue;
printf("[ %u, %d, %d, %d ]%s\n", printf("[ %" PRIu32 ", %" PRIu16 ", %" PRIu8 ", %" PRIu8 " ]%s\n",
ntohl(e->time), be32toh(e->time),
e->rate, e->rssi, e->noise, be16toh(e->rate), e->rssi, e->noise,
((i + sizeof(struct radio_entry)) < m.size) ? "," : ""); ((i + sizeof(struct radio_entry)) < m.size) ? "," : "");
} }
@ -680,9 +683,9 @@ static int run_dump_conns(void)
if (!e->time) if (!e->time)
continue; continue;
printf("[ %u, %u, %u, %u ]%s\n", printf("[ %" PRIu32 ", %" PRIu32 ", %" PRIu32 ", %" PRIu32 " ]%s\n",
ntohl(e->time), ntohl(e->udp), be32toh(e->time), be32toh(e->udp),
ntohl(e->tcp), ntohl(e->other), be32toh(e->tcp), be32toh(e->other),
((i + sizeof(struct conn_entry)) < m.size) ? "," : ""); ((i + sizeof(struct conn_entry)) < m.size) ? "," : "");
} }
@ -714,9 +717,9 @@ static int run_dump_load(void)
if (!e->time) if (!e->time)
continue; continue;
printf("[ %u, %u, %u, %u ]%s\n", printf("[ %" PRIu32 ", %" PRIu16 ", %" PRIu16 ", %" PRIu16 " ]%s\n",
ntohl(e->time), be32toh(e->time),
ntohs(e->load1), ntohs(e->load5), ntohs(e->load15), be16toh(e->load1), be16toh(e->load5), be16toh(e->load15),
((i + sizeof(struct load_entry)) < m.size) ? "," : ""); ((i + sizeof(struct load_entry)) < m.size) ? "," : "");
} }