diff options
author | Chieh-Min Wang <chiehmin18@gmail.com> | 2017-08-21 22:38:26 +0800 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2017-08-24 16:52:14 +0200 |
commit | d2849d189b0e6703e892fa8074477de07f4723e9 (patch) | |
tree | 24c54ef77f2196549771a098493c060166efa1a5 /src/conntrack.c | |
parent | 37cc7f0d7fcc387b234cf10036cab04408293787 (diff) |
conntrack: Show multiple CPUs stats from proc
When read cpu conntrack stats from /proc/net/stat/nf_conntrack,
it only shows stats from cpu0.
This patch list all cpus' conntrack stats like what `nfexp_stats_cb` did.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/conntrack.c')
-rw-r--r-- | src/conntrack.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/conntrack.c b/src/conntrack.c index 8d19cca..06f60e8 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -1794,6 +1794,7 @@ static int display_proc_conntrack_stats(void) char buf[4096], *token, *nl; char output[CT_STATS_ENTRIES_MAX][CT_STATS_STRING_MAX]; unsigned int value[CT_STATS_ENTRIES_MAX], i, max; + int cpu; fd = fopen(CT_STATS_PROC, "r"); if (fd == NULL) @@ -1817,24 +1818,25 @@ static int display_proc_conntrack_stats(void) } max = i; - if (fgets(buf, sizeof(buf), fd) == NULL) { - ret = -1; - goto out_err; - } - - nl = strchr(buf, '\n'); - while (nl != NULL) { - *nl = '\0'; + for (cpu = 0; fgets(buf, sizeof(buf), fd) != NULL; cpu++) { nl = strchr(buf, '\n'); - } - token = strtok(buf, " "); - for (i=0; token != NULL && i<CT_STATS_ENTRIES_MAX; i++) { - value[i] = (unsigned int) strtol(token, (char**) NULL, 16); - token = strtok(NULL, " "); - } + while (nl != NULL) { + *nl = '\0'; + nl = strchr(buf, '\n'); + } + token = strtok(buf, " "); + for (i = 0; token != NULL && i < CT_STATS_ENTRIES_MAX; i++) { + value[i] = (unsigned int) strtol(token, (char**) NULL, 16); + token = strtok(NULL, " "); + } - for (i=0; i<max; i++) - printf("%-10s\t\t%-8u\n", output[i], value[i]); + printf("cpu=%-4u\t", cpu); + for (i = 0; i < max; i++) + printf("%s=%u ", output[i], value[i]); + printf("\n"); + } + if (cpu == 0) + ret = -1; out_err: fclose(fd); |