[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180224191607.23892-4-stephen@networkplumber.org>
Date: Sat, 24 Feb 2018 11:16:07 -0800
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: ikomyagin@...il.com, Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH iproute2 3/3] ss: update slabinfo names and sum IPv4 and IPv6
For a long time the name of slabs for TCP sockets have changed.
And ss summary was missing them. Also it never handled IPv6.
Change the code to sum values from both protocols.
Also, print error if slabinfo can not be opened.
Typically this is attempt to run 'ss -s' as non-root user
and /proc/slabinfo is now protected.
Reported-by: Igor Komyagin <ikomyagin@...il.com>
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
misc/ss.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index 4c7057198eb2..f98acdba6e24 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -686,15 +686,14 @@ static int get_slabstat(struct slabstat *s)
{
char buf[256];
FILE *fp;
- int cnt;
static bool slabstat_valid;
static const char * const slabstat_ids[] = {
- "sock",
+ "sock_inode_cache",
"tcp_bind_bucket",
- "tcp_tw_bucket",
- "tcp_open_request",
+ "tw_sock_TCP",
+ "request_sock_TCP",
};
- unsigned int *vals = (unsigned int *) s;
+ unsigned int *slabstat_vals = (unsigned int *) s;
if (slabstat_valid)
return 0;
@@ -702,27 +701,29 @@ static int get_slabstat(struct slabstat *s)
memset(s, 0, sizeof(*s));
fp = slabinfo_open();
- if (!fp)
+ if (!fp) {
+ fprintf(stderr, "slabinfo unavailable: %s\n",
+ strerror(errno));
return -1;
-
- cnt = sizeof(*s)/sizeof(int);
+ }
if (!fgets(buf, sizeof(buf), fp)) {
fclose(fp);
return -1;
}
+
while (fgets(buf, sizeof(buf), fp) != NULL) {
int i;
for (i = 0; i < ARRAY_SIZE(slabstat_ids); i++) {
- if (memcmp(buf, slabstat_ids[i], strlen(slabstat_ids[i])) == 0) {
- sscanf(buf, "%*s%u", vals + i);
- cnt--;
- break;
- }
+ unsigned long val;
+
+ if (memcmp(buf, slabstat_ids[i], strlen(slabstat_ids[i])))
+ continue;
+
+ if (sscanf(buf, "%*s%lu", &val))
+ slabstat_vals[i] += val;
}
- if (cnt <= 0)
- break;
}
slabstat_valid = true;
--
2.16.1
Powered by blists - more mailing lists