blob: 7e735288b16e9e86198edb5d3f74a0953e8c80e7 [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>
36#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000037#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010038# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000039#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000040#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010041# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010043#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010044# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010045#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000047#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010049#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010050# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010052# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000055#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010056# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000057#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000058#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010059# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000060#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000061#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010062# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000063#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020064#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
65# include <bluetooth/bluetooth.h>
66# include <bluetooth/hci.h>
67# include <bluetooth/l2cap.h>
68# include <bluetooth/rfcomm.h>
69# include <bluetooth/sco.h>
70#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010072# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073#endif
74
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000075#include "xlat/domains.h"
76#include "xlat/addrfams.h"
77#include "xlat/socktypes.h"
78#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000079#ifndef SOCK_TYPE_MASK
80# define SOCK_TYPE_MASK 0xf
81#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000082
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000083#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000084
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000085#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090086
87#ifdef PF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +000088# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
89# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
90# endif
91# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090092#endif
93
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020094#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
95# include "xlat/bt_protocols.h"
96#endif
97
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000098#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000099
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000100#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000101# include "xlat/af_packet_types.h"
102#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000103
Dmitry V. Levinae280932015-06-05 20:13:21 +0000104static void
105print_ifindex(unsigned int ifindex)
106{
107#ifdef HAVE_IF_INDEXTONAME
108 char buf[IFNAMSIZ + 1];
109
110 if (if_indextoname(ifindex, buf)) {
111 tprints("if_nametoindex(");
112 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
113 tprints(")");
114 return;
115 }
116#endif
117 tprintf("%u", ifindex);
118}
119
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000121printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000123 union {
124 char pad[128];
125 struct sockaddr sa;
126 struct sockaddr_in sin;
127 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000128#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000129 struct sockaddr_in6 sa6;
130#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100131#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000132 struct sockaddr_ipx sipx;
133#endif
134#ifdef AF_PACKET
135 struct sockaddr_ll ll;
136#endif
137#ifdef AF_NETLINK
138 struct sockaddr_nl nl;
139#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200140#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
141 struct sockaddr_hci hci;
142 struct sockaddr_l2 l2;
143 struct sockaddr_rc rc;
144 struct sockaddr_sco sco;
145#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000146 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000147 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148
Denys Vlasenko383386d2015-07-30 13:29:20 +0200149 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000150 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200151 return;
152 }
153
154 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000155 addrlen = sizeof(addrbuf);
156
157 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000158 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000160 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000161
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200162 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000163 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200164 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000165
166 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000168 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200169 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000170 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000171 tprints("sun_path=");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000172 print_quoted_string(addrbuf.sau.sun_path,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000173 sizeof(addrbuf.sau.sun_path) + 1,
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000174 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000175 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000176 tprints("sun_path=@");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000177 print_quoted_string(addrbuf.sau.sun_path + 1,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000178 sizeof(addrbuf.sau.sun_path),
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000179 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000180 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181 break;
182 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000183 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000184 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000186#ifdef HAVE_INET_NTOP
187 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000188 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000189 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
190 ntohs(addrbuf.sa6.sin6_port), string_addr,
191 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000192#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Dmitry V. Levinae280932015-06-05 20:13:21 +0000193 tprints(", sin6_scope_id=");
194#if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
195 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
196 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr))
197 print_ifindex(addrbuf.sa6.sin6_scope_id);
198 else
Wichert Akkermanf1850652001-02-16 20:29:03 +0000199#endif
Dmitry V. Levinae280932015-06-05 20:13:21 +0000200 tprintf("%u", addrbuf.sa6.sin6_scope_id);
201#endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200202 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000203#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100204#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000206 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000208 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000209 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210 /* Yes, I know, this does not look too
211 * strace-ish, but otherwise the IPX
212 * addresses just look monstrous...
213 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000214 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000216 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200217 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000218 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
219 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220 }
221 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100222#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000223#ifdef AF_PACKET
224 case AF_PACKET:
225 {
226 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000227 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000228 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000229 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000230 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000231 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000232 addrbuf.ll.sll_halen,
233 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200234 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000235 tprintf("%02x", addrbuf.ll.sll_addr[i]);
236 }
237 break;
238
Denys Vlasenko84703742012-02-25 02:38:52 +0100239#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000240#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000241 case AF_NETLINK:
242 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
243 break;
244#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200245#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
246 case AF_BLUETOOTH:
247 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
248 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
249 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
250 "{hci_dev=htobs(%d)}",
251 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
252 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
253 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
254 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
255 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
256 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
257 addrbuf.rc.rc_channel,
258 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
259 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
260 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
261 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
262 btohs(addrbuf.hci.hci_dev));
263 break;
264#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000266 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267
268 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200269 tprints("sa_data=");
Dmitry V. Levind0dceaf2015-01-30 13:36:49 +0000270 print_quoted_string(addrbuf.sa.sa_data,
271 sizeof(addrbuf.sa.sa_data), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 break;
273 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200274 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275}
276
Dmitry V. Levind93c4e82015-06-17 20:09:13 +0000277#ifdef HAVE_SENDMSG
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000278# ifndef SCM_SECURITY
279# define SCM_SECURITY 0x03
280# endif
281# include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000282
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000283#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
284struct cmsghdr32 {
285 uint32_t cmsg_len;
286 int cmsg_level;
287 int cmsg_type;
288};
289#endif
290
291typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000292 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000293 struct cmsghdr *cmsg;
294#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
295 struct cmsghdr32 *cmsg32;
296#endif
297} union_cmsghdr;
298
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000299static bool
300print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000301{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000302 if (cmsg_size + sizeof(int) > cmsg_len)
303 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000304
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000305 int *fds = (int *) (ptr + cmsg_size);
306 bool seen = false;
307
308 tprints(", [");
309 while ((char *) fds < (ptr + cmsg_len)) {
310 if (seen)
311 tprints(", ");
312 else
313 seen = true;
314 printfd(tcp, *fds++);
315 }
316 tprints("]}");
317 return true;
318}
319
320static bool
321print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
322{
323 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
324 return false;
325
326 const struct ucred *uc = (void *) (ptr + cmsg_size);
327
328 tprintf(", {pid=%u, uid=%u, gid=%u}}",
329 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
330 return true;
331}
332
333static bool
334print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
335{
336 if (cmsg_size + sizeof(char) > cmsg_len)
337 return false;
338
339 const char *label = (const char *) (ptr + cmsg_size);
340 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000341
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000342 tprints(", ");
343 print_quoted_string(label, label_len, 0);
344 tprints("}");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000345
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000346 return true;
347}
348
349static void
350printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
351{
352 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000353#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
354 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
355#endif
356 sizeof(struct cmsghdr);
357
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000358 char *buf = len < cmsg_size ? NULL : malloc(len);
359 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000360 tprints(", msg_control=");
361 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000362 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000363 return;
364 }
365
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000366 union_cmsghdr u = { .ptr = buf };
367
368 tprints(", [");
369 while (len >= cmsg_size) {
370 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000371#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000372 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000373#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000374 u.cmsg->cmsg_len;
375 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000376#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000377 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000378#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000379 u.cmsg->cmsg_level;
380 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000381#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000382 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000383#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000384 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000385
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000386 if (u.ptr != buf)
387 tprints(", ");
388 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
389 printxval(socketlayers, cmsg_level, "SOL_???");
390 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000391
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000392 if (cmsg_len > len)
393 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000394
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000395 if (cmsg_level == SOL_SOCKET) {
396 printxval(scmvals, cmsg_type, "SCM_???");
397 switch (cmsg_type) {
398 case SCM_RIGHTS:
399 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
400 goto next_cmsg;
401 break;
402 case SCM_CREDENTIALS:
403 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
404 goto next_cmsg;
405 break;
406 case SCM_SECURITY:
407 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
408 goto next_cmsg;
409 break;
Roland McGrath50770822004-10-06 22:11:51 +0000410 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000411 } else {
412 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000413 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000414 tprints(", ...}");
415next_cmsg:
416 if (cmsg_len < cmsg_size) {
417 len -= cmsg_size;
418 break;
Roland McGrath50770822004-10-06 22:11:51 +0000419 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000420 cmsg_len = (cmsg_len + current_wordsize - 1) &
421 (size_t) ~(current_wordsize - 1);
422 if (cmsg_len >= len) {
423 len = 0;
424 break;
425 }
426 u.ptr += cmsg_len;
427 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000428 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000429 if (len)
430 tprints(", ...");
431 tprints("]");
432 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000433}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434
435static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200436do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100437{
438 tprintf("{msg_name(%d)=", msg->msg_namelen);
439 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
440
441 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200442 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
443 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100444
445#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
446 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
447 if (msg->msg_controllen)
448 printcmsghdr(tcp, (unsigned long) msg->msg_control,
449 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200450 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100451 printflags(msg_flags, msg->msg_flags, "MSG_???");
452#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
453 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
454 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
455#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200456 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100457}
458
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100459struct msghdr32 {
460 uint32_t /* void* */ msg_name;
461 uint32_t /* socklen_t */msg_namelen;
462 uint32_t /* iovec* */ msg_iov;
463 uint32_t /* size_t */ msg_iovlen;
464 uint32_t /* void* */ msg_control;
465 uint32_t /* size_t */ msg_controllen;
466 uint32_t /* int */ msg_flags;
467};
468struct mmsghdr32 {
469 struct msghdr32 msg_hdr;
470 uint32_t /* unsigned */ msg_len;
471};
472
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900473#ifndef HAVE_STRUCT_MMSGHDR
474struct mmsghdr {
475 struct msghdr msg_hdr;
476 unsigned msg_len;
477};
478#endif
479
Masatake YAMATOb2485432014-11-07 01:23:24 +0900480#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
481static void
482copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
483{
484 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
485 to_msg->msg_namelen = from_msg32->msg_namelen;
486 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
487 to_msg->msg_iovlen = from_msg32->msg_iovlen;
488 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
489 to_msg->msg_controllen = from_msg32->msg_controllen;
490 to_msg->msg_flags = from_msg32->msg_flags;
491}
492#endif
493
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900494static bool
495extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
496{
497#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
498 if (current_wordsize == 4) {
499 struct msghdr32 msg32;
500
501 if (umove(tcp, addr, &msg32) < 0)
502 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900503 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900504 } else
505#endif
506 if (umove(tcp, addr, msg) < 0)
507 return false;
508 return true;
509}
510
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900511static bool
512extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
513{
514#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
515 if (current_wordsize == 4) {
516 struct mmsghdr32 mmsg32;
517
518 addr += sizeof(struct mmsghdr32) * idx;
519 if (umove(tcp, addr, &mmsg32) < 0)
520 return false;
521
522 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
523 mmsg->msg_len = mmsg32.msg_len;
524 } else
525#endif
526 {
527 addr += sizeof(*mmsg) * idx;
528 if (umove(tcp, addr, mmsg) < 0)
529 return false;
530 }
531 return true;
532}
533
Andreas Schwab0873f292010-02-12 21:39:12 +0100534static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200535printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536{
537 struct msghdr msg;
538
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000539 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900540 do_msghdr(tcp, &msg, data_size);
541 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000542 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900543}
544
545void
546dumpiov_in_msghdr(struct tcb *tcp, long addr)
547{
548 struct msghdr msg;
549
550 if (extractmsghdr(tcp, addr, &msg))
551 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552}
553
Andreas Schwab0873f292010-02-12 21:39:12 +0100554static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000555printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100556{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900557 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100558
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900559 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
560 tprints("{");
561 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
562 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100563 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900564 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000565 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100566}
Andreas Schwab0873f292010-02-12 21:39:12 +0100567
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000568static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000569decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000570{
571 /* mmsgvec */
572 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000573 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000574 } else {
575 unsigned int len = tcp->u_rval;
576 unsigned int i;
577
578 tprints("{");
579 for (i = 0; i < len; ++i) {
580 if (i)
581 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000582 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000583 }
584 tprints("}");
585 }
586 /* vlen */
587 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
588 /* flags */
589 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
590}
591
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900592void
593dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
594{
595 unsigned int len = tcp->u_rval;
596 unsigned int i;
597 struct mmsghdr mmsg;
598
599 for (i = 0; i < len; ++i) {
600 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
601 tprintf(" = %lu buffers in vector %u\n",
602 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
603 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
604 (long)mmsg.msg_hdr.msg_iov);
605 }
606 }
607}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608#endif /* HAVE_SENDMSG */
609
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000610/*
611 * low bits of the socket type define real socket type,
612 * other bits are socket type flags.
613 */
614static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000615tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000616{
617 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
618
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200619 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200620 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000621 flags &= ~SOCK_TYPE_MASK;
622 if (!flags)
623 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200624 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000625 }
626 printflags(sock_type_flags, flags, "SOCK_???");
627}
628
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000629SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000631 printxval(domains, tcp->u_arg[0], "PF_???");
632 tprints(", ");
633 tprint_sock_type(tcp->u_arg[1]);
634 tprints(", ");
635 switch (tcp->u_arg[0]) {
636 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000637#ifdef PF_INET6
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000638 case PF_INET6:
Roland McGrath8758e542003-06-23 23:39:59 +0000639#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000640 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
641 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642#ifdef PF_IPX
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000643 case PF_IPX:
644 /* BTW: I don't believe this.. */
645 tprints("[");
646 printxval(domains, tcp->u_arg[2], "PF_???");
647 tprints("]");
648 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900650#ifdef PF_NETLINK
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000651 case PF_NETLINK:
652 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
653 break;
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900654#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200655#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000656 case PF_BLUETOOTH:
657 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
658 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200659#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000660 default:
661 tprintf("%lu", tcp->u_arg[2]);
662 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000664
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000665 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666}
667
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000668SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000670 printfd(tcp, tcp->u_arg[0]);
671 tprints(", ");
672 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
673 tprintf(", %lu", tcp->u_arg[2]);
674
675 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676}
677
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000678SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000680 printfd(tcp, tcp->u_arg[0]);
681 tprints(", ");
682 tprintf("%lu", tcp->u_arg[1]);
683
684 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685}
686
Paolo Bonzini705ff102009-08-14 12:34:05 +0200687static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000688do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689{
690 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800691 printfd(tcp, tcp->u_arg[0]);
692 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200693 return 0;
694 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000695
696 int len;
697 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
698 umove(tcp, tcp->u_arg[2], &len) < 0) {
699 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200700 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000701 printaddr(tcp->u_arg[2]);
702 } else {
703 printsock(tcp, tcp->u_arg[1], len);
704 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000706
Paolo Bonzini705ff102009-08-14 12:34:05 +0200707 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200708 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200709 printflags(sock_type_flags, tcp->u_arg[flags_arg],
710 "SOCK_???");
711 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712 return 0;
713}
714
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000715SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200716{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000717 do_sockname(tcp, -1);
718 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200719}
720
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000721SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200722{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000723 do_sockname(tcp, 3);
724 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200725}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200726
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000727SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000728{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000729 printfd(tcp, tcp->u_arg[0]);
730 tprints(", ");
731 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
732 tprintf(", %lu, ", tcp->u_arg[2]);
733 /* flags */
734 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
735
736 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000737}
738
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000739SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000741 printfd(tcp, tcp->u_arg[0]);
742 tprints(", ");
743 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
744 tprintf(", %lu, ", tcp->u_arg[2]);
745 /* flags */
746 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
747 /* to address */
748 tprints(", ");
749 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
750 /* to length */
751 tprintf(", %lu", tcp->u_arg[5]);
752
753 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000754}
755
756#ifdef HAVE_SENDMSG
757
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000758SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000760 printfd(tcp, tcp->u_arg[0]);
761 tprints(", ");
762 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
763 /* flags */
764 tprints(", ");
765 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
766
767 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768}
769
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000770SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000771{
772 if (entering(tcp)) {
773 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800774 printfd(tcp, tcp->u_arg[0]);
775 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000776 if (!verbose(tcp)) {
777 tprintf("%#lx, %u, ",
778 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
779 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
780 }
781 } else {
782 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000783 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000784 }
785 return 0;
786}
787
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788#endif /* HAVE_SENDMSG */
789
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000790SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000791{
792 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800793 printfd(tcp, tcp->u_arg[0]);
794 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795 } else {
796 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000797 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000798 else
799 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
800
801 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000802 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000803 }
804 return 0;
805}
806
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000807SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000808{
809 int fromlen;
810
811 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800812 printfd(tcp, tcp->u_arg[0]);
813 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200816 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000817 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200818 } else {
819 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
820 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 /* len */
822 tprintf(", %lu, ", tcp->u_arg[2]);
823 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000824 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200825 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000826 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000827 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200828 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000829 printaddr(tcp->u_arg[4]);
830 tprints(", ");
831 printaddr(tcp->u_arg[5]);
832 return 0;
833 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200834 /* from address */
835 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836 /* from length */
837 tprintf(", [%u]", fromlen);
838 }
839 return 0;
840}
841
842#ifdef HAVE_SENDMSG
843
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000844SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845{
846 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800847 printfd(tcp, tcp->u_arg[0]);
848 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000850 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000851 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200853 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200855 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000856 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857 }
858 return 0;
859}
860
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000861SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +0100862{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100863 /* +5 chars are for "left " prefix */
864 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400865
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100866 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800867 printfd(tcp, tcp->u_arg[0]);
868 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400869 if (verbose(tcp)) {
870 sprint_timespec(str, tcp, tcp->u_arg[4]);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100871 /* Abusing tcp->auxstr as temp storage.
872 * Will be used and freed on syscall exit.
873 */
Dmitry V. Levin3e9d71f2015-05-25 20:41:02 +0000874 tcp->auxstr = xstrdup(str);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400875 } else {
876 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
877 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200878 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400879 print_timespec(tcp, tcp->u_arg[4]);
880 }
881 return 0;
882 } else {
883 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000884 decode_mmsg(tcp, 0);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400885 /* timeout on entrance */
886 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
887 free((void *) tcp->auxstr);
888 tcp->auxstr = NULL;
889 }
890 if (syserror(tcp))
891 return 0;
892 if (tcp->u_rval == 0) {
893 tcp->auxstr = "Timeout";
894 return RVAL_STR;
895 }
896 if (!verbose(tcp))
897 return 0;
898 /* timeout on exit */
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100899 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400900 tcp->auxstr = str;
901 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100902 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100903}
Andreas Schwab0873f292010-02-12 21:39:12 +0100904
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000905#endif /* HAVE_SENDMSG */
906
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000907#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100908
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000909SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000911 printfd(tcp, tcp->u_arg[0]);
912 tprints(", ");
913 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
914
915 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916}
917
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000918SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000920 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000921}
922
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000923static void
924printpair_fd(struct tcb *tcp, const int i0, const int i1)
925{
926 tprints("[");
927 printfd(tcp, i0);
928 tprints(", ");
929 printfd(tcp, i1);
930 tprints("]");
931}
932
933static void
934decode_pair_fd(struct tcb *tcp, const long addr)
935{
936 int pair[2];
937
938 if (umove_or_printaddr(tcp, addr, &pair))
939 return;
940
941 printpair_fd(tcp, pair[0], pair[1]);
942}
943
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000944static int
945do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947 if (exiting(tcp)) {
948 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000949 printaddr(tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000950 } else {
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +0000951#ifdef HAVE_GETRVAL2
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000952 if (flags_arg < 0) {
953 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
954 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955#endif
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000956 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000957 }
958 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200959 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000960 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
961 }
962 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963 return 0;
964}
965
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000966SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000967{
968 return do_pipe(tcp, -1);
969}
970
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000971SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000972{
973 return do_pipe(tcp, 1);
974}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000975
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000976SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978 if (entering(tcp)) {
979 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200980 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000981 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000982 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +0000984 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000985 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 }
987 return 0;
988}
989
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000990#include "xlat/sockoptions.h"
991#include "xlat/sockipoptions.h"
992#include "xlat/sockipv6options.h"
993#include "xlat/sockipxoptions.h"
994#include "xlat/sockrawoptions.h"
995#include "xlat/sockpacketoptions.h"
996#include "xlat/socksctpoptions.h"
997#include "xlat/socktcpoptions.h"
998
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000999static void
1000print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001002 printfd(tcp, fd);
1003 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001004 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001005 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001006
John Hughes38ae88d2002-05-23 11:48:58 +00001007 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001008 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001009 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001010 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001011 case SOL_IP:
John Hughes38ae88d2002-05-23 11:48:58 +00001012 printxval(sockipoptions, name, "IP_???");
1013 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001014 case SOL_IPV6:
Roland McGrath4f6ba692004-08-31 07:01:26 +00001015 printxval(sockipv6options, name, "IPV6_???");
1016 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001017 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001018 printxval(sockipxoptions, name, "IPX_???");
1019 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001020 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001021 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001022 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001023 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001024 printxval(socktcpoptions, name, "TCP_???");
1025 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001026 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001027 printxval(socksctpoptions, name, "SCTP_???");
1028 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001029 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001030 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001031 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001032
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001033 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001034
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001035 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001036 tprintf("%u", name);
1037 }
1038
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001039 tprints(", ");
1040}
1041
1042#ifdef SO_LINGER
1043static void
1044print_linger(struct tcb *tcp, long addr, int len)
1045{
1046 struct linger linger;
1047
1048 if (len != sizeof(linger) ||
1049 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001050 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001051 return;
1052 }
1053
1054 tprintf("{onoff=%d, linger=%d}",
1055 linger.l_onoff,
1056 linger.l_linger);
1057}
1058#endif /* SO_LINGER */
1059
1060#ifdef SO_PEERCRED
1061static void
1062print_ucred(struct tcb *tcp, long addr, int len)
1063{
1064 struct ucred uc;
1065
1066 if (len != sizeof(uc) ||
1067 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001068 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001069 } else {
1070 tprintf("{pid=%u, uid=%u, gid=%u}",
1071 (unsigned) uc.pid,
1072 (unsigned) uc.uid,
1073 (unsigned) uc.gid);
1074 }
1075}
1076#endif /* SO_PEERCRED */
1077
1078#ifdef PACKET_STATISTICS
1079static void
1080print_tpacket_stats(struct tcb *tcp, long addr, int len)
1081{
1082 struct tpacket_stats stats;
1083
1084 if (len != sizeof(stats) ||
1085 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001086 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001087 } else {
1088 tprintf("{packets=%u, drops=%u}",
1089 stats.tp_packets,
1090 stats.tp_drops);
1091 }
1092}
1093#endif /* PACKET_STATISTICS */
1094
1095#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001096# include "xlat/icmpfilterflags.h"
1097
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001098static void
1099print_icmp_filter(struct tcb *tcp, long addr, int len)
1100{
1101 struct icmp_filter filter;
1102
1103 if (len != sizeof(filter) ||
1104 umove(tcp, addr, &filter) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001105 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001106 return;
1107 }
1108
1109 tprints("~(");
1110 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1111 tprints(")");
1112}
1113#endif /* ICMP_FILTER */
1114
1115static void
1116print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1117{
1118 if (addr && verbose(tcp))
1119 switch (level) {
1120 case SOL_SOCKET:
1121 switch (name) {
1122#ifdef SO_LINGER
1123 case SO_LINGER:
1124 print_linger(tcp, addr, len);
1125 goto done;
1126#endif
1127#ifdef SO_PEERCRED
1128 case SO_PEERCRED:
1129 print_ucred(tcp, addr, len);
1130 goto done;
1131#endif
1132 }
1133 break;
1134
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001135 case SOL_PACKET:
1136 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001137#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001138 case PACKET_STATISTICS:
1139 print_tpacket_stats(tcp, addr, len);
1140 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001141#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001142 }
1143 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001144
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001145 case SOL_RAW:
1146 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001147#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001148 case ICMP_FILTER:
1149 print_icmp_filter(tcp, addr, len);
1150 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001151#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001152 }
1153 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001154 }
1155
John Hughes38ae88d2002-05-23 11:48:58 +00001156 /* default arg printing */
1157
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001158 if (verbose(tcp)) {
1159 if (len == sizeof(int)) {
1160 printnum_int(tcp, addr, "%d");
1161 } else {
1162 printstr(tcp, addr, len);
1163 }
1164 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001165 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001166 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001167done:
1168 tprintf(", [%d]", len);
1169}
1170
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001171SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001172{
1173 if (entering(tcp)) {
1174 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1175 tcp->u_arg[1], tcp->u_arg[2]);
1176 } else {
1177 int len;
1178
1179 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1180 tprintf("%#lx, %#lx",
1181 tcp->u_arg[3], tcp->u_arg[4]);
1182 } else {
1183 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1184 tcp->u_arg[3], len);
1185 }
John Hughes38ae88d2002-05-23 11:48:58 +00001186 }
1187 return 0;
1188}
1189
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001190#ifdef IP_ADD_MEMBERSHIP
1191static void
1192print_mreq(struct tcb *tcp, long addr, unsigned int len)
1193{
1194 struct ip_mreq mreq;
1195
1196 if (len < sizeof(mreq)) {
1197 printstr(tcp, addr, len);
1198 return;
1199 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001200 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001201 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001202
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001203 tprints("{imr_multiaddr=inet_addr(");
1204 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1205 16, QUOTE_0_TERMINATED);
1206 tprints("), imr_interface=inet_addr(");
1207 print_quoted_string(inet_ntoa(mreq.imr_interface),
1208 16, QUOTE_0_TERMINATED);
1209 tprints(")}");
1210}
1211#endif /* IP_ADD_MEMBERSHIP */
1212
1213#ifdef IPV6_ADD_MEMBERSHIP
1214static void
1215print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1216{
1217 struct ipv6_mreq mreq;
1218
1219 if (len < sizeof(mreq))
1220 goto fail;
1221
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001222 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001223 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001224
1225#ifdef HAVE_INET_NTOP
1226 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1227 char address[INET6_ADDRSTRLEN];
1228
1229 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1230 goto fail;
1231
1232 tprints("{ipv6mr_multiaddr=inet_pton(");
1233 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1234 tprints("), ipv6mr_interface=");
1235 print_ifindex(mreq.ipv6mr_interface);
1236 tprints("}");
1237 return;
1238#endif /* HAVE_INET_NTOP */
1239
1240fail:
1241 printstr(tcp, addr, len);
1242}
1243#endif /* IPV6_ADD_MEMBERSHIP */
1244
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001245#ifdef MCAST_JOIN_GROUP
1246static void
1247print_group_req(struct tcb *tcp, long addr, int len)
1248{
1249 struct group_req greq;
1250
1251 if (len != sizeof(greq) ||
1252 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001253 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001254 return;
1255 }
1256
1257 union {
1258 struct sockaddr *sa;
1259 struct sockaddr_in *sin;
1260#ifdef HAVE_INET_NTOP
1261 struct sockaddr_in6 *sin6;
1262#endif
1263 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1264#ifdef HAVE_INET_NTOP
1265 char str[INET6_ADDRSTRLEN];
1266#endif
1267
1268 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1269 printxval(addrfams, a.sa->sa_family, "AF_???");
1270
1271 switch (a.sa->sa_family) {
1272 case AF_INET:
1273 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1274 ntohs(a.sin->sin_port),
1275 inet_ntoa(a.sin->sin_addr));
1276 return;
1277#ifdef HAVE_INET_NTOP
1278 case AF_INET6:
1279 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1280 break;
1281 tprintf(", sin6_port=htons(%u)"
1282 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1283 ntohs(a.sin6->sin6_port), str);
1284 return;
1285#endif /* HAVE_INET_NTOP */
1286 }
1287
1288 tprints(", sa_data=");
1289 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1290 tprintf("}}");
1291
1292}
1293#endif /* MCAST_JOIN_GROUP */
1294
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001295#ifdef PACKET_RX_RING
1296static void
1297print_tpacket_req(struct tcb *tcp, long addr, int len)
1298{
1299 struct tpacket_req req;
1300
1301 if (len != sizeof(req) ||
1302 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001303 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001304 } else {
1305 tprintf("{block_size=%u, block_nr=%u, "
1306 "frame_size=%u, frame_nr=%u}",
1307 req.tp_block_size,
1308 req.tp_block_nr,
1309 req.tp_frame_size,
1310 req.tp_frame_nr);
1311 }
1312}
1313#endif /* PACKET_RX_RING */
1314
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001315#ifdef PACKET_ADD_MEMBERSHIP
1316# include "xlat/packet_mreq_type.h"
1317
1318static void
1319print_packet_mreq(struct tcb *tcp, long addr, int len)
1320{
1321 struct packet_mreq mreq;
1322
1323 if (len != sizeof(mreq) ||
1324 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001325 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001326 } else {
1327 unsigned int i;
1328
1329 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1330 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1331 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1332 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1333 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1334 for (i = 0; i < mreq.mr_alen; ++i)
1335 tprintf("%02x", mreq.mr_address[i]);
1336 tprints("}");
1337 }
1338}
1339#endif /* PACKET_ADD_MEMBERSHIP */
1340
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001341static void
1342print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1343{
1344 if (addr && verbose(tcp))
1345 switch (level) {
1346 case SOL_SOCKET:
1347 switch (name) {
1348#ifdef SO_LINGER
1349 case SO_LINGER:
1350 print_linger(tcp, addr, len);
1351 goto done;
1352#endif
1353 }
1354 break;
1355
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001356 case SOL_IP:
1357 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001358#ifdef IP_ADD_MEMBERSHIP
1359 case IP_ADD_MEMBERSHIP:
1360 case IP_DROP_MEMBERSHIP:
1361 print_mreq(tcp, addr, len);
1362 goto done;
1363#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001364#ifdef MCAST_JOIN_GROUP
1365 case MCAST_JOIN_GROUP:
1366 case MCAST_LEAVE_GROUP:
1367 print_group_req(tcp, addr, len);
1368 goto done;
1369#endif /* MCAST_JOIN_GROUP */
1370 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001371 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001372
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001373 case SOL_IPV6:
1374 switch (name) {
1375#ifdef IPV6_ADD_MEMBERSHIP
1376 case IPV6_ADD_MEMBERSHIP:
1377 case IPV6_DROP_MEMBERSHIP:
1378# ifdef IPV6_JOIN_ANYCAST
1379 case IPV6_JOIN_ANYCAST:
1380# endif
1381# ifdef IPV6_LEAVE_ANYCAST
1382 case IPV6_LEAVE_ANYCAST:
1383# endif
1384 print_mreq6(tcp, addr, len);
1385 goto done;
1386#endif /* IPV6_ADD_MEMBERSHIP */
1387 }
1388 break;
1389
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001390 case SOL_PACKET:
1391 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001392#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001393 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001394# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001395 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001396# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001397 print_tpacket_req(tcp, addr, len);
1398 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001399#endif /* PACKET_RX_RING */
1400#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001401 case PACKET_ADD_MEMBERSHIP:
1402 case PACKET_DROP_MEMBERSHIP:
1403 print_packet_mreq(tcp, addr, len);
1404 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001405#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001406 }
1407 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001408
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001409 case SOL_RAW:
1410 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001411#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001412 case ICMP_FILTER:
1413 print_icmp_filter(tcp, addr, len);
1414 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001415#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001416 }
1417 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001418 }
1419
1420 /* default arg printing */
1421
1422 if (verbose(tcp)) {
1423 if (len == sizeof(int)) {
1424 printnum_int(tcp, addr, "%d");
1425 } else {
1426 printstr(tcp, addr, len);
1427 }
1428 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001429 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001430 }
1431done:
1432 tprintf(", %d", len);
1433}
1434
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001435SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001437 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1438 tcp->u_arg[1], tcp->u_arg[2]);
1439 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1440 tcp->u_arg[3], tcp->u_arg[4]);
1441
1442 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443}