Commit 055840f2 authored by Vadim Kochan's avatar Vadim Kochan Committed by Stephen Hemminger

ss: Split tcpstap struct to sockstat & tcpstat

Signed-off-by: default avatarVadim Kochan <vadim4j@gmail.com>
parent 1527a17e
...@@ -691,16 +691,7 @@ static const char *sstate_namel[] = { ...@@ -691,16 +691,7 @@ static const char *sstate_namel[] = {
[SS_CLOSING] = "closing", [SS_CLOSING] = "closing",
}; };
struct dctcpstat struct sockstat
{
unsigned int ce_state;
unsigned int alpha;
unsigned int ab_ecn;
unsigned int ab_tot;
bool enabled;
};
struct tcpstat
{ {
inet_prefix local; inet_prefix local;
inet_prefix remote; inet_prefix remote;
...@@ -713,6 +704,20 @@ struct tcpstat ...@@ -713,6 +704,20 @@ struct tcpstat
int refcnt; int refcnt;
unsigned int iface; unsigned int iface;
unsigned long long sk; unsigned long long sk;
};
struct dctcpstat
{
unsigned int ce_state;
unsigned int alpha;
unsigned int ab_ecn;
unsigned int ab_tot;
bool enabled;
};
struct tcpstat
{
struct sockstat ss;
int timer; int timer;
int timeout; int timeout;
int probes; int probes;
...@@ -1000,7 +1005,7 @@ static int unix_match(const inet_prefix *a, const inet_prefix *p) ...@@ -1000,7 +1005,7 @@ static int unix_match(const inet_prefix *a, const inet_prefix *p)
return !fnmatch(pattern, addr, 0); return !fnmatch(pattern, addr, 0);
} }
static int run_ssfilter(struct ssfilter *f, struct tcpstat *s) static int run_ssfilter(struct ssfilter *f, struct sockstat *s)
{ {
switch (f->type) { switch (f->type) {
case SSF_S_AUTO: case SSF_S_AUTO:
...@@ -1487,7 +1492,7 @@ static char *proto_name(int protocol) ...@@ -1487,7 +1492,7 @@ static char *proto_name(int protocol)
return "???"; return "???";
} }
static void inet_stats_print(struct tcpstat *s, int protocol) static void inet_stats_print(struct sockstat *s, int protocol)
{ {
char *buf = NULL; char *buf = NULL;
...@@ -1501,17 +1506,6 @@ static void inet_stats_print(struct tcpstat *s, int protocol) ...@@ -1501,17 +1506,6 @@ static void inet_stats_print(struct tcpstat *s, int protocol)
formatted_print(&s->local, s->lport, s->iface); formatted_print(&s->local, s->lport, s->iface);
formatted_print(&s->remote, s->rport, 0); formatted_print(&s->remote, s->rport, 0);
if (show_options) {
if (s->timer) {
if (s->timer > 4)
s->timer = 5;
printf(" timer:(%s,%s,%d)",
tmr_name[s->timer],
print_ms_timer(s->timeout),
s->retrans);
}
}
if (show_proc_ctx || show_sock_ctx) { if (show_proc_ctx || show_sock_ctx) {
if (find_entry(s->ino, &buf, if (find_entry(s->ino, &buf,
(show_proc_ctx & show_sock_ctx) ? (show_proc_ctx & show_sock_ctx) ?
...@@ -1527,7 +1521,8 @@ static void inet_stats_print(struct tcpstat *s, int protocol) ...@@ -1527,7 +1521,8 @@ static void inet_stats_print(struct tcpstat *s, int protocol)
} }
} }
static int proc_parse_inet_addr(char *loc, char *rem, int family, struct tcpstat *s) static int proc_parse_inet_addr(char *loc, char *rem, int family, struct
sockstat *s)
{ {
s->local.family = s->remote.family = family; s->local.family = s->remote.family = family;
if (family == AF_INET) { if (family == AF_INET) {
...@@ -1658,7 +1653,7 @@ static void tcp_stats_print(struct tcpstat *s) ...@@ -1658,7 +1653,7 @@ static void tcp_stats_print(struct tcpstat *s)
printf(" retrans:%u/%u", s->retrans, s->retrans_total); printf(" retrans:%u/%u", s->retrans, s->retrans_total);
if (s->lost) if (s->lost)
printf(" lost:%u", s->lost); printf(" lost:%u", s->lost);
if (s->sacked && s->state != SS_LISTEN) if (s->sacked && s->ss.state != SS_LISTEN)
printf(" sacked:%u", s->sacked); printf(" sacked:%u", s->sacked);
if (s->fackets) if (s->fackets)
printf(" fackets:%u", s->fackets); printf(" fackets:%u", s->fackets);
...@@ -1670,6 +1665,18 @@ static void tcp_stats_print(struct tcpstat *s) ...@@ -1670,6 +1665,18 @@ static void tcp_stats_print(struct tcpstat *s)
printf(" rcv_space:%d", s->rcv_space); printf(" rcv_space:%d", s->rcv_space);
} }
static void tcp_timer_print(struct tcpstat *s)
{
if (s->timer) {
if (s->timer > 4)
s->timer = 5;
printf(" timer:(%s,%s,%d)",
tmr_name[s->timer],
print_ms_timer(s->timeout),
s->retrans);
}
}
static int tcp_show_line(char *line, const struct filter *f, int family) static int tcp_show_line(char *line, const struct filter *f, int family)
{ {
int rto = 0, ato = 0; int rto = 0, ato = 0;
...@@ -1686,17 +1693,17 @@ static int tcp_show_line(char *line, const struct filter *f, int family) ...@@ -1686,17 +1693,17 @@ static int tcp_show_line(char *line, const struct filter *f, int family)
if (!(f->states & (1 << state))) if (!(f->states & (1 << state)))
return 0; return 0;
proc_parse_inet_addr(loc, rem, family, &s); proc_parse_inet_addr(loc, rem, family, &s.ss);
if (f->f && run_ssfilter(f->f, &s) == 0) if (f->f && run_ssfilter(f->f, &s.ss) == 0)
return 0; return 0;
opt[0] = 0; opt[0] = 0;
n = sscanf(data, "%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %d %d %[^\n]\n", n = sscanf(data, "%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %d %d %[^\n]\n",
&s.state, &s.wq, &s.rq, &s.ss.state, &s.ss.wq, &s.ss.rq,
&s.timer, &s.timeout, &s.retrans, &s.uid, &s.probes, &s.ino, &s.timer, &s.timeout, &s.retrans, &s.ss.uid, &s.probes,
&s.refcnt, &s.sk, &rto, &ato, &s.qack, &s.ss.ino, &s.ss.refcnt, &s.ss.sk, &rto, &ato, &s.qack, &s.cwnd,
&s.cwnd, &s.ssthresh, opt); &s.ssthresh, opt);
if (n < 17) if (n < 17)
opt[0] = 0; opt[0] = 0;
...@@ -1716,13 +1723,16 @@ static int tcp_show_line(char *line, const struct filter *f, int family) ...@@ -1716,13 +1723,16 @@ static int tcp_show_line(char *line, const struct filter *f, int family)
s.ssthresh = s.ssthresh == -1 ? 0 : s.ssthresh; s.ssthresh = s.ssthresh == -1 ? 0 : s.ssthresh;
s.rto = s.rto != 3 * hz ? s.rto / hz : 0; s.rto = s.rto != 3 * hz ? s.rto / hz : 0;
inet_stats_print(&s, IPPROTO_TCP); inet_stats_print(&s.ss, IPPROTO_TCP);
if (show_options)
tcp_timer_print(&s);
if (show_details) { if (show_details) {
if (s.uid) if (s.ss.uid)
printf(" uid:%u", (unsigned)s.uid); printf(" uid:%u", (unsigned)s.ss.uid);
printf(" ino:%u", s.ino); printf(" ino:%u", s.ss.ino);
printf(" sk:%llx", s.sk); printf(" sk:%llx", s.ss.sk);
if (opt[0]) if (opt[0])
printf(" opt:\"%s\"", opt); printf(" opt:\"%s\"", opt);
} }
...@@ -1807,6 +1817,8 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r, ...@@ -1807,6 +1817,8 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
double rtt = 0; double rtt = 0;
struct tcpstat s = {}; struct tcpstat s = {};
s.ss.state = r->idiag_state;
print_skmeminfo(tb, INET_DIAG_SKMEMINFO); print_skmeminfo(tb, INET_DIAG_SKMEMINFO);
if (tb[INET_DIAG_INFO]) { if (tb[INET_DIAG_INFO]) {
...@@ -1916,7 +1928,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol) ...@@ -1916,7 +1928,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
{ {
struct rtattr * tb[INET_DIAG_MAX+1]; struct rtattr * tb[INET_DIAG_MAX+1];
struct inet_diag_msg *r = NLMSG_DATA(nlh); struct inet_diag_msg *r = NLMSG_DATA(nlh);
struct tcpstat s = {}; struct sockstat s = {};
parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1), parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
...@@ -1927,9 +1939,6 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol) ...@@ -1927,9 +1939,6 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
s.rport = ntohs(r->id.idiag_dport); s.rport = ntohs(r->id.idiag_dport);
s.wq = r->idiag_wqueue; s.wq = r->idiag_wqueue;
s.rq = r->idiag_rqueue; s.rq = r->idiag_rqueue;
s.timer = r->idiag_timer;
s.timeout = r->idiag_expires;
s.retrans = r->idiag_retrans;
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;
...@@ -1948,6 +1957,15 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol) ...@@ -1948,6 +1957,15 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
inet_stats_print(&s, protocol); inet_stats_print(&s, protocol);
if (show_options) {
struct tcpstat t = {};
t.timer = r->idiag_timer;
t.timeout = r->idiag_expires;
t.retrans = r->idiag_retrans;
tcp_timer_print(&t);
}
if (show_details) { if (show_details) {
if (r->idiag_uid) if (r->idiag_uid)
printf(" uid:%u", (unsigned)r->idiag_uid); printf(" uid:%u", (unsigned)r->idiag_uid);
...@@ -2292,7 +2310,7 @@ outerr: ...@@ -2292,7 +2310,7 @@ outerr:
static int dgram_show_line(char *line, const struct filter *f, int family) static int dgram_show_line(char *line, const struct filter *f, int family)
{ {
struct tcpstat s = {}; struct sockstat s = {};
char *loc, *rem, *data; char *loc, *rem, *data;
char opt[256]; char opt[256];
int n; int n;
...@@ -2495,15 +2513,15 @@ static void unix_stats_print(struct unixstat *list, struct filter *f) ...@@ -2495,15 +2513,15 @@ static void unix_stats_print(struct unixstat *list, struct filter *f)
} }
if (f->f) { if (f->f) {
struct tcpstat tst; struct sockstat st;
tst.local.family = AF_UNIX; st.local.family = AF_UNIX;
tst.remote.family = AF_UNIX; st.remote.family = AF_UNIX;
memcpy(tst.local.data, &s->name, sizeof(s->name)); memcpy(st.local.data, &s->name, sizeof(s->name));
if (strcmp(peer, "*") == 0) if (strcmp(peer, "*") == 0)
memset(tst.remote.data, 0, sizeof(peer)); memset(st.remote.data, 0, sizeof(peer));
else else
memcpy(tst.remote.data, &peer, sizeof(peer)); memcpy(st.remote.data, &peer, sizeof(peer));
if (run_ssfilter(f->f, &tst) == 0) if (run_ssfilter(f->f, &st) == 0)
continue; continue;
} }
...@@ -2728,14 +2746,14 @@ static int packet_stats_print(struct pktstat *s, const struct filter *f) ...@@ -2728,14 +2746,14 @@ static int packet_stats_print(struct pktstat *s, const struct filter *f)
char *buf = NULL; char *buf = NULL;
if (f->f) { if (f->f) {
struct tcpstat tst; struct sockstat st;
tst.local.family = AF_PACKET; st.local.family = AF_PACKET;
tst.remote.family = AF_PACKET; st.remote.family = AF_PACKET;
tst.rport = 0; st.rport = 0;
tst.lport = s->iface; st.lport = s->iface;
tst.local.data[0] = s->prot; st.local.data[0] = s->prot;
tst.remote.data[0] = 0; st.remote.data[0] = 0;
if (run_ssfilter(f->f, &tst) == 0) if (run_ssfilter(f->f, &st) == 0)
return 1; return 1;
} }
...@@ -2911,14 +2929,14 @@ static void netlink_show_one(struct filter *f, ...@@ -2911,14 +2929,14 @@ static void netlink_show_one(struct filter *f,
SPRINT_BUF(prot_name); SPRINT_BUF(prot_name);
if (f->f) { if (f->f) {
struct tcpstat tst; struct sockstat st;
tst.local.family = AF_NETLINK; st.local.family = AF_NETLINK;
tst.remote.family = AF_NETLINK; st.remote.family = AF_NETLINK;
tst.rport = -1; st.rport = -1;
tst.lport = pid; st.lport = pid;
tst.local.data[0] = prot; st.local.data[0] = prot;
tst.remote.data[0] = 0; st.remote.data[0] = 0;
if (run_ssfilter(f->f, &tst) == 0) if (run_ssfilter(f->f, &st) == 0)
return; return;
} }
...@@ -3129,7 +3147,7 @@ static int get_snmp_int(char *proto, char *key, int *result) ...@@ -3129,7 +3147,7 @@ static int get_snmp_int(char *proto, char *key, int *result)
/* Get stats from sockstat */ /* Get stats from sockstat */
struct sockstat struct ssummary
{ {
int socks; int socks;
int tcp_mem; int tcp_mem;
...@@ -3148,7 +3166,7 @@ struct sockstat ...@@ -3148,7 +3166,7 @@ struct sockstat
int frag6_mem; int frag6_mem;
}; };
static void get_sockstat_line(char *line, struct sockstat *s) static void get_sockstat_line(char *line, struct ssummary *s)
{ {
char id[256], rem[256]; char id[256], rem[256];
...@@ -3177,7 +3195,7 @@ static void get_sockstat_line(char *line, struct sockstat *s) ...@@ -3177,7 +3195,7 @@ static void get_sockstat_line(char *line, struct sockstat *s)
&s->tcp_orphans, &s->tcp_tws, &s->tcp_total, &s->tcp_mem); &s->tcp_orphans, &s->tcp_tws, &s->tcp_total, &s->tcp_mem);
} }
static int get_sockstat(struct sockstat *s) static int get_sockstat(struct ssummary *s)
{ {
char buf[256]; char buf[256];
FILE *fp; FILE *fp;
...@@ -3201,7 +3219,7 @@ static int get_sockstat(struct sockstat *s) ...@@ -3201,7 +3219,7 @@ static int get_sockstat(struct sockstat *s)
static int print_summary(void) static int print_summary(void)
{ {
struct sockstat s; struct ssummary s;
struct snmpstat sn; struct snmpstat sn;
if (get_sockstat(&s) < 0) if (get_sockstat(&s) < 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