From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets Date: Mon, 27 Aug 2018 15:27:25 -0700 Message-ID: <20180827152725.479342e7@shemminger-XPS-13-9360> References: <20180827214652.29318-1-xiyou.wangcong@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org To: Cong Wang Return-path: Received: from mail-qk0-f193.google.com ([209.85.220.193]:43282 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeH1CQG (ORCPT ); Mon, 27 Aug 2018 22:16:06 -0400 Received: by mail-qk0-f193.google.com with SMTP id 130-v6so429241qkd.10 for ; Mon, 27 Aug 2018 15:27:30 -0700 (PDT) In-Reply-To: <20180827214652.29318-1-xiyou.wangcong@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: On Mon, 27 Aug 2018 14:46:52 -0700 Cong Wang wrote: > UNIX_DIAG_VFS and UNIX_DIAG_ICONS are never used by ss, > make them available in ss -e output. > > Cc: Stephen Hemminger > Signed-off-by: Cong Wang > --- > misc/ss.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/misc/ss.c b/misc/ss.c > index 41e7762b..d28bc1ec 100644 > --- a/misc/ss.c > +++ b/misc/ss.c > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include Why is this included, it isn't on my system. > #include > #include > #include > @@ -3604,6 +3605,28 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh, > out(" %c-%c", > mask & 1 ? '-' : '<', mask & 2 ? '-' : '>'); > } > + if (tb[UNIX_DIAG_VFS]) { > + struct unix_diag_vfs uv; > + > + memcpy(&uv, RTA_DATA(tb[UNIX_DIAG_VFS]), sizeof(uv)); Copy here is unnecessary, you can just do: const struct unix_diag_vfs *uv = RTA_DATA(tb[UNIX_DIAG_VFS]); > + out(" ino:%u dev:%u/%u", uv.udiag_vfs_ino, major(uv.udiag_vfs_dev), > + minor(uv.udiag_vfs_dev)); > + } > + if (tb[UNIX_DIAG_ICONS]) { > + int len = RTA_PAYLOAD(tb[UNIX_DIAG_ICONS]); > + __u32 *peers = malloc(len); > + int i; Ditto, allocation and copy are not necessary, just reference the data. > + if (!peers) { > + fprintf(stderr, "ss: failed to malloc buffer\n"); > + abort(); > + } > + memcpy(peers, RTA_DATA(tb[UNIX_DIAG_ICONS]), len); > + out(" peers:"); > + for (i = 0; i < len / sizeof(__u32); i++) > + out(" %u", peers[i]); > + free(peers); > + } > } > > return 0; > @@ -3641,6 +3664,8 @@ static int unix_show_netlink(struct filter *f) > req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER | UDIAG_SHOW_RQLEN; > if (show_mem) > req.r.udiag_show |= UDIAG_SHOW_MEMINFO; > + if (show_details) > + req.r.udiag_show |= UDIAG_SHOW_VFS | UDIAG_SHOW_ICONS; > > return handle_netlink_request(f, &req.nlh, sizeof(req), unix_show_sock); > }