ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets
Subsystems (2)
PATCH 1/1 ss: add UNIX_DIAG_VFS and UNIX_DIAG_ICONS for unix sockets
UNIX_DIAG_VFS and UNIX_DIAG_ICONS are never used by ss, make them available in ss -e output.
--- misc/ss.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
misc/ss.c +25 -0
@@ -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); }
Signature · 1 line
2.14.4
Quoted 14 lines · On Mon, 27 Aug 2018 14:46:52 -0700 Cong Wang <[email protected]> wrote:
UNIX_DIAG_VFSandUNIX_DIAG_ICONSare never used by ss, make them available in ss -e output.Cc Stephen Hemminger <[email protected]>Signed-off-by Cong Wang <[email protected]>--- misc/ss.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)misc/ss.c +0
-0
misc/ss.c line 19
Quoted 4 lines
misc/ss.c +1
-0@@ -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.
misc/ss.c static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh, · line 3611
Quoted 11 lines
misc/ss.c +4
-0#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]);
misc/ss.c static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh, · line 3618
Quoted 7 lines
misc/ss.c +7
-0+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.
Quoted 22 lines
misc/ss.c +12
-0+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); }
Quoted 13 lines · Stephen Hemminger
Quoted 9 lines · On Mon, 27 Aug 2018 14:46:52 -0700 Cong Wang <[email protected]> wrote:
UNIX_DIAG_VFSandUNIX_DIAG_ICONSare never used by ss, make them available in ss -e output.Cc Stephen Hemminger <[email protected]>Signed-off-by Cong Wang <[email protected]>--- misc/ss.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Quoted 11 lines
misc/ss.c line 19
Quoted 9 lines
misc/ss.c +1
-0@@ -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?
Quoted 16 lines
misc/ss.c static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh, · line 3611
Quoted 12 lines
misc/ss.c +4
-0#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 structunix_diag_vfs*uv
=RTA_DATA(tb[UNIX_DIAG_VFS]);
Oh, good point!
Quoted 11 lines
misc/ss.c static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh, · line 3618
Quoted 8 lines
misc/ss.c +7
-0+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.
Quoted 27 lines · On Tue, 28 Aug 2018 16:16:49 -0700 Cong Wang <[email protected]> wrote:
Quoted 13 lines · Stephen Hemminger
Quoted 9 lines · On Mon, 27 Aug 2018 14:46:52 -0700 Cong Wang <[email protected]> wrote:
UNIX_DIAG_VFSandUNIX_DIAG_ICONSare never used by ss, make them available in ss -e output.Cc Stephen Hemminger <[email protected]>Signed-off-by Cong Wang <[email protected]>--- misc/ss.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)Quoted 11 lines
misc/ss.c line 19
Quoted 9 lines
misc/ss.c +1
-0@@ -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.
Quoted 1 line
It is for
major()andminor().
Ok on Debian, these are in the architecture include, so this will work fine.