RFC 2507

IP Header Compression

๐Ÿ“… published February 1999, from ietf

RFC 2507: IP Header Compression ๐ŸŽ€

bestie, this one is a whole vibe ๐Ÿ’– It's from February 1999, it's a Standards Track doc (so it's real, official protocol stuff, not just a suggestion ๐Ÿ‘‘), and it came from three people at Lulea University of Technology, with two of them at SICS and one at Telia Research AB. The Network Working Group published it. It doesn't obsolete or update any other RFCs, because the title block doesn't list any.

The authors: M. Degermark (Lulea University of Technology/SICS), B. Nordgren (Lulea University of Technology/Telia Research AB), and S. Pink (Lulea University of Technology/SICS). ๐Ÿงš


Status of this Memo ๐Ÿ“œ

okay so this section tells you what kind of document this is ๐Ÿ’… It's an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements ๐Ÿ’ฌ If you want to know where this protocol stands on the standardization ladder, check the current edition of the "Internet Official Protocol Standards" (STD 1) ๐Ÿ” And the best part? Distribution of this memo is unlimited ๐ŸŒˆ

Copyright (C) The Internet Society (1999). All Rights Reserved. the legal bit, but it's giving very official ๐Ÿ™ˆ

Abstract ๐Ÿฆ‹

this doc is all about compressing multiple IP headers, plus TCP and UDP headers, on each hop over point to point links โœจ The methods work on IPv6 base and extension headers, IPv4 headers, TCP and UDP headers, and encapsulated IPv6 and IPv4 headers. So basically a lot of headers, all getting the glow-up treatment ๐Ÿ’–

typical UDP or TCP packets can have their headers squished down to 4-7 octets, and that count includes the 2 octet UDP or TCP checksum ๐Ÿ˜ญ That mostly gets rid of the bad impact of big IP headers and lets you use bandwidth efficiently on low and medium speed links ๐Ÿ”ฅ

the algorithms are designed specifically to work well over links with real packet-loss rates, and several wireless and modem technologies end up with links like that ๐Ÿ“ก

Table of Contents ๐Ÿ“š

   1.  Introduction..............................................3
   2.  Terminology...............................................5
   3.  Compression method........................................7
        3.1.  Packet types.......................................8
        3.2.  Lost packets in TCP packet streams.................9
        3.3.  Lost packets in UDP and non-TCP packet streams....10
   4.  Grouping packets into packet streams.....................14

        4.1.  Guidelines for grouping packets...................15
   5.  Size Issues..............................................16
        5.1.  Context identifiers...............................16
        5.2.  Size of the context...............................17
        5.3.  Size of full headers..............................18
           5.3.1.  Length fields in full TCP headers............19
           5.3.2.  Length fields in full non-TCP headers........19
   6.  Compressed Header Formats................................20
   7.  Compression of subheaders................................22
        7.1.  IPv6 Header.......................................24
        7.2.  IPv6 Extension Headers............................25
        7.3.  Options...........................................25
        7.4.  Hop-by-hop Options Header.........................26
        7.5.  Routing Header....................................26
        7.6.  Fragment Header...................................27
        7.7.  Destination Options Header........................28
        7.8.  No Next Header....................................29
        7.9.  Authentication Header.............................29
        7.10. Encapsulating Security Payload Header.............29
        7.11. UDP Header........................................30
        7.12. TCP Header........................................30
        7.13. IPv4 Header.......................................33
        7.14  Minimal Encapsulation header......................34
   8.  Changing context identifiers.............................35
   9.  Rules for dropping or temporarily storing packets........35
   10. Low-loss header compression for TCP .....................36
        10.1.  The "twice" algorithm............................37
        10.2.  Header Requests..................................37
   11. Links that reorder packets...............................38
        11.1.  Reordering in non-TCP packet streams.............39
        11.2.  Reordering in TCP packet streams.................39
   12. Hooks for additional header compression..................40
   13. Demultiplexing...........................................41
   14. Configuration Parameters.................................42
   15. Implementation Status....................................43
   16. Acknowledgments..........................................44
   17. Security Considerations..................................44
   18. Authors' Addresses.......................................45
   19. References...............................................46
   20. Full Copyright Statement.................................47

1. Introduction โœจ

okay so there are a bunch of reasons you'd want header compression on low- or medium-speed links ๐Ÿ’… Header compression can:

  • Improve interactive response time โฑ๏ธ

on really slow links, echoing your typed characters can take longer than 100-200 ms just because the big headers take forever to send ๐Ÿ˜ญ 100-200 ms is the most time people can handle before a system feels sluggish, so that's a big deal ๐Ÿ™ˆ

  • Allow using small packets for bulk data with good line efficiency ๐Ÿ“ฆ

this matters when interactive traffic (like Telnet) and bulk traffic (like FTP) are mixed together ๐Ÿ’– bulk data should ride in small packets, so an interactive packet doesn't wait forever when it gets stuck behind a big bulk one ๐Ÿงš

using small packets for the FTP traffic in this case is a global fix for a local problem ๐Ÿ’€ It makes the network deal with a ton of small packets, which adds load. A better move might be to locally fragment the large packets over the slow link ๐Ÿ”ฅ

  • Allow using small packets for delay sensitive low data-rate traffic ๐ŸŽค

for stuff like voice, filling a packet with data takes a while if the packets are large, so small packets are preferred to get low end-to-end delay ๐Ÿ’œ without header compression, the smallest possible IPv6/UDP headers (48 octets) eat 19.2 kbit/s at a packet rate of 50 packets/s ๐Ÿ˜ญ 50 packets/s is the same as having 20 ms worth of voice samples in each packet. IPv4/UDP headers eat 11.2 kbit/s at 50 packets/s ๐Ÿ’€ Tunneling or routing headers, for example to support mobility, add another 10-20 kbit/s to the header bandwidth. Compare that to the actual sound samples, like 13 kbit/s with GSM encoding, and yeah, headers are a whole thing โœจ Header compression can cut the bandwidth needed for headers a lot, to about 1.7 kbit/s in the example. That makes higher quality voice possible over 14.4 and 28.8 kbit/s modems ๐ŸŽ€

  • Decrease header overhead. ๐Ÿ“‰

a common TCP segment size for bulk transfers over medium-speed links is 512 octets today ๐Ÿ“ When TCP segments are tunneled, for example because Mobile IP is used, the IPv6/IPv6/TCP header is 100 octets ๐Ÿ’€ Header compression drops the header overhead for IPv6/TCP from 19.5 per cent to less than 1 per cent, and for tunneled IPv4/TCP from 11.7 to less than 1 per cent ๐Ÿ”ฅ That's a big win at line speeds as high as a few Mbit/s ๐Ÿ‘‘

the IPv6 specification prescribes path MTU discovery, so with IPv6, bulk TCP transfers should use segments larger than 512 octets when possible ๐ŸŒˆ Even so, with 1400 octet segments (RFC 894 Ethernet encapsulation allows 1500 octet payloads, of which 100 octets are used for IP headers), header compression still takes IPv6 header overhead from 7.1% down to 0.4% ๐Ÿซถ

  • Reduce packet loss rate over lossy links. ๐Ÿ“‰

fewer bits go in each packet, so the packet loss rate is lower for a given bit-error rate ๐Ÿ’– That means higher TCP throughput, because the sending window can open up more between losses, and fewer lost packets for UDP โœจ

the mechanisms here are meant for a point-to-point link, but they were designed with room for extensions to multi-access links and multicast ๐Ÿฆ‹

headers that can be compressed include TCP, UDP, IPv4, and IPv6 base and extension headers ๐Ÿงš For TCP packets, the mechanisms of Van Jacobson [RFC-1144] are used to recover from loss. Two extra mechanisms that make VJ header compression more efficient over lossy links are also described ๐Ÿ’… For non-TCP packets, compression slow-start and periodic header refreshes keep the periods of packet discard after a context-changing header is lost to a minimum ๐Ÿซถ There are hooks for adding header compression schemes on top of UDP, like compressing RTP headers ๐ŸŽ€

header compression relies on lots of fields staying constant, or changing seldom, in consecutive packets from the same packet stream ๐Ÿ’œ Fields that don't change between packets don't need to be sent at all ๐Ÿ™Œ Fields that change often with small and/or predictable values, e.g., TCP sequence numbers, can be encoded incrementally, so the number of bits they need drops a lot ๐Ÿ”ฅ Only fields that change often and randomly, e.g., checksums or authentication data, need to go in every header ๐Ÿ˜ญ

the general principle is to occasionally send a packet with a full header ๐ŸŒธ Later compressed headers refer to the context that the full header set up, and they may carry incremental changes to that context ๐Ÿ’–

this scheme doesn't require that all packets in the same stream pass over the compressed link ๐Ÿฆ‹ However, for TCP streams the difference between subsequent headers can get more irregular, and the compression rate can drop ๐Ÿ’€ It's also not required that corresponding TCP data and acknowledgment packets cross the link in opposite directions โœจ

this header compression scheme is useful on first-hop or last-hop links, and on links in the middle of the network too ๐ŸŒˆ When many packet streams (several hundred) go over the link, a phenomenon that could be called CID thrashing can happen ๐Ÿ˜ญ Headers seldom match an existing context, so they have to be sent uncompressed or as full headers ๐Ÿ™ˆ It's up to the implementation to use techniques like hysteresis so the packet streams with the highest compression rates keep their context ๐Ÿ‘‘ Those techniques are more likely to be needed in the middle of the network ๐Ÿงš

2. Terminology โœจ

okay so this section is basically our glossary, bestie ๐Ÿ“– it explains some terms we're gonna use the whole doc.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. ๐ŸŽ€

Subheader

An IPv6 base header, an IPv6 extension header, an IPv4 header, a UDP header, or a TCP header. ๐Ÿงš

Header

A chain of subheaders. ๐Ÿ”—

Compress

The act of reducing the size of a header by removing header fields or reducing the size of header fields. This is done in a way such that a decompressor can reconstruct the header if its context state is identical to the context state used when compressing the header. ๐Ÿ’…

Decompress

The act of reconstructing a compressed header. โœจ

Context identifier (CID)

A small unique number identifying the context that should be used to decompress a compressed header. Carried in full headers and compressed headers. ๐Ÿ†”

Context

The state which the compressor uses to compress a header and the decompressor uses to decompress a header. The context is the uncompressed version of the last header sent (compressor) or received (decompressor) over the link, except for fields in the header that are included "as-is" in compressed headers or can be inferred from, e.g., the size of the link-level frame.

The context for a packet stream is associated with a context identifier. The context for non-TCP packet streams is also associated with a generation. ๐ŸŒธ

Generation

For non-TCP packet streams, each new version of the context for a given CID is associated with a generation: a small number that is incremented whenever the context associated with that CID changes. Carried by full and compressed non-TCP headers. ๐Ÿ”ข

Packet stream

A sequence of packets whose headers are similar and share context. For example, headers in a TCP packet stream have the same source and final destination address, and the same port numbers in the TCP header. Similarly, headers in a UDP packet stream have the same source and destination address, and the same port numbers in the UDP header. ๐ŸŒŠ

Full header (header refresh)

An uncompressed header that updates or refreshes the context for a packet stream. It carries a CID that will be used to identify the context.

Full headers for non-TCP packet streams also carry the generation of the context they update or refresh. ๐Ÿ”„

Regular header

A normal, uncompressed, header. Does not carry CID or generation association. ๐Ÿ™‚

Incorrect decompression

When a compressed and then decompressed header is different from the uncompressed header. Usually due to mismatching context between the compressor and decompressor or bit errors during transmission of the compressed header. ๐Ÿ’€

Differential coding

A compression technique where the compressed value of a header field is the difference between the current value of the field and the value of the same field in the previous header belonging to the same packet stream. A decompressor can thus obtain the value of the field by adding the value in the compressed header to its context. This technique is used for TCP streams but not for non-TCP streams. ๐Ÿงฎ


3. Compression method ๐Ÿ—œ๏ธ

Much of the header information stays the same over the life-time of a packet stream. For non-TCP packet streams almost all fields of the headers are constant. For TCP many fields are constant and others change with small and predictable values. ๐Ÿฅฐ

To initiate compression of the headers of a packet stream, a full header carrying a context identifier, CID, is transmitted over the link. The compressor and decompressor store most fields of this full header as context. The context consists of the fields of the header whose values are constant and thus need not be sent over the link at all, or change little between consecutive headers so that it uses fewer bits to send the difference from the previous value compared to sending the absolute value. ๐Ÿ“ฆ

Any change in fields that are expected to be constant in a packet stream will cause the compressor to send a full header again to update the context at the decompressor. As long as the context is the same at compressor and decompressor, headers can be decompressed to be exactly as they were before compression. However, if a full header or compressed header is lost during transmission, the context of the decompressor may become obsolete as it is not updated properly. Compressed headers will then be decompressed incorrectly. ๐Ÿ˜ญ

IPv6 is not meant to be used over links that can deliver a significant fraction of damaged packets to the IPv6 module. This means that links must have a very low bit-error rate or that link-level frames must be protected by strong checksums, forward error correction or something of that nature. Header compression SHOULD not be used for IPv4 without strong link-level checksums. Damaged frames will thus be discarded by the link layer. The link layer implementation might indicate to the header compression module that a frame was damaged, but it cannot say what packet stream it belonged to as it might be the CID that is damaged. Moreover, frames may disappear without the link layer implementation's knowledge, for example if the link is a multi-hop link where frames can be dropped due to congestion at each hop. The kind of link errors that a header compression module should deal with and protect against will thus be packet loss. ๐Ÿ›ก๏ธ

ngl this part is the big one: if your link is noisy, header compression gets messy fast. strong checksums or a super low bit-error rate are the move ๐Ÿšจ

So a header compression scheme needs mechanisms to update the context at the decompressor and to detect or avoid incorrect decompression. These mechanisms are very different for TCP and non-TCP streams, and are described in sections 3.2 and 3.3. ๐Ÿง 

The compression mechanisms in this document assume that packets are not reordered between the compressor and decompressor. If the link does reorder, section 11 describes mechanisms for ordering the packets before decompression. It is also assumed that the link-layer implementation can provide the length of packets, and that there is no padding in UDP packets or tunneled packets. ๐Ÿ“

3.1. Packet types ๐Ÿท๏ธ

This compression method uses four packet types in addition to the IPv4 and IPv6 packet types. The combination of link-level packet type and the value of the first four bits of the packet uniquely determines the packet type. Details on how these packet types are represented are in section 13. ๐ŸŽฏ

  • FULL_HEADER - indicates a packet with an uncompressed header, including a CID and, if not a TCP packet, a generation. It establishes or refreshes the context for the packet stream identified by the CID. ๐Ÿซถ
  • COMPRESSED_NON_TCP - indicates a non-TCP packet with a compressed header. The compressed header consists of a CID identifying what context to use for decompression, a generation to detect an inconsistent context and the randomly changing fields of the header. ๐ŸŽฒ
  • COMPRESSED_TCP - indicates a packet with a compressed TCP header, containing a CID, a flag octet identifying what fields have changed, and the changed fields encoded as the difference from the previous value. ๐ŸŒˆ
  • COMPRESSED_TCP_NODELTA - indicates a packet with a compressed TCP header where all fields that are normally sent as the difference to the previous value are instead sent as-is. This packet type is only sent as the response to a header request from the decompressor. It must not be sent as the result of a retransmission. ๐Ÿ™ˆ

In addition to the packet types used for compression, regular IPv4 and IPv6 packets are used whenever a compressor decides to not compress a packet. An additional packet type may be used to speed up repair of TCP streams over links where the decompressor can send packets to the compressor. ๐Ÿš€

  • CONTEXT_STATE - indicates a special packet sent from the decompressor to the compressor to communicate a list of (TCP) CIDs for which synchronization has been lost. This packet is only sent over a single link so it requires no IP header. The format is shown in section 10.2. ๐Ÿงšโ€โ™€๏ธ

3.2. Lost packets in TCP packet streams ๐Ÿ’”

Since TCP headers are compressed using the difference from the previous TCP header, loss of a packet with a compressed or full header will cause subsequent compressed headers to be decompressed incorrectly because the context used for decompression was not incremented properly. ๐Ÿ˜ฉ

Loss of a compressed TCP header will cause the TCP sequence numbers of subsequently decompressed TCP headers to be off by k, where k is the size of the lost segment. Such incorrectly decompressed TCP headers will be discarded by the TCP receiver as the TCP checksum reliably catches "off-by-k" errors in the sequence numbers for plausible k. ๐Ÿ”

TCP's repair mechanisms will eventually retransmit the discarded segment and the compressor peeks into the TCP headers to detect when TCP retransmits. When this happens, the compressor sends a full header on the assumption that the retransmission was due to mismatching compression state at the decompressor. [RFC-1144] has a good explanation of this mechanism. ๐Ÿ“š

The mechanisms of section 10 should be used to speed up the repair of the context. This is important over medium speed links with high packet loss rates, for example wireless. Losing a timeout's worth of packets due to inconsistent context after each packet lost over the link is not acceptable, especially when the TCP connection is over the wide area. ๐ŸŒโœจ

3.3. Lost packets in UDP and other non-TCP packet streams โœจ

Okay so, UDP and other non-TCP packets are lowkey not as protected by checksums as TCP packets are ๐Ÿ˜ฌ. TCP has sequence numbers that go "off-by-k" and basically guarantee a failed checksum when a header gets decompressed wrong. UDP doesn't have anything like that. The UDP checksum only covers the payload, the UDP header, and the pseudo header. That pseudo header includes the source and destination addresses, the transport protocol type, and the length of the transport packet. Apart from those fields, big chunks of the IPv6 header aren't covered by the UDP checksum. And other non-TCP headers don't have checksums at all, fragments for example ๐Ÿ’€.

So to safely avoid decompressing non-TCP headers incorrectly, each version of the context for a non-TCP packet stream gets identified by a generation, which is a small number carried by the full headers that set up and refresh the context ๐ŸŽ€. Compressed headers carry the generation value of the context that was used to compress them. When a decompressor sees a compressed header whose generation doesn't match its context for that packet stream, the context is out of date. The packet must be discarded or stored until a full header sets up the correct context ๐Ÿ™ˆ.

Differential coding isn't used for non-TCP streams, so compressed non-TCP headers don't change the context. That means losing a compressed header doesn't break later packets with compressed headers ๐Ÿฆ‹. The generation also only changes when a full header's context is different from the previous full header's context. So losing a full header only makes the decompressor's context obsolete when that full header would actually have changed things โœจ.

The generation field is 6 bits long, so the generation value wraps around after 64 changes to the context ๐Ÿ”. To avoid incorrect decompression after error bursts or other temporary disruptions, the compressor must not reuse the same generation value in less time than MIN_WRAP seconds. A decompressor that has been disconnected for MIN_WRAP seconds or more must wait for the next full header before decompressing. A compressor must wait at least MIN_WRAP seconds after booting before compressing non-TCP headers. Rather than reusing a generation value too soon, a compressor may switch to another CID or send regular headers until MIN_WRAP seconds have passed. The value of MIN_WRAP is found in section 14 ๐Ÿ“–.

3.3.1. Compression Slow-Start ๐Ÿฃ

To help the decompressor bounce back quickly from losing a full header that would have changed the context, full headers get sent periodically, with an exponentially increasing period after a change in the context ๐Ÿš€. This skips the message exchange between compressor and decompressor that other schemes use, like the one in [RFC-1553]. Those exchanges are costly for wireless mobiles, since the transmitter eats more power and switching between sending and receiving adds delay ๐Ÿ”‹. Plus, techniques that need message exchanges can't be used over simplex links like direct-broadcast satellite channels or cable TV systems, and they're hard to adapt to multicast over multi-access links ๐Ÿ“ก.

    |.|..|....|........|................|..............................
    ^
    Change   Sent packets: | with full header, . with compressed header

The picture shows how packets are sent after a change ๐Ÿ‘€. The compressor keeps a variable for each non-TCP packet stream, F_PERIOD, which tracks how many compressed headers may be sent between full headers. When the headers of a non-TCP packet stream change so its context changes, a full header is sent and F_PERIOD is set to one. After F_PERIOD compressed headers have been sent, a full header is sent. During compression slow-start, F_PERIOD is doubled each time a full header is sent ๐Ÿ’–.

3.3.2. Periodic Header Refreshes ๐Ÿ”„

To avoid losing too many packets if a receiver has lost its context, there's an upper limit, F_MAX_PERIOD, on how many non-TCP packets with compressed headers can be sent between header refreshes ๐Ÿ›‘. If a packet is about to be sent and F_MAX_PERIOD compressed headers have gone out since the last full header for this packet stream was sent, a full header must be sent.

To avoid long periods of disconnection for low data rate packet streams, there's also an upper bound, F_MAX_TIME, on the time between full headers in a non-TCP packet stream โฐ. If a packet is about to be sent and more than F_MAX_TIME seconds have passed since the last full header was sent for this packet stream, a full header must be sent. The values of F_MAX_PERIOD and F_MAX_TIME are found in section 14.

3.3.3. Rules for sending Full Headers ๐Ÿง 

The following pseudo code can be used by the compressor to decide when to send a full header for a non-TCP packet stream. The code maintains two variables:

         C_NUM       -- a count of the number of compressed headers sent
                        since the last full header was sent.
         F_LAST      -- the time of sending the last full header.

It uses these functions:

         current_time()       return the current time
         min(a,b)             return the smallest of a and b

The procedures send_full_header(), increment_generation_value(), and send_compressed_header() do the obvious thing ๐Ÿ’….

         if ( <this header changes the context> )

             C_NUM := 0;
             F_LAST := current_time();
             F_PERIOD := 1;
             increment_generation_value();
             send_full_header();

         elseif ( C_NUM >= F_PERIOD )

             C_NUM := 0;
             F_LAST := current_time();
             F_PERIOD := min(2 * F_PERIOD, F_MAX_PERIOD);
             send_full_header();

         elseif ( current_time() > F_LAST + F_MAX_TIME )

             C_NUM := 0;
             F_LAST := current_time();
             send_full_header();

         else

             C_NUM := C_NUM + 1
             send_compressed_header();

         endif

3.3.4. Cost of sending Header Refreshes ๐Ÿ’ธ

If every f'th packet carries a full header, H is the size of a full header, and C is the size of a compressed header, the average header size is:

                 (H-C)/f + C

For f > 1, the average header size is (H-C)/f larger than a compressed header.

In a diagram where the average header size is plotted for various f values, there's a distinct knee in the curve. In other words, there's a limit beyond which further increasing f gives diminishing returns ๐Ÿ“‰. F_MAX_PERIOD should be chosen to be a frequency well to the right of the knee of the curve. For typical sizes of H and C, say 48 octets for the full header (IPv6/UDP) and 4 octets for the compressed header, setting F_MAX_PERIOD > 44 means that full headers will contribute less than an octet to the average header size. With a four-address routing header, F_MAX_PERIOD > 115 will have the same effect.

The default F_MAX_PERIOD value of 256 (section 14) puts the full header frequency well to the right of the knee. It means full headers will typically contribute considerably less than an octet to the average header size ๐Ÿฅฐ. For H = 48 and C = 4, full headers contribute about 1.4 bits to the average header size once the steady-state header refresh frequency set by the default F_MAX_PERIOD is reached. 1.4 bits is a very small overhead.

After a change in the context, the exponential backoff scheme will initially send full headers frequently. The default F_MAX_PERIOD will be reached after nine full headers and 255 compressed headers have been sent. That's equivalent to a little over 5 seconds for a typical voice stream with 20 ms worth of voice samples per packet ๐ŸŽค.

During the whole backoff period, full headers contribute 1.5 octets to the average header size when H = 48 and C = 4. For 20 ms voice samples, it takes less than 1.3 seconds until full headers contribute less than one octet to the average header size. During these initial 1.3 seconds, full headers add less than 4 octets to the average header size. The cost of the exponential backoff is not great, and since the headers of non-TCP packet streams are expected to change seldomly, the cost gets amortized over a long time โญ.

The bandwidth cost of header refreshes is higher than similar costs for hard state schemes like [RFC-1553]. In those schemes, full headers must be acknowledged by the decompressor before compressed headers may be sent. Such schemes typically send one full header plus a few control messages when the context changes. Hard state schemes require more types of protocol messages, and an exchange of messages is necessary. They also need to deal explicitly with various error conditions that soft state handles automatically, like one party disappearing unexpectedly. That's a common situation on wireless links, where mobiles may go out of range of the base station ๐Ÿ“ถ.

The major advantage of the soft state scheme is that no handshakes are needed between compressor and decompressor, so the scheme can be used over simplex links ๐Ÿ™Œ. Its bandwidth costs are higher than those of hard state schemes, but the simplicity of the decompressor, the simplicity of the protocol, and the lack of handshakes between compressor and decompressor make this small cost worth it. Soft state schemes are also more easily extended to multicast over multi-access links, such as radio links ๐Ÿ“ป.

4. Grouping packets into packet streams ๐Ÿงบ

This section explains how packets MAY be grouped together into packet streams for compression. To get the best compression rates, packets SHOULD be grouped together so that packets in the same packet stream have similar headers. If this grouping fails, header compression performance will be bad. The compression algorithm can rarely use the existing context for the packet stream, so full headers have to be sent frequently ๐Ÿ˜ฉ.

Grouping is done by the compressor. A compressor may use whatever criterion it finds appropriate to group packets into packet streams. To determine which packet stream a packet belongs to, a compressor MAY:

a) examine the compressible chain of subheaders (see section 7),

b) examine the contents of an upper layer protocol header that follows the compressible chain of subheaders, for example ICMP headers, DVMRP headers, or tunneled IPX headers,

c) use information obtained from a resource manager, for example if a resource manager requests compression for a particular packet stream and provides a way to identify packets belonging to that packet stream,

d) use any other relevant information. For example, if routes flap and the hop limit (TTL) field in a packet stream changes frequently between n and n+k, a compressor may choose to group the packets into two different packet streams ๐Ÿ”€.

A compressor is also free not to group packets into packet streams for compression. In that case, some packets keep their regular headers and pass through unmodified ๐ŸŒธ.

As long as the rules for when to send full headers for a non-TCP packet stream are followed, and subheaders are compressed as specified in this document, the decompressor is able to reconstruct a compressed header correctly, no matter how packets are grouped into packet streams ๐Ÿซถ.

4.1. Guidelines for grouping packets ๐Ÿงš

Okay so this part is about how a compressor sorts packets into packet streams ๐ŸŽ€ We give OPTIONAL guidelines for it, so you can do your own thing if you want ๐Ÿ’…

Defining fields ๐Ÿ’–

The defining fields of a header should be present and identical in all packets in the same packet stream โœจ These are the fields marked DEF in section 7. They include the flow label, the source and destination addresses of IP headers, the final destination address in routing headers, the next header fields (for IPv6), the protocol field (IPv4), port numbers (UDP and TCP), and the SPI in authentication and encryption headers ๐Ÿ”

Fragmented packets ๐Ÿงฉ

Fragmented and unfragmented packets should never be grouped together in the same packet stream ๐Ÿ™ˆ The Identification field of the Fragment header or IPv4 header should not be used to identify the packet stream. If it was, the first fragment of a new packet would cause a compression slow-start ๐Ÿ’€

No field after a Fragment Header, or an IPv4 header for a fragment, should be used for grouping purposes โœจ

Upper protocol identification ๐Ÿ‘‘

The first next header field that identifies a header not described in section 7 should be used to identify packet streams. In other words, all packets with the same DEF fields and the same upper protocol should be grouped together ๐Ÿซถ

TTL field (Hop Limit field) ๐Ÿฆ‹

A sophisticated implementation might keep an eye on the TTL (Hop Limit) field. If it changes frequently, the implementation can use it as a DEF field. This can happen when there are frequent route flaps, so that packets travel different paths through the internet ๐ŸŒˆ

Traffic Class field (IPv6), Type of Service field (IPv4) ๐Ÿ“

The Traffic Class field of the IPv6 header and the Type of Service field of the IPv4 header might change frequently between packets that otherwise have identical DEF fields. A sophisticated implementation should watch out for this and be ready to use these fields as defining fields ๐Ÿ‘€

Tunneled packets ๐Ÿš‡

When IP packets are tunneled, they are encapsulated with an additional IP header at the tunnel entry point and then sent to the tunnel endpoint. To group these packets into packet streams, the inner headers should also be examined to work out the packet stream. If this is not done, full headers will be sent each time the headers of the inner IP packet change ๐Ÿ˜ญ So when a packet is tunneled, the identifying fields of the inner subheaders should be considered as well as the identifying fields of the initial IP header ๐ŸŽ

An implementation can use other fields for identification than the ones described here. If too many fields are used for identification, performance might suffer, because more CIDs will be used and the wrong CIDs might be reused when new flows need CIDs. If too few fields are used for identification, performance might suffer, because the context changes too often ๐Ÿ“‰

We stress that these guidelines are educated guesses. When IPv6 is widely deployed and IPv6 traffic can be analyzed, we might find that other grouping algorithms perform better ๐Ÿ” We also stress that if the grouping fails, the result will be bad performance but not incorrect decompression. The decompressor can do its task regardless of how the grouping algorithm works ๐Ÿซถ


5. Size Issues ๐Ÿ“

5.1. Context Identifiers ๐Ÿชช

Context identifiers can be 8 or 16 bits long. Their size is not relevant for finding the context. An 8-bit CID with value two and a 16-bit CID with value two are equivalent ๐Ÿ’…

The CID spaces for TCP and non-TCP are separate, so a TCP CID and a non-TCP CID never identify the same context, even if they have the same value ๐Ÿ™Œ This doubles the available CID space while using the same number of bits for CIDs. It is always possible to tell whether a full or compressed header is for a TCP or non-TCP packet, so no mixups can occur ๐ŸŽ€

Non-TCP compressed headers encode the size of the CID using one bit in the second octet of the compressed header. The 8-bit CID allows a minimum compressed header size of 2 octets for non-TCP packets. The CID uses the first octet, and the size bit and the 6-bit Generation value fit in the second octet โœจ

For TCP, the only available CID size is 8 bits, as in [RFC-1144]. 8 bits is probably sufficient, as TCP connections are always point-to-point ๐Ÿงธ

The 16-bit CID size may not be needed for point-to-point links. It is intended for use on multi-access links, where a larger CID space may be needed for efficient selection of CIDs ๐Ÿ›ฃ๏ธ

The major difficulty with multi-access links is that several compressors share the CID space of a decompressor. CIDs can no longer be selected independently by the compressors, because collisions may occur ๐Ÿ˜ฌ This problem may be resolved by letting the decompressors have a separate CID space for each compressor. Having separate CID spaces requires that decompressors can identify which compressor sent the compressed packet, perhaps by using link-layer information about who sent the link-layer frame. If such information is not available, all compressors on the multi-access link may be enumerated, automatically or otherwise, and supply their number as part of the CID. This latter method requires a large CID space ๐Ÿ”ข

5.2. Size of the context ๐Ÿง 

The size of the context SHOULD be limited, to simplify implementation of the compressor and decompressor and to put a limit on their memory requirements ๐Ÿ’พ However, there is no upper limit on the size of an IPv6 header, because the chain of extension headers can be arbitrarily long. This is a problem, as the context is essentially a stored header ๐Ÿ˜ต

The configurable parameter MAX_HEADER (see section 14) represents the maximum size of the context, expressed as the maximum sized header that can be stored as context. When a header is larger than MAX_HEADER, only part of it is stored as context. An implementation MUST NOT compress more than the initial MAX_HEADER octets of a header. An implementation MUST NOT partially compress a subheader ๐Ÿšซ

So the part of the header that is stored as context and compressed is the longest initial sequence of entire subheaders that is not larger than MAX_HEADER octets ๐Ÿงฉ

5.3. Size of full headers ๐Ÿ“ฆ

It is desirable to avoid increasing the size of packets with full headers beyond their original size, as their size may be optimized for the MTU of the link. Since we assume that the link layer implementation provides the length of packets, we can use the length fields in full headers to pass the values of the CID and the generation to the decompressor ๐Ÿช„

This requires that the link layer must not add padding to the payload, at least not padding that can be delivered to the destination link user. It is also required that no extra padding is added after UDP data or in tunneled packets. This allows values of length fields to be calculated from the length of headers and the length of the link-layer frame ๐Ÿงฎ

The generation requires one octet, and the CID may require up to 2 octets. There are length fields of 2 octets in the IPv6 Base Header, the IPv4 header, and the UDP header ๐Ÿ“

A full TCP header will thus have at least 2 octets available in the IP header to pass the 8-bit CID, which is sufficient. There will be more than two octets available if there is more than one IP header ๐Ÿฅฐ

[RFC-1144] uses the 8-bit Protocol field of the IPv4 header to pass the CID. We cannot use the corresponding method, because the sequence of IPv6 extension headers is not fixed and CID values are not disjoint from the legal values of Next Header fields ๐Ÿ™…โ€โ™€๏ธ

An IPv6/UDP or IPv4/UDP packet will have 4 octets available to pass the generation and the CID, so all CID sizes may be used. Fragmented or encrypted packet streams may have only 2 octets available to pass the generation and CID. Thus, 8-bit CIDs may be the only CID sizes that can be used for such packet streams ๐Ÿ”’ When IPv6/IPv4 or IPv4/IPv6 tunneling is used, there will be at least 4 octets available, and both CID sizes may be used ๐Ÿš‡

The generation value is passed in the higher order octet of the first length field in the full header. When only one length field is available, the 8-bit CID is passed in the low order octet. When two length fields are available, the lowest two octets of the CID are passed in the second length field, and the low order octet of the first length field carries the highest octet of the CID ๐Ÿซง

5.3.1. Use of length fields in full TCP headers ๐Ÿงต

Use of first length field:

                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                    Length field   | LSB of pkt nr |      CID      |
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Use of second length field if available:

                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
              Second length field  | MSB of pkt nr |       0       |
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Pkt nr is short for packet sequence number, described in section 11.2 ๐Ÿ”ข

5.3.2. Use of length fields in full non-TCP headers ๐Ÿงถ

Full non-TCP headers with 8-bit CID:

                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
              First length field   |0|D| Generation|      CID      |
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Second length field (if avail.) |       0       | Data (if D=1) |
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Full non-TCP headers with 16-bit CID:

                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
              First length field   |1|D| Generation| Data (if D=1) |
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
              Second length field  |              CID              |
                                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The first bit in the first length field indicates the length of the CID. The Data field is zero if D is zero. The use of the D bit and the Data field is explained in section 12 ๐ŸŒธ

6. Compressed Header Formats ๐Ÿ’–

Okay bestie, this section leans on some terminology (DELTA, RANDOM) that doesn't get defined until section 7, so if it feels a little ahead of you, that's normal ๐Ÿงš

a) COMPRESSED_TCP format (similar to [RFC 1144]) ๐Ÿฆ‹

+-+-+-+-+-+-+-+-+
|      CID      |
+-+-+-+-+-+-+-+-+
|R O I P S A W U|
+-+-+-+-+-+-+-+-+
|               |
+  TCP Checksum +
|               |
+-+-+-+-+-+-+-+-+
| RANDOM fields, if any (see section 7)   (implied)
 - - - - - - - -
| R-octet       |                         (if R=1)
 - - - - - - - -
| Urgent Pointer Value                    (if U=1)
 - - - - - - - -
| Window Delta                            (if W=1)
 - - - - - - - -
| Acknowledgment Number Delta             (if A=1)
 - - - - - - - -
| Sequence Number Delta                   (if S=1)
 - - - - - - - -
| IPv4 Identification Delta               (if I=1)
 - - - - - - - -
|  Options                                (if O=1)
 - - - - - - - -

The latter flags in the second octet (IPSAWU) mean the same thing as they do in [RFC-1144], whether the TCP segments ride on IPv6 or IPv4 ๐ŸŒธ The C bit is gone because the CID is always there now. The context tied to the CID keeps track of the IP version and which RANDOM fields are present. The order of the delta fields is exactly the same as in [RFC-1144]. An implementation will typically scan the context from the beginning and slot the RANDOM fields in, in order. That means the RANDOM fields go before the DELTA fields of the TCP header, in the same order they show up in the original uncompressed header โœจ

The I flag is zero unless an IPv4 header comes right before the TCP header. In that case the combined IPv4/TCP header gets compressed as one unit, as described in [RFC-1144]. Identification fields in IPv4 headers that aren't directly followed by a TCP header are RANDOM ๐Ÿ’…

If the O flag is set, the Options of the TCP header weren't the same as in the previous header. The whole Option field gets placed last in the compressed TCP header ๐ŸŽ€

If the R flag is set, something was different between the context and either the Reserved field (6 bits) in the TCP header, or bit 6 or 7 of the TOS octet (Traffic Class octet) in an IPv4 header (IPv6 header) that comes right before the TCP header. An octet with the actual values of the Reserved field and bits 6 and 7 of the TOS or Traffic Class field then gets placed right after the RANDOM fields. Bits 0-5 of that passed octet hold the actual Reserved field value, and bits 6 and 7 hold the actual values of bits 6 and 7 in the TOS or Traffic Class field. If there's no IP header before it, bits 6 and 7 are 0. The octet passed with the R flag MUST NOT update the context ๐Ÿšซ

NOTE: The R-octet does not update the context because if it did, the nTCP checksum would not guard the receiving TCP from erroneously decompressed headers. Bits 6 and 7 of the TOS octet or Traffic Class octet is expected to change frequently due to Explicit Congestion Notification.

See section 7.12 and [RFC-1144] for more on how to compress TCP headers ๐Ÿ“š

b) COMPRESSED_TCP_NODELTA header format ๐ŸŒˆ

+-+-+-+-+-+-+-+-+
|      CID      |
+-+-+-+-+-+-+-+-+
|  RANDOM fields, if any (see section 7)   (implied)
+-+-+-+-+-+-+-+-+
|  Whole TCP header except for Port Numbers
+-+-+-+-+-+-+-+-+

c) Compressed non-TCP header, 8 bit CID ๐Ÿ“

 0             7
+-+-+-+-+-+-+-+-+
|      CID      |
+-+-+-+-+-+-+-+-+
|0|D| Generation|
+-+-+-+-+-+-+-+-+
|      data     |                      (if D=1)
 - - - - - - - -
| RANDOM fields, if any (section 7)    (implied)
 - - - - - - - -

d) Compressed non-TCP header, 16 bit CID ๐Ÿงš

 0             7
+-+-+-+-+-+-+-+-+
|  msb of CID   |
+-+-+-+-+-+-+-+-+
|1|D| Generation|
+-+-+-+-+-+-+-+-+
|  lsb of CID   |
+-+-+-+-+-+-+-+-+
|      data     |                      (if D=1)
 - - - - - - - -
| RANDOM fields, if any (section 7)    (implied)
 - - - - - - - -

The generation, CID and optional one-octet data are followed by whichever RANDOM fields the compression state implies (see section 7). Those are placed in the same order they appear in the original uncompressed header, and then comes the payload ๐Ÿ’œ


7. Compression of subheaders ๐ŸŒธ

This section lays out the rules for how the compressible chain of subheaders gets compressed. These rules MUST be followed ๐Ÿซถ Subheaders that can be compressed include IPv6 base and extension headers, TCP headers, UDP headers, and IPv4 headers. The compressible chain of subheaders runs from the beginning of the header, and it ends at whichever of these two spots gives the shorter chain:

  • a) up to but not including the first header that isn't an IPv4 header, an IPv6 base or extension header, a TCP header, or a UDP header, or
  • b) up to and including the first TCP header, UDP header, Fragment Header, Encapsulating Security Payload Header, or IPv4 header for a fragment.

For example, rules a) and b) both fit a chain of subheaders that has a Fragment Header and ends at a tunneled IPX packet. Since rule b) gives the shorter chain, the compressible chain stops at the Fragment Header ๐Ÿฆ‹

The following subsections are a systematic breakdown of how every field in the subheaders is expected to change ๐Ÿ‘‘ Here's the classification:

  • NOCHANGE: the field isn't expected to change. If it does change, a full header MUST be sent to update the context.
  • DELTA: the field may change a lot, but the difference from the field in the previous header is usually small, so it's cheaper to send the change from the previous value than the current one. This kind of compression is only used for TCP packet streams.
  • RANDOM: the field has to be included "as-is" in compressed headers, usually because it changes unpredictably.
  • INFERRED: the field holds a value that can be worked out from other values, like the size of the frame carrying the packet, so it must not be included in the compressed header ๐Ÿง 

The classification tells you how a compressed header gets built. No field that's NOCHANGE or INFERRED shows up in a compressed header. A compressor grabs the values of NOCHANGE fields from the context identified by the compression identifier, and grabs the values of INFERRED fields from the link-layer implementation (for example, from the size of the link-layer frame), or from other fields (for example, by recalculating the IPv4 header checksum). DELTA fields are encoded as the difference from the value in the previous packet in the same packet stream. The decompressor must update the context by adding the value from the compressed header to the value in its context, and the result is the proper value of the field. RANDOM fields must be sent "as-is" in the compressed header, and they must show up in the same order in the compressed header as they do in the full header โœจ

Fields that can optionally be used to identify which packet stream a packet belongs to (according to section 4.1) are marked with the word DEF. For a compressor using the optional guidelines from section 4.1, any difference in corresponding DEF fields between two packets means they belong to different packet streams. And if a DEF field is present in one packet but missing from another, those packets belong to different packet streams too ๐Ÿ’…

7.1. IPv6 Header [IPv6, section 3] ๐ŸŽ€

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| Traffic Class |               Flow Label              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Payload Length        |  Next Header  |   Hop Limit   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                         Source Address                        +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                      Destination Address                      +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Version                   NOCHANGE (DEF)
Traffic Class             NOCHANGE (might be DEF, see sect 4.1)
                                   (see also sect 6 a)
Flow Label                NOCHANGE (DEF)
Payload Length            INFERRED
Next Header               NOCHANGE
Hop Limit                 NOCHANGE (might be DEF, see sect 4.1)
Source Address            NOCHANGE (DEF)
Destination Address       NOCHANGE (DEF)

The Payload Length field of encapsulated headers has to match the length value of the encapsulating header. If it doesn't, the header chain MUST NOT be compressed ๐Ÿ™…โ€โ™€๏ธ

NOTE: If this the IP header closest to a TCP header, bit 7 of the Traffic Class field can be passed using the R-flag of the compressed TCP header. See section 6 a).

This classification means the entire IPv6 base header gets compressed away ๐Ÿงš

7.2. IPv6 Extension Headers [IPv6, section 4] ๐ŸŒˆ

What extension headers are present, and their relative order, isn't expected to change within a packet stream. Whenever that changes, a full packet header must be sent ๐Ÿ“ All Next Header fields in the IPv6 base header and IPv6 extension headers are NOCHANGE โœจ

7.3. Options [IPv6, section 4.2] ๐Ÿ’œ

The contents of Hop-by-hop Options and Destination Options extension headers are encoded as TLV "options" (see [IPv6]):

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
|  Option Type  |  Opt Data Len |  Option Data
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -

The Option Type and Opt Data Len fields are assumed to stay fixed for a given packet stream, so they're classified as NOCHANGE. The Option data is RANDOM unless it's specified otherwise below ๐Ÿฆ‹

Padding ๐Ÿซง

Pad1 option

+-+-+-+-+-+-+-+-+
|       0       |
+-+-+-+-+-+-+-+-+

The entire option is NOCHANGE ๐ŸŒธ

PadN option

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
|       1       |  Opt Data Len |  Option Data
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -

All fields are NOCHANGE ๐Ÿ‘‘

7.4. Hop-by-Hop Options Header [IPv6, section 4.3] โœจ

okay bestie, the Hop-by-Hop Options Header is up next ๐Ÿงš here's how it's laid out:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  |                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
|                                                               |
.                                                               .
.                            Options                            .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

both Next Header and Hdr Ext Len just get NOCHANGE, no drama ๐Ÿ’… and the Options field is handled like this:

Next Header          NOCHANGE
Hdr Ext Len          NOCHANGE

Options              TLV coded values and padding.
                     Classified according to 7.3 above, unless
                     being a Jumbo Payload option (see below).

the Jumbo Payload option is the special case ๐Ÿ‘‘ it looks like this:

                                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                |      194      |Opt Data Len=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     Jumbo Payload Length                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

the first two fields are NOCHANGE, and the Jumbo Payload Length is INFERRED. the frame length has to come from the link layer implementation, so that part is on the link layer ๐Ÿซถ

NOTE: ngl it's kinda silly to compress the headers of a packet that carries a Jumbo Payload Option, because the relative header overhead is negligible ๐Ÿ™ˆ it's also usually a bad idea to send packets this big over low- and medium-speed links.

7.5. Routing Header [IPv6, section 4.4] ๐Ÿฆ‹

the Routing Header layout:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  |  Routing Type | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                       type-specific data                      .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

every single field of the Routing Header is NOCHANGE ๐Ÿ’–

here's the tricky bit. if the Routing Type isn't recognized, you can't figure out the final Destination Address, UNLESS Segments Left is zero. in that case the Destination Address is just the final Destination Address in the basic IPv6 header ๐Ÿ‘‘

in the Type 0 Routing Header, the last address is DEF if (Segments Left > 0).

so Routing Headers get compressed away completely, and that's a huge win ๐ŸŽ€ the maximum size of the Routing Header is 392 octets, and Type 0 Routing Headers with one address (24 octets) are used by Mobile IP ๐ŸŒˆ


7.6. Fragment Header [IPv6, section 4.5] ๐Ÿงš

the first fragment of a packet has Fragment Offset = 0, and the chain of subheaders extends beyond its Fragment Header. if a fragment isn't the first one (Fragment Offset not 0), there are no subsequent subheaders. the exception is when the chain of subheaders in the first fragment didn't fit entirely in that first fragment ๐Ÿ’…

okay the plot twist: packets can get reordered before they reach the compression point, and some fragments can take different routes through the network. so a compressor can't count on seeing the first fragment before the others ๐Ÿ˜ญ that means the subheaders after the Fragment Header of the first fragment can't be looked at to figure out the right packet stream for the other fragments.

it's possible to design compression schemes that squish the subheaders after the Fragment Header, at least in the first fragment. BUT, to keep the rules for sending full headers and the rules for compression and decompression from getting messy, the chain of subheaders that follows a Fragment Header MUST NOT be compressed ๐Ÿ™…โ€โ™€๏ธ

here's how the fields of the Fragment Header get classified:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |   Reserved    |      Fragment Offset    |Res|M|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Identification                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

      Next Header          NOCHANGE
      Reserved             NOCHANGE
      Res                  RANDOM
      M flag               RANDOM
      Fragment Offset      RANDOM
      Identification       RANDOM

so a compressed Fragment Header ends up at 6 octets. the minimum IPv6 MTU is 1280 octets, which means most fragments will be at least 1280 octets long. since that 6 octet overhead gets spread over a pretty big packet, the extra complexity of fancier compression schemes isn't justifiable ๐Ÿ“

NOTE: The Identification field is RANDOM instead of NOCHANGE to avoid one compression slow-start per original packet.

now, grouping fragments, using the optional guidelines in section4.1:

  • fragments and unfragmented packets should not be grouped together.
  • port numbers can't be used to identify the packet stream, because port numbers aren't in every fragment. to follow the uniqueness rules for the Identification value, a fragmented packet stream is identified by the combination of Source Address and (final) Destination Address ๐Ÿฆ‹
NOTE: The Identification value is NOT used to identify the packet stream. This avoids using a new CID for each packet and saves the cost of the associated compression slow-start. We expect that the unfragmentable part of the headers will not change too frequently; if it does, thrashing may occur.

7.7. Destination Options Header [IPv6, section 4.6] ๐Ÿ’œ

layout:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  |                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
|                                                               |
.                                                               .
.                            Options                            .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Next Header          NOCHANGE
Hdr Ext Len          NOCHANGE

Options              TLV coded values and padding.
                       Compressed according to 7.3 above.

the only Destination Options defined in [IPv6] are the padding options ๐Ÿงธ


7.8. No Next Header [IPv6, section 4.7] ๐Ÿ™ˆ

this one's already covered by the rules for IPv6 Header Extensions (7.2), so nothing new here ๐Ÿ’…


7.9. Authentication Header [RFC-2402, section 3.2] ๐Ÿ”

layout:

 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
+---------------+---------------+---------------+---------------+
| Next Header   | Length        |           RESERVED            |
+---------------+---------------+---------------+---------------+
|                Security Parameters Index (SPI)                |
+---------------+---------------+---------------+---------------+
|                                                               |
+     Authentication Data (variable number of 32-bit words)     |
|                                                               |
+---------------+---------------+---------------+---------------+

Next Header          NOCHANGE
Length               NOCHANGE
Reserved             NOCHANGE
SPI                  NOCHANGE (DEF)
Authentication Data  RANDOM

[RFC-1828] explains how to do authentication with keyed MD5, which is the authentication method that all IPv6 implementations must support ๐Ÿซถ for this method, the Authentication Data is 16 octets.


7.10. Encapsulating Security Payload Header [RFC-2406, section 3.1] ๐Ÿ”’

this header means the rest of the packet is encrypted, so no more header compression is possible on the subsequent headers. encryption is usually already done by the time the compressor sees the packet ๐Ÿ˜ญ

BUT, when the ESP Header is used in tunnel mode, the whole IP packet is encrypted. the headers of that packet MAY be compressed before the packet gets encrypted at the entry point of the tunnel ๐Ÿงš that means it has to be possible to feed an IP packet and its length to the decompressor, as if it came from the link layer. the mechanisms for dealing with reordering described in section 11 MUST also be used, because packets can get reordered in a tunnel ๐ŸŒ€

+---------------+---------------+---------------+---------------+
|        Security Association Identifier (SPI), 32 bits         |
+===============+===============+===============+===============+
|            Opaque Transform Data, variable length             |
+---------------+---------------+---------------+---------------+

SPI                          NOCHANGE (DEF)
Opaque Transform Data        RANDOM

everything after the SPI is encrypted, so it isn't compressed ๐Ÿ”


7.11. UDP Header ๐ŸŒธ

the UDP header is described in [RFC-768] ๐Ÿ’–

the Next Header field (IPv6) or Protocol field (IPv4) in the preceding subheader is DEF.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            Length             |           Checksum            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Source Port          NOCHANGE (DEF)
Destination Port     NOCHANGE (DEF)
Length               INFERRED
Checksum             RANDOM, unless it is zero,
                       in which case it is NOCHANGE.

the Length field of the UDP header MUST match the Length field(s) of the preceding subheaders. i.e, there must not be any padding after the UDP payload that is covered by the IP Length ๐ŸŽ€

the UDP header usually compresses down to 2 octets, the UDP checksum. when the UDP checksum is zero (which it can't be with IPv6), it's likely to be zero for all packets in the flow, and it's defined to be NOCHANGE. that saves 2 octets in the compressed header โœจ

7.12. TCP Header ๐ŸŽ€

bestie, the TCP header is already fully described in [RFC-793] ๐Ÿ’… so we're not redefining it here. We're just looking at how it gets squished down ๐Ÿซถ

The Next Header field (IPv6) or Protocol field (IPv4) in the preceding subheader is DEF. ๐ŸŒธ

    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |          Source Port          |       Destination Port        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                        Sequence Number                        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Acknowledgment Number                      |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    | Offset| Reserved  |U|A|P|R|S|F|            Window             |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |           Checksum            |         Urgent Pointer        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Options                    |    Padding    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

U, A, P, R, S, and F stands for Urg, Ack, Psh, Rst, Syn, and Fin. ๐Ÿฆ‹

There are two ways to compress the TCP header. โœจ

7.12.1. Compressed with differential encoding

   Source Port           NOCHANGE  (DEF)
   Destination Port      NOCHANGE  (DEF)
   Sequence Number       DELTA
   Acknowledgment Number DELTA
   Offset                NOCHANGE
   Reserved              DELTA               (if differs from context,
                                              set R-flag in flag octet
                                              and send absolute value
                                              as described in 6 a.)
   Urg,Psh               RANDOM              (placed in flag octet)
   Ack                   INFERRED to be 1
   Rst,Syn,Fin           INFERRED to be 0
   Window                DELTA               (if change in Window,
                                              set W-flag in flag octet
                                              and send difference)
   Checksum              RANDOM
   Urgent Pointer        DELTA               (if Urg is set, send
                                              absolute value)
   Options, Padding      DELTA               (if change in Options,
                                              set O-flag and send
                                              whole Options, Padding)

okay so a packet with a TCP header compressed like the table above must be indicated to be of type COMPRESSED_TCP ๐Ÿ’– The compressed header is described in section 6. ๐Ÿงš

This method is basically the differential encoding trick from Jacobson, described in [RFC-1144] ๐Ÿ‘‘ The differences are where the compressed TCP header fields get placed (see section 6), the use of the O-flag, the use of the R-flag, and getting rid of the C-flag. The O-flag lets you compress the TCP header when the Timestamp option is used and the Options fields change with every header, which is lowkey iconic ๐Ÿฅน

DELTA values (except for the Reserved field and Options, Padding) MUST be coded as in [RFC-1144]. ๐Ÿซถ A Reserved field value passed with the R-flag MUST NOT update the context at the compressor or the decompressor. ๐Ÿ™ˆ

7.12.2. Without differential encoding

       Source Port           NOCHANGE  (DEF)
       Destination Port      NOCHANGE  (DEF)

       (all the rest)        RANDOM

The Identification field in a preceding IPv4 header is RANDOM. ๐ŸŽฒ

A packet with a TCP header compressed like this must be indicated to be of type COMPRESSED_TCP_NODELTA. ๐Ÿ“ It uses the same CID space as COMPRESSED_TCP packets, and the header MUST be saved as context. The compressed header is described in section 6. ๐Ÿ’œ

This packet type can be sent as the response to a header request instead of sending a full header. It can also be used over links that reorder packets, and it can be sent instead of a full header when there are changes that can't be represented by a compressed header. A sophisticated compressor can switch to sending only COMPRESSED_TCP_NODELTA headers when the packet loss frequency is high. ๐Ÿ˜ญ that's the main character move right there ๐Ÿ‘‘

7.13. IPv4 header [RFC-791, section 3.1] ๐ŸŒˆ

     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|  IHL  |Type of Service|          Total Length         |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |         Identification        |Flags|      Fragment Offset    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |  Time to Live |    Protocol   |         Header Checksum       |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                       Source Address                          |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Destination Address                        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Options                    |    Padding    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

There are two ways to compress the IPv4 header. ๐Ÿ’…

a) If the IPv4 header is not for a fragment (MF flag is not set and Fragment Offset is zero) and there are no options (IHL is 5), it is classified as follows. โœจ

       Version              NOCHANGE   (DEF)
       IHL                  NOCHANGE   (DEF, must be 5)
       Type of Service      NOCHANGE   (might be DEF, see sect 4.1)
                                       (see also 6 a)
       Total Length         INFERRED   (from link-layer implementation
                                        or encapsulating IP header)

       Identification       DELTA/     (If the Protocol field has the
                            RANDOM     (value corresponding to TCP)
                                       (otherwise)

       Flags                NOCHANGE   (MF flag must not be set)
       Fragment Offset      NOCHANGE   (must be zero)
       Time to Live         NOCHANGE   (might be DEF, see sect 4.1)
       Protocol             NOCHANGE
       Header Checksum      INFERRED   (calculated from other fields)
       Source Address       NOCHANGE   (DEF)
       Destination Address  NOCHANGE   (DEF)
       Options, Padding                (not present)

Note: When a TCP header immediately follows, the IPv4 and TCP header MUST be compressed as a unit as described in section 6. ๐Ÿซถ Bits 6 and 7 of the Type of Service field (bits 14 and 15 of the first word) can then be passed using the R-flag (see section 6 a). ๐ŸŒธ

b) If the IPv4 header is for a fragment (MF bit set or Fragment Offset nonzero), or there are options (IHL > 5), all fields are RANDOM (so if the header is compressed, all fields get sent as-is and not compressed). ๐ŸŽ€ This classification lets you compress the tunnel header, but not the fragment header, when fragments are tunneled. If the IPv4 header is for a fragment it ends the compressible chain of subheaders, which means it must be the last subheader to be compressed. If the IPv4 header has options but is not for a fragment, it does not end the compressible chain, so subsequent subheaders can still be compressed. ๐Ÿฆ‹

A compressor that follows the optional guidelines of section 4.1 will, in case a), use the Version, Source Address and Destination Address to define the packet stream, together with the fact that there are no IPv4 options and that this is not a fragment. โœจ

Case b) can define two kinds of packet streams, depending on whether the IPv4 header is for a fragment or not. ๐ŸŒˆ

If the IPv4 header in case b) is for a fragment, a compressor following the optional guidelines will use that fact together with the Version, Source Address, and Destination Address to determine the packet stream. ๐Ÿงš

If the IPv4 header in case b) is not for a fragment, it must have options. A compressor following the optional guidelines will use that fact, but not the size of the options, together with the Version, Source Address, and Destination Address to determine the packet stream. ๐Ÿ’œ

7.14. Minimal Encapsulation header [RFC-2004, section 3.1] ๐Ÿ“

     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
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |   Protocol    |S|  reserved   |        Header Checksum        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                 Original Destination Address                  |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    :            (if present) Original Source Address               :
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    Protocol                             NOCHANGE
    Original Source Address Present (S)  NOCHANGE
    reserved                             NOCHANGE
    Header Checksum                      INFERRED (calculated from
                                           other values)
    Original Destination Address         NOCHANGE
    Original Source Address              NOCHANGE (present only
                                                   if S=1)

This header is likely to be used by Mobile IP. ๐Ÿš€

8. Changing context identifiers โœจ

On a point-to-point link, the compressor has total knowledge of what CIDs are in use at the decompressor, and it may change what CID a packet stream uses or reuse CIDs at will. ๐Ÿ‘‘

Each non-TCP CID is associated with a context with a generation value. To avoid too rapid generation wrap-around and potential incorrect decompression, an implementation MUST avoid wrap-around of the generation value in less than MIN_WRAP seconds (see section 14). โฐ

To help avoid wrap-around, the generation value associated with a CID MUST NOT be reset when changing to a new packet stream. Instead, a compressor MUST increment the generation value by one when using the CID for a new non-TCP packet stream. ๐Ÿฆ‹

9. Rules for dropping or temporarily storing packets ๐ŸŒธ

When a decompressor receives a packet with a compressed TCP header with CID C, it MUST be discarded when the context for C has not been initialized by a full header. ๐Ÿ™ˆ

When a decompressor receives a packet with a compressed non-TCP header with CID C and generation G, the header must not be decompressed using the current context when:

a) the decompressor has been disconnected from the compressor for more than MIN_WRAP seconds, because the context might be obsolete even if it has generation G. ๐Ÿ˜ฌ

b) the context for C has a generation other than G. ๐Ÿ˜ฌ

In case a) and b), the packet may either be:

i) discarded immediately, or else

ii) stored temporarily until the context is updated by a packet with a full non-TCP header with CID C and generation G, after which the header can be decompressed.

Packets stored in this manner MUST be discarded when:

  • receiving full or compressed non-TCP headers with CID C and a generation other than G,
  • the decompressor has not received packets with CID C in the last MIN_WRAP seconds.

When full headers are lost, a decompressor can receive compressed non-TCP headers with a generation value other than the generation of its context. Rule ii) allows the decompressor to store such headers until they can be decompressed using the correct context. ๐Ÿ’–

10. Low-loss header compression for TCP ๐ŸŒธ

okay so, fewer bits per packet means fewer packets get wrecked for a fixed bit-error rate ๐Ÿ“‰โœจ. That makes header compression a total win on links with high bit-error rates, like wireless links ๐Ÿ’–.

BUT ๐Ÿ˜ญ TCP headers are compressed with differential encoding, so one lost TCP segment can ruin an entire sending window ๐Ÿ’€. The context doesn't get incremented properly at the decompressor, so every header after that decompresses to something different from what it was before compression. The TCP receiver then tosses them because the TCP checksum fails. Not it. ๐Ÿ™ˆ

Picture a TCP connection in the wide area where the last hop is a medium-speed lossy link, like a wireless LAN ๐Ÿ“ถ. With traditional header compression, performance is rough, because the delay-bandwidth product is relatively large and the bit-error rate is relatively high ๐Ÿ˜ค. For a 2 Mbit/s wireless LAN and an end-to-end RTT of 200 ms, the delay-bandwidth product is 50 kbyte. That's about 97 512-octet segments with compressed headers. So each loss can get multiplied by a factor of 100 ๐Ÿ’€๐Ÿ”ฅ.

This section describes two simple mechanisms for quick context repair. With them, header compression will improve TCP throughput over lossy links, as well as over links with low bit-error rates โœจ.


10.1. The "twice" algorithm ๐Ÿ’…

The decompressor may compute the TCP checksum to figure out whether its context got updated properly. If the checksum fails, the error is assumed to be caused by a lost segment that didn't update the context. So the delta of the current segment is added to the context again, on the assumption that the lost segment had the same delta as the current one. Then the decompressor decompresses and computes the TCP checksum again, to check whether the repair worked or whether the delta should be applied once more ๐Ÿ”.

Analysis of traces from various TCP bulk transfers shows that applying the delta of the current segment one or two times repairs the context for between 83 and 99 per cent of all single-segment losses in the data stream ๐Ÿ“Š. For the acknowledgment stream, the success rate is smaller, thanks to TCP's delayed ack mechanism ๐Ÿ™ƒ. The "twice" mechanism repairs the context for 53 to 99 per cent of the losses in the acknowledgment stream.

A sophisticated implementation would work out whether the TCP stream is an acknowledgment or data stream, and figure out the segment size by watching the stream of full and compressed headers ๐Ÿง . Trying deltas that are small multiples of the segment size gives even higher repair rates for acknowledgment streams ๐ŸŒˆ.


10.2. Header Requests ๐Ÿ™‹โ€โ™€๏ธ

The relatively low success rate of "twice" for TCP acknowledgment streams calls for an extra way to repair the context at the decompressor ๐Ÿซถ. When the decompressor fails to repair the context after a loss, it may optionally request a full header from the compressor. This is possible on links where the decompressor can identify the compressor and send packets to it.

On such links, a decompressor may send a CONTEXT_STATE packet back to the compressor to indicate that one or more contexts are invalid. A decompressor SHOULD NOT send a CONTEXT_STATE packet every time a compressed packet refers to an invalid context. Instead it should limit how often it sends them, so it doesn't flood the reverse channel ๐ŸŒŠ. One CONTEXT_STATE packet can indicate that several contexts are out of date, and this technique SHOULD be used instead of sending several separate packets ๐Ÿ“ฆ. Here's the format:

                       0   1   2   3   4   5   6   7
                    +---+---+---+---+---+---+---+---+
                    |     TCP header request = 3    |
                    +---+---+---+---+---+---+---+---+
                    |           CID count           |
                    +---+---+---+---+---+---+---+---+
                    |              CID              |
                    +---+---+---+---+---+---+---+---+
                    |              CID              |
                    +---+---+---+---+---+---+---+---+
                                           ...
                    +---+---+---+---+---+---+---+---+
                    |              CID              |
                    +---+---+---+---+---+---+---+---+

The first octet is a type code, so the CONTEXT_STATE packet type can be shared with other compression protocols that are (see [CRTP]) or may be defined in parallel with this one ๐Ÿงฉ. When it's used for TCP header requests, the type code has the value 3, and the rest of the packet is a sequence of CIDs, preceded by a one-octet count of how many CIDs there are ๐Ÿ”ข.

On receipt of a CONTEXT_STATE packet, the compressor MUST mark the CIDs invalid, to make sure the next packet emitted in those packet streams is a FULL_HEADER or COMPRESSED_TCP_NODELTA packet ๐Ÿšจ.

Header requests are an optimization, so losing a CONTEXT_STATE packet doesn't affect the correct operation of TCP header compression ๐Ÿ™Œ. When one is lost, eventually a new one gets sent, or TCP times out and retransmits. The big advantage of header requests is that TCP acknowledgment streams can be repaired after one round-trip time over the lossy link ๐ŸŽ‰. That typically avoids a TCP timeout and unnecessary retransmissions. The lower packet loss rate from smaller packets then gives higher throughput, because the TCP window can grow larger between losses ๐Ÿ“ˆ.


Some links reorder packets, for example multi-hop radio links that use deflection routing to route around congested nodes. Packets routed different ways can then arrive at the destination in a different order than they were sent ๐ŸŒ€.


11.1. Reordering in non-TCP packet streams

Compressed non-TCP headers don't change the context, and neither do full headers that refresh it. Problems can only happen when a full header that changes the context arrives out of order. There are two cases:

  • A packet with a full header with generation G arrives after a packet with a compressed header with generation G. This case is covered by rule b) ii) in section 9 ๐Ÿ“œ.
  • A packet with a full header with generation G arrives before a packet with a compressed header with generation G-1 (modulo 64). The decompressor MAY then keep both versions of the context around for a while, so it can decompress subsequent compressed headers with generation G-1 (modulo 64). The old context MUST be discarded after MIN_WRAP seconds โณ.

11.2. Reordering in TCP packet streams

A compressor may avoid sending COMPRESSED_TCP headers and only send COMPRESSED_TCP_NODELTA headers when there is reordering over the link. Compressed headers will typically be 17 octets with that method, which is significantly larger than the usual 4-7 octets ๐Ÿ˜.

For better compression rates, the following method adds only two octets to the compressed header, for a total of 6-9 octets, and may be used ๐Ÿงฎ. A packet sequence number, incremented by one for every packet in the TCP stream, is associated with each compressed and full header. This lets the decompressor place the packets in the correct sequence and apply their deltas to the context in the correct order. A simple sliding window scheme is used to place the packets in the correct order ๐ŸชŸ.

Two octets are needed for the packet sequence numbers, because one octet only gives 256 sequence numbers. In a sliding window scheme, the window should be no larger than half of the sequence number space, so packets cannot arrive more than 127 positions out-of-sequence. That's equivalent to a delay of 260 ms on 2 Mbit/s links with 512-octet segments. Delays of that order aren't uncommon over wide-area Internet connections ๐ŸŒ. However, two octets giving 2^16 = 65536 values should be sufficient ๐Ÿ’ฏ.

Full TCP/IP headers only have space for one octet of sequence number when there is no tunneling. It isn't feasible to increase the size of full headers, since the packet size might be optimized for the MTU of the link ๐Ÿ™…. So only the least significant octet of the packet sequence number can be placed in such full headers. We believe that such full headers can be positioned correctly frequently enough with only the least significant octet of the packet sequence number available.

The packet sequence number zero MUST be skipped over. Avoiding zero takes care of a problem that can occur when the TCP window scale option is used to enlarge the TCP window. When exactly 2^16 octets of TCP data are lost, a compressed header will be decompressed incorrectly without being detected by the TCP checksum ๐Ÿ˜ฑ. TCP segment sizes are often a power of two. So by using a packet sequence number space that is not a power of two either, the TCP sequence number or the packet sequence number will differ when 2^16 octets are lost. Whenever a compressor sees the window scale option on a SYN segment, it MUST use packet sequence numbers when subsequently compressing that packet stream.

In compressed TCP headers the two-octet packet sequence number MUST be placed immediately after the TCP Checksum. See section 5.3 for placement of packet sequence numbers in full headers ๐Ÿ“.


12. Hooks for additional header compression ๐Ÿช

The following hook is supplied to allow additional header compression schemes for headers on top of UDP. The initial chain of subheaders is compressed as described here, and the other header compression scheme is applied to the header above the UDP header. An example of such additional header compression is Compressed RTP by Casner and Jacobson [CRTP]. To allow some error detection, such schemes typically need a sequence number that may need to be passed in full headers as well as compressed UDP headers ๐Ÿ”.

The D-bit and Data octet (see section 6) provide the necessary mechanism. When a sequence number, say, needs to be passed in a FULL_HEADER or COMPRESSED_NON_TCP header, the D-bit is set and the sequence number is placed in the Data field. The decompressor must then extract and make the Data field available to the additional header compression scheme ๐ŸŽ€.

Use of additional header compression schemes like CRTP must be negotiated. The D-bit and Data octet mechanism must automatically be enabled whenever use of additional header compression schemes has been negotiated โœจ.

13. Demultiplexing ๐Ÿฆ‹

okay so every link layer needs a doc that spells out how the different packet types get labeled, and that's MUST for real ๐Ÿ’… PPP has its own, [PPP-HC]. This section gives OPTIONAL tips on how a specific link layer can mark packet types, so take them as bonus material, bestie ๐Ÿงš

we have to tell apart regular IPv4 headers, regular IPv6 headers, full IPv6 packets, full IPv4 packets, compressed TCP packets, compressed non-TCP packets, and CONTEXT_STATE packets. it's giving organized chaos ๐Ÿ˜ญ

the decision to give IPv6 its own ethertype (or equivalent) is already locked in, so link layers MUST be able to say "this is an IPv6 packet" ๐ŸŒธ

IP header compression needs the link layer to handle four kinds of packets: COMPRESSED_TCP for format a) in section 6, COMPRESSED_TCP_NODELTA for format b), COMPRESSED_NON_TCP for formats c) and d), and CONTEXT_STATE as described in section 11.2. indicating FULL_HEADERS at the link layer is also a good idea, even though it's not strictly required โœจ

full headers can be flagged by setting the first bit of the Version field in a packet marked as IPv6. on top of that, one bit of the Version field says whether the first subheader is IPv6 or IPv4, and another bit says whether that full header carries a TCP CID or a non-TCP CID. the first four bits work like this:

   Version  Meaning

   0110     regular IPv6 header

   1T*0     T=1 indicates a TCP header, T=0 indicates a non-TCP header
   1*V0     V=1 indicates a IPv6 header, V=0 indicates a IPv4 header

if a link layer can't indicate packet types for the compressed headers or CONTEXT_STATE, the packet types it can't signal could start with an octet naming the type, followed by the header ๐ŸŽ€

    First octet  Type of compressed header
    -----------   -------------------------

        0        COMPRESSED_TCP
        1        COMPRESSED_TCP_NODELTA
        2        COMPRESSED_NON_TCP
        3        CONTEXT_STATE

the currently assigned CONTEXT_STATE type values are:

    Value   Type                       Reference
    -----   -----                      ----------
      0     Reserved                   -
      1     IP/UDP/RTP w. 8-bit CID    [CRTP]
      2     IP/UDP/RTP w. 16-bit CID   [CRTP]
      3     TCP header request         Section 10.2

14. Configuration Parameters ๐Ÿ’œ

okay so header compression parameters get negotiated in a way that depends on the link layer. the procedures for link-layer xxx need to be written up in a document called "IP header compression over xxx". PPP has one of those too, [PPP-HC] ๐Ÿ“

one parameter is locked for every implementation of this scheme:

  MIN_WRAP     - minimum time of generation value wrap around

       3 seconds.

the next ones can be negotiated between the compressor and decompressor. if they don't get negotiated, their values MUST be the DEFAULT ones ๐Ÿซถ

  F_MAX_PERIOD - Largest number of compressed non-TCP headers that
                 may be sent without sending a full header.

       DEFAULT is 256

       F_MAX_PERIOD must be at least 1 and at most 65535.


  F_MAX_TIME   - Compressed headers may not be sent more than
                 F_MAX_TIME seconds after sending last full header.

       DEFAULT is 5
       F_MAX_TIME must be at least 1 and at most 255.

       NOTE:  F_MAX_PERIOD and F_MAX_TIME should be lower when it is
              likely that a decompressor loses its state.


  MAX_HEADER   - The largest header size in octets that may
                 be compressed.

       DEFAULT is 168 octets, which covers

                       - Two IPv6 base headers
                       - A Keyed MD5 Authentication Header
                       - A maximum-sized TCP header

       MAX_HEADER must be at least 60 octets and
               at most 65535 octets.


  TCP_SPACE    - Maximum CID value for TCP.

       DEFAULT is 15   (which gives 16 CID values)

       TCP_SPACE must be at least 3 and at most 255.


  NON_TCP_SPACE    - Maximum CID value for non-TCP.

       DEFAULT is 15   (which gives 16 CID values)

       NON_TCP_SPACE must be at least 3 and at most 65535.


  EXPECT_REORDERING       - The mechanisms in section 11 are used.

       DEFAULT no.
โš ๏ธ the NOTE on F_MAX_PERIOD and F_MAX_TIME is important: if a decompressor is likely to lose its state, those two values SHOULD be lower. it's a whole vibe check on reliability ๐Ÿ˜ญ

15. Implementation Status โœจ

a prototype using UDP as the link layer has been running since March 1996. a NetBSD implementation for PPP has been running since October 1996. the pioneers were literally out here building things ๐Ÿ”ฅ


16. Acknowledgments ๐ŸŒˆ

this protocol borrows a lot of ideas from Van Jacobson's header compression for TCP/IP over slow-speed links [RFC-1144]. it also got better thanks to chats with Stephen Casner and Carsten Bormann ๐Ÿซถ

shoutout to Craig Partridge for spotting a problem that can happen when the TCP window scale option is used ๐Ÿ‘‘ the fix, which relies on the packet sequence numbers used for reordering, is in section 11.2.


17. Security Considerations ๐Ÿ™ˆ

this is the serious part, bestie, so let's give it full attention ๐Ÿ’€

the compression protocols here run on top of a link-layer protocol. they don't add any new vulnerabilities on their own, beyond the ones that come with the link-layer technology being used.

denial-of-service attacks are possible if an intruder can slip in (for example) bogus Full Header packets onto the link. but an intruder who can inject arbitrary packets at the link layer like that brings security issues that completely overshadow anything header compression could cause ๐Ÿ˜ญ

we strongly advise implementers not to identify packet streams using information that's encrypted, even if the compressor happens to have access to it. doing that may expose traffic patterns. keep those patterns private, babe ๐Ÿ”’


18. Authors' Addresses ๐ŸŽ€

   Mikael Degermark
   Department of Computer Science and Electrical Engineering
   Lulea University of Technology
   SE-971 87 Lulea, Sweden

   Phone: +46 920 91188
   Fax: +46 920 72831
   Mobile: +46 70 833 8933
   EMail: micke@sm.luth.se


   Bjorn Nordgren
   CDT/Telia Research AB
   Aurorum 6
   S-977 75 Lulea, Sweden

   Phone: +46 920 75400
   Fax: +46 920 75490
   EMail: bcn@lulea.trab.se, bcn@cdt.luth.se


   Stephen Pink
   Department of Computer Science and Electrical Engineering
   Lulea University of Technology
   SE-971 87 Lulea, Sweden

   Phone: +46 920 752 29
   Fax: +46 920 728 31
   Mobile: +46 70 532 0007
   EMail: steve@sm.luth.se

19. References ๐Ÿ“š

these are the references, all listed with full details, so nobody gets lost ๐Ÿงš

   [RFC-768]       Postel, J., "User Datagram Protocol", STD 6, RFC 768,
                   August 1980.

   [RFC-791]       Postel, J., "Internet Protocol", STD 5, RFC 791,
                   September 1981.

   [RFC-793]       Postel, J., "Transmission Control Protocol", STD 7,
                   RFC 793, September 1981.

   [RFC-1144]      Jacobson, V., "Compressing TCP/IP Headers for Low-
                   Speed Serial Links", RFC 1144, February 1990.

   [RFC-1553]      Mathur, A. and M. Lewis, "Compressing IPX Headers
                   Over WAN Media (CIPX)", RFC 1553, December 1993.

   [RFC-1700]      Reynolds, J. and J. Postel, "Assigned Numbers", STD
                   2, RFC 1700, October 1994.  See also:
                   http://www.iana.org/numbers.html

   [RFC-2402]      Kent, S. and R. Atkinson, "IP Authentication Header",
                   RFC 2402, November 1998.

   [RFC-2406]      Kent, S. and R. Atkinson, "IP Encapsulating Security
                   Protocol (ESP)", RFC 2406, November 1998.

   [RFC-1828]      Metzger, W., "IP Authentication using Keyed MD5", RFC
                   1828, August 1995.

   [IPv6]          Deering, S. and R. Hinden, "Internet Protocol,
                   Version 6 (IPv6) Specification", RFC 2460, December
                   1998.

   [ICMPv6]        Conta, A. and S. Deering, "Internet Control Message
                   Protocol (ICMPv6) for the Internet Protocol Version 6
                   (IPv6) Specification.", RFC 2463, December 1998.

   [RFC-2004]      Perkins, C., "Minimal Encapsulation within IP", RFC
                   2004, October 1996.

   [CRTP]          Casner, S. and V. Jacobson, "Compressing IP/UDP/RTP
                   Headers for Low-Speed Serial Links", RFC 2508,
                   February 1999.

   [PPP-HC]        Engan, M., Casner, S. and C. Bormann, "IP Header
                   Compression for PPP", RFC 2509, February 1999.

Copyright (C) The Internet Society (1999). All Rights Reserved.

this document and translations of it may be copied and given to others. derivative works that comment on or otherwise explain it, or help with its implementation, may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. however, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations. the exceptions are when it's needed for developing Internet standards, in which case the procedures for copyrights defined in the Internet Standards process must be followed, or when it's required to translate it into languages other than English.

the limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns.

this document and the information in it are provided on an "AS IS" basis, and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. .fi

๐Ÿ“ฆ where this page comes from