The receiving process of the packet

Source: Internet
Author: User

Hierarchical structure of the network stack:

We're going to start at the bottom and trace the delivery flow of a packet.

1. Network interface layer

* The hardware listens to the physical medium, carries on the data reception, when the received data fills the buffer, the hardware will produce the interruption, after the interruption produces, the system will turn to the interrupt service subroutine.

* In the Interrupt service subroutine, the data is copied from the hardware buffer to the kernel's space buffer, packaged into a data structure (Sk_buff), and then called to the driver layer's interface function NETIF_RX () to send the data packets to the link layer. The implementation of the function in the NET/INET/DEV.C, (in the entire network stack implementation of the Dev.c file is of great importance, it links the driving layer and its network layer, it can be called the implementation of the link layer module)

2. Network layer
* As an example of IP packets, the IP_RCV function is called when passing from the link layer to the network layer. When the function finishes processing this layer, it invokes the handler function of the corresponding protocol according to the Transport layer protocol used in the IP header.

UDP corresponds to UDP_RCV, TCP corresponds to TCP_RCV, ICMP corresponds to ICMP_RCV, IGMP corresponds to IGMP_RCV (although here the ICMP,IGMP is generally a network layer protocol, but in fact they are encapsulated in the IP protocol, as the transport layer treated)

3. Transport Layer

If the header of the IP datagram indicates that data is being transmitted using TCP, the TCP_RCV function is called in the above function. The general process for this function is:

"All sockets that use the TCP protocol correspond to the sock structure are hung into the sock_array array of the proto structure represented by the Tcp_prot global variable, with the insertion method indexed with the local port number, so when the TCP_RCV function receives a packet, After the necessary checks and processing, it will be the TCP protocol header in the destination port number (for a received packet, the destination port number is the port number used locally) is the index, in the tcp_prot corresponding sock structure Sock_array array to get the correct sock structure queue, A query that iterates through the queue for the corresponding sock structure with other conditions, after obtaining a matching sock structure, hooks the packet into the cache queue in the sock structure (which is pointed by the Receive_queue field in the sock structure) to complete the final reception of the packet. ”

4. Application Layer

When the user needs to receive data, the socket structure and the sock structure are obtained first based on the file descriptor Inode, then the packet is read from the queue Recieve_queue pointed to in the sock structure, and the packet is copied to the user space buffer. The data is fully transferred from the hardware to the user space. This also completes a complete transfer from bottom to top.

The receiving process of the packet

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.