The IPv6 header and extension headers
Name the eight fields of the fixed 40-byte IPv6 header and state what each does. Explain how the Next Header field chains extension headers and the upper-layer header. Calculate the Payload Length and on-wire size of an IPv6 packet with extension headers. Contrast the IPv6 and IPv4 headers on checksum, fragmentation, options and TTL/Hop Limit.
Take the quiz · pass mark 70% · 9 questions
Explanation
A fixed, simpler header
The IPv4 header (RFC 791) is 20 to 60 bytes long, carries options, has a checksum that every router recalculates, and has fragmentation fields. RFC 8200 replaced it in IPv6 with a fixed 40-byte header of eight fields. Anything optional moves into extension headers that sit between the IPv6 header and the payload.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class | Flow Label |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload Length | Next Header | Hop Limit |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ Source Address (128 bits) +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ Destination Address (128 bits) +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Field | Bits | Purpose |
|---|---|---|
| Version | 4 | Always 6 |
| Traffic Class | 8 | QoS marking: 6 bits DSCP and 2 bits ECN, the same as IPv4's former ToS byte |
| Flow Label | 20 | Labels packets of one flow, so routers can keep a flow on one ECMP path without parsing deeper headers (RFC 6437) |
| Payload Length | 16 | Bytes after the 40-byte header: extension headers plus upper-layer data |
| Next Header | 8 | Type of the header that follows: an extension header or the upper-layer protocol |
| Hop Limit | 8 | Decremented by 1 at each router; the packet is discarded at 0 (like IPv4's TTL) |
| Source Address | 128 | Sender |
| Destination Address | 128 | Receiver, or the next waypoint when a Routing header is present |
4 + 8 + 20 + 16 + 8 + 8 + 128 + 128 = 320 bits = 40 bytes, always.
What disappeared from IPv4, and why
| IPv4 field | Fate in IPv6 | Reason |
|---|---|---|
| IHL (header length) | Removed | The header is fixed at 40 bytes |
| Header checksum | Removed | Link layers (Ethernet FCS) and transports already check integrity. Without it, routers don't recompute a checksum at every hop. Because of this, the UDP checksum is mandatory over IPv6 |
| Identification, Flags, Fragment Offset | Moved to the Fragment extension header | Only the source fragments in IPv6. Routers never do |
| Options | Moved to extension headers | Keeps the base header fixed and fast to parse |
| TTL | Renamed Hop Limit | It always counted hops, not time |
| Protocol | Renamed Next Header | It can now point to an extension header |
Extension headers and the Next Header chain
Each extension header has its own Next Header field, so the headers form a chain. The last Next Header value names the upper-layer protocol.
Drawing diagram…
Common Next Header values (assigned by IANA, used by RFC 8200):
| Value | Header |
|---|---|
| 0 | Hop-by-Hop Options |
| 6 | TCP |
| 17 | UDP |
| 43 | Routing |
| 44 | Fragment |
| 50 | ESP (IPsec) |
| 51 | AH (IPsec) |
| 58 | ICMPv6 |
| 59 | No Next Header |
| 60 | Destination Options |
RFC 8200 recommends this order when several extension headers are present:
- IPv6 header
- Hop-by-Hop Options
- Destination Options (only for options the Routing header's waypoints must process)
- Routing
- Fragment
- Authentication (AH)
- Encapsulating Security Payload (ESP)
- Destination Options (for the final destination)
- Upper-layer header
Key points:
- Hop-by-Hop Options is the only extension header that routers along the path may examine. If present, it must come immediately after the IPv6 header.
- Routing headers list waypoints. The old Type 0 routing header was deprecated by RFC 5095 because it enabled traffic-amplification attacks. Modern use is the Segment Routing Header (Level 8).
- Fragment headers are 8 bytes and carry a 32-bit Identification, a 13-bit Fragment Offset (in 8-byte units) and an M ("more fragments") flag.
- RFC 7045 says how nodes should transmit and process extension headers. In practice, packets with extension headers are often dropped on the Internet. Level 5 covers the security side.
Fragmentation and Packet Too Big
In IPv4 a router could fragment a packet that was too big for the next link. In IPv6:
- Routers never fragment. They drop the packet and send an ICMPv6 Packet Too Big message (type 2, RFC 4443) back to the source, giving the next link's MTU.
- The source uses those messages for Path MTU Discovery (RFC 8201) and fragments, if it must, with a Fragment header.
- Every link must carry at least 1280 bytes (RFC 8200). A source that never sends packets larger than 1280 bytes never needs PMTUD.
This is why blocking ICMPv6 wholesale breaks IPv6: Packet Too Big messages never arrive, and large packets disappear into a "black hole".
Worked examples
Example 1: Payload Length
Question: A host sends a TCP segment with a 20-byte TCP header and 1,000 bytes of data, with no extension headers. What is the Payload Length, and how many bytes is the IPv6 packet?
Working: Payload Length counts everything after the 40-byte header: 20 + 1,000 = 1,020. The packet is 40 + 1,020 = 1,060 bytes.
Example 2: Adding extension headers
Question: The same segment is sent with an 8-byte Hop-by-Hop Options header and an 8-byte Fragment header. What are the Payload Length, the Next Header values in order, and the packet size?
Working:
- Payload Length = 8 + 8 + 20 + 1,000 = 1,036. Packet = 40 + 1,036 = 1,076 bytes.
- Next Header chain: IPv6 header
0(Hop-by-Hop) → Hop-by-Hop44(Fragment) → Fragment6(TCP).
Example 3: Largest payload on a 1280-byte path
Question: What is the largest UDP payload a host can send in one packet without fragmentation on a path whose MTU is the IPv6 minimum, with no extension headers?
Working: 1,280 − 40 (IPv6) − 8 (UDP) = 1,232 bytes.
Example 4: Header overhead compared with IPv4
Question: A minimum IPv4 header is 20 bytes. How much larger is the IPv6 header, and what do you get for it?
Working: 40 − 20 = 20 bytes more. You get 128-bit addresses (32 of the 40 bytes are addresses), no per-hop checksum work, and a fixed-length header that is simpler to parse in hardware.
Lab
Goal: Craft IPv6 packets with extension headers and read the header chain in Wireshark.
You need: Linux with Python 3, Scapy (pip install scapy), and Wireshark or tshark. Packets are sent only between namespaces on your machine.
Step 1: Two namespaces
sudo ip netns add pa; sudo ip netns add pb
sudo ip link add va netns pa type veth peer name vb netns pb
sudo ip -n pa link set va up; sudo ip -n pb link set vb up
sudo ip -n pa -6 addr add 2001:db8:20::a/64 dev va nodad
sudo ip -n pb -6 addr add 2001:db8:20::b/64 dev vb nodad
sudo ip netns exec pb tcpdump -i vb -w /tmp/l104.pcap ip6 &
Step 2: Send crafted packets from pa
sudo ip netns exec pa python3 - <<'PY'
from scapy.all import IPv6, IPv6ExtHdrHopByHop, IPv6ExtHdrFragment, IPv6ExtHdrDestOpt, ICMPv6EchoRequest, UDP, Raw, send
dst = "2001:db8:20::b"
send(IPv6(dst=dst)/ICMPv6EchoRequest(data=b"plain"))
send(IPv6(dst=dst)/IPv6ExtHdrHopByHop()/ICMPv6EchoRequest(data=b"hbh"))
send(IPv6(dst=dst)/IPv6ExtHdrDestOpt()/UDP(dport=9)/Raw(b"x"*100))
send(IPv6(dst=dst)/IPv6ExtHdrHopByHop()/IPv6ExtHdrFragment(id=0x1234, m=0, offset=0)/UDP(dport=9)/Raw(b"y"*1000))
PY
sudo pkill tcpdump
Step 3: Read the chain
Open /tmp/l104.pcap in Wireshark (or run tshark -r /tmp/l104.pcap -V). For each of the four packets, record:
| Packet | Payload Length | Next Header chain (numbers) | Total length on the wire (IPv6 part) |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 |
Check every Payload Length by hand from the header sizes, using the method in Worked example 2.
Step 4: Watch Hop Limit
Send IPv6(dst=dst, hlim=1)/ICMPv6EchoRequest() and then the same with hlim=64. Confirm in the capture that the Hop Limit field carries the value you set. Explain what a router would do with the hlim=1 packet if pb were one hop further away.
Clean up
sudo ip netns del pa; sudo ip netns del pb
Summary
- The IPv6 header is a fixed 40 bytes with eight fields: Version, Traffic Class, Flow Label, Payload Length, Next Header, Hop Limit, Source and Destination.
- Payload Length counts everything after the 40-byte header, including extension headers.
- Next Header chains extension headers (0 Hop-by-Hop, 43 Routing, 44 Fragment, 60 Destination Options, 50 ESP, 51 AH) to the upper layer (6 TCP, 17 UDP, 58 ICMPv6).
- Compared with IPv4: no header checksum, no options in the base header, Hop Limit instead of TTL, and no fragmentation by routers. Routers send ICMPv6 Packet Too Big, and only the source fragments.
- The minimum MTU is 1280 bytes. Blocking ICMPv6 breaks Path MTU Discovery.
- Next lesson (L1.05): ICMPv6 and Neighbor Discovery.
Quiz imported · 9 questions · pass mark 70%. Lab questions are not auto-marked.