Packet Transmission
The most important tasks performed by network interfaces are data transmission and reception. I’ll start with transmission because it is slightly easier to understand.
Whenever the kernel needs to transmit a data packet, it calls the
hard_start_transmit method to put the data on an outgoing queue.
Each packet handled by the kernel is contained in a socket buffer
structure (struct sk_buff), whose definition is found in
<linux/skbuff.h>. The structure gets its name from the Unix
abstraction used to represent a network connection, the socket.
Even if the
interface has nothing to do with sockets, each network packet belongs
to a socket in the higher network layers, and the input/output buffers
of any socket are lists of struct sk_buff structures. The same
sk_buff
structure is used to host network data throughout all the Linux network
subsystems, but a socket buffer is just a packet as far as the interface
is concerned.
A pointer to sk_buff is usually called skb, and I’m
going to follow this practice both in the sample code and in the text.
The socket buffer is a complex structure, and the kernel
offers a number of functions to act on it. The functions are described
later in Section 14.8--for now a few basic facts about
sk_buff are enough for us to write a working driver. Also,
I prefer to show how things work before delving into boring details.
The socket buffer passed to hard_start_xmit contains the physical packet, complete with the transmission-level headers. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access