]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ss: do not bindly dump two families
authorEric Dumazet <edumazet@google.com>
Fri, 29 May 2015 12:37:49 +0000 (05:37 -0700)
committerStephen Hemminger <shemming@brocade.com>
Thu, 25 Jun 2015 03:11:33 +0000 (23:11 -0400)
ss currently dumps IPv4 sockets, then IPv6 sockets from the kernel,
even if -4 or -6 option was given. Filtering in user space then has to
drop all sockets of wrong family. Such a waste of time...

Before :

$ time ss -tn -4 | wc -l
251659

real 0m1.241s
user 0m0.423s
sys 0m0.806s

After:

$ time ss -tn -4 | wc -l
251672

real 0m0.779s
user 0m0.412s
sys 0m0.386s

Signed-off-by: Eric Dumazet <edumazet@google.com>
misc/ss.c

index 68bffe289ba9079c76113e7f05f90e66161a0c7f..1f4a30f7b3798ce9e026b2a44d6f4f435f66340d 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2199,6 +2199,8 @@ static int inet_show_netlink(struct filter *f, FILE *dump_fp, int protocol)
                return -1;
        rth.dump = MAGIC_SEQ;
        rth.dump_fp = dump_fp;
+       if (preferred_family == PF_INET6)
+               family = PF_INET6;
 
 again:
        if ((err = sockdiag_send(family, rth.fd, protocol, f)))
@@ -2211,7 +2213,7 @@ again:
                }
                goto Exit;
        }
-       if (family == PF_INET) {
+       if (family == PF_INET && preferred_family != PF_INET) {
                family = PF_INET6;
                goto again;
        }