JustKernel

Ray Of Hope

Life Of Packet – Ingres in the system

Packet Receiving process:  3 stages:

  •  Packet is transferred from tnetwork interface card (NIC) to the ring buffer. The NIC and device driver manage and controls this process.
  • Packet is transferred from ring buffer to a socket receive buffer, driver by  a software interrupt request (softirq). The kernel protocol stack handles this stage.
  • Packet data is copied from the socket receive buffer to the application, which we will term the Data Receiving Process.</li>

The linkux kernel uses structure sk_vuff[2] to hold any single packet up to the MTU of the network. The device driver maintains a “ring” of these packet buffers, known as a “ring buffer” fo packet reception. (and a seperate ring for packet transmission).A ring buffer consists of a device-and driver-dependent number of packet descriptors. To be able to receive a packet, a packet descriptor should be in “ready state” which means it should be initialized and pre-allocated with an empty sk_buff memory -mapped into I/O space for DMA. When a packet comes in, one of the ready packet descriptors in the reception ring will be used, the packet will be transferred into the pre-allocated sk_buff, and the descriptor will be marked as used.

When a packet is received , it is transferred into main memory and an interrupt is raised only after the packet is accesssible to the kernel. When CPU responds to the interrupt,  the driver’s interupt handler is called, which schedules a softirq. It puts a recerence to the device into the poll queue of the interrrupted CPU and disables the NIC’s receive interrupt until the packet in its ring buffer are processed.

The softirq is serviced shortly afterward. The CPU polls each devce in its poll queue to get the received packets from the ring buffer by calling hte poll method of the device driver. In dev-&gt;poll(), each received packet is passed upwards for further processing. After, a packet is dequeued from ints receiving ring buffer, its corresponding packet descriptor needs to be reinitinialized and refilled.

Originally Posted On: 2010-07-19 05:00:19

Anshul Makkar, anshul_makkar@justkernel.com

Tags: ,


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.