O'Reilly logo

Understanding the Linux Kernel, Second Edition by Marco Cesati, Daniel P. Bovet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

  1. 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).

  2. The network device raises an interrupt.

  3. The interrupt handler allocates and initializes a new socket buffer for the packet.

  4. The interrupt handler copies the packet from the device’s memory to the socket buffer.

  5. 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.

  6. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required