JingPiao Chen [Tue, 15 Aug 2017 04:41:20 +0000 (12:41 +0800)]
netlink: add basic decoding of NETLINK_ROUTE netconfmsg attributes
* rtnl_netconf.c: Include "netlink.h", "nlattr.h",
and "xlat/rtnl_netconf_attrs.h".
(decode_netconfmsg): Call decode_nlattr.
* xlat/rtnl_netconf_attrs.in: New file.
JingPiao Chen [Tue, 15 Aug 2017 04:41:18 +0000 (12:41 +0800)]
netlink: add basic decoding of NETLINK_ROUTE ifaddrlblmsg attributes
* rtnl_addrlabel.c: Include "netlink.h", "nlattr.h",
and "xlat/rtnl_addrlabel_attrs.h".
(decode_ifaddrlblmsg): Call decode_nlattr.
* xlat/rtnl_addrlabel_attrs.in: New file.
JingPiao Chen [Tue, 15 Aug 2017 04:41:17 +0000 (12:41 +0800)]
netlink: add basic decoding of NETLINK_ROUTE tcamsg attributes
* rtnl_tc_action.c: Include "nlattr.h" and "xlat/rtnl_tc_action_attrs.h".
(decode_tcamsg): Call decode_nlattr.
* xlat/rtnl_tc_action_attrs.in: New file.
Dmitry V. Levin [Tue, 15 Aug 2017 20:08:39 +0000 (20:08 +0000)]
tests: use ifindex_lo and IFINDEX_LO_STR
* tests/netlink_route.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(test_rtnl_link, test_rtnl_addr, test_rtnl_neigh, test_rtnl_tc,
test_rtnl_addrlabel, test_rtnl_mdb): Use ifindex_lo instead
of if_nametoindex, use IFINDEX_LO_STR instead of hardcoded string.
* tests/netlink_sock_diag.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(test_inet_diag_sockid, test_inet_diag_req, test_inet_diag_req_v2,
test_inet_diag_msg, test_smc_diag_req): Use ifindex_lo instead
of if_nametoindex, use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_inet_diag_msg.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(init_inet_diag_msg): Use ifindex_lo instead of if_nametoindex.
(print_inet_diag_msg): Use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_inet_diag_req_compat.c: Do not check
for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(init_inet_diag_req): Use ifindex_lo instead of if_nametoindex.
(print_inet_diag_req): Use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_inet_diag_req_v2.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(init_inet_diag_req_v2, print_inet_diag_req_v2,
test_inet_diag_bc_dev_cond): Use ifindex_lo instead of if_nametoindex,
use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_packet_diag_msg.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(main): Use ifindex_lo instead of if_nametoindex.
(print_packet_diag_mclist): Use IFINDEX_LO_STR instead of hardcoded
string.
Dmitry V. Levin [Fri, 11 Aug 2017 18:26:02 +0000 (18:26 +0000)]
tests/ip_mreq: use ifindex_lo and IFINDEX_LO_STR
* tests/ip_mreq.c: Do not check for HAVE_IF_INDEXTONAME.
(main): Use ifindex_lo instead of if_nametoindex, use IFINDEX_LO_STR
instead of hardcoded string.
Dmitry V. Levin [Thu, 10 Aug 2017 18:47:28 +0000 (18:47 +0000)]
tests/group_req: use ifindex_lo and IFINDEX_LO_STR
* tests/group_req.c: Do not check for HAVE_IF_INDEXTONAME.
(main): Use ifindex_lo instead of if_nametoindex, use IFINDEX_LO_STR
instead of hardcoded string.
Dmitry V. Levin [Tue, 8 Aug 2017 20:40:57 +0000 (20:40 +0000)]
tests: add ifindex_lo function and IFINDEX_LO_STR macro to libtests
* tests/ifindex.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/tests.h (ifindex_lo): New prototype.
(IFINDEX_LO_STR): New macro.
JingPiao Chen [Sun, 13 Aug 2017 02:27:28 +0000 (10:27 +0800)]
netlink: add a basic rtnetlink parser of netconf messages
* rtnl_netconf.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_route.h (decode_netconfmsg): New prototype.
* configure.ac (AC_CHECK_TYPES): Check for struct netconfmsg
in <linux/netconf.h>.
* netlink_route.c (route_decoders): Add RTM_GETNETCONF
and RTM_NEWNETCONF.
Make description of discrepancies between libc and kernel APIs more relevant
Looks like this part was untouched since the days strace supported OSes
other than Linux. Well, it's time to make it more contemporary.
* strace.1.in (.SH NOTES): Use faccessat(2) and setrlimit(2)/prlimit(2)
instead of time(2) and stat(2)/xstat(2) as examples of libc/kernel API
discrepancies.
Dmitry V. Levin [Wed, 9 Aug 2017 13:24:13 +0000 (13:24 +0000)]
rtnl_link: include "netlink.h" before <linux/rtnetlink.h>
<sys/socket.h> has to be included before <linux/netlink.h> because
the latter used to be incomplete in older kernel headers.
As a local wrapper file called netlink.h was introduced earlier
to workaround this and related portability issues, include it before
<linux/rtnetlink.h> that in turn includes <linux/netlink.h>.
This fixes build on systems with older kernel headers.
* rtnl_link.c: Include "netlink.h" before <linux/rtnetlink.h>.
JingPiao Chen [Fri, 16 Jun 2017 13:11:23 +0000 (21:11 +0800)]
netlink: add a basic rtnetlink parser of link messages
* netlink_route.h: New file.
* rtnl_link.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* defs.h (arp_hardware_types, iffflags): New xlat prototypes.
* netlink_route.c: Include "netlink_route.h"
and <linux/rtnetlink.h>.
(netlink_route_decoder_t): New typedef.
(route_decoders): New array.
(decode_netlink_route): Use it.
JingPiao Chen [Fri, 16 Jun 2017 12:58:38 +0000 (20:58 +0800)]
Move nl_route_types definition from netlink.c to netlink_route.c
The side effect of #include "xlat/nl_route_types.h" is
RTM_* constants properly defined in that header file.
While netlink.c does not use these constants itself,
netlink_route.c is going to need them soon.
* defs.h (nl_route_types): New xlat prototype.
* netlink.c: Move inclusion of "xlat/nl_route_types.h" ...
* netlink_route.c: ... here.
JingPiao Chen [Tue, 8 Aug 2017 14:37:37 +0000 (22:37 +0800)]
netlink: call get_fd_nl_family before nlmsghdr decoding
Prepare for decoding of NETLINK_KOBJECT_UEVENT. Messages of the latter,
unlike traditional netlink families, don't contain a header at all.
* netlink.c (NL_FAMILY_*): Remove enum.
(get_fd_nl_family): Replace NL_FAMILY_ERROR with -1.
(decode_nlmsg_type): Update the comment.
Skip family specific type decoders for type < NLMSG_MIN_TYPE.
(decode_nlmsghdr_with_payload): Skip family specific decoders
for type < NLMSG_MIN_TYPE && type != NLMSG_DONE.
(print_nlmsghdr): Move get_fd_nl_family invocation ...
(decode_nlmsghdr_with_payload): ... here.
Avoid proliferation of exactly the same definitions of shorthand
notations for macros defined in sysent.h by moving definitions
and undefs of these shorthand notations to separate files.
* sysent_shorthand_defs.h: New file.
* sysent_shorthand_undefs.h: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* syscall.c: Use them.
Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
In order to allow usage of utility functions by other binaries
included in the strace package (like the upcoming asinfo utility),
these functions should be moved to separate files.
* error_prints.h: New file.
* xmalloc.h: Likewise.
* defs.h: Include "xmalloc.h" and "error_prints.h".
(error_msg, error_msg_and_die, error_msg_and_help, perror_msg,
perror_msg_and_die): Move to error_prints.h.
(xcalloc, xmalloc, xreallocarray, xstrdup, xstrndup): Move to xmalloc.h.
* strace.c (die): Remove static quialifier to make visible
by error_prints.c.
(error_msg, error_msg_and_die, error_msg_and_help, perror_msg,
perror_msg_and_die, verror_msg): Move ...
* error_prints.c: ... to the new file.
* xmalloc.c: Include "config.h", <stdlib.h>, <string.h>,
"error_prints.h", and "xmalloc.h" instead of "defs.h".
Use int instead of bool. Fix codestyle.
* Makefile.am (strace_SOURCES): Add error_prints.c, error_prints.h,
and xmalloc.h.
Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Nikolay Marchuk [Tue, 27 Jun 2017 04:33:29 +0000 (11:33 +0700)]
Split qualify.c into basic_filters.c and filter_qualify.c
This change also exports add_number_to_set, qualify_tokens,
and qualify_syscall_tokens.
* basic_filters.c: New file, part of qualify.c.
* filter_qualify.c: Likewise.
* filter.h: New file.
* qualify.c: Remove.
* Makefile.am (strace_SOURCES): Add new files, remove qualify.c.
Dmitry V. Levin [Sun, 6 Aug 2017 15:10:56 +0000 (15:10 +0000)]
Simplify handling of unexpected tracees
* strace.c (maybe_allocate_tcb) <WIFSTOPPED(status) && !followfork>:
Remove the dance around possible re-injection of WSTOPSIG(status)
as the only observable stop here is the initial ptrace-stop.
Dmitry V. Levin [Sun, 6 Aug 2017 13:27:07 +0000 (13:27 +0000)]
Fix handling of unexpected tracees when PTRACE_SEIZE is not in use
* strace.c (maybe_allocate_tcb) <WIFSTOPPED(status) && !followfork>:
The expected ptrace stop signal in case of !use seize is not
syscall_trap_sig but SIGSTOP. An idea of using PTRACE_GETSIGINFO to
distinguish signal stops that should be re-injected from other kinds
of stops didn't work out due to kernel implementation peculiarities
of initial ptrace-stop.
Dmitry V. Levin [Sun, 6 Aug 2017 11:26:52 +0000 (11:26 +0000)]
Enhance fflush error diagnostics
* strace.c (flush_tcp_output): New function.
(line_ended, droptcb, print_event_exit): Use it to flush tcp->outf.
* tests/fflush.c: New file.
* tests/fflush.test: New test.
* tests/Makefile.am (MISC_TESTS): Add it.
* tests/.gitignore: Add fflush.
* tests/pure_executables.list: Likewise.
This solves potential issues when tests run first and strace is rebuilt
only after they have finished. As noted in [1], providing the current
directory explicitly should help.
When receiving a ptrace stop of an unexpected child, handle it
in the most transparent way possible:
- detach it instead of PTRACE_CONT'ing;
- send it the signal with which it has been stopped.
This should hopefully help to deal with processes that have been created
with misused CLONE_PTRACE flag set.
* strace.c (maybe_allocate_tcb) <WIFSTOPPED(status) && !followfork>:
Calculate the signal similarly to the way next_event does,
forward it to the unexpected tracee, and detach the tracee.
Dmitry V. Levin [Fri, 4 Aug 2017 18:47:59 +0000 (18:47 +0000)]
sparc64: do not bail out in get_scno if PTRACE_PEEKTEXT fails
If the kernel contains commit 84d77d3f06e7e8dea057d10e8ec77ad71f721be3,
PTRACE_PEEKTEXT becames unavailable when the process dumpable flag is
cleared. As this is not a fatal condition for get_scno, do not bail out
if PTRACE_PEEKTEXT fails.
This condition is triggered and therefore tested by prctl-dumpable test.
* linux/sparc64/get_scno.c (arch_get_scno): Do not bail out
if PTRACE_PEEKTEXT fails.