Skip to content

Commit a7da9c2

Browse files
committed
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 <[email protected]>
1 parent 13bf815 commit a7da9c2

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

print-ptp.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ static const struct tok ptp_msg_type[] = {
209209
#define PTP_HDR_LEN 0x22
210210

211211
/* mask based on the first byte */
212-
#define PTP_VERS_MASK 0xFF
212+
#define PTP_MAJOR_VERS_MASK 0x0F
213+
#define PTP_MINOR_VERS_MASK 0xF0
213214
#define PTP_V1_COMPAT 0x10
214215
#define PTP_MSG_TYPE_MASK 0x0F
215216

@@ -433,15 +434,27 @@ ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
433434
void
434435
ptp_print(netdissect_options *ndo, const u_char *bp, u_int len)
435436
{
436-
u_int vers;
437-
437+
u_int major_vers;
438+
u_int minor_vers;
439+
440+
/* In 1588-2019, a minorVersionPTP field has been created in the common PTP
441+
* message header, from a previously reserved field. Implementations
442+
* compatible to the 2019 edition shall indicate a versionPTP field value
443+
* of 2 and minorVersionPTP field value of 1, indicating that this is PTP
444+
* version 2.1.
445+
*/
438446
ndo->ndo_protocol = "ptp";
439447
if (len < PTP_HDR_LEN) {
440448
goto trunc;
441449
}
442-
vers = GET_BE_U_2(bp) & PTP_VERS_MASK;
443-
ND_PRINT("PTPv%u",vers);
444-
switch(vers) {
450+
major_vers = GET_BE_U_2(bp) & PTP_MAJOR_VERS_MASK;
451+
minor_vers = (GET_BE_U_2(bp) & PTP_MINOR_VERS_MASK) >> 4;
452+
if (minor_vers)
453+
ND_PRINT("PTPv%u.%u", major_vers, minor_vers);
454+
else
455+
ND_PRINT("PTPv%u", major_vers);
456+
457+
switch(major_vers) {
445458
case PTP_VER_1:
446459
ptp_print_1(ndo);
447460
break;

0 commit comments

Comments
 (0)