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) ...@@ -673,6 +673,11 @@ static inline char *sock_addr_get_str(const inet_prefix *prefix)
return tmp; 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[] = { static const char *sstate_name[] = {
"UNKNOWN", "UNKNOWN",
[SS_ESTABLISHED] = "ESTAB", [SS_ESTABLISHED] = "ESTAB",
...@@ -776,6 +781,15 @@ static void sock_state_print(struct sockstat *s, const char *sock_name) ...@@ -776,6 +781,15 @@ static void sock_state_print(struct sockstat *s, const char *sock_name)
printf("%-6d %-6d ", s->rq, s->wq); 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[] = { static const char *tmr_name[] = {
"off", "off",
"on", "on",
...@@ -1748,10 +1762,7 @@ static int tcp_show_line(char *line, const struct filter *f, int family) ...@@ -1748,10 +1762,7 @@ static int tcp_show_line(char *line, const struct filter *f, int family)
tcp_timer_print(&s); tcp_timer_print(&s);
if (show_details) { if (show_details) {
if (s.ss.uid) sock_details_print(&s.ss);
printf(" uid:%u", (unsigned)s.ss.uid);
printf(" ino:%u", s.ss.ino);
printf(" sk:%llx", s.ss.sk);
if (opt[0]) if (opt[0])
printf(" opt:\"%s\"", opt); printf(" opt:\"%s\"", opt);
} }
...@@ -1961,6 +1972,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol) ...@@ -1961,6 +1972,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
s.ino = r->idiag_inode; s.ino = r->idiag_inode;
s.uid = r->idiag_uid; s.uid = r->idiag_uid;
s.iface = r->id.idiag_if; s.iface = r->id.idiag_if;
s.sk = cookie_sk_get(&r->id.idiag_cookie[0]);
if (s.local.family == AF_INET) { if (s.local.family == AF_INET) {
s.local.bytelen = s.remote.bytelen = 4; s.local.bytelen = s.remote.bytelen = 4;
...@@ -1986,13 +1998,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol) ...@@ -1986,13 +1998,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
} }
if (show_details) { if (show_details) {
if (r->idiag_uid) sock_details_print(&s);
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]);
if (tb[INET_DIAG_SHUTDOWN]) { if (tb[INET_DIAG_SHUTDOWN]) {
unsigned char mask; unsigned char mask;
mask = *(__u8 *)RTA_DATA(tb[INET_DIAG_SHUTDOWN]); 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) ...@@ -2357,14 +2363,8 @@ static int dgram_show_line(char *line, const struct filter *f, int family)
inet_stats_print(&s, IPPROTO_UDP); inet_stats_print(&s, IPPROTO_UDP);
if (show_details) { if (show_details && opt[0])
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); printf(" opt:\"%s\"", opt);
}
printf("\n"); printf("\n");
return 0; return 0;
...@@ -2786,6 +2786,9 @@ static int packet_stats_print(struct sockstat *s, const struct filter *f) ...@@ -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; return 0;
} }
...@@ -2808,6 +2811,7 @@ static int packet_show_sock(const struct sockaddr_nl *addr, ...@@ -2808,6 +2811,7 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
stat.prot = r->pdiag_num; stat.prot = r->pdiag_num;
stat.ino = r->pdiag_ino; stat.ino = r->pdiag_ino;
stat.state = SS_CLOSE; stat.state = SS_CLOSE;
stat.sk = cookie_sk_get(&r->pdiag_cookie[0]);
if (tb[PACKET_DIAG_MEMINFO]) { if (tb[PACKET_DIAG_MEMINFO]) {
__u32 *skmeminfo = RTA_DATA(tb[PACKET_DIAG_MEMINFO]); __u32 *skmeminfo = RTA_DATA(tb[PACKET_DIAG_MEMINFO]);
...@@ -2819,20 +2823,11 @@ static int packet_show_sock(const struct sockaddr_nl *addr, ...@@ -2819,20 +2823,11 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
stat.lport = stat.iface = pinfo->pdi_index; stat.lport = stat.iface = pinfo->pdi_index;
} }
if (packet_stats_print(&stat, f))
return 0;
if (show_details) {
__u32 uid = 0;
if (tb[PACKET_DIAG_UID]) if (tb[PACKET_DIAG_UID])
uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]); stat.uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]);
printf(" ino=%u uid=%u sk=", r->pdiag_ino, uid); if (packet_stats_print(&stat, f))
if (r->pdiag_cookie[1] != 0) return 0;
printf("%08x", r->pdiag_cookie[1]);
printf("%08x", r->pdiag_cookie[0]);
}
if (show_bpf && tb[PACKET_DIAG_FILTER]) { if (show_bpf && tb[PACKET_DIAG_FILTER]) {
struct sock_filter *fil = struct sock_filter *fil =
...@@ -2890,9 +2885,6 @@ static int packet_show_line(char *buf, const struct filter *f, int fam) ...@@ -2890,9 +2885,6 @@ static int packet_show_line(char *buf, const struct filter *f, int fam)
if (packet_stats_print(&stat, f)) if (packet_stats_print(&stat, f))
return 0; return 0;
if (show_details) {
printf(" ino=%u uid=%u sk=%llx", ino, uid, sk);
}
printf("\n"); printf("\n");
return 0; 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