pseudo-header

term

networking

Kept in this browser · My desk

A block of fields copied from the Internet Protocol (IP) header, the two addresses, the protocol number and the transport length, that the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) add to their checksum calculation without ever sending it. It ties each segment or datagram to the addresses it was meant for, so a packet delivered to the wrong host or protocol fails its checksum.

Neither the Transmission Control Protocol (TCP) nor the User Datagram Protocol (UDP) carries addresses in its own header, only ports, yet both checksums cover the addresses. They do it by prefixing, for the calculation only, a pseudo-header: for IPv4, 12 bytes of source address, destination address, a zero byte, the protocol number and the transport length; for IPv6, 40 bytes with the 128-bit addresses, a 32-bit length and the next header value. Request for Comments (RFC) 768 gives the reason in one line, protection against misrouted datagrams. The cost appears in the middle of the network: a translator that rewrites an address or a port must update the transport checksum too, and IPv6 makes the UDP checksum mandatory, so the addresses are always covered end to end.

What it is. Request for Comments (RFC) 768, Jon Postel's User Datagram Protocol (UDP) specification of 28 August 1980, defines the checksum as the 16-bit one's complement of the one's complement sum of a pseudo header of information from the Internet Protocol (IP) header, the UDP header and the data, padded with a zero octet at the end if needed to make an even number of octets. The pseudo header, conceptually prefixed to the UDP header, contains the source address, the destination address, the protocol and the UDP length, and, in Postel's words, gives protection against misrouted datagrams; he adds that the procedure is the same one the Transmission Control Protocol (TCP) uses. For IPv4 it is 96 bits, 12 octets: the 32-bit source address, the 32-bit destination address, a zero octet, the 8-bit protocol number (6 for TCP, 17 for UDP) and the 16-bit length of the transport header and data. Nothing in it is transmitted; both ends rebuild it from the IP header they send or receive.

The same idea in TCP and IPv6. RFC 9293, the TCP standard of August 2022, describes the same structure in section 3.1 with the protocol field named PTCL and a TCP Length that is computed rather than transmitted and does not count the 12 octets of the pseudo-header, and states that including the pseudo-header gives the connection protection against misrouted segments; the pseudo-header is 96 bits for IPv4 and 320 bits for IPv6, and the TCP checksum is never optional. RFC 8200, the IPv6 specification of July 2017, defines the IPv6 version in section 8.1: source address, destination address, a 32-bit Upper-Layer Packet Length, three zero octets and the Next Header value, 40 octets in all. Two details are easy to get wrong. When a Routing header is present, the destination in the pseudo-header is the final destination, not the next waypoint; and the Next Header value is the upper-layer protocol, 6 or 17, which differs from the IPv6 header's own value when extension headers sit in between. The Internet Control Message Protocol (ICMP) for IPv6 also includes the pseudo-header, unlike ICMP for IPv4.

How the checksum is computed. RFC 1071 (September 1988, R. Braden, D. Borman and C. Partridge) describes the arithmetic: adjacent octets are paired into 16-bit words, the words are added in one's complement, which on ordinary hardware means adding any carry out of the top bit back into the bottom (the end-around carry), and the checksum field is the one's complement of the result, computed with the field itself set to zero. The receiver sums the same words including the checksum and expects all one bits. The sum does not depend on byte order and can be computed in any grouping. RFC 1071's own example adds the octets 00 01 f2 03 f4 f5 f6 f7 and obtains ddf2; the checksum of those octets would be its complement, 220d.

A worked UDP example. A Domain Name System (DNS) query for example.com, type A, from 192.0.2.10 port 50000 to 198.51.100.53 port 53, carries 29 octets of DNS message, so the UDP length is 8 + 29 = 37, hex 0025. The IPv4 pseudo-header words are c000 020a (192.0.2.10), c633 6435 (198.51.100.53), 0011 (zero octet and protocol 17) and 0025 (the length); their one's complement sum is eca9. The UDP header with the checksum field at zero is c350 0035 0025 0000, summing to c3aa. The 29 data octets, padded with one zero octet to 15 words, sum to e998. Adding the three partial sums gives eca9 + c3aa = 1b053, folded to b054; b054 + e998 = 199ec, folded to 99ed. The checksum is the complement, ffff minus 99ed, which is 6612, and the transmitted header reads c3 50 00 35 00 25 66 12. The receiver's sum over pseudo-header, header with 6612 and data comes to ffff, which is the pass condition. Change one bit of the destination address in transit and the receiver's pseudo-header, built from the address it actually received, no longer matches: the datagram fails its checksum instead of being handed to the wrong program.

The special values. In IPv4 the UDP checksum is optional: an all-zero field means the sender computed none, and a computed zero is therefore sent as all ones, equivalent in one's complement arithmetic, as RFC 768 and RFC 1122 both explain. RFC 1122 (October 1989) nevertheless requires hosts to implement UDP checksums, to default to checksumming on, and to discard silently a datagram whose non-zero checksum is wrong. IPv6 removes the option: RFC 8200 makes the UDP checksum mandatory, has a zero result sent as ffff and has receivers discard datagrams with a zero checksum, with one exception. RFC 6936 (April 2013, G. Fairhurst and M. Westerlund) allows zero checksums only for tunnel encapsulations on specific ports, off by default for sending and rejected by default on reception.

What goes wrong in the middle. Because the pseudo-header includes the addresses, any device that rewrites them must also rewrite the transport checksum. RFC 3022 (January 2001), on traditional Network Address Translation (NAT), says so directly: modifications for TCP and UDP sessions must include an update of the transport checksum because it covers a pseudo header with the source and destination addresses, UDP headers with a zero checksum are left alone, and ICMP query packets need no such change because their checksum does not cover addresses. RFC 1071 explains why this is cheap: the checksum can be updated incrementally by adding the differences of the 16-bit words that changed, without reading the whole packet. A translator that rewrites the address and forgets the checksum produces packets that every receiver silently discards, which looks like loss, not like an error. Tunnels and offload complicate the same picture: the outer packet's checksum covers the outer addresses only, and with offload the checksum may be computed after the operating system has handed the data over; Linux's udp(7) notes that UDP segmentation offload depends on checksum offload because datagram checksums are computed after segmentation.

Neighbours. The checksum entry explains the arithmetic in general; UDP and TCP are the two transports that use the pseudo-header; the five-tuple shares four of its fields; NAT is the device that must keep it consistent; fragmentation separates the transport header, and its checksum, from the later fragments, which carry only part of the data the checksum covers.

Also known as: pseudo header, pseudoheader, pseudo-header checksum, pseudo-cabeçalho

Sources

← Back to P Back to the glossary