]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/ss.c
ss cleanup and enable full features.
[mirror_iproute2.git] / misc / ss.c
index 31ada1f4c0b3ee35ecd0152a8e0cde008b62268c..80e0e5fdee04a12838245439681dbcc72cd47d34 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -728,7 +728,7 @@ int run_ssfilter(struct ssfilter *f, struct tcpstat *s)
 }
 
 /* Relocate external jumps by reloc. */ 
-void ssfilter_patch(char *a, int len, int reloc)
+static void ssfilter_patch(char *a, int len, int reloc)
 {
        while (len > 0) {
                struct tcpdiag_bc_op *op = (struct tcpdiag_bc_op*)a;
@@ -741,7 +741,7 @@ void ssfilter_patch(char *a, int len, int reloc)
                abort();
 }
 
-int ssfilter_bytecompile(struct ssfilter *f, char **bytecode)
+static int ssfilter_bytecompile(struct ssfilter *f, char **bytecode)
 {
        switch (f->type) {
                case SSF_S_AUTO:
@@ -865,7 +865,7 @@ int ssfilter_bytecompile(struct ssfilter *f, char **bytecode)
        }
 }
 
-int remember_he(struct aafilter *a, struct hostent *he)
+static int remember_he(struct aafilter *a, struct hostent *he)
 {
        char **ptr = he->h_addr_list; 
        int cnt = 0;
@@ -897,7 +897,7 @@ int remember_he(struct aafilter *a, struct hostent *he)
        return cnt;
 }
 
-int get_dns_host(struct aafilter *a, char *addr, int fam)
+static int get_dns_host(struct aafilter *a, const char *addr, int fam)
 {
        static int notfirst;
        int cnt = 0;
@@ -919,9 +919,9 @@ int get_dns_host(struct aafilter *a, char *addr, int fam)
        return !cnt;
 }
 
-int xll_initted = 0;
+static int xll_initted = 0;
 
-void xll_init(void)
+static void xll_init(void)
 {
        struct rtnl_handle rth;
        rtnl_open(&rth, 0);
@@ -930,14 +930,14 @@ void xll_init(void)
        xll_initted = 1;
 }
 
-const char *xll_index_to_name(int index)
+static const char *xll_index_to_name(int index)
 {
        if (!xll_initted)
                xll_init();
        return ll_index_to_name(index);
 }
 
-int xll_name_to_index(char *dev)
+static int xll_name_to_index(const char *dev)
 {
        if (!xll_initted)
                xll_init();
@@ -1102,7 +1102,7 @@ void *parse_hostcond(char *addr)
        return res;
 }
 
-int tcp_show_line(char *line, struct filter *f, int family)
+static int tcp_show_line(char *line, struct filter *f, int family)
 {
        struct tcpstat s;
        char *loc, *rem, *data;
@@ -1224,7 +1224,7 @@ int tcp_show_line(char *line, struct filter *f, int family)
        return 0;
 }
 
-int generic_record_read(int fd, char *buf, int bufsize,
+static int generic_record_read(int fd, char *buf, int bufsize,
                        int (*worker)(char*, struct filter *, int),
                        struct filter *f, int fam)
 {
@@ -1287,10 +1287,24 @@ outwrongformat:
 outerr:
        return -1;
 }
+                       
+static char *sprint_bw(char *buf, double bw)
+{
+       if (bw > 1000000.) 
+               sprintf(buf,"%.1fM", bw / 1000000.);
+       else if (bw > 1000.)
+               sprintf(buf,"%.1fK", bw / 1000.);
+       else
+               sprintf(buf, "%g", bw);
+
+       return buf;
+}
 
-void tcp_show_info(struct nlmsghdr *nlh, struct tcpdiagmsg *r)
+static void tcp_show_info(const struct nlmsghdr *nlh, struct tcpdiagmsg *r)
 {
        struct rtattr * tb[TCPDIAG_MAX+1];
+       char b1[64];
+       double rtt = 0;
 
        memset(tb, 0, sizeof(tb));
        parse_rtattr(tb, TCPDIAG_MAX, (struct rtattr*)(r+1),
@@ -1318,15 +1332,17 @@ void tcp_show_info(struct nlmsghdr *nlh, struct tcpdiagmsg *r)
                } else
                        info = RTA_DATA(tb[TCPDIAG_INFO]);
 
-               if (info->tcpi_options & TCPI_OPT_TIMESTAMPS)
-                       printf(" ts");
-               if (info->tcpi_options & TCPI_OPT_SACK)
-                       printf(" sack");
+               if (show_options) {
+                       if (info->tcpi_options & TCPI_OPT_TIMESTAMPS)
+                               printf(" ts");
+                       if (info->tcpi_options & TCPI_OPT_SACK)
+                               printf(" sack");
+                       if (info->tcpi_options & TCPI_OPT_ECN)
+                               printf(" ecn");
+               }
                if (info->tcpi_options & TCPI_OPT_WSCALE) 
                        printf(" wscale:%d,%d", info->tcpi_snd_wscale,
                               info->tcpi_rcv_wscale);
-               if (info->tcpi_options & TCPI_OPT_ECN)
-                       printf(" ecn");
                if (info->tcpi_rto && info->tcpi_rto != 3000000)
                        printf(" rto:%g", (double)info->tcpi_rto/1000);
                if (info->tcpi_rtt)
@@ -1339,12 +1355,7 @@ void tcp_show_info(struct nlmsghdr *nlh, struct tcpdiagmsg *r)
                if (info->tcpi_snd_ssthresh < 0xFFFF)
                        printf(" ssthresh:%d", info->tcpi_snd_ssthresh);
                
-#if LINUX_VERSION_CODE >= 0x20607
-               if (info->tcpi_rcv_rtt)
-                       printf(" rcv_rtt:%g", (double) info->tcpi_rcv_rtt/1000);
-               if (info->tcpi_rcv_space)
-                       printf(" rcv_space:%d", info->tcpi_rcv_space);
-
+               rtt = (double) info->tcpi_rtt;
                if (tb[TCPDIAG_VEGASINFO]) {
                        const struct tcpvegas_info *vinfo
                                = RTA_DATA(tb[TCPDIAG_VEGASINFO]);
@@ -1353,16 +1364,22 @@ void tcp_show_info(struct nlmsghdr *nlh, struct tcpdiagmsg *r)
                                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);
-                       }
+                           vinfo->tcpv_rtt != 0x7fffffff)
+                           rtt =  vinfo->tcpv_rtt;
+               }
+
+               if (rtt > 0 && info->tcpi_snd_mss && info->tcpi_snd_cwnd) {
+                       printf(" send %sbps",
+                              sprint_bw(b1, (double) info->tcpi_snd_cwnd *
+                                        (double) info->tcpi_snd_mss * 8000000.
+                                        / rtt));
                }
-#endif
+
+               if (info->tcpi_rcv_rtt)
+                       printf(" rcv_rtt:%g", (double) info->tcpi_rcv_rtt/1000);
+               if (info->tcpi_rcv_space)
+                       printf(" rcv_space:%d", info->tcpi_rcv_space);
+
        }
 }
 
@@ -1461,11 +1478,10 @@ 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) {
                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) };
@@ -2391,20 +2407,20 @@ int scan_state(const char *state)
                return (1<<SS_CLOSE);
        if (strcasecmp(state, "syn-rcv") == 0)
                return (1<<SS_SYN_RECV);
-       if (matches(state, "established") == 0)
+       if (strcasecmp(state, "established") == 0)
                return (1<<SS_ESTABLISHED);
        if (strcasecmp(state, "all") == 0)
                return SS_ALL;
        if (strcasecmp(state, "connected") == 0)
                return SS_ALL & ~((1<<SS_CLOSE)|(1<<SS_LISTEN));
-       if (matches(state, "synchronized") == 0)
+       if (strcasecmp(state, "synchronized") == 0)
                return SS_ALL & ~((1<<SS_CLOSE)|(1<<SS_LISTEN)|(1<<SS_SYN_SENT));
        if (strcasecmp(state, "bucket") == 0)
                return (1<<SS_SYN_RECV)|(1<<SS_TIME_WAIT);
        if (strcasecmp(state, "big") == 0)
                return SS_ALL & ~((1<<SS_SYN_RECV)|(1<<SS_TIME_WAIT));
        for (i=0; i<SS_MAX; i++) {
-               if (matches(state, sstate_namel[i]) == 0)
+               if (strcasecmp(state, sstate_namel[i]) == 0)
                        return (1<<i);
        }
        return 0;
@@ -2550,10 +2566,10 @@ int main(int argc, char *argv[])
                                        current_filter.dbs |= (1<<RAW_DB);
                                } else if (strcmp(p, "unix") == 0) {
                                        current_filter.dbs |= UNIX_DBM;
-                               } else if (matches(p, "unix_stream") == 0 ||
+                               } else if (strcasecmp(p, "unix_stream") == 0 ||
                                           strcmp(p, "u_str") == 0) {
                                        current_filter.dbs |= (1<<UNIX_ST_DB);
-                               } else if (matches(p, "unix_dgram") == 0 ||
+                               } else if (strcasecmp(p, "unix_dgram") == 0 ||
                                           strcmp(p, "u_dgr") == 0) {
                                        current_filter.dbs |= (1<<UNIX_DG_DB);
                                } else if (strcmp(p, "packet") == 0) {