]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/ss.c
ss: fix compilation under glibc < 2.18
[mirror_iproute2.git] / misc / ss.c
index f99b6874c2281d7160d1e7227e0df2406fc5dddd..766fdc5f5bb6b9ce6bc42e8beb88086e2b707645 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
 #include <linux/tipc_netlink.h>
 #include <linux/tipc_sockets_diag.h>
 
+/* AF_VSOCK/PF_VSOCK is only provided since glibc 2.18 */
+#ifndef PF_VSOCK
+#define PF_VSOCK 40
+#endif
+#ifndef AF_VSOCK
+#define AF_VSOCK PF_VSOCK
+#endif
+
 #define MAGIC_SEQ 123456
 #define BUF_CHUNK (1024 * 1024)
 #define LEN_ALIGN(x) (((x) + 1) & ~1)
@@ -96,20 +104,21 @@ static int security_get_initial_context(char *name,  char **context)
 }
 #endif
 
-int resolve_services = 1;
+static int resolve_services = 1;
 int preferred_family = AF_UNSPEC;
-int show_options;
+static int show_options;
 int show_details;
-int show_users;
-int show_mem;
-int show_tcpinfo;
-int show_bpf;
-int show_proc_ctx;
-int show_sock_ctx;
-int show_header = 1;
-int follow_events;
-int sctp_ino;
-int show_tipcinfo;
+static int show_users;
+static int show_mem;
+static int show_tcpinfo;
+static int show_bpf;
+static int show_proc_ctx;
+static int show_sock_ctx;
+static int show_header = 1;
+static int follow_events;
+static int sctp_ino;
+static int show_tipcinfo;
+static int show_tos;
 
 enum col_id {
        COL_NETID,
@@ -494,7 +503,7 @@ struct user_ent {
 };
 
 #define USER_ENT_HASH_SIZE     256
-struct user_ent *user_ent_hash[USER_ENT_HASH_SIZE];
+static struct user_ent *user_ent_hash[USER_ENT_HASH_SIZE];
 
 static int user_ent_hashfn(unsigned int ino)
 {
@@ -817,6 +826,10 @@ struct tcpstat {
        unsigned int        fackets;
        unsigned int        reordering;
        unsigned int        not_sent;
+       unsigned int        delivered;
+       unsigned int        delivered_ce;
+       unsigned int        dsack_dups;
+       unsigned int        reord_seen;
        double              rcv_rtt;
        double              min_rtt;
        int                 rcv_space;
@@ -824,6 +837,8 @@ struct tcpstat {
        unsigned long long  busy_time;
        unsigned long long  rwnd_limited;
        unsigned long long  sndbuf_limited;
+       unsigned long long  bytes_sent;
+       unsigned long long  bytes_retrans;
        bool                has_ts_opt;
        bool                has_sack_opt;
        bool                has_ecn_opt;
@@ -1260,7 +1275,7 @@ static void render(void)
        while (token) {
                /* Print left delimiter only if we already started a line */
                if (line_started++)
-                       printed = printf("%s", current_field->ldelim);
+                       printed = printf("%s", f->ldelim);
                else
                        printed = 0;
 
@@ -1404,7 +1419,7 @@ struct scache {
        const char *proto;
 };
 
-struct scache *rlist;
+static struct scache *rlist;
 
 static void init_service_resolver(void)
 {
@@ -2424,6 +2439,10 @@ static void tcp_stats_print(struct tcpstat *s)
        if (s->ssthresh)
                out(" ssthresh:%d", s->ssthresh);
 
+       if (s->bytes_sent)
+               out(" bytes_sent:%llu", s->bytes_sent);
+       if (s->bytes_retrans)
+               out(" bytes_retrans:%llu", s->bytes_retrans);
        if (s->bytes_acked)
                out(" bytes_acked:%llu", s->bytes_acked);
        if (s->bytes_received)
@@ -2483,6 +2502,10 @@ static void tcp_stats_print(struct tcpstat *s)
 
        if (s->delivery_rate)
                out(" delivery_rate %sbps", sprint_bw(b1, s->delivery_rate));
+       if (s->delivered)
+               out(" delivered:%u", s->delivered);
+       if (s->delivered_ce)
+               out(" delivered_ce:%u", s->delivered_ce);
        if (s->app_limited)
                out(" app_limited");
 
@@ -2506,10 +2529,14 @@ static void tcp_stats_print(struct tcpstat *s)
                out(" lost:%u", s->lost);
        if (s->sacked && s->ss.state != SS_LISTEN)
                out(" sacked:%u", s->sacked);
+       if (s->dsack_dups)
+               out(" dsack_dups:%u", s->dsack_dups);
        if (s->fackets)
                out(" fackets:%u", s->fackets);
        if (s->reordering != 3)
                out(" reordering:%d", s->reordering);
+       if (s->reord_seen)
+               out(" reord_seen:%d", s->reord_seen);
        if (s->rcv_rtt)
                out(" rcv_rtt:%g", s->rcv_rtt);
        if (s->rcv_space)
@@ -2829,6 +2856,12 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
                s.busy_time = info->tcpi_busy_time;
                s.rwnd_limited = info->tcpi_rwnd_limited;
                s.sndbuf_limited = info->tcpi_sndbuf_limited;
+               s.delivered = info->tcpi_delivered;
+               s.delivered_ce = info->tcpi_delivered_ce;
+               s.dsack_dups = info->tcpi_dsack_dups;
+               s.reord_seen = info->tcpi_reord_seen;
+               s.bytes_sent = info->tcpi_bytes_sent;
+               s.bytes_retrans = info->tcpi_bytes_retrans;
                tcp_stats_print(&s);
                free(s.dctcp);
                free(s.bbr_info);
@@ -2984,6 +3017,15 @@ static int inet_show_sock(struct nlmsghdr *nlh,
                }
        }
 
+       if (show_tos) {
+               if (tb[INET_DIAG_TOS])
+                       out(" tos:%#x", rta_getattr_u8(tb[INET_DIAG_TOS]));
+               if (tb[INET_DIAG_TCLASS])
+                       out(" tclass:%#x", rta_getattr_u8(tb[INET_DIAG_TCLASS]));
+               if (tb[INET_DIAG_CLASS_ID])
+                       out(" class_id:%#x", rta_getattr_u32(tb[INET_DIAG_CLASS_ID]));
+       }
+
        if (show_mem || (show_tcpinfo && s->type != IPPROTO_UDP)) {
                out("\n\t");
                if (s->type == IPPROTO_SCTP)
@@ -3034,6 +3076,11 @@ static int tcpdiag_send(int fd, int protocol, struct filter *f)
                req.r.idiag_ext |= (1<<(INET_DIAG_CONG-1));
        }
 
+       if (show_tos) {
+               req.r.idiag_ext |= (1<<(INET_DIAG_TOS-1));
+               req.r.idiag_ext |= (1<<(INET_DIAG_TCLASS-1));
+       }
+
        iov[0] = (struct iovec){
                .iov_base = &req,
                .iov_len = sizeof(req)
@@ -3094,6 +3141,11 @@ static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
                req.r.idiag_ext |= (1<<(INET_DIAG_CONG-1));
        }
 
+       if (show_tos) {
+               req.r.idiag_ext |= (1<<(INET_DIAG_TOS-1));
+               req.r.idiag_ext |= (1<<(INET_DIAG_TCLASS-1));
+       }
+
        iov[0] = (struct iovec){
                .iov_base = &req,
                .iov_len = sizeof(req)
@@ -3156,8 +3208,7 @@ static int kill_inet_sock(struct nlmsghdr *h, void *arg, struct sockstat *s)
        return rtnl_talk(rth, &req.nlh, NULL);
 }
 
-static int show_one_inet_sock(const struct sockaddr_nl *addr,
-               struct nlmsghdr *h, void *arg)
+static int show_one_inet_sock(struct nlmsghdr *h, void *arg)
 {
        int err;
        struct inet_diag_arg *diag_arg = arg;
@@ -3548,8 +3599,7 @@ static void unix_stats_print(struct sockstat *s, struct filter *f)
        proc_ctx_print(s);
 }
 
-static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
-               void *arg)
+static int unix_show_sock(struct nlmsghdr *nlh, void *arg)
 {
        struct filter *f = (struct filter *)arg;
        struct unix_diag_msg *r = NLMSG_DATA(nlh);
@@ -3843,8 +3893,7 @@ static void packet_show_ring(struct packet_diag_ring *ring)
        out(",features:0x%x", ring->pdr_features);
 }
 
-static int packet_show_sock(const struct sockaddr_nl *addr,
-               struct nlmsghdr *nlh, void *arg)
+static int packet_show_sock(struct nlmsghdr *nlh, void *arg)
 {
        const struct filter *f = arg;
        struct packet_diag_msg *r = NLMSG_DATA(nlh);
@@ -4133,8 +4182,7 @@ static int netlink_show_one(struct filter *f,
        return 0;
 }
 
-static int netlink_show_sock(const struct sockaddr_nl *addr,
-               struct nlmsghdr *nlh, void *arg)
+static int netlink_show_sock(struct nlmsghdr *nlh, void *arg)
 {
        struct filter *f = (struct filter *)arg;
        struct netlink_diag_msg *r = NLMSG_DATA(nlh);
@@ -4257,8 +4305,7 @@ static void vsock_stats_print(struct sockstat *s, struct filter *f)
        proc_ctx_print(s);
 }
 
-static int vsock_show_sock(const struct sockaddr_nl *addr,
-                          struct nlmsghdr *nlh, void *arg)
+static int vsock_show_sock(struct nlmsghdr *nlh, void *arg)
 {
        struct filter *f = (struct filter *)arg;
        struct vsock_diag_msg *r = NLMSG_DATA(nlh);
@@ -4311,8 +4358,7 @@ static void tipc_sock_addr_print(struct rtattr *net_addr, struct rtattr *id)
 
 }
 
-static int tipc_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
-                         void *arg)
+static int tipc_show_sock(struct nlmsghdr *nlh, void *arg)
 {
        struct rtattr *stat[TIPC_NLA_SOCK_STAT_MAX + 1] = {};
        struct rtattr *attrs[TIPC_NLA_SOCK_MAX + 1] = {};
@@ -4400,8 +4446,7 @@ struct sock_diag_msg {
        __u8 sdiag_family;
 };
 
-static int generic_show_sock(const struct sockaddr_nl *addr,
-               struct nlmsghdr *nlh, void *arg)
+static int generic_show_sock(struct nlmsghdr *nlh, void *arg)
 {
        struct sock_diag_msg *r = NLMSG_DATA(nlh);
        struct inet_diag_arg inet_arg = { .f = arg, .protocol = IPPROTO_MAX };
@@ -4411,19 +4456,19 @@ static int generic_show_sock(const struct sockaddr_nl *addr,
        case AF_INET:
        case AF_INET6:
                inet_arg.rth = inet_arg.f->rth_for_killing;
-               ret = show_one_inet_sock(addr, nlh, &inet_arg);
+               ret = show_one_inet_sock(nlh, &inet_arg);
                break;
        case AF_UNIX:
-               ret = unix_show_sock(addr, nlh, arg);
+               ret = unix_show_sock(nlh, arg);
                break;
        case AF_PACKET:
-               ret = packet_show_sock(addr, nlh, arg);
+               ret = packet_show_sock(nlh, arg);
                break;
        case AF_NETLINK:
-               ret = netlink_show_sock(addr, nlh, arg);
+               ret = netlink_show_sock(nlh, arg);
                break;
        case AF_VSOCK:
-               ret = vsock_show_sock(addr, nlh, arg);
+               ret = vsock_show_sock(nlh, arg);
                break;
        default:
                ret = -1;
@@ -4644,6 +4689,7 @@ static void _usage(FILE *dest)
 "   -i, --info          show internal TCP information\n"
 "       --tipcinfo      show internal tipc socket information\n"
 "   -s, --summary       show socket usage summary\n"
+"       --tos           show tos and priority information\n"
 "   -b, --bpf           show bpf filter socket information\n"
 "   -E, --events        continually display sockets as they are destroyed\n"
 "   -Z, --context       display process SELinux security contexts\n"
@@ -4748,6 +4794,8 @@ static int scan_state(const char *state)
 #define OPT_TIPCSOCK 257
 #define OPT_TIPCINFO 258
 
+#define OPT_TOS 259
+
 static const struct option long_opts[] = {
        { "numeric", 0, 0, 'n' },
        { "resolve", 0, 0, 'r' },
@@ -4783,6 +4831,7 @@ static const struct option long_opts[] = {
        { "contexts", 0, 0, 'z' },
        { "net", 1, 0, 'N' },
        { "tipcinfo", 0, 0, OPT_TIPCINFO},
+       { "tos", 0, 0, OPT_TOS },
        { "kill", 0, 0, 'K' },
        { "no-header", 0, 0, 'H' },
        { 0 }
@@ -4960,6 +5009,9 @@ int main(int argc, char *argv[])
                case OPT_TIPCINFO:
                        show_tipcinfo = 1;
                        break;
+               case OPT_TOS:
+                       show_tos = 1;
+                       break;
                case 'K':
                        current_filter.kill = 1;
                        break;