Commit Graph

239 Commits

Author SHA1 Message Date
4c14d39332 net: accept arbitrary option length for getsockopt's SO_LINGER
* net.c (print_linger): Rename to print_set_linger.
(print_setsockopt): Replace print_linger with print_set_linger.
(print_get_linger): New function that accepts arbitrary option length
to match the kernel behaviour.
(print_getsockopt): Replace print_linger with print_get_linger.
* NEWS: Mention this.
2017-07-08 14:57:44 +00:00
2ccd886706 net: accept large option length for SO_LINGER
* net.c (print_linger): Allow len > sizeof(struct linger) to match
the kernel behaviour.
2017-07-08 14:57:44 +00:00
6314e1d0f1 net: fix printing of struct linger's field names
* net.c: Include "print_fields.h".
(print_linger): Print fields of struct linger using PRINT_FIELD_D.
2017-07-08 14:57:44 +00:00
657b04b83b net: enhance decoding of getsockopt's optlen argument
As the last argument of getsockopt syscall has read-write semantics,
print both user and kernel values when they differ.

* net.c (SYS_FUNC(getsockopt)): On entering syscall, fetch and save
the length specified to the kernel.  On error, print the length saved
on entering.  When the saved length and the length returned by the
kernel differ, print both values.
* NEWS: Mention this.
* tests/net-icmp_filter.c (main): Update expected output.
2017-07-08 14:57:44 +00:00
bec9f165be net: move printing of [gs]etsockopt's socklen argument to toplevel parsers
* net.c (print_getsockopt, print_setsockopt): Remove "done" label,
replace "goto done" statement with "return".
Move printing of "len" argument ...
(SYS_FUNC(getsockopt), SYS_FUNC(setsockopt)): ... here.
2017-07-08 14:57:44 +00:00
4a2a9a7cb1 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.
2017-06-25 00:40:29 +00:00
3d42386923 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.
2017-06-16 00:00:42 +00:00
bd70a9c411 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.
2017-06-15 23:52:47 +00:00
Fabien Siron
8240e4e983 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>
2017-06-05 11:52:11 +00:00
c826fa0f71 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.
2017-06-04 17:03:44 +00:00
Eugene Syromyatnikov
9d095c7860 Add copyright headers 2017-05-22 17:33:51 +00:00
89636759d7 Automatically replace PRI_kr[dux] with PRI_kl[dux]
Remove temporary macros created for transition from long
to kernel_ulong_t.

Automatically replace PRI_kr[dux] with PRI_kl[dux] using
$ git grep -l 'PRI_kr[dux]' | xargs sed -ri 's/PRI_kr([dux])/PRI_kl\1/g'

* defs.h (PRI_krd, PRI_kru, PRI_krx): Remove.  All users updated.
2016-12-26 10:43:34 +00:00
7fa3d78319 Automatically replace kernel_(scno|ureg)_t with kernel_ulong_t
Remove temporary types created for transition from long
to kernel_ulong_t.

Automatically replace kernel_scno_t and kernel_ureg_t with
kernel_ulong_t using
$ git grep -El 'kernel_(scno|ureg)_t' |
  xargs sed -ri 's/kernel_(scno|ureg)_t/kernel_ulong_t/g'

* kernel_types.h (kernel_scno_t, kernel_ureg_t): Remove.
All users updated.
2016-12-26 10:43:34 +00:00
1d5bb61c49 Print kernel_ureg_t and kernel_scno_t using dedicated format strings
Prepare for the change of kernel_ureg_t and kernel_scno_t from
unsigned long to kernel_ulong_t.

* defs.h (PRI_krd, PRI_kru, PRI_krx): New temporary macros.
All users updated.
2016-12-26 10:43:04 +00:00
26102a5a87 decode_sockbuf: change addrlen argument type from long to kernel_ureg_t
* net.c (decode_sockbuf): Change addrlen argument type from long
to kernel_ureg_t.
2016-12-25 11:32:46 +00:00
a940d1a60f printstr: rename to printstrn, add printstr as a thin wrapper
As about half of all printstr uses cases are invocations with the last
argument set to -1, create a dedicated function for this use case.

* defs.h (printstr): Rename to printstrn.  All callers updated.
(printstr): New static inline function.  All callers updated.
2016-12-25 11:32:45 +00:00
405279fa77 net: change address argument type from long to kernel_ureg_t
* net.c (decode_sockbuf, decode_pair_fd, print_linger, print_ucred,
print_tpacket_stats, print_icmp_filter, print_getsockopt, print_mreq,
print_mreq6, print_group_req, print_tpacket_req, print_packet_mreq,
print_setsockopt): Change address argument type from long
to kernel_ureg_t.
2016-12-25 11:32:45 +00:00
d7f98585ef net: change address argument type from unsigned long to kernel_ureg_t
* net.c (fetch_socklen): Change address argument type from
unsigned long to kernel_ureg_t.
2016-12-23 19:26:58 +00:00
3a838cd31a xlat: provide fallback definitions for NETLINK_* constants
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.
2016-12-14 08:09:10 +00:00
cce5aaef1e Use tprints instead of tprintf in a few more places
* btrfs.c (btrfs_print_qgroup_inherit, btrfs_print_tree_search,
btrfs_ioctl): Replace tprintf with tprints for printing strings without
format specifiers.
* net.c (print_group_req): Likewise.
* scsi.c (scsi_ioctl): Likewise.
* term.c (decode_termios, decode_termio): Likewise.
* userfaultfd.c (uffdio_ioctl): Likewise.
2016-10-02 19:19:28 +00:00
b759d276d5 Unabuse struct tcb.auxstr
As we've got a proper mechanism that parsers can use for storing private
data between entering and exiting stages, all cases of struct tcb.auxstr
abuse should go.

* btrfs.c (btrfs_ioctl): Use set_tcb_priv_ulong and get_tcb_priv_ulong
instead of abusing tcp->auxstr.
* file_handle.c (SYS_FUNC(name_to_handle_at)): Likewise.
* msghdr.c (SYS_FUNC(recvmsg)): Likewise.
* net.c (decode_sockname, SYS_FUNC(recvfrom)): Likewise.
* v4l2.c (print_v4l2_queryctrl): Likewise.
2016-07-18 22:12:45 +00:00
dc84fa3646 net.c: move parsers of sendmsg and recvmsg syscalls to msghdr.c
* defs.h (fetch_msghdr_namelen, decode_msghdr): Remove.
* net.c (SYS_FUNC(sendmsg), SYS_FUNC(recvmsg)): Move ...
* msghdr.c: ... here.
(fetch_msghdr_namelen, decode_msghdr): Add static qualifier.
2016-07-18 22:12:44 +00:00
4de8de50d2 net.c: move parsers of sendmmsg and recvmmsg syscalls to mmsghdr.c
* defs.h (decode_mmsgvec): Remove.
* net.c: Do not include "msghdr.h".
(SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg)): Move ...
* mmsghdr.c: ... here.
(decode_mmsgvec): Add static qualifier.
2016-07-18 22:12:44 +00:00
d8f77cdf42 Fix decoding of struct msghdr.msg_name* arguments of recvmsg syscall
As the msghdr.msg_namelen argument of recvmsg syscall has the same
read-write semantics as the address length argument of recvfrom syscall,
parser of recvmsg syscall needs a similar fix.

* defs.h (fetch_msghdr_namelen): New prototype.
(decode_msghdr): Add "int *" argument.
* msghdr.c (print_msghdr): Likewise.  Treat it as a pointer to struct
msghdr.msg_namelen passed to the kernel.  Pass to decode_sockaddr
the size of socket address actually returned by the kernel.
Print both user and kernel address lengths when the value changes.
(decode_msghdr, decode_mmsghdr): Add "int *" argument,
forward it to print_msghdr.
(decode_mmsgvec): Update decode_mmsghdr invocation.
(fetch_msghdr_namelen): New function.
* net.c (SYS_FUNC(sendmsg)): Update decode_msghdr invocation.
(SYS_FUNC(recvmsg)): Use fetch_msghdr_namelen on entering to save
struct msghdr.msg_namelen.  On exiting, pass the saved value
to decode_msghdr.
2016-07-13 21:56:16 +00:00
7acde9e994 Fix printing of socklen argument of bind and sendto syscalls
* net.c (SYS_FUNC(bind)): Print 3rd syscall argument using %d format.
(SYS_FUNC(sendto)): Print 6th syscall argument using %d format.
2016-07-12 14:42:31 +00:00
802f264643 Fix decoding of sockaddr related arguments of recvfrom syscall
* net.c (SYS_FUNC(recvfrom)): Use fetch_socklen.  Save the address
length passed to the kernel and print it on error.  Do not print more
bytes of the socket address than actually returned by the kernel.
Print both user and kernel address lengths when the returned address
is truncated.
2016-07-12 14:42:30 +00:00
eca8b5b26a Print both values of changing address length in sockname family syscalls
* net.c (decode_sockname): Print both user and kernel address lengths
when the value changes.
* tests/net-y-unix.c (main): Update expected output.
* tests/net-yy-unix.c (main): Likewise.
* tests/net.expected: Likewise.
2016-07-12 10:54:25 +00:00
36df8223a1 Enhance diagnostics of address truncation in sockname family syscalls
* net.c (decode_sockname): Print both user and kernel address lengths
when the returned address is truncated.
* tests/sun_path.expected: Update expected output.
2016-07-12 07:40:31 +00:00
d07eac3ac4 Fix decoding of getsockname, getpeername, accept, and accept4 syscalls
* net.c (fetch_socklen): New function.
(decode_sockname): Use it.  On entering syscall, decode early
and return RVAL_DECODED when possible.  On error, print the address
length passed to the kernel.  Do not print more bytes of the socket
address than actually returned by the kernel.
2016-07-12 07:39:26 +00:00
d1cedf0fdb Prepare parsers of sockname family syscalls for the upcoming fix
* net.c (do_sockname): Rename to decode_sockname, drop second argument,
do not print sock_type_flags, return RVAL_DECODED on exiting.
(SYS_FUNC(accept), SYS_FUNC(getsockname)): Use decode_sockname instead
of do_sockname, take its return code into account.
(SYS_FUNC(accept4)): Likewise.  Print sock_type_flags when
decode_sockname returns RVAL_DECODED.
2016-07-11 22:43:47 +00:00
Fabien Siron
2850f745ca Add a general netlink socket parser
Introduce a general socket netlink parser which prints the header and
a string for the remaining part of the buffer.  It doesn't handle all
the netlink flags and types yet because the parser needs more
information, this will be implemented later.

* net.c (decode_sockbuf): New function.
(SYS_FUNC(send), SYS_FUNC(sendto), SYS_FUNC(recv), SYS_FUNC(recvfrom)):
Use it instead of printstr.
* msghdr.c (print_msghdr): Pass IOV_DECODE_NETLINK to tprint_iov_upto()
for netlink sockets.
* netlink.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (decode_netlink, getfdproto): New prototypes.
(iov_decode): Add IOV_DECODER_NETLINK.
* io.c (print_iovec): Use decode_netlink().
* util.c (getfdproto): Remove static keyword.
* xlat/netlink_flags.in: New file.
* xlat/netlink_types.in: New file.
2016-07-07 09:46:51 +00:00
95cce4f9a6 net.c: move all msghdr and mmsghdr parsers to a separate file
* defs.h (msg_flags, socketlayers, decode_msghdr, decode_mmsg):
New prototypes.
* msghdr.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* net.c: Move all msghdr and mmsghdr parsers to msghdr.c.
2016-06-27 00:10:58 +00:00
9a8216ea7b Mpersify fetchers of struct msghdr and struct mmsghdr
* fetch_struct_msghdr.c: New file.
* fetch_struct_mmsghdr.c: Likewise.
* Makefile.am (strace_SOURCES): Add them.
* net.c (struct msghdr32, struct mmsghdr32, copy_from_msghdr32,
fetch_msghdr, fetch_mmsghdr): Remove.
(decode_msghdr, dumpiov_in_msghdr): Use fetch_struct_msghdr instead
of fetch_msghdr.
(decode_mmsghdr): Change msg_len argument to use_msg_len.
Use fetch_struct_mmsghdr instead of fetch_mmsghdr.
Return fetch_struct_mmsghdr's return code.
(decode_mmsg): Rename to decode_mmsgvec.  Take addr and len arguments.
Do not print vlen and flags.  Check decode_mmsghdr's return code.
Print mmsghdr array using square brackets.
(dumpiov_in_mmsghdr): Use fetch_struct_mmsghdr instead of fetch_mmsghdr.
(SYS_FUNC(sendmmsg), SYS_FUNC(recvmmsg)): Use decode_mmsgvec instead
of decode_mmsg.  Print vlen and flags.
* tests/mmsg.c (main): Update expected output.
2016-06-27 00:10:58 +00:00
4b38ce956c net.c: move fallback definition of struct mmsghdr to a separate file.
* msghdr.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* net.c: Include it.  Move fallback definition of struct mmsghdr there.
* tests/mmsg.c: Include "msghdr.h".  Remove fallback definition
of struct mmsghdr.
2016-06-27 00:10:08 +00:00
26f90afc68 net.c: print struct msghdr as a regular structure
* net.c (print_msghdr): Print msg_name, msg_namelen, msg_iov,
and msg_iovlen fields like other regular fields.
* tests/inet-cmsg.c (main): Update expected output.
* tests/mmsg.c (main): Likewise.
* tests/recvmsg.c (main): Likewise.
* tests/scm_rights-fd.test: Likewise.
2016-06-26 23:57:39 +00:00
3e514c05e3 net.c: rename some internal functions for consistency and readability
* net.c (printcmsghdr): Rename to decode_msg_control.
(do_msghdr): Rename to print_msghdr.
(extractmsghdr): Rename to fetch_msghdr.
(extractmmsghdr): Rename to fetch_mmsghdr.
(printmsghdr): Rename to decode_msghdr.
(printmmsghdr): Rename to decode_mmsghdr.
All callers updated.
2016-06-26 23:57:29 +00:00
00ba20aae1 net.c: when printing struct msghdr.msg_control, also print its name
* net.c (printcmsghdr): Skip control messages of zero length.
Always print "msg_control=" before the control message.
(do_msghdr): Print control message before its length, not after.
* tests/inet-cmsg.c (main): Update expected output.
* tests/scm_rights-fd.test: Likewise.
2016-06-26 23:57:18 +00:00
cf0ef0852c Assume that libc provides struct msghdr.msg_control
* configure.ac (AC_CHECK_MEMBERS): Remove struct msghdr.msg_control.
* net.c (do_msghdr): Remove HAVE_STRUCT_MSGHDR_MSG_CONTROL check.
2016-06-26 23:56:59 +00:00
e96aee7ebb net.c: move all sockaddr parsers to a separate file
* sockaddr_ll.c: Rename to sockaddr.c
(print_sockaddr_data_ll): Add static keyword.
* Makefile.am (strace_SOURCES): Likewise.
* defs.h (print_sockaddr_data_ll): Remove.
(addrfams): New prototype.
* net.c: Move all sockaddr parsers to sockaddr.c.
2016-06-25 15:47:27 +00:00
42e566ae74 net.c: rename printsock to decode_sockaddr
* defs.h (printsock): Rename to decode_sockaddr.
* net.c (printsock): Likewise.
(do_msghdr, SYS_FUNC(bind), do_sockname, SYS_FUNC(sendto),
SYS_FUNC(recvfrom)): Replace printsock with decode_sockaddr.
2016-06-25 15:45:20 +00:00
45ae937ced net.c: fix printing AF_PACKET socket addresses
* defs.h (print_ifindex, print_sockaddr_data_ll): New prototypes.
* net.c: Stop including "xlat/af_packet_types.h".
(print_ifindex): Remove static keyword.
(print_sockaddr_data_l): Remove.
* sockaddr_ll.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* xlat/arp_hardware_types.in: New file.
* xlat/ethernet_protocols.in: Likewise.
2016-06-24 17:43:52 +00:00
eef96acd1a net.c: skip details of too short socket addresses, part 2
* net.c (sa_printers): Add minimal address length for each socket family.
(print_sockaddr): Call socket family specific sockaddr printer
only when socket address length is greater or equal
the minimal address length for the socket family.
2016-06-24 15:49:31 +00:00
324f68d439 net.c: fix printing AF_BLUETOOTH socket addresses
* xlat/hci_channels.in: New file.
* net.c (print_sockaddr_data_raw): New function.
(print_sockaddr): Use it.
[HAVE_BLUETOOTH_BLUETOOTH_H]: Include "xlat/hci_channels.h".
[HAVE_BLUETOOTH_BLUETOOTH_H] (print_sockaddr_data_bt): Fix printing
sockaddr_hci, sockaddr_sco, sockaddr_rc, and sockaddr_l2 structures.
2016-06-24 15:49:31 +00:00
102c8ca79e net.c: fix printing AF_IPX sockets addresses, part 2
* net.c (print_sockaddr_data_ipx): Print sockaddr_ipx.sipx_network
using %#08x format.  Print elements of sockaddr_ipx.sipx_node array
and sockaddr_ipx.sipx_type using %#02x format.
2016-06-24 15:49:31 +00:00
0e09796e95 net.c: fix printing AF_UNIX abstract socket addresses
AF_UNIX abstract socket address specified by sockaddr_un.sun_path
is not a NUL-terminated string.

* net.c (SIZEOF_SA_FAMILY): New macro.
(print_sockaddr_data_un): Use it.  Specify actual address length
in print_quoted_string calls.  Do not set QUOTE_0_TERMINATED flag
when printing an abstract socket address.
2016-06-24 15:48:52 +00:00
71e05be60a net.c: fix printing field names of struct sockaddr_nl
* net.c (print_sockaddr_data_nl): Change "pid" to "nl_pid", "groups"
to "nl_groups".  Print sockaddr_nl.nl_groups using %#08x format.
* tests/net-yy-netlink.c (main): Update.
2016-06-24 01:47:59 +00:00
60bf6c7e7b net.c: fix printing struct sockaddr_in6.sin6_flowinfo
* net.c (print_sockaddr_data_in6): Convert sockaddr_in6.sin6_flowinfo
from network order to host order before printing.
2016-06-24 01:47:59 +00:00
c6fd08c6ed net.c: do not print sockaddr_in6.sin6_scope_id unnecessarily
Prior to RFC2553, struct sockaddr_in6 had no sin6_scope_id field.
As the kernel still accepts RFC2133 editions of struct sockaddr_in6,
print sockaddr_in6.sin6_scope_id only when it is specified.

* net.c (SIN6_MIN_LEN): New macro.
(print_sockaddr_data_in6): Print sockaddr_in6.sin6_scope_id only when
socket address length exceeds SIN6_MIN_LEN.
2016-06-23 09:32:24 +00:00
dcc7a3c1c6 net.c: fix printing raw data of socket addresses
* net.c (print_sockaddr): When printing socket address raw data, read
exactly the number of data bytes specified for the socket addess.
2016-06-23 01:11:35 +00:00
f52753aad5 net.c: skip details of too short socket addresses
* net.c (print_sockaddr): Print socket address details only when
the address size is greater than sizeof(struct sockaddr.sa_family).
(print_sockaddr_data_un): Remove handling of addrlen == 2.
* tests/net-y-unix.c (main): Update expected pattern.
* tests/net-yy-unix.c (main): Likewise.
* tests/net.expected: Likewise.
2016-06-23 01:10:17 +00:00