]> granicus.if.org Git - strace/log
strace
7 years agonetlink: add a basic netlink attribute parser of AF_NETLINK diag
JingPiao Chen [Tue, 27 Jun 2017 10:10:03 +0000 (18:10 +0800)]
netlink: add a basic netlink attribute parser of AF_NETLINK diag

* linux/netlink_diag.h (NETLINK_DIAG_*): New enum.
* netlink_sock_diag.c: Include "xlat/netlink_diag_attrs.h".
(decode_netlink_diag_msg): Use decode_nlattr.
* xlat/netlink_diag_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink_sock_diag: ensure that structure field names are printed properly
Dmitry V. Levin [Tue, 27 Jun 2017 23:07:37 +0000 (23:07 +0000)]
netlink_sock_diag: ensure that structure field names are printed properly

* netlink_sock_diag.c (PRINT_FIELD_U, PRINT_FIELD_COOKIE,
PRINT_FIELD_FLAGS, PRINT_FIELD_XVAL): New macros.
(decode_unix_diag_req, decode_unix_diag_msg, decode_netlink_diag_req,
decode_netlink_diag_msg, decode_packet_diag_req, decode_packet_diag_msg,
print_inet_diag_sockid, decode_inet_diag_req_compat,
decode_inet_diag_req_v2, decode_inet_diag_msg, decode_smc_diag_req,
decode_smc_diag_msg): Use them to print structure fields.

7 years agoUpdate ioctl entries from linux v4.12-rc7
Gleb Fotengauer-Malinovskiy [Wed, 28 Jun 2017 17:49:00 +0000 (20:49 +0300)]
Update ioctl entries from linux v4.12-rc7

* linux/32/ioctls_inc_align16.h: Update from linux v4.12-rc7
(with f7a320ff commit applied on top) using ioctls_gen.sh.
* linux/32/ioctls_inc_align32.h: Likewise.
* linux/32/ioctls_inc_align64.h: Likewise.
* linux/64/ioctls_inc.h: Likewise.
* linux/x32/ioctls_inc0.h: Likewise.
* NEWS: Mention this.

7 years agomaint: fix ioctls_sym.sh premature termination
Gleb Fotengauer-Malinovskiy [Wed, 28 Jun 2017 17:39:54 +0000 (20:39 +0300)]
maint: fix ioctls_sym.sh premature termination

When the list of headers do not fit into the command line, xargs splits
it into several lists and then passes them to grep.  If no headers from
a list match the grep pattern, grep exits with a non-zero status that
causes xargs to exit with a non-zero status, too.

* maint/ioctls_sym.sh: Use "find -exec +" instead of xargs,
ignore its exit status.

7 years agotests: introduce NLMSG_ATTR macro
JingPiao Chen [Tue, 27 Jun 2017 08:18:23 +0000 (16:18 +0800)]
tests: introduce NLMSG_ATTR macro

* tests/tests.h (NLMSG_ATTR): New macro.
* tests/nlattr.c (test_nlattr, test_nla_type): Use it.

7 years agonetlink: pass NLMSG_DONE messages to family specific payload decoders
JingPiao Chen [Tue, 27 Jun 2017 08:16:56 +0000 (16:16 +0800)]
netlink: pass NLMSG_DONE messages to family specific payload decoders

While many NLMSG_DONE messages indeed have payload containing
just one integer, there are exceptions. Handle this by passing
payloads of NLMSG_DONE messages to family specific netlink
payload decoders.

* netlink.c (print_nlmsghdr): Do not skip family detection
for nlmsg_type == NLMSG_DONE.
(decode_nlmsg_type): Skip family specific type decoders
for type == NLMSG_DONE.
(decode_nlmsg_flags): Skip family specific decoding of flags
for type == NLMSG_DONE.
(decode_netlink_sock_diag): Skip for nlmsg_type == NLMSG_DONE.

7 years agoUnexport die_out_of_memory
Dmitry V. Levin [Mon, 26 Jun 2017 22:41:28 +0000 (22:41 +0000)]
Unexport die_out_of_memory

Print more specific error diagnostics than a generic "Out of memory"
when an error happens outside xmalloc.c.

* defs.h (die_out_of_memory): Remove prototype.
* strace.c (strace_popen, init): Call perror_msg_and_die instead
of die_out_of_memory.
* unwind.c (unwind_tcb_init): Likewise.
* xmalloc.c (die_out_of_memory): Add static qualifier.

7 years agoCheck -s argument early
Dmitry V. Levin [Mon, 26 Jun 2017 22:30:19 +0000 (22:30 +0000)]
Check -s argument early

* util.c (printstr_ex): Move the check that -s argument
does not exceed -1U / 4 ...
* strace.c (init): ... here.
* tests/options-syntax.test: Check it.

7 years agoInclude "netlink.h" instead of <linux/netlink.h>
Dmitry V. Levin [Sun, 25 Jun 2017 00:40:29 +0000 (00:40 +0000)]
Include "netlink.h" instead of <linux/netlink.h>

* net.c: Include "netlink.h" instead of <linux/netlink.h>.
* sockaddr.c: Likewise.
* tests/create_nl_socket.c: Likewise.
* tests/net-sockaddr.c: Likewise.
* tests/netlink_audit.c: Likewise.
* tests/netlink_generic.c: Likewise.
* tests/netlink_inet_diag.c: Likewise.
* tests/netlink_netfilter.c: Likewise.
* tests/netlink_route.c: Likewise.
* tests/netlink_selinux.c: Likewise.
* tests/netlink_xfrm.c: Likewise.
* tests/net-yy-netlink.c: Include "netlink.h" instead
of <linux/netlink.h>, remove fallback definition of NETLINK_SOCK_DIAG.
* tests/netlink_netlink_diag.c: Likewise.
* tests/netlink_protocol.c: Likewise.
* tests/netlink_sock_diag.c: Likewise.
* tests/netlink_unix_diag.c: Likewise.
* tests/nlattr.c: Likewise.

7 years agonetlink: provide a fallback definition of NETLINK_SOCK_DIAG
Dmitry V. Levin [Sat, 24 Jun 2017 22:25:28 +0000 (22:25 +0000)]
netlink: provide a fallback definition of NETLINK_SOCK_DIAG

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.

7 years agoUpdate prctl ARCH_* constants
Dmitry V. Levin [Fri, 23 Jun 2017 00:31:49 +0000 (00:31 +0000)]
Update prctl ARCH_* constants

* xlat/archvals.in: Add ARCH_GET_CPUID and ARCH_SET_CPUID
introduced by linux kernel commit v4.12-rc1~153^2~2.

7 years agoUpdate V4L2_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 21:48:00 +0000 (21:48 +0000)]
Update V4L2_* constants

* xlat/v4l2_buf_types.in: Add V4L2_BUF_TYPE_META_CAPTURE introduced
by linux kernel commit v4.12-rc1~85^2~71.
* xlat/v4l2_device_capabilities_flags.in: Add V4L2_CAP_META_CAPTURE
introduced by the same commit.
* xlat/v4l2_control_flags.in: Add V4L2_CTRL_FLAG_HAS_PAYLOAD,
V4L2_CTRL_FLAG_EXECUTE_ON_WRITE, and V4L2_CTRL_FLAG_MODIFY_LAYOUT
introduced by linux kernel commits v3.17-rc1~112^2~363,
v4.1-rc1~59^2~1^2~63, and v4.12-rc1~85^2~62, respectively.
* xlat/v4l2_control_types.in: Add V4L2_CTRL_TYPE_U8, V4L2_CTRL_TYPE_U16,
and V4L2_CTRL_TYPE_U32 introduced by linux kernel commits
v3.17-rc1~112^2~343 and v3.17-rc1~112^2~112.

7 years agoUpdate SCTP_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 21:42:00 +0000 (21:42 +0000)]
Update SCTP_* constants

* xlat/socksctpoptions.in: Add SCTP_ENABLE_STREAM_RESET,
SCTP_RESET_STREAMS, SCTP_RESET_ASSOC, SCTP_ADD_STREAMS,
SCTP_RECONFIG_SUPPORTED, and SCTP_PR_STREAM_STATUS introduced
by linux kernel commits v4.11-rc1~124^2~387^2~1, v4.11-rc1~124^2~387^2,
v4.11-rc1~124^2~166^2~2, v4.11-rc1~124^2~166^2, v4.12-rc1~64^3~469^2,
and v4.12-rc1~64^3~276, respectively.

7 years agoUpdate RTM_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 18:36:35 +0000 (18:36 +0000)]
Update RTM_* constants

* xlat/nl_route_types.in: Add RTM_DELNETCONF introduced
by linux kernel commit v4.12-rc1~64^3~312^2~6.

7 years agoUpdate NDIAG_SHOW_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 18:31:49 +0000 (18:31 +0000)]
Update NDIAG_SHOW_* constants

* linux/netlink_diag.h (NDIAG_SHOW_FLAGS): New constant introduced
by linux kernel commit v4.12-rc1~64^3~260.
* xlat/netlink_diag_show.in: Add it.

7 years agoUpdate KEYCTL_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 18:23:08 +0000 (18:23 +0000)]
Update KEYCTL_* constants

* xlat/keyctl_commands.in: Add KEYCTL_RESTRICT_KEYRING introduced
by linux kernel commit v4.12-rc1~123^2~7^2~2^2~3.

7 years agoUpdate ARPHRD_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 18:18:05 +0000 (18:18 +0000)]
Update ARPHRD_* constants

* xlat/arp_hardware_types.in: Add ARPHRD_VSOCKMON introduced
by linux kernel commit v4.12-rc1~129^2~118^2~2.

7 years agoUpdate SO_* constants
Dmitry V. Levin [Thu, 22 Jun 2017 18:08:24 +0000 (18:08 +0000)]
Update SO_* constants

* xlat/sockoptions.in: Add SO_MEMINFO, SO_INCOMING_NAPI_ID,
and SO_COOKIE introduced by linux kernel commits v4.12-rc1~64^3~389,
v4.12-rc1~64^3~341^2, and v4.12-rc1~64^3~221^2~1, respectively.

7 years agotests: check more corner cases of nlattr decoding
Dmitry V. Levin [Wed, 21 Jun 2017 10:37:02 +0000 (10:37 +0000)]
tests: check more corner cases of nlattr decoding

* tests/nlattr.c (test_nlattr): Check decoding in case of invalid
struct nlattr.nla_len.

7 years agotests: check decoding of netlink attribute
JingPiao Chen [Wed, 21 Jun 2017 16:24:24 +0000 (00:24 +0800)]
tests: check decoding of netlink attribute

* tests/nlattr.c: New file.
* tests/gen_tests.in (nlattr): New entry.
* tests/pure_executables.list: Add nlattr.
* tests/.gitignore: Likewise.

7 years agonetlink: introduce a basic netlink attributes parser
JingPiao Chen [Wed, 21 Jun 2017 16:24:23 +0000 (00:24 +0800)]
netlink: introduce a basic netlink attributes parser

* linux/unix_diag.h (UNIX_DIAG_*): New enum.
* nlattr.c: New file.
* nlattr.h: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* netlink_sock_diag.c: Include "nlattr.h" and "xlat/unix_diag_attrs.h".
(decode_unix_diag_msg): Use decode_nlattr.
* xlat/unix_diag_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
7 years agonetlink: introduce netlink.h
JingPiao Chen [Wed, 21 Jun 2017 16:24:22 +0000 (00:24 +0800)]
netlink: introduce netlink.h

* netlink.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_sock_diag.c: Include "netlink.h",
remove <sys/socket.h> and <linux/netlink.h>.
* netlink.c: Likewise.
(NLMSG_HDRLEN): Move to netlink.h.
* tests/netlink_protocol.c: Replace <linux/netlink.h> with "netlink.h".
* tests/netlink_sock_diag.c: Likewise.

7 years agotests: add SET_STRUCT macro to tests.h
Dmitry V. Levin [Tue, 20 Jun 2017 17:41:59 +0000 (17:41 +0000)]
tests: add SET_STRUCT macro to tests.h

* tests/netlink_sock_diag.c (INIT_STRUCT): Rename to SET_STRUCT,
all callers updated.  Move ...
* tests/tests.h: ... here.

7 years agotests: fix potential unaligned access in netlink_sock_diag.test
Dmitry V. Levin [Mon, 19 Jun 2017 21:36:47 +0000 (21:36 +0000)]
tests: fix potential unaligned access in netlink_sock_diag.test

Despite our efforts made to avoid unaligned access, gcc appears to be
generating instructions that might cause unaligned access when copying
structures to unaligned addresses.

Fix this issue by replacing copying of structures to unaligned addresses
with memcpy calls.

* tests/netlink_sock_diag.c (INIT_STRUCT): New macro.
(test_odd_family_req, test_odd_family_msg, test_unix_diag_req,
test_unix_diag_msg, test_netlink_diag_req, test_netlink_diag_msg,
test_packet_diag_req, test_packet_diag_msg, test_inet_diag_sockid,
test_inet_diag_req, test_inet_diag_req_v2, test_inet_diag_msg,
test_smc_diag_req, test_smc_diag_msg): Use it to initialize potentially
unaligned struct nlmsghdr.  Do not access nlh->nlmsg_len.

7 years agotests: check decoding of NETLINK_GENERIC message types
Masatake YAMATO [Tue, 13 Jun 2017 08:26:45 +0000 (17:26 +0900)]
tests: check decoding of NETLINK_GENERIC message types

* tests/netlink_generic.c: New file.
* tests/gen_tests.in (netlink_generic): New entry.
* tests/pure_executables.list: Add netlink_generic.
* tests/.gitignore: Likewise.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
7 years agonetlink: add decoding of NETLINK_GENERIC protocol families
Masatake YAMATO [Tue, 13 Jun 2017 08:26:44 +0000 (17:26 +0900)]
netlink: add decoding of NETLINK_GENERIC protocol families

NETLINK_GENERIC is a protocol stacked on netlink protocol.

When a NETLINK_GENERIC subsystem registers its "family" name in the
kernel at run time, an integer value associated with this name is
assigned by the kernel.  This integer value is specified in struct
nlmsghdr.nlmsg_type of subsequent communications with the
NETLINK_GENERIC subsystem.

This change implements decoding of NETLINK_GENERIC message types in
symbolic form, for example:

  $ ./strace -yy -e 'sendto' ip tcp_metrics > /dev/null
  sendto(4<NETLINK:[GENERIC:12345]>, {{len=20, type=tcp_metrics, ...
  +++ exited with 0 +++

Note that type= specifying the NETLINK_GENERIC protocol family
is decoded properly.

* netlink.c (decode_nlmsg_type_generic): New function.
(nlmsg_types): Add NETLINK_GENERIC entry.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
7 years agosocketutils: build a dynamic xlat table for NETLINK_GENERIC decoding
Masatake YAMATO [Tue, 13 Jun 2017 08:26:43 +0000 (17:26 +0900)]
socketutils: build a dynamic xlat table for NETLINK_GENERIC decoding

* 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>
7 years agodyxlat: new interface for building xlat tables dynamically
Masatake YAMATO [Tue, 13 Jun 2017 08:26:41 +0000 (17:26 +0900)]
dyxlat: new interface for building xlat tables dynamically

xlat tables are usually generated at build time.

printxval is suitable for printing struct nlmsghdr.nlmsg_type for
NETLINK_GENERIC protocol.  However, the corresponding xlat table
cannot be defined at build time because the values are registered
by the kernel at run time.

This change introduces dyxlat functions for building xlat tables
dynamically.  The primary use case is decoding nlmsg_type but this
interface can be used for other purposes.

* defs.h (struct dyxlat): New opaque data type.
(dyxlat_alloc, dyxlat_free, dyxlat_add_pair): New function declarations.
* dyxlat.c: New file.
* Makefile.am (strace_SOURCES): Add it.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
7 years agoIntroduce xstrndup function
Masatake YAMATO [Tue, 13 Jun 2017 08:26:42 +0000 (17:26 +0900)]
Introduce xstrndup function

* configure.ac (AC_CHECK_FUNCS): Add strndup.
* defs.h (xstrndup): New prototype.
* xmalloc.c (xstrndup): New function.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
7 years agonetlink: do not print extra braces around payloadless nlmsghdr
Dmitry V. Levin [Sun, 18 Jun 2017 21:43:39 +0000 (21:43 +0000)]
netlink: do not print extra braces around payloadless nlmsghdr

* netlink.c (decode_nlmsghdr_with_payload): Print braces before
print_nlmsghdr and after decode_payload iff decode_payload is invoked.
* tests/netlink_audit.c (test_nlmsg_type): Update expected output.
* tests/netlink_netfilter.c: Likewise.
* tests/netlink_selinux.c: Likewise.
* tests/netlink_protocol.c (send_query): Likewise.
* tests/netlink_route.c (test_nlmsg_type, test_nlmsg_flags): Likewise.
* tests/netlink_sock_diag.c: Likewise.
* tests/netlink_xfrm.c: Likewise.

7 years agoStrip argument name of type "struct tcb *" from function prototypes
Dmitry V. Levin [Sat, 17 Jun 2017 22:29:52 +0000 (22:29 +0000)]
Strip argument name of type "struct tcb *" from function prototypes

"struct tcb *" was used in most prototypes along with "struct tcb *tcp",
this change converts the latter form to the former for consistency.

7 years agoFix a few spacing style issues
Dmitry V. Levin [Sat, 17 Jun 2017 22:23:09 +0000 (22:23 +0000)]
Fix a few spacing style issues

Reported by kernel's checkpatch.pl script.

7 years agoStrip redundant trailing semicolons
Dmitry V. Levin [Sat, 17 Jun 2017 21:47:57 +0000 (21:47 +0000)]
Strip redundant trailing semicolons

Strip trailing semicolons from macro definitions.
Strip extra semicolons from statements terminations.

Reported by kernel's checkpatch.pl script.

7 years agoFix macros encosure in a do/while loop
Dmitry V. Levin [Sat, 17 Jun 2017 21:47:57 +0000 (21:47 +0000)]
Fix macros encosure in a do/while loop

Enclose macros with multiple statements and macros starting
with "if" statement in a do/while loop.
Do not enclose single statement macros in a do/while loop.

Reported by kernel's checkpatch.pl script.

7 years agoUse __func__ instead of gcc specific __FUNCTION__
Dmitry V. Levin [Sat, 17 Jun 2017 20:39:26 +0000 (20:39 +0000)]
Use __func__ instead of gcc specific __FUNCTION__

Reported by kernel's checkpatch.pl script.

7 years agoFix a few initialization style issues
Dmitry V. Levin [Sat, 17 Jun 2017 19:20:11 +0000 (19:20 +0000)]
Fix a few initialization style issues

Do not initialise statics and globals to 0, NULL, or false.

Reported by kernel's checkpatch.pl script.

7 years agoFix function prototypes with unspecified arguments
Dmitry V. Levin [Sat, 17 Jun 2017 19:08:36 +0000 (19:08 +0000)]
Fix function prototypes with unspecified arguments

Change functions declared as taking unspecified number of arguments
of unspecified type to functions that take no arguments.

Reported by kernel's checkpatch.pl script.

7 years agoFix a few sizeof style issues
Dmitry V. Levin [Sat, 17 Jun 2017 18:49:58 +0000 (18:49 +0000)]
Fix a few sizeof style issues

Reported by kernel's checkpatch.pl script.

7 years agoFix a few misspellings in comments
Dmitry V. Levin [Fri, 16 Jun 2017 22:54:04 +0000 (22:54 +0000)]
Fix a few misspellings in comments

Reported by kernel's checkpatch.pl script.

7 years agoprint_mreq: remove superfluous print_quoted_string calls
Dmitry V. Levin [Fri, 16 Jun 2017 00:00:42 +0000 (00:00 +0000)]
print_mreq: remove superfluous print_quoted_string calls

The string returned by inet_ntoa(3) has IPv4 dotted-decimal notation,
no need to quote it.

* net.c (print_mreq): Remove print_quoted_string calls.

7 years agotests: check decoding of incomplete SCM_TIMESTAMP* control messages
Dmitry V. Levin [Thu, 15 Jun 2017 17:00:34 +0000 (17:00 +0000)]
tests: check decoding of incomplete SCM_TIMESTAMP* control messages

* tests/msg_control.c (test_scm_timestamp, test_scm_timestampns,
test_scm_timestamping): Check decoding of incomplete control messages.

7 years agomsghdr: print SCM_TIMESTAMP* control messages
Miroslav Lichvar [Thu, 15 Jun 2017 14:02:40 +0000 (16:02 +0200)]
msghdr: print SCM_TIMESTAMP* control messages

Add support for printing control messages containing software and/or
hardware timestamps, which are typically enabled by NTP and PTP
implementations.

* print_timeval.c (print_struct_timeval_data_size): New mpers printer.
* print_timespec.c (print_struct_timespec_data_size,
print_struct_timespec_array_data_size): Likewise.
* msghdr.c (print_scm_timestamp, print_scm_timestampns,
print_scm_timestamping): New functions.
(cmsg_socket_printers): Add them.
* NEWS: Mention this change.
* tests/msg_control.c: Include "xlat.h" and "xlat/scmvals.h".
(test_scm_timestamp, test_scm_timestampns, test_scm_timestamping):
New functions.
(test_sol_socket): Use them.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
7 years agotests: check decoding of NETLINK_SOCK_DIAG AF_SMC messages
JingPiao Chen [Tue, 13 Jun 2017 05:49:46 +0000 (13:49 +0800)]
tests: check decoding of NETLINK_SOCK_DIAG AF_SMC messages

* tests/netlink_sock_diag.c: Include <linux/smc_diag.h>.
(SMC_ACTIVE): New macro.
(test_smc_diag_req, test_smc_diag_msg): New functions.
(main): Use them.

7 years agonetlink: add a basic socket diag parser of AF_SMC messages
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.

7 years agotests: check decoding of NETLINK_SOCK_DIAG AF_INET messages
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>
7 years agonetlink: add a basic socket diag parser of AF_INET and AF_INET6 messages
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>
7 years agoIntroduce print_inet_addr
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.

7 years agotests: check decoding of NETLINK_SOCK_DIAG AF_PACKET messages
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>
7 years agonetlink: add a basic socket diag parser of AF_PACKET messages
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>
7 years agotests: check decoding of NETLINK_SOCK_DIAG AF_NETLINK messages
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>
7 years agonetlink: add a basic socket diag parser of AF_NETLINK messages
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>
7 years agotests: check decoding of NETLINK_SOCK_DIAG AF_UNIX messages
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>
7 years agonetlink: add a basic socket diag parser of AF_UNIX messages
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>
7 years agonetlink: introduce family specific payload decoders
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>
7 years agoUpdate SCM_* constants
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.

7 years agonetlink: refactor decode_nlmsg_type
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.

7 years agotests: extend printstr test
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.

7 years agov4l2: fix preprocessor checks
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.

7 years agoMove xlat related functions to a separate file
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.

7 years agosocketeutils: extend receive_responses further
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>
7 years agosocketeutils: extend receive_responses to handle other netlink types
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>
7 years agotests: fix typo
JingPiao Chen [Mon, 12 Jun 2017 15:33:00 +0000 (23:33 +0800)]
tests: fix typo

* tests/dup3.c (SKIP_MAIN_UNDEFINED): Remove duplicated &&.

7 years agoIntroduce printflags_ex function
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.

7 years agotests: add check for decoding netlink get and new flags
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.

7 years agonetlink: implement generic nlmsg_flags decoding
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>
7 years agoxlat: provide fallback definitions for XFRM_MSG_* constants
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.

7 years agosyscall.c: split trace_syscall() into 6 functions
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.

7 years agotests: guard against missing linux/netfilter/nfnetlink.h
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.

7 years agotests: check decoding of NETLINK_XFRM message types
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.

7 years agotests: check decoding of NETLINK_SELINUX message types
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.

7 years agotests: check decoding of NETLINK_NETFILTER message types
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.

7 years agotests: check decoding of NETLINK_AUDIT message types
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.

7 years agotests: check decoding of NETLINK_ROUTE message types
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.

7 years agotests: check decoding of NETLINK_SOCK_DIAG message types
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.

7 years agotests: use create_nl_socket in netlink_protocol.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.

7 years agotests: change netlink_protocol.test to trace sendto syscalls only
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.

7 years agotests: enhance create_nl_socket diagnostics messages
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.

7 years agotests: use const and designated initializers in create_nl_socket.c
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.

7 years agotests: add create_nl_socket function to libtests
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.

7 years agonetlink: add decoding of NETLINK_NETFILTER message types
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>
7 years agonetlink: add decoding of NETLINK_XFRM message types
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>
7 years agonetlink: add decoding of NETLINK_SELINUX message types
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>
7 years agonetlink: add decoding of NETLINK_ROUTE message types
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>
7 years agonetlink: add decoding of NETLINK_AUDIT message types
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>
7 years agonetlink: implement generic nlmsg_type decoding
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>
7 years agonetlink: add netlink family argument to printers and decoders
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.

7 years agoAdd file descriptor argument to decode_netlink
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>
7 years agoIntroduce getfdinode to obtain inode from fd
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>
7 years agoIntroduce get_sockaddr_by_inode
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>
7 years agosocketutils.c: introduce get_sockaddr_by_inode_uncached
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.

7 years agosocketutils.c: use get_sockaddr_by_inode_cached
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>
7 years agosocketutils.c: move inet_print closer to its first use
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.

7 years agosocketutils.c: introduce cache_inode_details
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>
7 years agostrace.c: move termination code to a separate function
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.

7 years agotests: avoid hitting SO_SNDBUF limit in sendfile/sendfile64 tests
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>
7 years agoMove netlink_protocols definition from net.c to netlink.c
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.

7 years agotravis: switch from gcc-6 to gcc-7
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.

7 years agotests: extend checking of NLMSG_DONE decoding
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.

7 years agonetlink: decode NLMSG_DONE messages
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.

7 years agosocketutils.c: introduce get_sockaddr_by_inode_cached
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.