RFC 7821

UDP Checksum Complement in the Network Time Protocol (NTP)

๐Ÿ“… published March 2016, from ietf

RFC 7821: UDP Checksum Complement in the Network Time Protocol (NTP) ๐ŸŽ€

okay bestie, let's get into RFC 7821. ๐Ÿฆ‹ It's an Experimental doc by T. Mizrahi from Marvell, published in March 2016 as part of the IETF stream (ISSN 2070-1721). The title block doesn't list anything it obsoletes or updates, so it's a standalone new thing. ๐Ÿ’…


Abstract โœจ

okay so NTP lets clients sync their clocks to a time server by sending timestamped messages. ๐Ÿ•ฐ๏ธ For accurate timestamps, some setups use a hardware timestamping engine that stamps the real transmission time into every outgoing NTP packet on the way out. Since NTP rides on UDP, the UDP Checksum field has to be updated to match that change. ๐Ÿ˜ญ

This doc proposes an extension field with a 2-octet Checksum Complement. The timestamping engine can then put the checksum change in the last 2 octets of the packet instead of touching the UDP Checksum field. And it's interoperable with existing NTP implementations, so it's giving compatibility. ๐Ÿซถ

Status of This Memo

Real talk, this doc is not an Internet Standards Track spec. ๐Ÿง It's published so people can examine it, try it out in experimental implementations, and evaluate it. ๐Ÿ”ฌ

It defines an Experimental Protocol for the Internet community. It's a product of the IETF and represents the IETF community's consensus. It got public review and was approved for publication by the Internet Engineering Steering Group (IESG). Not every IESG-approved doc is a candidate for any level of Internet Standard, so see Section 2 of RFC 5741 for the details. ๐Ÿ“š

For the current status, any errata, and how to give feedback, check http://www.rfc-editor.org/info/rfc7821. ๐ŸŒธ

Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved. ยฉ๏ธ

This doc is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as in effect on the date of publication. Please review those docs carefully, because they spell out your rights and restrictions for this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they're provided without warranty as described in the Simplified BSD License. ๐Ÿ“œ

Table of Contents ๐Ÿ—‚๏ธ

   1. Introduction ....................................................3
      1.1. Intermediate Entities ......................................3
      1.2. Updating the UDP Checksum ..................................4
   2. Conventions Used in This Document ...............................5
      2.1. Terminology ................................................5
      2.2. Abbreviations ..............................................6
   3. Using the UDP Checksum Complement in NTP ........................6
      3.1. Overview ...................................................6
      3.2. Checksum Complement in NTP Packets .........................7
           3.2.1. Using the Checksum Complement .......................7
           3.2.2. Transmission of NTP with Checksum Complement ........8
           3.2.3. Updates of NTP with Checksum Complement .............8
           3.2.4. Reception of NTP with Checksum Complement ...........8
      3.3. Interoperability with Existing Implementations .............9
      3.4. The Checksum Complement and Authentication .................9
   4. Security Considerations ........................................10
   5. IANA Considerations ............................................10
   6. References .....................................................11
      6.1. Normative References ......................................11
      6.2. Informative References ....................................11
   Appendix A. Checksum Complement Usage Example .....................13
   Acknowledgments ...................................................14
   Author's Address ..................................................14

1. Introduction โœจ

The Network Time Protocol [NTPv4] lets clients sync their clocks to a time server by swapping NTP packets. ๐Ÿ•ฐ๏ธ As people want more and more accurate clock sync, implementations that do accurate timestamping are becoming a must-have vibe. ๐Ÿ”ฅ

1.1. Intermediate Entities

In this doc, we use the term "intermediate entity" for an entity that sits on the path between the sender and the receiver of an NTP packet and modifies that NTP packet en route. ๐Ÿ›ฃ๏ธ

To get accurate timestamps, an implementation can use a hardware-based timestamping engine, as shown in Figure 1. In that setup, NTP packets are sent and received by a software layer, while the timestamping engine changes every outgoing NTP packet by putting its accurate transmission time into the <Transmit Timestamp> field. โฑ๏ธ

                    NTP client/server
                  +-------------------+
                  |                   |
                  |   +-----------+   |
   Software       |   |    NTP    |   |
                  |   | protocol  |   |
                  |   +-----+-----+   |
                  |         |         |     +-----------------------+
                  |   +-----+-----+   |    / Intermediate entity    |
                  |   | Accurate  |   |   /  in charge of:          |
   ASIC/FPGA      |   | Timestamp |   |  /__ - Timestamping         |
                  |   |  engine   |   |     |- Updating checksum or |
                  |   +-----------+   |     |  Checksum Complement  |
                  |         |         |     +-----------------------+
                  +---------+---------+
                            |
                            |NTP packets
                            |
                        ___ v _
                       /   \_/ \__
                      /           \_
                     /     IP      /
                     \_  Network  /
                      /           \
                      \__/\_   ___/
                            \_/

   ASIC: Application-Specific Integrated Circuit
   FPGA: Field-Programmable Gate Array

                Figure 1: Accurate Timestamping in NTP

Sync accuracy over packet networks is super sensitive to delay jitter in the underlying network, and that really messes with clock accuracy. ๐Ÿ˜ฉ To deal with this, the Precision Time Protocol (PTP) [IEEE1588] defines Transparent Clocks (TCs), which are switches and routers that boost end-to-end clock accuracy by adding the latency caused by the current TC to a "Correction Field" in the PTP packet. ๐Ÿ” NTP doesn't have an equivalent entity defined yet, but future versions of NTP might define an intermediate node that changes en-route NTP packets using a "Correction Field". ๐Ÿ‘€

1.2. Updating the UDP Checksum

When an intermediate entity changes the UDP payload, the UDP Checksum field needs to be updated so the packet stays correct. ๐Ÿงฉ When you use UDP over IPv4 [UDP], an intermediate entity that can't update the UDP Checksum has no choice but to set the Checksum field to zero. That makes the receiver ignore the Checksum field, so it might accept corrupted packets. ๐Ÿ’€ UDP over IPv6, defined in [IPv6], doesn't allow a zero checksum, except in specific cases [ZeroChecksum]. As [ZeroChecksum] explains, using a zero checksum is generally not recommended and should be avoided to the extent possible. ๐Ÿ™…โ€โ™€๏ธ

An intermediate entity only changes one specific field in the packet, the Timestamp field, so the UDP Checksum update can be done incrementally, using the concepts in [Checksum]. ๐Ÿงฎ

This doc defines the Checksum Complement for [NTPv4]. The Checksum Complement is a 2-octet field that sits at the end of the UDP payload. It lets intermediate entities update NTP packets and keep the UDP Checksum correct by changing the last 2 octets of the packet, instead of updating the UDP Checksum field. To do that, you add an NTP extension field at the end of the packet, and the last 2 octets of that field serve as the Checksum Complement. โœจ

Using the Checksum Complement can sometimes make implementation simpler. If the packet data gets processed in serial order, it's easier to update the Timestamp field first and then the Checksum Complement, instead of updating the timestamp and then the UDP Checksum in the UDP header. ๐Ÿช„ Hardware timestamper that updates the UDP Checksum? Not impossible, but using the Checksum Complement instead can significantly simplify the implementation. ๐Ÿ’–

The software layer and the intermediate entity (see Figure 1) are two modules in a single NTP clock. It's assumed that these two modules agree on whether transmitted NTP packets include the Checksum Complement or not. ๐Ÿค

[RFC7820] defines the Checksum Complement mechanism for the One-Way Active Measurement Protocol (OWAMP) and the Two-Way Active Measurement Protocol (TWAMP). ๐Ÿง  A similar mechanism shows up in Annex E of [IEEE1588]. ๐ŸŒˆ

2. Conventions Used in This Document ๐Ÿ“–

2.1. Terminology

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 [KEYWORDS]. ๐Ÿ”‘

2.2. Abbreviations ๐Ÿ”ค

   MAC      Message Authentication Code

   NTP      Network Time Protocol

   PTP      Precision Time Protocol

   UDP      User Datagram Protocol

3. Using the UDP Checksum Complement in NTP ๐ŸŽ€

3.1. Overview

The UDP Checksum Complement is a 2-octet field that gets appended to the end of the UDP payload, using an NTP extension field. ๐ŸŽ Figure 2 shows the packet format of an NTP packet with a Checksum Complement extension. ๐Ÿ–ผ๏ธ

                       +--------------------------------+
                       |        IPv4/IPv6 Header        |
                       +--------------------------------+
                       |           UDP Header           |
                       +--------------------------------+
               ^       |                                |
               |       |           NTP packet           |
               |       |                                |
               |       +--------------------------------+
              UDP      | Optional NTP Extension Fields  |
            Payload    +--------------------------------+
               |       |    UDP Checksum Complement     |
               |       |   Extension Field (28 octets)  |
               v       +--------------------------------+

Figure 2: Checksum Complement in NTP Packets

The Checksum Complement compensates for changes that intermediate entities make to the NTP packet, as the Introduction (Section 1) describes. ๐Ÿซง You can see an example of how it's used in Appendix A. ๐Ÿ“


Part 1 of 3 done, bestie. Part 2 picks up with Section 3.2 and the Checksum Complement details. ๐Ÿ’œ

3.2. Checksum Complement in NTP Packets โœจ

okay so NTP rides on UDP ๐Ÿฆ‹ and it can run over IPv4 or IPv6, and this stuff works for both, so no one gets left out ๐Ÿ’–

NTP packets can carry one or more extension fields, as defined in [NTPv4] ๐ŸŽ€ The Checksum Complement lives in its very own NTP extension field, shown in Figure 3 below ๐Ÿ’…

If there's more than one extension field in the packet, the Checksum Complement extension is ALWAYS the last one ๐Ÿ‘‘ So the Checksum Complement is the last 2 octets in the UDP payload, sitting at (UDP Length - 2 octets) after the start of the UDP header ๐Ÿซถ Also, the Checksum Complement is NOT used in authenticated NTP packets, and we'll get into the tea on that in Section 3.4 ๐Ÿ™ˆ

3.2.1. Using the Checksum Complement

so remember Section 1? An intermediate entity that updates the timestamp in the NTP packet can use the Checksum Complement to keep the UDP Checksum field correct ๐ŸŒธ Here's the vibe: if the timestamp changes, the UDP Checksum changes too ๐Ÿ˜ญ So the intermediate entity writes a new value into the Checksum Complement that cancels that change, and boom, the UDP Checksum is still correct โœจ There's a full example in Appendix A ๐Ÿงš

     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
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |          Field Type           |      Length = 28 octets       |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                                                               |
    |                              MBZ                              |
    |                                                               |
    |                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                               |      Checksum Complement      |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 3: NTP Checksum Complement Extension Field

Field Type ๐Ÿ“

A dedicated Field Type value identifies the Checksum Complement extension. See Section 5 ๐Ÿ’–

Length ๐ŸŒˆ

The Checksum Complement extension field length is 28 octets.

This length makes sure the receiving host parses the packet correctly, whether or not the packet includes a MAC ๐Ÿซถ [RFC7822] has more details about extension field length when there's no MAC.

MBZ ๐Ÿง

The extension field has a 22-octet MBZ (MUST be zero) field. This field MUST be set to 0 and MUST be ignored by the recipient ๐Ÿ™…โ€โ™€๏ธ The MBZ field just pads the extension field out to 28 octets ๐ŸŒท

Checksum Complement ๐Ÿ”ฅ

The Checksum Complement extension has the Checksum Complement field, which lives in the last 2 octets of the extension ๐Ÿ’œ

3.2.2. Transmission of NTP with Checksum Complement

the transmitter of an NTP packet MAY include a Checksum Complement extension field ๐Ÿฆ‹

3.2.3. Updates of NTP with Checksum Complement

an intermediate entity that receives and changes an NTP packet with a Checksum Complement extension MAY use the Checksum Complement to keep a correct UDP Checksum value ๐ŸŒธ

3.2.4. Reception of NTP with Checksum Complement

this document doesn't add new requirements for the receiving end of an NTP packet ๐Ÿ’…

the UDP layer at the receiving end verifies the UDP Checksum of received NTP packets, and the NTP layer SHOULD ignore the Checksum Complement extension field ๐ŸŽ€

3.3. Interoperability with Existing Implementations

the behavior here doesn't add new requirements for receiving NTP packets beyond what [RFC7822] already says ๐Ÿงš Also, as [RFC7822] defines, a host that gets an NTP message with an unknown extension field SHOULD ignore that extension field, and MAY drop the packet if policy requires it ๐Ÿ‘€ So transmitters and intermediate entities that support the Checksum Complement can work smoothly with receivers that don't support it, as long as those receivers ignore unknown extension fields โœจ Fair warning though: existing implementations that throw away packets with unknown extension fields cannot interoperate with transmitters that use the Checksum Complement ๐Ÿ˜ญ

also, when hardware-based timestamping is used, it will likely be used at both ends, so both hosts in the protocol will support what this memo describes ๐Ÿซถ If only one host uses hardware-based timestamping, the Checksum Complement can only be used if it's known that the peer host can accept the Checksum Complement ๐Ÿ™ˆ

3.4. The Checksum Complement and Authentication

okay this one is important bestie ๐Ÿšจ A Checksum Complement MUST NOT be used when authentication is enabled ๐Ÿ›‘ The Checksum Complement is useful in unauthenticated mode, because it lets the intermediate entity process the packet serially without storing and forwarding it ๐Ÿ”ฅ

on the flip side, when message authentication is used, an intermediate entity that changes NTP packets also has to recompute the Message Authentication Code (MAC) ๐Ÿ˜ฉ In that case, the Checksum Complement can't be updated, because updating it would mean recalculating the MAC, and then the MAC and the Checksum Complement would depend on each other in a cycle ๐ŸŒ€ So when the MAC gets updated, the UDP Checksum field has to be updated instead, which makes the Checksum Complement field unnecessary when authentication is in play ๐Ÿ’€


4. Security Considerations ๐Ÿ”

this document shows how a Checksum Complement extension can keep the UDP Checksum correct ๐Ÿ’– The security considerations for time protocols in general are covered in [SecTime], and NTP's security considerations are covered in [NTPv4] ๐Ÿซถ

the whole point of this extension is to make accurate timestamping engines easier to build, as Figure 1 shows โœจ It's meant to be used INTERNALLY in an NTP client or server ๐ŸŽ€ It is NOT meant for switches and routers sitting between the client and the server ๐Ÿ™…โ€โ™€๏ธ Unlike PTP [IEEE1588], NTP doesn't require intermediate switches or routers to change the content of NTP messages, so any change like that should be treated as a malicious man-in-the-middle (MITM) attack ๐Ÿšจ๐Ÿ˜ค

it's really important to say this: the scheme in this document does NOT make the protocol more vulnerable to MITM attacks ๐Ÿ›ก๏ธ A MITM attacker who maliciously changes a packet and its Checksum Complement is logically the same as a MITM attacker who changes a packet and its UDP Checksum field ๐Ÿ’…

the concept in this document is only meant to be used in unauthenticated mode ๐Ÿ”’ As discussed in Section 3.4, if a cryptographic security mechanism is used, the Checksum Complement doesn't make implementation any simpler than the conventional Checksum does, so the Checksum Complement is not used ๐Ÿ™ˆ


5. IANA Considerations ๐Ÿ“‹

IANA has allocated a new value in the "NTP Extension Field Types" registry ๐ŸŽ€

   0x2005 Checksum Complement

6. References ๐Ÿ“š

6.1. Normative References

   [Checksum]  Rijsinghani, A., Ed., "Computation of the Internet
               Checksum via Incremental Update", RFC 1624,
               DOI 10.17487/RFC1624, May 1994,
               <http://www.rfc-editor.org/info/rfc1624>.

   [IPv6]      Deering, S. and R. Hinden, "Internet Protocol, Version 6
               (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460,
               December 1998, <http://www.rfc-editor.org/info/rfc2460>.

   [KEYWORDS]  Bradner, S., "Key words for use in RFCs to Indicate
               Requirement Levels", BCP 14, RFC 2119,
               DOI 10.17487/RFC2119, March 1997,
               <http://www.rfc-editor.org/info/rfc2119>.

   [NTPv4]     Mills, D., Martin, J., Ed., Burbank, J., and W. Kasch,
               "Network Time Protocol Version 4: Protocol and Algorithms
               Specification", RFC 5905, DOI 10.17487/RFC5905,
               June 2010, <http://www.rfc-editor.org/info/rfc5905>.

   [RFC7822]   Mizrahi, T. and D. Mayer, "Network Time Protocol
               Version 4 (NTPv4) Extension Fields", RFC 7822,
               DOI 10.17487/RFC7822, March 2016,
               <http://www.rfc-editor.org/info/rfc7822>.

   [UDP]       Postel, J., "User Datagram Protocol", STD 6, RFC 768,
               DOI 10.17487/RFC768, August 1980,
               <http://www.rfc-editor.org/info/rfc768>.

6.2. Informative References

   [IEEE1588]  IEEE, "IEEE Standard for a Precision Clock
               Synchronization Protocol for Networked Measurement and
               Control Systems", IEEE Std 1588-2008,
               DOI 10.1109/IEEESTD.2008.4579760, July 2008.

   [RFC7820]   Mizrahi, T., "UDP Checksum Complement in the One-Way
               Active Measurement Protocol (OWAMP) and Two-Way Active
               Measurement Protocol (TWAMP)", RFC 7820,
               DOI 10.17487/RFC7820, March 2016,
               <http://www.rfc-editor.org/info/rfc7820>.

   [SecTime]   Mizrahi, T., "Security Requirements of Time Protocols in
               Packet Switched Networks", RFC 7384,
               DOI 10.17487/RFC7384, October 2014,
               <http://www.rfc-editor.org/info/rfc7384>.

   [ZeroChecksum]
               Fairhurst, G. and M. Westerlund, "Applicability Statement
               for the Use of IPv6 UDP Datagrams with Zero Checksums",
               RFC 6936, DOI 10.17487/RFC6936, April 2013,
               <http://www.rfc-editor.org/info/rfc6936>.

Appendix A. Checksum Complement Usage Example ๐Ÿง

let's walk through an NTP packet going from an NTP client to an NTP server ๐Ÿฆ‹

the client's software layer (see Figure 1) makes an NTP packet with an Origin Timestamp T and a UDP Checksum value U ๐ŸŒธ The value of U is the checksum of the UDP header, UDP payload, and pseudo-header ๐Ÿ’œ So U works out to:

                     U = Const + checksum(T)                     (1)

where "Const" is the checksum of all the fields covered by the checksum, EXCEPT the Origin Timestamp T โœจ

remember, the client's software sends the NTP packet with a Checksum Complement extension field, which sits at the end of the PTP packet ๐ŸŽ€ It's assumed the client starts out with the Checksum Complement set to zero ๐Ÿซถ

the client's timestamping engine updates the Origin Timestamp field to the accurate time, changing its value from T to T' โฐ The engine also updates the Checksum Complement field from zero to a new value C, so that:

               checksum(C) = checksum(T) - checksum(T')          (2)

when the client's timestamping engine transmits the NTP packet, the checksum value is still U, same as before:

  U = Const + checksum(T) = Const + checksum(T) + checksum(T') -
      checksum(T') = Const + checksum(T') + checksum(C)          (3)

so after the timestamping engine updates the timestamp, U is STILL the correct checksum for the packet ๐ŸŽ‰

when the NTP packet reaches the NTP server, the server does a conventional UDP Checksum computation, and the result is U ๐Ÿ’… Since the Checksum Complement is part of the extension field, its value (C) gets included in the computation automatically, as shown in Equation (3), without the server needing any special handling ๐Ÿ‘‘

Acknowledgments ๐Ÿซถ

okay bestie, the author wants to thank some people who really showed up ๐Ÿ’– Danny Mayer, Miroslav Lichvar, Paul Kyzivat, Suresh Krishnan, and Brian Haberman all reviewed the work and left helpful comments, and the author is so grateful for that โœจ

Author's Address ๐Ÿฆ‹

this is where you can find the author, Tal Mizrahi ๐Ÿ’œ

Tal Mizrahi
Marvell
6 Hamada St.
Yokneam, 20692
Israel

Email: talmi@marvell.com

that's the whole document, and you made it through all three parts ๐ŸŽ€๐ŸŒˆ

๐Ÿ“ฆ where this page comes from