]> The Tcpdump Group git mirrors - tcpdump/commitdiff
ptp: Parse major and minor version correctly
authorCasper Andersson <[email protected]>
Mon, 10 Jul 2023 21:29:51 +0000 (23:29 +0200)
committerfxlb <[email protected]>
Fri, 14 Jul 2023 06:05:18 +0000 (06:05 +0000)
In IEEE1588-2008, the lower 4 bits of the field were defined as the PTP
version, and the upper 4 bits were marked as reserved. As of the 2019
version the upper 4 bits are defined as PTP minor version. Previously,
the whole byte was assumed to be the version by Tcpdump, resulting in
PTP v2.1 being parsed as v18 and not printing the rest of the
information.

With this commit the version is parsed correctly and the packet is
displayed as v2. Note: I do not have access to the 2019 version, so I
unfortunately can't add whatever new features it adds.

Signed-off-by: Casper Andersson <[email protected]>
print-ptp.c

index 3b4576273ee5c81b87108146edd6a9c5a3ada4c7..4d0bac2276968f2599aa079693d37ee0fb891190 100644 (file)
@@ -231,7 +231,8 @@ static const struct tok ptp_control_field[] = {
 #define PTP_HDR_LEN         0x22
 
 /* mask based on the first byte */
-#define PTP_VERS_MASK       0xFF
+#define PTP_MAJOR_VERS_MASK 0x0F
+#define PTP_MINOR_VERS_MASK 0xF0
 #define PTP_V1_COMPAT       0x10
 #define PTP_MSG_TYPE_MASK   0x0F
 
@@ -449,13 +450,25 @@ ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
 void
 ptp_print(netdissect_options *ndo, const u_char *bp, u_int length)
 {
-    u_int vers;
-
+    u_int major_vers;
+    u_int minor_vers;
+
+    /* In 1588-2019, a minorVersionPTP field has been created in the common PTP
+     * message header, from a previously reserved field. Implementations
+     * compatible to the 2019 edition shall indicate a versionPTP field value
+     * of 2 and minorVersionPTP field value of 1, indicating that this is PTP
+     * version 2.1.
+     */
     ndo->ndo_protocol = "ptp";
     ND_ICHECK_U(length, <, PTP_HDR_LEN);
-    vers = GET_BE_U_2(bp) & PTP_VERS_MASK;
-    ND_PRINT("PTPv%u",vers);
-    switch(vers) {
+    major_vers = GET_BE_U_2(bp) & PTP_MAJOR_VERS_MASK;
+    minor_vers = (GET_BE_U_2(bp) & PTP_MINOR_VERS_MASK) >> 4;
+    if (minor_vers)
+           ND_PRINT("PTPv%u.%u", major_vers, minor_vers);
+    else
+           ND_PRINT("PTPv%u", major_vers);
+
+    switch(major_vers) {
         case PTP_VER_1:
             ptp_print_1(ndo);
             break;