IP fragmentation works by dividing a large IP packet into smaller pieces (fragments) when it exceeds the Maximum Transmission Unit (MTU) of a network path. These fragments are then reassembled at the destination host.
Here's a more detailed breakdown:
1. The Need for Fragmentation:
- The Internet Protocol (IP) relies on the concept of a Maximum Transmission Unit (MTU). This is the largest packet size (in bytes) that a network can handle.
- Different networks can have different MTU sizes.
- When a packet's size exceeds the MTU of a network along the path, fragmentation becomes necessary to ensure the packet reaches its destination.
2. Where Fragmentation Occurs:
- Fragmentation can happen at the sending host or at any intermediate router along the path.
- The “Don't Fragment” (DF) flag in the IP header controls whether fragmentation is allowed. If the DF flag is set and a router encounters a packet larger than its MTU, the router will drop the packet and send an ICMP "Fragmentation Needed and DF set" message back to the source. This allows Path MTU Discovery to occur (a mechanism to determine the smallest MTU along a path).
3. Fragmentation Process:
- When a router (or the sending host) needs to fragment a packet, it divides the data into smaller fragments.
- Each fragment has its own IP header, which includes:
- Identification (ID): A value that identifies all fragments belonging to the same original IP packet. All fragments of the same original packet have the same ID.
- Fragment Offset: Indicates where the data in the fragment belongs within the original, unfragmented packet. It is measured in units of 8 bytes. The first fragment has an offset of 0.
- More Fragments (MF) flag: Indicates whether this is the last fragment. All fragments except the last one have the MF flag set to 1. The last fragment has the MF flag set to 0.
4. Example:
Let's say a host wants to send a 4000-byte IP packet (including header) across a network with an MTU of 1500 bytes. Assuming a 20-byte IP header, each fragment's data portion cannot exceed 1480 bytes (1500 - 20 = 1480). The packet would be fragmented as follows:
Fragment | ID | Offset | MF | Data Size (bytes) |
---|---|---|---|---|
1 | X | 0 | 1 | 1480 |
2 | X | 185 | 1 | 1480 |
3 | X | 370 | 0 | 1020 |
- ID (X): All fragments share the same identification number (X).
- Offset: Fragment 1 starts at byte 0, fragment 2 starts at byte 1480 (offset 185 x 8), and fragment 3 starts at byte 2960 (offset 370 x 8) of the original data.
- MF: The first two fragments have the "More Fragments" flag set to 1, indicating that more fragments are coming. The last fragment has the MF flag set to 0.
5. Reassembly:
- Reassembly always occurs at the destination host, not at intermediate routers.
- The destination host uses the ID, Fragment Offset, and MF flag in the IP header to reassemble the fragments into the original IP packet.
- If any fragment is lost, the entire original IP packet is lost, and the higher-layer protocol (e.g., TCP) will have to retransmit the data.
6. Disadvantages of Fragmentation:
- Overhead: Each fragment has its own IP header, increasing the total overhead.
- Inefficiency: Loss of a single fragment requires retransmission of the entire original IP packet.
- Security Risks: Fragmentation can be exploited in certain denial-of-service attacks.
7. Path MTU Discovery (PMTUD):
- PMTUD is a technique used to determine the smallest MTU along a path between two hosts.
- By using the DF flag and reacting to ICMP "Fragmentation Needed" messages, the sending host can dynamically adjust its packet size to avoid fragmentation.
- This is generally the preferred approach to avoid the disadvantages of fragmentation.
In summary, IP fragmentation is a mechanism to break down large IP packets into smaller units for transmission across networks with smaller MTUs. While it ensures delivery, it introduces overhead and potential inefficiency, making Path MTU Discovery a more desirable alternative where possible.