Skip to content

Commit f08d60d

Browse files
committed
Add sub-second packet timestamp checks for invalid micro/nano
Now prints e.g.: 2 17:16:10.1000000 (invalid ms) IP [...] 3 17:16:10.2147483648 (invalid ms) IP [...] or 2 17:16:10.1000000000 (invalid ns) IP [...] 3 17:16:10.2147483648 (invalid ns) IP [...] Add two test files.
1 parent 7e68ce3 commit f08d60d

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

tests/TESTLIST

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ tcp-handshake-nano-ttt tcp-handshake-nano.pcap tcp-handshake-nano-ttt.out -ttt -
3838
tcp-handshake-nano-tttt tcp-handshake-nano.pcap tcp-handshake-nano-tttt.out -tttt -q --nano SPECIAL_t
3939
tcp-handshake-nano-ttttt tcp-handshake-nano.pcap tcp-handshake-nano-ttttt.out -ttttt -q --nano SPECIAL_t
4040

41+
# Invalid timestamps, micro and nano precision
42+
timestamp_invalid_micro timestamp_invalid_micro.pcap timestamp_invalid_micro.out -q SPECIAL_t
43+
timestamp_invalid_nano timestamp_invalid_nano.pcap timestamp_invalid_nano.out -q --nano SPECIAL_t
44+
4145
# TCP with data in the RST segment
4246
tcp_rst_data tcp_rst_data.pcap tcp_rst_data-v.out -v
4347
tcp_rst_data tcp_rst_data.pcap tcp_rst_data.out

tests/timestamp_invalid_micro.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 17:16:09.999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
2+
2 17:16:10.1000000 (invalid ms) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
3+
3 17:16:10.2147483648 (invalid ms) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0

tests/timestamp_invalid_micro.pcap

292 Bytes
Binary file not shown.

tests/timestamp_invalid_nano.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 17:16:09.999999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
2+
2 17:16:10.1000000000 (invalid ns) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
3+
3 17:16:10.2147483648 (invalid ns) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0

tests/timestamp_invalid_nano.pcap

292 Bytes
Binary file not shown.

util-print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,14 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
216216

217217
case PCAP_TSTAMP_PRECISION_MICRO:
218218
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
219+
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
220+
ND_PRINT(" (invalid ms)");
219221
break;
220222

221223
case PCAP_TSTAMP_PRECISION_NANO:
222224
ND_PRINT(".%09u", (unsigned)tv->tv_usec);
225+
if ((unsigned)tv->tv_usec > ND_NANO_PER_SEC - 1)
226+
ND_PRINT(" (invalid ns)");
223227
break;
224228

225229
default:
@@ -228,6 +232,8 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
228232
}
229233
#else
230234
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
235+
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
236+
ND_PRINT(" (invalid ms)");
231237
#endif
232238
}
233239

0 commit comments

Comments
 (0)