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> |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 6 | * Copyright (c) 1999-2018 The strace developers. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 7 | * All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. The name of the author may not be used to endorse or promote products |
| 18 | * derived from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include "defs.h" |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 33 | #include "print_fields.h" |
| 34 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | #include <sys/stat.h> |
| 36 | #include <sys/socket.h> |
Dmitry V. Levin | b2fa2be | 2014-11-21 20:46:16 +0000 | [diff] [blame] | 37 | #include <sys/uio.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 38 | #include <sys/un.h> |
| 39 | #include <netinet/in.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 40 | #ifdef HAVE_NETINET_TCP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 41 | # include <netinet/tcp.h> |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 42 | #endif |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 43 | #ifdef HAVE_NETINET_UDP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 44 | # include <netinet/udp.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 45 | #endif |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 46 | #ifdef HAVE_NETINET_SCTP_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 47 | # include <netinet/sctp.h> |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 48 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 49 | #include <arpa/inet.h> |
Wichert Akkerman | f185065 | 2001-02-16 20:29:03 +0000 | [diff] [blame] | 50 | #include <net/if.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 51 | #include <asm/types.h> |
Dmitry V. Levin | ebda41a | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 52 | #ifdef HAVE_NETIPX_IPX_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 53 | # include <netipx/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 |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 59 | #include "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 | |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 85 | #define XLAT_MACROS_ONLY |
| 86 | # include "xlat/addrfams.h" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 87 | # include "xlat/ethernet_protocols.h" |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 88 | #undef XLAT_MACROS_ONLY |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 89 | #include "xlat/ax25_protocols.h" |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 90 | #include "xlat/irda_protocols.h" |
| 91 | #include "xlat/can_protocols.h" |
| 92 | #include "xlat/bt_protocols.h" |
| 93 | #include "xlat/isdn_protocols.h" |
| 94 | #include "xlat/phonet_protocols.h" |
| 95 | #include "xlat/caif_protocols.h" |
| 96 | #include "xlat/nfc_protocols.h" |
| 97 | #include "xlat/kcm_protocols.h" |
| 98 | #include "xlat/smc_protocols.h" |
| 99 | |
| 100 | const size_t inet_protocols_size = ARRAY_SIZE(inet_protocols) - 1; |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 101 | |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 102 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 103 | decode_sockbuf(struct tcb *const tcp, const int fd, const kernel_ulong_t addr, |
| 104 | const kernel_ulong_t addrlen) |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 105 | { |
| 106 | |
| 107 | switch (verbose(tcp) ? getfdproto(tcp, fd) : SOCK_PROTO_UNKNOWN) { |
| 108 | case SOCK_PROTO_NETLINK: |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 109 | decode_netlink(tcp, fd, addr, addrlen); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 110 | break; |
| 111 | default: |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 112 | printstrn(tcp, addr, addrlen); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 116 | /* |
| 117 | * low bits of the socket type define real socket type, |
| 118 | * other bits are socket type flags. |
| 119 | */ |
| 120 | static void |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 121 | tprint_sock_type(unsigned int flags) |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 122 | { |
| 123 | const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK); |
| 124 | |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 125 | if (str) { |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 126 | print_xlat_ex(flags & SOCK_TYPE_MASK, str, XLAT_STYLE_DEFAULT); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 127 | flags &= ~SOCK_TYPE_MASK; |
| 128 | if (!flags) |
| 129 | return; |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 130 | tprints("|"); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 131 | } |
| 132 | printflags(sock_type_flags, flags, "SOCK_???"); |
| 133 | } |
| 134 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 135 | SYS_FUNC(socket) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 136 | { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 137 | printxval(addrfams, tcp->u_arg[0], "AF_???"); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 138 | tprints(", "); |
| 139 | tprint_sock_type(tcp->u_arg[1]); |
| 140 | tprints(", "); |
| 141 | switch (tcp->u_arg[0]) { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 142 | case AF_INET: |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 143 | case AF_INET6: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 144 | printxval_search(inet_protocols, tcp->u_arg[2], "IPPROTO_???"); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 145 | break; |
Dmitry V. Levin | eb1c22b | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 146 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 147 | case AF_AX25: |
| 148 | /* Those are not available in public headers. */ |
| 149 | printxval_searchn_ex(ARRSZ_PAIR(ax25_protocols), tcp->u_arg[2], |
| 150 | "AX25_P_???", XLAT_STYLE_VERBOSE); |
| 151 | break; |
| 152 | |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 153 | case AF_NETLINK: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 154 | printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???"); |
| 155 | break; |
Dmitry V. Levin | bc4102e | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 156 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 157 | case AF_PACKET: |
| 158 | tprints("htons("); |
| 159 | printxval_searchn(ethernet_protocols, ethernet_protocols_size, |
| 160 | ntohs(tcp->u_arg[2]), "ETH_P_???"); |
| 161 | tprints(")"); |
| 162 | break; |
| 163 | |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 164 | case AF_IRDA: |
| 165 | printxval_index(can_protocols, tcp->u_arg[2], "IRDAPROTO_???"); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 166 | break; |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 167 | |
| 168 | case AF_CAN: |
| 169 | printxval_index(can_protocols, tcp->u_arg[2], "CAN_???"); |
| 170 | break; |
| 171 | |
| 172 | case AF_BLUETOOTH: |
| 173 | printxval_index(bt_protocols, tcp->u_arg[2], "BTPROTO_???"); |
| 174 | break; |
| 175 | |
| 176 | case AF_RXRPC: |
| 177 | printxval(addrfams, tcp->u_arg[2], "AF_???"); |
| 178 | break; |
| 179 | |
| 180 | case AF_ISDN: |
| 181 | printxval(isdn_protocols, tcp->u_arg[2], "ISDN_P_???"); |
| 182 | break; |
| 183 | |
| 184 | case AF_PHONET: |
| 185 | printxval_index(phonet_protocols, tcp->u_arg[2], "PN_PROTO_???"); |
| 186 | break; |
| 187 | |
| 188 | case AF_CAIF: |
| 189 | printxval_index(caif_protocols, tcp->u_arg[2], "CAIFPROTO_???"); |
| 190 | break; |
| 191 | |
| 192 | case AF_NFC: |
| 193 | printxval_index(nfc_protocols, tcp->u_arg[2], |
| 194 | "NFC_SOCKPROTO_???"); |
| 195 | break; |
| 196 | |
| 197 | case AF_KCM: |
| 198 | printxval_index(kcm_protocols, tcp->u_arg[2], "KCMPROTO_???"); |
| 199 | break; |
| 200 | |
| 201 | case AF_SMC: |
| 202 | printxval_index(smc_protocols, tcp->u_arg[2], "SMCPROTO_???"); |
| 203 | break; |
Dmitry V. Levin | bc4102e | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 204 | |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 205 | default: |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 206 | tprintf("%" PRI_klu, tcp->u_arg[2]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 207 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 208 | } |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 209 | |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 210 | return RVAL_DECODED | RVAL_FD; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 213 | static bool |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 214 | fetch_socklen(struct tcb *const tcp, int *const plen, |
| 215 | const kernel_ulong_t sockaddr, const kernel_ulong_t socklen) |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 216 | { |
| 217 | return verbose(tcp) && sockaddr && socklen |
| 218 | && umove(tcp, socklen, plen) == 0; |
| 219 | } |
| 220 | |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 221 | static int |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 222 | decode_sockname(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 223 | { |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 224 | int ulen, rlen; |
| 225 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 226 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 227 | printfd(tcp, tcp->u_arg[0]); |
| 228 | tprints(", "); |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 229 | if (fetch_socklen(tcp, &ulen, tcp->u_arg[1], tcp->u_arg[2])) { |
Dmitry V. Levin | b759d27 | 2016-07-15 16:08:19 +0000 | [diff] [blame] | 230 | set_tcb_priv_ulong(tcp, ulen); |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 231 | return 0; |
| 232 | } else { |
| 233 | printaddr(tcp->u_arg[1]); |
| 234 | tprints(", "); |
| 235 | printaddr(tcp->u_arg[2]); |
| 236 | return RVAL_DECODED; |
| 237 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 238 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 239 | |
Dmitry V. Levin | b759d27 | 2016-07-15 16:08:19 +0000 | [diff] [blame] | 240 | ulen = get_tcb_priv_ulong(tcp); |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 241 | |
| 242 | if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &rlen) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 243 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 244 | tprintf(", [%d]", ulen); |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 245 | } else { |
Dmitry V. Levin | d07eac3 | 2016-07-09 21:52:43 +0000 | [diff] [blame] | 246 | decode_sockaddr(tcp, tcp->u_arg[1], ulen > rlen ? rlen : ulen); |
Dmitry V. Levin | eca8b5b | 2016-07-09 21:52:58 +0000 | [diff] [blame] | 247 | if (ulen != rlen) |
Dmitry V. Levin | 36df822 | 2016-07-09 21:52:51 +0000 | [diff] [blame] | 248 | tprintf(", [%d->%d]", ulen, rlen); |
| 249 | else |
| 250 | tprintf(", [%d]", rlen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 251 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 252 | |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 253 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 256 | SYS_FUNC(accept) |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 257 | { |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 258 | return decode_sockname(tcp) | RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 261 | SYS_FUNC(accept4) |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 262 | { |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 263 | int rc = decode_sockname(tcp); |
| 264 | |
| 265 | if (rc & RVAL_DECODED) { |
| 266 | tprints(", "); |
| 267 | printflags(sock_type_flags, tcp->u_arg[3], "SOCK_???"); |
| 268 | } |
| 269 | |
| 270 | return rc | RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 271 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 272 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 273 | SYS_FUNC(send) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 274 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 275 | printfd(tcp, tcp->u_arg[0]); |
| 276 | tprints(", "); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 277 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 278 | tprintf(", %" PRI_klu ", ", tcp->u_arg[2]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 279 | /* flags */ |
| 280 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 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(sendto) |
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(", "); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 289 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 290 | tprintf(", %" PRI_klu ", ", tcp->u_arg[2]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 291 | /* flags */ |
| 292 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 293 | /* to address */ |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 294 | const int addrlen = tcp->u_arg[5]; |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 295 | tprints(", "); |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 296 | decode_sockaddr(tcp, tcp->u_arg[4], addrlen); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 297 | /* to length */ |
Dmitry V. Levin | 7acde9e | 2016-07-12 09:17:30 +0000 | [diff] [blame] | 298 | tprintf(", %d", addrlen); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 299 | |
| 300 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 303 | SYS_FUNC(recv) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 304 | { |
| 305 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 306 | printfd(tcp, tcp->u_arg[0]); |
| 307 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 308 | } else { |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 309 | if (syserror(tcp)) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 310 | printaddr(tcp->u_arg[1]); |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 311 | } else { |
| 312 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], |
| 313 | tcp->u_rval); |
| 314 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 315 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 316 | tprintf(", %" PRI_klu ", ", tcp->u_arg[2]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 317 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 322 | SYS_FUNC(recvfrom) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | { |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 324 | int ulen, rlen; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 325 | |
| 326 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 327 | printfd(tcp, tcp->u_arg[0]); |
| 328 | tprints(", "); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 329 | if (fetch_socklen(tcp, &ulen, tcp->u_arg[4], tcp->u_arg[5])) { |
Dmitry V. Levin | b759d27 | 2016-07-15 16:08:19 +0000 | [diff] [blame] | 330 | set_tcb_priv_ulong(tcp, ulen); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 331 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 332 | } else { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | /* buf */ |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 334 | if (syserror(tcp)) { |
Dmitry V. Levin | 52dc150 | 2015-07-30 13:53:42 +0000 | [diff] [blame] | 335 | printaddr(tcp->u_arg[1]); |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 336 | } else { |
Fabien Siron | 2850f74 | 2016-07-06 15:49:22 +0000 | [diff] [blame] | 337 | decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], |
| 338 | tcp->u_rval); |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 339 | } |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 340 | /* size */ |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 341 | tprintf(", %" PRI_klu ", ", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 342 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 343 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 344 | tprints(", "); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 345 | |
Dmitry V. Levin | b759d27 | 2016-07-15 16:08:19 +0000 | [diff] [blame] | 346 | ulen = get_tcb_priv_ulong(tcp); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 347 | |
| 348 | if (!fetch_socklen(tcp, &rlen, tcp->u_arg[4], tcp->u_arg[5])) { |
| 349 | /* from address */ |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 350 | printaddr(tcp->u_arg[4]); |
| 351 | tprints(", "); |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 352 | /* from length */ |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 353 | printaddr(tcp->u_arg[5]); |
| 354 | return 0; |
| 355 | } |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 356 | if (syserror(tcp)) { |
| 357 | /* from address */ |
| 358 | printaddr(tcp->u_arg[4]); |
| 359 | /* from length */ |
| 360 | tprintf(", [%d]", ulen); |
| 361 | return 0; |
| 362 | } |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 363 | /* from address */ |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 364 | decode_sockaddr(tcp, tcp->u_arg[4], ulen > rlen ? rlen : ulen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 365 | /* from length */ |
Dmitry V. Levin | 802f264 | 2016-07-12 07:46:19 +0000 | [diff] [blame] | 366 | if (ulen != rlen) |
| 367 | tprintf(", [%d->%d]", ulen, rlen); |
| 368 | else |
| 369 | tprintf(", [%d]", rlen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 374 | SYS_FUNC(getsockname) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 375 | { |
Dmitry V. Levin | d1cedf0 | 2016-07-09 21:52:34 +0000 | [diff] [blame] | 376 | return decode_sockname(tcp); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 379 | static void |
| 380 | printpair_fd(struct tcb *tcp, const int i0, const int i1) |
| 381 | { |
| 382 | tprints("["); |
| 383 | printfd(tcp, i0); |
| 384 | tprints(", "); |
| 385 | printfd(tcp, i1); |
| 386 | tprints("]"); |
| 387 | } |
| 388 | |
| 389 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 390 | decode_pair_fd(struct tcb *const tcp, const kernel_ulong_t addr) |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 391 | { |
| 392 | int pair[2]; |
| 393 | |
| 394 | if (umove_or_printaddr(tcp, addr, &pair)) |
| 395 | return; |
| 396 | |
| 397 | printpair_fd(tcp, pair[0], pair[1]); |
| 398 | } |
| 399 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 400 | static int |
| 401 | do_pipe(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 402 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 403 | if (exiting(tcp)) { |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 404 | decode_pair_fd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 405 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 406 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 407 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 408 | } |
| 409 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 410 | return 0; |
| 411 | } |
| 412 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 413 | SYS_FUNC(pipe) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 414 | { |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 415 | #if HAVE_ARCH_GETRVAL2 |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 416 | if (exiting(tcp) && !syserror(tcp)) |
| 417 | printpair_fd(tcp, tcp->u_rval, getrval2(tcp)); |
| 418 | return 0; |
| 419 | #else |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 420 | return do_pipe(tcp, -1); |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 421 | #endif |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 424 | SYS_FUNC(pipe2) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 425 | { |
| 426 | return do_pipe(tcp, 1); |
| 427 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 428 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 429 | SYS_FUNC(socketpair) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 430 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 431 | if (entering(tcp)) { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 432 | printxval(addrfams, tcp->u_arg[0], "AF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 433 | tprints(", "); |
Dmitry V. Levin | 1e42f2d | 2014-09-10 17:48:28 +0000 | [diff] [blame] | 434 | tprint_sock_type(tcp->u_arg[1]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 435 | tprintf(", %" PRI_klu, tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 436 | } else { |
Dmitry V. Levin | b679508 | 2015-07-06 22:33:39 +0000 | [diff] [blame] | 437 | tprints(", "); |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 438 | decode_pair_fd(tcp, tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 439 | } |
| 440 | return 0; |
| 441 | } |
| 442 | |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 443 | #include "xlat/sock_options.h" |
| 444 | #include "xlat/getsock_options.h" |
| 445 | #include "xlat/setsock_options.h" |
| 446 | #include "xlat/sock_ip_options.h" |
| 447 | #include "xlat/getsock_ip_options.h" |
| 448 | #include "xlat/setsock_ip_options.h" |
| 449 | #include "xlat/sock_ipv6_options.h" |
| 450 | #include "xlat/getsock_ipv6_options.h" |
| 451 | #include "xlat/setsock_ipv6_options.h" |
| 452 | #include "xlat/sock_ipx_options.h" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 453 | #include "xlat/sock_ax25_options.h" |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 454 | #include "xlat/sock_netlink_options.h" |
| 455 | #include "xlat/sock_packet_options.h" |
| 456 | #include "xlat/sock_raw_options.h" |
| 457 | #include "xlat/sock_sctp_options.h" |
| 458 | #include "xlat/sock_tcp_options.h" |
| 459 | #include "xlat/sock_udp_options.h" |
| 460 | #include "xlat/sock_irda_options.h" |
| 461 | #include "xlat/sock_llc_options.h" |
| 462 | #include "xlat/sock_dccp_options.h" |
| 463 | #include "xlat/sock_tipc_options.h" |
| 464 | #include "xlat/sock_rxrpc_options.h" |
| 465 | #include "xlat/sock_pppol2tp_options.h" |
| 466 | #include "xlat/sock_bluetooth_options.h" |
| 467 | #include "xlat/sock_pnp_options.h" |
| 468 | #include "xlat/sock_rds_options.h" |
| 469 | #include "xlat/sock_iucv_options.h" |
| 470 | #include "xlat/sock_caif_options.h" |
| 471 | #include "xlat/sock_alg_options.h" |
| 472 | #include "xlat/sock_nfcllcp_options.h" |
| 473 | #include "xlat/sock_kcm_options.h" |
| 474 | #include "xlat/sock_tls_options.h" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 475 | #include "xlat/sock_xdp_options.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 476 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 477 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 478 | print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level, |
| 479 | unsigned int name, bool is_getsockopt) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 480 | { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 481 | printfd(tcp, fd); |
| 482 | tprints(", "); |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 483 | printxval_search(socketlayers, level, "SOL_??"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 484 | tprints(", "); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 485 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 486 | switch (level) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 487 | case SOL_SOCKET: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 488 | printxvals(name, "SO_???", sock_options, |
| 489 | is_getsockopt ? getsock_options : |
| 490 | setsock_options, NULL); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 491 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 492 | case SOL_IP: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 493 | printxvals(name, "IP_???", sock_ip_options, |
| 494 | is_getsockopt ? getsock_ip_options : |
| 495 | setsock_ip_options, NULL); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 496 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 497 | case SOL_IPV6: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 498 | printxvals(name, "IPV6_???", sock_ipv6_options, |
| 499 | is_getsockopt ? getsock_ipv6_options : |
| 500 | setsock_ipv6_options, NULL); |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 501 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 502 | case SOL_IPX: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 503 | printxval(sock_ipx_options, name, "IPX_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 504 | break; |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 505 | case SOL_AX25: |
| 506 | printxval_search(sock_ax25_options, name, "AX25_???"); |
| 507 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 508 | case SOL_PACKET: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 509 | printxval(sock_packet_options, name, "PACKET_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 510 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 511 | case SOL_TCP: |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 512 | printxval_index(sock_tcp_options, name, "TCP_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 513 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 514 | case SOL_SCTP: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 515 | printxval(sock_sctp_options, name, "SCTP_???"); |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 516 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 517 | case SOL_RAW: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 518 | printxval(sock_raw_options, name, "RAW_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 519 | break; |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 520 | case SOL_NETLINK: |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 521 | printxval(sock_netlink_options, name, "NETLINK_???"); |
| 522 | break; |
| 523 | case SOL_UDP: |
| 524 | printxval(sock_udp_options, name, "UDP_???"); |
| 525 | break; |
| 526 | case SOL_IRDA: |
| 527 | printxval_index(sock_irda_options, name, "IRLMP_???"); |
| 528 | break; |
| 529 | case SOL_LLC: |
| 530 | printxval_index(sock_llc_options, name, "LLC_OPT_???"); |
| 531 | break; |
| 532 | case SOL_DCCP: |
| 533 | printxval_search(sock_dccp_options, name, "DCCP_SOCKOPT_???"); |
| 534 | break; |
| 535 | case SOL_TIPC: |
| 536 | printxval_search(sock_tipc_options, name, "TIPC_???"); |
| 537 | break; |
| 538 | case SOL_RXRPC: |
| 539 | printxval_index(sock_rxrpc_options, name, "RXRPC_???"); |
| 540 | break; |
| 541 | case SOL_PPPOL2TP: |
| 542 | printxval_index(sock_pppol2tp_options, name, "PPPOL2TP_SO_???"); |
| 543 | break; |
| 544 | case SOL_BLUETOOTH: |
| 545 | printxval_search(sock_bluetooth_options, name, "BT_???"); |
| 546 | break; |
| 547 | case SOL_PNPIPE: |
| 548 | printxval(sock_pnp_options, name, "PNPIPE_???"); |
| 549 | break; |
| 550 | case SOL_RDS: |
| 551 | printxval_search(sock_rds_options, name, "RDS_???"); |
| 552 | break; |
| 553 | case SOL_IUCV: |
| 554 | printxval(sock_iucv_options, name, "SO_???"); |
| 555 | break; |
| 556 | case SOL_CAIF: |
| 557 | printxval(sock_caif_options, name, "CAIFSO_???"); |
| 558 | break; |
| 559 | case SOL_ALG: |
| 560 | printxval_index(sock_alg_options, name, "ALG_???"); |
| 561 | break; |
| 562 | case SOL_NFC: |
| 563 | printxval_index(sock_nfcllcp_options, name, "NFC_LLCP_???"); |
| 564 | break; |
| 565 | case SOL_KCM: |
| 566 | printxval(sock_kcm_options, name, "KCM_???"); |
| 567 | break; |
| 568 | case SOL_TLS: |
| 569 | printxval(sock_tls_options, name, "TLS_???"); |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 570 | break; |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 571 | case SOL_XDP: |
| 572 | printxval_index(sock_xdp_options, name, "XDP_???"); |
| 573 | break; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 574 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 575 | /* Other SOL_* protocol levels still need work. */ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 576 | |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 577 | default: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 578 | tprintf("%u", name); |
| 579 | } |
| 580 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 581 | tprints(", "); |
| 582 | } |
| 583 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 584 | static void |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 585 | print_get_linger(struct tcb *const tcp, const kernel_ulong_t addr, |
| 586 | unsigned int len) |
| 587 | { |
| 588 | struct linger linger; |
| 589 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 590 | /* |
| 591 | * The kernel cannot return len > sizeof(linger) because struct linger |
| 592 | * cannot change, but extra safety won't harm either. |
| 593 | */ |
| 594 | if (len > sizeof(linger)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 595 | len = sizeof(linger); |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 596 | if (umoven_or_printaddr(tcp, addr, len, &linger)) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 597 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 598 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 599 | if (len < sizeof(linger.l_onoff)) { |
| 600 | tprints("{l_onoff="); |
| 601 | print_quoted_string((void *) &linger.l_onoff, |
| 602 | len, QUOTE_FORCE_HEX); |
| 603 | } else { |
| 604 | PRINT_FIELD_D("{", linger, l_onoff); |
| 605 | |
| 606 | if (len > offsetof(struct linger, l_linger)) { |
| 607 | len -= offsetof(struct linger, l_linger); |
| 608 | if (len < sizeof(linger.l_linger)) { |
| 609 | tprints(", l_linger="); |
| 610 | print_quoted_string((void *) &linger.l_linger, |
| 611 | len, QUOTE_FORCE_HEX); |
| 612 | } else { |
| 613 | PRINT_FIELD_D(", ", linger, l_linger); |
| 614 | } |
| 615 | } |
| 616 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 617 | tprints("}"); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 618 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 619 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 620 | static void |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 621 | print_get_ucred(struct tcb *const tcp, const kernel_ulong_t addr, |
| 622 | unsigned int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 623 | { |
| 624 | struct ucred uc; |
| 625 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 626 | /* |
| 627 | * The kernel is very unlikely to return len > sizeof(uc) |
| 628 | * because struct ucred is very unlikely to change, |
| 629 | * but extra safety won't harm either. |
| 630 | */ |
| 631 | if (len > sizeof(uc)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 632 | len = sizeof(uc); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 633 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 634 | if (umoven_or_printaddr(tcp, addr, len, &uc)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 635 | return; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 636 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 637 | if (len < sizeof(uc.pid)) { |
| 638 | tprints("{pid="); |
| 639 | print_quoted_string((void *) &uc.pid, |
| 640 | len, QUOTE_FORCE_HEX); |
| 641 | } else { |
| 642 | PRINT_FIELD_D("{", uc, pid); |
| 643 | |
| 644 | if (len > offsetof(struct ucred, uid)) { |
| 645 | len -= offsetof(struct ucred, uid); |
| 646 | if (len < sizeof(uc.uid)) { |
| 647 | tprints(", uid="); |
| 648 | print_quoted_string((void *) &uc.uid, |
| 649 | len, QUOTE_FORCE_HEX); |
| 650 | } else { |
| 651 | PRINT_FIELD_UID(", ", uc, uid); |
| 652 | |
| 653 | if (len > offsetof(struct ucred, gid) - |
| 654 | offsetof(struct ucred, uid)) { |
| 655 | len -= offsetof(struct ucred, gid) - |
| 656 | offsetof(struct ucred, uid); |
| 657 | if (len < sizeof(uc.gid)) { |
| 658 | tprints(", gid="); |
| 659 | print_quoted_string((void *) &uc.gid, |
| 660 | len, |
| 661 | QUOTE_FORCE_HEX); |
| 662 | } else { |
| 663 | PRINT_FIELD_UID(", ", uc, gid); |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 669 | tprints("}"); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 670 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 671 | |
| 672 | #ifdef PACKET_STATISTICS |
| 673 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 674 | print_tpacket_stats(struct tcb *const tcp, const kernel_ulong_t addr, |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 675 | unsigned int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 676 | { |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 677 | struct tp_stats { |
| 678 | unsigned int tp_packets, tp_drops, tp_freeze_q_cnt; |
| 679 | } stats; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 680 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 681 | /* |
| 682 | * The kernel may return len > sizeof(stats) if the kernel structure |
| 683 | * grew as it happened when tpacket_stats_v3 was introduced. |
| 684 | */ |
| 685 | if (len > sizeof(stats)) |
| 686 | len = sizeof(stats); |
| 687 | |
| 688 | if (umoven_or_printaddr(tcp, addr, len, &stats)) |
| 689 | return; |
| 690 | |
| 691 | if (len < sizeof(stats.tp_packets)) { |
| 692 | tprints("{tp_packets="); |
| 693 | print_quoted_string((void *) &stats.tp_packets, |
| 694 | len, QUOTE_FORCE_HEX); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 695 | } else { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 696 | PRINT_FIELD_U("{", stats, tp_packets); |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 697 | |
| 698 | if (len > offsetof(struct tp_stats, tp_drops)) { |
| 699 | len -= offsetof(struct tp_stats, tp_drops); |
| 700 | if (len < sizeof(stats.tp_drops)) { |
| 701 | tprints(", tp_drops="); |
| 702 | print_quoted_string((void *) &stats.tp_drops, |
| 703 | len, QUOTE_FORCE_HEX); |
| 704 | } else { |
| 705 | PRINT_FIELD_U(", ", stats, tp_drops); |
| 706 | |
| 707 | if (len > offsetof(struct tp_stats, tp_freeze_q_cnt) - |
| 708 | offsetof(struct tp_stats, tp_drops)) { |
| 709 | len -= offsetof(struct tp_stats, tp_freeze_q_cnt) - |
| 710 | offsetof(struct tp_stats, tp_drops); |
| 711 | if (len < sizeof(stats.tp_freeze_q_cnt)) { |
| 712 | tprints(", tp_freeze_q_cnt="); |
| 713 | print_quoted_string((void *) &stats.tp_freeze_q_cnt, |
| 714 | len, |
| 715 | QUOTE_FORCE_HEX); |
| 716 | } else { |
| 717 | PRINT_FIELD_U(", ", stats, tp_freeze_q_cnt); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 722 | } |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 723 | tprints("}"); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 724 | } |
| 725 | #endif /* PACKET_STATISTICS */ |
| 726 | |
Dmitry V. Levin | fba9db2 | 2016-06-15 21:29:07 +0000 | [diff] [blame] | 727 | #include "xlat/icmpfilterflags.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 728 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 729 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 730 | print_icmp_filter(struct tcb *const tcp, const kernel_ulong_t addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 731 | { |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 732 | struct icmp_filter filter = {}; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 733 | |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 734 | if (len > (int) sizeof(filter)) |
| 735 | len = sizeof(filter); |
| 736 | else if (len <= 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 737 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 738 | return; |
| 739 | } |
| 740 | |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 741 | if (umoven_or_printaddr(tcp, addr, len, &filter)) |
| 742 | return; |
| 743 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 744 | tprints("~("); |
| 745 | printflags(icmpfilterflags, ~filter.data, "ICMP_???"); |
| 746 | tprints(")"); |
| 747 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 748 | |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 749 | static bool |
| 750 | print_uint32(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
| 751 | { |
| 752 | tprintf("%u", *(uint32_t *) elem_buf); |
| 753 | |
| 754 | return true; |
| 755 | } |
| 756 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 757 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 758 | print_getsockopt(struct tcb *const tcp, const unsigned int level, |
| 759 | const unsigned int name, const kernel_ulong_t addr, |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 760 | const int ulen, const int rlen) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 761 | { |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 762 | if (ulen <= 0 || rlen <= 0) { |
| 763 | /* |
| 764 | * As the kernel neither accepts nor returns a negative |
| 765 | * length in case of successful getsockopt syscall |
| 766 | * invocation, negative values must have been forged |
| 767 | * by userspace. |
| 768 | */ |
| 769 | printaddr(addr); |
| 770 | return; |
| 771 | } |
| 772 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 773 | if (addr && verbose(tcp)) |
| 774 | switch (level) { |
| 775 | case SOL_SOCKET: |
| 776 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 777 | case SO_LINGER: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 778 | print_get_linger(tcp, addr, rlen); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 779 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 780 | case SO_PEERCRED: |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 781 | print_get_ucred(tcp, addr, rlen); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 782 | return; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 783 | case SO_ATTACH_FILTER: |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 784 | /* |
| 785 | * The length returned by the kernel in case of |
| 786 | * successful getsockopt syscall invocation is struct |
| 787 | * sock_fprog.len that has type unsigned short, |
| 788 | * anything else must have been forged by userspace. |
| 789 | */ |
| 790 | if ((unsigned short) rlen == (unsigned int) rlen) |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 791 | print_sock_fprog(tcp, addr, rlen); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 792 | else |
| 793 | printaddr(addr); |
| 794 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 795 | } |
| 796 | break; |
| 797 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 798 | case SOL_PACKET: |
| 799 | switch (name) { |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 800 | #ifdef PACKET_STATISTICS |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 801 | case PACKET_STATISTICS: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 802 | print_tpacket_stats(tcp, addr, rlen); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 803 | return; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 804 | #endif |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 805 | } |
| 806 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 807 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 808 | case SOL_RAW: |
| 809 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 810 | case ICMP_FILTER: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 811 | print_icmp_filter(tcp, addr, rlen); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 812 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 813 | } |
| 814 | break; |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 815 | |
| 816 | case SOL_NETLINK: |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 817 | switch (name) { |
| 818 | case NETLINK_LIST_MEMBERSHIPS: { |
| 819 | uint32_t buf; |
| 820 | print_array(tcp, addr, MIN(ulen, rlen) / sizeof(buf), |
| 821 | &buf, sizeof(buf), |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 822 | tfetch_mem, print_uint32, 0); |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 823 | break; |
| 824 | } |
| 825 | default: |
| 826 | printnum_int(tcp, addr, "%d"); |
| 827 | break; |
| 828 | } |
| 829 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 830 | } |
| 831 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 832 | /* default arg printing */ |
| 833 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 834 | if (verbose(tcp)) { |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 835 | if (rlen == sizeof(int)) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 836 | printnum_int(tcp, addr, "%d"); |
| 837 | } else { |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 838 | printstrn(tcp, addr, rlen); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 839 | } |
| 840 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 841 | printaddr(addr); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 842 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 845 | SYS_FUNC(getsockopt) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 846 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 847 | int ulen, rlen; |
| 848 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 849 | if (entering(tcp)) { |
| 850 | print_sockopt_fd_level_name(tcp, tcp->u_arg[0], |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 851 | tcp->u_arg[1], tcp->u_arg[2], true); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 852 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 853 | if (verbose(tcp) && tcp->u_arg[4] |
| 854 | && umove(tcp, tcp->u_arg[4], &ulen) == 0) { |
| 855 | set_tcb_priv_ulong(tcp, ulen); |
| 856 | return 0; |
| 857 | } else { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 858 | printaddr(tcp->u_arg[3]); |
| 859 | tprints(", "); |
| 860 | printaddr(tcp->u_arg[4]); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 861 | return RVAL_DECODED; |
| 862 | } |
| 863 | } else { |
| 864 | ulen = get_tcb_priv_ulong(tcp); |
| 865 | |
| 866 | if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &rlen) < 0) { |
| 867 | printaddr(tcp->u_arg[3]); |
| 868 | tprintf(", [%d]", ulen); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 869 | } else { |
| 870 | print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 871 | tcp->u_arg[3], ulen, rlen); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 872 | if (ulen != rlen) |
| 873 | tprintf(", [%d->%d]", ulen, rlen); |
| 874 | else |
| 875 | tprintf(", [%d]", rlen); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 876 | } |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 877 | } |
| 878 | return 0; |
| 879 | } |
| 880 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 881 | static void |
| 882 | print_set_linger(struct tcb *const tcp, const kernel_ulong_t addr, |
| 883 | const int len) |
| 884 | { |
| 885 | struct linger linger; |
| 886 | |
| 887 | if (len < (int) sizeof(linger)) { |
| 888 | printaddr(addr); |
| 889 | } else if (!umove_or_printaddr(tcp, addr, &linger)) { |
| 890 | PRINT_FIELD_D("{", linger, l_onoff); |
| 891 | PRINT_FIELD_D(", ", linger, l_linger); |
| 892 | tprints("}"); |
| 893 | } |
| 894 | } |
| 895 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 896 | #ifdef IP_ADD_MEMBERSHIP |
| 897 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 898 | print_mreq(struct tcb *const tcp, const kernel_ulong_t addr, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 899 | const int len) |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 900 | { |
| 901 | struct ip_mreq mreq; |
| 902 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 903 | if (len < (int) sizeof(mreq)) { |
| 904 | printaddr(addr); |
| 905 | } else if (!umove_or_printaddr(tcp, addr, &mreq)) { |
| 906 | PRINT_FIELD_INET4_ADDR("{", mreq, imr_multiaddr); |
| 907 | PRINT_FIELD_INET4_ADDR(", ", mreq, imr_interface); |
| 908 | tprints("}"); |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 909 | } |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 910 | } |
| 911 | #endif /* IP_ADD_MEMBERSHIP */ |
| 912 | |
| 913 | #ifdef IPV6_ADD_MEMBERSHIP |
| 914 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 915 | print_mreq6(struct tcb *const tcp, const kernel_ulong_t addr, |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 916 | const int len) |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 917 | { |
| 918 | struct ipv6_mreq mreq; |
| 919 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 920 | if (len < (int) sizeof(mreq)) { |
| 921 | printaddr(addr); |
| 922 | } else if (!umove_or_printaddr(tcp, addr, &mreq)) { |
| 923 | PRINT_FIELD_INET_ADDR("{", mreq, ipv6mr_multiaddr, AF_INET6); |
| 924 | PRINT_FIELD_IFINDEX(", ", mreq, ipv6mr_interface); |
| 925 | tprints("}"); |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 926 | } |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 927 | } |
| 928 | #endif /* IPV6_ADD_MEMBERSHIP */ |
| 929 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 930 | #ifdef PACKET_RX_RING |
| 931 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 932 | print_tpacket_req(struct tcb *const tcp, const kernel_ulong_t addr, const int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 933 | { |
| 934 | struct tpacket_req req; |
| 935 | |
| 936 | if (len != sizeof(req) || |
| 937 | umove(tcp, addr, &req) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 938 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 939 | } else { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 940 | PRINT_FIELD_U("{", req, tp_block_size); |
| 941 | PRINT_FIELD_U(", ", req, tp_block_nr); |
| 942 | PRINT_FIELD_U(", ", req, tp_frame_size); |
| 943 | PRINT_FIELD_U(", ", req, tp_frame_nr); |
| 944 | tprints("}"); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | #endif /* PACKET_RX_RING */ |
| 948 | |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 949 | #ifdef PACKET_ADD_MEMBERSHIP |
| 950 | # include "xlat/packet_mreq_type.h" |
| 951 | |
| 952 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 953 | print_packet_mreq(struct tcb *const tcp, const kernel_ulong_t addr, const int len) |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 954 | { |
| 955 | struct packet_mreq mreq; |
| 956 | |
| 957 | if (len != sizeof(mreq) || |
| 958 | umove(tcp, addr, &mreq) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 959 | printaddr(addr); |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 960 | } else { |
| 961 | unsigned int i; |
| 962 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 963 | PRINT_FIELD_IFINDEX("{", mreq, mr_ifindex); |
| 964 | PRINT_FIELD_XVAL(", ", mreq, mr_type, packet_mreq_type, |
| 965 | "PACKET_MR_???"); |
| 966 | PRINT_FIELD_U(", ", mreq, mr_alen); |
| 967 | tprints(", mr_address="); |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 968 | if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address)) |
| 969 | mreq.mr_alen = ARRAY_SIZE(mreq.mr_address); |
| 970 | for (i = 0; i < mreq.mr_alen; ++i) |
| 971 | tprintf("%02x", mreq.mr_address[i]); |
| 972 | tprints("}"); |
| 973 | } |
| 974 | } |
| 975 | #endif /* PACKET_ADD_MEMBERSHIP */ |
| 976 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 977 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 978 | print_setsockopt(struct tcb *const tcp, const unsigned int level, |
| 979 | const unsigned int name, const kernel_ulong_t addr, |
| 980 | const int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 981 | { |
| 982 | if (addr && verbose(tcp)) |
| 983 | switch (level) { |
| 984 | case SOL_SOCKET: |
| 985 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 986 | case SO_LINGER: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 987 | print_set_linger(tcp, addr, len); |
| 988 | return; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 989 | case SO_ATTACH_FILTER: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 990 | case SO_ATTACH_REUSEPORT_CBPF: |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 991 | if ((unsigned int) len == get_sock_fprog_size()) |
| 992 | decode_sock_fprog(tcp, addr); |
| 993 | else |
| 994 | printaddr(addr); |
| 995 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 996 | } |
| 997 | break; |
| 998 | |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 999 | case SOL_IP: |
| 1000 | switch (name) { |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1001 | #ifdef IP_ADD_MEMBERSHIP |
| 1002 | case IP_ADD_MEMBERSHIP: |
| 1003 | case IP_DROP_MEMBERSHIP: |
| 1004 | print_mreq(tcp, addr, len); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1005 | return; |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1006 | #endif /* IP_ADD_MEMBERSHIP */ |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1007 | #ifdef MCAST_JOIN_GROUP |
| 1008 | case MCAST_JOIN_GROUP: |
| 1009 | case MCAST_LEAVE_GROUP: |
| 1010 | print_group_req(tcp, addr, len); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1011 | return; |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1012 | #endif /* MCAST_JOIN_GROUP */ |
| 1013 | } |
Dmitry V. Levin | 3910d0f | 2015-02-08 01:19:06 +0000 | [diff] [blame] | 1014 | break; |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1015 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1016 | case SOL_IPV6: |
| 1017 | switch (name) { |
| 1018 | #ifdef IPV6_ADD_MEMBERSHIP |
| 1019 | case IPV6_ADD_MEMBERSHIP: |
| 1020 | case IPV6_DROP_MEMBERSHIP: |
| 1021 | # ifdef IPV6_JOIN_ANYCAST |
| 1022 | case IPV6_JOIN_ANYCAST: |
| 1023 | # endif |
| 1024 | # ifdef IPV6_LEAVE_ANYCAST |
| 1025 | case IPV6_LEAVE_ANYCAST: |
| 1026 | # endif |
| 1027 | print_mreq6(tcp, addr, len); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1028 | return; |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1029 | #endif /* IPV6_ADD_MEMBERSHIP */ |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1030 | #ifdef MCAST_JOIN_GROUP |
| 1031 | case MCAST_JOIN_GROUP: |
| 1032 | case MCAST_LEAVE_GROUP: |
| 1033 | print_group_req(tcp, addr, len); |
| 1034 | return; |
| 1035 | #endif /* MCAST_JOIN_GROUP */ |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1036 | } |
| 1037 | break; |
| 1038 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1039 | case SOL_PACKET: |
| 1040 | switch (name) { |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1041 | #ifdef PACKET_RX_RING |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1042 | case PACKET_RX_RING: |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1043 | # ifdef PACKET_TX_RING |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1044 | case PACKET_TX_RING: |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1045 | # endif |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1046 | print_tpacket_req(tcp, addr, len); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1047 | return; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1048 | #endif /* PACKET_RX_RING */ |
| 1049 | #ifdef PACKET_ADD_MEMBERSHIP |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 1050 | case PACKET_ADD_MEMBERSHIP: |
| 1051 | case PACKET_DROP_MEMBERSHIP: |
| 1052 | print_packet_mreq(tcp, addr, len); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1053 | return; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1054 | #endif /* PACKET_ADD_MEMBERSHIP */ |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1055 | } |
| 1056 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1057 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1058 | case SOL_RAW: |
| 1059 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1060 | case ICMP_FILTER: |
| 1061 | print_icmp_filter(tcp, addr, len); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1062 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1063 | } |
| 1064 | break; |
Elliott Hughes | b755614 | 2018-02-20 17:03:16 -0800 | [diff] [blame] | 1065 | |
| 1066 | case SOL_NETLINK: |
| 1067 | if (len < (int) sizeof(int)) |
| 1068 | printaddr(addr); |
| 1069 | else |
| 1070 | printnum_int(tcp, addr, "%d"); |
| 1071 | return; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | /* default arg printing */ |
| 1075 | |
| 1076 | if (verbose(tcp)) { |
| 1077 | if (len == sizeof(int)) { |
| 1078 | printnum_int(tcp, addr, "%d"); |
| 1079 | } else { |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 1080 | printstrn(tcp, addr, len); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1081 | } |
| 1082 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1083 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1084 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 1087 | SYS_FUNC(setsockopt) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1088 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 1089 | print_sockopt_fd_level_name(tcp, tcp->u_arg[0], |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 1090 | tcp->u_arg[1], tcp->u_arg[2], false); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 1091 | print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 1092 | tcp->u_arg[3], tcp->u_arg[4]); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 1093 | tprintf(", %d", (int) tcp->u_arg[4]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 1094 | |
| 1095 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1096 | } |