The net
directory in the Linux file hierarchy is
the repository for the socket abstraction and the network protocols;
these features account for a lot of code, since Linux supports several
different network protocols. Each protocol (IP, IPX, and so on) lives
in its own subdirectory; the directory for IP is called
ipv4
because it represents version 4 of the
protocol. The new standard (not yet in wide use as we write this) is
called ipv6
and is implemented in Linux as well.
Unix-domain sockets are treated as just another network protocol;
their implementation can be found in the unix
subdirectory.
The network implementation in Linux is based on the same file
operations that act on device files. This is natural, because network
connections (sockets) are described by normal file descriptors. The
file socket.c
is the locus of the socket file
operations. It dispatches the system calls to one of the network
protocols via a struct proto_ops
structure. This
structure is defined by each network protocol to map system calls to
its specific, low-level data handling operations.
Not every subdirectory of net
is used to define a
protocol family. There are a few notable exceptions:
core
, bridge
,
ethernet
, sunrpc
, and
khttpd
.
Files in core
implement generic network features
such as device handling, firewalls, multicasting, and aliases; this
includes the handling of socket buffers
(core/skbuff.c
) and socket operations that remain
independent of the underlying protocol
(core/sock.c
). The device-independent data
management that sits near device-specific code is defined in
core/dev.c
.
The ethernet
and bridge
directories are used to implement specific low-level functionalities,
specifically, the Ethernet-related helper functions described in Chapter 14, and bridging functionality.
sunrpc
and khttpd
are
peculiar because they include kernel-level implementations of tasks
that are usually carried out in user space.
In sunrpc
you can find support functions for the
kernel-level NFS server (which is an RPC-based service), while
khttpd
implements a kernel-space web
server. Those services have been brought to kernel space to avoid the
overhead of system calls and context switches during time-critical
tasks. Both have demonstrated good performance in this mode. The
khttpd subsystem, however, has already been
rendered obsolete by TUX, which, as of this
writing, holds the record for the world’s fastest web server.
TUX will likely be integrated into the 2.5
kernel series.
The two remaining source files within net
are
sysctl_net.c
and
netsyms.c
. The former is the back end of the
sysctl
mechanism,[66] and the latter is just a list of
EXPORT_SYMBOL
declarations. There are several such files all over the kernel, usually one in each major directory.
[66] sysctl has not been described in this book; interested readers can have a look at Alessandro’s description of this mechanism at http://www.linux.it/kerneldocs/sysctl.