iproute2: ss: add support to expose various inet sockopts
This commit adds support to expose the following inet socket options: -- recverr -- is_icsk -- freebind -- hdrincl -- mc_loop -- transparent -- mc_all -- nodefrag -- bind_address_no_port -- recverr_rfc4884 -- defer_connect with the option --inet-sockopt. The individual option is only shown when set. Signed-off-by: Wei Wang <weiwan@google.com> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
c8eb4b52c1
commit
ad34d5fadb
|
|
@ -379,6 +379,9 @@ Display vsock sockets (alias for -f vsock).
|
||||||
.B \-\-xdp
|
.B \-\-xdp
|
||||||
Display XDP sockets (alias for -f xdp).
|
Display XDP sockets (alias for -f xdp).
|
||||||
.TP
|
.TP
|
||||||
|
.B \-\-inet-sockopt
|
||||||
|
Display inet socket options.
|
||||||
|
.TP
|
||||||
.B \-f FAMILY, \-\-family=FAMILY
|
.B \-f FAMILY, \-\-family=FAMILY
|
||||||
Display sockets of type FAMILY. Currently the following families are
|
Display sockets of type FAMILY. Currently the following families are
|
||||||
supported: unix, inet, inet6, link, netlink, vsock, xdp.
|
supported: unix, inet, inet6, link, netlink, vsock, xdp.
|
||||||
|
|
|
||||||
43
misc/ss.c
43
misc/ss.c
|
|
@ -114,6 +114,7 @@ static int sctp_ino;
|
||||||
static int show_tipcinfo;
|
static int show_tipcinfo;
|
||||||
static int show_tos;
|
static int show_tos;
|
||||||
static int show_cgroup;
|
static int show_cgroup;
|
||||||
|
static int show_inet_sockopt;
|
||||||
int oneline;
|
int oneline;
|
||||||
|
|
||||||
enum col_id {
|
enum col_id {
|
||||||
|
|
@ -3333,6 +3334,41 @@ static int inet_show_sock(struct nlmsghdr *nlh,
|
||||||
out(" cgroup:%s", cg_id_to_path(rta_getattr_u64(tb[INET_DIAG_CGROUP_ID])));
|
out(" cgroup:%s", cg_id_to_path(rta_getattr_u64(tb[INET_DIAG_CGROUP_ID])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (show_inet_sockopt) {
|
||||||
|
if (tb[INET_DIAG_SOCKOPT] && RTA_PAYLOAD(tb[INET_DIAG_SOCKOPT]) >=
|
||||||
|
sizeof(struct inet_diag_sockopt)) {
|
||||||
|
const struct inet_diag_sockopt *sockopt =
|
||||||
|
RTA_DATA(tb[INET_DIAG_SOCKOPT]);
|
||||||
|
if (!oneline)
|
||||||
|
out("\n\tinet-sockopt: (");
|
||||||
|
else
|
||||||
|
out(" inet-sockopt: (");
|
||||||
|
if (sockopt->recverr)
|
||||||
|
out(" recverr");
|
||||||
|
if (sockopt->is_icsk)
|
||||||
|
out(" is_icsk");
|
||||||
|
if (sockopt->freebind)
|
||||||
|
out(" freebind");
|
||||||
|
if (sockopt->hdrincl)
|
||||||
|
out(" hdrincl");
|
||||||
|
if (sockopt->mc_loop)
|
||||||
|
out(" mc_loop");
|
||||||
|
if (sockopt->transparent)
|
||||||
|
out(" transparent");
|
||||||
|
if (sockopt->mc_all)
|
||||||
|
out(" mc_all");
|
||||||
|
if (sockopt->nodefrag)
|
||||||
|
out(" nodefrag");
|
||||||
|
if (sockopt->bind_address_no_port)
|
||||||
|
out(" bind_addr_no_port");
|
||||||
|
if (sockopt->recverr_rfc4884)
|
||||||
|
out(" recverr_rfc4884");
|
||||||
|
if (sockopt->defer_connect)
|
||||||
|
out(" defer_connect");
|
||||||
|
out(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (show_mem || (show_tcpinfo && s->type != IPPROTO_UDP)) {
|
if (show_mem || (show_tcpinfo && s->type != IPPROTO_UDP)) {
|
||||||
if (!oneline)
|
if (!oneline)
|
||||||
out("\n\t");
|
out("\n\t");
|
||||||
|
|
@ -5210,6 +5246,7 @@ static void _usage(FILE *dest)
|
||||||
" -K, --kill forcibly close sockets, display what was closed\n"
|
" -K, --kill forcibly close sockets, display what was closed\n"
|
||||||
" -H, --no-header Suppress header line\n"
|
" -H, --no-header Suppress header line\n"
|
||||||
" -O, --oneline socket's data printed on a single line\n"
|
" -O, --oneline socket's data printed on a single line\n"
|
||||||
|
" --inet-sockopt show various inet socket options\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -A, --query=QUERY, --socket=QUERY\n"
|
" -A, --query=QUERY, --socket=QUERY\n"
|
||||||
" QUERY := {all|inet|tcp|mptcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram|tipc}[,QUERY]\n"
|
" QUERY := {all|inet|tcp|mptcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram|tipc}[,QUERY]\n"
|
||||||
|
|
@ -5299,6 +5336,8 @@ static int scan_state(const char *state)
|
||||||
|
|
||||||
#define OPT_CGROUP 261
|
#define OPT_CGROUP 261
|
||||||
|
|
||||||
|
#define OPT_INET_SOCKOPT 262
|
||||||
|
|
||||||
static const struct option long_opts[] = {
|
static const struct option long_opts[] = {
|
||||||
{ "numeric", 0, 0, 'n' },
|
{ "numeric", 0, 0, 'n' },
|
||||||
{ "resolve", 0, 0, 'r' },
|
{ "resolve", 0, 0, 'r' },
|
||||||
|
|
@ -5341,6 +5380,7 @@ static const struct option long_opts[] = {
|
||||||
{ "xdp", 0, 0, OPT_XDPSOCK},
|
{ "xdp", 0, 0, OPT_XDPSOCK},
|
||||||
{ "mptcp", 0, 0, 'M' },
|
{ "mptcp", 0, 0, 'M' },
|
||||||
{ "oneline", 0, 0, 'O' },
|
{ "oneline", 0, 0, 'O' },
|
||||||
|
{ "inet-sockopt", 0, 0, OPT_INET_SOCKOPT },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -5539,6 +5579,9 @@ int main(int argc, char *argv[])
|
||||||
case 'O':
|
case 'O':
|
||||||
oneline = 1;
|
oneline = 1;
|
||||||
break;
|
break;
|
||||||
|
case OPT_INET_SOCKOPT:
|
||||||
|
show_inet_sockopt = 1;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
case '?':
|
case '?':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue