Download Using Time Division Multiplexing to support Real
Transcript
3.5.1 Important Data Structures in Networking Code The networking part of the linux kernel code primarily makes use of two data structures : socket buffers denoted as sk buff and sockets denoted as sock. The socket buffer (sk buff) data structure is defined in include/linux/skbuff.h. When a packet is processed by the kernel, coming either from the user space or from the network card, one of these data structures is created. Changing a field in a packet is achieved by updating a field of this data structure. This structure contains pointers to the headers of the different protocol layers. Processing of a packet in a layer is done by manipulating the header in the socket buffer for that corresponding layer. Thus passage of a network packet through the different layers is achieved by passing a pointer to this structure to the handling routines in the different protocol layers. The socket (sock) data structure is used to maintain the status of a connection. The sk buff structure also contains a pointer to the sock structure denoting the socket that owns the packet. It should be noted that when a packet is received from the network, the socket owner for that packet will be known only at a later stage. The sock data structure keeps data about the state of a TCP connection or a virtual UDP connection. This structure is created when a socket is created in the user space. The sock structure also contains protocol specific information, which store the state information of each layer. 3.5.2 Packet Transmission in Linux Network Stack Packet transmission from the application starts in the process context. It continues in the same context until the net device layer, where the packet gets queued. The network device is checked to see if it is available for transmission. If the device is available, the packet is transmitted in the process context, otherwise the packet is requeued and the transmission is carried out in softirq context. Figure 3.2 gives the control flow through the different layers when a packet is transmitted. The following section describes the different steps in transmission. 23