blob: 4ea79d2c57376980c9bafe1a0d09db21ddb01bf9 [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
Mike Frysinger54646b82015-08-19 13:29:27 -040055#if defined(HAVE_LINUX_IP_VS_H)
56# include <linux/ip_vs.h>
57#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000058#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010059# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000060#endif
Mike Frysinger54646b82015-08-19 13:29:27 -040061#if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
62# include <linux/netfilter_arp/arp_tables.h>
63#endif
64#if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
65# include <linux/netfilter_bridge/ebtables.h>
66#endif
67#if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
68# include <linux/netfilter_ipv4/ip_tables.h>
69#endif
70#if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
71# include <linux/netfilter_ipv6/ip6_tables.h>
72#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000073#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010074# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000075#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000076#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010077# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000078#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020079#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
80# include <bluetooth/bluetooth.h>
81# include <bluetooth/hci.h>
82# include <bluetooth/l2cap.h>
83# include <bluetooth/rfcomm.h>
84# include <bluetooth/sco.h>
85#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010087# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088#endif
89
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000090#include "xlat/domains.h"
91#include "xlat/addrfams.h"
92#include "xlat/socktypes.h"
93#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000094#ifndef SOCK_TYPE_MASK
95# define SOCK_TYPE_MASK 0xf
96#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000097
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000098#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000099
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000100#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900101
102#ifdef PF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +0000103# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
104# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
105# endif
106# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900107#endif
108
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200109#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
110# include "xlat/bt_protocols.h"
111#endif
112
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000113#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000114
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000115#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000116# include "xlat/af_packet_types.h"
117#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000118
Dmitry V. Levinae280932015-06-05 20:13:21 +0000119static void
120print_ifindex(unsigned int ifindex)
121{
122#ifdef HAVE_IF_INDEXTONAME
123 char buf[IFNAMSIZ + 1];
124
125 if (if_indextoname(ifindex, buf)) {
126 tprints("if_nametoindex(");
127 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
128 tprints(")");
129 return;
130 }
131#endif
132 tprintf("%u", ifindex);
133}
134
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000135typedef union {
136 char pad[128];
137 struct sockaddr sa;
138 struct sockaddr_in sin;
139 struct sockaddr_un sau;
140#ifdef HAVE_INET_NTOP
141 struct sockaddr_in6 sa6;
142#endif
143#if defined(AF_IPX)
144 struct sockaddr_ipx sipx;
145#endif
146#ifdef AF_PACKET
147 struct sockaddr_ll ll;
148#endif
149#ifdef AF_NETLINK
150 struct sockaddr_nl nl;
151#endif
152#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
153 struct sockaddr_hci hci;
154 struct sockaddr_l2 l2;
155 struct sockaddr_rc rc;
156 struct sockaddr_sco sco;
157#endif
158} sockaddr_buf_t;
159
160static void
161print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
162{
163 tprints("{sa_family=");
164 printxval(addrfams, addr->sa.sa_family, "AF_???");
165 tprints(", ");
166
167 switch (addr->sa.sa_family) {
168 case AF_UNIX:
169 if (addrlen == 2) {
170 tprints("NULL");
171 } else if (addr->sau.sun_path[0]) {
172 tprints("sun_path=");
173 print_quoted_string(addr->sau.sun_path,
174 sizeof(addr->sau.sun_path) + 1,
175 QUOTE_0_TERMINATED);
176 } else {
177 tprints("sun_path=@");
178 print_quoted_string(addr->sau.sun_path + 1,
179 sizeof(addr->sau.sun_path),
180 QUOTE_0_TERMINATED);
181 }
182 break;
183 case AF_INET:
184 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
185 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
186 break;
187#ifdef HAVE_INET_NTOP
188 case AF_INET6:
189 {
190 char string_addr[100];
191 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
192 string_addr, sizeof(string_addr));
193 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
194 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
195 ntohs(addr->sa6.sin6_port), string_addr,
196 addr->sa6.sin6_flowinfo);
197# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
198 tprints(", sin6_scope_id=");
199# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
200 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
201 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
202 print_ifindex(addr->sa6.sin6_scope_id);
203 else
204# endif
205 tprintf("%u", addr->sa6.sin6_scope_id);
206# endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
207 }
208 break;
209#endif
210#if defined(AF_IPX)
211 case AF_IPX:
212 {
213 int i;
214 tprintf("sipx_port=htons(%u), ",
215 ntohs(addr->sipx.sipx_port));
216 /* Yes, I know, this does not look too
217 * strace-ish, but otherwise the IPX
218 * addresses just look monstrous...
219 * Anyways, feel free if you don't like
220 * this way.. :)
221 */
222 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
223 for (i = 0; i < IPX_NODE_LEN; i++)
224 tprintf("%02x", addr->sipx.sipx_node[i]);
225 tprintf("/[%02x]", addr->sipx.sipx_type);
226 }
227 break;
228#endif /* AF_IPX */
229#ifdef AF_PACKET
230 case AF_PACKET:
231 {
232 int i;
233 tprintf("proto=%#04x, if%d, pkttype=",
234 ntohs(addr->ll.sll_protocol),
235 addr->ll.sll_ifindex);
236 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
237 tprintf(", addr(%d)={%d, ",
238 addr->ll.sll_halen,
239 addr->ll.sll_hatype);
240 for (i = 0; i < addr->ll.sll_halen; i++)
241 tprintf("%02x", addr->ll.sll_addr[i]);
242 }
243 break;
244
245#endif /* AF_PACKET */
246#ifdef AF_NETLINK
247 case AF_NETLINK:
248 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
249 break;
250#endif /* AF_NETLINK */
251#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
252 case AF_BLUETOOTH:
253 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
254 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
255 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
256 "{hci_dev=htobs(%d)}",
257 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
258 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
259 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
260 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
261 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
262 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
263 addr->rc.rc_channel,
264 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
265 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
266 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
267 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
268 btohs(addr->hci.hci_dev));
269 break;
270#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
271 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
272 AF_X25 AF_ROSE etc. still need to be done */
273
274 default:
275 tprints("sa_data=");
276 print_quoted_string(addr->sa.sa_data,
277 sizeof(addr->sa.sa_data), 0);
278 break;
279 }
280 tprints("}");
281}
282
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000284printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285{
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000286 sockaddr_buf_t addrbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287
Denys Vlasenko383386d2015-07-30 13:29:20 +0200288 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000289 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200290 return;
291 }
292
293 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000294 addrlen = sizeof(addrbuf);
295
296 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000297 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000299 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000300
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000301 print_sockaddr(tcp, &addrbuf, addrlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302}
303
Dmitry V. Levinb36d1322015-11-18 23:18:17 +0000304#include "xlat/scmvals.h"
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300305#include "xlat/ip_cmsg_types.h"
Roland McGrath50770822004-10-06 22:11:51 +0000306
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000307#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
308struct cmsghdr32 {
309 uint32_t cmsg_len;
310 int cmsg_level;
311 int cmsg_type;
312};
313#endif
314
315typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000316 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000317 struct cmsghdr *cmsg;
318#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
319 struct cmsghdr32 *cmsg32;
320#endif
321} union_cmsghdr;
322
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000323static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000324print_scm_rights(struct tcb *tcp, const void *cmsg_data,
325 const size_t data_len)
Roland McGrath50770822004-10-06 22:11:51 +0000326{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000327 const int *fds = cmsg_data;
328 const char *end = (const char *) cmsg_data + data_len;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000329 bool seen = false;
330
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000331 if (sizeof(*fds) > data_len)
332 return;
333
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000334 tprints(", [");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000335 while ((const char *) fds < end) {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000336 if (seen)
337 tprints(", ");
338 else
339 seen = true;
340 printfd(tcp, *fds++);
341 }
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000342 tprints("]");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000343}
344
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000345static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000346print_scm_creds(struct tcb *tcp, const void *cmsg_data,
347 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000348{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000349 const struct ucred *uc = cmsg_data;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000350
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000351 if (sizeof(*uc) > data_len)
352 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000353
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000354 tprintf(", {pid=%u, uid=%u, gid=%u}",
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000355 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000356}
357
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000358static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000359print_scm_security(struct tcb *tcp, const void *cmsg_data,
360 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000361{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000362 if (!data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000363 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000364
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000365 tprints(", ");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000366 print_quoted_string(cmsg_data, data_len, 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000367}
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000368
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000369static void
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300370print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
371 const size_t data_len)
372{
373 const struct in_pktinfo *info = cmsg_data;
374
375 if (sizeof(*info) > data_len)
376 return;
377
378 tprints(", {ipi_ifindex=");
379 print_ifindex(info->ipi_ifindex);
380 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
381 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
382}
383
384static void
385print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
386 const size_t data_len)
387{
388 const unsigned int *ttl = cmsg_data;
389
390 if (sizeof(*ttl) > data_len)
391 return;
392
393 tprintf(", {ttl=%u}", *ttl);
394}
395
396static void
397print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
398 const size_t data_len)
399{
400 const uint8_t *tos = cmsg_data;
401
402 if (sizeof(*tos) > data_len)
403 return;
404
405 tprintf(", {tos=%x}", *tos);
406}
407
408static void
409print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
410 const size_t data_len)
411{
412 const uint32_t *csum = cmsg_data;
413
414 if (sizeof(*csum) > data_len)
415 return;
416
417 tprintf(", {csum=%u}", *csum);
418}
419
420static void
421print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
422 const size_t data_len)
423{
Dmitry V. Levina17f5932015-11-22 23:07:52 +0000424 const unsigned char *opts = cmsg_data;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300425 size_t i;
426
427 if (!data_len)
428 return;
429
430 tprints(", {opts=0x");
431 for (i = 0; i < data_len; ++i)
432 tprintf("%02x", opts[i]);
433 tprints("}");
434}
435
436static void
437print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
438 const size_t data_len)
439{
440 const struct {
441 uint32_t ee_errno;
442 uint8_t ee_origin;
443 uint8_t ee_type;
444 uint8_t ee_code;
445 uint8_t ee_pad;
446 uint32_t ee_info;
447 uint32_t ee_data;
448 struct sockaddr_in offender;
449 } *err = cmsg_data;
450
451 if (sizeof(*err) > data_len)
452 return;
453
454 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
455 ", ee_info=%u, ee_data=%u, offender=",
456 err->ee_errno, err->ee_origin, err->ee_type,
457 err->ee_code, err->ee_info, err->ee_data);
458 print_sockaddr(tcp, (const void *) &err->offender,
459 sizeof(err->offender));
460 tprints("}");
461}
462
463static void
464print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
465 const size_t data_len)
466{
467 if (sizeof(struct sockaddr_in) > data_len)
468 return;
469
470 tprints(", ");
471 print_sockaddr(tcp, cmsg_data, data_len);
472}
473
474static void
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000475print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000476 const void *cmsg_data, const size_t data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000477{
478 switch (cmsg_level) {
479 case SOL_SOCKET:
480 printxval(scmvals, cmsg_type, "SCM_???");
481 switch (cmsg_type) {
482 case SCM_RIGHTS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000483 print_scm_rights(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000484 break;
485 case SCM_CREDENTIALS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000486 print_scm_creds(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000487 break;
488 case SCM_SECURITY:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000489 print_scm_security(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000490 break;
491 }
492 break;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300493 case SOL_IP:
494 printxval(ip_cmsg_types, cmsg_type, "IP_???");
495 switch (cmsg_type) {
496 case IP_PKTINFO:
497 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
498 break;
499 case IP_TTL:
500 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
501 break;
502 case IP_TOS:
503 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
504 break;
505 case IP_RECVOPTS:
506 case IP_RETOPTS:
507 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
508 break;
509 case IP_RECVERR:
510 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
511 break;
512 case IP_ORIGDSTADDR:
513 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
514 break;
515 case IP_CHECKSUM:
516 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
517 break;
518 case SCM_SECURITY:
519 print_scm_security(tcp, cmsg_data, data_len);
520 break;
521 }
522 break;
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000523 default:
524 tprintf("%u", cmsg_type);
525 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000526}
527
528static void
529printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
530{
531 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000532#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
533 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
534#endif
535 sizeof(struct cmsghdr);
536
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000537 char *buf = len < cmsg_size ? NULL : malloc(len);
538 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000539 tprints(", msg_control=");
540 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000541 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000542 return;
543 }
544
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000545 union_cmsghdr u = { .ptr = buf };
546
547 tprints(", [");
548 while (len >= cmsg_size) {
549 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000550#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000551 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000552#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000553 u.cmsg->cmsg_len;
554 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000555#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000556 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000557#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000558 u.cmsg->cmsg_level;
559 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000560#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000561 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000562#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000563 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000564
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000565 if (u.ptr != buf)
566 tprints(", ");
567 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
568 printxval(socketlayers, cmsg_level, "SOL_???");
569 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000570
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000571 if (cmsg_len > len)
572 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000573
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000574 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000575 (const void *) (u.ptr + cmsg_size),
576 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000577 tprints("}");
578
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000579 if (cmsg_len < cmsg_size) {
580 len -= cmsg_size;
581 break;
Roland McGrath50770822004-10-06 22:11:51 +0000582 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000583 cmsg_len = (cmsg_len + current_wordsize - 1) &
584 (size_t) ~(current_wordsize - 1);
585 if (cmsg_len >= len) {
586 len = 0;
587 break;
588 }
589 u.ptr += cmsg_len;
590 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000591 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000592 if (len)
593 tprints(", ...");
594 tprints("]");
595 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000596}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597
598static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200599do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100600{
601 tprintf("{msg_name(%d)=", msg->msg_namelen);
602 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
603
604 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200605 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
606 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100607
608#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
609 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
610 if (msg->msg_controllen)
611 printcmsghdr(tcp, (unsigned long) msg->msg_control,
612 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200613 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100614 printflags(msg_flags, msg->msg_flags, "MSG_???");
615#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
616 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
617 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
618#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200619 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100620}
621
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100622struct msghdr32 {
623 uint32_t /* void* */ msg_name;
624 uint32_t /* socklen_t */msg_namelen;
625 uint32_t /* iovec* */ msg_iov;
626 uint32_t /* size_t */ msg_iovlen;
627 uint32_t /* void* */ msg_control;
628 uint32_t /* size_t */ msg_controllen;
629 uint32_t /* int */ msg_flags;
630};
631struct mmsghdr32 {
632 struct msghdr32 msg_hdr;
633 uint32_t /* unsigned */ msg_len;
634};
635
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900636#ifndef HAVE_STRUCT_MMSGHDR
637struct mmsghdr {
638 struct msghdr msg_hdr;
639 unsigned msg_len;
640};
641#endif
642
Masatake YAMATOb2485432014-11-07 01:23:24 +0900643#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
644static void
645copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
646{
647 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
648 to_msg->msg_namelen = from_msg32->msg_namelen;
649 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
650 to_msg->msg_iovlen = from_msg32->msg_iovlen;
651 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
652 to_msg->msg_controllen = from_msg32->msg_controllen;
653 to_msg->msg_flags = from_msg32->msg_flags;
654}
655#endif
656
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900657static bool
658extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
659{
660#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
661 if (current_wordsize == 4) {
662 struct msghdr32 msg32;
663
664 if (umove(tcp, addr, &msg32) < 0)
665 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900666 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900667 } else
668#endif
669 if (umove(tcp, addr, msg) < 0)
670 return false;
671 return true;
672}
673
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900674static bool
675extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
676{
677#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
678 if (current_wordsize == 4) {
679 struct mmsghdr32 mmsg32;
680
681 addr += sizeof(struct mmsghdr32) * idx;
682 if (umove(tcp, addr, &mmsg32) < 0)
683 return false;
684
685 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
686 mmsg->msg_len = mmsg32.msg_len;
687 } else
688#endif
689 {
690 addr += sizeof(*mmsg) * idx;
691 if (umove(tcp, addr, mmsg) < 0)
692 return false;
693 }
694 return true;
695}
696
Andreas Schwab0873f292010-02-12 21:39:12 +0100697static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200698printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699{
700 struct msghdr msg;
701
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000702 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900703 do_msghdr(tcp, &msg, data_size);
704 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000705 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900706}
707
708void
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000709dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900710{
711 struct msghdr msg;
712
713 if (extractmsghdr(tcp, addr, &msg))
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000714 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000715}
716
Andreas Schwab0873f292010-02-12 21:39:12 +0100717static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000718printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100719{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900720 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100721
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900722 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
723 tprints("{");
724 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
725 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100726 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900727 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000728 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100729}
Andreas Schwab0873f292010-02-12 21:39:12 +0100730
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000731static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000732decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000733{
734 /* mmsgvec */
735 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000736 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000737 } else {
738 unsigned int len = tcp->u_rval;
739 unsigned int i;
740
741 tprints("{");
742 for (i = 0; i < len; ++i) {
743 if (i)
744 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000745 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000746 }
747 tprints("}");
748 }
749 /* vlen */
750 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
751 /* flags */
752 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
753}
754
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900755void
756dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
757{
758 unsigned int len = tcp->u_rval;
759 unsigned int i;
760 struct mmsghdr mmsg;
761
762 for (i = 0; i < len; ++i) {
763 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
764 tprintf(" = %lu buffers in vector %u\n",
765 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
Dmitry V. Levind44707d2016-01-20 04:56:25 +0000766 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
767 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900768 }
769 }
770}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000772/*
773 * low bits of the socket type define real socket type,
774 * other bits are socket type flags.
775 */
776static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000777tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000778{
779 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
780
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200781 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200782 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000783 flags &= ~SOCK_TYPE_MASK;
784 if (!flags)
785 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200786 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000787 }
788 printflags(sock_type_flags, flags, "SOCK_???");
789}
790
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000791SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000793 printxval(domains, tcp->u_arg[0], "PF_???");
794 tprints(", ");
795 tprint_sock_type(tcp->u_arg[1]);
796 tprints(", ");
797 switch (tcp->u_arg[0]) {
798 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000799#ifdef PF_INET6
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000800 case PF_INET6:
Roland McGrath8758e542003-06-23 23:39:59 +0000801#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000802 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
803 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000804#ifdef PF_IPX
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000805 case PF_IPX:
806 /* BTW: I don't believe this.. */
807 tprints("[");
808 printxval(domains, tcp->u_arg[2], "PF_???");
809 tprints("]");
810 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000811#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900812#ifdef PF_NETLINK
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000813 case PF_NETLINK:
814 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
815 break;
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900816#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200817#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000818 case PF_BLUETOOTH:
819 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
820 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200821#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000822 default:
823 tprintf("%lu", tcp->u_arg[2]);
824 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000826
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000827 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000828}
829
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000830SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000832 printfd(tcp, tcp->u_arg[0]);
833 tprints(", ");
834 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
835 tprintf(", %lu", tcp->u_arg[2]);
836
837 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838}
839
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000840SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000842 printfd(tcp, tcp->u_arg[0]);
843 tprints(", ");
844 tprintf("%lu", tcp->u_arg[1]);
845
846 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847}
848
Paolo Bonzini705ff102009-08-14 12:34:05 +0200849static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000850do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000851{
852 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800853 printfd(tcp, tcp->u_arg[0]);
854 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200855 return 0;
856 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000857
858 int len;
859 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
860 umove(tcp, tcp->u_arg[2], &len) < 0) {
861 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200862 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000863 printaddr(tcp->u_arg[2]);
864 } else {
865 printsock(tcp, tcp->u_arg[1], len);
866 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000868
Paolo Bonzini705ff102009-08-14 12:34:05 +0200869 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200870 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200871 printflags(sock_type_flags, tcp->u_arg[flags_arg],
872 "SOCK_???");
873 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874 return 0;
875}
876
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000877SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200878{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000879 do_sockname(tcp, -1);
880 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200881}
882
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000883SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200884{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000885 do_sockname(tcp, 3);
886 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200887}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200888
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000889SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000891 printfd(tcp, tcp->u_arg[0]);
892 tprints(", ");
893 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
894 tprintf(", %lu, ", tcp->u_arg[2]);
895 /* flags */
896 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
897
898 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899}
900
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000901SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000902{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000903 printfd(tcp, tcp->u_arg[0]);
904 tprints(", ");
905 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
906 tprintf(", %lu, ", tcp->u_arg[2]);
907 /* flags */
908 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
909 /* to address */
910 tprints(", ");
911 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
912 /* to length */
913 tprintf(", %lu", tcp->u_arg[5]);
914
915 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916}
917
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000918SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000919{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000920 printfd(tcp, tcp->u_arg[0]);
921 tprints(", ");
922 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
923 /* flags */
924 tprints(", ");
925 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
926
927 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000928}
929
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000930SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000931{
932 if (entering(tcp)) {
933 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800934 printfd(tcp, tcp->u_arg[0]);
935 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000936 if (!verbose(tcp)) {
937 tprintf("%#lx, %u, ",
938 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
939 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
940 }
941 } else {
942 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000943 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000944 }
945 return 0;
946}
947
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000948SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949{
950 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800951 printfd(tcp, tcp->u_arg[0]);
952 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 } else {
954 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000955 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956 else
957 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
958
959 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000960 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961 }
962 return 0;
963}
964
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000965SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966{
967 int fromlen;
968
969 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800970 printfd(tcp, tcp->u_arg[0]);
971 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200974 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000975 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200976 } else {
977 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
978 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979 /* len */
980 tprintf(", %lu, ", tcp->u_arg[2]);
981 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000982 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200983 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000984 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000985 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200986 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000987 printaddr(tcp->u_arg[4]);
988 tprints(", ");
989 printaddr(tcp->u_arg[5]);
990 return 0;
991 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200992 /* from address */
993 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994 /* from length */
995 tprintf(", [%u]", fromlen);
996 }
997 return 0;
998}
999
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001000SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001{
1002 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001003 printfd(tcp, tcp->u_arg[0]);
1004 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +00001006 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001007 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001009 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001011 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001012 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013 }
1014 return 0;
1015}
1016
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001017SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +01001018{
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001019 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001020
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001021 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001022 printfd(tcp, tcp->u_arg[0]);
1023 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001024 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001025 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001026 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001027 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001028 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001029 } else {
1030 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1031 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001032 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001033 print_timespec(tcp, tcp->u_arg[4]);
1034 }
1035 return 0;
1036 } else {
1037 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001038 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001039 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001040 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001041 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001042 tcp->auxstr = NULL;
1043 }
1044 if (syserror(tcp))
1045 return 0;
1046 if (tcp->u_rval == 0) {
1047 tcp->auxstr = "Timeout";
1048 return RVAL_STR;
1049 }
1050 if (!verbose(tcp))
1051 return 0;
1052 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001053 snprintf(str, sizeof(str), "left %s",
1054 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +04001055 tcp->auxstr = str;
1056 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001057 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001058}
Andreas Schwab0873f292010-02-12 21:39:12 +01001059
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001060#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001061
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001062SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001064 printfd(tcp, tcp->u_arg[0]);
1065 tprints(", ");
1066 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1067
1068 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069}
1070
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001071SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001073 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074}
1075
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001076static void
1077printpair_fd(struct tcb *tcp, const int i0, const int i1)
1078{
1079 tprints("[");
1080 printfd(tcp, i0);
1081 tprints(", ");
1082 printfd(tcp, i1);
1083 tprints("]");
1084}
1085
1086static void
1087decode_pair_fd(struct tcb *tcp, const long addr)
1088{
1089 int pair[2];
1090
1091 if (umove_or_printaddr(tcp, addr, &pair))
1092 return;
1093
1094 printpair_fd(tcp, pair[0], pair[1]);
1095}
1096
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001097static int
1098do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 if (exiting(tcp)) {
1101 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001102 printaddr(tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001103 } else {
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +00001104#ifdef HAVE_GETRVAL2
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001105 if (flags_arg < 0) {
1106 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1107 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108#endif
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001109 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001110 }
1111 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001112 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001113 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1114 }
1115 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 return 0;
1117}
1118
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001119SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001120{
1121 return do_pipe(tcp, -1);
1122}
1123
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001124SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001125{
1126 return do_pipe(tcp, 1);
1127}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001128
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001129SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001131 if (entering(tcp)) {
1132 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001133 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001134 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001135 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001136 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +00001137 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001138 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001139 }
1140 return 0;
1141}
1142
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001143#include "xlat/sockoptions.h"
1144#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001145#include "xlat/getsockipoptions.h"
1146#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001147#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001148#include "xlat/getsockipv6options.h"
1149#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001150#include "xlat/sockipxoptions.h"
1151#include "xlat/sockrawoptions.h"
1152#include "xlat/sockpacketoptions.h"
1153#include "xlat/socksctpoptions.h"
1154#include "xlat/socktcpoptions.h"
1155
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001156static void
Mike Frysinger54646b82015-08-19 13:29:27 -04001157print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001158{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001159 printfd(tcp, fd);
1160 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001161 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001162 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001163
John Hughes38ae88d2002-05-23 11:48:58 +00001164 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001165 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001166 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001167 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001168 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001169 printxvals(name, "IP_???", sockipoptions,
1170 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001171 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001172 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001173 printxvals(name, "IPV6_???", sockipv6options,
1174 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001175 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001176 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001177 printxval(sockipxoptions, name, "IPX_???");
1178 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001179 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001180 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001181 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001182 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001183 printxval(socktcpoptions, name, "TCP_???");
1184 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001185 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001186 printxval(socksctpoptions, name, "SCTP_???");
1187 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001188 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001189 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001190 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001191
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001192 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001193
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001194 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001195 tprintf("%u", name);
1196 }
1197
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001198 tprints(", ");
1199}
1200
1201#ifdef SO_LINGER
1202static void
1203print_linger(struct tcb *tcp, long addr, int len)
1204{
1205 struct linger linger;
1206
1207 if (len != sizeof(linger) ||
1208 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001209 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001210 return;
1211 }
1212
1213 tprintf("{onoff=%d, linger=%d}",
1214 linger.l_onoff,
1215 linger.l_linger);
1216}
1217#endif /* SO_LINGER */
1218
1219#ifdef SO_PEERCRED
1220static void
1221print_ucred(struct tcb *tcp, long addr, int len)
1222{
1223 struct ucred uc;
1224
1225 if (len != sizeof(uc) ||
1226 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001227 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001228 } else {
1229 tprintf("{pid=%u, uid=%u, gid=%u}",
1230 (unsigned) uc.pid,
1231 (unsigned) uc.uid,
1232 (unsigned) uc.gid);
1233 }
1234}
1235#endif /* SO_PEERCRED */
1236
1237#ifdef PACKET_STATISTICS
1238static void
1239print_tpacket_stats(struct tcb *tcp, long addr, int len)
1240{
1241 struct tpacket_stats stats;
1242
1243 if (len != sizeof(stats) ||
1244 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001245 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001246 } else {
1247 tprintf("{packets=%u, drops=%u}",
1248 stats.tp_packets,
1249 stats.tp_drops);
1250 }
1251}
1252#endif /* PACKET_STATISTICS */
1253
1254#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001255# include "xlat/icmpfilterflags.h"
1256
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001257static void
1258print_icmp_filter(struct tcb *tcp, long addr, int len)
1259{
1260 struct icmp_filter filter;
1261
1262 if (len != sizeof(filter) ||
1263 umove(tcp, addr, &filter) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001264 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001265 return;
1266 }
1267
1268 tprints("~(");
1269 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1270 tprints(")");
1271}
1272#endif /* ICMP_FILTER */
1273
1274static void
1275print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1276{
1277 if (addr && verbose(tcp))
1278 switch (level) {
1279 case SOL_SOCKET:
1280 switch (name) {
1281#ifdef SO_LINGER
1282 case SO_LINGER:
1283 print_linger(tcp, addr, len);
1284 goto done;
1285#endif
1286#ifdef SO_PEERCRED
1287 case SO_PEERCRED:
1288 print_ucred(tcp, addr, len);
1289 goto done;
1290#endif
1291 }
1292 break;
1293
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001294 case SOL_PACKET:
1295 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001296#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001297 case PACKET_STATISTICS:
1298 print_tpacket_stats(tcp, addr, len);
1299 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001300#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001301 }
1302 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001303
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001304 case SOL_RAW:
1305 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001306#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001307 case ICMP_FILTER:
1308 print_icmp_filter(tcp, addr, len);
1309 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001310#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001311 }
1312 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001313 }
1314
John Hughes38ae88d2002-05-23 11:48:58 +00001315 /* default arg printing */
1316
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001317 if (verbose(tcp)) {
1318 if (len == sizeof(int)) {
1319 printnum_int(tcp, addr, "%d");
1320 } else {
1321 printstr(tcp, addr, len);
1322 }
1323 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001324 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001325 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001326done:
1327 tprintf(", [%d]", len);
1328}
1329
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001330SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001331{
1332 if (entering(tcp)) {
1333 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001334 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001335 } else {
1336 int len;
1337
1338 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1339 tprintf("%#lx, %#lx",
1340 tcp->u_arg[3], tcp->u_arg[4]);
1341 } else {
1342 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1343 tcp->u_arg[3], len);
1344 }
John Hughes38ae88d2002-05-23 11:48:58 +00001345 }
1346 return 0;
1347}
1348
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001349#ifdef IP_ADD_MEMBERSHIP
1350static void
1351print_mreq(struct tcb *tcp, long addr, unsigned int len)
1352{
1353 struct ip_mreq mreq;
1354
1355 if (len < sizeof(mreq)) {
1356 printstr(tcp, addr, len);
1357 return;
1358 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001359 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001360 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001361
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001362 tprints("{imr_multiaddr=inet_addr(");
1363 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1364 16, QUOTE_0_TERMINATED);
1365 tprints("), imr_interface=inet_addr(");
1366 print_quoted_string(inet_ntoa(mreq.imr_interface),
1367 16, QUOTE_0_TERMINATED);
1368 tprints(")}");
1369}
1370#endif /* IP_ADD_MEMBERSHIP */
1371
1372#ifdef IPV6_ADD_MEMBERSHIP
1373static void
1374print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1375{
1376 struct ipv6_mreq mreq;
1377
1378 if (len < sizeof(mreq))
1379 goto fail;
1380
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001381 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001382 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001383
1384#ifdef HAVE_INET_NTOP
1385 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1386 char address[INET6_ADDRSTRLEN];
1387
1388 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1389 goto fail;
1390
1391 tprints("{ipv6mr_multiaddr=inet_pton(");
1392 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1393 tprints("), ipv6mr_interface=");
1394 print_ifindex(mreq.ipv6mr_interface);
1395 tprints("}");
1396 return;
1397#endif /* HAVE_INET_NTOP */
1398
1399fail:
1400 printstr(tcp, addr, len);
1401}
1402#endif /* IPV6_ADD_MEMBERSHIP */
1403
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001404#ifdef MCAST_JOIN_GROUP
1405static void
1406print_group_req(struct tcb *tcp, long addr, int len)
1407{
1408 struct group_req greq;
1409
1410 if (len != sizeof(greq) ||
1411 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001412 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001413 return;
1414 }
1415
Dmitry V. Levin1019f002015-11-21 02:38:59 +00001416 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1417 print_sockaddr(tcp, (const void *) &greq.gr_group,
1418 sizeof(greq.gr_group));
1419 tprintf("}");
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001420
1421}
1422#endif /* MCAST_JOIN_GROUP */
1423
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001424#ifdef PACKET_RX_RING
1425static void
1426print_tpacket_req(struct tcb *tcp, long addr, int len)
1427{
1428 struct tpacket_req req;
1429
1430 if (len != sizeof(req) ||
1431 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001432 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001433 } else {
1434 tprintf("{block_size=%u, block_nr=%u, "
1435 "frame_size=%u, frame_nr=%u}",
1436 req.tp_block_size,
1437 req.tp_block_nr,
1438 req.tp_frame_size,
1439 req.tp_frame_nr);
1440 }
1441}
1442#endif /* PACKET_RX_RING */
1443
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001444#ifdef PACKET_ADD_MEMBERSHIP
1445# include "xlat/packet_mreq_type.h"
1446
1447static void
1448print_packet_mreq(struct tcb *tcp, long addr, int len)
1449{
1450 struct packet_mreq mreq;
1451
1452 if (len != sizeof(mreq) ||
1453 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001454 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001455 } else {
1456 unsigned int i;
1457
1458 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1459 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1460 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1461 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1462 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1463 for (i = 0; i < mreq.mr_alen; ++i)
1464 tprintf("%02x", mreq.mr_address[i]);
1465 tprints("}");
1466 }
1467}
1468#endif /* PACKET_ADD_MEMBERSHIP */
1469
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001470static void
1471print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1472{
1473 if (addr && verbose(tcp))
1474 switch (level) {
1475 case SOL_SOCKET:
1476 switch (name) {
1477#ifdef SO_LINGER
1478 case SO_LINGER:
1479 print_linger(tcp, addr, len);
1480 goto done;
1481#endif
1482 }
1483 break;
1484
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001485 case SOL_IP:
1486 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001487#ifdef IP_ADD_MEMBERSHIP
1488 case IP_ADD_MEMBERSHIP:
1489 case IP_DROP_MEMBERSHIP:
1490 print_mreq(tcp, addr, len);
1491 goto done;
1492#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001493#ifdef MCAST_JOIN_GROUP
1494 case MCAST_JOIN_GROUP:
1495 case MCAST_LEAVE_GROUP:
1496 print_group_req(tcp, addr, len);
1497 goto done;
1498#endif /* MCAST_JOIN_GROUP */
1499 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001500 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001501
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001502 case SOL_IPV6:
1503 switch (name) {
1504#ifdef IPV6_ADD_MEMBERSHIP
1505 case IPV6_ADD_MEMBERSHIP:
1506 case IPV6_DROP_MEMBERSHIP:
1507# ifdef IPV6_JOIN_ANYCAST
1508 case IPV6_JOIN_ANYCAST:
1509# endif
1510# ifdef IPV6_LEAVE_ANYCAST
1511 case IPV6_LEAVE_ANYCAST:
1512# endif
1513 print_mreq6(tcp, addr, len);
1514 goto done;
1515#endif /* IPV6_ADD_MEMBERSHIP */
1516 }
1517 break;
1518
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001519 case SOL_PACKET:
1520 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001521#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001522 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001523# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001524 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001525# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001526 print_tpacket_req(tcp, addr, len);
1527 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001528#endif /* PACKET_RX_RING */
1529#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001530 case PACKET_ADD_MEMBERSHIP:
1531 case PACKET_DROP_MEMBERSHIP:
1532 print_packet_mreq(tcp, addr, len);
1533 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001534#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001535 }
1536 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001537
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001538 case SOL_RAW:
1539 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001540#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001541 case ICMP_FILTER:
1542 print_icmp_filter(tcp, addr, len);
1543 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001544#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001545 }
1546 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001547 }
1548
1549 /* default arg printing */
1550
1551 if (verbose(tcp)) {
1552 if (len == sizeof(int)) {
1553 printnum_int(tcp, addr, "%d");
1554 } else {
1555 printstr(tcp, addr, len);
1556 }
1557 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001558 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001559 }
1560done:
1561 tprintf(", %d", len);
1562}
1563
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001564SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001566 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001567 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001568 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1569 tcp->u_arg[3], tcp->u_arg[4]);
1570
1571 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572}