Skip to content

Commit

Permalink
[TEST ONLY] NTP: test a p_ntp_time_fmt() update
Browse files Browse the repository at this point in the history
Fail on 32-bit?
  • Loading branch information
fxlb committed Apr 2, 2024
1 parent 9b97f85 commit 41c5474
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
10 changes: 8 additions & 2 deletions ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

#include "extract.h"

#define JAN_1970 INT64_T_CONSTANT(2208988800) /* 1970 - 1900 in seconds */
#define DIFF_1970_1900 INT64_T_CONSTANT(2208988800) /* 1970 - 1900 in seconds */
/* RFC4330 - 3. NTP Timestamp Format - 6h 28m 16s UTC on 7 February 2036 */
#define DIFF_2036_1970 INT64_T_CONSTANT(2085978496) /* 2036 - 1970 in seconds */

void
p_ntp_time_fmt(netdissect_options *ndo, const char *fmt,
Expand All @@ -50,11 +52,15 @@ p_ntp_time_fmt(netdissect_options *ndo, const char *fmt,
* print the UTC time in human-readable format.
*/
if (i) {
int64_t seconds_64bit = (int64_t)i - JAN_1970;
int64_t seconds_64bit;
time_t seconds;
char time_buf[128];
const char *time_string;

if ((i & 0x80000000) != 0)
seconds_64bit = (int64_t)i - DIFF_1970_1900;
else
seconds_64bit = (int64_t)i + DIFF_2036_1970;
seconds = (time_t)seconds_64bit;
if (seconds != seconds_64bit) {
/*
Expand Down
20 changes: 10 additions & 10 deletions tests/lspping-fec-ldp-v.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 1
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -21,7 +21,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 1
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: 1087208228.000027928 (1934-06-15T10:17:08Z)
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: 1087208228.000027928 (2070-07-21T16:45:24Z)
4 2004-06-14 10:17:08.878375 MPLS (label 100704, tc 6, [S], ttl 64)
IP (tos 0xc0, ttl 64, id 40725, offset 0, flags [none], proto TCP (6), length 71)
12.4.4.4.2006 > 12.1.1.1.179: Flags [P.], cksum 0x6c0d (correct), seq 399708866:399708885, ack 708613212, win 16384, options [nop,nop,TS val 84784455 ecr 130411], length 19: BGP
Expand All @@ -37,7 +37,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 2
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -48,7 +48,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 2
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: 1087208229.000030186 (1934-06-15T10:17:09Z)
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: 1087208229.000030186 (2070-07-21T16:45:25Z)
8 2004-06-14 10:17:10.128607 MPLS (label 100688, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40729, offset 0, flags [none], proto UDP (17), length 76)
12.4.4.4.4786 > 127.0.0.1.3503:
Expand All @@ -57,7 +57,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 3
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -68,7 +68,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 3
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: 1087208230.000030250 (1934-06-15T10:17:10Z)
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: 1087208230.000030250 (2070-07-21T16:45:26Z)
10 2004-06-14 10:17:11.128577 MPLS (label 100688, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40731, offset 0, flags [none], proto UDP (17), length 76)
12.4.4.4.4786 > 127.0.0.1.3503:
Expand All @@ -77,7 +77,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 4
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -88,7 +88,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 4
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: 1087208231.000030237 (1934-06-15T10:17:11Z)
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: 1087208231.000030237 (2070-07-21T16:45:27Z)
12 2004-06-14 10:17:12.128655 MPLS (label 100688, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40733, offset 0, flags [none], proto UDP (17), length 76)
12.4.4.4.4786 > 127.0.0.1.3503:
Expand All @@ -97,7 +97,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 5
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -108,4 +108,4 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 5
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: 1087208232.000030273 (1934-06-15T10:17:12Z)
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: 1087208232.000030273 (2070-07-21T16:45:28Z)
20 changes: 10 additions & 10 deletions tests/lspping-fec-ldp-vv.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 1
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -23,7 +23,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 1
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: 1087208228.000027928 (1934-06-15T10:17:08Z)
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: 1087208228.000027928 (2070-07-21T16:45:24Z)
4 2004-06-14 10:17:08.878375 MPLS (label 100704, tc 6, [S], ttl 64)
IP (tos 0xc0, ttl 64, id 40725, offset 0, flags [none], proto TCP (6), length 71)
12.4.4.4.2006 > 12.1.1.1.179: Flags [P.], cksum 0x6c0d (correct), seq 399708866:399708885, ack 708613212, win 16384, options [nop,nop,TS val 84784455 ecr 130411], length 19: BGP
Expand All @@ -39,7 +39,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 2
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -52,7 +52,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 2
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: 1087208229.000030186 (1934-06-15T10:17:09Z)
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: 1087208229.000030186 (2070-07-21T16:45:25Z)
8 2004-06-14 10:17:10.128607 MPLS (label 100688, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40729, offset 0, flags [none], proto UDP (17), length 76)
12.4.4.4.4786 > 127.0.0.1.3503: [udp sum ok]
Expand All @@ -61,7 +61,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 3
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -74,7 +74,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 3
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: 1087208230.000030250 (1934-06-15T10:17:10Z)
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: 1087208230.000030250 (2070-07-21T16:45:26Z)
10 2004-06-14 10:17:11.128577 MPLS (label 100688, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40731, offset 0, flags [none], proto UDP (17), length 76)
12.4.4.4.4786 > 127.0.0.1.3503: [udp sum ok]
Expand All @@ -83,7 +83,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 4
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -96,7 +96,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 4
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: 1087208231.000030237 (1934-06-15T10:17:11Z)
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: 1087208231.000030237 (2070-07-21T16:45:27Z)
12 2004-06-14 10:17:12.128655 MPLS (label 100688, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40733, offset 0, flags [none], proto UDP (17), length 76)
12.4.4.4.4786 > 127.0.0.1.3503: [udp sum ok]
Expand All @@ -105,7 +105,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 5
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 12
LDP IPv4 prefix subTLV (1), length: 5
12.1.1.1/32
Expand All @@ -118,4 +118,4 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 5
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: 1087208232.000030273 (1934-06-15T10:17:12Z)
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: 1087208232.000030273 (2070-07-21T16:45:28Z)
20 changes: 10 additions & 10 deletions tests/lspping-fec-rsvp-v.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 1
Sender Timestamp: 1087208037.000131030 (1934-06-15T10:13:57Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208037.000131030 (2070-07-21T16:42:13Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 24
RSVP IPv4 Session Query subTLV (3), length: 20
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
Expand All @@ -18,7 +18,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 1
Sender Timestamp: 1087208037.000131030 (1934-06-15T10:13:57Z) Receiver Timestamp: 1087208037.000131348 (1934-06-15T10:13:57Z)
Sender Timestamp: 1087208037.000131030 (2070-07-21T16:42:13Z) Receiver Timestamp: 1087208037.000131348 (2070-07-21T16:42:13Z)
3 2004-06-14 10:13:58.572787 MPLS (label 100704, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40271, offset 0, flags [none], proto UDP (17), length 88)
12.4.4.4.4529 > 127.0.0.1.3503:
Expand All @@ -27,7 +27,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 2
Sender Timestamp: 1087208038.000133345 (1934-06-15T10:13:58Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208038.000133345 (2070-07-21T16:42:14Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 24
RSVP IPv4 Session Query subTLV (3), length: 20
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
Expand All @@ -39,7 +39,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 2
Sender Timestamp: 1087208038.000133345 (1934-06-15T10:13:58Z) Receiver Timestamp: 1087208038.000136480 (1934-06-15T10:13:58Z)
Sender Timestamp: 1087208038.000133345 (2070-07-21T16:42:14Z) Receiver Timestamp: 1087208038.000136480 (2070-07-21T16:42:14Z)
5 2004-06-14 10:13:59.572866 MPLS (label 100704, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40273, offset 0, flags [none], proto UDP (17), length 88)
12.4.4.4.4529 > 127.0.0.1.3503:
Expand All @@ -48,7 +48,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 3
Sender Timestamp: 1087208039.000133363 (1934-06-15T10:13:59Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208039.000133363 (2070-07-21T16:42:15Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 24
RSVP IPv4 Session Query subTLV (3), length: 20
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
Expand All @@ -60,7 +60,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 3
Sender Timestamp: 1087208039.000133363 (1934-06-15T10:13:59Z) Receiver Timestamp: 1087208039.000133684 (1934-06-15T10:13:59Z)
Sender Timestamp: 1087208039.000133363 (2070-07-21T16:42:15Z) Receiver Timestamp: 1087208039.000133684 (2070-07-21T16:42:15Z)
7 2004-06-14 10:14:00.572959 MPLS (label 100704, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40275, offset 0, flags [none], proto UDP (17), length 88)
12.4.4.4.4529 > 127.0.0.1.3503:
Expand All @@ -69,7 +69,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 4
Sender Timestamp: 1087208040.000133384 (1934-06-15T10:14:00Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208040.000133384 (2070-07-21T16:42:16Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 24
RSVP IPv4 Session Query subTLV (3), length: 20
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
Expand All @@ -81,7 +81,7 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 4
Sender Timestamp: 1087208040.000133384 (1934-06-15T10:14:00Z) Receiver Timestamp: 1087208040.000133697 (1934-06-15T10:14:00Z)
Sender Timestamp: 1087208040.000133384 (2070-07-21T16:42:16Z) Receiver Timestamp: 1087208040.000133697 (2070-07-21T16:42:16Z)
9 2004-06-14 10:14:01.573010 MPLS (label 100704, tc 7, [S], ttl 255)
IP (tos 0x0, ttl 64, id 40278, offset 0, flags [none], proto UDP (17), length 88)
12.4.4.4.4529 > 127.0.0.1.3503:
Expand All @@ -90,7 +90,7 @@
Return Code: No return code or return code contained in the Error Code TLV (0)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 5
Sender Timestamp: 1087208041.000133401 (1934-06-15T10:14:01Z) Receiver Timestamp: no timestamp
Sender Timestamp: 1087208041.000133401 (2070-07-21T16:42:17Z) Receiver Timestamp: no timestamp
Target FEC Stack TLV (1), length: 24
RSVP IPv4 Session Query subTLV (3), length: 20
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
Expand All @@ -102,4 +102,4 @@
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
Return Subcode: (0)
Sender Handle: 0x00000000, Sequence: 5
Sender Timestamp: 1087208041.000133401 (1934-06-15T10:14:01Z) Receiver Timestamp: 1087208041.000133707 (1934-06-15T10:14:01Z)
Sender Timestamp: 1087208041.000133401 (2070-07-21T16:42:17Z) Receiver Timestamp: 1087208041.000133707 (2070-07-21T16:42:17Z)
Loading

0 comments on commit 41c5474

Please sign in to comment.