blob: 74ea37f3552245d77860102460bd83771617f2e6 [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. Levinb85a7f32015-01-24 15:20:31 +0000310static bool
311print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
Roland McGrath50770822004-10-06 22:11:51 +0000312{
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000313 if (cmsg_size + sizeof(int) > cmsg_len)
314 return false;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000315
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000316 int *fds = (int *) (ptr + cmsg_size);
317 bool seen = false;
318
319 tprints(", [");
320 while ((char *) fds < (ptr + cmsg_len)) {
321 if (seen)
322 tprints(", ");
323 else
324 seen = true;
325 printfd(tcp, *fds++);
326 }
327 tprints("]}");
328 return true;
329}
330
331static bool
332print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
333{
334 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
335 return false;
336
337 const struct ucred *uc = (void *) (ptr + cmsg_size);
338
339 tprintf(", {pid=%u, uid=%u, gid=%u}}",
340 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
341 return true;
342}
343
344static bool
345print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
346{
347 if (cmsg_size + sizeof(char) > cmsg_len)
348 return false;
349
350 const char *label = (const char *) (ptr + cmsg_size);
351 const size_t label_len = cmsg_len - cmsg_size;
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000352
Dmitry V. Levin513e96e2015-01-26 01:17:08 +0000353 tprints(", ");
354 print_quoted_string(label, label_len, 0);
355 tprints("}");
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000356
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000357 return true;
358}
359
360static void
361printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
362{
363 const size_t cmsg_size =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000364#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
365 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
366#endif
367 sizeof(struct cmsghdr);
368
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000369 char *buf = len < cmsg_size ? NULL : malloc(len);
370 if (!buf || umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000371 tprints(", msg_control=");
372 printaddr(addr);
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000373 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000374 return;
375 }
376
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000377 union_cmsghdr u = { .ptr = buf };
378
379 tprints(", [");
380 while (len >= cmsg_size) {
381 size_t cmsg_len =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000382#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000383 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000384#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000385 u.cmsg->cmsg_len;
386 int cmsg_level =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000387#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000388 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000389#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000390 u.cmsg->cmsg_level;
391 int cmsg_type =
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000392#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000393 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000394#endif
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000395 u.cmsg->cmsg_type;
Dmitry V. Levin05884d82015-01-24 01:08:57 +0000396
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000397 if (u.ptr != buf)
398 tprints(", ");
399 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
400 printxval(socketlayers, cmsg_level, "SOL_???");
401 tprints(", cmsg_type=");
Roland McGrath50770822004-10-06 22:11:51 +0000402
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000403 if (cmsg_len > len)
404 cmsg_len = len;
Roland McGrath96ad7b82005-02-02 03:11:32 +0000405
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000406 if (cmsg_level == SOL_SOCKET) {
407 printxval(scmvals, cmsg_type, "SCM_???");
408 switch (cmsg_type) {
409 case SCM_RIGHTS:
410 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
411 goto next_cmsg;
412 break;
413 case SCM_CREDENTIALS:
414 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
415 goto next_cmsg;
416 break;
417 case SCM_SECURITY:
418 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
419 goto next_cmsg;
420 break;
Roland McGrath50770822004-10-06 22:11:51 +0000421 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000422 } else {
423 tprintf("%u", cmsg_type);
Roland McGrath50770822004-10-06 22:11:51 +0000424 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000425 tprints(", ...}");
426next_cmsg:
427 if (cmsg_len < cmsg_size) {
428 len -= cmsg_size;
429 break;
Roland McGrath50770822004-10-06 22:11:51 +0000430 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000431 cmsg_len = (cmsg_len + current_wordsize - 1) &
432 (size_t) ~(current_wordsize - 1);
433 if (cmsg_len >= len) {
434 len = 0;
435 break;
436 }
437 u.ptr += cmsg_len;
438 len -= cmsg_len;
Roland McGrath50770822004-10-06 22:11:51 +0000439 }
Dmitry V. Levinb85a7f32015-01-24 15:20:31 +0000440 if (len)
441 tprints(", ...");
442 tprints("]");
443 free(buf);
Roland McGrath50770822004-10-06 22:11:51 +0000444}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445
446static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200447do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
Andreas Schwab0873f292010-02-12 21:39:12 +0100448{
449 tprintf("{msg_name(%d)=", msg->msg_namelen);
450 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
451
452 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200453 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
454 (unsigned long)msg->msg_iov, 1, data_size);
Andreas Schwab0873f292010-02-12 21:39:12 +0100455
456#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
457 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
458 if (msg->msg_controllen)
459 printcmsghdr(tcp, (unsigned long) msg->msg_control,
460 msg->msg_controllen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200461 tprints(", msg_flags=");
Andreas Schwab0873f292010-02-12 21:39:12 +0100462 printflags(msg_flags, msg->msg_flags, "MSG_???");
463#else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
464 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
465 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
466#endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200467 tprints("}");
Andreas Schwab0873f292010-02-12 21:39:12 +0100468}
469
Denys Vlasenko3e759d42013-02-12 11:57:48 +0100470struct msghdr32 {
471 uint32_t /* void* */ msg_name;
472 uint32_t /* socklen_t */msg_namelen;
473 uint32_t /* iovec* */ msg_iov;
474 uint32_t /* size_t */ msg_iovlen;
475 uint32_t /* void* */ msg_control;
476 uint32_t /* size_t */ msg_controllen;
477 uint32_t /* int */ msg_flags;
478};
479struct mmsghdr32 {
480 struct msghdr32 msg_hdr;
481 uint32_t /* unsigned */ msg_len;
482};
483
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900484#ifndef HAVE_STRUCT_MMSGHDR
485struct mmsghdr {
486 struct msghdr msg_hdr;
487 unsigned msg_len;
488};
489#endif
490
Masatake YAMATOb2485432014-11-07 01:23:24 +0900491#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
492static void
493copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
494{
495 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
496 to_msg->msg_namelen = from_msg32->msg_namelen;
497 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
498 to_msg->msg_iovlen = from_msg32->msg_iovlen;
499 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
500 to_msg->msg_controllen = from_msg32->msg_controllen;
501 to_msg->msg_flags = from_msg32->msg_flags;
502}
503#endif
504
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900505static bool
506extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
507{
508#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
509 if (current_wordsize == 4) {
510 struct msghdr32 msg32;
511
512 if (umove(tcp, addr, &msg32) < 0)
513 return false;
Masatake YAMATOb2485432014-11-07 01:23:24 +0900514 copy_from_msghdr32(msg, &msg32);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900515 } else
516#endif
517 if (umove(tcp, addr, msg) < 0)
518 return false;
519 return true;
520}
521
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900522static bool
523extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
524{
525#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
526 if (current_wordsize == 4) {
527 struct mmsghdr32 mmsg32;
528
529 addr += sizeof(struct mmsghdr32) * idx;
530 if (umove(tcp, addr, &mmsg32) < 0)
531 return false;
532
533 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
534 mmsg->msg_len = mmsg32.msg_len;
535 } else
536#endif
537 {
538 addr += sizeof(*mmsg) * idx;
539 if (umove(tcp, addr, mmsg) < 0)
540 return false;
541 }
542 return true;
543}
544
Andreas Schwab0873f292010-02-12 21:39:12 +0100545static void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200546printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547{
548 struct msghdr msg;
549
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000550 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900551 do_msghdr(tcp, &msg, data_size);
552 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000553 printaddr(addr);
Masatake YAMATO02f9f6b2014-10-15 22:11:43 +0900554}
555
556void
557dumpiov_in_msghdr(struct tcb *tcp, long addr)
558{
559 struct msghdr msg;
560
561 if (extractmsghdr(tcp, addr, &msg))
562 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563}
564
Andreas Schwab0873f292010-02-12 21:39:12 +0100565static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000566printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
Andreas Schwab0873f292010-02-12 21:39:12 +0100567{
Masatake YAMATOcaf6a432014-11-07 01:23:25 +0900568 struct mmsghdr mmsg;
Andreas Schwab0873f292010-02-12 21:39:12 +0100569
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900570 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
571 tprints("{");
572 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
573 tprintf(", %u}", mmsg.msg_len);
Andreas Schwab0873f292010-02-12 21:39:12 +0100574 }
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900575 else
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000576 printaddr(addr);
Andreas Schwab0873f292010-02-12 21:39:12 +0100577}
Andreas Schwab0873f292010-02-12 21:39:12 +0100578
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000579static void
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000580decode_mmsg(struct tcb *tcp, unsigned long msg_len)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000581{
582 /* mmsgvec */
583 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000584 printaddr(tcp->u_arg[1]);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000585 } else {
586 unsigned int len = tcp->u_rval;
587 unsigned int i;
588
589 tprints("{");
590 for (i = 0; i < len; ++i) {
591 if (i)
592 tprints(", ");
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000593 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000594 }
595 tprints("}");
596 }
597 /* vlen */
598 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
599 /* flags */
600 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
601}
602
Masatake YAMATOa807dce2014-11-07 01:23:26 +0900603void
604dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
605{
606 unsigned int len = tcp->u_rval;
607 unsigned int i;
608 struct mmsghdr mmsg;
609
610 for (i = 0; i < len; ++i) {
611 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
612 tprintf(" = %lu buffers in vector %u\n",
613 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
614 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
615 (long)mmsg.msg_hdr.msg_iov);
616 }
617 }
618}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000620/*
621 * low bits of the socket type define real socket type,
622 * other bits are socket type flags.
623 */
624static void
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000625tprint_sock_type(int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000626{
627 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
628
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200629 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200630 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000631 flags &= ~SOCK_TYPE_MASK;
632 if (!flags)
633 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200634 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000635 }
636 printflags(sock_type_flags, flags, "SOCK_???");
637}
638
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000639SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000641 printxval(domains, tcp->u_arg[0], "PF_???");
642 tprints(", ");
643 tprint_sock_type(tcp->u_arg[1]);
644 tprints(", ");
645 switch (tcp->u_arg[0]) {
646 case PF_INET:
Roland McGrath8758e542003-06-23 23:39:59 +0000647#ifdef PF_INET6
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000648 case PF_INET6:
Roland McGrath8758e542003-06-23 23:39:59 +0000649#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000650 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
651 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652#ifdef PF_IPX
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000653 case PF_IPX:
654 /* BTW: I don't believe this.. */
655 tprints("[");
656 printxval(domains, tcp->u_arg[2], "PF_???");
657 tprints("]");
658 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659#endif /* PF_IPX */
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900660#ifdef PF_NETLINK
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000661 case PF_NETLINK:
662 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
663 break;
Masatake YAMATO2394a3d2014-03-11 23:37:37 +0900664#endif
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200665#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000666 case PF_BLUETOOTH:
667 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
668 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200669#endif
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000670 default:
671 tprintf("%lu", tcp->u_arg[2]);
672 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000674
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000675 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676}
677
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000678SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000680 printfd(tcp, tcp->u_arg[0]);
681 tprints(", ");
682 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
683 tprintf(", %lu", tcp->u_arg[2]);
684
685 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686}
687
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000688SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000690 printfd(tcp, tcp->u_arg[0]);
691 tprints(", ");
692 tprintf("%lu", tcp->u_arg[1]);
693
694 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695}
696
Paolo Bonzini705ff102009-08-14 12:34:05 +0200697static int
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000698do_sockname(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699{
700 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800701 printfd(tcp, tcp->u_arg[0]);
702 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200703 return 0;
704 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000705
706 int len;
707 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
708 umove(tcp, tcp->u_arg[2], &len) < 0) {
709 printaddr(tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200710 tprints(", ");
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000711 printaddr(tcp->u_arg[2]);
712 } else {
713 printsock(tcp, tcp->u_arg[1], len);
714 tprintf(", [%d]", len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000715 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000716
Paolo Bonzini705ff102009-08-14 12:34:05 +0200717 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200718 tprints(", ");
Paolo Bonzini705ff102009-08-14 12:34:05 +0200719 printflags(sock_type_flags, tcp->u_arg[flags_arg],
720 "SOCK_???");
721 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722 return 0;
723}
724
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000725SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200726{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000727 do_sockname(tcp, -1);
728 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200729}
730
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000731SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200732{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000733 do_sockname(tcp, 3);
734 return RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200735}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200736
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000737SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000739 printfd(tcp, tcp->u_arg[0]);
740 tprints(", ");
741 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
742 tprintf(", %lu, ", tcp->u_arg[2]);
743 /* flags */
744 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
745
746 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747}
748
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000749SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000750{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000751 printfd(tcp, tcp->u_arg[0]);
752 tprints(", ");
753 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
754 tprintf(", %lu, ", tcp->u_arg[2]);
755 /* flags */
756 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
757 /* to address */
758 tprints(", ");
759 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
760 /* to length */
761 tprintf(", %lu", tcp->u_arg[5]);
762
763 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764}
765
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000766SYS_FUNC(sendmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000768 printfd(tcp, tcp->u_arg[0]);
769 tprints(", ");
770 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
771 /* flags */
772 tprints(", ");
773 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
774
775 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776}
777
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000778SYS_FUNC(sendmmsg)
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000779{
780 if (entering(tcp)) {
781 /* sockfd */
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800782 printfd(tcp, tcp->u_arg[0]);
783 tprints(", ");
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000784 if (!verbose(tcp)) {
785 tprintf("%#lx, %u, ",
786 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
787 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
788 }
789 } else {
790 if (verbose(tcp))
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000791 decode_mmsg(tcp, (unsigned long) -1L);
Dmitry V. Levin7af9f352012-03-11 23:59:29 +0000792 }
793 return 0;
794}
795
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000796SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000797{
798 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800799 printfd(tcp, tcp->u_arg[0]);
800 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000801 } else {
802 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000803 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000804 else
805 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
806
807 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000808 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809 }
810 return 0;
811}
812
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000813SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814{
815 int fromlen;
816
817 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800818 printfd(tcp, tcp->u_arg[0]);
819 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200822 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000823 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200824 } else {
825 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
826 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000827 /* len */
828 tprintf(", %lu, ", tcp->u_arg[2]);
829 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000830 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200831 tprints(", ");
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000832 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000833 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
Denys Vlasenko383386d2015-07-30 13:29:20 +0200834 /* from address, len */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000835 printaddr(tcp->u_arg[4]);
836 tprints(", ");
837 printaddr(tcp->u_arg[5]);
838 return 0;
839 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200840 /* from address */
841 printsock(tcp, tcp->u_arg[4], fromlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000842 /* from length */
843 tprintf(", [%u]", fromlen);
844 }
845 return 0;
846}
847
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000848SYS_FUNC(recvmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000849{
850 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800851 printfd(tcp, tcp->u_arg[0]);
852 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 } else {
Dmitry V. Levin00244b92015-01-28 01:52:25 +0000854 if (syserror(tcp))
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000855 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 else
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200857 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000858 /* flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000860 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861 }
862 return 0;
863}
864
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000865SYS_FUNC(recvmmsg)
Andreas Schwab0873f292010-02-12 21:39:12 +0100866{
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000867 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
Dmitry V. Levine6591032010-03-29 20:45:48 +0400868
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100869 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800870 printfd(tcp, tcp->u_arg[0]);
871 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400872 if (verbose(tcp)) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100873 /* Abusing tcp->auxstr as temp storage.
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000874 * Will be used and cleared on syscall exit.
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100875 */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000876 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400877 } else {
878 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
879 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200880 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400881 print_timespec(tcp, tcp->u_arg[4]);
882 }
883 return 0;
884 } else {
885 if (verbose(tcp)) {
Dmitry V. Levin5ea97652012-05-01 20:41:40 +0000886 decode_mmsg(tcp, 0);
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000887 tprints(", ");
Dmitry V. Levine6591032010-03-29 20:45:48 +0400888 /* timeout on entrance */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000889 tprints(tcp->auxstr);
Dmitry V. Levine6591032010-03-29 20:45:48 +0400890 tcp->auxstr = NULL;
891 }
892 if (syserror(tcp))
893 return 0;
894 if (tcp->u_rval == 0) {
895 tcp->auxstr = "Timeout";
896 return RVAL_STR;
897 }
898 if (!verbose(tcp))
899 return 0;
900 /* timeout on exit */
Dmitry V. Levin2950de32015-09-18 17:44:16 +0000901 snprintf(str, sizeof(str), "left %s",
902 sprint_timespec(tcp, tcp->u_arg[4]));
Dmitry V. Levine6591032010-03-29 20:45:48 +0400903 tcp->auxstr = str;
904 return RVAL_STR;
Andreas Schwab0873f292010-02-12 21:39:12 +0100905 }
Andreas Schwab0873f292010-02-12 21:39:12 +0100906}
Andreas Schwab0873f292010-02-12 21:39:12 +0100907
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000908#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100909
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000910SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000911{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000912 printfd(tcp, tcp->u_arg[0]);
913 tprints(", ");
914 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
915
916 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917}
918
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000919SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000920{
Dmitry V. Levin15114ec2014-08-06 16:46:13 +0000921 return do_sockname(tcp, -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922}
923
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000924static void
925printpair_fd(struct tcb *tcp, const int i0, const int i1)
926{
927 tprints("[");
928 printfd(tcp, i0);
929 tprints(", ");
930 printfd(tcp, i1);
931 tprints("]");
932}
933
934static void
935decode_pair_fd(struct tcb *tcp, const long addr)
936{
937 int pair[2];
938
939 if (umove_or_printaddr(tcp, addr, &pair))
940 return;
941
942 printpair_fd(tcp, pair[0], pair[1]);
943}
944
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000945static int
946do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000947{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948 if (exiting(tcp)) {
949 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000950 printaddr(tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000951 } else {
Dmitry V. Levin78ed3f32015-03-23 00:04:27 +0000952#ifdef HAVE_GETRVAL2
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000953 if (flags_arg < 0) {
954 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
955 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956#endif
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000957 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000958 }
959 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200960 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000961 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
962 }
963 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964 return 0;
965}
966
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000967SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000968{
969 return do_pipe(tcp, -1);
970}
971
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000972SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000973{
974 return do_pipe(tcp, 1);
975}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000976
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000977SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000979 if (entering(tcp)) {
980 printxval(domains, tcp->u_arg[0], "PF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200981 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000982 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000983 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +0000985 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000986 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987 }
988 return 0;
989}
990
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000991#include "xlat/sockoptions.h"
992#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -0400993#include "xlat/getsockipoptions.h"
994#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000995#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -0400996#include "xlat/getsockipv6options.h"
997#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000998#include "xlat/sockipxoptions.h"
999#include "xlat/sockrawoptions.h"
1000#include "xlat/sockpacketoptions.h"
1001#include "xlat/socksctpoptions.h"
1002#include "xlat/socktcpoptions.h"
1003
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001004static void
Mike Frysinger54646b82015-08-19 13:29:27 -04001005print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001007 printfd(tcp, fd);
1008 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +00001009 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001010 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001011
John Hughes38ae88d2002-05-23 11:48:58 +00001012 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001013 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001014 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001015 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001016 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -04001017 printxvals(name, "IP_???", sockipoptions,
1018 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +00001019 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001020 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -04001021 printxvals(name, "IPV6_???", sockipv6options,
1022 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +00001023 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001024 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +00001025 printxval(sockipxoptions, name, "IPX_???");
1026 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001027 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +00001028 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001029 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001030 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +00001031 printxval(socktcpoptions, name, "TCP_???");
1032 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001033 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +01001034 printxval(socksctpoptions, name, "SCTP_???");
1035 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001036 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +00001037 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +00001038 break;
John Hughes38ae88d2002-05-23 11:48:58 +00001039
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001040 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +00001041
Denys Vlasenko989ebc92012-03-17 04:42:07 +01001042 default:
John Hughes38ae88d2002-05-23 11:48:58 +00001043 tprintf("%u", name);
1044 }
1045
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001046 tprints(", ");
1047}
1048
1049#ifdef SO_LINGER
1050static void
1051print_linger(struct tcb *tcp, long addr, int len)
1052{
1053 struct linger linger;
1054
1055 if (len != sizeof(linger) ||
1056 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001057 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001058 return;
1059 }
1060
1061 tprintf("{onoff=%d, linger=%d}",
1062 linger.l_onoff,
1063 linger.l_linger);
1064}
1065#endif /* SO_LINGER */
1066
1067#ifdef SO_PEERCRED
1068static void
1069print_ucred(struct tcb *tcp, long addr, int len)
1070{
1071 struct ucred uc;
1072
1073 if (len != sizeof(uc) ||
1074 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001075 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001076 } else {
1077 tprintf("{pid=%u, uid=%u, gid=%u}",
1078 (unsigned) uc.pid,
1079 (unsigned) uc.uid,
1080 (unsigned) uc.gid);
1081 }
1082}
1083#endif /* SO_PEERCRED */
1084
1085#ifdef PACKET_STATISTICS
1086static void
1087print_tpacket_stats(struct tcb *tcp, long addr, int len)
1088{
1089 struct tpacket_stats stats;
1090
1091 if (len != sizeof(stats) ||
1092 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001093 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001094 } else {
1095 tprintf("{packets=%u, drops=%u}",
1096 stats.tp_packets,
1097 stats.tp_drops);
1098 }
1099}
1100#endif /* PACKET_STATISTICS */
1101
1102#ifdef ICMP_FILTER
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001103# include "xlat/icmpfilterflags.h"
1104
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001105static void
1106print_icmp_filter(struct tcb *tcp, long addr, int len)
1107{
1108 struct icmp_filter filter;
1109
1110 if (len != sizeof(filter) ||
1111 umove(tcp, addr, &filter) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001112 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001113 return;
1114 }
1115
1116 tprints("~(");
1117 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1118 tprints(")");
1119}
1120#endif /* ICMP_FILTER */
1121
1122static void
1123print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1124{
1125 if (addr && verbose(tcp))
1126 switch (level) {
1127 case SOL_SOCKET:
1128 switch (name) {
1129#ifdef SO_LINGER
1130 case SO_LINGER:
1131 print_linger(tcp, addr, len);
1132 goto done;
1133#endif
1134#ifdef SO_PEERCRED
1135 case SO_PEERCRED:
1136 print_ucred(tcp, addr, len);
1137 goto done;
1138#endif
1139 }
1140 break;
1141
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001142 case SOL_PACKET:
1143 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001144#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001145 case PACKET_STATISTICS:
1146 print_tpacket_stats(tcp, addr, len);
1147 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001148#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001149 }
1150 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001151
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001152 case SOL_RAW:
1153 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001154#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001155 case ICMP_FILTER:
1156 print_icmp_filter(tcp, addr, len);
1157 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001158#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001159 }
1160 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001161 }
1162
John Hughes38ae88d2002-05-23 11:48:58 +00001163 /* default arg printing */
1164
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001165 if (verbose(tcp)) {
1166 if (len == sizeof(int)) {
1167 printnum_int(tcp, addr, "%d");
1168 } else {
1169 printstr(tcp, addr, len);
1170 }
1171 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001172 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +00001173 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001174done:
1175 tprintf(", [%d]", len);
1176}
1177
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001178SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001179{
1180 if (entering(tcp)) {
1181 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001182 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001183 } else {
1184 int len;
1185
1186 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1187 tprintf("%#lx, %#lx",
1188 tcp->u_arg[3], tcp->u_arg[4]);
1189 } else {
1190 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1191 tcp->u_arg[3], len);
1192 }
John Hughes38ae88d2002-05-23 11:48:58 +00001193 }
1194 return 0;
1195}
1196
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001197#ifdef IP_ADD_MEMBERSHIP
1198static void
1199print_mreq(struct tcb *tcp, long addr, unsigned int len)
1200{
1201 struct ip_mreq mreq;
1202
1203 if (len < sizeof(mreq)) {
1204 printstr(tcp, addr, len);
1205 return;
1206 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001207 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001208 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001209
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001210 tprints("{imr_multiaddr=inet_addr(");
1211 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1212 16, QUOTE_0_TERMINATED);
1213 tprints("), imr_interface=inet_addr(");
1214 print_quoted_string(inet_ntoa(mreq.imr_interface),
1215 16, QUOTE_0_TERMINATED);
1216 tprints(")}");
1217}
1218#endif /* IP_ADD_MEMBERSHIP */
1219
1220#ifdef IPV6_ADD_MEMBERSHIP
1221static void
1222print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1223{
1224 struct ipv6_mreq mreq;
1225
1226 if (len < sizeof(mreq))
1227 goto fail;
1228
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001229 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001230 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001231
1232#ifdef HAVE_INET_NTOP
1233 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1234 char address[INET6_ADDRSTRLEN];
1235
1236 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1237 goto fail;
1238
1239 tprints("{ipv6mr_multiaddr=inet_pton(");
1240 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1241 tprints("), ipv6mr_interface=");
1242 print_ifindex(mreq.ipv6mr_interface);
1243 tprints("}");
1244 return;
1245#endif /* HAVE_INET_NTOP */
1246
1247fail:
1248 printstr(tcp, addr, len);
1249}
1250#endif /* IPV6_ADD_MEMBERSHIP */
1251
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001252#ifdef MCAST_JOIN_GROUP
1253static void
1254print_group_req(struct tcb *tcp, long addr, int len)
1255{
1256 struct group_req greq;
1257
1258 if (len != sizeof(greq) ||
1259 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001260 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001261 return;
1262 }
1263
1264 union {
1265 struct sockaddr *sa;
1266 struct sockaddr_in *sin;
1267#ifdef HAVE_INET_NTOP
1268 struct sockaddr_in6 *sin6;
1269#endif
1270 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1271#ifdef HAVE_INET_NTOP
1272 char str[INET6_ADDRSTRLEN];
1273#endif
1274
1275 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1276 printxval(addrfams, a.sa->sa_family, "AF_???");
1277
1278 switch (a.sa->sa_family) {
1279 case AF_INET:
1280 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1281 ntohs(a.sin->sin_port),
1282 inet_ntoa(a.sin->sin_addr));
1283 return;
1284#ifdef HAVE_INET_NTOP
1285 case AF_INET6:
1286 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1287 break;
1288 tprintf(", sin6_port=htons(%u)"
1289 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1290 ntohs(a.sin6->sin6_port), str);
1291 return;
1292#endif /* HAVE_INET_NTOP */
1293 }
1294
1295 tprints(", sa_data=");
1296 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1297 tprintf("}}");
1298
1299}
1300#endif /* MCAST_JOIN_GROUP */
1301
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001302#ifdef PACKET_RX_RING
1303static void
1304print_tpacket_req(struct tcb *tcp, long addr, int len)
1305{
1306 struct tpacket_req req;
1307
1308 if (len != sizeof(req) ||
1309 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001310 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001311 } else {
1312 tprintf("{block_size=%u, block_nr=%u, "
1313 "frame_size=%u, frame_nr=%u}",
1314 req.tp_block_size,
1315 req.tp_block_nr,
1316 req.tp_frame_size,
1317 req.tp_frame_nr);
1318 }
1319}
1320#endif /* PACKET_RX_RING */
1321
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001322#ifdef PACKET_ADD_MEMBERSHIP
1323# include "xlat/packet_mreq_type.h"
1324
1325static void
1326print_packet_mreq(struct tcb *tcp, long addr, int len)
1327{
1328 struct packet_mreq mreq;
1329
1330 if (len != sizeof(mreq) ||
1331 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001332 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001333 } else {
1334 unsigned int i;
1335
1336 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1337 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1338 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1339 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1340 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1341 for (i = 0; i < mreq.mr_alen; ++i)
1342 tprintf("%02x", mreq.mr_address[i]);
1343 tprints("}");
1344 }
1345}
1346#endif /* PACKET_ADD_MEMBERSHIP */
1347
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001348static void
1349print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1350{
1351 if (addr && verbose(tcp))
1352 switch (level) {
1353 case SOL_SOCKET:
1354 switch (name) {
1355#ifdef SO_LINGER
1356 case SO_LINGER:
1357 print_linger(tcp, addr, len);
1358 goto done;
1359#endif
1360 }
1361 break;
1362
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001363 case SOL_IP:
1364 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001365#ifdef IP_ADD_MEMBERSHIP
1366 case IP_ADD_MEMBERSHIP:
1367 case IP_DROP_MEMBERSHIP:
1368 print_mreq(tcp, addr, len);
1369 goto done;
1370#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001371#ifdef MCAST_JOIN_GROUP
1372 case MCAST_JOIN_GROUP:
1373 case MCAST_LEAVE_GROUP:
1374 print_group_req(tcp, addr, len);
1375 goto done;
1376#endif /* MCAST_JOIN_GROUP */
1377 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +00001378 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +00001379
Dmitry V. Levin7bee4622015-06-08 14:19:46 +00001380 case SOL_IPV6:
1381 switch (name) {
1382#ifdef IPV6_ADD_MEMBERSHIP
1383 case IPV6_ADD_MEMBERSHIP:
1384 case IPV6_DROP_MEMBERSHIP:
1385# ifdef IPV6_JOIN_ANYCAST
1386 case IPV6_JOIN_ANYCAST:
1387# endif
1388# ifdef IPV6_LEAVE_ANYCAST
1389 case IPV6_LEAVE_ANYCAST:
1390# endif
1391 print_mreq6(tcp, addr, len);
1392 goto done;
1393#endif /* IPV6_ADD_MEMBERSHIP */
1394 }
1395 break;
1396
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001397 case SOL_PACKET:
1398 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001399#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001400 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001401# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001402 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001403# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001404 print_tpacket_req(tcp, addr, len);
1405 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001406#endif /* PACKET_RX_RING */
1407#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +00001408 case PACKET_ADD_MEMBERSHIP:
1409 case PACKET_DROP_MEMBERSHIP:
1410 print_packet_mreq(tcp, addr, len);
1411 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001412#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001413 }
1414 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001415
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001416 case SOL_RAW:
1417 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001418#ifdef ICMP_FILTER
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001419 case ICMP_FILTER:
1420 print_icmp_filter(tcp, addr, len);
1421 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +00001422#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001423 }
1424 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001425 }
1426
1427 /* default arg printing */
1428
1429 if (verbose(tcp)) {
1430 if (len == sizeof(int)) {
1431 printnum_int(tcp, addr, "%d");
1432 } else {
1433 printstr(tcp, addr, len);
1434 }
1435 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +00001436 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +00001437 }
1438done:
1439 tprintf(", %d", len);
1440}
1441
Dmitry V. Levina0bd3742015-04-07 01:36:50 +00001442SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001444 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -04001445 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +00001446 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1447 tcp->u_arg[3], tcp->u_arg[4]);
1448
1449 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450}