Fragmentation and reassembly of packets is one of the most important tasks in IP protocol.
The IPV4 header has a Len field (used to represent the total length of the message, in bytes) of 16bit, so the maximum size of the packet is defined as 64K, (2^16/1024=64).
However, in the actual network transmission, few network interfaces can transmit 64K such a large packet, but there is an MTU to indicate its maximum transmission unit. In this way, when the packet to be transmitted is larger than the MTU, the packet needs to be fragmented. It is important to note that the MTU we refer to is not just the MTU of the egress device, it depends on many factors, such as the MTU used by the routing table entry, the MTU of the egress device, and so on.
Let's not focus too much on how the MTU is calculated, but be aware that when packets are larger than the MTU, the packets need to be split into a number of equal (MTU size) fragments and then transferred separately. (Of course, packets do not necessarily equal the MTU size, so the last packet size may not reach the MTU size).
After a segmented packet is generally transferred to the destination host, it is not reorganized, but some intermediary devices (such as firewalls, NAT router devices) may need to view the full contents of the packet, which is also possible to reorganize the packet.
Influence of fragmentation and recombination on the upper layer
Fragmentation and reassembly can consume CPU and memory, consume bandwidth, and so on, excessive fragmentation and reassembly may affect the overall performance of the system, and if we can do some optimizations to avoid unnecessary fragmentation, some overhead will be reduced. The optimization work is performed on the upper layer (L4, L5).
Let's take an example to see some unnecessary fragments:
A->b->c: Packet (1000 bytes) from System A to pass B to the destination system c,a->b MTU is 800 bytes, B->c MTU is 512
In the absence of optimizations, when a->b, the packets are segmented into 800 bytes and 200 bytes based on the MTU of the A->b, and at B->c, the 800-byte packets from packet A are 512 bytes and 188 bytes in segments based on their MTU.
And if we do some optimizations that realize that the MTU of the path to A->B->C is 512 (taking a smaller value of 800 and 512), then the subcontracting is divided into 512 bytes and 488 bytes directly on the a host. In this way, only one segment is required, which reduces the overhead of the system.
TCP and UDP are not aware of the fragmentation and reassembly process, but the application layer can understand.
The Path MTU Discovery feature can discover the MTU (PMTU) of the entire path.
The RFC also specifies that the host should be able to receive at least 576 packets, so the MTU is set to 576 as a safe value.
Realization of segmentation and reorganizationIPv4 header, some fields are used for fragmentation and reassembly
Flags:-Consists of 3-bit fields, where the lowest (MF) control Shard, the presence of the next shard is set to 1, or 0 represents the end shard. The middle bit (DF) indicates whether the packet can be fragmented. The third or highest bit reservation is not used, but must be 0.
Fragment Offset:-13-bit field that indicates the location of the Shard data associated with the origin of the source datagram, supporting the destination IP to properly rebuild the source datagram.
Deep understanding of Linux Network Technology Insider--ipv4 Segmentation and reorganization