]> granicus.if.org Git - strace/blob - netlink_unix_diag.c
Fix preprocessor indentation
[strace] / netlink_unix_diag.c
1 /*
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.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11 #include "netlink.h"
12 #include "netlink_sock_diag.h"
13 #include "nlattr.h"
14 #include "print_fields.h"
15
16 #include <linux/sock_diag.h>
17 #include <linux/unix_diag.h>
18
19 #include "xlat/unix_diag_attrs.h"
20 #include "xlat/unix_diag_show.h"
21
22 DECL_NETLINK_DIAG_DECODER(decode_unix_diag_req)
23 {
24         struct unix_diag_req req = { .sdiag_family = family };
25         const size_t offset = sizeof(req.sdiag_family);
26
27         PRINT_FIELD_XVAL("{", req, sdiag_family, addrfams, "AF_???");
28         tprints(", ");
29         if (len >= sizeof(req)) {
30                 if (!umoven_or_printaddr(tcp, addr + offset,
31                                          sizeof(req) - offset,
32                                          (char *) &req + offset)) {
33                         PRINT_FIELD_U("", req, sdiag_protocol);
34                         PRINT_FIELD_FLAGS(", ", req, udiag_states,
35                                           tcp_state_flags, "1<<TCP_???");
36                         PRINT_FIELD_U(", ", req, udiag_ino);
37                         PRINT_FIELD_FLAGS(", ", req, udiag_show,
38                                           unix_diag_show, "UDIAG_SHOW_???");
39                         PRINT_FIELD_COOKIE(", ", req, udiag_cookie);
40                 }
41         } else
42                 tprints("...");
43         tprints("}");
44 }
45
46 static bool
47 decode_unix_diag_vfs(struct tcb *const tcp,
48                      const kernel_ulong_t addr,
49                      const unsigned int len,
50                      const void *const opaque_data)
51 {
52         struct unix_diag_vfs uv;
53
54         if (len < sizeof(uv))
55                 return false;
56         if (umove_or_printaddr(tcp, addr, &uv))
57                 return true;
58
59         PRINT_FIELD_DEV("{", uv, udiag_vfs_dev);
60         PRINT_FIELD_U(", ", uv, udiag_vfs_ino);
61         tprints("}");
62
63         return true;
64 }
65
66 static bool
67 print_inode(struct tcb *const tcp,
68             void *const elem_buf,
69             const size_t elem_size,
70             void *const opaque_data)
71 {
72         tprintf("%" PRIu32, *(uint32_t *) elem_buf);
73
74         return true;
75 }
76
77 static bool
78 decode_unix_diag_inode(struct tcb *const tcp,
79                        const kernel_ulong_t addr,
80                        const unsigned int len,
81                        const void *const opaque_data)
82 {
83         uint32_t inode;
84         const size_t nmemb = len / sizeof(inode);
85
86         if (!nmemb)
87                 return false;
88
89         print_array(tcp, addr, nmemb, &inode, sizeof(inode),
90                     tfetch_mem, print_inode, 0);
91
92         return true;
93 }
94
95 static bool
96 decode_unix_diag_rqlen(struct tcb *const tcp,
97                        const kernel_ulong_t addr,
98                        const unsigned int len,
99                        const void *const opaque_data)
100 {
101         struct unix_diag_rqlen rql;
102
103         if (len < sizeof(rql))
104                 return false;
105         if (umove_or_printaddr(tcp, addr, &rql))
106                 return true;
107
108         PRINT_FIELD_U("{", rql, udiag_rqueue);
109         PRINT_FIELD_U(", ", rql, udiag_wqueue);
110         tprints("}");
111
112         return true;
113 }
114
115 static const nla_decoder_t unix_diag_msg_nla_decoders[] = {
116         [UNIX_DIAG_NAME]        = decode_nla_str,
117         [UNIX_DIAG_VFS]         = decode_unix_diag_vfs,
118         [UNIX_DIAG_PEER]        = decode_nla_u32,
119         [UNIX_DIAG_ICONS]       = decode_unix_diag_inode,
120         [UNIX_DIAG_RQLEN]       = decode_unix_diag_rqlen,
121         [UNIX_DIAG_MEMINFO]     = decode_nla_meminfo,
122         [UNIX_DIAG_SHUTDOWN]    = decode_nla_u8,
123         [UNIX_DIAG_UID]         = decode_nla_uid
124 };
125
126 DECL_NETLINK_DIAG_DECODER(decode_unix_diag_msg)
127 {
128         struct unix_diag_msg msg = { .udiag_family = family };
129         size_t offset = sizeof(msg.udiag_family);
130         bool decode_nla = false;
131
132         PRINT_FIELD_XVAL("{", msg, udiag_family, addrfams, "AF_???");
133         tprints(", ");
134         if (len >= sizeof(msg)) {
135                 if (!umoven_or_printaddr(tcp, addr + offset,
136                                          sizeof(msg) - offset,
137                                          (char *) &msg + offset)) {
138                         PRINT_FIELD_XVAL("", msg, udiag_type,
139                                          socktypes, "SOCK_???");
140                         PRINT_FIELD_XVAL(", ", msg, udiag_state,
141                                          tcp_states, "TCP_???");
142                         PRINT_FIELD_U(", ", msg, udiag_ino);
143                         PRINT_FIELD_COOKIE(", ", msg, udiag_cookie);
144                         decode_nla = true;
145                 }
146         } else
147                 tprints("...");
148         tprints("}");
149
150         offset = NLMSG_ALIGN(sizeof(msg));
151         if (decode_nla && len > offset) {
152                 tprints(", ");
153                 decode_nlattr(tcp, addr + offset, len - offset,
154                               unix_diag_attrs, "UNIX_DIAG_???",
155                               unix_diag_msg_nla_decoders,
156                               ARRAY_SIZE(unix_diag_msg_nla_decoders), NULL);
157         }
158 }