tools/testing/vsock/vsock_diag_test.c
Source file repositories/reference/linux-study-clean/tools/testing/vsock/vsock_diag_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vsock/vsock_diag_test.c- Extension
.c- Size
- 11934 bytes
- Lines
- 597
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
getopt.hstdio.hstdlib.hstring.herrno.hunistd.hsys/stat.hsys/types.hlinux/list.hlinux/net.hlinux/netlink.hlinux/sock_diag.hlinux/vm_sockets_diag.hnetinet/tcp.htimeout.hcontrol.hutil.h
Detected Declarations
struct vsock_statfunction print_vsock_addrfunction print_vsock_statfunction print_vsock_statsfunction check_no_socketsfunction check_num_socketsfunction check_socket_statefunction send_reqfunction recv_respfunction add_vsock_statfunction read_vsock_statfunction free_sock_statfunction test_no_socketsfunction test_listen_socket_serverfunction test_connect_clientfunction test_connect_serverfunction usagefunction main
Annotated Snippet
struct vsock_stat {
struct list_head list;
struct vsock_diag_msg msg;
};
static const char *sock_type_str(int type)
{
switch (type) {
case SOCK_DGRAM:
return "DGRAM";
case SOCK_STREAM:
return "STREAM";
case SOCK_SEQPACKET:
return "SEQPACKET";
default:
return "INVALID TYPE";
}
}
static const char *sock_state_str(int state)
{
switch (state) {
case TCP_CLOSE:
return "UNCONNECTED";
case TCP_SYN_SENT:
return "CONNECTING";
case TCP_ESTABLISHED:
return "CONNECTED";
case TCP_CLOSING:
return "DISCONNECTING";
case TCP_LISTEN:
return "LISTEN";
default:
return "INVALID STATE";
}
}
static const char *sock_shutdown_str(int shutdown)
{
switch (shutdown) {
case 1:
return "RCV_SHUTDOWN";
case 2:
return "SEND_SHUTDOWN";
case 3:
return "RCV_SHUTDOWN | SEND_SHUTDOWN";
default:
return "0";
}
}
static void print_vsock_addr(FILE *fp, unsigned int cid, unsigned int port)
{
if (cid == VMADDR_CID_ANY)
fprintf(fp, "*:");
else
fprintf(fp, "%u:", cid);
if (port == VMADDR_PORT_ANY)
fprintf(fp, "*");
else
fprintf(fp, "%u", port);
}
static void print_vsock_stat(FILE *fp, struct vsock_stat *st)
{
print_vsock_addr(fp, st->msg.vdiag_src_cid, st->msg.vdiag_src_port);
fprintf(fp, " ");
print_vsock_addr(fp, st->msg.vdiag_dst_cid, st->msg.vdiag_dst_port);
fprintf(fp, " %s %s %s %u\n",
sock_type_str(st->msg.vdiag_type),
sock_state_str(st->msg.vdiag_state),
sock_shutdown_str(st->msg.vdiag_shutdown),
st->msg.vdiag_ino);
}
static void print_vsock_stats(FILE *fp, struct list_head *head)
{
struct vsock_stat *st;
list_for_each_entry(st, head, list)
print_vsock_stat(fp, st);
}
static struct vsock_stat *find_vsock_stat(struct list_head *head, int fd)
{
struct vsock_stat *st;
struct stat stat;
if (fstat(fd, &stat) < 0) {
Annotation
- Immediate include surface: `getopt.h`, `stdio.h`, `stdlib.h`, `string.h`, `errno.h`, `unistd.h`, `sys/stat.h`, `sys/types.h`.
- Detected declarations: `struct vsock_stat`, `function print_vsock_addr`, `function print_vsock_stat`, `function print_vsock_stats`, `function check_no_sockets`, `function check_num_sockets`, `function check_socket_state`, `function send_req`, `function recv_resp`, `function add_vsock_stat`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.