From: Casper Andersson Date: Mon, 10 Jul 2023 21:29:51 +0000 (+0200) Subject: ptp: Parse major and minor version correctly X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/63134a45c19b49ea113f2c88fa7367be13997ac0 ptp: Parse major and minor version correctly 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 --- diff --git a/print-ptp.c b/print-ptp.c index 3b457627..4d0bac22 100644 --- a/print-ptp.c +++ b/print-ptp.c @@ -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;