TDEB Top Bar

Trending
Semiconductor Industry News — The Digital Electronics Blog
Follow Us

TDEB Masthead

The Semiconductor Hub

Semiconductors.  Chips and Systems.  Innovation.

Indexed by leading Search Engines, AI and referenced by Engineers worldwide 500+ Articles 10M+ Pageviews 30+ Reports 50+ Citations

IP Fragmentation Questions and Answers

The Editor's Desk
by
0
Share Facebook X LinkedIn WhatsApp Email

IP fragmentation is what happens when an IP datagram is too big for the next link it has to cross: the datagram is cut into smaller pieces, each sent as its own IP datagram, and the destination puts them back together. The questions and answers below cover what fragmentation is, why it happens, how the header fields make it work, and how reassembly fails.

The first part covers the basics in plain terms. The deep dive then goes through the header fields, the fragmentation algorithm, a worked example with real numbers, and how IPv6 changed the rules.

The basics

1. What is meant by IP fragmentation?

The breaking up of a single IP datagram into two or more IP datagrams of smaller size is called IP fragmentation.

2. Why is an IP datagram fragmented?

Every transmission medium has a limit on the maximum size of a frame it can transmit, called the maximum transmission unit (MTU). As IP datagrams are encapsulated in frames, the size of an IP datagram is also restricted. If the size of an IP datagram is greater than this limit, then it must be fragmented. Ethernet, for example, has an MTU of 1,500 bytes.

3. Which RFCs discuss IP fragmentation?

RFC 791 and RFC 815 discuss IP datagrams, fragmentation and reassembly. RFC 791 defines the IPv4 header and the fragmentation procedure; RFC 815 describes an efficient reassembly algorithm.

4. Is it possible to select an IP datagram size to always avoid fragmentation?

It is not possible to select a particular IP datagram size that always avoids fragmentation, as the MTU differs from one transmission medium to another. It is possible, though, for a given path to choose a size that will not lead to fragmentation. This is called Path MTU Discovery and is described in RFC 1191. The TCP transport protocol tries to avoid fragmentation using the Maximum Segment Size (MSS) option.

5. Where can an IP datagram get fragmented?

An IP datagram may get fragmented either at the sending host or at one of the intermediate routers (in IPv4).

6. Where are the IP datagram fragments reassembled?

The IP fragments are reassembled only at the destination host.

7. How do you prevent an IP datagram from being fragmented?

An IP datagram can be prevented from fragmentation by setting the "don't fragment" (DF) flag in the IP header.

8. What happens when a datagram must be fragmented to traverse a network, but the "don't fragment" flag in the datagram is set?

The datagram whose "don't fragment" flag is set is discarded if it must be fragmented to traverse a network. Also, an ICMP error message is sent back to the sender of the datagram: Destination Unreachable with code 4, "fragmentation needed and DF set", as listed in RFC 792. Path MTU Discovery relies on exactly this message.

9. Will all the fragments of a datagram reach the destination using the same path?

The different fragments of the same IP datagram can travel either on the same path or on different paths to the destination.

10. Will all the fragments of a datagram arrive at the destination system in the correct order?

The different fragments of a single IP datagram can arrive in any order at the destination system.

11. What happens to the original IP datagram when one or more fragments are lost?

When one or more fragments of an IP datagram are lost, the entire IP datagram is discarded after a timeout period. The other fragments are wasted, which is one reason fragmentation is best avoided. If the first fragment did arrive, the destination may report the loss with an ICMP Time Exceeded message, code 1, "fragment reassembly time exceeded" (RFC 792).

Deep dive: the numbers and details

This part holds the header fields, the algorithms and a worked example. Skip it if the basics are all you need.

The header fields that make fragmentation work

FieldSizeRole in fragmentation
Identification16 bitsSame value in every fragment of one datagram
Flags: DF (don't fragment)1 bitForbids fragmentation
Flags: MF (more fragments)1 bit1 on every fragment except the last
Fragment offset13 bitsPosition of this fragment's data in the original, in units of 8 bytes
Total length16 bitsLength of this fragment, header included

Because the offset counts 8-byte units, every fragment except the last must carry a multiple of 8 data bytes. The largest offset is 8,191 units, or 65,528 bytes, which covers the 65,535-byte maximum IPv4 datagram (RFC 791, section 3.1).

Worked example: a 4,000-byte datagram over Ethernet

A host sends a 4,000-byte IPv4 datagram (20-byte header, 3,980 bytes of data) onto a link with a 1,500-byte MTU. Each fragment can carry at most 1,500 - 20 = 1,480 data bytes, and 1,480 is a multiple of 8 (185 units).

FragmentData bytesTotal lengthOffset (units)Offset (bytes)MF
11,4801,500001
21,4801,5001851,4801
31,0201,0403702,9600

The receiver finds the original data length from the last fragment: offset 2,960 bytes plus 1,020 data bytes gives 3,980 bytes. Note the cost: three headers instead of one, so 4,040 bytes on the wire instead of 4,000, and if any one fragment is lost all three are wasted.

12. What is the minimum size of an IP fragment?

The minimum size of an IP fragment is the minimum size of an IP header plus eight data bytes. RFC 791 states that every internet module must be able to forward a datagram of 68 octets without further fragmentation: a header of up to 60 octets plus the minimum fragment of 8 data octets. Most firewall-type devices will drop an initial IP fragment (offset 0) that does not contain enough data to hold the transport headers. In other words, the first fragment normally needs 20 octets of data in addition to the IP header to get through a firewall if the offset is 0. This defends against the "tiny fragment attack" described in RFC 1858, section 3, where an attacker splits the TCP header across fragments so a filter cannot see the port numbers or flags.

13. What are the limitations on the size of a fragment?

The size of an IP datagram fragment is limited by:

  1. The amount of remaining data in the original IP datagram.
  2. The MTU of the network.
  3. The requirement that the data length be a multiple of 8, except for the final fragment.

14. How is an IP datagram fragment differentiated from a non-fragmented IP datagram?

A complete IP datagram is differentiated from an IP fragment using the offset field and the "more fragments" flag. For a non-fragmented IP datagram, the fragment offset will be zero and the "more fragments" flag will be zero.

15. How are the fragments of a single IP datagram identified?

The "identification" field in the IP header is used to identify the fragments of a single IP datagram. The value of this field is set by the originating system. It is unique for that source-destination pair and protocol for the time during which the datagram will be active. With only 16 bits, the identification wraps after 65,536 datagrams, which on a fast link can happen within the reassembly timeout; this is another reason high-speed hosts avoid fragmentation.

16. How is the last fragment of an IP datagram identified?

The last fragment of an IP datagram is identified using the "more fragments" flag. The "more fragments" flag is set to zero for the last fragment.

17. How is the length of a complete IP datagram calculated from the received IP fragments?

Using the fragment offset field and the length of the last fragment, the length of a complete IP datagram is calculated, as the worked example above shows.

18. How is an IP datagram fragmented?

In the following example, an IP datagram is fragmented into two. The same algorithm can be used to fragment the datagram into n fragments. It follows the example procedure in RFC 791, section 3.2.

  1. The IP layer creates two new IP datagrams, whose lengths satisfy the requirements of the network on which the original datagram is going to be sent.
  2. The IP header from the original IP datagram is copied to the two new datagrams.
  3. The data in the original IP datagram is divided into two on an 8-byte boundary. The number of 8-byte blocks in the first portion is called the Number of Fragment Blocks (NFB).
  4. The first portion of the data is placed in the first new IP datagram.
  5. The length field in the first new IP datagram is set to the length of the first datagram.
  6. The fragment offset field in the first IP datagram is set to the value of that field in the original datagram.
  7. The "more fragments" field in the first IP datagram is set to one.
  8. The second portion of the data is placed in the second new IP datagram.
  9. The length field in the second new IP datagram is set to the length of the second datagram.
  10. The "more fragments" field in the second IP datagram is set to the same value as in the original IP datagram.
  11. The fragment offset field in the second IP datagram is set to the value of that field in the original datagram plus NFB.

Steps 6, 10 and 11 are what allow a fragment to be fragmented again by a later router: the offsets and flags stay correct relative to the original datagram.

19. How does a destination system reassemble the fragments of an IP datagram?

  1. When a host receives an IP fragment, it stores the fragment in a reassembly buffer based on its fragment offset field.
  2. Upon receiving the first fragment, a reassembly timer is started.
  3. Once all the fragments of the original IP datagram are received, the datagram is processed.
  4. If the reassembly timer expires before all the fragments are received, the datagram is discarded.

Fragments are matched to one datagram by four fields together: source address, destination address, protocol and identification.

20. What fields are changed in an IP header due to fragmentation?

The following IP header fields are changed due to IP fragmentation:

  1. Total Length
  2. Header Length (if options are dropped from later fragments)
  3. More Fragments Flag
  4. Fragment Offset
  5. Header Checksum
  6. Options

21. What happens to the IP options field when an IP datagram is fragmented?

Depending on the option, it is copied either to all the fragments or to only the first fragment.

22. Which IP options are copied to all the fragments of an IP datagram?

If the most significant bit in the option type (the "copied" flag) is set, that option is copied to all the fragments. If it is not set, it is copied only to the first fragment.

How IPv6 changed the rules

IPv6 moved fragmentation out of the routers. Under RFC 8200, section 5, only the source node fragments, using a separate Fragment extension header; routers never fragment and there is no DF flag, because every IPv6 packet behaves as if DF were set. Every link must carry at least 1,280 bytes in one piece, and a host that does not do Path MTU Discovery can simply send packets no larger than 1,280 bytes.

Common interview traps

  • Saying routers reassemble fragments. They do not; only the destination host does.
  • Forgetting that the offset is in 8-byte units, not bytes.
  • Assuming fragments arrive in order or over the same path.
  • Applying IPv4 router fragmentation to IPv6.
The Editor's Desk
About the Author
The Editor's Desk
Share Facebook X LinkedIn WhatsApp Email

Post a Comment

0 Comments

Your comments will be moderated before it appears here.

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!