IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an
email to Administrator. User accounts are meant only to access repo
and report issues and/or generate pull requests.
This is a purpose-specific Git hosting for
BaseALT
projects. Thank you for your understanding!
Только зарегистрированные пользователи имеют доступ к сервису!
Для получения аккаунта, обратитесь к администратору.
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.
Add a fallback definition of NETLINK_SOCK_DIAG to netlink.h
instead of adding these fallback definitions to every file.
* netlink.h: Provide a fallback definition of NETLINK_SOCK_DIAG.
* socketutils.c: Include "netlink.h" instead of <linux/netlink.h>,
remove fallback definition of NETLINK_SOCK_DIAG.
* configure.ac (AC_CHECK_HEADERS): Add linux/genetlink.h.
* defs.h (genl_families_xlat): New prototype.
* socketutils.c [HAVE_LINUX_GENETLINK_H]: Include <linux/genetlink.h>.
[HAVE_LINUX_GENETLINK_H] (genl_send_dump_families,
genl_parse_families_response): New helper functions.
(genl_families_xlat): New function for building the xlat table
for NETLINK_GENERIC decoding.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
This is the second patch in series of implementing NETLINK_GENERIC
protocol decoder.
This change allows passing of opaque user data to the callback function.
* socketutils.c (receive_responses): Change the type of proto_name
argument from "const char *" to "void *" to allow passing
of arbitrary data to the callback function.
Rename proto_name to opaque_data, make it the last argument.
Pass it to the callback function as the last argument.
(inet_parse_response, unix_parse_response, netlink_parse_response):
Change the type of proto_name argument from "const char *" to "void *",
rename it to opaque_data, make it the last argument.
Introduce a local variable proto_name to convert the type
of opaque_data argument from "void *" to "const char *".
(unix_get, inet_get, netlink_get): Cast the protocol name from
"const char *" to "void *" for passing to the callback function.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
This is the first patch in series of implementing NETLINK_GENERIC
protocol decoder.
receive_responses was written for decoding kernel responses of type
SOCK_DIAG_BY_FAMILY, other types were ignored.
This change makes the type of netlink response a parameter
so the function can be used for other types of communication.
* socketutils.c (receive_responses): add a new parameter
expected_msg_type to handle types other than SOCK_DIAG_BY_FAMILY.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Add a way to get socket information without printing it.
* defs.h (get_sockaddr_by_inode): New prototype.
* socketutils.c (get_sockaddr_by_inode): New function.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
cache_inode_details gives a way to obtain cache information without
printing it.
* socketutils.c (cache_and_print_inode_details): Rename
to cache_inode_details. Do not print cached information.
(inet_parse_response, unix_parse_response, netlink_parse_response):
Use cache_inode_details instead of cache_and_print_inode_details.
(inet_print, unix_print, netlink_print): Call
print_sockaddr_by_inode_cached.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Change print_sockaddr_by_inode to be the only function exposed,
hide print_sockaddr_by_inode_cached as a part of implementation.
* defs.h (print_sockaddr_by_inode_cached): Remove prototype.
(print_sockaddr_by_inode): Add struct tcb * and descriptor arguments.
* socketutils.c (print_sockaddr_by_inode_cached): Make static.
(print_sockaddr_by_inode): Rename to print_sockaddr_by_inode_uncached,
make static.
(print_sockaddr_by_inode): New function.
* util.c (printfd): Update to use new print_sockaddr_by_inode.
Make netlink_protocols a global xlat array defined in net.c file.
* defs.h (netlink_protocols): New prototype.
* socketutils.c: Stop including "xlat/netlink_protocols.h".
As new constants have been added gradually over kernel releases, define
all constant values to make newer constants decoded properly when strace
is built with older kernel headers.
* xlat/netlink_protocols.in: Add default values for constants.
* net.c [!NETLINK_SOCK_DIAG && NETLINK_INET_DIAG]: Remove.
* socketutils.c: Likewise.
Introduce a new enum type sock_proto and use it instead of strings for socket
protocols identification.
* defs.h (sock_proto): New enum.
(get_proto_by_name): New function.
* socketutils.c (protocols): New static table.
(print_sockaddr_by_inode): Use it. Change type of "proto" argument
to sock_proto.
(get_proto_by_name): New function.
* util.c (getfdproto): Use it. Change return type to sock_proto.
(printfd): Update.
* linux/netlink_diag.h: New file.
* Makefile.am (EXTRA_DIST): Add it.
* socketutils.c: Include it and "xlat/netlink_protocols.h".
(netlink_send_query, netlink_parse_response, netlink_print): New
functions.
(print_sockaddr_by_inode): Hook up netlink_print.
Unfortunately, 64-bit linux kernel has a bug in matching inode numbers
greater than INT_MAX, so unix_diag exact match is not reliable.
This partially reverts commit 69bfc89770.
* socketutils.c (unix_send_query): Add NLM_F_DUMP to nlmsg_flags,
remove initialization of udiag_cookie.
* tests/netlink_unix_diag.c (send_query): Remove "inode" argument,
add NLM_F_DUMP to nlmsg_flags, remove initialization of udiag_ino
and udiag_cookie.
(check_responses): Remove "inode" argument and its use.
(main): Remove invocation of inode_of_sockfd and passing of listening
socket inode to send_query and check_responses.
* socketutils.c (cache_and_print_inode_details): Make "details"
parameter const.
(print_sockaddr_by_inode_cached): Make "e" variable const.
(inet_send_query): Make struct nlmsghdr and struct inet_diag_req_v2
members const. Make "msg" variable const.
(inet_parse_response): Make "data" parameter and diag_msg variable const.
(receive_responses): Make "h" and "rc" variables const.
(unix_send_query): Make struct nlmsghdr and struct unix_diag_req
members const. Make "msg" variable const.
(unix_print): Make all parameters const.
(print_sockaddr_by_inode): Make proto_name parameter const.
* socketutils.c (tcp_v4_print, udp_v4_print, tcp_v6_print,
udp_v6_print): New functions.
(print_sockaddr_by_inode): Make "protocols" array static, replace
"family" and "protocol" members with "print" in its underlying
structure. Iterate through protocols array when the protocol name
is specified.
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.
* socketutils.c (inet_parse_response, unix_parse_response): Change
return type from bool to int, return -1 on all parse errors except
inode mismatch.
(receive_responses): Stop on the first nlmsg_type that is not
SOCK_DIAG_BY_FAMILY, also stop when the parser returns -1.
* tests/netlink_inet_diag.c (check_responses): Stop on short messages,
on first nlmsg_type that is not SOCK_DIAG_BY_FAMILY, print more verbose
diagnostics for NLMSG_ERROR.
* tests/netlink_unix_diag.c (check_responses): Likewise.
Before this change, all files that exist since 20th century had
copyright headers, while most files that appeared later didn't. This
change fixes the inconsistency by adding missing copyright headers.
It doesn't mean that copyright headers became maintained. In my view,
git history provides much better information on this subject and is much
more accurate than copyright headers.
string_quote() has proven to be too hard to use, replace it with
print_quoted_string() that does memory allocation and prints the result.
* defs.h (string_quote): Remove.
(QUOTE_0_TERMINATED, QUOTE_OMIT_LEADING_TRAILING_QUOTES): New macros.
(print_quoted_string): New prototype.
* util.c (string_quote): Make static; take "style" flags instead
of "len", treat QUOTE_0_TERMINATED style flag as former (len == -1);
add QUOTE_OMIT_LEADING_TRAILING_QUOTES style flag support.
(ALLOCA_CUTOFF, use_alloca): New macros.
(print_quoted_string): New function.
(printpathn, printstr): Update to new API.
* loop.c (loop_ioctl): Likewise.
* mtd.c (ubi_ioctl): Likewise.
* net.c (print_scm_security): Likewise.
* socketutils.c (unix_parse_response): Likewise.
NETLINK_INET_DIAG was introduced in linux v2.6.14,
NETLINK_SOCK_DIAG was added much later in linux v3.3.
* net.c [!NETLINK_SOCK_DIAG && NETLINK_INET_DIAG]
(NETLINK_SOCK_DIAG): Define.
* socketutils.c: Likewise.
* tests/netlink_unix_diag.c: Likewise.
Prepend -yy output generated for INET/INET6 TCP/UDP sockets with their
protocol name obtained using getxattr.
* socketutils.c (inet_parse_response): Add proto_name argument.
Print proto_name for connected and unconnected sockets.
(receive_responses): Add proto_name argument, pass it to the parser.
(inet_print): Add proto_name argument, pass it to receive_responses.
(unix_parse_response): Add proto_name argument.
(print_sockaddr_by_inode): Pass protocol name to inet_print calls.
* tests/net-yy-accept.awk: Update to match new output format.
* tests/net-yy-connect.awk: Likewise.
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>
To resolve the peer address of socket, all combinations of families
(AF_INET, AF_INET6) and protocols(IPPROTO_TCP, IPPROTO_UDP) were tried.
This change utilizes the protocol name obtained via getxattr to specify
the right combination.
* socketutils.c (inet_print): New helper function.
(print_sockaddr_by_inode): Use it. Utilize the protocol name
associated with the given inode for resolving the peer socket
address. If the protocol name is NULL, resolve the address
by trying combinations of families and protocols as before.
* defs.h (print_sockaddr_by_inode): Update prototype.
* util.c (printfd): Pass the protocol name associated with
the given path to print_sockaddr_by_inode as the 2nd argument.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
When two ore more -y options are given, print local and remote ip:port
pairs associated with socket descriptors. This implementation uses
NETLINK_INET_DIAG for sockaddr lookup; it's based on the patch
prepared by Zubin Mithra as a part of his GSoC 2014 strace project.
* Makefile.am (strace_SOURCES): Add socketutils.c
(EXTRA_DIST): Add linux/inet_diag.h and linux/sock_diag.h.
* defs.h (print_sockaddr_by_inode): New prototype.
* linux/inet_diag.h: New file.
* linux/sock_diag.h: Likewise.
* socketutils.c: Likewise.
* strace.1: Document -yy option.
* strace.c (usage): Likewise.
* util.c (printfd): Use print_sockaddr_by_inode.