Commit Graph

249 Commits

Author SHA1 Message Date
Phil Sutter
e469523e8e ss: Drop useless assignment
After '*b = *a', 'b->next' already has the same value as 'a->next'.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2017-08-21 17:12:21 -07:00
Phil Sutter
44448a90ea ss: Skip useless check in parse_hostcond()
The passed 'addr' parameter is dereferenced by caller before and in
parse_hostcond() multiple times before this check, so assume it is
always true.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2017-08-21 17:12:21 -07:00
Phil Sutter
46131577cf ss: Fix potential memleak in unix_stats_print()
Fixes: 2d0e538f3e ("ss: Drop list traversal from unix_stats_print()")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2017-08-18 09:39:52 -07:00
Phil Sutter
4b45ae221e ss: Don't leak fd in tcp_show_netlink_file()
Signed-off-by: Phil Sutter <phil@nwl.cc>
2017-08-18 09:16:59 -07:00
Stephen Hemminger
aba9c23a6e ss: enclose IPv6 address in brackets
Based on patch by Lehner Florian <dev@der-flo.net>

Adds support for RFC2732 IPv6 address format with brackets.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-08-04 12:04:04 -07:00
Stephen Hemminger
9f1370c0e5 netlink route attribute cleanup
Use the new helper functions rta_getattr_u* instead of direct
cast of RTA_DATA().  Where RTA_DATA() is a structure, then remove
the unnecessary cast since RTA_DATA() is void *

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2017-02-24 08:56:38 -08:00
Eric Dumazet
38e6dbc4b3 ss: print tcpi_rcv_mss and tcpi_advmss
tcpi_rcv_mss and tcpi_advmss tcp info fields were not yet reported
by ss.

While adding GRO support to packetdrill, I found this was useful.

Signed-off-by: Eric Dumazet <edumazet@google.com>
2017-02-06 13:50:29 -08:00
Stephen Hemminger
f2df31170f Merge branch 'master' into net-next 2016-12-02 14:19:08 -08:00
Simon Horman
1dd0cca7fa ss: initialise variables outside of for loop
Initialise for loops outside of for loops. GCC flags this as being
out of spec unless C99 or C11 mode is used.

With this change the entire tree appears to compile cleanly with -Wall.

$ gcc --version
gcc (Debian 4.9.2-10) 4.9.2
...
$ make
...
ss.c: In function ‘unix_show_sock’:
ss.c:3128:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
...

Signed-off-by: Simon Horman <simon.horman@netronome.com>
2016-12-02 14:17:09 -08:00
Phil Sutter
039b3620cf ss: unix_show: No need to initialize members of calloc'ed structs
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:47 -08:00
Phil Sutter
b710a72254 ss: Make sstate_namel local to scan_state()
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:47 -08:00
Phil Sutter
1882c0db02 ss: Make sstate_name local to sock_state_print()
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:47 -08:00
Phil Sutter
96d45daa92 ss: Make unix_state_map local to unix_show()
Also make it const, since there won't be any write access happening.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:47 -08:00
Phil Sutter
2f938ce1fa ss: Get rid of single-fielded struct snmpstat
A struct with only a single field does not make much sense. Besides
that, it was used by print_summary() only.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:47 -08:00
Phil Sutter
6b224dad23 ss: Get rid of useless goto in handle_follow_request()
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
b3535dd61d ss: Make slabstat_ids local to get_slabstat()
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
95eafe438a ss: Make some variables function-local
addrp_width and screen_width are used in main() only, so no need to have
them globally available.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
b25bad2ffe ss: Make user_ent_hash_build_init local to user_ent_hash_build()
By having it statically defined, there is no need for it to be global.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
86dfa1be4a ss: Make tmr_name local to tcp_timer_print()
It's used only there, so no need to have it globally defined.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
0cb74a8610 ss: Turn generic_proc_open() wrappers into macros
Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
f25062e9e7 ss: Eliminate unix_use_proc()
This function is used only at a single place anymore, so replace the
call to it by it's content, which makes that specific part of
unix_show() consistent with e.g. tcp_show().

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
2d0e538f3e ss: Drop list traversal from unix_stats_print()
Although this complicates the dedicated procfs-based code path in
unix_show() a bit, it's the only sane way to get rid of unix_show_sock()
output diverging from other socket types in that it prints all socket
details in a new line.

As a side effect, it allows to eliminate all procfs specific code in
the same function.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
5f27ac1db9 ss: introduce proc_ctx_print()
This consolidates identical code in three places. While the function
name is not quite perfect as there is different proc_ctx printing code
in netlink_show_one() as well, I sadly didn't find a more suitable one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
be7e4d20b9 ss: Use sockstat->type in all socket types
Unix sockets used that field already to hold info about the socket type.
By replicating this approach in all other socket types, we can get rid
of protocol parameter in inet_stats_print() and have sock_state_print()
figure things out by itself.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
4519999708 ss: Add missing tab when printing UNIX details
When dumping UNIX sockets and show_details is active but not show_mem
(ss -xne), the socket details are printed without being prefixed by tab.
Fix this by printing the tab character when either one of '-e' or '-m'
has been specified.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
6babc649a9 ss: Drop empty lines in UDP output
When dumping UDP sockets and show_tcpinfo (-i) is active but not
show_mem (-m), print_tcpinfo() does not output anything leading to an
empty line being printed after every socket. Fix this by skipping the
call to print_tcpinfo() and the previous newline printing in that case.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Phil Sutter
36df1a6e92 ss: Mark fall through in arg parsing switch()
As there is a certain chance of overlooking this, better add a comment
to draw readers' attention.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-12-02 14:07:46 -08:00
Yuchung Cheng
b6c7fc61fa ss: print new tcp_info fields: busy, rwnd-limited, sndbuf-limited times
Dump some new fields added to tcp_info in v4.10: tcpi_busy_time,
tcpi_rwnd_limited, tcpi_sndbuf_limited.

Example output for a flow busy for 110ms but never measurably limited by
receive window or send buffer:
   busy:110ms

Example output for a flow usually limited by receive window:
   busy:111ms rwnd_limited:101ms(91.0%)

Example output for a flow sometimes limited by send buffer:
   busy:50ms sndbuf_limited:10ms(20.0%)

Signed-off-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
2016-12-01 11:00:28 -08:00
Neal Cardwell
2f579872fb ss: print new tcp_info fields: delivery_rate and app_limited
Dump the new delivery_rate and delivery_rate_app_limited fields that
were added to tcp_info in Linux v4.9.

Example output:
  pacing_rate 65.7Mbps delivery_rate 62.9Mbps

And for the application-limited case this looks like:
  pacing_rate 1031.1Mbps delivery_rate 87.4Mbps app_limited

Signed-off-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
2016-12-01 11:00:28 -08:00
Cyrill Gorcunov
41fe6c34de ss: Add inet raw sockets information gathering via netlink diag interface
unix, tcp, udp[lite], packet, netlink sockets already support diag
interface for their collection and killing. Implement support
for raw sockets.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
2016-12-01 10:55:56 -08:00
Stephen Hemminger
168d97f97b ss: break really long lines 2016-11-29 11:41:58 -08:00
Phil Sutter
f89d46ad63 ss: Add support for SCTP protocol
This makes use of the sctp_diag interface recently added to the kernel.

Joint work with Xin Long who provided the PoC implementation which I
merely polished up a bit.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-11-29 11:41:57 -08:00
Isaac Boukris
878dadc79d iproute2: ss: escape all null bytes in abstract unix domain socket
Abstract unix domain socket may embed null characters,
these should be translated to '@' when printed by ss the
same way the null prefix is currently being translated.

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
2016-11-12 10:16:24 +03:00
Hangbin Liu
d1f338b318 misc/ss: tcp cwnd should be unsigned
tcp->snd_cwd is a u32, but ss treats it like a signed int. This may
results in negative bandwidth calculations.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: Phil Sutter <phil@nwl.cc>
2016-09-22 16:38:22 -07:00
Lorenzo Colitti
ec75249b14 ss: Support displaying and filtering on socket marks.
This allows the user to dump sockets with a given mark (via
"fwmark = 0x1234/0x1234" or "fwmark = 12345", etc.) , and to
display the socket marks of dumped sockets.

The relevant kernel commits are: d545caca827b ("net: inet: diag:
expose the socket mark to privileged processes.") and
- a52e95abf772 ("net: diag: allow socket bytecode filters to
match socket marks")

Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
2016-09-22 16:34:40 -07:00
Neal Cardwell
2f0f9aef94 ss: output TCP BBR diag information
Dump useful TCP BBR state information from a struct tcp_bbr_info that
was grabbed using the inet_diag API.

We tolerate info that is shorter or longer than expected, in case the
kernel is older or newer than the ss binary. We simply print the
minimum of what is expected from the kernel and what is provided from
the kernel. We use the same trick as that used for struct tcp_info:
when the info from the kernel is shorter than we hoped, we pad the end
with zeroes, and don't print fields if they are zero.

The BBR output looks like:
  bbr:(bw:1.2Mbps,mrtt:18.965,pacing_gain:2.88672,cwnd_gain:2.88672)

The motivation here is to be consistent with DCTCP, which looks like:
  dctcp(ce_state:23,alpha:23,ab_ecn:23,ab_tot:23)

Signed-off-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
2016-09-21 16:29:35 -07:00
Gustavo Zacarias
6b376ebd6e ss: fix build with musl libc
UINT_MAX usage requires limits.h, so include it.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
2016-08-22 10:02:12 -07:00
Phil Sutter
d17b136f7d Use C99 style initializers everywhere
This big patch was compiled by vimgrepping for memset calls and changing
to C99 initializer if applicable. One notable exception is the
initialization of union bpf_attr in tc/tc_bpf.c: changing it would break
for older gcc versions (at least <=3.4.6).

Calls to memset for struct rtattr pointer fields for parse_rtattr*()
were just dropped since they are not needed.

The changes here allowed the compiler to discover some unused variables,
so get rid of them, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
2016-07-20 12:05:24 -07:00
David Ahern
7a4559f67c ss: Add option to suppress header line
Add option to suppress header line. When used the following line
is not shown:
"State  Recv-Q Send-Q     Local Address:Port  Peer Address:Port"

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2016-07-20 11:55:43 -07:00
David Ahern
930d3f2819 ss: Fix support for device filter by index
Support was recently added for device filters. The intent was to allow
the device to be specified by name or index, and using the if%u format
(dev == if5) or the simpler and more intuitive index alone (dev == 5).
The latter case is broken since the index is not saved to the filter
after the strtoul conversion. Further, the tmp variable used for the
conversion shadows another variable used in the function. Fix both.

With this change all 3 variants work as expected:
$ ss -t 'dev == 62'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442

$ ss -t 'dev == mgmt'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      224         10.0.1.3%mgmt:ssh   192.168.0.50:58442

$ ss -t 'dev == if62'
State   Recv-Q Send-Q         Local Address:Port    Peer Address:Port
ESTAB       0      36          10.0.1.3%mgmt:ssh   192.168.0.50:58442

Fixes: 2d29321256 ("ss: Add support to filter on device")
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2016-07-20 11:55:43 -07:00
Phil Sutter
62000e51e0 Use ARRAY_SIZE macro everywhere
This patch was generated by the following semantic patch (a trimmed down
version of what is shipped with Linux sources):

@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)

The only manual adjustment was to include utils.h in misc/nstat.c to make
the macro known there.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-06-29 09:18:18 -07:00
David Ahern
2d29321256 ss: Add support to filter on device
Add support for device names in the filter. Example:

    root@kenny:~# ss -t  'sport == :22 && dev == red'
    State      Recv-Q Send-Q     Local Address:Port      Peer Address:Port
    ESTAB      0      0          10.100.1.2%red:ssh      10.100.1.254:47814
    ESTAB      0      0           2100:1::2%red:ssh        2100:1::64:49406

Since kernel does not support iface in the filter specifying a
device name means all filtering is done in userspace.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2016-06-28 12:09:01 -07:00
David Ahern
376fb86872 ss: Allow ssfilter_bytecompile to return 0
Allow ssfilter_bytecompile to return 0 for filter ops the kernel
does not support. If such an op is in the filter string then all
filtering is done in userspace.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2016-06-28 12:09:01 -07:00
David Ahern
82d73ea03a ss: Refactor inet_show_sock
Extract parsing of sockstat and filter from inet_show_sock.
While moving run_ssfilter into callers of inet_show_sock enable
userspace filtering before the kill.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2016-06-28 12:09:01 -07:00
Martin KaFai Lau
414aeec90f ss: Add tcp_info fields data_segs_in/out
tcp_info fields, data_segs_in and data_segs_out, have been added to the
kernel in commit a44d6eacdaf5 ("tcp: Add RFC4898 tcpEStatsPerfDataSegsOut/In")
since kernel 4.6.

This patch supports those fileds in ss:

ESTAB      801736 360                            face:face:face:face::1:22                                      face:face:face:face::face:46779
         cubic wscale:9,7 rto:223 rtt:22.195/8.202 ato:40 mss:1428 cwnd:11 ssthresh:7 bytes_acked:203649 bytes_received:334034603 segs_out:18513 segs_in:241825 data_segs_out:4192 data_segs_in:241672 send 5.7Mbps lastsnd:2 lastack:3 pacing_rate 6.8Mbps unacked:10 retrans:0/1 rcv_rtt:29.375 rcv_space:1241704 minrtt:0.013

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
2016-06-21 08:48:50 -07:00
Fabien Siron
ebef3174b6 misc/ss: Add family list to -f option in _usage()
Signed-off-by: Fabien Siron <fabien.siron@epita.fr>
2016-06-08 08:36:41 -07:00
Stephen Hemminger
18820bacdc Merge branch 'master' into net-next 2016-05-13 14:48:53 -07:00
subashab@codeaurora.org
b38e740903 ss: Remove unused argument from kill_inet_sock
addr is not used here.

Signed-off-by: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
2016-05-13 14:47:28 -07:00
Eric Dumazet
6df9c7a06a ss: add SK_MEMINFO_DROPS display
SK_MEMINFO_DROPS is added in linux-4.7 for TCP, UDP and SCTP

skmem will display the socket drop count using d prefix as in :

$ ss -tm src :22 | more
State      Recv-Q Send-Q Local Address:Port    Peer Address:Port
ESTAB      0      52     10.246.7.151:ssh      172.20.10.101:50759
	 skmem:(r0,rb8388608,t0,tb8388608,f1792,w2304,o0,bl0,d0)

Signed-off-by: Eric Dumazet <edumazet@google.com>
2016-04-22 10:20:32 -07:00
Eric Dumazet
d9ba887e9d ss: take care of unknown min_rtt
Kernel sets info->tcpi_min_rtt to ~0U when no RTT sample was ever
taken for the session, thus min_rtt is unknown.

Signed-off-by: Eric Dumazet <edumazet@google.com>
2016-04-19 07:56:54 -07:00
Phil Sutter
e56a959e55 ss: Fix accidental state filter override
Passing a filter expression and selecting an address family using the
'-f' flag would overwrite the state filter by accident. Therefore
calling e.g. 'ss -nl -f inet '(sport = :22)' would not only print
listening sockets (as requested by '-l' flag) but connected ones, as
well.

Fix this by reusing the formerly ineffective call to filter_states_set()
to restore the state filter as it was before the call to
filter_af_set().

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-04-19 07:56:53 -07:00
Phil Sutter
9d320e1e92 ss: Drop silly assignment
An expression of the form '(a | b) & b' will evaluate to the value of b
for any value of a or b.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-04-19 07:56:53 -07:00
Phil Sutter
a418e45164 make format_host non-reentrant by default
There are only three users which require it to be reentrant, the rest is
fine without. Instead, provide a reentrant format_host_r() for users
which need it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2016-03-27 10:37:34 -07:00
Stephen Hemminger
acd1e437be misc: fix style issues
More checkpatch spring cleaning
2016-03-21 11:56:36 -07:00
Stephen Hemminger
9e99e49528 ss: display not_sent and min_rtt info
Display new info from net-next kernel.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2016-02-17 17:44:39 -08:00
Lorenzo Colitti
fb2594c183 ss: support closing inet sockets via SOCK_DESTROY.
This patch adds a -K / --kill option to ss that attempts to
forcibly close matching sockets using SOCK_DESTROY.

Because ss typically prints sockets instead of acting on them,
and because the kernel only supports forcibly closing some types
of sockets, the output of -K is as follows:

- If closing the socket succeeds, the socket is printed.
- If the kernel does not support forcibly closing this type of
  socket (e.g., if it's a UDP socket, or a TIME_WAIT socket),
  the socket is silently skipped.
- If an error occurs (e.g., permission denied), the error is
  reported and ss exits.

Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
2016-01-18 11:47:03 -08:00
Phil Sutter
61170fd88d get rid of unnecessary fgets() buffer size limitation
fgets() will read at most size-1 bytes into the buffer and add a
terminating null-char at the end. Therefore it is not necessary to pass
a reduced buffer size when calling it.

This change was generated using the following semantic patch:

@@
identifier buf, fp;
@@
- fgets(buf, sizeof(buf) - 1, fp)
+ fgets(buf, sizeof(buf), fp)

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-11-29 11:48:24 -08:00
Phil Sutter
d572ed4d0a get rid of remaining -Wunused-result warnings
Although not fundamentally necessary to check return codes in these
spots, preventing the warnings will put new ones into focus.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-11-29 11:48:24 -08:00
Phil Sutter
c29d37925a ss: review is_ephemeral()
No need to keep static port boundaries global, they are not used
directly. Keeping them local also allows to safely reduce their names to
the minimum. Assign hardcoded fallback values also if fscanf() fails.
Get rid of unnecessary braces around return parameter.

Instead of more or less duplicating is_ephemeral() in run_ssfilter(),
simply call the function instead.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-11-29 11:48:24 -08:00
Phil Sutter
596307ea3d ss: reduce max indentation level in init_service_resolver()
Exit early or continue on error instead of putting conditional into
conditional to make reading the code a bit easier.

Also, the call to memcpy() can be skipped by initialising prog with the
desired prefix.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-11-29 11:48:24 -08:00
Phil Sutter
f73105ab42 ss: return -1 if an unrecognized option was given
When getopt_long encounters an option which has not been registered, it
returns '?'. React upon that and call usage() instead of help() so ss
returns with a non-zero exit status.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2015-10-18 21:56:55 -07:00
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