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>
5 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
33 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #ifdef HAVE_NETINET_TCP_H
38 # include <netinet/tcp.h>
40 #ifdef HAVE_NETINET_UDP_H
41 # include <netinet/udp.h>
43 #ifdef HAVE_NETINET_SCTP_H
44 # include <netinet/sctp.h>
46 #include <arpa/inet.h>
48 #include <asm/types.h>
49 #ifdef HAVE_NETIPX_IPX_H
50 # include <netipx/ipx.h>
52 # include <linux/ipx.h>
55 #if defined(HAVE_LINUX_IP_VS_H)
56 # include <linux/ip_vs.h>
58 #include <linux/netlink.h>
59 #if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
60 # include <linux/netfilter_arp/arp_tables.h>
62 #if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
63 # include <linux/netfilter_bridge/ebtables.h>
65 #if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
66 # include <linux/netfilter_ipv4/ip_tables.h>
68 #if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
69 # include <linux/netfilter_ipv6/ip6_tables.h>
71 #include <linux/if_packet.h>
72 #include <linux/icmp.h>
74 #include "xlat/socktypes.h"
75 #include "xlat/sock_type_flags.h"
76 #ifndef SOCK_TYPE_MASK
77 # define SOCK_TYPE_MASK 0xf
80 #include "xlat/socketlayers.h"
82 #include "xlat/inet_protocols.h"
83 #include "xlat/netlink_protocols.h"
85 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
86 # include <bluetooth/bluetooth.h>
87 # include "xlat/bt_protocols.h"
91 print_ifindex(unsigned int ifindex)
93 #ifdef HAVE_IF_INDEXTONAME
94 char buf[IFNAMSIZ + 1];
96 if (if_indextoname(ifindex, buf)) {
97 tprints("if_nametoindex(");
98 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
103 tprintf("%u", ifindex);
107 decode_sockbuf(struct tcb *tcp, int fd, long addr, long addrlen)
110 switch (verbose(tcp) ? getfdproto(tcp, fd) : SOCK_PROTO_UNKNOWN) {
111 case SOCK_PROTO_NETLINK:
112 decode_netlink(tcp, addr, addrlen);
115 printstr(tcp, addr, addrlen);
120 * low bits of the socket type define real socket type,
121 * other bits are socket type flags.
124 tprint_sock_type(unsigned int flags)
126 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
130 flags &= ~SOCK_TYPE_MASK;
135 printflags(sock_type_flags, flags, "SOCK_???");
140 printxval(addrfams, tcp->u_arg[0], "AF_???");
142 tprint_sock_type(tcp->u_arg[1]);
144 switch (tcp->u_arg[0]) {
147 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
151 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
154 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
156 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
161 tprintf("%lu", tcp->u_arg[2]);
165 return RVAL_DECODED | RVAL_FD;
170 printfd(tcp, tcp->u_arg[0]);
172 const int addrlen = tcp->u_arg[2];
173 decode_sockaddr(tcp, tcp->u_arg[1], addrlen);
174 tprintf(", %d", addrlen);
181 printfd(tcp, tcp->u_arg[0]);
183 tprintf("%lu", tcp->u_arg[1]);
189 fetch_socklen(struct tcb *const tcp, int *const plen,
190 const kernel_ureg_t sockaddr, const kernel_ureg_t socklen)
192 return verbose(tcp) && sockaddr && socklen
193 && umove(tcp, socklen, plen) == 0;
197 decode_sockname(struct tcb *tcp)
202 printfd(tcp, tcp->u_arg[0]);
204 if (fetch_socklen(tcp, &ulen, tcp->u_arg[1], tcp->u_arg[2])) {
205 set_tcb_priv_ulong(tcp, ulen);
208 printaddr(tcp->u_arg[1]);
210 printaddr(tcp->u_arg[2]);
215 ulen = get_tcb_priv_ulong(tcp);
217 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &rlen) < 0) {
218 printaddr(tcp->u_arg[1]);
219 tprintf(", [%d]", ulen);
221 decode_sockaddr(tcp, tcp->u_arg[1], ulen > rlen ? rlen : ulen);
223 tprintf(", [%d->%d]", ulen, rlen);
225 tprintf(", [%d]", rlen);
233 return decode_sockname(tcp) | RVAL_FD;
238 int rc = decode_sockname(tcp);
240 if (rc & RVAL_DECODED) {
242 printflags(sock_type_flags, tcp->u_arg[3], "SOCK_???");
250 printfd(tcp, tcp->u_arg[0]);
252 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
253 tprintf(", %lu, ", tcp->u_arg[2]);
255 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
262 printfd(tcp, tcp->u_arg[0]);
264 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
265 tprintf(", %lu, ", tcp->u_arg[2]);
267 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
269 const int addrlen = tcp->u_arg[5];
271 decode_sockaddr(tcp, tcp->u_arg[4], addrlen);
273 tprintf(", %d", addrlen);
281 printfd(tcp, tcp->u_arg[0]);
285 printaddr(tcp->u_arg[1]);
287 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1],
291 tprintf(", %lu, ", tcp->u_arg[2]);
292 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
302 printfd(tcp, tcp->u_arg[0]);
304 if (fetch_socklen(tcp, &ulen, tcp->u_arg[4], tcp->u_arg[5])) {
305 set_tcb_priv_ulong(tcp, ulen);
310 printaddr(tcp->u_arg[1]);
312 decode_sockbuf(tcp, tcp->u_arg[0], tcp->u_arg[1],
316 tprintf(", %lu, ", tcp->u_arg[2]);
318 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
321 ulen = get_tcb_priv_ulong(tcp);
323 if (!fetch_socklen(tcp, &rlen, tcp->u_arg[4], tcp->u_arg[5])) {
325 printaddr(tcp->u_arg[4]);
328 printaddr(tcp->u_arg[5]);
333 printaddr(tcp->u_arg[4]);
335 tprintf(", [%d]", ulen);
339 decode_sockaddr(tcp, tcp->u_arg[4], ulen > rlen ? rlen : ulen);
342 tprintf(", [%d->%d]", ulen, rlen);
344 tprintf(", [%d]", rlen);
349 #include "xlat/shutdown_modes.h"
353 printfd(tcp, tcp->u_arg[0]);
355 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
360 SYS_FUNC(getsockname)
362 return decode_sockname(tcp);
366 printpair_fd(struct tcb *tcp, const int i0, const int i1)
376 decode_pair_fd(struct tcb *tcp, const long addr)
380 if (umove_or_printaddr(tcp, addr, &pair))
383 printpair_fd(tcp, pair[0], pair[1]);
387 do_pipe(struct tcb *tcp, int flags_arg)
390 decode_pair_fd(tcp, tcp->u_arg[0]);
391 if (flags_arg >= 0) {
393 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
402 if (exiting(tcp) && !syserror(tcp))
403 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
406 return do_pipe(tcp, -1);
412 return do_pipe(tcp, 1);
418 printxval(addrfams, tcp->u_arg[0], "AF_???");
420 tprint_sock_type(tcp->u_arg[1]);
421 tprintf(", %lu", tcp->u_arg[2]);
424 decode_pair_fd(tcp, tcp->u_arg[3]);
429 #include "xlat/sockoptions.h"
430 #include "xlat/sockipoptions.h"
431 #include "xlat/getsockipoptions.h"
432 #include "xlat/setsockipoptions.h"
433 #include "xlat/sockipv6options.h"
434 #include "xlat/getsockipv6options.h"
435 #include "xlat/setsockipv6options.h"
436 #include "xlat/sockipxoptions.h"
437 #include "xlat/sockrawoptions.h"
438 #include "xlat/sockpacketoptions.h"
439 #include "xlat/socksctpoptions.h"
440 #include "xlat/socktcpoptions.h"
443 print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
444 unsigned int name, bool is_getsockopt)
448 printxval(socketlayers, level, "SOL_??");
453 printxval(sockoptions, name, "SO_???");
456 printxvals(name, "IP_???", sockipoptions,
457 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
460 printxvals(name, "IPV6_???", sockipv6options,
461 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
464 printxval(sockipxoptions, name, "IPX_???");
467 printxval(sockpacketoptions, name, "PACKET_???");
470 printxval(socktcpoptions, name, "TCP_???");
473 printxval(socksctpoptions, name, "SCTP_???");
476 printxval(sockrawoptions, name, "RAW_???");
479 /* Other SOL_* protocol levels still need work. */
489 print_linger(struct tcb *tcp, long addr, int len)
491 struct linger linger;
493 if (len != sizeof(linger) ||
494 umove(tcp, addr, &linger) < 0) {
499 tprintf("{onoff=%d, linger=%d}",
506 print_ucred(struct tcb *tcp, long addr, int len)
510 if (len != sizeof(uc) ||
511 umove(tcp, addr, &uc) < 0) {
514 tprintf("{pid=%u, uid=%u, gid=%u}",
520 #endif /* SO_PEERCRED */
522 #ifdef PACKET_STATISTICS
524 print_tpacket_stats(struct tcb *tcp, long addr, int len)
526 struct tpacket_stats stats;
528 if (len != sizeof(stats) ||
529 umove(tcp, addr, &stats) < 0) {
532 tprintf("{packets=%u, drops=%u}",
537 #endif /* PACKET_STATISTICS */
539 #include "xlat/icmpfilterflags.h"
542 print_icmp_filter(struct tcb *tcp, const long addr, int len)
544 struct icmp_filter filter = {};
546 if (len > (int) sizeof(filter))
547 len = sizeof(filter);
553 if (umoven_or_printaddr(tcp, addr, len, &filter))
557 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
562 print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
565 if (addr && verbose(tcp))
570 print_linger(tcp, addr, len);
574 print_ucred(tcp, addr, len);
582 #ifdef PACKET_STATISTICS
583 case PACKET_STATISTICS:
584 print_tpacket_stats(tcp, addr, len);
593 print_icmp_filter(tcp, addr, len);
599 /* default arg printing */
602 if (len == sizeof(int)) {
603 printnum_int(tcp, addr, "%d");
605 printstr(tcp, addr, len);
611 tprintf(", [%d]", len);
617 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
618 tcp->u_arg[1], tcp->u_arg[2], true);
622 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
623 printaddr(tcp->u_arg[3]);
625 printaddr(tcp->u_arg[4]);
627 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
634 #ifdef IP_ADD_MEMBERSHIP
636 print_mreq(struct tcb *tcp, long addr, unsigned int len)
640 if (len < sizeof(mreq)) {
641 printstr(tcp, addr, len);
644 if (umove_or_printaddr(tcp, addr, &mreq))
647 tprints("{imr_multiaddr=inet_addr(");
648 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
649 16, QUOTE_0_TERMINATED);
650 tprints("), imr_interface=inet_addr(");
651 print_quoted_string(inet_ntoa(mreq.imr_interface),
652 16, QUOTE_0_TERMINATED);
655 #endif /* IP_ADD_MEMBERSHIP */
657 #ifdef IPV6_ADD_MEMBERSHIP
659 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
661 struct ipv6_mreq mreq;
663 if (len < sizeof(mreq))
666 if (umove_or_printaddr(tcp, addr, &mreq))
669 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
670 char address[INET6_ADDRSTRLEN];
672 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
675 tprints("{ipv6mr_multiaddr=inet_pton(");
676 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
677 tprints("), ipv6mr_interface=");
678 print_ifindex(mreq.ipv6mr_interface);
683 printstr(tcp, addr, len);
685 #endif /* IPV6_ADD_MEMBERSHIP */
687 #ifdef MCAST_JOIN_GROUP
689 print_group_req(struct tcb *tcp, long addr, int len)
691 struct group_req greq;
693 if (len != sizeof(greq) ||
694 umove(tcp, addr, &greq) < 0) {
699 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
700 print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group));
704 #endif /* MCAST_JOIN_GROUP */
706 #ifdef PACKET_RX_RING
708 print_tpacket_req(struct tcb *tcp, long addr, int len)
710 struct tpacket_req req;
712 if (len != sizeof(req) ||
713 umove(tcp, addr, &req) < 0) {
716 tprintf("{block_size=%u, block_nr=%u, "
717 "frame_size=%u, frame_nr=%u}",
724 #endif /* PACKET_RX_RING */
726 #ifdef PACKET_ADD_MEMBERSHIP
727 # include "xlat/packet_mreq_type.h"
730 print_packet_mreq(struct tcb *tcp, long addr, int len)
732 struct packet_mreq mreq;
734 if (len != sizeof(mreq) ||
735 umove(tcp, addr, &mreq) < 0) {
740 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
741 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
742 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
743 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
744 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
745 for (i = 0; i < mreq.mr_alen; ++i)
746 tprintf("%02x", mreq.mr_address[i]);
750 #endif /* PACKET_ADD_MEMBERSHIP */
753 print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
756 if (addr && verbose(tcp))
761 print_linger(tcp, addr, len);
768 #ifdef IP_ADD_MEMBERSHIP
769 case IP_ADD_MEMBERSHIP:
770 case IP_DROP_MEMBERSHIP:
771 print_mreq(tcp, addr, len);
773 #endif /* IP_ADD_MEMBERSHIP */
774 #ifdef MCAST_JOIN_GROUP
775 case MCAST_JOIN_GROUP:
776 case MCAST_LEAVE_GROUP:
777 print_group_req(tcp, addr, len);
779 #endif /* MCAST_JOIN_GROUP */
785 #ifdef IPV6_ADD_MEMBERSHIP
786 case IPV6_ADD_MEMBERSHIP:
787 case IPV6_DROP_MEMBERSHIP:
788 # ifdef IPV6_JOIN_ANYCAST
789 case IPV6_JOIN_ANYCAST:
791 # ifdef IPV6_LEAVE_ANYCAST
792 case IPV6_LEAVE_ANYCAST:
794 print_mreq6(tcp, addr, len);
796 #endif /* IPV6_ADD_MEMBERSHIP */
802 #ifdef PACKET_RX_RING
804 # ifdef PACKET_TX_RING
807 print_tpacket_req(tcp, addr, len);
809 #endif /* PACKET_RX_RING */
810 #ifdef PACKET_ADD_MEMBERSHIP
811 case PACKET_ADD_MEMBERSHIP:
812 case PACKET_DROP_MEMBERSHIP:
813 print_packet_mreq(tcp, addr, len);
815 #endif /* PACKET_ADD_MEMBERSHIP */
822 print_icmp_filter(tcp, addr, len);
828 /* default arg printing */
831 if (len == sizeof(int)) {
832 printnum_int(tcp, addr, "%d");
834 printstr(tcp, addr, len);
840 tprintf(", %d", len);
845 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
846 tcp->u_arg[1], tcp->u_arg[2], false);
847 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
848 tcp->u_arg[3], tcp->u_arg[4]);