Skip to content

Commit 762bb69

Browse files
ppiaoldv-alt
authored andcommitted
netlink: decode AF_UNIX unix_diag_msg attributes
* netlink_sock_diag.c (unix_diag_msg_nla_decoders): New array. (decode_unix_diag_msg): Use it. * linux/unix_diag.h (unix_diag_vfs, unix_diag_rqlen): New structures.
1 parent e4cfb43 commit 762bb69

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

linux/unix_diag.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ enum {
3737
UNIX_DIAG_SHUTDOWN,
3838
};
3939

40+
struct unix_diag_vfs {
41+
uint32_t udiag_vfs_ino;
42+
uint32_t udiag_vfs_dev;
43+
};
44+
45+
struct unix_diag_rqlen {
46+
uint32_t udiag_rqueue;
47+
uint32_t udiag_wqueue;
48+
};
49+
4050
#endif /* !STRACE_LINUX_UNIX_DIAG_H */

netlink_sock_diag.c

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,76 @@ decode_meminfo(struct tcb *const tcp,
165165
return true;
166166
}
167167

168+
static bool
169+
decode_unix_diag_vfs(struct tcb *tcp, kernel_ulong_t addr,
170+
kernel_ulong_t len, const void *const opaque_data)
171+
{
172+
struct unix_diag_vfs uv;
173+
174+
if (len < sizeof(uv))
175+
return false;
176+
if (umove_or_printaddr(tcp, addr, &uv))
177+
return true;
178+
179+
tprints("{udiag_vfs_dev=");
180+
print_dev_t(uv.udiag_vfs_dev);
181+
tprintf(", udiag_vfs_ino=%" PRIu32 "}", uv.udiag_vfs_ino);
182+
183+
return true;
184+
}
185+
186+
static bool
187+
print_inode(struct tcb *tcp, void *elem_buf,
188+
size_t elem_size, void *opaque_data)
189+
{
190+
tprintf("%" PRIu32, *(uint32_t *) elem_buf);
191+
192+
return true;
193+
}
194+
195+
static bool
196+
decode_unix_diag_inode(struct tcb *tcp, kernel_ulong_t addr,
197+
kernel_ulong_t len, const void *const opaque_data)
198+
{
199+
uint32_t inode;
200+
size_t nmemb = len / sizeof(inode);
201+
202+
if (!nmemb)
203+
return false;
204+
205+
print_array(tcp, addr, nmemb, &inode, sizeof(inode),
206+
umoven_or_printaddr, print_inode, 0);
207+
208+
return true;
209+
}
210+
211+
static bool
212+
decode_unix_diag_rqlen(struct tcb *tcp, kernel_ulong_t addr,
213+
kernel_ulong_t len, const void *const opaque_data)
214+
{
215+
struct unix_diag_rqlen rql;
216+
217+
if (len < sizeof(rql))
218+
return false;
219+
if (umove_or_printaddr(tcp, addr, &rql))
220+
return true;
221+
222+
tprintf("{udiag_rqueue=%" PRIu32 ", udiag_wqueue=%" PRIu32 "}",
223+
rql.udiag_rqueue, rql.udiag_wqueue);
224+
225+
return true;
226+
}
227+
228+
static const nla_decoder_t unix_diag_msg_nla_decoders[] = {
229+
[UNIX_DIAG_NAME] = decode_nla_str,
230+
[UNIX_DIAG_VFS] = decode_unix_diag_vfs,
231+
[UNIX_DIAG_PEER] = decode_nla_u32,
232+
[UNIX_DIAG_ICONS] = decode_unix_diag_inode,
233+
[UNIX_DIAG_RQLEN] = decode_unix_diag_rqlen,
234+
[UNIX_DIAG_MEMINFO] = decode_meminfo,
235+
[UNIX_DIAG_SHUTDOWN] = decode_nla_u8
236+
};
237+
168238
static void
169239
decode_unix_diag_msg(struct tcb *const tcp,
170240
const struct nlmsghdr *const nlmsghdr,
@@ -199,7 +269,8 @@ decode_unix_diag_msg(struct tcb *const tcp,
199269
tprints(", ");
200270
decode_nlattr(tcp, addr + offset, len - offset,
201271
unix_diag_attrs, "UNIX_DIAG_???",
202-
NULL, 0, NULL);
272+
unix_diag_msg_nla_decoders,
273+
ARRAY_SIZE(unix_diag_msg_nla_decoders), NULL);
203274
}
204275
}
205276

0 commit comments

Comments
 (0)