blob: 1a6c265f692bdd2489a1906d9f009691816627e7 [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>
Dmitry V. Levinebda41a2016-06-19 22:02:45 +000049#ifdef HAVE_NETIPX_IPX_H
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
Dmitry V. Levinc981b1f2016-06-15 21:42:30 +0000103#include "xlat/af_packet_types.h"
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000104
Dmitry V. Levinae280932015-06-05 20:13:21 +0000105static void
106print_ifindex(unsigned int ifindex)
107{
108#ifdef HAVE_IF_INDEXTONAME
109 char buf[IFNAMSIZ + 1];
110
111 if (if_indextoname(ifindex, buf)) {
112 tprints("if_nametoindex(");
113 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
114 tprints(")");
115 return;
116 }
117#endif
118 tprintf("%u", ifindex);
119}
120
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000121typedef union {
122 char pad[128];
123 struct sockaddr sa;
124 struct sockaddr_in sin;
125 struct sockaddr_un sau;
126#ifdef HAVE_INET_NTOP
127 struct sockaddr_in6 sa6;
128#endif
129#if defined(AF_IPX)
130 struct sockaddr_ipx sipx;
131#endif
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000132 struct sockaddr_ll ll;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000133 struct sockaddr_nl nl;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000134#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
135 struct sockaddr_hci hci;
136 struct sockaddr_l2 l2;
137 struct sockaddr_rc rc;
138 struct sockaddr_sco sco;
139#endif
140} sockaddr_buf_t;
141
142static void
143print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
144{
145 tprints("{sa_family=");
146 printxval(addrfams, addr->sa.sa_family, "AF_???");
147 tprints(", ");
148
149 switch (addr->sa.sa_family) {
150 case AF_UNIX:
151 if (addrlen == 2) {
152 tprints("NULL");
153 } else if (addr->sau.sun_path[0]) {
154 tprints("sun_path=");
155 print_quoted_string(addr->sau.sun_path,
156 sizeof(addr->sau.sun_path) + 1,
157 QUOTE_0_TERMINATED);
158 } else {
159 tprints("sun_path=@");
160 print_quoted_string(addr->sau.sun_path + 1,
161 sizeof(addr->sau.sun_path),
162 QUOTE_0_TERMINATED);
163 }
164 break;
165 case AF_INET:
166 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
167 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
168 break;
169#ifdef HAVE_INET_NTOP
170 case AF_INET6:
171 {
172 char string_addr[100];
173 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
174 string_addr, sizeof(string_addr));
175 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
176 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
177 ntohs(addr->sa6.sin6_port), string_addr,
178 addr->sa6.sin6_flowinfo);
179# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
180 tprints(", sin6_scope_id=");
181# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
182 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
183 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
184 print_ifindex(addr->sa6.sin6_scope_id);
185 else
186# endif
187 tprintf("%u", addr->sa6.sin6_scope_id);
188# endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
189 }
190 break;
191#endif
192#if defined(AF_IPX)
193 case AF_IPX:
194 {
195 int i;
196 tprintf("sipx_port=htons(%u), ",
197 ntohs(addr->sipx.sipx_port));
198 /* Yes, I know, this does not look too
199 * strace-ish, but otherwise the IPX
200 * addresses just look monstrous...
201 * Anyways, feel free if you don't like
202 * this way.. :)
203 */
204 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
205 for (i = 0; i < IPX_NODE_LEN; i++)
206 tprintf("%02x", addr->sipx.sipx_node[i]);
207 tprintf("/[%02x]", addr->sipx.sipx_type);
208 }
209 break;
210#endif /* AF_IPX */
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000211 case AF_PACKET:
212 {
213 int i;
214 tprintf("proto=%#04x, if%d, pkttype=",
215 ntohs(addr->ll.sll_protocol),
216 addr->ll.sll_ifindex);
217 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
218 tprintf(", addr(%d)={%d, ",
219 addr->ll.sll_halen,
220 addr->ll.sll_hatype);
221 for (i = 0; i < addr->ll.sll_halen; i++)
222 tprintf("%02x", addr->ll.sll_addr[i]);
223 }
224 break;
225
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000226 case AF_NETLINK:
227 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
228 break;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000229#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
230 case AF_BLUETOOTH:
231 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
232 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
233 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
234 "{hci_dev=htobs(%d)}",
235 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
236 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
237 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
238 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
239 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
240 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
241 addr->rc.rc_channel,
242 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
243 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
244 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
245 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
246 btohs(addr->hci.hci_dev));
247 break;
248#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
249 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
250 AF_X25 AF_ROSE etc. still need to be done */
251
252 default:
253 tprints("sa_data=");
254 print_quoted_string(addr->sa.sa_data,
255 sizeof(addr->sa.sa_data), 0);
256 break;
257 }
258 tprints("}");
259}
260
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000262printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263{
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000264 sockaddr_buf_t addrbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265
Denys Vlasenko383386d2015-07-30 13:29:20 +0200266 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000267 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200268 return;
269 }
270
271 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000272 addrlen = sizeof(addrbuf);
273
274 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000275 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000277 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000278
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000279 print_sockaddr(tcp, &addrbuf, addrlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280}
281
Dmitry V. Levinb36d1322015-11-18 23:18:17 +0000282#include "xlat/scmvals.h"
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300283#include "xlat/ip_cmsg_types.h"
Roland McGrath50770822004-10-06 22:11:51 +0000284
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000285#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
286struct cmsghdr32 {
287 uint32_t cmsg_len;
288 int cmsg_level;
289 int cmsg_type;
290};
291#endif
292
293typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000294 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000295 struct cmsghdr *cmsg;
296#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
297 struct cmsghdr32 *cmsg32;
298#endif
299} union_cmsghdr;
300
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000301static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000302print_scm_rights(struct tcb *tcp, const void *cmsg_data,
303 const size_t data_len)
Roland McGrath50770822004-10-06 22:11:51 +0000304{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000305 const int *fds = cmsg_data;
306 const char *end = (const char *) cmsg_data + data_len;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000307 bool seen = false;
308
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000309 if (sizeof(*fds) > data_len)
310 return;
311
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000312 tprints(", [");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000313 while ((const char *) fds < end) {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000314 if (seen)
315 tprints(", ");
316 else
317 seen = true;
318 printfd(tcp, *fds++);
319 }
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000320 tprints("]");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000321}
322
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000323static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000324print_scm_creds(struct tcb *tcp, const void *cmsg_data,
325 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000326{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000327 const struct ucred *uc = cmsg_data;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000328
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000329 if (sizeof(*uc) > data_len)
330 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000331
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000332 tprintf(", {pid=%u, uid=%u, gid=%u}",
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000333 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000334}
335
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000336static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000337print_scm_security(struct tcb *tcp, const void *cmsg_data,
338 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000339{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000340 if (!data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000341 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000342
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000343 tprints(", ");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000344 print_quoted_string(cmsg_data, data_len, 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000345}
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000346
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000347static void
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300348print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
349 const size_t data_len)
350{
351 const struct in_pktinfo *info = cmsg_data;
352
353 if (sizeof(*info) > data_len)
354 return;
355
356 tprints(", {ipi_ifindex=");
357 print_ifindex(info->ipi_ifindex);
358 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
359 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
360}
361
362static void
363print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
364 const size_t data_len)
365{
366 const unsigned int *ttl = cmsg_data;
367
368 if (sizeof(*ttl) > data_len)
369 return;
370
371 tprintf(", {ttl=%u}", *ttl);
372}
373
374static void
375print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
376 const size_t data_len)
377{
378 const uint8_t *tos = cmsg_data;
379
380 if (sizeof(*tos) > data_len)
381 return;
382
383 tprintf(", {tos=%x}", *tos);
384}
385
386static void
387print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
388 const size_t data_len)
389{
390 const uint32_t *csum = cmsg_data;
391
392 if (sizeof(*csum) > data_len)
393 return;
394
395 tprintf(", {csum=%u}", *csum);
396}
397
398static void
399print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
400 const size_t data_len)
401{
Dmitry V. Levina17f5932015-11-22 23:07:52 +0000402 const unsigned char *opts = cmsg_data;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300403 size_t i;
404
405 if (!data_len)
406 return;
407
408 tprints(", {opts=0x");
409 for (i = 0; i < data_len; ++i)
410 tprintf("%02x", opts[i]);
411 tprints("}");
412}
413
414static void
415print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
416 const size_t data_len)
417{
418 const struct {
419 uint32_t ee_errno;
420 uint8_t ee_origin;
421 uint8_t ee_type;
422 uint8_t ee_code;
423 uint8_t ee_pad;
424 uint32_t ee_info;
425 uint32_t ee_data;
426 struct sockaddr_in offender;
427 } *err = cmsg_data;
428
429 if (sizeof(*err) > data_len)
430 return;
431
432 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
433 ", ee_info=%u, ee_data=%u, offender=",
434 err->ee_errno, err->ee_origin, err->ee_type,
435 err->ee_code, err->ee_info, err->ee_data);
436 print_sockaddr(tcp, (const void *) &err->offender,
437 sizeof(err->offender));
438 tprints("}");
439}
440
441static void
442print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
443 const size_t data_len)
444{
445 if (sizeof(struct sockaddr_in) > data_len)
446 return;
447
448 tprints(", ");
449 print_sockaddr(tcp, cmsg_data, data_len);
450}
451
452static void
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000453print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000454 const void *cmsg_data, const size_t data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000455{
456 switch (cmsg_level) {
457 case SOL_SOCKET:
458 printxval(scmvals, cmsg_type, "SCM_???");
459 switch (cmsg_type) {
460 case SCM_RIGHTS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000461 print_scm_rights(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000462 break;
463 case SCM_CREDENTIALS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000464 print_scm_creds(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000465 break;
466 case SCM_SECURITY:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000467 print_scm_security(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000468 break;
469 }
470 break;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300471 case SOL_IP:
472 printxval(ip_cmsg_types, cmsg_type, "IP_???");
473 switch (cmsg_type) {
474 case IP_PKTINFO:
475 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
476 break;
477 case IP_TTL:
478 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
479 break;
480 case IP_TOS:
481 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
482 break;
483 case IP_RECVOPTS:
484 case IP_RETOPTS:
485 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
486 break;
487 case IP_RECVERR:
488 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
489 break;
490 case IP_ORIGDSTADDR:
491 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
492 break;
493 case IP_CHECKSUM:
494 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
495 break;
496 case SCM_SECURITY:
497 print_scm_security(tcp, cmsg_data, data_len);
498 break;
499 }
500 break;
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000501 default:
502 tprintf("%u", cmsg_type);
503 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000504}
505
506static void
507printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
508{
509 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000510#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
511 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
512#endif
513 sizeof(struct cmsghdr);
514
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000515 char *buf = len < cmsg_size ? NULL : malloc(len);
516 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000517 tprints(", msg_control=");
518 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000519 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000520 return;
521 }
522
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000523 union_cmsghdr u = { .ptr = buf };
524
525 tprints(", [");
526 while (len >= cmsg_size) {
527 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000528#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000529 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000530#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000531 u.cmsg->cmsg_len;
532 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000533#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000534 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000535#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000536 u.cmsg->cmsg_level;
537 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000538#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000539 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000540#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000541 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000542
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000543 if (u.ptr != buf)
544 tprints(", ");
545 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
546 printxval(socketlayers, cmsg_level, "SOL_???");
547 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000548
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000549 if (cmsg_len > len)
550 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000551
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000552 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000553 (const void *) (u.ptr + cmsg_size),
554 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000555 tprints("}");
556
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000557 if (cmsg_len < cmsg_size) {
558 len -= cmsg_size;
559 break;
Roland McGrath50770822004-10-06 22:11:51 +0000560 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000561 cmsg_len = (cmsg_len + current_wordsize - 1) &
562 (size_t) ~(current_wordsize - 1);
563 if (cmsg_len >= len) {
564 len = 0;
565 break;
566 }
567 u.ptr += cmsg_len;
568 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000569 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000570 if (len)
571 tprints(", ...");
572 tprints("]");
573 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000574}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575
576static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200577do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100578{
579 tprintf("{msg_name(%d)=", msg->msg_namelen);
580 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
581
582 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200583 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
584 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100585
586#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
587 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
588 if (msg->msg_controllen)
589 printcmsghdr(tcp, (unsigned long) msg->msg_control,
590 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200591 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100592 printflags(msg_flags, msg->msg_flags, "MSG_???");
593#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
594 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
595 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
596#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200597 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100598}
599
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100600struct msghdr32 {
601 uint32_t /* void* */ msg_name;
602 uint32_t /* socklen_t */msg_namelen;
603 uint32_t /* iovec* */ msg_iov;
604 uint32_t /* size_t */ msg_iovlen;
605 uint32_t /* void* */ msg_control;
606 uint32_t /* size_t */ msg_controllen;
607 uint32_t /* int */ msg_flags;
608};
609struct mmsghdr32 {
610 struct msghdr32 msg_hdr;
611 uint32_t /* unsigned */ msg_len;
612};
613
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900614#ifndef HAVE_STRUCT_MMSGHDR
615struct mmsghdr {
616 struct msghdr msg_hdr;
617 unsigned msg_len;
618};
619#endif
620
Masatake YAMATOb2485432014-11-07 01:23:24 +0900621#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
622static void
623copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
624{
625 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
626 to_msg->msg_namelen = from_msg32->msg_namelen;
627 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
628 to_msg->msg_iovlen = from_msg32->msg_iovlen;
629 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
630 to_msg->msg_controllen = from_msg32->msg_controllen;
631 to_msg->msg_flags = from_msg32->msg_flags;
632}
633#endif
634
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900635static bool
636extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
637{
638#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
639 if (current_wordsize == 4) {
640 struct msghdr32 msg32;
641
642 if (umove(tcp, addr, &msg32) < 0)
643 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900644 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900645 } else
646#endif
647 if (umove(tcp, addr, msg) < 0)
648 return false;
649 return true;
650}
651
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900652static bool
653extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
654{
655#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
656 if (current_wordsize == 4) {
657 struct mmsghdr32 mmsg32;
658
659 addr += sizeof(struct mmsghdr32) * idx;
660 if (umove(tcp, addr, &mmsg32) < 0)
661 return false;
662
663 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
664 mmsg->msg_len = mmsg32.msg_len;
665 } else
666#endif
667 {
668 addr += sizeof(*mmsg) * idx;
669 if (umove(tcp, addr, mmsg) < 0)
670 return false;
671 }
672 return true;
673}
674
Andreas Schwab0873f292010-02-12 21:39:12 +0100675static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200676printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677{
678 struct msghdr msg;
679
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000680 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900681 do_msghdr(tcp, &msg, data_size);
682 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000683 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900684}
685
686void
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000687dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900688{
689 struct msghdr msg;
690
691 if (extractmsghdr(tcp, addr, &msg))
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000692 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000693}
694
Andreas Schwab0873f292010-02-12 21:39:12 +0100695static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000696printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100697{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900698 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100699
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900700 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
701 tprints("{");
702 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
703 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100704 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900705 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000706 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100707}
Andreas Schwab0873f292010-02-12 21:39:12 +0100708
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000709static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000710decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000711{
712 /* mmsgvec */
713 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000714 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000715 } else {
716 unsigned int len = tcp->u_rval;
717 unsigned int i;
718
719 tprints("{");
720 for (i = 0; i < len; ++i) {
721 if (i)
722 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000723 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000724 }
725 tprints("}");
726 }
727 /* vlen */
728 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
729 /* flags */
730 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
731}
732
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900733void
734dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
735{
736 unsigned int len = tcp->u_rval;
737 unsigned int i;
738 struct mmsghdr mmsg;
739
740 for (i = 0; i < len; ++i) {
741 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
742 tprintf(" = %lu buffers in vector %u\n",
743 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
Dmitry V. Levind44707d2016-01-20 04:56:25 +0000744 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
745 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900746 }
747 }
748}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000749
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000750/*
751 * low bits of the socket type define real socket type,
752 * other bits are socket type flags.
753 */
754static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +0000755tprint_sock_type(unsigned int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000756{
757 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
758
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200759 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200760 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000761 flags &= ~SOCK_TYPE_MASK;
762 if (!flags)
763 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200764 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000765 }
766 printflags(sock_type_flags, flags, "SOCK_???");
767}
768
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000769SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770{
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000771 printxval(addrfams, tcp->u_arg[0], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000772 tprints(", ");
773 tprint_sock_type(tcp->u_arg[1]);
774 tprints(", ");
775 switch (tcp->u_arg[0]) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000776 case AF_INET:
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000777 case AF_INET6:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000778 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
779 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000780#ifdef AF_IPX
781 case AF_IPX:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000782 /* BTW: I don't believe this.. */
783 tprints("[");
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000784 printxval(addrfams, tcp->u_arg[2], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000785 tprints("]");
786 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000787#endif /* AF_IPX */
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000788 case AF_NETLINK:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000789 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
790 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000791#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
792 case AF_BLUETOOTH:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000793 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
794 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200795#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000796 default:
797 tprintf("%lu", tcp->u_arg[2]);
798 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000800
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000801 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802}
803
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000804SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000805{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000806 printfd(tcp, tcp->u_arg[0]);
807 tprints(", ");
808 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
809 tprintf(", %lu", tcp->u_arg[2]);
810
811 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812}
813
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000814SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000816 printfd(tcp, tcp->u_arg[0]);
817 tprints(", ");
818 tprintf("%lu", tcp->u_arg[1]);
819
820 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821}
822
Paolo Bonzini705ff102009-08-14 12:34:05 +0200823static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000824do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825{
826 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800827 printfd(tcp, tcp->u_arg[0]);
828 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200829 return 0;
830 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000831
832 int len;
833 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
834 umove(tcp, tcp->u_arg[2], &len) < 0) {
835 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200836 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000837 printaddr(tcp->u_arg[2]);
838 } else {
839 printsock(tcp, tcp->u_arg[1], len);
840 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000842
Paolo Bonzini705ff102009-08-14 12:34:05 +0200843 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200844 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200845 printflags(sock_type_flags, tcp->u_arg[flags_arg],
846 "SOCK_???");
847 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848 return 0;
849}
850
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000851SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200852{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000853 do_sockname(tcp, -1);
854 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200855}
856
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000857SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200858{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000859 do_sockname(tcp, 3);
860 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200861}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200862
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000863SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000865 printfd(tcp, tcp->u_arg[0]);
866 tprints(", ");
867 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
868 tprintf(", %lu, ", tcp->u_arg[2]);
869 /* flags */
870 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
871
872 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873}
874
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000875SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000877 printfd(tcp, tcp->u_arg[0]);
878 tprints(", ");
879 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
880 tprintf(", %lu, ", tcp->u_arg[2]);
881 /* flags */
882 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
883 /* to address */
884 tprints(", ");
885 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
886 /* to length */
887 tprintf(", %lu", tcp->u_arg[5]);
888
889 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890}
891
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000892SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000893{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000894 printfd(tcp, tcp->u_arg[0]);
895 tprints(", ");
896 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
897 /* flags */
898 tprints(", ");
899 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
900
901 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000902}
903
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000904SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000905{
906 if (entering(tcp)) {
907 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800908 printfd(tcp, tcp->u_arg[0]);
909 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000910 if (!verbose(tcp)) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000911 printaddr(tcp->u_arg[1]);
912 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000913 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
914 }
915 } else {
916 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000917 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000918 }
919 return 0;
920}
921
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000922SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923{
924 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800925 printfd(tcp, tcp->u_arg[0]);
926 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927 } else {
928 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000929 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000930 else
931 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
932
933 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000934 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000935 }
936 return 0;
937}
938
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000939SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000940{
941 int fromlen;
942
943 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800944 printfd(tcp, tcp->u_arg[0]);
945 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000946 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200948 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000949 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200950 } else {
951 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
952 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 /* len */
954 tprintf(", %lu, ", tcp->u_arg[2]);
955 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000956 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200957 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000958 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000959 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200960 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000961 printaddr(tcp->u_arg[4]);
962 tprints(", ");
963 printaddr(tcp->u_arg[5]);
964 return 0;
965 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200966 /* from address */
967 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968 /* from length */
969 tprintf(", [%u]", fromlen);
970 }
971 return 0;
972}
973
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000974SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975{
976 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800977 printfd(tcp, tcp->u_arg[0]);
978 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000980 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000981 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200983 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200985 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000986 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 }
988 return 0;
989}
990
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000991SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +0100992{
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000993 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400994
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100995 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800996 printfd(tcp, tcp->u_arg[0]);
997 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400998 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100999 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001000 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +01001001 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001002 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001003 } else {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001004 printaddr(tcp->u_arg[1]);
1005 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001006 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001007 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001008 print_timespec(tcp, tcp->u_arg[4]);
1009 }
1010 return 0;
1011 } else {
1012 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001013 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001014 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001015 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001016 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001017 tcp->auxstr = NULL;
1018 }
1019 if (syserror(tcp))
1020 return 0;
1021 if (tcp->u_rval == 0) {
1022 tcp->auxstr = "Timeout";
1023 return RVAL_STR;
1024 }
1025 if (!verbose(tcp))
1026 return 0;
1027 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001028 snprintf(str, sizeof(str), "left %s",
1029 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +04001030 tcp->auxstr = str;
1031 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001032 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001033}
Andreas Schwab0873f292010-02-12 21:39:12 +01001034
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001035#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001036
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001037SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001039 printfd(tcp, tcp->u_arg[0]);
1040 tprints(", ");
1041 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1042
1043 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044}
1045
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001046SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001047{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001048 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001049}
1050
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001051static void
1052printpair_fd(struct tcb *tcp, const int i0, const int i1)
1053{
1054 tprints("[");
1055 printfd(tcp, i0);
1056 tprints(", ");
1057 printfd(tcp, i1);
1058 tprints("]");
1059}
1060
1061static void
1062decode_pair_fd(struct tcb *tcp, const long addr)
1063{
1064 int pair[2];
1065
1066 if (umove_or_printaddr(tcp, addr, &pair))
1067 return;
1068
1069 printpair_fd(tcp, pair[0], pair[1]);
1070}
1071
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001072static int
1073do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075 if (exiting(tcp)) {
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001076 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001077 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001078 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001079 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1080 }
1081 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082 return 0;
1083}
1084
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001085SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001086{
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001087#ifdef HAVE_GETRVAL2
1088 if (exiting(tcp) && !syserror(tcp))
1089 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1090 return 0;
1091#else
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001092 return do_pipe(tcp, -1);
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001093#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001094}
1095
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001096SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001097{
1098 return do_pipe(tcp, 1);
1099}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001100
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001101SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 if (entering(tcp)) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +00001104 printxval(addrfams, tcp->u_arg[0], "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001105 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001106 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001107 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +00001109 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001110 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001111 }
1112 return 0;
1113}
1114
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001115#include "xlat/sockoptions.h"
1116#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001117#include "xlat/getsockipoptions.h"
1118#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001119#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001120#include "xlat/getsockipv6options.h"
1121#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001122#include "xlat/sockipxoptions.h"
1123#include "xlat/sockrawoptions.h"
1124#include "xlat/sockpacketoptions.h"
1125#include "xlat/socksctpoptions.h"
1126#include "xlat/socktcpoptions.h"
1127
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001128static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001129print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1130 unsigned int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001131{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001132 printfd(tcp, fd);
1133 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001134 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001135 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001136
John Hughes38ae88d2002-05-23 11:48:58 +00001137 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001138 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001139 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001140 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001141 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001142 printxvals(name, "IP_???", sockipoptions,
1143 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001144 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001145 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001146 printxvals(name, "IPV6_???", sockipv6options,
1147 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001148 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001149 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001150 printxval(sockipxoptions, name, "IPX_???");
1151 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001152 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001153 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001154 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001155 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001156 printxval(socktcpoptions, name, "TCP_???");
1157 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001158 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001159 printxval(socksctpoptions, name, "SCTP_???");
1160 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001161 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001162 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001163 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001164
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001165 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001166
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001167 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001168 tprintf("%u", name);
1169 }
1170
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001171 tprints(", ");
1172}
1173
1174#ifdef SO_LINGER
1175static void
1176print_linger(struct tcb *tcp, long addr, int len)
1177{
1178 struct linger linger;
1179
1180 if (len != sizeof(linger) ||
1181 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001182 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001183 return;
1184 }
1185
1186 tprintf("{onoff=%d, linger=%d}",
1187 linger.l_onoff,
1188 linger.l_linger);
1189}
1190#endif /* SO_LINGER */
1191
1192#ifdef SO_PEERCRED
1193static void
1194print_ucred(struct tcb *tcp, long addr, int len)
1195{
1196 struct ucred uc;
1197
1198 if (len != sizeof(uc) ||
1199 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001200 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001201 } else {
1202 tprintf("{pid=%u, uid=%u, gid=%u}",
1203 (unsigned) uc.pid,
1204 (unsigned) uc.uid,
1205 (unsigned) uc.gid);
1206 }
1207}
1208#endif /* SO_PEERCRED */
1209
1210#ifdef PACKET_STATISTICS
1211static void
1212print_tpacket_stats(struct tcb *tcp, long addr, int len)
1213{
1214 struct tpacket_stats stats;
1215
1216 if (len != sizeof(stats) ||
1217 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001218 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001219 } else {
1220 tprintf("{packets=%u, drops=%u}",
1221 stats.tp_packets,
1222 stats.tp_drops);
1223 }
1224}
1225#endif /* PACKET_STATISTICS */
1226
Dmitry V. Levinfba9db22016-06-15 21:29:07 +00001227#include "xlat/icmpfilterflags.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001228
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001229static void
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001230print_icmp_filter(struct tcb *tcp, const long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001231{
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001232 struct icmp_filter filter = {};
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001233
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001234 if (len > (int) sizeof(filter))
1235 len = sizeof(filter);
1236 else if (len <= 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001237 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001238 return;
1239 }
1240
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001241 if (umoven_or_printaddr(tcp, addr, len, &filter))
1242 return;
1243
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001244 tprints("~(");
1245 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1246 tprints(")");
1247}
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001248
1249static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001250print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1251 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001252{
1253 if (addr && verbose(tcp))
1254 switch (level) {
1255 case SOL_SOCKET:
1256 switch (name) {
1257#ifdef SO_LINGER
1258 case SO_LINGER:
1259 print_linger(tcp, addr, len);
1260 goto done;
1261#endif
1262#ifdef SO_PEERCRED
1263 case SO_PEERCRED:
1264 print_ucred(tcp, addr, len);
1265 goto done;
1266#endif
1267 }
1268 break;
1269
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001270 case SOL_PACKET:
1271 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001272#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001273 case PACKET_STATISTICS:
1274 print_tpacket_stats(tcp, addr, len);
1275 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001276#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001277 }
1278 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001279
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001280 case SOL_RAW:
1281 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001282 case ICMP_FILTER:
1283 print_icmp_filter(tcp, addr, len);
1284 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001285 }
1286 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001287 }
1288
John Hughes38ae88d2002-05-23 11:48:58 +00001289 /* default arg printing */
1290
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001291 if (verbose(tcp)) {
1292 if (len == sizeof(int)) {
1293 printnum_int(tcp, addr, "%d");
1294 } else {
1295 printstr(tcp, addr, len);
1296 }
1297 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001298 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001299 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001300done:
1301 tprintf(", [%d]", len);
1302}
1303
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001304SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001305{
1306 if (entering(tcp)) {
1307 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001308 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001309 } else {
1310 int len;
1311
1312 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001313 printaddr(tcp->u_arg[3]);
1314 tprints(", ");
1315 printaddr(tcp->u_arg[4]);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001316 } else {
1317 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1318 tcp->u_arg[3], len);
1319 }
John Hughes38ae88d2002-05-23 11:48:58 +00001320 }
1321 return 0;
1322}
1323
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001324#ifdef IP_ADD_MEMBERSHIP
1325static void
1326print_mreq(struct tcb *tcp, long addr, unsigned int len)
1327{
1328 struct ip_mreq mreq;
1329
1330 if (len < sizeof(mreq)) {
1331 printstr(tcp, addr, len);
1332 return;
1333 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001334 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001335 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001336
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001337 tprints("{imr_multiaddr=inet_addr(");
1338 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1339 16, QUOTE_0_TERMINATED);
1340 tprints("), imr_interface=inet_addr(");
1341 print_quoted_string(inet_ntoa(mreq.imr_interface),
1342 16, QUOTE_0_TERMINATED);
1343 tprints(")}");
1344}
1345#endif /* IP_ADD_MEMBERSHIP */
1346
1347#ifdef IPV6_ADD_MEMBERSHIP
1348static void
1349print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1350{
1351 struct ipv6_mreq mreq;
1352
1353 if (len < sizeof(mreq))
1354 goto fail;
1355
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001356 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001357 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001358
1359#ifdef HAVE_INET_NTOP
1360 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1361 char address[INET6_ADDRSTRLEN];
1362
1363 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1364 goto fail;
1365
1366 tprints("{ipv6mr_multiaddr=inet_pton(");
1367 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1368 tprints("), ipv6mr_interface=");
1369 print_ifindex(mreq.ipv6mr_interface);
1370 tprints("}");
1371 return;
1372#endif /* HAVE_INET_NTOP */
1373
1374fail:
1375 printstr(tcp, addr, len);
1376}
1377#endif /* IPV6_ADD_MEMBERSHIP */
1378
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001379#ifdef MCAST_JOIN_GROUP
1380static void
1381print_group_req(struct tcb *tcp, long addr, int len)
1382{
1383 struct group_req greq;
1384
1385 if (len != sizeof(greq) ||
1386 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001387 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001388 return;
1389 }
1390
Dmitry V. Levin1019f002015-11-21 02:38:59 +00001391 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1392 print_sockaddr(tcp, (const void *) &greq.gr_group,
1393 sizeof(greq.gr_group));
1394 tprintf("}");
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001395
1396}
1397#endif /* MCAST_JOIN_GROUP */
1398
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001399#ifdef PACKET_RX_RING
1400static void
1401print_tpacket_req(struct tcb *tcp, long addr, int len)
1402{
1403 struct tpacket_req req;
1404
1405 if (len != sizeof(req) ||
1406 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001407 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001408 } else {
1409 tprintf("{block_size=%u, block_nr=%u, "
1410 "frame_size=%u, frame_nr=%u}",
1411 req.tp_block_size,
1412 req.tp_block_nr,
1413 req.tp_frame_size,
1414 req.tp_frame_nr);
1415 }
1416}
1417#endif /* PACKET_RX_RING */
1418
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001419#ifdef PACKET_ADD_MEMBERSHIP
1420# include "xlat/packet_mreq_type.h"
1421
1422static void
1423print_packet_mreq(struct tcb *tcp, long addr, int len)
1424{
1425 struct packet_mreq mreq;
1426
1427 if (len != sizeof(mreq) ||
1428 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001429 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001430 } else {
1431 unsigned int i;
1432
1433 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1434 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1435 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1436 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1437 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1438 for (i = 0; i < mreq.mr_alen; ++i)
1439 tprintf("%02x", mreq.mr_address[i]);
1440 tprints("}");
1441 }
1442}
1443#endif /* PACKET_ADD_MEMBERSHIP */
1444
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001445static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001446print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1447 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001448{
1449 if (addr && verbose(tcp))
1450 switch (level) {
1451 case SOL_SOCKET:
1452 switch (name) {
1453#ifdef SO_LINGER
1454 case SO_LINGER:
1455 print_linger(tcp, addr, len);
1456 goto done;
1457#endif
1458 }
1459 break;
1460
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001461 case SOL_IP:
1462 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001463#ifdef IP_ADD_MEMBERSHIP
1464 case IP_ADD_MEMBERSHIP:
1465 case IP_DROP_MEMBERSHIP:
1466 print_mreq(tcp, addr, len);
1467 goto done;
1468#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001469#ifdef MCAST_JOIN_GROUP
1470 case MCAST_JOIN_GROUP:
1471 case MCAST_LEAVE_GROUP:
1472 print_group_req(tcp, addr, len);
1473 goto done;
1474#endif /* MCAST_JOIN_GROUP */
1475 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001476 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001477
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001478 case SOL_IPV6:
1479 switch (name) {
1480#ifdef IPV6_ADD_MEMBERSHIP
1481 case IPV6_ADD_MEMBERSHIP:
1482 case IPV6_DROP_MEMBERSHIP:
1483# ifdef IPV6_JOIN_ANYCAST
1484 case IPV6_JOIN_ANYCAST:
1485# endif
1486# ifdef IPV6_LEAVE_ANYCAST
1487 case IPV6_LEAVE_ANYCAST:
1488# endif
1489 print_mreq6(tcp, addr, len);
1490 goto done;
1491#endif /* IPV6_ADD_MEMBERSHIP */
1492 }
1493 break;
1494
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001495 case SOL_PACKET:
1496 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001497#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001498 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001499# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001500 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001501# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001502 print_tpacket_req(tcp, addr, len);
1503 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001504#endif /* PACKET_RX_RING */
1505#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001506 case PACKET_ADD_MEMBERSHIP:
1507 case PACKET_DROP_MEMBERSHIP:
1508 print_packet_mreq(tcp, addr, len);
1509 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001510#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001511 }
1512 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001513
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001514 case SOL_RAW:
1515 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001516 case ICMP_FILTER:
1517 print_icmp_filter(tcp, addr, len);
1518 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001519 }
1520 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001521 }
1522
1523 /* default arg printing */
1524
1525 if (verbose(tcp)) {
1526 if (len == sizeof(int)) {
1527 printnum_int(tcp, addr, "%d");
1528 } else {
1529 printstr(tcp, addr, len);
1530 }
1531 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001532 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001533 }
1534done:
1535 tprintf(", %d", len);
1536}
1537
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001538SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001539{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001540 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001541 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001542 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1543 tcp->u_arg[3], tcp->u_arg[4]);
1544
1545 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001546}