2015-12-17 20:56:48 +03:00
/*
* Copyright ( c ) 2014 Zubin Mithra < zubin . mithra @ gmail . com >
2016-01-31 02:50:54 +03:00
* Copyright ( c ) 2014 - 2016 Dmitry V . Levin < ldv @ altlinux . org >
2018-02-14 01:00:00 +03:00
* Copyright ( c ) 2014 - 2018 The strace developers .
2015-12-17 20:56:48 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : LGPL - 2.1 - or - later
2015-12-17 20:56:48 +03:00
*/
2014-08-21 07:17:48 +04:00
# include "defs.h"
# include <netinet/in.h>
# include <sys/socket.h>
# include <arpa/inet.h>
2017-06-25 01:25:28 +03:00
# include "netlink.h"
2014-08-21 07:17:48 +04:00
# include <linux/sock_diag.h>
# include <linux/inet_diag.h>
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
# include <linux/unix_diag.h>
2016-05-17 13:08:47 +03:00
# include <linux/netlink_diag.h>
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
# include <linux/rtnetlink.h>
2017-06-13 11:26:43 +03:00
# include <linux/genetlink.h>
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
# include <sys/un.h>
# ifndef UNIX_PATH_MAX
# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) 0)->sun_path)
# endif
2014-08-21 07:17:48 +04:00
2018-01-06 04:45:16 +03:00
# include "xstring.h"
socketutils: add more IP/IPv6 transport protocols
* defs.h (sock_proto): Add SOCK_PROTO_UDPLITE, SOCK_PROTO_DCCP,
SOCK_PROTO_SCTP, SOCK_PROTO_L2TP_IP, SOCK_PROTO_PING, SOCK_PROTO_RAW,
SOCK_PROTO_UDPLITEv6, SOCK_PROTO_DCCPv6, SOCK_PROTO_L2TP_IPv6,
SOCK_PROTO_SCTPv6, SOCK_PROTO_PINGv6, and SOCK_PROTO_RAWv6.
* socketutils.c: Include "xlat/inet_protocols.h" in XLAT_MACROS_ONLY
mode.
(protocols): Add protocol descriptions for them.
2018-08-27 13:46:34 +03:00
# define XLAT_MACROS_ONLY
# include "xlat / inet_protocols.h"
# undef XLAT_MACROS_ONLY
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
typedef struct {
unsigned long inode ;
char * details ;
} cache_entry ;
# define CACHE_SIZE 1024U
static cache_entry cache [ CACHE_SIZE ] ;
# define CACHE_MASK (CACHE_SIZE - 1)
static int
2016-06-22 16:51:49 +03:00
cache_inode_details ( const unsigned long inode , char * const details )
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
{
cache_entry * e = & cache [ inode & CACHE_MASK ] ;
free ( e - > details ) ;
e - > inode = inode ;
e - > details = details ;
return 1 ;
}
2017-06-04 14:38:30 +03:00
static const char *
get_sockaddr_by_inode_cached ( const unsigned long inode )
{
const cache_entry * const e = & cache [ inode & CACHE_MASK ] ;
return ( e & & inode = = e - > inode ) ? e - > details : NULL ;
}
2017-06-03 20:52:24 +03:00
static bool
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
print_sockaddr_by_inode_cached ( const unsigned long inode )
{
2017-06-04 14:38:30 +03:00
const char * const details = get_sockaddr_by_inode_cached ( inode ) ;
if ( details ) {
tprints ( details ) ;
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
return true ;
}
return false ;
}
2014-08-21 07:17:48 +04:00
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
send_query ( struct tcb * tcp , const int fd , void * req , size_t req_size )
2014-08-21 07:17:48 +04:00
{
2014-11-21 22:59:16 +03:00
struct sockaddr_nl nladdr = {
. nl_family = AF_NETLINK
} ;
2014-08-21 07:17:48 +04:00
struct iovec iov = {
2016-05-08 13:45:52 +03:00
. iov_base = req ,
. iov_len = req_size
2014-08-21 07:17:48 +04:00
} ;
2016-02-10 20:43:09 +03:00
const struct msghdr msg = {
. msg_name = & nladdr ,
2014-08-21 07:17:48 +04:00
. msg_namelen = sizeof ( nladdr ) ,
. msg_iov = & iov ,
. msg_iovlen = 1
} ;
for ( ; ; ) {
if ( sendmsg ( fd , & msg , 0 ) < 0 ) {
if ( errno = = EINTR )
continue ;
return false ;
}
return true ;
}
}
2016-05-08 13:45:52 +03:00
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
inet_send_query ( struct tcb * tcp , const int fd , const int family ,
const int proto )
2016-05-08 13:45:52 +03:00
{
struct {
const struct nlmsghdr nlh ;
const struct inet_diag_req_v2 idr ;
} req = {
. nlh = {
. nlmsg_len = sizeof ( req ) ,
. nlmsg_type = SOCK_DIAG_BY_FAMILY ,
. nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
} ,
. idr = {
. sdiag_family = family ,
. sdiag_protocol = proto ,
. idiag_states = - 1
}
} ;
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return send_query ( tcp , fd , & req , sizeof ( req ) ) ;
2016-05-08 13:45:52 +03:00
}
2016-01-31 02:50:54 +03:00
static int
2017-06-11 10:42:28 +03:00
inet_parse_response ( const void * const data , const int data_len ,
const unsigned long inode , void * opaque_data )
2014-08-21 07:17:48 +04:00
{
2017-06-11 10:42:28 +03:00
const char * const proto_name = opaque_data ;
2016-02-10 20:43:09 +03:00
const struct inet_diag_msg * const diag_msg = data ;
2014-08-21 07:17:48 +04:00
static const char zero_addr [ sizeof ( struct in6_addr ) ] ;
socklen_t addr_size , text_size ;
2016-01-29 02:46:56 +03:00
if ( data_len < ( int ) NLMSG_LENGTH ( sizeof ( * diag_msg ) ) )
2016-01-31 02:50:54 +03:00
return - 1 ;
2014-08-21 07:17:48 +04:00
if ( diag_msg - > idiag_inode ! = inode )
2016-01-31 02:50:54 +03:00
return 0 ;
2014-08-21 07:17:48 +04:00
2017-06-18 01:23:09 +03:00
switch ( diag_msg - > idiag_family ) {
2014-08-21 07:17:48 +04:00
case AF_INET :
addr_size = sizeof ( struct in_addr ) ;
text_size = INET_ADDRSTRLEN ;
break ;
case AF_INET6 :
addr_size = sizeof ( struct in6_addr ) ;
text_size = INET6_ADDRSTRLEN ;
break ;
default :
2016-01-31 02:50:54 +03:00
return - 1 ;
2014-08-21 07:17:48 +04:00
}
char src_buf [ text_size ] ;
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
char * details ;
2014-08-21 07:17:48 +04:00
2018-02-08 16:15:01 +03:00
/* open/closing brackets for IPv6 addresses */
const char * ob = diag_msg - > idiag_family = = AF_INET6 ? " [ " : " " ;
const char * cb = diag_msg - > idiag_family = = AF_INET6 ? " ] " : " " ;
2014-08-21 07:17:48 +04:00
if ( ! inet_ntop ( diag_msg - > idiag_family , diag_msg - > id . idiag_src ,
src_buf , text_size ) )
2016-01-31 02:50:54 +03:00
return - 1 ;
2014-08-21 07:17:48 +04:00
if ( diag_msg - > id . idiag_dport | |
memcmp ( zero_addr , diag_msg - > id . idiag_dst , addr_size ) ) {
char dst_buf [ text_size ] ;
if ( ! inet_ntop ( diag_msg - > idiag_family , diag_msg - > id . idiag_dst ,
dst_buf , text_size ) )
2016-01-31 02:50:54 +03:00
return - 1 ;
2014-08-21 07:17:48 +04:00
2018-02-08 16:15:01 +03:00
if ( asprintf ( & details , " %s:[%s%s%s:%u->%s%s%s:%u] " , proto_name ,
ob , src_buf , cb , ntohs ( diag_msg - > id . idiag_sport ) ,
ob , dst_buf , cb , ntohs ( diag_msg - > id . idiag_dport ) )
< 0 )
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
return false ;
2014-08-21 07:17:48 +04:00
} else {
2018-02-08 16:15:01 +03:00
if ( asprintf ( & details , " %s:[%s%s%s:%u] " ,
proto_name , ob , src_buf , cb ,
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
ntohs ( diag_msg - > id . idiag_sport ) ) < 0 )
return false ;
2014-08-21 07:17:48 +04:00
}
2016-06-22 16:51:49 +03:00
return cache_inode_details ( inode , details ) ;
2014-08-21 07:17:48 +04:00
}
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
receive_responses ( struct tcb * tcp , const int fd , const unsigned long inode ,
2017-06-11 10:42:27 +03:00
const unsigned long expected_msg_type ,
2017-06-11 10:42:28 +03:00
int ( * parser ) ( const void * , int ,
unsigned long , void * ) ,
void * opaque_data )
2014-08-21 07:17:48 +04:00
{
2016-05-19 04:23:40 +03:00
static union {
struct nlmsghdr hdr ;
long buf [ 8192 / sizeof ( long ) ] ;
} hdr_buf ;
2014-11-21 22:59:16 +03:00
struct sockaddr_nl nladdr = {
. nl_family = AF_NETLINK
} ;
2014-08-21 07:17:48 +04:00
struct iovec iov = {
2016-05-19 04:23:40 +03:00
. iov_base = hdr_buf . buf ,
. iov_len = sizeof ( hdr_buf . buf )
2014-08-21 07:17:48 +04:00
} ;
2016-01-28 00:35:50 +03:00
int flags = 0 ;
2014-08-21 07:17:48 +04:00
for ( ; ; ) {
struct msghdr msg = {
2016-02-10 20:43:09 +03:00
. msg_name = & nladdr ,
2014-08-21 07:17:48 +04:00
. msg_namelen = sizeof ( nladdr ) ,
. msg_iov = & iov ,
2014-11-21 22:59:16 +03:00
. msg_iovlen = 1
2014-08-21 07:17:48 +04:00
} ;
2016-02-10 20:43:09 +03:00
ssize_t ret = recvmsg ( fd , & msg , flags ) ;
2014-08-21 07:17:48 +04:00
if ( ret < 0 ) {
if ( errno = = EINTR )
continue ;
return false ;
}
2016-01-31 02:50:54 +03:00
2016-05-19 04:23:40 +03:00
const struct nlmsghdr * h = & hdr_buf . hdr ;
2018-09-17 00:32:37 +03:00
if ( ! is_nlmsg_ok ( h , ret ) )
2014-08-21 07:17:48 +04:00
return false ;
2018-09-17 00:32:37 +03:00
for ( ; is_nlmsg_ok ( h , ret ) ; h = NLMSG_NEXT ( h , ret ) ) {
2017-06-11 10:42:27 +03:00
if ( h - > nlmsg_type ! = expected_msg_type )
2016-01-31 02:50:54 +03:00
return false ;
2017-06-11 10:42:28 +03:00
const int rc = parser ( NLMSG_DATA ( h ) ,
h - > nlmsg_len , inode , opaque_data ) ;
2016-01-31 02:50:54 +03:00
if ( rc > 0 )
2014-08-21 07:17:48 +04:00
return true ;
2016-01-31 02:50:54 +03:00
if ( rc < 0 )
return false ;
2014-08-21 07:17:48 +04:00
}
2016-01-28 00:35:50 +03:00
flags = MSG_DONTWAIT ;
2014-08-21 07:17:48 +04:00
}
}
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
unix_send_query ( struct tcb * tcp , const int fd , const unsigned long inode )
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
{
2018-05-15 01:54:33 +03:00
/*
* The kernel bug was fixed in mainline by commit v4 .5 - rc6 ~ 35 ^ 2 ~ 11
* and backported to stable / linux - 4.4 . y by commit v4 .4 .4 ~ 297.
*/
const uint16_t dump_flag =
os_release < KERNEL_VERSION ( 4 , 4 , 4 ) ? NLM_F_DUMP : 0 ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
struct {
2016-02-10 20:43:09 +03:00
const struct nlmsghdr nlh ;
const struct unix_diag_req udr ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
} req = {
. nlh = {
. nlmsg_len = sizeof ( req ) ,
. nlmsg_type = SOCK_DIAG_BY_FAMILY ,
2018-05-15 01:54:33 +03:00
. nlmsg_flags = NLM_F_REQUEST | dump_flag
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
} ,
. udr = {
. sdiag_family = AF_UNIX ,
. udiag_ino = inode ,
. udiag_states = - 1 ,
2018-05-15 01:54:33 +03:00
. udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER ,
. udiag_cookie = { ~ 0U , ~ 0U }
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
}
} ;
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return send_query ( tcp , fd , & req , sizeof ( req ) ) ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
}
2016-01-31 02:50:54 +03:00
static int
2017-06-11 10:42:28 +03:00
unix_parse_response ( const void * data , const int data_len ,
const unsigned long inode , void * opaque_data )
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
{
2017-06-11 10:42:28 +03:00
const char * proto_name = opaque_data ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
const struct unix_diag_msg * diag_msg = data ;
struct rtattr * attr ;
int rta_len = data_len - NLMSG_LENGTH ( sizeof ( * diag_msg ) ) ;
uint32_t peer = 0 ;
size_t path_len = 0 ;
char path [ UNIX_PATH_MAX + 1 ] ;
2016-01-24 01:46:40 +03:00
if ( rta_len < 0 )
2016-01-31 02:50:54 +03:00
return - 1 ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
if ( diag_msg - > udiag_ino ! = inode )
2016-01-31 02:50:54 +03:00
return 0 ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
if ( diag_msg - > udiag_family ! = AF_UNIX )
2016-01-31 02:50:54 +03:00
return - 1 ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
for ( attr = ( struct rtattr * ) ( diag_msg + 1 ) ;
RTA_OK ( attr , rta_len ) ;
attr = RTA_NEXT ( attr , rta_len ) ) {
switch ( attr - > rta_type ) {
case UNIX_DIAG_NAME :
if ( ! path_len ) {
path_len = RTA_PAYLOAD ( attr ) ;
if ( path_len > UNIX_PATH_MAX )
path_len = UNIX_PATH_MAX ;
memcpy ( path , RTA_DATA ( attr ) , path_len ) ;
path [ path_len ] = ' \0 ' ;
}
break ;
case UNIX_DIAG_PEER :
if ( RTA_PAYLOAD ( attr ) > = 4 )
2016-01-31 02:50:54 +03:00
peer = * ( uint32_t * ) RTA_DATA ( attr ) ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
break ;
}
}
/*
* print obtained information in the following format :
* " UNIX:[ " SELF_INODE [ " -> " PEER_INODE ] [ " , " SOCKET_FILE ] " ] "
*/
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
if ( ! peer & & ! path_len )
return - 1 ;
char peer_str [ 3 + sizeof ( peer ) * 3 ] ;
if ( peer )
2018-01-06 04:45:16 +03:00
xsprintf ( peer_str , " ->%u " , peer ) ;
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
else
peer_str [ 0 ] = ' \0 ' ;
const char * path_str ;
if ( path_len ) {
char * outstr = alloca ( 4 * path_len + 4 ) ;
outstr [ 0 ] = ' , ' ;
if ( path [ 0 ] = = ' \0 ' ) {
outstr [ 1 ] = ' @ ' ;
string_quote ( path + 1 , outstr + 2 ,
2018-02-02 20:46:29 +03:00
path_len - 1 , QUOTE_0_TERMINATED , NULL ) ;
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
} else {
string_quote ( path , outstr + 1 ,
2018-02-02 20:46:29 +03:00
path_len , QUOTE_0_TERMINATED , NULL ) ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
}
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
path_str = outstr ;
} else {
path_str = " " ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
}
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
char * details ;
if ( asprintf ( & details , " %s:[%lu%s%s] " , proto_name , inode ,
peer_str , path_str ) < 0 )
2016-01-31 02:50:54 +03:00
return - 1 ;
Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.
The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.
* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-02 02:14:59 +03:00
2016-06-22 16:51:49 +03:00
return cache_inode_details ( inode , details ) ;
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
}
2016-05-17 13:08:47 +03:00
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
netlink_send_query ( struct tcb * tcp , const int fd , const unsigned long inode )
2016-05-17 13:08:47 +03:00
{
struct {
const struct nlmsghdr nlh ;
const struct netlink_diag_req ndr ;
} req = {
. nlh = {
. nlmsg_len = sizeof ( req ) ,
. nlmsg_type = SOCK_DIAG_BY_FAMILY ,
. nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
} ,
. ndr = {
. sdiag_family = AF_NETLINK ,
2018-05-14 20:20:21 +03:00
. sdiag_protocol = NDIAG_PROTO_ALL
2016-05-17 13:08:47 +03:00
}
} ;
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return send_query ( tcp , fd , & req , sizeof ( req ) ) ;
2016-05-17 13:08:47 +03:00
}
static int
2017-06-11 10:42:28 +03:00
netlink_parse_response ( const void * data , const int data_len ,
const unsigned long inode , void * opaque_data )
2016-05-17 13:08:47 +03:00
{
2017-06-11 10:42:28 +03:00
const char * proto_name = opaque_data ;
2016-05-17 13:08:47 +03:00
const struct netlink_diag_msg * const diag_msg = data ;
const char * netlink_proto ;
char * details ;
if ( data_len < ( int ) NLMSG_LENGTH ( sizeof ( * diag_msg ) ) )
return - 1 ;
if ( diag_msg - > ndiag_ino ! = inode )
return 0 ;
if ( diag_msg - > ndiag_family ! = AF_NETLINK )
return - 1 ;
netlink_proto = xlookup ( netlink_protocols ,
diag_msg - > ndiag_protocol ) ;
if ( netlink_proto ) {
2017-06-03 19:55:12 +03:00
netlink_proto = STR_STRIP_PREFIX ( netlink_proto , " NETLINK_ " ) ;
2016-05-17 13:08:47 +03:00
if ( asprintf ( & details , " %s:[%s:%u] " , proto_name ,
netlink_proto , diag_msg - > ndiag_portid ) < 0 )
return - 1 ;
} else {
if ( asprintf ( & details , " %s:[%u] " , proto_name ,
( unsigned ) diag_msg - > ndiag_protocol ) < 0 )
return - 1 ;
}
2016-06-22 16:51:49 +03:00
return cache_inode_details ( inode , details ) ;
2016-05-17 13:08:47 +03:00
}
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
static const char *
2018-08-27 13:41:48 +03:00
unix_get ( struct tcb * tcp , const int fd , const int family , const int proto ,
const unsigned long inode , const char * name )
Support unix domain sockets in -yy option
This change extends -yy option to handle unix domain sockets:
their peer addresses will be printed, similar to inet sockets.
For a listening socket, its socket inode and socket path are printed.
For an accepted socket, its socket inode, the peer inode, and the
socket path are printed.
For a client socket, its socket inode and the peer inode are printed.
An example of a server side communication using netcat:
$ ./strace -yy -e network nc -l -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0
accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]>
recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6
INPUT
An example of a client side communication using netcat:
$ ./strace -yy -e network nc -U /tmp/example.sock
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
INPUT
...
sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6
* linux/unix_diag.h: New file.
* socketutils.c (send_query): Rename to inet_send_query.
(parse_response): Rename to inet_parse_response.
(unix_print, unix_send_query, unix_parse_response): New functions.
(receive_responses): Add a new argument named parser: a function for
handling protocol specific data parts of diag messages.
(print_sockaddr_by_inode): Call unix_print.
Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal
but NETLINK_SOCK_DIAG looks more generic.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 14:59:31 +03:00
{
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return unix_send_query ( tcp , fd , inode )
& & receive_responses ( tcp , fd , inode , SOCK_DIAG_BY_FAMILY ,
2018-08-27 13:41:48 +03:00
unix_parse_response , ( void * ) name )
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
? get_sockaddr_by_inode_cached ( inode ) : NULL ;
2014-12-10 06:55:06 +03:00
}
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
static const char *
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
inet_get ( struct tcb * tcp , const int fd , const int family , const int protocol ,
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
const unsigned long inode , const char * proto_name )
2017-06-03 02:26:15 +03:00
{
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return inet_send_query ( tcp , fd , family , protocol )
& & receive_responses ( tcp , fd , inode , SOCK_DIAG_BY_FAMILY ,
2017-06-11 10:42:28 +03:00
inet_parse_response , ( void * ) proto_name )
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
? get_sockaddr_by_inode_cached ( inode ) : NULL ;
2017-06-03 02:26:15 +03:00
}
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
static const char *
2018-08-27 13:41:48 +03:00
netlink_get ( struct tcb * tcp , const int fd , const int family , const int protocol ,
const unsigned long inode , const char * proto_name )
2016-05-17 13:08:47 +03:00
{
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return netlink_send_query ( tcp , fd , inode )
& & receive_responses ( tcp , fd , inode , SOCK_DIAG_BY_FAMILY ,
2018-08-27 13:41:48 +03:00
netlink_parse_response ,
( void * ) proto_name )
socketutils.c: use get_sockaddr_by_inode_cached
* socketutils.c (unix_print, inet_print, tcp_v4_print, tcp_v6_print,
udp_v4_print, udp_v6_print, netlink_print): Remove.
(unix_get, inet_get, tcp_v4_get, tcp_v6_get, udp_v4_get,
udp_v6_get, netlink_get): New functions.
(protocols): Update.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2016-05-26 13:46:28 +03:00
? get_sockaddr_by_inode_cached ( inode ) : NULL ;
2016-05-17 13:08:47 +03:00
}
2016-06-17 19:29:53 +03:00
static const struct {
const char * const name ;
2018-08-27 13:41:48 +03:00
const char * ( * const get ) ( struct tcb * , int fd , int family ,
int protocol , unsigned long inode ,
const char * proto_name ) ;
int family ;
int proto ;
2016-06-17 19:29:53 +03:00
} protocols [ ] = {
2018-08-27 13:41:48 +03:00
[ SOCK_PROTO_UNIX ] = { " UNIX " , unix_get , AF_UNIX } ,
socketutils: add more IP/IPv6 transport protocols
* defs.h (sock_proto): Add SOCK_PROTO_UDPLITE, SOCK_PROTO_DCCP,
SOCK_PROTO_SCTP, SOCK_PROTO_L2TP_IP, SOCK_PROTO_PING, SOCK_PROTO_RAW,
SOCK_PROTO_UDPLITEv6, SOCK_PROTO_DCCPv6, SOCK_PROTO_L2TP_IPv6,
SOCK_PROTO_SCTPv6, SOCK_PROTO_PINGv6, and SOCK_PROTO_RAWv6.
* socketutils.c: Include "xlat/inet_protocols.h" in XLAT_MACROS_ONLY
mode.
(protocols): Add protocol descriptions for them.
2018-08-27 13:46:34 +03:00
/*
* inet_diag handlers are currently implemented only for TCP ,
* UDP ( lite ) , SCTP , RAW , and DCCP , but we try to resolve it for all
* protocols anyway , just in case .
*/
2018-08-27 13:41:48 +03:00
[ SOCK_PROTO_TCP ] =
{ " TCP " , inet_get , AF_INET , IPPROTO_TCP } ,
[ SOCK_PROTO_UDP ] =
{ " UDP " , inet_get , AF_INET , IPPROTO_UDP } ,
socketutils: add more IP/IPv6 transport protocols
* defs.h (sock_proto): Add SOCK_PROTO_UDPLITE, SOCK_PROTO_DCCP,
SOCK_PROTO_SCTP, SOCK_PROTO_L2TP_IP, SOCK_PROTO_PING, SOCK_PROTO_RAW,
SOCK_PROTO_UDPLITEv6, SOCK_PROTO_DCCPv6, SOCK_PROTO_L2TP_IPv6,
SOCK_PROTO_SCTPv6, SOCK_PROTO_PINGv6, and SOCK_PROTO_RAWv6.
* socketutils.c: Include "xlat/inet_protocols.h" in XLAT_MACROS_ONLY
mode.
(protocols): Add protocol descriptions for them.
2018-08-27 13:46:34 +03:00
[ SOCK_PROTO_UDPLITE ] =
{ " UDPLITE " , inet_get , AF_INET , IPPROTO_UDPLITE } ,
[ SOCK_PROTO_DCCP ] =
{ " DCCP " , inet_get , AF_INET , IPPROTO_DCCP } ,
[ SOCK_PROTO_SCTP ] =
{ " SCTP " , inet_get , AF_INET , IPPROTO_SCTP } ,
[ SOCK_PROTO_L2TP_IP ] =
{ " L2TP/IP " , inet_get , AF_INET , IPPROTO_L2TP } ,
[ SOCK_PROTO_PING ] =
{ " PING " , inet_get , AF_INET , IPPROTO_ICMP } ,
[ SOCK_PROTO_RAW ] =
{ " RAW " , inet_get , AF_INET , IPPROTO_RAW } ,
2018-08-27 13:41:48 +03:00
[ SOCK_PROTO_TCPv6 ] =
{ " TCPv6 " , inet_get , AF_INET6 , IPPROTO_TCP } ,
[ SOCK_PROTO_UDPv6 ] =
{ " UDPv6 " , inet_get , AF_INET6 , IPPROTO_UDP } ,
socketutils: add more IP/IPv6 transport protocols
* defs.h (sock_proto): Add SOCK_PROTO_UDPLITE, SOCK_PROTO_DCCP,
SOCK_PROTO_SCTP, SOCK_PROTO_L2TP_IP, SOCK_PROTO_PING, SOCK_PROTO_RAW,
SOCK_PROTO_UDPLITEv6, SOCK_PROTO_DCCPv6, SOCK_PROTO_L2TP_IPv6,
SOCK_PROTO_SCTPv6, SOCK_PROTO_PINGv6, and SOCK_PROTO_RAWv6.
* socketutils.c: Include "xlat/inet_protocols.h" in XLAT_MACROS_ONLY
mode.
(protocols): Add protocol descriptions for them.
2018-08-27 13:46:34 +03:00
[ SOCK_PROTO_UDPLITEv6 ] =
{ " UDPLITEv6 " , inet_get , AF_INET6 , IPPROTO_UDPLITE } ,
[ SOCK_PROTO_DCCPv6 ] =
{ " DCCPv6 " , inet_get , AF_INET6 , IPPROTO_DCCP } ,
[ SOCK_PROTO_SCTPv6 ] =
{ " SCTPv6 " , inet_get , AF_INET6 , IPPROTO_SCTP } ,
[ SOCK_PROTO_L2TP_IPv6 ] =
{ " L2TP/IPv6 " , inet_get , AF_INET6 , IPPROTO_L2TP } ,
[ SOCK_PROTO_PINGv6 ] =
{ " PINGv6 " , inet_get , AF_INET6 , IPPROTO_ICMP } ,
[ SOCK_PROTO_RAWv6 ] =
{ " RAWv6 " , inet_get , AF_INET6 , IPPROTO_RAW } ,
2018-08-27 13:41:48 +03:00
[ SOCK_PROTO_NETLINK ] = { " NETLINK " , netlink_get , AF_NETLINK } ,
2016-06-17 19:29:53 +03:00
} ;
enum sock_proto
get_proto_by_name ( const char * const name )
{
unsigned int i ;
for ( i = ( unsigned int ) SOCK_PROTO_UNKNOWN + 1 ;
i < ARRAY_SIZE ( protocols ) ; + + i ) {
if ( protocols [ i ] . name & & ! strcmp ( name , protocols [ i ] . name ) )
return ( enum sock_proto ) i ;
}
return SOCK_PROTO_UNKNOWN ;
}
2018-08-27 13:49:20 +03:00
int
get_family_by_proto ( enum sock_proto proto )
{
if ( ( size_t ) proto < ARRAY_SIZE ( protocols ) )
return protocols [ proto ] . family ;
return AF_UNSPEC ;
}
2017-06-03 02:30:57 +03:00
static const char *
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
get_sockaddr_by_inode_uncached ( struct tcb * tcp , const unsigned long inode ,
2017-06-03 02:30:57 +03:00
const enum sock_proto proto )
2014-08-21 07:17:48 +04:00
{
2016-06-17 19:29:53 +03:00
if ( ( unsigned int ) proto > = ARRAY_SIZE ( protocols ) | |
2017-06-03 02:30:57 +03:00
( proto ! = SOCK_PROTO_UNKNOWN & & ! protocols [ proto ] . get ) )
return NULL ;
2014-08-21 07:17:48 +04:00
2016-02-10 20:39:57 +03:00
const int fd = socket ( AF_NETLINK , SOCK_RAW , NETLINK_SOCK_DIAG ) ;
2014-08-21 07:17:48 +04:00
if ( fd < 0 )
2017-06-03 02:30:57 +03:00
return NULL ;
const char * details = NULL ;
2016-01-23 19:35:02 +03:00
2016-06-17 19:29:53 +03:00
if ( proto ! = SOCK_PROTO_UNKNOWN ) {
2018-08-27 13:41:48 +03:00
details = protocols [ proto ] . get ( tcp , fd , protocols [ proto ] . family ,
protocols [ proto ] . proto , inode ,
protocols [ proto ] . name ) ;
2014-12-10 06:55:06 +03:00
} else {
2016-06-17 19:29:53 +03:00
unsigned int i ;
for ( i = ( unsigned int ) SOCK_PROTO_UNKNOWN + 1 ;
i < ARRAY_SIZE ( protocols ) ; + + i ) {
2017-06-03 02:30:57 +03:00
if ( ! protocols [ i ] . get )
2016-06-17 19:29:53 +03:00
continue ;
2018-08-27 13:41:48 +03:00
details = protocols [ i ] . get ( tcp , fd ,
protocols [ proto ] . family ,
protocols [ proto ] . proto ,
inode ,
protocols [ proto ] . name ) ;
2017-06-03 02:30:57 +03:00
if ( details )
2014-12-27 02:29:26 +03:00
break ;
2014-08-21 07:17:48 +04:00
}
}
2014-12-27 02:29:26 +03:00
2014-08-21 07:17:48 +04:00
close ( fd ) ;
2017-06-03 02:30:57 +03:00
return details ;
}
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
print_sockaddr_by_inode_uncached ( struct tcb * tcp , const unsigned long inode ,
2017-06-03 02:30:57 +03:00
const enum sock_proto proto )
{
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
const char * details = get_sockaddr_by_inode_uncached ( tcp , inode , proto ) ;
2017-06-03 02:30:57 +03:00
if ( details ) {
tprints ( details ) ;
return true ;
}
if ( ( unsigned int ) proto < ARRAY_SIZE ( protocols ) & &
protocols [ proto ] . name ) {
tprintf ( " %s:[%lu] " , protocols [ proto ] . name , inode ) ;
return true ;
}
return false ;
2014-08-21 07:17:48 +04:00
}
2017-06-03 20:52:24 +03:00
2016-05-26 13:46:28 +03:00
/* Given an inode number of a socket, return its protocol details. */
const char *
get_sockaddr_by_inode ( struct tcb * const tcp , const int fd ,
const unsigned long inode )
{
const char * details = get_sockaddr_by_inode_cached ( inode ) ;
return details ? details :
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
get_sockaddr_by_inode_uncached ( tcp , inode , getfdproto ( tcp , fd ) ) ;
2016-05-26 13:46:28 +03:00
}
2017-06-03 20:52:24 +03:00
/* Given an inode number of a socket, print out its protocol details. */
bool
print_sockaddr_by_inode ( struct tcb * const tcp , const int fd ,
2017-06-18 01:23:09 +03:00
const unsigned long inode )
2017-06-03 20:52:24 +03:00
{
return print_sockaddr_by_inode_cached ( inode ) ? true :
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
print_sockaddr_by_inode_uncached ( tcp , inode ,
getfdproto ( tcp , fd ) ) ;
2017-06-03 20:52:24 +03:00
}
2017-06-13 11:26:43 +03:00
/*
* Managing the cache for decoding communications of Netlink GENERIC protocol
*
* As name shown Netlink GENERIC protocol is generic protocol . The
* numbers of msg types used in the protocol are not defined
* statically . Kernel defines them on demand . So the xlat converted
* from header files doesn ' t help for decoding the protocol . Following
* codes are building xlat ( dyxlat ) at runtime .
*/
static bool
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
genl_send_dump_families ( struct tcb * tcp , const int fd )
2017-06-13 11:26:43 +03:00
{
struct {
const struct nlmsghdr nlh ;
struct genlmsghdr gnlh ;
} req = {
. nlh = {
. nlmsg_len = sizeof ( req ) ,
. nlmsg_type = GENL_ID_CTRL ,
. nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST ,
} ,
. gnlh = {
. cmd = CTRL_CMD_GETFAMILY ,
}
} ;
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
return send_query ( tcp , fd , & req , sizeof ( req ) ) ;
2017-06-13 11:26:43 +03:00
}
static int
genl_parse_families_response ( const void * const data ,
const int data_len , const unsigned long inode ,
void * opaque_data )
{
struct dyxlat * const dyxlat = opaque_data ;
const struct genlmsghdr * const gnlh = data ;
struct rtattr * attr ;
int rta_len = data_len - NLMSG_LENGTH ( sizeof ( * gnlh ) ) ;
char * name = NULL ;
unsigned int name_len = 0 ;
uint16_t * id = NULL ;
if ( rta_len < 0 )
return - 1 ;
if ( gnlh - > cmd ! = CTRL_CMD_NEWFAMILY )
return - 1 ;
if ( gnlh - > version ! = 2 )
return - 1 ;
for ( attr = ( struct rtattr * ) ( gnlh + 1 ) ;
RTA_OK ( attr , rta_len ) ;
attr = RTA_NEXT ( attr , rta_len ) ) {
switch ( attr - > rta_type ) {
case CTRL_ATTR_FAMILY_NAME :
if ( ! name ) {
name = RTA_DATA ( attr ) ;
name_len = RTA_PAYLOAD ( attr ) ;
}
break ;
case CTRL_ATTR_FAMILY_ID :
if ( ! id & & RTA_PAYLOAD ( attr ) = = sizeof ( * id ) )
id = RTA_DATA ( attr ) ;
break ;
}
if ( name & & id ) {
dyxlat_add_pair ( dyxlat , * id , name , name_len ) ;
name = NULL ;
id = NULL ;
}
}
return 0 ;
}
const struct xlat *
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
genl_families_xlat ( struct tcb * tcp )
2017-06-13 11:26:43 +03:00
{
static struct dyxlat * dyxlat ;
if ( ! dyxlat ) {
dyxlat = dyxlat_alloc ( 32 ) ;
int fd = socket ( AF_NETLINK , SOCK_RAW , NETLINK_GENERIC ) ;
if ( fd < 0 )
goto out ;
Add tcp arguments to netlink calls
Since they call tracee-specific socket/sendmsg/recvmsg, we'd like to
pass tcp there.
* defs.h (genl_families_xlat): Add tcp argument.
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_generic,
decode_nlmsg_type_netfilter, typedef nlmsg_types_decoder_t): Likewise.
(decode_nlmsg_type): Add tcp argument. Pass tcp to decoder call.
(print_nlmsghdr): Pass tcp to the decode_nlmsg_type call.
* socketutils.c (send_query, receive_responses): Add tcp argument.
(inet_send_query, unix_send_query, netlink_send_query, ): Add tcp argument.
Pass tcp to the send_query call.
(unix_get): Add tcp argument. Pass tcp to the unix_send_query and
receive_responses calls.
(inet_get): Add tcp argument. Pass tcp to the inet_send_query and
receive_responses calls.
(tcp_v4_get, udp_v4_get, tcp_v6_get, udp_v6_get): Add tcp argument. Pass
tcp to the inet_get call.
(netlink_get): Add tcp argument. Pass tcp to the netlink_send_query and
receive_responses calls.
(protocols): Add tcp argument to the get field.
(get_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the protocols[].get calls.
(print_sockaddr_by_inode_uncached): Add tcp argument. Pass tcp to
the get_sockaddr_by_inode_uncached call.
(get_sockaddr_by_inode): Pass tcp to the get_sockaddr_by_inode_uncached
call.
(print_sockaddr_by_inode): Pass tcp to the
print_sockaddr_by_inode_uncached call.
(genl_send_dump_families): Add tcp argument. Pass tcp to the send_query
call.
(genl_families_xlat): Add tcp argument. Pass tcp to the
genl_send_dump_families and receive_responses calls.
2017-12-26 02:14:14 +03:00
if ( genl_send_dump_families ( tcp , fd ) )
receive_responses ( tcp , fd , 0 , GENL_ID_CTRL ,
2017-06-13 11:26:43 +03:00
genl_parse_families_response , dyxlat ) ;
close ( fd ) ;
}
out :
return dyxlat_get ( dyxlat ) ;
}