Skip to content

Commit 63134a4

Browse files
cappe987fxlb
authored andcommitted
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 1e3b959 commit 63134a4

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
@@ -231,7 +231,8 @@ static const struct tok ptp_control_field[] = {
231231
#define PTP_HDR_LEN 0x22
232232

233233
/* mask based on the first byte */
234-
#define PTP_VERS_MASK 0xFF
234+
#define PTP_MAJOR_VERS_MASK 0x0F
235+
#define PTP_MINOR_VERS_MASK 0xF0
235236
#define PTP_V1_COMPAT 0x10
236237
#define PTP_MSG_TYPE_MASK 0x0F
237238

@@ -449,13 +450,25 @@ ptp_print_2(netdissect_options *ndo, const u_char *bp, u_int length)
449450
void
450451
ptp_print(netdissect_options *ndo, const u_char *bp, u_int length)
451452
{
452-
u_int vers;
453-
453+
u_int major_vers;
454+
u_int minor_vers;
455+
456+
/* In 1588-2019, a minorVersionPTP field has been created in the common PTP
457+
* message header, from a previously reserved field. Implementations
458+
* compatible to the 2019 edition shall indicate a versionPTP field value
459+
* of 2 and minorVersionPTP field value of 1, indicating that this is PTP
460+
* version 2.1.
461+
*/
454462
ndo->ndo_protocol = "ptp";
455463
ND_ICHECK_U(length, <, PTP_HDR_LEN);
456-
vers = GET_BE_U_2(bp) & PTP_VERS_MASK;
457-
ND_PRINT("PTPv%u",vers);
458-
switch(vers) {
464+
major_vers = GET_BE_U_2(bp) & PTP_MAJOR_VERS_MASK;
465+
minor_vers = (GET_BE_U_2(bp) & PTP_MINOR_VERS_MASK) >> 4;
466+
if (minor_vers)
467+
ND_PRINT("PTPv%u.%u", major_vers, minor_vers);
468+
else
469+
ND_PRINT("PTPv%u", major_vers);
470+
471+
switch(major_vers) {
459472
case PTP_VER_1:
460473
ptp_print_1(ndo);
461474
break;

0 commit comments

Comments
 (0)