Commit Graph

138 Commits

Author SHA1 Message Date
willy tarreau
0ee9052f1b fix "ss -p" segfaults
I've updated Jose's patch to make it slightly simpler (eg: calloc instead
of malloc+memset), and ported it to 4.2.0 which requires it as well, and
attached it to this e-mail.

I can confirm that with this patch 4.1.1 doesn't segfault on me anymore.
The commit message should be reworked I guess though everything's in it
and I didn't want to modify his description.

Can it be merged as-is or should I reword the commit message and reference
Jose as the fix reporter ? We should not let this bug live forever.

From: "j.ps@openmailbox.org" <j.ps@openmailbox.org>

Essentially all that is needed to get rid of this issue is the
addition of:

    memset(u, 0, sizeof(*u));

after:

    if (!(u = malloc(sizeof(*u))))
            break;

Also patched some other situations (strcpy and sprintf uses) that
potentially produce the same results.

Signed-off-by: Jose P Santos <j.ps@openmailbox.org>

[ wt: made Jose's patch slightly simpler, all credits to him for the diag ]
Signed-off-by: Willy Tarreau <w@1wt.eu>
2015-10-12 09:49:06 -07:00
Dan Webster
a8e35427fb ss: fix file-based filtering segfault
Commit 1527a17 introduced a change where the second of two ssfilter_parse()
calls in ss.c was moved outside of a conditional block (ss.c: ~3575). This
commit enabled the parsing of services, such as 'sport = :ssh', but
inadvertently broke the '-F' file-based filtering:
2015-09-25 12:36:43 -07:00
Mike Saal
4fcfb6bc71 ss format bug
Hi:

I found a formatting bug in the 4.1.1 ss command. The following line was
incorrectly output due to passing a negative length to printf() when
displaying the local address. In this instance hostapd does a "bind to
device" on cdreth0 and then does a udp "in address any" port 67 bind.
Please note the whitespace between the '*' and ' %cdreth0:67'

    'udp UNCONN 0 0 ** %cdreth0:67* *:* users:(("hostapd",pid=19241,fd=5))'

Attached is my patch for the bug fix, it might be prudent to add more
guard code looking for negative length format codes.

Sincerely, Mike
2015-09-09 08:17:42 -07:00
Phil Sutter
a02371fb38 misc/ss: fix memory leak in user_ent_hash_build()
Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-08-12 09:23:47 -07:00
Phil Sutter
b95d28c380 misc/ss: add missing fclose() calls
Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-08-12 09:23:47 -07:00
Phil Sutter
532ca40a52 misc/ss: simplify buffer realloc, fix checking realloc failure
Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-08-12 09:23:47 -07:00
Phil Sutter
e0dce0e5dc misc/ss: avoid NULL pointer dereference
This was working before, but only if realloc a) succeeded and b) did not
move the buffer to a different location. ''**buf = **new_buf' then
writes the value of *new_buf's first field into that of *buf.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-08-12 09:23:47 -07:00
Phil Sutter
7f9dddbe7d misc/ss: don't imply -a when -A was specified
Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-08-10 11:23:39 -07:00
Vadim Kochan
99bb68ff66 ss: fix crash when dump stats from /proc with '-p'
It really partially reverts:

    ec4d0d8a9d (ss: Replace unixstat struct by new sockstat struct)

but adds few fields (name & peer_name) from removed unixstat to sockstat struct to easy
return original code.

Fixes: ec4d0d8a9d (ss: Replace unixstat struct by new sockstat struct)
Reported-by: Marc Dietrich <marvin24@gmx.de>
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-07-21 10:53:19 -07:00
Stephen Hemminger
92de1c2c82 remove unnecessary checks for NULL before free
Since free(NULL) is a no-op, it is safe to remove unnecesary
if checks.
2015-07-21 10:49:54 -07:00
Nikolay Aleksandrov
235c445347 ss: fix display of raw sockets
After commit 8250bc9ff4 ("ss: Unify inet sockets output") raw sockets
are displayed as udp because dgram_show_line() is used for both and
thus IPPROTO_UDP is used for both so proto_name() returns "udp".
Fix this by checking dg_proto which is set according to the caller of
dgram_show_line().

Reported-by: Miha Marolt <miham@beyondsemi.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
2015-07-20 14:57:47 -07:00
Phil Sutter
f32dc7467f ss: print value of IPV6_V6ONLY socket option if set
If available and set, print 'v6only:1' for AF_INET6 sockets upon request
of extended information. For IPv6 sockets bound to in6addr_any, this is
the only way to determine if they will also accept IPv4 requests or not.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-06-26 00:13:47 -04:00
Craig Gallek
6885e3bf8e ss: Include -E option for socket destroy events
Use the IPv4/IPv6/TCP/UDP multicast groups of NETLINK_SOCK_DIAG
to filter and display socket statistics as they are destroyed.

Kernel support patch series: 24029a3603cfa633e8bc2b3fb3e48e76c497831d

Signed-off-by: Craig Gallek <kraig@google.com>
2015-06-26 00:13:47 -04:00
Stephen Hemminger
69be46c562 Merge branch 'master' into net-next 2015-06-26 00:04:04 -04:00
Craig Gallek
ecb435eacd ss: add support for segs_in and segs_out
Two new tcp_info fields: tcpi_segs_in and tcpi_segs_out.
(2efd055c53c06b7e89c167c98069bab9afce7e59)

~: ss -ti src :22
	 cubic wscale:7,6 rto:201 rtt:0.244/0.012 ato:40 mss:1418 cwnd:21 bytes_acked:80605 bytes_received:20491 segs_out:414 segs_in:600 send 976.3Mbps lastsnd:23 lastrcv:23 lastack:22 pacing_rate 1952.7Mbps rcv_rtt:98 rcv_space:28960

Signed-off-by: Craig Gallek <kraig@google.com>
Reviewed-by: Marcelo Ricardo Leitner <mleitner@redhat.com>
2015-06-25 23:50:15 -04:00
Maciej Żenczykowski
bbd303d183 iproute2: misc/ss.c - fix run_ssfilter af_packet when protocol == 0
s->local.data is a pointer to a field of a non-NULL struct, and hence
cannot be NULL, thus comparing it to 0 is always false, and thus the
return is always false.

Presumably this was meant to be a check whether s->local.data[0] (which
I believe stores af_packet protocol) is 0, ie. ANY.

Change-Id: Ia232f5b06ce081e3b2fb6338f1a709cd94e03ae5
Fixes:
  ss.c:1018:37: error: comparison of array 's->local.data' equal to a null pointer is always false [-Werror,-Wtautological-pointer-compare]
    return s->lport == 0 && s->local.data == 0;
                            ~~~~~~~~~^~~~    ~
  1 error generated.
2015-06-25 08:52:06 -04:00
Stephen Hemminger
f975059a51 Merge branch 'master' into net-next 2015-06-25 08:01:51 -04:00
Eric Dumazet
518af1e0b1 ss: do not bindly dump two families
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>
2015-06-24 23:11:33 -04:00
Eric Dumazet
22588a0e65 ss: speedup resolve_service()
Lets implement a full cache with proper hash table, memory got cheaper
these days.

Before :

$ time ss -t | wc -l
529678

real	0m22.708s
user	0m19.591s
sys	0m2.969s

After :

$ time ss -t | wc -l
528291

real	0m5.078s
user	0m4.099s
sys	0m0.985s

Signed-off-by: Eric Dumazet <edumazet@google.com>
2015-06-24 23:11:33 -04:00
Eric Dumazet
d2055ea597 ss: Fix allocation of cong control alg name
On Fri, 2015-05-29 at 13:30 +0300, Vadim Kochan wrote:
> From: Vadim Kochan <vadim4j@gmail.com>
>
> Use strdup instead of malloc, and get rid of bad strcpy.
>
> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
> ---
>  misc/ss.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/misc/ss.c b/misc/ss.c
> index 347e3a1..a719466 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1908,8 +1908,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
>
>  		if (tb[INET_DIAG_CONG]) {
>  			const char *cong_attr = rta_getattr_str(tb[INET_DIAG_CONG]);
> -			s.cong_alg = malloc(strlen(cong_attr + 1));
> -			strcpy(s.cong_alg, cong_attr);
> +			s.cong_alg = strdup(cong_attr);
>  		}
>
>  		if (TCPI_HAS_OPT(info, TCPI_OPT_WSCALE)) {

I doubt TCP_CA_NAME_MAX will ever change in the kernel : 16 bytes.

Its typically "cubic" and less than 8 bytes.

Using 8 bytes to point to a malloc(8) is a waste.

Please remove the memory allocation, or store the pointer, since
tcp_show_info() does the malloc()/free() before return.
2015-06-24 23:11:33 -04:00
Eric Dumazet
1a4dda7103 ss: add support for bytes_acked & bytes_received
tcp_info has 2 new fields : bytes_acked & bytes_received

$ ss -ti src :22
...
	 cubic wscale:7,6 rto:234 rtt:33.199/17.225 ato:17.225 mss:1418 cwnd:9
ssthresh:9 send 3.1Mbps lastsnd:3 lastrcv:4 lastack:193
bytes_acked:188396 bytes_received:13639 pacing_rate 6.2Mbps unacked:1
retrans:0/4 reordering:4 rcv_rtt:47.25 rcv_space:28960

Signed-off-by: Eric Dumazet <edumazet@google.com>
2015-05-21 15:21:04 -07:00
Vadim Kochan
2631b85666 ss: Show more info (ring,fanout) for packet socks
Print such info like version, tx/rx ring, fanout for
packet sockets when '-e' option was specified.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-05-21 14:47:44 -07:00
Eric Dumazet
3bf5445c5e ss: dctcp changes
Missing space before dctcp: markers.

With dctcp, cwnd=2 is pretty common, just display cwnd value even
if cwnd has this value, it makes parsing easier.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
2015-05-11 09:16:43 -07:00
Eric Dumazet
656e8fdd2d ss: small optim in tcp_show_info()
Kernel can give us smaller tcp_info than our.

We copy the kernel provided structure and fill with 0
the remaining part.

Lets clear only the missing part to save some cycles, as we intend to
slightly increase tcp_info size in the future.

Signed-off-by: Eric Dumazet <edumazet@google.com>
2015-05-11 09:15:08 -07:00
Vadim Kochan
57ff5a1096 ss: Fix wrong filter behaviour
Fixed applying family & socket type filters.
It was not possible to select UDP & UNIX sockets together.

Now selected families are ORed.

The problem was that filters were combined by AND.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Reported-By: Mihai Moldovan <ionic@ionic.de>
2015-05-04 08:58:47 -07:00
Eric Dumazet
2e7e805d0a ss: better 32bit support
Socket cookies are 64bit, even if ss happens to be
a 32bit binary, running on a 64 bit host.

Signed-off-by: Eric Dumazet <edumazet@google.com>
2015-03-15 12:11:43 -07:00
Vadim Kochan
7871f7dbf0 ss: Allow to specify sport/dport without ':'
Ugly change but it allows to specify sport/dport w/o ':'

    # ss dport = 80 and sport = 44862

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-03-15 12:11:42 -07:00
Hagen Paul Pfeifer
b5024ee1ed ss: group DCTCP socket statistics
Keep ss output consistent and format DCTCP socket statistics similar to skmen
and timer where a group of logical values are grouped by brackets. This makes
parser scripts *and* humans more happy.

Current output of 'ss -inetm dst :80':
ESTAB       0      0 192.168.11.14:55511 173.194.66.189:443
        timer:(keepalive,14sec,0) uid:1000 ino:428768
        sk:ffff88020ceb5b00 <-> skmem:(r0,rb372480,t0,tb87040,f0,w0,o0,bl0)
        ts sack wscale:7,7 rto:250 rtt:49.225/20.837 ato:40 mss:1408 cwnd:10
        ce_state 23 alpha 23 ab_ecn 23 ab_tot 23 send 2.3Mbps
        lastsnd:121026 lastrcv:121026 lastack:30850 pacing_rate 4.6Mbps
        retrans:0/2 rcv_rtt:40.416 rcv_space:2920

New grouped output:
ESTAB       0      0 192.168.11.14:55511 173.194.66.189:443
        timer:(keepalive,14sec,0) uid:1000 ino:428768
        sk:ffff88020ceb5b00 <-> skmem:(r0,rb372480,t0,tb87040,f0,w0,o0,bl0)
        ts sack wscale:7,7 rto:250 rtt:49.225/20.837 ato:40 mss:1408 cwnd:10
        dctcp(ce_state:23,alpha:23,ab_ecn:23,ab_tot:23) send 2.3Mbps
        lastsnd:121026 lastrcv:121026 lastack:30850 pacing_rate 4.6Mbps
        retrans:0/2 rcv_rtt:40.416 rcv_space:2920

Cc: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
2015-02-24 15:59:44 -08:00
Vadim Kochan
5f24ec0e06 ss: Skip filtered netlink sockets before detailed info
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-24 15:59:44 -08:00
Vadim Kochan
29999b0ff2 ss: Add filter before printing unix stats from Netlink
Detailed info can be printed if filter should not pass
the socket info.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-24 15:59:44 -08:00
Bryton Lee
a221d621bb prevent the read ahead of /proc/slabinfo in ss
Signed-off-by: Bryton Lee <brytonlee01@gmail.com>
2015-02-21 16:41:41 -08:00
Vadim Kochan
11ba90fcbd ss: Fixed wrong tcp ato value from netlink
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
b217df108c ss: Unify socket address output by one generic func
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
f1b39e1bd6 ss: Unify details info output:ino,uid,sk
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
2d791bc87c ss: Unify state socket output:netid, state, rq, wq
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
ec4d0d8a9d ss: Replace unixstat struct by new sockstat struct
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
89f634f917 ss: Replace pktstat struct by new sockstat struct
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
055840f27f ss: Split tcpstap struct to sockstat & tcpstat
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
1527a17ed8 ss: Fix filter expression parser
Seems expression parser did not work correctly some
long time and such simple things did not work too:

    # ss -a '( sport = :ssh )'

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-21 16:40:26 -08:00
Vadim Kochan
95ce04bc86 ss: Show stats from specified network namespace
Added new '-N NSNAME, --net=NSNAME' option to show socket stats
from the specified network namespace name.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-10 15:11:59 -08:00
Vadim Kochan
8250bc9ff4 ss: Unify inet sockets output
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-05 10:16:25 -08:00
Vadim Kochan
db08bdb816 ss: Unify meminfo output
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-05 10:16:25 -08:00
Vadim Kochan
f42a457470 ss: Filter inet dgram sockets with established state by default
As inet dgram sockets (udp, raw) can call connect(...)  - they
might be set in ESTABLISHED state. So keep the original behaviour of
'ss' which filtered them by ESTABLISHED state by default. So:

    $ ss -u

    or

    $ ss -w

Will show only ESTABLISHED UDP sockets by default.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-02-05 10:15:24 -08:00
Vadim Kochan
ff041f1619 ss: Usage filter state names, options alignment
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-01-13 17:29:17 -08:00
Vadim Kochan
ace5cb31b1 ss: Fix case when UDP is printed as ipproto-xxx
When 'ss' prints UDP sockets info together with RAW sockets
e.g.:

    $ ss -a

then UDP sockets are resolved as "ipproto-xxx".

It was caused that dg_proto was set after printing UDP
socket info from netlink. So fixed issue by moving
setting dg_proto before printing info from Netlink.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-01-13 17:29:17 -08:00
Vadim Kochan
9db7bf15e2 ss: Filtering logic changing, with fixes
This patch fixes some filtering combinations issues which does not
work on the 'master' version:

    $ ss -4
    shows inet & unix sockets, instead of only inet sockets

    $ ss -u
    needs to specify 'state closed'

    $ ss src unix:*X11*
    needs to specify '-x' shortcut for UNIX family

    $ ss -A all
    shows only sockets with established states

There might some other issues which was not observed.

Also changed logic for calculating families, socket types and
states filtering. I think that this version is a little simpler
one. Now there are 2 predefined default tables which describes
the following maping:

    family  -> (states, dbs)
    db      -> (states, families)

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-01-07 15:14:19 -08:00
Vadim Kochan
4a0053b606 ss: Unify packet stats output from netlink and proc
Refactored to use one func for output packet stats info
from both /proc and netlink.

Added possibility to get packet stats info from /proc
by setting environment variable PROC_ROOT or PROC_NET_PACKET.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-01-07 15:13:29 -08:00
Vadim Kochan
bf4ceee6ae ss: Unify unix stats output from netlink and proc
Refactored to use one func for output unix stats info
from both /proc and netlink.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2015-01-07 15:13:29 -08:00
Vadim Kochan
486ccd99a0 ss: Use rtnl_dump_filter for inet_show_netlink
Just another refactoring for ss to use rtnl API from lib

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
2014-12-27 10:21:10 -08:00
Stephen Hemminger
3d0b7439df whitespace cleanup
Remove all trailing whitespace and space before tabs.
2014-12-20 15:47:17 -08:00