mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
Fix #1458: 'show ntp tracking' does not show reference id properly
admin@gateway:~$ chronyc tracking Reference ID : C23ACD14 (svl1.ntp.netnod.se) Stratum : 2 Ref time (UTC) : Sun Apr 19 20:28:40 2026 System time : 0.000000000 seconds fast of NTP time Last offset : -17.822519302 seconds RMS offset : 17.822519302 seconds Frequency : 1064.750 ppm slow Residual freq : +0.581 ppm Skew : 0.794 ppm Root delay : 0.018065268 seconds Root dispersion : 0.000200240 seconds Update interval : 0.0 seconds Leap status : Normal vs admin@gateway:/> show ntp tracking Reference ID : 194.58.205.20 Stratum : 2 Ref time (UTC) : Sun Apr 19 20:28:40 2026 System time : 0.000000 seconds slow of NTP time Last offset : -17.822519302 seconds RMS offset : 17.822519302 seconds Frequency : 1064.750 ppm slow Residual freq : +0.581 ppm Skew : 0.794 ppm Root delay : 0.018065 seconds Root dispersion : 0.000188 seconds Update interval : 0.0 seconds Leap status : Normal Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -191,9 +191,20 @@ def add_ntp_clock_state(out):
|
||||
refid_ip = parts[0]
|
||||
refid_name = parts[1]
|
||||
|
||||
if refid_name:
|
||||
# NTP refids are always 4 bytes; chronyc strips trailing padding.
|
||||
# YANG typedef 'refid' requires exactly length 4 for strings.
|
||||
def _is_ipv4(s):
|
||||
p = s.split('.')
|
||||
if len(p) != 4:
|
||||
return False
|
||||
try:
|
||||
return all(0 <= int(x) <= 255 for x in p)
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
if refid_name and _is_ipv4(refid_name):
|
||||
# chronyc reports the IPv4 server address as the name field; use it directly
|
||||
system_status["clock-refid"] = refid_name
|
||||
elif refid_name and ':' not in refid_name:
|
||||
# Short NTP code (GPS, NIST, INIT, …); YANG refid requires length 4
|
||||
system_status["clock-refid"] = refid_name.ljust(4)[:4]
|
||||
elif refid_ip and len(refid_ip) == 8:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user