blob: b9733a0eed6151665c8a38ce1c338a7fe67b012e [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. Levind9177df2015-01-29 07:34:40 +0000288 print_quoted_string(addrbuf.sau.sun_path,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000289 sizeof(addrbuf.sau.sun_path) + 1,
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000290 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000291 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000292 tprints("sun_path=@");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000293 print_quoted_string(addrbuf.sau.sun_path + 1,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000294 sizeof(addrbuf.sau.sun_path),
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000295 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000296 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000297 break;
298 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000299 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000300 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000302#ifdef HAVE_INET_NTOP
303 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000304 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000305 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
306 ntohs(addrbuf.sa6.sin6_port), string_addr,
307 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000308#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000309 {
310#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200311 int numericscope = 0;
312 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
313 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
314 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000315
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200316 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
317 numericscope++;
Dmitry V. Levin0e9d5942015-01-24 20:23:02 +0000318 else {
319 tprints(", sin6_scope_id=if_nametoindex(");
320 print_quoted_string(scopebuf,
321 sizeof(scopebuf),
322 QUOTE_0_TERMINATED);
323 tprints(")");
324 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200325 } else
326 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000327
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200328 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000329#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200330 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000331 }
332#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200333 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000334#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100335#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000337 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000339 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000340 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341 /* Yes, I know, this does not look too
342 * strace-ish, but otherwise the IPX
343 * addresses just look monstrous...
344 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000345 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000347 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200348 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000349 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
350 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351 }
352 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100353#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000354#ifdef AF_PACKET
355 case AF_PACKET:
356 {
357 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000358 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000359 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000360 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000361 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000362 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000363 addrbuf.ll.sll_halen,
364 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200365 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000366 tprintf("%02x", addrbuf.ll.sll_addr[i]);
367 }
368 break;
369
Denys Vlasenko84703742012-02-25 02:38:52 +0100370#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000371#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000372 case AF_NETLINK:
373 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
374 break;
375#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200376#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
377 case AF_BLUETOOTH:
378 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
379 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
380 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
381 "{hci_dev=htobs(%d)}",
382 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
383 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
384 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
385 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
386 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
387 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
388 addrbuf.rc.rc_channel,
389 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
390 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
391 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
392 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
393 btohs(addrbuf.hci.hci_dev));
394 break;
395#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000397 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398
399 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200400 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000402 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 break;
404 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200405 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406}
407
408#if HAVE_SENDMSG
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000409# ifndef SCM_SECURITY
410# define SCM_SECURITY 0x03
411# endif
412# include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000413
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000414#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
415struct cmsghdr32 {
416 uint32_t cmsg_len;
417 int cmsg_level;
418 int cmsg_type;
419};
420#endif
421
422typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000423 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000424 struct cmsghdr *cmsg;
425#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
426 struct cmsghdr32 *cmsg32;
427#endif
428} union_cmsghdr;
429
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000430static bool
431print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000432{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000433 if (cmsg_size + sizeof(int) > cmsg_len)
434 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000435
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000436 int *fds = (int *) (ptr + cmsg_size);
437 bool seen = false;
438
439 tprints(", [");
440 while ((char *) fds < (ptr + cmsg_len)) {
441 if (seen)
442 tprints(", ");
443 else
444 seen = true;
445 printfd(tcp, *fds++);
446 }
447 tprints("]}");
448 return true;
449}
450
451static bool
452print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
453{
454 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
455 return false;
456
457 const struct ucred *uc = (void *) (ptr + cmsg_size);
458
459 tprintf(", {pid=%u, uid=%u, gid=%u}}",
460 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
461 return true;
462}
463
464static bool
465print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
466{
467 if (cmsg_size + sizeof(char) > cmsg_len)
468 return false;
469
470 const char *label = (const char *) (ptr + cmsg_size);
471 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000472
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000473 tprints(", ");
474 print_quoted_string(label, label_len, 0);
475 tprints("}");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000476
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000477 return true;
478}
479
480static void
481printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
482{
483 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000484#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
485 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
486#endif
487 sizeof(struct cmsghdr);
488
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000489 char *buf = len < cmsg_size ? NULL : malloc(len);
490 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000491 tprintf(", msg_control=%#lx", addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000492 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000493 return;
494 }
495
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000496 union_cmsghdr u = { .ptr = buf };
497
498 tprints(", [");
499 while (len >= cmsg_size) {
500 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000501#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000502 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000503#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000504 u.cmsg->cmsg_len;
505 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000506#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000507 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000508#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000509 u.cmsg->cmsg_level;
510 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000511#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000512 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000513#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000514 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000515
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000516 if (u.ptr != buf)
517 tprints(", ");
518 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
519 printxval(socketlayers, cmsg_level, "SOL_???");
520 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000521
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000522 if (cmsg_len > len)
523 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000524
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000525 if (cmsg_level == SOL_SOCKET) {
526 printxval(scmvals, cmsg_type, "SCM_???");
527 switch (cmsg_type) {
528 case SCM_RIGHTS:
529 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
530 goto next_cmsg;
531 break;
532 case SCM_CREDENTIALS:
533 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
534 goto next_cmsg;
535 break;
536 case SCM_SECURITY:
537 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
538 goto next_cmsg;
539 break;
Roland McGrath50770822004-10-06 22:11:51 +0000540 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000541 } else {
542 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000543 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000544 tprints(", ...}");
545next_cmsg:
546 if (cmsg_len < cmsg_size) {
547 len -= cmsg_size;
548 break;
Roland McGrath50770822004-10-06 22:11:51 +0000549 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000550 cmsg_len = (cmsg_len + current_wordsize - 1) &
551 (size_t) ~(current_wordsize - 1);
552 if (cmsg_len >= len) {
553 len = 0;
554 break;
555 }
556 u.ptr += cmsg_len;
557 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000558 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000559 if (len)
560 tprints(", ...");
561 tprints("]");
562 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000563}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564
565static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200566do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100567{
568 tprintf("{msg_name(%d)=", msg->msg_namelen);
569 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
570
571 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200572 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
573 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100574
575#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
576 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
577 if (msg->msg_controllen)
578 printcmsghdr(tcp, (unsigned long) msg->msg_control,
579 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200580 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100581 printflags(msg_flags, msg->msg_flags, "MSG_???");
582#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
583 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
584 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
585#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200586 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100587}
588
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100589struct msghdr32 {
590 uint32_t /* void* */ msg_name;
591 uint32_t /* socklen_t */msg_namelen;
592 uint32_t /* iovec* */ msg_iov;
593 uint32_t /* size_t */ msg_iovlen;
594 uint32_t /* void* */ msg_control;
595 uint32_t /* size_t */ msg_controllen;
596 uint32_t /* int */ msg_flags;
597};
598struct mmsghdr32 {
599 struct msghdr32 msg_hdr;
600 uint32_t /* unsigned */ msg_len;
601};
602
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900603#ifndef HAVE_STRUCT_MMSGHDR
604struct mmsghdr {
605 struct msghdr msg_hdr;
606 unsigned msg_len;
607};
608#endif
609
Masatake YAMATOb2485432014-11-07 01:23:24 +0900610#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
611static void
612copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
613{
614 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
615 to_msg->msg_namelen = from_msg32->msg_namelen;
616 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
617 to_msg->msg_iovlen = from_msg32->msg_iovlen;
618 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
619 to_msg->msg_controllen = from_msg32->msg_controllen;
620 to_msg->msg_flags = from_msg32->msg_flags;
621}
622#endif
623
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900624static bool
625extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
626{
627#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
628 if (current_wordsize == 4) {
629 struct msghdr32 msg32;
630
631 if (umove(tcp, addr, &msg32) < 0)
632 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900633 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900634 } else
635#endif
636 if (umove(tcp, addr, msg) < 0)
637 return false;
638 return true;
639}
640
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900641static bool
642extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
643{
644#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
645 if (current_wordsize == 4) {
646 struct mmsghdr32 mmsg32;
647
648 addr += sizeof(struct mmsghdr32) * idx;
649 if (umove(tcp, addr, &mmsg32) < 0)
650 return false;
651
652 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
653 mmsg->msg_len = mmsg32.msg_len;
654 } else
655#endif
656 {
657 addr += sizeof(*mmsg) * idx;
658 if (umove(tcp, addr, mmsg) < 0)
659 return false;
660 }
661 return true;
662}
663
Andreas Schwab0873f292010-02-12 21:39:12 +0100664static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200665printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666{
667 struct msghdr msg;
668
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000669 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900670 do_msghdr(tcp, &msg, data_size);
671 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000672 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900673}
674
675void
676dumpiov_in_msghdr(struct tcb *tcp, long addr)
677{
678 struct msghdr msg;
679
680 if (extractmsghdr(tcp, addr, &msg))
681 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682}
683
Andreas Schwab0873f292010-02-12 21:39:12 +0100684static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000685printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100686{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900687 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100688
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900689 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
690 tprints("{");
691 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
692 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100693 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900694 else
695 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100696}
Andreas Schwab0873f292010-02-12 21:39:12 +0100697
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000698static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000699decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000700{
701 /* mmsgvec */
702 if (syserror(tcp)) {
703 tprintf("%#lx", tcp->u_arg[1]);
704 } else {
705 unsigned int len = tcp->u_rval;
706 unsigned int i;
707
708 tprints("{");
709 for (i = 0; i < len; ++i) {
710 if (i)
711 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000712 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000713 }
714 tprints("}");
715 }
716 /* vlen */
717 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
718 /* flags */
719 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
720}
721
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900722void
723dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
724{
725 unsigned int len = tcp->u_rval;
726 unsigned int i;
727 struct mmsghdr mmsg;
728
729 for (i = 0; i < len; ++i) {
730 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
731 tprintf(" = %lu buffers in vector %u\n",
732 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
733 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
734 (long)mmsg.msg_hdr.msg_iov);
735 }
736 }
737}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738#endif /* HAVE_SENDMSG */
739
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000740/*
741 * low bits of the socket type define real socket type,
742 * other bits are socket type flags.
743 */
744static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000745tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000746{
747 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
748
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200749 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200750 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000751 flags &= ~SOCK_TYPE_MASK;
752 if (!flags)
753 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200754 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000755 }
756 printflags(sock_type_flags, flags, "SOCK_???");
757}
758
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000760sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761{
762 if (entering(tcp)) {
763 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200764 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000765 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200766 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767 switch (tcp->u_arg[0]) {
768 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000769#ifdef PF_INET6
770 case PF_INET6:
771#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900772 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000773 break;
774#ifdef PF_IPX
775 case PF_IPX:
776 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200777 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200779 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780 break;
781#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900782#ifdef PF_NETLINK
783 case PF_NETLINK:
784 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
785 break;
786#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200787#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
788 case PF_BLUETOOTH:
789 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
790 break;
791#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792 default:
793 tprintf("%lu", tcp->u_arg[2]);
794 break;
795 }
796 }
797 return 0;
798}
799
John Hughesbdf48f52001-03-06 15:08:09 +0000800int
Denys Vlasenko12014262011-05-30 14:00:14 +0200801sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802{
803 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800804 printfd(tcp, tcp->u_arg[0]);
805 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000806 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 tprintf(", %lu", tcp->u_arg[2]);
808 }
809 return 0;
810}
811
812int
Denys Vlasenko12014262011-05-30 14:00:14 +0200813sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814{
815 return sys_bind(tcp);
816}
817
818int
Denys Vlasenko12014262011-05-30 14:00:14 +0200819sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820{
821 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800822 printfd(tcp, tcp->u_arg[0]);
823 tprints(", ");
824 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 }
826 return 0;
827}
828
Paolo Bonzini705ff102009-08-14 12:34:05 +0200829static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000830do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831{
832 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800833 printfd(tcp, tcp->u_arg[0]);
834 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200835 return 0;
836 }
837 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838 tprintf("%#lx, NULL", tcp->u_arg[1]);
839 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000840 int len;
841 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200842 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843 tprintf("%#lx", tcp->u_arg[1]);
844 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000845 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200847 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000848 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200850 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200851 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200852 printflags(sock_type_flags, tcp->u_arg[flags_arg],
853 "SOCK_???");
854 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855 return 0;
856}
857
858int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200859sys_accept(struct tcb *tcp)
860{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000861 do_sockname(tcp, -1);
862 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200863}
864
Paolo Bonzini705ff102009-08-14 12:34:05 +0200865int
866sys_accept4(struct tcb *tcp)
867{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000868 do_sockname(tcp, 3);
869 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200870}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200871
872int
Denys Vlasenko12014262011-05-30 14:00:14 +0200873sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874{
875 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800876 printfd(tcp, tcp->u_arg[0]);
877 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
879 tprintf(", %lu, ", tcp->u_arg[2]);
880 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000881 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882 }
883 return 0;
884}
885
886int
Denys Vlasenko12014262011-05-30 14:00:14 +0200887sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000888{
889 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800890 printfd(tcp, tcp->u_arg[0]);
891 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000892 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
893 tprintf(", %lu, ", tcp->u_arg[2]);
894 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000895 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000896 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200897 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000898 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899 /* to length */
900 tprintf(", %lu", tcp->u_arg[5]);
901 }
902 return 0;
903}
904
905#ifdef HAVE_SENDMSG
906
907int
Denys Vlasenko12014262011-05-30 14:00:14 +0200908sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000909{
910 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800911 printfd(tcp, tcp->u_arg[0]);
912 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000913 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200915 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000916 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917 }
918 return 0;
919}
920
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000921int
922sys_sendmmsg(struct tcb *tcp)
923{
924 if (entering(tcp)) {
925 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800926 printfd(tcp, tcp->u_arg[0]);
927 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000928 if (!verbose(tcp)) {
929 tprintf("%#lx, %u, ",
930 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
931 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
932 }
933 } else {
934 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000935 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000936 }
937 return 0;
938}
939
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000940#endif /* HAVE_SENDMSG */
941
942int
Denys Vlasenko12014262011-05-30 14:00:14 +0200943sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944{
945 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800946 printfd(tcp, tcp->u_arg[0]);
947 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948 } else {
949 if (syserror(tcp))
950 tprintf("%#lx", tcp->u_arg[1]);
951 else
952 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
953
954 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000955 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 }
957 return 0;
958}
959
960int
Denys Vlasenko12014262011-05-30 14:00:14 +0200961sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962{
963 int fromlen;
964
965 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800966 printfd(tcp, tcp->u_arg[0]);
967 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 } else {
969 if (syserror(tcp)) {
970 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
971 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
972 tcp->u_arg[4], tcp->u_arg[5]);
973 return 0;
974 }
975 /* buf */
976 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
977 /* len */
978 tprintf(", %lu, ", tcp->u_arg[2]);
979 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000980 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 /* from address, len */
982 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
983 if (tcp->u_arg[4] == 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[4]);
987 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200988 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 else
990 tprintf(", %#lx", tcp->u_arg[5]);
991 return 0;
992 }
993 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200994 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 return 0;
996 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200997 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000998 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999 /* from length */
1000 tprintf(", [%u]", fromlen);
1001 }
1002 return 0;
1003}
1004
1005#ifdef HAVE_SENDMSG
1006
1007int
Denys Vlasenko12014262011-05-30 14:00:14 +02001008sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009{
1010 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001011 printfd(tcp, tcp->u_arg[0]);
1012 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +00001014 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 tprintf("%#lx", tcp->u_arg[1]);
1016 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001017 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001019 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001020 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 }
1022 return 0;
1023}
1024
Andreas Schwab0873f292010-02-12 21:39:12 +01001025int
1026sys_recvmmsg(struct tcb *tcp)
1027{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001028 /* +5 chars are for "left " prefix */
1029 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001030
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001031 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001032 printfd(tcp, tcp->u_arg[0]);
1033 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001034 if (verbose(tcp)) {
1035 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001036 /* Abusing tcp->auxstr as temp storage.
1037 * Will be used and freed on syscall exit.
1038 */
Dmitry V. Levine6591032010-03-29 20:45:48 +04001039 tcp->auxstr = strdup(str);
1040 } else {
1041 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1042 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001043 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001044 print_timespec(tcp, tcp->u_arg[4]);
1045 }
1046 return 0;
1047 } else {
1048 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001049 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001050 /* timeout on entrance */
1051 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1052 free((void *) tcp->auxstr);
1053 tcp->auxstr = NULL;
1054 }
1055 if (syserror(tcp))
1056 return 0;
1057 if (tcp->u_rval == 0) {
1058 tcp->auxstr = "Timeout";
1059 return RVAL_STR;
1060 }
1061 if (!verbose(tcp))
1062 return 0;
1063 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001064 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001065 tcp->auxstr = str;
1066 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001067 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001068}
Andreas Schwab0873f292010-02-12 21:39:12 +01001069
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001070#endif /* HAVE_SENDMSG */
1071
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001072#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001073
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074int
Denys Vlasenko12014262011-05-30 14:00:14 +02001075sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076{
1077 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001078 printfd(tcp, tcp->u_arg[0]);
1079 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001080 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081 }
1082 return 0;
1083}
1084
1085int
Denys Vlasenko12014262011-05-30 14:00:14 +02001086sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001088 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089}
1090
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001091static int
1092do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001093{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 if (exiting(tcp)) {
1095 if (syserror(tcp)) {
1096 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001097 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001098#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001099 int fds[2];
1100
1101 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001102 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001103 else
1104 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001105#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001106 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1107#else
1108 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001109#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001110 }
1111 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001112 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001113 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1114 }
1115 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 return 0;
1117}
1118
1119int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001120sys_pipe(struct tcb *tcp)
1121{
1122 return do_pipe(tcp, -1);
1123}
1124
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001125int
1126sys_pipe2(struct tcb *tcp)
1127{
1128 return do_pipe(tcp, 1);
1129}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001130
1131int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001132sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001133{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001134 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135
1136 if (entering(tcp)) {
1137 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001138 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001139 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001140 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001141 } else {
1142 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001143 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 return 0;
1145 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001146 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001147 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148 else
1149 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001150 }
1151 return 0;
1152}
1153
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001154#include "xlat/sockoptions.h"
1155#include "xlat/sockipoptions.h"
1156#include "xlat/sockipv6options.h"
1157#include "xlat/sockipxoptions.h"
1158#include "xlat/sockrawoptions.h"
1159#include "xlat/sockpacketoptions.h"
1160#include "xlat/socksctpoptions.h"
1161#include "xlat/socktcpoptions.h"
1162
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001163static void
1164print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001165{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001166 printfd(tcp, fd);
1167 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001168 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001169 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001170
John Hughes38ae88d2002-05-23 11:48:58 +00001171 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001172 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001173 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001174 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001175 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001176 printxval(sockipoptions, name, "IP_???");
1177 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001178 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001179 printxval(sockipv6options, name, "IPV6_???");
1180 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001181 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001182 printxval(sockipxoptions, name, "IPX_???");
1183 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001184 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001185 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001186 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001187 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001188 printxval(socktcpoptions, name, "TCP_???");
1189 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001190 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001191 printxval(socksctpoptions, name, "SCTP_???");
1192 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001193 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001194 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001195 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001196
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001197 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001198
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001199 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001200 tprintf("%u", name);
1201 }
1202
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001203 tprints(", ");
1204}
1205
1206#ifdef SO_LINGER
1207static void
1208print_linger(struct tcb *tcp, long addr, int len)
1209{
1210 struct linger linger;
1211
1212 if (len != sizeof(linger) ||
1213 umove(tcp, addr, &linger) < 0) {
1214 tprintf("%#lx", addr);
1215 return;
1216 }
1217
1218 tprintf("{onoff=%d, linger=%d}",
1219 linger.l_onoff,
1220 linger.l_linger);
1221}
1222#endif /* SO_LINGER */
1223
1224#ifdef SO_PEERCRED
1225static void
1226print_ucred(struct tcb *tcp, long addr, int len)
1227{
1228 struct ucred uc;
1229
1230 if (len != sizeof(uc) ||
1231 umove(tcp, addr, &uc) < 0) {
1232 tprintf("%#lx", addr);
1233 } else {
1234 tprintf("{pid=%u, uid=%u, gid=%u}",
1235 (unsigned) uc.pid,
1236 (unsigned) uc.uid,
1237 (unsigned) uc.gid);
1238 }
1239}
1240#endif /* SO_PEERCRED */
1241
1242#ifdef PACKET_STATISTICS
1243static void
1244print_tpacket_stats(struct tcb *tcp, long addr, int len)
1245{
1246 struct tpacket_stats stats;
1247
1248 if (len != sizeof(stats) ||
1249 umove(tcp, addr, &stats) < 0) {
1250 tprintf("%#lx", addr);
1251 } else {
1252 tprintf("{packets=%u, drops=%u}",
1253 stats.tp_packets,
1254 stats.tp_drops);
1255 }
1256}
1257#endif /* PACKET_STATISTICS */
1258
1259#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001260# include "xlat/icmpfilterflags.h"
1261
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001262static void
1263print_icmp_filter(struct tcb *tcp, long addr, int len)
1264{
1265 struct icmp_filter filter;
1266
1267 if (len != sizeof(filter) ||
1268 umove(tcp, addr, &filter) < 0) {
1269 tprintf("%#lx", addr);
1270 return;
1271 }
1272
1273 tprints("~(");
1274 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1275 tprints(")");
1276}
1277#endif /* ICMP_FILTER */
1278
1279static void
1280print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1281{
1282 if (addr && verbose(tcp))
1283 switch (level) {
1284 case SOL_SOCKET:
1285 switch (name) {
1286#ifdef SO_LINGER
1287 case SO_LINGER:
1288 print_linger(tcp, addr, len);
1289 goto done;
1290#endif
1291#ifdef SO_PEERCRED
1292 case SO_PEERCRED:
1293 print_ucred(tcp, addr, len);
1294 goto done;
1295#endif
1296 }
1297 break;
1298
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001299 case SOL_PACKET:
1300 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001301#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001302 case PACKET_STATISTICS:
1303 print_tpacket_stats(tcp, addr, len);
1304 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001305#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001306 }
1307 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001308
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001309 case SOL_RAW:
1310 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001311#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001312 case ICMP_FILTER:
1313 print_icmp_filter(tcp, addr, len);
1314 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001315#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001316 }
1317 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001318 }
1319
John Hughes38ae88d2002-05-23 11:48:58 +00001320 /* default arg printing */
1321
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001322 if (verbose(tcp)) {
1323 if (len == sizeof(int)) {
1324 printnum_int(tcp, addr, "%d");
1325 } else {
1326 printstr(tcp, addr, len);
1327 }
1328 } else {
1329 tprintf("%#lx", addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001330 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001331done:
1332 tprintf(", [%d]", len);
1333}
1334
1335int
1336sys_getsockopt(struct tcb *tcp)
1337{
1338 if (entering(tcp)) {
1339 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1340 tcp->u_arg[1], tcp->u_arg[2]);
1341 } else {
1342 int len;
1343
1344 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1345 tprintf("%#lx, %#lx",
1346 tcp->u_arg[3], tcp->u_arg[4]);
1347 } else {
1348 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1349 tcp->u_arg[3], len);
1350 }
John Hughes38ae88d2002-05-23 11:48:58 +00001351 }
1352 return 0;
1353}
1354
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001355#ifdef MCAST_JOIN_GROUP
1356static void
1357print_group_req(struct tcb *tcp, long addr, int len)
1358{
1359 struct group_req greq;
1360
1361 if (len != sizeof(greq) ||
1362 umove(tcp, addr, &greq) < 0) {
1363 tprintf("%#lx", addr);
1364 return;
1365 }
1366
1367 union {
1368 struct sockaddr *sa;
1369 struct sockaddr_in *sin;
1370#ifdef HAVE_INET_NTOP
1371 struct sockaddr_in6 *sin6;
1372#endif
1373 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1374#ifdef HAVE_INET_NTOP
1375 char str[INET6_ADDRSTRLEN];
1376#endif
1377
1378 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1379 printxval(addrfams, a.sa->sa_family, "AF_???");
1380
1381 switch (a.sa->sa_family) {
1382 case AF_INET:
1383 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1384 ntohs(a.sin->sin_port),
1385 inet_ntoa(a.sin->sin_addr));
1386 return;
1387#ifdef HAVE_INET_NTOP
1388 case AF_INET6:
1389 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1390 break;
1391 tprintf(", sin6_port=htons(%u)"
1392 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1393 ntohs(a.sin6->sin6_port), str);
1394 return;
1395#endif /* HAVE_INET_NTOP */
1396 }
1397
1398 tprints(", sa_data=");
1399 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1400 tprintf("}}");
1401
1402}
1403#endif /* MCAST_JOIN_GROUP */
1404
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001405#ifdef PACKET_RX_RING
1406static void
1407print_tpacket_req(struct tcb *tcp, long addr, int len)
1408{
1409 struct tpacket_req req;
1410
1411 if (len != sizeof(req) ||
1412 umove(tcp, addr, &req) < 0) {
1413 tprintf("%#lx", addr);
1414 } else {
1415 tprintf("{block_size=%u, block_nr=%u, "
1416 "frame_size=%u, frame_nr=%u}",
1417 req.tp_block_size,
1418 req.tp_block_nr,
1419 req.tp_frame_size,
1420 req.tp_frame_nr);
1421 }
1422}
1423#endif /* PACKET_RX_RING */
1424
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001425#ifdef PACKET_ADD_MEMBERSHIP
1426# include "xlat/packet_mreq_type.h"
1427
1428static void
1429print_packet_mreq(struct tcb *tcp, long addr, int len)
1430{
1431 struct packet_mreq mreq;
1432
1433 if (len != sizeof(mreq) ||
1434 umove(tcp, addr, &mreq) < 0) {
1435 tprintf("%#lx", addr);
1436 } else {
1437 unsigned int i;
1438
1439 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1440 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1441 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1442 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1443 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1444 for (i = 0; i < mreq.mr_alen; ++i)
1445 tprintf("%02x", mreq.mr_address[i]);
1446 tprints("}");
1447 }
1448}
1449#endif /* PACKET_ADD_MEMBERSHIP */
1450
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001451static void
1452print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1453{
1454 if (addr && verbose(tcp))
1455 switch (level) {
1456 case SOL_SOCKET:
1457 switch (name) {
1458#ifdef SO_LINGER
1459 case SO_LINGER:
1460 print_linger(tcp, addr, len);
1461 goto done;
1462#endif
1463 }
1464 break;
1465
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001466 case SOL_IP:
1467 switch (name) {
1468#ifdef MCAST_JOIN_GROUP
1469 case MCAST_JOIN_GROUP:
1470 case MCAST_LEAVE_GROUP:
1471 print_group_req(tcp, addr, len);
1472 goto done;
1473#endif /* MCAST_JOIN_GROUP */
1474 }
1475
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001476 case SOL_PACKET:
1477 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001478#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001479 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001480# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001481 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001482# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001483 print_tpacket_req(tcp, addr, len);
1484 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001485#endif /* PACKET_RX_RING */
1486#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001487 case PACKET_ADD_MEMBERSHIP:
1488 case PACKET_DROP_MEMBERSHIP:
1489 print_packet_mreq(tcp, addr, len);
1490 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001491#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001492 }
1493 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001494
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001495 case SOL_RAW:
1496 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001497#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001498 case ICMP_FILTER:
1499 print_icmp_filter(tcp, addr, len);
1500 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001501#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001502 }
1503 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001504 }
1505
1506 /* default arg printing */
1507
1508 if (verbose(tcp)) {
1509 if (len == sizeof(int)) {
1510 printnum_int(tcp, addr, "%d");
1511 } else {
1512 printstr(tcp, addr, len);
1513 }
1514 } else {
1515 tprintf("%#lx", addr);
1516 }
1517done:
1518 tprintf(", %d", len);
1519}
1520
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521int
Denys Vlasenko12014262011-05-30 14:00:14 +02001522sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001523{
1524 if (entering(tcp)) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001525 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1526 tcp->u_arg[1], tcp->u_arg[2]);
1527 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1528 tcp->u_arg[3], tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529 }
1530 return 0;
1531}