This is the Title of the Book, eMatter Edition
Copyright © 2005 O’Reilly & Associates, Inc. All rights reserved.
497
Chapter 17
CHAPTER 17
Network Drivers
Having discussed char and block drivers, we are now ready to move on to the world
of networking. Network interfaces are the third standard class of Linux devices, and
this chapter describes how they interact with the rest of the kernel.
The role of a network interface within the system is similar to that of a mounted
block device. A block device registers its disks and methods with the kernel, and
then “transmits” and “receives” blocks on request, by means of its request function.
Similarly, a network interface must register itself within specific kernel data struc-
tures in order to be invoked when packets are exchanged with the outside world.
There are a few important differences between mounted disks and packet-delivery
interfaces. To begin with, a disk exists as a special file in the /dev directory, whereas a
network interface has no such entry point. The normal file operations (read, write,
and so on) do not make sense when applied to network interfaces, so it is not possi-
ble to apply the Unix “everything is a file” approach to them. Thus, network inter-
faces exist in their own namespace and export a different set of operations.
Although you may object that applications use the read and write system calls when
using sockets, those calls act on a software object that is distinct from the interface.
Several hundred sockets can be multiplexed on the same physical interface.
But the most important difference between the two is that block drivers operate only
in response to requests from the kernel, whereas network drivers receive packets
asynchronously from the outside. Thus, while a block driver is asked to send a buffer
toward the kernel, the network device asks to push incoming packets toward the ker-
nel. The kernel interface for network drivers is designed for this different mode of
operation.
Network drivers also have to be prepared to support a number of administrative
tasks, such as setting addresses, modifying transmission parameters, and maintain-
ing traffic and error statistics. The API for network drivers reflects this need and,
therefore, looks somewhat different from the interfaces we have seen so far.
,ch17.13860 Page 497 Friday, January 21, 2005 11:10 AM