blob: 8b43444d273b076a89d1218033fd629209590300 [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
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000129 struct sockaddr_ipx sipx;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000130 struct sockaddr_ll ll;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000131 struct sockaddr_nl nl;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000132#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
133 struct sockaddr_hci hci;
134 struct sockaddr_l2 l2;
135 struct sockaddr_rc rc;
136 struct sockaddr_sco sco;
137#endif
138} sockaddr_buf_t;
139
140static void
141print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
142{
143 tprints("{sa_family=");
144 printxval(addrfams, addr->sa.sa_family, "AF_???");
145 tprints(", ");
146
147 switch (addr->sa.sa_family) {
148 case AF_UNIX:
149 if (addrlen == 2) {
150 tprints("NULL");
151 } else if (addr->sau.sun_path[0]) {
152 tprints("sun_path=");
153 print_quoted_string(addr->sau.sun_path,
154 sizeof(addr->sau.sun_path) + 1,
155 QUOTE_0_TERMINATED);
156 } else {
157 tprints("sun_path=@");
158 print_quoted_string(addr->sau.sun_path + 1,
159 sizeof(addr->sau.sun_path),
160 QUOTE_0_TERMINATED);
161 }
162 break;
163 case AF_INET:
164 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
165 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
166 break;
167#ifdef HAVE_INET_NTOP
168 case AF_INET6:
169 {
170 char string_addr[100];
171 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
172 string_addr, sizeof(string_addr));
173 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
174 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
175 ntohs(addr->sa6.sin6_port), string_addr,
176 addr->sa6.sin6_flowinfo);
177# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
178 tprints(", sin6_scope_id=");
179# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
180 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
181 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
182 print_ifindex(addr->sa6.sin6_scope_id);
183 else
184# endif
185 tprintf("%u", addr->sa6.sin6_scope_id);
186# endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
187 }
188 break;
189#endif
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000190 case AF_IPX:
191 {
192 int i;
193 tprintf("sipx_port=htons(%u), ",
194 ntohs(addr->sipx.sipx_port));
195 /* Yes, I know, this does not look too
196 * strace-ish, but otherwise the IPX
197 * addresses just look monstrous...
198 * Anyways, feel free if you don't like
199 * this way.. :)
200 */
201 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
202 for (i = 0; i < IPX_NODE_LEN; i++)
203 tprintf("%02x", addr->sipx.sipx_node[i]);
204 tprintf("/[%02x]", addr->sipx.sipx_type);
205 }
206 break;
Dmitry V. Levineb1c22b2016-06-19 22:02:45 +0000207
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000208 case AF_PACKET:
209 {
210 int i;
211 tprintf("proto=%#04x, if%d, pkttype=",
212 ntohs(addr->ll.sll_protocol),
213 addr->ll.sll_ifindex);
214 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
215 tprintf(", addr(%d)={%d, ",
216 addr->ll.sll_halen,
217 addr->ll.sll_hatype);
218 for (i = 0; i < addr->ll.sll_halen; i++)
219 tprintf("%02x", addr->ll.sll_addr[i]);
220 }
221 break;
222
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000223 case AF_NETLINK:
224 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
225 break;
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000226#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
227 case AF_BLUETOOTH:
228 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
229 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
230 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
231 "{hci_dev=htobs(%d)}",
232 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
233 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
234 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
235 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
236 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
237 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
238 addr->rc.rc_channel,
239 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
240 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
241 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
242 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
243 btohs(addr->hci.hci_dev));
244 break;
245#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
246 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
247 AF_X25 AF_ROSE etc. still need to be done */
248
249 default:
250 tprints("sa_data=");
251 print_quoted_string(addr->sa.sa_data,
252 sizeof(addr->sa.sa_data), 0);
253 break;
254 }
255 tprints("}");
256}
257
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000259printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000260{
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000261 sockaddr_buf_t addrbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262
Denys Vlasenko383386d2015-07-30 13:29:20 +0200263 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000264 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200265 return;
266 }
267
268 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000269 addrlen = sizeof(addrbuf);
270
271 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000272 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000274 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000275
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000276 print_sockaddr(tcp, &addrbuf, addrlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277}
278
Dmitry V. Levinb36d1322015-11-18 23:18:17 +0000279#include "xlat/scmvals.h"
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300280#include "xlat/ip_cmsg_types.h"
Roland McGrath50770822004-10-06 22:11:51 +0000281
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000282#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
283struct cmsghdr32 {
284 uint32_t cmsg_len;
285 int cmsg_level;
286 int cmsg_type;
287};
288#endif
289
290typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000291 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000292 struct cmsghdr *cmsg;
293#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
294 struct cmsghdr32 *cmsg32;
295#endif
296} union_cmsghdr;
297
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000298static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000299print_scm_rights(struct tcb *tcp, const void *cmsg_data,
300 const size_t data_len)
Roland McGrath50770822004-10-06 22:11:51 +0000301{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000302 const int *fds = cmsg_data;
303 const char *end = (const char *) cmsg_data + data_len;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000304 bool seen = false;
305
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000306 if (sizeof(*fds) > data_len)
307 return;
308
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000309 tprints(", [");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000310 while ((const char *) fds < end) {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000311 if (seen)
312 tprints(", ");
313 else
314 seen = true;
315 printfd(tcp, *fds++);
316 }
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000317 tprints("]");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000318}
319
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000320static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000321print_scm_creds(struct tcb *tcp, const void *cmsg_data,
322 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000323{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000324 const struct ucred *uc = cmsg_data;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000325
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000326 if (sizeof(*uc) > data_len)
327 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000328
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000329 tprintf(", {pid=%u, uid=%u, gid=%u}",
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000330 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000331}
332
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000333static void
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000334print_scm_security(struct tcb *tcp, const void *cmsg_data,
335 const size_t data_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000336{
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000337 if (!data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000338 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000339
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000340 tprints(", ");
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000341 print_quoted_string(cmsg_data, data_len, 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000342}
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000343
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000344static void
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300345print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
346 const size_t data_len)
347{
348 const struct in_pktinfo *info = cmsg_data;
349
350 if (sizeof(*info) > data_len)
351 return;
352
353 tprints(", {ipi_ifindex=");
354 print_ifindex(info->ipi_ifindex);
355 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
356 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
357}
358
359static void
360print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
361 const size_t data_len)
362{
363 const unsigned int *ttl = cmsg_data;
364
365 if (sizeof(*ttl) > data_len)
366 return;
367
368 tprintf(", {ttl=%u}", *ttl);
369}
370
371static void
372print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
373 const size_t data_len)
374{
375 const uint8_t *tos = cmsg_data;
376
377 if (sizeof(*tos) > data_len)
378 return;
379
380 tprintf(", {tos=%x}", *tos);
381}
382
383static void
384print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
385 const size_t data_len)
386{
387 const uint32_t *csum = cmsg_data;
388
389 if (sizeof(*csum) > data_len)
390 return;
391
392 tprintf(", {csum=%u}", *csum);
393}
394
395static void
396print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
397 const size_t data_len)
398{
Dmitry V. Levina17f5932015-11-22 23:07:52 +0000399 const unsigned char *opts = cmsg_data;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300400 size_t i;
401
402 if (!data_len)
403 return;
404
405 tprints(", {opts=0x");
406 for (i = 0; i < data_len; ++i)
407 tprintf("%02x", opts[i]);
408 tprints("}");
409}
410
411static void
412print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
413 const size_t data_len)
414{
415 const struct {
416 uint32_t ee_errno;
417 uint8_t ee_origin;
418 uint8_t ee_type;
419 uint8_t ee_code;
420 uint8_t ee_pad;
421 uint32_t ee_info;
422 uint32_t ee_data;
423 struct sockaddr_in offender;
424 } *err = cmsg_data;
425
426 if (sizeof(*err) > data_len)
427 return;
428
429 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
430 ", ee_info=%u, ee_data=%u, offender=",
431 err->ee_errno, err->ee_origin, err->ee_type,
432 err->ee_code, err->ee_info, err->ee_data);
433 print_sockaddr(tcp, (const void *) &err->offender,
434 sizeof(err->offender));
435 tprints("}");
436}
437
438static void
439print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
440 const size_t data_len)
441{
442 if (sizeof(struct sockaddr_in) > data_len)
443 return;
444
445 tprints(", ");
446 print_sockaddr(tcp, cmsg_data, data_len);
447}
448
449static void
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000450print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000451 const void *cmsg_data, const size_t data_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000452{
453 switch (cmsg_level) {
454 case SOL_SOCKET:
455 printxval(scmvals, cmsg_type, "SCM_???");
456 switch (cmsg_type) {
457 case SCM_RIGHTS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000458 print_scm_rights(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000459 break;
460 case SCM_CREDENTIALS:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000461 print_scm_creds(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000462 break;
463 case SCM_SECURITY:
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000464 print_scm_security(tcp, cmsg_data, data_len);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000465 break;
466 }
467 break;
Dmitry V. Levin1f111cf2015-11-21 03:03:54 +0300468 case SOL_IP:
469 printxval(ip_cmsg_types, cmsg_type, "IP_???");
470 switch (cmsg_type) {
471 case IP_PKTINFO:
472 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
473 break;
474 case IP_TTL:
475 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
476 break;
477 case IP_TOS:
478 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
479 break;
480 case IP_RECVOPTS:
481 case IP_RETOPTS:
482 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
483 break;
484 case IP_RECVERR:
485 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
486 break;
487 case IP_ORIGDSTADDR:
488 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
489 break;
490 case IP_CHECKSUM:
491 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
492 break;
493 case SCM_SECURITY:
494 print_scm_security(tcp, cmsg_data, data_len);
495 break;
496 }
497 break;
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000498 default:
499 tprintf("%u", cmsg_type);
500 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000501}
502
503static void
504printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
505{
506 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000507#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
508 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
509#endif
510 sizeof(struct cmsghdr);
511
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000512 char *buf = len < cmsg_size ? NULL : malloc(len);
513 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000514 tprints(", msg_control=");
515 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000516 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000517 return;
518 }
519
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000520 union_cmsghdr u = { .ptr = buf };
521
522 tprints(", [");
523 while (len >= cmsg_size) {
524 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000525#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000526 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000527#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000528 u.cmsg->cmsg_len;
529 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000530#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000531 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000532#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000533 u.cmsg->cmsg_level;
534 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000535#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000536 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000537#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000538 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000539
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000540 if (u.ptr != buf)
541 tprints(", ");
542 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
543 printxval(socketlayers, cmsg_level, "SOL_???");
544 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000545
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000546 if (cmsg_len > len)
547 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000548
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000549 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
Dmitry V. Levin1103b4e2015-11-21 03:59:09 +0000550 (const void *) (u.ptr + cmsg_size),
551 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000552 tprints("}");
553
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000554 if (cmsg_len < cmsg_size) {
555 len -= cmsg_size;
556 break;
Roland McGrath50770822004-10-06 22:11:51 +0000557 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000558 cmsg_len = (cmsg_len + current_wordsize - 1) &
559 (size_t) ~(current_wordsize - 1);
560 if (cmsg_len >= len) {
561 len = 0;
562 break;
563 }
564 u.ptr += cmsg_len;
565 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000566 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000567 if (len)
568 tprints(", ...");
569 tprints("]");
570 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000571}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572
573static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200574do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100575{
576 tprintf("{msg_name(%d)=", msg->msg_namelen);
577 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
578
579 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200580 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
581 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100582
583#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
584 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
585 if (msg->msg_controllen)
586 printcmsghdr(tcp, (unsigned long) msg->msg_control,
587 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200588 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100589 printflags(msg_flags, msg->msg_flags, "MSG_???");
590#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
591 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
592 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
593#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200594 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100595}
596
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100597struct msghdr32 {
598 uint32_t /* void* */ msg_name;
599 uint32_t /* socklen_t */msg_namelen;
600 uint32_t /* iovec* */ msg_iov;
601 uint32_t /* size_t */ msg_iovlen;
602 uint32_t /* void* */ msg_control;
603 uint32_t /* size_t */ msg_controllen;
604 uint32_t /* int */ msg_flags;
605};
606struct mmsghdr32 {
607 struct msghdr32 msg_hdr;
608 uint32_t /* unsigned */ msg_len;
609};
610
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900611#ifndef HAVE_STRUCT_MMSGHDR
612struct mmsghdr {
613 struct msghdr msg_hdr;
614 unsigned msg_len;
615};
616#endif
617
Masatake YAMATOb2485432014-11-07 01:23:24 +0900618#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
619static void
620copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
621{
622 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
623 to_msg->msg_namelen = from_msg32->msg_namelen;
624 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
625 to_msg->msg_iovlen = from_msg32->msg_iovlen;
626 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
627 to_msg->msg_controllen = from_msg32->msg_controllen;
628 to_msg->msg_flags = from_msg32->msg_flags;
629}
630#endif
631
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900632static bool
633extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
634{
635#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
636 if (current_wordsize == 4) {
637 struct msghdr32 msg32;
638
639 if (umove(tcp, addr, &msg32) < 0)
640 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900641 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900642 } else
643#endif
644 if (umove(tcp, addr, msg) < 0)
645 return false;
646 return true;
647}
648
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900649static bool
650extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
651{
652#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
653 if (current_wordsize == 4) {
654 struct mmsghdr32 mmsg32;
655
656 addr += sizeof(struct mmsghdr32) * idx;
657 if (umove(tcp, addr, &mmsg32) < 0)
658 return false;
659
660 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
661 mmsg->msg_len = mmsg32.msg_len;
662 } else
663#endif
664 {
665 addr += sizeof(*mmsg) * idx;
666 if (umove(tcp, addr, mmsg) < 0)
667 return false;
668 }
669 return true;
670}
671
Andreas Schwab0873f292010-02-12 21:39:12 +0100672static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200673printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674{
675 struct msghdr msg;
676
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000677 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900678 do_msghdr(tcp, &msg, data_size);
679 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000680 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900681}
682
683void
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000684dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900685{
686 struct msghdr msg;
687
688 if (extractmsghdr(tcp, addr, &msg))
Dmitry V. Levin93c9d1c2016-01-20 03:26:37 +0000689 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690}
691
Andreas Schwab0873f292010-02-12 21:39:12 +0100692static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000693printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100694{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900695 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100696
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900697 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
698 tprints("{");
699 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
700 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100701 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900702 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000703 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100704}
Andreas Schwab0873f292010-02-12 21:39:12 +0100705
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000706static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000707decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000708{
709 /* mmsgvec */
710 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000711 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000712 } else {
713 unsigned int len = tcp->u_rval;
714 unsigned int i;
715
716 tprints("{");
717 for (i = 0; i < len; ++i) {
718 if (i)
719 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000720 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000721 }
722 tprints("}");
723 }
724 /* vlen */
725 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
726 /* flags */
727 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
728}
729
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900730void
731dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
732{
733 unsigned int len = tcp->u_rval;
734 unsigned int i;
735 struct mmsghdr mmsg;
736
737 for (i = 0; i < len; ++i) {
738 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
739 tprintf(" = %lu buffers in vector %u\n",
740 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
Dmitry V. Levind44707d2016-01-20 04:56:25 +0000741 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
742 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900743 }
744 }
745}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000746
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000747/*
748 * low bits of the socket type define real socket type,
749 * other bits are socket type flags.
750 */
751static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +0000752tprint_sock_type(unsigned int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000753{
754 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
755
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200756 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200757 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000758 flags &= ~SOCK_TYPE_MASK;
759 if (!flags)
760 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200761 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000762 }
763 printflags(sock_type_flags, flags, "SOCK_???");
764}
765
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000766SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767{
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000768 printxval(addrfams, tcp->u_arg[0], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000769 tprints(", ");
770 tprint_sock_type(tcp->u_arg[1]);
771 tprints(", ");
772 switch (tcp->u_arg[0]) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000773 case AF_INET:
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000774 case AF_INET6:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000775 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
776 break;
Dmitry V. Levineb1c22b2016-06-19 22:02:45 +0000777
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000778 case AF_IPX:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000779 /* BTW: I don't believe this.. */
780 tprints("[");
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000781 printxval(addrfams, tcp->u_arg[2], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000782 tprints("]");
783 break;
Dmitry V. Levineb1c22b2016-06-19 22:02:45 +0000784
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000785 case AF_NETLINK:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000786 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
787 break;
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000788#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
789 case AF_BLUETOOTH:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000790 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
791 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200792#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000793 default:
794 tprintf("%lu", tcp->u_arg[2]);
795 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000796 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000797
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000798 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799}
800
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000801SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000803 printfd(tcp, tcp->u_arg[0]);
804 tprints(", ");
805 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
806 tprintf(", %lu", tcp->u_arg[2]);
807
808 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809}
810
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000811SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000812{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000813 printfd(tcp, tcp->u_arg[0]);
814 tprints(", ");
815 tprintf("%lu", tcp->u_arg[1]);
816
817 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000818}
819
Paolo Bonzini705ff102009-08-14 12:34:05 +0200820static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000821do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822{
823 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800824 printfd(tcp, tcp->u_arg[0]);
825 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200826 return 0;
827 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000828
829 int len;
830 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
831 umove(tcp, tcp->u_arg[2], &len) < 0) {
832 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200833 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000834 printaddr(tcp->u_arg[2]);
835 } else {
836 printsock(tcp, tcp->u_arg[1], len);
837 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000839
Paolo Bonzini705ff102009-08-14 12:34:05 +0200840 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200841 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200842 printflags(sock_type_flags, tcp->u_arg[flags_arg],
843 "SOCK_???");
844 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845 return 0;
846}
847
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000848SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200849{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000850 do_sockname(tcp, -1);
851 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200852}
853
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000854SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200855{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000856 do_sockname(tcp, 3);
857 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200858}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200859
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000860SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000862 printfd(tcp, tcp->u_arg[0]);
863 tprints(", ");
864 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
865 tprintf(", %lu, ", tcp->u_arg[2]);
866 /* flags */
867 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
868
869 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870}
871
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000872SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000873{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000874 printfd(tcp, tcp->u_arg[0]);
875 tprints(", ");
876 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
877 tprintf(", %lu, ", tcp->u_arg[2]);
878 /* flags */
879 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
880 /* to address */
881 tprints(", ");
882 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
883 /* to length */
884 tprintf(", %lu", tcp->u_arg[5]);
885
886 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887}
888
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000889SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000890{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000891 printfd(tcp, tcp->u_arg[0]);
892 tprints(", ");
893 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
894 /* flags */
895 tprints(", ");
896 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
897
898 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899}
900
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000901SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000902{
903 if (entering(tcp)) {
904 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800905 printfd(tcp, tcp->u_arg[0]);
906 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000907 if (!verbose(tcp)) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000908 printaddr(tcp->u_arg[1]);
909 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000910 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
911 }
912 } else {
913 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000914 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000915 }
916 return 0;
917}
918
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000919SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000920{
921 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800922 printfd(tcp, tcp->u_arg[0]);
923 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000924 } else {
925 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000926 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927 else
928 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
929
930 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000931 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000932 }
933 return 0;
934}
935
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000936SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000937{
938 int fromlen;
939
940 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800941 printfd(tcp, tcp->u_arg[0]);
942 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000943 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000944 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200945 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000946 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200947 } else {
948 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
949 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950 /* len */
951 tprintf(", %lu, ", tcp->u_arg[2]);
952 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000953 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200954 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000955 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000956 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200957 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000958 printaddr(tcp->u_arg[4]);
959 tprints(", ");
960 printaddr(tcp->u_arg[5]);
961 return 0;
962 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200963 /* from address */
964 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965 /* from length */
966 tprintf(", [%u]", fromlen);
967 }
968 return 0;
969}
970
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000971SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972{
973 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800974 printfd(tcp, tcp->u_arg[0]);
975 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000977 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000978 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200980 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200982 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000983 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 }
985 return 0;
986}
987
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000988SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +0100989{
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000990 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400991
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100992 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800993 printfd(tcp, tcp->u_arg[0]);
994 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400995 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100996 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000997 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100998 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000999 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001000 } else {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001001 printaddr(tcp->u_arg[1]);
1002 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001003 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001004 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001005 print_timespec(tcp, tcp->u_arg[4]);
1006 }
1007 return 0;
1008 } else {
1009 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +00001010 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001011 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +04001012 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001013 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +04001014 tcp->auxstr = NULL;
1015 }
1016 if (syserror(tcp))
1017 return 0;
1018 if (tcp->u_rval == 0) {
1019 tcp->auxstr = "Timeout";
1020 return RVAL_STR;
1021 }
1022 if (!verbose(tcp))
1023 return 0;
1024 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +00001025 snprintf(str, sizeof(str), "left %s",
1026 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +04001027 tcp->auxstr = str;
1028 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +01001029 }
Andreas Schwab0873f292010-02-12 21:39:12 +01001030}
Andreas Schwab0873f292010-02-12 21:39:12 +01001031
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001032#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +01001033
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001034SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001035{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001036 printfd(tcp, tcp->u_arg[0]);
1037 tprints(", ");
1038 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1039
1040 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041}
1042
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001043SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +00001045 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046}
1047
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001048static void
1049printpair_fd(struct tcb *tcp, const int i0, const int i1)
1050{
1051 tprints("[");
1052 printfd(tcp, i0);
1053 tprints(", ");
1054 printfd(tcp, i1);
1055 tprints("]");
1056}
1057
1058static void
1059decode_pair_fd(struct tcb *tcp, const long addr)
1060{
1061 int pair[2];
1062
1063 if (umove_or_printaddr(tcp, addr, &pair))
1064 return;
1065
1066 printpair_fd(tcp, pair[0], pair[1]);
1067}
1068
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001069static int
1070do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072 if (exiting(tcp)) {
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001073 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001074 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001075 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001076 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1077 }
1078 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079 return 0;
1080}
1081
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001082SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001083{
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001084#ifdef HAVE_GETRVAL2
1085 if (exiting(tcp) && !syserror(tcp))
1086 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1087 return 0;
1088#else
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001089 return do_pipe(tcp, -1);
Dmitry V. Levin9b388852016-02-12 16:37:31 +00001090#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001091}
1092
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001093SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001094{
1095 return do_pipe(tcp, 1);
1096}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001097
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001098SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001100 if (entering(tcp)) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +00001101 printxval(addrfams, tcp->u_arg[0], "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001102 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +00001103 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +00001104 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001105 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +00001106 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +00001107 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108 }
1109 return 0;
1110}
1111
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001112#include "xlat/sockoptions.h"
1113#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001114#include "xlat/getsockipoptions.h"
1115#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001116#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001117#include "xlat/getsockipv6options.h"
1118#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001119#include "xlat/sockipxoptions.h"
1120#include "xlat/sockrawoptions.h"
1121#include "xlat/sockpacketoptions.h"
1122#include "xlat/socksctpoptions.h"
1123#include "xlat/socktcpoptions.h"
1124
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001125static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001126print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1127 unsigned int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001129 printfd(tcp, fd);
1130 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001131 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001132 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001133
John Hughes38ae88d2002-05-23 11:48:58 +00001134 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001135 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001136 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001137 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001138 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001139 printxvals(name, "IP_???", sockipoptions,
1140 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001141 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001142 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001143 printxvals(name, "IPV6_???", sockipv6options,
1144 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001145 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001146 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001147 printxval(sockipxoptions, name, "IPX_???");
1148 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001149 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001150 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001151 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001152 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001153 printxval(socktcpoptions, name, "TCP_???");
1154 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001155 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001156 printxval(socksctpoptions, name, "SCTP_???");
1157 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001158 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001159 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001160 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001161
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001162 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001163
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001164 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001165 tprintf("%u", name);
1166 }
1167
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001168 tprints(", ");
1169}
1170
1171#ifdef SO_LINGER
1172static void
1173print_linger(struct tcb *tcp, long addr, int len)
1174{
1175 struct linger linger;
1176
1177 if (len != sizeof(linger) ||
1178 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001179 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001180 return;
1181 }
1182
1183 tprintf("{onoff=%d, linger=%d}",
1184 linger.l_onoff,
1185 linger.l_linger);
1186}
1187#endif /* SO_LINGER */
1188
1189#ifdef SO_PEERCRED
1190static void
1191print_ucred(struct tcb *tcp, long addr, int len)
1192{
1193 struct ucred uc;
1194
1195 if (len != sizeof(uc) ||
1196 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001197 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001198 } else {
1199 tprintf("{pid=%u, uid=%u, gid=%u}",
1200 (unsigned) uc.pid,
1201 (unsigned) uc.uid,
1202 (unsigned) uc.gid);
1203 }
1204}
1205#endif /* SO_PEERCRED */
1206
1207#ifdef PACKET_STATISTICS
1208static void
1209print_tpacket_stats(struct tcb *tcp, long addr, int len)
1210{
1211 struct tpacket_stats stats;
1212
1213 if (len != sizeof(stats) ||
1214 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001215 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001216 } else {
1217 tprintf("{packets=%u, drops=%u}",
1218 stats.tp_packets,
1219 stats.tp_drops);
1220 }
1221}
1222#endif /* PACKET_STATISTICS */
1223
Dmitry V. Levinfba9db22016-06-15 21:29:07 +00001224#include "xlat/icmpfilterflags.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001225
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001226static void
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001227print_icmp_filter(struct tcb *tcp, const long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001228{
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001229 struct icmp_filter filter = {};
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001230
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001231 if (len > (int) sizeof(filter))
1232 len = sizeof(filter);
1233 else if (len <= 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001234 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001235 return;
1236 }
1237
Dmitry V. Levineb5c2332016-05-06 00:06:15 +00001238 if (umoven_or_printaddr(tcp, addr, len, &filter))
1239 return;
1240
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001241 tprints("~(");
1242 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1243 tprints(")");
1244}
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001245
1246static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001247print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1248 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001249{
1250 if (addr && verbose(tcp))
1251 switch (level) {
1252 case SOL_SOCKET:
1253 switch (name) {
1254#ifdef SO_LINGER
1255 case SO_LINGER:
1256 print_linger(tcp, addr, len);
1257 goto done;
1258#endif
1259#ifdef SO_PEERCRED
1260 case SO_PEERCRED:
1261 print_ucred(tcp, addr, len);
1262 goto done;
1263#endif
1264 }
1265 break;
1266
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001267 case SOL_PACKET:
1268 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001269#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001270 case PACKET_STATISTICS:
1271 print_tpacket_stats(tcp, addr, len);
1272 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001273#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001274 }
1275 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001276
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001277 case SOL_RAW:
1278 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001279 case ICMP_FILTER:
1280 print_icmp_filter(tcp, addr, len);
1281 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001282 }
1283 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001284 }
1285
John Hughes38ae88d2002-05-23 11:48:58 +00001286 /* default arg printing */
1287
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001288 if (verbose(tcp)) {
1289 if (len == sizeof(int)) {
1290 printnum_int(tcp, addr, "%d");
1291 } else {
1292 printstr(tcp, addr, len);
1293 }
1294 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001295 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001296 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001297done:
1298 tprintf(", [%d]", len);
1299}
1300
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001301SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001302{
1303 if (entering(tcp)) {
1304 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001305 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001306 } else {
1307 int len;
1308
1309 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +00001310 printaddr(tcp->u_arg[3]);
1311 tprints(", ");
1312 printaddr(tcp->u_arg[4]);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001313 } else {
1314 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1315 tcp->u_arg[3], len);
1316 }
John Hughes38ae88d2002-05-23 11:48:58 +00001317 }
1318 return 0;
1319}
1320
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001321#ifdef IP_ADD_MEMBERSHIP
1322static void
1323print_mreq(struct tcb *tcp, long addr, unsigned int len)
1324{
1325 struct ip_mreq mreq;
1326
1327 if (len < sizeof(mreq)) {
1328 printstr(tcp, addr, len);
1329 return;
1330 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001331 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001332 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001333
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001334 tprints("{imr_multiaddr=inet_addr(");
1335 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1336 16, QUOTE_0_TERMINATED);
1337 tprints("), imr_interface=inet_addr(");
1338 print_quoted_string(inet_ntoa(mreq.imr_interface),
1339 16, QUOTE_0_TERMINATED);
1340 tprints(")}");
1341}
1342#endif /* IP_ADD_MEMBERSHIP */
1343
1344#ifdef IPV6_ADD_MEMBERSHIP
1345static void
1346print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1347{
1348 struct ipv6_mreq mreq;
1349
1350 if (len < sizeof(mreq))
1351 goto fail;
1352
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001353 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001354 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001355
1356#ifdef HAVE_INET_NTOP
1357 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1358 char address[INET6_ADDRSTRLEN];
1359
1360 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1361 goto fail;
1362
1363 tprints("{ipv6mr_multiaddr=inet_pton(");
1364 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1365 tprints("), ipv6mr_interface=");
1366 print_ifindex(mreq.ipv6mr_interface);
1367 tprints("}");
1368 return;
1369#endif /* HAVE_INET_NTOP */
1370
1371fail:
1372 printstr(tcp, addr, len);
1373}
1374#endif /* IPV6_ADD_MEMBERSHIP */
1375
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001376#ifdef MCAST_JOIN_GROUP
1377static void
1378print_group_req(struct tcb *tcp, long addr, int len)
1379{
1380 struct group_req greq;
1381
1382 if (len != sizeof(greq) ||
1383 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001384 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001385 return;
1386 }
1387
Dmitry V. Levin1019f002015-11-21 02:38:59 +00001388 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1389 print_sockaddr(tcp, (const void *) &greq.gr_group,
1390 sizeof(greq.gr_group));
1391 tprintf("}");
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001392
1393}
1394#endif /* MCAST_JOIN_GROUP */
1395
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001396#ifdef PACKET_RX_RING
1397static void
1398print_tpacket_req(struct tcb *tcp, long addr, int len)
1399{
1400 struct tpacket_req req;
1401
1402 if (len != sizeof(req) ||
1403 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001404 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001405 } else {
1406 tprintf("{block_size=%u, block_nr=%u, "
1407 "frame_size=%u, frame_nr=%u}",
1408 req.tp_block_size,
1409 req.tp_block_nr,
1410 req.tp_frame_size,
1411 req.tp_frame_nr);
1412 }
1413}
1414#endif /* PACKET_RX_RING */
1415
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001416#ifdef PACKET_ADD_MEMBERSHIP
1417# include "xlat/packet_mreq_type.h"
1418
1419static void
1420print_packet_mreq(struct tcb *tcp, long addr, int len)
1421{
1422 struct packet_mreq mreq;
1423
1424 if (len != sizeof(mreq) ||
1425 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001426 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001427 } else {
1428 unsigned int i;
1429
1430 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1431 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1432 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1433 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1434 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1435 for (i = 0; i < mreq.mr_alen; ++i)
1436 tprintf("%02x", mreq.mr_address[i]);
1437 tprints("}");
1438 }
1439}
1440#endif /* PACKET_ADD_MEMBERSHIP */
1441
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001442static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +00001443print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1444 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001445{
1446 if (addr && verbose(tcp))
1447 switch (level) {
1448 case SOL_SOCKET:
1449 switch (name) {
1450#ifdef SO_LINGER
1451 case SO_LINGER:
1452 print_linger(tcp, addr, len);
1453 goto done;
1454#endif
1455 }
1456 break;
1457
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001458 case SOL_IP:
1459 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001460#ifdef IP_ADD_MEMBERSHIP
1461 case IP_ADD_MEMBERSHIP:
1462 case IP_DROP_MEMBERSHIP:
1463 print_mreq(tcp, addr, len);
1464 goto done;
1465#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001466#ifdef MCAST_JOIN_GROUP
1467 case MCAST_JOIN_GROUP:
1468 case MCAST_LEAVE_GROUP:
1469 print_group_req(tcp, addr, len);
1470 goto done;
1471#endif /* MCAST_JOIN_GROUP */
1472 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001473 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001474
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001475 case SOL_IPV6:
1476 switch (name) {
1477#ifdef IPV6_ADD_MEMBERSHIP
1478 case IPV6_ADD_MEMBERSHIP:
1479 case IPV6_DROP_MEMBERSHIP:
1480# ifdef IPV6_JOIN_ANYCAST
1481 case IPV6_JOIN_ANYCAST:
1482# endif
1483# ifdef IPV6_LEAVE_ANYCAST
1484 case IPV6_LEAVE_ANYCAST:
1485# endif
1486 print_mreq6(tcp, addr, len);
1487 goto done;
1488#endif /* IPV6_ADD_MEMBERSHIP */
1489 }
1490 break;
1491
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001492 case SOL_PACKET:
1493 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001494#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001495 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001496# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001497 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001498# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001499 print_tpacket_req(tcp, addr, len);
1500 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001501#endif /* PACKET_RX_RING */
1502#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001503 case PACKET_ADD_MEMBERSHIP:
1504 case PACKET_DROP_MEMBERSHIP:
1505 print_packet_mreq(tcp, addr, len);
1506 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001507#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001508 }
1509 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001510
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001511 case SOL_RAW:
1512 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001513 case ICMP_FILTER:
1514 print_icmp_filter(tcp, addr, len);
1515 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001516 }
1517 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001518 }
1519
1520 /* default arg printing */
1521
1522 if (verbose(tcp)) {
1523 if (len == sizeof(int)) {
1524 printnum_int(tcp, addr, "%d");
1525 } else {
1526 printstr(tcp, addr, len);
1527 }
1528 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001529 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001530 }
1531done:
1532 tprintf(", %d", len);
1533}
1534
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001535SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001536{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001537 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001538 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001539 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1540 tcp->u_arg[3], tcp->u_arg[4]);
1541
1542 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543}