Linux kernel Analysis

Source: Internet
Author: User
Tags htons

Kernel version: 2.6.34

In the previous "IP protocol" in the message received when the IP layer processing analysis, this analysis will be sent to the message when the IP layer processing.

When the transport layer is processed, ip_push_pending_frames () is invoked to pass the message to the IP layer:

Ip_push_pending_frames ()-> ip_local_out ()-> __ip_local_out ()

In Ip_push_pending_frames (), the header field for the first IP fragment is set, and Tot_len and check are not set.

int ip_local_out (struct sk_buff *skb)
{
 int err;
 Err = __ip_local_out (SKB);     
 if (likely (err = = 1))
  err = Dst_output (SKB);
 return err;
}

__ip_local_out (): Sets the total length of IP header bytes Tot_len, checksum check.

Iph->tot_len = htons (skb-

>len);     
Ip_send_check (IPH);

The Last Call Dst_output () sends the data to the IP layer, dst_output () actually calls SKB_DST (SKB)->output (SKB), SKB_DST (SKB) is the corresponding routing item for SKB. SKB_DST (SKB) points to the routing item dst_entry, its input is assigned a value ip_local_deliver () when the message is received, and output is assigned Ip_output () when the message is sent.

Return Nf_hook (Pf_inet, Nf_inet_local_out, SKB, NULL, SKB_DST (SKB)->dev, dst_output);

The process of calling at the IP layer is as follows:

Ip_output ()-> ip_finish_output ()-> Ip_finish_output2 ()-> hh->hh_output ()

In Ip_output (), the Dev and protocol number is set, from the IP layer down, is the dev drive data transmission.

Skb->dev = Dev;     
Skb->protocol = htons (ETH_P_IP);

In Ip_finish_output (), it is judged that if the message is too large, the ip_fragment () is called to fragment (after which the function is parsed) and then the Ip_finish_output2 () is sent.

if (Skb->len > Ip_skb_dst_mtu

(SKB) &&!skb_is_gso (SKB)) return     
 ip_fragment (SKB, Ip_finish_ OUTPUT2);     
else return 
 Ip_finish_output2 (SKB);

Situation one: Ip_fragment ()

Ip_fragment () and Ip_append_data () are two functions that are important for the IP layer to send messages, and it is important to understand their relationship.

Ip_append_data () is used by the SKB to transmit data to the IP layer, which slices the transmitted data according to the MTU value, followed by the fragment chain on the first frag_list; if the device supports SG, then the same fragment content (when the fragment content is entered multiple times) Not necessarily in a linear space, the subsequent input fragment content exists in a fragmented frags array. Only the first fragment is frag_list, and each fragment can have a frags. The SKB, constructed by Ip_append_data (), is roughly as shown in the following illustration:

Ip_fragments () literally is a fragment, but in fact the Shard work has been done by Ip_append_data (), which is only fragmented when the upper layer is problematic. Its main role is to complete the follow-up work of fragmentation. Suppose a message is divided into three skb1, SKB2, SKB3, which will be transmitted independently to the network, but obviously Ip_append_data () SKB is not independent, SKB1 contains the message of the whole message, and the fragmented message is also linked to frag_list; skb2 , Skb3 lacks IP header information, such as fragment offset, fragment identification, checksum, and so on. The main task of ip_fragments () is to split the SKB into a message that can be sent independently. The SKB that is processed by ip_fragments () is shown in the figure:

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.