blob: 017764cc74d9d6b887405524e606047383dea159 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman7987cdf2000-07-05 16:05:39 +00005 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/stat.h>
33#include <sys/socket.h>
Dmitry V. Levinb2fa2be2014-11-21 20:46:16 +000034#include <sys/uio.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <sys/un.h>
36#include <netinet/in.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000037#ifdef HAVE_NETINET_TCP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010038# include <netinet/tcp.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000039#endif
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000040#ifdef HAVE_NETINET_UDP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010041# include <netinet/udp.h>
Wichert Akkerman8c7122c2001-02-16 19:59:55 +000042#endif
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010043#ifdef HAVE_NETINET_SCTP_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010044# include <netinet/sctp.h>
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +010045#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#include <arpa/inet.h>
Wichert Akkermanf1850652001-02-16 20:29:03 +000047#include <net/if.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048#include <asm/types.h>
Dmitry V. Levinebda41a2016-06-19 22:02:45 +000049#ifdef HAVE_NETIPX_IPX_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010050# include <netipx/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051#else
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010052# include <linux/ipx.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054
Mike Frysinger54646b82015-08-19 13:29:27 -040055#if defined(HAVE_LINUX_IP_VS_H)
56# include <linux/ip_vs.h>
57#endif
Dmitry V. Levinb10ee4e2016-06-14 13:53:47 +000058#include <linux/netlink.h>
Mike Frysinger54646b82015-08-19 13:29:27 -040059#if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
60# include <linux/netfilter_arp/arp_tables.h>
61#endif
62#if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
63# include <linux/netfilter_bridge/ebtables.h>
64#endif
65#if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
66# include <linux/netfilter_ipv4/ip_tables.h>
67#endif
68#if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
69# include <linux/netfilter_ipv6/ip6_tables.h>
70#endif
Dmitry V. Levin4f689a12016-06-15 21:35:48 +000071#include <linux/if_packet.h>
Dmitry V. Levind06010b2016-06-15 21:27:41 +000072#include <linux/icmp.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000074#include "xlat/socktypes.h"
75#include "xlat/sock_type_flags.h"
Dmitry V. Levin8a550d72008-11-10 17:21:23 +000076#ifndef SOCK_TYPE_MASK
77# define SOCK_TYPE_MASK 0xf
78#endif
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000079
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000080#include "xlat/socketlayers.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +000081
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000082#include "xlat/inet_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090083
Dmitry V. Levin94573042016-06-14 13:53:47 +000084#if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
85# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090086#endif
Dmitry V. Levin94573042016-06-14 13:53:47 +000087#include "xlat/netlink_protocols.h"
Masatake YAMATO2394a3d2014-03-11 23:37:37 +090088
Dmitry V. Levine96aee72016-06-25 13:47:54 +000089#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
90# include <bluetooth/bluetooth.h>
Lubomir Rintelc400a1c2014-10-03 11:40:28 +020091# include "xlat/bt_protocols.h"
92#endif
93
Dmitry V. Levin45ae9372016-06-23 17:38:18 +000094void
Dmitry V. Levinae280932015-06-05 20:13:21 +000095print_ifindex(unsigned int ifindex)
96{
97#ifdef HAVE_IF_INDEXTONAME
98 char buf[IFNAMSIZ + 1];
99
100 if (if_indextoname(ifindex, buf)) {
101 tprints("if_nametoindex(");
102 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
103 tprints(")");
104 return;
105 }
106#endif
107 tprintf("%u", ifindex);
108}
109
Fabien Siron2850f742016-07-06 15:49:22 +0000110static void
111decode_sockbuf(struct tcb *tcp, int fd, long addr, long addrlen)
112{
113
114 switch (verbose(tcp) ? getfdproto(tcp, fd) : SOCK_PROTO_UNKNOWN) {
115 case SOCK_PROTO_NETLINK:
116 decode_netlink(tcp, addr, addrlen);
117 break;
118 default:
119 printstr(tcp, addr, addrlen);
120 }
121}
122
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000123/*
124 * low bits of the socket type define real socket type,
125 * other bits are socket type flags.
126 */
127static void
Dmitry V. Levin9134aab2016-05-14 21:46:05 +0000128tprint_sock_type(unsigned int flags)
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000129{
130 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
131
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200132 if (str) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200133 tprints(str);
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000134 flags &= ~SOCK_TYPE_MASK;
135 if (!flags)
136 return;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200137 tprints("|");
Dmitry V. Levin8a550d72008-11-10 17:21:23 +0000138 }
139 printflags(sock_type_flags, flags, "SOCK_???");
140}
141
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000142SYS_FUNC(socket)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143{
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000144 printxval(addrfams, tcp->u_arg[0], "AF_???");
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000145 tprints(", ");
146 tprint_sock_type(tcp->u_arg[1]);
147 tprints(", ");
148 switch (tcp->u_arg[0]) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000149 case AF_INET:
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000150 case AF_INET6:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000151 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
152 break;
Dmitry V. Levineb1c22b2016-06-19 22:02:45 +0000153
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000154 case AF_NETLINK:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000155 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
156 break;
Dmitry V. Levinbc4102e2016-06-19 22:02:45 +0000157
Dmitry V. Levin43369fc2016-06-21 16:43:30 +0000158#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000159 case AF_BLUETOOTH:
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000160 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
161 break;
Lubomir Rintelc400a1c2014-10-03 11:40:28 +0200162#endif
Dmitry V. Levinbc4102e2016-06-19 22:02:45 +0000163
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000164 default:
165 tprintf("%lu", tcp->u_arg[2]);
166 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167 }
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000168
Dmitry V. Levin3d463be2015-08-02 01:41:26 +0000169 return RVAL_DECODED | RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170}
171
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000172SYS_FUNC(bind)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000174 printfd(tcp, tcp->u_arg[0]);
175 tprints(", ");
Dmitry V. Levin7acde9e2016-07-12 09:17:30 +0000176 const int addrlen = tcp->u_arg[2];
177 decode_sockaddr(tcp, tcp->u_arg[1], addrlen);
178 tprintf(", %d", addrlen);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000179
180 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181}
182
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000183SYS_FUNC(listen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000185 printfd(tcp, tcp->u_arg[0]);
186 tprints(", ");
187 tprintf("%lu", tcp->u_arg[1]);
188
189 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190}
191
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000192static bool
193fetch_socklen(struct tcb *tcp, int *plen,
194 const unsigned long sockaddr, const unsigned long socklen)
195{
196 return verbose(tcp) && sockaddr && socklen
197 && umove(tcp, socklen, plen) == 0;
198}
199
Paolo Bonzini705ff102009-08-14 12:34:05 +0200200static int
Dmitry V. Levind1cedf02016-07-09 21:52:34 +0000201decode_sockname(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202{
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000203 int ulen, rlen;
204
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800206 printfd(tcp, tcp->u_arg[0]);
207 tprints(", ");
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000208 if (fetch_socklen(tcp, &ulen, tcp->u_arg[1], tcp->u_arg[2])) {
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000209 set_tcb_priv_ulong(tcp, ulen);
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000210 return 0;
211 } else {
212 printaddr(tcp->u_arg[1]);
213 tprints(", ");
214 printaddr(tcp->u_arg[2]);
215 return RVAL_DECODED;
216 }
Paolo Bonzini705ff102009-08-14 12:34:05 +0200217 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000218
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000219 ulen = get_tcb_priv_ulong(tcp);
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000220
221 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &rlen) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000222 printaddr(tcp->u_arg[1]);
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000223 tprintf(", [%d]", ulen);
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000224 } else {
Dmitry V. Levind07eac32016-07-09 21:52:43 +0000225 decode_sockaddr(tcp, tcp->u_arg[1], ulen > rlen ? rlen : ulen);
Dmitry V. Levineca8b5b2016-07-09 21:52:58 +0000226 if (ulen != rlen)
Dmitry V. Levin36df8222016-07-09 21:52:51 +0000227 tprintf(", [%d->%d]", ulen, rlen);
228 else
229 tprintf(", [%d]", rlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000231
Dmitry V. Levind1cedf02016-07-09 21:52:34 +0000232 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233}
234
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000235SYS_FUNC(accept)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200236{
Dmitry V. Levind1cedf02016-07-09 21:52:34 +0000237 return decode_sockname(tcp) | RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200238}
239
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000240SYS_FUNC(accept4)
Paolo Bonzini705ff102009-08-14 12:34:05 +0200241{
Dmitry V. Levind1cedf02016-07-09 21:52:34 +0000242 int rc = decode_sockname(tcp);
243
244 if (rc & RVAL_DECODED) {
245 tprints(", ");
246 printflags(sock_type_flags, tcp->u_arg[3], "SOCK_???");
247 }
248
249 return rc | RVAL_FD;
Paolo Bonzini705ff102009-08-14 12:34:05 +0200250}
Paolo Bonzini705ff102009-08-14 12:34:05 +0200251
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000252SYS_FUNC(send)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000254 printfd(tcp, tcp->u_arg[0]);
255 tprints(", ");
Fabien Siron2850f742016-07-06 15:49:22 +0000256 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000257 tprintf(", %lu, ", tcp->u_arg[2]);
258 /* flags */
259 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
260
261 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262}
263
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000264SYS_FUNC(sendto)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000266 printfd(tcp, tcp->u_arg[0]);
267 tprints(", ");
Fabien Siron2850f742016-07-06 15:49:22 +0000268 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000269 tprintf(", %lu, ", tcp->u_arg[2]);
270 /* flags */
271 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
272 /* to address */
Dmitry V. Levin7acde9e2016-07-12 09:17:30 +0000273 const int addrlen = tcp->u_arg[5];
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000274 tprints(", ");
Dmitry V. Levin7acde9e2016-07-12 09:17:30 +0000275 decode_sockaddr(tcp, tcp->u_arg[4], addrlen);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000276 /* to length */
Dmitry V. Levin7acde9e2016-07-12 09:17:30 +0000277 tprintf(", %d", addrlen);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000278
279 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280}
281
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000282SYS_FUNC(recv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283{
284 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800285 printfd(tcp, tcp->u_arg[0]);
286 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287 } else {
Fabien Siron2850f742016-07-06 15:49:22 +0000288 if (syserror(tcp)) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000289 printaddr(tcp->u_arg[1]);
Fabien Siron2850f742016-07-06 15:49:22 +0000290 } else {
291 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1],
292 tcp->u_rval);
293 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294
295 tprintf(", %lu, ", tcp->u_arg[2]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000296 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000297 }
298 return 0;
299}
300
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000301SYS_FUNC(recvfrom)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302{
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000303 int ulen, rlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304
305 if (entering(tcp)) {
Philippe Ombredanne894c7e32014-02-01 09:57:45 -0800306 printfd(tcp, tcp->u_arg[0]);
307 tprints(", ");
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000308 if (fetch_socklen(tcp, &ulen, tcp->u_arg[4], tcp->u_arg[5])) {
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000309 set_tcb_priv_ulong(tcp, ulen);
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000310 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312 /* buf */
Denys Vlasenko383386d2015-07-30 13:29:20 +0200313 if (syserror(tcp)) {
Dmitry V. Levin52dc1502015-07-30 13:53:42 +0000314 printaddr(tcp->u_arg[1]);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200315 } else {
Fabien Siron2850f742016-07-06 15:49:22 +0000316 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1],
317 tcp->u_rval);
Denys Vlasenko383386d2015-07-30 13:29:20 +0200318 }
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000319 /* size */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320 tprintf(", %lu, ", tcp->u_arg[2]);
321 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000322 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200323 tprints(", ");
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000324
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000325 ulen = get_tcb_priv_ulong(tcp);
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000326
327 if (!fetch_socklen(tcp, &rlen, tcp->u_arg[4], tcp->u_arg[5])) {
328 /* from address */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000329 printaddr(tcp->u_arg[4]);
330 tprints(", ");
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000331 /* from length */
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000332 printaddr(tcp->u_arg[5]);
333 return 0;
334 }
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000335 if (syserror(tcp)) {
336 /* from address */
337 printaddr(tcp->u_arg[4]);
338 /* from length */
339 tprintf(", [%d]", ulen);
340 return 0;
341 }
Denys Vlasenko383386d2015-07-30 13:29:20 +0200342 /* from address */
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000343 decode_sockaddr(tcp, tcp->u_arg[4], ulen > rlen ? rlen : ulen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344 /* from length */
Dmitry V. Levin802f2642016-07-12 07:46:19 +0000345 if (ulen != rlen)
346 tprintf(", [%d->%d]", ulen, rlen);
347 else
348 tprintf(", [%d]", rlen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000349 }
350 return 0;
351}
352
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000353#include "xlat/shutdown_modes.h"
Sebastian Pipping9cd38502011-03-03 01:12:25 +0100354
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000355SYS_FUNC(shutdown)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000357 printfd(tcp, tcp->u_arg[0]);
358 tprints(", ");
359 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
360
361 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362}
363
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000364SYS_FUNC(getsockname)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365{
Dmitry V. Levind1cedf02016-07-09 21:52:34 +0000366 return decode_sockname(tcp);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367}
368
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000369static void
370printpair_fd(struct tcb *tcp, const int i0, const int i1)
371{
372 tprints("[");
373 printfd(tcp, i0);
374 tprints(", ");
375 printfd(tcp, i1);
376 tprints("]");
377}
378
379static void
380decode_pair_fd(struct tcb *tcp, const long addr)
381{
382 int pair[2];
383
384 if (umove_or_printaddr(tcp, addr, &pair))
385 return;
386
387 printpair_fd(tcp, pair[0], pair[1]);
388}
389
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000390static int
391do_pipe(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393 if (exiting(tcp)) {
Dmitry V. Levin9b388852016-02-12 16:37:31 +0000394 decode_pair_fd(tcp, tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000395 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200396 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000397 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
398 }
399 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400 return 0;
401}
402
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000403SYS_FUNC(pipe)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000404{
Dmitry V. Levin9b388852016-02-12 16:37:31 +0000405#ifdef HAVE_GETRVAL2
406 if (exiting(tcp) && !syserror(tcp))
407 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
408 return 0;
409#else
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000410 return do_pipe(tcp, -1);
Dmitry V. Levin9b388852016-02-12 16:37:31 +0000411#endif
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000412}
413
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000414SYS_FUNC(pipe2)
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000415{
416 return do_pipe(tcp, 1);
417}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000418
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000419SYS_FUNC(socketpair)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421 if (entering(tcp)) {
Dmitry V. Levin71fe62e2016-04-04 01:35:28 +0000422 printxval(addrfams, tcp->u_arg[0], "AF_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200423 tprints(", ");
Dmitry V. Levin1e42f2d2014-09-10 17:48:28 +0000424 tprint_sock_type(tcp->u_arg[1]);
Dmitry V. Levin033fb912014-03-11 22:50:39 +0000425 tprintf(", %lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426 } else {
Dmitry V. Levinb6795082015-07-06 22:33:39 +0000427 tprints(", ");
Dmitry V. Levin2a4f0522015-08-02 01:54:48 +0000428 decode_pair_fd(tcp, tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429 }
430 return 0;
431}
432
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000433#include "xlat/sockoptions.h"
434#include "xlat/sockipoptions.h"
Mike Frysinger54646b82015-08-19 13:29:27 -0400435#include "xlat/getsockipoptions.h"
436#include "xlat/setsockipoptions.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000437#include "xlat/sockipv6options.h"
Mike Frysinger54646b82015-08-19 13:29:27 -0400438#include "xlat/getsockipv6options.h"
439#include "xlat/setsockipv6options.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000440#include "xlat/sockipxoptions.h"
441#include "xlat/sockrawoptions.h"
442#include "xlat/sockpacketoptions.h"
443#include "xlat/socksctpoptions.h"
444#include "xlat/socktcpoptions.h"
445
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000446static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +0000447print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
448 unsigned int name, bool is_getsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449{
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000450 printfd(tcp, fd);
451 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +0000452 printxval(socketlayers, level, "SOL_??");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200453 tprints(", ");
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000454
John Hughes38ae88d2002-05-23 11:48:58 +0000455 switch (level) {
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100456 case SOL_SOCKET:
John Hughes38ae88d2002-05-23 11:48:58 +0000457 printxval(sockoptions, name, "SO_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000458 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100459 case SOL_IP:
Mike Frysinger54646b82015-08-19 13:29:27 -0400460 printxvals(name, "IP_???", sockipoptions,
461 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
John Hughes38ae88d2002-05-23 11:48:58 +0000462 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100463 case SOL_IPV6:
Mike Frysinger54646b82015-08-19 13:29:27 -0400464 printxvals(name, "IPV6_???", sockipv6options,
465 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
Roland McGrath4f6ba692004-08-31 07:01:26 +0000466 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100467 case SOL_IPX:
John Hughes38ae88d2002-05-23 11:48:58 +0000468 printxval(sockipxoptions, name, "IPX_???");
469 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100470 case SOL_PACKET:
John Hughes38ae88d2002-05-23 11:48:58 +0000471 printxval(sockpacketoptions, name, "PACKET_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000472 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100473 case SOL_TCP:
John Hughes38ae88d2002-05-23 11:48:58 +0000474 printxval(socktcpoptions, name, "TCP_???");
475 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100476 case SOL_SCTP:
Holger Hans Peter Freyther7fea79b2011-01-14 11:08:12 +0100477 printxval(socksctpoptions, name, "SCTP_???");
478 break;
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100479 case SOL_RAW:
John Hughes38ae88d2002-05-23 11:48:58 +0000480 printxval(sockrawoptions, name, "RAW_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000481 break;
John Hughes38ae88d2002-05-23 11:48:58 +0000482
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000483 /* Other SOL_* protocol levels still need work. */
John Hughes38ae88d2002-05-23 11:48:58 +0000484
Denys Vlasenko989ebc92012-03-17 04:42:07 +0100485 default:
John Hughes38ae88d2002-05-23 11:48:58 +0000486 tprintf("%u", name);
487 }
488
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000489 tprints(", ");
490}
491
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000492static void
493print_linger(struct tcb *tcp, long addr, int len)
494{
495 struct linger linger;
496
497 if (len != sizeof(linger) ||
498 umove(tcp, addr, &linger) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000499 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000500 return;
501 }
502
503 tprintf("{onoff=%d, linger=%d}",
504 linger.l_onoff,
505 linger.l_linger);
506}
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000507
508#ifdef SO_PEERCRED
509static void
510print_ucred(struct tcb *tcp, long addr, int len)
511{
512 struct ucred uc;
513
514 if (len != sizeof(uc) ||
515 umove(tcp, addr, &uc) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000516 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000517 } else {
518 tprintf("{pid=%u, uid=%u, gid=%u}",
519 (unsigned) uc.pid,
520 (unsigned) uc.uid,
521 (unsigned) uc.gid);
522 }
523}
524#endif /* SO_PEERCRED */
525
526#ifdef PACKET_STATISTICS
527static void
528print_tpacket_stats(struct tcb *tcp, long addr, int len)
529{
530 struct tpacket_stats stats;
531
532 if (len != sizeof(stats) ||
533 umove(tcp, addr, &stats) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000534 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000535 } else {
536 tprintf("{packets=%u, drops=%u}",
537 stats.tp_packets,
538 stats.tp_drops);
539 }
540}
541#endif /* PACKET_STATISTICS */
542
Dmitry V. Levinfba9db22016-06-15 21:29:07 +0000543#include "xlat/icmpfilterflags.h"
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000544
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000545static void
Dmitry V. Levineb5c2332016-05-06 00:06:15 +0000546print_icmp_filter(struct tcb *tcp, const long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000547{
Dmitry V. Levineb5c2332016-05-06 00:06:15 +0000548 struct icmp_filter filter = {};
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000549
Dmitry V. Levineb5c2332016-05-06 00:06:15 +0000550 if (len > (int) sizeof(filter))
551 len = sizeof(filter);
552 else if (len <= 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000553 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000554 return;
555 }
556
Dmitry V. Levineb5c2332016-05-06 00:06:15 +0000557 if (umoven_or_printaddr(tcp, addr, len, &filter))
558 return;
559
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000560 tprints("~(");
561 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
562 tprints(")");
563}
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000564
565static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +0000566print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
567 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000568{
569 if (addr && verbose(tcp))
570 switch (level) {
571 case SOL_SOCKET:
572 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000573 case SO_LINGER:
574 print_linger(tcp, addr, len);
575 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000576#ifdef SO_PEERCRED
577 case SO_PEERCRED:
578 print_ucred(tcp, addr, len);
579 goto done;
580#endif
581 }
582 break;
583
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000584 case SOL_PACKET:
585 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000586#ifdef PACKET_STATISTICS
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000587 case PACKET_STATISTICS:
588 print_tpacket_stats(tcp, addr, len);
589 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000590#endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000591 }
592 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000593
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000594 case SOL_RAW:
595 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000596 case ICMP_FILTER:
597 print_icmp_filter(tcp, addr, len);
598 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000599 }
600 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000601 }
602
John Hughes38ae88d2002-05-23 11:48:58 +0000603 /* default arg printing */
604
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000605 if (verbose(tcp)) {
606 if (len == sizeof(int)) {
607 printnum_int(tcp, addr, "%d");
608 } else {
609 printstr(tcp, addr, len);
610 }
611 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000612 printaddr(addr);
John Hughes38ae88d2002-05-23 11:48:58 +0000613 }
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000614done:
615 tprintf(", [%d]", len);
616}
617
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000618SYS_FUNC(getsockopt)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000619{
620 if (entering(tcp)) {
621 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -0400622 tcp->u_arg[1], tcp->u_arg[2], true);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000623 } else {
624 int len;
625
626 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
Dmitry V. Levin484326d2016-06-11 01:28:21 +0000627 printaddr(tcp->u_arg[3]);
628 tprints(", ");
629 printaddr(tcp->u_arg[4]);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000630 } else {
631 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
632 tcp->u_arg[3], len);
633 }
John Hughes38ae88d2002-05-23 11:48:58 +0000634 }
635 return 0;
636}
637
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000638#ifdef IP_ADD_MEMBERSHIP
639static void
640print_mreq(struct tcb *tcp, long addr, unsigned int len)
641{
642 struct ip_mreq mreq;
643
644 if (len < sizeof(mreq)) {
645 printstr(tcp, addr, len);
646 return;
647 }
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000648 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000649 return;
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000650
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000651 tprints("{imr_multiaddr=inet_addr(");
652 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
653 16, QUOTE_0_TERMINATED);
654 tprints("), imr_interface=inet_addr(");
655 print_quoted_string(inet_ntoa(mreq.imr_interface),
656 16, QUOTE_0_TERMINATED);
657 tprints(")}");
658}
659#endif /* IP_ADD_MEMBERSHIP */
660
661#ifdef IPV6_ADD_MEMBERSHIP
662static void
663print_mreq6(struct tcb *tcp, long addr, unsigned int len)
664{
665 struct ipv6_mreq mreq;
666
667 if (len < sizeof(mreq))
668 goto fail;
669
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000670 if (umove_or_printaddr(tcp, addr, &mreq))
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000671 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000672
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000673 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
674 char address[INET6_ADDRSTRLEN];
675
676 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
677 goto fail;
678
679 tprints("{ipv6mr_multiaddr=inet_pton(");
680 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
681 tprints("), ipv6mr_interface=");
682 print_ifindex(mreq.ipv6mr_interface);
683 tprints("}");
684 return;
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000685
686fail:
687 printstr(tcp, addr, len);
688}
689#endif /* IPV6_ADD_MEMBERSHIP */
690
Dmitry V. Levina0a49092015-01-30 01:55:20 +0000691#ifdef MCAST_JOIN_GROUP
692static void
693print_group_req(struct tcb *tcp, long addr, int len)
694{
695 struct group_req greq;
696
697 if (len != sizeof(greq) ||
698 umove(tcp, addr, &greq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000699 printaddr(addr);
Dmitry V. Levina0a49092015-01-30 01:55:20 +0000700 return;
701 }
702
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000703 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
Dmitry V. Levin3bf9c192016-06-21 16:45:40 +0000704 print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group));
Dmitry V. Levin1019f002015-11-21 02:38:59 +0000705 tprintf("}");
Dmitry V. Levina0a49092015-01-30 01:55:20 +0000706
707}
708#endif /* MCAST_JOIN_GROUP */
709
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000710#ifdef PACKET_RX_RING
711static void
712print_tpacket_req(struct tcb *tcp, long addr, int len)
713{
714 struct tpacket_req req;
715
716 if (len != sizeof(req) ||
717 umove(tcp, addr, &req) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000718 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000719 } else {
720 tprintf("{block_size=%u, block_nr=%u, "
721 "frame_size=%u, frame_nr=%u}",
722 req.tp_block_size,
723 req.tp_block_nr,
724 req.tp_frame_size,
725 req.tp_frame_nr);
726 }
727}
728#endif /* PACKET_RX_RING */
729
Dmitry V. Levin02f2f092015-01-29 03:26:53 +0000730#ifdef PACKET_ADD_MEMBERSHIP
731# include "xlat/packet_mreq_type.h"
732
733static void
734print_packet_mreq(struct tcb *tcp, long addr, int len)
735{
736 struct packet_mreq mreq;
737
738 if (len != sizeof(mreq) ||
739 umove(tcp, addr, &mreq) < 0) {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000740 printaddr(addr);
Dmitry V. Levin02f2f092015-01-29 03:26:53 +0000741 } else {
742 unsigned int i;
743
744 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
745 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
746 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
747 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
748 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
749 for (i = 0; i < mreq.mr_alen; ++i)
750 tprintf("%02x", mreq.mr_address[i]);
751 tprints("}");
752 }
753}
754#endif /* PACKET_ADD_MEMBERSHIP */
755
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000756static void
Dmitry V. Levinf40ea792016-04-01 01:03:20 +0000757print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
758 long addr, int len)
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000759{
760 if (addr && verbose(tcp))
761 switch (level) {
762 case SOL_SOCKET:
763 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000764 case SO_LINGER:
765 print_linger(tcp, addr, len);
766 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000767 }
768 break;
769
Dmitry V. Levina0a49092015-01-30 01:55:20 +0000770 case SOL_IP:
771 switch (name) {
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000772#ifdef IP_ADD_MEMBERSHIP
773 case IP_ADD_MEMBERSHIP:
774 case IP_DROP_MEMBERSHIP:
775 print_mreq(tcp, addr, len);
776 goto done;
777#endif /* IP_ADD_MEMBERSHIP */
Dmitry V. Levina0a49092015-01-30 01:55:20 +0000778#ifdef MCAST_JOIN_GROUP
779 case MCAST_JOIN_GROUP:
780 case MCAST_LEAVE_GROUP:
781 print_group_req(tcp, addr, len);
782 goto done;
783#endif /* MCAST_JOIN_GROUP */
784 }
Dmitry V. Levin3910d0f2015-02-08 01:19:06 +0000785 break;
Dmitry V. Levina0a49092015-01-30 01:55:20 +0000786
Dmitry V. Levin7bee4622015-06-08 14:19:46 +0000787 case SOL_IPV6:
788 switch (name) {
789#ifdef IPV6_ADD_MEMBERSHIP
790 case IPV6_ADD_MEMBERSHIP:
791 case IPV6_DROP_MEMBERSHIP:
792# ifdef IPV6_JOIN_ANYCAST
793 case IPV6_JOIN_ANYCAST:
794# endif
795# ifdef IPV6_LEAVE_ANYCAST
796 case IPV6_LEAVE_ANYCAST:
797# endif
798 print_mreq6(tcp, addr, len);
799 goto done;
800#endif /* IPV6_ADD_MEMBERSHIP */
801 }
802 break;
803
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000804 case SOL_PACKET:
805 switch (name) {
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000806#ifdef PACKET_RX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000807 case PACKET_RX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000808# ifdef PACKET_TX_RING
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000809 case PACKET_TX_RING:
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000810# endif
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000811 print_tpacket_req(tcp, addr, len);
812 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000813#endif /* PACKET_RX_RING */
814#ifdef PACKET_ADD_MEMBERSHIP
Dmitry V. Levin02f2f092015-01-29 03:26:53 +0000815 case PACKET_ADD_MEMBERSHIP:
816 case PACKET_DROP_MEMBERSHIP:
817 print_packet_mreq(tcp, addr, len);
818 goto done;
Dmitry V. Levin6d31c7a2015-01-29 04:42:37 +0000819#endif /* PACKET_ADD_MEMBERSHIP */
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000820 }
821 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000822
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000823 case SOL_RAW:
824 switch (name) {
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000825 case ICMP_FILTER:
826 print_icmp_filter(tcp, addr, len);
827 goto done;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000828 }
829 break;
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000830 }
831
832 /* default arg printing */
833
834 if (verbose(tcp)) {
835 if (len == sizeof(int)) {
836 printnum_int(tcp, addr, "%d");
837 } else {
838 printstr(tcp, addr, len);
839 }
840 } else {
Dmitry V. Levin6c277da2015-07-19 22:36:46 +0000841 printaddr(addr);
Dmitry V. Levin0509c8e2015-01-29 03:11:41 +0000842 }
843done:
844 tprintf(", %d", len);
845}
846
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000847SYS_FUNC(setsockopt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000848{
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000849 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
Mike Frysinger54646b82015-08-19 13:29:27 -0400850 tcp->u_arg[1], tcp->u_arg[2], false);
Dmitry V. Levin219b3a72015-07-19 22:52:47 +0000851 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
852 tcp->u_arg[3], tcp->u_arg[4]);
853
854 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855}