From 7d105b5648138bde7ad8a16302987f4cbb95062a Mon Sep 17 00:00:00 2001 From: "osdl.org!shemminger" Date: Wed, 2 Jun 2004 20:22:08 +0000 Subject: [PATCH] Build and constant cleanup (Logical change 1.6) --- misc/ss.c | 212 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 123 insertions(+), 89 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 3918bdef..7cf5f367 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -30,10 +30,11 @@ #include "rt_names.h" #include "ll_map.h" #include "libnetlink.h" -#include "tcp_diag.h" #include "SNAPSHOT.h" +#include #include +#include int resolve_hosts = 0; int resolve_services = 1; @@ -74,19 +75,19 @@ enum #define ALL_DB ((1<data, sizeof(addr)); @@ -1268,6 +1267,71 @@ outerr: return -1; } +void tcp_show_info(struct nlmsghdr *nlh, struct tcpdiagmsg *r) +{ + struct rtattr * tb[TCPDIAG_MAX+1]; + const struct tcpdiag_meminfo *minfo = NULL; + const struct tcp_info *info = NULL; + const struct tcpvegas_info *vinfo = NULL; + + memset(tb, 0, sizeof(tb)); + parse_rtattr(tb, TCPDIAG_MAX, (struct rtattr*)(r+1), + nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); + + if (tb[TCPDIAG_MEMINFO]) + minfo = RTA_DATA(tb[TCPDIAG_MEMINFO]); + if (tb[TCPDIAG_INFO]) + info = RTA_DATA(tb[TCPDIAG_INFO]); + +#ifdef TCPDIAG_VEGASINFO + if (tb[TCPDIAG_VEGASINFO]) + vinfo = RTA_DATA(tb[TCPDIAG_VEGASINFO]); +#endif + + if (minfo) { + printf(" mem:(r%u,w%u,f%u,t%u)", + minfo->tcpdiag_rmem, + minfo->tcpdiag_wmem, + minfo->tcpdiag_fmem, + minfo->tcpdiag_tmem); + } + + if (info) { +#ifdef TCP_INFO + if (info->tcpi_rto && info->tcpi_rto != 3000000) + printf(" rto:%g", (double)info->tcpi_rto/1000); + if (info->tcpi_rtt) + printf(" rtt:%g/%g", (double)info->tcpi_rtt/1000, + (double)info->tcpi_rttvar/1000); + if (info->tcpi_ato) + printf(" ato:%g", (double)info->tcpi_ato/1000); + if (info->tcpi_snd_cwnd != 2) + printf(" cwnd:%d", info->tcpi_snd_cwnd); + if (info->tcpi_snd_ssthresh < 0xFFFF) + printf(" ssthresh:%d", info->tcpi_snd_ssthresh); + + +#ifdef TCPDIAG_VEGASINFO + if (vinfo) { + if (vinfo->tcpv_enabled) + printf(" vegas"); + if (vinfo->tcpv_rtt && + vinfo->tcpv_rtt != 0x7fffffff && + info->tcpi_snd_mss && + info->tcpi_snd_cwnd) { + printf(" bw:%g", + (double) info->tcpi_snd_cwnd * + (double) info->tcpi_snd_mss * + 8000000. / (double) vinfo->tcpv_rtt); + } + } +#endif + } +#else +#warning No TCP_INFO. Please, do not repeat this experiment, use right kernel. + printf(" MORE_INFO_PROVIDED_YOU_COMPILED_SS_RIGHT"); +#endif +} int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f) { @@ -1323,43 +1387,10 @@ int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f) printf("%08x", r->id.tcpdiag_cookie[1]); } if (show_mem || show_tcpinfo) { - struct rtattr * tb[TCPDIAG_MAX+1]; - struct tcpdiag_meminfo *minfo = NULL; - struct tcp_info *info = NULL; - - memset(tb, 0, sizeof(tb)); - parse_rtattr(tb, TCPDIAG_MAX, (struct rtattr*)(r+1), - nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); - if (tb[TCPDIAG_MEMINFO]) - minfo = RTA_DATA(tb[TCPDIAG_MEMINFO]); - if (tb[TCPDIAG_INFO]) - info = RTA_DATA(tb[TCPDIAG_INFO]); - if (minfo) { - printf(" mem:(r%u,w%u,f%u,t%u)", - minfo->tcpdiag_rmem, - minfo->tcpdiag_wmem, - minfo->tcpdiag_fmem, - minfo->tcpdiag_tmem); - } - if (info) { -#ifdef TCP_INFO - if (info->tcpi_rto && info->tcpi_rto != 3000000) - printf(" rto:%g", (double)info->tcpi_rto/1000); - if (info->tcpi_rtt) - printf(" rtt:%g/%g", (double)info->tcpi_rtt/1000, - (double)info->tcpi_rttvar/1000); - if (info->tcpi_ato) - printf(" ato:%g", (double)info->tcpi_ato/1000); - if (info->tcpi_snd_cwnd != 2) - printf(" cwnd:%d", info->tcpi_snd_cwnd); - if (info->tcpi_snd_ssthresh < 0xFFFF) - printf(" ssthresh:%d", info->tcpi_snd_ssthresh); -#else -#warning No TCP_INFO. Please, do not repeat this experiment, use right kernel. - printf(" MORE_INFO_PROVIDED_YOU_COMPILED_SS_RIGHT"); -#endif - } + printf("\n\t"); + tcp_show_info(nlh, r); } + printf("\n"); return 0; @@ -1397,8 +1428,12 @@ int tcp_show_netlink(struct filter *f, FILE *dump_fp) req.r.tcpdiag_states = f->states; if (show_mem) req.r.tcpdiag_ext |= (1<<(TCPDIAG_MEMINFO-1)); - if (show_tcpinfo) + if (show_tcpinfo) { req.r.tcpdiag_ext |= (1<<(TCPDIAG_INFO-1)); +#ifdef TCPDIAG_VEGASINFO + req.r.tcpdiag_ext |= (1<<(TCPDIAG_VEGASINFO-1)); +#endif + } iov[0] = (struct iovec){ &req, sizeof(req) }; if (f->f) { @@ -2285,7 +2320,7 @@ static void usage(void) " ss [ OPTIONS ] [ FILTER ]\n" "where OPTIONS := { -h[elp] | -V[ersion] | -n[umeric] | -r[esolve] |\n" " -a[ll] -l[istening] -o[ptions] -e[xtended] -p[rocesses]\n" -" -A QUERY } -s[ummary]\n" +" -A QUERY -i[nfo] } -s[ummary]\n" " -f[amily] { inet | inet6 | link | unix } }\n" " QUERY := {all|inet|tcp|udp|raw|unix|packet|netlink}[,QUERY]\n" " FILTER := [ state TCP-STATE ] [ EXPRESSION ]\n" @@ -2294,7 +2329,7 @@ static void usage(void) } -int scan_state(char *state) +int scan_state(const char *state) { int i; if (strcasecmp(state, "close") == 0 || @@ -2321,14 +2356,13 @@ int scan_state(char *state) return 0; } - int main(int argc, char *argv[]) { int do_default = 1; int saw_states = 0; int saw_query = 0; int do_summary = 0; - char *dump_tcpdiag = NULL; + const char *dump_tcpdiag = NULL; FILE *filter_fp = NULL; int ch; @@ -2336,7 +2370,7 @@ int main(int argc, char *argv[]) current_filter.states = default_filter.states; - while ((ch = getopt(argc, argv, "h?aletuwxnro460spfmiA:D:F:vV")) != EOF) { + while ((ch = getopt(argc, argv, "h?aletuwxnro460spf:miA:D:F:vV")) != EOF) { switch(ch) { case 'n': resolve_services = 0;