]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/ss.c
libnetlink.c, ss.c: properly handle fread() errors
[mirror_iproute2.git] / misc / ss.c
index c472fbd9a8790d1b779a6fa8d96995dfc8cd42d6..efa8778160e3fda91daeab782fe071f1d065ac61 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -19,9 +19,6 @@
 #include <sys/sysmacros.h>
 #include <netinet/in.h>
 #include <string.h>
-#ifdef HAVE_LIBBSD
-#include <bsd/string.h>
-#endif
 #include <errno.h>
 #include <netdb.h>
 #include <arpa/inet.h>
@@ -45,6 +42,7 @@
 #include <linux/unix_diag.h>
 #include <linux/netdevice.h>   /* for MAX_ADDR_LEN */
 #include <linux/filter.h>
+#include <linux/xdp_diag.h>
 #include <linux/packet_diag.h>
 #include <linux/netlink_diag.h>
 #include <linux/sctp.h>
 #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 BUF_CHUNK (1024 * 1024)        /* Buffer chunk allocation size */
+#define BUF_CHUNKS_MAX 5       /* Maximum number of allocated buffer chunks */
 #define LEN_ALIGN(x) (((x) + 1) & ~1)
 
 #define DIAG_REQUEST(_req, _r)                                             \
@@ -99,20 +106,22 @@ static int security_get_initial_context(char *name,  char **context)
 }
 #endif
 
-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;
+int numeric;
+int oneline;
 
 enum col_id {
        COL_NETID,
@@ -178,6 +187,7 @@ static struct {
        struct buf_token *cur;  /* Position of current token in chunk */
        struct buf_chunk *head; /* First chunk */
        struct buf_chunk *tail; /* Current chunk */
+       int chunks;             /* Number of allocated chunks */
 } buffer;
 
 static const char *TCP_PROTO = "tcp";
@@ -201,6 +211,7 @@ enum {
        VSOCK_ST_DB,
        VSOCK_DG_DB,
        TIPC_DB,
+       XDP_DB,
        MAX_DB
 };
 
@@ -312,6 +323,10 @@ static const struct filter default_dbs[MAX_DB] = {
                .states   = TIPC_SS_CONN,
                .families = FAMILY_MASK(AF_TIPC),
        },
+       [XDP_DB] = {
+               .states   = (1 << SS_CLOSE),
+               .families = FAMILY_MASK(AF_XDP),
+       },
 };
 
 static const struct filter default_afs[AF_MAX] = {
@@ -343,6 +358,10 @@ static const struct filter default_afs[AF_MAX] = {
                .dbs    = (1 << TIPC_DB),
                .states = TIPC_SS_CONN,
        },
+       [AF_XDP] = {
+               .dbs    = (1 << XDP_DB),
+               .states = (1 << SS_CLOSE),
+       },
 };
 
 static int do_default = 1;
@@ -369,7 +388,7 @@ static int filter_db_parse(struct filter *f, const char *s)
                ENTRY(all, UDP_DB, DCCP_DB, TCP_DB, RAW_DB,
                           UNIX_ST_DB, UNIX_DG_DB, UNIX_SQ_DB,
                           PACKET_R_DB, PACKET_DG_DB, NETLINK_DB,
-                          SCTP_DB, VSOCK_ST_DB, VSOCK_DG_DB),
+                          SCTP_DB, VSOCK_ST_DB, VSOCK_DG_DB, XDP_DB),
                ENTRY(inet, UDP_DB, DCCP_DB, TCP_DB, SCTP_DB, RAW_DB),
                ENTRY(udp, UDP_DB),
                ENTRY(dccp, DCCP_DB),
@@ -394,6 +413,7 @@ static int filter_db_parse(struct filter *f, const char *s)
                ENTRY(v_str, VSOCK_ST_DB),      /* alias for vsock_stream */
                ENTRY(vsock_dgram, VSOCK_DG_DB),
                ENTRY(v_dgr, VSOCK_DG_DB),      /* alias for vsock_dgram */
+               ENTRY(xdp, XDP_DB),
 #undef ENTRY
        };
        bool enable = true;
@@ -497,7 +517,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)
 {
@@ -820,6 +840,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;
@@ -827,6 +851,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;
@@ -932,6 +958,8 @@ static struct buf_chunk *buf_chunk_new(void)
 
        new->end = buffer.cur->data;
 
+       buffer.chunks++;
+
        return new;
 }
 
@@ -1076,33 +1104,6 @@ static int field_is_last(struct column *f)
        return f - columns == COL_MAX - 1;
 }
 
-static void field_next(void)
-{
-       field_flush(current_field);
-
-       if (field_is_last(current_field))
-               current_field = columns;
-       else
-               current_field++;
-}
-
-/* Walk through fields and flush them until we reach the desired one */
-static void field_set(enum col_id id)
-{
-       while (id != current_field - columns)
-               field_next();
-}
-
-/* Print header for all non-empty columns */
-static void print_header(void)
-{
-       while (!field_is_last(current_field)) {
-               if (!current_field->disabled)
-                       out("%s", current_field->header);
-               field_next();
-       }
-}
-
 /* Get the next available token in the buffer starting from the current token */
 static struct buf_token *buf_token_next(struct buf_token *cur)
 {
@@ -1128,6 +1129,7 @@ static void buf_free_all(void)
                free(tmp);
        }
        buffer.head = NULL;
+       buffer.chunks = 0;
 }
 
 /* Get current screen width, default to 80 columns if TIOCGWINSZ fails */
@@ -1290,6 +1292,40 @@ static void render(void)
        current_field = columns;
 }
 
+/* Move to next field, and render buffer if we reached the maximum number of
+ * chunks, at the last field in a line.
+ */
+static void field_next(void)
+{
+       if (field_is_last(current_field) && buffer.chunks >= BUF_CHUNKS_MAX) {
+               render();
+               return;
+       }
+
+       field_flush(current_field);
+       if (field_is_last(current_field))
+               current_field = columns;
+       else
+               current_field++;
+}
+
+/* Walk through fields and flush them until we reach the desired one */
+static void field_set(enum col_id id)
+{
+       while (id != current_field - columns)
+               field_next();
+}
+
+/* Print header for all non-empty columns */
+static void print_header(void)
+{
+       while (!field_is_last(current_field)) {
+               if (!current_field->disabled)
+                       out("%s", current_field->header);
+               field_next();
+       }
+}
+
 static void sock_state_print(struct sockstat *s)
 {
        const char *sock_name;
@@ -1328,6 +1364,9 @@ static void sock_state_print(struct sockstat *s)
        case AF_VSOCK:
                sock_name = vsock_netid_name(s->type);
                break;
+       case AF_XDP:
+               sock_name = "xdp";
+               break;
        default:
                sock_name = "unknown";
        }
@@ -1407,7 +1446,7 @@ struct scache {
        const char *proto;
 };
 
-struct scache *rlist;
+static struct scache *rlist;
 
 static void init_service_resolver(void)
 {
@@ -1514,7 +1553,7 @@ static const char *resolve_service(int port)
                return buf;
        }
 
-       if (!resolve_services)
+       if (numeric)
                goto do_numeric;
 
        if (dg_proto == RAW_PROTO)
@@ -2322,7 +2361,9 @@ static int proc_inet_split_line(char *line, char **loc, char **rem, char **data)
 
 static char *sprint_bw(char *buf, double bw)
 {
-       if (bw > 1000000.)
+       if (numeric)
+               sprintf(buf, "%.0f", bw);
+       else if (bw > 1000000.)
                sprintf(buf, "%.1fM", bw / 1000000.);
        else if (bw > 1000.)
                sprintf(buf, "%.1fK", bw / 1000.);
@@ -2373,7 +2414,7 @@ static void sctp_stats_print(struct sctp_info *s)
        if (s->sctpi_s_pd_point)
                out(" pdpoint:%d", s->sctpi_s_pd_point);
        if (s->sctpi_s_nodelay)
-               out(" nodealy:%d", s->sctpi_s_nodelay);
+               out(" nodelay:%d", s->sctpi_s_nodelay);
        if (s->sctpi_s_disable_fragments)
                out(" nofrag:%d", s->sctpi_s_disable_fragments);
        if (s->sctpi_s_v4mapped)
@@ -2427,6 +2468,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)
@@ -2486,6 +2531,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");
 
@@ -2509,10 +2558,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)
@@ -2832,6 +2885,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);
@@ -2878,7 +2937,7 @@ static void sctp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
                len = RTA_PAYLOAD(tb[INET_DIAG_LOCALS]);
                sa = RTA_DATA(tb[INET_DIAG_LOCALS]);
 
-               out("locals:%s", format_host_sa(sa));
+               out(" locals:%s", format_host_sa(sa));
                for (sa++, len -= sizeof(*sa); len > 0; sa++, len -= sizeof(*sa))
                        out(",%s", format_host_sa(sa));
 
@@ -2987,8 +3046,18 @@ 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 (!oneline)
+                       out("\n\t");
                if (s->type == IPPROTO_SCTP)
                        sctp_show_info(nlh, r, tb);
                else
@@ -3037,6 +3106,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)
@@ -3097,6 +3171,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)
@@ -3250,28 +3329,28 @@ static int tcp_show_netlink_file(struct filter *f)
        }
 
        while (1) {
-               int status, err2;
+               int err2;
+               size_t status, nitems;
                struct nlmsghdr *h = (struct nlmsghdr *)buf;
                struct sockstat s = {};
 
                status = fread(buf, 1, sizeof(*h), fp);
-               if (status < 0) {
-                       perror("Reading header from $TCPDIAG_FILE");
-                       break;
-               }
                if (status != sizeof(*h)) {
-                       perror("Unexpected EOF reading $TCPDIAG_FILE");
+                       if (ferror(fp))
+                               perror("Reading header from $TCPDIAG_FILE");
+                       if (feof(fp))
+                               fprintf(stderr, "Unexpected EOF reading $TCPDIAG_FILE");
                        break;
                }
 
-               status = fread(h+1, 1, NLMSG_ALIGN(h->nlmsg_len-sizeof(*h)), fp);
+               nitems = NLMSG_ALIGN(h->nlmsg_len - sizeof(*h));
+               status = fread(h+1, 1, nitems, fp);
 
-               if (status < 0) {
-                       perror("Reading $TCPDIAG_FILE");
-                       break;
-               }
-               if (status + sizeof(*h) < h->nlmsg_len) {
-                       perror("Unexpected EOF reading $TCPDIAG_FILE");
+               if (status != nitems) {
+                       if (ferror(fp))
+                               perror("Reading $TCPDIAG_FILE");
+                       if (feof(fp))
+                               fprintf(stderr, "Unexpected EOF reading $TCPDIAG_FILE");
                        break;
                }
 
@@ -3898,7 +3977,10 @@ static int packet_show_sock(struct nlmsghdr *nlh, void *arg)
 
        if (show_details) {
                if (pinfo) {
-                       out("\n\tver:%d", pinfo->pdi_version);
+                       if (oneline)
+                               out(" ver:%d", pinfo->pdi_version);
+                       else
+                               out("\n\tver:%d", pinfo->pdi_version);
                        out(" cpy_thresh:%d", pinfo->pdi_copy_thresh);
                        out(" flags( ");
                        if (pinfo->pdi_flags & PDI_RUNNING)
@@ -3916,19 +3998,28 @@ static int packet_show_sock(struct nlmsghdr *nlh, void *arg)
                        out(" )");
                }
                if (ring_rx) {
-                       out("\n\tring_rx(");
+                       if (oneline)
+                               out(" ring_rx(");
+                       else
+                               out("\n\tring_rx(");
                        packet_show_ring(ring_rx);
                        out(")");
                }
                if (ring_tx) {
-                       out("\n\tring_tx(");
+                       if (oneline)
+                               out(" ring_tx(");
+                       else
+                               out("\n\tring_tx(");
                        packet_show_ring(ring_tx);
                        out(")");
                }
                if (has_fanout) {
                        uint16_t type = (fanout >> 16) & 0xffff;
 
-                       out("\n\tfanout(");
+                       if (oneline)
+                               out(" fanout(");
+                       else
+                               out("\n\tfanout(");
                        out("id:%d,", fanout & 0xffff);
                        out("type:");
 
@@ -3957,7 +4048,10 @@ static int packet_show_sock(struct nlmsghdr *nlh, void *arg)
                int num = RTA_PAYLOAD(tb[PACKET_DIAG_FILTER]) /
                          sizeof(struct sock_filter);
 
-               out("\n\tbpf filter (%d): ", num);
+               if (oneline)
+                       out(" bpf filter (%d): ", num);
+               else
+                       out("\n\tbpf filter (%d): ", num);
                while (num) {
                        out(" 0x%02x %u %u %u,",
                            fil->code, fil->jt, fil->jf, fil->k);
@@ -4034,6 +4128,148 @@ static int packet_show(struct filter *f)
        return rc;
 }
 
+static int xdp_stats_print(struct sockstat *s, const struct filter *f)
+{
+       const char *addr, *port;
+       char q_str[16];
+
+       s->local.family = s->remote.family = AF_XDP;
+
+       if (f->f) {
+               if (run_ssfilter(f->f, s) == 0)
+                       return 1;
+       }
+
+       sock_state_print(s);
+
+       if (s->iface) {
+               addr = xll_index_to_name(s->iface);
+               snprintf(q_str, sizeof(q_str), "q%d", s->lport);
+               port = q_str;
+               sock_addr_print(addr, ":", port, NULL);
+       } else {
+               sock_addr_print("", "*", "", NULL);
+       }
+
+       sock_addr_print("", "*", "", NULL);
+
+       proc_ctx_print(s);
+
+       if (show_details)
+               sock_details_print(s);
+
+       return 0;
+}
+
+static void xdp_show_ring(const char *name, struct xdp_diag_ring *ring)
+{
+       if (oneline)
+               out(" %s(", name);
+       else
+               out("\n\t%s(", name);
+       out("entries:%u", ring->entries);
+       out(")");
+}
+
+static void xdp_show_umem(struct xdp_diag_umem *umem, struct xdp_diag_ring *fr,
+                         struct xdp_diag_ring *cr)
+{
+       if (oneline)
+               out(" tumem(");
+       else
+               out("\n\tumem(");
+       out("id:%u", umem->id);
+       out(",size:%llu", umem->size);
+       out(",num_pages:%u", umem->num_pages);
+       out(",chunk_size:%u", umem->chunk_size);
+       out(",headroom:%u", umem->headroom);
+       out(",ifindex:%u", umem->ifindex);
+       out(",qid:%u", umem->queue_id);
+       out(",zc:%u", umem->flags & XDP_DU_F_ZEROCOPY);
+       out(",refs:%u", umem->refs);
+       out(")");
+
+       if (fr)
+               xdp_show_ring("fr", fr);
+       if (cr)
+               xdp_show_ring("cr", cr);
+}
+
+static int xdp_show_sock(struct nlmsghdr *nlh, void *arg)
+{
+       struct xdp_diag_ring *rx = NULL, *tx = NULL, *fr = NULL, *cr = NULL;
+       struct xdp_diag_msg *msg = NLMSG_DATA(nlh);
+       struct rtattr *tb[XDP_DIAG_MAX + 1];
+       struct xdp_diag_info *info = NULL;
+       struct xdp_diag_umem *umem = NULL;
+       const struct filter *f = arg;
+       struct sockstat stat = {};
+
+       parse_rtattr(tb, XDP_DIAG_MAX, (struct rtattr *)(msg + 1),
+                    nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*msg)));
+
+       stat.type = msg->xdiag_type;
+       stat.ino = msg->xdiag_ino;
+       stat.state = SS_CLOSE;
+       stat.sk = cookie_sk_get(&msg->xdiag_cookie[0]);
+
+       if (tb[XDP_DIAG_INFO]) {
+               info = RTA_DATA(tb[XDP_DIAG_INFO]);
+               stat.iface = info->ifindex;
+               stat.lport = info->queue_id;
+       }
+
+       if (tb[XDP_DIAG_UID])
+               stat.uid = rta_getattr_u32(tb[XDP_DIAG_UID]);
+       if (tb[XDP_DIAG_RX_RING])
+               rx = RTA_DATA(tb[XDP_DIAG_RX_RING]);
+       if (tb[XDP_DIAG_TX_RING])
+               tx = RTA_DATA(tb[XDP_DIAG_TX_RING]);
+       if (tb[XDP_DIAG_UMEM])
+               umem = RTA_DATA(tb[XDP_DIAG_UMEM]);
+       if (tb[XDP_DIAG_UMEM_FILL_RING])
+               fr = RTA_DATA(tb[XDP_DIAG_UMEM_FILL_RING]);
+       if (tb[XDP_DIAG_UMEM_COMPLETION_RING])
+               cr = RTA_DATA(tb[XDP_DIAG_UMEM_COMPLETION_RING]);
+       if (tb[XDP_DIAG_MEMINFO]) {
+               __u32 *skmeminfo = RTA_DATA(tb[XDP_DIAG_MEMINFO]);
+
+               stat.rq = skmeminfo[SK_MEMINFO_RMEM_ALLOC];
+       }
+
+       if (xdp_stats_print(&stat, f))
+               return 0;
+
+       if (show_details) {
+               if (rx)
+                       xdp_show_ring("rx", rx);
+               if (tx)
+                       xdp_show_ring("tx", tx);
+               if (umem)
+                       xdp_show_umem(umem, fr, cr);
+       }
+
+       if (show_mem)
+               print_skmeminfo(tb, XDP_DIAG_MEMINFO); // really?
+
+
+       return 0;
+}
+
+static int xdp_show(struct filter *f)
+{
+       DIAG_REQUEST(req, struct xdp_diag_req r);
+
+       if (!filter_af_get(f, AF_XDP) || !(f->states & (1 << SS_CLOSE)))
+               return 0;
+
+       req.r.sdiag_family = AF_XDP;
+       req.r.xdiag_show = XDP_SHOW_INFO | XDP_SHOW_RING_CFG | XDP_SHOW_UMEM |
+                          XDP_SHOW_MEMINFO;
+
+       return handle_netlink_request(f, &req.nlh, sizeof(req), xdp_show_sock);
+}
+
 static int netlink_show_one(struct filter *f,
                                int prot, int pid, unsigned int groups,
                                int state, int dst_pid, unsigned int dst_group,
@@ -4062,14 +4298,11 @@ static int netlink_show_one(struct filter *f,
 
        sock_state_print(&st);
 
-       if (resolve_services)
-               prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
-       else
-               prot_name = int_to_str(prot, prot_buf);
+       prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
 
        if (pid == -1) {
                procname[0] = '*';
-       } else if (resolve_services) {
+       } else if (!numeric) {
                int done = 0;
 
                if (!pid) {
@@ -4363,7 +4596,10 @@ static int tipc_show_sock(struct nlmsghdr *nlh, void *arg)
        proc_ctx_print(&ss);
 
        if (show_tipcinfo) {
-               out("\n type:%s", stype_nameg[ss.type]);
+               if (oneline)
+                       out(" type:%s", stype_nameg[ss.type]);
+               else
+                       out("\n type:%s", stype_nameg[ss.type]);
                out(" cong:%s ",
                       stat[TIPC_NLA_SOCK_STAT_LINK_CONG] ? "link" :
                       stat[TIPC_NLA_SOCK_STAT_CONN_CONG] ? "conn" : "none");
@@ -4421,6 +4657,9 @@ static int generic_show_sock(struct nlmsghdr *nlh, void *arg)
        case AF_VSOCK:
                ret = vsock_show_sock(nlh, arg);
                break;
+       case AF_XDP:
+               ret = xdp_show_sock(nlh, arg);
+               break;
        default:
                ret = -1;
        }
@@ -4640,6 +4879,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"
@@ -4658,10 +4898,11 @@ static void _usage(FILE *dest)
 "       --tipc          display only TIPC sockets\n"
 "       --vsock         display only vsock sockets\n"
 "   -f, --family=FAMILY display sockets of type FAMILY\n"
-"       FAMILY := {inet|inet6|link|unix|netlink|vsock|tipc|help}\n"
+"       FAMILY := {inet|inet6|link|unix|netlink|vsock|tipc|xdp|help}\n"
 "\n"
 "   -K, --kill          forcibly close sockets, display what was closed\n"
 "   -H, --no-header     Suppress header line\n"
+"   -O, --oneline       socket's data printed on a single line\n"
 "\n"
 "   -A, --query=QUERY, --socket=QUERY\n"
 "       QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram|tipc}[,QUERY]\n"
@@ -4744,6 +4985,11 @@ static int scan_state(const char *state)
 #define OPT_TIPCSOCK 257
 #define OPT_TIPCINFO 258
 
+#define OPT_TOS 259
+
+/* Values of 'x' are already used so a non-character is used */
+#define OPT_XDPSOCK 260
+
 static const struct option long_opts[] = {
        { "numeric", 0, 0, 'n' },
        { "resolve", 0, 0, 'r' },
@@ -4779,8 +5025,11 @@ 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' },
+       { "xdp", 0, 0, OPT_XDPSOCK},
+       { "oneline", 0, 0, 'O' },
        { 0 }
 
 };
@@ -4796,11 +5045,11 @@ int main(int argc, char *argv[])
        int state_filter = 0;
 
        while ((ch = getopt_long(argc, argv,
-                                "dhaletuwxnro460spbEf:miA:D:F:vVzZN:KHS",
+                                "dhaletuwxnro460spbEf:miA:D:F:vVzZN:KHSO",
                                 long_opts, NULL)) != EOF) {
                switch (ch) {
                case 'n':
-                       resolve_services = 0;
+                       numeric = 1;
                        break;
                case 'r':
                        resolve_hosts = 1;
@@ -4868,6 +5117,9 @@ int main(int argc, char *argv[])
                case '0':
                        filter_af_set(&current_filter, AF_PACKET);
                        break;
+               case OPT_XDPSOCK:
+                       filter_af_set(&current_filter, AF_XDP);
+                       break;
                case 'f':
                        if (strcmp(optarg, "inet") == 0)
                                filter_af_set(&current_filter, AF_INET);
@@ -4883,6 +5135,8 @@ int main(int argc, char *argv[])
                                filter_af_set(&current_filter, AF_TIPC);
                        else if (strcmp(optarg, "vsock") == 0)
                                filter_af_set(&current_filter, AF_VSOCK);
+                       else if (strcmp(optarg, "xdp") == 0)
+                               filter_af_set(&current_filter, AF_XDP);
                        else if (strcmp(optarg, "help") == 0)
                                help();
                        else {
@@ -4956,12 +5210,18 @@ 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;
                case 'H':
                        show_header = 0;
                        break;
+               case 'O':
+                       oneline = 1;
+                       break;
                case 'h':
                        help();
                case '?':
@@ -5007,7 +5267,7 @@ int main(int argc, char *argv[])
        filter_states_set(&current_filter, state_filter);
        filter_merge_defaults(&current_filter);
 
-       if (resolve_services && resolve_hosts &&
+       if (!numeric && resolve_hosts &&
            (current_filter.dbs & (UNIX_DBM|INET_L4_DBM)))
                init_service_resolver();
 
@@ -5080,6 +5340,8 @@ int main(int argc, char *argv[])
                vsock_show(&current_filter);
        if (current_filter.dbs & (1<<TIPC_DB))
                tipc_show(&current_filter);
+       if (current_filter.dbs & (1<<XDP_DB))
+               xdp_show(&current_filter);
 
        if (show_users || show_proc_ctx || show_sock_ctx)
                user_ent_destroy();