All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets
@ 2018-08-27 21:46 Cong Wang
  2018-08-27 22:27 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2018-08-27 21:46 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Stephen Hemminger

UNIX_DIAG_VFS and UNIX_DIAG_ICONS are never used by ss,
make them available in ss -e output.

Cc: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 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 <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
+#include <sys/sysmacros.h>
 #include <netinet/in.h>
 #include <string.h>
 #include <errno.h>
@@ -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));
+			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;
+
+			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);
 }
-- 
2.14.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets
  2018-08-27 21:46 [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets Cong Wang
@ 2018-08-27 22:27 ` Stephen Hemminger
  2018-08-28 23:16   ` Cong Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2018-08-27 22:27 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev

On Mon, 27 Aug 2018 14:46:52 -0700
Cong Wang <xiyou.wangcong@gmail.com> wrote:

> UNIX_DIAG_VFS and UNIX_DIAG_ICONS are never used by ss,
> make them available in ss -e output.
> 
> Cc: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  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 <sys/ioctl.h>
>  #include <sys/socket.h>
>  #include <sys/uio.h>
> +#include <sys/sysmacros.h>

Why is this included, it isn't on my system.

>  #include <netinet/in.h>
>  #include <string.h>
>  #include <errno.h>
> @@ -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);
>  }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets
  2018-08-27 22:27 ` Stephen Hemminger
@ 2018-08-28 23:16   ` Cong Wang
  2018-08-29 15:41     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2018-08-28 23:16 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Linux Kernel Network Developers

On Mon, Aug 27, 2018 at 3:27 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Mon, 27 Aug 2018 14:46:52 -0700
> Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> > UNIX_DIAG_VFS and UNIX_DIAG_ICONS are never used by ss,
> > make them available in ss -e output.
> >
> > Cc: Stephen Hemminger <stephen@networkplumber.org>
> > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> > ---
> >  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 <sys/ioctl.h>
> >  #include <sys/socket.h>
> >  #include <sys/uio.h>
> > +#include <sys/sysmacros.h>
>
> Why is this included, it isn't on my system.

It is for major() and minor().

$ find /usr/include/ -name sysmacros.h
/usr/include/bits/sysmacros.h
/usr/include/sys/sysmacros.h
$ rpm -qf /usr/include/sys/sysmacros.h
glibc-headers-2.26-28.fc27.x86_64

So you are not using glibc? Or iproute2 should be built with non-glibc?

>
> >  #include <netinet/in.h>
> >  #include <string.h>
> >  #include <errno.h>
> > @@ -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]);


Oh, good point!


>
> > +                     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.
>

Sure, will update.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets
  2018-08-28 23:16   ` Cong Wang
@ 2018-08-29 15:41     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2018-08-29 15:41 UTC (permalink / raw)
  To: Cong Wang; +Cc: Linux Kernel Network Developers

On Tue, 28 Aug 2018 16:16:49 -0700
Cong Wang <xiyou.wangcong@gmail.com> wrote:

> On Mon, Aug 27, 2018 at 3:27 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > On Mon, 27 Aug 2018 14:46:52 -0700
> > Cong Wang <xiyou.wangcong@gmail.com> wrote:
> >  
> > > UNIX_DIAG_VFS and UNIX_DIAG_ICONS are never used by ss,
> > > make them available in ss -e output.
> > >
> > > Cc: Stephen Hemminger <stephen@networkplumber.org>
> > > Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> > > ---
> > >  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 <sys/ioctl.h>
> > >  #include <sys/socket.h>
> > >  #include <sys/uio.h>
> > > +#include <sys/sysmacros.h>  
> >
> > Why is this included, it isn't on my system.  
> 
> It is for major() and minor().

Ok on Debian, these are in the architecture include, so this will work fine.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-29 19:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-27 21:46 [Patch iproute2] ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets Cong Wang
2018-08-27 22:27 ` Stephen Hemminger
2018-08-28 23:16   ` Cong Wang
2018-08-29 15:41     ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.