This is the Title of the Book, eMatter Edition
Copyright © 2005 O’Reilly & Associates, Inc. All rights reserved.
498
|
Chapter 17: Network Drivers
The network subsystem of the Linux kernel is designed to be completely protocol-
independent. This applies to both networking protocols (Internet protocol [IP] versus
IPX or other protocols) and hardware protocols (Ethernet versus token ring, etc.).
Interaction between a network driver and the kernel properly deals with one network
packet at a time; this allows protocol issues to be hidden neatly from the driver and
the physical transmission to be hidden from the protocol.
This chapter describes how the network interfaces fit in with the rest of the Linux
kernel and provides examples in the form of a memory-based modularized network
interface, which is called (you guessed it) snull. To simplify the discussion, the inter-
face uses the Ethernet hardware protocol and transmits IP packets. The knowledge
you acquire from examining snull can be readily applied to protocols other than IP,
and writing a non-Ethernet driver is different only in tiny details related to the actual
network protocol.
This chapter doesn’t talk about IP numbering schemes, network protocols, or other
general networking concepts. Such topics are not (usually) of concern to the driver
writer, and it’s impossible to offer a satisfactory overview of networking technology
in less than a few hundred pages. The interested reader is urged to refer to other
books describing networking issues.
One note on terminology is called for before getting into network devices. The net-
working world uses the term octet to refer to a group of eight bits, which is generally
the smallest unit understood by networking devices and protocols. The term byte is
almost never encountered in this context. In keeping with standard usage, we will
use octet when talking about networking devices.
The term “header” also merits a quick mention. A header is a set of bytes (err, octets)
prepended to a packet as it is passed through the various layers of the networking
subsystem. When an application sends a block of data through a TCP socket, the
networking subsystem breaks that data up into packets and puts a TCP header,
describing where each packet fits within the stream, at the beginning. The lower lev-
els then put an IP header, used to route the packet to its destination, in front of the
TCP header. If the packet moves over an Ethernet-like medium, an Ethernet header,
interpreted by the hardware, goes in front of the rest. Network drivers need not con-
cern themselves with higher-level headers (usually), but they often must be involved
in the creation of the hardware-level header.
How snull Is Designed
This section discusses the design concepts that led to the snull network interface.
Although this information might appear to be of marginal use, failing to understand
it might lead to problems when you play with the sample code.
The first, and most important, design decision was that the sample interfaces should
remain independent of real hardware, just like most of the sample code used in this
,ch17.13860 Page 498 Friday, January 21, 2005 11:10 AM
- 1
- 2
前往页