Skip to content

Commit d039af7

Browse files
committed
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>
1 parent 59028c4 commit d039af7

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/statd/python/yanger/ietf_ntp.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,20 @@ def add_ntp_clock_state(out):
191191
refid_ip = parts[0]
192192
refid_name = parts[1]
193193

194-
if refid_name:
195-
# NTP refids are always 4 bytes; chronyc strips trailing padding.
196-
# YANG typedef 'refid' requires exactly length 4 for strings.
194+
def _is_ipv4(s):
195+
p = s.split('.')
196+
if len(p) != 4:
197+
return False
198+
try:
199+
return all(0 <= int(x) <= 255 for x in p)
200+
except ValueError:
201+
return False
202+
203+
if refid_name and _is_ipv4(refid_name):
204+
# chronyc reports the IPv4 server address as the name field; use it directly
205+
system_status["clock-refid"] = refid_name
206+
elif refid_name and ':' not in refid_name:
207+
# Short NTP code (GPS, NIST, INIT, …); YANG refid requires length 4
197208
system_status["clock-refid"] = refid_name.ljust(4)[:4]
198209
elif refid_ip and len(refid_ip) == 8:
199210
try:

0 commit comments

Comments
 (0)