From: Vadim Kochan Date: Fri, 13 Feb 2015 20:13:58 +0000 (+0200) Subject: ss: Split tcpstap struct to sockstat & tcpstat X-Git-Tag: v4.0.0~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=055840f27f09704d5d1003620e847058bc30089d;p=thirdparty%2Fiproute2.git ss: Split tcpstap struct to sockstat & tcpstat Signed-off-by: Vadim Kochan --- diff --git a/misc/ss.c b/misc/ss.c index eb4e0ec0f..922cf8c68 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -691,16 +691,7 @@ static const char *sstate_namel[] = { [SS_CLOSING] = "closing", }; -struct dctcpstat -{ - unsigned int ce_state; - unsigned int alpha; - unsigned int ab_ecn; - unsigned int ab_tot; - bool enabled; -}; - -struct tcpstat +struct sockstat { inet_prefix local; inet_prefix remote; @@ -713,6 +704,20 @@ struct tcpstat int refcnt; unsigned int iface; 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 timeout; int probes; @@ -1000,7 +1005,7 @@ static int unix_match(const inet_prefix *a, const inet_prefix *p) 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) { case SSF_S_AUTO: @@ -1487,7 +1492,7 @@ static char *proto_name(int protocol) return "???"; } -static void inet_stats_print(struct tcpstat *s, int protocol) +static void inet_stats_print(struct sockstat *s, int protocol) { char *buf = NULL; @@ -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->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 (find_entry(s->ino, &buf, (show_proc_ctx & show_sock_ctx) ? @@ -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; if (family == AF_INET) { @@ -1658,7 +1653,7 @@ static void tcp_stats_print(struct tcpstat *s) printf(" retrans:%u/%u", s->retrans, s->retrans_total); if (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); if (s->fackets) printf(" fackets:%u", s->fackets); @@ -1670,6 +1665,18 @@ static void tcp_stats_print(struct tcpstat *s) 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) { int rto = 0, ato = 0; @@ -1686,17 +1693,17 @@ static int tcp_show_line(char *line, const struct filter *f, int family) if (!(f->states & (1 << state))) 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; opt[0] = 0; 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.timer, &s.timeout, &s.retrans, &s.uid, &s.probes, &s.ino, - &s.refcnt, &s.sk, &rto, &ato, &s.qack, - &s.cwnd, &s.ssthresh, opt); + &s.ss.state, &s.ss.wq, &s.ss.rq, + &s.timer, &s.timeout, &s.retrans, &s.ss.uid, &s.probes, + &s.ss.ino, &s.ss.refcnt, &s.ss.sk, &rto, &ato, &s.qack, &s.cwnd, + &s.ssthresh, opt); if (n < 17) opt[0] = 0; @@ -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.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 (s.uid) - printf(" uid:%u", (unsigned)s.uid); - printf(" ino:%u", s.ino); - printf(" sk:%llx", s.sk); + if (s.ss.uid) + printf(" uid:%u", (unsigned)s.ss.uid); + printf(" ino:%u", s.ss.ino); + printf(" sk:%llx", s.ss.sk); if (opt[0]) printf(" opt:\"%s\"", opt); } @@ -1807,6 +1817,8 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r, double rtt = 0; struct tcpstat s = {}; + s.ss.state = r->idiag_state; + print_skmeminfo(tb, INET_DIAG_SKMEMINFO); if (tb[INET_DIAG_INFO]) { @@ -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 inet_diag_msg *r = NLMSG_DATA(nlh); - struct tcpstat s = {}; + struct sockstat s = {}; parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1), nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); @@ -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.wq = r->idiag_wqueue; 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.uid = r->idiag_uid; s.iface = r->id.idiag_if; @@ -1948,6 +1957,15 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int 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 (r->idiag_uid) printf(" uid:%u", (unsigned)r->idiag_uid); @@ -2292,7 +2310,7 @@ outerr: static int dgram_show_line(char *line, const struct filter *f, int family) { - struct tcpstat s = {}; + struct sockstat s = {}; char *loc, *rem, *data; char opt[256]; int n; @@ -2495,15 +2513,15 @@ static void unix_stats_print(struct unixstat *list, struct filter *f) } if (f->f) { - struct tcpstat tst; - tst.local.family = AF_UNIX; - tst.remote.family = AF_UNIX; - memcpy(tst.local.data, &s->name, sizeof(s->name)); + struct sockstat st; + st.local.family = AF_UNIX; + st.remote.family = AF_UNIX; + memcpy(st.local.data, &s->name, sizeof(s->name)); if (strcmp(peer, "*") == 0) - memset(tst.remote.data, 0, sizeof(peer)); + memset(st.remote.data, 0, sizeof(peer)); else - memcpy(tst.remote.data, &peer, sizeof(peer)); - if (run_ssfilter(f->f, &tst) == 0) + memcpy(st.remote.data, &peer, sizeof(peer)); + if (run_ssfilter(f->f, &st) == 0) continue; } @@ -2728,14 +2746,14 @@ static int packet_stats_print(struct pktstat *s, const struct filter *f) char *buf = NULL; if (f->f) { - struct tcpstat tst; - tst.local.family = AF_PACKET; - tst.remote.family = AF_PACKET; - tst.rport = 0; - tst.lport = s->iface; - tst.local.data[0] = s->prot; - tst.remote.data[0] = 0; - if (run_ssfilter(f->f, &tst) == 0) + struct sockstat st; + st.local.family = AF_PACKET; + st.remote.family = AF_PACKET; + st.rport = 0; + st.lport = s->iface; + st.local.data[0] = s->prot; + st.remote.data[0] = 0; + if (run_ssfilter(f->f, &st) == 0) return 1; } @@ -2911,14 +2929,14 @@ static void netlink_show_one(struct filter *f, SPRINT_BUF(prot_name); if (f->f) { - struct tcpstat tst; - tst.local.family = AF_NETLINK; - tst.remote.family = AF_NETLINK; - tst.rport = -1; - tst.lport = pid; - tst.local.data[0] = prot; - tst.remote.data[0] = 0; - if (run_ssfilter(f->f, &tst) == 0) + struct sockstat st; + st.local.family = AF_NETLINK; + st.remote.family = AF_NETLINK; + st.rport = -1; + st.lport = pid; + st.local.data[0] = prot; + st.remote.data[0] = 0; + if (run_ssfilter(f->f, &st) == 0) return; } @@ -3129,7 +3147,7 @@ static int get_snmp_int(char *proto, char *key, int *result) /* Get stats from sockstat */ -struct sockstat +struct ssummary { int socks; int tcp_mem; @@ -3148,7 +3166,7 @@ struct sockstat 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]; @@ -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); } -static int get_sockstat(struct sockstat *s) +static int get_sockstat(struct ssummary *s) { char buf[256]; FILE *fp; @@ -3201,7 +3219,7 @@ static int get_sockstat(struct sockstat *s) static int print_summary(void) { - struct sockstat s; + struct ssummary s; struct snmpstat sn; if (get_sockstat(&s) < 0)