blob: 829f3ad849abda74a4119af7138c2d0416efb410 [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++;
256 else
257 tprintf(", sin6_scope_id=if_nametoindex(\"%s\")", scopebuf);
258 } else
259 numericscope++;
Roland McGrath6d2b3492002-12-30 00:51:30 +0000260
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200261 if (numericscope)
Wichert Akkermanf1850652001-02-16 20:29:03 +0000262#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
Wichert Akkermanf1850652001-02-16 20:29:03 +0000264 }
265#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200266 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000267#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100268#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000270 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000272 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000273 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 /* Yes, I know, this does not look too
275 * strace-ish, but otherwise the IPX
276 * addresses just look monstrous...
277 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000278 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000280 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200281 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000282 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
283 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284 }
285 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100286#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000287#ifdef AF_PACKET
288 case AF_PACKET:
289 {
290 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000291 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000292 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000293 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000294 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000295 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000296 addrbuf.ll.sll_halen,
297 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200298 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000299 tprintf("%02x", addrbuf.ll.sll_addr[i]);
300 }
301 break;
302
Denys Vlasenko84703742012-02-25 02:38:52 +0100303#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000304#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000305 case AF_NETLINK:
306 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
307 break;
308#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200309#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
310 case AF_BLUETOOTH:
311 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
312 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
313 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
314 "{hci_dev=htobs(%d)}",
315 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
316 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
317 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
318 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
319 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
320 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
321 addrbuf.rc.rc_channel,
322 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
323 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
324 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
325 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
326 btohs(addrbuf.hci.hci_dev));
327 break;
328#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000330 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331
332 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200333 tprints("sa_data=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336 break;
337 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200338 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339}
340
341#if HAVE_SENDMSG
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000342# ifndef SCM_SECURITY
343# define SCM_SECURITY 0x03
344# endif
345# include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000346
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000347#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
348struct cmsghdr32 {
349 uint32_t cmsg_len;
350 int cmsg_level;
351 int cmsg_type;
352};
353#endif
354
355typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000356 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000357 struct cmsghdr *cmsg;
358#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
359 struct cmsghdr32 *cmsg32;
360#endif
361} union_cmsghdr;
362
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000363static bool
364print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000365{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000366 if (cmsg_size + sizeof(int) > cmsg_len)
367 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000368
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000369 int *fds = (int *) (ptr + cmsg_size);
370 bool seen = false;
371
372 tprints(", [");
373 while ((char *) fds < (ptr + cmsg_len)) {
374 if (seen)
375 tprints(", ");
376 else
377 seen = true;
378 printfd(tcp, *fds++);
379 }
380 tprints("]}");
381 return true;
382}
383
384static bool
385print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
386{
387 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
388 return false;
389
390 const struct ucred *uc = (void *) (ptr + cmsg_size);
391
392 tprintf(", {pid=%u, uid=%u, gid=%u}}",
393 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
394 return true;
395}
396
397static bool
398print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
399{
400 if (cmsg_size + sizeof(char) > cmsg_len)
401 return false;
402
403 const char *label = (const char *) (ptr + cmsg_size);
404 const size_t label_len = cmsg_len - cmsg_size;
405 char *outstr;
406 const size_t alloc_len = 4 * label_len + 3;
407
408 if (label_len != alloc_len / 4 ||
409 !(outstr = malloc(alloc_len)))
410 return false;
411
412 string_quote(label, outstr, 0, label_len);
413 tprintf(", %s}", outstr);
414
415 free(outstr);
416 return true;
417}
418
419static void
420printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
421{
422 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000423#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
424 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
425#endif
426 sizeof(struct cmsghdr);
427
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000428 char *buf = len < cmsg_size ? NULL : malloc(len);
429 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Roland McGrath50770822004-10-06 22:11:51 +0000430 tprintf(", msg_control=%#lx", addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000431 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000432 return;
433 }
434
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000435 union_cmsghdr u = { .ptr = buf };
436
437 tprints(", [");
438 while (len >= cmsg_size) {
439 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000440#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000441 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000442#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000443 u.cmsg->cmsg_len;
444 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000445#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000446 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000447#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000448 u.cmsg->cmsg_level;
449 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000450#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000451 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000452#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000453 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000454
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000455 if (u.ptr != buf)
456 tprints(", ");
457 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
458 printxval(socketlayers, cmsg_level, "SOL_???");
459 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000460
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000461 if (cmsg_len > len)
462 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000463
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000464 if (cmsg_level == SOL_SOCKET) {
465 printxval(scmvals, cmsg_type, "SCM_???");
466 switch (cmsg_type) {
467 case SCM_RIGHTS:
468 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
469 goto next_cmsg;
470 break;
471 case SCM_CREDENTIALS:
472 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
473 goto next_cmsg;
474 break;
475 case SCM_SECURITY:
476 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
477 goto next_cmsg;
478 break;
Roland McGrath50770822004-10-06 22:11:51 +0000479 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000480 } else {
481 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000482 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000483 tprints(", ...}");
484next_cmsg:
485 if (cmsg_len < cmsg_size) {
486 len -= cmsg_size;
487 break;
Roland McGrath50770822004-10-06 22:11:51 +0000488 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000489 cmsg_len = (cmsg_len + current_wordsize - 1) &
490 (size_t) ~(current_wordsize - 1);
491 if (cmsg_len >= len) {
492 len = 0;
493 break;
494 }
495 u.ptr += cmsg_len;
496 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000497 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000498 if (len)
499 tprints(", ...");
500 tprints("]");
501 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000502}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503
504static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200505do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100506{
507 tprintf("{msg_name(%d)=", msg->msg_namelen);
508 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
509
510 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200511 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
512 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100513
514#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
515 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
516 if (msg->msg_controllen)
517 printcmsghdr(tcp, (unsigned long) msg->msg_control,
518 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200519 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100520 printflags(msg_flags, msg->msg_flags, "MSG_???");
521#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
522 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
523 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
524#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200525 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100526}
527
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100528struct msghdr32 {
529 uint32_t /* void* */ msg_name;
530 uint32_t /* socklen_t */msg_namelen;
531 uint32_t /* iovec* */ msg_iov;
532 uint32_t /* size_t */ msg_iovlen;
533 uint32_t /* void* */ msg_control;
534 uint32_t /* size_t */ msg_controllen;
535 uint32_t /* int */ msg_flags;
536};
537struct mmsghdr32 {
538 struct msghdr32 msg_hdr;
539 uint32_t /* unsigned */ msg_len;
540};
541
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900542#ifndef HAVE_STRUCT_MMSGHDR
543struct mmsghdr {
544 struct msghdr msg_hdr;
545 unsigned msg_len;
546};
547#endif
548
Masatake YAMATOb2485432014-11-07 01:23:24 +0900549#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
550static void
551copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
552{
553 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
554 to_msg->msg_namelen = from_msg32->msg_namelen;
555 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
556 to_msg->msg_iovlen = from_msg32->msg_iovlen;
557 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
558 to_msg->msg_controllen = from_msg32->msg_controllen;
559 to_msg->msg_flags = from_msg32->msg_flags;
560}
561#endif
562
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900563static bool
564extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
565{
566#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
567 if (current_wordsize == 4) {
568 struct msghdr32 msg32;
569
570 if (umove(tcp, addr, &msg32) < 0)
571 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900572 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900573 } else
574#endif
575 if (umove(tcp, addr, msg) < 0)
576 return false;
577 return true;
578}
579
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900580static bool
581extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
582{
583#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
584 if (current_wordsize == 4) {
585 struct mmsghdr32 mmsg32;
586
587 addr += sizeof(struct mmsghdr32) * idx;
588 if (umove(tcp, addr, &mmsg32) < 0)
589 return false;
590
591 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
592 mmsg->msg_len = mmsg32.msg_len;
593 } else
594#endif
595 {
596 addr += sizeof(*mmsg) * idx;
597 if (umove(tcp, addr, mmsg) < 0)
598 return false;
599 }
600 return true;
601}
602
Andreas Schwab0873f292010-02-12 21:39:12 +0100603static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200604printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000605{
606 struct msghdr msg;
607
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900608 if (extractmsghdr(tcp, addr, &msg))
609 do_msghdr(tcp, &msg, data_size);
610 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000611 tprintf("%#lx", addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900612}
613
614void
615dumpiov_in_msghdr(struct tcb *tcp, long addr)
616{
617 struct msghdr msg;
618
619 if (extractmsghdr(tcp, addr, &msg))
620 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000621}
622
Andreas Schwab0873f292010-02-12 21:39:12 +0100623static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000624printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100625{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900626 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100627
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900628 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
629 tprints("{");
630 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
631 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100632 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900633 else
634 tprintf("%#lx", addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100635}
Andreas Schwab0873f292010-02-12 21:39:12 +0100636
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000637static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000638decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000639{
640 /* mmsgvec */
641 if (syserror(tcp)) {
642 tprintf("%#lx", tcp->u_arg[1]);
643 } else {
644 unsigned int len = tcp->u_rval;
645 unsigned int i;
646
647 tprints("{");
648 for (i = 0; i < len; ++i) {
649 if (i)
650 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000651 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000652 }
653 tprints("}");
654 }
655 /* vlen */
656 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
657 /* flags */
658 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
659}
660
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900661void
662dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
663{
664 unsigned int len = tcp->u_rval;
665 unsigned int i;
666 struct mmsghdr mmsg;
667
668 for (i = 0; i < len; ++i) {
669 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
670 tprintf(" = %lu buffers in vector %u\n",
671 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
672 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
673 (long)mmsg.msg_hdr.msg_iov);
674 }
675 }
676}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677#endif /* HAVE_SENDMSG */
678
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000679/*
680 * low bits of the socket type define real socket type,
681 * other bits are socket type flags.
682 */
683static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000684tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000685{
686 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
687
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200688 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200689 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000690 flags &= ~SOCK_TYPE_MASK;
691 if (!flags)
692 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200693 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000694 }
695 printflags(sock_type_flags, flags, "SOCK_???");
696}
697
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000699sys_socket(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700{
701 if (entering(tcp)) {
702 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200703 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000704 tprint_sock_type(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200705 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 switch (tcp->u_arg[0]) {
707 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000708#ifdef PF_INET6
709 case PF_INET6:
710#endif
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900711 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712 break;
713#ifdef PF_IPX
714 case PF_IPX:
715 /* BTW: I don't believe this.. */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200716 tprints("[");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717 printxval(domains, tcp->u_arg[2], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200718 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000719 break;
720#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900721#ifdef PF_NETLINK
722 case PF_NETLINK:
723 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
724 break;
725#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200726#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
727 case PF_BLUETOOTH:
728 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
729 break;
730#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 default:
732 tprintf("%lu", tcp->u_arg[2]);
733 break;
734 }
735 }
736 return 0;
737}
738
John Hughesbdf48f52001-03-06 15:08:09 +0000739int
Denys Vlasenko12014262011-05-30 14:00:14 +0200740sys_bind(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000741{
742 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800743 printfd(tcp, tcp->u_arg[0]);
744 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000745 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000746 tprintf(", %lu", tcp->u_arg[2]);
747 }
748 return 0;
749}
750
751int
Denys Vlasenko12014262011-05-30 14:00:14 +0200752sys_connect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753{
754 return sys_bind(tcp);
755}
756
757int
Denys Vlasenko12014262011-05-30 14:00:14 +0200758sys_listen(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759{
760 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800761 printfd(tcp, tcp->u_arg[0]);
762 tprints(", ");
763 tprintf("%lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 }
765 return 0;
766}
767
Paolo Bonzini705ff102009-08-14 12:34:05 +0200768static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000769do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770{
771 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800772 printfd(tcp, tcp->u_arg[0]);
773 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200774 return 0;
775 }
776 if (!tcp->u_arg[2])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000777 tprintf("%#lx, NULL", tcp->u_arg[1]);
778 else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000779 int len;
780 if (tcp->u_arg[1] == 0 || syserror(tcp)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200781 || umove(tcp, tcp->u_arg[2], &len) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000782 tprintf("%#lx", tcp->u_arg[1]);
783 } else {
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000784 printsock(tcp, tcp->u_arg[1], len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000785 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200786 tprints(", ");
Dmitry V. Levin2fc66152009-01-01 22:47:51 +0000787 printnum_int(tcp, tcp->u_arg[2], "%u");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200789 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200790 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200791 printflags(sock_type_flags, tcp->u_arg[flags_arg],
792 "SOCK_???");
793 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000794 return 0;
795}
796
797int
Paolo Bonzini705ff102009-08-14 12:34:05 +0200798sys_accept(struct tcb *tcp)
799{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000800 do_sockname(tcp, -1);
801 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200802}
803
Paolo Bonzini705ff102009-08-14 12:34:05 +0200804int
805sys_accept4(struct tcb *tcp)
806{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000807 do_sockname(tcp, 3);
808 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200809}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200810
811int
Denys Vlasenko12014262011-05-30 14:00:14 +0200812sys_send(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813{
814 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800815 printfd(tcp, tcp->u_arg[0]);
816 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
818 tprintf(", %lu, ", tcp->u_arg[2]);
819 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000820 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 }
822 return 0;
823}
824
825int
Denys Vlasenko12014262011-05-30 14:00:14 +0200826sys_sendto(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827{
828 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800829 printfd(tcp, tcp->u_arg[0]);
830 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
832 tprintf(", %lu, ", tcp->u_arg[2]);
833 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000834 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835 /* to address */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200836 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000837 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838 /* to length */
839 tprintf(", %lu", tcp->u_arg[5]);
840 }
841 return 0;
842}
843
844#ifdef HAVE_SENDMSG
845
846int
Denys Vlasenko12014262011-05-30 14:00:14 +0200847sys_sendmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848{
849 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800850 printfd(tcp, tcp->u_arg[0]);
851 tprints(", ");
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000852 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200854 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000855 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 }
857 return 0;
858}
859
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000860int
861sys_sendmmsg(struct tcb *tcp)
862{
863 if (entering(tcp)) {
864 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800865 printfd(tcp, tcp->u_arg[0]);
866 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000867 if (!verbose(tcp)) {
868 tprintf("%#lx, %u, ",
869 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
870 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
871 }
872 } else {
873 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000874 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000875 }
876 return 0;
877}
878
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000879#endif /* HAVE_SENDMSG */
880
881int
Denys Vlasenko12014262011-05-30 14:00:14 +0200882sys_recv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883{
884 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800885 printfd(tcp, tcp->u_arg[0]);
886 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887 } else {
888 if (syserror(tcp))
889 tprintf("%#lx", tcp->u_arg[1]);
890 else
891 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
892
893 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000894 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895 }
896 return 0;
897}
898
899int
Denys Vlasenko12014262011-05-30 14:00:14 +0200900sys_recvfrom(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901{
902 int fromlen;
903
904 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800905 printfd(tcp, tcp->u_arg[0]);
906 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000907 } else {
908 if (syserror(tcp)) {
909 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
910 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
911 tcp->u_arg[4], tcp->u_arg[5]);
912 return 0;
913 }
914 /* buf */
915 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
916 /* len */
917 tprintf(", %lu, ", tcp->u_arg[2]);
918 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000919 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000920 /* from address, len */
921 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
922 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200923 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924 else
925 tprintf(", %#lx", tcp->u_arg[4]);
926 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200927 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928 else
929 tprintf(", %#lx", tcp->u_arg[5]);
930 return 0;
931 }
932 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200933 tprints(", {...}, [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000934 return 0;
935 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200936 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000937 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938 /* from length */
939 tprintf(", [%u]", fromlen);
940 }
941 return 0;
942}
943
944#ifdef HAVE_SENDMSG
945
946int
Denys Vlasenko12014262011-05-30 14:00:14 +0200947sys_recvmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948{
949 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800950 printfd(tcp, tcp->u_arg[0]);
951 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 } else {
953 if (syserror(tcp) || !verbose(tcp))
954 tprintf("%#lx", tcp->u_arg[1]);
955 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200956 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200958 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000959 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960 }
961 return 0;
962}
963
Andreas Schwab0873f292010-02-12 21:39:12 +0100964int
965sys_recvmmsg(struct tcb *tcp)
966{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100967 /* +5 chars are for "left " prefix */
968 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400969
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100970 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800971 printfd(tcp, tcp->u_arg[0]);
972 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400973 if (verbose(tcp)) {
974 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100975 /* Abusing tcp->auxstr as temp storage.
976 * Will be used and freed on syscall exit.
977 */
Dmitry V. Levine6591032010-03-29 20:45:48 +0400978 tcp->auxstr = strdup(str);
979 } else {
980 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
981 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200982 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400983 print_timespec(tcp, tcp->u_arg[4]);
984 }
985 return 0;
986 } else {
987 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000988 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400989 /* timeout on entrance */
990 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
991 free((void *) tcp->auxstr);
992 tcp->auxstr = NULL;
993 }
994 if (syserror(tcp))
995 return 0;
996 if (tcp->u_rval == 0) {
997 tcp->auxstr = "Timeout";
998 return RVAL_STR;
999 }
1000 if (!verbose(tcp))
1001 return 0;
1002 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001003 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001004 tcp->auxstr = str;
1005 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001006 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001007}
Andreas Schwab0873f292010-02-12 21:39:12 +01001008
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009#endif /* HAVE_SENDMSG */
1010
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001011#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001012
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013int
Denys Vlasenko12014262011-05-30 14:00:14 +02001014sys_shutdown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015{
1016 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001017 printfd(tcp, tcp->u_arg[0]);
1018 tprints(", ");
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001019 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001020 }
1021 return 0;
1022}
1023
1024int
Denys Vlasenko12014262011-05-30 14:00:14 +02001025sys_getsockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001027 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028}
1029
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001030static int
1031do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033 if (exiting(tcp)) {
1034 if (syserror(tcp)) {
1035 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001036 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001037#if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001038 int fds[2];
1039
1040 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001041 tprints("[...]");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001042 else
1043 tprintf("[%u, %u]", fds[0], fds[1]);
Denys Vlasenko84703742012-02-25 02:38:52 +01001044#elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001045 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1046#else
1047 tprintf("%#lx", tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001049 }
1050 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001051 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001052 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1053 }
1054 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 return 0;
1056}
1057
1058int
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001059sys_pipe(struct tcb *tcp)
1060{
1061 return do_pipe(tcp, -1);
1062}
1063
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001064int
1065sys_pipe2(struct tcb *tcp)
1066{
1067 return do_pipe(tcp, 1);
1068}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001069
1070int
Dmitry V. Levin8a550d72008-11-10 17:21:23 +00001071sys_socketpair(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073 int fds[2];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074
1075 if (entering(tcp)) {
1076 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001077 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001078 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001079 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080 } else {
1081 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001082 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083 return 0;
1084 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001085 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001086 tprints(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001087 else
1088 tprintf(", [%u, %u]", fds[0], fds[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001089 }
1090 return 0;
1091}
1092
1093int
Dmitry V. Levin31289192009-11-06 18:05:40 +00001094sys_getsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095{
1096 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001097 printfd(tcp, tcp->u_arg[0]);
1098 tprints(", ");
John Hughes93f7fcc2002-05-22 15:46:49 +00001099 printxval(socketlayers, tcp->u_arg[1], "SOL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001100 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001101 switch (tcp->u_arg[1]) {
1102 case SOL_SOCKET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 printxval(sockoptions, tcp->u_arg[2], "SO_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001104 break;
1105#ifdef SOL_IP
1106 case SOL_IP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001107 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108 break;
1109#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001110#ifdef SOL_IPV6
1111 case SOL_IPV6:
1112 printxval(sockipv6options, tcp->u_arg[2], "IPV6_???");
1113 break;
1114#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001115#ifdef SOL_IPX
1116 case SOL_IPX:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001117 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001118 break;
1119#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001120#ifdef SOL_PACKET
1121 case SOL_PACKET:
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001122 printxval(sockpacketoptions, tcp->u_arg[2], "PACKET_???");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001123 break;
1124#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125#ifdef SOL_TCP
1126 case SOL_TCP:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 break;
1129#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001130#ifdef SOL_SCTP
1131 case SOL_SCTP:
1132 printxval(socksctpoptions, tcp->u_arg[2], "SCTP_???");
1133 break;
1134#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135
1136 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
1137 * etc. still need work */
Roland McGrath6d2b3492002-12-30 00:51:30 +00001138 default:
John Hughes93f7fcc2002-05-22 15:46:49 +00001139 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001140 break;
1141 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001142 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001143 } else {
Roland McGrathfc544db2005-02-02 02:48:57 +00001144 int len;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001145 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001146 tprintf("%#lx, %#lx",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001147 tcp->u_arg[3], tcp->u_arg[4]);
1148 return 0;
1149 }
John Hughes93f7fcc2002-05-22 15:46:49 +00001150
1151 switch (tcp->u_arg[1]) {
1152 case SOL_SOCKET:
1153 switch (tcp->u_arg[2]) {
1154#ifdef SO_LINGER
1155 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001156 if (len == sizeof(struct linger)) {
John Hughes93f7fcc2002-05-22 15:46:49 +00001157 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001158 if (umove(tcp,
John Hughes93f7fcc2002-05-22 15:46:49 +00001159 tcp->u_arg[3],
1160 &linger) < 0)
1161 break;
Dmitry V. Levin31289192009-11-06 18:05:40 +00001162 tprintf("{onoff=%d, linger=%d}, "
Roland McGrath96ad7b82005-02-02 03:11:32 +00001163 "[%d]",
John Hughes93f7fcc2002-05-22 15:46:49 +00001164 linger.l_onoff,
1165 linger.l_linger,
1166 len);
1167 return 0;
1168 }
1169 break;
1170#endif
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001171#ifdef SO_PEERCRED
1172 case SO_PEERCRED:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001173 if (len == sizeof(struct ucred)) {
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001174 struct ucred uc;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001175 if (umove(tcp,
Dmitry V. Levin0ddd8ad2010-12-03 16:54:53 +00001176 tcp->u_arg[3],
1177 &uc) < 0)
1178 break;
1179 tprintf("{pid=%ld, uid=%ld, gid=%ld}, "
1180 "[%d]",
1181 (long)uc.pid,
1182 (long)uc.uid,
1183 (long)uc.gid,
1184 len);
1185 return 0;
1186 }
1187 break;
1188#endif
John Hughes93f7fcc2002-05-22 15:46:49 +00001189 }
1190 break;
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001191 case SOL_PACKET:
1192 switch (tcp->u_arg[2]) {
1193#ifdef PACKET_STATISTICS
1194 case PACKET_STATISTICS:
1195 if (len == sizeof(struct tpacket_stats)) {
1196 struct tpacket_stats stats;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001197 if (umove(tcp,
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001198 tcp->u_arg[3],
1199 &stats) < 0)
1200 break;
1201 tprintf("{packets=%u, drops=%u}, "
1202 "[%d]",
1203 stats.tp_packets,
1204 stats.tp_drops,
1205 len);
1206 return 0;
1207 }
1208 break;
1209#endif
1210 }
1211 break;
John Hughes93f7fcc2002-05-22 15:46:49 +00001212 }
1213
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001214 if (len == sizeof(int)) {
Dmitry V. Levin31289192009-11-06 18:05:40 +00001215 printnum_int(tcp, tcp->u_arg[3], "%d");
John Hughes93f7fcc2002-05-22 15:46:49 +00001216 }
1217 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001218 printstr(tcp, tcp->u_arg[3], len);
John Hughes93f7fcc2002-05-22 15:46:49 +00001219 }
Roland McGrathfc544db2005-02-02 02:48:57 +00001220 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 }
1222 return 0;
1223}
1224
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001225#if defined(ICMP_FILTER)
Denys Vlasenko12014262011-05-30 14:00:14 +02001226static void printicmpfilter(struct tcb *tcp, long addr)
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001227{
1228 struct icmp_filter filter;
1229
1230 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001231 tprints("NULL");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001232 return;
1233 }
1234 if (syserror(tcp) || !verbose(tcp)) {
1235 tprintf("%#lx", addr);
1236 return;
1237 }
1238 if (umove(tcp, addr, &filter) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001239 tprints("{...}");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001240 return;
1241 }
1242
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001243 tprints("~(");
Roland McGrathb2dee132005-06-01 19:02:36 +00001244 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001245 tprints(")");
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00001246}
1247#endif /* ICMP_FILTER */
1248
John Hughes38ae88d2002-05-23 11:48:58 +00001249static int
Denys Vlasenko12014262011-05-30 14:00:14 +02001250printsockopt(struct tcb *tcp, int level, int name, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +00001251{
1252 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001253 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001254 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001255 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001256 printxval(sockoptions, name, "SO_???");
1257 switch (name) {
1258#if defined(SO_LINGER)
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001259 case SO_LINGER:
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001260 if (len == sizeof(struct linger)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001261 struct linger linger;
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001262 if (umove(tcp, addr, &linger) < 0)
John Hughes38ae88d2002-05-23 11:48:58 +00001263 break;
1264 tprintf(", {onoff=%d, linger=%d}",
1265 linger.l_onoff,
1266 linger.l_linger);
1267 return 0;
1268 }
1269 break;
1270#endif
1271 }
1272 break;
1273#ifdef SOL_IP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001274 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001275 printxval(sockipoptions, name, "IP_???");
1276 break;
1277#endif
Roland McGrath4f6ba692004-08-31 07:01:26 +00001278#ifdef SOL_IPV6
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001279 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001280 printxval(sockipv6options, name, "IPV6_???");
1281 break;
1282#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001283#ifdef SOL_IPX
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001284 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001285 printxval(sockipxoptions, name, "IPX_???");
1286 break;
1287#endif
1288#ifdef SOL_PACKET
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001289 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001290 printxval(sockpacketoptions, name, "PACKET_???");
1291 /* TODO: decode packate_mreq for PACKET_*_MEMBERSHIP */
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001292 switch (name) {
1293#ifdef PACKET_RX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001294 case PACKET_RX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001295#endif
1296#ifdef PACKET_TX_RING
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001297 case PACKET_TX_RING:
Dmitry V. Levinca75bd62009-11-13 12:51:04 +00001298#endif
1299#if defined(PACKET_RX_RING) || defined(PACKET_TX_RING)
1300 if (len == sizeof(struct tpacket_req)) {
1301 struct tpacket_req req;
1302 if (umove(tcp, addr, &req) < 0)
1303 break;
1304 tprintf(", {block_size=%u, block_nr=%u, frame_size=%u, frame_nr=%u}",
1305 req.tp_block_size,
1306 req.tp_block_nr,
1307 req.tp_frame_size,
1308 req.tp_frame_nr);
1309 return 0;
1310 }
1311 break;
1312#endif /* PACKET_RX_RING || PACKET_TX_RING */
1313 }
John Hughes38ae88d2002-05-23 11:48:58 +00001314 break;
1315#endif
1316#ifdef SOL_TCP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001317 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001318 printxval(socktcpoptions, name, "TCP_???");
1319 break;
1320#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001321#ifdef SOL_SCTP
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001322 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001323 printxval(socksctpoptions, name, "SCTP_???");
1324 break;
1325#endif
John Hughes38ae88d2002-05-23 11:48:58 +00001326#ifdef SOL_RAW
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001327 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001328 printxval(sockrawoptions, name, "RAW_???");
1329 switch (name) {
1330#if defined(ICMP_FILTER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001331 case ICMP_FILTER:
1332 tprints(", ");
1333 printicmpfilter(tcp, addr);
1334 return 0;
John Hughes38ae88d2002-05-23 11:48:58 +00001335#endif
1336 }
1337 break;
1338#endif
1339
Roland McGrath6d2b3492002-12-30 00:51:30 +00001340 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
John Hughes38ae88d2002-05-23 11:48:58 +00001341 * etc. still need work */
1342
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001343 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001344 tprintf("%u", name);
1345 }
1346
1347 /* default arg printing */
1348
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001349 tprints(", ");
Roland McGrath6d2b3492002-12-30 00:51:30 +00001350
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001351 if (len == sizeof(int)) {
1352 printnum_int(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +00001353 }
1354 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001355 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +00001356 }
1357 return 0;
1358}
1359
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001360int
Denys Vlasenko12014262011-05-30 14:00:14 +02001361sys_setsockopt(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001362{
1363 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001364 printfd(tcp, tcp->u_arg[0]);
1365 tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001366 printsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
John Hughes38ae88d2002-05-23 11:48:58 +00001367 tcp->u_arg[3], tcp->u_arg[4]);
John Hughes93f7fcc2002-05-22 15:46:49 +00001368 tprintf(", %lu", tcp->u_arg[4]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001369 }
1370 return 0;
1371}