blob: 1de3cb33434da2c5eb87f93b2d80bcd0d6c9a681 [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. Levin0ed617b2014-04-25 23:30:54 +0000109#include "xlat/socketlayers.h"
John Hughes93f7fcc2002-05-22 15:46:49 +0000110/*** WARNING: DANGER WILL ROBINSON: NOTE "socketlayers" array above
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900111 falls into "inet_protocols" array below!!!! This is intended!!! ***/
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000112#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900113
114#ifdef PF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +0000115# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
116# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
117# endif
118# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900119#endif
120
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200121#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
122# include "xlat/bt_protocols.h"
123#endif
124
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000125#include "xlat/msg_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000126#include "xlat/sockoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000127
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100128#if !defined(SOL_IP) && defined(IPPROTO_IP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000129#define SOL_IP IPPROTO_IP
130#endif
131
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000132#ifdef SOL_IP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000133#include "xlat/sockipoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000134#endif /* SOL_IP */
135
Roland McGrath4f6ba692004-08-31 07:01:26 +0000136#ifdef SOL_IPV6
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000137#include "xlat/sockipv6options.h"
Roland McGrath4f6ba692004-08-31 07:01:26 +0000138#endif /* SOL_IPV6 */
139
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140#ifdef SOL_IPX
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000141#include "xlat/sockipxoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#endif /* SOL_IPX */
143
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000144#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000145#include "xlat/sockrawoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000146#endif /* SOL_RAW */
147
148#ifdef SOL_PACKET
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000149#include "xlat/sockpacketoptions.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000150#endif /* SOL_PACKET */
151
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100152#ifdef SOL_SCTP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000153#include "xlat/socksctpoptions.h"
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100154#endif
155
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100156#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
John Hughes93f7fcc2002-05-22 15:46:49 +0000157#define SOL_TCP IPPROTO_TCP
158#endif
159
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160#ifdef SOL_TCP
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000161#include "xlat/socktcpoptions.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162#endif /* SOL_TCP */
163
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000164#ifdef SOL_RAW
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000165#include "xlat/icmpfilterflags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000166#endif /* SOL_RAW */
167
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000168#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000169#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000170#endif /* defined(AF_PACKET) */
171
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000173printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000175 union {
176 char pad[128];
177 struct sockaddr sa;
178 struct sockaddr_in sin;
179 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000180#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000181 struct sockaddr_in6 sa6;
182#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100183#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000184 struct sockaddr_ipx sipx;
185#endif
186#ifdef AF_PACKET
187 struct sockaddr_ll ll;
188#endif
189#ifdef AF_NETLINK
190 struct sockaddr_nl nl;
191#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200192#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
193 struct sockaddr_hci hci;
194 struct sockaddr_l2 l2;
195 struct sockaddr_rc rc;
196 struct sockaddr_sco sco;
197#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000198 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000199 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200
201 if (addr == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200202 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 return;
204 }
205 if (!verbose(tcp)) {
206 tprintf("%#lx", addr);
207 return;
208 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000209
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +0000210 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000211 addrlen = sizeof(addrbuf);
212
213 memset(&addrbuf, 0, sizeof(addrbuf));
214 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200215 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 return;
217 }
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000218 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000219
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200220 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000221 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200222 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000223
224 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000226 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200227 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000228 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000229 tprints("sun_path=");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000230 printpathn(tcp, addr + 2, strlen(addrbuf.sau.sun_path));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000231 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000232 tprints("sun_path=@");
Dmitry V. Levin16fbe972007-10-13 21:03:17 +0000233 printpathn(tcp, addr + 3, strlen(addrbuf.sau.sun_path + 1));
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000234 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 break;
236 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000237 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000238 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000240#ifdef HAVE_INET_NTOP
241 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000242 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000243 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
244 ntohs(addrbuf.sa6.sin6_port), string_addr,
245 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000246#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Wichert Akkermanf1850652001-02-16 20:29:03 +0000247 {
248#if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200249 int numericscope = 0;
250 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
251 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
252 char scopebuf[IFNAMSIZ + 1];
Roland McGrath6d2b3492002-12-30 00:51:30 +0000253
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200254 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
255 numericscope++;
Dmitry V. Levin0e9d5942015-01-24 20:23:02 +0000256 else {
257 tprints(", sin6_scope_id=if_nametoindex(");
258 print_quoted_string(scopebuf,
259 sizeof(scopebuf),
260 QUOTE_0_TERMINATED);
261 tprints(")");
262 }
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 } else
264 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000265
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200266 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000267#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200268 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000269 }
270#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200271 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000272#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100273#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000275 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000277 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000278 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279 /* Yes, I know, this does not look too
280 * strace-ish, but otherwise the IPX
281 * addresses just look monstrous...
282 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000283 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000285 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200286 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000287 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
288 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000289 }
290 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100291#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000292#ifdef AF_PACKET
293 case AF_PACKET:
294 {
295 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000296 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000297 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000298 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000299 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000300 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000301 addrbuf.ll.sll_halen,
302 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200303 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000304 tprintf("%02x", addrbuf.ll.sll_addr[i]);
305 }
306 break;
307
Denys Vlasenko84703742012-02-25 02:38:52 +0100308#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000309#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000310 case AF_NETLINK:
311 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
312 break;
313#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200314#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
315 case AF_BLUETOOTH:
316 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
317 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
318 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
319 "{hci_dev=htobs(%d)}",
320 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
321 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
322 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
323 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
324 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
325 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
326 addrbuf.rc.rc_channel,
327 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
328 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
329 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
330 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
331 btohs(addrbuf.hci.hci_dev));
332 break;
333#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336
337 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200338 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000340 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341 break;
342 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200343 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344}
345
346#if HAVE_SENDMSG
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000347# ifndef SCM_SECURITY
348# define SCM_SECURITY 0x03
349# endif
350# include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000351
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000352#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
353struct cmsghdr32 {
354 uint32_t cmsg_len;
355 int cmsg_level;
356 int cmsg_type;
357};
358#endif
359
360typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000361 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000362 struct cmsghdr *cmsg;
363#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
364 struct cmsghdr32 *cmsg32;
365#endif
366} union_cmsghdr;
367
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000368static bool
369print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000370{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000371 if (cmsg_size + sizeof(int) > cmsg_len)
372 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000373
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000374 int *fds = (int *) (ptr + cmsg_size);
375 bool seen = false;
376
377 tprints(", [");
378 while ((char *) fds < (ptr + cmsg_len)) {
379 if (seen)
380 tprints(", ");
381 else
382 seen = true;
383 printfd(tcp, *fds++);
384 }
385 tprints("]}");
386 return true;
387}
388
389static bool
390print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
391{
392 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
393 return false;
394
395 const struct ucred *uc = (void *) (ptr + cmsg_size);
396
397 tprintf(", {pid=%u, uid=%u, gid=%u}}",
398 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
399 return true;
400}
401
402static bool
403print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
404{
405 if (cmsg_size + sizeof(char) > cmsg_len)
406 return false;
407
408 const char *label = (const char *) (ptr + cmsg_size);
409 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000410
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000411 tprints(", ");
412 print_quoted_string(label, label_len, 0);
413 tprints("}");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000414
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000415 return true;
416}
417
418static void
419printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
420{
421 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000422#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
423 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
424#endif
425 sizeof(struct cmsghdr);
426
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000427 char *buf = len < cmsg_size ? NULL : malloc(len);
428 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000429 tprintf(", msg_control=%#lx", addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000430 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000431 return;
432 }
433
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000434 union_cmsghdr u = { .ptr = buf };
435
436 tprints(", [");
437 while (len >= cmsg_size) {
438 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000439#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000440 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000441#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000442 u.cmsg->cmsg_len;
443 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000444#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000445 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000446#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000447 u.cmsg->cmsg_level;
448 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000449#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000450 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000451#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000452 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000453
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000454 if (u.ptr != buf)
455 tprints(", ");
456 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
457 printxval(socketlayers, cmsg_level, "SOL_???");
458 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000459
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000460 if (cmsg_len > len)
461 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000462
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000463 if (cmsg_level == SOL_SOCKET) {
464 printxval(scmvals, cmsg_type, "SCM_???");
465 switch (cmsg_type) {
466 case SCM_RIGHTS:
467 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
468 goto next_cmsg;
469 break;
470 case SCM_CREDENTIALS:
471 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
472 goto next_cmsg;
473 break;
474 case SCM_SECURITY:
475 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
476 goto next_cmsg;
477 break;
Roland McGrath50770822004-10-06 22:11:51 +0000478 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000479 } else {
480 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000481 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000482 tprints(", ...}");
483next_cmsg:
484 if (cmsg_len < cmsg_size) {
485 len -= cmsg_size;
486 break;
Roland McGrath50770822004-10-06 22:11:51 +0000487 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000488 cmsg_len = (cmsg_len + current_wordsize - 1) &
489 (size_t) ~(current_wordsize - 1);
490 if (cmsg_len >= len) {
491 len = 0;
492 break;
493 }
494 u.ptr += cmsg_len;
495 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000496 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000497 if (len)
498 tprints(", ...");
499 tprints("]");
500 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000501}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502
503static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200504do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100505{
506 tprintf("{msg_name(%d)=", msg->msg_namelen);
507 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
508
509 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200510 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
511 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100512
513#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
514 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
515 if (msg->msg_controllen)
516 printcmsghdr(tcp, (unsigned long) msg->msg_control,
517 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100519 printflags(msg_flags, msg->msg_flags, "MSG_???");
520#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
521 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
522 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
523#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200524 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100525}
526
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100527struct msghdr32 {
528 uint32_t /* void* */ msg_name;
529 uint32_t /* socklen_t */msg_namelen;
530 uint32_t /* iovec* */ msg_iov;
531 uint32_t /* size_t */ msg_iovlen;
532 uint32_t /* void* */ msg_control;
533 uint32_t /* size_t */ msg_controllen;
534 uint32_t /* int */ msg_flags;
535};
536struct mmsghdr32 {
537 struct msghdr32 msg_hdr;
538 uint32_t /* unsigned */ msg_len;
539};
540
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900541#ifndef HAVE_STRUCT_MMSGHDR
542struct mmsghdr {
543 struct msghdr msg_hdr;
544 unsigned msg_len;
545};
546#endif
547
Masatake YAMATOb2485432014-11-07 01:23:24 +0900548#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
549static void
550copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
551{
552 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
553 to_msg->msg_namelen = from_msg32->msg_namelen;
554 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
555 to_msg->msg_iovlen = from_msg32->msg_iovlen;
556 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
557 to_msg->msg_controllen = from_msg32->msg_controllen;
558 to_msg->msg_flags = from_msg32->msg_flags;
559}
560#endif
561
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900562static bool
563extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
564{
565#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
566 if (current_wordsize == 4) {
567 struct msghdr32 msg32;
568
569 if (umove(tcp, addr, &msg32) < 0)
570 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900571 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900572 } else
573#endif
574 if (umove(tcp, addr, msg) < 0)
575 return false;
576 return true;
577}
578
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900579static bool
580extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
581{
582#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
583 if (current_wordsize == 4) {
584 struct mmsghdr32 mmsg32;
585
586 addr += sizeof(struct mmsghdr32) * idx;
587 if (umove(tcp, addr, &mmsg32) < 0)
588 return false;
589
590 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
591 mmsg->msg_len = mmsg32.msg_len;
592 } else
593#endif
594 {
595 addr += sizeof(*mmsg) * idx;
596 if (umove(tcp, addr, mmsg) < 0)
597 return false;
598 }
599 return true;
600}
601
Andreas Schwab0873f292010-02-12 21:39:12 +0100602static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200603printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604{
605 struct msghdr msg;
606
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000607 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900608 do_msghdr(tcp, &msg, data_size);
609 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000610 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900611}
612
613void
614dumpiov_in_msghdr(struct tcb *tcp, long addr)
615{
616 struct msghdr msg;
617
618 if (extractmsghdr(tcp, addr, &msg))
619 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620}
621
Andreas Schwab0873f292010-02-12 21:39:12 +0100622static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000623printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100624{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900625 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100626
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900627 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
628 tprints("{");
629 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
630 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100631 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900632 else
633 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100634}
Andreas Schwab0873f292010-02-12 21:39:12 +0100635
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000636static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000637decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000638{
639 /* mmsgvec */
640 if (syserror(tcp)) {
641 tprintf("%#lx", tcp->u_arg[1]);
642 } else {
643 unsigned int len = tcp->u_rval;
644 unsigned int i;
645
646 tprints("{");
647 for (i = 0; i < len; ++i) {
648 if (i)
649 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000650 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000651 }
652 tprints("}");
653 }
654 /* vlen */
655 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
656 /* flags */
657 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
658}
659
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900660void
661dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
662{
663 unsigned int len = tcp->u_rval;
664 unsigned int i;
665 struct mmsghdr mmsg;
666
667 for (i = 0; i < len; ++i) {
668 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
669 tprintf(" = %lu buffers in vector %u\n",
670 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
671 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
672 (long)mmsg.msg_hdr.msg_iov);
673 }
674 }
675}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676#endif /* HAVE_SENDMSG */
677
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000678/*
679 * low bits of the socket type define real socket type,
680 * other bits are socket type flags.
681 */
682static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000683tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000684{
685 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
686
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200687 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200688 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000689 flags &= ~SOCK_TYPE_MASK;
690 if (!flags)
691 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200692 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000693 }
694 printflags(sock_type_flags, flags, "SOCK_???");
695}
696
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000698sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699{
700 if (entering(tcp)) {
701 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200702 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000703 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200704 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705 switch (tcp->u_arg[0]) {
706 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000707#ifdef PF_INET6
708 case PF_INET6:
709#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900710 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 break;
712#ifdef PF_IPX
713 case PF_IPX:
714 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200715 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200717 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718 break;
719#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900720#ifdef PF_NETLINK
721 case PF_NETLINK:
722 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
723 break;
724#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200725#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
726 case PF_BLUETOOTH:
727 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
728 break;
729#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000730 default:
731 tprintf("%lu", tcp->u_arg[2]);
732 break;
733 }
734 }
735 return 0;
736}
737
John Hughesbdf48f52001-03-06 15:08:09 +0000738int
Denys Vlasenko12014262011-05-30 14:00:14 +0200739sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740{
741 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800742 printfd(tcp, tcp->u_arg[0]);
743 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000744 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000745 tprintf(", %lu", tcp->u_arg[2]);
746 }
747 return 0;
748}
749
750int
Denys Vlasenko12014262011-05-30 14:00:14 +0200751sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752{
753 return sys_bind(tcp);
754}
755
756int
Denys Vlasenko12014262011-05-30 14:00:14 +0200757sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000758{
759 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800760 printfd(tcp, tcp->u_arg[0]);
761 tprints(", ");
762 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763 }
764 return 0;
765}
766
Paolo Bonzini705ff102009-08-14 12:34:05 +0200767static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000768do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000769{
770 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800771 printfd(tcp, tcp->u_arg[0]);
772 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200773 return 0;
774 }
775 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776 tprintf("%#lx, NULL", tcp->u_arg[1]);
777 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000778 int len;
779 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200780 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000781 tprintf("%#lx", tcp->u_arg[1]);
782 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000783 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000784 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200785 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000786 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000787 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200788 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200789 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200790 printflags(sock_type_flags, tcp->u_arg[flags_arg],
791 "SOCK_???");
792 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793 return 0;
794}
795
796int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200797sys_accept(struct tcb *tcp)
798{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000799 do_sockname(tcp, -1);
800 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200801}
802
Paolo Bonzini705ff102009-08-14 12:34:05 +0200803int
804sys_accept4(struct tcb *tcp)
805{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000806 do_sockname(tcp, 3);
807 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200808}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200809
810int
Denys Vlasenko12014262011-05-30 14:00:14 +0200811sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812{
813 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800814 printfd(tcp, tcp->u_arg[0]);
815 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
817 tprintf(", %lu, ", tcp->u_arg[2]);
818 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000819 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820 }
821 return 0;
822}
823
824int
Denys Vlasenko12014262011-05-30 14:00:14 +0200825sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826{
827 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800828 printfd(tcp, tcp->u_arg[0]);
829 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000830 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
831 tprintf(", %lu, ", tcp->u_arg[2]);
832 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000833 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200835 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000836 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837 /* to length */
838 tprintf(", %lu", tcp->u_arg[5]);
839 }
840 return 0;
841}
842
843#ifdef HAVE_SENDMSG
844
845int
Denys Vlasenko12014262011-05-30 14:00:14 +0200846sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847{
848 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800849 printfd(tcp, tcp->u_arg[0]);
850 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000851 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200853 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000854 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855 }
856 return 0;
857}
858
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000859int
860sys_sendmmsg(struct tcb *tcp)
861{
862 if (entering(tcp)) {
863 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800864 printfd(tcp, tcp->u_arg[0]);
865 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000866 if (!verbose(tcp)) {
867 tprintf("%#lx, %u, ",
868 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
869 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
870 }
871 } else {
872 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000873 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000874 }
875 return 0;
876}
877
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878#endif /* HAVE_SENDMSG */
879
880int
Denys Vlasenko12014262011-05-30 14:00:14 +0200881sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882{
883 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800884 printfd(tcp, tcp->u_arg[0]);
885 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886 } else {
887 if (syserror(tcp))
888 tprintf("%#lx", tcp->u_arg[1]);
889 else
890 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
891
892 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000893 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894 }
895 return 0;
896}
897
898int
Denys Vlasenko12014262011-05-30 14:00:14 +0200899sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000900{
901 int fromlen;
902
903 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800904 printfd(tcp, tcp->u_arg[0]);
905 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000906 } else {
907 if (syserror(tcp)) {
908 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
909 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
910 tcp->u_arg[4], tcp->u_arg[5]);
911 return 0;
912 }
913 /* buf */
914 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
915 /* len */
916 tprintf(", %lu, ", tcp->u_arg[2]);
917 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000918 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919 /* from address, len */
920 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
921 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200922 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923 else
924 tprintf(", %#lx", tcp->u_arg[4]);
925 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200926 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927 else
928 tprintf(", %#lx", tcp->u_arg[5]);
929 return 0;
930 }
931 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200932 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933 return 0;
934 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200935 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000936 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000937 /* from length */
938 tprintf(", [%u]", fromlen);
939 }
940 return 0;
941}
942
943#ifdef HAVE_SENDMSG
944
945int
Denys Vlasenko12014262011-05-30 14:00:14 +0200946sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947{
948 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800949 printfd(tcp, tcp->u_arg[0]);
950 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000951 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000952 if (syserror(tcp))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 tprintf("%#lx", tcp->u_arg[1]);
954 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200955 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200957 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000958 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000959 }
960 return 0;
961}
962
Andreas Schwab0873f292010-02-12 21:39:12 +0100963int
964sys_recvmmsg(struct tcb *tcp)
965{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100966 /* +5 chars are for "left " prefix */
967 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400968
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100969 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800970 printfd(tcp, tcp->u_arg[0]);
971 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400972 if (verbose(tcp)) {
973 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100974 /* Abusing tcp->auxstr as temp storage.
975 * Will be used and freed on syscall exit.
976 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400977 tcp->auxstr = strdup(str);
978 } else {
979 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
980 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200981 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400982 print_timespec(tcp, tcp->u_arg[4]);
983 }
984 return 0;
985 } else {
986 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000987 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400988 /* timeout on entrance */
989 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
990 free((void *) tcp->auxstr);
991 tcp->auxstr = NULL;
992 }
993 if (syserror(tcp))
994 return 0;
995 if (tcp->u_rval == 0) {
996 tcp->auxstr = "Timeout";
997 return RVAL_STR;
998 }
999 if (!verbose(tcp))
1000 return 0;
1001 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001002 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001003 tcp->auxstr = str;
1004 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001005 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001006}
Andreas Schwab0873f292010-02-12 21:39:12 +01001007
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008#endif /* HAVE_SENDMSG */
1009
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001010#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001011
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012int
Denys Vlasenko12014262011-05-30 14:00:14 +02001013sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014{
1015 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001016 printfd(tcp, tcp->u_arg[0]);
1017 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001018 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 }
1020 return 0;
1021}
1022
1023int
Denys Vlasenko12014262011-05-30 14:00:14 +02001024sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001026 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027}
1028
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001029static int
1030do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032 if (exiting(tcp)) {
1033 if (syserror(tcp)) {
1034 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001035 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001036#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001037 int fds[2];
1038
1039 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001040 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001041 else
1042 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001043#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001044 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1045#else
1046 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001048 }
1049 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001050 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001051 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1052 }
1053 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 return 0;
1055}
1056
1057int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001058sys_pipe(struct tcb *tcp)
1059{
1060 return do_pipe(tcp, -1);
1061}
1062
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001063int
1064sys_pipe2(struct tcb *tcp)
1065{
1066 return do_pipe(tcp, 1);
1067}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001068
1069int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001070sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073
1074 if (entering(tcp)) {
1075 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001076 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001077 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001078 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079 } else {
1080 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001081 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082 return 0;
1083 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001084 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001085 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086 else
1087 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088 }
1089 return 0;
1090}
1091
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001092static void
1093print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001095 printfd(tcp, fd);
1096 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001097 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001098 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001099
John Hughes38ae88d2002-05-23 11:48:58 +00001100 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001101 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001102 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001103 break;
1104#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001105 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001106 printxval(sockipoptions, name, "IP_???");
1107 break;
1108#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001109#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001110 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001111 printxval(sockipv6options, name, "IPV6_???");
1112 break;
1113#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001114#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001115 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001116 printxval(sockipxoptions, name, "IPX_???");
1117 break;
1118#endif
1119#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001120 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001121 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001122 break;
1123#endif
1124#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001125 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001126 printxval(socktcpoptions, name, "TCP_???");
1127 break;
1128#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001129#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001130 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001131 printxval(socksctpoptions, name, "SCTP_???");
1132 break;
1133#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001134#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001135 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001136 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001137 break;
1138#endif
1139
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001140 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001141
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001142 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001143 tprintf("%u", name);
1144 }
1145
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001146 tprints(", ");
1147}
1148
1149#ifdef SO_LINGER
1150static void
1151print_linger(struct tcb *tcp, long addr, int len)
1152{
1153 struct linger linger;
1154
1155 if (len != sizeof(linger) ||
1156 umove(tcp, addr, &linger) < 0) {
1157 tprintf("%#lx", addr);
1158 return;
1159 }
1160
1161 tprintf("{onoff=%d, linger=%d}",
1162 linger.l_onoff,
1163 linger.l_linger);
1164}
1165#endif /* SO_LINGER */
1166
1167#ifdef SO_PEERCRED
1168static void
1169print_ucred(struct tcb *tcp, long addr, int len)
1170{
1171 struct ucred uc;
1172
1173 if (len != sizeof(uc) ||
1174 umove(tcp, addr, &uc) < 0) {
1175 tprintf("%#lx", addr);
1176 } else {
1177 tprintf("{pid=%u, uid=%u, gid=%u}",
1178 (unsigned) uc.pid,
1179 (unsigned) uc.uid,
1180 (unsigned) uc.gid);
1181 }
1182}
1183#endif /* SO_PEERCRED */
1184
1185#ifdef PACKET_STATISTICS
1186static void
1187print_tpacket_stats(struct tcb *tcp, long addr, int len)
1188{
1189 struct tpacket_stats stats;
1190
1191 if (len != sizeof(stats) ||
1192 umove(tcp, addr, &stats) < 0) {
1193 tprintf("%#lx", addr);
1194 } else {
1195 tprintf("{packets=%u, drops=%u}",
1196 stats.tp_packets,
1197 stats.tp_drops);
1198 }
1199}
1200#endif /* PACKET_STATISTICS */
1201
1202#ifdef ICMP_FILTER
1203static void
1204print_icmp_filter(struct tcb *tcp, long addr, int len)
1205{
1206 struct icmp_filter filter;
1207
1208 if (len != sizeof(filter) ||
1209 umove(tcp, addr, &filter) < 0) {
1210 tprintf("%#lx", addr);
1211 return;
1212 }
1213
1214 tprints("~(");
1215 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1216 tprints(")");
1217}
1218#endif /* ICMP_FILTER */
1219
1220static void
1221print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1222{
1223 if (addr && verbose(tcp))
1224 switch (level) {
1225 case SOL_SOCKET:
1226 switch (name) {
1227#ifdef SO_LINGER
1228 case SO_LINGER:
1229 print_linger(tcp, addr, len);
1230 goto done;
1231#endif
1232#ifdef SO_PEERCRED
1233 case SO_PEERCRED:
1234 print_ucred(tcp, addr, len);
1235 goto done;
1236#endif
1237 }
1238 break;
1239
1240#ifdef SOL_PACKET
1241 case SOL_PACKET:
1242 switch (name) {
1243# ifdef PACKET_STATISTICS
1244 case PACKET_STATISTICS:
1245 print_tpacket_stats(tcp, addr, len);
1246 goto done;
1247# endif
1248 }
1249 break;
1250#endif /* SOL_PACKET */
1251
1252#ifdef SOL_RAW
1253 case SOL_RAW:
1254 switch (name) {
1255# ifdef ICMP_FILTER
1256 case ICMP_FILTER:
1257 print_icmp_filter(tcp, addr, len);
1258 goto done;
1259# endif
1260 }
1261 break;
1262#endif /* SOL_RAW */
1263 }
1264
John Hughes38ae88d2002-05-23 11:48:58 +00001265 /* default arg printing */
1266
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001267 if (verbose(tcp)) {
1268 if (len == sizeof(int)) {
1269 printnum_int(tcp, addr, "%d");
1270 } else {
1271 printstr(tcp, addr, len);
1272 }
1273 } else {
1274 tprintf("%#lx", addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001275 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001276done:
1277 tprintf(", [%d]", len);
1278}
1279
1280int
1281sys_getsockopt(struct tcb *tcp)
1282{
1283 if (entering(tcp)) {
1284 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1285 tcp->u_arg[1], tcp->u_arg[2]);
1286 } else {
1287 int len;
1288
1289 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1290 tprintf("%#lx, %#lx",
1291 tcp->u_arg[3], tcp->u_arg[4]);
1292 } else {
1293 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1294 tcp->u_arg[3], len);
1295 }
John Hughes38ae88d2002-05-23 11:48:58 +00001296 }
1297 return 0;
1298}
1299
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001300#ifdef PACKET_RX_RING
1301static void
1302print_tpacket_req(struct tcb *tcp, long addr, int len)
1303{
1304 struct tpacket_req req;
1305
1306 if (len != sizeof(req) ||
1307 umove(tcp, addr, &req) < 0) {
1308 tprintf("%#lx", addr);
1309 } else {
1310 tprintf("{block_size=%u, block_nr=%u, "
1311 "frame_size=%u, frame_nr=%u}",
1312 req.tp_block_size,
1313 req.tp_block_nr,
1314 req.tp_frame_size,
1315 req.tp_frame_nr);
1316 }
1317}
1318#endif /* PACKET_RX_RING */
1319
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001320#ifdef PACKET_ADD_MEMBERSHIP
1321# include "xlat/packet_mreq_type.h"
1322
1323static void
1324print_packet_mreq(struct tcb *tcp, long addr, int len)
1325{
1326 struct packet_mreq mreq;
1327
1328 if (len != sizeof(mreq) ||
1329 umove(tcp, addr, &mreq) < 0) {
1330 tprintf("%#lx", addr);
1331 } else {
1332 unsigned int i;
1333
1334 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1335 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1336 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1337 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1338 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1339 for (i = 0; i < mreq.mr_alen; ++i)
1340 tprintf("%02x", mreq.mr_address[i]);
1341 tprints("}");
1342 }
1343}
1344#endif /* PACKET_ADD_MEMBERSHIP */
1345
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001346static void
1347print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1348{
1349 if (addr && verbose(tcp))
1350 switch (level) {
1351 case SOL_SOCKET:
1352 switch (name) {
1353#ifdef SO_LINGER
1354 case SO_LINGER:
1355 print_linger(tcp, addr, len);
1356 goto done;
1357#endif
1358 }
1359 break;
1360
1361#ifdef SOL_PACKET
1362 case SOL_PACKET:
1363 switch (name) {
1364# ifdef PACKET_RX_RING
1365 case PACKET_RX_RING:
1366# ifdef PACKET_TX_RING
1367 case PACKET_TX_RING:
1368# endif
1369 print_tpacket_req(tcp, addr, len);
1370 goto done;
1371# endif /* PACKET_RX_RING */
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001372# ifdef PACKET_ADD_MEMBERSHIP
1373 case PACKET_ADD_MEMBERSHIP:
1374 case PACKET_DROP_MEMBERSHIP:
1375 print_packet_mreq(tcp, addr, len);
1376 goto done;
1377# endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001378 }
1379 break;
1380#endif /* SOL_PACKET */
1381
1382#ifdef SOL_RAW
1383 case SOL_RAW:
1384 switch (name) {
1385# ifdef ICMP_FILTER
1386 case ICMP_FILTER:
1387 print_icmp_filter(tcp, addr, len);
1388 goto done;
1389# endif
1390 }
1391 break;
1392#endif /* SOL_RAW */
1393 }
1394
1395 /* default arg printing */
1396
1397 if (verbose(tcp)) {
1398 if (len == sizeof(int)) {
1399 printnum_int(tcp, addr, "%d");
1400 } else {
1401 printstr(tcp, addr, len);
1402 }
1403 } else {
1404 tprintf("%#lx", addr);
1405 }
1406done:
1407 tprintf(", %d", len);
1408}
1409
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410int
Denys Vlasenko12014262011-05-30 14:00:14 +02001411sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412{
1413 if (entering(tcp)) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001414 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1415 tcp->u_arg[1], tcp->u_arg[2]);
1416 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1417 tcp->u_arg[3], tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 }
1419 return 0;
1420}