Receiving Packets from the Network Card
This chapter is mostly focused on how the kernel handles the transmission of network packets. We have already glimpsed at many crucial data structures of the networking code, so we will just give a brief description of the other side of the story; namely, how a network packet is received.
The main difference between transmitting and receiving is that the kernel cannot predict when a packet will arrive at a network card device. Therefore, the networking code that takes care of receiving the packets runs in interrupt handlers and deferrable functions.
Let’s sketch a typical chain of events occurring when a packet carrying the right hardware address (card identifier) arrives to the network device.
The network device saves the packet in a buffer in the device’s memory (the card usually keeps several packets at once in a circular buffer).
The network device raises an interrupt.
The interrupt handler allocates and initializes a new socket buffer for the packet.
The interrupt handler copies the packet from the device’s memory to the socket buffer.
The interrupt handler invokes a function (such as
eth_type_trans( )
function for Ethernet and IEEE 802.3) to determine the protocol of the packet encapsulated in the data link frame.The interrupt handler invokes the
netif_rx( )
function to notify the Linux networking code that a new packet is arrived and should be processed.
Of course, the interrupt handler is specific to the network card device. Many ...
Get Understanding the Linux Kernel, Second Edition 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.