Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of fragmentation and assembly of IP datagrams?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly analyzes the IP datagram fragmentation and assembly principle for everyone, the content is detailed and easy to understand, the operation details are reasonable, and it has certain reference value. If you are interested, you may wish to follow Xiao Bian to have a look. Let's follow Xiao Bian to learn more about "what is the fragmentation and assembly principle of IP datagrams".

A packet of data sent from one host to another through a router must pass through many routing layers. The process is complicated, so how does IP forward the datagram to the destination host in the routing layer?

First we need to understand the format of the datagram:

IP forwarding and control are determined by IP datagram headers

the numerical value of the 4-bit header length is in units of 4 bytes, and the minimum value is 5, that is, the minimum header length is 4x5 =20 bytes.

That is, IP header without any options, the maximum value represented by the 4-bit energy table is 15, that is, the maximum header length is 60 bytes.

The 8-bit TOS field has 3 bits for specifying the priority of IP datagrams (now obsolete) and 4 bits for optional

service type (minimum latency, maximum throughput, maximum reliability, minimum cost), and one bit is always 0.

The total length of 16 bits is the number of bytes of the entire datagram (including IP header and IP layer payload).

Each IP datagram is transmitted with a 16-bit identifier plus 1, which can be used for fragmentation and reassembly of datagrams.

A 3-bit flag and a 13-bit slice offset are used for fragmentation.

TTL(Time to Live) is used when the source host sets a time to live for packets, such as 64, every time a router passes

If the route is too long and the destination host network is still not found, the packet is discarded, so

This survival time is not measured in seconds, but in hops.

The protocol field indicates whether the upper layer protocol is TCP, UDP, ICMP, or IGMP.

Then there's the checksum, which checks only the IP header, and the verification of the data is left to the higher layer protocols.

IPv4 IP addresses are 32 bits long.

In IP datagrams, the total length of the field is 16 bits, and the maximum length of a datagram is 2^16-1. Although datagrams as long as possible can improve transmission efficiency, there are few more than 1500 bytes; therefore, as long as they exceed 1500 bytes, they are considered to be fragmented. After the IP datagram is fragmented, each fragment forms a packet with an IP header and has its own independent route. After arriving at the destination host, the IP layer of the destination host will reassemble all received fragments into a datagram before transmitting it to the transport layer.

I.IP fragmentation

1. IP fragmentation principle:

The fragmentation and reassembly process is transparent to the transport layer, because after the IP datagram is fragmented, it can only be reassembled when it arrives at the next station, and it is completed by the IP layer of the destination. After fragmentation, the datagram can be fragmented again according to needs.

IP fragments and complete packets almost have the same IP header, and the ID field is the same for both US and UK fragments, so that the same IP data packet fragment can be identified during assembly. In the IP header, the 16-bit identification number uniquely records the ID of an IP packet, and IP fragments with the same ID will be reassembled; while the 13-bit fragment offset records the position of an IP fragment relative to the entire packet; the 3-bit flag in the middle of these two tables indicates whether there are new fragments after the fragment. These three fields make up all the information of IP fragmentation, which can be used by the receiver to reassemble IP data.

(1) Role of flag field

0 DF MF

Flag field has three bits, the most significant bit is 0, this value must be copied to all groups

Do not fragment (DF) values must be copied. DF=1 indicates that the recipient host cannot fragment the packet. If the packet length exceeds the MTU and cannot be fragmented, the packet can only be discarded and reported to the source host with ICMP error messages. DF=0, indicating that fragmentation is possible

Fragment (MF) indicates whether the fragment is the last fragment, MF=1 indicates that the fragment accepted is not the last fragment, MF=0 indicates that the fragment accepted is the last fragment.

Deliberately sending some IP fragments instead of all will cause the target host to always wait for fragments to consume and consume system resources.

MTU (Maximum Transmission Unit) Principle

When two remote CPs are interconnected, their data must pass through many routers and various network media to reach the opposite end.

The MTU of different media in the network is different, just like a long section of water pipe, which is composed of pipes of different thicknesses (MTU is different).

For the upper protocols at the network layer (TCP/IP for example) they don't care about the thickness of the pipes because they think it's a network thing. The network layer IP protocol detects the size of each datagram packet coming down from the upper layer protocol and decides whether to fragment it according to the MTU size of the local machine. The biggest disadvantage of fragmentation is that it reduces transmission performance. Things that could have been done at one time are divided into multiple times. Therefore, at a higher layer of the network (the implementation of the transport layer), attention is often paid to this, because some higher layers may require that packets cannot be fragmented for some reasons, and the index will add a label to the header of the IP datagram: DF. When an IP packet is transmitted in a large segment of the network, if MTU is less than the packet, the forwarding device will drop the packet according to the situation. It then returns an error message to the sender, which often causes communication problems, but fortunately most network links have MTUs of 1500 or greater.

For UDP, this protocol itself is a connectionless protocol, and it does not care whether the order of arrival of data packets is correct, so UDP generally has no requirements for fragmentation.

TCP, on the other hand, is a connection-oriented protocol, and TCP is very concerned about the order in which packets arrive.

And whether there are errors in the transmission process, so some TCP applications have requirements for fragmentation---no fragmentation.

3. Principle of MSS (Maximum Message Segment Length)

MSS is the maximum data segment that TCP packets can transmit each time. In order to achieve the best transmission efficiency, TCP usually negotiates the MSS value between the two parties when establishing the connection. This value is replaced by MTU when TCP is implemented (to subtract the header size of IP packets 20 bits and the header of TCP data segments 20BITES). Therefore, the MSS size is often 1460. Both parties will determine the maximum MSS value of this connection according to the minimum MSS value provided.

II.IP fragmentation steps

The fragmentation information field of an unfragmented datagram is all 0, that is, multiple fragmentation flag bits are 0 and the offset is 0. Fragmenting a datagram requires the following steps

(1) Check the DF flag bit to see if fragmentation is allowed. If this bit is set, the datagram will be dropped and an ICMP error will be returned to the source.

(2) Divide the data field into two or pairs of parts based on the MTU value. Except for the last data part, all new data options must be multiples of 8 bytes in length.

(3) Each data is put into an IP datagram, and the headers of these datagrams are slightly changed from the original headers.

(4) Except for the last datagram fragment, all fragments are set with multiple fragment flag bits.

(5) The fragment offset field in each fragment is set to the position occupied by this data portion in the original datagram, which is relative to the beginning of the original unfragmented datagram.

(6) If an option is included in the original datagram, the high-order byte of the option type byte determines whether this information is copied to all fragmented datagrams or only to the first datagram.

(7) Set the header field and total length field of the new datagram.

(8) Recalculate the checksum field of the message header.

These fragmented datagrams are forwarded as a complete IP datagram. IP processes each datagram fragment independently. Datagram fragments can reach their destination through different routes. If they pass through those routes with smaller MTUs, they can be further fragmented.

At the destination host, the data is reassembled into the original datagram. The flag field set by the sending host is used together with the IP address and destination IP address in the datagram. The fragmentation process does not change this field.

III. recombinant

To reassemble the datagram fragments, the receiving host allocates a storage buffer when the first fragment arrives. The host will also start a timer. When subsequent fragments of the datagram arrive, the data is copied to the buffer memory at the location specified by the fragment offset, and when all fragments arrive, the complete unfragmented original datagram is recovered.

If the timer expires and the fragment remains unacknowledged, the data is discarded. This timer is initialized with the lifetime of the IP datagram and depends on the implementation, some implementations allow it to be configured.

recombination step

On the receiver side, an original IP datagram sent by the sender reassembles all fragments before it can be submitted to the upper layer protocol. Each IP datagram to be reassembled is represented by an ipq structure.

In order to be able to effectively improve assembly shards, the structure used to preserve shards must do the following

(1) Quickly locate a group of packets of a datagram

(2) Quickly insert new fragments into a group of fragments belonging to a datagram

(3) Effectively determining whether all fragments of a datagram have been received

(4) Reassembly timeout mechanism, if timeout overflows before reassembly is completed, delete all contents of the datagram

This article mainly analyzes the IP datagram fragmentation and assembly principle for everyone, the content is detailed and easy to understand, the operation details are reasonable, and it has certain reference value. If you are interested, you may wish to follow Xiao Bian to have a look. Let's follow Xiao Bian to learn more about "what is the fragmentation and assembly principle of IP datagrams".

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report