summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-status
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-mod-status')
-rw-r--r--modules/luci-mod-status/src/luci-bwc.c83
1 files changed, 43 insertions, 40 deletions
diff --git a/modules/luci-mod-status/src/luci-bwc.c b/modules/luci-mod-status/src/luci-bwc.c
index 8ddd91727..dc68a2e4d 100644
--- a/modules/luci-mod-status/src/luci-bwc.c
+++ b/modules/luci-mod-status/src/luci-bwc.c
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+#define _BSD_SOURCE
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -26,6 +28,7 @@
#include <errno.h>
#include <unistd.h>
#include <signal.h>
+#include <endian.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -47,9 +50,9 @@
#define DB_LD_FILE DB_PATH "/load"
#define IF_SCAN_PATTERN \
- " %[^ :]:%u %u" \
- " %*d %*d %*d %*d %*d %*d" \
- " %u %u"
+ " %[^ :]:%" SCNu64 " %" SCNu64 \
+ " %*u %*u %*u %*u %*u %*u" \
+ " %" SCNu64 " %" SCNu64
#define LD_SCAN_PATTERN \
"%f %f %f"
@@ -63,10 +66,10 @@ struct file_map {
struct traffic_entry {
uint32_t time;
- uint32_t rxb;
- uint32_t rxp;
- uint32_t txb;
- uint32_t txp;
+ uint64_t rxb;
+ uint64_t rxp;
+ uint64_t txb;
+ uint64_t txp;
};
struct conn_entry {
@@ -190,7 +193,7 @@ static int init_file(char *path, int esize)
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)
@@ -296,7 +299,7 @@ static void iw_close(void *iw)
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];
@@ -316,11 +319,11 @@ static int update_ifstat(
}
}
- e.time = htonl(time(NULL));
- e.rxb = htonl(rxb);
- e.rxp = htonl(rxp);
- e.txb = htonl(txb);
- e.txp = htonl(txp);
+ e.time = htobe32(time(NULL));
+ e.rxb = htobe64(rxb);
+ e.rxp = htobe64(rxp);
+ e.txb = htobe64(txb);
+ e.txp = htobe64(txp);
return update_file(path, &e, sizeof(struct traffic_entry));
}
@@ -346,8 +349,8 @@ static int update_radiostat(
}
}
- e.time = htonl(time(NULL));
- e.rate = htons(rate);
+ e.time = htobe32(time(NULL));
+ e.rate = htobe16(rate);
e.rssi = rssi;
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.udp = htonl(udp);
- e.tcp = htonl(tcp);
- e.other = htonl(other);
+ e.time = htobe32(time(NULL));
+ e.udp = htobe32(udp);
+ e.tcp = htobe32(tcp);
+ e.other = htobe32(other);
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.load1 = htons(load1);
- e.load5 = htons(load5);
- e.load15 = htons(load15);
+ e.time = htobe32(time(NULL));
+ e.load1 = htobe16(load1);
+ e.load5 = htobe16(load5);
+ e.load15 = htobe16(load15);
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)
{
FILE *info;
- uint32_t rxb, txb, rxp, txp;
+ uint64_t rxb, txb, rxp, txp;
uint32_t udp, tcp, other;
uint16_t rate;
uint8_t rssi, noise;
@@ -521,7 +524,7 @@ static int run_daemon(void)
if (strstr(line, "TIME_WAIT"))
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 ")))
continue;
@@ -610,11 +613,11 @@ static int run_dump_ifname(const char *ifname)
if (!e->time)
continue;
- printf("[ %u, %u, %" PRIu32
- ", %u, %u ]%s\n",
- ntohl(e->time),
- ntohl(e->rxb), ntohl(e->rxp),
- ntohl(e->txb), ntohl(e->txp),
+ printf("[ %" PRIu32 ", %" PRIu64 ", %" PRIu64
+ ", %" PRIu64 ", %" PRIu64 " ]%s\n",
+ be32toh(e->time),
+ be64toh(e->rxb), be64toh(e->rxp),
+ be64toh(e->txb), be64toh(e->txp),
((i + sizeof(struct traffic_entry)) < m.size) ? "," : "");
}
@@ -646,9 +649,9 @@ static int run_dump_radio(const char *ifname)
if (!e->time)
continue;
- printf("[ %u, %d, %d, %d ]%s\n",
- ntohl(e->time),
- e->rate, e->rssi, e->noise,
+ printf("[ %" PRIu32 ", %" PRIu16 ", %" PRIu8 ", %" PRIu8 " ]%s\n",
+ be32toh(e->time),
+ be16toh(e->rate), e->rssi, e->noise,
((i + sizeof(struct radio_entry)) < m.size) ? "," : "");
}
@@ -680,9 +683,9 @@ static int run_dump_conns(void)
if (!e->time)
continue;
- printf("[ %u, %u, %u, %u ]%s\n",
- ntohl(e->time), ntohl(e->udp),
- ntohl(e->tcp), ntohl(e->other),
+ printf("[ %" PRIu32 ", %" PRIu32 ", %" PRIu32 ", %" PRIu32 " ]%s\n",
+ be32toh(e->time), be32toh(e->udp),
+ be32toh(e->tcp), be32toh(e->other),
((i + sizeof(struct conn_entry)) < m.size) ? "," : "");
}
@@ -714,9 +717,9 @@ static int run_dump_load(void)
if (!e->time)
continue;
- printf("[ %u, %u, %u, %u ]%s\n",
- ntohl(e->time),
- ntohs(e->load1), ntohs(e->load5), ntohs(e->load15),
+ printf("[ %" PRIu32 ", %" PRIu16 ", %" PRIu16 ", %" PRIu16 " ]%s\n",
+ be32toh(e->time),
+ be16toh(e->load1), be16toh(e->load5), be16toh(e->load15),
((i + sizeof(struct load_entry)) < m.size) ? "," : "");
}