pub enum ReferenceIdentifier {
PrimarySource(PrimarySource),
SecondaryOrClient([u8; 4]),
KissOfDeath(KissOfDeath),
Unknown([u8; 4]),
}Expand description
A 32-bit code identifying the particular server or reference clock.
The interpretation depends on the value in the stratum field:
- For packet stratum 0 (unspecified or invalid), this is a four-character ASCII [RFC1345] string, called the “kiss code”, used for debugging and monitoring purposes.
- For stratum 1 (reference clock), this is a four-octet, left-justified, zero-padded ASCII string assigned to the reference clock.
The authoritative list of Reference Identifiers is maintained by IANA; however, any string beginning with the ASCII character “X” is reserved for unregistered experimentation and development.
Variants§
PrimarySource(PrimarySource)
Primary reference source (stratum 1) identifier.
SecondaryOrClient([u8; 4])
The reference identifier of the secondary or client server. Can be used to detect timing loops.
If using the IPv4 address family, the identifier is the four-octet IPv4 address.
If using the IPv6 address family, it is the first four octets of the MD5 hash of the IPv6 address. Note that when using the IPv6 address family on a NTPv4 server with a NTPv3 client, the Reference Identifier field appears to be a random value and a timing loop might not be detected.
KissOfDeath(KissOfDeath)
Kiss-o’-Death packet code (stratum 0).
Unknown([u8; 4])
An unrecognized 4-byte reference identifier.
Used for stratum 0 packets with non-standard kiss codes, stratum 1 packets with unrecognized reference source identifiers, and stratum 16+ (unsynchronized/reserved) packets.
Implementations§
Source§impl ReferenceIdentifier
impl ReferenceIdentifier
Sourcepub fn from_bytes_with_stratum(
bytes: [u8; 4],
stratum: Stratum,
) -> ReferenceIdentifier
pub fn from_bytes_with_stratum( bytes: [u8; 4], stratum: Stratum, ) -> ReferenceIdentifier
Parse a reference identifier from 4 bytes, using stratum for disambiguation.
The interpretation of the reference identifier depends on the stratum:
- Stratum 0: Kiss-o’-Death code
- Stratum 1: Primary source identifier
- Stratum 2-15: Secondary/client reference (IPv4 or IPv6 hash)
- Stratum 16+: Unknown
Source§impl ReferenceIdentifier
impl ReferenceIdentifier
Sourcepub fn as_bytes(&self) -> [u8; 4]
pub fn as_bytes(&self) -> [u8; 4]
Returns the raw 4-byte representation of the reference identifier.
Sourcepub fn is_kiss_of_death(&self) -> bool
pub fn is_kiss_of_death(&self) -> bool
Returns true if this is a Kiss-o’-Death reference identifier.
Sourcepub fn from_ipv4(addr: Ipv4Addr) -> ReferenceIdentifier
pub fn from_ipv4(addr: Ipv4Addr) -> ReferenceIdentifier
Construct a reference identifier from an IPv4 address.
For stratum 2+ servers, the reference identifier is the upstream server’s IPv4 address (RFC 5905 Section 7.3).
Sourcepub fn from_ipv6(addr: Ipv6Addr) -> ReferenceIdentifier
pub fn from_ipv6(addr: Ipv6Addr) -> ReferenceIdentifier
Construct a reference identifier from an IPv6 address.
Per RFC 5905, the reference identifier for IPv6 peers is the first
4 bytes of MD5(IPv6_address).
§Collision Risk
This 4-byte hash may coincidentally match an IPv4 address, causing
false positive loop detection. draft-ietf-ntp-refid-updates-05
proposes a fix but is stalled. NTPv5’s 120-bit Bloom filter
Reference IDs eliminate this problem entirely.
Sourcepub fn matches_ipv4(&self, addr: Ipv4Addr) -> bool
pub fn matches_ipv4(&self, addr: Ipv4Addr) -> bool
Check if this reference identifier matches an IPv4 address.
Used for loop detection: if the upstream server’s reference ID matches our own IPv4 address, a timing loop exists.
Trait Implementations§
Source§impl Clone for ReferenceIdentifier
impl Clone for ReferenceIdentifier
Source§fn clone(&self) -> ReferenceIdentifier
fn clone(&self) -> ReferenceIdentifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConstPackedSizeBytes for ReferenceIdentifier
impl ConstPackedSizeBytes for ReferenceIdentifier
Source§const PACKED_SIZE_BYTES: usize = 4
const PACKED_SIZE_BYTES: usize = 4
Source§impl Debug for ReferenceIdentifier
impl Debug for ReferenceIdentifier
Source§impl Default for ReferenceIdentifier
impl Default for ReferenceIdentifier
Source§fn default() -> ReferenceIdentifier
fn default() -> ReferenceIdentifier
Defaults to Unknown([0; 4]) (unset reference identifier).
Source§impl Hash for ReferenceIdentifier
impl Hash for ReferenceIdentifier
Source§impl PartialEq for ReferenceIdentifier
impl PartialEq for ReferenceIdentifier
Source§impl ToBytes for ReferenceIdentifier
impl ToBytes for ReferenceIdentifier
Source§fn to_bytes(&self, buf: &mut [u8]) -> Result<usize, ParseError>
fn to_bytes(&self, buf: &mut [u8]) -> Result<usize, ParseError>
ParseError::BufferTooShort if buf is too short.