blob: 13299f2b3f124a98992ed043ee3d392c81975964 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
Dmitry V. Levinb2fa2be2014-11-21 20:46:16 +000034#include <sys/uio.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <sys/un.h>
36#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000037#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010038# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000039#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000040#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010041# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010043#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010044# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010045#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000047#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048#include <asm/types.h>
Denys Vlasenko99aa1812013-02-08 18:49:06 +010049#if defined(__GLIBC__)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010050# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010052# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054
Mike Frysinger54646b82015-08-19 13:29:27 -040055#if defined(HAVE_LINUX_IP_VS_H)
56# include <linux/ip_vs.h>
57#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000058#if defined(HAVE_LINUX_NETLINK_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010059# include <linux/netlink.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000060#endif
Mike Frysinger54646b82015-08-19 13:29:27 -040061#if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
62# include <linux/netfilter_arp/arp_tables.h>
63#endif
64#if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
65# include <linux/netfilter_bridge/ebtables.h>
66#endif
67#if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
68# include <linux/netfilter_ipv4/ip_tables.h>
69#endif
70#if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
71# include <linux/netfilter_ipv6/ip6_tables.h>
72#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000073#if defined(HAVE_LINUX_IF_PACKET_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010074# include <linux/if_packet.h>
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000075#endif
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000076#if defined(HAVE_LINUX_ICMP_H)
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010077# include <linux/icmp.h>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +000078#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020079#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
80# include <bluetooth/bluetooth.h>
81# include <bluetooth/hci.h>
82# include <bluetooth/l2cap.h>
83# include <bluetooth/rfcomm.h>
84# include <bluetooth/sco.h>
85#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086#ifndef PF_UNSPEC
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010087# define PF_UNSPEC AF_UNSPEC
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088#endif
89
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000090#include "xlat/domains.h"
91#include "xlat/addrfams.h"
92#include "xlat/socktypes.h"
93#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000094#ifndef SOCK_TYPE_MASK
95# define SOCK_TYPE_MASK 0xf
96#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000097
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000098#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000099
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000100#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900101
102#ifdef PF_NETLINK
Dmitry V. Levind9f7e7a2015-01-09 03:03:39 +0000103# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
104# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
105# endif
106# include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900107#endif
108
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200109#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
110# include "xlat/bt_protocols.h"
111#endif
112
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000113#include "xlat/msg_flags.h"
Wichert Akkerman7987cdf2000-07-05 16:05:39 +0000114
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000115#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000116# include "xlat/af_packet_types.h"
117#endif
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000118
Dmitry V. Levinae280932015-06-05 20:13:21 +0000119static void
120print_ifindex(unsigned int ifindex)
121{
122#ifdef HAVE_IF_INDEXTONAME
123 char buf[IFNAMSIZ + 1];
124
125 if (if_indextoname(ifindex, buf)) {
126 tprints("if_nametoindex(");
127 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
128 tprints(")");
129 return;
130 }
131#endif
132 tprintf("%u", ifindex);
133}
134
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135void
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000136printsock(struct tcb *tcp, long addr, int addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000137{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000138 union {
139 char pad[128];
140 struct sockaddr sa;
141 struct sockaddr_in sin;
142 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000143#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000144 struct sockaddr_in6 sa6;
145#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100146#if defined(AF_IPX)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000147 struct sockaddr_ipx sipx;
148#endif
149#ifdef AF_PACKET
150 struct sockaddr_ll ll;
151#endif
152#ifdef AF_NETLINK
153 struct sockaddr_nl nl;
154#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200155#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
156 struct sockaddr_hci hci;
157 struct sockaddr_l2 l2;
158 struct sockaddr_rc rc;
159 struct sockaddr_sco sco;
160#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000161 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000162 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163
Denys Vlasenko383386d2015-07-30 13:29:20 +0200164 if (addrlen < 2) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000165 printaddr(addr);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200166 return;
167 }
168
169 if (addrlen > (int) sizeof(addrbuf))
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000170 addrlen = sizeof(addrbuf);
171
172 memset(&addrbuf, 0, sizeof(addrbuf));
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000173 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174 return;
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000175 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000176
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200177 tprints("{sa_family=");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000178 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200179 tprints(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000180
181 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 case AF_UNIX:
Dmitry V. Levinb6c32f42007-10-08 23:31:19 +0000183 if (addrlen == 2) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200184 tprints("NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000185 } else if (addrbuf.sau.sun_path[0]) {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000186 tprints("sun_path=");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000187 print_quoted_string(addrbuf.sau.sun_path,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000188 sizeof(addrbuf.sau.sun_path) + 1,
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000189 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000190 } else {
Dmitry V. Levinc86340e2012-02-22 00:23:52 +0000191 tprints("sun_path=@");
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000192 print_quoted_string(addrbuf.sau.sun_path + 1,
Dmitry V. Levinf57bd112015-01-29 15:19:21 +0000193 sizeof(addrbuf.sau.sun_path),
Dmitry V. Levind9177df2015-01-29 07:34:40 +0000194 QUOTE_0_TERMINATED);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000195 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196 break;
197 case AF_INET:
John Hughes1fcb1d62001-09-18 15:56:53 +0000198 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000199 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000201#ifdef HAVE_INET_NTOP
202 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000203 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
Wichert Akkermanf1850652001-02-16 20:29:03 +0000204 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
205 ntohs(addrbuf.sa6.sin6_port), string_addr,
206 addrbuf.sa6.sin6_flowinfo);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000207#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
Dmitry V. Levinae280932015-06-05 20:13:21 +0000208 tprints(", sin6_scope_id=");
209#if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
210 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
211 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr))
212 print_ifindex(addrbuf.sa6.sin6_scope_id);
213 else
Wichert Akkermanf1850652001-02-16 20:29:03 +0000214#endif
Dmitry V. Levinae280932015-06-05 20:13:21 +0000215 tprintf("%u", addrbuf.sa6.sin6_scope_id);
216#endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200217 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000218#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100219#if defined(AF_IPX)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000221 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 int i;
John Hughes1fcb1d62001-09-18 15:56:53 +0000223 tprintf("sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000224 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225 /* Yes, I know, this does not look too
226 * strace-ish, but otherwise the IPX
227 * addresses just look monstrous...
228 * Anyways, feel free if you don't like
Roland McGrath6d2b3492002-12-30 00:51:30 +0000229 * this way.. :)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000231 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200232 for (i = 0; i < IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000233 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
234 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 }
236 break;
Denys Vlasenko84703742012-02-25 02:38:52 +0100237#endif /* AF_IPX */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000238#ifdef AF_PACKET
239 case AF_PACKET:
240 {
241 int i;
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000242 tprintf("proto=%#04x, if%d, pkttype=",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000243 ntohs(addrbuf.ll.sll_protocol),
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000244 addrbuf.ll.sll_ifindex);
Dmitry V. Levin13063652014-09-10 00:13:56 +0000245 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
Wichert Akkermanb0c598f2002-04-01 12:48:06 +0000246 tprintf(", addr(%d)={%d, ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000247 addrbuf.ll.sll_halen,
248 addrbuf.ll.sll_hatype);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200249 for (i = 0; i < addrbuf.ll.sll_halen; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000250 tprintf("%02x", addrbuf.ll.sll_addr[i]);
251 }
252 break;
253
Denys Vlasenko84703742012-02-25 02:38:52 +0100254#endif /* AF_PACKET */
Roland McGrath36ef1bc2003-11-06 23:41:23 +0000255#ifdef AF_NETLINK
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000256 case AF_NETLINK:
257 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
258 break;
259#endif /* AF_NETLINK */
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200260#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
261 case AF_BLUETOOTH:
262 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
263 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
264 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
265 "{hci_dev=htobs(%d)}",
266 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
267 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
268 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
269 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
270 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
271 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
272 addrbuf.rc.rc_channel,
273 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
274 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
275 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
276 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
277 btohs(addrbuf.hci.hci_dev));
278 break;
279#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000281 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282
283 default:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200284 tprints("sa_data=");
Dmitry V. Levind0dceaf2015-01-30 13:36:49 +0000285 print_quoted_string(addrbuf.sa.sa_data,
286 sizeof(addrbuf.sa.sa_data), 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287 break;
288 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200289 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000290}
291
Dmitry V. Levinb36d1322015-11-18 23:18:17 +0000292#include "xlat/scmvals.h"
Roland McGrath50770822004-10-06 22:11:51 +0000293
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000294#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
295struct cmsghdr32 {
296 uint32_t cmsg_len;
297 int cmsg_level;
298 int cmsg_type;
299};
300#endif
301
302typedef union {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000303 char *ptr;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000304 struct cmsghdr *cmsg;
305#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
306 struct cmsghdr32 *cmsg32;
307#endif
308} union_cmsghdr;
309
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000310static void
311print_scm_rights(struct tcb *tcp, const size_t cmsg_size, const char *ptr,
312 const size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000313{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000314 if (cmsg_size + sizeof(int) > cmsg_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000315 return;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000316
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000317 const int *fds = (const int *) (ptr + cmsg_size);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000318 bool seen = false;
319
320 tprints(", [");
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000321 while ((const char *) fds < (ptr + cmsg_len)) {
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000322 if (seen)
323 tprints(", ");
324 else
325 seen = true;
326 printfd(tcp, *fds++);
327 }
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000328 tprints("]");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000329}
330
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000331static void
332print_scm_creds(struct tcb *tcp, const size_t cmsg_size, const char *ptr,
333 const size_t cmsg_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000334{
335 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000336 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000337
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000338 const struct ucred *uc = (const void *) (ptr + cmsg_size);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000339
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000340 tprintf(", {pid=%u, uid=%u, gid=%u}",
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000341 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000342}
343
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000344static void
345print_scm_security(struct tcb *tcp, const size_t cmsg_size, const char *ptr,
346 const size_t cmsg_len)
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000347{
348 if (cmsg_size + sizeof(char) > cmsg_len)
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000349 return;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000350
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000351 const char *label = ptr + cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000352 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000353
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000354 tprints(", ");
355 print_quoted_string(label, label_len, 0);
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000356}
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000357
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000358static void
359print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
360 const size_t cmsg_size, const char *ptr, const size_t cmsg_len)
361{
362 switch (cmsg_level) {
363 case SOL_SOCKET:
364 printxval(scmvals, cmsg_type, "SCM_???");
365 switch (cmsg_type) {
366 case SCM_RIGHTS:
367 print_scm_rights(tcp, cmsg_size, ptr, cmsg_len);
368 break;
369 case SCM_CREDENTIALS:
370 print_scm_creds(tcp, cmsg_size, ptr, cmsg_len);
371 break;
372 case SCM_SECURITY:
373 print_scm_security(tcp, cmsg_size, ptr, cmsg_len);
374 break;
375 }
376 break;
377 default:
378 tprintf("%u", cmsg_type);
379 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000380}
381
382static void
383printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
384{
385 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000386#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
387 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
388#endif
389 sizeof(struct cmsghdr);
390
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000391 char *buf = len < cmsg_size ? NULL : malloc(len);
392 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000393 tprints(", msg_control=");
394 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000395 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000396 return;
397 }
398
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000399 union_cmsghdr u = { .ptr = buf };
400
401 tprints(", [");
402 while (len >= cmsg_size) {
403 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000404#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000405 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000406#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000407 u.cmsg->cmsg_len;
408 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000409#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000410 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000411#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000412 u.cmsg->cmsg_level;
413 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000414#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000415 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000416#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000417 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000418
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000419 if (u.ptr != buf)
420 tprints(", ");
421 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
422 printxval(socketlayers, cmsg_level, "SOL_???");
423 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000424
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000425 if (cmsg_len > len)
426 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000427
Dmitry V. Levinf54cb962015-11-19 00:29:19 +0000428 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
429 cmsg_size, u.ptr, cmsg_len);
430 tprints("}");
431
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000432 if (cmsg_len < cmsg_size) {
433 len -= cmsg_size;
434 break;
Roland McGrath50770822004-10-06 22:11:51 +0000435 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000436 cmsg_len = (cmsg_len + current_wordsize - 1) &
437 (size_t) ~(current_wordsize - 1);
438 if (cmsg_len >= len) {
439 len = 0;
440 break;
441 }
442 u.ptr += cmsg_len;
443 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000444 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000445 if (len)
446 tprints(", ...");
447 tprints("]");
448 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000449}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450
451static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200452do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100453{
454 tprintf("{msg_name(%d)=", msg->msg_namelen);
455 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
456
457 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200458 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
459 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100460
461#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
462 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
463 if (msg->msg_controllen)
464 printcmsghdr(tcp, (unsigned long) msg->msg_control,
465 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200466 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100467 printflags(msg_flags, msg->msg_flags, "MSG_???");
468#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
469 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
470 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
471#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200472 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100473}
474
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100475struct msghdr32 {
476 uint32_t /* void* */ msg_name;
477 uint32_t /* socklen_t */msg_namelen;
478 uint32_t /* iovec* */ msg_iov;
479 uint32_t /* size_t */ msg_iovlen;
480 uint32_t /* void* */ msg_control;
481 uint32_t /* size_t */ msg_controllen;
482 uint32_t /* int */ msg_flags;
483};
484struct mmsghdr32 {
485 struct msghdr32 msg_hdr;
486 uint32_t /* unsigned */ msg_len;
487};
488
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900489#ifndef HAVE_STRUCT_MMSGHDR
490struct mmsghdr {
491 struct msghdr msg_hdr;
492 unsigned msg_len;
493};
494#endif
495
Masatake YAMATOb2485432014-11-07 01:23:24 +0900496#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
497static void
498copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
499{
500 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
501 to_msg->msg_namelen = from_msg32->msg_namelen;
502 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
503 to_msg->msg_iovlen = from_msg32->msg_iovlen;
504 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
505 to_msg->msg_controllen = from_msg32->msg_controllen;
506 to_msg->msg_flags = from_msg32->msg_flags;
507}
508#endif
509
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900510static bool
511extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
512{
513#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
514 if (current_wordsize == 4) {
515 struct msghdr32 msg32;
516
517 if (umove(tcp, addr, &msg32) < 0)
518 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900519 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900520 } else
521#endif
522 if (umove(tcp, addr, msg) < 0)
523 return false;
524 return true;
525}
526
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900527static bool
528extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
529{
530#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
531 if (current_wordsize == 4) {
532 struct mmsghdr32 mmsg32;
533
534 addr += sizeof(struct mmsghdr32) * idx;
535 if (umove(tcp, addr, &mmsg32) < 0)
536 return false;
537
538 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
539 mmsg->msg_len = mmsg32.msg_len;
540 } else
541#endif
542 {
543 addr += sizeof(*mmsg) * idx;
544 if (umove(tcp, addr, mmsg) < 0)
545 return false;
546 }
547 return true;
548}
549
Andreas Schwab0873f292010-02-12 21:39:12 +0100550static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200551printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552{
553 struct msghdr msg;
554
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000555 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900556 do_msghdr(tcp, &msg, data_size);
557 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000558 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900559}
560
561void
562dumpiov_in_msghdr(struct tcb *tcp, long addr)
563{
564 struct msghdr msg;
565
566 if (extractmsghdr(tcp, addr, &msg))
567 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568}
569
Andreas Schwab0873f292010-02-12 21:39:12 +0100570static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000571printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100572{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900573 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100574
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900575 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
576 tprints("{");
577 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
578 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100579 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900580 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000581 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100582}
Andreas Schwab0873f292010-02-12 21:39:12 +0100583
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000584static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000585decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000586{
587 /* mmsgvec */
588 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000589 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000590 } else {
591 unsigned int len = tcp->u_rval;
592 unsigned int i;
593
594 tprints("{");
595 for (i = 0; i < len; ++i) {
596 if (i)
597 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000598 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000599 }
600 tprints("}");
601 }
602 /* vlen */
603 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
604 /* flags */
605 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
606}
607
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900608void
609dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
610{
611 unsigned int len = tcp->u_rval;
612 unsigned int i;
613 struct mmsghdr mmsg;
614
615 for (i = 0; i < len; ++i) {
616 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
617 tprintf(" = %lu buffers in vector %u\n",
618 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
619 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
620 (long)mmsg.msg_hdr.msg_iov);
621 }
622 }
623}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000625/*
626 * low bits of the socket type define real socket type,
627 * other bits are socket type flags.
628 */
629static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000630tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000631{
632 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
633
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200634 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200635 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000636 flags &= ~SOCK_TYPE_MASK;
637 if (!flags)
638 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200639 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000640 }
641 printflags(sock_type_flags, flags, "SOCK_???");
642}
643
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000644SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000646 printxval(domains, tcp->u_arg[0], "PF_???");
647 tprints(", ");
648 tprint_sock_type(tcp->u_arg[1]);
649 tprints(", ");
650 switch (tcp->u_arg[0]) {
651 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000652#ifdef PF_INET6
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000653 case PF_INET6:
Roland McGrath8758e542003-06-23 23:39:59 +0000654#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000655 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
656 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657#ifdef PF_IPX
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000658 case PF_IPX:
659 /* BTW: I don't believe this.. */
660 tprints("[");
661 printxval(domains, tcp->u_arg[2], "PF_???");
662 tprints("]");
663 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900665#ifdef PF_NETLINK
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000666 case PF_NETLINK:
667 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
668 break;
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900669#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200670#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000671 case PF_BLUETOOTH:
672 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
673 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200674#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000675 default:
676 tprintf("%lu", tcp->u_arg[2]);
677 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000679
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000680 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000681}
682
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000683SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000685 printfd(tcp, tcp->u_arg[0]);
686 tprints(", ");
687 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
688 tprintf(", %lu", tcp->u_arg[2]);
689
690 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000691}
692
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000693SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000695 printfd(tcp, tcp->u_arg[0]);
696 tprints(", ");
697 tprintf("%lu", tcp->u_arg[1]);
698
699 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700}
701
Paolo Bonzini705ff102009-08-14 12:34:05 +0200702static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000703do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704{
705 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800706 printfd(tcp, tcp->u_arg[0]);
707 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200708 return 0;
709 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000710
711 int len;
712 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
713 umove(tcp, tcp->u_arg[2], &len) < 0) {
714 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200715 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000716 printaddr(tcp->u_arg[2]);
717 } else {
718 printsock(tcp, tcp->u_arg[1], len);
719 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000721
Paolo Bonzini705ff102009-08-14 12:34:05 +0200722 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200723 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200724 printflags(sock_type_flags, tcp->u_arg[flags_arg],
725 "SOCK_???");
726 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727 return 0;
728}
729
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000730SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200731{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000732 do_sockname(tcp, -1);
733 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200734}
735
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000736SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200737{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000738 do_sockname(tcp, 3);
739 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200740}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200741
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000742SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000744 printfd(tcp, tcp->u_arg[0]);
745 tprints(", ");
746 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
747 tprintf(", %lu, ", tcp->u_arg[2]);
748 /* flags */
749 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
750
751 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752}
753
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000754SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000756 printfd(tcp, tcp->u_arg[0]);
757 tprints(", ");
758 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
759 tprintf(", %lu, ", tcp->u_arg[2]);
760 /* flags */
761 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
762 /* to address */
763 tprints(", ");
764 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
765 /* to length */
766 tprintf(", %lu", tcp->u_arg[5]);
767
768 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000769}
770
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000771SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000772{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000773 printfd(tcp, tcp->u_arg[0]);
774 tprints(", ");
775 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
776 /* flags */
777 tprints(", ");
778 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
779
780 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000781}
782
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000783SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000784{
785 if (entering(tcp)) {
786 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800787 printfd(tcp, tcp->u_arg[0]);
788 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000789 if (!verbose(tcp)) {
790 tprintf("%#lx, %u, ",
791 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
792 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
793 }
794 } else {
795 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000796 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000797 }
798 return 0;
799}
800
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000801SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802{
803 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800804 printfd(tcp, tcp->u_arg[0]);
805 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000806 } else {
807 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000808 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 else
810 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
811
812 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000813 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814 }
815 return 0;
816}
817
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000818SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819{
820 int fromlen;
821
822 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800823 printfd(tcp, tcp->u_arg[0]);
824 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000826 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200827 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000828 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200829 } else {
830 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
831 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832 /* len */
833 tprintf(", %lu, ", tcp->u_arg[2]);
834 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000835 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200836 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000837 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000838 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200839 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000840 printaddr(tcp->u_arg[4]);
841 tprints(", ");
842 printaddr(tcp->u_arg[5]);
843 return 0;
844 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200845 /* from address */
846 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847 /* from length */
848 tprintf(", [%u]", fromlen);
849 }
850 return 0;
851}
852
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000853SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854{
855 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800856 printfd(tcp, tcp->u_arg[0]);
857 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000858 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000859 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000860 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200862 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000863 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200864 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000865 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000866 }
867 return 0;
868}
869
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000870SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +0100871{
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000872 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400873
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100874 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800875 printfd(tcp, tcp->u_arg[0]);
876 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400877 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100878 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000879 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100880 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000881 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400882 } else {
883 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
884 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200885 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400886 print_timespec(tcp, tcp->u_arg[4]);
887 }
888 return 0;
889 } else {
890 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000891 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000892 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400893 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000894 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400895 tcp->auxstr = NULL;
896 }
897 if (syserror(tcp))
898 return 0;
899 if (tcp->u_rval == 0) {
900 tcp->auxstr = "Timeout";
901 return RVAL_STR;
902 }
903 if (!verbose(tcp))
904 return 0;
905 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000906 snprintf(str, sizeof(str), "left %s",
907 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +0400908 tcp->auxstr = str;
909 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100910 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100911}
Andreas Schwab0873f292010-02-12 21:39:12 +0100912
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000913#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100914
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000915SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000917 printfd(tcp, tcp->u_arg[0]);
918 tprints(", ");
919 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
920
921 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922}
923
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000924SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000925{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000926 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927}
928
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000929static void
930printpair_fd(struct tcb *tcp, const int i0, const int i1)
931{
932 tprints("[");
933 printfd(tcp, i0);
934 tprints(", ");
935 printfd(tcp, i1);
936 tprints("]");
937}
938
939static void
940decode_pair_fd(struct tcb *tcp, const long addr)
941{
942 int pair[2];
943
944 if (umove_or_printaddr(tcp, addr, &pair))
945 return;
946
947 printpair_fd(tcp, pair[0], pair[1]);
948}
949
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000950static int
951do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 if (exiting(tcp)) {
954 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000955 printaddr(tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000956 } else {
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +0000957#ifdef HAVE_GETRVAL2
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000958 if (flags_arg < 0) {
959 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
960 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961#endif
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000962 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000963 }
964 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200965 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000966 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
967 }
968 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969 return 0;
970}
971
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000972SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000973{
974 return do_pipe(tcp, -1);
975}
976
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000977SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000978{
979 return do_pipe(tcp, 1);
980}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000981
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000982SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 if (entering(tcp)) {
985 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000987 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000988 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +0000990 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000991 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992 }
993 return 0;
994}
995
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000996#include "xlat/sockoptions.h"
997#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -0400998#include "xlat/getsockipoptions.h"
999#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001000#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -04001001#include "xlat/getsockipv6options.h"
1002#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001003#include "xlat/sockipxoptions.h"
1004#include "xlat/sockrawoptions.h"
1005#include "xlat/sockpacketoptions.h"
1006#include "xlat/socksctpoptions.h"
1007#include "xlat/socktcpoptions.h"
1008
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001009static void
Mike Frysinger54646b82015-08-19 13:29:27 -04001010print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001011{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001012 printfd(tcp, fd);
1013 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001014 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001015 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001016
John Hughes38ae88d2002-05-23 11:48:58 +00001017 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001018 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001019 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001020 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001021 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001022 printxvals(name, "IP_???", sockipoptions,
1023 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001024 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001025 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001026 printxvals(name, "IPV6_???", sockipv6options,
1027 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001028 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001029 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001030 printxval(sockipxoptions, name, "IPX_???");
1031 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001032 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001033 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001034 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001035 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001036 printxval(socktcpoptions, name, "TCP_???");
1037 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001038 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001039 printxval(socksctpoptions, name, "SCTP_???");
1040 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001041 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001042 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001043 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001044
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001045 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001046
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001047 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001048 tprintf("%u", name);
1049 }
1050
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001051 tprints(", ");
1052}
1053
1054#ifdef SO_LINGER
1055static void
1056print_linger(struct tcb *tcp, long addr, int len)
1057{
1058 struct linger linger;
1059
1060 if (len != sizeof(linger) ||
1061 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001062 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001063 return;
1064 }
1065
1066 tprintf("{onoff=%d, linger=%d}",
1067 linger.l_onoff,
1068 linger.l_linger);
1069}
1070#endif /* SO_LINGER */
1071
1072#ifdef SO_PEERCRED
1073static void
1074print_ucred(struct tcb *tcp, long addr, int len)
1075{
1076 struct ucred uc;
1077
1078 if (len != sizeof(uc) ||
1079 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001080 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001081 } else {
1082 tprintf("{pid=%u, uid=%u, gid=%u}",
1083 (unsigned) uc.pid,
1084 (unsigned) uc.uid,
1085 (unsigned) uc.gid);
1086 }
1087}
1088#endif /* SO_PEERCRED */
1089
1090#ifdef PACKET_STATISTICS
1091static void
1092print_tpacket_stats(struct tcb *tcp, long addr, int len)
1093{
1094 struct tpacket_stats stats;
1095
1096 if (len != sizeof(stats) ||
1097 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001098 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001099 } else {
1100 tprintf("{packets=%u, drops=%u}",
1101 stats.tp_packets,
1102 stats.tp_drops);
1103 }
1104}
1105#endif /* PACKET_STATISTICS */
1106
1107#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001108# include "xlat/icmpfilterflags.h"
1109
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001110static void
1111print_icmp_filter(struct tcb *tcp, long addr, int len)
1112{
1113 struct icmp_filter filter;
1114
1115 if (len != sizeof(filter) ||
1116 umove(tcp, addr, &filter) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001117 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001118 return;
1119 }
1120
1121 tprints("~(");
1122 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1123 tprints(")");
1124}
1125#endif /* ICMP_FILTER */
1126
1127static void
1128print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1129{
1130 if (addr && verbose(tcp))
1131 switch (level) {
1132 case SOL_SOCKET:
1133 switch (name) {
1134#ifdef SO_LINGER
1135 case SO_LINGER:
1136 print_linger(tcp, addr, len);
1137 goto done;
1138#endif
1139#ifdef SO_PEERCRED
1140 case SO_PEERCRED:
1141 print_ucred(tcp, addr, len);
1142 goto done;
1143#endif
1144 }
1145 break;
1146
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001147 case SOL_PACKET:
1148 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001149#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001150 case PACKET_STATISTICS:
1151 print_tpacket_stats(tcp, addr, len);
1152 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001153#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001154 }
1155 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001156
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001157 case SOL_RAW:
1158 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001159#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001160 case ICMP_FILTER:
1161 print_icmp_filter(tcp, addr, len);
1162 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001163#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001164 }
1165 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001166 }
1167
John Hughes38ae88d2002-05-23 11:48:58 +00001168 /* default arg printing */
1169
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001170 if (verbose(tcp)) {
1171 if (len == sizeof(int)) {
1172 printnum_int(tcp, addr, "%d");
1173 } else {
1174 printstr(tcp, addr, len);
1175 }
1176 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001177 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001178 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001179done:
1180 tprintf(", [%d]", len);
1181}
1182
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001183SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001184{
1185 if (entering(tcp)) {
1186 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001187 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001188 } else {
1189 int len;
1190
1191 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1192 tprintf("%#lx, %#lx",
1193 tcp->u_arg[3], tcp->u_arg[4]);
1194 } else {
1195 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1196 tcp->u_arg[3], len);
1197 }
John Hughes38ae88d2002-05-23 11:48:58 +00001198 }
1199 return 0;
1200}
1201
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001202#ifdef IP_ADD_MEMBERSHIP
1203static void
1204print_mreq(struct tcb *tcp, long addr, unsigned int len)
1205{
1206 struct ip_mreq mreq;
1207
1208 if (len < sizeof(mreq)) {
1209 printstr(tcp, addr, len);
1210 return;
1211 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001212 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001213 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001214
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001215 tprints("{imr_multiaddr=inet_addr(");
1216 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1217 16, QUOTE_0_TERMINATED);
1218 tprints("), imr_interface=inet_addr(");
1219 print_quoted_string(inet_ntoa(mreq.imr_interface),
1220 16, QUOTE_0_TERMINATED);
1221 tprints(")}");
1222}
1223#endif /* IP_ADD_MEMBERSHIP */
1224
1225#ifdef IPV6_ADD_MEMBERSHIP
1226static void
1227print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1228{
1229 struct ipv6_mreq mreq;
1230
1231 if (len < sizeof(mreq))
1232 goto fail;
1233
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001234 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001235 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001236
1237#ifdef HAVE_INET_NTOP
1238 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1239 char address[INET6_ADDRSTRLEN];
1240
1241 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1242 goto fail;
1243
1244 tprints("{ipv6mr_multiaddr=inet_pton(");
1245 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1246 tprints("), ipv6mr_interface=");
1247 print_ifindex(mreq.ipv6mr_interface);
1248 tprints("}");
1249 return;
1250#endif /* HAVE_INET_NTOP */
1251
1252fail:
1253 printstr(tcp, addr, len);
1254}
1255#endif /* IPV6_ADD_MEMBERSHIP */
1256
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001257#ifdef MCAST_JOIN_GROUP
1258static void
1259print_group_req(struct tcb *tcp, long addr, int len)
1260{
1261 struct group_req greq;
1262
1263 if (len != sizeof(greq) ||
1264 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001265 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001266 return;
1267 }
1268
1269 union {
1270 struct sockaddr *sa;
1271 struct sockaddr_in *sin;
1272#ifdef HAVE_INET_NTOP
1273 struct sockaddr_in6 *sin6;
1274#endif
1275 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1276#ifdef HAVE_INET_NTOP
1277 char str[INET6_ADDRSTRLEN];
1278#endif
1279
1280 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1281 printxval(addrfams, a.sa->sa_family, "AF_???");
1282
1283 switch (a.sa->sa_family) {
1284 case AF_INET:
1285 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1286 ntohs(a.sin->sin_port),
1287 inet_ntoa(a.sin->sin_addr));
1288 return;
1289#ifdef HAVE_INET_NTOP
1290 case AF_INET6:
1291 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1292 break;
1293 tprintf(", sin6_port=htons(%u)"
1294 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1295 ntohs(a.sin6->sin6_port), str);
1296 return;
1297#endif /* HAVE_INET_NTOP */
1298 }
1299
1300 tprints(", sa_data=");
1301 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1302 tprintf("}}");
1303
1304}
1305#endif /* MCAST_JOIN_GROUP */
1306
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001307#ifdef PACKET_RX_RING
1308static void
1309print_tpacket_req(struct tcb *tcp, long addr, int len)
1310{
1311 struct tpacket_req req;
1312
1313 if (len != sizeof(req) ||
1314 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001315 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001316 } else {
1317 tprintf("{block_size=%u, block_nr=%u, "
1318 "frame_size=%u, frame_nr=%u}",
1319 req.tp_block_size,
1320 req.tp_block_nr,
1321 req.tp_frame_size,
1322 req.tp_frame_nr);
1323 }
1324}
1325#endif /* PACKET_RX_RING */
1326
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001327#ifdef PACKET_ADD_MEMBERSHIP
1328# include "xlat/packet_mreq_type.h"
1329
1330static void
1331print_packet_mreq(struct tcb *tcp, long addr, int len)
1332{
1333 struct packet_mreq mreq;
1334
1335 if (len != sizeof(mreq) ||
1336 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001337 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001338 } else {
1339 unsigned int i;
1340
1341 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1342 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1343 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1344 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1345 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1346 for (i = 0; i < mreq.mr_alen; ++i)
1347 tprintf("%02x", mreq.mr_address[i]);
1348 tprints("}");
1349 }
1350}
1351#endif /* PACKET_ADD_MEMBERSHIP */
1352
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001353static void
1354print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1355{
1356 if (addr && verbose(tcp))
1357 switch (level) {
1358 case SOL_SOCKET:
1359 switch (name) {
1360#ifdef SO_LINGER
1361 case SO_LINGER:
1362 print_linger(tcp, addr, len);
1363 goto done;
1364#endif
1365 }
1366 break;
1367
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001368 case SOL_IP:
1369 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001370#ifdef IP_ADD_MEMBERSHIP
1371 case IP_ADD_MEMBERSHIP:
1372 case IP_DROP_MEMBERSHIP:
1373 print_mreq(tcp, addr, len);
1374 goto done;
1375#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001376#ifdef MCAST_JOIN_GROUP
1377 case MCAST_JOIN_GROUP:
1378 case MCAST_LEAVE_GROUP:
1379 print_group_req(tcp, addr, len);
1380 goto done;
1381#endif /* MCAST_JOIN_GROUP */
1382 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001383 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001384
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001385 case SOL_IPV6:
1386 switch (name) {
1387#ifdef IPV6_ADD_MEMBERSHIP
1388 case IPV6_ADD_MEMBERSHIP:
1389 case IPV6_DROP_MEMBERSHIP:
1390# ifdef IPV6_JOIN_ANYCAST
1391 case IPV6_JOIN_ANYCAST:
1392# endif
1393# ifdef IPV6_LEAVE_ANYCAST
1394 case IPV6_LEAVE_ANYCAST:
1395# endif
1396 print_mreq6(tcp, addr, len);
1397 goto done;
1398#endif /* IPV6_ADD_MEMBERSHIP */
1399 }
1400 break;
1401
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001402 case SOL_PACKET:
1403 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001404#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001405 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001406# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001407 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001408# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001409 print_tpacket_req(tcp, addr, len);
1410 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001411#endif /* PACKET_RX_RING */
1412#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001413 case PACKET_ADD_MEMBERSHIP:
1414 case PACKET_DROP_MEMBERSHIP:
1415 print_packet_mreq(tcp, addr, len);
1416 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001417#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001418 }
1419 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001420
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001421 case SOL_RAW:
1422 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001423#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001424 case ICMP_FILTER:
1425 print_icmp_filter(tcp, addr, len);
1426 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001427#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001428 }
1429 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001430 }
1431
1432 /* default arg printing */
1433
1434 if (verbose(tcp)) {
1435 if (len == sizeof(int)) {
1436 printnum_int(tcp, addr, "%d");
1437 } else {
1438 printstr(tcp, addr, len);
1439 }
1440 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001441 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001442 }
1443done:
1444 tprintf(", %d", len);
1445}
1446
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001447SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001448{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001449 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001450 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001451 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1452 tcp->u_arg[3], tcp->u_arg[4]);
1453
1454 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455}