JingPiao Chen [Tue, 13 Jun 2017 05:38:27 +0000 (13:38 +0800)]
netlink: add a basic socket diag parser of AF_SMC messages
* linux/smc_diag.h: New file.
* Makefile.am (EXTRA_DIST): Add it.
* netlink_sock_diag.c: Include <linux/smc_diag.h>,
"xlat/smc_diag_extended_flags.h" and "xlat/smc_states.h".
(decode_smc_diag_req, decode_smc_diag_msg): New functions.
(diag_decoders): Add AF_SMC.
* xlat/smc_diag_extended_flags.in: New file.
* xlat/smc_states.in: Likewise.
JingPiao Chen [Tue, 13 Jun 2017 05:28:02 +0000 (13:28 +0800)]
tests: check decoding of NETLINK_SOCK_DIAG AF_INET messages
* tests/netlink_sock_diag.c: Include <arpa/inet.h>
and <linux/inet_diag.h>.
(test_inet_diag_sockid, test_inet_diag_req, test_inet_diag_req_v2,
test_inet_diag_msg): New functions.
(mian): Use them.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
JingPiao Chen [Tue, 13 Jun 2017 04:43:31 +0000 (12:43 +0800)]
netlink: add a basic socket diag parser of AF_INET and AF_INET6 messages
* defs.h (inet_protocols): New xlat prototype.
* linux/inet_diag.h (inet_diag_req): New structure.
(INET_DIAG_*): New enum.
* netlink_sock_diag.c: Include <arpa/inet.h>, <linux/inet_diag.h>
and "xlat/inet_diag_extended_flags.h".
(print_inet_diag_sockid, decode_inet_diag_req_compat)
(decode_inet_diag_req_v2, decode_inet_diag_req)
(decode_inet_diag_msg): New functions.
(diag_decoders): Add AF_INET and AF_INET6;
* xlat/inet_diag_extended_flags.in: New file.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Thu, 15 Jun 2017 21:02:14 +0000 (21:02 +0000)]
Introduce print_inet_addr
* defs.h (print_inet_addr): New prototype.
* sockaddr.c (print_inet_addr): New function.
(print_sockaddr_data_in6): Use it.
* net.c (print_mreq6): Likewise.
* tests/ip_mreq.c (main): Update expected output.
JingPiao Chen [Tue, 13 Jun 2017 03:58:25 +0000 (11:58 +0800)]
tests: check decoding of NETLINK_SOCK_DIAG AF_PACKET messages
* tests/netlink_sock_diag.c: Include <linux/if_ether.h>
and <linux/packet_diag.h>.
(test_packet_diag_req, test_packet_diag_msg): New functions.
(main): Use them.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
JingPiao Chen [Tue, 13 Jun 2017 03:50:15 +0000 (11:50 +0800)]
netlink: add a basic socket diag parser of AF_PACKET messages
* linux/packet_diag.h: New file.
* Makefile.am (EXTRA_DIST): Add it.
* defs.h (ethernet_protocols): New xlat prototype.
* netlink_sock_diag.c: Include <linux/packet_diag.h>
and "xlat/packet_diag_show.h".
(decode_packet_diag_req, decode_packet_diag_msg): New functions.
(diag_decoders): Add AF_PACKET.
* xlat/packet_diag_show.in: New file.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
JingPiao Chen [Tue, 13 Jun 2017 03:22:14 +0000 (11:22 +0800)]
tests: check decoding of NETLINK_SOCK_DIAG AF_NETLINK messages
* tests/netlink_sock_diag.c: Include <linux/netlink_diag.h>.
(test_netlink_diag_req, test_netlink_diag_msg): New functions.
(main): Use them.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
JingPiao Chen [Tue, 13 Jun 2017 02:32:55 +0000 (10:32 +0800)]
netlink: add a basic socket diag parser of AF_NETLINK messages
* linux/netlink_diag.h (NDIAG_SHOW_GROUPS, NDIAG_SHOW_RING_CFG):
New macros.
* netlink_sock_diag.c: Include <linux/netlink_diag.h>,
"xlat/netlink_diag_show.h" and "xlat/netlink_states.h".
(decode_netlink_diag_req, decode_netlink_diag_msg): New functions.
(diag_decoders): Add AF_NETLINK.
* xlat/netlink_diag_show.in: New file.
* xlat/netlink_states.in: Likewise.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sat, 10 Jun 2017 22:07:54 +0000 (22:07 +0000)]
tests: check decoding of NETLINK_SOCK_DIAG AF_UNIX messages
* tests/netlink_sock_diag.c: Include <netinet/tcp.h>
and <linux/unix_diag.h>.
(test_odd_family_req, test_odd_family_msg, test_unix_diag_req,
test_unix_diag_msg): New functions.
(main): Use them.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
Dmitry V. Levin [Sat, 10 Jun 2017 22:07:54 +0000 (22:07 +0000)]
netlink: add a basic socket diag parser of AF_UNIX messages
* defs.h (socktypes): New xlat prototype.
* linux/unix_diag.h (UDIAG_SHOW_VFS, UDIAG_SHOW_ICONS, UDIAG_SHOW_RQLEN,
UDIAG_SHOW_MEMINFO): New macros.
* netlink_sock_diag.c: Include <sys/socket.h>, <linux/netlink.h>,
<linux/unix_diag.h>, "xlat/tcp_states.h", "xlat/tcp_state_flags.h",
and "xlat/unix_diag_show.h".
(decode_unix_diag_req, decode_unix_diag_msg): New functions.
(netlink_diag_decoder_t): New typedef.
(diag_decoders): New array.
(decode_netlink_sock_diag): Use it.
* xlat/tcp_state_flags.in: New file.
* xlat/tcp_states.in: Likewise.
* xlat/unix_diag_show.in: Likewise.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
Dmitry V. Levin [Fri, 9 Jun 2017 23:06:42 +0000 (23:06 +0000)]
netlink: introduce family specific payload decoders
* defs.h (netlink_decoder_t): New typedef.
(DECL_NETLINK): New macro.
(decode_netlink_sock_diag): New prototype.
* netlink.c (netlink_decoders): New array.
(decode_payload): Use it to invoke netlink family specific decoders.
* netlink_sock_diag.c: New file.
* Makefile.am (strace_SOURCES): Add it.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
Dmitry V. Levin [Thu, 15 Jun 2017 00:27:30 +0000 (00:27 +0000)]
Update SCM_* constants
* xlat/scmvals.in: Add SCM_TIMESTAMP, SCM_TIMESTAMPNS, SCM_TIMESTAMPING,
SCM_WIFI_STATUS, and SCM_TIMESTAMPING_OPT_STATS.
Dmitry V. Levin [Wed, 14 Jun 2017 23:32:45 +0000 (23:32 +0000)]
netlink: refactor decode_nlmsg_type
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_netfilter):
New functions.
(nlmsg_types_decoder_t): New typedef.
(nlmsg_types): Add decoder field.
(decode_nlmsg_type): Use it.
JingPiao Chen [Wed, 14 Jun 2017 03:54:16 +0000 (11:54 +0800)]
tests: extend printstr test
* tests/printstr.c (main): Add a case for short read.
Dmitry V. Levin [Tue, 13 Jun 2017 21:00:04 +0000 (21:00 +0000)]
v4l2: fix preprocessor checks
Fix checks for struct v4l2_window.global_alpha and struct
v4l2_sdr_format.buffersize.
* v4l2.c (print_v4l2_format_fmt): Do not assume that
HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA and
HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE are defined.
* tests/ioctl_v4l2.c (init_v4l2_format, dprint_ioctl_v4l2): Likewise.
Dmitry V. Levin [Mon, 12 Jun 2017 15:41:54 +0000 (15:41 +0000)]
Move xlat related functions to a separate file
* util.c (xlookup, xlat_bsearch_compare, xlat_search, printxvals,
printxval_searchn, addflags, sprintflags, printflags_ex): Move ...
* xlat.c: ... to this new file.
* Makefile.am (strace_SOURCES): Add it.
Masatake YAMATO [Sun, 11 Jun 2017 07:42:28 +0000 (16:42 +0900)]
socketeutils: extend receive_responses further
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>
Masatake YAMATO [Sun, 11 Jun 2017 07:42:27 +0000 (16:42 +0900)]
socketeutils: extend receive_responses to handle other netlink types
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>
JingPiao Chen [Mon, 12 Jun 2017 15:33:00 +0000 (23:33 +0800)]
tests: fix typo
* tests/dup3.c (SKIP_MAIN_UNDEFINED): Remove duplicated &&.
Dmitry V. Levin [Thu, 8 Jun 2017 22:15:58 +0000 (22:15 +0000)]
Introduce printflags_ex function
Add printflags_ex extension over printflags64 that, similar
to printxvals, takes a NULL-terminated sequence of xlat pointers.
* defs.h (printflags_ex): New prototype.
(printflags64): Turn into a thin wrapper around printflags_ex.
* netlink.c (decode_nlmsg_flags): Use printflags_ex.
* util.c (printflags_ex): New function.
(printflags64): Remove.
* xlat/netlink_get_flags.in: Remove entries listed
in xlat/netlink_flags.in file.
* xlat/netlink_new_flags.in: Likewise.
JingPiao Chen [Wed, 7 Jun 2017 15:35:19 +0000 (23:35 +0800)]
tests: add check for decoding netlink get and new flags
* tests/netlink_route.c (test_nlmsg_flags): New function, checks
decoding of NETLINK_ROUTE get and new flags.
(main): Use it.
* tests/netlink_sock_diag.c (test_nlmsg_flags): New function, checks
decoding of NETLINK_SOCK_DIAG get flags.
(main): Use it.
* tests/netlink_xfrm.c: (test_nlmsg_flags): New function, checks
decoding of NETLINK_XFRM get and new flags.
(main): Use it.
JingPiao Chen [Thu, 8 Jun 2017 01:02:22 +0000 (09:02 +0800)]
netlink: implement generic nlmsg_flags decoding
* netlink.c: Include "xlat/netlink_get_flags.h"
and "xlat/netlink_new_flags.h".
(decode_nlmsg_flags): New function.
(print_nlmsghdr): Use it.
* xlat/netlink_get_flags.in: New file.
* xlat/netlink_new_flags.in: Likewise.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Tue, 6 Jun 2017 20:25:26 +0000 (20:25 +0000)]
xlat: provide fallback definitions for XFRM_MSG_* constants
Some of XFRM_MSG_* constants were introduced later than the header file
where they are defined.
* xlat/nl_xfrm_types.in: Add default values for constants.
Victor Krapivensky [Mon, 5 Jun 2017 19:19:07 +0000 (22:19 +0300)]
syscall.c: split trace_syscall() into 6 functions
This change removes the trace_syscall function. Now, the code that uses
syscall.c trace functions is expected to check whether it is a syscall
entry or exit (with entering(tcp)/exiting(tcp)) itself, and then make
an appropriate sequence of function calls.
* defs.h: Update comment on TCB_INSYSCALL.
(trace_syscall): Remove prototype.
(syscall_entering_decode, syscall_entering_trace,
syscall_entering_finish, syscall_exiting_decode, syscall_exiting_trace,
syscall_exiting_finish): New prototypes.
* strace.c (trace_syscall): New static replacement for old trace_syscall.
* syscall.c (trace_syscall): Remove.
(trace_syscall_entering): Split into ...
(syscall_entering_decode, syscall_entering_trace,
syscall_entering_finish): ... new functions.
(trace_syscall_exiting): Split into ...
(syscall_exiting_decode, syscall_exiting_trace,
syscall_exiting_finish): ... new functions.
Dmitry V. Levin [Mon, 5 Jun 2017 13:59:56 +0000 (13:59 +0000)]
tests: guard against missing linux/netfilter/nfnetlink.h
nfnetlink was introduced in linux by commit v2.6.14-rc1~1035^2~217,
add a guard for the case when system headers are not fresh enough.
* configure.ac (AC_CHECK_HEADERS): Add linux/netfilter/nfnetlink.h.
* tests/netlink_netfilter.c: Check for HAVE_LINUX_NETFILTER_NFNETLINK_H.
JingPiao Chen [Mon, 5 Jun 2017 14:05:12 +0000 (22:05 +0800)]
tests: check decoding of NETLINK_XFRM message types
* tests/netlink_xfrm.c: New file.
* tests/gen_tests.in (netlink_xfrm): New entry.
* tests/pure_executables.list: Add netlink_xfrm.
* tests/.gitignore: Likewise.
JingPiao Chen [Mon, 5 Jun 2017 14:05:11 +0000 (22:05 +0800)]
tests: check decoding of NETLINK_SELINUX message types
* tests/netlink_selinux.c: New file.
* tests/gen_tests.in (netlink_selinux): New entry.
* tests/pure_executables.list: Add netlink_selinux.
* tests/.gitignore: Likewise.
JingPiao Chen [Mon, 5 Jun 2017 14:05:10 +0000 (22:05 +0800)]
tests: check decoding of NETLINK_NETFILTER message types
* tests/netlink_netfilter.c: New file.
* tests/gen_tests.in (netlink_netfilter): New entry.
* tests/pure_executables.list: Add netlink_netfilter.
* tests/.gitignore: Likewise.
JingPiao Chen [Mon, 5 Jun 2017 14:05:09 +0000 (22:05 +0800)]
tests: check decoding of NETLINK_AUDIT message types
* tests/netlink_audit.c: New file.
* tests/gen_tests.in (netlink_audit): New entry.
* tests/pure_executables.list: Add netlink_audit.
* tests/.gitignore: Likewise.
JingPiao Chen [Mon, 5 Jun 2017 14:05:08 +0000 (22:05 +0800)]
tests: check decoding of NETLINK_ROUTE message types
* tests/netlink_route.c: New file.
* tests/gen_tests.in (netlink_route): New entry.
* tests/pure_executables.list: Add netlink_route.
* tests/.gitignore: Likewise.
JingPiao Chen [Mon, 5 Jun 2017 14:05:07 +0000 (22:05 +0800)]
tests: check decoding of NETLINK_SOCK_DIAG message types
* tests/netlink_sock_diag.c: New file.
* tests/netlink_sock_diag.test: New test.
* tests/pure_executables.list: Add netlink_sock_diag.
* tests/.gitignore: Likewise.
* tests/Makefile.am (DECODER_TESTS): Add netlink_sock_diag.test.
Dmitry V. Levin [Mon, 5 Jun 2017 13:11:44 +0000 (13:11 +0000)]
tests: use create_nl_socket in netlink_protocol.test
* tests/netlink_protocol.c (main): Use create_nl_socket.
Dmitry V. Levin [Mon, 5 Jun 2017 13:11:44 +0000 (13:11 +0000)]
tests: change netlink_protocol.test to trace sendto syscalls only
* tests/gen_tests.in (netlink_protocol): Replace %network with sendto.
* tests/netlink_protocol.c (main): Update expected output.
Dmitry V. Levin [Mon, 5 Jun 2017 12:17:49 +0000 (12:17 +0000)]
tests: enhance create_nl_socket diagnostics messages
* tests/tests.h (create_nl_socket): Rename to create_nl_socket_ext,
add a string argument.
(create_nl_socket): New macro wrapper around create_nl_socket_ext.
* tests/create_nl_socket.c (create_nl_socket): Rename
to create_nl_socket_ext, add a string argument, include it
in diagnostic messages.
Dmitry V. Levin [Mon, 5 Jun 2017 12:16:01 +0000 (12:16 +0000)]
tests: use const and designated initializers in create_nl_socket.c
* tests/create_nl_socket.c: Stop including <string.h>.
(create_nl_socket): Use const and designated initializers.
JingPiao Chen [Mon, 5 Jun 2017 14:05:07 +0000 (22:05 +0800)]
tests: add create_nl_socket function to libtests
* tests/create_nl_socket.c: New file.
* tests/tests.h (create_nl_socket): New prototype.
* tests/Makefile.am (libtests_a_SOURCES): Add create_nl_socket.c.
Dmitry V. Levin [Sun, 4 Jun 2017 18:14:50 +0000 (18:14 +0000)]
netlink: add decoding of NETLINK_NETFILTER message types
* xlat/nl_netfilter_msg_types.in: New file.
* xlat/nl_netfilter_subsys_ids.in: Likewise.
* netlink.c: Include "xlat/nl_netfilter_msg_types.h"
and "xlat/nl_netfilter_subsys_ids.h".
(nlmsg_types): Add NETLINK_NETFILTER.
(decode_nlmsg_type): Handle NETLINK_NETFILTER.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sun, 4 Jun 2017 16:57:21 +0000 (16:57 +0000)]
netlink: add decoding of NETLINK_XFRM message types
* xlat/nl_xfrm_types.in: New file.
* netlink.c: Include "xlat/nl_xfrm_types.h".
(nlmsg_types): Add NETLINK_XFRM.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sun, 4 Jun 2017 16:48:10 +0000 (16:48 +0000)]
netlink: add decoding of NETLINK_SELINUX message types
* xlat/nl_selinux_types.in: New file.
* netlink.c: Include "xlat/nl_selinux_types.h".
(nlmsg_types): Add NETLINK_SELINUX.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sun, 4 Jun 2017 16:43:48 +0000 (16:43 +0000)]
netlink: add decoding of NETLINK_ROUTE message types
* xlat/nl_route_types.in: New file.
* netlink.c: Include <linux/rtnetlink.h> and "xlat/nl_route_types.h".
(nlmsg_types): Add NETLINK_ROUTE.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sun, 4 Jun 2017 14:53:22 +0000 (14:53 +0000)]
netlink: add decoding of NETLINK_AUDIT message types
* xlat/nl_audit_types.in: New file.
* netlink.c: Include <linux/audit.h> and "xlat/nl_audit_types.h".
(nlmsg_types): Add NETLINK_AUDIT.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sat, 3 Jun 2017 23:19:49 +0000 (23:19 +0000)]
netlink: implement generic nlmsg_type decoding
Implement a pluggable mechanism of nlmsg_type decoding.
Add decoding of NETLINK_SOCK_DIAG types.
* linux/sock_diag.h (SOCK_DESTROY): New macro.
* xlat/nl_sock_diag_types.in: New file.
* netlink.c: Include xlat/nl_sock_diag_types.h.
(get_fd_nl_family, decode_nlmsg_type): New functions.
(print_nlmsghdr): Use them for nlmsg_type decoding.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Dmitry V. Levin [Sat, 3 Jun 2017 22:56:32 +0000 (22:56 +0000)]
netlink: add netlink family argument to printers and decoders
* netlink.c (NL_FAMILY_ERROR, NL_FAMILY_DEFAULT): New constants.
(print_nlmsghdr): Add netlink family argument, change return type
to int, return family.
(decode_nlmsghdr_with_payload, decode_nlmsgerr, decode_payload): Add
netlink family argument. All callers updated.
Fabien Siron [Mon, 11 Jul 2016 12:54:59 +0000 (12:54 +0000)]
Add file descriptor argument to decode_netlink
* defs.h (decode_netlink): Add file descriptor argument.
* io.c (print_iovec): Specify file descriptor to decode_netlink.
* net.c (decode_sockbuf): Likewise.
* netlink.c (print_nlmsghdr, decode_nlmsghdr_with_payload,
decode_nlmsgerr, decode_payload, decode_nlmsghdr_with_payload,
decode_netlink): Likewise.
All callers updated.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fabien Siron [Thu, 26 May 2016 10:59:07 +0000 (10:59 +0000)]
Introduce getfdinode to obtain inode from fd
* defs.h (getfdinode): New prototype.
* utils.c (getfdinode): New function.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fabien Siron [Thu, 26 May 2016 10:46:28 +0000 (10:46 +0000)]
Introduce get_sockaddr_by_inode
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>
Dmitry V. Levin [Fri, 2 Jun 2017 23:30:57 +0000 (23:30 +0000)]
socketutils.c: introduce get_sockaddr_by_inode_uncached
* socketutils.c (get_sockaddr_by_inode_uncached): New function.
(print_sockaddr_by_inode_uncached): Use it.
Fabien Siron [Thu, 26 May 2016 10:46:28 +0000 (10:46 +0000)]
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>
Dmitry V. Levin [Fri, 2 Jun 2017 23:26:15 +0000 (23:26 +0000)]
socketutils.c: move inet_print closer to its first use
* socketutils.c (inet_print): Move right before tcp_v4_print.
Fabien Siron [Wed, 22 Jun 2016 13:51:49 +0000 (13:51 +0000)]
socketutils.c: introduce cache_inode_details
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>
Victor Krapivensky [Mon, 5 Jun 2017 11:46:34 +0000 (14:46 +0300)]
strace.c: move termination code to a separate function
This will be needed for the pull-style API.
* strace.c (terminate): New function.
(main): Use it.
Dmitry V. Levin [Sun, 4 Jun 2017 21:17:15 +0000 (21:17 +0000)]
tests: avoid hitting SO_SNDBUF limit in sendfile/sendfile64 tests
Do not assume that an executable is small enough and SO_SNDBUF is large
enough so that the executable could be sendfile'ed into a socket pair.
* tests/sendfile.c (main): Create a regular file of the right size
to avoid hitting SO_SNDBUF limit.
* tests/sendfile64.c: Likewise.
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Dmitry V. Levin [Sun, 4 Jun 2017 17:03:44 +0000 (17:03 +0000)]
Move netlink_protocols definition from net.c to netlink.c
The side effect of #include "xlat/netlink_protocols.h" is
NETLINK_* constants properly defined in that header file.
While net.c does not use these constants itself, netlink.c
is going to need them soon.
* net.c: Move inclusion of "xlat/netlink_protocols.h" ...
* netlink.c: ... here.
Dmitry V. Levin [Sun, 4 Jun 2017 14:20:16 +0000 (14:20 +0000)]
travis: switch from gcc-6 to gcc-7
* .travis.yml (matrix): Change gcc-6 to gcc-7.
Dmitry V. Levin [Sun, 4 Jun 2017 13:40:17 +0000 (13:40 +0000)]
tests: extend checking of NLMSG_DONE decoding
* tests/netlink_protocol.c (test_nlmsg_done): Use designated
initializers. Check decoding of messages with non-integer payload.
JingPiao Chen [Fri, 5 May 2017 10:21:17 +0000 (18:21 +0800)]
netlink: decode NLMSG_DONE messages
* netlink.c (decode_payload): Decode NLMSG_DONE messages.
* tests/netlink_protocol.c (test_nlmsg_done): New function
for checking decoding of NLMSG_DONE messages.
(main): Use it.
Dmitry V. Levin [Sun, 4 Jun 2017 11:38:30 +0000 (11:38 +0000)]
socketutils.c: introduce get_sockaddr_by_inode_cached
* socketutils.c (get_sockaddr_by_inode_cached): New function.
(print_sockaddr_by_inode_cached): Use it.
Dmitry V. Levin [Sat, 3 Jun 2017 17:52:24 +0000 (17:52 +0000)]
Unexport print_sockaddr_by_inode_cached
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.
Dmitry V. Levin [Sat, 3 Jun 2017 16:55:12 +0000 (16:55 +0000)]
Introduce str_strip_prefix_len function and STR_STRIP_PREFIX macro
Address proliferation of string prefix check implementations.
* defs.h (str_strip_prefix_len): New inline function.
(STR_STRIP_PREFIX): New macro.
* qualify.c (strip_prefix): Remove.
(parse_inject_token): Use STR_STRIP_PREFIX instead of strip_prefix.
(qualify): Use str_strip_prefix_len.
* socketutils.c (netlink_parse_response): Likewise.
* util.c (printfd): Likewise.
Dmitry V. Levin [Fri, 2 Jun 2017 22:22:22 +0000 (22:22 +0000)]
netlink: move NLMSG_ERROR payload length check to nlmsgerr decoder
Move decoder specific check to the decoder.
* netlink.c (decode_payload): Move NLMSG_ERROR payload length check ...
(decode_nlmsgerr): ... here.
Dmitry V. Levin [Fri, 2 Jun 2017 21:49:02 +0000 (21:49 +0000)]
strace.c: handle PTRACE_EVENT_EXEC like other events
There is nothing unusual about PTRACE_EVENT_EXEC that would require
a special treatment.
* strace.c (next_event): Move PTRACE_EVENT_EXEC handling to the main
switch statement.
Dmitry V. Levin [Fri, 2 Jun 2017 20:01:31 +0000 (20:01 +0000)]
strace.c: remove dead code
As strace does not use WCONTINUED flag, there is no need to handle
WIFCONTINUED status.
* strace.c (print_debug_info) [WIFCONTINUED]: Remove.
(next_event): Remove redundant !WIFSTOPPED check.
Victor Krapivensky [Fri, 2 Jun 2017 14:05:56 +0000 (17:05 +0300)]
strace.c: refactor trace into two functions
This change decouples waiting for next event from reacting to it. This
makes the control flow easier to understand, and serves as a preparation
for implementing a pull-style API for LuaJIT.
* strace.c (enum trace_event): New enum.
(trace): Split into ...
(next_event, dispatch_event): ... new functions.
(main): Use them.
Dmitry V. Levin [Tue, 30 May 2017 22:44:47 +0000 (22:44 +0000)]
scno.am: include config.h before syscallent.h
This fixes generation of syscallent.i and subsequent scno.h files
on mips where syscallent.h checks macros defined in config.h.
* scno.am (syscallent.i): Add $(top_builddir)/config.h
to prerequisites, include it.
* NEWS: Mention this fix.
Reported-by: David Robins <dbrobins@i4031.net>
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
tests: check decoding of sigaction syscall
* tests/sigaction.c: New file.
* tests/gen_tests.in (sigaction): New entry.
* tests/pure_executables.list: Add sigaction.
* tests/.gitignore: Likewise.
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
tests: rename sigaction.test to rt_sigaction.test
* tests/sigaction.awk: Rename to rt_sigaction.awk.
* tests/sigaction.c: Rename to tests/rt_sigaction.c.
* tests/sigaction.test: Rename to tests/rt_sigaction.test.
* tests/.gitignore: Replace sigaction with rt_sigaction.
* tests/pure_executables.list: Likewise.
* tests/Makefile.am (DECODER_TESTS): Replace sigaction.test
with rt_sigaction.test.
(EXTRA_DIST): Replace sigaction.awk with rt_sigaction.awk.
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
sparc: enhance decoding of signal number argument of sigaction syscall
On sparc, unlike all other architectures, old sigaction syscall takes
a negated signal number.
* signal.c (SYS_FUNC(sigaction)) [SPARC || SPARC64]: Enhance printing
of negative signal number argument.
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
signal: enhance printing of old_sigaction.mask
* signal.c (decode_old_sigaction): Print old_sigaction.mask
using tprint_old_sigmask_val.
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
signal: limit scope of struct old_sigaction32 definition
* signal.c (struct old_sigaction32): Define only if [!current_wordsize].
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
signal: fix decoding of struct old_sigaction on some architectures
On alpha, struct old_sigaction.sa_flags has a 32-bit type.
On mips, only first word of old_sigaction.sa_mask is read.
On all architectures except alpha and mips that have old sigaction
syscall, struct old_sigaction has sa_restorer field that has to be
decoded.
* signal.c (struct old_sigaction) [ALPHA]: Change sa_flags type
to unsigned int, add ATTRIBUTE_PACKED.
[MIPS]: Dhrink sa_mask array to 1 element.
[!ALPHA && !MIPS]: Define sa_restorer field unconditionally.
(struct old_sigaction32): Likewise.
(decode_old_sigaction) [!current_wordsize]: Initialize sa_restorer field
from old_sigaction32.sa_restorer unconditionally.
[!ALPHA && !MIPS]: Print old_sigaction.sa_restorer if SA_RESTORER flag
is set.
* NEWS: Mention this change.
Dmitry V. Levin [Sun, 28 May 2017 17:13:29 +0000 (17:13 +0000)]
xlat: rename SA_STACK to SA_ONSTACK
SA_ONSTACK is the standard name while its alias SA_STACK is not even
defined on many platforms.
* xlat/sigact_flags.in (SA_STACK): Rename to SA_ONSTACK.
Dmitry V. Levin [Sun, 28 May 2017 00:09:52 +0000 (00:09 +0000)]
tests: check decoding of sigpending syscall
* tests/sigpending.c: New file.
* tests/gen_tests.in (sigpending): New entry.
* tests/pure_executables.list: Add sigpending.
* tests/.gitignore: Likewise.
Dmitry V. Levin [Sun, 28 May 2017 00:09:45 +0000 (00:09 +0000)]
tests: check decoding of sigprocmask syscall
* tests/sigprocmask.c: New file.
* tests/gen_tests.in (sigprocmask): New entry.
* tests/pure_executables.list: Add sigprocmask.
* tests/.gitignore: Likewise.
Dmitry V. Levin [Sun, 28 May 2017 00:09:32 +0000 (00:09 +0000)]
alpha: rename sys_sigprocmask to sys_osf_sigprocmask
Parsers of sigprocmask and osf_sigprocmask syscalls are different
anyway, so rename the function to match the syscall name.
* signal.c [ALPHA] (SYS_FUNC(sigprocmask)): Rename
to SYS_FUNC(osf_sigprocmask).
* linux/alpha/syscallent.h: Update sys_func.
Dmitry V. Levin [Sat, 27 May 2017 18:58:31 +0000 (18:58 +0000)]
Enable coverage when strace is self terminated by signal
The data collected by -fprofile-arcs during program run is saved
on program exit. When program is terminated by signal, the data
is not saved. However, libgcov provides an interface to dump
the data at runtime.
* m4/ax_code_coverage.m4 (AX_CODE_COVERAGE): Add -DENABLE_COVERAGE_GCOV
to CODE_COVERAGE_CPPFLAGS.
* strace.c [ENABLE_COVERAGE_GCOV] (__gcov_flush): New prototype.
(main) [ENABLE_COVERAGE_GCOV]: Call __gcov_flush() before raise()
and sigprocmask() calls that might cause program termination.
Dmitry V. Levin [Sat, 27 May 2017 17:59:44 +0000 (17:59 +0000)]
tests: check termination signal forwarding
* tests/run_expect_termsig.c: New file.
* tests/unblock_reset_raise.c: Likewise.
* tests/termsig.test: New test.
* tests/.gitignore: Add run_expect_termsig and unblock_reset_raise.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add termsig.test.
Dmitry V. Levin [Sat, 27 May 2017 17:59:44 +0000 (17:59 +0000)]
Fix termination signal forwarding
When traced command is terminated by a blocked signal, unblock
that signal to ensure strace termination with the same signal.
* strace.c (main): Unblock the signal raised for strace termination.
* NEWS: Mention this change.
Dmitry V. Levin [Sat, 27 May 2017 15:58:54 +0000 (15:58 +0000)]
Do not reset SIGCHLD handler in tracees to SIG_DFL
While strace resets SIGCHLD handler to the default action so that
waitpid definitely works without losing track of children, tracees
should not inherit this change.
* strace.c (struct exec_params): Add child_sa field.
(init): When setting SIGCHLD handler to SIG_DFL, save the old handler.
(exec_or_die): Restore SIGCHLD handler if it was different from SIG_DFL
at startup.
* NEWS: Mention this change.
Dmitry V. Levin [Sat, 27 May 2017 12:26:05 +0000 (12:26 +0000)]
Refactor setting of signal handlers to reduce redundancy
* strace.c (set_sigaction): New function.
(init): Use it instead of sigaction with sigaddset.
Dmitry V. Levin [Sat, 27 May 2017 10:00:43 +0000 (10:00 +0000)]
tests: check how signals are unblocked in interactive mode
* tests/block_reset_raise_run.c: New file.
* tests/interactive_block.test: New test.
* tests/.gitignore: Add block_reset_raise_run.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add interactive_block.test.
Dmitry V. Levin [Sat, 27 May 2017 10:00:43 +0000 (10:00 +0000)]
Fix unblocking of signals in interactive mode
In interactive mode (-I2), those signals that were blocked at startup
will remain blocked for the whole period of strace execution.
* strace.c (empty_set): Rename to start_set. All users changed.
(init): Initialize start_set and blocked_set to the set of currently
blocked signals.
(startup_attach, trace): Use SIG_SETMASK instead of SIG_BLOCK.
* NEWS: Mention this change.
Dmitry V. Levin [Fri, 26 May 2017 23:16:57 +0000 (23:16 +0000)]
Cleanup interactive check
* strace.c (init): Check for INTR_WHILE_WAIT mode the same way
as in other places.
Dmitry V. Levin [Fri, 26 May 2017 20:42:13 +0000 (20:42 +0000)]
tests: check decoding of signal syscall
* tests/signal.c: New file.
* tests/gen_tests.in (signal): New entry.
* tests/pure_executables.list: Add signal.
* tests/.gitignore: Likewise.
Eugene Syromyatnikov [Wed, 24 May 2017 20:01:05 +0000 (22:01 +0200)]
Unify capitalisation of (c) in copyright notices
Dmitry V. Levin [Thu, 25 May 2017 19:42:20 +0000 (19:42 +0000)]
Post-release administrivia
* NEWS: Add a header line for the next release.
* debian/changelog.in: Add a changelog entry for 4.17-1.
* strace.spec.in: Likewise.
Dmitry V. Levin [Wed, 24 May 2017 16:17:18 +0000 (16:17 +0000)]
Prepare for 4.17 release
* NEWS: Update for 4.17 release.
Dmitry V. Levin [Wed, 24 May 2017 16:17:18 +0000 (16:17 +0000)]
powerpc64, sparc, sparc64: wire up statx syscall
* linux/powerpc64/syscallent.h [383]: Add statx entry.
* linux/sparc/syscallent.h [360]: Likewise.
* linux/sparc64/syscallent.h [360]: Likewise.
Dmitry V. Levin [Tue, 23 May 2017 23:20:18 +0000 (23:20 +0000)]
Fix compat personality support for sgetmask syscall
* signal.c (SYS_FUNC(sgetmask)): Replace sprintsigmask_val
with sprint_old_sigmask_val.
* tests/sxetmask.c (main): Check decoding of signal mask containing
RT signals.
Dmitry V. Levin [Mon, 22 May 2017 10:48:13 +0000 (10:48 +0000)]
Fix decoding of sgetmask and ssetmask syscalls
Old ssetmask syscall takes an argument and returns a value of type int.
Old sgetmask syscall may return an error.
* signal.c (SYS_FUNC(ssetmask)): Explicitly convert the argument
and return value to unsigned int, print it using sprint_old_sigmask_val.
(SYS_FUNC(sgetmask)): Do not print the mask in case of syserror.
* tests/sxetmask.c: New file.
* tests/gen_tests.in (sxetmask): New entry.
* tests/pure_executables.list: Add sxetmask.
* tests/.gitignore: Likewise.
* NEWS: Mention this fix.
Eugene Syromyatnikov [Mon, 22 May 2017 17:14:52 +0000 (19:14 +0200)]
Add copyright headers
Eugene Syromyatnikov [Mon, 1 May 2017 17:10:15 +0000 (19:10 +0200)]
Add scripts for automating copyright notices update
* maint/update_copyright_years.awk: New file.
* maint/update_copyright_years.sh: Likewise.
Co-authored-by: Elvira Khabirova <lineprinter0@gmail.com>
Eugene Syromyatnikov [Mon, 22 May 2017 16:53:14 +0000 (18:53 +0200)]
Fix typos in copyright notices
Eugene Syromyatnikov [Mon, 22 May 2017 17:08:47 +0000 (19:08 +0200)]
unwind.c: remove non-ASCII character from comment
Dmitry V. Levin [Sun, 21 May 2017 17:51:01 +0000 (17:51 +0000)]
Rename sys_sig[gs]etmask to sys_s[gs]etmask to match syscall names
* signal.c (SYS_FUNC(sigsetmask)): Rename to SYS_FUNC(ssetmask).
(SYS_FUNC(siggetmask)): Rename to SYS_FUNC(sgetmask).
* linux/arm/syscallent.h (sgetmask, ssetmask): Update sys_func.
* linux/bfin/syscallent.h: Likewise.
* linux/crisv10/syscallent.h: Likewise.
* linux/hppa/syscallent.h: Likewise.
* linux/i386/syscallent.h: Likewise.
* linux/m68k/syscallent.h: Likewise.
* linux/microblaze/syscallent.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/powerpc64/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/sparc64/syscallent.h: Likewise.
Dmitry V. Levin [Sun, 21 May 2017 14:37:48 +0000 (14:37 +0000)]
tests: enhance sigsuspend.test
* tests/sigsuspend.c (sigtxt): New variable.
(main): Change signal masks to contain all signals except USR1 and USR2.
Dmitry V. Levin [Sat, 20 May 2017 20:17:59 +0000 (20:17 +0000)]
Fix compat personality support for old sigsuspend syscall
* signal.c (sprint_old_sigmask_val): New function.
(tprint_old_sigmask_val): New macro.
(SYS_FUNC(sigsuspend)): Use it.
Dmitry V. Levin [Tue, 16 May 2017 02:11:35 +0000 (02:11 +0000)]
Move errnoent.sh, signalent.sh, and syscallent.sh to maint subdirectory
Also do not include them into release tarballs. These files are
intended for developers who are expected to use a git repository.
* errnoent.sh: Move to maint subdirectory.
* signalent.sh: Likewise.
* syscallent.sh: Likewise.
* HACKING-scripts: Update.
* Makefile.am (EXTRA_DIST): Remove errnoent.sh, signalent.sh,
and syscallent.sh.
Dmitry V. Levin [Tue, 16 May 2017 02:11:35 +0000 (02:11 +0000)]
Do not include maint subdirectory into release tarballs
These files are intended for developers who are expected to use
a git repository.
* Makefile.am (EXTRA_DIST): Remove maint/ioctls_gen.sh,
maint/ioctls_hex.sh, maint/ioctls_sym.sh, and maint/print_ioctlent.c.
Eugene Syromyatnikov [Mon, 1 May 2017 16:40:01 +0000 (18:40 +0200)]
linux/ia64/syscallent.h: remove tabulation, add spaces in file comment
Eugene Syromyatnikov [Mon, 1 May 2017 16:39:25 +0000 (18:39 +0200)]
linux/mtd-abi.h: remove non-ASCII character from file comment