Networking

The net directory in the Linux file hierarchy is the repository of the socket abstraction and the network protocols; these features account for a lot of code, as Linux supports several different network protocols. Each protocol (IP, IPX, and so on) lives in its own subdirectory. Unix-domain sockets are treated like another network protocol and their implementation can be found in the unix subdirectory. It’s interesting to note that version 2.0 of the kernel includes only version 4 of IP, while version 2.1 includes fairly complete support for version 6, the upcoming standard to solve the numbering problems of version 4.

The network implementation in Linux is based on the same file operations that are used to act on device files. This is natural, as network connections (sockets) are described by normal file descriptors. A socket is described in the kernel by a struct socket (<linux/net.h>). The file socket.c is the repository of the socket file operations. It dispatches the system calls to one of the network protocols via the struct proto_ops structure. This structure is defined by each network protocol to map system calls to the low-level data handling.

Each of the directories under net (except bridge, core, and ethernet) is devoted to implementing a network protocol. The bridge directory includes an optimized implementation of Ethernet bridging according to the IEEE specifications. Files in core implement generic network features like device handling, firewalls, ...

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.