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 | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 95 | #include "xlat/msg_flags.h" |
Wichert Akkerman | 7987cdf | 2000-07-05 16:05:39 +0000 | [diff] [blame] | 96 | |
Dmitry V. Levin | 45ae937 | 2016-06-23 17:38:18 +0000 | [diff] [blame] | 97 | void |
Dmitry V. Levin | ae28093 | 2015-06-05 20:13:21 +0000 | [diff] [blame] | 98 | print_ifindex(unsigned int ifindex) |
| 99 | { |
| 100 | #ifdef HAVE_IF_INDEXTONAME |
| 101 | char buf[IFNAMSIZ + 1]; |
| 102 | |
| 103 | if (if_indextoname(ifindex, buf)) { |
| 104 | tprints("if_nametoindex("); |
| 105 | print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED); |
| 106 | tprints(")"); |
| 107 | return; |
| 108 | } |
| 109 | #endif |
| 110 | tprintf("%u", ifindex); |
| 111 | } |
| 112 | |
Dmitry V. Levin | b36d132 | 2015-11-18 23:18:17 +0000 | [diff] [blame] | 113 | #include "xlat/scmvals.h" |
Dmitry V. Levin | 1f111cf | 2015-11-21 03:03:54 +0300 | [diff] [blame] | 114 | #include "xlat/ip_cmsg_types.h" |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 115 | |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 116 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 117 | struct cmsghdr32 { |
| 118 | uint32_t cmsg_len; |
| 119 | int cmsg_level; |
| 120 | int cmsg_type; |
| 121 | }; |
| 122 | #endif |
| 123 | |
| 124 | typedef union { |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 125 | char *ptr; |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 126 | struct cmsghdr *cmsg; |
| 127 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 128 | struct cmsghdr32 *cmsg32; |
| 129 | #endif |
| 130 | } union_cmsghdr; |
| 131 | |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 132 | static void |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 133 | print_scm_rights(struct tcb *tcp, const void *cmsg_data, |
| 134 | const size_t data_len) |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 135 | { |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 136 | const int *fds = cmsg_data; |
| 137 | const char *end = (const char *) cmsg_data + data_len; |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 138 | bool seen = false; |
| 139 | |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 140 | if (sizeof(*fds) > data_len) |
| 141 | return; |
| 142 | |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 143 | tprints(", ["); |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 144 | while ((const char *) fds < end) { |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 145 | if (seen) |
| 146 | tprints(", "); |
| 147 | else |
| 148 | seen = true; |
| 149 | printfd(tcp, *fds++); |
| 150 | } |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 151 | tprints("]"); |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 154 | static void |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 155 | print_scm_creds(struct tcb *tcp, const void *cmsg_data, |
| 156 | const size_t data_len) |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 157 | { |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 158 | const struct ucred *uc = cmsg_data; |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 159 | |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 160 | if (sizeof(*uc) > data_len) |
| 161 | return; |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 162 | |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 163 | tprintf(", {pid=%u, uid=%u, gid=%u}", |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 164 | (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid); |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 167 | static void |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 168 | print_scm_security(struct tcb *tcp, const void *cmsg_data, |
| 169 | const size_t data_len) |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 170 | { |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 171 | if (!data_len) |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 172 | return; |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 173 | |
Dmitry V. Levin | 513e96e | 2015-01-26 01:17:08 +0000 | [diff] [blame] | 174 | tprints(", "); |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 175 | print_quoted_string(cmsg_data, data_len, 0); |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 176 | } |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 177 | |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 178 | static void |
Dmitry V. Levin | 1f111cf | 2015-11-21 03:03:54 +0300 | [diff] [blame] | 179 | print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data, |
| 180 | const size_t data_len) |
| 181 | { |
| 182 | const struct in_pktinfo *info = cmsg_data; |
| 183 | |
| 184 | if (sizeof(*info) > data_len) |
| 185 | return; |
| 186 | |
| 187 | tprints(", {ipi_ifindex="); |
| 188 | print_ifindex(info->ipi_ifindex); |
| 189 | tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}", |
| 190 | inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr)); |
| 191 | } |
| 192 | |
| 193 | static void |
| 194 | print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data, |
| 195 | const size_t data_len) |
| 196 | { |
| 197 | const unsigned int *ttl = cmsg_data; |
| 198 | |
| 199 | if (sizeof(*ttl) > data_len) |
| 200 | return; |
| 201 | |
| 202 | tprintf(", {ttl=%u}", *ttl); |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data, |
| 207 | const size_t data_len) |
| 208 | { |
| 209 | const uint8_t *tos = cmsg_data; |
| 210 | |
| 211 | if (sizeof(*tos) > data_len) |
| 212 | return; |
| 213 | |
| 214 | tprintf(", {tos=%x}", *tos); |
| 215 | } |
| 216 | |
| 217 | static void |
| 218 | print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data, |
| 219 | const size_t data_len) |
| 220 | { |
| 221 | const uint32_t *csum = cmsg_data; |
| 222 | |
| 223 | if (sizeof(*csum) > data_len) |
| 224 | return; |
| 225 | |
| 226 | tprintf(", {csum=%u}", *csum); |
| 227 | } |
| 228 | |
| 229 | static void |
| 230 | print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data, |
| 231 | const size_t data_len) |
| 232 | { |
Dmitry V. Levin | a17f593 | 2015-11-22 23:07:52 +0000 | [diff] [blame] | 233 | const unsigned char *opts = cmsg_data; |
Dmitry V. Levin | 1f111cf | 2015-11-21 03:03:54 +0300 | [diff] [blame] | 234 | size_t i; |
| 235 | |
| 236 | if (!data_len) |
| 237 | return; |
| 238 | |
| 239 | tprints(", {opts=0x"); |
| 240 | for (i = 0; i < data_len; ++i) |
| 241 | tprintf("%02x", opts[i]); |
| 242 | tprints("}"); |
| 243 | } |
| 244 | |
| 245 | static void |
| 246 | print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data, |
| 247 | const size_t data_len) |
| 248 | { |
| 249 | const struct { |
| 250 | uint32_t ee_errno; |
| 251 | uint8_t ee_origin; |
| 252 | uint8_t ee_type; |
| 253 | uint8_t ee_code; |
| 254 | uint8_t ee_pad; |
| 255 | uint32_t ee_info; |
| 256 | uint32_t ee_data; |
| 257 | struct sockaddr_in offender; |
| 258 | } *err = cmsg_data; |
| 259 | |
| 260 | if (sizeof(*err) > data_len) |
| 261 | return; |
| 262 | |
| 263 | tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u" |
| 264 | ", ee_info=%u, ee_data=%u, offender=", |
| 265 | err->ee_errno, err->ee_origin, err->ee_type, |
| 266 | err->ee_code, err->ee_info, err->ee_data); |
Dmitry V. Levin | 3bf9c19 | 2016-06-21 16:45:40 +0000 | [diff] [blame] | 267 | print_sockaddr(tcp, &err->offender, sizeof(err->offender)); |
Dmitry V. Levin | 1f111cf | 2015-11-21 03:03:54 +0300 | [diff] [blame] | 268 | tprints("}"); |
| 269 | } |
| 270 | |
| 271 | static void |
| 272 | print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data, |
| 273 | const size_t data_len) |
| 274 | { |
| 275 | if (sizeof(struct sockaddr_in) > data_len) |
| 276 | return; |
| 277 | |
| 278 | tprints(", "); |
| 279 | print_sockaddr(tcp, cmsg_data, data_len); |
| 280 | } |
| 281 | |
| 282 | static void |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 283 | print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type, |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 284 | const void *cmsg_data, const size_t data_len) |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 285 | { |
| 286 | switch (cmsg_level) { |
| 287 | case SOL_SOCKET: |
| 288 | printxval(scmvals, cmsg_type, "SCM_???"); |
| 289 | switch (cmsg_type) { |
| 290 | case SCM_RIGHTS: |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 291 | print_scm_rights(tcp, cmsg_data, data_len); |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 292 | break; |
| 293 | case SCM_CREDENTIALS: |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 294 | print_scm_creds(tcp, cmsg_data, data_len); |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 295 | break; |
| 296 | case SCM_SECURITY: |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 297 | print_scm_security(tcp, cmsg_data, data_len); |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 298 | break; |
| 299 | } |
| 300 | break; |
Dmitry V. Levin | 1f111cf | 2015-11-21 03:03:54 +0300 | [diff] [blame] | 301 | case SOL_IP: |
| 302 | printxval(ip_cmsg_types, cmsg_type, "IP_???"); |
| 303 | switch (cmsg_type) { |
| 304 | case IP_PKTINFO: |
| 305 | print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len); |
| 306 | break; |
| 307 | case IP_TTL: |
| 308 | print_cmsg_ip_ttl(tcp, cmsg_data, data_len); |
| 309 | break; |
| 310 | case IP_TOS: |
| 311 | print_cmsg_ip_tos(tcp, cmsg_data, data_len); |
| 312 | break; |
| 313 | case IP_RECVOPTS: |
| 314 | case IP_RETOPTS: |
| 315 | print_cmsg_ip_opts(tcp, cmsg_data, data_len); |
| 316 | break; |
| 317 | case IP_RECVERR: |
| 318 | print_cmsg_ip_recverr(tcp, cmsg_data, data_len); |
| 319 | break; |
| 320 | case IP_ORIGDSTADDR: |
| 321 | print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len); |
| 322 | break; |
| 323 | case IP_CHECKSUM: |
| 324 | print_cmsg_ip_checksum(tcp, cmsg_data, data_len); |
| 325 | break; |
| 326 | case SCM_SECURITY: |
| 327 | print_scm_security(tcp, cmsg_data, data_len); |
| 328 | break; |
| 329 | } |
| 330 | break; |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 331 | default: |
| 332 | tprintf("%u", cmsg_type); |
| 333 | } |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static void |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 337 | decode_msg_control(struct tcb *tcp, unsigned long addr, size_t len) |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 338 | { |
| 339 | const size_t cmsg_size = |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 340 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 341 | (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) : |
| 342 | #endif |
| 343 | sizeof(struct cmsghdr); |
| 344 | |
Dmitry V. Levin | 00ba20a | 2016-06-26 23:57:18 +0000 | [diff] [blame] | 345 | if (!len) |
| 346 | return; |
| 347 | tprints(", msg_control="); |
| 348 | |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 349 | char *buf = len < cmsg_size ? NULL : malloc(len); |
| 350 | if (!buf || umoven(tcp, addr, len, buf) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 351 | printaddr(addr); |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 352 | free(buf); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 356 | union_cmsghdr u = { .ptr = buf }; |
| 357 | |
Dmitry V. Levin | 00ba20a | 2016-06-26 23:57:18 +0000 | [diff] [blame] | 358 | tprints("["); |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 359 | while (len >= cmsg_size) { |
| 360 | size_t cmsg_len = |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 361 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 362 | (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len : |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 363 | #endif |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 364 | u.cmsg->cmsg_len; |
| 365 | int cmsg_level = |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 366 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 367 | (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level : |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 368 | #endif |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 369 | u.cmsg->cmsg_level; |
| 370 | int cmsg_type = |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 371 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 372 | (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type : |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 373 | #endif |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 374 | u.cmsg->cmsg_type; |
Dmitry V. Levin | 05884d8 | 2015-01-24 01:08:57 +0000 | [diff] [blame] | 375 | |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 376 | if (u.ptr != buf) |
| 377 | tprints(", "); |
| 378 | tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len); |
| 379 | printxval(socketlayers, cmsg_level, "SOL_???"); |
| 380 | tprints(", cmsg_type="); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 381 | |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 382 | if (cmsg_len > len) |
| 383 | cmsg_len = len; |
Roland McGrath | 96ad7b8 | 2005-02-02 03:11:32 +0000 | [diff] [blame] | 384 | |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 385 | print_cmsg_type_data(tcp, cmsg_level, cmsg_type, |
Dmitry V. Levin | 1103b4e | 2015-11-21 03:59:09 +0000 | [diff] [blame] | 386 | (const void *) (u.ptr + cmsg_size), |
| 387 | cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0); |
Dmitry V. Levin | f54cb96 | 2015-11-19 00:29:19 +0000 | [diff] [blame] | 388 | tprints("}"); |
| 389 | |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 390 | if (cmsg_len < cmsg_size) { |
| 391 | len -= cmsg_size; |
| 392 | break; |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 393 | } |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 394 | cmsg_len = (cmsg_len + current_wordsize - 1) & |
| 395 | (size_t) ~(current_wordsize - 1); |
| 396 | if (cmsg_len >= len) { |
| 397 | len = 0; |
| 398 | break; |
| 399 | } |
| 400 | u.ptr += cmsg_len; |
| 401 | len -= cmsg_len; |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 402 | } |
Dmitry V. Levin | b85a7f3 | 2015-01-24 15:20:31 +0000 | [diff] [blame] | 403 | if (len) |
| 404 | tprints(", ..."); |
| 405 | tprints("]"); |
| 406 | free(buf); |
Roland McGrath | 5077082 | 2004-10-06 22:11:51 +0000 | [diff] [blame] | 407 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | |
| 409 | static void |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 410 | print_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size) |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 411 | { |
Dmitry V. Levin | 26f90af | 2016-06-26 23:57:39 +0000 | [diff] [blame] | 412 | tprints("{msg_name="); |
Dmitry V. Levin | 42e566a | 2016-06-25 11:31:48 +0000 | [diff] [blame] | 413 | decode_sockaddr(tcp, (long)msg->msg_name, msg->msg_namelen); |
Dmitry V. Levin | 26f90af | 2016-06-26 23:57:39 +0000 | [diff] [blame] | 414 | tprintf(", msg_namelen=%d", msg->msg_namelen); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 415 | |
Dmitry V. Levin | 26f90af | 2016-06-26 23:57:39 +0000 | [diff] [blame] | 416 | tprints(", msg_iov="); |
| 417 | tprint_iov_upto(tcp, (unsigned long) msg->msg_iovlen, |
| 418 | (unsigned long) msg->msg_iov, IOV_DECODE_STR, data_size); |
| 419 | tprintf(", msg_iovlen=%lu", (unsigned long) msg->msg_iovlen); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 420 | |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 421 | decode_msg_control(tcp, (unsigned long) msg->msg_control, |
Dmitry V. Levin | 00ba20a | 2016-06-26 23:57:18 +0000 | [diff] [blame] | 422 | msg->msg_controllen); |
| 423 | tprintf(", msg_controllen=%lu", (unsigned long) msg->msg_controllen); |
| 424 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 425 | tprints(", msg_flags="); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 426 | printflags(msg_flags, msg->msg_flags, "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 427 | tprints("}"); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 431 | decode_msghdr(struct tcb *tcp, long addr, unsigned long data_size) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 432 | { |
| 433 | struct msghdr msg; |
| 434 | |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 435 | if (addr && verbose(tcp) && fetch_struct_msghdr(tcp, addr, &msg)) |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 436 | print_msghdr(tcp, &msg, data_size); |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 437 | else |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 438 | printaddr(addr); |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void |
Dmitry V. Levin | 93c9d1c | 2016-01-20 03:26:37 +0000 | [diff] [blame] | 442 | dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size) |
Masatake YAMATO | 02f9f6b | 2014-10-15 22:11:43 +0900 | [diff] [blame] | 443 | { |
| 444 | struct msghdr msg; |
| 445 | |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 446 | if (fetch_struct_msghdr(tcp, addr, &msg)) |
Dmitry V. Levin | 93c9d1c | 2016-01-20 03:26:37 +0000 | [diff] [blame] | 447 | dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 450 | static int |
| 451 | decode_mmsghdr(struct tcb *tcp, long addr, bool use_msg_len) |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 452 | { |
Masatake YAMATO | caf6a43 | 2014-11-07 01:23:25 +0900 | [diff] [blame] | 453 | struct mmsghdr mmsg; |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 454 | int fetched = fetch_struct_mmsghdr(tcp, addr, &mmsg); |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 455 | |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 456 | if (fetched) { |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 457 | tprints("{"); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 458 | print_msghdr(tcp, &mmsg.msg_hdr, use_msg_len ? mmsg.msg_len : -1UL); |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 459 | tprintf(", %u}", mmsg.msg_len); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 460 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 461 | printaddr(addr); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 462 | } |
| 463 | |
| 464 | return fetched; |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 465 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 466 | |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 467 | static void |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 468 | decode_mmsgvec(struct tcb *tcp, unsigned long addr, unsigned int len, |
| 469 | bool use_msg_len) |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 470 | { |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 471 | if (syserror(tcp)) { |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 472 | printaddr(addr); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 473 | } else { |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 474 | unsigned int i, fetched; |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 475 | |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 476 | tprints("["); |
| 477 | for (i = 0; i < len; ++i, addr += fetched) { |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 478 | if (i) |
| 479 | tprints(", "); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 480 | fetched = decode_mmsghdr(tcp, addr, use_msg_len); |
| 481 | if (!fetched) |
| 482 | break; |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 483 | } |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 484 | tprints("]"); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 485 | } |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 488 | void |
| 489 | dumpiov_in_mmsghdr(struct tcb *tcp, long addr) |
| 490 | { |
| 491 | unsigned int len = tcp->u_rval; |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 492 | unsigned int i, fetched; |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 493 | struct mmsghdr mmsg; |
| 494 | |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 495 | for (i = 0; i < len; ++i, addr += fetched) { |
| 496 | fetched = fetch_struct_mmsghdr(tcp, addr, &mmsg); |
| 497 | if (!fetched) |
| 498 | break; |
| 499 | tprintf(" = %lu buffers in vector %u\n", |
| 500 | (unsigned long)mmsg.msg_hdr.msg_iovlen, i); |
| 501 | dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen, |
| 502 | (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len); |
Masatake YAMATO | a807dce | 2014-11-07 01:23:26 +0900 | [diff] [blame] | 503 | } |
| 504 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 505 | |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 506 | /* |
| 507 | * low bits of the socket type define real socket type, |
| 508 | * other bits are socket type flags. |
| 509 | */ |
| 510 | static void |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 511 | tprint_sock_type(unsigned int flags) |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 512 | { |
| 513 | const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK); |
| 514 | |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 515 | if (str) { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 516 | tprints(str); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 517 | flags &= ~SOCK_TYPE_MASK; |
| 518 | if (!flags) |
| 519 | return; |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 520 | tprints("|"); |
Dmitry V. Levin | 8a550d7 | 2008-11-10 17:21:23 +0000 | [diff] [blame] | 521 | } |
| 522 | printflags(sock_type_flags, flags, "SOCK_???"); |
| 523 | } |
| 524 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 525 | SYS_FUNC(socket) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 526 | { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 527 | printxval(addrfams, tcp->u_arg[0], "AF_???"); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 528 | tprints(", "); |
| 529 | tprint_sock_type(tcp->u_arg[1]); |
| 530 | tprints(", "); |
| 531 | switch (tcp->u_arg[0]) { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 532 | case AF_INET: |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 533 | case AF_INET6: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 534 | printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???"); |
| 535 | break; |
Dmitry V. Levin | eb1c22b | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 536 | |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 537 | case AF_NETLINK: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 538 | printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???"); |
| 539 | break; |
Dmitry V. Levin | bc4102e | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 540 | |
Dmitry V. Levin | 43369fc | 2016-06-21 16:43:30 +0000 | [diff] [blame] | 541 | #ifdef HAVE_BLUETOOTH_BLUETOOTH_H |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 542 | case AF_BLUETOOTH: |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 543 | printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???"); |
| 544 | break; |
Lubomir Rintel | c400a1c | 2014-10-03 11:40:28 +0200 | [diff] [blame] | 545 | #endif |
Dmitry V. Levin | bc4102e | 2016-06-19 22:02:45 +0000 | [diff] [blame] | 546 | |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 547 | default: |
| 548 | tprintf("%lu", tcp->u_arg[2]); |
| 549 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 550 | } |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 551 | |
Dmitry V. Levin | 3d463be | 2015-08-02 01:41:26 +0000 | [diff] [blame] | 552 | return RVAL_DECODED | RVAL_FD; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 555 | SYS_FUNC(bind) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 556 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 557 | printfd(tcp, tcp->u_arg[0]); |
| 558 | tprints(", "); |
Dmitry V. Levin | 42e566a | 2016-06-25 11:31:48 +0000 | [diff] [blame] | 559 | decode_sockaddr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 560 | tprintf(", %lu", tcp->u_arg[2]); |
| 561 | |
| 562 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 565 | SYS_FUNC(listen) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 566 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 567 | printfd(tcp, tcp->u_arg[0]); |
| 568 | tprints(", "); |
| 569 | tprintf("%lu", tcp->u_arg[1]); |
| 570 | |
| 571 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 574 | static int |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 575 | do_sockname(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 576 | { |
| 577 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 578 | printfd(tcp, tcp->u_arg[0]); |
| 579 | tprints(", "); |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 580 | return 0; |
| 581 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 582 | |
| 583 | int len; |
| 584 | if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) || |
| 585 | umove(tcp, tcp->u_arg[2], &len) < 0) { |
| 586 | printaddr(tcp->u_arg[1]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 587 | tprints(", "); |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 588 | printaddr(tcp->u_arg[2]); |
| 589 | } else { |
Dmitry V. Levin | 42e566a | 2016-06-25 11:31:48 +0000 | [diff] [blame] | 590 | decode_sockaddr(tcp, tcp->u_arg[1], len); |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 591 | tprintf(", [%d]", len); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 592 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 593 | |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 594 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 595 | tprints(", "); |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 596 | printflags(sock_type_flags, tcp->u_arg[flags_arg], |
| 597 | "SOCK_???"); |
| 598 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 599 | return 0; |
| 600 | } |
| 601 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 602 | SYS_FUNC(accept) |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 603 | { |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 604 | do_sockname(tcp, -1); |
| 605 | return RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 608 | SYS_FUNC(accept4) |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 609 | { |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 610 | do_sockname(tcp, 3); |
| 611 | return RVAL_FD; |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 612 | } |
Paolo Bonzini | 705ff10 | 2009-08-14 12:34:05 +0200 | [diff] [blame] | 613 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 614 | SYS_FUNC(send) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 615 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 616 | printfd(tcp, tcp->u_arg[0]); |
| 617 | tprints(", "); |
| 618 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 619 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 620 | /* flags */ |
| 621 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 622 | |
| 623 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 626 | SYS_FUNC(sendto) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 627 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 628 | printfd(tcp, tcp->u_arg[0]); |
| 629 | tprints(", "); |
| 630 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 631 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 632 | /* flags */ |
| 633 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
| 634 | /* to address */ |
| 635 | tprints(", "); |
Dmitry V. Levin | 42e566a | 2016-06-25 11:31:48 +0000 | [diff] [blame] | 636 | decode_sockaddr(tcp, tcp->u_arg[4], tcp->u_arg[5]); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 637 | /* to length */ |
| 638 | tprintf(", %lu", tcp->u_arg[5]); |
| 639 | |
| 640 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 643 | SYS_FUNC(sendmsg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 644 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 645 | printfd(tcp, tcp->u_arg[0]); |
| 646 | tprints(", "); |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 647 | decode_msghdr(tcp, tcp->u_arg[1], (unsigned long) -1L); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 648 | /* flags */ |
| 649 | tprints(", "); |
| 650 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
| 651 | |
| 652 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 655 | SYS_FUNC(sendmmsg) |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 656 | { |
| 657 | if (entering(tcp)) { |
| 658 | /* sockfd */ |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 659 | printfd(tcp, tcp->u_arg[0]); |
| 660 | tprints(", "); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 661 | if (!verbose(tcp)) { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 662 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 663 | /* vlen */ |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 664 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 665 | /* flags */ |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 666 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 667 | return RVAL_DECODED; |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 668 | } |
| 669 | } else { |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 670 | decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, false); |
| 671 | /* vlen */ |
| 672 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
| 673 | /* flags */ |
| 674 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Dmitry V. Levin | 7af9f35 | 2012-03-11 23:59:29 +0000 | [diff] [blame] | 675 | } |
| 676 | return 0; |
| 677 | } |
| 678 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 679 | SYS_FUNC(recv) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 680 | { |
| 681 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 682 | printfd(tcp, tcp->u_arg[0]); |
| 683 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 684 | } else { |
| 685 | if (syserror(tcp)) |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 686 | printaddr(tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 687 | else |
| 688 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 689 | |
| 690 | tprintf(", %lu, ", tcp->u_arg[2]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 691 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 692 | } |
| 693 | return 0; |
| 694 | } |
| 695 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 696 | SYS_FUNC(recvfrom) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 697 | { |
| 698 | int fromlen; |
| 699 | |
| 700 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 701 | printfd(tcp, tcp->u_arg[0]); |
| 702 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 703 | } else { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 704 | /* buf */ |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 705 | if (syserror(tcp)) { |
Dmitry V. Levin | 52dc150 | 2015-07-30 13:53:42 +0000 | [diff] [blame] | 706 | printaddr(tcp->u_arg[1]); |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 707 | } else { |
| 708 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 709 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 710 | /* len */ |
| 711 | tprintf(", %lu, ", tcp->u_arg[2]); |
| 712 | /* flags */ |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 713 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 714 | tprints(", "); |
Dmitry V. Levin | 52dc150 | 2015-07-30 13:53:42 +0000 | [diff] [blame] | 715 | if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] || |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 716 | umove(tcp, tcp->u_arg[5], &fromlen) < 0) { |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 717 | /* from address, len */ |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 718 | printaddr(tcp->u_arg[4]); |
| 719 | tprints(", "); |
| 720 | printaddr(tcp->u_arg[5]); |
| 721 | return 0; |
| 722 | } |
Denys Vlasenko | 383386d | 2015-07-30 13:29:20 +0200 | [diff] [blame] | 723 | /* from address */ |
Dmitry V. Levin | 42e566a | 2016-06-25 11:31:48 +0000 | [diff] [blame] | 724 | decode_sockaddr(tcp, tcp->u_arg[4], fromlen); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 725 | /* from length */ |
| 726 | tprintf(", [%u]", fromlen); |
| 727 | } |
| 728 | return 0; |
| 729 | } |
| 730 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 731 | SYS_FUNC(recvmsg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 732 | { |
| 733 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 734 | printfd(tcp, tcp->u_arg[0]); |
| 735 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 736 | } else { |
Dmitry V. Levin | 00244b9 | 2015-01-28 01:52:25 +0000 | [diff] [blame] | 737 | if (syserror(tcp)) |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 738 | printaddr(tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 739 | else |
Dmitry V. Levin | 3e514c0 | 2016-06-26 23:57:29 +0000 | [diff] [blame] | 740 | decode_msghdr(tcp, tcp->u_arg[1], tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 741 | /* flags */ |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 742 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 743 | printflags(msg_flags, tcp->u_arg[2], "MSG_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 744 | } |
| 745 | return 0; |
| 746 | } |
| 747 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 748 | SYS_FUNC(recvmmsg) |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 749 | { |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 750 | static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE]; |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 751 | |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 752 | if (entering(tcp)) { |
Philippe Ombredanne | 894c7e3 | 2014-02-01 09:57:45 -0800 | [diff] [blame] | 753 | printfd(tcp, tcp->u_arg[0]); |
| 754 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 755 | if (verbose(tcp)) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 756 | /* Abusing tcp->auxstr as temp storage. |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 757 | * Will be used and cleared on syscall exit. |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 758 | */ |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 759 | tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 760 | } else { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 761 | printaddr(tcp->u_arg[1]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 762 | /* vlen */ |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 763 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 764 | /* flags */ |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 765 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 766 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 767 | print_timespec(tcp, tcp->u_arg[4]); |
| 768 | } |
| 769 | return 0; |
| 770 | } else { |
| 771 | if (verbose(tcp)) { |
Dmitry V. Levin | 9a8216e | 2016-06-27 00:02:50 +0000 | [diff] [blame^] | 772 | decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval, true); |
| 773 | /* vlen */ |
| 774 | tprintf(", %u, ", (unsigned int) tcp->u_arg[2]); |
| 775 | /* flags */ |
| 776 | printflags(msg_flags, tcp->u_arg[3], "MSG_???"); |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 777 | tprints(", "); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 778 | /* timeout on entrance */ |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 779 | tprints(tcp->auxstr); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 780 | tcp->auxstr = NULL; |
| 781 | } |
| 782 | if (syserror(tcp)) |
| 783 | return 0; |
| 784 | if (tcp->u_rval == 0) { |
| 785 | tcp->auxstr = "Timeout"; |
| 786 | return RVAL_STR; |
| 787 | } |
| 788 | if (!verbose(tcp)) |
| 789 | return 0; |
| 790 | /* timeout on exit */ |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 791 | snprintf(str, sizeof(str), "left %s", |
| 792 | sprint_timespec(tcp, tcp->u_arg[4])); |
Dmitry V. Levin | e659103 | 2010-03-29 20:45:48 +0400 | [diff] [blame] | 793 | tcp->auxstr = str; |
| 794 | return RVAL_STR; |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 795 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 796 | } |
Andreas Schwab | 0873f29 | 2010-02-12 21:39:12 +0100 | [diff] [blame] | 797 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 798 | #include "xlat/shutdown_modes.h" |
Sebastian Pipping | 9cd3850 | 2011-03-03 01:12:25 +0100 | [diff] [blame] | 799 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 800 | SYS_FUNC(shutdown) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 801 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 802 | printfd(tcp, tcp->u_arg[0]); |
| 803 | tprints(", "); |
| 804 | printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???"); |
| 805 | |
| 806 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 809 | SYS_FUNC(getsockname) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 810 | { |
Dmitry V. Levin | 15114ec | 2014-08-06 16:46:13 +0000 | [diff] [blame] | 811 | return do_sockname(tcp, -1); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 814 | static void |
| 815 | printpair_fd(struct tcb *tcp, const int i0, const int i1) |
| 816 | { |
| 817 | tprints("["); |
| 818 | printfd(tcp, i0); |
| 819 | tprints(", "); |
| 820 | printfd(tcp, i1); |
| 821 | tprints("]"); |
| 822 | } |
| 823 | |
| 824 | static void |
| 825 | decode_pair_fd(struct tcb *tcp, const long addr) |
| 826 | { |
| 827 | int pair[2]; |
| 828 | |
| 829 | if (umove_or_printaddr(tcp, addr, &pair)) |
| 830 | return; |
| 831 | |
| 832 | printpair_fd(tcp, pair[0], pair[1]); |
| 833 | } |
| 834 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 835 | static int |
| 836 | do_pipe(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 837 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 838 | if (exiting(tcp)) { |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 839 | decode_pair_fd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 840 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 841 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 842 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 843 | } |
| 844 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 845 | return 0; |
| 846 | } |
| 847 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 848 | SYS_FUNC(pipe) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 849 | { |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 850 | #ifdef HAVE_GETRVAL2 |
| 851 | if (exiting(tcp) && !syserror(tcp)) |
| 852 | printpair_fd(tcp, tcp->u_rval, getrval2(tcp)); |
| 853 | return 0; |
| 854 | #else |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 855 | return do_pipe(tcp, -1); |
Dmitry V. Levin | 9b38885 | 2016-02-12 16:37:31 +0000 | [diff] [blame] | 856 | #endif |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 859 | SYS_FUNC(pipe2) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 860 | { |
| 861 | return do_pipe(tcp, 1); |
| 862 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 863 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 864 | SYS_FUNC(socketpair) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 865 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 866 | if (entering(tcp)) { |
Dmitry V. Levin | 71fe62e | 2016-04-04 01:35:28 +0000 | [diff] [blame] | 867 | printxval(addrfams, tcp->u_arg[0], "AF_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 868 | tprints(", "); |
Dmitry V. Levin | 1e42f2d | 2014-09-10 17:48:28 +0000 | [diff] [blame] | 869 | tprint_sock_type(tcp->u_arg[1]); |
Dmitry V. Levin | 033fb91 | 2014-03-11 22:50:39 +0000 | [diff] [blame] | 870 | tprintf(", %lu", tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 871 | } else { |
Dmitry V. Levin | b679508 | 2015-07-06 22:33:39 +0000 | [diff] [blame] | 872 | tprints(", "); |
Dmitry V. Levin | 2a4f052 | 2015-08-02 01:54:48 +0000 | [diff] [blame] | 873 | decode_pair_fd(tcp, tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 874 | } |
| 875 | return 0; |
| 876 | } |
| 877 | |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 878 | #include "xlat/sockoptions.h" |
| 879 | #include "xlat/sockipoptions.h" |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 880 | #include "xlat/getsockipoptions.h" |
| 881 | #include "xlat/setsockipoptions.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 882 | #include "xlat/sockipv6options.h" |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 883 | #include "xlat/getsockipv6options.h" |
| 884 | #include "xlat/setsockipv6options.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 885 | #include "xlat/sockipxoptions.h" |
| 886 | #include "xlat/sockrawoptions.h" |
| 887 | #include "xlat/sockpacketoptions.h" |
| 888 | #include "xlat/socksctpoptions.h" |
| 889 | #include "xlat/socktcpoptions.h" |
| 890 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 891 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 892 | print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level, |
| 893 | unsigned int name, bool is_getsockopt) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 894 | { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 895 | printfd(tcp, fd); |
| 896 | tprints(", "); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 897 | printxval(socketlayers, level, "SOL_??"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 898 | tprints(", "); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 899 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 900 | switch (level) { |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 901 | case SOL_SOCKET: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 902 | printxval(sockoptions, name, "SO_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 903 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 904 | case SOL_IP: |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 905 | printxvals(name, "IP_???", sockipoptions, |
| 906 | is_getsockopt ? getsockipoptions : setsockipoptions, NULL); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 907 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 908 | case SOL_IPV6: |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 909 | printxvals(name, "IPV6_???", sockipv6options, |
| 910 | is_getsockopt ? getsockipv6options : setsockipv6options, NULL); |
Roland McGrath | 4f6ba69 | 2004-08-31 07:01:26 +0000 | [diff] [blame] | 911 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 912 | case SOL_IPX: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 913 | printxval(sockipxoptions, name, "IPX_???"); |
| 914 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 915 | case SOL_PACKET: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 916 | printxval(sockpacketoptions, name, "PACKET_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 917 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 918 | case SOL_TCP: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 919 | printxval(socktcpoptions, name, "TCP_???"); |
| 920 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 921 | case SOL_SCTP: |
Holger Hans Peter Freyther | 7fea79b | 2011-01-14 11:08:12 +0100 | [diff] [blame] | 922 | printxval(socksctpoptions, name, "SCTP_???"); |
| 923 | break; |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 924 | case SOL_RAW: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 925 | printxval(sockrawoptions, name, "RAW_???"); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 926 | break; |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 927 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 928 | /* Other SOL_* protocol levels still need work. */ |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 929 | |
Denys Vlasenko | 989ebc9 | 2012-03-17 04:42:07 +0100 | [diff] [blame] | 930 | default: |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 931 | tprintf("%u", name); |
| 932 | } |
| 933 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 934 | tprints(", "); |
| 935 | } |
| 936 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 937 | static void |
| 938 | print_linger(struct tcb *tcp, long addr, int len) |
| 939 | { |
| 940 | struct linger linger; |
| 941 | |
| 942 | if (len != sizeof(linger) || |
| 943 | umove(tcp, addr, &linger) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 944 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 945 | return; |
| 946 | } |
| 947 | |
| 948 | tprintf("{onoff=%d, linger=%d}", |
| 949 | linger.l_onoff, |
| 950 | linger.l_linger); |
| 951 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 952 | |
| 953 | #ifdef SO_PEERCRED |
| 954 | static void |
| 955 | print_ucred(struct tcb *tcp, long addr, int len) |
| 956 | { |
| 957 | struct ucred uc; |
| 958 | |
| 959 | if (len != sizeof(uc) || |
| 960 | umove(tcp, addr, &uc) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 961 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 962 | } else { |
| 963 | tprintf("{pid=%u, uid=%u, gid=%u}", |
| 964 | (unsigned) uc.pid, |
| 965 | (unsigned) uc.uid, |
| 966 | (unsigned) uc.gid); |
| 967 | } |
| 968 | } |
| 969 | #endif /* SO_PEERCRED */ |
| 970 | |
| 971 | #ifdef PACKET_STATISTICS |
| 972 | static void |
| 973 | print_tpacket_stats(struct tcb *tcp, long addr, int len) |
| 974 | { |
| 975 | struct tpacket_stats stats; |
| 976 | |
| 977 | if (len != sizeof(stats) || |
| 978 | umove(tcp, addr, &stats) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 979 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 980 | } else { |
| 981 | tprintf("{packets=%u, drops=%u}", |
| 982 | stats.tp_packets, |
| 983 | stats.tp_drops); |
| 984 | } |
| 985 | } |
| 986 | #endif /* PACKET_STATISTICS */ |
| 987 | |
Dmitry V. Levin | fba9db2 | 2016-06-15 21:29:07 +0000 | [diff] [blame] | 988 | #include "xlat/icmpfilterflags.h" |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 989 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 990 | static void |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 991 | print_icmp_filter(struct tcb *tcp, const long addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 992 | { |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 993 | struct icmp_filter filter = {}; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 994 | |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 995 | if (len > (int) sizeof(filter)) |
| 996 | len = sizeof(filter); |
| 997 | else if (len <= 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 998 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 999 | return; |
| 1000 | } |
| 1001 | |
Dmitry V. Levin | eb5c233 | 2016-05-06 00:06:15 +0000 | [diff] [blame] | 1002 | if (umoven_or_printaddr(tcp, addr, len, &filter)) |
| 1003 | return; |
| 1004 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1005 | tprints("~("); |
| 1006 | printflags(icmpfilterflags, ~filter.data, "ICMP_???"); |
| 1007 | tprints(")"); |
| 1008 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1009 | |
| 1010 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 1011 | print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name, |
| 1012 | long addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1013 | { |
| 1014 | if (addr && verbose(tcp)) |
| 1015 | switch (level) { |
| 1016 | case SOL_SOCKET: |
| 1017 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1018 | case SO_LINGER: |
| 1019 | print_linger(tcp, addr, len); |
| 1020 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1021 | #ifdef SO_PEERCRED |
| 1022 | case SO_PEERCRED: |
| 1023 | print_ucred(tcp, addr, len); |
| 1024 | goto done; |
| 1025 | #endif |
| 1026 | } |
| 1027 | break; |
| 1028 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1029 | case SOL_PACKET: |
| 1030 | switch (name) { |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1031 | #ifdef PACKET_STATISTICS |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1032 | case PACKET_STATISTICS: |
| 1033 | print_tpacket_stats(tcp, addr, len); |
| 1034 | goto done; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1035 | #endif |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1036 | } |
| 1037 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1038 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1039 | case SOL_RAW: |
| 1040 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1041 | case ICMP_FILTER: |
| 1042 | print_icmp_filter(tcp, addr, len); |
| 1043 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1044 | } |
| 1045 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1048 | /* default arg printing */ |
| 1049 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1050 | if (verbose(tcp)) { |
| 1051 | if (len == sizeof(int)) { |
| 1052 | printnum_int(tcp, addr, "%d"); |
| 1053 | } else { |
| 1054 | printstr(tcp, addr, len); |
| 1055 | } |
| 1056 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1057 | printaddr(addr); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1058 | } |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1059 | done: |
| 1060 | tprintf(", [%d]", len); |
| 1061 | } |
| 1062 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 1063 | SYS_FUNC(getsockopt) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1064 | { |
| 1065 | if (entering(tcp)) { |
| 1066 | print_sockopt_fd_level_name(tcp, tcp->u_arg[0], |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 1067 | tcp->u_arg[1], tcp->u_arg[2], true); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1068 | } else { |
| 1069 | int len; |
| 1070 | |
| 1071 | if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) { |
Dmitry V. Levin | 484326d | 2016-06-11 01:28:21 +0000 | [diff] [blame] | 1072 | printaddr(tcp->u_arg[3]); |
| 1073 | tprints(", "); |
| 1074 | printaddr(tcp->u_arg[4]); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1075 | } else { |
| 1076 | print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 1077 | tcp->u_arg[3], len); |
| 1078 | } |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 1079 | } |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1083 | #ifdef IP_ADD_MEMBERSHIP |
| 1084 | static void |
| 1085 | print_mreq(struct tcb *tcp, long addr, unsigned int len) |
| 1086 | { |
| 1087 | struct ip_mreq mreq; |
| 1088 | |
| 1089 | if (len < sizeof(mreq)) { |
| 1090 | printstr(tcp, addr, len); |
| 1091 | return; |
| 1092 | } |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1093 | if (umove_or_printaddr(tcp, addr, &mreq)) |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1094 | return; |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1095 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1096 | tprints("{imr_multiaddr=inet_addr("); |
| 1097 | print_quoted_string(inet_ntoa(mreq.imr_multiaddr), |
| 1098 | 16, QUOTE_0_TERMINATED); |
| 1099 | tprints("), imr_interface=inet_addr("); |
| 1100 | print_quoted_string(inet_ntoa(mreq.imr_interface), |
| 1101 | 16, QUOTE_0_TERMINATED); |
| 1102 | tprints(")}"); |
| 1103 | } |
| 1104 | #endif /* IP_ADD_MEMBERSHIP */ |
| 1105 | |
| 1106 | #ifdef IPV6_ADD_MEMBERSHIP |
| 1107 | static void |
| 1108 | print_mreq6(struct tcb *tcp, long addr, unsigned int len) |
| 1109 | { |
| 1110 | struct ipv6_mreq mreq; |
| 1111 | |
| 1112 | if (len < sizeof(mreq)) |
| 1113 | goto fail; |
| 1114 | |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1115 | if (umove_or_printaddr(tcp, addr, &mreq)) |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1116 | return; |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1117 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1118 | const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr; |
| 1119 | char address[INET6_ADDRSTRLEN]; |
| 1120 | |
| 1121 | if (!inet_ntop(AF_INET6, in6, address, sizeof(address))) |
| 1122 | goto fail; |
| 1123 | |
| 1124 | tprints("{ipv6mr_multiaddr=inet_pton("); |
| 1125 | print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED); |
| 1126 | tprints("), ipv6mr_interface="); |
| 1127 | print_ifindex(mreq.ipv6mr_interface); |
| 1128 | tprints("}"); |
| 1129 | return; |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1130 | |
| 1131 | fail: |
| 1132 | printstr(tcp, addr, len); |
| 1133 | } |
| 1134 | #endif /* IPV6_ADD_MEMBERSHIP */ |
| 1135 | |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1136 | #ifdef MCAST_JOIN_GROUP |
| 1137 | static void |
| 1138 | print_group_req(struct tcb *tcp, long addr, int len) |
| 1139 | { |
| 1140 | struct group_req greq; |
| 1141 | |
| 1142 | if (len != sizeof(greq) || |
| 1143 | umove(tcp, addr, &greq) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1144 | printaddr(addr); |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1145 | return; |
| 1146 | } |
| 1147 | |
Dmitry V. Levin | 1019f00 | 2015-11-21 02:38:59 +0000 | [diff] [blame] | 1148 | tprintf("{gr_interface=%u, gr_group=", greq.gr_interface); |
Dmitry V. Levin | 3bf9c19 | 2016-06-21 16:45:40 +0000 | [diff] [blame] | 1149 | print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group)); |
Dmitry V. Levin | 1019f00 | 2015-11-21 02:38:59 +0000 | [diff] [blame] | 1150 | tprintf("}"); |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1151 | |
| 1152 | } |
| 1153 | #endif /* MCAST_JOIN_GROUP */ |
| 1154 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1155 | #ifdef PACKET_RX_RING |
| 1156 | static void |
| 1157 | print_tpacket_req(struct tcb *tcp, long addr, int len) |
| 1158 | { |
| 1159 | struct tpacket_req req; |
| 1160 | |
| 1161 | if (len != sizeof(req) || |
| 1162 | umove(tcp, addr, &req) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1163 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1164 | } else { |
| 1165 | tprintf("{block_size=%u, block_nr=%u, " |
| 1166 | "frame_size=%u, frame_nr=%u}", |
| 1167 | req.tp_block_size, |
| 1168 | req.tp_block_nr, |
| 1169 | req.tp_frame_size, |
| 1170 | req.tp_frame_nr); |
| 1171 | } |
| 1172 | } |
| 1173 | #endif /* PACKET_RX_RING */ |
| 1174 | |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 1175 | #ifdef PACKET_ADD_MEMBERSHIP |
| 1176 | # include "xlat/packet_mreq_type.h" |
| 1177 | |
| 1178 | static void |
| 1179 | print_packet_mreq(struct tcb *tcp, long addr, int len) |
| 1180 | { |
| 1181 | struct packet_mreq mreq; |
| 1182 | |
| 1183 | if (len != sizeof(mreq) || |
| 1184 | umove(tcp, addr, &mreq) < 0) { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1185 | printaddr(addr); |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 1186 | } else { |
| 1187 | unsigned int i; |
| 1188 | |
| 1189 | tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex); |
| 1190 | printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???"); |
| 1191 | tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen); |
| 1192 | if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address)) |
| 1193 | mreq.mr_alen = ARRAY_SIZE(mreq.mr_address); |
| 1194 | for (i = 0; i < mreq.mr_alen; ++i) |
| 1195 | tprintf("%02x", mreq.mr_address[i]); |
| 1196 | tprints("}"); |
| 1197 | } |
| 1198 | } |
| 1199 | #endif /* PACKET_ADD_MEMBERSHIP */ |
| 1200 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1201 | static void |
Dmitry V. Levin | f40ea79 | 2016-04-01 01:03:20 +0000 | [diff] [blame] | 1202 | print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name, |
| 1203 | long addr, int len) |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1204 | { |
| 1205 | if (addr && verbose(tcp)) |
| 1206 | switch (level) { |
| 1207 | case SOL_SOCKET: |
| 1208 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1209 | case SO_LINGER: |
| 1210 | print_linger(tcp, addr, len); |
| 1211 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1212 | } |
| 1213 | break; |
| 1214 | |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1215 | case SOL_IP: |
| 1216 | switch (name) { |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1217 | #ifdef IP_ADD_MEMBERSHIP |
| 1218 | case IP_ADD_MEMBERSHIP: |
| 1219 | case IP_DROP_MEMBERSHIP: |
| 1220 | print_mreq(tcp, addr, len); |
| 1221 | goto done; |
| 1222 | #endif /* IP_ADD_MEMBERSHIP */ |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1223 | #ifdef MCAST_JOIN_GROUP |
| 1224 | case MCAST_JOIN_GROUP: |
| 1225 | case MCAST_LEAVE_GROUP: |
| 1226 | print_group_req(tcp, addr, len); |
| 1227 | goto done; |
| 1228 | #endif /* MCAST_JOIN_GROUP */ |
| 1229 | } |
Dmitry V. Levin | 3910d0f | 2015-02-08 01:19:06 +0000 | [diff] [blame] | 1230 | break; |
Dmitry V. Levin | a0a4909 | 2015-01-30 01:55:20 +0000 | [diff] [blame] | 1231 | |
Dmitry V. Levin | 7bee462 | 2015-06-08 14:19:46 +0000 | [diff] [blame] | 1232 | case SOL_IPV6: |
| 1233 | switch (name) { |
| 1234 | #ifdef IPV6_ADD_MEMBERSHIP |
| 1235 | case IPV6_ADD_MEMBERSHIP: |
| 1236 | case IPV6_DROP_MEMBERSHIP: |
| 1237 | # ifdef IPV6_JOIN_ANYCAST |
| 1238 | case IPV6_JOIN_ANYCAST: |
| 1239 | # endif |
| 1240 | # ifdef IPV6_LEAVE_ANYCAST |
| 1241 | case IPV6_LEAVE_ANYCAST: |
| 1242 | # endif |
| 1243 | print_mreq6(tcp, addr, len); |
| 1244 | goto done; |
| 1245 | #endif /* IPV6_ADD_MEMBERSHIP */ |
| 1246 | } |
| 1247 | break; |
| 1248 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1249 | case SOL_PACKET: |
| 1250 | switch (name) { |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1251 | #ifdef PACKET_RX_RING |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1252 | case PACKET_RX_RING: |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1253 | # ifdef PACKET_TX_RING |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1254 | case PACKET_TX_RING: |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1255 | # endif |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1256 | print_tpacket_req(tcp, addr, len); |
| 1257 | goto done; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1258 | #endif /* PACKET_RX_RING */ |
| 1259 | #ifdef PACKET_ADD_MEMBERSHIP |
Dmitry V. Levin | 02f2f09 | 2015-01-29 03:26:53 +0000 | [diff] [blame] | 1260 | case PACKET_ADD_MEMBERSHIP: |
| 1261 | case PACKET_DROP_MEMBERSHIP: |
| 1262 | print_packet_mreq(tcp, addr, len); |
| 1263 | goto done; |
Dmitry V. Levin | 6d31c7a | 2015-01-29 04:42:37 +0000 | [diff] [blame] | 1264 | #endif /* PACKET_ADD_MEMBERSHIP */ |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1265 | } |
| 1266 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1267 | |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1268 | case SOL_RAW: |
| 1269 | switch (name) { |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1270 | case ICMP_FILTER: |
| 1271 | print_icmp_filter(tcp, addr, len); |
| 1272 | goto done; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1273 | } |
| 1274 | break; |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | /* default arg printing */ |
| 1278 | |
| 1279 | if (verbose(tcp)) { |
| 1280 | if (len == sizeof(int)) { |
| 1281 | printnum_int(tcp, addr, "%d"); |
| 1282 | } else { |
| 1283 | printstr(tcp, addr, len); |
| 1284 | } |
| 1285 | } else { |
Dmitry V. Levin | 6c277da | 2015-07-19 22:36:46 +0000 | [diff] [blame] | 1286 | printaddr(addr); |
Dmitry V. Levin | 0509c8e | 2015-01-29 03:11:41 +0000 | [diff] [blame] | 1287 | } |
| 1288 | done: |
| 1289 | tprintf(", %d", len); |
| 1290 | } |
| 1291 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 1292 | SYS_FUNC(setsockopt) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1293 | { |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 1294 | print_sockopt_fd_level_name(tcp, tcp->u_arg[0], |
Mike Frysinger | 54646b8 | 2015-08-19 13:29:27 -0400 | [diff] [blame] | 1295 | tcp->u_arg[1], tcp->u_arg[2], false); |
Dmitry V. Levin | 219b3a7 | 2015-07-19 22:52:47 +0000 | [diff] [blame] | 1296 | print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2], |
| 1297 | tcp->u_arg[3], tcp->u_arg[4]); |
| 1298 | |
| 1299 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1300 | } |