IPv4 Options
IPv4 Options Format
Read aloud is unavailable in this browser.
The Extensibility Mechanism of IPv4
The designers of IPv4 faced a fundamental challenge: how do you create a protocol flexible enough to accommodate features that haven't been invented yet, while keeping the base header efficient for the common case? Their solution was elegant—optional header extensions.
The IPv4 options field is a variable-length extension that follows the fixed 20-byte header. It enables advanced functionality like route recording, source routing, and timestamping without burdening every packet with rarely-used fields. Understanding options is essential for deep protocol analysis, network troubleshooting, and security assessment.
By the end of this page, you will understand the complete structure of IPv4 options, including the type field encoding, length semantics, copying behavior, and how options are padded to maintain 32-bit alignment. You'll be able to decode any IPv4 option from raw packet data.
The Options Field in Context
Before diving into the format details, let's understand where the options field sits within the IPv4 header and why it exists.
IPv4 Header Structure Recap:
The IPv4 header consists of two parts:
- Fixed header (20 bytes): Contains essential fields like version, IHL, total length, TTL, protocol, source and destination addresses
- Options field (0-40 bytes): Variable-length extension for additional functionality
The Internet Header Length (IHL) field indicates the total header size in 32-bit words. With a minimum value of 5 (20 bytes) and maximum of 15 (60 bytes), the options field can consume up to 40 bytes.
| IHL Value | Header Size (bytes) | Options Size (bytes) | Description |
|---|---|---|---|
| 5 | 20 | 0 | Minimum header, no options |
| 6 | 24 | 4 | One 32-bit word of options |
| 7 | 28 | 8 | Two 32-bit words of options |
| 10 | 40 | 20 | Five 32-bit words of options |
| 15 | 60 | 40 | Maximum header, full options |
The maximum options size of 40 bytes is a hard constraint of IPv4. This limit proved challenging for features like Record Route, which can only record 9 router addresses. This limitation influenced IPv6's design, which uses extension headers without such constraints.
Option Format Categories
IPv4 options come in two distinct formats, distinguished by their structure:
1. Single-Byte Options (Type Only)
These options consist of just the 1-byte type field. They carry no additional data and are used for control purposes.
2. Multi-Byte Options (Type + Length + Data)
These options use a Type-Length-Value (TLV) structure:
- Type (1 byte): Identifies the option
- Length (1 byte): Total option size including type and length bytes
- Data (variable): Option-specific payload
| Aspect | Single-Byte | Multi-Byte |
|---|---|---|
| Structure | Type only | Type + Length + Data |
| Size | 1 byte fixed | Variable (minimum 2 bytes) |
| Examples | EOL (0), NOP (1) | Record Route, Source Routing, Timestamp |
| Purpose | Padding and list termination | Functional capabilities |
| Parsing | Read 1 byte, done | Read type, read length, read (length-2) data bytes |
The Type Field Encoding
The 1-byte type field is not merely an identifier—it's a carefully encoded structure with three distinct subfields:
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| C |Class| Number |
+---+---+---+---+---+---+---+---+
|1b | 2b | 5 bits |
Bit 0 - Copy Flag (C):
0: Option is NOT copied to all fragments during fragmentation1: Option IS copied to every fragment
Bits 1-2 - Option Class:
00(0): Control options10(2): Debugging and measurement options01(1) and11(3): Reserved for future use
Bits 3-7 - Option Number:
- Identifies the specific option within its class
- Provides space for 32 options per class
The copy flag determines option behavior during fragmentation. If an option must be present in every fragment for proper interpretation (like Source Route), the copy flag is set. Options needed only by the first fragment (like Record Route progress) don't require copying.
| Option Name | Type Value (Binary) | Copy | Class | Number | Decimal |
|---|---|---|---|---|---|
| End of Options List | 00000000 | 0 | 00 | 00000 | 0 |
| No Operation | 00000001 | 0 | 00 | 00001 | 1 |
| Record Route | 00000111 | 0 | 00 | 00111 | 7 |
| Timestamp | 01000100 | 0 | 10 | 00100 | 68 |
| Loose Source Routing | 10000011 | 1 | 00 | 00011 | 131 |
| Strict Source Routing | 10001001 | 1 | 00 | 01001 | 137 |
Decoding Example:
Let's decode option type value 137 (0x89 in hexadecimal):
- Binary representation:
10001001 - Copy flag (bit 0):
1→ Option is copied to all fragments - Class (bits 1-2):
00→ Control option - Number (bits 3-7):
01001= 9 → Strict Source Routing
This encoding tells us that Strict Source Routing must be present in every fragment because routers along the path need routing instructions for each fragment they receive.
The Length Field Semantics
The length field in multi-byte options deserves careful attention because its interpretation differs from some other protocols.
Critical Point: Length Includes Type and Length Bytes
The length value indicates the total size of the option, including:
- 1 byte for the type field
- 1 byte for the length field itself
- Variable bytes for the data
Therefore:
- Minimum valid length is
2(type + length, no data) - Data payload size = Length - 2
A frequent bug in packet parsing code is treating the length field as the data-only length. If you read 'length' bytes of data after the length field, you'll read 2 bytes too many, corrupting your parse and potentially causing security vulnerabilities.
12345678910111213141516171819202122232425
// INCORRECT: Common mistake in option parsingvoid parse_option_wrong(uint8_t *option) { uint8_t type = option[0]; uint8_t length = option[1]; // Bug: Reading 'length' bytes of data reads 2 extra bytes! uint8_t data[length]; memcpy(data, &option[2], length); // WRONG!} // CORRECT: Proper option parsingvoid parse_option_correct(uint8_t *option) { uint8_t type = option[0]; uint8_t length = option[1]; // Validate minimum length if (length < 2) { // Invalid option - handle error return; } // Data length is total length minus type and length bytes uint8_t data_length = length - 2; uint8_t data[data_length]; memcpy(data, &option[2], data_length); // CORRECT!}End of Options List (EOL) - Type 0
The End of Options List (EOL) option, type value 0, is a single-byte option that marks the absolute end of the options area. After encountering EOL, no further option processing occurs—remaining bytes until the IHL-indicated header end are padding.
Key Characteristics:
- Type: 0 (binary: 00000000)
- Size: 1 byte
- Copy flag: 0 (not copied during fragmentation)
- Behavior: Terminates option parsing immediately
Usage Rules:
- EOL is only required if options don't naturally end at a 32-bit boundary
- After EOL, parsers ignore remaining bytes (treated as padding)
- Unlike NOP, EOL indicates "no more options exist" rather than "skip this byte"
EOL (End of Options List) terminates parsing entirely. NOP (No Operation) is just a 1-byte skip that allows parsing to continue. Using NOP where EOL is intended can cause security issues, as parsers may continue processing garbage data as options.
No Operation (NOP) - Type 1
The No Operation (NOP) option, type value 1, is a single-byte padding option used to align subsequent options on specific boundaries.
Key Characteristics:
- Type: 1 (binary: 00000001)
- Size: 1 byte
- Copy flag: 0 (not copied during fragmentation)
- Behavior: Parser skips this byte and continues processing
Primary Uses:
- Alignment: Align multi-byte options to 16-bit or 32-bit boundaries for efficient memory access
- Separation: Insert visual separation between options in debugging output
- Placeholder: Reserve space that might be filled later by intermediate devices
Example: Using NOP for 32-bit alignment Options area structure:Offset 0: Type = 1 (NOP) - 1 byte paddingOffset 1: Type = 1 (NOP) - 1 byte padding Offset 2: Type = 1 (NOP) - 1 byte paddingOffset 3: Type = 68 (Timestamp) Offset 4: Length = 12Offset 5-14: Timestamp data Without NOPs, Timestamp would start at offset 0.With NOPs, Timestamp is aligned to 32-bit boundary (offset 3). Benefits:- Faster memory access on aligned architectures- Cleaner debugging display- Predictable option positionsWhile alignment using NOP is optional, some systems perform better with aligned options. The Timestamp option, in particular, often benefits from 32-bit alignment since it contains 32-bit timestamp values. However, in memory-constrained scenarios, omitting alignment NOPs conserves the precious 40-byte options budget.
Option Processing by Routers
Options processing significantly impacts router performance and behavior. Unlike the fixed header fields, which can be processed in hardware at line rate, options require software handling and careful security consideration.
Processing Flow:
- Detection: Router checks IHL field; if > 5, options are present
- Parsing: Options area is scanned byte-by-byte
- Interpretation: Each option is processed according to its type
- Action: Router performs required actions (record address, follow route, etc.)
- Forwarding: Packet continues with potentially modified options
Packets with options bypass hardware fast-path processing on most modern routers. A router that handles millions of packets per second in fast-path may only handle thousands in slow-path. This performance differential is why options are rarely used in production traffic and why many networks filter or drop packets containing options.
Security Considerations:
IPv4 options have significant security implications:
- Source Routing Abuse: Attackers can bypass firewall rules by specifying routes that avoid security devices
- Reconnaissance: Record Route and Timestamp reveal network topology information
- DoS Potential: Complex options processing can exhaust router CPU
- Filtering Policies: Many enterprise and ISP networks now block packets with options
RFC 7126 (Internet Architecture Board) recommends filtering source-routed packets at network borders.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.