Linux Network kernel? Learning and thinking

Source: Internet
Author: User
Linux Network kernel? Learning and thinking-Linux general technology-Linux programming and kernel information. The following is a detailed description. Abstract The software architecture of the operating system. It is generally considered that the Linux kernel consists of Process Scheduling (SCHED), memory management (MM), Virtual File System (VFS), and inter-process communication (IPC) and Network Interface (NET) and other five subsystems, each subsystem has different degrees of dependency on other subsystems, its subtle relationships and complex communication lay the foundation for the superior performance of the entire system. From the general perspective of operating systems, network subsystems have shown their importance and network functions have long been one of the basic objectives of modern operating systems. But in fact, Linux was born from the beginning of the network, and its continuous growth and improvement are also promoted in the network environment. As a mainstream network operating system, with its powerful network support functions, high-level network security performance, and continuous and stable operation, it has an increasing share in the application server platform market year by year, it is not only the biggest competitor of Microsoft's network servers based on NT technology in this field, but also the dominant position of the Linux network server platform in the entire application field.

The Network part of the Linux kernel, that is, the network kernel itself, is deployed according to the hierarchical model. The direct interface between the user's application process and the network kernel is Socket, the specific network communication protocol works on the protocol layer under the Socket, and the underlying network communication hardware device. In fact, there are multiple levels within each layer that can be subdivided intermittently, data transmitted over the network is transmitted in the order of bottom-up and top-down before it reaches the host or is to be sent from the host. Data transmitted over the network cannot span any of these layers, the kernel guarantees the uniqueness of this transmission path to ensure the reliability and accuracy of the entire network subsystem.

We know that the Linux kernel source code is mainly written in C language. However, in terms of the design and implementation of the network subsystem, the object-oriented design concept is obviously embodied. Although there is no direct introduction of class definitions, there is no clear OOP concepts such as formal encapsulation inheritance, however, the idea of designing data attributes and operation sets in an integrated data structure shows the object-oriented feature in essence, for example, the device structure and sk_buff structure, which are the most important data structures in the network kernel, are good instances. In this object-oriented design, network device interfaces, Socket buffers, sockets, and network protocols are considered as the core "Network objects" of this subsystem ", the Design and Implementation of the entire network kernel is based on the four main objects and their connection and communication. These four systems reflect the relationship between the network subsystem and other subsystems in the kernel. The running of the network kernel is inseparable from the support of VFS, MM, and SCHED, the Socket buffer object reflects the close relationship between the network subsystem and MM ?? The Socket buffer itself is a piece of space opened up in the virtual memory. The management of it is actually very large programs rely on the functions provided by the memory management subsystem; the management of Socket network objects involves signal synchronization, distribution and access of file descriptors, and other sub-system functions such as SCHED and FS in the kernel.

Socket buffer
Network communication protocol
Socket)
Network Device Interface

Network kernel objects and their relationships

Among the four core network objects mentioned above, the Socket buffer becomes the core network object because it has direct dependency with the other three objects, in fact, the source code of Linux's network kernel is indeed the most significant cost for managing network buffers. We can combine the workflow of one-time communication between two endpoints in the network to understand the role of this buffer: After the sender has data to be sent and the Socket for sending is established, the corresponding Socket buffer is established at the Socket layer, and then transmitted from the application process to the physical layer from top to bottom, each layer of the Protocol adds the corresponding Header and Tail (Header & Tail) to the Socket buffer that is also passed down. Finally, when the data to be sent is organized into a bit stream at the physical layer, the Socket buffer disappears when it is released at this layer. After the data reaches the acceptor through the network path, the work to be done is basically the opposite: the Socket buffer is established in the physical layer and is transferred to the Socekt layer of the receiver in the order of bottom-up, during the transfer process, the header and tail of each layer of the Protocol will be removed from the data packet and deleted in the Socekt buffer. Finally, when the data reaches the Socket layer of the receiver, the data to be transmitted is handed over to the application process at the receiving end, And the Socket buffer disappears at the Socket layer. The execution of these tasks, including the implementation of linked list operations for organizing these network buffers, all depend on the call of a series of function interfaces related to Socket buffer allocation and collection and process control provided by the Linux Network kernel ?? These calls can be found in some standard routines of the network device driver.

Another extremely critical structure is device. It is easy to see that it is closely related to network device interfaces in four core network objects. In fact, this structure involves the compilation of general device drivers. Register a new network device with the Linux kernel. The most important task is to complete the content defined in this structure and attach it to the network device table of the system. Of course, Linux's support for the module mechanism is one of its important advantages. If the network device driver exists in the form of a module rather than being compiled into the kernel itself, you also need to do some work related to the module registration, initialization, and uninstallation. This part of content itself can be said to be quite a lot, and we will leave it for the next discussion. However, it must be mentioned that this structure includes a set of standard operation routines required to send and receive data on the network device at the FS level, one thing that cannot be ignored is that the network device itself is also used as a file for Linux. In the file structure we are familiar with, the file_operations * pointer will need to point to this operation set ?? The sending and receiving of network data is the read and write operations on network device files.

The above actually involves the Socket layer of Linux. I think it is necessary to understand that the Socket we are familiar with when programming network applications is actually at the top of the BSDSocket layer, this layer can be considered as a unified abstract socket layer, which shields the differences in addressing methods and communication protocols between different address families involved in the following address family socket layer. For example, the most familiar TCP/IP corresponds to the INET address family, and the layer is the INET layer. The bottom of this hierarchy model is the protocol layer, specifically some network communication protocols contained in the upper-layer address family, such as TCP and UDP. The BSDSocket operations called in network applications are based on the protocol operation set registered in the kernel of the address family, the proto_ops structure pointer in the pops vector in the kernel points to the structure that contains the definitions of these protocol operation routines.

The above is just a personal understanding of the Linux kernel. I believe there will be some false statements. I hope you can give me some advice and hope to discuss and learn with you.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.