Commit f1b39e1b authored by Vadim Kochan's avatar Vadim Kochan Committed by Stephen Hemminger

ss: Unify details info output:ino,uid,sk

Signed-off-by: default avatarVadim Kochan <vadim4j@gmail.com>
parent 2d791bc8
......@@ -673,6 +673,11 @@ static inline char *sock_addr_get_str(const inet_prefix *prefix)
return tmp;
}
static unsigned long cookie_sk_get(uint32_t *cookie)
{
return (((unsigned long)cookie[1] << 31) << 1) | cookie[0];
}
static const char *sstate_name[] = {
"UNKNOWN",
[SS_ESTABLISHED] = "ESTAB",
......@@ -776,6 +781,15 @@ static void sock_state_print(struct sockstat *s, const char *sock_name)
printf("%-6d %-6d ", s->rq, s->wq);
}
static void sock_details_print(struct sockstat *s)
{
if (s->uid)
printf(" uid:%u", s->uid);
printf(" ino:%u", s->ino);
printf(" sk:%llx", s->sk);
}
static const char *tmr_name[] = {
"off",
"on",
......@@ -1748,10 +1762,7 @@ static int tcp_show_line(char *line, const struct filter *f, int family)
tcp_timer_print(&s);
if (show_details) {
if (s.ss.uid)
printf(" uid:%u", (unsigned)s.ss.uid);
printf(" ino:%u", s.ss.ino);
printf(" sk:%llx", s.ss.sk);
sock_details_print(&s.ss);
if (opt[0])
printf(" opt:\"%s\"", opt);
}
......@@ -1952,15 +1963,16 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
s.state = r->idiag_state;
s.local.family = s.remote.family = r->idiag_family;
s.lport = ntohs(r->id.idiag_sport);
s.rport = ntohs(r->id.idiag_dport);
s.wq = r->idiag_wqueue;
s.rq = r->idiag_rqueue;
s.ino = r->idiag_inode;
s.uid = r->idiag_uid;
s.iface = r->id.idiag_if;
s.state = r->idiag_state;
s.local.family = s.remote.family = r->idiag_family;
s.lport = ntohs(r->id.idiag_sport);
s.rport = ntohs(r->id.idiag_dport);
s.wq = r->idiag_wqueue;
s.rq = r->idiag_rqueue;
s.ino = r->idiag_inode;
s.uid = r->idiag_uid;
s.iface = r->id.idiag_if;
s.sk = cookie_sk_get(&r->id.idiag_cookie[0]);
if (s.local.family == AF_INET) {
s.local.bytelen = s.remote.bytelen = 4;
......@@ -1986,13 +1998,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
}
if (show_details) {
if (r->idiag_uid)
printf(" uid:%u", (unsigned)r->idiag_uid);
printf(" ino:%u", r->idiag_inode);
printf(" sk:");
if (r->id.idiag_cookie[1] != 0)
printf("%08x", r->id.idiag_cookie[1]);
printf("%08x", r->id.idiag_cookie[0]);
sock_details_print(&s);
if (tb[INET_DIAG_SHUTDOWN]) {
unsigned char mask;
mask = *(__u8 *)RTA_DATA(tb[INET_DIAG_SHUTDOWN]);
......@@ -2357,14 +2363,8 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
inet_stats_print(&s, IPPROTO_UDP);
if (show_details) {
if (s.uid)
printf(" uid=%u", (unsigned)s.uid);
printf(" ino=%u", s.ino);
printf(" sk=%llx", s.sk);
if (opt[0])
printf(" opt:\"%s\"", opt);
}
if (show_details && opt[0])
printf(" opt:\"%s\"", opt);
printf("\n");
return 0;
......@@ -2786,6 +2786,9 @@ static int packet_stats_print(struct sockstat *s, const struct filter *f)
}
}
if (show_details)
sock_details_print(s);
return 0;
}
......@@ -2808,6 +2811,7 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
stat.prot = r->pdiag_num;
stat.ino = r->pdiag_ino;
stat.state = SS_CLOSE;
stat.sk = cookie_sk_get(&r->pdiag_cookie[0]);
if (tb[PACKET_DIAG_MEMINFO]) {
__u32 *skmeminfo = RTA_DATA(tb[PACKET_DIAG_MEMINFO]);
......@@ -2819,21 +2823,12 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
stat.lport = stat.iface = pinfo->pdi_index;
}
if (tb[PACKET_DIAG_UID])
stat.uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]);
if (packet_stats_print(&stat, f))
return 0;
if (show_details) {
__u32 uid = 0;
if (tb[PACKET_DIAG_UID])
uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]);
printf(" ino=%u uid=%u sk=", r->pdiag_ino, uid);
if (r->pdiag_cookie[1] != 0)
printf("%08x", r->pdiag_cookie[1]);
printf("%08x", r->pdiag_cookie[0]);
}
if (show_bpf && tb[PACKET_DIAG_FILTER]) {
struct sock_filter *fil =
RTA_DATA(tb[PACKET_DIAG_FILTER]);
......@@ -2890,9 +2885,6 @@ static int packet_show_line(char *buf, const struct filter *f, int fam)
if (packet_stats_print(&stat, f))
return 0;
if (show_details) {
printf(" ino=%u uid=%u sk=%llx", ino, uid, sk);
}
printf("\n");
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment