summaryrefslogtreecommitdiffstats
path: root/misc/ifstat.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-17 14:59:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-17 14:59:00 +0000
commitfefb35b1e2e9e60637e9cbdd2a44f716054a5208 (patch)
treeb8b59752343c1f91cd1f23afffc2e6a753bff6c7 /misc/ifstat.c
parentAdding upstream version 6.8.0. (diff)
downloadiproute2-fefb35b1e2e9e60637e9cbdd2a44f716054a5208.tar.xz
iproute2-fefb35b1e2e9e60637e9cbdd2a44f716054a5208.zip
Adding upstream version 6.9.0.upstream/6.9.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/ifstat.c')
-rw-r--r--misc/ifstat.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/misc/ifstat.c b/misc/ifstat.c
index 7290109..9b93ded 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -51,7 +51,7 @@ int sub_type;
char info_source[128];
int source_mismatch;
-#define MAXS (sizeof(struct rtnl_link_stats)/sizeof(__u32))
+#define MAXS (sizeof(struct rtnl_link_stats64)/sizeof(__u64))
#define NO_SUB_TYPE 0xffff
struct ifstat_ent {
@@ -60,7 +60,7 @@ struct ifstat_ent {
int ifindex;
unsigned long long val[MAXS];
double rate[MAXS];
- __u32 ival[MAXS];
+ __u64 ival[MAXS];
};
static const char *stats[MAXS] = {
@@ -74,19 +74,25 @@ static const char *stats[MAXS] = {
"tx_dropped",
"multicast",
"collisions",
+
"rx_length_errors",
"rx_over_errors",
"rx_crc_errors",
"rx_frame_errors",
"rx_fifo_errors",
"rx_missed_errors",
+
"tx_aborted_errors",
"tx_carrier_errors",
"tx_fifo_errors",
"tx_heartbeat_errors",
"tx_window_errors",
+
"rx_compressed",
- "tx_compressed"
+ "tx_compressed",
+ "rx_nohandler",
+
+ "rx_otherhost_dropped",
};
struct ifstat_ent *kern_db;
@@ -134,6 +140,10 @@ static int get_nlmsg_extended(struct nlmsghdr *m, void *arg)
n->ifindex = ifsm->ifindex;
n->name = strdup(ll_index_to_name(ifsm->ifindex));
+ if (!n->name) {
+ free(n);
+ return -1;
+ }
if (sub_type == NO_SUB_TYPE) {
memcpy(&n->val, RTA_DATA(tb[filter_type]), sizeof(n->val));
@@ -174,7 +184,7 @@ static int get_nlmsg(struct nlmsghdr *m, void *arg)
return 0;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
- if (tb[IFLA_IFNAME] == NULL || tb[IFLA_STATS] == NULL)
+ if (tb[IFLA_IFNAME] == NULL)
return 0;
n = malloc(sizeof(*n));
@@ -182,10 +192,30 @@ static int get_nlmsg(struct nlmsghdr *m, void *arg)
errno = ENOMEM;
return -1;
}
+
n->ifindex = ifi->ifi_index;
n->name = strdup(RTA_DATA(tb[IFLA_IFNAME]));
- memcpy(&n->ival, RTA_DATA(tb[IFLA_STATS]), sizeof(n->ival));
+ if (!n->name) {
+ free(n);
+ return -1;
+ }
+
memset(&n->rate, 0, sizeof(n->rate));
+
+ if (tb[IFLA_STATS64]) {
+ memcpy(&n->ival, RTA_DATA(tb[IFLA_STATS64]), sizeof(n->ival));
+ } else if (tb[IFLA_STATS]) {
+ __u32 *stats = RTA_DATA(tb[IFLA_STATS]);
+
+ /* expand 32 bit values to 64 bit */
+ for (i = 0; i < MAXS; i++)
+ n->ival[i] = stats[i];
+ } else {
+ /* missing stats? */
+ free(n);
+ return 0;
+ }
+
for (i = 0; i < MAXS; i++)
n->val[i] = n->ival[i];
n->next = kern_db;
@@ -379,10 +409,10 @@ static void format_rate(FILE *fp, const unsigned long long *vals,
fprintf(fp, "%8llu ", vals[i]);
if (rates[i] > mega) {
- sprintf(temp, "%uM", (unsigned int)(rates[i]/mega));
+ snprintf(temp, sizeof(temp), "%uM", (unsigned int)(rates[i]/mega));
fprintf(fp, "%-6s ", temp);
} else if (rates[i] > kilo) {
- sprintf(temp, "%uK", (unsigned int)(rates[i]/kilo));
+ snprintf(temp, sizeof(temp), "%uK", (unsigned int)(rates[i]/kilo));
fprintf(fp, "%-6s ", temp);
} else
fprintf(fp, "%-6u ", (unsigned int)rates[i]);
@@ -400,10 +430,10 @@ static void format_pair(FILE *fp, const unsigned long long *vals, int i, int k)
fprintf(fp, "%8llu ", vals[i]);
if (vals[k] > giga) {
- sprintf(temp, "%uM", (unsigned int)(vals[k]/mega));
+ snprintf(temp, sizeof(temp), "%uM", (unsigned int)(vals[k]/mega));
fprintf(fp, "%-6s ", temp);
} else if (vals[k] > mega) {
- sprintf(temp, "%uK", (unsigned int)(vals[k]/kilo));
+ snprintf(temp, sizeof(temp), "%uK", (unsigned int)(vals[k]/kilo));
fprintf(fp, "%-6s ", temp);
} else
fprintf(fp, "%-6u ", (unsigned int)vals[k]);
@@ -675,7 +705,7 @@ static void server_loop(int fd)
p.fd = fd;
p.events = p.revents = POLLIN;
- sprintf(info_source, "%d.%lu sampling_interval=%d time_const=%d",
+ snprintf(info_source, sizeof(info_source), "%d.%lu sampling_interval=%d time_const=%d",
getpid(), (unsigned long)random(), scan_interval/1000, time_constant/1000);
load_info();
@@ -893,7 +923,7 @@ int main(int argc, char *argv[])
sun.sun_family = AF_UNIX;
sun.sun_path[0] = 0;
- sprintf(sun.sun_path+1, "ifstat%d", getuid());
+ snprintf(sun.sun_path + 1, sizeof(sun.sun_path) - 1, "ifstat%d", getuid());
if (scan_interval > 0) {
if (time_constant == 0)