blob: 2ec5edadcc3cd3bafb3cef839d047b09ba64eae3 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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 Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * 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 Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
Dmitry V. Levinb2fa2be2014-11-21 20:46:16 +000034#include <sys/uio.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <sys/un.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000036#if defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010037# define in6_addr in6_addr_libc
38# define ipv6_mreq ipv6_mreq_libc
39# define sockaddr_in6 sockaddr_in6_libc
Wichert Akkermanf1850652001-02-16 20:29:03 +000040#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010043# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000044#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000045#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010046# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000047#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010048#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010049# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010050#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000052#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010054#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010055# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010057# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059
Denys Vlasenko99aa1812013-02-08 18:49:06 +010060#if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010061# if defined(HAVE_LINUX_IN6_H)
62# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
63# undef in6_addr
64# undef ipv6_mreq
65# undef sockaddr_in6
66# define in6_addr in6_addr_kernel
67# define ipv6_mreq ipv6_mreq_kernel
68# define sockaddr_in6 sockaddr_in6_kernel
69# endif
70# include <linux/in6.h>
71# if defined(HAVE_SIN6_SCOPE_ID_LINUX)
72# undef in6_addr
73# undef ipv6_mreq
74# undef sockaddr_in6
75# define in6_addr in6_addr_libc
76# define ipv6_mreq ipv6_mreq_libc
77# define sockaddr_in6 sockaddr_in6_kernel
78# endif
79# endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000080#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000081
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000082#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010083# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000085#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010086# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000087#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000088#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010089# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000090#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020091#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
92# include <bluetooth/bluetooth.h>
93# include <bluetooth/hci.h>
94# include <bluetooth/l2cap.h>
95# include <bluetooth/rfcomm.h>
96# include <bluetooth/sco.h>
97#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000098#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010099# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100#endif
101
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000102#include "xlat/domains.h"
103#include "xlat/addrfams.h"
104#include "xlat/socktypes.h"
105#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000106#ifndef SOCK_TYPE_MASK
107# define SOCK_TYPE_MASK 0xf
108#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000109
110#ifndef SOL_IP
111# define SOL_IP 0
112#endif
113#ifndef SOL_TCP
114# define SOL_TCP 6
115#endif
116#ifndef SOL_UDP
117# define SOL_UDP 17
118#endif
119#ifndef SOL_IPV6
120# define SOL_IPV6 41
121#endif
122#ifndef SOL_ICMPV6
123# define SOL_ICMPV6 58
124#endif
125#ifndef SOL_SCTP
126# define SOL_SCTP 132
127#endif
128#ifndef SOL_UDPLITE
129# define SOL_UDPLITE 136
130#endif
131#ifndef SOL_RAW
132# define SOL_RAW 255
133#endif
134#ifndef SOL_IPX
135# define SOL_IPX 256
136#endif
137#ifndef SOL_AX25
138# define SOL_AX25 257
139#endif
140#ifndef SOL_ATALK
141# define SOL_ATALK 258
142#endif
143#ifndef SOL_NETROM
144# define SOL_NETROM 259
145#endif
146#ifndef SOL_ROSE
147# define SOL_ROSE 260
148#endif
149#ifndef SOL_DECNET
150# define SOL_DECNET 261
151#endif
152#ifndef SOL_X25
153# define SOL_X25 262
154#endif
155#ifndef SOL_PACKET
156# define SOL_PACKET 263
157#endif
158#ifndef SOL_ATM
159# define SOL_ATM 264
160#endif
161#ifndef SOL_AAL
162# define SOL_AAL 265
163#endif
164#ifndef SOL_IRDA
165# define SOL_IRDA 266
166#endif
167#ifndef SOL_NETBEUI
168# define SOL_NETBEUI 267
169#endif
170#ifndef SOL_LLC
171# define SOL_LLC 268
172#endif
173#ifndef SOL_DCCP
174# define SOL_DCCP 269
175#endif
176#ifndef SOL_NETLINK
177# define SOL_NETLINK 270
178#endif
179#ifndef SOL_TIPC
180# define SOL_TIPC 271
181#endif
182#ifndef SOL_RXRPC
183# define SOL_RXRPC 272
184#endif
185#ifndef SOL_PPPOL2TP
186# define SOL_PPPOL2TP 273
187#endif
188#ifndef SOL_BLUETOOTH
189# define SOL_BLUETOOTH 274
190#endif
191#ifndef SOL_PNPIPE
192# define SOL_PNPIPE 275
193#endif
194#ifndef SOL_RDS
195# define SOL_RDS 276
196#endif
197#ifndef SOL_IUCV
198# define SOL_IUCV 277
199#endif
200#ifndef SOL_CAIF
201# define SOL_CAIF 278
202#endif
203#ifndef SOL_ALG
204# define SOL_ALG 279
205#endif
206#ifndef SOL_NFC
207# define SOL_NFC 280
208#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000209#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000210
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000211#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900212
213#ifdef PF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +0000214# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
215# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
216# endif
217# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900218#endif
219
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200220#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
221# include "xlat/bt_protocols.h"
222#endif
223
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000224#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000225
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000226#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000227# include "xlat/af_packet_types.h"
228#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000229
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000231printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000233 union {
234 char pad[128];
235 struct sockaddr sa;
236 struct sockaddr_in sin;
237 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000238#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000239 struct sockaddr_in6 sa6;
240#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100241#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242 struct sockaddr_ipx sipx;
243#endif
244#ifdef AF_PACKET
245 struct sockaddr_ll ll;
246#endif
247#ifdef AF_NETLINK
248 struct sockaddr_nl nl;
249#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200250#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
251 struct sockaddr_hci hci;
252 struct sockaddr_l2 l2;
253 struct sockaddr_rc rc;
254 struct sockaddr_sco sco;
255#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000256 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000257 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258
259 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200260 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261 return;
262 }
263 if (!verbose(tcp)) {
264 tprintf("%#lx", addr);
265 return;
266 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000267
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000268 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000269 addrlen = sizeof(addrbuf);
270
271 memset(&addrbuf, 0, sizeof(addrbuf));
272 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200273 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 return;
275 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000276 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000277
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200278 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000279 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200280 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000281
282 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000284 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200285 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000286 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000287 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000288 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000289 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000290 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000291 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000292 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293 break;
294 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000295 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000296 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000297 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000298#ifdef HAVE_INET_NTOP
299 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000300 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000301 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
302 ntohs(addrbuf.sa6.sin6_port), string_addr,
303 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000304#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000305 {
306#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200307 int numericscope = 0;
308 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
309 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
310 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000311
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200312 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
313 numericscope++;
Dmitry V. Levin0e9d5942015-01-24 20:23:02 +0000314 else {
315 tprints(", sin6_scope_id=if_nametoindex(");
316 print_quoted_string(scopebuf,
317 sizeof(scopebuf),
318 QUOTE_0_TERMINATED);
319 tprints(")");
320 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200321 } else
322 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000323
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200324 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000325#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200326 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000327 }
328#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200329 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000330#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100331#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000332 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000333 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000335 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000336 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 /* Yes, I know, this does not look too
338 * strace-ish, but otherwise the IPX
339 * addresses just look monstrous...
340 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000341 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000342 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000343 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200344 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000345 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
346 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347 }
348 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100349#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000350#ifdef AF_PACKET
351 case AF_PACKET:
352 {
353 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000354 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000355 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000356 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000357 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000358 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000359 addrbuf.ll.sll_halen,
360 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200361 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000362 tprintf("%02x", addrbuf.ll.sll_addr[i]);
363 }
364 break;
365
Denys Vlasenko84703742012-02-25 02:38:52 +0100366#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000367#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000368 case AF_NETLINK:
369 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
370 break;
371#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200372#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
373 case AF_BLUETOOTH:
374 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
375 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
376 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
377 "{hci_dev=htobs(%d)}",
378 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
379 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
380 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
381 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
382 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
383 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
384 addrbuf.rc.rc_channel,
385 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
386 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
387 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
388 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
389 btohs(addrbuf.hci.hci_dev));
390 break;
391#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000393 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394
395 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200396 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000398 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399 break;
400 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200401 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402}
403
404#if HAVE_SENDMSG
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000405# ifndef SCM_SECURITY
406# define SCM_SECURITY 0x03
407# endif
408# include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000409
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000410#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
411struct cmsghdr32 {
412 uint32_t cmsg_len;
413 int cmsg_level;
414 int cmsg_type;
415};
416#endif
417
418typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000419 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000420 struct cmsghdr *cmsg;
421#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
422 struct cmsghdr32 *cmsg32;
423#endif
424} union_cmsghdr;
425
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000426static bool
427print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000428{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000429 if (cmsg_size + sizeof(int) > cmsg_len)
430 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000431
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000432 int *fds = (int *) (ptr + cmsg_size);
433 bool seen = false;
434
435 tprints(", [");
436 while ((char *) fds < (ptr + cmsg_len)) {
437 if (seen)
438 tprints(", ");
439 else
440 seen = true;
441 printfd(tcp, *fds++);
442 }
443 tprints("]}");
444 return true;
445}
446
447static bool
448print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
449{
450 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
451 return false;
452
453 const struct ucred *uc = (void *) (ptr + cmsg_size);
454
455 tprintf(", {pid=%u, uid=%u, gid=%u}}",
456 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
457 return true;
458}
459
460static bool
461print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
462{
463 if (cmsg_size + sizeof(char) > cmsg_len)
464 return false;
465
466 const char *label = (const char *) (ptr + cmsg_size);
467 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000468
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000469 tprints(", ");
470 print_quoted_string(label, label_len, 0);
471 tprints("}");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000472
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000473 return true;
474}
475
476static void
477printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
478{
479 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000480#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
481 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
482#endif
483 sizeof(struct cmsghdr);
484
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000485 char *buf = len < cmsg_size ? NULL : malloc(len);
486 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000487 tprintf(", msg_control=%#lx", addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000488 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000489 return;
490 }
491
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000492 union_cmsghdr u = { .ptr = buf };
493
494 tprints(", [");
495 while (len >= cmsg_size) {
496 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000497#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000498 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000499#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000500 u.cmsg->cmsg_len;
501 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000502#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000503 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000504#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000505 u.cmsg->cmsg_level;
506 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000507#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000508 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000509#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000510 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000511
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000512 if (u.ptr != buf)
513 tprints(", ");
514 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
515 printxval(socketlayers, cmsg_level, "SOL_???");
516 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000517
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000518 if (cmsg_len > len)
519 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000520
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000521 if (cmsg_level == SOL_SOCKET) {
522 printxval(scmvals, cmsg_type, "SCM_???");
523 switch (cmsg_type) {
524 case SCM_RIGHTS:
525 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
526 goto next_cmsg;
527 break;
528 case SCM_CREDENTIALS:
529 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
530 goto next_cmsg;
531 break;
532 case SCM_SECURITY:
533 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
534 goto next_cmsg;
535 break;
Roland McGrath50770822004-10-06 22:11:51 +0000536 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000537 } else {
538 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000539 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000540 tprints(", ...}");
541next_cmsg:
542 if (cmsg_len < cmsg_size) {
543 len -= cmsg_size;
544 break;
Roland McGrath50770822004-10-06 22:11:51 +0000545 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000546 cmsg_len = (cmsg_len + current_wordsize - 1) &
547 (size_t) ~(current_wordsize - 1);
548 if (cmsg_len >= len) {
549 len = 0;
550 break;
551 }
552 u.ptr += cmsg_len;
553 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000554 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000555 if (len)
556 tprints(", ...");
557 tprints("]");
558 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000559}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560
561static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200562do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100563{
564 tprintf("{msg_name(%d)=", msg->msg_namelen);
565 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
566
567 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200568 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
569 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100570
571#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
572 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
573 if (msg->msg_controllen)
574 printcmsghdr(tcp, (unsigned long) msg->msg_control,
575 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200576 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100577 printflags(msg_flags, msg->msg_flags, "MSG_???");
578#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
579 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
580 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
581#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200582 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100583}
584
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100585struct msghdr32 {
586 uint32_t /* void* */ msg_name;
587 uint32_t /* socklen_t */msg_namelen;
588 uint32_t /* iovec* */ msg_iov;
589 uint32_t /* size_t */ msg_iovlen;
590 uint32_t /* void* */ msg_control;
591 uint32_t /* size_t */ msg_controllen;
592 uint32_t /* int */ msg_flags;
593};
594struct mmsghdr32 {
595 struct msghdr32 msg_hdr;
596 uint32_t /* unsigned */ msg_len;
597};
598
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900599#ifndef HAVE_STRUCT_MMSGHDR
600struct mmsghdr {
601 struct msghdr msg_hdr;
602 unsigned msg_len;
603};
604#endif
605
Masatake YAMATOb2485432014-11-07 01:23:24 +0900606#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
607static void
608copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
609{
610 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
611 to_msg->msg_namelen = from_msg32->msg_namelen;
612 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
613 to_msg->msg_iovlen = from_msg32->msg_iovlen;
614 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
615 to_msg->msg_controllen = from_msg32->msg_controllen;
616 to_msg->msg_flags = from_msg32->msg_flags;
617}
618#endif
619
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900620static bool
621extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
622{
623#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
624 if (current_wordsize == 4) {
625 struct msghdr32 msg32;
626
627 if (umove(tcp, addr, &msg32) < 0)
628 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900629 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900630 } else
631#endif
632 if (umove(tcp, addr, msg) < 0)
633 return false;
634 return true;
635}
636
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900637static bool
638extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
639{
640#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
641 if (current_wordsize == 4) {
642 struct mmsghdr32 mmsg32;
643
644 addr += sizeof(struct mmsghdr32) * idx;
645 if (umove(tcp, addr, &mmsg32) < 0)
646 return false;
647
648 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
649 mmsg->msg_len = mmsg32.msg_len;
650 } else
651#endif
652 {
653 addr += sizeof(*mmsg) * idx;
654 if (umove(tcp, addr, mmsg) < 0)
655 return false;
656 }
657 return true;
658}
659
Andreas Schwab0873f292010-02-12 21:39:12 +0100660static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200661printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662{
663 struct msghdr msg;
664
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000665 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900666 do_msghdr(tcp, &msg, data_size);
667 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000668 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900669}
670
671void
672dumpiov_in_msghdr(struct tcb *tcp, long addr)
673{
674 struct msghdr msg;
675
676 if (extractmsghdr(tcp, addr, &msg))
677 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678}
679
Andreas Schwab0873f292010-02-12 21:39:12 +0100680static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000681printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100682{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900683 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100684
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900685 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
686 tprints("{");
687 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
688 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100689 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900690 else
691 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100692}
Andreas Schwab0873f292010-02-12 21:39:12 +0100693
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000694static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000695decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000696{
697 /* mmsgvec */
698 if (syserror(tcp)) {
699 tprintf("%#lx", tcp->u_arg[1]);
700 } else {
701 unsigned int len = tcp->u_rval;
702 unsigned int i;
703
704 tprints("{");
705 for (i = 0; i < len; ++i) {
706 if (i)
707 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000708 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000709 }
710 tprints("}");
711 }
712 /* vlen */
713 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
714 /* flags */
715 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
716}
717
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900718void
719dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
720{
721 unsigned int len = tcp->u_rval;
722 unsigned int i;
723 struct mmsghdr mmsg;
724
725 for (i = 0; i < len; ++i) {
726 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
727 tprintf(" = %lu buffers in vector %u\n",
728 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
729 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
730 (long)mmsg.msg_hdr.msg_iov);
731 }
732 }
733}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734#endif /* HAVE_SENDMSG */
735
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000736/*
737 * low bits of the socket type define real socket type,
738 * other bits are socket type flags.
739 */
740static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000741tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000742{
743 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
744
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200745 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200746 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000747 flags &= ~SOCK_TYPE_MASK;
748 if (!flags)
749 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200750 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000751 }
752 printflags(sock_type_flags, flags, "SOCK_???");
753}
754
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000756sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757{
758 if (entering(tcp)) {
759 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200760 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000761 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200762 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763 switch (tcp->u_arg[0]) {
764 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000765#ifdef PF_INET6
766 case PF_INET6:
767#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900768 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000769 break;
770#ifdef PF_IPX
771 case PF_IPX:
772 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200773 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000774 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200775 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776 break;
777#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900778#ifdef PF_NETLINK
779 case PF_NETLINK:
780 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
781 break;
782#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200783#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
784 case PF_BLUETOOTH:
785 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
786 break;
787#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788 default:
789 tprintf("%lu", tcp->u_arg[2]);
790 break;
791 }
792 }
793 return 0;
794}
795
John Hughesbdf48f52001-03-06 15:08:09 +0000796int
Denys Vlasenko12014262011-05-30 14:00:14 +0200797sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000798{
799 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800800 printfd(tcp, tcp->u_arg[0]);
801 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000802 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000803 tprintf(", %lu", tcp->u_arg[2]);
804 }
805 return 0;
806}
807
808int
Denys Vlasenko12014262011-05-30 14:00:14 +0200809sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000810{
811 return sys_bind(tcp);
812}
813
814int
Denys Vlasenko12014262011-05-30 14:00:14 +0200815sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816{
817 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800818 printfd(tcp, tcp->u_arg[0]);
819 tprints(", ");
820 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 }
822 return 0;
823}
824
Paolo Bonzini705ff102009-08-14 12:34:05 +0200825static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000826do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827{
828 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800829 printfd(tcp, tcp->u_arg[0]);
830 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200831 return 0;
832 }
833 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834 tprintf("%#lx, NULL", tcp->u_arg[1]);
835 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000836 int len;
837 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200838 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839 tprintf("%#lx", tcp->u_arg[1]);
840 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000841 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000842 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200843 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000844 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200846 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200847 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200848 printflags(sock_type_flags, tcp->u_arg[flags_arg],
849 "SOCK_???");
850 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851 return 0;
852}
853
854int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200855sys_accept(struct tcb *tcp)
856{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000857 do_sockname(tcp, -1);
858 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200859}
860
Paolo Bonzini705ff102009-08-14 12:34:05 +0200861int
862sys_accept4(struct tcb *tcp)
863{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000864 do_sockname(tcp, 3);
865 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200866}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200867
868int
Denys Vlasenko12014262011-05-30 14:00:14 +0200869sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870{
871 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800872 printfd(tcp, tcp->u_arg[0]);
873 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
875 tprintf(", %lu, ", tcp->u_arg[2]);
876 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000877 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878 }
879 return 0;
880}
881
882int
Denys Vlasenko12014262011-05-30 14:00:14 +0200883sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884{
885 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800886 printfd(tcp, tcp->u_arg[0]);
887 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000888 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
889 tprintf(", %lu, ", tcp->u_arg[2]);
890 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000891 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000892 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200893 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000894 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895 /* to length */
896 tprintf(", %lu", tcp->u_arg[5]);
897 }
898 return 0;
899}
900
901#ifdef HAVE_SENDMSG
902
903int
Denys Vlasenko12014262011-05-30 14:00:14 +0200904sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000905{
906 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800907 printfd(tcp, tcp->u_arg[0]);
908 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000909 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200911 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000912 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000913 }
914 return 0;
915}
916
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000917int
918sys_sendmmsg(struct tcb *tcp)
919{
920 if (entering(tcp)) {
921 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800922 printfd(tcp, tcp->u_arg[0]);
923 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000924 if (!verbose(tcp)) {
925 tprintf("%#lx, %u, ",
926 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
927 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
928 }
929 } else {
930 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000931 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000932 }
933 return 0;
934}
935
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000936#endif /* HAVE_SENDMSG */
937
938int
Denys Vlasenko12014262011-05-30 14:00:14 +0200939sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000940{
941 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800942 printfd(tcp, tcp->u_arg[0]);
943 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944 } else {
945 if (syserror(tcp))
946 tprintf("%#lx", tcp->u_arg[1]);
947 else
948 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
949
950 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000951 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 }
953 return 0;
954}
955
956int
Denys Vlasenko12014262011-05-30 14:00:14 +0200957sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958{
959 int fromlen;
960
961 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800962 printfd(tcp, tcp->u_arg[0]);
963 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 } else {
965 if (syserror(tcp)) {
966 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
967 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
968 tcp->u_arg[4], tcp->u_arg[5]);
969 return 0;
970 }
971 /* buf */
972 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
973 /* len */
974 tprintf(", %lu, ", tcp->u_arg[2]);
975 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000976 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977 /* from address, len */
978 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
979 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200980 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 else
982 tprintf(", %#lx", tcp->u_arg[4]);
983 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200984 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985 else
986 tprintf(", %#lx", tcp->u_arg[5]);
987 return 0;
988 }
989 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200990 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991 return 0;
992 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200993 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000994 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 /* from length */
996 tprintf(", [%u]", fromlen);
997 }
998 return 0;
999}
1000
1001#ifdef HAVE_SENDMSG
1002
1003int
Denys Vlasenko12014262011-05-30 14:00:14 +02001004sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005{
1006 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001007 printfd(tcp, tcp->u_arg[0]);
1008 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +00001010 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001011 tprintf("%#lx", tcp->u_arg[1]);
1012 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001013 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001015 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001016 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017 }
1018 return 0;
1019}
1020
Andreas Schwab0873f292010-02-12 21:39:12 +01001021int
1022sys_recvmmsg(struct tcb *tcp)
1023{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001024 /* +5 chars are for "left " prefix */
1025 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001026
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001027 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001028 printfd(tcp, tcp->u_arg[0]);
1029 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001030 if (verbose(tcp)) {
1031 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001032 /* Abusing tcp->auxstr as temp storage.
1033 * Will be used and freed on syscall exit.
1034 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001035 tcp->auxstr = strdup(str);
1036 } else {
1037 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1038 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001039 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001040 print_timespec(tcp, tcp->u_arg[4]);
1041 }
1042 return 0;
1043 } else {
1044 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001045 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001046 /* timeout on entrance */
1047 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1048 free((void *) tcp->auxstr);
1049 tcp->auxstr = NULL;
1050 }
1051 if (syserror(tcp))
1052 return 0;
1053 if (tcp->u_rval == 0) {
1054 tcp->auxstr = "Timeout";
1055 return RVAL_STR;
1056 }
1057 if (!verbose(tcp))
1058 return 0;
1059 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001060 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001061 tcp->auxstr = str;
1062 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001063 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001064}
Andreas Schwab0873f292010-02-12 21:39:12 +01001065
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066#endif /* HAVE_SENDMSG */
1067
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001068#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001069
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001070int
Denys Vlasenko12014262011-05-30 14:00:14 +02001071sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072{
1073 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001074 printfd(tcp, tcp->u_arg[0]);
1075 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001076 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077 }
1078 return 0;
1079}
1080
1081int
Denys Vlasenko12014262011-05-30 14:00:14 +02001082sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001084 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001085}
1086
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001087static int
1088do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090 if (exiting(tcp)) {
1091 if (syserror(tcp)) {
1092 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001093 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001094#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001095 int fds[2];
1096
1097 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001098 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001099 else
1100 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001101#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001102 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1103#else
1104 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001106 }
1107 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001108 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001109 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1110 }
1111 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001112 return 0;
1113}
1114
1115int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001116sys_pipe(struct tcb *tcp)
1117{
1118 return do_pipe(tcp, -1);
1119}
1120
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001121int
1122sys_pipe2(struct tcb *tcp)
1123{
1124 return do_pipe(tcp, 1);
1125}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001126
1127int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001128sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001129{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001131
1132 if (entering(tcp)) {
1133 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001134 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001135 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001136 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001137 } else {
1138 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001139 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140 return 0;
1141 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001142 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001143 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 else
1145 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001146 }
1147 return 0;
1148}
1149
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001150#include "xlat/sockoptions.h"
1151#include "xlat/sockipoptions.h"
1152#include "xlat/sockipv6options.h"
1153#include "xlat/sockipxoptions.h"
1154#include "xlat/sockrawoptions.h"
1155#include "xlat/sockpacketoptions.h"
1156#include "xlat/socksctpoptions.h"
1157#include "xlat/socktcpoptions.h"
1158
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001159static void
1160print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001161{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001162 printfd(tcp, fd);
1163 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001164 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001165 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001166
John Hughes38ae88d2002-05-23 11:48:58 +00001167 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001168 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001169 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001170 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001171 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001172 printxval(sockipoptions, name, "IP_???");
1173 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001174 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001175 printxval(sockipv6options, name, "IPV6_???");
1176 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001177 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001178 printxval(sockipxoptions, name, "IPX_???");
1179 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001180 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001181 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001182 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001183 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001184 printxval(socktcpoptions, name, "TCP_???");
1185 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001186 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001187 printxval(socksctpoptions, name, "SCTP_???");
1188 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001189 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001190 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001191 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001192
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001193 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001194
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001195 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001196 tprintf("%u", name);
1197 }
1198
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001199 tprints(", ");
1200}
1201
1202#ifdef SO_LINGER
1203static void
1204print_linger(struct tcb *tcp, long addr, int len)
1205{
1206 struct linger linger;
1207
1208 if (len != sizeof(linger) ||
1209 umove(tcp, addr, &linger) < 0) {
1210 tprintf("%#lx", addr);
1211 return;
1212 }
1213
1214 tprintf("{onoff=%d, linger=%d}",
1215 linger.l_onoff,
1216 linger.l_linger);
1217}
1218#endif /* SO_LINGER */
1219
1220#ifdef SO_PEERCRED
1221static void
1222print_ucred(struct tcb *tcp, long addr, int len)
1223{
1224 struct ucred uc;
1225
1226 if (len != sizeof(uc) ||
1227 umove(tcp, addr, &uc) < 0) {
1228 tprintf("%#lx", addr);
1229 } else {
1230 tprintf("{pid=%u, uid=%u, gid=%u}",
1231 (unsigned) uc.pid,
1232 (unsigned) uc.uid,
1233 (unsigned) uc.gid);
1234 }
1235}
1236#endif /* SO_PEERCRED */
1237
1238#ifdef PACKET_STATISTICS
1239static void
1240print_tpacket_stats(struct tcb *tcp, long addr, int len)
1241{
1242 struct tpacket_stats stats;
1243
1244 if (len != sizeof(stats) ||
1245 umove(tcp, addr, &stats) < 0) {
1246 tprintf("%#lx", addr);
1247 } else {
1248 tprintf("{packets=%u, drops=%u}",
1249 stats.tp_packets,
1250 stats.tp_drops);
1251 }
1252}
1253#endif /* PACKET_STATISTICS */
1254
1255#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001256# include "xlat/icmpfilterflags.h"
1257
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001258static void
1259print_icmp_filter(struct tcb *tcp, long addr, int len)
1260{
1261 struct icmp_filter filter;
1262
1263 if (len != sizeof(filter) ||
1264 umove(tcp, addr, &filter) < 0) {
1265 tprintf("%#lx", addr);
1266 return;
1267 }
1268
1269 tprints("~(");
1270 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1271 tprints(")");
1272}
1273#endif /* ICMP_FILTER */
1274
1275static void
1276print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1277{
1278 if (addr && verbose(tcp))
1279 switch (level) {
1280 case SOL_SOCKET:
1281 switch (name) {
1282#ifdef SO_LINGER
1283 case SO_LINGER:
1284 print_linger(tcp, addr, len);
1285 goto done;
1286#endif
1287#ifdef SO_PEERCRED
1288 case SO_PEERCRED:
1289 print_ucred(tcp, addr, len);
1290 goto done;
1291#endif
1292 }
1293 break;
1294
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001295 case SOL_PACKET:
1296 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001297#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001298 case PACKET_STATISTICS:
1299 print_tpacket_stats(tcp, addr, len);
1300 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001301#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001302 }
1303 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001304
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001305 case SOL_RAW:
1306 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001307#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001308 case ICMP_FILTER:
1309 print_icmp_filter(tcp, addr, len);
1310 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001311#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001312 }
1313 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001314 }
1315
John Hughes38ae88d2002-05-23 11:48:58 +00001316 /* default arg printing */
1317
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001318 if (verbose(tcp)) {
1319 if (len == sizeof(int)) {
1320 printnum_int(tcp, addr, "%d");
1321 } else {
1322 printstr(tcp, addr, len);
1323 }
1324 } else {
1325 tprintf("%#lx", addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001326 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001327done:
1328 tprintf(", [%d]", len);
1329}
1330
1331int
1332sys_getsockopt(struct tcb *tcp)
1333{
1334 if (entering(tcp)) {
1335 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1336 tcp->u_arg[1], tcp->u_arg[2]);
1337 } else {
1338 int len;
1339
1340 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1341 tprintf("%#lx, %#lx",
1342 tcp->u_arg[3], tcp->u_arg[4]);
1343 } else {
1344 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1345 tcp->u_arg[3], len);
1346 }
John Hughes38ae88d2002-05-23 11:48:58 +00001347 }
1348 return 0;
1349}
1350
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001351#ifdef PACKET_RX_RING
1352static void
1353print_tpacket_req(struct tcb *tcp, long addr, int len)
1354{
1355 struct tpacket_req req;
1356
1357 if (len != sizeof(req) ||
1358 umove(tcp, addr, &req) < 0) {
1359 tprintf("%#lx", addr);
1360 } else {
1361 tprintf("{block_size=%u, block_nr=%u, "
1362 "frame_size=%u, frame_nr=%u}",
1363 req.tp_block_size,
1364 req.tp_block_nr,
1365 req.tp_frame_size,
1366 req.tp_frame_nr);
1367 }
1368}
1369#endif /* PACKET_RX_RING */
1370
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001371#ifdef PACKET_ADD_MEMBERSHIP
1372# include "xlat/packet_mreq_type.h"
1373
1374static void
1375print_packet_mreq(struct tcb *tcp, long addr, int len)
1376{
1377 struct packet_mreq mreq;
1378
1379 if (len != sizeof(mreq) ||
1380 umove(tcp, addr, &mreq) < 0) {
1381 tprintf("%#lx", addr);
1382 } else {
1383 unsigned int i;
1384
1385 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1386 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1387 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1388 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1389 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1390 for (i = 0; i < mreq.mr_alen; ++i)
1391 tprintf("%02x", mreq.mr_address[i]);
1392 tprints("}");
1393 }
1394}
1395#endif /* PACKET_ADD_MEMBERSHIP */
1396
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001397static void
1398print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1399{
1400 if (addr && verbose(tcp))
1401 switch (level) {
1402 case SOL_SOCKET:
1403 switch (name) {
1404#ifdef SO_LINGER
1405 case SO_LINGER:
1406 print_linger(tcp, addr, len);
1407 goto done;
1408#endif
1409 }
1410 break;
1411
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001412 case SOL_PACKET:
1413 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001414#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001415 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001416# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001417 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001418# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001419 print_tpacket_req(tcp, addr, len);
1420 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001421#endif /* PACKET_RX_RING */
1422#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001423 case PACKET_ADD_MEMBERSHIP:
1424 case PACKET_DROP_MEMBERSHIP:
1425 print_packet_mreq(tcp, addr, len);
1426 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001427#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001428 }
1429 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001430
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001431 case SOL_RAW:
1432 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001433#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001434 case ICMP_FILTER:
1435 print_icmp_filter(tcp, addr, len);
1436 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001437#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001438 }
1439 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001440 }
1441
1442 /* default arg printing */
1443
1444 if (verbose(tcp)) {
1445 if (len == sizeof(int)) {
1446 printnum_int(tcp, addr, "%d");
1447 } else {
1448 printstr(tcp, addr, len);
1449 }
1450 } else {
1451 tprintf("%#lx", addr);
1452 }
1453done:
1454 tprintf(", %d", len);
1455}
1456
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457int
Denys Vlasenko12014262011-05-30 14:00:14 +02001458sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459{
1460 if (entering(tcp)) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001461 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1462 tcp->u_arg[1], tcp->u_arg[2]);
1463 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1464 tcp->u_arg[3], tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465 }
1466 return 0;
1467}