Socket cache
Each level of protocol is provided in another layer, so that the use of multi-storey network protocols will have a problem: Each protocol should be added to the protocol head and protocol tail when transmitting data, and the data is reached again. . In this way, there must be a data cache between different protocols, and each layer needs to know which location and the end of the specific protocol. A solution is to copy the cache in each layer, but this is very efficient. Linux switches data between the protocol layer and the network device driver with Socket cache or SK_Buffs. SK_BUFFS includes pointers and field lengths, so that each protocol layer can operate the application data through standard functions or "methods".
Figure 1: Socket Cache (SK_BUFF)
Figure 1 shows the SK_BUFF data structure; each SK_BUFF has a block of data. SK_BUFF has four pointers, these pointers are used to manipulate data from Socket cached:
HEAD
Point to the beginning of the data area in memory. This pointer is
SK_BUFF is fixed when it allocates the relevant data blocks.
Data
Point to the beginning of the current protocol data. This pointer is with current ownership
SK_BUFF which protocol layer is changed.
TAIL
Point to the end of the current protocol data. Similarly, this pointer also has currently owned
SK_BUFF which protocol layer is changed.
end
Point to the end of the data area in memory. This pointer is
SK_BUFF and its related data block are assigned.
LEN and TRUESIZE These two fields are used to describe the current protocol package length and data cache overall length. SK_BUFF processing code provides standard operation to add and remove the protocol header and protocol tail to the application. This can safely operate Data, Tail, and Len fields in SK_BUFF.
push
It
DATA pointer points to the beginning of the data area and increases
Len. Used to increase the protocol head at the beginning of the data to be transmitted.
PULL
It
The DATA pointer moves from the beginning of the data area to the end of the data area, and decreases
Len. Used to remove the protocol head at the beginning of the received data.
PUT
It
TAIL pointer points to the end of the data area and increases
Len. Used to add data or protocol information at the end of the data to be transmitted.
TRIM
It
TAIL pointer points to the beginning of the data area and decreases
Len. Used to remove data or protocol information at the end of the received data.
The SK_BUFF structure also includes a list of dual connection loops for SK_BUFFs for some pointers for some pointers. General SK_BUFF cases can add SK_BUFF to the front or back of these lists, or you can delete them.
Receive IP package
Device Drive Chapter Describes how Linux network devices are placed in the kernel and initialized. A series of DEVICE data structures are connected to each other in the dev_base table. Each DEVICE structure describes its device and provides a callback routine, and the network protocol layer calls these routines when the network driver is required. These functions are closely related to the transmitted data and network device addresses. When a network device receives a package from the Internet, it must convert the received data to the SK_BUFF structure. These SK_BUFFs are added to the Backlog queue by the network driver.
If the Backlog queue is too long, discard the received SK_BUFF. When you are ready to run, the network base will be set.
When the network underlying is running in accordance with the schedule, any network package that is waiting to be transmitted is processed by it. SK_BUFF decides which layers processed the received package.
When the Linux network layer is initialized, each protocol registers itself by adding the Packet_Type structure to the PTYPE_ALL list or the PTYPE_BASE HASH table. The Packet_Type structure contains the protocol type, a pointer to the network device, a pointer to the receiving data processing routine of the protocol, and finally includes a pointer to the next packet_type structure in the list chain or the HASH chain. The PTYPE_ALL link is used to listen to all packages received from the network device, usually not using it. The PTYPE_BASE HASH table is the protocol identifier to make it to determine which protocol will receive incoming network packets. The network underlayer matches the protocol type that passes into SK_BUFF through one or more packet_type items in the two tables. The protocol can match more than one item, such as a plurality of SK_BUFFs to copy when all of the transmission on the online transmission. SK_BUFF will pass the matching protocol processing routine. 10.5.3 Send IP Package
The application is transferred when the application exchanges data, otherwise it is generated by the network protocol to establish a connection or supporting a established connection. Regardless of whether the data is generated, a SK_BUFF is established to include data, and when the protocol layer, these protocols will add various heads.
SK_BUFF needs to be transmitted over a network device. First of all agreements, such as IP, you need to determine which network device is in use. This is the best route depends on the package. For a simple network through MODEM, such as through the PPP protocol, the choice of route is simple. The package should be sent to the local host through the local loop device or the gateway sent to the PPP MODEM. For more than the computer connected to the network, the more complicated the route is complex.
For each transmitted IP package, IP uses a routing table for the purpose IP address to resolve the route. When you successfully find the destination IP from the routing table, a RTABLE structure describing the route to use is returned. This includes the source IP address to be used, the address of the network Device structure, and sometimes pre-established hardware heads. These hardware headers are network devices specific, physical addresses, and other physical addresses, and other specific media information. If the network device is an Ethernet device, the hardware head should be shown in Figure 10.1, and the source and destination address should be a physical Ethernet address. Hardware heads can be cached during routing because it must be added to each of the IP packets to be transmitted. The physical address contained in the hardware head is parsed with the ARP protocol. The outgoing bag will be issued after the address is parsed. After parsing the address, the hardware head is cached so that the next IP package does not need to use ARP when using this interface.
Data block
Each network device has a maximum of a package size, a transmission or receiving packet cannot be larger than this value. The IP protocol allows data to be divided into smaller units so that the network device can process. The IP protocol head has a block field, which contains a flag and split offset.
When the IP package is ready to transfer, IP finds a network device to send an IP package. This device is found from the IP routing table. There is an MTU in each DEVICE structure to describe the maximum transmission unit (in bytes). If the MTU of the device is smaller than the package size of the IP packet to be transmitted, the IP package must be split into smaller units. Each unit is characterized by a SK_BUFF structure; its IP header is monitored to identify it is a plug-in package, which also contains the split offset. The last package is identified as the last IP unit. If the IP cannot assign SK_BUFF during the blocking process, the transmission failed.