blob: 8cc97da1c3e2adcb3e7d0f3eb53ea55f55ef7f8d [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
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000087#include "xlat/addrfams.h"
88#include "xlat/socktypes.h"
89#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000090#ifndef SOCK_TYPE_MASK
91# define SOCK_TYPE_MASK 0xf
92#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000093
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000094#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000095
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000096#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090097
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +000098#ifdef AF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +000099# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
100# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
101# endif
102# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900103#endif
104
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200105#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
106# include "xlat/bt_protocols.h"
107#endif
108
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000109#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000110
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000111#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000112# include "xlat/af_packet_types.h"
113#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000114
Dmitry V. Levinae280932015-06-05 20:13:21 +0000115static void
116print_ifindex(unsigned int ifindex)
117{
118#ifdef HAVE_IF_INDEXTONAME
119 char buf[IFNAMSIZ + 1];
120
121 if (if_indextoname(ifindex, buf)) {
122 tprints("if_nametoindex(");
123 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
124 tprints(")");
125 return;
126 }
127#endif
128 tprintf("%u", ifindex);
129}
130
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000131typedef union {
132 char pad[128];
133 struct sockaddr sa;
134 struct sockaddr_in sin;
135 struct sockaddr_un sau;
136#ifdef HAVE_INET_NTOP
137 struct sockaddr_in6 sa6;
138#endif
139#if defined(AF_IPX)
140 struct sockaddr_ipx sipx;
141#endif
142#ifdef AF_PACKET
143 struct sockaddr_ll ll;
144#endif
145#ifdef AF_NETLINK
146 struct sockaddr_nl nl;
147#endif
148#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
149 struct sockaddr_hci hci;
150 struct sockaddr_l2 l2;
151 struct sockaddr_rc rc;
152 struct sockaddr_sco sco;
153#endif
154} sockaddr_buf_t;
155
156static void
157print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
158{
159 tprints("{sa_family=");
160 printxval(addrfams, addr->sa.sa_family, "AF_???");
161 tprints(", ");
162
163 switch (addr->sa.sa_family) {
164 case AF_UNIX:
165 if (addrlen == 2) {
166 tprints("NULL");
167 } else if (addr->sau.sun_path[0]) {
168 tprints("sun_path=");
169 print_quoted_string(addr->sau.sun_path,
170 sizeof(addr->sau.sun_path) + 1,
171 QUOTE_0_TERMINATED);
172 } else {
173 tprints("sun_path=@");
174 print_quoted_string(addr->sau.sun_path + 1,
175 sizeof(addr->sau.sun_path),
176 QUOTE_0_TERMINATED);
177 }
178 break;
179 case AF_INET:
180 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
181 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
182 break;
183#ifdef HAVE_INET_NTOP
184 case AF_INET6:
185 {
186 char string_addr[100];
187 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
188 string_addr, sizeof(string_addr));
189 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
190 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
191 ntohs(addr->sa6.sin6_port), string_addr,
192 addr->sa6.sin6_flowinfo);
193# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
194 tprints(", sin6_scope_id=");
195# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
196 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
197 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
198 print_ifindex(addr->sa6.sin6_scope_id);
199 else
200# endif
201 tprintf("%u", addr->sa6.sin6_scope_id);
202# endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
203 }
204 break;
205#endif
206#if defined(AF_IPX)
207 case AF_IPX:
208 {
209 int i;
210 tprintf("sipx_port=htons(%u), ",
211 ntohs(addr->sipx.sipx_port));
212 /* Yes, I know, this does not look too
213 * strace-ish, but otherwise the IPX
214 * addresses just look monstrous...
215 * Anyways, feel free if you don't like
216 * this way.. :)
217 */
218 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
219 for (i = 0; i < IPX_NODE_LEN; i++)
220 tprintf("%02x", addr->sipx.sipx_node[i]);
221 tprintf("/[%02x]", addr->sipx.sipx_type);
222 }
223 break;
224#endif /* AF_IPX */
225#ifdef AF_PACKET
226 case AF_PACKET:
227 {
228 int i;
229 tprintf("proto=%#04x, if%d, pkttype=",
230 ntohs(addr->ll.sll_protocol),
231 addr->ll.sll_ifindex);
232 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
233 tprintf(", addr(%d)={%d, ",
234 addr->ll.sll_halen,
235 addr->ll.sll_hatype);
236 for (i = 0; i < addr->ll.sll_halen; i++)
237 tprintf("%02x", addr->ll.sll_addr[i]);
238 }
239 break;
240
241#endif /* AF_PACKET */
242#ifdef AF_NETLINK
243 case AF_NETLINK:
244 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
245 break;
246#endif /* AF_NETLINK */
247#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
248 case AF_BLUETOOTH:
249 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
250 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
251 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
252 "{hci_dev=htobs(%d)}",
253 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
254 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
255 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
256 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
257 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
258 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
259 addr->rc.rc_channel,
260 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
261 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
262 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
263 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
264 btohs(addr->hci.hci_dev));
265 break;
266#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
267 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
268 AF_X25 AF_ROSE etc. still need to be done */
269
270 default:
271 tprints("sa_data=");
272 print_quoted_string(addr->sa.sa_data,
273 sizeof(addr->sa.sa_data), 0);
274 break;
275 }
276 tprints("}");
277}
278
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000280printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281{
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000282 sockaddr_buf_t addrbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283
Denys Vlasenko383386d2015-07-30 13:29:20 +0200284 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000285 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200286 return;
287 }
288
289 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000290 addrlen = sizeof(addrbuf);
291
292 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000293 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000295 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000296
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000297 print_sockaddr(tcp, &addrbuf, addrlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298}
299
Dmitry V. Levinb36d1322015-11-18 23:18:17 +0000300#include "xlat/scmvals.h"
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300301#include "xlat/ip_cmsg_types.h"
Roland McGrath50770822004-10-06 22:11:51 +0000302
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000303#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
304struct cmsghdr32 {
305 uint32_t cmsg_len;
306 int cmsg_level;
307 int cmsg_type;
308};
309#endif
310
311typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000312 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000313 struct cmsghdr *cmsg;
314#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
315 struct cmsghdr32 *cmsg32;
316#endif
317} union_cmsghdr;
318
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000319static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000320print_scm_rights(struct tcb *tcp, const void *cmsg_data,
321 const size_t data_len)
Roland McGrath50770822004-10-06 22:11:51 +0000322{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000323 const int *fds = cmsg_data;
324 const char *end = (const char *) cmsg_data + data_len;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000325 bool seen = false;
326
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000327 if (sizeof(*fds) > data_len)
328 return;
329
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000330 tprints(", [");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000331 while ((const char *) fds < end) {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000332 if (seen)
333 tprints(", ");
334 else
335 seen = true;
336 printfd(tcp, *fds++);
337 }
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000338 tprints("]");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000339}
340
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000341static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000342print_scm_creds(struct tcb *tcp, const void *cmsg_data,
343 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000344{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000345 const struct ucred *uc = cmsg_data;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000346
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000347 if (sizeof(*uc) > data_len)
348 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000349
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000350 tprintf(", {pid=%u, uid=%u, gid=%u}",
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000351 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000352}
353
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000354static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000355print_scm_security(struct tcb *tcp, const void *cmsg_data,
356 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000357{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000358 if (!data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000359 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000360
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000361 tprints(", ");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000362 print_quoted_string(cmsg_data, data_len, 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000363}
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000364
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000365static void
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300366print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
367 const size_t data_len)
368{
369 const struct in_pktinfo *info = cmsg_data;
370
371 if (sizeof(*info) > data_len)
372 return;
373
374 tprints(", {ipi_ifindex=");
375 print_ifindex(info->ipi_ifindex);
376 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
377 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
378}
379
380static void
381print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
382 const size_t data_len)
383{
384 const unsigned int *ttl = cmsg_data;
385
386 if (sizeof(*ttl) > data_len)
387 return;
388
389 tprintf(", {ttl=%u}", *ttl);
390}
391
392static void
393print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
394 const size_t data_len)
395{
396 const uint8_t *tos = cmsg_data;
397
398 if (sizeof(*tos) > data_len)
399 return;
400
401 tprintf(", {tos=%x}", *tos);
402}
403
404static void
405print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
406 const size_t data_len)
407{
408 const uint32_t *csum = cmsg_data;
409
410 if (sizeof(*csum) > data_len)
411 return;
412
413 tprintf(", {csum=%u}", *csum);
414}
415
416static void
417print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
418 const size_t data_len)
419{
Dmitry V. Levina17f5932015-11-22 23:07:52 +0000420 const unsigned char *opts = cmsg_data;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300421 size_t i;
422
423 if (!data_len)
424 return;
425
426 tprints(", {opts=0x");
427 for (i = 0; i < data_len; ++i)
428 tprintf("%02x", opts[i]);
429 tprints("}");
430}
431
432static void
433print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
434 const size_t data_len)
435{
436 const struct {
437 uint32_t ee_errno;
438 uint8_t ee_origin;
439 uint8_t ee_type;
440 uint8_t ee_code;
441 uint8_t ee_pad;
442 uint32_t ee_info;
443 uint32_t ee_data;
444 struct sockaddr_in offender;
445 } *err = cmsg_data;
446
447 if (sizeof(*err) > data_len)
448 return;
449
450 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
451 ", ee_info=%u, ee_data=%u, offender=",
452 err->ee_errno, err->ee_origin, err->ee_type,
453 err->ee_code, err->ee_info, err->ee_data);
454 print_sockaddr(tcp, (const void *) &err->offender,
455 sizeof(err->offender));
456 tprints("}");
457}
458
459static void
460print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
461 const size_t data_len)
462{
463 if (sizeof(struct sockaddr_in) > data_len)
464 return;
465
466 tprints(", ");
467 print_sockaddr(tcp, cmsg_data, data_len);
468}
469
470static void
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000471print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000472 const void *cmsg_data, const size_t data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000473{
474 switch (cmsg_level) {
475 case SOL_SOCKET:
476 printxval(scmvals, cmsg_type, "SCM_???");
477 switch (cmsg_type) {
478 case SCM_RIGHTS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000479 print_scm_rights(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000480 break;
481 case SCM_CREDENTIALS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000482 print_scm_creds(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000483 break;
484 case SCM_SECURITY:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000485 print_scm_security(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000486 break;
487 }
488 break;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300489 case SOL_IP:
490 printxval(ip_cmsg_types, cmsg_type, "IP_???");
491 switch (cmsg_type) {
492 case IP_PKTINFO:
493 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
494 break;
495 case IP_TTL:
496 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
497 break;
498 case IP_TOS:
499 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
500 break;
501 case IP_RECVOPTS:
502 case IP_RETOPTS:
503 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
504 break;
505 case IP_RECVERR:
506 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
507 break;
508 case IP_ORIGDSTADDR:
509 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
510 break;
511 case IP_CHECKSUM:
512 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
513 break;
514 case SCM_SECURITY:
515 print_scm_security(tcp, cmsg_data, data_len);
516 break;
517 }
518 break;
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000519 default:
520 tprintf("%u", cmsg_type);
521 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000522}
523
524static void
525printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
526{
527 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000528#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
529 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
530#endif
531 sizeof(struct cmsghdr);
532
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000533 char *buf = len < cmsg_size ? NULL : malloc(len);
534 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000535 tprints(", msg_control=");
536 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000537 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000538 return;
539 }
540
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000541 union_cmsghdr u = { .ptr = buf };
542
543 tprints(", [");
544 while (len >= cmsg_size) {
545 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000546#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000547 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000548#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000549 u.cmsg->cmsg_len;
550 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000551#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000552 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000553#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000554 u.cmsg->cmsg_level;
555 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000556#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000557 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000558#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000559 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000560
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000561 if (u.ptr != buf)
562 tprints(", ");
563 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
564 printxval(socketlayers, cmsg_level, "SOL_???");
565 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000566
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000567 if (cmsg_len > len)
568 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000569
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000570 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000571 (const void *) (u.ptr + cmsg_size),
572 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000573 tprints("}");
574
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000575 if (cmsg_len < cmsg_size) {
576 len -= cmsg_size;
577 break;
Roland McGrath50770822004-10-06 22:11:51 +0000578 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000579 cmsg_len = (cmsg_len + current_wordsize - 1) &
580 (size_t) ~(current_wordsize - 1);
581 if (cmsg_len >= len) {
582 len = 0;
583 break;
584 }
585 u.ptr += cmsg_len;
586 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000587 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000588 if (len)
589 tprints(", ...");
590 tprints("]");
591 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000592}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593
594static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200595do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100596{
597 tprintf("{msg_name(%d)=", msg->msg_namelen);
598 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
599
600 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200601 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
602 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100603
604#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
605 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
606 if (msg->msg_controllen)
607 printcmsghdr(tcp, (unsigned long) msg->msg_control,
608 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200609 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100610 printflags(msg_flags, msg->msg_flags, "MSG_???");
611#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
612 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
613 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
614#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200615 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100616}
617
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100618struct msghdr32 {
619 uint32_t /* void* */ msg_name;
620 uint32_t /* socklen_t */msg_namelen;
621 uint32_t /* iovec* */ msg_iov;
622 uint32_t /* size_t */ msg_iovlen;
623 uint32_t /* void* */ msg_control;
624 uint32_t /* size_t */ msg_controllen;
625 uint32_t /* int */ msg_flags;
626};
627struct mmsghdr32 {
628 struct msghdr32 msg_hdr;
629 uint32_t /* unsigned */ msg_len;
630};
631
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900632#ifndef HAVE_STRUCT_MMSGHDR
633struct mmsghdr {
634 struct msghdr msg_hdr;
635 unsigned msg_len;
636};
637#endif
638
Masatake YAMATOb2485432014-11-07 01:23:24 +0900639#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
640static void
641copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
642{
643 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
644 to_msg->msg_namelen = from_msg32->msg_namelen;
645 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
646 to_msg->msg_iovlen = from_msg32->msg_iovlen;
647 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
648 to_msg->msg_controllen = from_msg32->msg_controllen;
649 to_msg->msg_flags = from_msg32->msg_flags;
650}
651#endif
652
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900653static bool
654extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
655{
656#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
657 if (current_wordsize == 4) {
658 struct msghdr32 msg32;
659
660 if (umove(tcp, addr, &msg32) < 0)
661 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900662 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900663 } else
664#endif
665 if (umove(tcp, addr, msg) < 0)
666 return false;
667 return true;
668}
669
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900670static bool
671extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
672{
673#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
674 if (current_wordsize == 4) {
675 struct mmsghdr32 mmsg32;
676
677 addr += sizeof(struct mmsghdr32) * idx;
678 if (umove(tcp, addr, &mmsg32) < 0)
679 return false;
680
681 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
682 mmsg->msg_len = mmsg32.msg_len;
683 } else
684#endif
685 {
686 addr += sizeof(*mmsg) * idx;
687 if (umove(tcp, addr, mmsg) < 0)
688 return false;
689 }
690 return true;
691}
692
Andreas Schwab0873f292010-02-12 21:39:12 +0100693static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200694printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695{
696 struct msghdr msg;
697
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000698 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900699 do_msghdr(tcp, &msg, data_size);
700 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000701 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900702}
703
704void
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000705dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900706{
707 struct msghdr msg;
708
709 if (extractmsghdr(tcp, addr, &msg))
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000710 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711}
712
Andreas Schwab0873f292010-02-12 21:39:12 +0100713static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000714printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100715{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900716 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100717
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900718 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
719 tprints("{");
720 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
721 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100722 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900723 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000724 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100725}
Andreas Schwab0873f292010-02-12 21:39:12 +0100726
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000727static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000728decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000729{
730 /* mmsgvec */
731 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000732 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000733 } else {
734 unsigned int len = tcp->u_rval;
735 unsigned int i;
736
737 tprints("{");
738 for (i = 0; i < len; ++i) {
739 if (i)
740 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000741 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000742 }
743 tprints("}");
744 }
745 /* vlen */
746 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
747 /* flags */
748 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
749}
750
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900751void
752dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
753{
754 unsigned int len = tcp->u_rval;
755 unsigned int i;
756 struct mmsghdr mmsg;
757
758 for (i = 0; i < len; ++i) {
759 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
760 tprintf(" = %lu buffers in vector %u\n",
761 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
Dmitry V. Levind44707d2016-01-20 04:56:25 +0000762 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
763 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900764 }
765 }
766}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000768/*
769 * low bits of the socket type define real socket type,
770 * other bits are socket type flags.
771 */
772static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +0000773tprint_sock_type(unsigned int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000774{
775 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
776
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200777 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200778 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000779 flags &= ~SOCK_TYPE_MASK;
780 if (!flags)
781 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200782 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000783 }
784 printflags(sock_type_flags, flags, "SOCK_???");
785}
786
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000787SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788{
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000789 printxval(addrfams, tcp->u_arg[0], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000790 tprints(", ");
791 tprint_sock_type(tcp->u_arg[1]);
792 tprints(", ");
793 switch (tcp->u_arg[0]) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000794 case AF_INET:
795#ifdef AF_INET6
796 case AF_INET6:
Roland McGrath8758e542003-06-23 23:39:59 +0000797#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000798 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
799 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000800#ifdef AF_IPX
801 case AF_IPX:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000802 /* BTW: I don't believe this.. */
803 tprints("[");
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000804 printxval(addrfams, tcp->u_arg[2], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000805 tprints("]");
806 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000807#endif /* AF_IPX */
808#ifdef AF_NETLINK
809 case AF_NETLINK:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000810 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
811 break;
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900812#endif
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000813#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
814 case AF_BLUETOOTH:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000815 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
816 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200817#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000818 default:
819 tprintf("%lu", tcp->u_arg[2]);
820 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000822
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000823 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824}
825
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000826SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000828 printfd(tcp, tcp->u_arg[0]);
829 tprints(", ");
830 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
831 tprintf(", %lu", tcp->u_arg[2]);
832
833 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834}
835
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000836SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000838 printfd(tcp, tcp->u_arg[0]);
839 tprints(", ");
840 tprintf("%lu", tcp->u_arg[1]);
841
842 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843}
844
Paolo Bonzini705ff102009-08-14 12:34:05 +0200845static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000846do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847{
848 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800849 printfd(tcp, tcp->u_arg[0]);
850 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200851 return 0;
852 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000853
854 int len;
855 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
856 umove(tcp, tcp->u_arg[2], &len) < 0) {
857 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200858 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000859 printaddr(tcp->u_arg[2]);
860 } else {
861 printsock(tcp, tcp->u_arg[1], len);
862 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000863 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000864
Paolo Bonzini705ff102009-08-14 12:34:05 +0200865 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200866 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200867 printflags(sock_type_flags, tcp->u_arg[flags_arg],
868 "SOCK_???");
869 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870 return 0;
871}
872
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000873SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200874{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000875 do_sockname(tcp, -1);
876 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200877}
878
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000879SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200880{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000881 do_sockname(tcp, 3);
882 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200883}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200884
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000885SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000887 printfd(tcp, tcp->u_arg[0]);
888 tprints(", ");
889 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
890 tprintf(", %lu, ", tcp->u_arg[2]);
891 /* flags */
892 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
893
894 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895}
896
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000897SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000899 printfd(tcp, tcp->u_arg[0]);
900 tprints(", ");
901 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
902 tprintf(", %lu, ", tcp->u_arg[2]);
903 /* flags */
904 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
905 /* to address */
906 tprints(", ");
907 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
908 /* to length */
909 tprintf(", %lu", tcp->u_arg[5]);
910
911 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912}
913
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000914SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000916 printfd(tcp, tcp->u_arg[0]);
917 tprints(", ");
918 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
919 /* flags */
920 tprints(", ");
921 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
922
923 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924}
925
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000926SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000927{
928 if (entering(tcp)) {
929 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800930 printfd(tcp, tcp->u_arg[0]);
931 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000932 if (!verbose(tcp)) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000933 printaddr(tcp->u_arg[1]);
934 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000935 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
936 }
937 } else {
938 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000939 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000940 }
941 return 0;
942}
943
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000944SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945{
946 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800947 printfd(tcp, tcp->u_arg[0]);
948 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949 } else {
950 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000951 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952 else
953 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
954
955 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000956 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000957 }
958 return 0;
959}
960
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000961SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962{
963 int fromlen;
964
965 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800966 printfd(tcp, tcp->u_arg[0]);
967 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200970 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000971 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200972 } else {
973 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
974 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 /* len */
976 tprintf(", %lu, ", tcp->u_arg[2]);
977 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000978 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200979 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000980 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000981 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200982 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000983 printaddr(tcp->u_arg[4]);
984 tprints(", ");
985 printaddr(tcp->u_arg[5]);
986 return 0;
987 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200988 /* from address */
989 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 /* from length */
991 tprintf(", [%u]", fromlen);
992 }
993 return 0;
994}
995
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000996SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997{
998 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800999 printfd(tcp, tcp->u_arg[0]);
1000 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001001 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +00001002 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001003 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +02001005 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001007 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001008 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 }
1010 return 0;
1011}
1012
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001013SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +01001014{
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001015 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001016
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001017 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001018 printfd(tcp, tcp->u_arg[0]);
1019 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001020 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001021 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001022 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001023 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001024 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001025 } else {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001026 printaddr(tcp->u_arg[1]);
1027 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001028 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001029 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001030 print_timespec(tcp, tcp->u_arg[4]);
1031 }
1032 return 0;
1033 } else {
1034 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001035 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001036 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001037 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001038 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001039 tcp->auxstr = NULL;
1040 }
1041 if (syserror(tcp))
1042 return 0;
1043 if (tcp->u_rval == 0) {
1044 tcp->auxstr = "Timeout";
1045 return RVAL_STR;
1046 }
1047 if (!verbose(tcp))
1048 return 0;
1049 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001050 snprintf(str, sizeof(str), "left %s",
1051 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +04001052 tcp->auxstr = str;
1053 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001054 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001055}
Andreas Schwab0873f292010-02-12 21:39:12 +01001056
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001057#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001058
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001059SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001061 printfd(tcp, tcp->u_arg[0]);
1062 tprints(", ");
1063 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1064
1065 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066}
1067
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001068SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001070 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071}
1072
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001073static void
1074printpair_fd(struct tcb *tcp, const int i0, const int i1)
1075{
1076 tprints("[");
1077 printfd(tcp, i0);
1078 tprints(", ");
1079 printfd(tcp, i1);
1080 tprints("]");
1081}
1082
1083static void
1084decode_pair_fd(struct tcb *tcp, const long addr)
1085{
1086 int pair[2];
1087
1088 if (umove_or_printaddr(tcp, addr, &pair))
1089 return;
1090
1091 printpair_fd(tcp, pair[0], pair[1]);
1092}
1093
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001094static int
1095do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001097 if (exiting(tcp)) {
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001098 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001099 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001100 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001101 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1102 }
1103 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001104 return 0;
1105}
1106
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001107SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001108{
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001109#ifdef HAVE_GETRVAL2
1110 if (exiting(tcp) && !syserror(tcp))
1111 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1112 return 0;
1113#else
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001114 return do_pipe(tcp, -1);
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001115#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001116}
1117
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001118SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001119{
1120 return do_pipe(tcp, 1);
1121}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001122
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001123SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001124{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125 if (entering(tcp)) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +00001126 printxval(addrfams, tcp->u_arg[0], "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001127 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001128 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001129 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +00001131 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001132 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001133 }
1134 return 0;
1135}
1136
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001137#include "xlat/sockoptions.h"
1138#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001139#include "xlat/getsockipoptions.h"
1140#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001141#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001142#include "xlat/getsockipv6options.h"
1143#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001144#include "xlat/sockipxoptions.h"
1145#include "xlat/sockrawoptions.h"
1146#include "xlat/sockpacketoptions.h"
1147#include "xlat/socksctpoptions.h"
1148#include "xlat/socktcpoptions.h"
1149
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001150static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001151print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1152 unsigned int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001153{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001154 printfd(tcp, fd);
1155 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001156 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001157 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001158
John Hughes38ae88d2002-05-23 11:48:58 +00001159 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001160 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001161 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001162 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001163 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001164 printxvals(name, "IP_???", sockipoptions,
1165 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001166 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001167 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001168 printxvals(name, "IPV6_???", sockipv6options,
1169 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001170 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001171 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001172 printxval(sockipxoptions, name, "IPX_???");
1173 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001174 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001175 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001176 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001177 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001178 printxval(socktcpoptions, name, "TCP_???");
1179 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001180 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001181 printxval(socksctpoptions, name, "SCTP_???");
1182 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001183 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001184 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001185 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001186
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001187 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001188
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001189 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001190 tprintf("%u", name);
1191 }
1192
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001193 tprints(", ");
1194}
1195
1196#ifdef SO_LINGER
1197static void
1198print_linger(struct tcb *tcp, long addr, int len)
1199{
1200 struct linger linger;
1201
1202 if (len != sizeof(linger) ||
1203 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001204 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001205 return;
1206 }
1207
1208 tprintf("{onoff=%d, linger=%d}",
1209 linger.l_onoff,
1210 linger.l_linger);
1211}
1212#endif /* SO_LINGER */
1213
1214#ifdef SO_PEERCRED
1215static void
1216print_ucred(struct tcb *tcp, long addr, int len)
1217{
1218 struct ucred uc;
1219
1220 if (len != sizeof(uc) ||
1221 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001222 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001223 } else {
1224 tprintf("{pid=%u, uid=%u, gid=%u}",
1225 (unsigned) uc.pid,
1226 (unsigned) uc.uid,
1227 (unsigned) uc.gid);
1228 }
1229}
1230#endif /* SO_PEERCRED */
1231
1232#ifdef PACKET_STATISTICS
1233static void
1234print_tpacket_stats(struct tcb *tcp, long addr, int len)
1235{
1236 struct tpacket_stats stats;
1237
1238 if (len != sizeof(stats) ||
1239 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001240 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001241 } else {
1242 tprintf("{packets=%u, drops=%u}",
1243 stats.tp_packets,
1244 stats.tp_drops);
1245 }
1246}
1247#endif /* PACKET_STATISTICS */
1248
1249#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001250# include "xlat/icmpfilterflags.h"
1251
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001252static void
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001253print_icmp_filter(struct tcb *tcp, const long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001254{
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001255 struct icmp_filter filter = {};
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001256
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001257 if (len > (int) sizeof(filter))
1258 len = sizeof(filter);
1259 else if (len <= 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001260 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001261 return;
1262 }
1263
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001264 if (umoven_or_printaddr(tcp, addr, len, &filter))
1265 return;
1266
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001267 tprints("~(");
1268 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1269 tprints(")");
1270}
1271#endif /* ICMP_FILTER */
1272
1273static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001274print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1275 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001276{
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) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001339 printaddr(tcp->u_arg[3]);
1340 tprints(", ");
1341 printaddr(tcp->u_arg[4]);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001342 } else {
1343 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1344 tcp->u_arg[3], len);
1345 }
John Hughes38ae88d2002-05-23 11:48:58 +00001346 }
1347 return 0;
1348}
1349
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001350#ifdef IP_ADD_MEMBERSHIP
1351static void
1352print_mreq(struct tcb *tcp, long addr, unsigned int len)
1353{
1354 struct ip_mreq mreq;
1355
1356 if (len < sizeof(mreq)) {
1357 printstr(tcp, addr, len);
1358 return;
1359 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001360 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001361 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001362
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001363 tprints("{imr_multiaddr=inet_addr(");
1364 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1365 16, QUOTE_0_TERMINATED);
1366 tprints("), imr_interface=inet_addr(");
1367 print_quoted_string(inet_ntoa(mreq.imr_interface),
1368 16, QUOTE_0_TERMINATED);
1369 tprints(")}");
1370}
1371#endif /* IP_ADD_MEMBERSHIP */
1372
1373#ifdef IPV6_ADD_MEMBERSHIP
1374static void
1375print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1376{
1377 struct ipv6_mreq mreq;
1378
1379 if (len < sizeof(mreq))
1380 goto fail;
1381
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001382 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001383 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001384
1385#ifdef HAVE_INET_NTOP
1386 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1387 char address[INET6_ADDRSTRLEN];
1388
1389 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1390 goto fail;
1391
1392 tprints("{ipv6mr_multiaddr=inet_pton(");
1393 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1394 tprints("), ipv6mr_interface=");
1395 print_ifindex(mreq.ipv6mr_interface);
1396 tprints("}");
1397 return;
1398#endif /* HAVE_INET_NTOP */
1399
1400fail:
1401 printstr(tcp, addr, len);
1402}
1403#endif /* IPV6_ADD_MEMBERSHIP */
1404
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001405#ifdef MCAST_JOIN_GROUP
1406static void
1407print_group_req(struct tcb *tcp, long addr, int len)
1408{
1409 struct group_req greq;
1410
1411 if (len != sizeof(greq) ||
1412 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001413 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001414 return;
1415 }
1416
Dmitry V. Levin1019f002015-11-21 02:38:59 +00001417 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1418 print_sockaddr(tcp, (const void *) &greq.gr_group,
1419 sizeof(greq.gr_group));
1420 tprintf("}");
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001421
1422}
1423#endif /* MCAST_JOIN_GROUP */
1424
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001425#ifdef PACKET_RX_RING
1426static void
1427print_tpacket_req(struct tcb *tcp, long addr, int len)
1428{
1429 struct tpacket_req req;
1430
1431 if (len != sizeof(req) ||
1432 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001433 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001434 } else {
1435 tprintf("{block_size=%u, block_nr=%u, "
1436 "frame_size=%u, frame_nr=%u}",
1437 req.tp_block_size,
1438 req.tp_block_nr,
1439 req.tp_frame_size,
1440 req.tp_frame_nr);
1441 }
1442}
1443#endif /* PACKET_RX_RING */
1444
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001445#ifdef PACKET_ADD_MEMBERSHIP
1446# include "xlat/packet_mreq_type.h"
1447
1448static void
1449print_packet_mreq(struct tcb *tcp, long addr, int len)
1450{
1451 struct packet_mreq mreq;
1452
1453 if (len != sizeof(mreq) ||
1454 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001455 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001456 } else {
1457 unsigned int i;
1458
1459 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1460 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1461 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1462 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1463 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1464 for (i = 0; i < mreq.mr_alen; ++i)
1465 tprintf("%02x", mreq.mr_address[i]);
1466 tprints("}");
1467 }
1468}
1469#endif /* PACKET_ADD_MEMBERSHIP */
1470
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001471static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001472print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1473 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001474{
1475 if (addr && verbose(tcp))
1476 switch (level) {
1477 case SOL_SOCKET:
1478 switch (name) {
1479#ifdef SO_LINGER
1480 case SO_LINGER:
1481 print_linger(tcp, addr, len);
1482 goto done;
1483#endif
1484 }
1485 break;
1486
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001487 case SOL_IP:
1488 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001489#ifdef IP_ADD_MEMBERSHIP
1490 case IP_ADD_MEMBERSHIP:
1491 case IP_DROP_MEMBERSHIP:
1492 print_mreq(tcp, addr, len);
1493 goto done;
1494#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001495#ifdef MCAST_JOIN_GROUP
1496 case MCAST_JOIN_GROUP:
1497 case MCAST_LEAVE_GROUP:
1498 print_group_req(tcp, addr, len);
1499 goto done;
1500#endif /* MCAST_JOIN_GROUP */
1501 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001502 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001503
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001504 case SOL_IPV6:
1505 switch (name) {
1506#ifdef IPV6_ADD_MEMBERSHIP
1507 case IPV6_ADD_MEMBERSHIP:
1508 case IPV6_DROP_MEMBERSHIP:
1509# ifdef IPV6_JOIN_ANYCAST
1510 case IPV6_JOIN_ANYCAST:
1511# endif
1512# ifdef IPV6_LEAVE_ANYCAST
1513 case IPV6_LEAVE_ANYCAST:
1514# endif
1515 print_mreq6(tcp, addr, len);
1516 goto done;
1517#endif /* IPV6_ADD_MEMBERSHIP */
1518 }
1519 break;
1520
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001521 case SOL_PACKET:
1522 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001523#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001524 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001525# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001526 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001527# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001528 print_tpacket_req(tcp, addr, len);
1529 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001530#endif /* PACKET_RX_RING */
1531#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001532 case PACKET_ADD_MEMBERSHIP:
1533 case PACKET_DROP_MEMBERSHIP:
1534 print_packet_mreq(tcp, addr, len);
1535 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001536#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001537 }
1538 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001539
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001540 case SOL_RAW:
1541 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001542#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001543 case ICMP_FILTER:
1544 print_icmp_filter(tcp, addr, len);
1545 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001546#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001547 }
1548 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001549 }
1550
1551 /* default arg printing */
1552
1553 if (verbose(tcp)) {
1554 if (len == sizeof(int)) {
1555 printnum_int(tcp, addr, "%d");
1556 } else {
1557 printstr(tcp, addr, len);
1558 }
1559 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001560 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001561 }
1562done:
1563 tprintf(", %d", len);
1564}
1565
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001566SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001567{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001568 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001569 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001570 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1571 tcp->u_arg[3], tcp->u_arg[4]);
1572
1573 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574}