1

I'm reading the Linux kernel implementation of the TCP/IP stack. Everything was ok till I encounter this figure
VFS - Networking subsystems interaction while reading TCP/IP architecture, design and implementation in Linux

As you may see there the author tries to describe the interaction between VFS and the socket layer on Linux. That left me with ton of doubts:

On the image it's shown a socket as a part of a file struct under a particular inode, thing is: that relationship doesn't exist anymore! (and tbh doesn't makes a ton of sense since only netlink and unix domain sockets might have inodes associated but not inet sockets isn't it?). See struct file definition; f_dentry dissapeared and while greping you can find

Documentation/filesystems/porting.rst 570: f_dentry is gone; use f_path.dentry, or, better yet, see if you can avoid it

Now same struct above does have a reachable dentry (as mentioned in docs) through f_path field but dentry is described as a two purpose struct, fist for describing a directory entry and second as a file system directory cache, so even if the relationship had not disappeared (as described in picture) this does not make a lot of sense to me, why to put the socket within an object that is intended to be ephemereal, see Dcache (maybe I'm misunderstanding dentry/dcache?).

Continuing looking at the code you can see socket struct definition. We can see that it still has the old file struct as field (makes more sense to clear VFS -> TCP/IP relationship but conserve TCP/IP -> VFS relationship in those directions for the reason above), but, question is, does it really dissapeared? I'm not seeing anything stopping for fd creation at any kind of socket, see sock_map_fd - sock_alloc_file - alloc_file_pseudo as well. Also this particular inode object socket->file->inode) should be existent only in memory since does not pertain to any device filesystem, but, who is its superblock?, see indode.sb.

This is not entirely TCP/IP-VFS interaction exactly, but, I can get an inode either from file->f_inode or through file->f_path->d_inode, what is the relation between both inodes?.

If someone can help me to understand it would be awesome folks, thanks in advance.

4
  • All sockets (address families) have inodes. This can be clearly seen in ˋ/proc/self/net/tcpˋ with the inode column, as well as when cat'ing a ˋ/proc/$PID/fdinfo/$FDˋ pseudo file. The latter will show in its first line "socket:[#ino]". Commented Apr 10, 2023 at 19:58
  • So you are saying that each socket is part of the proc fs, that's weird (to me). Proc fs is built in real time isn't it? and particularly /proc/self inherits the process which intends to read the fs, so what about a socket not actually created with the process reading the fs but let's say systemd like ssh daemons or things like that. Commented Apr 11, 2023 at 16:54
  • check out netstat, show socket, or even my lxkns namespace discovery engine. lxkns discovers namespaces also from open file descriptors which it reads from the host's procfs. My fdooze leak checker for Go also dcans the fds in a process procfs view, including sockets, as you can see in the unit tests. Commented Apr 12, 2023 at 6:53
  • 1
    maybe view the architecture not from the VFS side of things, but from inodes as the tool used for managing resource lifecycles. The VFS doesn't necessarily show all resources as first class citizens: sockets don't show up in directories as themselves (but some other resources, like namespaces can be bind-mounted into the VFS outside of the procfs). Yet sockets and other resources have inodes (look for sockfs IIRC) and are handled using file descriptors. The procfs chooses to make information about sockets visible in some places through pseudo text files; these are not the sockets themselves. Commented Apr 12, 2023 at 7:17

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.