Skip to content

Commit d52bc5b

Browse files
fabiensironppiao
andcommitted
netlink: add a basic netlink socket diag parser
* Makefile.am (strace_SOURCES): Add netlink_sock_diag.c. (EXTRA_DIST): Add linux/packet_diag.h and linux/smc_diag.h. * defs.h (ethernet_protocols, inet_protocols) (socktypes): New xlat prototype. (decode_netlink_sock_diag): New prototype. * netlink.c (decode_specific_proto): New function. (decode_specific_proto): Use decode_netlink_sock_diag. (decode_payload): Use decode_specific_proto. * netlink_sock_diag.c: New file. * linux/inet_diag.h: Import linux headers. * linux/netlink_diag.h: Likewise. * linux/unix_diag.h: Likewise. * linux/packet_diag.h: New file. * linux/smc_diag.h: Likewise. * xlat/inet_diag_extended_flags.in: Likewise. * xlat/netlink_diag_show.in: Likewise. * xlat/netlink_sock_states.in: Likewise. * xlat/packet_diag_show.in: Likewise. * xlat/smc_diag_extended_flags.in: Likewise. * xlat/smc_sock_states.in: Likewise. * xlat/tcp_sock_state_flags.in: Likewise. * xlat/tcp_sock_states.in: Likewise. * xlat/unix_diag_show.in: Likewise. Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
1 parent 0036991 commit d52bc5b

18 files changed

+617
-3
lines changed

Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ strace_SOURCES = \
172172
native_defs.h \
173173
net.c \
174174
netlink.c \
175+
netlink_sock_diag.c \
175176
nsfs.c \
176177
nsfs.h \
177178
nsig.h \
@@ -562,6 +563,7 @@ EXTRA_DIST = \
562563
linux/or1k/set_scno.c \
563564
linux/or1k/syscallent.h \
564565
linux/or1k/userent.h \
566+
linux/packet_diag.h \
565567
linux/personality.h \
566568
linux/powerpc/arch_regs.c \
567569
linux/powerpc/arch_regs.h \
@@ -678,6 +680,7 @@ EXTRA_DIST = \
678680
linux/sh64/syscallent.h \
679681
linux/sh64/userent.h \
680682
linux/signalent.h \
683+
linux/smc_diag.h \
681684
linux/sock_diag.h \
682685
linux/sparc/arch_getrval2.c \
683686
linux/sparc/arch_regs.c \

defs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ extern const struct xlat addrfams[];
295295
extern const struct xlat at_flags[];
296296
extern const struct xlat clocknames[];
297297
extern const struct xlat dirent_types[];
298+
extern const struct xlat ethernet_protocols[];
298299
extern const struct xlat evdev_abs[];
300+
extern const struct xlat inet_protocols[];
299301
extern const struct xlat msg_flags[];
300302
extern const struct xlat netlink_protocols[];
301303
extern const struct xlat open_access_modes[];
@@ -304,6 +306,7 @@ extern const struct xlat resource_flags[];
304306
extern const struct xlat setns_types[];
305307
extern const struct xlat sg_io_info[];
306308
extern const struct xlat socketlayers[];
309+
extern const struct xlat socktypes[];
307310
extern const struct xlat whence_codes[];
308311

309312
/* Format of syscall return values */
@@ -623,6 +626,9 @@ tprint_iov_upto(struct tcb *, kernel_ulong_t len, kernel_ulong_t addr,
623626

624627
extern void
625628
decode_netlink(struct tcb *, int, kernel_ulong_t addr, kernel_ulong_t len);
629+
extern bool
630+
decode_netlink_sock_diag(struct tcb *, kernel_ulong_t addr,
631+
kernel_ulong_t len, unsigned int, int);
626632

627633
extern void tprint_open_modes(unsigned int);
628634
extern const char *sprint_open_modes(unsigned int);

linux/inet_diag.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ struct inet_diag_sockid {
1414
uint32_t idiag_cookie[2];
1515
};
1616

17-
/* Request structure */
17+
/* Request structures */
18+
struct inet_diag_req {
19+
uint8_t idiag_family;
20+
uint8_t idiag_src_len;
21+
uint8_t idiag_dst_len;
22+
uint8_t idiag_ext;
23+
struct inet_diag_sockid id;
24+
uint32_t idiag_states;
25+
uint32_t idiag_dbs;
26+
};
27+
1828
struct inet_diag_req_v2 {
1929
uint8_t sdiag_family;
2030
uint8_t sdiag_protocol;
@@ -40,4 +50,28 @@ struct inet_diag_msg {
4050
uint32_t idiag_inode;
4151
};
4252

53+
/* Extensions */
54+
enum {
55+
INET_DIAG_NONE,
56+
INET_DIAG_MEMINFO,
57+
INET_DIAG_INFO,
58+
INET_DIAG_VEGASINFO,
59+
INET_DIAG_CONG,
60+
INET_DIAG_TOS,
61+
INET_DIAG_TCLASS,
62+
INET_DIAG_SKMEMINFO,
63+
INET_DIAG_SHUTDOWN,
64+
INET_DIAG_DCTCPINFO,
65+
INET_DIAG_PROTOCOL, /* response attribute only */
66+
INET_DIAG_SKV6ONLY,
67+
INET_DIAG_LOCALS,
68+
INET_DIAG_PEERS,
69+
INET_DIAG_PAD,
70+
INET_DIAG_MARK,
71+
INET_DIAG_BBRINFO,
72+
__INET_DIAG_MAX,
73+
};
74+
75+
#define INET_DIAG_MAX (__INET_DIAG_MAX - 1)
76+
4377
#endif /* !STRACE_LINUX_INET_DIAG_H */

linux/netlink_diag.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ struct netlink_diag_msg {
2424
};
2525

2626
#define NDIAG_SHOW_MEMINFO 0x00000001
27+
#define NDIAG_SHOW_GROUPS 0x00000002
28+
/* deprecated since 4.6 */
29+
#define NDIAG_SHOW_RING_CFG 0x00000004
2730
#define NDIAG_PROTO_ALL ((uint8_t) ~0)
2831

2932
#endif /* !STRACE_LINUX_NETLINK_DIAG_H */

linux/packet_diag.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef STRACE_LINUX_PACKET_DIAG_H
2+
#define STRACE_LINUX_PACKET_DIAG_H
3+
4+
struct packet_diag_req {
5+
uint8_t sdiag_family;
6+
uint8_t sdiag_protocol;
7+
uint16_t pad;
8+
uint32_t pdiag_ino;
9+
uint32_t pdiag_show;
10+
uint32_t pdiag_cookie[2];
11+
};
12+
13+
#define PACKET_SHOW_INFO 0x00000001 /* Basic packet_sk information */
14+
#define PACKET_SHOW_MCLIST 0x00000002 /* A set of packet_diag_mclist-s */
15+
#define PACKET_SHOW_RING_CFG 0x00000004 /* Rings configuration parameters */
16+
#define PACKET_SHOW_FANOUT 0x00000008
17+
#define PACKET_SHOW_MEMINFO 0x00000010
18+
#define PACKET_SHOW_FILTER 0x00000020
19+
20+
struct packet_diag_msg {
21+
uint8_t pdiag_family;
22+
uint8_t pdiag_type;
23+
uint16_t pdiag_num;
24+
25+
uint32_t pdiag_ino;
26+
uint32_t pdiag_cookie[2];
27+
};
28+
29+
#endif /* !STRACE_LINUX_PACKET_DIAG_H */

linux/smc_diag.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef STRACE_LINUX_SMC_DIAG_H
2+
#define STRACE_LINUX_SMC_DIAG_H
3+
4+
#include <linux/inet_diag.h>
5+
6+
/* Request structure */
7+
struct smc_diag_req {
8+
uint8_t diag_family;
9+
uint8_t pad[2];
10+
uint8_t diag_ext; /* Query extended information */
11+
struct inet_diag_sockid id;
12+
};
13+
14+
/* Base info structure. It contains socket identity (addrs/ports/cookie) based
15+
* on the internal clcsock, and more SMC-related socket data
16+
*/
17+
struct smc_diag_msg {
18+
uint8_t diag_family;
19+
uint8_t diag_state;
20+
uint8_t diag_fallback;
21+
uint8_t diag_shutdown;
22+
struct inet_diag_sockid id;
23+
24+
uint32_t diag_uid;
25+
uint64_t diag_inode;
26+
};
27+
28+
/* Extensions */
29+
30+
enum {
31+
SMC_DIAG_NONE,
32+
SMC_DIAG_CONNINFO,
33+
SMC_DIAG_LGRINFO,
34+
SMC_DIAG_SHUTDOWN,
35+
__SMC_DIAG_MAX,
36+
};
37+
38+
#define SMC_DIAG_MAX (__SMC_DIAG_MAX - 1)
39+
40+
#endif /* !STRACE_LINUX_SMC_DIAG_H */

linux/unix_diag.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ struct unix_diag_req {
1111
uint32_t udiag_cookie[2];
1212
};
1313

14-
#define UDIAG_SHOW_NAME 0x01
15-
#define UDIAG_SHOW_PEER 0x04
14+
#define UDIAG_SHOW_NAME 0x00000001 /* show name (not path) */
15+
#define UDIAG_SHOW_VFS 0x00000002 /* show VFS inode info */
16+
#define UDIAG_SHOW_PEER 0x00000004 /* show peer socket info */
17+
#define UDIAG_SHOW_ICONS 0x00000008 /* show pending connections */
18+
#define UDIAG_SHOW_RQLEN 0x00000010 /* show skb receive queue len */
19+
#define UDIAG_SHOW_MEMINFO 0x00000020 /* show memory info of a socket */
1620

1721
struct unix_diag_msg {
1822
uint8_t udiag_family;

netlink.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,25 @@ decode_nlmsgerr(struct tcb *const tcp, int fd,
209209
tprints("}");
210210
}
211211

212+
static bool
213+
decode_specific_proto(struct tcb *const tcp, int fd,
214+
const struct nlmsghdr *const nlmsghdr,
215+
const kernel_ulong_t addr,
216+
const kernel_ulong_t len)
217+
{
218+
int proto = getfdnlproto(tcp, fd, netlink_protocols);
219+
220+
switch (proto) {
221+
case NETLINK_SOCK_DIAG:
222+
return decode_netlink_sock_diag(tcp, addr, len,
223+
nlmsghdr->nlmsg_type,
224+
nlmsghdr->nlmsg_flags &
225+
NLM_F_REQUEST);
226+
default:
227+
return false;
228+
}
229+
}
230+
212231
static void
213232
decode_payload(struct tcb *const tcp, int fd,
214233
const struct nlmsghdr *const nlmsghdr,
@@ -218,6 +237,8 @@ decode_payload(struct tcb *const tcp, int fd,
218237
if (nlmsghdr->nlmsg_type == NLMSG_ERROR) {
219238
decode_nlmsgerr(tcp, fd, addr, len);
220239
return;
240+
} else if (decode_specific_proto(tcp, fd, nlmsghdr, addr, len)) {
241+
return;
221242
} else if (nlmsghdr->nlmsg_type == NLMSG_DONE && len == sizeof(int)) {
222243
int total_len;
223244

0 commit comments

Comments
 (0)