Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. The name of the author may not be used to endorse or promote products |
| 17 | * derived from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Dmitry V. Levin | 4b38ce9 | 2016-06-27 00:02:41 +0000 | [diff] [blame] | 32 | #include "msghdr.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 33 | #include <sys/stat.h> |
| 34 | #include <sys/socket.h> |
Dmitry V. Levin | b2fa2be | 2014-11-21 20:46:16 +0000 | [diff] [blame] | 35 | #include <sys/uio.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #include <sys/un.h> |
| 37 | #include <netinet/in.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 38 | #ifdef HAVE_NETINET_TCP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 39 | # include <netinet/tcp.h> |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 40 | #endif |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 41 | #ifdef HAVE_NETINET_UDP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 42 | # include <netinet/udp.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 43 | #endif |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 44 | #ifdef HAVE_NETINET_SCTP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 45 | # include <netinet/sctp.h> |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 46 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 47 | #include <arpa/inet.h> |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 48 | #include <net/if.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 49 | #include <asm/types.h> |
Dmitry V. Levin | ebda41a | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 50 | #ifdef HAVE_NETIPX_IPX_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 51 | # include <netipx/ipx.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 52 | #else |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 53 | # include <linux/ipx.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 54 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 55 | |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 56 | #if defined(HAVE_LINUX_IP_VS_H) |
| 57 | # include <linux/ip_vs.h> |
| 58 | #endif |
Dmitry V. Levin | b10ee4e | 2016-06-14 13:53:47 +0000 | [diff] [blame] | 59 | #include <linux/netlink.h> |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 60 | #if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H) |
| 61 | # include <linux/netfilter_arp/arp_tables.h> |
| 62 | #endif |
| 63 | #if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H) |
| 64 | # include <linux/netfilter_bridge/ebtables.h> |
| 65 | #endif |
| 66 | #if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H) |
| 67 | # include <linux/netfilter_ipv4/ip_tables.h> |
| 68 | #endif |
| 69 | #if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H) |
| 70 | # include <linux/netfilter_ipv6/ip6_tables.h> |
| 71 | #endif |
Dmitry V. Levin | 4f689a1 | 2016-06-15 21:35:48 +0000 | [diff] [blame] | 72 | #include <linux/if_packet.h> |
Dmitry V. Levin | d06010b | 2016-06-15 21:27:41 +0000 | [diff] [blame] | 73 | #include <linux/icmp.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 75 | #include "xlat/socktypes.h" |
| 76 | #include "xlat/sock_type_flags.h" |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 77 | #ifndef SOCK_TYPE_MASK |
| 78 | # define SOCK_TYPE_MASK 0xf |
| 79 | #endif |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 80 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 81 | #include "xlat/socketlayers.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 82 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 83 | #include "xlat/inet_protocols.h" |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 84 | |
Dmitry V. Levin | 9457304 | 2016-06-14 13:53:47 +0000 | [diff] [blame] | 85 | #if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG |
| 86 | # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 87 | #endif |
Dmitry V. Levin | 9457304 | 2016-06-14 13:53:47 +0000 | [diff] [blame] | 88 | #include "xlat/netlink_protocols.h" |
Masatake YAMATO | 2394a3d | 2014-03-11 23:37:37 +0900 | [diff] [blame] | 89 | |
Dmitry V. Levin | e96aee7 | 2016-06-25 13:47:54 +0000 | [diff] [blame] | 90 | #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
| 91 | # include <bluetooth/bluetooth.h> |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 92 | # include "xlat/bt_protocols.h" |
| 93 | #endif |
| 94 | |
Dmitry V. Levin | 45ae937 | 2016-06-23 17:38:18 +0000 | [diff] [blame] | 95 | void |
Dmitry V. Levin | ae28093 | 2015-06-05 20:13:21 +0000 | [diff] [blame] | 96 | print_ifindex(unsigned int ifindex) |
| 97 | { |
| 98 | #ifdef HAVE_IF_INDEXTONAME |
| 99 | char buf[IFNAMSIZ + 1]; |
| 100 | |
| 101 | if (if_indextoname(ifindex, buf)) { |
| 102 | tprints("if_nametoindex("); |
| 103 | print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED); |
| 104 | tprints(")"); |
| 105 | return; |
| 106 | } |
| 107 | #endif |
| 108 | tprintf("%u", ifindex); |
| 109 | } |
| 110 | |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 111 | static void |
| 112 | decode_sockbuf(struct tcb *tcp, int fd, long addr, long addrlen) |
| 113 | { |
| 114 | |
| 115 | switch (verbose(tcp) ? getfdproto(tcp, fd) : SOCK_PROTO_UNKNOWN) { |
| 116 | case SOCK_PROTO_NETLINK: |
| 117 | decode_netlink(tcp, addr, addrlen); |
| 118 | break; |
| 119 | default: |
| 120 | printstr(tcp, addr, addrlen); |
| 121 | } |
| 122 | } |
| 123 | |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 124 | /* |
| 125 | * low bits of the socket type define real socket type, |
| 126 | * other bits are socket type flags. |
| 127 | */ |
| 128 | static void |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 129 | tprint_sock_type(unsigned int flags) |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 130 | { |
| 131 | const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK); |
| 132 | |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 133 | if (str) { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 134 | tprints(str); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 135 | flags &= ~SOCK_TYPE_MASK; |
| 136 | if (!flags) |
| 137 | return; |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 138 | tprints("|"); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 139 | } |
| 140 | printflags(sock_type_flags, flags, "SOCK_???"); |
| 141 | } |
| 142 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 143 | SYS_FUNC(socket) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 145 | printxval(addrfams, tcp->u_arg[0], "AF_???"); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 146 | tprints(", "); |
| 147 | tprint_sock_type(tcp->u_arg[1]); |
| 148 | tprints(", "); |
| 149 | switch (tcp->u_arg[0]) { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 150 | case AF_INET: |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 151 | case AF_INET6: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 152 | printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???"); |
| 153 | break; |
Dmitry V. Levin | eb1c22b | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 154 | |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 155 | case AF_NETLINK: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 156 | printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???"); |
| 157 | break; |
Dmitry V. Levin | bc4102e | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 158 | |
Dmitry V. Levin | 43369fc | 2016-06-21 16:43:30 +0000 | [diff] [blame] | 159 | #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 160 | case AF_BLUETOOTH: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 161 | printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???"); |
| 162 | break; |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 163 | #endif |
Dmitry V. Levin | bc4102e | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 164 | |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 165 | default: |
| 166 | tprintf("%lu", tcp->u_arg[2]); |
| 167 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 168 | } |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 169 | |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 170 | return RVAL_DECODED | RVAL_FD; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 173 | SYS_FUNC(bind) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 174 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 175 | printfd(tcp, tcp->u_arg[0]); |
| 176 | tprints(", "); |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 177 | const int addrlen = tcp->u_arg[2]; |
| 178 | decode_sockaddr(tcp, tcp->u_arg[1], addrlen); |
| 179 | tprintf(", %d", addrlen); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 180 | |
| 181 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 184 | SYS_FUNC(listen) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 185 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 186 | printfd(tcp, tcp->u_arg[0]); |
| 187 | tprints(", "); |
| 188 | tprintf("%lu", tcp->u_arg[1]); |
| 189 | |
| 190 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 193 | static bool |
| 194 | fetch_socklen(struct tcb *tcp, int *plen, |
| 195 | const unsigned long sockaddr, const unsigned long socklen) |
| 196 | { |
| 197 | return verbose(tcp) && sockaddr && socklen |
| 198 | && umove(tcp, socklen, plen) == 0; |
| 199 | } |
| 200 | |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 201 | static int |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 202 | decode_sockname(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 203 | { |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 204 | int ulen, rlen; |
| 205 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 206 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 207 | printfd(tcp, tcp->u_arg[0]); |
| 208 | tprints(", "); |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 209 | if (fetch_socklen(tcp, &ulen, tcp->u_arg[1], tcp->u_arg[2])) { |
| 210 | /* abuse of auxstr to retain state */ |
| 211 | tcp->auxstr = (void *) (long) ulen; |
| 212 | return 0; |
| 213 | } else { |
| 214 | printaddr(tcp->u_arg[1]); |
| 215 | tprints(", "); |
| 216 | printaddr(tcp->u_arg[2]); |
| 217 | return RVAL_DECODED; |
| 218 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 219 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 220 | |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 221 | ulen = (long) tcp->auxstr; |
| 222 | tcp->auxstr = NULL; |
| 223 | |
| 224 | if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &rlen) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 225 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 226 | tprintf(", [%d]", ulen); |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 227 | } else { |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 228 | decode_sockaddr(tcp, tcp->u_arg[1], ulen > rlen ? rlen : ulen); |
Dmitry V. Levin | eca8b5b | 2016-07-09 21:52:58 +0000 | [diff] [blame] | 229 | if (ulen != rlen) |
Dmitry V. Levin | 36df822 | 2016-07-09 21:52:51 +0000 | [diff] [blame] | 230 | tprintf(", [%d->%d]", ulen, rlen); |
| 231 | else |
| 232 | tprintf(", [%d]", rlen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 233 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 234 | |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 235 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 238 | SYS_FUNC(accept) |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 239 | { |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 240 | return decode_sockname(tcp) | RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 243 | SYS_FUNC(accept4) |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 244 | { |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 245 | int rc = decode_sockname(tcp); |
| 246 | |
| 247 | if (rc & RVAL_DECODED) { |
| 248 | tprints(", "); |
| 249 | printflags(sock_type_flags, tcp->u_arg[3], "SOCK_???"); |
| 250 | } |
| 251 | |
| 252 | return rc | RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 253 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 254 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 255 | SYS_FUNC(send) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 256 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 257 | printfd(tcp, tcp->u_arg[0]); |
| 258 | tprints(", "); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 259 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 260 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 261 | /* flags */ |
| 262 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 263 | |
| 264 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 267 | SYS_FUNC(sendto) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 268 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 269 | printfd(tcp, tcp->u_arg[0]); |
| 270 | tprints(", "); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 271 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 272 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 273 | /* flags */ |
| 274 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 275 | /* to address */ |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 276 | const int addrlen = tcp->u_arg[5]; |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 277 | tprints(", "); |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 278 | decode_sockaddr(tcp, tcp->u_arg[4], addrlen); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 279 | /* to length */ |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 280 | tprintf(", %d", addrlen); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 281 | |
| 282 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 285 | SYS_FUNC(sendmsg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 286 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 287 | printfd(tcp, tcp->u_arg[0]); |
| 288 | tprints(", "); |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 289 | decode_msghdr(tcp, tcp->u_arg[1], (unsigned long) -1L); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 290 | /* flags */ |
| 291 | tprints(", "); |
| 292 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
| 293 | |
| 294 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 297 | SYS_FUNC(sendmmsg) |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 298 | { |
| 299 | if (entering(tcp)) { |
| 300 | /* sockfd */ |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 301 | printfd(tcp, tcp->u_arg[0]); |
| 302 | tprints(", "); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 303 | if (!verbose(tcp)) { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 304 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 305 | /* vlen */ |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 306 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 307 | /* flags */ |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 308 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 309 | return RVAL_DECODED; |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 310 | } |
| 311 | } else { |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 312 | decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, false); |
| 313 | /* vlen */ |
| 314 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
| 315 | /* flags */ |
| 316 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 317 | } |
| 318 | return 0; |
| 319 | } |
| 320 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 321 | SYS_FUNC(recv) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 322 | { |
| 323 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 324 | printfd(tcp, tcp->u_arg[0]); |
| 325 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 326 | } else { |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 327 | if (syserror(tcp)) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 328 | printaddr(tcp->u_arg[1]); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 329 | } else { |
| 330 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], |
| 331 | tcp->u_rval); |
| 332 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | |
| 334 | tprintf(", %lu, ", tcp->u_arg[2]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 335 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 340 | SYS_FUNC(recvfrom) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 341 | { |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 342 | int ulen, rlen; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 343 | |
| 344 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 345 | printfd(tcp, tcp->u_arg[0]); |
| 346 | tprints(", "); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 347 | if (fetch_socklen(tcp, &ulen, tcp->u_arg[4], tcp->u_arg[5])) { |
| 348 | /* abuse of auxstr to retain state */ |
| 349 | tcp->auxstr = (void *) (long) ulen; |
| 350 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 351 | } else { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 352 | /* buf */ |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 353 | if (syserror(tcp)) { |
Dmitry V. Levin | 52dc150 | 2015-07-30 13:53:42 +0000 | [diff] [blame] | 354 | printaddr(tcp->u_arg[1]); |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 355 | } else { |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 356 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], |
| 357 | tcp->u_rval); |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 358 | } |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 359 | /* size */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 360 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 361 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 362 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 363 | tprints(", "); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 364 | |
| 365 | ulen = (long) tcp->auxstr; |
| 366 | tcp->auxstr = NULL; |
| 367 | |
| 368 | if (!fetch_socklen(tcp, &rlen, tcp->u_arg[4], tcp->u_arg[5])) { |
| 369 | /* from address */ |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 370 | printaddr(tcp->u_arg[4]); |
| 371 | tprints(", "); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 372 | /* from length */ |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 373 | printaddr(tcp->u_arg[5]); |
| 374 | return 0; |
| 375 | } |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 376 | if (syserror(tcp)) { |
| 377 | /* from address */ |
| 378 | printaddr(tcp->u_arg[4]); |
| 379 | /* from length */ |
| 380 | tprintf(", [%d]", ulen); |
| 381 | return 0; |
| 382 | } |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 383 | /* from address */ |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 384 | decode_sockaddr(tcp, tcp->u_arg[4], ulen > rlen ? rlen : ulen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 385 | /* from length */ |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 386 | if (ulen != rlen) |
| 387 | tprintf(", [%d->%d]", ulen, rlen); |
| 388 | else |
| 389 | tprintf(", [%d]", rlen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 394 | SYS_FUNC(recvmsg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 395 | { |
| 396 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 397 | printfd(tcp, tcp->u_arg[0]); |
| 398 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 399 | } else { |
Dmitry V. Levin | 00244b9 | 2015-01-28 01:52:25 +0000 | [diff] [blame] | 400 | if (syserror(tcp)) |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 401 | printaddr(tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 402 | else |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 403 | decode_msghdr(tcp, tcp->u_arg[1], tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 404 | /* flags */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 405 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 406 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 411 | SYS_FUNC(recvmmsg) |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 412 | { |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 413 | static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE]; |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 414 | |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 415 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 416 | printfd(tcp, tcp->u_arg[0]); |
| 417 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 418 | if (verbose(tcp)) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 419 | /* Abusing tcp->auxstr as temp storage. |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 420 | * Will be used and cleared on syscall exit. |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 421 | */ |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 422 | tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 423 | } else { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 424 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 425 | /* vlen */ |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 426 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 427 | /* flags */ |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 428 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 429 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 430 | print_timespec(tcp, tcp->u_arg[4]); |
| 431 | } |
| 432 | return 0; |
| 433 | } else { |
| 434 | if (verbose(tcp)) { |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame] | 435 | decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, true); |
| 436 | /* vlen */ |
| 437 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
| 438 | /* flags */ |
| 439 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 440 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 441 | /* timeout on entrance */ |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 442 | tprints(tcp->auxstr); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 443 | tcp->auxstr = NULL; |
| 444 | } |
| 445 | if (syserror(tcp)) |
| 446 | return 0; |
| 447 | if (tcp->u_rval == 0) { |
| 448 | tcp->auxstr = "Timeout"; |
| 449 | return RVAL_STR; |
| 450 | } |
| 451 | if (!verbose(tcp)) |
| 452 | return 0; |
| 453 | /* timeout on exit */ |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 454 | snprintf(str, sizeof(str), "left %s", |
| 455 | sprint_timespec(tcp, tcp->u_arg[4])); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 456 | tcp->auxstr = str; |
| 457 | return RVAL_STR; |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 458 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 459 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 460 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 461 | #include "xlat/shutdown_modes.h" |
Sebastian Pipping | 9cd3850 | 2011-03-03 01:12:25 +0100 | [diff] [blame] | 462 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 463 | SYS_FUNC(shutdown) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 464 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 465 | printfd(tcp, tcp->u_arg[0]); |
| 466 | tprints(", "); |
| 467 | printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???"); |
| 468 | |
| 469 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 472 | SYS_FUNC(getsockname) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 473 | { |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 474 | return decode_sockname(tcp); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 477 | static void |
| 478 | printpair_fd(struct tcb *tcp, const int i0, const int i1) |
| 479 | { |
| 480 | tprints("["); |
| 481 | printfd(tcp, i0); |
| 482 | tprints(", "); |
| 483 | printfd(tcp, i1); |
| 484 | tprints("]"); |
| 485 | } |
| 486 | |
| 487 | static void |
| 488 | decode_pair_fd(struct tcb *tcp, const long addr) |
| 489 | { |
| 490 | int pair[2]; |
| 491 | |
| 492 | if (umove_or_printaddr(tcp, addr, &pair)) |
| 493 | return; |
| 494 | |
| 495 | printpair_fd(tcp, pair[0], pair[1]); |
| 496 | } |
| 497 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 498 | static int |
| 499 | do_pipe(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 500 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 501 | if (exiting(tcp)) { |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 502 | decode_pair_fd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 503 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 504 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 505 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 506 | } |
| 507 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 508 | return 0; |
| 509 | } |
| 510 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 511 | SYS_FUNC(pipe) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 512 | { |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 513 | #ifdef HAVE_GETRVAL2 |
| 514 | if (exiting(tcp) && !syserror(tcp)) |
| 515 | printpair_fd(tcp, tcp->u_rval, getrval2(tcp)); |
| 516 | return 0; |
| 517 | #else |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 518 | return do_pipe(tcp, -1); |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 519 | #endif |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 522 | SYS_FUNC(pipe2) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 523 | { |
| 524 | return do_pipe(tcp, 1); |
| 525 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 526 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 527 | SYS_FUNC(socketpair) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 528 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 529 | if (entering(tcp)) { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 530 | printxval(addrfams, tcp->u_arg[0], "AF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 531 | tprints(", "); |
Dmitry V. Levin | 1e42f2d | 2014-09-10 17:48:28 +0000 | [diff] [blame] | 532 | tprint_sock_type(tcp->u_arg[1]); |
Dmitry V. Levin | 033fb91 | 2014-03-11 22:50:39 +0000 | [diff] [blame] | 533 | tprintf(", %lu", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 534 | } else { |
Dmitry V. Levin | b679508 | 2015-07-06 22:33:39 +0000 | [diff] [blame] | 535 | tprints(", "); |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 536 | decode_pair_fd(tcp, tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 537 | } |
| 538 | return 0; |
| 539 | } |
| 540 | |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 541 | #include "xlat/sockoptions.h" |
| 542 | #include "xlat/sockipoptions.h" |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 543 | #include "xlat/getsockipoptions.h" |
| 544 | #include "xlat/setsockipoptions.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 545 | #include "xlat/sockipv6options.h" |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 546 | #include "xlat/getsockipv6options.h" |
| 547 | #include "xlat/setsockipv6options.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 548 | #include "xlat/sockipxoptions.h" |
| 549 | #include "xlat/sockrawoptions.h" |
| 550 | #include "xlat/sockpacketoptions.h" |
| 551 | #include "xlat/socksctpoptions.h" |
| 552 | #include "xlat/socktcpoptions.h" |
| 553 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 554 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 555 | print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level, |
| 556 | unsigned int name, bool is_getsockopt) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 557 | { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 558 | printfd(tcp, fd); |
| 559 | tprints(", "); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 560 | printxval(socketlayers, level, "SOL_??"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 561 | tprints(", "); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 562 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 563 | switch (level) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 564 | case SOL_SOCKET: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 565 | printxval(sockoptions, name, "SO_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 566 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 567 | case SOL_IP: |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 568 | printxvals(name, "IP_???", sockipoptions, |
| 569 | is_getsockopt ? getsockipoptions : setsockipoptions, NULL); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 570 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 571 | case SOL_IPV6: |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 572 | printxvals(name, "IPV6_???", sockipv6options, |
| 573 | is_getsockopt ? getsockipv6options : setsockipv6options, NULL); |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 574 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 575 | case SOL_IPX: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 576 | printxval(sockipxoptions, name, "IPX_???"); |
| 577 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 578 | case SOL_PACKET: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 579 | printxval(sockpacketoptions, name, "PACKET_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 580 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 581 | case SOL_TCP: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 582 | printxval(socktcpoptions, name, "TCP_???"); |
| 583 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 584 | case SOL_SCTP: |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 585 | printxval(socksctpoptions, name, "SCTP_???"); |
| 586 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 587 | case SOL_RAW: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 588 | printxval(sockrawoptions, name, "RAW_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 589 | break; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 590 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 591 | /* Other SOL_* protocol levels still need work. */ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 592 | |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 593 | default: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 594 | tprintf("%u", name); |
| 595 | } |
| 596 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 597 | tprints(", "); |
| 598 | } |
| 599 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 600 | static void |
| 601 | print_linger(struct tcb *tcp, long addr, int len) |
| 602 | { |
| 603 | struct linger linger; |
| 604 | |
| 605 | if (len != sizeof(linger) || |
| 606 | umove(tcp, addr, &linger) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 607 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 608 | return; |
| 609 | } |
| 610 | |
| 611 | tprintf("{onoff=%d, linger=%d}", |
| 612 | linger.l_onoff, |
| 613 | linger.l_linger); |
| 614 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 615 | |
| 616 | #ifdef SO_PEERCRED |
| 617 | static void |
| 618 | print_ucred(struct tcb *tcp, long addr, int len) |
| 619 | { |
| 620 | struct ucred uc; |
| 621 | |
| 622 | if (len != sizeof(uc) || |
| 623 | umove(tcp, addr, &uc) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 624 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 625 | } else { |
| 626 | tprintf("{pid=%u, uid=%u, gid=%u}", |
| 627 | (unsigned) uc.pid, |
| 628 | (unsigned) uc.uid, |
| 629 | (unsigned) uc.gid); |
| 630 | } |
| 631 | } |
| 632 | #endif /* SO_PEERCRED */ |
| 633 | |
| 634 | #ifdef PACKET_STATISTICS |
| 635 | static void |
| 636 | print_tpacket_stats(struct tcb *tcp, long addr, int len) |
| 637 | { |
| 638 | struct tpacket_stats stats; |
| 639 | |
| 640 | if (len != sizeof(stats) || |
| 641 | umove(tcp, addr, &stats) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 642 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 643 | } else { |
| 644 | tprintf("{packets=%u, drops=%u}", |
| 645 | stats.tp_packets, |
| 646 | stats.tp_drops); |
| 647 | } |
| 648 | } |
| 649 | #endif /* PACKET_STATISTICS */ |
| 650 | |
Dmitry V. Levin | fba9db2 | 2016-06-15 21:29:07 +0000 | [diff] [blame] | 651 | #include "xlat/icmpfilterflags.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 652 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 653 | static void |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 654 | print_icmp_filter(struct tcb *tcp, const long addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 655 | { |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 656 | struct icmp_filter filter = {}; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 657 | |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 658 | if (len > (int) sizeof(filter)) |
| 659 | len = sizeof(filter); |
| 660 | else if (len <= 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 661 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 662 | return; |
| 663 | } |
| 664 | |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 665 | if (umoven_or_printaddr(tcp, addr, len, &filter)) |
| 666 | return; |
| 667 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 668 | tprints("~("); |
| 669 | printflags(icmpfilterflags, ~filter.data, "ICMP_???"); |
| 670 | tprints(")"); |
| 671 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 672 | |
| 673 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 674 | print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name, |
| 675 | long addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 676 | { |
| 677 | if (addr && verbose(tcp)) |
| 678 | switch (level) { |
| 679 | case SOL_SOCKET: |
| 680 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 681 | case SO_LINGER: |
| 682 | print_linger(tcp, addr, len); |
| 683 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 684 | #ifdef SO_PEERCRED |
| 685 | case SO_PEERCRED: |
| 686 | print_ucred(tcp, addr, len); |
| 687 | goto done; |
| 688 | #endif |
| 689 | } |
| 690 | break; |
| 691 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 692 | case SOL_PACKET: |
| 693 | switch (name) { |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 694 | #ifdef PACKET_STATISTICS |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 695 | case PACKET_STATISTICS: |
| 696 | print_tpacket_stats(tcp, addr, len); |
| 697 | goto done; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 698 | #endif |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 699 | } |
| 700 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 701 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 702 | case SOL_RAW: |
| 703 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 704 | case ICMP_FILTER: |
| 705 | print_icmp_filter(tcp, addr, len); |
| 706 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 707 | } |
| 708 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 709 | } |
| 710 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 711 | /* default arg printing */ |
| 712 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 713 | if (verbose(tcp)) { |
| 714 | if (len == sizeof(int)) { |
| 715 | printnum_int(tcp, addr, "%d"); |
| 716 | } else { |
| 717 | printstr(tcp, addr, len); |
| 718 | } |
| 719 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 720 | printaddr(addr); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 721 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 722 | done: |
| 723 | tprintf(", [%d]", len); |
| 724 | } |
| 725 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 726 | SYS_FUNC(getsockopt) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 727 | { |
| 728 | if (entering(tcp)) { |
| 729 | print_sockopt_fd_level_name(tcp, tcp->u_arg[0], |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 730 | tcp->u_arg[1], tcp->u_arg[2], true); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 731 | } else { |
| 732 | int len; |
| 733 | |
| 734 | if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 735 | printaddr(tcp->u_arg[3]); |
| 736 | tprints(", "); |
| 737 | printaddr(tcp->u_arg[4]); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 738 | } else { |
| 739 | print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 740 | tcp->u_arg[3], len); |
| 741 | } |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 742 | } |
| 743 | return 0; |
| 744 | } |
| 745 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 746 | #ifdef IP_ADD_MEMBERSHIP |
| 747 | static void |
| 748 | print_mreq(struct tcb *tcp, long addr, unsigned int len) |
| 749 | { |
| 750 | struct ip_mreq mreq; |
| 751 | |
| 752 | if (len < sizeof(mreq)) { |
| 753 | printstr(tcp, addr, len); |
| 754 | return; |
| 755 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 756 | if (umove_or_printaddr(tcp, addr, &mreq)) |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 757 | return; |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 758 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 759 | tprints("{imr_multiaddr=inet_addr("); |
| 760 | print_quoted_string(inet_ntoa(mreq.imr_multiaddr), |
| 761 | 16, QUOTE_0_TERMINATED); |
| 762 | tprints("), imr_interface=inet_addr("); |
| 763 | print_quoted_string(inet_ntoa(mreq.imr_interface), |
| 764 | 16, QUOTE_0_TERMINATED); |
| 765 | tprints(")}"); |
| 766 | } |
| 767 | #endif /* IP_ADD_MEMBERSHIP */ |
| 768 | |
| 769 | #ifdef IPV6_ADD_MEMBERSHIP |
| 770 | static void |
| 771 | print_mreq6(struct tcb *tcp, long addr, unsigned int len) |
| 772 | { |
| 773 | struct ipv6_mreq mreq; |
| 774 | |
| 775 | if (len < sizeof(mreq)) |
| 776 | goto fail; |
| 777 | |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 778 | if (umove_or_printaddr(tcp, addr, &mreq)) |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 779 | return; |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 780 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 781 | const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr; |
| 782 | char address[INET6_ADDRSTRLEN]; |
| 783 | |
| 784 | if (!inet_ntop(AF_INET6, in6, address, sizeof(address))) |
| 785 | goto fail; |
| 786 | |
| 787 | tprints("{ipv6mr_multiaddr=inet_pton("); |
| 788 | print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED); |
| 789 | tprints("), ipv6mr_interface="); |
| 790 | print_ifindex(mreq.ipv6mr_interface); |
| 791 | tprints("}"); |
| 792 | return; |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 793 | |
| 794 | fail: |
| 795 | printstr(tcp, addr, len); |
| 796 | } |
| 797 | #endif /* IPV6_ADD_MEMBERSHIP */ |
| 798 | |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 799 | #ifdef MCAST_JOIN_GROUP |
| 800 | static void |
| 801 | print_group_req(struct tcb *tcp, long addr, int len) |
| 802 | { |
| 803 | struct group_req greq; |
| 804 | |
| 805 | if (len != sizeof(greq) || |
| 806 | umove(tcp, addr, &greq) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 807 | printaddr(addr); |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | |
Dmitry V. Levin | 1019f00 | 2015-11-21 02:38:59 +0000 | [diff] [blame] | 811 | tprintf("{gr_interface=%u, gr_group=", greq.gr_interface); |
Dmitry V. Levin | 3bf9c19 | 2016-06-21 16:45:40 +0000 | [diff] [blame] | 812 | print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group)); |
Dmitry V. Levin | 1019f00 | 2015-11-21 02:38:59 +0000 | [diff] [blame] | 813 | tprintf("}"); |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 814 | |
| 815 | } |
| 816 | #endif /* MCAST_JOIN_GROUP */ |
| 817 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 818 | #ifdef PACKET_RX_RING |
| 819 | static void |
| 820 | print_tpacket_req(struct tcb *tcp, long addr, int len) |
| 821 | { |
| 822 | struct tpacket_req req; |
| 823 | |
| 824 | if (len != sizeof(req) || |
| 825 | umove(tcp, addr, &req) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 826 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 827 | } else { |
| 828 | tprintf("{block_size=%u, block_nr=%u, " |
| 829 | "frame_size=%u, frame_nr=%u}", |
| 830 | req.tp_block_size, |
| 831 | req.tp_block_nr, |
| 832 | req.tp_frame_size, |
| 833 | req.tp_frame_nr); |
| 834 | } |
| 835 | } |
| 836 | #endif /* PACKET_RX_RING */ |
| 837 | |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 838 | #ifdef PACKET_ADD_MEMBERSHIP |
| 839 | # include "xlat/packet_mreq_type.h" |
| 840 | |
| 841 | static void |
| 842 | print_packet_mreq(struct tcb *tcp, long addr, int len) |
| 843 | { |
| 844 | struct packet_mreq mreq; |
| 845 | |
| 846 | if (len != sizeof(mreq) || |
| 847 | umove(tcp, addr, &mreq) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 848 | printaddr(addr); |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 849 | } else { |
| 850 | unsigned int i; |
| 851 | |
| 852 | tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex); |
| 853 | printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???"); |
| 854 | tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen); |
| 855 | if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address)) |
| 856 | mreq.mr_alen = ARRAY_SIZE(mreq.mr_address); |
| 857 | for (i = 0; i < mreq.mr_alen; ++i) |
| 858 | tprintf("%02x", mreq.mr_address[i]); |
| 859 | tprints("}"); |
| 860 | } |
| 861 | } |
| 862 | #endif /* PACKET_ADD_MEMBERSHIP */ |
| 863 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 864 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 865 | print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name, |
| 866 | long addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 867 | { |
| 868 | if (addr && verbose(tcp)) |
| 869 | switch (level) { |
| 870 | case SOL_SOCKET: |
| 871 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 872 | case SO_LINGER: |
| 873 | print_linger(tcp, addr, len); |
| 874 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 875 | } |
| 876 | break; |
| 877 | |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 878 | case SOL_IP: |
| 879 | switch (name) { |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 880 | #ifdef IP_ADD_MEMBERSHIP |
| 881 | case IP_ADD_MEMBERSHIP: |
| 882 | case IP_DROP_MEMBERSHIP: |
| 883 | print_mreq(tcp, addr, len); |
| 884 | goto done; |
| 885 | #endif /* IP_ADD_MEMBERSHIP */ |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 886 | #ifdef MCAST_JOIN_GROUP |
| 887 | case MCAST_JOIN_GROUP: |
| 888 | case MCAST_LEAVE_GROUP: |
| 889 | print_group_req(tcp, addr, len); |
| 890 | goto done; |
| 891 | #endif /* MCAST_JOIN_GROUP */ |
| 892 | } |
Dmitry V. Levin | 3910d0f | 2015-02-08 01:19:06 +0000 | [diff] [blame] | 893 | break; |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 894 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 895 | case SOL_IPV6: |
| 896 | switch (name) { |
| 897 | #ifdef IPV6_ADD_MEMBERSHIP |
| 898 | case IPV6_ADD_MEMBERSHIP: |
| 899 | case IPV6_DROP_MEMBERSHIP: |
| 900 | # ifdef IPV6_JOIN_ANYCAST |
| 901 | case IPV6_JOIN_ANYCAST: |
| 902 | # endif |
| 903 | # ifdef IPV6_LEAVE_ANYCAST |
| 904 | case IPV6_LEAVE_ANYCAST: |
| 905 | # endif |
| 906 | print_mreq6(tcp, addr, len); |
| 907 | goto done; |
| 908 | #endif /* IPV6_ADD_MEMBERSHIP */ |
| 909 | } |
| 910 | break; |
| 911 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 912 | case SOL_PACKET: |
| 913 | switch (name) { |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 914 | #ifdef PACKET_RX_RING |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 915 | case PACKET_RX_RING: |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 916 | # ifdef PACKET_TX_RING |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 917 | case PACKET_TX_RING: |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 918 | # endif |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 919 | print_tpacket_req(tcp, addr, len); |
| 920 | goto done; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 921 | #endif /* PACKET_RX_RING */ |
| 922 | #ifdef PACKET_ADD_MEMBERSHIP |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 923 | case PACKET_ADD_MEMBERSHIP: |
| 924 | case PACKET_DROP_MEMBERSHIP: |
| 925 | print_packet_mreq(tcp, addr, len); |
| 926 | goto done; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 927 | #endif /* PACKET_ADD_MEMBERSHIP */ |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 928 | } |
| 929 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 930 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 931 | case SOL_RAW: |
| 932 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 933 | case ICMP_FILTER: |
| 934 | print_icmp_filter(tcp, addr, len); |
| 935 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 936 | } |
| 937 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* default arg printing */ |
| 941 | |
| 942 | if (verbose(tcp)) { |
| 943 | if (len == sizeof(int)) { |
| 944 | printnum_int(tcp, addr, "%d"); |
| 945 | } else { |
| 946 | printstr(tcp, addr, len); |
| 947 | } |
| 948 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 949 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 950 | } |
| 951 | done: |
| 952 | tprintf(", %d", len); |
| 953 | } |
| 954 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 955 | SYS_FUNC(setsockopt) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 956 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 957 | print_sockopt_fd_level_name(tcp, tcp->u_arg[0], |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 958 | tcp->u_arg[1], tcp->u_arg[2], false); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 959 | print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 960 | tcp->u_arg[3], tcp->u_arg[4]); |
| 961 | |
| 962 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 963 | } |