Skip to content

Commit b9d8946

Browse files
committed
[TEST ONLY] NTP: test a p_ntp_time_fmt() update
Fail on 32-bit?
1 parent 9fcec3c commit b9d8946

6 files changed

+49
-43
lines changed

ntp.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
#include "extract.h"
2828

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

3133
void
3234
p_ntp_time_fmt(netdissect_options *ndo, const char *fmt,
@@ -50,11 +52,15 @@ p_ntp_time_fmt(netdissect_options *ndo, const char *fmt,
5052
* print the UTC time in human-readable format.
5153
*/
5254
if (i) {
53-
int64_t seconds_64bit = (int64_t)i - JAN_1970;
55+
int64_t seconds_64bit;
5456
time_t seconds;
5557
char time_buf[128];
5658
const char *time_string;
5759

60+
if ((i & 0x80000000) != 0)
61+
seconds_64bit = (int64_t)i - DIFF_1970_1900;
62+
else
63+
seconds_64bit = (int64_t)i + DIFF_2036_1970;
5864
seconds = (time_t)seconds_64bit;
5965
if (seconds != seconds_64bit) {
6066
/*

tests/lspping-fec-ldp-v.out

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Return Code: No return code or return code contained in the Error Code TLV (0)
1111
Return Subcode: (0)
1212
Sender Handle: 0x00000000, Sequence: 1
13-
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: no timestamp
13+
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: no timestamp
1414
Target FEC Stack TLV (1), length: 12
1515
LDP IPv4 prefix subTLV (1), length: 5
1616
12.1.1.1/32
@@ -21,7 +21,7 @@
2121
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
2222
Return Subcode: (0)
2323
Sender Handle: 0x00000000, Sequence: 1
24-
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: 1087208228.000027928 (1934-06-15T10:17:08Z)
24+
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: 1087208228.000027928 (2070-07-21T16:45:24Z)
2525
4 2004-06-14 10:17:08.878375 MPLS (label 100704, tc 6, [S], ttl 64)
2626
IP (tos 0xc0, ttl 64, id 40725, offset 0, flags [none], proto TCP (6), length 71)
2727
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
@@ -37,7 +37,7 @@
3737
Return Code: No return code or return code contained in the Error Code TLV (0)
3838
Return Subcode: (0)
3939
Sender Handle: 0x00000000, Sequence: 2
40-
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: no timestamp
40+
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: no timestamp
4141
Target FEC Stack TLV (1), length: 12
4242
LDP IPv4 prefix subTLV (1), length: 5
4343
12.1.1.1/32
@@ -48,7 +48,7 @@
4848
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
4949
Return Subcode: (0)
5050
Sender Handle: 0x00000000, Sequence: 2
51-
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: 1087208229.000030186 (1934-06-15T10:17:09Z)
51+
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: 1087208229.000030186 (2070-07-21T16:45:25Z)
5252
8 2004-06-14 10:17:10.128607 MPLS (label 100688, tc 7, [S], ttl 255)
5353
IP (tos 0x0, ttl 64, id 40729, offset 0, flags [none], proto UDP (17), length 76)
5454
12.4.4.4.4786 > 127.0.0.1.3503:
@@ -57,7 +57,7 @@
5757
Return Code: No return code or return code contained in the Error Code TLV (0)
5858
Return Subcode: (0)
5959
Sender Handle: 0x00000000, Sequence: 3
60-
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: no timestamp
60+
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: no timestamp
6161
Target FEC Stack TLV (1), length: 12
6262
LDP IPv4 prefix subTLV (1), length: 5
6363
12.1.1.1/32
@@ -68,7 +68,7 @@
6868
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
6969
Return Subcode: (0)
7070
Sender Handle: 0x00000000, Sequence: 3
71-
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: 1087208230.000030250 (1934-06-15T10:17:10Z)
71+
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: 1087208230.000030250 (2070-07-21T16:45:26Z)
7272
10 2004-06-14 10:17:11.128577 MPLS (label 100688, tc 7, [S], ttl 255)
7373
IP (tos 0x0, ttl 64, id 40731, offset 0, flags [none], proto UDP (17), length 76)
7474
12.4.4.4.4786 > 127.0.0.1.3503:
@@ -77,7 +77,7 @@
7777
Return Code: No return code or return code contained in the Error Code TLV (0)
7878
Return Subcode: (0)
7979
Sender Handle: 0x00000000, Sequence: 4
80-
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: no timestamp
80+
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: no timestamp
8181
Target FEC Stack TLV (1), length: 12
8282
LDP IPv4 prefix subTLV (1), length: 5
8383
12.1.1.1/32
@@ -88,7 +88,7 @@
8888
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
8989
Return Subcode: (0)
9090
Sender Handle: 0x00000000, Sequence: 4
91-
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: 1087208231.000030237 (1934-06-15T10:17:11Z)
91+
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: 1087208231.000030237 (2070-07-21T16:45:27Z)
9292
12 2004-06-14 10:17:12.128655 MPLS (label 100688, tc 7, [S], ttl 255)
9393
IP (tos 0x0, ttl 64, id 40733, offset 0, flags [none], proto UDP (17), length 76)
9494
12.4.4.4.4786 > 127.0.0.1.3503:
@@ -97,7 +97,7 @@
9797
Return Code: No return code or return code contained in the Error Code TLV (0)
9898
Return Subcode: (0)
9999
Sender Handle: 0x00000000, Sequence: 5
100-
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: no timestamp
100+
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: no timestamp
101101
Target FEC Stack TLV (1), length: 12
102102
LDP IPv4 prefix subTLV (1), length: 5
103103
12.1.1.1/32
@@ -108,4 +108,4 @@
108108
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
109109
Return Subcode: (0)
110110
Sender Handle: 0x00000000, Sequence: 5
111-
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: 1087208232.000030273 (1934-06-15T10:17:12Z)
111+
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: 1087208232.000030273 (2070-07-21T16:45:28Z)

tests/lspping-fec-ldp-vv.out

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Return Code: No return code or return code contained in the Error Code TLV (0)
1111
Return Subcode: (0)
1212
Sender Handle: 0x00000000, Sequence: 1
13-
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: no timestamp
13+
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: no timestamp
1414
Target FEC Stack TLV (1), length: 12
1515
LDP IPv4 prefix subTLV (1), length: 5
1616
12.1.1.1/32
@@ -23,7 +23,7 @@
2323
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
2424
Return Subcode: (0)
2525
Sender Handle: 0x00000000, Sequence: 1
26-
Sender Timestamp: 1087208228.000027564 (1934-06-15T10:17:08Z) Receiver Timestamp: 1087208228.000027928 (1934-06-15T10:17:08Z)
26+
Sender Timestamp: 1087208228.000027564 (2070-07-21T16:45:24Z) Receiver Timestamp: 1087208228.000027928 (2070-07-21T16:45:24Z)
2727
4 2004-06-14 10:17:08.878375 MPLS (label 100704, tc 6, [S], ttl 64)
2828
IP (tos 0xc0, ttl 64, id 40725, offset 0, flags [none], proto TCP (6), length 71)
2929
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
@@ -39,7 +39,7 @@
3939
Return Code: No return code or return code contained in the Error Code TLV (0)
4040
Return Subcode: (0)
4141
Sender Handle: 0x00000000, Sequence: 2
42-
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: no timestamp
42+
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: no timestamp
4343
Target FEC Stack TLV (1), length: 12
4444
LDP IPv4 prefix subTLV (1), length: 5
4545
12.1.1.1/32
@@ -52,7 +52,7 @@
5252
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
5353
Return Subcode: (0)
5454
Sender Handle: 0x00000000, Sequence: 2
55-
Sender Timestamp: 1087208229.000029880 (1934-06-15T10:17:09Z) Receiver Timestamp: 1087208229.000030186 (1934-06-15T10:17:09Z)
55+
Sender Timestamp: 1087208229.000029880 (2070-07-21T16:45:25Z) Receiver Timestamp: 1087208229.000030186 (2070-07-21T16:45:25Z)
5656
8 2004-06-14 10:17:10.128607 MPLS (label 100688, tc 7, [S], ttl 255)
5757
IP (tos 0x0, ttl 64, id 40729, offset 0, flags [none], proto UDP (17), length 76)
5858
12.4.4.4.4786 > 127.0.0.1.3503: [udp sum ok]
@@ -61,7 +61,7 @@
6161
Return Code: No return code or return code contained in the Error Code TLV (0)
6262
Return Subcode: (0)
6363
Sender Handle: 0x00000000, Sequence: 3
64-
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: no timestamp
64+
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: no timestamp
6565
Target FEC Stack TLV (1), length: 12
6666
LDP IPv4 prefix subTLV (1), length: 5
6767
12.1.1.1/32
@@ -74,7 +74,7 @@
7474
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
7575
Return Subcode: (0)
7676
Sender Handle: 0x00000000, Sequence: 3
77-
Sender Timestamp: 1087208230.000029928 (1934-06-15T10:17:10Z) Receiver Timestamp: 1087208230.000030250 (1934-06-15T10:17:10Z)
77+
Sender Timestamp: 1087208230.000029928 (2070-07-21T16:45:26Z) Receiver Timestamp: 1087208230.000030250 (2070-07-21T16:45:26Z)
7878
10 2004-06-14 10:17:11.128577 MPLS (label 100688, tc 7, [S], ttl 255)
7979
IP (tos 0x0, ttl 64, id 40731, offset 0, flags [none], proto UDP (17), length 76)
8080
12.4.4.4.4786 > 127.0.0.1.3503: [udp sum ok]
@@ -83,7 +83,7 @@
8383
Return Code: No return code or return code contained in the Error Code TLV (0)
8484
Return Subcode: (0)
8585
Sender Handle: 0x00000000, Sequence: 4
86-
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: no timestamp
86+
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: no timestamp
8787
Target FEC Stack TLV (1), length: 12
8888
LDP IPv4 prefix subTLV (1), length: 5
8989
12.1.1.1/32
@@ -96,7 +96,7 @@
9696
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
9797
Return Subcode: (0)
9898
Sender Handle: 0x00000000, Sequence: 4
99-
Sender Timestamp: 1087208231.000029918 (1934-06-15T10:17:11Z) Receiver Timestamp: 1087208231.000030237 (1934-06-15T10:17:11Z)
99+
Sender Timestamp: 1087208231.000029918 (2070-07-21T16:45:27Z) Receiver Timestamp: 1087208231.000030237 (2070-07-21T16:45:27Z)
100100
12 2004-06-14 10:17:12.128655 MPLS (label 100688, tc 7, [S], ttl 255)
101101
IP (tos 0x0, ttl 64, id 40733, offset 0, flags [none], proto UDP (17), length 76)
102102
12.4.4.4.4786 > 127.0.0.1.3503: [udp sum ok]
@@ -105,7 +105,7 @@
105105
Return Code: No return code or return code contained in the Error Code TLV (0)
106106
Return Subcode: (0)
107107
Sender Handle: 0x00000000, Sequence: 5
108-
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: no timestamp
108+
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: no timestamp
109109
Target FEC Stack TLV (1), length: 12
110110
LDP IPv4 prefix subTLV (1), length: 5
111111
12.1.1.1/32
@@ -118,4 +118,4 @@
118118
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
119119
Return Subcode: (0)
120120
Sender Handle: 0x00000000, Sequence: 5
121-
Sender Timestamp: 1087208232.000029937 (1934-06-15T10:17:12Z) Receiver Timestamp: 1087208232.000030273 (1934-06-15T10:17:12Z)
121+
Sender Timestamp: 1087208232.000029937 (2070-07-21T16:45:28Z) Receiver Timestamp: 1087208232.000030273 (2070-07-21T16:45:28Z)

tests/lspping-fec-rsvp-v.out

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Return Code: No return code or return code contained in the Error Code TLV (0)
77
Return Subcode: (0)
88
Sender Handle: 0x00000000, Sequence: 1
9-
Sender Timestamp: 1087208037.000131030 (1934-06-15T10:13:57Z) Receiver Timestamp: no timestamp
9+
Sender Timestamp: 1087208037.000131030 (2070-07-21T16:42:13Z) Receiver Timestamp: no timestamp
1010
Target FEC Stack TLV (1), length: 24
1111
RSVP IPv4 Session Query subTLV (3), length: 20
1212
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
@@ -18,7 +18,7 @@
1818
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
1919
Return Subcode: (0)
2020
Sender Handle: 0x00000000, Sequence: 1
21-
Sender Timestamp: 1087208037.000131030 (1934-06-15T10:13:57Z) Receiver Timestamp: 1087208037.000131348 (1934-06-15T10:13:57Z)
21+
Sender Timestamp: 1087208037.000131030 (2070-07-21T16:42:13Z) Receiver Timestamp: 1087208037.000131348 (2070-07-21T16:42:13Z)
2222
3 2004-06-14 10:13:58.572787 MPLS (label 100704, tc 7, [S], ttl 255)
2323
IP (tos 0x0, ttl 64, id 40271, offset 0, flags [none], proto UDP (17), length 88)
2424
12.4.4.4.4529 > 127.0.0.1.3503:
@@ -27,7 +27,7 @@
2727
Return Code: No return code or return code contained in the Error Code TLV (0)
2828
Return Subcode: (0)
2929
Sender Handle: 0x00000000, Sequence: 2
30-
Sender Timestamp: 1087208038.000133345 (1934-06-15T10:13:58Z) Receiver Timestamp: no timestamp
30+
Sender Timestamp: 1087208038.000133345 (2070-07-21T16:42:14Z) Receiver Timestamp: no timestamp
3131
Target FEC Stack TLV (1), length: 24
3232
RSVP IPv4 Session Query subTLV (3), length: 20
3333
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
@@ -39,7 +39,7 @@
3939
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
4040
Return Subcode: (0)
4141
Sender Handle: 0x00000000, Sequence: 2
42-
Sender Timestamp: 1087208038.000133345 (1934-06-15T10:13:58Z) Receiver Timestamp: 1087208038.000136480 (1934-06-15T10:13:58Z)
42+
Sender Timestamp: 1087208038.000133345 (2070-07-21T16:42:14Z) Receiver Timestamp: 1087208038.000136480 (2070-07-21T16:42:14Z)
4343
5 2004-06-14 10:13:59.572866 MPLS (label 100704, tc 7, [S], ttl 255)
4444
IP (tos 0x0, ttl 64, id 40273, offset 0, flags [none], proto UDP (17), length 88)
4545
12.4.4.4.4529 > 127.0.0.1.3503:
@@ -48,7 +48,7 @@
4848
Return Code: No return code or return code contained in the Error Code TLV (0)
4949
Return Subcode: (0)
5050
Sender Handle: 0x00000000, Sequence: 3
51-
Sender Timestamp: 1087208039.000133363 (1934-06-15T10:13:59Z) Receiver Timestamp: no timestamp
51+
Sender Timestamp: 1087208039.000133363 (2070-07-21T16:42:15Z) Receiver Timestamp: no timestamp
5252
Target FEC Stack TLV (1), length: 24
5353
RSVP IPv4 Session Query subTLV (3), length: 20
5454
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
@@ -60,7 +60,7 @@
6060
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
6161
Return Subcode: (0)
6262
Sender Handle: 0x00000000, Sequence: 3
63-
Sender Timestamp: 1087208039.000133363 (1934-06-15T10:13:59Z) Receiver Timestamp: 1087208039.000133684 (1934-06-15T10:13:59Z)
63+
Sender Timestamp: 1087208039.000133363 (2070-07-21T16:42:15Z) Receiver Timestamp: 1087208039.000133684 (2070-07-21T16:42:15Z)
6464
7 2004-06-14 10:14:00.572959 MPLS (label 100704, tc 7, [S], ttl 255)
6565
IP (tos 0x0, ttl 64, id 40275, offset 0, flags [none], proto UDP (17), length 88)
6666
12.4.4.4.4529 > 127.0.0.1.3503:
@@ -69,7 +69,7 @@
6969
Return Code: No return code or return code contained in the Error Code TLV (0)
7070
Return Subcode: (0)
7171
Sender Handle: 0x00000000, Sequence: 4
72-
Sender Timestamp: 1087208040.000133384 (1934-06-15T10:14:00Z) Receiver Timestamp: no timestamp
72+
Sender Timestamp: 1087208040.000133384 (2070-07-21T16:42:16Z) Receiver Timestamp: no timestamp
7373
Target FEC Stack TLV (1), length: 24
7474
RSVP IPv4 Session Query subTLV (3), length: 20
7575
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
@@ -81,7 +81,7 @@
8181
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
8282
Return Subcode: (0)
8383
Sender Handle: 0x00000000, Sequence: 4
84-
Sender Timestamp: 1087208040.000133384 (1934-06-15T10:14:00Z) Receiver Timestamp: 1087208040.000133697 (1934-06-15T10:14:00Z)
84+
Sender Timestamp: 1087208040.000133384 (2070-07-21T16:42:16Z) Receiver Timestamp: 1087208040.000133697 (2070-07-21T16:42:16Z)
8585
9 2004-06-14 10:14:01.573010 MPLS (label 100704, tc 7, [S], ttl 255)
8686
IP (tos 0x0, ttl 64, id 40278, offset 0, flags [none], proto UDP (17), length 88)
8787
12.4.4.4.4529 > 127.0.0.1.3503:
@@ -90,7 +90,7 @@
9090
Return Code: No return code or return code contained in the Error Code TLV (0)
9191
Return Subcode: (0)
9292
Sender Handle: 0x00000000, Sequence: 5
93-
Sender Timestamp: 1087208041.000133401 (1934-06-15T10:14:01Z) Receiver Timestamp: no timestamp
93+
Sender Timestamp: 1087208041.000133401 (2070-07-21T16:42:17Z) Receiver Timestamp: no timestamp
9494
Target FEC Stack TLV (1), length: 24
9595
RSVP IPv4 Session Query subTLV (3), length: 20
9696
tunnel end-point 12.1.1.1, tunnel sender 12.4.4.4, lsp-id 0x0010
@@ -102,4 +102,4 @@
102102
Return Code: Replying router is an egress for the FEC at stack depth 0 (3)
103103
Return Subcode: (0)
104104
Sender Handle: 0x00000000, Sequence: 5
105-
Sender Timestamp: 1087208041.000133401 (1934-06-15T10:14:01Z) Receiver Timestamp: 1087208041.000133707 (1934-06-15T10:14:01Z)
105+
Sender Timestamp: 1087208041.000133401 (2070-07-21T16:42:17Z) Receiver Timestamp: 1087208041.000133707 (2070-07-21T16:42:17Z)

0 commit comments

Comments
 (0)