Network protocol stack 17: Network Layer receiving data processing based on connect Function Decomposition

Source: Internet
Author: User

After checking the upper-layer protocol, the link layer uploads data packets to the corresponding upper-layer protocol layer, which is the IP layer protocol.

 

After the data arrives at the IP layer, the IP layer needs to check and determine whether to upload the data to the upper layer. The following is what the IP layer needs to do.

1. first, check whether the IP address header of the data packet is correct, that is, check the length, version, and size of the IP address segment of the data packet. If yes, continue with the following steps, if the request is not met, the data packet is released and the system exits directly.

2. check whether the IP header contains the option part by checking whether the total length field of the IP header is greater than the IP header length. If yes, you need to resolve the option part, this option will tell you if there are any options when it is uploaded to the upper-layer protocol.

3. check whether a data packet is a shard data. If it is a shard data, you need to allocate a space to store the data packet. At the same time, wait for the arrival of all data packets to reorganize all the shard data, to return the complete data packet. If not, the system returns directly, which is equivalent to waiting for all the sharded data and completing the reorganization.

4. checks whether it is a multicast data packet. If it is a multicast data packet, checks whether the data packet is in the multicast group. If yes, it receives the data packet. If not, then, discard the receipt. How to check whether the local IP address is a member of multicast groups, mainly to traverse the multicast group linked list of the current device, if the multicast linked list maintained by the current device contains the destination IP address for this transfer, this IP address is a member of the multicast group and can receive data.

5. checks the upper-layer protocol corresponding to this data packet. It is learned that the chain table struct inet_protocol is traversed, because the chain table struct inet_protocol is initialized in the system, link igmp_protocol/icmp_protocol/udp_protocol/tcp_protocol and other upper-layer protocols. Now, you only need to traverse and find the upper-layer protocol of the Peer protocol, you can call the receiving function corresponding to the upper-layer protocol to receive data. For the connect function, the Protocol above the IP address is the TCP protocol, and the struct inet_protocol struct to which it receives data:

Static struct inet_protocol tcp_protocol = {

Tcp_rcv,/* TCP handler */

Null,/* No fragment handler (and won't be for a long time )*/

Tcp_err,/* TCP error control */

Null,/* Next */

Ipproto_tcp,/* protocol id */

0,/* Copy */

Null,/* Data */

"TCP"/* name */

};

The receiving function is tcp_rcv (). The system calls this function to receive data uploaded by IP addresses.

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.