From c8a59b1d2a8b01e12a071a08810a9959f55a9fef Mon Sep 17 00:00:00 2001 From: "Charles (Chas) Williams" Date: Wed, 5 Oct 2022 07:58:01 -0400 Subject: [PATCH] PTP: fix printing of the correction fields The nanosecond part of the correction field is 48 bits and the sub-nanosecond part is 16 bits. --- print-ptp.c | 17 ++++++++++------- tests/TESTLIST | 1 + tests/ptp_corrections.out | 3 +++ tests/ptp_corrections.pcap | Bin 0 -> 340 bytes 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 tests/ptp_corrections.out create mode 100644 tests/ptp_corrections.pcap diff --git a/print-ptp.c b/print-ptp.c index c4ff0204..3f538f00 100644 --- a/print-ptp.c +++ b/print-ptp.c @@ -35,7 +35,8 @@ * | domain No | rsvd1 | flag Field | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Correction NS | - * | Correction Sub NS | + * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | Correction Sub NS | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Reserved2 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -345,7 +346,9 @@ ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length) u_int len = length; uint16_t msg_len, flags, port_id, seq_id; uint8_t foct, domain_no, msg_type, v1_compat, rsvd1, lm_int, control; - uint32_t ns_corr, sns_corr, rsvd2; + uint64_t ns_corr; + uint16_t sns_corr; + uint32_t rsvd2; uint64_t clk_id; foct = GET_U_1(bp); @@ -367,14 +370,14 @@ ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length) /* flags */ len -= 2; bp += 2; flags = GET_BE_U_2(bp); ND_PRINT(", Flags [%s]", bittok2str(ptp_flag_values, "none", flags)); - /* correction NS */ - len -= 2; bp += 2; ns_corr = GET_BE_U_4(bp); ND_PRINT(", NS correction : %u", ns_corr); + /* correction NS (48 bits) */ + len -= 2; bp += 2; ns_corr = GET_BE_U_6(bp); ND_PRINT(", NS correction : %"PRIu64, ns_corr); - /* correction sub NS */ - len -= 4; bp += 4; sns_corr = GET_BE_U_4(bp); ND_PRINT(", sub NS correction : %u", sns_corr); + /* correction sub NS (16 bits) */ + len -= 6; bp += 6; sns_corr = GET_BE_U_2(bp); ND_PRINT(", sub NS correction : %u", sns_corr); /* Reserved 2 */ - len -= 4; bp += 4; rsvd2 = GET_BE_U_4(bp); ND_PRINT(", reserved2 : %u", rsvd2); + len -= 2; bp += 2; rsvd2 = GET_BE_U_4(bp); ND_PRINT(", reserved2 : %u", rsvd2); /* clock identity */ len -= 4; bp += 4; clk_id = GET_BE_U_8(bp); ND_PRINT(", clock identity : 0x%"PRIx64, clk_id); diff --git a/tests/TESTLIST b/tests/TESTLIST index 0e1c071d..460a8a1a 100644 --- a/tests/TESTLIST +++ b/tests/TESTLIST @@ -874,6 +874,7 @@ huge-tipc-messages huge-tipc-messages.pcap huge-tipc-messages.out #ptp tests ptp ptp.pcap ptp.out ptp_ethernet ptp_ethernet.pcap ptp_ethernet.out -e +ptp_corrections ptp_corrections.pcap ptp_corrections.out # bad packets from Jason Xiaole ldp_tlv_print-oobr ldp_tlv_print-oobr.pcap ldp_tlv_print-oobr.out -v diff --git a/tests/ptp_corrections.out b/tests/ptp_corrections.out new file mode 100644 index 00000000..394fdd2d --- /dev/null +++ b/tests/ptp_corrections.out @@ -0,0 +1,3 @@ + 1 17:52:26.679146 IP 4.5.0.2.319 > 2.2.2.2.319: PTPv2, v1 compat : no, msg type : delay req msg, length : 44, domain : 44, reserved1 : 0, Flags [unicast], NS correction : 0, sub NS correction : 0, reserved2 : 0, clock identity : 0xa0369ffffe856e8a, port id : 1, seq id : 1203, control : 1 (delay req msg), log message interval : 127, originTimeStamp : 0 seconds, 0 nanoseconds + 2 17:52:26.679265 IP 2.2.2.2.320 > 4.5.0.2.320: PTPv2, v1 compat : no, msg type : delay resp msg, length : 54, domain : 44, reserved1 : 0, Flags [unicast], NS correction : 36035, sub NS correction : 0, reserved2 : 0, clock identity : 0xe8c57affff01313f, port id : 3, seq id : 1203, control : 3 (peer delay resp msg), log message interval : 127, receiveTimeStamp : 1665510783 seconds, 679015501 nanoseconds, port identity : 0xa0369ffffe856e8a, port id : 1 + 3 17:52:26.682034 IP 2.2.2.2.319 > 4.5.0.2.319: PTPv2, v1 compat : no, msg type : sync msg, length : 44, domain : 44, reserved1 : 0, Flags [unicast], NS correction : 105045, sub NS correction : 0, reserved2 : 0, clock identity : 0xe8c57affff01313f, port id : 3, seq id : 1213, control : 0 (sync msg), log message interval : 127, originTimeStamp : 1665510783 seconds, 681548698 nanoseconds diff --git a/tests/ptp_corrections.pcap b/tests/ptp_corrections.pcap new file mode 100644 index 0000000000000000000000000000000000000000..3d2386eed5128a0bfdd5ce46edab3447cf9d8925 GIT binary patch literal 340 zcmca|c+)~A1{MYcU}0bca-!C{Cclc|Vh97WLHNbdDn>*51!nVG^SU?~Tp1WV9`QLa zI0y#xu&^>PfdHdDqdkKOM*t%egN_c0i3|)tegFRfbuuurY-X%S*afmBF_w!V0Vo8* z5c45+0d0A}5X8U$vc+&C$Oe#2j1G(r40hY^axyWP!EEU{4Acq)Kz;xJ16|3$%(9so zXiKu|+Io$OFTM!dLG~GCAbf>kp9j>w-EjNBzS?8LfbbRLtWXU5_A