Skip to content

Commit c99c899

Browse files
demsbjf8fxlb
authored andcommitted
NTP: Print kiss codes relevant for NTP debugging
NTPv4 (RFC 5905, section 7.4) formalizes that if the stratum value is zero, the refid _may_ contain a printable ("designed for character displays and log files"), four-character, left justified, zero filled ASCII string for status reporting and debugging ("kiss code"). RFC 5905 establishes a registry at IANA for kiss codes, initially populated with values defined in the RFC, but the list may be modified or extended in the future, and unregistered kiss codes, e.g., for experimentation and development, are possible (and are being seen in the field). Thus, IF the stratum value is zero AND the refid field begins with a printable character, assume the refid field contains a kiss code and print it (instead of current "(unspec)").
1 parent 72095a1 commit c99c899

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
2424
NetFlow: Use tcp_flag_values[] for TCP flags.
2525
NTP: Check that the entire extension field is in the capture even
2626
if it isn't printed
27+
NTP: Print kiss codes relevant for NTP debugging.
2728
MPTCP: parse MPC data_len field, print flags from MP_CAPABLE option.
2829
OSPF: Fix printing of Traffic Engineering Link TLVs to correctly
2930
advance the packet data pointer

print-ntp.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <config.h>
3636

3737
#include "netdissect-stdinc.h"
38+
#include "netdissect-ctype.h"
3839

3940
#define ND_LONGJMP_FROM_TCHECK
4041
#include "netdissect.h"
@@ -268,8 +269,20 @@ ntp_time_print(netdissect_options *ndo,
268269
switch (stratum) {
269270

270271
case UNSPECIFIED:
271-
ND_PRINT("(unspec)");
272-
ND_TCHECK_4(bp->refid);
272+
/* NTPv4 (RFC 5905, section 7.4) formalizes that refid _may_
273+
* contain a printable, four-character, left justified, zero
274+
* filled ASCII string ("kiss code") for status reporting
275+
* and debugging. Some kiss codes are defined in the RFC as
276+
* initial set for a new IANA registry, but the list may be
277+
* modified or extended in the future, and unregistered kiss
278+
* codes are possible (and are being seen in the field).
279+
*/
280+
if (!ND_ASCII_ISPRINT((bp->refid)[0])) {
281+
ND_PRINT("(unspec)");
282+
ND_TCHECK_4(bp->refid);
283+
} else {
284+
nd_printjn(ndo, (const u_char *)&(bp->refid), 4);
285+
}
273286
break;
274287

275288
case PRIM_REF:

tests/ntp-v.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
2 2017-06-19 14:12:10.231082 IP (tos 0xb8, ttl 64, id 24722, offset 0, flags [DF], proto UDP (17), length 80)
1414
192.168.100.1.123 > 192.168.100.2.58054: NTPv4, Server, length 52
1515
Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 3 (8s), precision -23
16-
Root Delay: 0.000000, Root dispersion: 0.001373, Reference-ID: (unspec)
16+
Root Delay: 0.000000, Root dispersion: 0.001373, Reference-ID: STEP
1717
Reference Timestamp: 0.000000000
1818
Originator Timestamp: 2763234513.007738396 (1987-07-25T21:08:33Z)
1919
Receive Timestamp: 3706870329.516015118 (2017-06-19T14:12:09Z)
@@ -68,7 +68,7 @@
6868
7 2017-06-19 14:47:12.800853 IP (tos 0xc0, ttl 64, id 4575, offset 0, flags [DF], proto UDP (17), length 96)
6969
192.168.100.2.123 > 192.168.100.1.123: NTPv4, Client, length 68
7070
Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -25
71-
Root Delay: 0.000000, Root dispersion: 0.000000, Reference-ID: (unspec)
71+
Root Delay: 0.000000, Root dispersion: 0.000000, Reference-ID: INIT
7272
Reference Timestamp: 0.000000000
7373
Originator Timestamp: 0.000000000
7474
Receive Timestamp: 0.000000000

0 commit comments

Comments
 (0)