]> The Tcpdump Group git mirrors - tcpdump/commitdiff
PTP: fix printing of the correction fields
authorCharles (Chas) Williams <[email protected]>
Wed, 5 Oct 2022 11:58:01 +0000 (07:58 -0400)
committerfxlb <[email protected]>
Fri, 14 Oct 2022 04:18:59 +0000 (04:18 +0000)
The nanosecond part of the correction field is 48 bits and the
sub-nanosecond part is 16 bits.

print-ptp.c
tests/TESTLIST
tests/ptp_corrections.out [new file with mode: 0644]
tests/ptp_corrections.pcap [new file with mode: 0644]

index c4ff02042e4ef2e480908aa20f1521fa38e6fce2..3f538f00191cc3f79fb0b0693292ef1a782da04f 100644 (file)
@@ -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);
index 0e1c071d81d9ee854136d0fe7ed4a60406162f2c..460a8a1affce250c22fdba278afb6f2d19887c81 100644 (file)
@@ -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 (file)
index 0000000..394fdd2
--- /dev/null
@@ -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 (file)
index 0000000..3d2386e
Binary files /dev/null and b/tests/ptp_corrections.pcap differ