2 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
4 * Copyright (c) 2017-2018 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "netlink_sock_diag.h"
34 #include "print_fields.h"
36 #include <linux/sock_diag.h>
37 #include <linux/unix_diag.h>
39 #include "xlat/unix_diag_attrs.h"
40 #include "xlat/unix_diag_show.h"
42 DECL_NETLINK_DIAG_DECODER(decode_unix_diag_req)
44 struct unix_diag_req req = { .sdiag_family = family };
45 const size_t offset = sizeof(req.sdiag_family);
47 PRINT_FIELD_XVAL("{", req, sdiag_family, addrfams, "AF_???");
49 if (len >= sizeof(req)) {
50 if (!umoven_or_printaddr(tcp, addr + offset,
52 (char *) &req + offset)) {
53 PRINT_FIELD_U("", req, sdiag_protocol);
54 PRINT_FIELD_FLAGS(", ", req, udiag_states,
55 tcp_state_flags, "1<<TCP_???");
56 PRINT_FIELD_U(", ", req, udiag_ino);
57 PRINT_FIELD_FLAGS(", ", req, udiag_show,
58 unix_diag_show, "UDIAG_SHOW_???");
59 PRINT_FIELD_COOKIE(", ", req, udiag_cookie);
67 decode_unix_diag_vfs(struct tcb *const tcp,
68 const kernel_ulong_t addr,
69 const unsigned int len,
70 const void *const opaque_data)
72 struct unix_diag_vfs uv;
76 if (umove_or_printaddr(tcp, addr, &uv))
79 PRINT_FIELD_DEV("{", uv, udiag_vfs_dev);
80 PRINT_FIELD_U(", ", uv, udiag_vfs_ino);
87 print_inode(struct tcb *const tcp,
89 const size_t elem_size,
90 void *const opaque_data)
92 tprintf("%" PRIu32, *(uint32_t *) elem_buf);
98 decode_unix_diag_inode(struct tcb *const tcp,
99 const kernel_ulong_t addr,
100 const unsigned int len,
101 const void *const opaque_data)
104 const size_t nmemb = len / sizeof(inode);
109 print_array(tcp, addr, nmemb, &inode, sizeof(inode),
110 umoven_or_printaddr, print_inode, 0);
116 decode_unix_diag_rqlen(struct tcb *const tcp,
117 const kernel_ulong_t addr,
118 const unsigned int len,
119 const void *const opaque_data)
121 struct unix_diag_rqlen rql;
123 if (len < sizeof(rql))
125 if (umove_or_printaddr(tcp, addr, &rql))
128 PRINT_FIELD_U("{", rql, udiag_rqueue);
129 PRINT_FIELD_U(", ", rql, udiag_wqueue);
135 static const nla_decoder_t unix_diag_msg_nla_decoders[] = {
136 [UNIX_DIAG_NAME] = decode_nla_str,
137 [UNIX_DIAG_VFS] = decode_unix_diag_vfs,
138 [UNIX_DIAG_PEER] = decode_nla_u32,
139 [UNIX_DIAG_ICONS] = decode_unix_diag_inode,
140 [UNIX_DIAG_RQLEN] = decode_unix_diag_rqlen,
141 [UNIX_DIAG_MEMINFO] = decode_nla_meminfo,
142 [UNIX_DIAG_SHUTDOWN] = decode_nla_u8
145 DECL_NETLINK_DIAG_DECODER(decode_unix_diag_msg)
147 struct unix_diag_msg msg = { .udiag_family = family };
148 size_t offset = sizeof(msg.udiag_family);
149 bool decode_nla = false;
151 PRINT_FIELD_XVAL("{", msg, udiag_family, addrfams, "AF_???");
153 if (len >= sizeof(msg)) {
154 if (!umoven_or_printaddr(tcp, addr + offset,
155 sizeof(msg) - offset,
156 (char *) &msg + offset)) {
157 PRINT_FIELD_XVAL("", msg, udiag_type,
158 socktypes, "SOCK_???");
159 PRINT_FIELD_XVAL(", ", msg, udiag_state,
160 tcp_states, "TCP_???");
161 PRINT_FIELD_U(", ", msg, udiag_ino);
162 PRINT_FIELD_COOKIE(", ", msg, udiag_cookie);
169 offset = NLMSG_ALIGN(sizeof(msg));
170 if (decode_nla && len > offset) {
172 decode_nlattr(tcp, addr + offset, len - offset,
173 unix_diag_attrs, "UNIX_DIAG_???",
174 unix_diag_msg_nla_decoders,
175 ARRAY_SIZE(unix_diag_msg_nla_decoders), NULL);