Skip to content

PTP: Refine timestamp printing. #1277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
the subrule is present (inspird by the OpenBSD tcpdump).
pflog: Handle OpenBSD's "rewritten" flag and addresses (adapted
from the OpenBSD tcpdump).
PTP: Refine timestamp printing.
SLL2: Translate interface indices to names on Linux only.
RT6: Add a bounds check for the PadN TLV in Segment Routing Header.
TCP: Add support for the AE (AccECN) flag.
Expand Down
42 changes: 12 additions & 30 deletions print-ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
#include "timeval-operations.h"

/*
* PTP header
Expand Down Expand Up @@ -227,6 +228,7 @@ static const struct tok ptp_control_field[] = {
#define PTP_FALSE !PTP_TRUE

#define PTP_HDR_LEN 0x22
#define PTP_TIMESTAMP_LEN 10U

/* mask based on the first byte */
#define PTP_MAJOR_VERS_MASK 0x0F
Expand Down Expand Up @@ -495,37 +497,28 @@ ptp_print_timestamp(netdissect_options *ndo, const u_char *bp, u_int *len, const
ND_PRINT(", %s:", stype);
/* sec time stamp 6 bytes */
secs = GET_BE_U_6(bp);
ND_PRINT(" %"PRIu64" seconds,", secs);
ND_PRINT(" %"PRIu64".", secs);
*len -= 6;
bp += 6;

/* NS time stamp 4 bytes */
nsecs = GET_BE_U_4(bp);
ND_PRINT(" %u nanoseconds", nsecs);
ND_PRINT("%09u seconds", nsecs);
if (nsecs > ND_NANO_PER_SEC - 1)
ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
*len -= 4;
bp += 4;
}
static void
ptp_print_timestamp_identity(netdissect_options *ndo,
const u_char *bp, u_int *len, const char *ttype)
{
uint64_t secs;
uint32_t nsecs;
uint16_t port_id;
uint64_t port_identity;

ND_PRINT(", %s:", ttype);
/* sec time stamp 6 bytes */
secs = GET_BE_U_6(bp);
ND_PRINT(" %"PRIu64" seconds,", secs);
*len -= 6;
bp += 6;

/* NS time stamp 4 bytes */
nsecs = GET_BE_U_4(bp);
ND_PRINT(" %u nanoseconds", nsecs);
*len -= 4;
bp += 4;
ptp_print_timestamp(ndo, bp, len, ttype);
*len -= PTP_TIMESTAMP_LEN;
bp += PTP_TIMESTAMP_LEN;

/* port identity*/
port_identity = GET_BE_U_8(bp);
Expand All @@ -545,21 +538,10 @@ ptp_print_announce_msg(netdissect_options *ndo, const u_char *bp, u_int *len)
uint8_t rsvd, gm_prio_1, gm_prio_2, gm_clk_cls, gm_clk_acc, time_src;
uint16_t origin_cur_utc, gm_clk_var, steps_removed;
uint64_t gm_clock_id;
uint64_t secs;
uint32_t nsecs;

ND_PRINT(", %s:", p_origin_ts);
/* sec time stamp 6 bytes */
secs = GET_BE_U_6(bp);
ND_PRINT(" %"PRIu64" seconds", secs);
*len -= 6;
bp += 6;

/* NS time stamp 4 bytes */
nsecs = GET_BE_U_4(bp);
ND_PRINT(" %u nanoseconds", nsecs);
*len -= 4;
bp += 4;
ptp_print_timestamp(ndo, bp, len, p_origin_ts);
*len -= PTP_TIMESTAMP_LEN;
bp += PTP_TIMESTAMP_LEN;

/* origin cur utc */
origin_cur_utc = GET_BE_U_2(bp);
Expand Down
10 changes: 5 additions & 5 deletions tests/ptp.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 2018-01-23 19:44:09.248292 IP 11.0.0.110.319 > 224.0.1.129.319: PTPv2, majorSdoId: 0x0, msg type: delay req msg, length: 44, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x7cfe90fffef950b4, port id: 1, seq id: 132, control: 1 (Delay_Req), log message interval: 127, originTimeStamp: 0 seconds, 0 nanoseconds
2 2018-01-23 19:44:09.248437 IP 11.0.0.9.320 > 224.0.1.129.320: PTPv2, majorSdoId: 0x0, msg type: delay resp msg, length: 54, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 132, control: 3 (Delay_Resp), log message interval: 0, receiveTimeStamp: 1516736649 seconds, 248292005 nanoseconds, port identity: 0x7cfe90fffef950b4, port id: 1
3 2018-01-23 19:44:09.982883 IP 11.0.0.9.320 > 224.0.1.129.320: PTPv2, majorSdoId: 0x0, msg type: announce msg, length: 64, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 534, control: 5 (Other), log message interval: 1, originTimeStamp: 0 seconds 0 nanoseconds, origin cur utc:36, rsvd: 0, gm priority_1: 128, gm clock class: 248, gm clock accuracy: 254, gm clock variance: 65535, gm priority_2: 128, gm clock id: 0x200fffe000001, steps removed: 0, time source: 0xa0
4 2018-01-23 19:44:10.034745 IP 11.0.0.9.319 > 224.0.1.129.319: PTPv2, majorSdoId: 0x0, msg type: sync msg, length: 44, domain: 0, reserved1: 0, Flags [two step], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 1067, control: 0 (Sync), log message interval: 0, originTimeStamp: 0 seconds, 0 nanoseconds
5 2018-01-23 19:44:10.034796 IP 11.0.0.9.320 > 224.0.1.129.320: PTPv2, majorSdoId: 0x0, msg type: follow up msg, length: 44, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 1067, control: 2 (Follow_Up), log message interval: 0, preciseOriginTimeStamp: 1516736650 seconds, 34751783 nanoseconds
1 2018-01-23 19:44:09.248292 IP 11.0.0.110.319 > 224.0.1.129.319: PTPv2, majorSdoId: 0x0, msg type: delay req msg, length: 44, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x7cfe90fffef950b4, port id: 1, seq id: 132, control: 1 (Delay_Req), log message interval: 127, originTimeStamp: 0.000000000 seconds
2 2018-01-23 19:44:09.248437 IP 11.0.0.9.320 > 224.0.1.129.320: PTPv2, majorSdoId: 0x0, msg type: delay resp msg, length: 54, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 132, control: 3 (Delay_Resp), log message interval: 0, receiveTimeStamp: 1516736649.248292005 seconds, port identity: 0x7cfe90fffef950b4, port id: 1
3 2018-01-23 19:44:09.982883 IP 11.0.0.9.320 > 224.0.1.129.320: PTPv2, majorSdoId: 0x0, msg type: announce msg, length: 64, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 534, control: 5 (Other), log message interval: 1, originTimeStamp: 0.000000000 seconds, origin cur utc:36, rsvd: 0, gm priority_1: 128, gm clock class: 248, gm clock accuracy: 254, gm clock variance: 65535, gm priority_2: 128, gm clock id: 0x200fffe000001, steps removed: 0, time source: 0xa0
4 2018-01-23 19:44:10.034745 IP 11.0.0.9.319 > 224.0.1.129.319: PTPv2, majorSdoId: 0x0, msg type: sync msg, length: 44, domain: 0, reserved1: 0, Flags [two step], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 1067, control: 0 (Sync), log message interval: 0, originTimeStamp: 0.000000000 seconds
5 2018-01-23 19:44:10.034796 IP 11.0.0.9.320 > 224.0.1.129.320: PTPv2, majorSdoId: 0x0, msg type: follow up msg, length: 44, domain: 0, reserved1: 0, Flags [none], NS correction: 0, sub NS correction: 0, reserved2: 0, clock identity: 0x200fffe000001, port id: 1, seq id: 1067, control: 2 (Follow_Up), log message interval: 0, preciseOriginTimeStamp: 1516736650.034751783 seconds
6 changes: 3 additions & 3 deletions tests/ptp_corrections.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1 2022-10-11 17:52:26.679146 IP 4.5.0.2.319 > 2.2.2.2.319: PTPv2, majorSdoId: 0x0, 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), log message interval: 127, originTimeStamp: 0 seconds, 0 nanoseconds
2 2022-10-11 17:52:26.679265 IP 2.2.2.2.320 > 4.5.0.2.320: PTPv2, majorSdoId: 0x0, 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 (Delay_Resp), log message interval: 127, receiveTimeStamp: 1665510783 seconds, 679015501 nanoseconds, port identity: 0xa0369ffffe856e8a, port id: 1
3 2022-10-11 17:52:26.682034 IP 2.2.2.2.319 > 4.5.0.2.319: PTPv2, majorSdoId: 0x0, 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), log message interval: 127, originTimeStamp: 1665510783 seconds, 681548698 nanoseconds
1 2022-10-11 17:52:26.679146 IP 4.5.0.2.319 > 2.2.2.2.319: PTPv2, majorSdoId: 0x0, 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), log message interval: 127, originTimeStamp: 0.000000000 seconds
2 2022-10-11 17:52:26.679265 IP 2.2.2.2.320 > 4.5.0.2.320: PTPv2, majorSdoId: 0x0, 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 (Delay_Resp), log message interval: 127, receiveTimeStamp: 1665510783.679015501 seconds, port identity: 0xa0369ffffe856e8a, port id: 1
3 2022-10-11 17:52:26.682034 IP 2.2.2.2.319 > 4.5.0.2.319: PTPv2, majorSdoId: 0x0, 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), log message interval: 127, originTimeStamp: 1665510783.681548698 seconds
Loading