Linux Networking Subsystem
网络子系统代码定义于 net/
目录和 drivers/net
目录下:
-
net/
目录包含偏协议栈上层的代码; - 而
drivers/net/
目录下的代码则更多的偏于协议栈下层,即数据链路层和物理层,因为和物理设备强绑定,所以放在drivers/
目录下面。
网络子系统注册在 VFS 里的文件系统叫做 sockfs
,使得我们能够 read()
和 write()
一个 socket fd:
// net/socket.c
static struct file_system_type sock_fs_type = {
.name = "sockfs",
.init_fs_context = sockfs_init_fs_context,
.kill_sb = kill_anon_super,
};
static const struct file_operations socket_file_ops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read_iter = sock_read_iter,
.write_iter = sock_write_iter,
.poll = sock_poll,
.unlocked_ioctl = sock_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_sock_ioctl,
#endif
.uring_cmd = io_uring_cmd_sock,
.mmap = sock_mmap,
.release = sock_close,
.fasync = sock_fasync,
.splice_write = splice_to_socket,
.splice_read = sock_splice_read,
.splice_eof = sock_splice_eof,
.show_fdinfo = sock_show_fdinfo,
};
🗞️ Recent Posts