strace/linux/unix_diag.h

51 lines
925 B
C
Raw Normal View History

#ifndef STRACE_LINUX_UNIX_DIAG_H
#define STRACE_LINUX_UNIX_DIAG_H
Support unix domain sockets in -yy option This change extends -yy option to handle unix domain sockets: their peer addresses will be printed, similar to inet sockets. For a listening socket, its socket inode and socket path are printed. For an accepted socket, its socket inode, the peer inode, and the socket path are printed. For a client socket, its socket inode and the peer inode are printed. An example of a server side communication using netcat: $ ./strace -yy -e network nc -l -U /tmp/example.sock socket(PF_LOCAL, SOCK_STREAM, 0) = 3 setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0 listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0 accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]> recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6 INPUT An example of a client side communication using netcat: $ ./strace -yy -e network nc -U /tmp/example.sock socket(PF_LOCAL, SOCK_STREAM, 0) = 3 connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0 getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 INPUT ... sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6 * linux/unix_diag.h: New file. * socketutils.c (send_query): Rename to inet_send_query. (parse_response): Rename to inet_parse_response. (unix_print, unix_send_query, unix_parse_response): New functions. (receive_responses): Add a new argument named parser: a function for handling protocol specific data parts of diag messages. (print_sockaddr_by_inode): Call unix_print. Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal but NETLINK_SOCK_DIAG looks more generic. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 20:59:31 +09:00
struct unix_diag_req {
uint8_t sdiag_family;
uint8_t sdiag_protocol;
uint16_t pad;
uint32_t udiag_states;
uint32_t udiag_ino;
uint32_t udiag_show;
uint32_t udiag_cookie[2];
};
#define UDIAG_SHOW_NAME 0x01
#define UDIAG_SHOW_VFS 0x02
Support unix domain sockets in -yy option This change extends -yy option to handle unix domain sockets: their peer addresses will be printed, similar to inet sockets. For a listening socket, its socket inode and socket path are printed. For an accepted socket, its socket inode, the peer inode, and the socket path are printed. For a client socket, its socket inode and the peer inode are printed. An example of a server side communication using netcat: $ ./strace -yy -e network nc -l -U /tmp/example.sock socket(PF_LOCAL, SOCK_STREAM, 0) = 3 setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0 listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0 accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]> recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6 INPUT An example of a client side communication using netcat: $ ./strace -yy -e network nc -U /tmp/example.sock socket(PF_LOCAL, SOCK_STREAM, 0) = 3 connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0 getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 INPUT ... sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6 * linux/unix_diag.h: New file. * socketutils.c (send_query): Rename to inet_send_query. (parse_response): Rename to inet_parse_response. (unix_print, unix_send_query, unix_parse_response): New functions. (receive_responses): Add a new argument named parser: a function for handling protocol specific data parts of diag messages. (print_sockaddr_by_inode): Call unix_print. Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal but NETLINK_SOCK_DIAG looks more generic. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 20:59:31 +09:00
#define UDIAG_SHOW_PEER 0x04
#define UDIAG_SHOW_ICONS 0x08
#define UDIAG_SHOW_RQLEN 0x10
#define UDIAG_SHOW_MEMINFO 0x20
Support unix domain sockets in -yy option This change extends -yy option to handle unix domain sockets: their peer addresses will be printed, similar to inet sockets. For a listening socket, its socket inode and socket path are printed. For an accepted socket, its socket inode, the peer inode, and the socket path are printed. For a client socket, its socket inode and the peer inode are printed. An example of a server side communication using netcat: $ ./strace -yy -e network nc -l -U /tmp/example.sock socket(PF_LOCAL, SOCK_STREAM, 0) = 3 setsockopt(3<UNIX:[14728348]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(3<UNIX:[14728348]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0 listen(3<UNIX:[14728348,"/tmp/example.sock"]>, 10) = 0 accept(3<UNIX:[14728348,"/tmp/example.sock"]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14727246->14727245,"/tmp/example.sock"]> recvfrom(4<UNIX:[14727246->14727245,"/tmp/example.sock"]>, "INPUT\n", 8192, 0, NULL, NULL) = 6 INPUT An example of a client side communication using netcat: $ ./strace -yy -e network nc -U /tmp/example.sock socket(PF_LOCAL, SOCK_STREAM, 0) = 3 connect(3<UNIX:[14727245]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0 getsockopt(3<UNIX:[14727245]>, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 INPUT ... sendto(3<UNIX:[14727245->14727246]>, "INPUT\n", 6, 0, NULL, 0) = 6 * linux/unix_diag.h: New file. * socketutils.c (send_query): Rename to inet_send_query. (parse_response): Rename to inet_parse_response. (unix_print, unix_send_query, unix_parse_response): New functions. (receive_responses): Add a new argument named parser: a function for handling protocol specific data parts of diag messages. (print_sockaddr_by_inode): Call unix_print. Replace NETLINK_INET_DIAG with NETLINK_SOCK_DIAG, they are equal but NETLINK_SOCK_DIAG looks more generic. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2014-12-24 20:59:31 +09:00
struct unix_diag_msg {
uint8_t udiag_family;
uint8_t udiag_type;
uint8_t udiag_state;
uint8_t pad;
uint32_t udiag_ino;
uint32_t udiag_cookie[2];
};
enum {
UNIX_DIAG_NAME,
UNIX_DIAG_VFS,
UNIX_DIAG_PEER,
UNIX_DIAG_ICONS,
UNIX_DIAG_RQLEN,
UNIX_DIAG_MEMINFO,
UNIX_DIAG_SHUTDOWN,
};
struct unix_diag_vfs {
uint32_t udiag_vfs_ino;
uint32_t udiag_vfs_dev;
};
struct unix_diag_rqlen {
uint32_t udiag_rqueue;
uint32_t udiag_wqueue;
};
#endif /* !STRACE_LINUX_UNIX_DIAG_H */