编程知识 cdmana.com

Aren't you curious about the Linux Network contracting process?

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" Preface ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" This time, , Let's focus on one problem .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Linux How does the system send and receive network packets ?","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"horizontalrule","attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" Text ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" A network model ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" In order to enable a variety of devices to communicate with each other through the network , And in order to solve the compatibility problem of different devices in the network interconnection , ISO has developed a reference model for open system interconnection communication (","attrs":{}},{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"pen System Interconnection Reference Model","attrs":{}},{"type":"text","text":"), That is to say OSI A network model , This model mainly includes 7 layer , The application layer 、 The presentation layer 、 The session layer 、 Transport layer 、 The network layer 、 And the physical layer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Each layer is responsible for different functions , as follows :","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" application layer , Responsible for providing a unified interface for applications ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The presentation layer , Responsible for converting data into a format compatible with another system ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The session layer , Responsible for establishing 、 Manage and terminate communication sessions between presentation layer entities ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Transport layer , Responsible for end-to-end data transmission ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The network layer , Responsible for data routing 、 forward 、 Fragmentation ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Data link layer , Responsible for data framing and error detection , as well as MAC Addressing ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The physical layer , Responsible for transmitting data frames in the physical network ;","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" because OSI The model is too complicated , What we put forward is only the stratification of concept and theory , There is no specific implementation plan . in fact , We're more familiar with , Also more practical is the four layer model , namely TCP/IP A network model ,Linux The system implements the network protocol stack according to the network model .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"TCP/IP Network models share 4 layer , The application layer 、 Transport layer 、 Network layer and network interface layer , Each layer is responsible for the following functions :","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" application layer , Responsible for providing users with a set of applications , such as HTTP、DNS、FTP etc. ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Transport layer , Responsible for end-to-end communication , such as TCP、UDP etc. ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The network layer , Responsible for the encapsulation of network package 、 Fragmentation 、 route 、 forward , such as IP、ICMP etc. ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Network interface layer , Responsible for the transmission of network packets in the physical network , For example, the encapsulation of network packets 、 MAC Addressing 、 Error detection , And through the network card transmission network frame and so on ;","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"TCP/IP Network model compared to OSI The network model is simplified a lot , And it's easier to remember , The relationship between them is as follows :","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ac/accdc75a60926191d4ad8d8343e50301.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" however , We often talk about seven layer and four layer load balancing , Yes, it is OSI Network model to describe , The seven layers correspond to the application layer , The four layers correspond to the transport layer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"horizontalrule","attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Linux Network protocol stack ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" We can compare our bodies to data in the application layer , The undergarment is compared to the one in the transport layer TCP head , The coat is compared to the network layer IP head , Hats and shoes are compared to the header and tail of the network interface layer, respectively .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" In the winter season , When we're going out to play from home , Naturally, you have to wear a base coat first , Put on a warm coat , Finally put on your hat and shoes before you go out , It's like we put TCP When the network packet of protocol communication is sent out , The application layer data will be packaged and processed layer by layer according to the network protocol stack .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" You can see from the picture below that , The encapsulation format of application layer data in each layer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4d/4daed9e15b85f1691497bf911642b229.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" among :","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Transport layer , Add... To the front of application data TCP head ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The network layer , to TCP Add... To the front of the packet IP head ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Network interface layer , to IP The frame header and tail are added before and after the packet ;","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" These additions and the head and tail , They all have their own functions , It is also filled in according to the specific protocol format , Each layer has its own protocol header , Naturally, the size of the network packet increases , But physical links can't transmit packets of any size , So in Ethernet , The maximum transmission unit is specified (MTU) yes ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"1500","attrs":{}}],"attrs":{}},{"type":"text","text":" byte , In other words, the maximum of a single transmission is specified IP Bag size .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" When the network packet exceeds MTU Size , It will be fragmented in the network layer , In order to ensure that the IP The bag won't exceed MTU size , If MTU The smaller it is , The more subcontracting is needed , The worse the network throughput is , Contrary , If MTU The bigger it is , The smaller the need for subcontracting , The better the network throughput .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" got it TCP/IP A network model , And the principle of network packet encapsulation , that Linux What the network protocol stack looks like , You must have guessed about , It's just like TCP/IP Four story structure of :","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/36/361e77d512918f5cd16a340b3bd351af.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" From the network protocol stack shown above , You can see :","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The application needs to be called by the system , Follow me Socket Layer for data interaction ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Socket Below the layer is the transport layer 、 Network layer and network interface layer ;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The bottom floor , It is the network card driver and hardware network card device ;","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"horizontalrule","attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Linux The process of receiving network packets ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" A network card is a piece of hardware in a computer , Responsible for receiving and sending network packets , When the network card receives a network packet , Will pass DMA technology , Put the network packet into Ring Buffer, This is a ring buffer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After receiving the network packet , How to tell the operating system that the network packet has arrived ?","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The simplest way is to trigger an interrupt , That is, whenever the network card receives a network packet , Just trigger an interrupt to tell the operating system .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" however , There is a problem , In high performance network environment , The number of network packets will be very large , Then a lot of interrupts will be triggered , You know, when CPU Interrupt received , Will stop what you're doing , And to handle these packets , After processing , To go back to other things , Trigger interrupts so often , Will lead to CPU Has not played out of processing interrupt , And other missions may not be able to move forward , This will affect the overall efficiency of the system .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" So in order to solve the performance overhead caused by frequent interrupts ,Linux Kernel in 2.6 The version introduces ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"NAPI Mechanism ","attrs":{}},{"type":"text","text":", It's a mixture of 「 Interrupt and polling 」 To receive network packets , Its core concept is ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":" Read data without interruption ","attrs":{}},{"type":"text","text":", First of all, interrupt is used to wake up the service program receiving data , then ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"poll","attrs":{}}],"attrs":{}},{"type":"text","text":" Method to poll data .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" such as , When a network packet arrives , The network card initiates a hardware interrupt , The hardware interrupt handling function of the network card will be executed ,","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":" The interrupt handling function needs 「 Temporarily mask interrupt 」, Then wake up 「 Soft interrupt 」 To poll and process data , The interrupt is not restored until there is no new data , This interrupt processes multiple network packets at a time ","attrs":{}},{"type":"text","text":", So it can reduce the performance overhead caused by network card interruption .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" How does soft interrupt handle network packets ? It will be from Ring Buffer Copy data to the kernel struct sk_buff Buffer zone , So it can be used as a network packet to be processed layer by layer by the network protocol stack .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" First , It will go to the network interface layer first , At this level, the legality of the message is checked , If it's against the law, throw it away , If it is legal, it will find out the type of the upper layer protocol of the network packet , For example IPv4, still IPv6, Then remove the head and tail of the frame , And then give it to the network layer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" To the network layer , Take out IP package , Determine the next direction of network packets , For example, it should be handed over to the upper level for processing or forwarding . After confirming that the network packet will be sent to this machine , It will start from IP In the head, the type of the upper layer protocol is TCP still UDP, And then remove IP head , And then to the transport layer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Transport layer removal TCP Head or UDP head , According to the quadruple 「 Source IP、 Source port 、 Purpose IP、 Destination port 」 As identification , Find the corresponding Socket, And copy the data to Socket Receive buffer for .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Last , Application layer program calls Socket Interface , From the kernel Socket The receive buffer reads the incoming data to the application layer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" thus , The receiving process of a network packet is over , You can also see the process of receiving network packets from the left part of the figure below , The right part just turns around , It's the process of sending network packets .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/42/427db83b285da4c3e6b28090f73f43da.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Linux The process of sending network packets ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" There's half of the picture above , The process of sending network packets is the opposite of receiving packets .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" First , The application will call Socket The interface for sending packets , Because this is a system call , So it will fall from user mode to kernel mode Socket layer ,Socket Layer will copy application layer data to Socket Send buffer .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Next , Network protocol stack from Socket Send the packet out of the buffer , And in accordance with the TCP/IP The protocol stack is processed layer by layer from top to bottom .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" If you are using TCP The transport protocol sends data , Then it will add TCP baotou , And then give it to the network layer , The network layer will add IP package , Then confirm the next hop by querying the routing table IP, And in accordance with the MTU The size is divided into pieces .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Network packet after fragmentation , It will be sent to the network interface layer , It will pass through here ARP Agreement to get the next hop of MAC Address , Then add the header and the tail of the frame , Put it in the contract queue .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" When these are ready , Will trigger a soft interrupt to tell the network card driver , There are new network packets to send , Finally, the driver passes through DMA, Read network packets from the packet queue , Put it in the queue of the hardware network card , Then the physical network card sends it out .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"----","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" summary ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Computers and computers are usually called network cards 、 Switch 、 Routers and other network devices are connected together , That's because of the heterogeneity of network devices , The international organization for standardization has defined a seven level OSI A network model , But because of the complexity of this model , It is not used in practical application , It's a simpler version of TCP/IP Model ,Linux The network protocol stack is implemented according to the model .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"TCP/IP The model is mainly divided into application layer 、 Transport layer 、 The network layer 、 Network interface layer, four layers , The responsibilities of each level are different , This is also Linux The main components of network protocol stack .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" When the application passes Socket Interface sends packets , Data packets will be processed layer by layer by layer from top to bottom of network protocol stack , Will be sent to the network card queue , Then the network card sends out the network packet .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" And when receiving network packets , Also need to go through the network protocol stack from bottom to top layer by layer processing , It's finally sent to the application .","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225105051864i.html

Scroll to Top