From: Stephen Hemminger <sthem...@microsoft.com>

The slabinfo names changed years ago, and ss statistics were broken.
This changes to use current slab names and handle TCP IPv6.

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 misc/ss.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 97304cd8abfc..66c767cc415b 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -742,12 +742,12 @@ static int get_slabstat(struct slabstat *s)
 {
        char buf[256];
        FILE *fp;
-       int cnt;
+       int *stats = (int *) s;
        static int slabstat_valid;
        static const char * const slabstat_ids[] = {
-               "sock",
-               "tcp_tw_bucket",
-               "tcp_open_request",
+               "sock_inode_cache",
+               "tw_sock_TCP",
+               "request_sock_TCP",
        };
 
        if (slabstat_valid)
@@ -759,24 +759,23 @@ static int get_slabstat(struct slabstat *s)
        if (!fp)
                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;
+               int i, v;
 
                for (i = 0; i < ARRAY_SIZE(slabstat_ids); i++) {
-                       if (memcmp(buf, slabstat_ids[i], 
strlen(slabstat_ids[i])) == 0) {
-                               sscanf(buf, "%*s%d", ((int *)s) + i);
-                               cnt--;
+                       if (memcmp(buf, slabstat_ids[i], 
strlen(slabstat_ids[i])) != 0)
+                               continue;
+
+                       if (sscanf(buf, "%*s%d", &v) == 1) {
+                               stats[i] += v;
                                break;
                        }
                }
-               if (cnt <= 0)
-                       break;
        }
 
        slabstat_valid = 1;
-- 
2.17.0

Reply via email to