blob: 8ba5e130572c778c3e8cdba28737a9a5f1fda23c [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
Dmitry V. Levinb10ee4e2016-06-14 13:53:47 +000058#include <linux/netlink.h>
Mike Frysinger54646b82015-08-19 13:29:27 -040059#if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
60# include <linux/netfilter_arp/arp_tables.h>
61#endif
62#if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
63# include <linux/netfilter_bridge/ebtables.h>
64#endif
65#if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
66# include <linux/netfilter_ipv4/ip_tables.h>
67#endif
68#if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
69# include <linux/netfilter_ipv6/ip6_tables.h>
70#endif
Dmitry V. Levin4f689a12016-06-15 21:35:48 +000071#include <linux/if_packet.h>
Dmitry V. Levind06010b2016-06-15 21:27:41 +000072#include <linux/icmp.h>
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020073#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
74# include <bluetooth/bluetooth.h>
75# include <bluetooth/hci.h>
76# include <bluetooth/l2cap.h>
77# include <bluetooth/rfcomm.h>
78# include <bluetooth/sco.h>
79#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000081#include "xlat/addrfams.h"
82#include "xlat/socktypes.h"
83#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000084#ifndef SOCK_TYPE_MASK
85# define SOCK_TYPE_MASK 0xf
86#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000087
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000088#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000089
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000090#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090091
Dmitry V. Levin94573042016-06-14 13:53:47 +000092#if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
93# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090094#endif
Dmitry V. Levin94573042016-06-14 13:53:47 +000095#include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090096
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020097#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
98# include "xlat/bt_protocols.h"
99#endif
100
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000101#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000102
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000103#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000104# include "xlat/af_packet_types.h"
105#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000106
Dmitry V. Levinae280932015-06-05 20:13:21 +0000107static void
108print_ifindex(unsigned int ifindex)
109{
110#ifdef HAVE_IF_INDEXTONAME
111 char buf[IFNAMSIZ + 1];
112
113 if (if_indextoname(ifindex, buf)) {
114 tprints("if_nametoindex(");
115 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
116 tprints(")");
117 return;
118 }
119#endif
120 tprintf("%u", ifindex);
121}
122
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000123typedef union {
124 char pad[128];
125 struct sockaddr sa;
126 struct sockaddr_in sin;
127 struct sockaddr_un sau;
128#ifdef HAVE_INET_NTOP
129 struct sockaddr_in6 sa6;
130#endif
131#if defined(AF_IPX)
132 struct sockaddr_ipx sipx;
133#endif
134#ifdef AF_PACKET
135 struct sockaddr_ll ll;
136#endif
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000137 struct sockaddr_nl nl;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000138#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
139 struct sockaddr_hci hci;
140 struct sockaddr_l2 l2;
141 struct sockaddr_rc rc;
142 struct sockaddr_sco sco;
143#endif
144} sockaddr_buf_t;
145
146static void
147print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
148{
149 tprints("{sa_family=");
150 printxval(addrfams, addr->sa.sa_family, "AF_???");
151 tprints(", ");
152
153 switch (addr->sa.sa_family) {
154 case AF_UNIX:
155 if (addrlen == 2) {
156 tprints("NULL");
157 } else if (addr->sau.sun_path[0]) {
158 tprints("sun_path=");
159 print_quoted_string(addr->sau.sun_path,
160 sizeof(addr->sau.sun_path) + 1,
161 QUOTE_0_TERMINATED);
162 } else {
163 tprints("sun_path=@");
164 print_quoted_string(addr->sau.sun_path + 1,
165 sizeof(addr->sau.sun_path),
166 QUOTE_0_TERMINATED);
167 }
168 break;
169 case AF_INET:
170 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
171 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
172 break;
173#ifdef HAVE_INET_NTOP
174 case AF_INET6:
175 {
176 char string_addr[100];
177 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
178 string_addr, sizeof(string_addr));
179 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
180 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
181 ntohs(addr->sa6.sin6_port), string_addr,
182 addr->sa6.sin6_flowinfo);
183# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
184 tprints(", sin6_scope_id=");
185# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
186 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
187 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
188 print_ifindex(addr->sa6.sin6_scope_id);
189 else
190# endif
191 tprintf("%u", addr->sa6.sin6_scope_id);
192# endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
193 }
194 break;
195#endif
196#if defined(AF_IPX)
197 case AF_IPX:
198 {
199 int i;
200 tprintf("sipx_port=htons(%u), ",
201 ntohs(addr->sipx.sipx_port));
202 /* Yes, I know, this does not look too
203 * strace-ish, but otherwise the IPX
204 * addresses just look monstrous...
205 * Anyways, feel free if you don't like
206 * this way.. :)
207 */
208 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
209 for (i = 0; i < IPX_NODE_LEN; i++)
210 tprintf("%02x", addr->sipx.sipx_node[i]);
211 tprintf("/[%02x]", addr->sipx.sipx_type);
212 }
213 break;
214#endif /* AF_IPX */
215#ifdef AF_PACKET
216 case AF_PACKET:
217 {
218 int i;
219 tprintf("proto=%#04x, if%d, pkttype=",
220 ntohs(addr->ll.sll_protocol),
221 addr->ll.sll_ifindex);
222 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
223 tprintf(", addr(%d)={%d, ",
224 addr->ll.sll_halen,
225 addr->ll.sll_hatype);
226 for (i = 0; i < addr->ll.sll_halen; i++)
227 tprintf("%02x", addr->ll.sll_addr[i]);
228 }
229 break;
230
231#endif /* AF_PACKET */
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000232 case AF_NETLINK:
233 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
234 break;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000235#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
236 case AF_BLUETOOTH:
237 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
238 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
239 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
240 "{hci_dev=htobs(%d)}",
241 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
242 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
243 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
244 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
245 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
246 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
247 addr->rc.rc_channel,
248 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
249 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
250 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
251 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
252 btohs(addr->hci.hci_dev));
253 break;
254#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
255 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
256 AF_X25 AF_ROSE etc. still need to be done */
257
258 default:
259 tprints("sa_data=");
260 print_quoted_string(addr->sa.sa_data,
261 sizeof(addr->sa.sa_data), 0);
262 break;
263 }
264 tprints("}");
265}
266
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000268printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269{
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000270 sockaddr_buf_t addrbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271
Denys Vlasenko383386d2015-07-30 13:29:20 +0200272 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000273 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200274 return;
275 }
276
277 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000278 addrlen = sizeof(addrbuf);
279
280 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000281 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000283 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000284
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000285 print_sockaddr(tcp, &addrbuf, addrlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000286}
287
Dmitry V. Levinb36d1322015-11-18 23:18:17 +0000288#include "xlat/scmvals.h"
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300289#include "xlat/ip_cmsg_types.h"
Roland McGrath50770822004-10-06 22:11:51 +0000290
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000291#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
292struct cmsghdr32 {
293 uint32_t cmsg_len;
294 int cmsg_level;
295 int cmsg_type;
296};
297#endif
298
299typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000300 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000301 struct cmsghdr *cmsg;
302#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
303 struct cmsghdr32 *cmsg32;
304#endif
305} union_cmsghdr;
306
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000307static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000308print_scm_rights(struct tcb *tcp, const void *cmsg_data,
309 const size_t data_len)
Roland McGrath50770822004-10-06 22:11:51 +0000310{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000311 const int *fds = cmsg_data;
312 const char *end = (const char *) cmsg_data + data_len;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000313 bool seen = false;
314
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000315 if (sizeof(*fds) > data_len)
316 return;
317
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000318 tprints(", [");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000319 while ((const char *) fds < end) {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000320 if (seen)
321 tprints(", ");
322 else
323 seen = true;
324 printfd(tcp, *fds++);
325 }
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000326 tprints("]");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000327}
328
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000329static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000330print_scm_creds(struct tcb *tcp, const void *cmsg_data,
331 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000332{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000333 const struct ucred *uc = cmsg_data;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000334
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000335 if (sizeof(*uc) > data_len)
336 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000337
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000338 tprintf(", {pid=%u, uid=%u, gid=%u}",
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000339 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000340}
341
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000342static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000343print_scm_security(struct tcb *tcp, const void *cmsg_data,
344 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000345{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000346 if (!data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000347 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000348
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000349 tprints(", ");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000350 print_quoted_string(cmsg_data, data_len, 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000351}
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000352
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000353static void
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300354print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
355 const size_t data_len)
356{
357 const struct in_pktinfo *info = cmsg_data;
358
359 if (sizeof(*info) > data_len)
360 return;
361
362 tprints(", {ipi_ifindex=");
363 print_ifindex(info->ipi_ifindex);
364 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
365 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
366}
367
368static void
369print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
370 const size_t data_len)
371{
372 const unsigned int *ttl = cmsg_data;
373
374 if (sizeof(*ttl) > data_len)
375 return;
376
377 tprintf(", {ttl=%u}", *ttl);
378}
379
380static void
381print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
382 const size_t data_len)
383{
384 const uint8_t *tos = cmsg_data;
385
386 if (sizeof(*tos) > data_len)
387 return;
388
389 tprintf(", {tos=%x}", *tos);
390}
391
392static void
393print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
394 const size_t data_len)
395{
396 const uint32_t *csum = cmsg_data;
397
398 if (sizeof(*csum) > data_len)
399 return;
400
401 tprintf(", {csum=%u}", *csum);
402}
403
404static void
405print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
406 const size_t data_len)
407{
Dmitry V. Levina17f5932015-11-22 23:07:52 +0000408 const unsigned char *opts = cmsg_data;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300409 size_t i;
410
411 if (!data_len)
412 return;
413
414 tprints(", {opts=0x");
415 for (i = 0; i < data_len; ++i)
416 tprintf("%02x", opts[i]);
417 tprints("}");
418}
419
420static void
421print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
422 const size_t data_len)
423{
424 const struct {
425 uint32_t ee_errno;
426 uint8_t ee_origin;
427 uint8_t ee_type;
428 uint8_t ee_code;
429 uint8_t ee_pad;
430 uint32_t ee_info;
431 uint32_t ee_data;
432 struct sockaddr_in offender;
433 } *err = cmsg_data;
434
435 if (sizeof(*err) > data_len)
436 return;
437
438 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
439 ", ee_info=%u, ee_data=%u, offender=",
440 err->ee_errno, err->ee_origin, err->ee_type,
441 err->ee_code, err->ee_info, err->ee_data);
442 print_sockaddr(tcp, (const void *) &err->offender,
443 sizeof(err->offender));
444 tprints("}");
445}
446
447static void
448print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
449 const size_t data_len)
450{
451 if (sizeof(struct sockaddr_in) > data_len)
452 return;
453
454 tprints(", ");
455 print_sockaddr(tcp, cmsg_data, data_len);
456}
457
458static void
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000459print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000460 const void *cmsg_data, const size_t data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000461{
462 switch (cmsg_level) {
463 case SOL_SOCKET:
464 printxval(scmvals, cmsg_type, "SCM_???");
465 switch (cmsg_type) {
466 case SCM_RIGHTS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000467 print_scm_rights(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000468 break;
469 case SCM_CREDENTIALS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000470 print_scm_creds(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000471 break;
472 case SCM_SECURITY:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000473 print_scm_security(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000474 break;
475 }
476 break;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300477 case SOL_IP:
478 printxval(ip_cmsg_types, cmsg_type, "IP_???");
479 switch (cmsg_type) {
480 case IP_PKTINFO:
481 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
482 break;
483 case IP_TTL:
484 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
485 break;
486 case IP_TOS:
487 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
488 break;
489 case IP_RECVOPTS:
490 case IP_RETOPTS:
491 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
492 break;
493 case IP_RECVERR:
494 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
495 break;
496 case IP_ORIGDSTADDR:
497 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
498 break;
499 case IP_CHECKSUM:
500 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
501 break;
502 case SCM_SECURITY:
503 print_scm_security(tcp, cmsg_data, data_len);
504 break;
505 }
506 break;
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000507 default:
508 tprintf("%u", cmsg_type);
509 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000510}
511
512static void
513printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
514{
515 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000516#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
517 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
518#endif
519 sizeof(struct cmsghdr);
520
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000521 char *buf = len < cmsg_size ? NULL : malloc(len);
522 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000523 tprints(", msg_control=");
524 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000525 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000526 return;
527 }
528
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000529 union_cmsghdr u = { .ptr = buf };
530
531 tprints(", [");
532 while (len >= cmsg_size) {
533 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000534#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000535 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000536#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000537 u.cmsg->cmsg_len;
538 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000539#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000540 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000541#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000542 u.cmsg->cmsg_level;
543 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000544#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000545 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000546#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000547 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000548
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000549 if (u.ptr != buf)
550 tprints(", ");
551 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
552 printxval(socketlayers, cmsg_level, "SOL_???");
553 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000554
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000555 if (cmsg_len > len)
556 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000557
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000558 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000559 (const void *) (u.ptr + cmsg_size),
560 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000561 tprints("}");
562
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000563 if (cmsg_len < cmsg_size) {
564 len -= cmsg_size;
565 break;
Roland McGrath50770822004-10-06 22:11:51 +0000566 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000567 cmsg_len = (cmsg_len + current_wordsize - 1) &
568 (size_t) ~(current_wordsize - 1);
569 if (cmsg_len >= len) {
570 len = 0;
571 break;
572 }
573 u.ptr += cmsg_len;
574 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000575 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000576 if (len)
577 tprints(", ...");
578 tprints("]");
579 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000580}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581
582static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200583do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100584{
585 tprintf("{msg_name(%d)=", msg->msg_namelen);
586 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
587
588 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200589 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
590 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100591
592#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
593 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
594 if (msg->msg_controllen)
595 printcmsghdr(tcp, (unsigned long) msg->msg_control,
596 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200597 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100598 printflags(msg_flags, msg->msg_flags, "MSG_???");
599#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
600 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
601 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
602#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200603 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100604}
605
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100606struct msghdr32 {
607 uint32_t /* void* */ msg_name;
608 uint32_t /* socklen_t */msg_namelen;
609 uint32_t /* iovec* */ msg_iov;
610 uint32_t /* size_t */ msg_iovlen;
611 uint32_t /* void* */ msg_control;
612 uint32_t /* size_t */ msg_controllen;
613 uint32_t /* int */ msg_flags;
614};
615struct mmsghdr32 {
616 struct msghdr32 msg_hdr;
617 uint32_t /* unsigned */ msg_len;
618};
619
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900620#ifndef HAVE_STRUCT_MMSGHDR
621struct mmsghdr {
622 struct msghdr msg_hdr;
623 unsigned msg_len;
624};
625#endif
626
Masatake YAMATOb2485432014-11-07 01:23:24 +0900627#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
628static void
629copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
630{
631 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
632 to_msg->msg_namelen = from_msg32->msg_namelen;
633 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
634 to_msg->msg_iovlen = from_msg32->msg_iovlen;
635 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
636 to_msg->msg_controllen = from_msg32->msg_controllen;
637 to_msg->msg_flags = from_msg32->msg_flags;
638}
639#endif
640
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900641static bool
642extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
643{
644#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
645 if (current_wordsize == 4) {
646 struct msghdr32 msg32;
647
648 if (umove(tcp, addr, &msg32) < 0)
649 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900650 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900651 } else
652#endif
653 if (umove(tcp, addr, msg) < 0)
654 return false;
655 return true;
656}
657
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900658static bool
659extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
660{
661#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
662 if (current_wordsize == 4) {
663 struct mmsghdr32 mmsg32;
664
665 addr += sizeof(struct mmsghdr32) * idx;
666 if (umove(tcp, addr, &mmsg32) < 0)
667 return false;
668
669 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
670 mmsg->msg_len = mmsg32.msg_len;
671 } else
672#endif
673 {
674 addr += sizeof(*mmsg) * idx;
675 if (umove(tcp, addr, mmsg) < 0)
676 return false;
677 }
678 return true;
679}
680
Andreas Schwab0873f292010-02-12 21:39:12 +0100681static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200682printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683{
684 struct msghdr msg;
685
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000686 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900687 do_msghdr(tcp, &msg, data_size);
688 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000689 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900690}
691
692void
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000693dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900694{
695 struct msghdr msg;
696
697 if (extractmsghdr(tcp, addr, &msg))
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000698 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699}
700
Andreas Schwab0873f292010-02-12 21:39:12 +0100701static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000702printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100703{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900704 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100705
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900706 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
707 tprints("{");
708 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
709 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100710 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900711 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000712 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100713}
Andreas Schwab0873f292010-02-12 21:39:12 +0100714
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000715static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000716decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000717{
718 /* mmsgvec */
719 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000720 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000721 } else {
722 unsigned int len = tcp->u_rval;
723 unsigned int i;
724
725 tprints("{");
726 for (i = 0; i < len; ++i) {
727 if (i)
728 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000729 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000730 }
731 tprints("}");
732 }
733 /* vlen */
734 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
735 /* flags */
736 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
737}
738
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900739void
740dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
741{
742 unsigned int len = tcp->u_rval;
743 unsigned int i;
744 struct mmsghdr mmsg;
745
746 for (i = 0; i < len; ++i) {
747 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
748 tprintf(" = %lu buffers in vector %u\n",
749 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
Dmitry V. Levind44707d2016-01-20 04:56:25 +0000750 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
751 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900752 }
753 }
754}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000756/*
757 * low bits of the socket type define real socket type,
758 * other bits are socket type flags.
759 */
760static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +0000761tprint_sock_type(unsigned int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000762{
763 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
764
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200765 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200766 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000767 flags &= ~SOCK_TYPE_MASK;
768 if (!flags)
769 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200770 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000771 }
772 printflags(sock_type_flags, flags, "SOCK_???");
773}
774
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000775SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776{
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000777 printxval(addrfams, tcp->u_arg[0], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000778 tprints(", ");
779 tprint_sock_type(tcp->u_arg[1]);
780 tprints(", ");
781 switch (tcp->u_arg[0]) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000782 case AF_INET:
783#ifdef AF_INET6
784 case AF_INET6:
Roland McGrath8758e542003-06-23 23:39:59 +0000785#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000786 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
787 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000788#ifdef AF_IPX
789 case AF_IPX:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000790 /* BTW: I don't believe this.. */
791 tprints("[");
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000792 printxval(addrfams, tcp->u_arg[2], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000793 tprints("]");
794 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000795#endif /* AF_IPX */
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000796 case AF_NETLINK:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000797 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
798 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000799#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
800 case AF_BLUETOOTH:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000801 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
802 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200803#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000804 default:
805 tprintf("%lu", tcp->u_arg[2]);
806 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000808
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000809 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000810}
811
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000812SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000814 printfd(tcp, tcp->u_arg[0]);
815 tprints(", ");
816 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
817 tprintf(", %lu", tcp->u_arg[2]);
818
819 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820}
821
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000822SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000823{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000824 printfd(tcp, tcp->u_arg[0]);
825 tprints(", ");
826 tprintf("%lu", tcp->u_arg[1]);
827
828 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000829}
830
Paolo Bonzini705ff102009-08-14 12:34:05 +0200831static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000832do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000833{
834 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800835 printfd(tcp, tcp->u_arg[0]);
836 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200837 return 0;
838 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000839
840 int len;
841 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
842 umove(tcp, tcp->u_arg[2], &len) < 0) {
843 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200844 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000845 printaddr(tcp->u_arg[2]);
846 } else {
847 printsock(tcp, tcp->u_arg[1], len);
848 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000850
Paolo Bonzini705ff102009-08-14 12:34:05 +0200851 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200852 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200853 printflags(sock_type_flags, tcp->u_arg[flags_arg],
854 "SOCK_???");
855 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 return 0;
857}
858
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000859SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200860{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000861 do_sockname(tcp, -1);
862 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200863}
864
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000865SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200866{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000867 do_sockname(tcp, 3);
868 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200869}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200870
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000871SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000873 printfd(tcp, tcp->u_arg[0]);
874 tprints(", ");
875 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
876 tprintf(", %lu, ", tcp->u_arg[2]);
877 /* flags */
878 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
879
880 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881}
882
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000883SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000885 printfd(tcp, tcp->u_arg[0]);
886 tprints(", ");
887 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
888 tprintf(", %lu, ", tcp->u_arg[2]);
889 /* flags */
890 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
891 /* to address */
892 tprints(", ");
893 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
894 /* to length */
895 tprintf(", %lu", tcp->u_arg[5]);
896
897 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000898}
899
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000900SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000902 printfd(tcp, tcp->u_arg[0]);
903 tprints(", ");
904 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
905 /* flags */
906 tprints(", ");
907 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
908
909 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910}
911
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000912SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000913{
914 if (entering(tcp)) {
915 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800916 printfd(tcp, tcp->u_arg[0]);
917 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000918 if (!verbose(tcp)) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000919 printaddr(tcp->u_arg[1]);
920 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000921 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
922 }
923 } else {
924 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000925 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000926 }
927 return 0;
928}
929
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000930SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931{
932 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800933 printfd(tcp, tcp->u_arg[0]);
934 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000935 } else {
936 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000937 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000938 else
939 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
940
941 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000942 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000943 }
944 return 0;
945}
946
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000947SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948{
949 int fromlen;
950
951 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800952 printfd(tcp, tcp->u_arg[0]);
953 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200956 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000957 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200958 } else {
959 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
960 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961 /* len */
962 tprintf(", %lu, ", tcp->u_arg[2]);
963 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000964 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200965 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000966 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000967 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200968 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000969 printaddr(tcp->u_arg[4]);
970 tprints(", ");
971 printaddr(tcp->u_arg[5]);
972 return 0;
973 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200974 /* from address */
975 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976 /* from length */
977 tprintf(", [%u]", fromlen);
978 }
979 return 0;
980}
981
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000982SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983{
984 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800985 printfd(tcp, tcp->u_arg[0]);
986 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000988 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000989 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200991 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200993 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000994 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 }
996 return 0;
997}
998
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000999SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +01001000{
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001001 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +04001002
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001003 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -08001004 printfd(tcp, tcp->u_arg[0]);
1005 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001006 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001007 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001008 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001009 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001010 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001011 } else {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001012 printaddr(tcp->u_arg[1]);
1013 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001014 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001015 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001016 print_timespec(tcp, tcp->u_arg[4]);
1017 }
1018 return 0;
1019 } else {
1020 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001021 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001022 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001023 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001024 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001025 tcp->auxstr = NULL;
1026 }
1027 if (syserror(tcp))
1028 return 0;
1029 if (tcp->u_rval == 0) {
1030 tcp->auxstr = "Timeout";
1031 return RVAL_STR;
1032 }
1033 if (!verbose(tcp))
1034 return 0;
1035 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001036 snprintf(str, sizeof(str), "left %s",
1037 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +04001038 tcp->auxstr = str;
1039 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001040 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001041}
Andreas Schwab0873f292010-02-12 21:39:12 +01001042
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001043#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001044
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001045SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001047 printfd(tcp, tcp->u_arg[0]);
1048 tprints(", ");
1049 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1050
1051 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052}
1053
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001054SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001056 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001057}
1058
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001059static void
1060printpair_fd(struct tcb *tcp, const int i0, const int i1)
1061{
1062 tprints("[");
1063 printfd(tcp, i0);
1064 tprints(", ");
1065 printfd(tcp, i1);
1066 tprints("]");
1067}
1068
1069static void
1070decode_pair_fd(struct tcb *tcp, const long addr)
1071{
1072 int pair[2];
1073
1074 if (umove_or_printaddr(tcp, addr, &pair))
1075 return;
1076
1077 printpair_fd(tcp, pair[0], pair[1]);
1078}
1079
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001080static int
1081do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083 if (exiting(tcp)) {
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001084 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001085 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001086 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001087 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1088 }
1089 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090 return 0;
1091}
1092
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001093SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001094{
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001095#ifdef HAVE_GETRVAL2
1096 if (exiting(tcp) && !syserror(tcp))
1097 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1098 return 0;
1099#else
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001100 return do_pipe(tcp, -1);
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001101#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001102}
1103
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001104SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001105{
1106 return do_pipe(tcp, 1);
1107}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001108
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001109SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001110{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001111 if (entering(tcp)) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +00001112 printxval(addrfams, tcp->u_arg[0], "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001113 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001114 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001115 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +00001117 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001118 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001119 }
1120 return 0;
1121}
1122
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001123#include "xlat/sockoptions.h"
1124#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001125#include "xlat/getsockipoptions.h"
1126#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001127#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001128#include "xlat/getsockipv6options.h"
1129#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001130#include "xlat/sockipxoptions.h"
1131#include "xlat/sockrawoptions.h"
1132#include "xlat/sockpacketoptions.h"
1133#include "xlat/socksctpoptions.h"
1134#include "xlat/socktcpoptions.h"
1135
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001136static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001137print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1138 unsigned int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001139{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001140 printfd(tcp, fd);
1141 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001142 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001143 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001144
John Hughes38ae88d2002-05-23 11:48:58 +00001145 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001146 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001147 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001148 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001149 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001150 printxvals(name, "IP_???", sockipoptions,
1151 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001152 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001153 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001154 printxvals(name, "IPV6_???", sockipv6options,
1155 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001156 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001157 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001158 printxval(sockipxoptions, name, "IPX_???");
1159 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001160 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001161 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001162 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001163 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001164 printxval(socktcpoptions, name, "TCP_???");
1165 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001166 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001167 printxval(socksctpoptions, name, "SCTP_???");
1168 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001169 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001170 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001171 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001172
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001173 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001174
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001175 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001176 tprintf("%u", name);
1177 }
1178
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001179 tprints(", ");
1180}
1181
1182#ifdef SO_LINGER
1183static void
1184print_linger(struct tcb *tcp, long addr, int len)
1185{
1186 struct linger linger;
1187
1188 if (len != sizeof(linger) ||
1189 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001190 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001191 return;
1192 }
1193
1194 tprintf("{onoff=%d, linger=%d}",
1195 linger.l_onoff,
1196 linger.l_linger);
1197}
1198#endif /* SO_LINGER */
1199
1200#ifdef SO_PEERCRED
1201static void
1202print_ucred(struct tcb *tcp, long addr, int len)
1203{
1204 struct ucred uc;
1205
1206 if (len != sizeof(uc) ||
1207 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001208 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001209 } else {
1210 tprintf("{pid=%u, uid=%u, gid=%u}",
1211 (unsigned) uc.pid,
1212 (unsigned) uc.uid,
1213 (unsigned) uc.gid);
1214 }
1215}
1216#endif /* SO_PEERCRED */
1217
1218#ifdef PACKET_STATISTICS
1219static void
1220print_tpacket_stats(struct tcb *tcp, long addr, int len)
1221{
1222 struct tpacket_stats stats;
1223
1224 if (len != sizeof(stats) ||
1225 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001226 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001227 } else {
1228 tprintf("{packets=%u, drops=%u}",
1229 stats.tp_packets,
1230 stats.tp_drops);
1231 }
1232}
1233#endif /* PACKET_STATISTICS */
1234
Dmitry V. Levinfba9db22016-06-15 21:29:07 +00001235#include "xlat/icmpfilterflags.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001236
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001237static void
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001238print_icmp_filter(struct tcb *tcp, const long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001239{
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001240 struct icmp_filter filter = {};
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001241
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001242 if (len > (int) sizeof(filter))
1243 len = sizeof(filter);
1244 else if (len <= 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001245 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001246 return;
1247 }
1248
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001249 if (umoven_or_printaddr(tcp, addr, len, &filter))
1250 return;
1251
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001252 tprints("~(");
1253 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1254 tprints(")");
1255}
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001256
1257static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001258print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1259 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001260{
1261 if (addr && verbose(tcp))
1262 switch (level) {
1263 case SOL_SOCKET:
1264 switch (name) {
1265#ifdef SO_LINGER
1266 case SO_LINGER:
1267 print_linger(tcp, addr, len);
1268 goto done;
1269#endif
1270#ifdef SO_PEERCRED
1271 case SO_PEERCRED:
1272 print_ucred(tcp, addr, len);
1273 goto done;
1274#endif
1275 }
1276 break;
1277
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001278 case SOL_PACKET:
1279 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001280#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001281 case PACKET_STATISTICS:
1282 print_tpacket_stats(tcp, addr, len);
1283 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001284#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001285 }
1286 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001287
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001288 case SOL_RAW:
1289 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001290 case ICMP_FILTER:
1291 print_icmp_filter(tcp, addr, len);
1292 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001293 }
1294 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001295 }
1296
John Hughes38ae88d2002-05-23 11:48:58 +00001297 /* default arg printing */
1298
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001299 if (verbose(tcp)) {
1300 if (len == sizeof(int)) {
1301 printnum_int(tcp, addr, "%d");
1302 } else {
1303 printstr(tcp, addr, len);
1304 }
1305 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001306 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001307 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001308done:
1309 tprintf(", [%d]", len);
1310}
1311
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001312SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001313{
1314 if (entering(tcp)) {
1315 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001316 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001317 } else {
1318 int len;
1319
1320 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001321 printaddr(tcp->u_arg[3]);
1322 tprints(", ");
1323 printaddr(tcp->u_arg[4]);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001324 } else {
1325 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1326 tcp->u_arg[3], len);
1327 }
John Hughes38ae88d2002-05-23 11:48:58 +00001328 }
1329 return 0;
1330}
1331
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001332#ifdef IP_ADD_MEMBERSHIP
1333static void
1334print_mreq(struct tcb *tcp, long addr, unsigned int len)
1335{
1336 struct ip_mreq mreq;
1337
1338 if (len < sizeof(mreq)) {
1339 printstr(tcp, addr, len);
1340 return;
1341 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001342 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001343 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001344
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001345 tprints("{imr_multiaddr=inet_addr(");
1346 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1347 16, QUOTE_0_TERMINATED);
1348 tprints("), imr_interface=inet_addr(");
1349 print_quoted_string(inet_ntoa(mreq.imr_interface),
1350 16, QUOTE_0_TERMINATED);
1351 tprints(")}");
1352}
1353#endif /* IP_ADD_MEMBERSHIP */
1354
1355#ifdef IPV6_ADD_MEMBERSHIP
1356static void
1357print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1358{
1359 struct ipv6_mreq mreq;
1360
1361 if (len < sizeof(mreq))
1362 goto fail;
1363
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001364 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001365 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001366
1367#ifdef HAVE_INET_NTOP
1368 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1369 char address[INET6_ADDRSTRLEN];
1370
1371 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1372 goto fail;
1373
1374 tprints("{ipv6mr_multiaddr=inet_pton(");
1375 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1376 tprints("), ipv6mr_interface=");
1377 print_ifindex(mreq.ipv6mr_interface);
1378 tprints("}");
1379 return;
1380#endif /* HAVE_INET_NTOP */
1381
1382fail:
1383 printstr(tcp, addr, len);
1384}
1385#endif /* IPV6_ADD_MEMBERSHIP */
1386
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001387#ifdef MCAST_JOIN_GROUP
1388static void
1389print_group_req(struct tcb *tcp, long addr, int len)
1390{
1391 struct group_req greq;
1392
1393 if (len != sizeof(greq) ||
1394 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001395 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001396 return;
1397 }
1398
Dmitry V. Levin1019f002015-11-21 02:38:59 +00001399 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1400 print_sockaddr(tcp, (const void *) &greq.gr_group,
1401 sizeof(greq.gr_group));
1402 tprintf("}");
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001403
1404}
1405#endif /* MCAST_JOIN_GROUP */
1406
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001407#ifdef PACKET_RX_RING
1408static void
1409print_tpacket_req(struct tcb *tcp, long addr, int len)
1410{
1411 struct tpacket_req req;
1412
1413 if (len != sizeof(req) ||
1414 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001415 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001416 } else {
1417 tprintf("{block_size=%u, block_nr=%u, "
1418 "frame_size=%u, frame_nr=%u}",
1419 req.tp_block_size,
1420 req.tp_block_nr,
1421 req.tp_frame_size,
1422 req.tp_frame_nr);
1423 }
1424}
1425#endif /* PACKET_RX_RING */
1426
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001427#ifdef PACKET_ADD_MEMBERSHIP
1428# include "xlat/packet_mreq_type.h"
1429
1430static void
1431print_packet_mreq(struct tcb *tcp, long addr, int len)
1432{
1433 struct packet_mreq mreq;
1434
1435 if (len != sizeof(mreq) ||
1436 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001437 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001438 } else {
1439 unsigned int i;
1440
1441 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1442 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1443 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1444 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1445 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1446 for (i = 0; i < mreq.mr_alen; ++i)
1447 tprintf("%02x", mreq.mr_address[i]);
1448 tprints("}");
1449 }
1450}
1451#endif /* PACKET_ADD_MEMBERSHIP */
1452
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001453static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001454print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1455 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001456{
1457 if (addr && verbose(tcp))
1458 switch (level) {
1459 case SOL_SOCKET:
1460 switch (name) {
1461#ifdef SO_LINGER
1462 case SO_LINGER:
1463 print_linger(tcp, addr, len);
1464 goto done;
1465#endif
1466 }
1467 break;
1468
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001469 case SOL_IP:
1470 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001471#ifdef IP_ADD_MEMBERSHIP
1472 case IP_ADD_MEMBERSHIP:
1473 case IP_DROP_MEMBERSHIP:
1474 print_mreq(tcp, addr, len);
1475 goto done;
1476#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001477#ifdef MCAST_JOIN_GROUP
1478 case MCAST_JOIN_GROUP:
1479 case MCAST_LEAVE_GROUP:
1480 print_group_req(tcp, addr, len);
1481 goto done;
1482#endif /* MCAST_JOIN_GROUP */
1483 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001484 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001485
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001486 case SOL_IPV6:
1487 switch (name) {
1488#ifdef IPV6_ADD_MEMBERSHIP
1489 case IPV6_ADD_MEMBERSHIP:
1490 case IPV6_DROP_MEMBERSHIP:
1491# ifdef IPV6_JOIN_ANYCAST
1492 case IPV6_JOIN_ANYCAST:
1493# endif
1494# ifdef IPV6_LEAVE_ANYCAST
1495 case IPV6_LEAVE_ANYCAST:
1496# endif
1497 print_mreq6(tcp, addr, len);
1498 goto done;
1499#endif /* IPV6_ADD_MEMBERSHIP */
1500 }
1501 break;
1502
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001503 case SOL_PACKET:
1504 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001505#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001506 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001507# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001508 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001509# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001510 print_tpacket_req(tcp, addr, len);
1511 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001512#endif /* PACKET_RX_RING */
1513#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001514 case PACKET_ADD_MEMBERSHIP:
1515 case PACKET_DROP_MEMBERSHIP:
1516 print_packet_mreq(tcp, addr, len);
1517 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001518#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001519 }
1520 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001521
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001522 case SOL_RAW:
1523 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001524 case ICMP_FILTER:
1525 print_icmp_filter(tcp, addr, len);
1526 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001527 }
1528 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001529 }
1530
1531 /* default arg printing */
1532
1533 if (verbose(tcp)) {
1534 if (len == sizeof(int)) {
1535 printnum_int(tcp, addr, "%d");
1536 } else {
1537 printstr(tcp, addr, len);
1538 }
1539 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001540 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001541 }
1542done:
1543 tprintf(", %d", len);
1544}
1545
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001546SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001547{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001548 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001549 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001550 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1551 tcp->u_arg[3], tcp->u_arg[4]);
1552
1553 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001554}