Expand description
SNTP client for Xila: sets the system UTC clock from the network.
The protocol is not reimplemented here. The [sntpc] crate (RFC 4330 and
RFC 5905, SNTP version 4 over UDP port 123) builds and validates the
packets, reconstructs the NTP era and computes the offset from all four
timestamps. This module only adapts it to Xila: a [sntpc::NtpUdpSocket]
over the network subsystem’s UDP socket, a [sntpc::NtpTimestampGenerator]
over the time manager, and the application of the result through
time::Manager::set_realtime with ClockSource::Network.
The client lives in the network subsystem because it is a network service
owned by that runtime. It resolves server names with
Manager::resolve and opens its socket with
Manager::new_udp_socket, and it needs
the task spawner, the virtual file system (for the configuration file) and
the time manager, which are already its dependencies. The UDP socket is
created once and reused (it buffers 4 datagrams); DNS resolution returns a
heap Vec per name, cached for one hour.
§Safety bounds
Answers before the platform’s minimum timestamp (the build date on devices
without a battery clock) are rejected. After the first network
synchronization, a clock step larger than 1000 s is applied only when a
second answer confirms it: the signed offset of the two answers (candidate
minus the current clock) must agree within 5 s. Another configured server
in the same attempt confirms at once; otherwise a later attempt confirms,
possibly from another address if DNS rotates. With a single server, only
later exchanges of that server can confirm, so a single-server setup only
resists a blind off-path attacker. Unauthenticated SNTP cannot stop an
on-path attacker, and sntpc 0.11 does not randomize the low bits of the
transmit timestamp as RFC 5905 section 8 asks; each exchange sends from a
fresh source port instead (the stack’s port counter is sequential).
§Configuration and the NTP Pool
Servers come from /configuration/system/sntp.json (default
pool.ntp.org, resynchronized every hour). The default server name is a
placeholder only: the NTP Pool asks vendors not to ship the standard
pool.ntp.org names as a default configuration (“You must absolutely not
use the default pool.ntp.org zone names as the default configuration in your
application or appliance.”), and to request a vendor zone such as
xila.pool.ntp.org instead. See https://www.ntppool.org/vendors.html.
Service::start spawns the synchronization task: it waits until an
interface has an address, queries the configured servers at random times,
then resynchronizes periodically with a bounded exponential backoff on
failure. Kiss-of-death answers ban or slow down a server per RFC 5905
section 7.4.
Structs§
- Service
- The SNTP service, assembled from the runtime subsystems it needs.