mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 18:45:07 -05:00
Compare commits
1378 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f323c814af | ||
|
|
19b47dcbc9 | ||
|
|
5edeadcbd9 | ||
|
|
d91ae2094f | ||
|
|
30a5845098 | ||
|
|
0f367efac5 | ||
|
|
24c011d4a6 | ||
|
|
0c2cdd2fb1 | ||
|
|
cd1a666e1b | ||
|
|
070b4f69d0 | ||
|
|
851c823b42 | ||
|
|
df80274644 | ||
|
|
bb2d68ddf9 | ||
|
|
685d8f725b | ||
|
|
4234732b08 | ||
|
|
a16094adfb | ||
|
|
a4349b13df | ||
|
|
3556dadea1 | ||
|
|
220e6d1907 | ||
|
|
a738037705 | ||
|
|
7daf34675a | ||
|
|
de598c2310 | ||
|
|
91cc4dbb12 | ||
|
|
0ae6f2485b | ||
|
|
52ec694d2b | ||
|
|
e2e07af8a4 | ||
|
|
2ed88c31c7 | ||
|
|
af8e4a5115 | ||
|
|
f503a9a490 | ||
|
|
9c64fbb9c4 | ||
|
|
b428f901c7 | ||
|
|
09b7f77f9a | ||
|
|
c23c0b8484 | ||
|
|
d530055917 | ||
|
|
f41d09e19f | ||
|
|
46030d9d3e | ||
|
|
02ccd3a3c7 | ||
|
|
9cc609c4b0 | ||
|
|
a0a496dcb4 | ||
|
|
8d08486edf | ||
|
|
a3b376cf0a | ||
|
|
e66f1df89d | ||
|
|
35220aac9d | ||
|
|
5b04f3ca90 | ||
|
|
beb1c36136 | ||
|
|
da3495c472 | ||
|
|
356771c0c3 | ||
|
|
fca8966ada | ||
|
|
25f80a1a9d | ||
|
|
1219f99935 | ||
|
|
33a1fe7a9c | ||
|
|
eed0a0de56 | ||
|
|
07600cbd71 | ||
|
|
f2e341b5ed | ||
|
|
55717c1ccd | ||
|
|
d5e645eb38 | ||
|
|
3196630fb9 | ||
|
|
663dde1ad7 | ||
|
|
62757cda49 | ||
|
|
af6ae9186b | ||
|
|
4c29f8888c | ||
|
|
d06ae4a60e | ||
|
|
f9af2f9733 | ||
|
|
43ae0131cd | ||
|
|
8bb8f15a7d | ||
|
|
e55f174bd3 | ||
|
|
5bd13c8d59 | ||
|
|
759580aa6f | ||
|
|
b61cbed689 | ||
|
|
2ac2247756 | ||
|
|
55f48b14b7 | ||
|
|
3dfac33858 | ||
|
|
d5f2401421 | ||
|
|
fb0570cc73 | ||
|
|
43936ba0d1 | ||
|
|
f2ba20f293 | ||
|
|
fcd384523b | ||
|
|
48bce351bf | ||
|
|
25f93875d9 | ||
|
|
ebc610fcb3 | ||
|
|
264957a443 | ||
|
|
af611b5842 | ||
|
|
1c1ca1d12f | ||
|
|
c506b9aac8 | ||
|
|
2eefa61f10 | ||
|
|
89a5e21e4d | ||
|
|
6a79771898 | ||
|
|
53353529cf | ||
|
|
22bfdf204f | ||
|
|
fc28e9ae56 | ||
|
|
17e6258694 | ||
|
|
d7a444593f | ||
|
|
701b9415a5 | ||
|
|
d5894c0738 | ||
|
|
a0a9560258 | ||
|
|
09067e06d3 | ||
|
|
dbbdd5af06 | ||
|
|
7f984cf7fa | ||
|
|
8df49b799f | ||
|
|
e7c2f71cea | ||
|
|
219085b8f6 | ||
|
|
2319f72b29 | ||
|
|
72f7d09f58 | ||
|
|
0bf39c0ab9 | ||
|
|
2e126ed2b5 | ||
|
|
a652ce7d0e | ||
|
|
a97ca73704 | ||
|
|
125d7a5c32 | ||
|
|
36356ef033 | ||
|
|
a2d1569455 | ||
|
|
952c3b2528 | ||
|
|
d92d24ad7f | ||
|
|
bc33e1cda1 | ||
|
|
189bf9c536 | ||
|
|
c5dde9b66a | ||
|
|
1fb60f8db8 | ||
|
|
2f05287e15 | ||
|
|
61226cda8c | ||
|
|
26b51d841e | ||
|
|
5f4cbaab7e | ||
|
|
7a80647fb4 | ||
|
|
14b8df3702 | ||
|
|
5cb469b204 | ||
|
|
29d7d3176d | ||
|
|
76a905d652 | ||
|
|
83f96efdfd | ||
|
|
127826a399 | ||
|
|
7ee5f4888e | ||
|
|
9ed1d1afc2 | ||
|
|
d0d9a3fa43 | ||
|
|
9600993c28 | ||
|
|
5e6f8458ff | ||
|
|
f5fe5452f6 | ||
|
|
3ac6a0c26c | ||
|
|
c2872d1e12 | ||
|
|
e47e7e3661 | ||
|
|
d8f14ec59b | ||
|
|
274a51bc38 | ||
|
|
92700e194c | ||
|
|
87df268723 | ||
|
|
17a9caf5c8 | ||
|
|
36441fabde | ||
|
|
f363998517 | ||
|
|
6fc30baba8 | ||
|
|
70a0f18d52 | ||
|
|
0ad5f5ea89 | ||
|
|
d676f39b84 | ||
|
|
31690261f5 | ||
|
|
93326488a3 | ||
|
|
d5ca98eaaa | ||
|
|
be3158c4e5 | ||
|
|
2f1d5d9255 | ||
|
|
b2c2132e4b | ||
|
|
aab6d1b153 | ||
|
|
bbbd80bf03 | ||
|
|
f27d719a4e | ||
|
|
789817cd91 | ||
|
|
885e7774fd | ||
|
|
883b7eed8a | ||
|
|
4049ed8766 | ||
|
|
f9f6803b8a | ||
|
|
385f7ebfd9 | ||
|
|
f9cbc4803d | ||
|
|
97973b1833 | ||
|
|
9cdfc15e31 | ||
|
|
fc99317291 | ||
|
|
bb9ba3e4bd | ||
|
|
649f54a1e6 | ||
|
|
4070d7ffa6 | ||
|
|
0493abb68a | ||
|
|
8c1e16711d | ||
|
|
1d03908646 | ||
|
|
49d718c025 | ||
|
|
c536b2561b | ||
|
|
b9f5ce83b0 | ||
|
|
8baab00ae0 | ||
|
|
d01cb5af46 | ||
|
|
7925ed39b8 | ||
|
|
9d869d8709 | ||
|
|
4f94e22b4b | ||
|
|
d9b720471d | ||
|
|
039b388c82 | ||
|
|
3f6528da77 | ||
|
|
4f43c060a3 | ||
|
|
3e55fe6919 | ||
|
|
754097944b | ||
|
|
dd6a25edf2 | ||
|
|
e697833976 | ||
|
|
40d80624f6 | ||
|
|
9a716cc284 | ||
|
|
13a78ecd2f | ||
|
|
a9f0c681cb | ||
|
|
862aa285a2 | ||
|
|
84d2811800 | ||
|
|
635a9d3f5a | ||
|
|
81f7f6ddf0 | ||
|
|
aa22c515ce | ||
|
|
2ca2c85365 | ||
|
|
966e6fd939 | ||
|
|
4f0dd72cf0 | ||
|
|
69aa2eff99 | ||
|
|
3e1ec36ca5 | ||
|
|
224ab8ddb1 | ||
|
|
307c2ec70f | ||
|
|
5381fb4ee9 | ||
|
|
3812ec2aa2 | ||
|
|
4e7690ebec | ||
|
|
cf3d976a68 | ||
|
|
26fc28c056 | ||
|
|
d2117ab697 | ||
|
|
52b29f673f | ||
|
|
e86b60a9d7 | ||
|
|
53501b743f | ||
|
|
c61ddb70da | ||
|
|
9339766bfe | ||
|
|
f60410016a | ||
|
|
7a02371698 | ||
|
|
579d8c9907 | ||
|
|
10c760a80c | ||
|
|
2d39a12f51 | ||
|
|
517b1ae29a | ||
|
|
b7347d931b | ||
|
|
4f878ba144 | ||
|
|
8acdb5d1e2 | ||
|
|
62f2d5736d | ||
|
|
dc22df93f5 | ||
|
|
d898bd246b | ||
|
|
ebf0ff2c0d | ||
|
|
cc77b0e9fd | ||
|
|
a8bc25e543 | ||
|
|
6615bb1b78 | ||
|
|
f650b8c515 | ||
|
|
ae2e0318d1 | ||
|
|
26ce610155 | ||
|
|
316d47e3b4 | ||
|
|
90557cf1ba | ||
|
|
80e627c86b | ||
|
|
0e4995e10b | ||
|
|
a598983f9b | ||
|
|
27641876c5 | ||
|
|
4d139eeca6 | ||
|
|
3f2806c19c | ||
|
|
e297df78e4 | ||
|
|
c1d56ede3f | ||
|
|
2e52aca3bf | ||
|
|
b0fc5832f4 | ||
|
|
cf6af112e1 | ||
|
|
fa3052e776 | ||
|
|
f8610d69f0 | ||
|
|
1a8dcce84f | ||
|
|
f74eb67567 | ||
|
|
144fcdde34 | ||
|
|
3cef7f975c | ||
|
|
a2372b0c3a | ||
|
|
362d7c517d | ||
|
|
62389b7e50 | ||
|
|
eb9e6701fd | ||
|
|
b585954b21 | ||
|
|
82ddc6a883 | ||
|
|
624b76e86e | ||
|
|
4dd0aece02 | ||
|
|
e85fb0c25e | ||
|
|
fc8783a933 | ||
|
|
e7897eb9cc | ||
|
|
59e8b79034 | ||
|
|
fb7475bf59 | ||
|
|
cd98516cae | ||
|
|
e399d8dd1f | ||
|
|
d327cfea5a | ||
|
|
c94e7c72e7 | ||
|
|
f3aea33ad4 | ||
|
|
48709d9c4a | ||
|
|
4779adcb50 | ||
|
|
01e29ec685 | ||
|
|
e4cccc115d | ||
|
|
8e9716d5d4 | ||
|
|
a96d288027 | ||
|
|
545d2563ef | ||
|
|
1494ef1df3 | ||
|
|
698f270b5b | ||
|
|
f15f6a86b0 | ||
|
|
5d60d611ae | ||
|
|
6e71e902c8 | ||
|
|
473cb3c968 | ||
|
|
df43ebe9e0 | ||
|
|
642173e864 | ||
|
|
944cf6e318 | ||
|
|
a655eab34f | ||
|
|
f020d479e0 | ||
|
|
de752b28de | ||
|
|
f41d370e6a | ||
|
|
a97830d9d6 | ||
|
|
ea4fc47cda | ||
|
|
0e08ca7c89 | ||
|
|
068cd3c311 | ||
|
|
455b8e4b44 | ||
|
|
d9a363606b | ||
|
|
59ad433b6b | ||
|
|
35b3a42ed9 | ||
|
|
0639205617 | ||
|
|
3916c3366b | ||
|
|
f0a33e7b28 | ||
|
|
c9b8f8bc70 | ||
|
|
983b0723f6 | ||
|
|
02c38934ea | ||
|
|
c28c2cde43 | ||
|
|
349323dec7 | ||
|
|
ddfaf2e542 | ||
|
|
3177474ae8 | ||
|
|
cc535632d1 | ||
|
|
cb8ee57b9e | ||
|
|
c0b19b3fea | ||
|
|
8235da6885 | ||
|
|
f6625717cd | ||
|
|
fdfcabd79b | ||
|
|
2bb88b45c6 | ||
|
|
9820c22c1d | ||
|
|
bcd7bad467 | ||
|
|
83ea9fe284 | ||
|
|
c74d6e458d | ||
|
|
ff466439fc | ||
|
|
0fcdf4389b | ||
|
|
9cb9021c87 | ||
|
|
9c36236742 | ||
|
|
adebb027be | ||
|
|
7d3798d7cd | ||
|
|
b7c7c293e5 | ||
|
|
9ca250755f | ||
|
|
bd3b36865e | ||
|
|
538e1c5eb1 | ||
|
|
009f1a5ae8 | ||
|
|
4f1418abf9 | ||
|
|
79b348f075 | ||
|
|
9d88c028e2 | ||
|
|
51172b3510 | ||
|
|
892636036a | ||
|
|
4cf6b29397 | ||
|
|
571359b366 | ||
|
|
0f009e7718 | ||
|
|
24effd7340 | ||
|
|
5289fc5f80 | ||
|
|
ca49304bd6 | ||
|
|
b7fbac617d | ||
|
|
839e9aa4af | ||
|
|
c5ac15ad33 | ||
|
|
598cd10c34 | ||
|
|
1885729024 | ||
|
|
2127f63961 | ||
|
|
97a8b1e43b | ||
|
|
aeee1feda6 | ||
|
|
18d9243eb9 | ||
|
|
1aa4827b3b | ||
|
|
ed1077a788 | ||
|
|
356c475a6a | ||
|
|
9ac582fa35 | ||
|
|
8c75f44603 | ||
|
|
0a63ad95ce | ||
|
|
d274fe44da | ||
|
|
6d1cb58d8f | ||
|
|
784122d44f | ||
|
|
32fb8d41ca | ||
|
|
4993c35e11 | ||
|
|
6a5665ca58 | ||
|
|
e5cf006378 | ||
|
|
0e51552d2d | ||
|
|
cc007ad93b | ||
|
|
3096926547 | ||
|
|
d48f012809 | ||
|
|
def137bc80 | ||
|
|
3e0272e55f | ||
|
|
be503bbcf6 | ||
|
|
72bf3d26eb | ||
|
|
cc20ead3dc | ||
|
|
fd8fbcd090 | ||
|
|
77bd0f83fe | ||
|
|
32a82a38fd | ||
|
|
66e097e3e6 | ||
|
|
51d77d6cfc | ||
|
|
2bb0769516 | ||
|
|
58da0c0ad2 | ||
|
|
c10b66b579 | ||
|
|
55a90c3735 | ||
|
|
962afb9e7d | ||
|
|
7abd982f87 | ||
|
|
c099aac79c | ||
|
|
828e6ce30f | ||
|
|
dc08cbfe59 | ||
|
|
3bdcce6903 | ||
|
|
d93aa10bac | ||
|
|
de4ecc72d1 | ||
|
|
db54bfc0c1 | ||
|
|
72ee80debe | ||
|
|
a3436c26f0 | ||
|
|
b0f5024d56 | ||
|
|
eae4b2abe5 | ||
|
|
ff03b813b0 | ||
|
|
4e747da4b4 | ||
|
|
99e3c67a81 | ||
|
|
c4a2550518 | ||
|
|
4ef944b734 | ||
|
|
0f04baeb97 | ||
|
|
bf7f63eaed | ||
|
|
59cf4e0b96 | ||
|
|
3fc72c0cfa | ||
|
|
ad69f4f32b | ||
|
|
81c2b2e886 | ||
|
|
c9f03fb222 | ||
|
|
b0fe443632 | ||
|
|
8882fb21e0 | ||
|
|
7d551d34a0 | ||
|
|
feef0dd983 | ||
|
|
d29f7b7c70 | ||
|
|
e3cd248f0d | ||
|
|
27e20a568b | ||
|
|
80316de3b8 | ||
|
|
f9e2a5852d | ||
|
|
500c9cbf3b | ||
|
|
46714fec2d | ||
|
|
e1d9a57bd0 | ||
|
|
1b82604f61 | ||
|
|
d69ac07183 | ||
|
|
519796de37 | ||
|
|
ea4811b3b3 | ||
|
|
951f14ae06 | ||
|
|
428f9e4228 | ||
|
|
ea425bf01e | ||
|
|
8567a0e466 | ||
|
|
f6bf12bdcd | ||
|
|
e8968ea429 | ||
|
|
cf10ce1b68 | ||
|
|
15dc83420d | ||
|
|
37dbc211cd | ||
|
|
ed78cda6ad | ||
|
|
faff931a76 | ||
|
|
1e68671690 | ||
|
|
8eb167fd21 | ||
|
|
bc46174e98 | ||
|
|
b86c89460a | ||
|
|
03541f3626 | ||
|
|
39a462496a | ||
|
|
7ba8994838 | ||
|
|
8da025da99 | ||
|
|
5dc7242703 | ||
|
|
11bffa0d55 | ||
|
|
5f6f265f80 | ||
|
|
bf92314dc4 | ||
|
|
a3fda9f992 | ||
|
|
cd34b377aa | ||
|
|
145423068b | ||
|
|
fb4c3f31c0 | ||
|
|
60049f1551 | ||
|
|
e555548dda | ||
|
|
eedf61b3a2 | ||
|
|
ab54f76a38 | ||
|
|
f8df4789b1 | ||
|
|
6366ebc17e | ||
|
|
3a2d33d5a3 | ||
|
|
1afd5b23d7 | ||
|
|
17fb9e3709 | ||
|
|
7a7295992f | ||
|
|
526974366f | ||
|
|
51fe589aeb | ||
|
|
28cf4acf13 | ||
|
|
ee2220f2e7 | ||
|
|
a6ec6ec3ac | ||
|
|
4f5343f086 | ||
|
|
79c7384e5e | ||
|
|
75beeaf2b0 | ||
|
|
f4ed2abdca | ||
|
|
11a5c7337a | ||
|
|
972c476c5a | ||
|
|
a8c8f2f309 | ||
|
|
a0d2513be6 | ||
|
|
43dc0b3295 | ||
|
|
195ff5c51b | ||
|
|
e49aececce | ||
|
|
814b07c3a2 | ||
|
|
3470ab66f0 | ||
|
|
6901df5c18 | ||
|
|
bddb3b3228 | ||
|
|
dfe877144a | ||
|
|
59a9b7a9f6 | ||
|
|
ad8fb64276 | ||
|
|
436c1d3ea2 | ||
|
|
7fc5da5f80 | ||
|
|
105b3faa46 | ||
|
|
709223826f | ||
|
|
eace93f2af | ||
|
|
2775846db7 | ||
|
|
4aff08e95d | ||
|
|
958d66f8a7 | ||
|
|
85fa29c43d | ||
|
|
0344b9a9c9 | ||
|
|
04f6329773 | ||
|
|
d690faeb19 | ||
|
|
0b2e77ae64 | ||
|
|
2a4fd0a5c6 | ||
|
|
e569e1c9d9 | ||
|
|
7be360041c | ||
|
|
2fa83b541c | ||
|
|
8db9d59dac | ||
|
|
adcf073484 | ||
|
|
5296858411 | ||
|
|
d603426389 | ||
|
|
d3f4292968 | ||
|
|
4dde7198c8 | ||
|
|
b145d3ff51 | ||
|
|
9b98247d9c | ||
|
|
eedabb3d27 | ||
|
|
66dc2b6d6b | ||
|
|
bcdbbbd694 | ||
|
|
7b07e47c08 | ||
|
|
a608496faf | ||
|
|
c687224a11 | ||
|
|
a6f2a613f3 | ||
|
|
cfa39af345 | ||
|
|
8bab35c122 | ||
|
|
b20ef4cd7f | ||
|
|
b8b751a932 | ||
|
|
4a390841eb | ||
|
|
f506f44033 | ||
|
|
1f8355f154 | ||
|
|
ddc2761498 | ||
|
|
8b50a8298a | ||
|
|
3eab329042 | ||
|
|
552d3b53b1 | ||
|
|
8afd62d954 | ||
|
|
4883086fc1 | ||
|
|
2582be8754 | ||
|
|
ff9301567e | ||
|
|
e7a254265f | ||
|
|
d5311adafb | ||
|
|
18d7ea62b3 | ||
|
|
fb2849b230 | ||
|
|
fd59877692 | ||
|
|
bb0553e4c4 | ||
|
|
46f954490d | ||
|
|
31e6a50386 | ||
|
|
9a9c0d7b99 | ||
|
|
0c80f00d0b | ||
|
|
27b3bf48ea | ||
|
|
c3e34b8145 | ||
|
|
7bf3ec4aeb | ||
|
|
50204a125b | ||
|
|
111d170542 | ||
|
|
d6dd6f0bc9 | ||
|
|
44aac84feb | ||
|
|
c41508723f | ||
|
|
6043632f80 | ||
|
|
a420ed57a1 | ||
|
|
72f99033fe | ||
|
|
2d798bc4cf | ||
|
|
881d07fa0a | ||
|
|
c5306bed39 | ||
|
|
934b8712a5 | ||
|
|
1d4690eb64 | ||
|
|
e6848b1e3f | ||
|
|
3e537416a9 | ||
|
|
26a1ed8bc3 | ||
|
|
24538fe3e9 | ||
|
|
e43d699973 | ||
|
|
1e727c4497 | ||
|
|
83010590af | ||
|
|
fa402a173a | ||
|
|
ca83d2a804 | ||
|
|
725beb360a | ||
|
|
86d29221f3 | ||
|
|
e8062b7ff1 | ||
|
|
9468fd4aa6 | ||
|
|
5ed9b888ff | ||
|
|
7661a6e95b | ||
|
|
aca1daf7c9 | ||
|
|
46cac4e22f | ||
|
|
56a102ed4d | ||
|
|
ca28dbd2c3 | ||
|
|
588785e160 | ||
|
|
cabcccd6c3 | ||
|
|
567e66a0bb | ||
|
|
b8ee6d6e56 | ||
|
|
9ea1e4e40f | ||
|
|
2d492eacb5 | ||
|
|
cb8660e79a | ||
|
|
d29bef93e9 | ||
|
|
5a09adebfd | ||
|
|
8c0ee9c175 | ||
|
|
f20fabdbf4 | ||
|
|
57cea56e6e | ||
|
|
db7d9639b4 | ||
|
|
beb40d63ed | ||
|
|
672b98dd3f | ||
|
|
a24d2713cd | ||
|
|
a5110d3ed9 | ||
|
|
9d1c1505b9 | ||
|
|
8c25632321 | ||
|
|
2507b66640 | ||
|
|
d7e3ad17ff | ||
|
|
84902d0e00 | ||
|
|
f7f3667bcb | ||
|
|
794cbfbbb5 | ||
|
|
1858104b5c | ||
|
|
994409a036 | ||
|
|
2d9eb5b6fa | ||
|
|
3477cbe28f | ||
|
|
8634158de0 | ||
|
|
3eaf0765b0 | ||
|
|
dd0679ad45 | ||
|
|
bfcd8ecc56 | ||
|
|
50e5865c73 | ||
|
|
93f6358916 | ||
|
|
9300854439 | ||
|
|
02914ac637 | ||
|
|
00fff161cf | ||
|
|
3763befd62 | ||
|
|
2ae008bcee | ||
|
|
ea41f7ab09 | ||
|
|
c673b1e8b7 | ||
|
|
2bf1ba22f2 | ||
|
|
dfc2f70876 | ||
|
|
0dba2b9689 | ||
|
|
e7fc2d31cc | ||
|
|
f231efb811 | ||
|
|
c4d6f98bed | ||
|
|
bff3f51d13 | ||
|
|
f5eb7daf20 | ||
|
|
d66b2f2b24 | ||
|
|
a57e1eb542 | ||
|
|
25bdee7a0e | ||
|
|
f6001202ec | ||
|
|
0cf506c929 | ||
|
|
d05e9fb2ec | ||
|
|
54d7e3e94a | ||
|
|
c7223f4c8f | ||
|
|
07badbede7 | ||
|
|
468cfeeb71 | ||
|
|
b3fc549622 | ||
|
|
077dbd5692 | ||
|
|
e18903a6b5 | ||
|
|
7dfd4ae556 | ||
|
|
429c4468b0 | ||
|
|
7a4c396bba | ||
|
|
88f846f656 | ||
|
|
27c8a64977 | ||
|
|
2fc8edacb8 | ||
|
|
903fa247f8 | ||
|
|
96771d6857 | ||
|
|
f4c6a00b2a | ||
|
|
990f8cd89b | ||
|
|
813ea71b50 | ||
|
|
e8be384cdf | ||
|
|
61773a2c07 | ||
|
|
510aa8b050 | ||
|
|
57957ab6cf | ||
|
|
e8069a0179 | ||
|
|
f3f840551a | ||
|
|
10a42c1e04 | ||
|
|
4a219ecbf1 | ||
|
|
0d298bfc4c | ||
|
|
792c241e3a | ||
|
|
6336a87855 | ||
|
|
f5721b1212 | ||
|
|
7d3e9180c6 | ||
|
|
03b8ca186a | ||
|
|
435cbef31a | ||
|
|
4adcf58368 | ||
|
|
004986310d | ||
|
|
7a88e0a87b | ||
|
|
64e21d6281 | ||
|
|
9ef7ea2bcb | ||
|
|
6d1796d6be | ||
|
|
fcaba98101 | ||
|
|
9bbda5c964 | ||
|
|
2c81d38861 | ||
|
|
78fec3f05a | ||
|
|
392a1a5ff6 | ||
|
|
219a414cb7 | ||
|
|
58fc81441b | ||
|
|
02ada36838 | ||
|
|
81978f0ba0 | ||
|
|
622769cdfd | ||
|
|
3038047f9b | ||
|
|
3e3f045ab7 | ||
|
|
a6d9f41eda | ||
|
|
bf6a4e1a81 | ||
|
|
5982d96b75 | ||
|
|
28e3e4cdca | ||
|
|
24134c78e8 | ||
|
|
5e8ed72b89 | ||
|
|
45e41b7ac1 | ||
|
|
27fd751915 | ||
|
|
4d26cfc92b | ||
|
|
d78680912e | ||
|
|
47e4cb31b2 | ||
|
|
91da65a782 | ||
|
|
bb1c02e9f5 | ||
|
|
c651ea9b6b | ||
|
|
207f9fb128 | ||
|
|
f06c1cfa97 | ||
|
|
6cd47bff8f | ||
|
|
2de24cfd82 | ||
|
|
86a3ef9ed1 | ||
|
|
3f8c57c8f2 | ||
|
|
ca96946416 | ||
|
|
e5b9b6d701 | ||
|
|
8cb689a5e6 | ||
|
|
2270234115 | ||
|
|
a073f383e6 | ||
|
|
8e74655b03 | ||
|
|
70fa3a6905 | ||
|
|
1227873b88 | ||
|
|
d30e73d0d9 | ||
|
|
9e7a7008de | ||
|
|
62d6aed6a6 | ||
|
|
ffb9887cce | ||
|
|
9220c9b8a2 | ||
|
|
2e28b19112 | ||
|
|
636a4e2794 | ||
|
|
5c9e1e0b69 | ||
|
|
64fd1b8ba5 | ||
|
|
69d3913f3e | ||
|
|
08fd011b6a | ||
|
|
c172268cfe | ||
|
|
94b014865c | ||
|
|
099aaf2cb1 | ||
|
|
4481a8b24f | ||
|
|
b626fe661e | ||
|
|
ba8fcd145d | ||
|
|
981d09de40 | ||
|
|
86a99bb257 | ||
|
|
3093a11cd0 | ||
|
|
058b788d38 | ||
|
|
66a42fa493 | ||
|
|
a85f63cc15 | ||
|
|
bbe1e69dcc | ||
|
|
1b52bba7b9 | ||
|
|
c5c80ef400 | ||
|
|
a78031ce0d | ||
|
|
34e9dd13ce | ||
|
|
6e52a9be7a | ||
|
|
69c6dffd63 | ||
|
|
2ddd0ae231 | ||
|
|
79db0b7eca | ||
|
|
2ebba7fbaa | ||
|
|
e392d1fde9 | ||
|
|
d7c93ec950 | ||
|
|
6af39d63aa | ||
|
|
cc8414b1b3 | ||
|
|
6b44055e3d | ||
|
|
9f9c6cc6ab | ||
|
|
f176193d35 | ||
|
|
e8bc41e862 | ||
|
|
91dbe3c6c2 | ||
|
|
3e876d4218 | ||
|
|
31b1f2e8a1 | ||
|
|
4169e94b1d | ||
|
|
948ecf8431 | ||
|
|
91f3f97ea7 | ||
|
|
65bb65b440 | ||
|
|
ea6e8d85a3 | ||
|
|
add932501f | ||
|
|
89390a738f | ||
|
|
ac4f6ab93b | ||
|
|
dbcb1b9b0b | ||
|
|
6375307798 | ||
|
|
fb78e60d26 | ||
|
|
b822c7164f | ||
|
|
aa295730a0 | ||
|
|
69d70703b2 | ||
|
|
b2b6ef00dc | ||
|
|
5dc86c236b | ||
|
|
2563dd9d29 | ||
|
|
a899e3df33 | ||
|
|
692cea49f8 | ||
|
|
bcedacaa3d | ||
|
|
be3c1b5243 | ||
|
|
e626ec6c37 | ||
|
|
49d52b547f | ||
|
|
74a546a9e7 | ||
|
|
d1777087c1 | ||
|
|
cf7b5363cd | ||
|
|
7f3183cc72 | ||
|
|
f1b8da085b | ||
|
|
09dfca49ec | ||
|
|
88e0ec07aa | ||
|
|
0adc8e8f92 | ||
|
|
5fc7674e36 | ||
|
|
018977044a | ||
|
|
cc49d8e6e6 | ||
|
|
933bd017b4 | ||
|
|
d558b33d85 | ||
|
|
9268bf2cff | ||
|
|
dbf2c22467 | ||
|
|
af4fe92095 | ||
|
|
e034a07be8 | ||
|
|
eb8c9ad601 | ||
|
|
6847536669 | ||
|
|
f5206db9b0 | ||
|
|
6ab2ed0da6 | ||
|
|
7352e470e1 | ||
|
|
5bc9c0d07a | ||
|
|
a2146e82ef | ||
|
|
6e10e6740c | ||
|
|
bfaa10f2b0 | ||
|
|
9f167a7997 | ||
|
|
6908163464 | ||
|
|
671daf06b8 | ||
|
|
b189a5386b | ||
|
|
7889d108c2 | ||
|
|
3cfa8ce9d3 | ||
|
|
570573fe28 | ||
|
|
62b1a11736 | ||
|
|
c00d517e12 | ||
|
|
001f3d5e27 | ||
|
|
6045023a49 | ||
|
|
bba29a0ee7 | ||
|
|
cffc856b50 | ||
|
|
419077e04b | ||
|
|
7db9d4acea | ||
|
|
8d5b86efe7 | ||
|
|
6cf16aea7b | ||
|
|
870545d3cb | ||
|
|
2a030c0d0c | ||
|
|
0b709ab1bc | ||
|
|
a1f2f17385 | ||
|
|
2240eefbd0 | ||
|
|
706d0c281a | ||
|
|
ca73e34f30 | ||
|
|
cca2ef4649 | ||
|
|
05d9edbf8f | ||
|
|
c5bdc52a59 | ||
|
|
74f0c0924a | ||
|
|
05492d1d23 | ||
|
|
eea343b93f | ||
|
|
afff06c88c | ||
|
|
c0717a27f6 | ||
|
|
159bd73f76 | ||
|
|
9931a9166b | ||
|
|
8aa4ae027b | ||
|
|
dcce79fdbe | ||
|
|
189aafde9d | ||
|
|
99e3045df4 | ||
|
|
c498c21fad | ||
|
|
6bef8aa0e9 | ||
|
|
108d112272 | ||
|
|
05078e4252 | ||
|
|
4ceb9e4cd0 | ||
|
|
a9f237a395 | ||
|
|
e7ca560c3d | ||
|
|
d9f86f6f70 | ||
|
|
879d936277 | ||
|
|
5bb2bf9361 | ||
|
|
a8167b7959 | ||
|
|
b33b682356 | ||
|
|
2c47602c33 | ||
|
|
59d1b41716 | ||
|
|
5b75d4afef | ||
|
|
e15c7cd236 | ||
|
|
9bc774d6af | ||
|
|
9b34556952 | ||
|
|
9a6369d8f1 | ||
|
|
49cdd6bf09 | ||
|
|
63fe34e890 | ||
|
|
85465afb62 | ||
|
|
339cb06a49 | ||
|
|
10150bfcab | ||
|
|
e50dc739d8 | ||
|
|
26e08abe71 | ||
|
|
7637faa0d0 | ||
|
|
8a57a28177 | ||
|
|
34db671b57 | ||
|
|
8b9021bf34 | ||
|
|
ce6b896948 | ||
|
|
2962fc6286 | ||
|
|
76bed76289 | ||
|
|
113f2ebec0 | ||
|
|
7c5bd948bb | ||
|
|
8cbc68f28f | ||
|
|
bf7aa52394 | ||
|
|
366345790d | ||
|
|
f881c153bf | ||
|
|
19f3ab2225 | ||
|
|
fd1e80802f | ||
|
|
4b7cb161a8 | ||
|
|
7848794222 | ||
|
|
94822d5156 | ||
|
|
e3f840aae9 | ||
|
|
5aae563277 | ||
|
|
02de782fa3 | ||
|
|
3f6df33feb | ||
|
|
a94f5fe007 | ||
|
|
63f0234748 | ||
|
|
47921c7c0c | ||
|
|
42a85f685e | ||
|
|
feca2399e4 | ||
|
|
d34e611ec8 | ||
|
|
02098ed830 | ||
|
|
aa4228bf1b | ||
|
|
b296441708 | ||
|
|
b827475378 | ||
|
|
78a6698ae1 | ||
|
|
e7b6feb34b | ||
|
|
84be834385 | ||
|
|
e83d808dfd | ||
|
|
35a68d5b59 | ||
|
|
3c593137b0 | ||
|
|
deaf0ffed3 | ||
|
|
af145e871e | ||
|
|
fbca570d0b | ||
|
|
448ef779c2 | ||
|
|
499a69e611 | ||
|
|
58c2915878 | ||
|
|
eda4b111d3 | ||
|
|
c6dd749687 | ||
|
|
d2a96f5fbc | ||
|
|
499f513d40 | ||
|
|
8b1f68b1b4 | ||
|
|
8e4c776900 | ||
|
|
d0eb9427c2 | ||
|
|
7d100b89fc | ||
|
|
a4bd7f1800 | ||
|
|
5308e0a25f | ||
|
|
da862158bf | ||
|
|
7b98443a13 | ||
|
|
4da9f74d24 | ||
|
|
e41042e258 | ||
|
|
5581466c63 | ||
|
|
e79a6c2116 | ||
|
|
666ece122e | ||
|
|
2c7ab98370 | ||
|
|
f0f18a02a7 | ||
|
|
c5d8af0285 | ||
|
|
0ce15a8472 | ||
|
|
da60629201 | ||
|
|
2343e7a89c | ||
|
|
45f27f4f5e | ||
|
|
0bc112f8b4 | ||
|
|
bfc2fa645c | ||
|
|
11111804fd | ||
|
|
87ec67247e | ||
|
|
0df8328ceb | ||
|
|
b563048ee2 | ||
|
|
e8096330be | ||
|
|
b1647dbcb7 | ||
|
|
4ddadd5622 | ||
|
|
3e854006c7 | ||
|
|
2c4c235147 | ||
|
|
6863e43269 | ||
|
|
de8708f331 | ||
|
|
d0b2486036 | ||
|
|
5384a93645 | ||
|
|
4bbc768652 | ||
|
|
fead915b45 | ||
|
|
5422e49026 | ||
|
|
77a1f27a1d | ||
|
|
b45d864f73 | ||
|
|
f35c81c871 | ||
|
|
a349b2803c | ||
|
|
f5d1b8fb74 | ||
|
|
a0fe71eef1 | ||
|
|
154b39cf7a | ||
|
|
6f54210db2 | ||
|
|
f6539449c5 | ||
|
|
b8d546a0d1 | ||
|
|
04e6474b75 | ||
|
|
eb51c500e8 | ||
|
|
6f8fba9a3f | ||
|
|
750afc30f2 | ||
|
|
e0e6ec0d84 | ||
|
|
c9f50fc686 | ||
|
|
83c26b458b | ||
|
|
b711873f45 | ||
|
|
c68ca40ce4 | ||
|
|
51fe80ad95 | ||
|
|
7ffee73524 | ||
|
|
f40b0024bd | ||
|
|
a06c9909a6 | ||
|
|
aee42fada8 | ||
|
|
3e93068c43 | ||
|
|
36291b707b | ||
|
|
6dad2c24bf | ||
|
|
27cbf20d23 | ||
|
|
5c571bbbe7 | ||
|
|
33d65c8614 | ||
|
|
d87db7cdb8 | ||
|
|
45fa4750da | ||
|
|
8472fd8133 | ||
|
|
5ab645e310 | ||
|
|
8ccda538d3 | ||
|
|
b06d74ab73 | ||
|
|
d0964ffa83 | ||
|
|
3d08815efb | ||
|
|
a83f0d3cdc | ||
|
|
702db726d3 | ||
|
|
ed5c43204b | ||
|
|
f91bdd604d | ||
|
|
3a1dbb1354 | ||
|
|
4b511143b8 | ||
|
|
93076e7e1c | ||
|
|
1c51feb3c5 | ||
|
|
c2773dbc2f | ||
|
|
4534db84c4 | ||
|
|
be8215e181 | ||
|
|
ae82bbbace | ||
|
|
2b6ea41062 | ||
|
|
d9f745fe70 | ||
|
|
9aac179367 | ||
|
|
b896bb5a78 | ||
|
|
64c2fd9888 | ||
|
|
2668a12e4e | ||
|
|
e1645966ec | ||
|
|
4f1fc1ee78 | ||
|
|
d70df3daab | ||
|
|
554b9b06de | ||
|
|
f734bd1a7c | ||
|
|
77fc5c42b9 | ||
|
|
ea85bc43e0 | ||
|
|
e8fb11c433 | ||
|
|
01a29c7a11 | ||
|
|
6ec3dc1650 | ||
|
|
0c54cf316d | ||
|
|
bd3fb49a1e | ||
|
|
f6e72a80e1 | ||
|
|
c2ab1426e5 | ||
|
|
fa2c59d78d | ||
|
|
16afa8eb50 | ||
|
|
992590e99c | ||
|
|
0baa35eade | ||
|
|
2e0870ee0c | ||
|
|
43cd119d6d | ||
|
|
62cd319a51 | ||
|
|
d0f789425b | ||
|
|
30e6549692 | ||
|
|
043c7d7c9f | ||
|
|
1c277a8850 | ||
|
|
ccb94ac5fb | ||
|
|
778fce4039 | ||
|
|
9983185d6d | ||
|
|
7bd1c02781 | ||
|
|
760285218f | ||
|
|
4fe0e6b7fd | ||
|
|
0773a1e630 | ||
|
|
4a24368763 | ||
|
|
577290c5bc | ||
|
|
854ff69f78 | ||
|
|
29b0ad894c | ||
|
|
cde0a20307 | ||
|
|
a768578a26 | ||
|
|
5d838729ef | ||
|
|
d6b763dc24 | ||
|
|
95adb52a45 | ||
|
|
707d9a3484 | ||
|
|
1872d4d195 | ||
|
|
17f32c266e | ||
|
|
6207655ab2 | ||
|
|
5e1e31ad5f | ||
|
|
13111c1dd8 | ||
|
|
85c84073c1 | ||
|
|
c2944d8727 | ||
|
|
e118b9b1e8 | ||
|
|
7fb7f95979 | ||
|
|
cc507bffae | ||
|
|
0dbfe020ad | ||
|
|
018a1c42b0 | ||
|
|
c5735ebfe9 | ||
|
|
db93180ce1 | ||
|
|
39da10d939 | ||
|
|
f2da253bc3 | ||
|
|
934d4047f1 | ||
|
|
b799cfd1c4 | ||
|
|
b712c100d7 | ||
|
|
c049bce007 | ||
|
|
46fad717e5 | ||
|
|
ae0c3bbbe8 | ||
|
|
f95d57e0d9 | ||
|
|
a1cbd4eb82 | ||
|
|
6cbeb107db | ||
|
|
3a5566c6c3 | ||
|
|
73c548ad01 | ||
|
|
82203e12c8 | ||
|
|
1ca099473f | ||
|
|
eceb8d9937 | ||
|
|
4ba92bb6d6 | ||
|
|
f31f68ae8e | ||
|
|
cff15f91d4 | ||
|
|
6b74917954 | ||
|
|
1bf2384a1f | ||
|
|
54a12779e2 | ||
|
|
e8b06fef9f | ||
|
|
653d70ec4e | ||
|
|
abb09418b1 | ||
|
|
c103bebd9f | ||
|
|
935d855b47 | ||
|
|
f8f9100a0d | ||
|
|
6de7b98e76 | ||
|
|
c390351c65 | ||
|
|
768bce799b | ||
|
|
d3a30142e5 | ||
|
|
3a635fc51f | ||
|
|
10078566da | ||
|
|
c44346096c | ||
|
|
0ff449e6a6 | ||
|
|
f3a16383b9 | ||
|
|
539ef3f770 | ||
|
|
f282856c72 | ||
|
|
6db8ec1ba2 | ||
|
|
5187c08c90 | ||
|
|
c8076ac10d | ||
|
|
362d155558 | ||
|
|
7b7eb0a6e5 | ||
|
|
d96f49f67d | ||
|
|
43ba5d2126 | ||
|
|
48f7598fed | ||
|
|
510b22e96b | ||
|
|
0a0aff14d8 | ||
|
|
e225ac68bc | ||
|
|
58060c40a5 | ||
|
|
2ac1b3d5c4 | ||
|
|
c174566982 | ||
|
|
60fca19d40 | ||
|
|
8bcb15b02f | ||
|
|
65c2cebcd5 | ||
|
|
2a51b45a43 | ||
|
|
5ac791665e | ||
|
|
a4e3f83611 | ||
|
|
8a837f9c2b | ||
|
|
da2d33e9a8 | ||
|
|
4b98dadae9 | ||
|
|
86acea5c46 | ||
|
|
a60fc73e7b | ||
|
|
50f99ec5f4 | ||
|
|
31b6a14444 | ||
|
|
9df4d36157 | ||
|
|
b70f0b674f | ||
|
|
510784077f | ||
|
|
9800e397fb | ||
|
|
1436d9961f | ||
|
|
98f5d05925 | ||
|
|
7a937c7652 | ||
|
|
b198d76676 | ||
|
|
97d4203354 | ||
|
|
beaaaad162 | ||
|
|
4e78975909 | ||
|
|
99147ed8f2 | ||
|
|
dec0d3bfc2 | ||
|
|
cd84c99e70 | ||
|
|
d5c507975c | ||
|
|
b4235abd36 | ||
|
|
1966085a97 | ||
|
|
e31e7af48f | ||
|
|
adb9123fc3 | ||
|
|
b0f7efd59e | ||
|
|
e28dfada8c | ||
|
|
ac0b28cce6 | ||
|
|
48b16ae66c | ||
|
|
061579ec28 | ||
|
|
f2f834e7e7 | ||
|
|
a7802e9a76 | ||
|
|
8f7ab95ff0 | ||
|
|
042c670747 | ||
|
|
cacbe9976f | ||
|
|
8efec1d640 | ||
|
|
c44d282f0b | ||
|
|
4432f29bd2 | ||
|
|
5fee3ed5e9 | ||
|
|
b76ea64263 | ||
|
|
ed904f08a4 | ||
|
|
96cc80ffc8 | ||
|
|
ab99373cfc | ||
|
|
dbfb49384b | ||
|
|
14bb9f29a3 | ||
|
|
16519ee2cc | ||
|
|
50022e9286 | ||
|
|
5059019535 | ||
|
|
c6a38f5069 | ||
|
|
11ed197663 | ||
|
|
5634e6b963 | ||
|
|
db312a5ff6 | ||
|
|
88c31b3785 | ||
|
|
967f3e4f77 | ||
|
|
2e311d1766 | ||
|
|
11f7cc0507 | ||
|
|
a4f28892a5 | ||
|
|
5bc53741be | ||
|
|
95a4f33265 | ||
|
|
fac1093ebf | ||
|
|
1b1384ccaa | ||
|
|
0c9a19ded5 | ||
|
|
b7bd7469b7 | ||
|
|
9568ff3f06 | ||
|
|
742ddcce11 | ||
|
|
e72cc9e3da | ||
|
|
3156e5a293 | ||
|
|
9a901e1cb0 | ||
|
|
8c11044ee2 | ||
|
|
a75d2db75b | ||
|
|
6aac72fd80 | ||
|
|
b692cb720c | ||
|
|
25102489f5 | ||
|
|
a2d2cad384 | ||
|
|
859e0c2323 | ||
|
|
e62a39cafe | ||
|
|
8bbb8fa062 | ||
|
|
68039e0d14 | ||
|
|
65fd30a547 | ||
|
|
23a4e8b38d | ||
|
|
979b53866d | ||
|
|
46061d8eec | ||
|
|
946ee8f611 | ||
|
|
7f757f09ce | ||
|
|
9ba8a33966 | ||
|
|
492940568d | ||
|
|
b95c2a3f78 | ||
|
|
53b661b59d | ||
|
|
a049c9e0f8 | ||
|
|
3513484852 | ||
|
|
2d67871bbf | ||
|
|
e6e9a472db | ||
|
|
1d5d768545 | ||
|
|
6c8588c13c | ||
|
|
89b127bf6c | ||
|
|
38c4a7ff97 | ||
|
|
2f5b4aea91 | ||
|
|
4fc6a1b424 | ||
|
|
6b3800cc94 | ||
|
|
633a007b7b | ||
|
|
756c2e9afb | ||
|
|
27ea58d5fd | ||
|
|
64f9205189 | ||
|
|
535ca64bba | ||
|
|
7255f9ef74 | ||
|
|
cdb0b6124f | ||
|
|
5fb1107cc7 | ||
|
|
1045adaa88 | ||
|
|
ed286f3617 | ||
|
|
9f9dd7948b | ||
|
|
9c760de676 | ||
|
|
90229984cf | ||
|
|
2b3d64c31d | ||
|
|
d23c647e34 | ||
|
|
2408bbcd77 | ||
|
|
d75f6830f1 | ||
|
|
4d7eb2f7a6 | ||
|
|
3a67dedad6 | ||
|
|
518837e17a | ||
|
|
c7e778757a | ||
|
|
c45be946ce | ||
|
|
258bcc21b8 | ||
|
|
db286ca6ea | ||
|
|
85fbfd9b15 | ||
|
|
b819c7fe55 | ||
|
|
2b5c86b9a3 | ||
|
|
0a848e2528 | ||
|
|
b443ec5ea5 | ||
|
|
37d1467368 | ||
|
|
1d9d19d76b | ||
|
|
9603f0552a | ||
|
|
12befc2afd | ||
|
|
78f20f7b3e | ||
|
|
875b0e262c | ||
|
|
8823e2b064 | ||
|
|
5b2caf48dc | ||
|
|
7ec048ce7f | ||
|
|
cfb3c3ba44 | ||
|
|
4b0ef09221 | ||
|
|
74f581e7ab | ||
|
|
07aa54b183 | ||
|
|
00da177e51 | ||
|
|
6e9bfac07d | ||
|
|
06f93e7bf0 | ||
|
|
d84a706c08 | ||
|
|
ea58a1e72c | ||
|
|
5c691a5460 | ||
|
|
2c877fa149 | ||
|
|
33053a5e14 | ||
|
|
8662652192 | ||
|
|
227c7e60a4 | ||
|
|
6e9c04896b | ||
|
|
0e273939d2 | ||
|
|
14647032b2 | ||
|
|
14a1059e43 | ||
|
|
4449259d88 | ||
|
|
01e5ea7d31 | ||
|
|
94522bfed1 | ||
|
|
9bdd35c9fa | ||
|
|
d366530699 | ||
|
|
96d652e5bd | ||
|
|
bd736f9234 | ||
|
|
90b25f5b83 | ||
|
|
997406fe47 | ||
|
|
14c8f07629 | ||
|
|
8f6a1b5318 | ||
|
|
a8c6bea2d5 | ||
|
|
19fde8f49c | ||
|
|
8f85291d23 | ||
|
|
9c48166e90 | ||
|
|
b536296c05 | ||
|
|
d36c522453 | ||
|
|
2577e20f09 | ||
|
|
c169ad3f58 | ||
|
|
411f4697ca | ||
|
|
6c5de8dcb0 | ||
|
|
c8373f1649 | ||
|
|
45f86122fa | ||
|
|
c0a8afdb68 | ||
|
|
1afb285aad | ||
|
|
c08e7e716d | ||
|
|
a06a5f1baa | ||
|
|
fb5d4f1da4 | ||
|
|
d2e5b41369 | ||
|
|
4b6b6e5cba | ||
|
|
27b4c396d0 | ||
|
|
41eb5b79cb | ||
|
|
23cf74d5c7 | ||
|
|
1a038bfd50 | ||
|
|
dd02d67224 | ||
|
|
648bf8bd3e | ||
|
|
82c4bfe5d2 | ||
|
|
98ba4ce4d5 | ||
|
|
f63e414024 | ||
|
|
a8886603c2 | ||
|
|
4f10144b09 | ||
|
|
af664e6cec | ||
|
|
c30816eb65 | ||
|
|
b1accfd0ff | ||
|
|
5c45e4ccb5 | ||
|
|
41cf867738 | ||
|
|
02844e9b01 | ||
|
|
7a1ebc3467 | ||
|
|
8d89610ff6 | ||
|
|
cfe706f032 | ||
|
|
99cc94529d | ||
|
|
d0dfa1de9e | ||
|
|
0899ab52dd | ||
|
|
71e0ebcb6b | ||
|
|
e488371b01 | ||
|
|
39f34eb674 | ||
|
|
9d9d6c30cf | ||
|
|
27d59e54cc | ||
|
|
507a01ab17 | ||
|
|
f7b8cd1a09 | ||
|
|
8bc48af630 | ||
|
|
b0838280a9 | ||
|
|
cea21adbbb | ||
|
|
c619d555f0 | ||
|
|
e306199588 | ||
|
|
895c15d677 | ||
|
|
d18f9ca75a | ||
|
|
82e76c39d9 | ||
|
|
577aed4842 | ||
|
|
2a8ce63fc7 | ||
|
|
61dd4e0ccb | ||
|
|
8220e51ae4 | ||
|
|
d322c8e6e5 | ||
|
|
3dec266dd5 | ||
|
|
862938cc79 | ||
|
|
ee396702f2 | ||
|
|
316d50d6f1 | ||
|
|
5e92aaf8a5 | ||
|
|
7ffe59a734 | ||
|
|
6cd558398a | ||
|
|
632cd1a177 | ||
|
|
223ad0e8aa | ||
|
|
f8bd9ab378 | ||
|
|
d78e8f096c | ||
|
|
57fc2ff1be | ||
|
|
d8d096aa54 | ||
|
|
0a10545314 | ||
|
|
aeb57a36b2 | ||
|
|
b703bc32c9 | ||
|
|
09afdd4b36 | ||
|
|
5cadaf8d55 | ||
|
|
89ac745184 | ||
|
|
e2422023c4 | ||
|
|
1ec0813663 | ||
|
|
6ba7fad2a7 | ||
|
|
962ca91574 | ||
|
|
91cbebb629 | ||
|
|
722f038f1f | ||
|
|
5e61c002a6 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,9 +1,12 @@
|
|||||||
.deps
|
.deps
|
||||||
.vimrc
|
.vimrc
|
||||||
|
*.gcda
|
||||||
|
*.gcno
|
||||||
*.o
|
*.o
|
||||||
*.swp
|
*.swp
|
||||||
*.dSYM
|
*.dSYM
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
core.*
|
||||||
tags
|
tags
|
||||||
/RELEASES
|
/RELEASES
|
||||||
/Makefile
|
/Makefile
|
||||||
|
|||||||
65
Makefile.in
65
Makefile.in
@@ -21,62 +21,56 @@
|
|||||||
#
|
#
|
||||||
# Makefile template
|
# Makefile template
|
||||||
|
|
||||||
SYSCONFDIR=@SYSCONFDIR@
|
SYSCONFDIR = @SYSCONFDIR@
|
||||||
BINDIR=@BINDIR@
|
BINDIR = @BINDIR@
|
||||||
SBINDIR=@SBINDIR@
|
SBINDIR = @SBINDIR@
|
||||||
LOCALSTATEDIR=@LOCALSTATEDIR@
|
LOCALSTATEDIR = @LOCALSTATEDIR@
|
||||||
CHRONYVARDIR=@CHRONYVARDIR@
|
CHRONYVARDIR = @CHRONYVARDIR@
|
||||||
|
DESTDIR =
|
||||||
|
|
||||||
CC = @CC@
|
CC = @CC@
|
||||||
CFLAGS = @CFLAGS@
|
CFLAGS = @CFLAGS@
|
||||||
CPPFLAGS = @CPPFLAGS@
|
CPPFLAGS = @CPPFLAGS@
|
||||||
|
LDFLAGS = @LDFLAGS@
|
||||||
|
|
||||||
DESTDIR=
|
EXTRA_OBJS = @EXTRA_OBJS@
|
||||||
|
|
||||||
HASH_OBJ = @HASH_OBJ@
|
OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o quantiles.o \
|
||||||
|
reference.o regress.o rtc.o samplefilt.o sched.o socket.o sources.o sourcestats.o \
|
||||||
|
stubs.o smooth.o sys.o sys_null.o tempcomp.o util.o $(EXTRA_OBJS)
|
||||||
|
|
||||||
OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o \
|
EXTRA_CLI_OBJS = @EXTRA_CLI_OBJS@
|
||||||
reference.o regress.o rtc.o sched.o sources.o sourcestats.o stubs.o \
|
|
||||||
sys.o smooth.o tempcomp.o util.o $(HASH_OBJ)
|
|
||||||
|
|
||||||
EXTRA_OBJS=@EXTRA_OBJECTS@
|
|
||||||
|
|
||||||
CLI_OBJS = array.o client.o cmdparse.o getdate.o memory.o nameserv.o \
|
CLI_OBJS = array.o client.o cmdparse.o getdate.o memory.o nameserv.o \
|
||||||
pktlength.o util.o $(HASH_OBJ)
|
pktlength.o socket.o util.o $(EXTRA_CLI_OBJS)
|
||||||
|
|
||||||
ALL_OBJS = $(OBJS) $(EXTRA_OBJS) $(CLI_OBJS)
|
ALL_OBJS = $(OBJS) $(CLI_OBJS)
|
||||||
|
|
||||||
LDFLAGS = @LDFLAGS@
|
|
||||||
LIBS = @LIBS@
|
LIBS = @LIBS@
|
||||||
|
EXTRA_LIBS = @EXTRA_LIBS@
|
||||||
EXTRA_LIBS=@EXTRA_LIBS@
|
EXTRA_CLI_LIBS = @EXTRA_CLI_LIBS@
|
||||||
EXTRA_CLI_LIBS=@EXTRA_CLI_LIBS@
|
|
||||||
|
|
||||||
# Until we have a main procedure we can link, just build object files
|
# Until we have a main procedure we can link, just build object files
|
||||||
# to test compilation
|
# to test compilation
|
||||||
|
|
||||||
all : chronyd chronyc
|
all : chronyd chronyc
|
||||||
|
|
||||||
chronyd : $(OBJS) $(EXTRA_OBJS)
|
chronyd : $(OBJS)
|
||||||
$(CC) $(CFLAGS) -o chronyd $(OBJS) $(EXTRA_OBJS) $(LDFLAGS) $(LIBS) $(EXTRA_LIBS)
|
$(CC) $(CFLAGS) -o chronyd $(OBJS) $(LDFLAGS) $(LIBS) $(EXTRA_LIBS)
|
||||||
|
|
||||||
chronyc : $(CLI_OBJS)
|
chronyc : $(CLI_OBJS)
|
||||||
$(CC) $(CFLAGS) -o chronyc $(CLI_OBJS) $(LDFLAGS) $(LIBS) $(EXTRA_CLI_LIBS)
|
$(CC) $(CFLAGS) -o chronyc $(CLI_OBJS) $(LDFLAGS) $(LIBS) $(EXTRA_CLI_LIBS)
|
||||||
|
|
||||||
client.o : client.c
|
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) @READLINE_COMPILE@ -c $<
|
|
||||||
|
|
||||||
$(HASH_OBJ) : $(patsubst %.o,%.c,$(HASH_OBJ))
|
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) @HASH_COMPILE@ -c $<
|
|
||||||
|
|
||||||
distclean : clean
|
distclean : clean
|
||||||
-rm -f .DS_Store
|
|
||||||
-rm -f Makefile config.h config.log
|
|
||||||
$(MAKE) -C doc distclean
|
$(MAKE) -C doc distclean
|
||||||
$(MAKE) -C test/unit distclean
|
$(MAKE) -C test/unit distclean
|
||||||
|
-rm -f .DS_Store
|
||||||
|
-rm -f Makefile config.h config.log
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
-rm -f *.o *.s chronyc chronyd core *~
|
$(MAKE) -C test/unit clean
|
||||||
|
-rm -f *.o *.s chronyc chronyd core.* *~
|
||||||
|
-rm -f *.gcda *.gcno
|
||||||
-rm -rf .deps
|
-rm -rf .deps
|
||||||
-rm -rf *.dSYM
|
-rm -rf *.dSYM
|
||||||
|
|
||||||
@@ -115,9 +109,18 @@ install-docs :
|
|||||||
%.s : %.c
|
%.s : %.c
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -S $<
|
$(CC) $(CFLAGS) $(CPPFLAGS) -S $<
|
||||||
|
|
||||||
check : chronyd chronyc
|
quickcheck : chronyd chronyc
|
||||||
$(MAKE) -C test/unit check
|
$(MAKE) -C test/unit check
|
||||||
cd test/simulation && ./run
|
cd test/simulation && ./run
|
||||||
|
cd test/system && ./run
|
||||||
|
|
||||||
|
check : chronyd chronyc
|
||||||
|
$(MAKE) -C test/unit check
|
||||||
|
cd test/simulation && ./run -i 20 -m 2
|
||||||
|
cd test/system && ./run
|
||||||
|
|
||||||
|
print-chronyd-objects :
|
||||||
|
@echo $(OBJS)
|
||||||
|
|
||||||
Makefile : Makefile.in configure
|
Makefile : Makefile.in configure
|
||||||
@echo
|
@echo
|
||||||
@@ -131,4 +134,6 @@ Makefile : Makefile.in configure
|
|||||||
.deps/%.d: %.c | .deps
|
.deps/%.d: %.c | .deps
|
||||||
@$(CC) -MM $(CPPFLAGS) -MT '$(<:%.c=%.o) $@' $< -o $@
|
@$(CC) -MM $(CPPFLAGS) -MT '$(<:%.c=%.o) $@' $< -o $@
|
||||||
|
|
||||||
|
ifndef NODEPS
|
||||||
-include $(ALL_OBJS:%.o=.deps/%.d)
|
-include $(ALL_OBJS:%.o=.deps/%.d)
|
||||||
|
endif
|
||||||
|
|||||||
285
NEWS
285
NEWS
@@ -1,3 +1,287 @@
|
|||||||
|
New in version 4.3
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add local option to refclock directive to stabilise system clock
|
||||||
|
with more stable free-running clock (e.g. TCXO, OCXO)
|
||||||
|
* Add maxdelayquant option to server/pool/peer directive to replace
|
||||||
|
maxdelaydevratio filter with long-term quantile-based filtering
|
||||||
|
* Add selection option to log directive
|
||||||
|
* Allow external PPS in PHC refclock without configurable pin
|
||||||
|
* Don't accept first interleaved response to minimise error in delay
|
||||||
|
* Don't use arc4random on Linux to avoid server performance loss
|
||||||
|
* Improve filter option to better handle missing NTP samples
|
||||||
|
* Improve stability with hardware timestamping and PHC refclock
|
||||||
|
* Update seccomp filter
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix waitsync command to reconnect when not getting response
|
||||||
|
|
||||||
|
New in version 4.2
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add support for NTPv4 extension field improving synchronisation
|
||||||
|
stability and resolution of root delay and dispersion (experimental)
|
||||||
|
* Add support for NTP over PTP (experimental)
|
||||||
|
* Add support for AES-CMAC and hash functions in GnuTLS
|
||||||
|
* Improve server interleaved mode to be more reliable and support
|
||||||
|
multiple clients behind NAT
|
||||||
|
* Update seccomp filter
|
||||||
|
* Add statistics about interleaved mode to serverstats report
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix RTC support with 64-bit time_t on 32-bit Linux
|
||||||
|
* Fix seccomp filter to work correctly with bind*device directives
|
||||||
|
* Suppress kernel adjustments of system clock (dosynctodr) on illumos
|
||||||
|
|
||||||
|
Other changes
|
||||||
|
-------------
|
||||||
|
* Switch Solaris support to illumos
|
||||||
|
|
||||||
|
New in version 4.1
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add support for NTS servers specified by IP address (matching
|
||||||
|
Subject Alternative Name in server certificate)
|
||||||
|
* Add source-specific configuration of trusted certificates
|
||||||
|
* Allow multiple files and directories with trusted certificates
|
||||||
|
* Allow multiple pairs of server keys and certificates
|
||||||
|
* Add copy option to server/pool directive
|
||||||
|
* Increase PPS lock limit to 40% of pulse interval
|
||||||
|
* Perform source selection immediately after loading dump files
|
||||||
|
* Reload dump files for addresses negotiated by NTS-KE server
|
||||||
|
* Update seccomp filter and add less restrictive level
|
||||||
|
* Restart ongoing name resolution on online command
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix responding to IPv4 command requests on FreeBSD
|
||||||
|
* Fix dump files to not include uncorrected offset
|
||||||
|
* Fix initstepslew to accept time from own NTP clients
|
||||||
|
* Reset NTP address and port when no longer negotiated by NTS-KE server
|
||||||
|
|
||||||
|
New in version 4.0
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add support for Network Time Security (NTS) authentication
|
||||||
|
* Add support for AES-CMAC keys (AES128, AES256) with Nettle
|
||||||
|
* Add authselectmode directive to control selection of unauthenticated sources
|
||||||
|
* Add binddevice, bindacqdevice, bindcmddevice directives
|
||||||
|
* Add confdir directive to better support fragmented configuration
|
||||||
|
* Add sourcedir directive and "reload sources" command to support dynamic
|
||||||
|
NTP sources specified in files
|
||||||
|
* Add clockprecision directive
|
||||||
|
* Add dscp directive to set Differentiated Services Code Point (DSCP)
|
||||||
|
* Add -L option to limit log messages by severity
|
||||||
|
* Add -p option to print whole configuration with included files
|
||||||
|
* Add -U option to allow start under non-root user
|
||||||
|
* Allow maxsamples to be set to 1 for faster update with -q/-Q option
|
||||||
|
* Avoid replacing NTP sources with sources that have unreachable address
|
||||||
|
* Improve pools to repeat name resolution to get "maxsources" sources
|
||||||
|
* Improve source selection with trusted sources
|
||||||
|
* Improve NTP loop test to prevent synchronisation to itself
|
||||||
|
* Repeat iburst when NTP source is switched from offline state to online
|
||||||
|
* Update clock synchronisation status and leap status more frequently
|
||||||
|
* Update seccomp filter
|
||||||
|
* Add "add pool" command
|
||||||
|
* Add "reset sources" command to drop all measurements
|
||||||
|
* Add authdata command to print details about NTP authentication
|
||||||
|
* Add selectdata command to print details about source selection
|
||||||
|
* Add -N option and sourcename command to print original names of sources
|
||||||
|
* Add -a option to some commands to print also unresolved sources
|
||||||
|
* Add -k, -p, -r options to clients command to select, limit, reset data
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Don't set interface for NTP responses to allow asymmetric routing
|
||||||
|
* Handle RTCs that don't support interrupts
|
||||||
|
* Respond to command requests with correct address on multihomed hosts
|
||||||
|
|
||||||
|
Removed features
|
||||||
|
----------------
|
||||||
|
* Drop support for RIPEMD keys (RMD128, RMD160, RMD256, RMD320)
|
||||||
|
* Drop support for long (non-standard) MACs in NTPv4 packets (chrony 2.x
|
||||||
|
clients using non-MD5/SHA1 keys need to use option "version 3")
|
||||||
|
* Drop support for line editing with GNU Readline
|
||||||
|
|
||||||
|
New in version 3.5.1
|
||||||
|
====================
|
||||||
|
|
||||||
|
Security fixes
|
||||||
|
--------------
|
||||||
|
* Create new file when writing pidfile (CVE-2020-14367)
|
||||||
|
|
||||||
|
New in version 3.5
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add support for more accurate reading of PHC on Linux 5.0
|
||||||
|
* Add support for hardware timestamping on interfaces with read-only
|
||||||
|
timestamping configuration
|
||||||
|
* Add support for memory locking and real-time priority on FreeBSD,
|
||||||
|
NetBSD, Solaris
|
||||||
|
* Update seccomp filter to work on more architectures
|
||||||
|
* Validate refclock driver options
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix bindaddress directive on FreeBSD
|
||||||
|
* Fix transposition of hardware RX timestamp on Linux 4.13 and later
|
||||||
|
* Fix building on non-glibc systems
|
||||||
|
|
||||||
|
New in version 3.4
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add filter option to server/pool/peer directive
|
||||||
|
* Add minsamples and maxsamples options to hwtimestamp directive
|
||||||
|
* Add support for faster frequency adjustments in Linux 4.19
|
||||||
|
* Change default pidfile to /var/run/chrony/chronyd.pid to allow
|
||||||
|
chronyd without root privileges to remove it on exit
|
||||||
|
* Disable sub-second polling intervals for distant NTP sources
|
||||||
|
* Extend range of supported sub-second polling intervals
|
||||||
|
* Get/set IPv4 destination/source address of NTP packets on FreeBSD
|
||||||
|
* Make burst options and command useful with short polling intervals
|
||||||
|
* Modify auto_offline option to activate when sending request failed
|
||||||
|
* Respond from interface that received NTP request if possible
|
||||||
|
* Add onoffline command to switch between online and offline state
|
||||||
|
according to current system network configuration
|
||||||
|
* Improve example NetworkManager dispatcher script
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Avoid waiting in Linux getrandom system call
|
||||||
|
* Fix PPS support on FreeBSD and NetBSD
|
||||||
|
|
||||||
|
New in version 3.3
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add burst option to server/pool directive
|
||||||
|
* Add stratum and tai options to refclock directive
|
||||||
|
* Add support for Nettle crypto library
|
||||||
|
* Add workaround for missing kernel receive timestamps on Linux
|
||||||
|
* Wait for late hardware transmit timestamps
|
||||||
|
* Improve source selection with unreachable sources
|
||||||
|
* Improve protection against replay attacks on symmetric mode
|
||||||
|
* Allow PHC refclock to use socket in /var/run/chrony
|
||||||
|
* Add shutdown command to stop chronyd
|
||||||
|
* Simplify format of response to manual list command
|
||||||
|
* Improve handling of unknown responses in chronyc
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Respond to NTPv1 client requests with zero mode
|
||||||
|
* Fix -x option to not require CAP_SYS_TIME under non-root user
|
||||||
|
* Fix acquisitionport directive to work with privilege separation
|
||||||
|
* Fix handling of socket errors on Linux to avoid high CPU usage
|
||||||
|
* Fix chronyc to not get stuck in infinite loop after clock step
|
||||||
|
|
||||||
|
New in version 3.2
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Improve stability with NTP sources and reference clocks
|
||||||
|
* Improve stability with hardware timestamping
|
||||||
|
* Improve support for NTP interleaved modes
|
||||||
|
* Control frequency of system clock on macOS 10.13 and later
|
||||||
|
* Set TAI-UTC offset of system clock with leapsectz directive
|
||||||
|
* Minimise data in client requests to improve privacy
|
||||||
|
* Allow transmit-only hardware timestamping
|
||||||
|
* Add support for new timestamping options introduced in Linux 4.13
|
||||||
|
* Add root delay, root dispersion and maximum error to tracking log
|
||||||
|
* Add mindelay and asymmetry options to server/peer/pool directive
|
||||||
|
* Add extpps option to PHC refclock to timestamp external PPS signal
|
||||||
|
* Add pps option to refclock directive to treat any refclock as PPS
|
||||||
|
* Add width option to refclock directive to filter wrong pulse edges
|
||||||
|
* Add rxfilter option to hwtimestamp directive
|
||||||
|
* Add -x option to disable control of system clock
|
||||||
|
* Add -l option to log to specified file instead of syslog
|
||||||
|
* Allow multiple command-line options to be specified together
|
||||||
|
* Allow starting without root privileges with -Q option
|
||||||
|
* Update seccomp filter for new glibc versions
|
||||||
|
* Dump history on exit by default with dumpdir directive
|
||||||
|
* Use hardening compiler options by default
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Don't drop PHC samples with low-resolution system clock
|
||||||
|
* Ignore outliers in PHC tracking, RTC tracking, manual input
|
||||||
|
* Increase polling interval when peer is not responding
|
||||||
|
* Exit with error message when include directive fails
|
||||||
|
* Don't allow slash after hostname in allow/deny directive/command
|
||||||
|
* Try to connect to all addresses in chronyc before giving up
|
||||||
|
|
||||||
|
New in version 3.1
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add support for precise cross timestamping of PHC on Linux
|
||||||
|
* Add minpoll, precision, nocrossts options to hwtimestamp directive
|
||||||
|
* Add rawmeasurements option to log directive and modify measurements
|
||||||
|
option to log only valid measurements from synchronised sources
|
||||||
|
* Allow sub-second polling interval with NTP sources
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix time smoothing in interleaved mode
|
||||||
|
|
||||||
|
New in version 3.0
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add support for software and hardware timestamping on Linux
|
||||||
|
* Add support for client/server and symmetric interleaved modes
|
||||||
|
* Add support for MS-SNTP authentication in Samba
|
||||||
|
* Add support for truncated MACs in NTPv4 packets
|
||||||
|
* Estimate and correct for asymmetric network jitter
|
||||||
|
* Increase default minsamples and polltarget to improve stability
|
||||||
|
with very low jitter
|
||||||
|
* Add maxjitter directive to limit source selection by jitter
|
||||||
|
* Add offset option to server/pool/peer directive
|
||||||
|
* Add maxlockage option to refclock directive
|
||||||
|
* Add -t option to chronyd to exit after specified time
|
||||||
|
* Add partial protection against replay attacks on symmetric mode
|
||||||
|
* Don't reset polling interval when switching sources to online state
|
||||||
|
* Allow rate limiting with very short intervals
|
||||||
|
* Improve maximum server throughput on Linux and NetBSD
|
||||||
|
* Remove dump files after start
|
||||||
|
* Add tab-completion to chronyc with libedit/readline
|
||||||
|
* Add ntpdata command to print details about NTP measurements
|
||||||
|
* Allow all source options to be set in add server/peer command
|
||||||
|
* Indicate truncated addresses/hostnames in chronyc output
|
||||||
|
* Print reference IDs as hexadecimal numbers to avoid confusion with
|
||||||
|
IPv4 addresses
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix crash with disabled asynchronous name resolving
|
||||||
|
|
||||||
|
New in version 2.4.1
|
||||||
|
====================
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix processing of kernel timestamps on non-Linux systems
|
||||||
|
* Fix crash with smoothtime directive
|
||||||
|
* Fix validation of refclock sample times
|
||||||
|
* Fix parsing of refclock directive
|
||||||
|
|
||||||
New in version 2.4
|
New in version 2.4
|
||||||
==================
|
==================
|
||||||
|
|
||||||
@@ -19,6 +303,7 @@ Bug fixes
|
|||||||
---------
|
---------
|
||||||
* Fix SOCK refclock to work correctly when not specified as last refclock
|
* Fix SOCK refclock to work correctly when not specified as last refclock
|
||||||
* Fix initstepslew and -q/-Q options to accept time from own NTP clients
|
* Fix initstepslew and -q/-Q options to accept time from own NTP clients
|
||||||
|
* Fix authentication with keys using 512-bit hash functions
|
||||||
* Fix crash on exit when multiple signals are received
|
* Fix crash on exit when multiple signals are received
|
||||||
* Fix conversion of very small floating-point numbers in command packets
|
* Fix conversion of very small floating-point numbers in command packets
|
||||||
|
|
||||||
|
|||||||
206
README
206
README
@@ -4,7 +4,7 @@ What is chrony?
|
|||||||
===============
|
===============
|
||||||
|
|
||||||
chrony is a versatile implementation of the Network Time Protocol (NTP).
|
chrony is a versatile implementation of the Network Time Protocol (NTP).
|
||||||
It can synchronize the system clock with NTP servers, reference clocks
|
It can synchronise the system clock with NTP servers, reference clocks
|
||||||
(e.g. GPS receiver), and manual input using wristwatch and keyboard.
|
(e.g. GPS receiver), and manual input using wristwatch and keyboard.
|
||||||
It can also operate as an NTPv4 (RFC 5905) server and peer to provide
|
It can also operate as an NTPv4 (RFC 5905) server and peer to provide
|
||||||
a time service to other computers in the network.
|
a time service to other computers in the network.
|
||||||
@@ -14,10 +14,10 @@ intermittent network connections, heavily congested networks, changing
|
|||||||
temperatures (ordinary computer clocks are sensitive to temperature),
|
temperatures (ordinary computer clocks are sensitive to temperature),
|
||||||
and systems that do not run continuosly, or run on a virtual machine.
|
and systems that do not run continuosly, or run on a virtual machine.
|
||||||
|
|
||||||
Typical accuracy between two machines on a LAN is in tens, or a few
|
Typical accuracy between two machines synchronised over the Internet is
|
||||||
hundreds, of microseconds; over the Internet, accuracy is typically
|
within a few milliseconds; on a LAN, accuracy is typically in tens of
|
||||||
within a few milliseconds. With a good hardware reference clock
|
microseconds. With hardware timestamping, or a hardware reference clock,
|
||||||
sub-microsecond accuracy is possible.
|
sub-microsecond accuracy may be possible.
|
||||||
|
|
||||||
Two programs are included in chrony, chronyd is a daemon that can be
|
Two programs are included in chrony, chronyd is a daemon that can be
|
||||||
started at boot time and chronyc is a command-line interface program
|
started at boot time and chronyc is a command-line interface program
|
||||||
@@ -27,30 +27,24 @@ operating parameters whilst it is running.
|
|||||||
What will chrony run on?
|
What will chrony run on?
|
||||||
========================
|
========================
|
||||||
|
|
||||||
The software is known to work on Linux, FreeBSD, NetBSD, Mac OS X and
|
The software is known to work on Linux, FreeBSD, NetBSD, macOS and
|
||||||
Solaris. Closely related systems may work too. Any other system will
|
illumos. Closely related systems may work too. Any other system will
|
||||||
likely require a porting exercise. You would need to start from one
|
likely require a porting exercise.
|
||||||
of the existing system-specific drivers and look into the quirks of
|
|
||||||
certain system calls and the kernel on your target system.
|
|
||||||
|
|
||||||
How do I set it up?
|
How do I set it up?
|
||||||
===================
|
===================
|
||||||
|
|
||||||
The file INSTALL gives instructions. On supported systems the
|
The file INSTALL gives instructions. On supported systems the
|
||||||
compilation process should be automatic.
|
compilation process should be automatic. You will need a C compiler,
|
||||||
|
e.g. gcc or clang.
|
||||||
You will need an ANSI C compiler -- gcc is recommended.
|
|
||||||
|
|
||||||
The manual (in texinfo and text formats) describes how to set the
|
|
||||||
software up for the less straightforward cases.
|
|
||||||
|
|
||||||
What documentation is there?
|
What documentation is there?
|
||||||
============================
|
============================
|
||||||
|
|
||||||
A manual is supplied in Texinfo format (chrony.texi) and
|
The distribution includes manual pages and a document containing
|
||||||
ready-formatted plain text (chrony.txt) in the distribution.
|
Frequently Asked Questions (FAQ).
|
||||||
|
|
||||||
There is also information available on the chrony web pages, accessible
|
The documentation is also available on the chrony web pages, accessible
|
||||||
through the URL
|
through the URL
|
||||||
|
|
||||||
https://chrony.tuxfamily.org/
|
https://chrony.tuxfamily.org/
|
||||||
@@ -59,24 +53,20 @@ Where are new versions announced?
|
|||||||
=================================
|
=================================
|
||||||
|
|
||||||
There is a low volume mailing list where new versions and other
|
There is a low volume mailing list where new versions and other
|
||||||
important news relating to chrony is announced. You can join this list
|
important news relating to chrony are announced. You can join this list
|
||||||
by sending mail with the subject "subscribe" to
|
by sending mail with the subject "subscribe" to
|
||||||
|
|
||||||
chrony-announce-request@chrony.tuxfamily.org
|
chrony-announce-request@chrony.tuxfamily.org
|
||||||
|
|
||||||
These messages will be copied to chrony-users (see below).
|
|
||||||
|
|
||||||
How can I get support for chrony?
|
How can I get support for chrony?
|
||||||
and where can I discuss new features, possible bugs etc?
|
=================================
|
||||||
========================================================
|
|
||||||
|
|
||||||
There are 3 mailing lists relating to chrony. chrony-announce was
|
There are two other mailing lists relating to chrony. chrony-users is a
|
||||||
mentioned above. chrony-users is a users' discussion list, e.g. for
|
discussion list for users, e.g. for questions about chrony configuration
|
||||||
general questions and answers about using chrony. chrony-dev is a more
|
and bug reports. chrony-dev is a more technical list for developers,
|
||||||
technical list, e.g. for discussing how new features should be
|
e.g. for submitting patches and discussing how new features should be
|
||||||
implemented, exchange of information between developers etc. To
|
implemented. To subscribe to either of these lists, send a message with
|
||||||
subscribe to either of these lists, send a message with the subject
|
the subject "subscribe" to
|
||||||
"subscribe" to
|
|
||||||
|
|
||||||
chrony-users-request@chrony.tuxfamily.org
|
chrony-users-request@chrony.tuxfamily.org
|
||||||
or
|
or
|
||||||
@@ -84,161 +74,87 @@ chrony-dev-request@chrony.tuxfamily.org
|
|||||||
|
|
||||||
as applicable.
|
as applicable.
|
||||||
|
|
||||||
When you are reporting a bug, please send us all the information you can.
|
|
||||||
Unfortunately, chrony has proven to be one of those programs where it is very
|
|
||||||
difficult to reproduce bugs in a different environment. So we may have to
|
|
||||||
interact with you quite a lot to obtain enough extra logging and tracing to
|
|
||||||
pin-point the problem in some cases. Please be patient and plan for this!
|
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
chrony is distributed under the GNU General Public License version 2.
|
chrony is distributed under the GNU General Public License version 2.
|
||||||
|
|
||||||
|
Authors
|
||||||
Author
|
=======
|
||||||
======
|
|
||||||
|
|
||||||
Richard P. Curnow <rc@rc0.org.uk>
|
Richard P. Curnow <rc@rc0.org.uk>
|
||||||
|
|
||||||
|
|
||||||
Maintainers
|
|
||||||
===========
|
|
||||||
|
|
||||||
Miroslav Lichvar <mlichvar@redhat.com>
|
Miroslav Lichvar <mlichvar@redhat.com>
|
||||||
|
|
||||||
|
|
||||||
Acknowledgements
|
Acknowledgements
|
||||||
================
|
================
|
||||||
|
|
||||||
In writing the chronyd program, extensive use has been made of RFC 1305
|
In writing the chronyd program, extensive use has been made of the NTPv3 (RFC
|
||||||
and RFC 5905, written by David Mills. The source code of the NTP reference
|
1305) and NTPv4 (RFC 5905) specification. The source code of the xntpd/ntpd
|
||||||
implementation has been used to check the details of the protocol.
|
implementation written by Dennis Fergusson, Lars Mathiesen, David Mills, and
|
||||||
|
others has been used to check the details of the protocol.
|
||||||
|
|
||||||
The following people have provided patches and other major contributions
|
The following people have provided patches and other major contributions
|
||||||
to the program :
|
to chrony:
|
||||||
|
|
||||||
|
Lonnie Abelbeck <lonnie@abelbeck.com>
|
||||||
Benny Lyne Amorsen <benny@amorsen.dk>
|
Benny Lyne Amorsen <benny@amorsen.dk>
|
||||||
Patch to add minstratum option
|
|
||||||
|
|
||||||
Andrew Bishop <amb@gedanken.demon.co.uk>
|
Andrew Bishop <amb@gedanken.demon.co.uk>
|
||||||
Fixes for bugs in logging when in daemon mode
|
Vincent Blut <vincent.debian@free.fr>
|
||||||
Fixes for compiler warnings
|
|
||||||
Robustness improvements for drift file
|
|
||||||
Improve installation (directory checking etc)
|
|
||||||
Entries in contrib directory
|
|
||||||
Improvements to 'sources' and 'sourcestats' output from chronyc
|
|
||||||
Improvements to documentation
|
|
||||||
Investigation of required dosynctodr behaviour for various Solaris
|
|
||||||
versions.
|
|
||||||
|
|
||||||
Stephan I. Boettcher <stephan@nevis1.columbia.edu>
|
Stephan I. Boettcher <stephan@nevis1.columbia.edu>
|
||||||
Entries in contrib directory
|
David Bohman <debohman@gmail.com>
|
||||||
|
Goswin Brederlow <brederlo@informatik.uni-tuebingen.de>
|
||||||
|
Leigh Brown <leigh@solinno.co.uk>
|
||||||
Erik Bryer <ebryer@spots.ab.ca>
|
Erik Bryer <ebryer@spots.ab.ca>
|
||||||
Entries in contrib directory
|
Jonathan Cameron <jic23@cam.ac.uk>
|
||||||
|
|
||||||
Bryan Christianson <bryan@whatroute.net>
|
Bryan Christianson <bryan@whatroute.net>
|
||||||
Support for Mac OS X
|
|
||||||
Support for privilege separation
|
|
||||||
|
|
||||||
Juliusz Chroboczek <jch@pps.jussieu.fr>
|
Juliusz Chroboczek <jch@pps.jussieu.fr>
|
||||||
Fix install rule in Makefile if chronyd file is in use.
|
Kamil Dudka <kdudka@redhat.com>
|
||||||
|
Christian Ehrhardt <christian.ehrhardt@canonical.com>
|
||||||
Paul Elliott <pelliott@io.com>
|
Paul Elliott <pelliott@io.com>
|
||||||
DNSchrony (in contrib directory), a tool for handling NTP servers
|
Robert Fairley <rfairley@redhat.com>
|
||||||
with variable IP addresses.
|
Stefan R. Filipek <srfilipek@gmail.com>
|
||||||
|
|
||||||
Mike Fleetwood <mike@rockover.demon.co.uk>
|
Mike Fleetwood <mike@rockover.demon.co.uk>
|
||||||
Fixes for compiler warnings
|
|
||||||
|
|
||||||
Alexander Gretencord <arutha@gmx.de>
|
Alexander Gretencord <arutha@gmx.de>
|
||||||
Changes to installation directory system to make it easier for
|
|
||||||
package builders.
|
|
||||||
|
|
||||||
Andrew Griffiths <agriffit@redhat.com>
|
Andrew Griffiths <agriffit@redhat.com>
|
||||||
Patch to add support for seccomp filter
|
|
||||||
|
|
||||||
Walter Haidinger <walter.haidinger@gmx.at>
|
Walter Haidinger <walter.haidinger@gmx.at>
|
||||||
Providing me with login access to a Linux installation where v1.12
|
|
||||||
wouldn't compile, so I could develop the fixes for v1.13. Also, for
|
|
||||||
providing the disc space so I can keep an independent backup of the
|
|
||||||
sources.
|
|
||||||
|
|
||||||
Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
|
Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>
|
||||||
Port to NetBSD
|
|
||||||
|
|
||||||
John Hasler <john@dhh.gt.org>
|
John Hasler <john@dhh.gt.org>
|
||||||
Project and website at tuxfamily.org
|
|
||||||
Changes to support 64 bit machines (i.e. those where
|
|
||||||
sizeof(unsigned long) > 4)
|
|
||||||
Bug fix to initstepslew directive
|
|
||||||
Fix to remove potential buffer overrun errors.
|
|
||||||
Memory locking and real-time scheduler support
|
|
||||||
Fix fault where chronyd enters an endless loop
|
|
||||||
|
|
||||||
Tjalling Hattink <t.hattink@fugro.nl>
|
Tjalling Hattink <t.hattink@fugro.nl>
|
||||||
Fix scheduler to allow stepping clock from timeout handler
|
|
||||||
Patch to take leap second in PPS refclock from locked source
|
|
||||||
Patch to make reading of RTC for initial trim more reliable
|
|
||||||
|
|
||||||
Liam Hatton <me@liamhatton.com>
|
Liam Hatton <me@liamhatton.com>
|
||||||
Advice on configuring for Linux on PPC
|
|
||||||
|
|
||||||
Jachym Holecek <jakym@volny.cz>
|
Jachym Holecek <jakym@volny.cz>
|
||||||
Patch to make Linux real time clock work with devfs
|
|
||||||
|
|
||||||
Håkan Johansson <f96hajo@chalmers.se>
|
Håkan Johansson <f96hajo@chalmers.se>
|
||||||
Patch to avoid large values in sources and sourcestats output
|
|
||||||
|
|
||||||
Jim Knoble <jmknoble@pobox.com>
|
Jim Knoble <jmknoble@pobox.com>
|
||||||
Fixes for compiler warnings
|
|
||||||
|
|
||||||
Antti Jrvinen <costello@iki.fi>
|
Antti Jrvinen <costello@iki.fi>
|
||||||
Advice on configuring for BSD/386
|
Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
|
||||||
|
Eric Lammerts <eric@lammerts.org>
|
||||||
Miroslav Lichvar <mlichvar@redhat.com>
|
Stefan Lucke <stefan@lucke.in-berlin.de>
|
||||||
Reference clock support
|
Victor Lum <viclum@vanu.com>
|
||||||
IPv6 support
|
Kevin Lyda <kevin@ie.suberic.net>
|
||||||
Linux capabilities support
|
Paul Menzel <paulepanter@users.sourceforge.net>
|
||||||
Leap second support
|
Vladimir Michl <vladimir.michl@seznam.cz>
|
||||||
Improved source selection
|
|
||||||
Improved sample history trimming
|
|
||||||
Improved polling interval adjustment
|
|
||||||
Improved stability with temporary asymmetric delays
|
|
||||||
Temperature compensation
|
|
||||||
Many other bug fixes and improvements
|
|
||||||
|
|
||||||
Victor Moroz <vim@prv.adlum.ru>
|
Victor Moroz <vim@prv.adlum.ru>
|
||||||
Patch to support Linux with HZ!=100
|
|
||||||
|
|
||||||
Kalle Olavi Niemitalo <tosi@stekt.oulu.fi>
|
Kalle Olavi Niemitalo <tosi@stekt.oulu.fi>
|
||||||
acquisitionport support
|
|
||||||
|
|
||||||
Frank Otto <sandwichmacher@web.de>
|
Frank Otto <sandwichmacher@web.de>
|
||||||
Handling arbitrary HZ values
|
Denny Page <dennypage@me.com>
|
||||||
|
Chris Perl <cperl@janestreet.com>
|
||||||
Gautier PHILIPPON <gautier.philippon@ensimag.grenoble-inp.fr>
|
Gautier PHILIPPON <gautier.philippon@ensimag.grenoble-inp.fr>
|
||||||
Patch to add refresh command to chronyc
|
|
||||||
|
|
||||||
Andreas Piesk <apiesk@virbus.de>
|
Andreas Piesk <apiesk@virbus.de>
|
||||||
Patch to make chronyc use the readline library if available
|
Baruch Siach <baruch@tkos.co.il>
|
||||||
|
Foster Snowhill <forst@forstwoof.ru>
|
||||||
|
Andreas Steinmetz <ast@domdv.de>
|
||||||
|
NAKAMURA Takumi <takumi@ps.sakura.ne.jp>
|
||||||
Timo Teras <timo.teras@iki.fi>
|
Timo Teras <timo.teras@iki.fi>
|
||||||
Patch to reply correctly on multihomed hosts
|
Bill Unruh <unruh@physics.ubc.ca>
|
||||||
|
Stephen Wadeley <swadeley@redhat.com>
|
||||||
|
Bernhard Weiss <lisnablagh@web.de>
|
||||||
Wolfgang Weisselberg <weissel@netcologne.de>
|
Wolfgang Weisselberg <weissel@netcologne.de>
|
||||||
Entries in contrib directory
|
Bernhard M. Wiedemann <bwiedemann@suse.de>
|
||||||
|
Joachim Wiedorn <ad_debian@joonet.de>
|
||||||
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
|
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
|
||||||
Many robustness and security improvements
|
Ulrich Windl <ulrich.windl@rz.uni-regensburg.de>
|
||||||
|
Michael Witten <mfwitten@gmail.com>
|
||||||
Ulrich Windl <ulrich.windl@rz.uni-regensburg.de> for the
|
|
||||||
Providing me with information about the Linux 2.2 kernel
|
|
||||||
functionality compared to 2.0.
|
|
||||||
|
|
||||||
Doug Woodward <dougw@whistler.com>
|
Doug Woodward <dougw@whistler.com>
|
||||||
Advice on configuring for Solaris 2.8 on x86
|
Thomas Zajic <zlatko@zlatko.fdns.net>
|
||||||
|
|
||||||
Many other people have contributed bug reports and suggestions. I'm
|
Many other people have contributed bug reports and suggestions. We are sorry
|
||||||
sorry I can't identify all of you individually.
|
we cannot identify all of you individually.
|
||||||
|
|||||||
13
addressing.h
13
addressing.h
@@ -30,27 +30,36 @@
|
|||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
/* This type is used to represent an IPv4 address or IPv6 address.
|
/* This type is used to represent an IPv4 address or IPv6 address.
|
||||||
|
Addresses which are not resolved yet can be represented with an ID.
|
||||||
All parts are in HOST order, NOT network order. */
|
All parts are in HOST order, NOT network order. */
|
||||||
|
|
||||||
#define IPADDR_UNSPEC 0
|
#define IPADDR_UNSPEC 0
|
||||||
#define IPADDR_INET4 1
|
#define IPADDR_INET4 1
|
||||||
#define IPADDR_INET6 2
|
#define IPADDR_INET6 2
|
||||||
|
#define IPADDR_ID 3
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
uint32_t in4;
|
uint32_t in4;
|
||||||
uint8_t in6[16];
|
uint8_t in6[16];
|
||||||
|
uint32_t id;
|
||||||
} addr;
|
} addr;
|
||||||
uint16_t family;
|
uint16_t family;
|
||||||
|
uint16_t _pad;
|
||||||
} IPAddr;
|
} IPAddr;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
unsigned short port;
|
uint16_t port;
|
||||||
} NTP_Remote_Address;
|
} IPSockAddr;
|
||||||
|
|
||||||
|
typedef IPSockAddr NTP_Remote_Address;
|
||||||
|
|
||||||
|
#define INVALID_IF_INDEX -1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
|
int if_index;
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
} NTP_Local_Address;
|
} NTP_Local_Address;
|
||||||
|
|
||||||
|
|||||||
@@ -247,6 +247,8 @@ set_subnet_(ADF_AuthTable table,
|
|||||||
set_subnet(&table->base6, ip6, 4, 0, new_state, delete_children) == ADF_SUCCESS)
|
set_subnet(&table->base6, ip6, 4, 0, new_state, delete_children) == ADF_SUCCESS)
|
||||||
return ADF_SUCCESS;
|
return ADF_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ADF_BADSUBNET;
|
return ADF_BADSUBNET;
|
||||||
@@ -359,9 +361,9 @@ ADF_IsAllowed(ADF_AuthTable table,
|
|||||||
case IPADDR_INET6:
|
case IPADDR_INET6:
|
||||||
split_ip6(ip_addr, ip6);
|
split_ip6(ip_addr, ip6);
|
||||||
return check_ip_in_node(&table->base6, ip6);
|
return check_ip_in_node(&table->base6, ip6);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
7
array.c
7
array.c
@@ -66,8 +66,6 @@ ARR_DestroyInstance(ARR_Instance array)
|
|||||||
static void
|
static void
|
||||||
realloc_array(ARR_Instance array, unsigned int min_size)
|
realloc_array(ARR_Instance array, unsigned int min_size)
|
||||||
{
|
{
|
||||||
size_t data_size;
|
|
||||||
|
|
||||||
assert(min_size <= 2 * min_size);
|
assert(min_size <= 2 * min_size);
|
||||||
if (array->allocated >= min_size && array->allocated <= 2 * min_size)
|
if (array->allocated >= min_size && array->allocated <= 2 * min_size)
|
||||||
return;
|
return;
|
||||||
@@ -79,10 +77,7 @@ realloc_array(ARR_Instance array, unsigned int min_size)
|
|||||||
array->allocated = min_size;
|
array->allocated = min_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
data_size = (size_t)array->elem_size * array->allocated;
|
array->data = Realloc2(array->data, array->allocated, array->elem_size);
|
||||||
assert(data_size / array->elem_size == array->allocated);
|
|
||||||
|
|
||||||
array->data = Realloc(array->data, data_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
|||||||
220
candm.h
220
candm.h
@@ -94,14 +94,29 @@
|
|||||||
#define REQ_SERVER_STATS 54
|
#define REQ_SERVER_STATS 54
|
||||||
#define REQ_CLIENT_ACCESSES_BY_INDEX2 55
|
#define REQ_CLIENT_ACCESSES_BY_INDEX2 55
|
||||||
#define REQ_LOCAL2 56
|
#define REQ_LOCAL2 56
|
||||||
#define N_REQUEST_TYPES 57
|
#define REQ_NTP_DATA 57
|
||||||
|
#define REQ_ADD_SERVER2 58
|
||||||
|
#define REQ_ADD_PEER2 59
|
||||||
|
#define REQ_ADD_SERVER3 60
|
||||||
|
#define REQ_ADD_PEER3 61
|
||||||
|
#define REQ_SHUTDOWN 62
|
||||||
|
#define REQ_ONOFFLINE 63
|
||||||
|
#define REQ_ADD_SOURCE 64
|
||||||
|
#define REQ_NTP_SOURCE_NAME 65
|
||||||
|
#define REQ_RESET_SOURCES 66
|
||||||
|
#define REQ_AUTH_DATA 67
|
||||||
|
#define REQ_CLIENT_ACCESSES_BY_INDEX3 68
|
||||||
|
#define REQ_SELECT_DATA 69
|
||||||
|
#define REQ_RELOAD_SOURCES 70
|
||||||
|
#define REQ_DOFFSET2 71
|
||||||
|
#define N_REQUEST_TYPES 72
|
||||||
|
|
||||||
/* Structure used to exchange timevals independent on size of time_t */
|
/* Structure used to exchange timespecs independent of time_t size */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t tv_sec_high;
|
uint32_t tv_sec_high;
|
||||||
uint32_t tv_sec_low;
|
uint32_t tv_sec_low;
|
||||||
uint32_t tv_nsec;
|
uint32_t tv_nsec;
|
||||||
} Timeval;
|
} Timespec;
|
||||||
|
|
||||||
/* This is used in tv_sec_high for 32-bit timestamps */
|
/* This is used in tv_sec_high for 32-bit timestamps */
|
||||||
#define TV_NOHIGHSEC 0x7fffffff
|
#define TV_NOHIGHSEC 0x7fffffff
|
||||||
@@ -200,12 +215,12 @@ typedef struct {
|
|||||||
} REQ_Modify_Makestep;
|
} REQ_Modify_Makestep;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Timeval ts;
|
Timespec ts;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_Logon;
|
} REQ_Logon;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Timeval ts;
|
Timespec ts;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_Settime;
|
} REQ_Settime;
|
||||||
|
|
||||||
@@ -238,6 +253,11 @@ typedef struct {
|
|||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_Ac_Check;
|
} REQ_Ac_Check;
|
||||||
|
|
||||||
|
/* Source types in NTP source requests */
|
||||||
|
#define REQ_ADDSRC_SERVER 1
|
||||||
|
#define REQ_ADDSRC_PEER 2
|
||||||
|
#define REQ_ADDSRC_POOL 3
|
||||||
|
|
||||||
/* Flags used in NTP source requests */
|
/* Flags used in NTP source requests */
|
||||||
#define REQ_ADDSRC_ONLINE 0x1
|
#define REQ_ADDSRC_ONLINE 0x1
|
||||||
#define REQ_ADDSRC_AUTOOFFLINE 0x2
|
#define REQ_ADDSRC_AUTOOFFLINE 0x2
|
||||||
@@ -246,17 +266,38 @@ typedef struct {
|
|||||||
#define REQ_ADDSRC_NOSELECT 0x10
|
#define REQ_ADDSRC_NOSELECT 0x10
|
||||||
#define REQ_ADDSRC_TRUST 0x20
|
#define REQ_ADDSRC_TRUST 0x20
|
||||||
#define REQ_ADDSRC_REQUIRE 0x40
|
#define REQ_ADDSRC_REQUIRE 0x40
|
||||||
|
#define REQ_ADDSRC_INTERLEAVED 0x80
|
||||||
|
#define REQ_ADDSRC_BURST 0x100
|
||||||
|
#define REQ_ADDSRC_NTS 0x200
|
||||||
|
#define REQ_ADDSRC_COPY 0x400
|
||||||
|
#define REQ_ADDSRC_EF_EXP1 0x800
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr;
|
uint32_t type;
|
||||||
|
uint8_t name[256];
|
||||||
uint32_t port;
|
uint32_t port;
|
||||||
int32_t minpoll;
|
int32_t minpoll;
|
||||||
int32_t maxpoll;
|
int32_t maxpoll;
|
||||||
int32_t presend_minpoll;
|
int32_t presend_minpoll;
|
||||||
|
uint32_t min_stratum;
|
||||||
|
uint32_t poll_target;
|
||||||
|
uint32_t version;
|
||||||
|
uint32_t max_sources;
|
||||||
|
int32_t min_samples;
|
||||||
|
int32_t max_samples;
|
||||||
uint32_t authkey;
|
uint32_t authkey;
|
||||||
|
uint32_t nts_port;
|
||||||
Float max_delay;
|
Float max_delay;
|
||||||
Float max_delay_ratio;
|
Float max_delay_ratio;
|
||||||
|
Float max_delay_dev_ratio;
|
||||||
|
Float min_delay;
|
||||||
|
Float asymmetry;
|
||||||
|
Float offset;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
int32_t filter_length;
|
||||||
|
uint32_t cert_set;
|
||||||
|
Float max_delay_quant;
|
||||||
|
uint32_t reserved[1];
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_NTP_Source;
|
} REQ_NTP_Source;
|
||||||
|
|
||||||
@@ -271,8 +312,7 @@ typedef struct {
|
|||||||
} REQ_Dfreq;
|
} REQ_Dfreq;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t sec;
|
Float doffset;
|
||||||
int32_t usec;
|
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_Doffset;
|
} REQ_Doffset;
|
||||||
|
|
||||||
@@ -288,6 +328,8 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t first_index;
|
uint32_t first_index;
|
||||||
uint32_t n_clients;
|
uint32_t n_clients;
|
||||||
|
uint32_t min_hits;
|
||||||
|
uint32_t reset;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_ClientAccessesByIndex;
|
} REQ_ClientAccessesByIndex;
|
||||||
|
|
||||||
@@ -309,6 +351,26 @@ typedef struct {
|
|||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_SmoothTime;
|
} REQ_SmoothTime;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
IPAddr ip_addr;
|
||||||
|
int32_t EOR;
|
||||||
|
} REQ_NTPData;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
IPAddr ip_addr;
|
||||||
|
int32_t EOR;
|
||||||
|
} REQ_NTPSourceName;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
IPAddr ip_addr;
|
||||||
|
int32_t EOR;
|
||||||
|
} REQ_AuthData;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t index;
|
||||||
|
int32_t EOR;
|
||||||
|
} REQ_SelectData;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
#define PKT_TYPE_CMD_REQUEST 1
|
#define PKT_TYPE_CMD_REQUEST 1
|
||||||
@@ -345,8 +407,10 @@ typedef struct {
|
|||||||
domain socket.
|
domain socket.
|
||||||
|
|
||||||
Version 6 (no authentication) : changed format of client accesses by index
|
Version 6 (no authentication) : changed format of client accesses by index
|
||||||
(using new request/reply types), new flags in NTP source request and report,
|
(two times), delta offset, and manual timestamp, added new fields and
|
||||||
new commands: refresh, serverstats
|
flags to NTP source request and report, made length of manual list constant,
|
||||||
|
added new commands: authdata, ntpdata, onoffline, refresh, reset,
|
||||||
|
selectdata, serverstats, shutdown, sourcename
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PROTO_VERSION_NUMBER 6
|
#define PROTO_VERSION_NUMBER 6
|
||||||
@@ -360,8 +424,8 @@ typedef struct {
|
|||||||
#define PROTO_VERSION_PADDING 6
|
#define PROTO_VERSION_PADDING 6
|
||||||
|
|
||||||
/* The maximum length of padding in request packet, currently
|
/* The maximum length of padding in request packet, currently
|
||||||
defined by MANUAL_LIST */
|
defined by CLIENT_ACCESSES_BY_INDEX3 */
|
||||||
#define MAX_PADDING_LENGTH 396
|
#define MAX_PADDING_LENGTH 484
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -409,6 +473,10 @@ typedef struct {
|
|||||||
REQ_ManualDelete manual_delete;
|
REQ_ManualDelete manual_delete;
|
||||||
REQ_ReselectDistance reselect_distance;
|
REQ_ReselectDistance reselect_distance;
|
||||||
REQ_SmoothTime smoothtime;
|
REQ_SmoothTime smoothtime;
|
||||||
|
REQ_NTPData ntp_data;
|
||||||
|
REQ_NTPSourceName ntp_source_name;
|
||||||
|
REQ_AuthData auth_data;
|
||||||
|
REQ_SelectData select_data;
|
||||||
} data; /* Command specific parameters */
|
} data; /* Command specific parameters */
|
||||||
|
|
||||||
/* Padding used to prevent traffic amplification. It only defines the
|
/* Padding used to prevent traffic amplification. It only defines the
|
||||||
@@ -442,7 +510,16 @@ typedef struct {
|
|||||||
#define RPY_SMOOTHING 13
|
#define RPY_SMOOTHING 13
|
||||||
#define RPY_SERVER_STATS 14
|
#define RPY_SERVER_STATS 14
|
||||||
#define RPY_CLIENT_ACCESSES_BY_INDEX2 15
|
#define RPY_CLIENT_ACCESSES_BY_INDEX2 15
|
||||||
#define N_REPLY_TYPES 16
|
#define RPY_NTP_DATA 16
|
||||||
|
#define RPY_MANUAL_TIMESTAMP2 17
|
||||||
|
#define RPY_MANUAL_LIST2 18
|
||||||
|
#define RPY_NTP_SOURCE_NAME 19
|
||||||
|
#define RPY_AUTH_DATA 20
|
||||||
|
#define RPY_CLIENT_ACCESSES_BY_INDEX3 21
|
||||||
|
#define RPY_SERVER_STATS2 22
|
||||||
|
#define RPY_SELECT_DATA 23
|
||||||
|
#define RPY_SERVER_STATS3 24
|
||||||
|
#define N_REPLY_TYPES 25
|
||||||
|
|
||||||
/* Status codes */
|
/* Status codes */
|
||||||
#define STT_SUCCESS 0
|
#define STT_SUCCESS 0
|
||||||
@@ -455,8 +532,7 @@ typedef struct {
|
|||||||
#define STT_BADSUBNET 7
|
#define STT_BADSUBNET 7
|
||||||
#define STT_ACCESSALLOWED 8
|
#define STT_ACCESSALLOWED 8
|
||||||
#define STT_ACCESSDENIED 9
|
#define STT_ACCESSDENIED 9
|
||||||
/* Deprecated */
|
#define STT_NOHOSTACCESS 10 /* Deprecated */
|
||||||
#define STT_NOHOSTACCESS 10
|
|
||||||
#define STT_SOURCEALREADYKNOWN 11
|
#define STT_SOURCEALREADYKNOWN 11
|
||||||
#define STT_TOOMANYSOURCES 12
|
#define STT_TOOMANYSOURCES 12
|
||||||
#define STT_NORTC 13
|
#define STT_NORTC 13
|
||||||
@@ -466,6 +542,7 @@ typedef struct {
|
|||||||
#define STT_INVALIDAF 17
|
#define STT_INVALIDAF 17
|
||||||
#define STT_BADPKTVERSION 18
|
#define STT_BADPKTVERSION 18
|
||||||
#define STT_BADPKTLENGTH 19
|
#define STT_BADPKTLENGTH 19
|
||||||
|
#define STT_INVALIDNAME 21
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
@@ -480,17 +557,12 @@ typedef struct {
|
|||||||
#define RPY_SD_MD_PEER 1
|
#define RPY_SD_MD_PEER 1
|
||||||
#define RPY_SD_MD_REF 2
|
#define RPY_SD_MD_REF 2
|
||||||
|
|
||||||
#define RPY_SD_ST_SYNC 0
|
#define RPY_SD_ST_SELECTED 0
|
||||||
#define RPY_SD_ST_UNREACH 1
|
#define RPY_SD_ST_NONSELECTABLE 1
|
||||||
#define RPY_SD_ST_FALSETICKER 2
|
#define RPY_SD_ST_FALSETICKER 2
|
||||||
#define RPY_SD_ST_JITTERY 3
|
#define RPY_SD_ST_JITTERY 3
|
||||||
#define RPY_SD_ST_CANDIDATE 4
|
#define RPY_SD_ST_UNSELECTED 4
|
||||||
#define RPY_SD_ST_OUTLIER 5
|
#define RPY_SD_ST_SELECTABLE 5
|
||||||
|
|
||||||
#define RPY_SD_FLAG_NOSELECT 0x1
|
|
||||||
#define RPY_SD_FLAG_PREFER 0x2
|
|
||||||
#define RPY_SD_FLAG_TRUST 0x4
|
|
||||||
#define RPY_SD_FLAG_REQUIRE 0x8
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
@@ -512,7 +584,7 @@ typedef struct {
|
|||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
uint16_t stratum;
|
uint16_t stratum;
|
||||||
uint16_t leap_status;
|
uint16_t leap_status;
|
||||||
Timeval ref_time;
|
Timespec ref_time;
|
||||||
Float current_correction;
|
Float current_correction;
|
||||||
Float last_offset;
|
Float last_offset;
|
||||||
Float rms_offset;
|
Float rms_offset;
|
||||||
@@ -540,7 +612,7 @@ typedef struct {
|
|||||||
} RPY_Sourcestats;
|
} RPY_Sourcestats;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Timeval ref_time;
|
Timespec ref_time;
|
||||||
uint16_t n_samples;
|
uint16_t n_samples;
|
||||||
uint16_t n_runs;
|
uint16_t n_runs;
|
||||||
uint32_t span_seconds;
|
uint32_t span_seconds;
|
||||||
@@ -550,7 +622,7 @@ typedef struct {
|
|||||||
} RPY_Rtc;
|
} RPY_Rtc;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t centiseconds;
|
Float offset;
|
||||||
Float dfreq_ppm;
|
Float dfreq_ppm;
|
||||||
Float new_afreq_ppm;
|
Float new_afreq_ppm;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
@@ -559,14 +631,17 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip;
|
IPAddr ip;
|
||||||
uint32_t ntp_hits;
|
uint32_t ntp_hits;
|
||||||
|
uint32_t nke_hits;
|
||||||
uint32_t cmd_hits;
|
uint32_t cmd_hits;
|
||||||
uint32_t ntp_drops;
|
uint32_t ntp_drops;
|
||||||
|
uint32_t nke_drops;
|
||||||
uint32_t cmd_drops;
|
uint32_t cmd_drops;
|
||||||
int8_t ntp_interval;
|
int8_t ntp_interval;
|
||||||
|
int8_t nke_interval;
|
||||||
int8_t cmd_interval;
|
int8_t cmd_interval;
|
||||||
int8_t ntp_timeout_interval;
|
int8_t ntp_timeout_interval;
|
||||||
int8_t pad;
|
|
||||||
uint32_t last_ntp_hit_ago;
|
uint32_t last_ntp_hit_ago;
|
||||||
|
uint32_t last_nke_hit_ago;
|
||||||
uint32_t last_cmd_hit_ago;
|
uint32_t last_cmd_hit_ago;
|
||||||
} RPY_ClientAccesses_Client;
|
} RPY_ClientAccesses_Client;
|
||||||
|
|
||||||
@@ -580,17 +655,23 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t ntp_hits;
|
uint32_t ntp_hits;
|
||||||
|
uint32_t nke_hits;
|
||||||
uint32_t cmd_hits;
|
uint32_t cmd_hits;
|
||||||
uint32_t ntp_drops;
|
uint32_t ntp_drops;
|
||||||
|
uint32_t nke_drops;
|
||||||
uint32_t cmd_drops;
|
uint32_t cmd_drops;
|
||||||
uint32_t log_drops;
|
uint32_t log_drops;
|
||||||
|
uint32_t ntp_auth_hits;
|
||||||
|
uint32_t ntp_interleaved_hits;
|
||||||
|
uint32_t ntp_timestamps;
|
||||||
|
uint32_t ntp_span_seconds;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} RPY_ServerStats;
|
} RPY_ServerStats;
|
||||||
|
|
||||||
#define MAX_MANUAL_LIST_SAMPLES 16
|
#define MAX_MANUAL_LIST_SAMPLES 16
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Timeval when;
|
Timespec when;
|
||||||
Float slewed_offset;
|
Float slewed_offset;
|
||||||
Float orig_offset;
|
Float orig_offset;
|
||||||
Float residual;
|
Float residual;
|
||||||
@@ -624,6 +705,83 @@ typedef struct {
|
|||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} RPY_Smoothing;
|
} RPY_Smoothing;
|
||||||
|
|
||||||
|
#define RPY_NTP_FLAGS_TESTS 0x3ff
|
||||||
|
#define RPY_NTP_FLAG_INTERLEAVED 0x4000
|
||||||
|
#define RPY_NTP_FLAG_AUTHENTICATED 0x8000
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
IPAddr remote_addr;
|
||||||
|
IPAddr local_addr;
|
||||||
|
uint16_t remote_port;
|
||||||
|
uint8_t leap;
|
||||||
|
uint8_t version;
|
||||||
|
uint8_t mode;
|
||||||
|
uint8_t stratum;
|
||||||
|
int8_t poll;
|
||||||
|
int8_t precision;
|
||||||
|
Float root_delay;
|
||||||
|
Float root_dispersion;
|
||||||
|
uint32_t ref_id;
|
||||||
|
Timespec ref_time;
|
||||||
|
Float offset;
|
||||||
|
Float peer_delay;
|
||||||
|
Float peer_dispersion;
|
||||||
|
Float response_time;
|
||||||
|
Float jitter_asymmetry;
|
||||||
|
uint16_t flags;
|
||||||
|
uint8_t tx_tss_char;
|
||||||
|
uint8_t rx_tss_char;
|
||||||
|
uint32_t total_tx_count;
|
||||||
|
uint32_t total_rx_count;
|
||||||
|
uint32_t total_valid_count;
|
||||||
|
uint32_t reserved[4];
|
||||||
|
int32_t EOR;
|
||||||
|
} RPY_NTPData;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t name[256];
|
||||||
|
int32_t EOR;
|
||||||
|
} RPY_NTPSourceName;
|
||||||
|
|
||||||
|
#define RPY_AD_MD_NONE 0
|
||||||
|
#define RPY_AD_MD_SYMMETRIC 1
|
||||||
|
#define RPY_AD_MD_NTS 2
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t mode;
|
||||||
|
uint16_t key_type;
|
||||||
|
uint32_t key_id;
|
||||||
|
uint16_t key_length;
|
||||||
|
uint16_t ke_attempts;
|
||||||
|
uint32_t last_ke_ago;
|
||||||
|
uint16_t cookies;
|
||||||
|
uint16_t cookie_length;
|
||||||
|
uint16_t nak;
|
||||||
|
uint16_t pad;
|
||||||
|
int32_t EOR;
|
||||||
|
} RPY_AuthData;
|
||||||
|
|
||||||
|
#define RPY_SD_OPTION_NOSELECT 0x1
|
||||||
|
#define RPY_SD_OPTION_PREFER 0x2
|
||||||
|
#define RPY_SD_OPTION_TRUST 0x4
|
||||||
|
#define RPY_SD_OPTION_REQUIRE 0x8
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t ref_id;
|
||||||
|
IPAddr ip_addr;
|
||||||
|
uint8_t state_char;
|
||||||
|
uint8_t authentication;
|
||||||
|
uint8_t leap;
|
||||||
|
uint8_t pad;
|
||||||
|
uint16_t conf_options;
|
||||||
|
uint16_t eff_options;
|
||||||
|
uint32_t last_sample_ago;
|
||||||
|
Float score;
|
||||||
|
Float lo_limit;
|
||||||
|
Float hi_limit;
|
||||||
|
int32_t EOR;
|
||||||
|
} RPY_SelectData;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
uint8_t pkt_type;
|
uint8_t pkt_type;
|
||||||
@@ -652,6 +810,10 @@ typedef struct {
|
|||||||
RPY_ManualList manual_list;
|
RPY_ManualList manual_list;
|
||||||
RPY_Activity activity;
|
RPY_Activity activity;
|
||||||
RPY_Smoothing smoothing;
|
RPY_Smoothing smoothing;
|
||||||
|
RPY_NTPData ntp_data;
|
||||||
|
RPY_NTPSourceName ntp_source_name;
|
||||||
|
RPY_AuthData auth_data;
|
||||||
|
RPY_SelectData select_data;
|
||||||
} data; /* Reply specific parameters */
|
} data; /* Reply specific parameters */
|
||||||
|
|
||||||
} CMD_Reply;
|
} CMD_Reply;
|
||||||
|
|||||||
750
clientlog.c
750
clientlog.c
File diff suppressed because it is too large
Load Diff
26
clientlog.h
26
clientlog.h
@@ -31,17 +31,33 @@
|
|||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CLG_NTP = 0,
|
||||||
|
CLG_NTSKE,
|
||||||
|
CLG_CMDMON,
|
||||||
|
} CLG_Service;
|
||||||
|
|
||||||
extern void CLG_Initialise(void);
|
extern void CLG_Initialise(void);
|
||||||
extern void CLG_Finalise(void);
|
extern void CLG_Finalise(void);
|
||||||
extern int CLG_LogNTPAccess(IPAddr *client, struct timeval *now);
|
extern int CLG_GetClientIndex(IPAddr *client);
|
||||||
extern int CLG_LogCommandAccess(IPAddr *client, struct timeval *now);
|
extern int CLG_LogServiceAccess(CLG_Service service, IPAddr *client, struct timespec *now);
|
||||||
extern int CLG_LimitNTPResponseRate(int index);
|
extern int CLG_LimitServiceRate(CLG_Service service, int index);
|
||||||
extern int CLG_LimitCommandResponseRate(int index);
|
extern void CLG_LogAuthNtpRequest(void);
|
||||||
|
extern int CLG_GetNtpMinPoll(void);
|
||||||
|
|
||||||
|
/* Functions to save and retrieve timestamps for server interleaved mode */
|
||||||
|
extern void CLG_SaveNtpTimestamps(NTP_int64 *rx_ts, struct timespec *tx_ts);
|
||||||
|
extern void CLG_UndoNtpTxTimestampSlew(NTP_int64 *rx_ts, struct timespec *tx_ts);
|
||||||
|
extern void CLG_UpdateNtpTxTimestamp(NTP_int64 *rx_ts, struct timespec *tx_ts);
|
||||||
|
extern int CLG_GetNtpTxTimestamp(NTP_int64 *rx_ts, struct timespec *tx_ts);
|
||||||
|
extern void CLG_DisableNtpTimestamps(NTP_int64 *rx_ts);
|
||||||
|
|
||||||
/* And some reporting functions, for use by chronyc. */
|
/* And some reporting functions, for use by chronyc. */
|
||||||
|
|
||||||
extern int CLG_GetNumberOfIndices(void);
|
extern int CLG_GetNumberOfIndices(void);
|
||||||
extern int CLG_GetClientAccessReportByIndex(int index, RPT_ClientAccessByIndex_Report *report, struct timeval *now);
|
extern int CLG_GetClientAccessReportByIndex(int index, int reset, uint32_t min_hits,
|
||||||
|
RPT_ClientAccessByIndex_Report *report,
|
||||||
|
struct timespec *now);
|
||||||
extern void CLG_GetServerStatsReport(RPT_ServerStatsReport *report);
|
extern void CLG_GetServerStatsReport(RPT_ServerStatsReport *report);
|
||||||
|
|
||||||
#endif /* GOT_CLIENTLOG_H */
|
#endif /* GOT_CLIENTLOG_H */
|
||||||
|
|||||||
48
cmac.h
Normal file
48
cmac.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2019
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for CMAC.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_CMAC_H
|
||||||
|
#define GOT_CMAC_H
|
||||||
|
|
||||||
|
/* Avoid overlapping with the hash enumeration */
|
||||||
|
typedef enum {
|
||||||
|
CMC_INVALID = 0,
|
||||||
|
CMC_AES128 = 13,
|
||||||
|
CMC_AES256 = 14,
|
||||||
|
} CMC_Algorithm;
|
||||||
|
|
||||||
|
typedef struct CMC_Instance_Record *CMC_Instance;
|
||||||
|
|
||||||
|
extern int CMC_GetKeyLength(CMC_Algorithm algorithm);
|
||||||
|
extern CMC_Instance CMC_CreateInstance(CMC_Algorithm algorithm, const unsigned char *key,
|
||||||
|
int length);
|
||||||
|
extern int CMC_Hash(CMC_Instance inst, const void *in, int in_len,
|
||||||
|
unsigned char *out, int out_len);
|
||||||
|
extern void CMC_DestroyInstance(CMC_Instance inst);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
189
cmac_gnutls.c
Normal file
189
cmac_gnutls.c
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2021
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
CMAC using the GnuTLS library
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <gnutls/crypto.h>
|
||||||
|
|
||||||
|
#include "cmac.h"
|
||||||
|
#include "hash.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
struct CMC_Instance_Record {
|
||||||
|
gnutls_mac_algorithm_t algorithm;
|
||||||
|
gnutls_hmac_hd_t mac;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int instance_counter = 0;
|
||||||
|
static int gnutls_initialised = 0;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_gnutls(void)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if (gnutls_initialised)
|
||||||
|
return;
|
||||||
|
|
||||||
|
r = gnutls_global_init();
|
||||||
|
if (r < 0)
|
||||||
|
LOG_FATAL("Could not initialise %s : %s", "gnutls", gnutls_strerror(r));
|
||||||
|
|
||||||
|
DEBUG_LOG("Initialised");
|
||||||
|
gnutls_initialised = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
deinit_gnutls(void)
|
||||||
|
{
|
||||||
|
assert(gnutls_initialised);
|
||||||
|
gnutls_global_deinit();
|
||||||
|
gnutls_initialised = 0;
|
||||||
|
DEBUG_LOG("Deinitialised");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static gnutls_mac_algorithm_t
|
||||||
|
get_mac_algorithm(CMC_Algorithm algorithm)
|
||||||
|
{
|
||||||
|
switch (algorithm) {
|
||||||
|
case CMC_AES128:
|
||||||
|
return GNUTLS_MAC_AES_CMAC_128;
|
||||||
|
case CMC_AES256:
|
||||||
|
return GNUTLS_MAC_AES_CMAC_256;
|
||||||
|
default:
|
||||||
|
return GNUTLS_MAC_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CMC_GetKeyLength(CMC_Algorithm algorithm)
|
||||||
|
{
|
||||||
|
gnutls_mac_algorithm_t malgo = get_mac_algorithm(algorithm);
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (malgo == GNUTLS_MAC_UNKNOWN)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
len = gnutls_hmac_get_key_size(malgo);
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
CMC_Instance
|
||||||
|
CMC_CreateInstance(CMC_Algorithm algorithm, const unsigned char *key, int length)
|
||||||
|
{
|
||||||
|
gnutls_hmac_hd_t handle;
|
||||||
|
CMC_Instance inst;
|
||||||
|
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if (instance_counter == 0)
|
||||||
|
init_gnutls();
|
||||||
|
|
||||||
|
if (length <= 0 || length != CMC_GetKeyLength(algorithm))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
r = gnutls_hmac_init(&handle, get_mac_algorithm(algorithm), key, length);
|
||||||
|
if (r < 0) {
|
||||||
|
DEBUG_LOG("Could not initialise %s : %s", "mac", gnutls_strerror(r));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst = MallocNew(struct CMC_Instance_Record);
|
||||||
|
inst->algorithm = get_mac_algorithm(algorithm);
|
||||||
|
inst->mac = handle;
|
||||||
|
|
||||||
|
instance_counter++;
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (instance_counter == 0)
|
||||||
|
deinit_gnutls();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CMC_Hash(CMC_Instance inst, const void *in, int in_len, unsigned char *out, int out_len)
|
||||||
|
{
|
||||||
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
|
int hash_len;
|
||||||
|
|
||||||
|
if (in_len < 0 || out_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
hash_len = gnutls_hmac_get_len(inst->algorithm);
|
||||||
|
|
||||||
|
if (out_len > hash_len)
|
||||||
|
out_len = hash_len;
|
||||||
|
|
||||||
|
if (hash_len > sizeof (buf))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (gnutls_hmac(inst->mac, in, in_len) < 0) {
|
||||||
|
/* Reset the state */
|
||||||
|
gnutls_hmac_output(inst->mac, buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gnutls_hmac_output(inst->mac, buf);
|
||||||
|
memcpy(out, buf, out_len);
|
||||||
|
|
||||||
|
return out_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
CMC_DestroyInstance(CMC_Instance inst)
|
||||||
|
{
|
||||||
|
gnutls_hmac_deinit(inst->mac, NULL);
|
||||||
|
Free(inst);
|
||||||
|
|
||||||
|
instance_counter--;
|
||||||
|
if (instance_counter == 0)
|
||||||
|
deinit_gnutls();
|
||||||
|
}
|
||||||
117
cmac_nettle.c
Normal file
117
cmac_nettle.c
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2019
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Support for AES128 and AES256 CMAC in Nettle.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <nettle/cmac.h>
|
||||||
|
|
||||||
|
#include "cmac.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
struct CMC_Instance_Record {
|
||||||
|
int key_length;
|
||||||
|
union {
|
||||||
|
struct cmac_aes128_ctx aes128;
|
||||||
|
struct cmac_aes256_ctx aes256;
|
||||||
|
} context;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CMC_GetKeyLength(CMC_Algorithm algorithm)
|
||||||
|
{
|
||||||
|
if (algorithm == CMC_AES128)
|
||||||
|
return AES128_KEY_SIZE;
|
||||||
|
else if (algorithm == CMC_AES256)
|
||||||
|
return AES256_KEY_SIZE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
CMC_Instance
|
||||||
|
CMC_CreateInstance(CMC_Algorithm algorithm, const unsigned char *key, int length)
|
||||||
|
{
|
||||||
|
CMC_Instance inst;
|
||||||
|
|
||||||
|
if (length <= 0 || length != CMC_GetKeyLength(algorithm))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
inst = MallocNew(struct CMC_Instance_Record);
|
||||||
|
inst->key_length = length;
|
||||||
|
|
||||||
|
switch (length) {
|
||||||
|
case AES128_KEY_SIZE:
|
||||||
|
cmac_aes128_set_key(&inst->context.aes128, key);
|
||||||
|
break;
|
||||||
|
case AES256_KEY_SIZE:
|
||||||
|
cmac_aes256_set_key(&inst->context.aes256, key);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CMC_Hash(CMC_Instance inst, const void *in, int in_len, unsigned char *out, int out_len)
|
||||||
|
{
|
||||||
|
if (in_len < 0 || out_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (out_len > CMAC128_DIGEST_SIZE)
|
||||||
|
out_len = CMAC128_DIGEST_SIZE;
|
||||||
|
|
||||||
|
switch (inst->key_length) {
|
||||||
|
case AES128_KEY_SIZE:
|
||||||
|
cmac_aes128_update(&inst->context.aes128, in_len, in);
|
||||||
|
cmac_aes128_digest(&inst->context.aes128, out_len, out);
|
||||||
|
break;
|
||||||
|
case AES256_KEY_SIZE:
|
||||||
|
cmac_aes256_update(&inst->context.aes256, in_len, in);
|
||||||
|
cmac_aes256_digest(&inst->context.aes256, out_len, out);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
CMC_DestroyInstance(CMC_Instance inst)
|
||||||
|
{
|
||||||
|
Free(inst);
|
||||||
|
}
|
||||||
2
cmdmon.h
2
cmdmon.h
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
|
||||||
extern void CAM_Initialise(int family);
|
extern void CAM_Initialise(void);
|
||||||
|
|
||||||
extern void CAM_Finalise(void);
|
extern void CAM_Finalise(void);
|
||||||
|
|
||||||
|
|||||||
436
cmdparse.c
436
cmdparse.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2013-2014, 2016
|
* Copyright (C) Miroslav Lichvar 2013-2014, 2016, 2021
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -39,186 +39,239 @@
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
CPS_Status
|
int
|
||||||
CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
{
|
{
|
||||||
char *hostname, *cmd;
|
char *hostname, *cmd;
|
||||||
int n, done;
|
uint32_t ef_type;
|
||||||
CPS_Status result;
|
int n;
|
||||||
|
|
||||||
src->port = SRC_DEFAULT_PORT;
|
src->port = SRC_DEFAULT_PORT;
|
||||||
src->params.minpoll = SRC_DEFAULT_MINPOLL;
|
src->params.minpoll = SRC_DEFAULT_MINPOLL;
|
||||||
src->params.maxpoll = SRC_DEFAULT_MAXPOLL;
|
src->params.maxpoll = SRC_DEFAULT_MAXPOLL;
|
||||||
src->params.presend_minpoll = SRC_DEFAULT_PRESEND_MINPOLL;
|
src->params.connectivity = SRC_ONLINE;
|
||||||
src->params.authkey = INACTIVE_AUTHKEY;
|
|
||||||
src->params.max_delay = SRC_DEFAULT_MAXDELAY;
|
|
||||||
src->params.max_delay_ratio = SRC_DEFAULT_MAXDELAYRATIO;
|
|
||||||
src->params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO;
|
|
||||||
src->params.online = 1;
|
|
||||||
src->params.auto_offline = 0;
|
src->params.auto_offline = 0;
|
||||||
|
src->params.presend_minpoll = SRC_DEFAULT_PRESEND_MINPOLL;
|
||||||
|
src->params.burst = 0;
|
||||||
src->params.iburst = 0;
|
src->params.iburst = 0;
|
||||||
src->params.min_stratum = SRC_DEFAULT_MINSTRATUM;
|
src->params.min_stratum = SRC_DEFAULT_MINSTRATUM;
|
||||||
src->params.poll_target = SRC_DEFAULT_POLLTARGET;
|
src->params.poll_target = SRC_DEFAULT_POLLTARGET;
|
||||||
src->params.version = NTP_VERSION;
|
src->params.version = 0;
|
||||||
src->params.max_sources = SRC_DEFAULT_MAXSOURCES;
|
src->params.max_sources = SRC_DEFAULT_MAXSOURCES;
|
||||||
src->params.min_samples = SRC_DEFAULT_MINSAMPLES;
|
src->params.min_samples = SRC_DEFAULT_MINSAMPLES;
|
||||||
src->params.max_samples = SRC_DEFAULT_MAXSAMPLES;
|
src->params.max_samples = SRC_DEFAULT_MAXSAMPLES;
|
||||||
|
src->params.filter_length = 0;
|
||||||
|
src->params.interleaved = 0;
|
||||||
src->params.sel_options = 0;
|
src->params.sel_options = 0;
|
||||||
|
src->params.nts = 0;
|
||||||
|
src->params.nts_port = SRC_DEFAULT_NTSPORT;
|
||||||
|
src->params.copy = 0;
|
||||||
|
src->params.ext_fields = 0;
|
||||||
|
src->params.authkey = INACTIVE_AUTHKEY;
|
||||||
|
src->params.cert_set = SRC_DEFAULT_CERTSET;
|
||||||
|
src->params.max_delay = SRC_DEFAULT_MAXDELAY;
|
||||||
|
src->params.max_delay_ratio = SRC_DEFAULT_MAXDELAYRATIO;
|
||||||
|
src->params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO;
|
||||||
|
src->params.max_delay_quant = 0.0;
|
||||||
|
src->params.min_delay = 0.0;
|
||||||
|
src->params.asymmetry = SRC_DEFAULT_ASYMMETRY;
|
||||||
|
src->params.offset = 0.0;
|
||||||
|
|
||||||
result = CPS_Success;
|
|
||||||
|
|
||||||
hostname = line;
|
hostname = line;
|
||||||
line = CPS_SplitWord(line);
|
line = CPS_SplitWord(line);
|
||||||
|
|
||||||
if (!*hostname) {
|
if (!*hostname)
|
||||||
result = CPS_BadHost;
|
return 0;
|
||||||
} else {
|
|
||||||
src->name = hostname;
|
|
||||||
|
|
||||||
/* Parse subfields */
|
src->name = hostname;
|
||||||
done = 0;
|
|
||||||
do {
|
|
||||||
cmd = line;
|
|
||||||
line = CPS_SplitWord(line);
|
|
||||||
|
|
||||||
if (*cmd) {
|
/* Parse options */
|
||||||
if (!strcasecmp(cmd, "port")) {
|
for (; *line; line += n) {
|
||||||
if (sscanf(line, "%hu%n", &src->port, &n) != 1) {
|
cmd = line;
|
||||||
result = CPS_BadPort;
|
line = CPS_SplitWord(line);
|
||||||
done = 1;
|
n = 0;
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "minpoll")) {
|
|
||||||
if (sscanf(line, "%d%n", &src->params.minpoll, &n) != 1) {
|
|
||||||
result = CPS_BadMinpoll;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "maxpoll")) {
|
|
||||||
if (sscanf(line, "%d%n", &src->params.maxpoll, &n) != 1) {
|
|
||||||
result = CPS_BadMaxpoll;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "presend")) {
|
|
||||||
if (sscanf(line, "%d%n", &src->params.presend_minpoll, &n) != 1) {
|
|
||||||
result = CPS_BadPresend;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "maxdelaydevratio")) {
|
|
||||||
if (sscanf(line, "%lf%n", &src->params.max_delay_dev_ratio, &n) != 1) {
|
|
||||||
result = CPS_BadMaxdelaydevratio;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "maxdelayratio")) {
|
|
||||||
if (sscanf(line, "%lf%n", &src->params.max_delay_ratio, &n) != 1) {
|
|
||||||
result = CPS_BadMaxdelayratio;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "maxdelay")) {
|
|
||||||
if (sscanf(line, "%lf%n", &src->params.max_delay, &n) != 1) {
|
|
||||||
result = CPS_BadMaxdelay;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "key")) {
|
|
||||||
if (sscanf(line, "%"SCNu32"%n", &src->params.authkey, &n) != 1 ||
|
|
||||||
src->params.authkey == INACTIVE_AUTHKEY) {
|
|
||||||
result = CPS_BadKey;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(cmd, "offline")) {
|
|
||||||
src->params.online = 0;
|
|
||||||
|
|
||||||
} else if (!strcasecmp(cmd, "auto_offline")) {
|
if (!strcasecmp(cmd, "auto_offline")) {
|
||||||
src->params.auto_offline = 1;
|
src->params.auto_offline = 1;
|
||||||
|
} else if (!strcasecmp(cmd, "burst")) {
|
||||||
} else if (!strcasecmp(cmd, "iburst")) {
|
src->params.burst = 1;
|
||||||
src->params.iburst = 1;
|
} else if (!strcasecmp(cmd, "copy")) {
|
||||||
|
src->params.copy = 1;
|
||||||
} else if (!strcasecmp(cmd, "minstratum")) {
|
} else if (!strcasecmp(cmd, "iburst")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1) {
|
src->params.iburst = 1;
|
||||||
result = CPS_BadMinstratum;
|
} else if (!strcasecmp(cmd, "offline")) {
|
||||||
done = 1;
|
src->params.connectivity = SRC_OFFLINE;
|
||||||
} else {
|
} else if (!strcasecmp(cmd, "noselect")) {
|
||||||
line += n;
|
src->params.sel_options |= SRC_SELECT_NOSELECT;
|
||||||
}
|
} else if (!strcasecmp(cmd, "prefer")) {
|
||||||
|
src->params.sel_options |= SRC_SELECT_PREFER;
|
||||||
} else if (!strcasecmp(cmd, "polltarget")) {
|
} else if (!strcasecmp(cmd, "require")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.poll_target, &n) != 1) {
|
src->params.sel_options |= SRC_SELECT_REQUIRE;
|
||||||
result = CPS_BadPolltarget;
|
} else if (!strcasecmp(cmd, "trust")) {
|
||||||
done = 1;
|
src->params.sel_options |= SRC_SELECT_TRUST;
|
||||||
} else {
|
} else if (!strcasecmp(cmd, "certset")) {
|
||||||
line += n;
|
if (sscanf(line, "%"SCNu32"%n", &src->params.cert_set, &n) != 1)
|
||||||
}
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "key")) {
|
||||||
} else if (!strcasecmp(cmd, "noselect")) {
|
if (sscanf(line, "%"SCNu32"%n", &src->params.authkey, &n) != 1 ||
|
||||||
src->params.sel_options |= SRC_SELECT_NOSELECT;
|
src->params.authkey == INACTIVE_AUTHKEY)
|
||||||
|
return 0;
|
||||||
} else if (!strcasecmp(cmd, "prefer")) {
|
} else if (!strcasecmp(cmd, "asymmetry")) {
|
||||||
src->params.sel_options |= SRC_SELECT_PREFER;
|
if (sscanf(line, "%lf%n", &src->params.asymmetry, &n) != 1)
|
||||||
|
return 0;
|
||||||
} else if (!strcasecmp(cmd, "trust")) {
|
} else if (!strcasecmp(cmd, "extfield")) {
|
||||||
src->params.sel_options |= SRC_SELECT_TRUST;
|
if (sscanf(line, "%"SCNx32"%n", &ef_type, &n) != 1)
|
||||||
|
return 0;
|
||||||
} else if (!strcasecmp(cmd, "require")) {
|
switch (ef_type) {
|
||||||
src->params.sel_options |= SRC_SELECT_REQUIRE;
|
case NTP_EF_EXP1:
|
||||||
|
src->params.ext_fields |= NTP_EF_FLAG_EXP1;
|
||||||
} else if (!strcasecmp(cmd, "version")) {
|
break;
|
||||||
if (sscanf(line, "%d%n", &src->params.version, &n) != 1) {
|
default:
|
||||||
result = CPS_BadVersion;
|
return 0;
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!strcasecmp(cmd, "maxsources")) {
|
|
||||||
if (sscanf(line, "%d%n", &src->params.max_sources, &n) != 1) {
|
|
||||||
result = CPS_BadMaxsources;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!strcasecmp(cmd, "minsamples")) {
|
|
||||||
if (sscanf(line, "%d%n", &src->params.min_samples, &n) != 1) {
|
|
||||||
result = CPS_BadMinsamples;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!strcasecmp(cmd, "maxsamples")) {
|
|
||||||
if (sscanf(line, "%d%n", &src->params.max_samples, &n) != 1) {
|
|
||||||
result = CPS_BadMaxsamples;
|
|
||||||
done = 1;
|
|
||||||
} else {
|
|
||||||
line += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result = CPS_BadOption;
|
|
||||||
done = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
done = 1;
|
|
||||||
}
|
}
|
||||||
} while (!done);
|
} else if (!strcasecmp(cmd, "filter")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.filter_length, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxdelay")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.max_delay, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxdelayratio")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.max_delay_ratio, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxdelaydevratio")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.max_delay_dev_ratio, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxdelayquant")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.max_delay_quant, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxpoll")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.maxpoll, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxsamples")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.max_samples, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "maxsources")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.max_sources, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "mindelay")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.min_delay, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "minpoll")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.minpoll, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "minsamples")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.min_samples, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "minstratum")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "nts")) {
|
||||||
|
src->params.nts = 1;
|
||||||
|
} else if (!strcasecmp(cmd, "ntsport")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.nts_port, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "offset")) {
|
||||||
|
if (sscanf(line, "%lf%n", &src->params.offset, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "port")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->port, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "polltarget")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.poll_target, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "presend")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.presend_minpoll, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "version")) {
|
||||||
|
if (sscanf(line, "%d%n", &src->params.version, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "xleave")) {
|
||||||
|
src->params.interleaved = 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CPS_ParseAllowDeny(char *line, int *all, IPAddr *ip, int *subnet_bits)
|
||||||
|
{
|
||||||
|
char *p, *net, *slash;
|
||||||
|
uint32_t a, b, c;
|
||||||
|
int bits, len, n;
|
||||||
|
|
||||||
|
p = CPS_SplitWord(line);
|
||||||
|
|
||||||
|
if (strcmp(line, "all") == 0) {
|
||||||
|
*all = 1;
|
||||||
|
net = p;
|
||||||
|
p = CPS_SplitWord(p);
|
||||||
|
} else {
|
||||||
|
*all = 0;
|
||||||
|
net = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure there are no other arguments */
|
||||||
|
if (*p)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* No specified address or network means all IPv4 and IPv6 addresses */
|
||||||
|
if (!*net) {
|
||||||
|
ip->family = IPADDR_UNSPEC;
|
||||||
|
*subnet_bits = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
slash = strchr(net, '/');
|
||||||
|
if (slash) {
|
||||||
|
if (sscanf(slash + 1, "%d%n", &bits, &len) != 1 || slash[len + 1] || bits < 0)
|
||||||
|
return 0;
|
||||||
|
*slash = '\0';
|
||||||
|
} else {
|
||||||
|
bits = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UTI_StringToIP(net, ip)) {
|
||||||
|
if (bits >= 0)
|
||||||
|
*subnet_bits = bits;
|
||||||
|
else
|
||||||
|
*subnet_bits = ip->family == IPADDR_INET6 ? 128 : 32;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for a shortened IPv4 network notation using only 1, 2, or 3 decimal
|
||||||
|
numbers. This is different than the numbers-and-dots notation accepted
|
||||||
|
by inet_aton()! */
|
||||||
|
|
||||||
|
a = b = c = 0;
|
||||||
|
n = sscanf(net, "%"PRIu32"%n.%"PRIu32"%n.%"PRIu32"%n", &a, &len, &b, &len, &c, &len);
|
||||||
|
|
||||||
|
if (n > 0 && !net[len]) {
|
||||||
|
if (a > 255 || b > 255 || c > 255)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ip->family = IPADDR_INET4;
|
||||||
|
ip->addr.in4 = (a << 24) | (b << 16) | (c << 8);
|
||||||
|
|
||||||
|
if (bits >= 0)
|
||||||
|
*subnet_bits = bits;
|
||||||
|
else
|
||||||
|
*subnet_bits = n * 8;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The last possibility is a hostname */
|
||||||
|
if (bits < 0 && DNS_Name2IPAddress(net, ip, 1) == DNS_Success) {
|
||||||
|
*subnet_bits = ip->family == IPADDR_INET6 ? 128 : 32;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -256,71 +309,6 @@ CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
void
|
|
||||||
CPS_StatusToString(CPS_Status status, char *dest, int len)
|
|
||||||
{
|
|
||||||
const char *s = NULL;
|
|
||||||
|
|
||||||
if (len > 0)
|
|
||||||
dest[0] = '\0';
|
|
||||||
|
|
||||||
switch (status) {
|
|
||||||
case CPS_Success:
|
|
||||||
return;
|
|
||||||
case CPS_BadOption:
|
|
||||||
s = "server/peer/pool option";
|
|
||||||
break;
|
|
||||||
case CPS_BadHost:
|
|
||||||
s = "address";
|
|
||||||
break;
|
|
||||||
case CPS_BadPort:
|
|
||||||
s = "port";
|
|
||||||
break;
|
|
||||||
case CPS_BadMinpoll:
|
|
||||||
s = "minpoll";
|
|
||||||
break;
|
|
||||||
case CPS_BadMaxpoll:
|
|
||||||
s = "maxpoll";
|
|
||||||
break;
|
|
||||||
case CPS_BadPresend:
|
|
||||||
s = "presend";
|
|
||||||
break;
|
|
||||||
case CPS_BadMaxdelaydevratio:
|
|
||||||
s = "maxdelaydevratio";
|
|
||||||
break;
|
|
||||||
case CPS_BadMaxdelayratio:
|
|
||||||
s = "maxdelayratio";
|
|
||||||
break;
|
|
||||||
case CPS_BadMaxdelay:
|
|
||||||
s = "maxdelay";
|
|
||||||
break;
|
|
||||||
case CPS_BadKey:
|
|
||||||
s = "key";
|
|
||||||
break;
|
|
||||||
case CPS_BadMinstratum:
|
|
||||||
s = "minstratum";
|
|
||||||
break;
|
|
||||||
case CPS_BadPolltarget:
|
|
||||||
s = "polltarget";
|
|
||||||
break;
|
|
||||||
case CPS_BadVersion:
|
|
||||||
s = "version";
|
|
||||||
break;
|
|
||||||
case CPS_BadMaxsources:
|
|
||||||
s = "maxsources";
|
|
||||||
break;
|
|
||||||
case CPS_BadMinsamples:
|
|
||||||
s = "minsamples";
|
|
||||||
break;
|
|
||||||
case CPS_BadMaxsamples:
|
|
||||||
s = "maxsamples";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(dest, len, "Invalid %s", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -382,7 +370,7 @@ CPS_SplitWord(char *line)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
CPS_ParseKey(char *line, uint32_t *id, const char **hash, char **key)
|
CPS_ParseKey(char *line, uint32_t *id, const char **type, char **key)
|
||||||
{
|
{
|
||||||
char *s1, *s2, *s3, *s4;
|
char *s1, *s2, *s3, *s4;
|
||||||
|
|
||||||
@@ -399,10 +387,10 @@ CPS_ParseKey(char *line, uint32_t *id, const char **hash, char **key)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (*s3) {
|
if (*s3) {
|
||||||
*hash = s2;
|
*type = s2;
|
||||||
*key = s3;
|
*key = s3;
|
||||||
} else {
|
} else {
|
||||||
*hash = "MD5";
|
*type = "MD5";
|
||||||
*key = s2;
|
*key = s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
cmdparse.h
32
cmdparse.h
@@ -30,41 +30,21 @@
|
|||||||
#include "srcparams.h"
|
#include "srcparams.h"
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
CPS_Success,
|
|
||||||
CPS_BadOption,
|
|
||||||
CPS_BadHost,
|
|
||||||
CPS_BadPort,
|
|
||||||
CPS_BadMinpoll,
|
|
||||||
CPS_BadMaxpoll,
|
|
||||||
CPS_BadPresend,
|
|
||||||
CPS_BadMaxdelaydevratio,
|
|
||||||
CPS_BadMaxdelayratio,
|
|
||||||
CPS_BadMaxdelay,
|
|
||||||
CPS_BadKey,
|
|
||||||
CPS_BadMinstratum,
|
|
||||||
CPS_BadPolltarget,
|
|
||||||
CPS_BadVersion,
|
|
||||||
CPS_BadMaxsources,
|
|
||||||
CPS_BadMinsamples,
|
|
||||||
CPS_BadMaxsamples,
|
|
||||||
} CPS_Status;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
unsigned short port;
|
int port;
|
||||||
SourceParameters params;
|
SourceParameters params;
|
||||||
} CPS_NTP_Source;
|
} CPS_NTP_Source;
|
||||||
|
|
||||||
/* Parse a command to add an NTP server or peer */
|
/* Parse a command to add an NTP server or peer */
|
||||||
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
extern int CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
||||||
|
|
||||||
|
/* Parse a command to allow/deny access */
|
||||||
|
extern int CPS_ParseAllowDeny(char *line, int *all, IPAddr *ip, int *subnet_bits);
|
||||||
|
|
||||||
/* Parse a command to enable local reference */
|
/* Parse a command to enable local reference */
|
||||||
extern int CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance);
|
extern int CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance);
|
||||||
|
|
||||||
/* Get a string describing error status */
|
|
||||||
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
|
||||||
|
|
||||||
/* Remove extra white-space and comments */
|
/* Remove extra white-space and comments */
|
||||||
extern void CPS_NormalizeLine(char *line);
|
extern void CPS_NormalizeLine(char *line);
|
||||||
|
|
||||||
@@ -72,6 +52,6 @@ extern void CPS_NormalizeLine(char *line);
|
|||||||
extern char *CPS_SplitWord(char *line);
|
extern char *CPS_SplitWord(char *line);
|
||||||
|
|
||||||
/* Parse a key from keyfile */
|
/* Parse a key from keyfile */
|
||||||
extern int CPS_ParseKey(char *line, uint32_t *id, const char **hash, char **key);
|
extern int CPS_ParseKey(char *line, uint32_t *id, const char **type, char **key);
|
||||||
|
|
||||||
#endif /* GOT_CMDPARSE_H */
|
#endif /* GOT_CMDPARSE_H */
|
||||||
|
|||||||
56
conf.h
56
conf.h
@@ -30,10 +30,13 @@
|
|||||||
|
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
#include "reference.h"
|
#include "reference.h"
|
||||||
|
#include "sources.h"
|
||||||
|
|
||||||
extern void CNF_Initialise(int restarted);
|
extern void CNF_Initialise(int restarted, int client_only);
|
||||||
extern void CNF_Finalise(void);
|
extern void CNF_Finalise(void);
|
||||||
|
|
||||||
|
extern void CNF_EnablePrint(void);
|
||||||
|
|
||||||
extern char *CNF_GetRtcDevice(void);
|
extern char *CNF_GetRtcDevice(void);
|
||||||
|
|
||||||
extern void CNF_ReadFile(const char *filename);
|
extern void CNF_ReadFile(const char *filename);
|
||||||
@@ -46,13 +49,16 @@ extern void CNF_AddSources(void);
|
|||||||
extern void CNF_AddBroadcasts(void);
|
extern void CNF_AddBroadcasts(void);
|
||||||
extern void CNF_AddRefclocks(void);
|
extern void CNF_AddRefclocks(void);
|
||||||
|
|
||||||
|
extern void CNF_ReloadSources(void);
|
||||||
|
|
||||||
extern int CNF_GetAcquisitionPort(void);
|
extern int CNF_GetAcquisitionPort(void);
|
||||||
extern int CNF_GetNTPPort(void);
|
extern int CNF_GetNTPPort(void);
|
||||||
extern char *CNF_GetDriftFile(void);
|
extern char *CNF_GetDriftFile(void);
|
||||||
extern char *CNF_GetLogDir(void);
|
extern char *CNF_GetLogDir(void);
|
||||||
extern char *CNF_GetDumpDir(void);
|
extern char *CNF_GetDumpDir(void);
|
||||||
extern int CNF_GetLogBanner(void);
|
extern int CNF_GetLogBanner(void);
|
||||||
extern int CNF_GetLogMeasurements(void);
|
extern int CNF_GetLogMeasurements(int *raw);
|
||||||
|
extern int CNF_GetLogSelection(void);
|
||||||
extern int CNF_GetLogStatistics(void);
|
extern int CNF_GetLogStatistics(void);
|
||||||
extern int CNF_GetLogTracking(void);
|
extern int CNF_GetLogTracking(void);
|
||||||
extern int CNF_GetLogRtc(void);
|
extern int CNF_GetLogRtc(void);
|
||||||
@@ -60,7 +66,6 @@ extern int CNF_GetLogRefclocks(void);
|
|||||||
extern int CNF_GetLogTempComp(void);
|
extern int CNF_GetLogTempComp(void);
|
||||||
extern char *CNF_GetKeysFile(void);
|
extern char *CNF_GetKeysFile(void);
|
||||||
extern char *CNF_GetRtcFile(void);
|
extern char *CNF_GetRtcFile(void);
|
||||||
extern int CNF_GetDumpOnExit(void);
|
|
||||||
extern int CNF_GetManualEnabled(void);
|
extern int CNF_GetManualEnabled(void);
|
||||||
extern int CNF_GetCommandPort(void);
|
extern int CNF_GetCommandPort(void);
|
||||||
extern int CNF_GetRtcOnUtc(void);
|
extern int CNF_GetRtcOnUtc(void);
|
||||||
@@ -75,7 +80,12 @@ extern void CNF_GetFallbackDrifts(int *min, int *max);
|
|||||||
extern void CNF_GetBindAddress(int family, IPAddr *addr);
|
extern void CNF_GetBindAddress(int family, IPAddr *addr);
|
||||||
extern void CNF_GetBindAcquisitionAddress(int family, IPAddr *addr);
|
extern void CNF_GetBindAcquisitionAddress(int family, IPAddr *addr);
|
||||||
extern void CNF_GetBindCommandAddress(int family, IPAddr *addr);
|
extern void CNF_GetBindCommandAddress(int family, IPAddr *addr);
|
||||||
|
extern char *CNF_GetBindNtpInterface(void);
|
||||||
|
extern char *CNF_GetBindAcquisitionInterface(void);
|
||||||
|
extern char *CNF_GetBindCommandInterface(void);
|
||||||
extern char *CNF_GetBindCommandPath(void);
|
extern char *CNF_GetBindCommandPath(void);
|
||||||
|
extern int CNF_GetNtpDscp(void);
|
||||||
|
extern char *CNF_GetNtpSigndSocket(void);
|
||||||
extern char *CNF_GetPidFile(void);
|
extern char *CNF_GetPidFile(void);
|
||||||
extern REF_LeapMode CNF_GetLeapSecMode(void);
|
extern REF_LeapMode CNF_GetLeapSecMode(void);
|
||||||
extern char *CNF_GetLeapSecTimezone(void);
|
extern char *CNF_GetLeapSecTimezone(void);
|
||||||
@@ -86,8 +96,11 @@ extern double CNF_GetMaxClockError(void);
|
|||||||
extern double CNF_GetMaxDrift(void);
|
extern double CNF_GetMaxDrift(void);
|
||||||
extern double CNF_GetCorrectionTimeRatio(void);
|
extern double CNF_GetCorrectionTimeRatio(void);
|
||||||
extern double CNF_GetMaxSlewRate(void);
|
extern double CNF_GetMaxSlewRate(void);
|
||||||
|
extern double CNF_GetClockPrecision(void);
|
||||||
|
|
||||||
|
extern SRC_AuthSelectMode CNF_GetAuthSelectMode(void);
|
||||||
extern double CNF_GetMaxDistance(void);
|
extern double CNF_GetMaxDistance(void);
|
||||||
|
extern double CNF_GetMaxJitter(void);
|
||||||
extern double CNF_GetReselectDistance(void);
|
extern double CNF_GetReselectDistance(void);
|
||||||
extern double CNF_GetStratumWeight(void);
|
extern double CNF_GetStratumWeight(void);
|
||||||
extern double CNF_GetCombineLimit(void);
|
extern double CNF_GetCombineLimit(void);
|
||||||
@@ -100,6 +113,7 @@ extern int CNF_GetSchedPriority(void);
|
|||||||
extern int CNF_GetLockMemory(void);
|
extern int CNF_GetLockMemory(void);
|
||||||
|
|
||||||
extern int CNF_GetNTPRateLimit(int *interval, int *burst, int *leak);
|
extern int CNF_GetNTPRateLimit(int *interval, int *burst, int *leak);
|
||||||
|
extern int CNF_GetNtsRateLimit(int *interval, int *burst, int *leak);
|
||||||
extern int CNF_GetCommandRateLimit(int *interval, int *burst, int *leak);
|
extern int CNF_GetCommandRateLimit(int *interval, int *burst, int *leak);
|
||||||
extern void CNF_GetSmooth(double *max_freq, double *max_wander, int *leap_only);
|
extern void CNF_GetSmooth(double *max_freq, double *max_wander, int *leap_only);
|
||||||
extern void CNF_GetTempComp(char **file, double *interval, char **point_file, double *T0, double *k0, double *k1, double *k2);
|
extern void CNF_GetTempComp(char **file, double *interval, char **point_file, double *T0, double *k0, double *k1, double *k2);
|
||||||
@@ -117,4 +131,40 @@ extern char *CNF_GetHwclockFile(void);
|
|||||||
extern int CNF_GetInitSources(void);
|
extern int CNF_GetInitSources(void);
|
||||||
extern double CNF_GetInitStepThreshold(void);
|
extern double CNF_GetInitStepThreshold(void);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CNF_HWTS_RXFILTER_ANY,
|
||||||
|
CNF_HWTS_RXFILTER_NONE,
|
||||||
|
CNF_HWTS_RXFILTER_NTP,
|
||||||
|
CNF_HWTS_RXFILTER_PTP,
|
||||||
|
CNF_HWTS_RXFILTER_ALL,
|
||||||
|
} CNF_HwTs_RxFilter;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
int minpoll;
|
||||||
|
int min_samples;
|
||||||
|
int max_samples;
|
||||||
|
int nocrossts;
|
||||||
|
CNF_HwTs_RxFilter rxfilter;
|
||||||
|
double precision;
|
||||||
|
double tx_comp;
|
||||||
|
double rx_comp;
|
||||||
|
} CNF_HwTsInterface;
|
||||||
|
|
||||||
|
extern int CNF_GetHwTsInterface(unsigned int index, CNF_HwTsInterface **iface);
|
||||||
|
|
||||||
|
extern int CNF_GetPtpPort(void);
|
||||||
|
|
||||||
|
extern char *CNF_GetNtsDumpDir(void);
|
||||||
|
extern char *CNF_GetNtsNtpServer(void);
|
||||||
|
extern int CNF_GetNtsServerCertAndKeyFiles(const char ***certs, const char ***keys);
|
||||||
|
extern int CNF_GetNtsServerPort(void);
|
||||||
|
extern int CNF_GetNtsServerProcesses(void);
|
||||||
|
extern int CNF_GetNtsServerConnections(void);
|
||||||
|
extern int CNF_GetNtsRefresh(void);
|
||||||
|
extern int CNF_GetNtsRotate(void);
|
||||||
|
extern int CNF_GetNtsTrustedCertsPaths(const char ***paths, uint32_t **ids);
|
||||||
|
extern int CNF_GetNoSystemCert(void);
|
||||||
|
extern int CNF_GetNoCertTimeCheck(void);
|
||||||
|
|
||||||
#endif /* GOT_CONF_H */
|
#endif /* GOT_CONF_H */
|
||||||
|
|||||||
564
configure
vendored
564
configure
vendored
@@ -4,7 +4,9 @@
|
|||||||
# chronyd/chronyc - Programs for keeping computer clocks accurate.
|
# chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
#
|
#
|
||||||
# Copyright (C) Richard P. Curnow 1997-2003
|
# Copyright (C) Richard P. Curnow 1997-2003
|
||||||
# Copyright (C) Miroslav Lichvar 2009, 2012-2015
|
# Copyright (C) Bryan Christianson 2016
|
||||||
|
# Copyright (C) Miroslav Lichvar 2009, 2012-2021
|
||||||
|
# Copyright (C) Stefan R. Filipek 2019
|
||||||
#
|
#
|
||||||
# =======================================================================
|
# =======================================================================
|
||||||
|
|
||||||
@@ -24,19 +26,20 @@ test_code () {
|
|||||||
printf "%s" "Checking for $name : "
|
printf "%s" "Checking for $name : "
|
||||||
|
|
||||||
(
|
(
|
||||||
|
echo "#include \"config.h\""
|
||||||
for h in $headers; do
|
for h in $headers; do
|
||||||
echo "#include <$h>"
|
echo "#include <$h>"
|
||||||
done
|
done
|
||||||
echo "int main(int argc, char **argv) {"
|
echo "int main(int argc, char **argv) {"
|
||||||
echo "$code"
|
echo "$code"
|
||||||
echo "return 0; }"
|
echo "return 0; }"
|
||||||
) > docheck.c
|
) > conftest.c
|
||||||
|
|
||||||
echo "docheck.c:" >> config.log
|
echo "conftest.c:" >> config.log
|
||||||
cat docheck.c >> config.log
|
cat conftest.c >> config.log
|
||||||
echo $MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags \
|
echo $MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o conftest conftest.c $ldflags \
|
||||||
$MYLDFLAGS >> config.log
|
$MYLDFLAGS >> config.log
|
||||||
$MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags \
|
$MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o conftest conftest.c $ldflags \
|
||||||
$MYLDFLAGS >> config.log 2>&1
|
$MYLDFLAGS >> config.log 2>&1
|
||||||
|
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
||||||
@@ -47,11 +50,39 @@ test_code () {
|
|||||||
echo "No"
|
echo "No"
|
||||||
result=1
|
result=1
|
||||||
fi
|
fi
|
||||||
rm -f docheck.c docheck
|
rm -f conftest.c conftest
|
||||||
echo >> config.log
|
echo >> config.log
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
#}}}
|
#}}}
|
||||||
|
#{{{ test_executable
|
||||||
|
test_executable () {
|
||||||
|
name=$1
|
||||||
|
executable=$2
|
||||||
|
options=$3
|
||||||
|
|
||||||
|
printf "%s" "Checking for $name : "
|
||||||
|
|
||||||
|
echo $executable $options >> config.log
|
||||||
|
$executable $options >> config.log 2>&1
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "Yes"
|
||||||
|
result=0
|
||||||
|
else
|
||||||
|
echo "No"
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
|
echo >> config.log
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
#}}}
|
||||||
|
#{{{ pkg_config
|
||||||
|
pkg_config () {
|
||||||
|
$PKG_CONFIG "$@" 2>> config.log
|
||||||
|
}
|
||||||
|
#}}}
|
||||||
#{{{ usage
|
#{{{ usage
|
||||||
usage () {
|
usage () {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@@ -77,15 +108,13 @@ for instance \`--prefix=$HOME'.
|
|||||||
|
|
||||||
For better control, use the options below.
|
For better control, use the options below.
|
||||||
--disable-readline Disable line editing support
|
--disable-readline Disable line editing support
|
||||||
--without-readline Don't use GNU readline even if it is available
|
|
||||||
--without-editline Don't use editline even if it is available
|
--without-editline Don't use editline even if it is available
|
||||||
--readline-dir=DIR Specify parent of readline include and lib directories
|
|
||||||
--readline-inc-dir=DIR Specify where readline include directory is
|
|
||||||
--readline-lib-dir=DIR Specify where readline lib directory is
|
|
||||||
--with-ncurses-library=DIR Specify where ncurses lib directory is
|
|
||||||
--disable-sechash Disable support for hashes other than MD5
|
--disable-sechash Disable support for hashes other than MD5
|
||||||
|
--without-nettle Don't use nettle even if it is available
|
||||||
--without-nss Don't use NSS even if it is available
|
--without-nss Don't use NSS even if it is available
|
||||||
--without-tomcrypt Don't use libtomcrypt even if it is available
|
--without-tomcrypt Don't use libtomcrypt even if it is available
|
||||||
|
--disable-nts Disable NTS support
|
||||||
|
--without-gnutls Don't use gnutls even if it is available
|
||||||
--disable-cmdmon Disable command and monitoring support
|
--disable-cmdmon Disable command and monitoring support
|
||||||
--disable-ntp Disable NTP support
|
--disable-ntp Disable NTP support
|
||||||
--disable-refclock Disable reference clock support
|
--disable-refclock Disable reference clock support
|
||||||
@@ -99,10 +128,15 @@ For better control, use the options below.
|
|||||||
--without-seccomp Don't use seccomp even if it is available
|
--without-seccomp Don't use seccomp even if it is available
|
||||||
--disable-asyncdns Disable asynchronous name resolving
|
--disable-asyncdns Disable asynchronous name resolving
|
||||||
--disable-forcednsretry Don't retry on permanent DNS error
|
--disable-forcednsretry Don't retry on permanent DNS error
|
||||||
|
--without-clock-gettime Don't use clock_gettime() even if it is available
|
||||||
|
--disable-timestamping Disable support for SW/HW timestamping
|
||||||
|
--enable-ntp-signd Enable support for MS-SNTP authentication in Samba
|
||||||
--with-ntp-era=SECONDS Specify earliest assumed NTP time in seconds
|
--with-ntp-era=SECONDS Specify earliest assumed NTP time in seconds
|
||||||
since 1970-01-01 [50*365 days ago]
|
since 1970-01-01 [50*365 days ago]
|
||||||
--with-user=USER Specify default chronyd user [root]
|
--with-user=USER Specify default chronyd user [root]
|
||||||
--with-hwclockfile=PATH Specify default path to hwclock(8) adjtime file
|
--with-hwclockfile=PATH Specify default path to hwclock(8) adjtime file
|
||||||
|
--with-pidfile=PATH Specify default pidfile [/var/run/chrony/chronyd.pid]
|
||||||
|
--with-rtcdevice=PATH Specify default path to RTC device [/dev/rtc]
|
||||||
--with-sendmail=PATH Path to sendmail binary [/usr/lib/sendmail]
|
--with-sendmail=PATH Path to sendmail binary [/usr/lib/sendmail]
|
||||||
--enable-debug Enable debugging support
|
--enable-debug Enable debugging support
|
||||||
|
|
||||||
@@ -114,7 +148,7 @@ Fine tuning of the installation directories:
|
|||||||
--mandir=DIR man documentation [DATAROOTDIR/man]
|
--mandir=DIR man documentation [DATAROOTDIR/man]
|
||||||
--docdir=DIR documentation root [DATAROOTDIR/doc/chrony]
|
--docdir=DIR documentation root [DATAROOTDIR/doc/chrony]
|
||||||
--localstatedir=DIR modifiable single-machine data [/var]
|
--localstatedir=DIR modifiable single-machine data [/var]
|
||||||
--chronysockdir=DIR location for chrony sockets [LOCALSTATEDIR/run/chrony]
|
--chronyrundir=DIR location for chrony sockets [LOCALSTATEDIR/run/chrony]
|
||||||
--chronyvardir=DIR location for chrony data [LOCALSTATEDIR/lib/chrony]
|
--chronyvardir=DIR location for chrony data [LOCALSTATEDIR/lib/chrony]
|
||||||
|
|
||||||
Overriding system detection when cross-compiling:
|
Overriding system detection when cross-compiling:
|
||||||
@@ -129,6 +163,11 @@ Some influential environment variables:
|
|||||||
headers in a nonstandard directory <include dir>
|
headers in a nonstandard directory <include dir>
|
||||||
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
|
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
|
||||||
nonstandard directory <lib dir>
|
nonstandard directory <lib dir>
|
||||||
|
PKG_CONFIG path to pkg-config utility
|
||||||
|
PKG_CONFIG_PATH
|
||||||
|
directories to add to pkg-config's search path
|
||||||
|
PKG_CONFIG_LIBDIR
|
||||||
|
path overriding pkg-config's built-in search path
|
||||||
|
|
||||||
Use these variables to override the choices made by \`configure' or to help
|
Use these variables to override the choices made by \`configure' or to help
|
||||||
it to find libraries and programs with nonstandard names/locations.
|
it to find libraries and programs with nonstandard names/locations.
|
||||||
@@ -146,13 +185,6 @@ add_def () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#}}}
|
#}}}
|
||||||
#{{{ pkg_config
|
|
||||||
pkg_config () {
|
|
||||||
type pkg-config > /dev/null 2> /dev/null || return 1
|
|
||||||
|
|
||||||
pkg-config $@ 2> /dev/null
|
|
||||||
}
|
|
||||||
#}}}
|
|
||||||
#{{{ get_features
|
#{{{ get_features
|
||||||
get_features () {
|
get_features () {
|
||||||
ff=1
|
ff=1
|
||||||
@@ -178,22 +210,24 @@ OPERATINGSYSTEM=`uname -s`
|
|||||||
VERSION=`uname -r`
|
VERSION=`uname -r`
|
||||||
MACHINE=`uname -m`
|
MACHINE=`uname -m`
|
||||||
|
|
||||||
|
LIBS=""
|
||||||
EXTRA_LIBS=""
|
EXTRA_LIBS=""
|
||||||
EXTRA_CLI_LIBS=""
|
EXTRA_CLI_LIBS=""
|
||||||
EXTRA_OBJECTS=""
|
EXTRA_OBJECTS=""
|
||||||
EXTRA_DEFS=""
|
EXTRA_CLI_OBJECTS=""
|
||||||
SYSDEFS=""
|
|
||||||
|
|
||||||
feat_debug=0
|
feat_debug=0
|
||||||
feat_cmdmon=1
|
feat_cmdmon=1
|
||||||
feat_ntp=1
|
feat_ntp=1
|
||||||
feat_refclock=1
|
feat_refclock=1
|
||||||
feat_readline=1
|
feat_readline=1
|
||||||
try_readline=1
|
|
||||||
try_editline=1
|
try_editline=1
|
||||||
feat_sechash=1
|
feat_sechash=1
|
||||||
|
try_nettle=1
|
||||||
try_nss=1
|
try_nss=1
|
||||||
try_tomcrypt=1
|
try_tomcrypt=1
|
||||||
|
feat_nts=1
|
||||||
|
try_gnutls=1
|
||||||
feat_rtc=1
|
feat_rtc=1
|
||||||
try_rtc=0
|
try_rtc=0
|
||||||
feat_droproot=1
|
feat_droproot=1
|
||||||
@@ -202,9 +236,6 @@ try_clockctl=0
|
|||||||
feat_scfilter=0
|
feat_scfilter=0
|
||||||
try_seccomp=-1
|
try_seccomp=-1
|
||||||
priv_ops=""
|
priv_ops=""
|
||||||
readline_lib=""
|
|
||||||
readline_inc=""
|
|
||||||
ncurses_lib=""
|
|
||||||
feat_ipv6=1
|
feat_ipv6=1
|
||||||
feat_phc=1
|
feat_phc=1
|
||||||
try_phc=0
|
try_phc=0
|
||||||
@@ -213,9 +244,18 @@ try_setsched=0
|
|||||||
try_lockmem=0
|
try_lockmem=0
|
||||||
feat_asyncdns=1
|
feat_asyncdns=1
|
||||||
feat_forcednsretry=1
|
feat_forcednsretry=1
|
||||||
|
try_clock_gettime=1
|
||||||
|
try_arc4random=1
|
||||||
|
try_recvmmsg=1
|
||||||
|
feat_timestamping=1
|
||||||
|
try_timestamping=0
|
||||||
|
feat_ntp_signd=0
|
||||||
ntp_era_split=""
|
ntp_era_split=""
|
||||||
|
use_pthread=0
|
||||||
default_user="root"
|
default_user="root"
|
||||||
default_hwclockfile=""
|
default_hwclockfile=""
|
||||||
|
default_pidfile="/var/run/chrony/chronyd.pid"
|
||||||
|
default_rtcdevice="/dev/rtc"
|
||||||
mail_program="/usr/lib/sendmail"
|
mail_program="/usr/lib/sendmail"
|
||||||
|
|
||||||
for option
|
for option
|
||||||
@@ -227,21 +267,9 @@ do
|
|||||||
--disable-readline )
|
--disable-readline )
|
||||||
feat_readline=0
|
feat_readline=0
|
||||||
;;
|
;;
|
||||||
--without-readline )
|
|
||||||
try_readline=0
|
|
||||||
;;
|
|
||||||
--without-editline )
|
--without-editline )
|
||||||
try_editline=0
|
try_editline=0
|
||||||
;;
|
;;
|
||||||
--with-readline-library=* )
|
|
||||||
readline_lib=-L`echo $option | sed -e 's/^.*=//;'`
|
|
||||||
;;
|
|
||||||
--with-readline-includes=* )
|
|
||||||
readline_inc=-I`echo $option | sed -e 's/^.*=//;'`
|
|
||||||
;;
|
|
||||||
--with-ncurses-library=* )
|
|
||||||
ncurses_lib=-L`echo $option | sed -e 's/^.*=//;'`
|
|
||||||
;;
|
|
||||||
--prefix=* | --install_prefix=* )
|
--prefix=* | --install_prefix=* )
|
||||||
SETPREFIX=`echo $option | sed -e 's/[^=]*=//;'`
|
SETPREFIX=`echo $option | sed -e 's/[^=]*=//;'`
|
||||||
;;
|
;;
|
||||||
@@ -269,8 +297,8 @@ do
|
|||||||
--localstatedir=* )
|
--localstatedir=* )
|
||||||
SETLOCALSTATEDIR=`echo $option | sed -e 's/^.*=//;'`
|
SETLOCALSTATEDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
--chronysockdir=* )
|
--chronyrundir=* | --chronysockdir=* )
|
||||||
SETCHRONYSOCKDIR=`echo $option | sed -e 's/^.*=//;'`
|
SETCHRONYRUNDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
--chronyvardir=* )
|
--chronyvardir=* )
|
||||||
SETCHRONYVARDIR=`echo $option | sed -e 's/^.*=//;'`
|
SETCHRONYVARDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
@@ -317,6 +345,15 @@ do
|
|||||||
--disable-forcednsretry)
|
--disable-forcednsretry)
|
||||||
feat_forcednsretry=0
|
feat_forcednsretry=0
|
||||||
;;
|
;;
|
||||||
|
--without-clock-gettime)
|
||||||
|
try_clock_gettime=0
|
||||||
|
;;
|
||||||
|
--disable-timestamping)
|
||||||
|
feat_timestamping=0
|
||||||
|
;;
|
||||||
|
--enable-ntp-signd)
|
||||||
|
feat_ntp_signd=1
|
||||||
|
;;
|
||||||
--with-ntp-era=* )
|
--with-ntp-era=* )
|
||||||
ntp_era_split=`echo $option | sed -e 's/^.*=//;'`
|
ntp_era_split=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
@@ -326,18 +363,33 @@ do
|
|||||||
--with-hwclockfile=* )
|
--with-hwclockfile=* )
|
||||||
default_hwclockfile=`echo $option | sed -e 's/^.*=//;'`
|
default_hwclockfile=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
|
--with-pidfile=* )
|
||||||
|
default_pidfile=`echo $option | sed -e 's/^.*=//;'`
|
||||||
|
;;
|
||||||
|
--with-rtcdevice=* )
|
||||||
|
default_rtcdevice=`echo $option | sed -e 's/^.*=//;'`
|
||||||
|
;;
|
||||||
--with-sendmail=* )
|
--with-sendmail=* )
|
||||||
mail_program=`echo $option | sed -e 's/^.*=//;'`
|
mail_program=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
--disable-sechash )
|
--disable-sechash )
|
||||||
feat_sechash=0
|
feat_sechash=0
|
||||||
;;
|
;;
|
||||||
|
--without-nettle )
|
||||||
|
try_nettle=0
|
||||||
|
;;
|
||||||
--without-nss )
|
--without-nss )
|
||||||
try_nss=0
|
try_nss=0
|
||||||
;;
|
;;
|
||||||
--without-tomcrypt )
|
--without-tomcrypt )
|
||||||
try_tomcrypt=0
|
try_tomcrypt=0
|
||||||
;;
|
;;
|
||||||
|
--disable-nts )
|
||||||
|
feat_nts=0
|
||||||
|
;;
|
||||||
|
--without-gnutls )
|
||||||
|
try_gnutls=0
|
||||||
|
;;
|
||||||
--host-system=* )
|
--host-system=* )
|
||||||
OPERATINGSYSTEM=`echo $option | sed -e 's/^.*=//;'`
|
OPERATINGSYSTEM=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
@@ -362,18 +414,25 @@ SYSTEM=${OPERATINGSYSTEM}-${MACHINE}
|
|||||||
|
|
||||||
case $OPERATINGSYSTEM in
|
case $OPERATINGSYSTEM in
|
||||||
Linux)
|
Linux)
|
||||||
EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o"
|
EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o sys_posix.o"
|
||||||
[ $try_libcap != "0" ] && try_libcap=1
|
[ $try_libcap != "0" ] && try_libcap=1
|
||||||
try_rtc=1
|
try_rtc=1
|
||||||
[ $try_seccomp != "0" ] && try_seccomp=1
|
[ $try_seccomp != "0" ] && try_seccomp=1
|
||||||
|
try_timestamping=1
|
||||||
try_setsched=1
|
try_setsched=1
|
||||||
try_lockmem=1
|
try_lockmem=1
|
||||||
try_phc=1
|
try_phc=1
|
||||||
|
try_arc4random=0
|
||||||
add_def LINUX
|
add_def LINUX
|
||||||
echo "Configuring for " $SYSTEM
|
echo "Configuring for " $SYSTEM
|
||||||
;;
|
;;
|
||||||
FreeBSD)
|
FreeBSD)
|
||||||
EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o"
|
# recvmmsg() seems to be broken on FreeBSD 11.0 and it's just
|
||||||
|
# a wrapper around recvmsg()
|
||||||
|
try_recvmmsg=0
|
||||||
|
EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
|
||||||
|
try_setsched=1
|
||||||
|
try_lockmem=1
|
||||||
add_def FREEBSD
|
add_def FREEBSD
|
||||||
if [ $feat_droproot = "1" ]; then
|
if [ $feat_droproot = "1" ]; then
|
||||||
add_def FEAT_PRIVDROP
|
add_def FEAT_PRIVDROP
|
||||||
@@ -382,26 +441,37 @@ case $OPERATINGSYSTEM in
|
|||||||
echo "Configuring for $SYSTEM"
|
echo "Configuring for $SYSTEM"
|
||||||
;;
|
;;
|
||||||
NetBSD)
|
NetBSD)
|
||||||
EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o"
|
EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
|
||||||
try_clockctl=1
|
try_clockctl=1
|
||||||
|
try_setsched=1
|
||||||
|
try_lockmem=1
|
||||||
add_def NETBSD
|
add_def NETBSD
|
||||||
echo "Configuring for $SYSTEM"
|
echo "Configuring for $SYSTEM"
|
||||||
;;
|
;;
|
||||||
Darwin)
|
Darwin)
|
||||||
EXTRA_OBJECTS="sys_macosx.o"
|
EXTRA_OBJECTS="sys_macosx.o"
|
||||||
EXTRA_LIBS="-lresolv"
|
LIBS="$LIBS -lresolv"
|
||||||
EXTRA_CLI_LIBS="-lresolv"
|
|
||||||
add_def MACOSX
|
add_def MACOSX
|
||||||
if [ $feat_droproot = "1" ]; then
|
if [ $feat_droproot = "1" ]; then
|
||||||
add_def FEAT_PRIVDROP
|
add_def FEAT_PRIVDROP
|
||||||
priv_ops="ADJUSTTIME SETTIME BINDSOCKET"
|
priv_ops="ADJUSTTIME SETTIME BINDSOCKET"
|
||||||
fi
|
fi
|
||||||
echo "Configuring for MacOS X (" $SYSTEM "MacOS X version" $VERSION ")"
|
major=`echo $VERSION | cut -d. -f1`
|
||||||
|
# ntp_adjtime is not available in macOS 10.12 (Darwin 16.x.x) and earlier
|
||||||
|
if [ $major -gt "16" ]; then
|
||||||
|
add_def HAVE_MACOS_SYS_TIMEX
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS sys_generic.o sys_netbsd.o sys_timex.o"
|
||||||
|
if [ $feat_droproot = "1" ]; then
|
||||||
|
priv_ops="$priv_ops ADJUSTTIMEX"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "Configuring for macOS (" $SYSTEM "macOS version" $VERSION ")"
|
||||||
;;
|
;;
|
||||||
SunOS)
|
SunOS)
|
||||||
EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o"
|
EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o sys_posix.o"
|
||||||
EXTRA_LIBS="-lsocket -lnsl -lresolv"
|
LIBS="$LIBS -lsocket -lnsl -lkvm -lelf -lresolv"
|
||||||
EXTRA_CLI_LIBS="-lsocket -lnsl -lresolv"
|
try_setsched=1
|
||||||
|
try_lockmem=1
|
||||||
add_def SOLARIS
|
add_def SOLARIS
|
||||||
# These are needed to have msg_control in struct msghdr
|
# These are needed to have msg_control in struct msghdr
|
||||||
add_def __EXTENSIONS__
|
add_def __EXTENSIONS__
|
||||||
@@ -411,7 +481,7 @@ case $OPERATINGSYSTEM in
|
|||||||
add_def FEAT_PRIVDROP
|
add_def FEAT_PRIVDROP
|
||||||
priv_ops="ADJUSTTIMEX SETTIME BINDSOCKET"
|
priv_ops="ADJUSTTIMEX SETTIME BINDSOCKET"
|
||||||
fi
|
fi
|
||||||
echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
|
echo "Configuring for illumos (" $SYSTEM "SunOS version" $VERSION ")"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
echo "error: $SYSTEM is not supported (yet?)"
|
echo "error: $SYSTEM is not supported (yet?)"
|
||||||
@@ -431,9 +501,14 @@ fi
|
|||||||
|
|
||||||
if [ $feat_ntp = "1" ]; then
|
if [ $feat_ntp = "1" ]; then
|
||||||
add_def FEAT_NTP
|
add_def FEAT_NTP
|
||||||
EXTRA_OBJECTS="$EXTRA_OBJECTS ntp_core.o ntp_io.o ntp_sources.o"
|
EXTRA_OBJECTS="$EXTRA_OBJECTS ntp_auth.o ntp_core.o ntp_ext.o ntp_io.o ntp_sources.o"
|
||||||
|
if [ $feat_ntp_signd = "1" ]; then
|
||||||
|
add_def FEAT_SIGND
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS ntp_signd.o"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
feat_asyncdns=0
|
feat_asyncdns=0
|
||||||
|
feat_timestamping=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$feat_cmdmon" = "1" ] || [ $feat_ntp = "1" ]; then
|
if [ "$feat_cmdmon" = "1" ] || [ $feat_ntp = "1" ]; then
|
||||||
@@ -453,14 +528,16 @@ MYCPPFLAGS="$CPPFLAGS"
|
|||||||
MYLDFLAGS="$LDFLAGS"
|
MYLDFLAGS="$LDFLAGS"
|
||||||
|
|
||||||
if [ "x$MYCC" = "x" ]; then
|
if [ "x$MYCC" = "x" ]; then
|
||||||
MYCC=gcc
|
for cc in gcc clang cc ""; do
|
||||||
if ! test_code "$MYCC" '' '' '' ''; then
|
if [ "x$cc" = "x" ]; then
|
||||||
MYCC=cc
|
|
||||||
if ! test_code "$MYCC" '' '' '' ''; then
|
|
||||||
echo "error: no C compiler found"
|
echo "error: no C compiler found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
MYCC=$cc
|
||||||
|
if test_code "$MYCC" '' '' '' ''; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
else
|
else
|
||||||
if ! test_code "$MYCC" '' '' '' ''; then
|
if ! test_code "$MYCC" '' '' '' ''; then
|
||||||
echo "error: C compiler $MYCC cannot create executables"
|
echo "error: C compiler $MYCC cannot create executables"
|
||||||
@@ -470,12 +547,38 @@ fi
|
|||||||
|
|
||||||
if [ "x$MYCFLAGS" = "x" ]; then
|
if [ "x$MYCFLAGS" = "x" ]; then
|
||||||
MYCFLAGS="-O2 -g"
|
MYCFLAGS="-O2 -g"
|
||||||
|
|
||||||
|
TESTCFLAGS="-D_FORTIFY_SOURCE=2 -fPIE"
|
||||||
|
TESTLDFLAGS="-pie -Wl,-z,relro,-z,now"
|
||||||
|
if test_code 'hardening compiler options' '' "$TESTCFLAGS" "$TESTLDFLAGS" ''; then
|
||||||
|
MYCFLAGS="$MYCFLAGS $TESTCFLAGS"
|
||||||
|
MYLDFLAGS="$MYLDFLAGS $TESTLDFLAGS"
|
||||||
|
fi
|
||||||
|
TESTCFLAGS="-fstack-protector-strong --param=ssp-buffer-size=4"
|
||||||
|
if test_code '-fstack-protector-strong' '' "$TESTCFLAGS" '' ''; then
|
||||||
|
MYCFLAGS="$MYCFLAGS $TESTCFLAGS"
|
||||||
|
else
|
||||||
|
TESTCFLAGS="-fstack-protector --param=ssp-buffer-size=4"
|
||||||
|
if test_code '-fstack-protector' '' "$TESTCFLAGS" '' ''; then
|
||||||
|
MYCFLAGS="$MYCFLAGS $TESTCFLAGS"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$MYCC" = "xgcc" ]; then
|
if [ "x$MYCC" = "xgcc" ] || [ "x$MYCC" = "xclang" ]; then
|
||||||
MYCFLAGS="$MYCFLAGS -Wmissing-prototypes -Wall"
|
MYCFLAGS="$MYCFLAGS -Wmissing-prototypes -Wall"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "x$PKG_CONFIG" = "x" ]; then
|
||||||
|
PKG_CONFIG=pkg-config
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test_executable "pkg-config" $PKG_CONFIG --version; then
|
||||||
|
try_nettle=0
|
||||||
|
try_nss=0
|
||||||
|
try_gnutls=0
|
||||||
|
fi
|
||||||
|
|
||||||
if test_code '64-bit time_t' 'time.h' '' '' '
|
if test_code '64-bit time_t' 'time.h' '' '' '
|
||||||
char x[sizeof(time_t) > 4 ? 1 : -1] = {0};
|
char x[sizeof(time_t) > 4 ? 1 : -1] = {0};
|
||||||
return x[0];'
|
return x[0];'
|
||||||
@@ -486,7 +589,11 @@ then
|
|||||||
split_seconds=$ntp_era_split
|
split_seconds=$ntp_era_split
|
||||||
split_days=0
|
split_days=0
|
||||||
else
|
else
|
||||||
split_seconds=`date '+%s'`
|
if [ "x$SOURCE_DATE_EPOCH" != "x" ]; then
|
||||||
|
split_seconds=$SOURCE_DATE_EPOCH
|
||||||
|
else
|
||||||
|
split_seconds=`date '+%s'`
|
||||||
|
fi
|
||||||
if [ "x$split_seconds" = "x" ]; then
|
if [ "x$split_seconds" = "x" ]; then
|
||||||
echo "error: could not get current time, --with-ntp-era option is needed"
|
echo "error: could not get current time, --with-ntp-era option is needed"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -511,25 +618,15 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
MATHCODE='return (int) pow(2.0, log(sqrt((double)argc)));'
|
MATHCODE='return (int) pow(2.0, log(sqrt((double)argc)));'
|
||||||
if test_code 'math' 'math.h' '' '' "$MATHCODE"; then
|
if ! test_code 'math' 'math.h' '' '' "$MATHCODE"; then
|
||||||
LIBS=""
|
|
||||||
else
|
|
||||||
if test_code 'math in -lm' 'math.h' '' '-lm' "$MATHCODE"; then
|
if test_code 'math in -lm' 'math.h' '' '-lm' "$MATHCODE"; then
|
||||||
LIBS="-lm"
|
LIBS="$LIBS -lm"
|
||||||
else
|
else
|
||||||
echo "error: could not compile/link a program which uses sqrt(), log(), pow()"
|
echo "error: could not compile/link a program which uses sqrt(), log(), pow()"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test_code '<stdint.h>' 'stdint.h' '' '' ''; then
|
|
||||||
add_def HAVE_STDINT_H
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test_code '<inttypes.h>' 'inttypes.h' '' '' ''; then
|
|
||||||
add_def HAVE_INTTYPES_H
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test_code 'struct in_pktinfo' 'sys/socket.h netinet/in.h' '' '' '
|
if test_code 'struct in_pktinfo' 'sys/socket.h netinet/in.h' '' '' '
|
||||||
struct in_pktinfo ipi;
|
struct in_pktinfo ipi;
|
||||||
return sizeof (ipi.ipi_spec_dst.s_addr) + IP_PKTINFO;'
|
return sizeof (ipi.ipi_spec_dst.s_addr) + IP_PKTINFO;'
|
||||||
@@ -538,10 +635,11 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_ipv6 = "1" ] && \
|
if [ $feat_ipv6 = "1" ] && \
|
||||||
test_code 'IPv6 support' 'arpa/inet.h sys/socket.h netinet/in.h' '' "$EXTRA_LIBS" '
|
test_code 'IPv6 support' 'arpa/inet.h sys/socket.h netinet/in.h' '' "$LIBS" '
|
||||||
struct sockaddr_in6 n;
|
struct sockaddr_in6 n;
|
||||||
char p[100];
|
char p[100];
|
||||||
n.sin6_addr = in6addr_any;
|
n.sin6_addr = in6addr_any;
|
||||||
|
n.sin6_scope_id = 0;
|
||||||
return !inet_ntop(AF_INET6, &n.sin6_addr.s6_addr, p, sizeof(p));'
|
return !inet_ntop(AF_INET6, &n.sin6_addr.s6_addr, p, sizeof(p));'
|
||||||
then
|
then
|
||||||
add_def FEAT_IPV6
|
add_def FEAT_IPV6
|
||||||
@@ -559,33 +657,113 @@ then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$EXTRA_LIBS" \
|
if ! test_code 'O_NOFOLLOW flag' 'sys/types.h sys/stat.h fcntl.h' '' "$LIBS" \
|
||||||
|
'return open("/dev/null", O_NOFOLLOW);'
|
||||||
|
then
|
||||||
|
if test_code 'O_NOFOLLOW flag with _GNU_SOURCE' 'sys/types.h sys/stat.h fcntl.h' \
|
||||||
|
'-D_GNU_SOURCE' "$LIBS" \
|
||||||
|
'return open("/dev/null", O_NOFOLLOW);'
|
||||||
|
then
|
||||||
|
add_def _GNU_SOURCE
|
||||||
|
else
|
||||||
|
echo "error: open() does not support O_NOFOLLOW flag"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $try_clock_gettime = "1" ]; then
|
||||||
|
if test_code 'clock_gettime()' 'time.h' '' '' \
|
||||||
|
'clock_gettime(CLOCK_REALTIME, (void *)1);'
|
||||||
|
then
|
||||||
|
add_def HAVE_CLOCK_GETTIME
|
||||||
|
else
|
||||||
|
if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \
|
||||||
|
'clock_gettime(CLOCK_REALTIME, (void *)1);'
|
||||||
|
then
|
||||||
|
add_def HAVE_CLOCK_GETTIME
|
||||||
|
EXTRA_LIBS="$EXTRA_LIBS -lrt"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$LIBS" \
|
||||||
'return getaddrinfo(0, 0, 0, 0);'
|
'return getaddrinfo(0, 0, 0, 0);'
|
||||||
then
|
then
|
||||||
add_def HAVE_GETADDRINFO
|
echo "error: getaddrinfo() not found"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_asyncdns = "1" ] && \
|
if [ $feat_asyncdns = "1" ] && \
|
||||||
test_code 'pthread' 'pthread.h' '-pthread' '' \
|
test_code 'pthread' 'pthread.h' '-pthread' '' '
|
||||||
'return pthread_create((void *)1, NULL, (void *)1, NULL);'
|
pthread_t thread;
|
||||||
|
return (int)pthread_create(&thread, NULL, (void *)1, NULL);'
|
||||||
then
|
then
|
||||||
add_def FEAT_ASYNCDNS
|
add_def FEAT_ASYNCDNS
|
||||||
add_def USE_PTHREAD_ASYNCDNS
|
add_def USE_PTHREAD_ASYNCDNS
|
||||||
EXTRA_OBJECTS="$EXTRA_OBJECTS nameserv_async.o"
|
EXTRA_OBJECTS="$EXTRA_OBJECTS nameserv_async.o"
|
||||||
MYCFLAGS="$MYCFLAGS -pthread"
|
use_pthread=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test_code 'arc4random_buf()' 'stdlib.h' '' '' 'arc4random_buf(NULL, 0);'; then
|
if [ $try_arc4random = "1" ] && \
|
||||||
|
test_code 'arc4random_buf()' 'stdlib.h' '' '' \
|
||||||
|
'arc4random_buf((void *)1, 1);'
|
||||||
|
then
|
||||||
add_def HAVE_ARC4RANDOM
|
add_def HAVE_ARC4RANDOM
|
||||||
|
else
|
||||||
|
if test_code 'getrandom()' 'stdlib.h sys/random.h' '' '' \
|
||||||
|
'return getrandom((void *)1, 1, 0);'; then
|
||||||
|
add_def HAVE_GETRANDOM
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
RECVMMSG_CODE='
|
||||||
|
struct mmsghdr hdr;
|
||||||
|
return !recvmmsg(0, &hdr, 1, MSG_DONTWAIT, 0);'
|
||||||
|
if [ $try_recvmmsg = "1" ]; then
|
||||||
|
if test_code 'recvmmsg()' 'sys/socket.h' '' "$LIBS" "$RECVMMSG_CODE"; then
|
||||||
|
add_def HAVE_RECVMMSG
|
||||||
|
else
|
||||||
|
if test_code 'recvmmsg() with _GNU_SOURCE' 'sys/socket.h' '-D_GNU_SOURCE' \
|
||||||
|
"$LIBS" "$RECVMMSG_CODE"
|
||||||
|
then
|
||||||
|
add_def _GNU_SOURCE
|
||||||
|
add_def HAVE_RECVMMSG
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $feat_timestamping = "1" ] && [ $try_timestamping = "1" ] &&
|
||||||
|
test_code 'SW/HW timestamping' 'sys/types.h sys/socket.h linux/net_tstamp.h
|
||||||
|
linux/errqueue.h linux/ptp_clock.h' '' '' '
|
||||||
|
int val = SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE |
|
||||||
|
SOF_TIMESTAMPING_RAW_HARDWARE | SOF_TIMESTAMPING_OPT_CMSG;
|
||||||
|
return sizeof (struct scm_timestamping) + SCM_TSTAMP_SND + PTP_SYS_OFFSET +
|
||||||
|
setsockopt(0, SOL_SOCKET, SO_SELECT_ERR_QUEUE + SO_TIMESTAMPING,
|
||||||
|
&val, sizeof (val));'
|
||||||
|
then
|
||||||
|
add_def HAVE_LINUX_TIMESTAMPING
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o ntp_io_linux.o"
|
||||||
|
|
||||||
|
if test_code 'other timestamping options' \
|
||||||
|
'sys/types.h sys/socket.h linux/net_tstamp.h' '' '' '
|
||||||
|
struct scm_ts_pktinfo pktinfo;
|
||||||
|
pktinfo.if_index = pktinfo.pkt_length = 0;
|
||||||
|
return pktinfo.if_index + pktinfo.pkt_length + HWTSTAMP_FILTER_NTP_ALL +
|
||||||
|
SCM_TIMESTAMPING_PKTINFO +
|
||||||
|
SOF_TIMESTAMPING_OPT_PKTINFO + SOF_TIMESTAMPING_OPT_TX_SWHW;'; then
|
||||||
|
add_def HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP 1
|
||||||
|
add_def HAVE_LINUX_TIMESTAMPING_OPT_PKTINFO 1
|
||||||
|
add_def HAVE_LINUX_TIMESTAMPING_OPT_TX_SWHW 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
timepps_h=""
|
timepps_h=""
|
||||||
if [ $feat_refclock = "1" ] && [ $feat_pps = "1" ]; then
|
if [ $feat_refclock = "1" ] && [ $feat_pps = "1" ]; then
|
||||||
if test_code '<sys/timepps.h>' 'sys/timepps.h' '' '' ''; then
|
if test_code '<sys/timepps.h>' 'inttypes.h time.h sys/timepps.h' '' '' ''; then
|
||||||
timepps_h="sys/timepps.h"
|
timepps_h="sys/timepps.h"
|
||||||
add_def HAVE_SYS_TIMEPPS_H
|
add_def HAVE_SYS_TIMEPPS_H
|
||||||
else
|
else
|
||||||
if test_code '<timepps.h>' 'timepps.h' '' '' ''; then
|
if test_code '<timepps.h>' 'inttypes.h time.h timepps.h' '' '' ''; then
|
||||||
timepps_h="timepps.h"
|
timepps_h="timepps.h"
|
||||||
add_def HAVE_TIMEPPS_H
|
add_def HAVE_TIMEPPS_H
|
||||||
fi
|
fi
|
||||||
@@ -593,10 +771,11 @@ if [ $feat_refclock = "1" ] && [ $feat_pps = "1" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$timepps_h" != "x" ] && \
|
if [ "x$timepps_h" != "x" ] && \
|
||||||
test_code 'PPSAPI' "string.h $timepps_h" '' '' '
|
test_code 'PPSAPI' "inttypes.h string.h time.h $timepps_h" '' '' '
|
||||||
pps_handle_t h = 0;
|
pps_handle_t h = 0;
|
||||||
pps_info_t i;
|
pps_info_t i;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
ts.tv_sec = ts.tv_nsec = 0;
|
||||||
return time_pps_fetch(h, PPS_TSFMT_TSPEC, &i, &ts);'
|
return time_pps_fetch(h, PPS_TSFMT_TSPEC, &i, &ts);'
|
||||||
then
|
then
|
||||||
add_def FEAT_PPS
|
add_def FEAT_PPS
|
||||||
@@ -625,10 +804,12 @@ if [ $feat_scfilter = "1" ] && [ $try_seccomp = "1" ] && \
|
|||||||
'seccomp_init(SCMP_ACT_KILL);'
|
'seccomp_init(SCMP_ACT_KILL);'
|
||||||
then
|
then
|
||||||
add_def FEAT_SCFILTER
|
add_def FEAT_SCFILTER
|
||||||
# NAME2IPADDRESS shouldn't be enabled with other operations as the helper
|
if [ $feat_ntp = "1" ]; then
|
||||||
# process works on one request at the time and the async resolver could
|
# NAME2IPADDRESS shouldn't be enabled together with a privops operation
|
||||||
# block the main thread
|
# used by the main thread as the helper process works on one request at
|
||||||
priv_ops="NAME2IPADDRESS"
|
# a time and the async resolver would block the main thread
|
||||||
|
priv_ops="NAME2IPADDRESS RELOADDNS"
|
||||||
|
fi
|
||||||
EXTRA_LIBS="$EXTRA_LIBS -lseccomp"
|
EXTRA_LIBS="$EXTRA_LIBS -lseccomp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -649,83 +830,59 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_refclock = "1" ] && [ $feat_phc = "1" ] && [ $try_phc = "1" ] && \
|
if [ $feat_refclock = "1" ] && [ $feat_phc = "1" ] && [ $try_phc = "1" ] && \
|
||||||
|
grep '#define HAVE_CLOCK_GETTIME' config.h > /dev/null && \
|
||||||
test_code '<linux/ptp_clock.h>' 'sys/ioctl.h linux/ptp_clock.h' '' '' \
|
test_code '<linux/ptp_clock.h>' 'sys/ioctl.h linux/ptp_clock.h' '' '' \
|
||||||
'ioctl(1, PTP_CLOCK_GETCAPS, 0);'
|
'ioctl(1, PTP_CLOCK_GETCAPS + PTP_SYS_OFFSET, 0);'
|
||||||
then
|
then
|
||||||
if test_code 'clock_gettime()' 'time.h' '' '' 'clock_gettime(0, NULL);'; then
|
grep 'HAVE_LINUX_TIMESTAMPING' config.h > /dev/null ||
|
||||||
add_def FEAT_PHC
|
EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o"
|
||||||
else
|
add_def FEAT_PHC
|
||||||
if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \
|
|
||||||
'clock_gettime(0, NULL);'
|
|
||||||
then
|
|
||||||
EXTRA_LIBS="$EXTRA_LIBS -lrt"
|
|
||||||
add_def FEAT_PHC
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $try_setsched = "1" ] && \
|
if [ $try_setsched = "1" ] && \
|
||||||
test_code \
|
test_code \
|
||||||
'sched_setscheduler()' \
|
'pthread_setschedparam()' \
|
||||||
'sched.h' '' '' '
|
'pthread.h sched.h' '-pthread' '' '
|
||||||
struct sched_param sched;
|
struct sched_param sched;
|
||||||
sched_get_priority_max(SCHED_FIFO);
|
sched_get_priority_max(SCHED_FIFO);
|
||||||
sched_setscheduler(0, SCHED_FIFO, &sched);'
|
pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched);'
|
||||||
then
|
then
|
||||||
add_def HAVE_SCHED_SETSCHEDULER
|
add_def HAVE_PTHREAD_SETSCHEDPARAM
|
||||||
|
use_pthread=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $try_lockmem = "1" ] && \
|
if [ $try_lockmem = "1" ] && \
|
||||||
test_code \
|
test_code \
|
||||||
'mlockall()' \
|
'mlockall()' \
|
||||||
'sys/mman.h sys/resource.h' '' '' '
|
'sys/mman.h' '' '' '
|
||||||
struct rlimit rlim;
|
|
||||||
setrlimit(RLIMIT_MEMLOCK, &rlim);
|
|
||||||
mlockall(MCL_CURRENT|MCL_FUTURE);'
|
mlockall(MCL_CURRENT|MCL_FUTURE);'
|
||||||
then
|
then
|
||||||
add_def HAVE_MLOCKALL
|
add_def HAVE_MLOCKALL
|
||||||
fi
|
fi
|
||||||
|
if [ $try_lockmem = "1" ] && \
|
||||||
|
test_code \
|
||||||
|
'setrlimit(RLIMIT_MEMLOCK, ...)' \
|
||||||
|
'sys/resource.h' '' '' '
|
||||||
|
struct rlimit rlim;
|
||||||
|
rlim.rlim_max = rlim.rlim_cur = RLIM_INFINITY;
|
||||||
|
setrlimit(RLIMIT_MEMLOCK, &rlim);'
|
||||||
|
then
|
||||||
|
add_def HAVE_SETRLIMIT_MEMLOCK
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $feat_forcednsretry = "1" ]
|
if [ $feat_forcednsretry = "1" ]
|
||||||
then
|
then
|
||||||
add_def FORCE_DNSRETRY
|
add_def FORCE_DNSRETRY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
READLINE_COMPILE=""
|
|
||||||
READLINE_LINK=""
|
READLINE_LINK=""
|
||||||
if [ $feat_readline = "1" ]; then
|
if [ $feat_readline = "1" ]; then
|
||||||
if [ $try_editline = "1" ]; then
|
if [ $try_editline = "1" ]; then
|
||||||
if test_code editline 'stdio.h editline/readline.h' \
|
if test_code editline 'stdio.h editline/readline.h' '' '-ledit' \
|
||||||
"$readline_inc" "$readline_lib -ledit" \
|
|
||||||
'add_history(readline("prompt"));'
|
'add_history(readline("prompt"));'
|
||||||
then
|
then
|
||||||
add_def FEAT_READLINE
|
add_def FEAT_READLINE
|
||||||
add_def USE_EDITLINE
|
READLINE_LINK="-ledit"
|
||||||
READLINE_COMPILE="$readline_inc"
|
|
||||||
READLINE_LINK="$readline_lib -ledit"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
|
|
||||||
if test_code readline 'stdio.h readline/readline.h readline/history.h' \
|
|
||||||
"$readline_inc" "$readline_lib -lreadline" \
|
|
||||||
'add_history(readline("prompt"));'
|
|
||||||
then
|
|
||||||
add_def FEAT_READLINE
|
|
||||||
READLINE_COMPILE="$readline_inc"
|
|
||||||
READLINE_LINK="$readline_lib -lreadline"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
|
|
||||||
if test_code 'readline with -lncurses' \
|
|
||||||
'stdio.h readline/readline.h readline/history.h' \
|
|
||||||
"$readline_inc" "$readline_lib $ncurses_lib -lreadline -lncurses" \
|
|
||||||
'add_history(readline("prompt"));'
|
|
||||||
then
|
|
||||||
add_def FEAT_READLINE
|
|
||||||
READLINE_COMPILE="$readline_inc"
|
|
||||||
READLINE_LINK="$readline_lib $ncurses_lib -lreadline -lncurses"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -733,36 +890,139 @@ if [ $feat_readline = "1" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
HASH_OBJ="hash_intmd5.o"
|
HASH_OBJ="hash_intmd5.o"
|
||||||
HASH_COMPILE=""
|
|
||||||
HASH_LINK=""
|
HASH_LINK=""
|
||||||
|
|
||||||
if [ $feat_sechash = "1" ] && [ $try_nss = "1" ]; then
|
if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_nettle = "1" ]; then
|
||||||
|
test_cflags="`pkg_config --cflags nettle`"
|
||||||
|
test_link="`pkg_config --libs nettle`"
|
||||||
|
if test_code 'nettle' 'nettle/nettle-meta.h nettle/sha2.h' \
|
||||||
|
"$test_cflags" "$test_link" \
|
||||||
|
'return nettle_hashes[0]->context_size;'
|
||||||
|
then
|
||||||
|
HASH_OBJ="hash_nettle.o"
|
||||||
|
HASH_LINK="$test_link"
|
||||||
|
MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
|
||||||
|
add_def FEAT_SECHASH
|
||||||
|
|
||||||
|
if test_code 'CMAC in nettle' 'nettle/cmac.h' "$test_cflags" "$test_link" \
|
||||||
|
'cmac128_update((void *)1, (void *)2, (void *)3, 1, (void *)4);'
|
||||||
|
then
|
||||||
|
add_def HAVE_CMAC
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS cmac_nettle.o"
|
||||||
|
EXTRA_CLI_OBJECTS="$EXTRA_CLI_OBJECTS cmac_nettle.o"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_nss = "1" ]; then
|
||||||
test_cflags="`pkg_config --cflags nss`"
|
test_cflags="`pkg_config --cflags nss`"
|
||||||
test_link="`pkg_config --libs-only-L nss` -lfreebl3"
|
test_link="`pkg_config --libs-only-L nss` -lfreebl3 -lnssutil3"
|
||||||
if test_code 'NSS' 'nss.h hasht.h nsslowhash.h' \
|
if test_code 'NSS' 'nss.h hasht.h nsslowhash.h' \
|
||||||
"$test_cflags" "$test_link" \
|
"$test_cflags" "$test_link" \
|
||||||
'NSSLOWHASH_Begin(NSSLOWHASH_NewContext(NSSLOW_Init(), HASH_AlgSHA512));'
|
'NSSLOWHASH_Begin(NSSLOWHASH_NewContext(NSSLOW_Init(), HASH_AlgSHA512));'
|
||||||
then
|
then
|
||||||
HASH_OBJ="hash_nss.o"
|
HASH_OBJ="hash_nss.o"
|
||||||
HASH_COMPILE="$test_cflags"
|
|
||||||
HASH_LINK="$test_link"
|
HASH_LINK="$test_link"
|
||||||
LIBS="$LIBS $HASH_LINK"
|
MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
|
||||||
add_def FEAT_SECHASH
|
add_def FEAT_SECHASH
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_tomcrypt = "1" ]; then
|
if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_tomcrypt = "1" ]; then
|
||||||
if test_code 'tomcrypt' 'tomcrypt.h' '-I/usr/include/tomcrypt' '-ltomcrypt' \
|
if test_code 'tomcrypt' 'tomcrypt.h' '-I/usr/include/tomcrypt' '-ltomcrypt' \
|
||||||
'hash_memory_multi(find_hash("md5"), NULL, NULL, NULL, 0, NULL, 0);'
|
'hash_memory_multi(find_hash("md5"), (void *)1, (void *)2, (void *)3, 1, (void *)4, 1);'
|
||||||
then
|
then
|
||||||
HASH_OBJ="hash_tomcrypt.o"
|
HASH_OBJ="hash_tomcrypt.o"
|
||||||
HASH_COMPILE="-I/usr/include/tomcrypt"
|
|
||||||
HASH_LINK="-ltomcrypt"
|
HASH_LINK="-ltomcrypt"
|
||||||
LIBS="$LIBS $HASH_LINK"
|
MYCPPFLAGS="$MYCPPFLAGS -I/usr/include/tomcrypt"
|
||||||
add_def FEAT_SECHASH
|
add_def FEAT_SECHASH
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_gnutls = "1" ]; then
|
||||||
|
test_cflags="`pkg_config --cflags gnutls`"
|
||||||
|
test_link="`pkg_config --libs gnutls`"
|
||||||
|
if test_code 'gnutls' 'gnutls/crypto.h' \
|
||||||
|
"$test_cflags" "$test_link" '
|
||||||
|
return gnutls_hash((void *)1, (void *)2, 1);'
|
||||||
|
then
|
||||||
|
HASH_OBJ="hash_gnutls.o"
|
||||||
|
HASH_LINK="$test_link"
|
||||||
|
MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
|
||||||
|
add_def FEAT_SECHASH
|
||||||
|
|
||||||
|
if test_code 'CMAC in gnutls' 'gnutls/crypto.h' "$test_cflags" "$test_link" \
|
||||||
|
'return gnutls_hmac_init((void *)1, GNUTLS_MAC_AES_CMAC_128, (void *)2, 0);'
|
||||||
|
then
|
||||||
|
add_def HAVE_CMAC
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS cmac_gnutls.o"
|
||||||
|
EXTRA_CLI_OBJECTS="$EXTRA_CLI_OBJECTS cmac_gnutls.o"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS $HASH_OBJ"
|
||||||
|
EXTRA_CLI_OBJECTS="$EXTRA_CLI_OBJECTS $HASH_OBJ"
|
||||||
|
LIBS="$LIBS $HASH_LINK"
|
||||||
|
|
||||||
|
if [ $feat_ntp = "1" ] && [ $feat_nts = "1" ] && [ $try_gnutls = "1" ]; then
|
||||||
|
if [ "$HASH_OBJ" = "hash_gnutls.o" ]; then
|
||||||
|
test_cflags=""
|
||||||
|
test_link=""
|
||||||
|
else
|
||||||
|
test_cflags="`pkg_config --cflags gnutls`"
|
||||||
|
test_link="`pkg_config --libs gnutls`"
|
||||||
|
fi
|
||||||
|
if test_code 'TLS1.3 in gnutls' 'gnutls/gnutls.h' \
|
||||||
|
"$test_cflags" "$test_link $LIBS" '
|
||||||
|
return gnutls_init((void *)1, 0) + GNUTLS_TLS1_3 +
|
||||||
|
gnutls_priority_init2((void *)1, "", NULL, GNUTLS_PRIORITY_INIT_DEF_APPEND) +
|
||||||
|
gnutls_prf_rfc5705((void *)1, 0, "", 0, "", 16, (void *)2);'
|
||||||
|
then
|
||||||
|
if test_code 'SIV in nettle' \
|
||||||
|
'nettle/siv-cmac.h' "" "$LIBS" \
|
||||||
|
'siv_cmac_aes128_set_key((void *)1, (void *)2);'
|
||||||
|
then
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS siv_nettle.o"
|
||||||
|
add_def HAVE_SIV
|
||||||
|
add_def HAVE_NETTLE_SIV_CMAC
|
||||||
|
else
|
||||||
|
if test_code 'SIV in gnutls' 'gnutls/crypto.h' \
|
||||||
|
"$test_cflags" "$test_link $LIBS" '
|
||||||
|
return gnutls_aead_cipher_init((void *)1, GNUTLS_CIPHER_AES_128_SIV, (void *)2);'
|
||||||
|
then
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS siv_gnutls.o"
|
||||||
|
add_def HAVE_SIV
|
||||||
|
if test_code 'gnutls_aead_cipher_set_key()' 'gnutls/crypto.h' \
|
||||||
|
"$test_cflags" "$test_link $LIBS" '
|
||||||
|
return gnutls_aead_cipher_set_key((void *)1, (void *)2);'
|
||||||
|
then
|
||||||
|
add_def HAVE_GNUTLS_AEAD_CIPHER_SET_KEY
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if test_code 'AES128 in nettle' 'nettle/aes.h' '' "$LIBS" \
|
||||||
|
'aes128_set_encrypt_key((void *)1, (void *)2);'
|
||||||
|
then
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS siv_nettle.o"
|
||||||
|
add_def HAVE_SIV
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep '#define HAVE_SIV' config.h > /dev/null; then
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS nts_ke_client.o nts_ke_server.o nts_ke_session.o"
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS nts_ntp_auth.o nts_ntp_client.o nts_ntp_server.o"
|
||||||
|
LIBS="$LIBS $test_link"
|
||||||
|
MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
|
||||||
|
add_def FEAT_NTS
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $use_pthread = "1" ]; then
|
||||||
|
MYCFLAGS="$MYCFLAGS -pthread"
|
||||||
|
fi
|
||||||
|
|
||||||
SYSCONFDIR=/etc
|
SYSCONFDIR=/etc
|
||||||
if [ "x$SETSYSCONFDIR" != "x" ]; then
|
if [ "x$SETSYSCONFDIR" != "x" ]; then
|
||||||
SYSCONFDIR=$SETSYSCONFDIR
|
SYSCONFDIR=$SETSYSCONFDIR
|
||||||
@@ -808,9 +1068,9 @@ if [ "x$SETLOCALSTATEDIR" != "x" ]; then
|
|||||||
LOCALSTATEDIR=$SETLOCALSTATEDIR
|
LOCALSTATEDIR=$SETLOCALSTATEDIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHRONYSOCKDIR=${LOCALSTATEDIR}/run/chrony
|
CHRONYRUNDIR=${LOCALSTATEDIR}/run/chrony
|
||||||
if [ "x$SETCHRONYSOCKDIR" != "x" ]; then
|
if [ "x$SETCHRONYRUNDIR" != "x" ]; then
|
||||||
CHRONYSOCKDIR=$SETCHRONYSOCKDIR
|
CHRONYRUNDIR=$SETCHRONYRUNDIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CHRONYVARDIR=${LOCALSTATEDIR}/lib/chrony
|
CHRONYVARDIR=${LOCALSTATEDIR}/lib/chrony
|
||||||
@@ -820,13 +1080,15 @@ fi
|
|||||||
|
|
||||||
add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
|
add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
|
||||||
add_def DEFAULT_HWCLOCK_FILE "\"$default_hwclockfile\""
|
add_def DEFAULT_HWCLOCK_FILE "\"$default_hwclockfile\""
|
||||||
|
add_def DEFAULT_PID_FILE "\"$default_pidfile\""
|
||||||
|
add_def DEFAULT_RTC_DEVICE "\"$default_rtcdevice\""
|
||||||
add_def DEFAULT_USER "\"$default_user\""
|
add_def DEFAULT_USER "\"$default_user\""
|
||||||
add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYSOCKDIR/chronyd.sock\""
|
add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYRUNDIR/chronyd.sock\""
|
||||||
add_def MAIL_PROGRAM "\"$mail_program\""
|
add_def MAIL_PROGRAM "\"$mail_program\""
|
||||||
|
|
||||||
common_features="`get_features IPV6 DEBUG`"
|
common_features="`get_features SECHASH IPV6 DEBUG`"
|
||||||
chronyc_features="`get_features READLINE`"
|
chronyc_features="`get_features READLINE`"
|
||||||
chronyd_features="`get_features CMDMON NTP REFCLOCK RTC PRIVDROP SCFILTER SECHASH ASYNCDNS`"
|
chronyd_features="`get_features CMDMON NTP REFCLOCK RTC PRIVDROP SCFILTER SIGND ASYNCDNS NTS`"
|
||||||
add_def CHRONYC_FEATURES "\"$chronyc_features $common_features\""
|
add_def CHRONYC_FEATURES "\"$chronyc_features $common_features\""
|
||||||
add_def CHRONYD_FEATURES "\"$chronyd_features $common_features\""
|
add_def CHRONYD_FEATURES "\"$chronyd_features $common_features\""
|
||||||
echo "Features : $chronyd_features $chronyc_features $common_features"
|
echo "Features : $chronyd_features $chronyc_features $common_features"
|
||||||
@@ -842,26 +1104,26 @@ add_def CHRONY_VERSION "\"${CHRONY_VERSION}\""
|
|||||||
for f in Makefile doc/Makefile test/unit/Makefile
|
for f in Makefile doc/Makefile test/unit/Makefile
|
||||||
do
|
do
|
||||||
echo Creating $f
|
echo Creating $f
|
||||||
sed -e "s%@EXTRA_OBJECTS@%${EXTRA_OBJECTS}%;\
|
sed -e "s%@EXTRA_OBJS@%${EXTRA_OBJECTS}%;\
|
||||||
|
s%@EXTRA_CLI_OBJS@%${EXTRA_CLI_OBJECTS}%;\
|
||||||
s%@CC@%${MYCC}%;\
|
s%@CC@%${MYCC}%;\
|
||||||
s%@CFLAGS@%${MYCFLAGS}%;\
|
s%@CFLAGS@%${MYCFLAGS}%;\
|
||||||
s%@CPPFLAGS@%${MYCPPFLAGS}%;\
|
s%@CPPFLAGS@%${MYCPPFLAGS}%;\
|
||||||
s%@LIBS@%${LIBS}%;\
|
|
||||||
s%@LDFLAGS@%${MYLDFLAGS}%;\
|
s%@LDFLAGS@%${MYLDFLAGS}%;\
|
||||||
|
s%@LIBS@%${LIBS}%;\
|
||||||
s%@EXTRA_LIBS@%${EXTRA_LIBS}%;\
|
s%@EXTRA_LIBS@%${EXTRA_LIBS}%;\
|
||||||
s%@EXTRA_CLI_LIBS@%${EXTRA_CLI_LIBS}%;\
|
s%@EXTRA_CLI_LIBS@%${EXTRA_CLI_LIBS}%;\
|
||||||
s%@READLINE_COMPILE@%${READLINE_COMPILE}%;\
|
|
||||||
s%@HASH_OBJ@%${HASH_OBJ}%;\
|
|
||||||
s%@HASH_COMPILE@%${HASH_COMPILE}%;\
|
|
||||||
s%@SYSCONFDIR@%${SYSCONFDIR}%;\
|
s%@SYSCONFDIR@%${SYSCONFDIR}%;\
|
||||||
s%@BINDIR@%${BINDIR}%;\
|
s%@BINDIR@%${BINDIR}%;\
|
||||||
s%@SBINDIR@%${SBINDIR}%;\
|
s%@SBINDIR@%${SBINDIR}%;\
|
||||||
s%@DOCDIR@%${DOCDIR}%;\
|
s%@DOCDIR@%${DOCDIR}%;\
|
||||||
s%@MANDIR@%${MANDIR}%;\
|
s%@MANDIR@%${MANDIR}%;\
|
||||||
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
|
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
|
||||||
s%@CHRONYSOCKDIR@%${CHRONYSOCKDIR}%;\
|
s%@CHRONYRUNDIR@%${CHRONYRUNDIR}%;\
|
||||||
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
|
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
|
||||||
s%@DEFAULT_HWCLOCK_FILE@%${default_hwclockfile}%;\
|
s%@DEFAULT_HWCLOCK_FILE@%${default_hwclockfile}%;\
|
||||||
|
s%@DEFAULT_PID_FILE@%${default_pidfile}%;\
|
||||||
|
s%@DEFAULT_RTC_DEVICE@%${default_rtcdevice}%;\
|
||||||
s%@DEFAULT_USER@%${default_user}%;\
|
s%@DEFAULT_USER@%${default_user}%;\
|
||||||
s%@CHRONY_VERSION@%${CHRONY_VERSION}%;" \
|
s%@CHRONY_VERSION@%${CHRONY_VERSION}%;" \
|
||||||
< ${f}.in > $f
|
< ${f}.in > $f
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
Notes for installing chrony on MacOS X
|
Notes for installing chrony on macOS
|
||||||
Author: Bryan Christianson (bryan@whatroute.net)
|
Author: Bryan Christianson (bryan@whatroute.net)
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|
||||||
These files are for those admins/users who would prefer to install chrony
|
These files are for those admins/users who would prefer to install chrony
|
||||||
from the source distribution and are intended as guidelines rather than
|
from the source distribution and are intended as guidelines rather than
|
||||||
being definitive. They can be edited with a plain text editor, such as
|
being definitive. They can be edited with a plain text editor, such as
|
||||||
vi, emacs or your favourite IDE (xcode)
|
vi, emacs or your favourite IDE (Xcode)
|
||||||
|
|
||||||
It is assumed you are comfortable with installing software from the
|
It is assumed you are comfortable with installing software from the
|
||||||
terminal command line and know how to use sudo to acquire root access.
|
terminal command line and know how to use sudo to acquire root access.
|
||||||
|
|
||||||
If you are not familiar with the MacOS X command line then
|
If you are not familiar with the macOS command line then
|
||||||
please consider using ChronyControl from http://whatroute.net/chronycontrol.html
|
please consider using ChronyControl from http://whatroute.net/chronycontrol.html
|
||||||
|
|
||||||
ChronyControl provides a gui wrapper for installing these files and sets the
|
ChronyControl provides a gui wrapper for installing these files and sets the
|
||||||
@@ -72,7 +72,7 @@ Installing the support files
|
|||||||
|
|
||||||
1. chronylogrotate.sh
|
1. chronylogrotate.sh
|
||||||
This is a simple shell script that deletes old log files. Unfortunately because
|
This is a simple shell script that deletes old log files. Unfortunately because
|
||||||
of the need to run chronyc, the standard MacOS X logrotation does not work with
|
of the need to run chronyc, the standard macOS logrotation does not work with
|
||||||
chrony logs.
|
chrony logs.
|
||||||
|
|
||||||
This script runs on a daily basis under control of launchd and should be
|
This script runs on a daily basis under control of launchd and should be
|
||||||
|
|||||||
@@ -13,19 +13,23 @@ BINDIR = @BINDIR@
|
|||||||
SBINDIR = @SBINDIR@
|
SBINDIR = @SBINDIR@
|
||||||
MANDIR = @MANDIR@
|
MANDIR = @MANDIR@
|
||||||
DOCDIR = @DOCDIR@
|
DOCDIR = @DOCDIR@
|
||||||
CHRONYSOCKDIR = @CHRONYSOCKDIR@
|
CHRONYRUNDIR = @CHRONYRUNDIR@
|
||||||
CHRONYVARDIR = @CHRONYVARDIR@
|
CHRONYVARDIR = @CHRONYVARDIR@
|
||||||
CHRONY_VERSION = @CHRONY_VERSION@
|
CHRONY_VERSION = @CHRONY_VERSION@
|
||||||
DEFAULT_USER = @DEFAULT_USER@
|
DEFAULT_USER = @DEFAULT_USER@
|
||||||
DEFAULT_HWCLOCK_FILE = @DEFAULT_HWCLOCK_FILE@
|
DEFAULT_HWCLOCK_FILE = @DEFAULT_HWCLOCK_FILE@
|
||||||
|
DEFAULT_PID_FILE = @DEFAULT_PID_FILE@
|
||||||
|
DEFAULT_RTC_DEVICE = @DEFAULT_RTC_DEVICE@
|
||||||
|
|
||||||
SED_COMMANDS = "s%\@SYSCONFDIR\@%$(SYSCONFDIR)%g;\
|
SED_COMMANDS = "s%\@SYSCONFDIR\@%$(SYSCONFDIR)%g;\
|
||||||
s%\@BINDIR\@%$(BINDIR)%g;\
|
s%\@BINDIR\@%$(BINDIR)%g;\
|
||||||
s%\@SBINDIR\@%$(SBINDIR)%g;\
|
s%\@SBINDIR\@%$(SBINDIR)%g;\
|
||||||
s%\@CHRONY_VERSION\@%$(CHRONY_VERSION)%g;\
|
s%\@CHRONY_VERSION\@%$(CHRONY_VERSION)%g;\
|
||||||
s%\@DEFAULT_HWCLOCK_FILE\@%$(DEFAULT_HWCLOCK_FILE)%g;\
|
s%\@DEFAULT_HWCLOCK_FILE\@%$(DEFAULT_HWCLOCK_FILE)%g;\
|
||||||
|
s%\@DEFAULT_PID_FILE\@%$(DEFAULT_PID_FILE)%g;\
|
||||||
|
s%\@DEFAULT_RTC_DEVICE\@%$(DEFAULT_RTC_DEVICE)%g;\
|
||||||
s%\@DEFAULT_USER\@%$(DEFAULT_USER)%g;\
|
s%\@DEFAULT_USER\@%$(DEFAULT_USER)%g;\
|
||||||
s%\@CHRONYSOCKDIR\@%$(CHRONYSOCKDIR)%g;\
|
s%\@CHRONYRUNDIR\@%$(CHRONYRUNDIR)%g;\
|
||||||
s%\@CHRONYVARDIR\@%$(CHRONYVARDIR)%g;"
|
s%\@CHRONYVARDIR\@%$(CHRONYVARDIR)%g;"
|
||||||
|
|
||||||
man: $(MAN_FILES) $(MAN_IN_FILES)
|
man: $(MAN_FILES) $(MAN_IN_FILES)
|
||||||
|
|||||||
2066
doc/chrony.conf.adoc
2066
doc/chrony.conf.adoc
File diff suppressed because it is too large
Load Diff
730
doc/chronyc.adoc
730
doc/chronyc.adoc
File diff suppressed because it is too large
Load Diff
130
doc/chronyd.adoc
130
doc/chronyd.adoc
@@ -1,7 +1,7 @@
|
|||||||
// This file is part of chrony
|
// This file is part of chrony
|
||||||
//
|
//
|
||||||
// Copyright (C) Richard P. Curnow 1997-2003
|
// Copyright (C) Richard P. Curnow 1997-2003
|
||||||
// Copyright (C) Miroslav Lichvar 2009-2016
|
// Copyright (C) Miroslav Lichvar 2009-2017
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of version 2 of the GNU General Public License as
|
// it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -41,7 +41,7 @@ If no configuration directives are specified on the command line, *chronyd*
|
|||||||
will read them from a configuration file. The compiled-in default location of
|
will read them from a configuration file. The compiled-in default location of
|
||||||
the file is _@SYSCONFDIR@/chrony.conf_.
|
the file is _@SYSCONFDIR@/chrony.conf_.
|
||||||
|
|
||||||
Information messages and warnings will be logged to syslog.
|
Informational messages, warnings, and errors will be logged to syslog.
|
||||||
|
|
||||||
== OPTIONS
|
== OPTIONS
|
||||||
|
|
||||||
@@ -55,34 +55,52 @@ IPv6 sockets will be created.
|
|||||||
|
|
||||||
*-f* _file_::
|
*-f* _file_::
|
||||||
This option can be used to specify an alternate location for the configuration
|
This option can be used to specify an alternate location for the configuration
|
||||||
file (default _@SYSCONFDIR@/chrony.conf_).
|
file. The compiled-in default value is _@SYSCONFDIR@/chrony.conf_.
|
||||||
|
|
||||||
*-n*::
|
*-n*::
|
||||||
When run in this mode, the program will not detach itself from the terminal.
|
When run in this mode, the program will not detach itself from the terminal.
|
||||||
|
|
||||||
*-d*::
|
*-d*::
|
||||||
When run in this mode, the program will not detach itself from the terminal,
|
When run in this mode, the program will not detach itself from the terminal,
|
||||||
and all messages will be sent to the terminal instead of to syslog. When
|
and all messages will be written to the terminal instead of syslog. If
|
||||||
*chronyd* was compiled with debugging support, this option can be used twice to
|
*chronyd* was compiled with enabled support for debugging, this option can be
|
||||||
print also debugging messages.
|
used twice to enable debug messages.
|
||||||
|
|
||||||
|
*-l* _file_::
|
||||||
|
This option enables writing of log messages to a file instead of syslog or the
|
||||||
|
terminal.
|
||||||
|
|
||||||
|
*-L* _level_::
|
||||||
|
This option specifies the minimum severity level of messages to be written to
|
||||||
|
the log file, syslog, or terminal. The following levels can be specified:
|
||||||
|
0 (informational), 1 (warning), 2 (non-fatal error), and 3 (fatal error). The
|
||||||
|
default value is 0.
|
||||||
|
|
||||||
|
*-p*::
|
||||||
|
When run in this mode, *chronyd* will print the configuration and exit. It will
|
||||||
|
not detach from the terminal. This option can be used to verify the syntax of
|
||||||
|
the configuration and get the whole configuration, even if it is split into
|
||||||
|
multiple files and read by the *include* or *confdir* directive.
|
||||||
|
|
||||||
*-q*::
|
*-q*::
|
||||||
When run in this mode, *chronyd* will set the system clock once and exit. It
|
When run in this mode, *chronyd* will set the system clock once and exit. It
|
||||||
will not detach from the terminal.
|
will not detach from the terminal.
|
||||||
|
|
||||||
*-Q*::
|
*-Q*::
|
||||||
This option is similar to *-q*, but it will only print the offset without any
|
This option is similar to the *-q* option, except it only prints the offset
|
||||||
corrections of the clock.
|
without making any corrections of the clock and it allows *chronyd* to be
|
||||||
|
started without root privileges.
|
||||||
|
|
||||||
*-r*::
|
*-r*::
|
||||||
This option will reload sample histories for each of the servers and refclocks
|
This option will try to reload and then delete files containing sample
|
||||||
being used. These histories are created by using the
|
histories for each of the servers and reference clocks being used. The
|
||||||
<<chronyc.adoc#dump,*dump*>> command in *chronyc*, or by setting the
|
files are expected to be in the directory specified by the
|
||||||
<<chrony.conf.adoc#dumponexit,*dumponexit*>> directive in the configuration
|
<<chrony.conf.adoc#dumpdir,*dumpdir*>>
|
||||||
file. This option is useful if you want to stop and restart *chronyd* briefly
|
directive in the configuration file. This option is useful if you want to stop
|
||||||
for any reason, e.g. to install a new version. However, it should be used only
|
and restart *chronyd* briefly for any reason, e.g. to install a new version.
|
||||||
on systems where the kernel can maintain clock compensation whilst not under
|
However, it should be used only on systems where the kernel can maintain clock
|
||||||
*chronyd*'s control (i.e. Linux, FreeBSD, NetBSD and Solaris).
|
compensation whilst not under *chronyd*'s control (i.e. Linux, FreeBSD, NetBSD,
|
||||||
|
illumos, and macOS 10.13 or later).
|
||||||
|
|
||||||
*-R*::
|
*-R*::
|
||||||
When this option is used, the <<chrony.conf.adoc#initstepslew,*initstepslew*>>
|
When this option is used, the <<chrony.conf.adoc#initstepslew,*initstepslew*>>
|
||||||
@@ -109,43 +127,83 @@ time and the RTC time, the system time will be set to it to restore the time
|
|||||||
when *chronyd* was previously stopped. This is useful on computers that have no
|
when *chronyd* was previously stopped. This is useful on computers that have no
|
||||||
RTC or the RTC is broken (e.g. it has no battery).
|
RTC or the RTC is broken (e.g. it has no battery).
|
||||||
|
|
||||||
|
*-t* _timeout_::
|
||||||
|
This option sets a timeout (in seconds) after which *chronyd* will exit. If the
|
||||||
|
clock is not synchronised, it will exit with a non-zero status. This is useful
|
||||||
|
with the *-q* or *-Q* option to shorten the maximum time waiting for
|
||||||
|
measurements, or with the *-r* option to limit the time when *chronyd* is
|
||||||
|
running, but still allow it to adjust the frequency of the system clock.
|
||||||
|
|
||||||
*-u* _user_::
|
*-u* _user_::
|
||||||
This option sets the name of the system user to which *chronyd* will switch
|
This option sets the name of the system user to which *chronyd* will switch
|
||||||
after start in order to drop root privileges. It overrides the
|
after start in order to drop root privileges. It overrides the
|
||||||
<<chrony.conf.adoc#user,*user*>> directive (default _@DEFAULT_USER@_).
|
<<chrony.conf.adoc#user,*user*>> directive. The compiled-in default value is
|
||||||
|
_@DEFAULT_USER@_.
|
||||||
+
|
+
|
||||||
On Linux, *chronyd* needs to be compiled with support for the *libcap* library.
|
On Linux, *chronyd* needs to be compiled with support for the *libcap* library.
|
||||||
On Mac OS X, FreeBSD, NetBSD and Solaris *chronyd* forks into two processes.
|
On macOS, FreeBSD, NetBSD, and illumos *chronyd* forks into two processes.
|
||||||
The child process retains root privileges, but can only perform a very limited
|
The child process retains root privileges, but can only perform a very limited
|
||||||
range of privileged system calls on behalf of the parent.
|
range of privileged system calls on behalf of the parent.
|
||||||
|
|
||||||
|
*-U*::
|
||||||
|
This option disables a check for root privileges to allow *chronyd* to be
|
||||||
|
started under a non-root user, assuming the process will have all capabilities
|
||||||
|
(e.g. provided by the service manager) and access to all files, directories,
|
||||||
|
and devices, needed to operate correctly in the specified configuration. Note
|
||||||
|
that different capabilities might be needed with different configurations and
|
||||||
|
different Linux kernel versions. Starting *chronyd* under a non-root user is
|
||||||
|
not recommended when the configuration is not known, or at least limited to
|
||||||
|
specific directives.
|
||||||
|
|
||||||
*-F* _level_::
|
*-F* _level_::
|
||||||
This option configures a system call filter when *chronyd* is compiled with
|
This option configures system call filters loaded by *chronyd* processes if it
|
||||||
support for the Linux secure computing (seccomp) facility. In level 1 the
|
was compiled with support for the Linux secure computing (seccomp) facility.
|
||||||
process is killed when a forbidden system call is made, in level -1 the SYSSIG
|
Three levels are defined: 0, 1, 2. The filters are disabled at level 0. At
|
||||||
signal is thrown instead and in level 0 the filter is disabled (default 0).
|
levels 1 and 2, *chronyd* will be killed if it makes a system call which is
|
||||||
|
blocked by the filters. The level can be specified as a negative number to
|
||||||
|
trigger the SIGSYS signal instead of SIGKILL, which can be useful for
|
||||||
|
debugging. The default value is 0.
|
||||||
+
|
+
|
||||||
It's recommended to enable the filter only when it's known to work on the
|
At level 1, the filters allow only selected system calls that are normally
|
||||||
version of the system where *chrony* is installed as the filter needs to allow
|
expected to be made by *chronyd*. Other system calls are blocked. This level is
|
||||||
also system calls made from libraries that *chronyd* is using (e.g. libc) and
|
recommended only if it is known to work on the version of the system where
|
||||||
different versions or implementations of the libraries may make different
|
*chrony* is installed. The filters need to allow also system calls made by
|
||||||
system calls. If the filter is missing some system call, *chronyd* could be
|
libraries that *chronyd* is using (e.g. libc), but different versions or
|
||||||
killed even in normal operation.
|
implementations of the libraries might make different system calls. If the
|
||||||
|
filters are missing a system call, *chronyd* could be killed even in normal
|
||||||
|
operation.
|
||||||
|
+
|
||||||
|
At level 2, the filters block only a small number of specific system calls
|
||||||
|
(e.g. fork and exec). This approach should avoid false positives, but the
|
||||||
|
protection of the system against a compromised *chronyd* process is much more
|
||||||
|
limited.
|
||||||
|
+
|
||||||
|
The filters cannot be enabled with the *mailonchange* directive.
|
||||||
|
|
||||||
*-P* _priority_::
|
*-P* _priority_::
|
||||||
On Linux, this option will select the SCHED_FIFO real-time scheduler at the
|
On Linux, FreeBSD, NetBSD, and illumos this option will select the SCHED_FIFO
|
||||||
specified priority (which must be between 0 and 100). On Mac OS X, this option
|
real-time scheduler at the specified priority (which must be between 0 and
|
||||||
must have either a value of 0 (the default) to disable the thread time
|
100). On macOS, this option must have either a value of 0 to disable the thread
|
||||||
constraint policy or 1 for the policy to be enabled. Other systems do not
|
time constraint policy or 1 for the policy to be enabled. Other systems do not
|
||||||
support this option.
|
support this option. The default value is 0.
|
||||||
|
|
||||||
*-m*::
|
*-m*::
|
||||||
This option will lock *chronyd* into RAM so that it will never be paged out.
|
This option will lock *chronyd* into RAM so that it will never be paged out.
|
||||||
This mode is only supported on Linux.
|
This mode is only supported on Linux, FreeBSD, NetBSD, and illumos.
|
||||||
|
|
||||||
*-v*::
|
*-x*::
|
||||||
|
This option disables the control of the system clock. *chronyd* will not try to
|
||||||
|
make any adjustments of the clock. It will assume the clock is free running and
|
||||||
|
still track its offset and frequency relative to the estimated true time. This
|
||||||
|
option allows *chronyd* to be started without the capability to adjust or set
|
||||||
|
the system clock (e.g. in some containers) to operate as an NTP server.
|
||||||
|
|
||||||
|
*-v*, *--version*::
|
||||||
With this option *chronyd* will print version number to the terminal and exit.
|
With this option *chronyd* will print version number to the terminal and exit.
|
||||||
|
|
||||||
|
*-h*, *--help*::
|
||||||
|
With this option *chronyd* will print a help message to the terminal and exit.
|
||||||
|
|
||||||
== FILES
|
== FILES
|
||||||
|
|
||||||
_@SYSCONFDIR@/chrony.conf_
|
_@SYSCONFDIR@/chrony.conf_
|
||||||
@@ -161,4 +219,4 @@ https://chrony.tuxfamily.org/.
|
|||||||
|
|
||||||
== AUTHORS
|
== AUTHORS
|
||||||
|
|
||||||
chrony was written by Richard Curnow, Miroslav Lichvar and others.
|
chrony was written by Richard Curnow, Miroslav Lichvar, and others.
|
||||||
|
|||||||
895
doc/faq.adoc
895
doc/faq.adoc
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,26 @@ The software is distributed as source code which has to be compiled. The source
|
|||||||
code is supplied in the form of a gzipped tar file, which unpacks to a
|
code is supplied in the form of a gzipped tar file, which unpacks to a
|
||||||
subdirectory identifying the name and version of the program.
|
subdirectory identifying the name and version of the program.
|
||||||
|
|
||||||
|
A C compiler (e.g. `gcc` or `clang`) and GNU Make are needed to build `chrony`.
|
||||||
|
The following libraries with their development files, and programs, are needed
|
||||||
|
to enable optional features:
|
||||||
|
|
||||||
|
* pkg-config: detection of development libraries
|
||||||
|
* Nettle, GnuTLS, NSS, or LibTomCrypt: secure hash functions (`SECHASH`)
|
||||||
|
* libcap: dropping root privileges on Linux (`DROPROOT`)
|
||||||
|
* libseccomp: system call filter on Linux (`SCFILTER`)
|
||||||
|
* GnuTLS and Nettle: Network Time Security (`NTS`)
|
||||||
|
* Editline: line editing in `chronyc` (`READLINE`)
|
||||||
|
* timepps.h header: PPS reference clock
|
||||||
|
* Asciidoctor: documentation in HTML format
|
||||||
|
* Bash: test suite
|
||||||
|
|
||||||
|
The following programs are needed when building `chrony` from the git
|
||||||
|
repository instead of a released tar file:
|
||||||
|
|
||||||
|
* Asciidoctor: manual pages
|
||||||
|
* Bison: parser for chronyc settime command
|
||||||
|
|
||||||
After unpacking the source code, change directory into it, and type
|
After unpacking the source code, change directory into it, and type
|
||||||
|
|
||||||
----
|
----
|
||||||
@@ -29,8 +49,8 @@ After unpacking the source code, change directory into it, and type
|
|||||||
----
|
----
|
||||||
|
|
||||||
This is a shell script that automatically determines the system type. There is
|
This is a shell script that automatically determines the system type. There is
|
||||||
a single optional parameter, `--prefix` which indicates the directory tree
|
an optional parameter `--prefix`, which indicates the directory tree where the
|
||||||
where the software should be installed. For example,
|
software should be installed. For example,
|
||||||
|
|
||||||
----
|
----
|
||||||
./configure --prefix=/opt/free
|
./configure --prefix=/opt/free
|
||||||
@@ -40,11 +60,11 @@ will install the `chronyd` daemon into `/opt/free/sbin` and the `chronyc`
|
|||||||
control program into `/opt/free/bin`. The default value for the prefix is
|
control program into `/opt/free/bin`. The default value for the prefix is
|
||||||
`/usr/local`.
|
`/usr/local`.
|
||||||
|
|
||||||
The configure script assumes you want to use gcc as your compiler. If you want
|
The `configure` script assumes you want to use `gcc` as your compiler. If you
|
||||||
to use a different compiler, you can configure this way:
|
want to use a different compiler, you can configure this way:
|
||||||
|
|
||||||
----
|
----
|
||||||
CC=cc CFLAGS=-O ./configure --prefix=/opt/free
|
CC=cc ./configure --prefix=/opt/free
|
||||||
----
|
----
|
||||||
|
|
||||||
for Bourne-family shells, or
|
for Bourne-family shells, or
|
||||||
@@ -63,11 +83,26 @@ shown. Otherwise, `Makefile` will be generated.
|
|||||||
On Linux, if development files for the libcap library are available, `chronyd`
|
On Linux, if development files for the libcap library are available, `chronyd`
|
||||||
will be built with support for dropping root privileges. On other systems no
|
will be built with support for dropping root privileges. On other systems no
|
||||||
extra library is needed. The default user which `chronyd` should run as can be
|
extra library is needed. The default user which `chronyd` should run as can be
|
||||||
specified with the `--with-user` option of the configure script.
|
specified with the `--with-user` option of the `configure` script.
|
||||||
|
|
||||||
If development files for the editline or readline library are available,
|
If development files for the POSIX threads library are available, `chronyd`
|
||||||
|
will be built with support for asynchronous resolving of hostnames specified in
|
||||||
|
the `server`, `peer`, and `pool` directives. This allows `chronyd` operating as
|
||||||
|
a server to respond to client requests when resolving a hostname. If you don't
|
||||||
|
want to enable the support, specify the `--disable-asyncdns` flag to
|
||||||
|
`configure`.
|
||||||
|
|
||||||
|
If development files for the https://www.lysator.liu.se/~nisse/nettle/[Nettle],
|
||||||
|
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS[NSS], or
|
||||||
|
https://www.libtom.net/LibTomCrypt/[libtomcrypt] library are available,
|
||||||
|
`chronyd` will be built with support for other cryptographic hash functions
|
||||||
|
than MD5, which can be used for NTP authentication with a symmetric key. If you
|
||||||
|
don't want to enable the support, specify the `--disable-sechash` flag to
|
||||||
|
`configure`.
|
||||||
|
|
||||||
|
If development files for the editline library are available,
|
||||||
`chronyc` will be built with line editing support. If you don't want this,
|
`chronyc` will be built with line editing support. If you don't want this,
|
||||||
specify the `--disable-readline` flag to configure.
|
specify the `--disable-readline` flag to `configure`.
|
||||||
|
|
||||||
If a `timepps.h` header is available (e.g. from the
|
If a `timepps.h` header is available (e.g. from the
|
||||||
http://linuxpps.org[LinuxPPS project]), `chronyd` will be built with PPS API
|
http://linuxpps.org[LinuxPPS project]), `chronyd` will be built with PPS API
|
||||||
@@ -75,6 +110,9 @@ reference clock driver. If the header is installed in a location that isn't
|
|||||||
normally searched by the compiler, you can add it to the searched locations by
|
normally searched by the compiler, you can add it to the searched locations by
|
||||||
setting the `CPPFLAGS` variable to `-I/path/to/timepps`.
|
setting the `CPPFLAGS` variable to `-I/path/to/timepps`.
|
||||||
|
|
||||||
|
The `--help` option can be specified to `configure` to print all options
|
||||||
|
supported by the script.
|
||||||
|
|
||||||
Now type
|
Now type
|
||||||
|
|
||||||
----
|
----
|
||||||
@@ -122,51 +160,24 @@ unprivileged user for `chronyd` and specify it with the `-u` command-line
|
|||||||
option or the `user` directive in the configuration file, or set the default
|
option or the `user` directive in the configuration file, or set the default
|
||||||
user with the `--with-user` configure option before building.
|
user with the `--with-user` configure option before building.
|
||||||
|
|
||||||
== Support for line editing libraries
|
== Support for system call filtering
|
||||||
|
|
||||||
`chronyc` can be built with support for line editing, this allows you to use
|
`chronyd` can be built with support for the Linux secure computing (seccomp)
|
||||||
the cursor keys to replay and edit old commands. Two libraries are supported
|
facility. This requires development files for the
|
||||||
which provide such functionality, editline and GNU readline.
|
https://github.com/seccomp/libseccomp[libseccomp] library and the
|
||||||
|
`--enable-scfilter` option specified to `configure`. The `-F` option of
|
||||||
Please note that readline since version 6.0 is licensed under GPLv3+ which is
|
`chronyd` will enable a system call filter, which should significantly reduce
|
||||||
incompatible with chrony's license GPLv2. You should use editline instead if
|
the kernel attack surface and possibly prevent kernel exploits from `chronyd`
|
||||||
you don't want to use older readline versions.
|
if it is compromised.
|
||||||
|
|
||||||
The configure script will automatically enable the line editing support if one
|
|
||||||
of the supported libraries is available. If they are both available, the
|
|
||||||
editline library will be used.
|
|
||||||
|
|
||||||
If you don't want to use it (in which case chronyc will use a minimal command
|
|
||||||
line interface), invoke configure like this:
|
|
||||||
|
|
||||||
----
|
|
||||||
./configure --disable-readline other-options...
|
|
||||||
----
|
|
||||||
|
|
||||||
If you have editline, readline or ncurses installed in locations that aren't
|
|
||||||
normally searched by the compiler and linker, you need to use extra options:
|
|
||||||
|
|
||||||
`--with-readline-includes=directory_name`::
|
|
||||||
This defines the name of the directory above the one where `readline.h` is.
|
|
||||||
`readline.h` is assumed to be in `editline` or `readline` subdirectory of the
|
|
||||||
named directory.
|
|
||||||
|
|
||||||
`--with-readline-library=directory_name`::
|
|
||||||
This defines the directory containing the `libedit.a` or `libedit.so` file,
|
|
||||||
or `libreadline.a` or `libreadline.so` file.
|
|
||||||
|
|
||||||
`--with-ncurses-library=directory_name`::
|
|
||||||
This defines the directory containing the `libncurses.a` or `libncurses.so`
|
|
||||||
file.
|
|
||||||
|
|
||||||
== Extra options for package builders
|
== Extra options for package builders
|
||||||
|
|
||||||
The configure and make procedures have some extra options that may be useful if
|
The `configure` and `make` procedures have some extra options that may be
|
||||||
you are building a distribution package for chrony.
|
useful if you are building a distribution package for `chrony`.
|
||||||
|
|
||||||
The `--mandir=DIR` option to configure specifies an install directory for the
|
The `--mandir=DIR` option to `configure` specifies an installation directory
|
||||||
man pages. This overrides the `man` subdirectory of the argument to the
|
for the man pages. This overrides the `man` subdirectory of the argument to the
|
||||||
--prefix option.
|
`--prefix` option.
|
||||||
|
|
||||||
----
|
----
|
||||||
./configure --prefix=/usr --mandir=/usr/share/man
|
./configure --prefix=/usr --mandir=/usr/share/man
|
||||||
@@ -174,8 +185,8 @@ man pages. This overrides the `man` subdirectory of the argument to the
|
|||||||
|
|
||||||
to set both options together.
|
to set both options together.
|
||||||
|
|
||||||
The final option is the `DESTDIR` option to the make command. For example, you
|
The final option is the `DESTDIR` option to the `make` command. For example,
|
||||||
could use the commands
|
you could use the commands
|
||||||
|
|
||||||
----
|
----
|
||||||
./configure --prefix=/usr --mandir=/usr/share/man
|
./configure --prefix=/usr --mandir=/usr/share/man
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Wait for chrony to synchronize system clock
|
Description=Wait for chrony to synchronize system clock
|
||||||
|
Documentation=man:chronyc(1)
|
||||||
After=chronyd.service
|
After=chronyd.service
|
||||||
Requires=chronyd.service
|
Requires=chronyd.service
|
||||||
Before=time-sync.target
|
Before=time-sync.target
|
||||||
@@ -7,11 +8,40 @@ Wants=time-sync.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
# Wait up to ~10 minutes for chronyd to synchronize and the remaining
|
# Wait for chronyd to update the clock and the remaining
|
||||||
# clock correction to be less than 0.1 seconds
|
# correction to be less than 0.1 seconds
|
||||||
ExecStart=/usr/bin/chronyc waitsync 600 0.1 0.0 1
|
ExecStart=/usr/bin/chronyc -h 127.0.0.1,::1 waitsync 0 0.1 0.0 1
|
||||||
|
# Wait for at most 3 minutes
|
||||||
|
TimeoutStartSec=180
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
StandardOutput=null
|
StandardOutput=null
|
||||||
|
|
||||||
|
CapabilityBoundingSet=
|
||||||
|
DevicePolicy=closed
|
||||||
|
DynamicUser=yes
|
||||||
|
IPAddressAllow=localhost
|
||||||
|
IPAddressDeny=any
|
||||||
|
LockPersonality=yes
|
||||||
|
MemoryDenyWriteExecute=yes
|
||||||
|
PrivateDevices=yes
|
||||||
|
PrivateUsers=yes
|
||||||
|
ProcSubset=pid
|
||||||
|
ProtectClock=yes
|
||||||
|
ProtectControlGroups=yes
|
||||||
|
ProtectHome=yes
|
||||||
|
ProtectHostname=yes
|
||||||
|
ProtectKernelLogs=yes
|
||||||
|
ProtectKernelModules=yes
|
||||||
|
ProtectKernelTunables=yes
|
||||||
|
ProtectProc=invisible
|
||||||
|
ProtectSystem=strict
|
||||||
|
RestrictAddressFamilies=AF_INET AF_INET6
|
||||||
|
RestrictNamespaces=yes
|
||||||
|
RestrictRealtime=yes
|
||||||
|
SystemCallArchitectures=native
|
||||||
|
SystemCallFilter=@system-service
|
||||||
|
SystemCallFilter=~@privileged @resources
|
||||||
|
UMask=0777
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ pool pool.ntp.org iburst
|
|||||||
# Record the rate at which the system clock gains/losses time.
|
# Record the rate at which the system clock gains/losses time.
|
||||||
driftfile /var/lib/chrony/drift
|
driftfile /var/lib/chrony/drift
|
||||||
|
|
||||||
# In first three updates step the system clock instead of slew
|
# Allow the system clock to be stepped in the first three updates
|
||||||
# if the adjustment is larger than 1 second.
|
# if its offset is larger than 1 second.
|
||||||
makestep 1.0 3
|
makestep 1.0 3
|
||||||
|
|
||||||
# Enable kernel synchronization of the real-time clock (RTC).
|
# Enable kernel synchronization of the real-time clock (RTC).
|
||||||
|
|||||||
@@ -1,26 +1,45 @@
|
|||||||
# Use public servers from the pool.ntp.org project.
|
# Use public servers from the pool.ntp.org project.
|
||||||
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
|
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
|
||||||
pool pool.ntp.org iburst
|
pool pool.ntp.org iburst
|
||||||
|
|
||||||
# Record the rate at which the system clock gains/losses time.
|
# Record the rate at which the system clock gains/losses time.
|
||||||
driftfile /var/lib/chrony/drift
|
driftfile /var/lib/chrony/drift
|
||||||
|
|
||||||
# In first three updates step the system clock instead of slew
|
# Allow the system clock to be stepped in the first three updates
|
||||||
# if the adjustment is larger than 1 second.
|
# if its offset is larger than 1 second.
|
||||||
makestep 1.0 3
|
makestep 1.0 3
|
||||||
|
|
||||||
# Enable kernel synchronization of the real-time clock (RTC).
|
# Enable kernel synchronization of the real-time clock (RTC).
|
||||||
rtcsync
|
rtcsync
|
||||||
|
|
||||||
# Allow NTP client access from local network.
|
# Enable hardware timestamping on all interfaces that support it.
|
||||||
#allow 192.168/16
|
#hwtimestamp *
|
||||||
|
|
||||||
# Serve time even if not synchronized to any NTP server.
|
# Increase the minimum number of selectable sources required to adjust
|
||||||
|
# the system clock.
|
||||||
|
#minsources 2
|
||||||
|
|
||||||
|
# Allow NTP client access from local network.
|
||||||
|
#allow 192.168.0.0/16
|
||||||
|
|
||||||
|
# Serve time even if not synchronized to a time source.
|
||||||
#local stratum 10
|
#local stratum 10
|
||||||
|
|
||||||
|
# Require authentication (nts or key option) for all NTP sources.
|
||||||
|
#authselectmode require
|
||||||
|
|
||||||
# Specify file containing keys for NTP authentication.
|
# Specify file containing keys for NTP authentication.
|
||||||
#keyfile /etc/chrony.keys
|
#keyfile /etc/chrony.keys
|
||||||
|
|
||||||
|
# Save NTS keys and cookies.
|
||||||
|
ntsdumpdir /var/lib/chrony
|
||||||
|
|
||||||
|
# Insert/delete leap seconds by slewing instead of stepping.
|
||||||
|
#leapsecmode slew
|
||||||
|
|
||||||
|
# Get TAI-UTC offset and leap seconds from the system tz database.
|
||||||
|
#leapsectz right/UTC
|
||||||
|
|
||||||
# Specify directory for log files.
|
# Specify directory for log files.
|
||||||
logdir /var/log/chrony
|
logdir /var/log/chrony
|
||||||
|
|
||||||
|
|||||||
@@ -33,42 +33,44 @@
|
|||||||
|
|
||||||
! pool pool.ntp.org iburst
|
! pool pool.ntp.org iburst
|
||||||
|
|
||||||
# However, for dial-up use you probably want these instead. The word
|
|
||||||
# 'offline' means that the server is not visible at boot time. Use
|
|
||||||
# chronyc's 'online' command to tell chronyd that these servers have
|
|
||||||
# become visible after you go on-line.
|
|
||||||
|
|
||||||
! server foo.example.net offline
|
|
||||||
! server bar.example.net offline
|
|
||||||
! server baz.example.net offline
|
|
||||||
|
|
||||||
! pool pool.ntp.org offline
|
|
||||||
|
|
||||||
# You may want to specify NTP 'peers' instead. If you run a network
|
|
||||||
# with a lot of computers and want several computers running chrony to
|
|
||||||
# have the 'front-line' interface to the public NTP servers, you can
|
|
||||||
# 'peer' these machines together to increase robustness.
|
|
||||||
|
|
||||||
! peer foo.example.net
|
|
||||||
|
|
||||||
# There are other options to the 'server' and 'peer' directives that you
|
|
||||||
# might want to use. For example, you can ignore measurements whose
|
|
||||||
# round-trip-time is too large (indicating that the measurement is
|
|
||||||
# probably useless, because you don't know which way the measurement
|
|
||||||
# message got held up.) Consult the full documentation for details.
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### AVOIDING POTENTIALLY BOGUS CHANGES TO YOUR CLOCK
|
### AVOIDING POTENTIALLY BOGUS CHANGES TO YOUR CLOCK
|
||||||
#
|
#
|
||||||
# To avoid changes being made to your computer's gain/loss compensation
|
# To avoid changes being made to your computer's gain/loss compensation
|
||||||
# when the measurement history is too erratic, you might want to enable
|
# when the measurement history is too erratic, you might want to enable
|
||||||
# one of the following lines. The first seems good for dial-up (or
|
# one of the following lines. The first seems good with servers on the
|
||||||
# other high-latency connections like slow leased lines), the second
|
# Internet, the second seems OK for a LAN environment.
|
||||||
# seems OK for a LAN environment.
|
|
||||||
|
|
||||||
! maxupdateskew 100
|
! maxupdateskew 100
|
||||||
! maxupdateskew 5
|
! maxupdateskew 5
|
||||||
|
|
||||||
|
# If you want to increase the minimum number of selectable sources
|
||||||
|
# required to update the system clock in order to make the
|
||||||
|
# synchronisation more reliable, uncomment (and edit) the following
|
||||||
|
# line.
|
||||||
|
|
||||||
|
! minsources 2
|
||||||
|
|
||||||
|
# If your computer has a good stable clock (e.g. it is not a virtual
|
||||||
|
# machine), you might also want to reduce the maximum assumed drift
|
||||||
|
# (frequency error) of the clock (the value is specified in ppm).
|
||||||
|
|
||||||
|
! maxdrift 100
|
||||||
|
|
||||||
|
# By default, chronyd allows synchronisation to an unauthenticated NTP
|
||||||
|
# source (i.e. specified without the nts and key options) if it agrees with
|
||||||
|
# a majority of authenticated NTP sources, or if no authenticated source is
|
||||||
|
# specified. If you don't want chronyd to ever synchronise to an
|
||||||
|
# unauthenticated NTP source, uncomment the first from the following lines.
|
||||||
|
# If you don't want to synchronise to an unauthenticated NTP source only
|
||||||
|
# when an authenticated source is specified, uncomment the second line.
|
||||||
|
# If you want chronyd to ignore authentication in the source selection,
|
||||||
|
# uncomment the third line.
|
||||||
|
|
||||||
|
! authselectmode require
|
||||||
|
! authselectmode prefer
|
||||||
|
! authselectmode ignore
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### FILENAMES ETC
|
### FILENAMES ETC
|
||||||
# Chrony likes to keep information about your computer's clock in files.
|
# Chrony likes to keep information about your computer's clock in files.
|
||||||
@@ -84,22 +86,37 @@ driftfile /var/lib/chrony/drift
|
|||||||
|
|
||||||
! keyfile /etc/chrony.keys
|
! keyfile /etc/chrony.keys
|
||||||
|
|
||||||
|
# If you specify an NTP server with the nts option to enable authentication
|
||||||
|
# with the Network Time Security (NTS) mechanism, or enable server NTS with
|
||||||
|
# the ntsservercert and ntsserverkey directives below, the following line will
|
||||||
|
# allow the client/server to save the NTS keys and cookies in order to reduce
|
||||||
|
# the number of key establishments (NTS-KE sessions).
|
||||||
|
|
||||||
|
ntsdumpdir /var/lib/chrony
|
||||||
|
|
||||||
|
# If chronyd is configured to act as an NTP server and you want to enable NTS
|
||||||
|
# for its clients, you will need a TLS certificate and private key. Uncomment
|
||||||
|
# and edit the following lines to specify the locations of the certificate and
|
||||||
|
# key.
|
||||||
|
|
||||||
|
! ntsservercert /etc/.../foo.example.net.crt
|
||||||
|
! ntsserverkey /etc/.../foo.example.net.key
|
||||||
|
|
||||||
# chronyd can save the measurement history for the servers to files when
|
# chronyd can save the measurement history for the servers to files when
|
||||||
# it it exits. This is useful in 2 situations:
|
# it exits. This is useful in 2 situations:
|
||||||
#
|
#
|
||||||
# 1. On Linux, if you stop chronyd and restart it with '-r' (e.g. after
|
# 1. If you stop chronyd and restart it with the '-r' option (e.g. after
|
||||||
# an upgrade), the old measurements will still be relevant when chronyd
|
# an upgrade), the old measurements will still be relevant when chronyd
|
||||||
# is restarted. This will reduce the time needed to get accurate
|
# is restarted. This will reduce the time needed to get accurate
|
||||||
# gain/loss measurements, especially with a dial-up link.
|
# gain/loss measurements.
|
||||||
#
|
#
|
||||||
# 2. Again on Linux, if you use the RTC support and start chronyd with
|
# 2. On Linux, if you use the RTC support and start chronyd with
|
||||||
# '-r -s' on bootup, measurements from the last boot will still be
|
# '-r -s' on bootup, measurements from the last boot will still be
|
||||||
# useful (the real time clock is used to 'flywheel' chronyd between
|
# useful (the real time clock is used to 'flywheel' chronyd between
|
||||||
# boots).
|
# boots).
|
||||||
#
|
#
|
||||||
# Enable these two options to use this.
|
# Uncomment the following line to use this.
|
||||||
|
|
||||||
! dumponexit
|
|
||||||
! dumpdir /var/lib/chrony
|
! dumpdir /var/lib/chrony
|
||||||
|
|
||||||
# chronyd writes its process ID to a file. If you try to start a second
|
# chronyd writes its process ID to a file. If you try to start a second
|
||||||
@@ -107,7 +124,13 @@ driftfile /var/lib/chrony/drift
|
|||||||
# still running and bail out. If you want to change the path to the PID
|
# still running and bail out. If you want to change the path to the PID
|
||||||
# file, uncomment this line and edit it. The default path is shown.
|
# file, uncomment this line and edit it. The default path is shown.
|
||||||
|
|
||||||
! pidfile /var/run/chronyd.pid
|
! pidfile /var/run/chrony/chronyd.pid
|
||||||
|
|
||||||
|
# If the system timezone database is kept up to date and includes the
|
||||||
|
# right/UTC timezone, chronyd can use it to determine the current
|
||||||
|
# TAI-UTC offset and when will the next leap second occur.
|
||||||
|
|
||||||
|
! leapsectz right/UTC
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### INITIAL CLOCK CORRECTION
|
### INITIAL CLOCK CORRECTION
|
||||||
@@ -122,6 +145,18 @@ driftfile /var/lib/chrony/drift
|
|||||||
|
|
||||||
! makestep 1.0 3
|
! makestep 1.0 3
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
### LEAP SECONDS
|
||||||
|
# A leap second is an occasional one-second correction of the UTC
|
||||||
|
# time scale. By default, chronyd tells the kernel to insert/delete
|
||||||
|
# the leap second, which makes a backward/forward step to correct the
|
||||||
|
# clock for it. As with the makestep directive, this jump can upset
|
||||||
|
# some applications. If you prefer chronyd to make a gradual
|
||||||
|
# correction, causing the clock to be off for a longer time, uncomment
|
||||||
|
# the following line.
|
||||||
|
|
||||||
|
! leapsecmode slew
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### LOGGING
|
### LOGGING
|
||||||
# If you want to log information about the time measurements chronyd has
|
# If you want to log information about the time measurements chronyd has
|
||||||
@@ -141,8 +176,6 @@ driftfile /var/lib/chrony/drift
|
|||||||
#######################################################################
|
#######################################################################
|
||||||
### ACTING AS AN NTP SERVER
|
### ACTING AS AN NTP SERVER
|
||||||
# You might want the computer to be an NTP server for other computers.
|
# You might want the computer to be an NTP server for other computers.
|
||||||
# e.g. you might be running chronyd on a dial-up machine that has a LAN
|
|
||||||
# sitting behind it with several 'satellite' computers on it.
|
|
||||||
#
|
#
|
||||||
# By default, chronyd does not allow any clients to access it. You need
|
# By default, chronyd does not allow any clients to access it. You need
|
||||||
# to explicitly enable access using 'allow' and 'deny' directives.
|
# to explicitly enable access using 'allow' and 'deny' directives.
|
||||||
@@ -158,15 +191,6 @@ driftfile /var/lib/chrony/drift
|
|||||||
# You can have as many allow and deny directives as you need. The order
|
# You can have as many allow and deny directives as you need. The order
|
||||||
# is unimportant.
|
# is unimportant.
|
||||||
|
|
||||||
# If you want chronyd to act as an NTP broadcast server, enable and edit
|
|
||||||
# (and maybe copy) the following line. This means that a broadcast
|
|
||||||
# packet is sent to the address 192.168.1.255 every 60 seconds. The
|
|
||||||
# address MUST correspond to the broadcast address of one of the network
|
|
||||||
# interfaces on your machine. If you have multiple network interfaces,
|
|
||||||
# add a broadcast line for each.
|
|
||||||
|
|
||||||
! broadcast 60 192.168.1.255
|
|
||||||
|
|
||||||
# If you want to present your computer's time for others to synchronise
|
# If you want to present your computer's time for others to synchronise
|
||||||
# with, even if you don't seem to be synchronised to any NTP servers
|
# with, even if you don't seem to be synchronised to any NTP servers
|
||||||
# yourself, enable the following line. The value 10 may be varied
|
# yourself, enable the following line. The value 10 may be varied
|
||||||
@@ -181,13 +205,12 @@ driftfile /var/lib/chrony/drift
|
|||||||
# machine accesses it. The information can be accessed by the 'clients'
|
# machine accesses it. The information can be accessed by the 'clients'
|
||||||
# command of chronyc. You can disable this facility by uncommenting the
|
# command of chronyc. You can disable this facility by uncommenting the
|
||||||
# following line. This will save a bit of memory if you have many
|
# following line. This will save a bit of memory if you have many
|
||||||
# clients.
|
# clients and it will also disable support for the interleaved mode.
|
||||||
|
|
||||||
! noclientlog
|
! noclientlog
|
||||||
|
|
||||||
# The clientlog size is limited to 512KB by default. If you have many
|
# The clientlog size is limited to 512KB by default. If you have many
|
||||||
# clients, especially in many different subnets, you might want to
|
# clients, you might want to increase the limit.
|
||||||
# increase the limit.
|
|
||||||
|
|
||||||
! clientloglimit 4194304
|
! clientloglimit 4194304
|
||||||
|
|
||||||
@@ -196,7 +219,7 @@ driftfile /var/lib/chrony/drift
|
|||||||
# clients that are sending requests too frequently, uncomment and edit
|
# clients that are sending requests too frequently, uncomment and edit
|
||||||
# the following line.
|
# the following line.
|
||||||
|
|
||||||
! limitrate interval 3 burst 8
|
! ratelimit interval 3 burst 8
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### REPORTING BIG CLOCK CHANGES
|
### REPORTING BIG CLOCK CHANGES
|
||||||
@@ -243,7 +266,17 @@ driftfile /var/lib/chrony/drift
|
|||||||
# Rate limiting can be enabled also for command packets. (Note,
|
# Rate limiting can be enabled also for command packets. (Note,
|
||||||
# commands from localhost are never limited.)
|
# commands from localhost are never limited.)
|
||||||
|
|
||||||
! cmdratelimit interval 1 burst 16
|
! cmdratelimit interval -4 burst 16
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
### HARDWARE TIMESTAMPING
|
||||||
|
# On Linux, if the network interface controller and its driver support
|
||||||
|
# hardware timestamping, it can significantly improve the accuracy of
|
||||||
|
# synchronisation. It can be enabled on specified interfaces only, or it
|
||||||
|
# can be enabled on all interfaces that support it.
|
||||||
|
|
||||||
|
! hwtimestamp eth0
|
||||||
|
! hwtimestamp *
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### REAL TIME CLOCK
|
### REAL TIME CLOCK
|
||||||
@@ -274,6 +307,12 @@ driftfile /var/lib/chrony/drift
|
|||||||
|
|
||||||
! rtcdevice /dev/misc/rtc
|
! rtcdevice /dev/misc/rtc
|
||||||
|
|
||||||
|
# Alternatively, if not using the -s option, this directive can be used
|
||||||
|
# to enable a mode in which the RTC is periodically set to the system
|
||||||
|
# time, with no tracking of its drift.
|
||||||
|
|
||||||
|
! rtcsync
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### REAL TIME SCHEDULER
|
### REAL TIME SCHEDULER
|
||||||
# This directive tells chronyd to use the real-time FIFO scheduler with the
|
# This directive tells chronyd to use the real-time FIFO scheduler with the
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# This is an example chrony keys file. It is used for NTP authentication with
|
# This is an example chrony keys file. It enables authentication of NTP
|
||||||
# symmetric keys. It should be readable only by root or the user to which
|
# packets with symmetric keys when its location is specified by the keyfile
|
||||||
# chronyd is configured to switch to after start.
|
# directive in chrony.conf(5). It should be readable only by root and the
|
||||||
|
# user under which chronyd is running.
|
||||||
#
|
#
|
||||||
# Don't use the example keys! It's recommended to generate random keys using
|
# Don't use the example keys! It's recommended to generate random keys using
|
||||||
# the chronyc keygen command.
|
# the chronyc keygen command.
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# This is a NetworkManager dispatcher script for chronyd to set its NTP sources
|
|
||||||
# online/offline when a default route is configured/removed on the system.
|
|
||||||
|
|
||||||
export LC_ALL=C
|
|
||||||
|
|
||||||
if [ "$2" = "up" ]; then
|
|
||||||
/sbin/ip route list dev "$1" | grep -q '^default' &&
|
|
||||||
/usr/bin/chronyc online > /dev/null 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$2" = "down" ]; then
|
|
||||||
/sbin/ip route list | grep -q '^default' ||
|
|
||||||
/usr/bin/chronyc offline > /dev/null 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
49
examples/chrony.nm-dispatcher.dhcp
Normal file
49
examples/chrony.nm-dispatcher.dhcp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# This is a NetworkManager dispatcher script for chronyd to update
|
||||||
|
# its NTP sources with servers from DHCP options passed by NetworkManager
|
||||||
|
# in the DHCP4_NTP_SERVERS and DHCP6_DHCP6_NTP_SERVERS environment variables.
|
||||||
|
|
||||||
|
export LC_ALL=C
|
||||||
|
|
||||||
|
interface=$1
|
||||||
|
action=$2
|
||||||
|
|
||||||
|
chronyc=/usr/bin/chronyc
|
||||||
|
server_options=iburst
|
||||||
|
server_dir=/var/run/chrony-dhcp
|
||||||
|
|
||||||
|
dhcp_server_file=$server_dir/$interface.sources
|
||||||
|
dhcp_ntp_servers="$DHCP4_NTP_SERVERS $DHCP6_DHCP6_NTP_SERVERS"
|
||||||
|
|
||||||
|
add_servers_from_dhcp() {
|
||||||
|
rm -f "$dhcp_server_file"
|
||||||
|
for server in $dhcp_ntp_servers; do
|
||||||
|
# Check for invalid characters (from the DHCPv6 NTP FQDN suboption)
|
||||||
|
len1=$(printf '%s' "$server" | wc -c)
|
||||||
|
len2=$(printf '%s' "$server" | tr -d -c 'A-Za-z0-9:.-' | wc -c)
|
||||||
|
if [ "$len1" -ne "$len2" ] || [ "$len2" -lt 1 ] || [ "$len2" -gt 255 ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'server %s %s\n' "$server" "$server_options" >> "$dhcp_server_file"
|
||||||
|
done
|
||||||
|
$chronyc reload sources > /dev/null 2>&1 || :
|
||||||
|
}
|
||||||
|
|
||||||
|
clear_servers_from_dhcp() {
|
||||||
|
if [ -f "$dhcp_server_file" ]; then
|
||||||
|
rm -f "$dhcp_server_file"
|
||||||
|
$chronyc reload sources > /dev/null 2>&1 || :
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir -p $server_dir
|
||||||
|
|
||||||
|
case "$action" in
|
||||||
|
up|dhcp4-change|dhcp6-change)
|
||||||
|
add_servers_from_dhcp;;
|
||||||
|
down)
|
||||||
|
clear_servers_from_dhcp;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
27
examples/chrony.nm-dispatcher.onoffline
Normal file
27
examples/chrony.nm-dispatcher.onoffline
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# This is a NetworkManager dispatcher / networkd-dispatcher script for
|
||||||
|
# chronyd to set its NTP sources online or offline when a network interface
|
||||||
|
# is configured or removed
|
||||||
|
|
||||||
|
export LC_ALL=C
|
||||||
|
|
||||||
|
chronyc=/usr/bin/chronyc
|
||||||
|
|
||||||
|
# For NetworkManager consider only selected events
|
||||||
|
if [ $# -ge 2 ]; then
|
||||||
|
case "$2" in
|
||||||
|
up|down|connectivity-change)
|
||||||
|
;;
|
||||||
|
dhcp6-change)
|
||||||
|
# No other action is reported for routable IPv6
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 0;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Note: for networkd-dispatcher routable.d ~= on and off.d ~= off
|
||||||
|
|
||||||
|
$chronyc onoffline > /dev/null 2>&1
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
%global chrony_version @@VERSION@@
|
|
||||||
%if 0%(echo %{chrony_version} | grep -q pre && echo 1)
|
|
||||||
%global prerelease %(echo %{chrony_version} | sed 's/.*-//')
|
|
||||||
%endif
|
|
||||||
Summary: An NTP client/server
|
|
||||||
Name: chrony
|
|
||||||
Version: %(echo %{chrony_version} | sed 's/-.*//')
|
|
||||||
Release: %{!?prerelease:1}%{?prerelease:0.1.%{prerelease}}
|
|
||||||
Source: chrony-%{version}%{?prerelease:-%{prerelease}}.tar.gz
|
|
||||||
License: GPLv2
|
|
||||||
Group: Applications/Utilities
|
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(id -u -n)
|
|
||||||
Requires: info
|
|
||||||
|
|
||||||
%description
|
|
||||||
chrony is a client and server for the Network Time Protocol (NTP).
|
|
||||||
This program keeps your computer's clock accurate. It was specially
|
|
||||||
designed to support systems with intermittent Internet connections,
|
|
||||||
but it also works well in permanently connected environments. It can
|
|
||||||
also use hardware reference clocks, the system real-time clock, or
|
|
||||||
manual input as time references.
|
|
||||||
|
|
||||||
%prep
|
|
||||||
%setup -q -n %{name}-%{version}%{?prerelease:-%{prerelease}}
|
|
||||||
|
|
||||||
%build
|
|
||||||
./configure \
|
|
||||||
--prefix=%{_prefix} \
|
|
||||||
--bindir=%{_bindir} \
|
|
||||||
--sbindir=%{_sbindir} \
|
|
||||||
--infodir=%{_infodir} \
|
|
||||||
--mandir=%{_mandir}
|
|
||||||
make
|
|
||||||
make chrony.txt
|
|
||||||
make chrony.info
|
|
||||||
|
|
||||||
%install
|
|
||||||
rm -rf $RPM_BUILD_ROOT
|
|
||||||
make install DESTDIR=$RPM_BUILD_ROOT
|
|
||||||
rm -rf $RPM_BUILD_ROOT%{_docdir}
|
|
||||||
mkdir -p $RPM_BUILD_ROOT%{_infodir}
|
|
||||||
cp chrony.info* $RPM_BUILD_ROOT%{_infodir}
|
|
||||||
|
|
||||||
%files
|
|
||||||
%{_sbindir}/chronyd
|
|
||||||
%{_bindir}/chronyc
|
|
||||||
%{_infodir}/chrony.info*
|
|
||||||
%{_mandir}/man1/chronyc.1.gz
|
|
||||||
%{_mandir}/man5/chrony.conf.5.gz
|
|
||||||
%{_mandir}/man8/chronyd.8.gz
|
|
||||||
%doc README
|
|
||||||
%doc chrony.txt
|
|
||||||
%doc COPYING
|
|
||||||
%doc examples/chrony.conf.example*
|
|
||||||
%doc examples/chrony.keys.example
|
|
||||||
|
|
||||||
@@ -1,13 +1,49 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=NTP client/server
|
Description=NTP client/server
|
||||||
|
Documentation=man:chronyd(8) man:chrony.conf(5)
|
||||||
After=ntpdate.service sntp.service ntpd.service
|
After=ntpdate.service sntp.service ntpd.service
|
||||||
Conflicts=ntpd.service systemd-timesyncd.service
|
Conflicts=ntpd.service systemd-timesyncd.service
|
||||||
|
ConditionCapability=CAP_SYS_TIME
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=forking
|
Type=forking
|
||||||
PIDFile=/var/run/chronyd.pid
|
PIDFile=/run/chrony/chronyd.pid
|
||||||
EnvironmentFile=-/etc/sysconfig/chronyd
|
EnvironmentFile=-/etc/sysconfig/chronyd
|
||||||
ExecStart=/usr/sbin/chronyd $OPTIONS
|
ExecStart=/usr/sbin/chronyd $OPTIONS
|
||||||
|
|
||||||
|
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
|
||||||
|
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE
|
||||||
|
CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_MKNOD CAP_SYS_ADMIN
|
||||||
|
CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_CHROOT CAP_SYS_MODULE CAP_SYS_PACCT
|
||||||
|
CapabilityBoundingSet=~CAP_SYS_PTRACE CAP_SYS_RAWIO CAP_SYS_TTY_CONFIG CAP_WAKE_ALARM
|
||||||
|
DeviceAllow=char-pps rw
|
||||||
|
DeviceAllow=char-ptp rw
|
||||||
|
DeviceAllow=char-rtc rw
|
||||||
|
DevicePolicy=closed
|
||||||
|
LockPersonality=yes
|
||||||
|
MemoryDenyWriteExecute=yes
|
||||||
|
NoNewPrivileges=yes
|
||||||
|
PrivateTmp=yes
|
||||||
|
ProcSubset=pid
|
||||||
|
ProtectControlGroups=yes
|
||||||
|
ProtectHome=yes
|
||||||
|
ProtectHostname=yes
|
||||||
|
ProtectKernelLogs=yes
|
||||||
|
ProtectKernelModules=yes
|
||||||
|
ProtectKernelTunables=yes
|
||||||
|
ProtectProc=invisible
|
||||||
|
ProtectSystem=strict
|
||||||
|
ReadWritePaths=/run /var/lib/chrony -/var/log
|
||||||
|
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
|
||||||
|
RestrictNamespaces=yes
|
||||||
|
RestrictSUIDSGID=yes
|
||||||
|
SystemCallArchitectures=native
|
||||||
|
SystemCallFilter=~@cpu-emulation @debug @module @mount @obsolete @raw-io @reboot @swap
|
||||||
|
|
||||||
|
# Adjust restrictions for /usr/sbin/sendmail (mailonchange directive)
|
||||||
|
NoNewPrivileges=no
|
||||||
|
ReadWritePaths=-/var/spool
|
||||||
|
RestrictAddressFamilies=AF_NETLINK
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
24
hash.h
24
hash.h
@@ -31,12 +31,26 @@
|
|||||||
/* length of hash values produced by SHA512 */
|
/* length of hash values produced by SHA512 */
|
||||||
#define MAX_HASH_LENGTH 64
|
#define MAX_HASH_LENGTH 64
|
||||||
|
|
||||||
extern int HSH_GetHashId(const char *name);
|
typedef enum {
|
||||||
|
HSH_INVALID = 0,
|
||||||
|
HSH_MD5 = 1,
|
||||||
|
HSH_SHA1 = 2,
|
||||||
|
HSH_SHA256 = 3,
|
||||||
|
HSH_SHA384 = 4,
|
||||||
|
HSH_SHA512 = 5,
|
||||||
|
HSH_SHA3_224 = 6,
|
||||||
|
HSH_SHA3_256 = 7,
|
||||||
|
HSH_SHA3_384 = 8,
|
||||||
|
HSH_SHA3_512 = 9,
|
||||||
|
HSH_TIGER = 10,
|
||||||
|
HSH_WHIRLPOOL = 11,
|
||||||
|
HSH_MD5_NONCRYPTO = 10000, /* For NTPv4 reference ID */
|
||||||
|
} HSH_Algorithm;
|
||||||
|
|
||||||
extern unsigned int HSH_Hash(int id,
|
extern int HSH_GetHashId(HSH_Algorithm algorithm);
|
||||||
const unsigned char *in1, unsigned int in1_len,
|
|
||||||
const unsigned char *in2, unsigned int in2_len,
|
extern int HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
|
||||||
unsigned char *out, unsigned int out_len);
|
unsigned char *out, int out_len);
|
||||||
|
|
||||||
extern void HSH_Finalise(void);
|
extern void HSH_Finalise(void);
|
||||||
|
|
||||||
|
|||||||
145
hash_gnutls.c
Normal file
145
hash_gnutls.c
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2021
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Crypto hashing using the GnuTLS library
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <gnutls/crypto.h>
|
||||||
|
|
||||||
|
#include "hash.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
struct hash {
|
||||||
|
const HSH_Algorithm algorithm;
|
||||||
|
const gnutls_digest_algorithm_t type;
|
||||||
|
gnutls_hash_hd_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct hash hashes[] = {
|
||||||
|
{ HSH_MD5_NONCRYPTO, GNUTLS_DIG_MD5, NULL },
|
||||||
|
{ HSH_MD5, GNUTLS_DIG_MD5, NULL },
|
||||||
|
{ HSH_SHA1, GNUTLS_DIG_SHA1, NULL },
|
||||||
|
{ HSH_SHA256, GNUTLS_DIG_SHA256, NULL },
|
||||||
|
{ HSH_SHA384, GNUTLS_DIG_SHA384, NULL },
|
||||||
|
{ HSH_SHA512, GNUTLS_DIG_SHA512, NULL },
|
||||||
|
{ HSH_SHA3_224, GNUTLS_DIG_SHA3_224, NULL },
|
||||||
|
{ HSH_SHA3_256, GNUTLS_DIG_SHA3_256, NULL },
|
||||||
|
{ HSH_SHA3_384, GNUTLS_DIG_SHA3_384, NULL },
|
||||||
|
{ HSH_SHA3_512, GNUTLS_DIG_SHA3_512, NULL },
|
||||||
|
{ 0, 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static int gnutls_initialised = 0;
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_GetHashId(HSH_Algorithm algorithm)
|
||||||
|
{
|
||||||
|
int id, r;
|
||||||
|
|
||||||
|
if (!gnutls_initialised) {
|
||||||
|
r = gnutls_global_init();
|
||||||
|
if (r < 0)
|
||||||
|
LOG_FATAL("Could not initialise %s : %s", "gnutls", gnutls_strerror(r));
|
||||||
|
gnutls_initialised = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (id = 0; hashes[id].algorithm != 0; id++) {
|
||||||
|
if (hashes[id].algorithm == algorithm)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hashes[id].algorithm == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (hashes[id].handle)
|
||||||
|
return id;
|
||||||
|
|
||||||
|
if (algorithm == HSH_MD5_NONCRYPTO)
|
||||||
|
GNUTLS_FIPS140_SET_LAX_MODE();
|
||||||
|
|
||||||
|
r = gnutls_hash_init(&hashes[id].handle, hashes[id].type);
|
||||||
|
|
||||||
|
if (algorithm == HSH_MD5_NONCRYPTO)
|
||||||
|
GNUTLS_FIPS140_SET_STRICT_MODE();
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
DEBUG_LOG("Could not initialise %s : %s", "hash", gnutls_strerror(r));
|
||||||
|
hashes[id].handle = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
|
||||||
|
unsigned char *out, int out_len)
|
||||||
|
{
|
||||||
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
|
gnutls_hash_hd_t handle;
|
||||||
|
int hash_len;
|
||||||
|
|
||||||
|
if (in1_len < 0 || in2_len < 0 || out_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
handle = hashes[id].handle;
|
||||||
|
hash_len = gnutls_hash_get_len(hashes[id].type);
|
||||||
|
|
||||||
|
if (out_len > hash_len)
|
||||||
|
out_len = hash_len;
|
||||||
|
|
||||||
|
if (hash_len > sizeof (buf))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (gnutls_hash(handle, in1, in1_len) < 0 ||
|
||||||
|
(in2 && gnutls_hash(handle, in2, in2_len) < 0)) {
|
||||||
|
/* Reset the state */
|
||||||
|
gnutls_hash_output(handle, buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gnutls_hash_output(handle, buf);
|
||||||
|
memcpy(out, buf, out_len);
|
||||||
|
|
||||||
|
return out_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HSH_Finalise(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!gnutls_initialised)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; hashes[i].algorithm != 0; i++) {
|
||||||
|
if (hashes[i].handle)
|
||||||
|
gnutls_hash_deinit(hashes[i].handle, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
gnutls_global_deinit();
|
||||||
|
}
|
||||||
@@ -29,27 +29,27 @@
|
|||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include "md5.c"
|
#include "md5.c"
|
||||||
|
|
||||||
static MD5_CTX ctx;
|
static MD5_CTX ctx;
|
||||||
|
|
||||||
int
|
int
|
||||||
HSH_GetHashId(const char *name)
|
HSH_GetHashId(HSH_Algorithm algorithm)
|
||||||
{
|
{
|
||||||
/* only MD5 is supported */
|
/* only MD5 is supported */
|
||||||
if (strcmp(name, "MD5"))
|
if (algorithm != HSH_MD5 && algorithm != HSH_MD5_NONCRYPTO)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
int
|
||||||
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
|
||||||
const unsigned char *in2, unsigned int in2_len,
|
unsigned char *out, int out_len)
|
||||||
unsigned char *out, unsigned int out_len)
|
|
||||||
{
|
{
|
||||||
if (out_len < 16)
|
if (in1_len < 0 || in2_len < 0 || out_len < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
MD5Init(&ctx);
|
MD5Init(&ctx);
|
||||||
@@ -58,9 +58,11 @@ HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
|||||||
MD5Update(&ctx, in2, in2_len);
|
MD5Update(&ctx, in2, in2_len);
|
||||||
MD5Final(&ctx);
|
MD5Final(&ctx);
|
||||||
|
|
||||||
memcpy(out, ctx.digest, 16);
|
out_len = MIN(out_len, 16);
|
||||||
|
|
||||||
return 16;
|
memcpy(out, ctx.digest, out_len);
|
||||||
|
|
||||||
|
return out_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
124
hash_nettle.c
Normal file
124
hash_nettle.c
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2018
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Routines implementing crypto hashing using the nettle library.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <nettle/nettle-meta.h>
|
||||||
|
|
||||||
|
#include "hash.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
struct hash {
|
||||||
|
const HSH_Algorithm algorithm;
|
||||||
|
const char *int_name;
|
||||||
|
const struct nettle_hash *nettle_hash;
|
||||||
|
void *context;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct hash hashes[] = {
|
||||||
|
{ HSH_MD5, "md5", NULL, NULL },
|
||||||
|
{ HSH_SHA1, "sha1", NULL, NULL },
|
||||||
|
{ HSH_SHA256, "sha256", NULL, NULL },
|
||||||
|
{ HSH_SHA384, "sha384", NULL, NULL },
|
||||||
|
{ HSH_SHA512, "sha512", NULL, NULL },
|
||||||
|
{ HSH_SHA3_224, "sha3_224", NULL, NULL },
|
||||||
|
{ HSH_SHA3_256, "sha3_256", NULL, NULL },
|
||||||
|
{ HSH_SHA3_384, "sha3_384", NULL, NULL },
|
||||||
|
{ HSH_SHA3_512, "sha3_512", NULL, NULL },
|
||||||
|
{ 0, NULL, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_GetHashId(HSH_Algorithm algorithm)
|
||||||
|
{
|
||||||
|
int id, nid;
|
||||||
|
|
||||||
|
if (algorithm == HSH_MD5_NONCRYPTO)
|
||||||
|
algorithm = HSH_MD5;
|
||||||
|
|
||||||
|
for (id = 0; hashes[id].algorithm != 0; id++) {
|
||||||
|
if (hashes[id].algorithm == algorithm)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hashes[id].algorithm == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (hashes[id].context)
|
||||||
|
return id;
|
||||||
|
|
||||||
|
for (nid = 0; nettle_hashes[nid]; nid++) {
|
||||||
|
if (!strcmp(hashes[id].int_name, nettle_hashes[nid]->name))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nettle_hashes[nid] || !nettle_hashes[nid]->context_size || !nettle_hashes[nid]->init)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
hashes[id].nettle_hash = nettle_hashes[nid];
|
||||||
|
hashes[id].context = Malloc(hashes[id].nettle_hash->context_size);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
|
||||||
|
unsigned char *out, int out_len)
|
||||||
|
{
|
||||||
|
const struct nettle_hash *hash;
|
||||||
|
void *context;
|
||||||
|
|
||||||
|
if (in1_len < 0 || in2_len < 0 || out_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
hash = hashes[id].nettle_hash;
|
||||||
|
context = hashes[id].context;
|
||||||
|
|
||||||
|
if (out_len > hash->digest_size)
|
||||||
|
out_len = hash->digest_size;
|
||||||
|
|
||||||
|
hash->init(context);
|
||||||
|
hash->update(context, in1_len, in1);
|
||||||
|
if (in2)
|
||||||
|
hash->update(context, in2_len, in2);
|
||||||
|
hash->digest(context, out_len, out);
|
||||||
|
|
||||||
|
return out_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HSH_Finalise(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; hashes[i].algorithm != 0; i++) {
|
||||||
|
if (hashes[i].context)
|
||||||
|
Free(hashes[i].context);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
hash_nss.c
46
hash_nss.c
@@ -32,35 +32,39 @@
|
|||||||
#include <nsslowhash.h>
|
#include <nsslowhash.h>
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static NSSLOWInitContext *ictx;
|
static NSSLOWInitContext *ictx;
|
||||||
|
|
||||||
struct hash {
|
struct hash {
|
||||||
HASH_HashType type;
|
HASH_HashType type;
|
||||||
const char *name;
|
HSH_Algorithm algorithm;
|
||||||
NSSLOWHASHContext *context;
|
NSSLOWHASHContext *context;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct hash hashes[] = {
|
static struct hash hashes[] = {
|
||||||
{ HASH_AlgMD5, "MD5", NULL },
|
{ HASH_AlgMD5, HSH_MD5, NULL },
|
||||||
{ HASH_AlgSHA1, "SHA1", NULL },
|
{ HASH_AlgSHA1, HSH_SHA1, NULL },
|
||||||
{ HASH_AlgSHA256, "SHA256", NULL },
|
{ HASH_AlgSHA256, HSH_SHA256, NULL },
|
||||||
{ HASH_AlgSHA384, "SHA384", NULL },
|
{ HASH_AlgSHA384, HSH_SHA384, NULL },
|
||||||
{ HASH_AlgSHA512, "SHA512", NULL },
|
{ HASH_AlgSHA512, HSH_SHA512, NULL },
|
||||||
{ 0, NULL, NULL }
|
{ 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
HSH_GetHashId(const char *name)
|
HSH_GetHashId(HSH_Algorithm algorithm)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; hashes[i].name; i++) {
|
if (algorithm == HSH_MD5_NONCRYPTO)
|
||||||
if (!strcmp(name, hashes[i].name))
|
algorithm = HSH_MD5;
|
||||||
|
|
||||||
|
for (i = 0; hashes[i].algorithm != 0; i++) {
|
||||||
|
if (hashes[i].algorithm == algorithm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hashes[i].name)
|
if (hashes[i].algorithm == 0)
|
||||||
return -1; /* not found */
|
return -1; /* not found */
|
||||||
|
|
||||||
if (!ictx && !(ictx = NSSLOW_Init()))
|
if (!ictx && !(ictx = NSSLOW_Init()))
|
||||||
@@ -73,18 +77,24 @@ HSH_GetHashId(const char *name)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
int
|
||||||
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
|
||||||
const unsigned char *in2, unsigned int in2_len,
|
unsigned char *out, int out_len)
|
||||||
unsigned char *out, unsigned int out_len)
|
|
||||||
{
|
{
|
||||||
unsigned int ret;
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
|
unsigned int ret = 0;
|
||||||
|
|
||||||
|
if (in1_len < 0 || in2_len < 0 || out_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
NSSLOWHASH_Begin(hashes[id].context);
|
NSSLOWHASH_Begin(hashes[id].context);
|
||||||
NSSLOWHASH_Update(hashes[id].context, in1, in1_len);
|
NSSLOWHASH_Update(hashes[id].context, in1, in1_len);
|
||||||
if (in2)
|
if (in2)
|
||||||
NSSLOWHASH_Update(hashes[id].context, in2, in2_len);
|
NSSLOWHASH_Update(hashes[id].context, in2, in2_len);
|
||||||
NSSLOWHASH_End(hashes[id].context, out, &ret, out_len);
|
NSSLOWHASH_End(hashes[id].context, buf, &ret, sizeof (buf));
|
||||||
|
|
||||||
|
ret = MIN(ret, out_len);
|
||||||
|
memcpy(out, buf, ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -94,7 +104,7 @@ HSH_Finalise(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; hashes[i].name; i++) {
|
for (i = 0; hashes[i].algorithm != 0; i++) {
|
||||||
if (hashes[i].context)
|
if (hashes[i].context)
|
||||||
NSSLOWHASH_Destroy(hashes[i].context);
|
NSSLOWHASH_Destroy(hashes[i].context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Miroslav Lichvar 2012
|
* Copyright (C) Miroslav Lichvar 2012, 2018
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -29,59 +29,57 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct hash {
|
struct hash {
|
||||||
const char *name;
|
HSH_Algorithm algorithm;
|
||||||
const char *int_name;
|
const char *int_name;
|
||||||
const struct ltc_hash_descriptor *desc;
|
const struct ltc_hash_descriptor *desc;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct hash hashes[] = {
|
static const struct hash hashes[] = {
|
||||||
{ "MD5", "md5", &md5_desc },
|
{ HSH_MD5, "md5", &md5_desc },
|
||||||
#ifdef LTC_RIPEMD128
|
|
||||||
{ "RMD128", "rmd128", &rmd128_desc },
|
|
||||||
#endif
|
|
||||||
#ifdef LTC_RIPEMD160
|
|
||||||
{ "RMD160", "rmd160", &rmd160_desc },
|
|
||||||
#endif
|
|
||||||
#ifdef LTC_RIPEMD256
|
|
||||||
{ "RMD256", "rmd256", &rmd256_desc },
|
|
||||||
#endif
|
|
||||||
#ifdef LTC_RIPEMD320
|
|
||||||
{ "RMD320", "rmd320", &rmd320_desc },
|
|
||||||
#endif
|
|
||||||
#ifdef LTC_SHA1
|
#ifdef LTC_SHA1
|
||||||
{ "SHA1", "sha1", &sha1_desc },
|
{ HSH_SHA1, "sha1", &sha1_desc },
|
||||||
#endif
|
#endif
|
||||||
#ifdef LTC_SHA256
|
#ifdef LTC_SHA256
|
||||||
{ "SHA256", "sha256", &sha256_desc },
|
{ HSH_SHA256, "sha256", &sha256_desc },
|
||||||
#endif
|
#endif
|
||||||
#ifdef LTC_SHA384
|
#ifdef LTC_SHA384
|
||||||
{ "SHA384", "sha384", &sha384_desc },
|
{ HSH_SHA384, "sha384", &sha384_desc },
|
||||||
#endif
|
#endif
|
||||||
#ifdef LTC_SHA512
|
#ifdef LTC_SHA512
|
||||||
{ "SHA512", "sha512", &sha512_desc },
|
{ HSH_SHA512, "sha512", &sha512_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_SHA3
|
||||||
|
{ HSH_SHA3_224, "sha3-224", &sha3_224_desc },
|
||||||
|
{ HSH_SHA3_256, "sha3-256", &sha3_256_desc },
|
||||||
|
{ HSH_SHA3_384, "sha3-384", &sha3_384_desc },
|
||||||
|
{ HSH_SHA3_512, "sha3-512", &sha3_512_desc },
|
||||||
#endif
|
#endif
|
||||||
#ifdef LTC_TIGER
|
#ifdef LTC_TIGER
|
||||||
{ "TIGER", "tiger", &tiger_desc },
|
{ HSH_TIGER, "tiger", &tiger_desc },
|
||||||
#endif
|
#endif
|
||||||
#ifdef LTC_WHIRLPOOL
|
#ifdef LTC_WHIRLPOOL
|
||||||
{ "WHIRLPOOL", "whirlpool", &whirlpool_desc },
|
{ HSH_WHIRLPOOL, "whirlpool", &whirlpool_desc },
|
||||||
#endif
|
#endif
|
||||||
{ NULL, NULL, NULL }
|
{ 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
HSH_GetHashId(const char *name)
|
HSH_GetHashId(HSH_Algorithm algorithm)
|
||||||
{
|
{
|
||||||
int i, h;
|
int i, h;
|
||||||
|
|
||||||
for (i = 0; hashes[i].name; i++) {
|
if (algorithm == HSH_MD5_NONCRYPTO)
|
||||||
if (!strcmp(name, hashes[i].name))
|
algorithm = HSH_MD5;
|
||||||
|
|
||||||
|
for (i = 0; hashes[i].algorithm != 0; i++) {
|
||||||
|
if (hashes[i].algorithm == algorithm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hashes[i].name)
|
if (hashes[i].algorithm == 0)
|
||||||
return -1; /* not found */
|
return -1; /* not found */
|
||||||
|
|
||||||
h = find_hash(hashes[i].int_name);
|
h = find_hash(hashes[i].int_name);
|
||||||
@@ -94,24 +92,31 @@ HSH_GetHashId(const char *name)
|
|||||||
return find_hash(hashes[i].int_name);
|
return find_hash(hashes[i].int_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
int
|
||||||
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
|
||||||
const unsigned char *in2, unsigned int in2_len,
|
unsigned char *out, int out_len)
|
||||||
unsigned char *out, unsigned int out_len)
|
|
||||||
{
|
{
|
||||||
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
len = out_len;
|
if (in1_len < 0 || in2_len < 0 || out_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
len = sizeof (buf);
|
||||||
if (in2)
|
if (in2)
|
||||||
r = hash_memory_multi(id, out, &len,
|
r = hash_memory_multi(id, buf, &len,
|
||||||
in1, (unsigned long)in1_len, in2, (unsigned long)in2_len, NULL, 0);
|
in1, (unsigned long)in1_len,
|
||||||
|
in2, (unsigned long)in2_len, NULL, 0);
|
||||||
else
|
else
|
||||||
r = hash_memory(id, in1, in1_len, out, &len);
|
r = hash_memory(id, in1, in1_len, buf, &len);
|
||||||
|
|
||||||
if (r != CRYPT_OK)
|
if (r != CRYPT_OK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
len = MIN(len, out_len);
|
||||||
|
memcpy(out, buf, len);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
334
hwclock.c
Normal file
334
hwclock.c
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016-2018
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Tracking of hardware clocks (e.g. RTC, PHC)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "array.h"
|
||||||
|
#include "hwclock.h"
|
||||||
|
#include "local.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "quantiles.h"
|
||||||
|
#include "regress.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
/* Minimum and maximum number of samples per clock */
|
||||||
|
#define MIN_SAMPLES 2
|
||||||
|
#define MAX_SAMPLES 64
|
||||||
|
|
||||||
|
/* Maximum acceptable frequency offset of the clock */
|
||||||
|
#define MAX_FREQ_OFFSET (2.0 / 3.0)
|
||||||
|
|
||||||
|
/* Quantiles for filtering readings by delay */
|
||||||
|
#define DELAY_QUANT_MIN_K 1
|
||||||
|
#define DELAY_QUANT_MAX_K 2
|
||||||
|
#define DELAY_QUANT_Q 10
|
||||||
|
#define DELAY_QUANT_REPEAT 7
|
||||||
|
#define DELAY_QUANT_MIN_STEP 1.0e-9
|
||||||
|
|
||||||
|
struct HCL_Instance_Record {
|
||||||
|
/* HW and local reference timestamp */
|
||||||
|
struct timespec hw_ref;
|
||||||
|
struct timespec local_ref;
|
||||||
|
|
||||||
|
/* Samples stored as intervals (uncorrected for frequency error)
|
||||||
|
relative to local_ref and hw_ref */
|
||||||
|
double *x_data;
|
||||||
|
double *y_data;
|
||||||
|
|
||||||
|
/* Minimum, maximum and current number of samples */
|
||||||
|
int min_samples;
|
||||||
|
int max_samples;
|
||||||
|
int n_samples;
|
||||||
|
|
||||||
|
/* Maximum error of the last sample */
|
||||||
|
double last_err;
|
||||||
|
|
||||||
|
/* Minimum interval between samples */
|
||||||
|
double min_separation;
|
||||||
|
|
||||||
|
/* Expected precision of readings */
|
||||||
|
double precision;
|
||||||
|
|
||||||
|
/* Flag indicating the offset and frequency values are valid */
|
||||||
|
int valid_coefs;
|
||||||
|
|
||||||
|
/* Estimated offset and frequency of HW clock relative to local clock */
|
||||||
|
double offset;
|
||||||
|
double frequency;
|
||||||
|
|
||||||
|
/* Estimated quantiles of reading delay */
|
||||||
|
QNT_Instance delay_quants;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_slew(struct timespec *raw, struct timespec *cooked, double dfreq,
|
||||||
|
double doffset, LCL_ChangeType change_type, void *anything)
|
||||||
|
{
|
||||||
|
HCL_Instance clock;
|
||||||
|
double delta;
|
||||||
|
|
||||||
|
clock = anything;
|
||||||
|
|
||||||
|
if (clock->n_samples)
|
||||||
|
UTI_AdjustTimespec(&clock->local_ref, cooked, &clock->local_ref, &delta, dfreq, doffset);
|
||||||
|
if (clock->valid_coefs)
|
||||||
|
clock->frequency /= 1.0 - dfreq;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
HCL_Instance
|
||||||
|
HCL_CreateInstance(int min_samples, int max_samples, double min_separation, double precision)
|
||||||
|
{
|
||||||
|
HCL_Instance clock;
|
||||||
|
|
||||||
|
min_samples = CLAMP(MIN_SAMPLES, min_samples, MAX_SAMPLES);
|
||||||
|
max_samples = CLAMP(MIN_SAMPLES, max_samples, MAX_SAMPLES);
|
||||||
|
max_samples = MAX(min_samples, max_samples);
|
||||||
|
|
||||||
|
clock = MallocNew(struct HCL_Instance_Record);
|
||||||
|
clock->x_data = MallocArray(double, max_samples);
|
||||||
|
clock->y_data = MallocArray(double, max_samples);
|
||||||
|
clock->x_data[max_samples - 1] = 0.0;
|
||||||
|
clock->y_data[max_samples - 1] = 0.0;
|
||||||
|
clock->min_samples = min_samples;
|
||||||
|
clock->max_samples = max_samples;
|
||||||
|
clock->n_samples = 0;
|
||||||
|
clock->valid_coefs = 0;
|
||||||
|
clock->min_separation = min_separation;
|
||||||
|
clock->precision = precision;
|
||||||
|
clock->delay_quants = QNT_CreateInstance(DELAY_QUANT_MIN_K, DELAY_QUANT_MAX_K,
|
||||||
|
DELAY_QUANT_Q, DELAY_QUANT_REPEAT,
|
||||||
|
DELAY_QUANT_MIN_STEP);
|
||||||
|
|
||||||
|
LCL_AddParameterChangeHandler(handle_slew, clock);
|
||||||
|
|
||||||
|
return clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void HCL_DestroyInstance(HCL_Instance clock)
|
||||||
|
{
|
||||||
|
LCL_RemoveParameterChangeHandler(handle_slew, clock);
|
||||||
|
QNT_DestroyInstance(clock->delay_quants);
|
||||||
|
Free(clock->y_data);
|
||||||
|
Free(clock->x_data);
|
||||||
|
Free(clock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
HCL_NeedsNewSample(HCL_Instance clock, struct timespec *now)
|
||||||
|
{
|
||||||
|
if (!clock->n_samples ||
|
||||||
|
fabs(UTI_DiffTimespecsToDouble(now, &clock->local_ref)) >= clock->min_separation)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
HCL_ProcessReadings(HCL_Instance clock, int n_readings, struct timespec tss[][3],
|
||||||
|
struct timespec *hw_ts, struct timespec *local_ts, double *err)
|
||||||
|
{
|
||||||
|
double delay, raw_delay, min_delay, low_delay, high_delay, e, pred_err;
|
||||||
|
double delay_sum, hw_sum, local_sum, local_prec, freq;
|
||||||
|
int i, min_reading, combined;
|
||||||
|
struct timespec ts1, ts2;
|
||||||
|
|
||||||
|
if (n_readings < 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Work out the current correction multiplier needed to get cooked delays */
|
||||||
|
LCL_CookTime(&tss[0][0], &ts1, NULL);
|
||||||
|
LCL_CookTime(&tss[n_readings - 1][2], &ts2, NULL);
|
||||||
|
if (UTI_CompareTimespecs(&tss[0][0], &tss[n_readings - 1][2]) < 0)
|
||||||
|
freq = UTI_DiffTimespecsToDouble(&ts1, &ts2) /
|
||||||
|
UTI_DiffTimespecsToDouble(&tss[0][0], &tss[n_readings - 1][2]);
|
||||||
|
else
|
||||||
|
freq = 1.0;
|
||||||
|
|
||||||
|
for (i = 0; i < n_readings; i++) {
|
||||||
|
delay = freq * UTI_DiffTimespecsToDouble(&tss[i][2], &tss[i][0]);
|
||||||
|
|
||||||
|
if (delay < 0.0) {
|
||||||
|
/* Step in the middle of a reading? */
|
||||||
|
DEBUG_LOG("Bad reading delay=%e", delay);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 0 || min_delay > delay) {
|
||||||
|
min_delay = delay;
|
||||||
|
min_reading = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
QNT_Accumulate(clock->delay_quants, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
local_prec = LCL_GetSysPrecisionAsQuantum();
|
||||||
|
|
||||||
|
low_delay = QNT_GetQuantile(clock->delay_quants, DELAY_QUANT_MIN_K);
|
||||||
|
high_delay = QNT_GetQuantile(clock->delay_quants, DELAY_QUANT_MAX_K);
|
||||||
|
low_delay = MIN(low_delay, high_delay);
|
||||||
|
high_delay = MAX(high_delay, low_delay + local_prec);
|
||||||
|
|
||||||
|
/* Combine readings with delay in the expected interval */
|
||||||
|
for (i = combined = 0, delay_sum = hw_sum = local_sum = 0.0; i < n_readings; i++) {
|
||||||
|
raw_delay = UTI_DiffTimespecsToDouble(&tss[i][2], &tss[i][0]);
|
||||||
|
delay = freq * raw_delay;
|
||||||
|
|
||||||
|
if (delay < low_delay || delay > high_delay)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
delay_sum += delay;
|
||||||
|
hw_sum += UTI_DiffTimespecsToDouble(&tss[i][1], &tss[0][1]);
|
||||||
|
local_sum += UTI_DiffTimespecsToDouble(&tss[i][0], &tss[0][0]) + raw_delay / 2.0;
|
||||||
|
combined++;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Combined %d readings lo=%e hi=%e", combined, low_delay, high_delay);
|
||||||
|
|
||||||
|
if (combined > 0) {
|
||||||
|
UTI_AddDoubleToTimespec(&tss[0][1], hw_sum / combined, hw_ts);
|
||||||
|
UTI_AddDoubleToTimespec(&tss[0][0], local_sum / combined, local_ts);
|
||||||
|
*err = MAX(delay_sum / combined / 2.0, clock->precision);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Accept the reading with minimum delay if its interval does not contain
|
||||||
|
the current offset predicted from previous samples */
|
||||||
|
|
||||||
|
*hw_ts = tss[min_reading][1];
|
||||||
|
UTI_AddDoubleToTimespec(&tss[min_reading][0], min_delay / freq / 2.0, local_ts);
|
||||||
|
*err = MAX(min_delay / 2.0, clock->precision);
|
||||||
|
|
||||||
|
pred_err = 0.0;
|
||||||
|
LCL_CookTime(local_ts, &ts1, NULL);
|
||||||
|
if (!HCL_CookTime(clock, hw_ts, &ts2, &e) ||
|
||||||
|
((pred_err = UTI_DiffTimespecsToDouble(&ts1, &ts2)) > *err)) {
|
||||||
|
DEBUG_LOG("Accepted reading err=%e prerr=%e", *err, pred_err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
HCL_AccumulateSample(HCL_Instance clock, struct timespec *hw_ts,
|
||||||
|
struct timespec *local_ts, double err)
|
||||||
|
{
|
||||||
|
double hw_delta, local_delta, local_freq, raw_freq;
|
||||||
|
int i, n_runs, best_start;
|
||||||
|
|
||||||
|
local_freq = 1.0 - LCL_ReadAbsoluteFrequency() / 1.0e6;
|
||||||
|
|
||||||
|
/* Shift old samples */
|
||||||
|
if (clock->n_samples) {
|
||||||
|
if (clock->n_samples >= clock->max_samples)
|
||||||
|
clock->n_samples--;
|
||||||
|
|
||||||
|
hw_delta = UTI_DiffTimespecsToDouble(hw_ts, &clock->hw_ref);
|
||||||
|
local_delta = UTI_DiffTimespecsToDouble(local_ts, &clock->local_ref) / local_freq;
|
||||||
|
|
||||||
|
if (hw_delta <= 0.0 || local_delta < clock->min_separation / 2.0) {
|
||||||
|
clock->n_samples = 0;
|
||||||
|
DEBUG_LOG("HW clock reset interval=%f", local_delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = clock->max_samples - clock->n_samples; i < clock->max_samples; i++) {
|
||||||
|
clock->y_data[i - 1] = clock->y_data[i] - hw_delta;
|
||||||
|
clock->x_data[i - 1] = clock->x_data[i] - local_delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clock->n_samples++;
|
||||||
|
clock->hw_ref = *hw_ts;
|
||||||
|
clock->local_ref = *local_ts;
|
||||||
|
clock->last_err = err;
|
||||||
|
|
||||||
|
/* Get new coefficients */
|
||||||
|
clock->valid_coefs =
|
||||||
|
RGR_FindBestRobustRegression(clock->x_data + clock->max_samples - clock->n_samples,
|
||||||
|
clock->y_data + clock->max_samples - clock->n_samples,
|
||||||
|
clock->n_samples, 1.0e-10, &clock->offset, &raw_freq,
|
||||||
|
&n_runs, &best_start);
|
||||||
|
|
||||||
|
if (!clock->valid_coefs) {
|
||||||
|
DEBUG_LOG("HW clock needs more samples");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clock->frequency = raw_freq / local_freq;
|
||||||
|
|
||||||
|
/* Drop unneeded samples */
|
||||||
|
if (clock->n_samples > clock->min_samples)
|
||||||
|
clock->n_samples -= MIN(best_start, clock->n_samples - clock->min_samples);
|
||||||
|
|
||||||
|
/* If the fit doesn't cross the error interval of the last sample,
|
||||||
|
or the frequency is not sane, drop all samples and start again */
|
||||||
|
if (fabs(clock->offset) > err ||
|
||||||
|
fabs(clock->frequency - 1.0) > MAX_FREQ_OFFSET) {
|
||||||
|
DEBUG_LOG("HW clock reset");
|
||||||
|
clock->n_samples = 0;
|
||||||
|
clock->valid_coefs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("HW clock samples=%d offset=%e freq=%e raw_freq=%e err=%e ref_diff=%e",
|
||||||
|
clock->n_samples, clock->offset, clock->frequency - 1.0, raw_freq - 1.0, err,
|
||||||
|
UTI_DiffTimespecsToDouble(&clock->hw_ref, &clock->local_ref));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
HCL_CookTime(HCL_Instance clock, struct timespec *raw, struct timespec *cooked, double *err)
|
||||||
|
{
|
||||||
|
double offset, elapsed;
|
||||||
|
|
||||||
|
if (!clock->valid_coefs)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
elapsed = UTI_DiffTimespecsToDouble(raw, &clock->hw_ref);
|
||||||
|
offset = elapsed / clock->frequency - clock->offset;
|
||||||
|
UTI_AddDoubleToTimespec(&clock->local_ref, offset, cooked);
|
||||||
|
|
||||||
|
/* Fow now, just return the error of the last sample */
|
||||||
|
if (err)
|
||||||
|
*err = clock->last_err;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
54
hwclock.h
Normal file
54
hwclock.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header for tracking of hardware clocks */
|
||||||
|
|
||||||
|
#ifndef GOT_HWCLOCK_H
|
||||||
|
#define GOT_HWCLOCK_H
|
||||||
|
|
||||||
|
typedef struct HCL_Instance_Record *HCL_Instance;
|
||||||
|
|
||||||
|
/* Create a new HW clock instance */
|
||||||
|
extern HCL_Instance HCL_CreateInstance(int min_samples, int max_samples,
|
||||||
|
double min_separation, double precision);
|
||||||
|
|
||||||
|
/* Destroy a HW clock instance */
|
||||||
|
extern void HCL_DestroyInstance(HCL_Instance clock);
|
||||||
|
|
||||||
|
/* Check if a new sample should be accumulated at this time */
|
||||||
|
extern int HCL_NeedsNewSample(HCL_Instance clock, struct timespec *now);
|
||||||
|
|
||||||
|
/* Process new readings of the HW clock in form of (sys, hw, sys) triplets and
|
||||||
|
produce a sample which can be accumulated */
|
||||||
|
extern int HCL_ProcessReadings(HCL_Instance clock, int n_readings, struct timespec tss[][3],
|
||||||
|
struct timespec *hw_ts, struct timespec *local_ts, double *err);
|
||||||
|
|
||||||
|
/* Accumulate a new sample */
|
||||||
|
extern void HCL_AccumulateSample(HCL_Instance clock, struct timespec *hw_ts,
|
||||||
|
struct timespec *local_ts, double err);
|
||||||
|
|
||||||
|
/* Convert raw hardware time to cooked local time */
|
||||||
|
extern int HCL_CookTime(HCL_Instance clock, struct timespec *raw, struct timespec *cooked,
|
||||||
|
double *err);
|
||||||
|
|
||||||
|
#endif
|
||||||
220
keys.c
220
keys.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2012-2016
|
* Copyright (C) Miroslav Lichvar 2012-2016, 2019-2020
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
|
#include "cmac.h"
|
||||||
#include "cmdparse.h"
|
#include "cmdparse.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
@@ -42,12 +43,23 @@
|
|||||||
/* Consider 80 bits as the absolute minimum for a secure key */
|
/* Consider 80 bits as the absolute minimum for a secure key */
|
||||||
#define MIN_SECURE_KEY_LENGTH 10
|
#define MIN_SECURE_KEY_LENGTH 10
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NTP_MAC,
|
||||||
|
CMAC,
|
||||||
|
} KeyClass;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
char *val;
|
int type;
|
||||||
int len;
|
int length;
|
||||||
int hash_id;
|
KeyClass class;
|
||||||
int auth_delay;
|
union {
|
||||||
|
struct {
|
||||||
|
unsigned char *value;
|
||||||
|
int hash_id;
|
||||||
|
} ntp_mac;
|
||||||
|
CMC_Instance cmac;
|
||||||
|
} data;
|
||||||
} Key;
|
} Key;
|
||||||
|
|
||||||
static ARR_Instance keys;
|
static ARR_Instance keys;
|
||||||
@@ -62,9 +74,21 @@ static void
|
|||||||
free_keys(void)
|
free_keys(void)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
Key *key;
|
||||||
|
|
||||||
for (i = 0; i < ARR_GetSize(keys); i++)
|
for (i = 0; i < ARR_GetSize(keys); i++) {
|
||||||
Free(((Key *)ARR_GetElement(keys, i))->val);
|
key = ARR_GetElement(keys, i);
|
||||||
|
switch (key->class) {
|
||||||
|
case NTP_MAC:
|
||||||
|
Free(key->data.ntp_mac.value);
|
||||||
|
break;
|
||||||
|
case CMAC:
|
||||||
|
CMC_DestroyInstance(key->data.cmac);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ARR_SetSize(keys, 0);
|
ARR_SetSize(keys, 0);
|
||||||
cache_valid = 0;
|
cache_valid = 0;
|
||||||
@@ -98,34 +122,22 @@ get_key(unsigned int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
/* Decode key encoded in ASCII or HEX */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
determine_hash_delay(uint32_t key_id)
|
decode_key(char *key)
|
||||||
{
|
{
|
||||||
NTP_Packet pkt;
|
int len = strlen(key);
|
||||||
struct timeval before, after;
|
|
||||||
unsigned long usecs, min_usecs=0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < 10; i++) {
|
if (!strncmp(key, "ASCII:", 6)) {
|
||||||
LCL_ReadRawTime(&before);
|
memmove(key, key + 6, len - 6);
|
||||||
KEY_GenerateAuth(key_id, (unsigned char *)&pkt, NTP_NORMAL_PACKET_LENGTH,
|
return len - 6;
|
||||||
(unsigned char *)&pkt.auth_data, sizeof (pkt.auth_data));
|
} else if (!strncmp(key, "HEX:", 4)) {
|
||||||
LCL_ReadRawTime(&after);
|
return UTI_HexToBytes(key + 4, key, len);
|
||||||
|
} else {
|
||||||
usecs = (after.tv_sec - before.tv_sec) * 1000000 + (after.tv_usec - before.tv_usec);
|
/* assume ASCII */
|
||||||
|
return len;
|
||||||
if (i == 0 || usecs < min_usecs) {
|
|
||||||
min_usecs = usecs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add on a bit extra to allow for copying, conversions etc */
|
|
||||||
min_usecs += min_usecs >> 4;
|
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_Keys, "authentication delay for key %"PRIu32": %ld useconds", key_id, min_usecs);
|
|
||||||
|
|
||||||
return min_usecs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -153,11 +165,13 @@ compare_keys_by_id(const void *a, const void *b)
|
|||||||
void
|
void
|
||||||
KEY_Reload(void)
|
KEY_Reload(void)
|
||||||
{
|
{
|
||||||
unsigned int i, line_number;
|
unsigned int i, line_number, key_length, cmac_key_length;
|
||||||
FILE *in;
|
FILE *in;
|
||||||
uint32_t key_id;
|
char line[2048], *key_file, *key_value;
|
||||||
char line[2048], *keyval, *key_file;
|
const char *key_type;
|
||||||
const char *hashname;
|
HSH_Algorithm hash_algorithm;
|
||||||
|
CMC_Algorithm cmac_algorithm;
|
||||||
|
int hash_id;
|
||||||
Key key;
|
Key key;
|
||||||
|
|
||||||
free_keys();
|
free_keys();
|
||||||
@@ -168,9 +182,9 @@ KEY_Reload(void)
|
|||||||
if (!key_file)
|
if (!key_file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
in = fopen(key_file, "r");
|
in = UTI_OpenFile(NULL, key_file, NULL, 'r', 0);
|
||||||
if (!in) {
|
if (!in) {
|
||||||
LOG(LOGS_WARN, LOGF_Keys, "Could not open keyfile %s", key_file);
|
LOG(LOGS_WARN, "Could not open keyfile %s", key_file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,26 +195,56 @@ KEY_Reload(void)
|
|||||||
if (!*line)
|
if (!*line)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!CPS_ParseKey(line, &key_id, &hashname, &keyval)) {
|
memset(&key, 0, sizeof (key));
|
||||||
LOG(LOGS_WARN, LOGF_Keys, "Could not parse key at line %d in file %s", line_number, key_file);
|
|
||||||
|
if (!CPS_ParseKey(line, &key.id, &key_type, &key_value)) {
|
||||||
|
LOG(LOGS_WARN, "Could not parse key at line %u in file %s", line_number, key_file);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
key.hash_id = HSH_GetHashId(hashname);
|
key_length = decode_key(key_value);
|
||||||
if (key.hash_id < 0) {
|
if (key_length == 0) {
|
||||||
LOG(LOGS_WARN, LOGF_Keys, "Unknown hash function in key %"PRIu32, key_id);
|
LOG(LOGS_WARN, "Could not decode key %"PRIu32, key.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
key.len = UTI_DecodePasswordFromText(keyval);
|
hash_algorithm = UTI_HashNameToAlgorithm(key_type);
|
||||||
if (!key.len) {
|
cmac_algorithm = UTI_CmacNameToAlgorithm(key_type);
|
||||||
LOG(LOGS_WARN, LOGF_Keys, "Could not decode password in key %"PRIu32, key_id);
|
|
||||||
|
if (hash_algorithm != 0) {
|
||||||
|
hash_id = HSH_GetHashId(hash_algorithm);
|
||||||
|
if (hash_id < 0) {
|
||||||
|
LOG(LOGS_WARN, "Unsupported %s in key %"PRIu32, "hash function", key.id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
key.class = NTP_MAC;
|
||||||
|
key.type = hash_algorithm;
|
||||||
|
key.length = key_length;
|
||||||
|
key.data.ntp_mac.value = MallocArray(unsigned char, key_length);
|
||||||
|
memcpy(key.data.ntp_mac.value, key_value, key_length);
|
||||||
|
key.data.ntp_mac.hash_id = hash_id;
|
||||||
|
} else if (cmac_algorithm != 0) {
|
||||||
|
cmac_key_length = CMC_GetKeyLength(cmac_algorithm);
|
||||||
|
if (cmac_key_length == 0) {
|
||||||
|
LOG(LOGS_WARN, "Unsupported %s in key %"PRIu32, "cipher", key.id);
|
||||||
|
continue;
|
||||||
|
} else if (cmac_key_length != key_length) {
|
||||||
|
LOG(LOGS_WARN, "Invalid length of %s key %"PRIu32" (expected %u bits)",
|
||||||
|
key_type, key.id, 8 * cmac_key_length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
key.class = CMAC;
|
||||||
|
key.type = cmac_algorithm;
|
||||||
|
key.length = key_length;
|
||||||
|
key.data.cmac = CMC_CreateInstance(cmac_algorithm, (unsigned char *)key_value,
|
||||||
|
key_length);
|
||||||
|
assert(key.data.cmac);
|
||||||
|
} else {
|
||||||
|
LOG(LOGS_WARN, "Invalid type in key %"PRIu32, key.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
key.id = key_id;
|
|
||||||
key.val = MallocArray(char, key.len);
|
|
||||||
memcpy(key.val, keyval, key.len);
|
|
||||||
ARR_AppendElement(keys, &key);
|
ARR_AppendElement(keys, &key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,14 +258,11 @@ KEY_Reload(void)
|
|||||||
/* Check for duplicates */
|
/* Check for duplicates */
|
||||||
for (i = 1; i < ARR_GetSize(keys); i++) {
|
for (i = 1; i < ARR_GetSize(keys); i++) {
|
||||||
if (get_key(i - 1)->id == get_key(i)->id)
|
if (get_key(i - 1)->id == get_key(i)->id)
|
||||||
LOG(LOGS_WARN, LOGF_Keys, "Detected duplicate key %"PRIu32, get_key(i - 1)->id);
|
LOG(LOGS_WARN, "Detected duplicate key %"PRIu32, get_key(i - 1)->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Erase any passwords from stack */
|
/* Erase any passwords from stack */
|
||||||
memset(line, 0, sizeof (line));
|
memset(line, 0, sizeof (line));
|
||||||
|
|
||||||
for (i = 0; i < ARR_GetSize(keys); i++)
|
|
||||||
get_key(i)->auth_delay = determine_hash_delay(get_key(i)->id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -278,8 +319,9 @@ KEY_KeyKnown(uint32_t key_id)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
KEY_GetAuthDelay(uint32_t key_id)
|
KEY_GetAuthLength(uint32_t key_id)
|
||||||
{
|
{
|
||||||
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
Key *key;
|
Key *key;
|
||||||
|
|
||||||
key = get_key_by_id(key_id);
|
key = get_key_by_id(key_id);
|
||||||
@@ -287,7 +329,15 @@ KEY_GetAuthDelay(uint32_t key_id)
|
|||||||
if (!key)
|
if (!key)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return key->auth_delay;
|
switch (key->class) {
|
||||||
|
case NTP_MAC:
|
||||||
|
return HSH_Hash(key->data.ntp_mac.hash_id, buf, 0, buf, 0, buf, sizeof (buf));
|
||||||
|
case CMAC:
|
||||||
|
return CMC_Hash(key->data.cmac, buf, 0, buf, sizeof (buf));
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -302,14 +352,13 @@ KEY_CheckKeyLength(uint32_t key_id)
|
|||||||
if (!key)
|
if (!key)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return key->len >= MIN_SECURE_KEY_LENGTH;
|
return key->length >= MIN_SECURE_KEY_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
KEY_GenerateAuth(uint32_t key_id, const unsigned char *data, int data_len,
|
KEY_GetKeyInfo(uint32_t key_id, int *type, int *bits)
|
||||||
unsigned char *auth, int auth_len)
|
|
||||||
{
|
{
|
||||||
Key *key;
|
Key *key;
|
||||||
|
|
||||||
@@ -318,15 +367,47 @@ KEY_GenerateAuth(uint32_t key_id, const unsigned char *data, int data_len,
|
|||||||
if (!key)
|
if (!key)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return UTI_GenerateNTPAuth(key->hash_id, (unsigned char *)key->val,
|
*type = key->type;
|
||||||
key->len, data, data_len, auth, auth_len);
|
*bits = 8 * key->length;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
generate_auth(Key *key, const void *data, int data_len, unsigned char *auth, int auth_len)
|
||||||
|
{
|
||||||
|
switch (key->class) {
|
||||||
|
case NTP_MAC:
|
||||||
|
return HSH_Hash(key->data.ntp_mac.hash_id, key->data.ntp_mac.value,
|
||||||
|
key->length, data, data_len, auth, auth_len);
|
||||||
|
case CMAC:
|
||||||
|
return CMC_Hash(key->data.cmac, data, data_len, auth, auth_len);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_auth(Key *key, const void *data, int data_len,
|
||||||
|
const unsigned char *auth, int auth_len, int trunc_len)
|
||||||
|
{
|
||||||
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
|
int hash_len;
|
||||||
|
|
||||||
|
hash_len = generate_auth(key, data, data_len, buf, sizeof (buf));
|
||||||
|
|
||||||
|
return MIN(hash_len, trunc_len) == auth_len && !memcmp(buf, auth, auth_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
KEY_CheckAuth(uint32_t key_id, const unsigned char *data, int data_len,
|
KEY_GenerateAuth(uint32_t key_id, const void *data, int data_len,
|
||||||
const unsigned char *auth, int auth_len)
|
unsigned char *auth, int auth_len)
|
||||||
{
|
{
|
||||||
Key *key;
|
Key *key;
|
||||||
|
|
||||||
@@ -335,6 +416,21 @@ KEY_CheckAuth(uint32_t key_id, const unsigned char *data, int data_len,
|
|||||||
if (!key)
|
if (!key)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return UTI_CheckNTPAuth(key->hash_id, (unsigned char *)key->val,
|
return generate_auth(key, data, data_len, auth, auth_len);
|
||||||
key->len, data, data_len, auth, auth_len);
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
KEY_CheckAuth(uint32_t key_id, const void *data, int data_len,
|
||||||
|
const unsigned char *auth, int auth_len, int trunc_len)
|
||||||
|
{
|
||||||
|
Key *key;
|
||||||
|
|
||||||
|
key = get_key_by_id(key_id);
|
||||||
|
|
||||||
|
if (!key)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return check_auth(key, data, data_len, auth, auth_len, trunc_len);
|
||||||
}
|
}
|
||||||
|
|||||||
12
keys.h
12
keys.h
@@ -34,14 +34,14 @@ extern void KEY_Finalise(void);
|
|||||||
|
|
||||||
extern void KEY_Reload(void);
|
extern void KEY_Reload(void);
|
||||||
|
|
||||||
extern int KEY_GetKey(uint32_t key_id, char **key, int *len);
|
|
||||||
extern int KEY_KeyKnown(uint32_t key_id);
|
extern int KEY_KeyKnown(uint32_t key_id);
|
||||||
extern int KEY_GetAuthDelay(uint32_t key_id);
|
extern int KEY_GetAuthLength(uint32_t key_id);
|
||||||
extern int KEY_CheckKeyLength(uint32_t key_id);
|
extern int KEY_CheckKeyLength(uint32_t key_id);
|
||||||
|
extern int KEY_GetKeyInfo(uint32_t key_id, int *type, int *bits);
|
||||||
|
|
||||||
extern int KEY_GenerateAuth(uint32_t key_id, const unsigned char *data,
|
extern int KEY_GenerateAuth(uint32_t key_id, const void *data, int data_len,
|
||||||
int data_len, unsigned char *auth, int auth_len);
|
unsigned char *auth, int auth_len);
|
||||||
extern int KEY_CheckAuth(uint32_t key_id, const unsigned char *data,
|
extern int KEY_CheckAuth(uint32_t key_id, const void *data, int data_len,
|
||||||
int data_len, const unsigned char *auth, int auth_len);
|
const unsigned char *auth, int auth_len, int trunc_len);
|
||||||
|
|
||||||
#endif /* GOT_KEYS_H */
|
#endif /* GOT_KEYS_H */
|
||||||
|
|||||||
180
local.c
180
local.c
@@ -106,40 +106,36 @@ static double max_clock_error;
|
|||||||
under 1s of busy waiting. */
|
under 1s of busy waiting. */
|
||||||
#define NITERS 100
|
#define NITERS 100
|
||||||
|
|
||||||
static void
|
#define NSEC_PER_SEC 1000000000
|
||||||
calculate_sys_precision(void)
|
|
||||||
{
|
|
||||||
struct timeval tv, old_tv;
|
|
||||||
int dusec, best_dusec;
|
|
||||||
int iters;
|
|
||||||
|
|
||||||
gettimeofday(&old_tv, NULL);
|
static double
|
||||||
best_dusec = 1000000; /* Assume we must be better than a second */
|
measure_clock_precision(void)
|
||||||
|
{
|
||||||
|
struct timespec ts, old_ts;
|
||||||
|
int iters, diff, best;
|
||||||
|
|
||||||
|
LCL_ReadRawTime(&old_ts);
|
||||||
|
|
||||||
|
/* Assume we must be better than a second */
|
||||||
|
best = NSEC_PER_SEC;
|
||||||
iters = 0;
|
iters = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
gettimeofday(&tv, NULL);
|
LCL_ReadRawTime(&ts);
|
||||||
dusec = 1000000*(tv.tv_sec - old_tv.tv_sec) + (tv.tv_usec - old_tv.tv_usec);
|
|
||||||
old_tv = tv;
|
diff = NSEC_PER_SEC * (ts.tv_sec - old_ts.tv_sec) + (ts.tv_nsec - old_ts.tv_nsec);
|
||||||
if (dusec > 0) {
|
|
||||||
if (dusec < best_dusec) {
|
old_ts = ts;
|
||||||
best_dusec = dusec;
|
if (diff > 0) {
|
||||||
}
|
if (diff < best)
|
||||||
|
best = diff;
|
||||||
iters++;
|
iters++;
|
||||||
}
|
}
|
||||||
} while (iters < NITERS);
|
} while (iters < NITERS);
|
||||||
|
|
||||||
assert(best_dusec > 0);
|
assert(best > 0);
|
||||||
|
|
||||||
precision_quantum = best_dusec * 1.0e-6;
|
return 1.0e-9 * best;
|
||||||
|
|
||||||
/* Get rounded log2 value of the measured precision */
|
|
||||||
precision_log = 0;
|
|
||||||
while (best_dusec < 707107) {
|
|
||||||
precision_log--;
|
|
||||||
best_dusec *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_Local, "Clock precision %.9f (%d)", precision_quantum, precision_log);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -163,7 +159,16 @@ LCL_Initialise(void)
|
|||||||
current_freq_ppm = 0.0;
|
current_freq_ppm = 0.0;
|
||||||
temp_comp_ppm = 0.0;
|
temp_comp_ppm = 0.0;
|
||||||
|
|
||||||
calculate_sys_precision();
|
precision_quantum = CNF_GetClockPrecision();
|
||||||
|
if (precision_quantum <= 0.0)
|
||||||
|
precision_quantum = measure_clock_precision();
|
||||||
|
|
||||||
|
precision_quantum = CLAMP(1.0e-9, precision_quantum, 1.0);
|
||||||
|
precision_log = round(log(precision_quantum) / log(2.0));
|
||||||
|
/* NTP code doesn't support smaller log than -30 */
|
||||||
|
assert(precision_log >= -30);
|
||||||
|
|
||||||
|
DEBUG_LOG("Clock precision %.9f (%d)", precision_quantum, precision_log);
|
||||||
|
|
||||||
/* This is the maximum allowed frequency offset in ppm, the time must
|
/* This is the maximum allowed frequency offset in ppm, the time must
|
||||||
never stop or run backwards */
|
never stop or run backwards */
|
||||||
@@ -178,13 +183,11 @@ LCL_Initialise(void)
|
|||||||
void
|
void
|
||||||
LCL_Finalise(void)
|
LCL_Finalise(void)
|
||||||
{
|
{
|
||||||
while (change_list.next != &change_list)
|
/* Make sure all handlers have been removed */
|
||||||
LCL_RemoveParameterChangeHandler(change_list.next->handler,
|
if (change_list.next != &change_list)
|
||||||
change_list.next->anything);
|
assert(0);
|
||||||
|
if (dispersion_notify_list.next != &dispersion_notify_list)
|
||||||
while (dispersion_notify_list.next != &dispersion_notify_list)
|
assert(0);
|
||||||
LCL_RemoveDispersionNotifyHandler(dispersion_notify_list.next->handler,
|
|
||||||
dispersion_notify_list.next->anything);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -278,7 +281,7 @@ LCL_IsFirstParameterChangeHandler(LCL_ParameterChangeHandler handler)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
invoke_parameter_change_handlers(struct timeval *raw, struct timeval *cooked,
|
invoke_parameter_change_handlers(struct timespec *raw, struct timespec *cooked,
|
||||||
double dfreq, double doffset,
|
double dfreq, double doffset,
|
||||||
LCL_ChangeType change_type)
|
LCL_ChangeType change_type)
|
||||||
{
|
{
|
||||||
@@ -345,23 +348,29 @@ void LCL_RemoveDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* At the moment, this is just gettimeofday(), because
|
|
||||||
I can't think of a Unix system where it would not be */
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_ReadRawTime(struct timeval *result)
|
LCL_ReadRawTime(struct timespec *ts)
|
||||||
{
|
{
|
||||||
if (gettimeofday(result, NULL) < 0) {
|
#if HAVE_CLOCK_GETTIME
|
||||||
LOG_FATAL(LOGF_Local, "gettimeofday() failed");
|
if (clock_gettime(CLOCK_REALTIME, ts) < 0)
|
||||||
}
|
LOG_FATAL("clock_gettime() failed : %s", strerror(errno));
|
||||||
|
#else
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
if (gettimeofday(&tv, NULL) < 0)
|
||||||
|
LOG_FATAL("gettimeofday() failed : %s", strerror(errno));
|
||||||
|
|
||||||
|
UTI_TimevalToTimespec(&tv, ts);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_ReadCookedTime(struct timeval *result, double *err)
|
LCL_ReadCookedTime(struct timespec *result, double *err)
|
||||||
{
|
{
|
||||||
struct timeval raw;
|
struct timespec raw;
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw);
|
LCL_ReadRawTime(&raw);
|
||||||
LCL_CookTime(&raw, result, err);
|
LCL_CookTime(&raw, result, err);
|
||||||
@@ -370,18 +379,18 @@ LCL_ReadCookedTime(struct timeval *result, double *err)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_CookTime(struct timeval *raw, struct timeval *cooked, double *err)
|
LCL_CookTime(struct timespec *raw, struct timespec *cooked, double *err)
|
||||||
{
|
{
|
||||||
double correction;
|
double correction;
|
||||||
|
|
||||||
LCL_GetOffsetCorrection(raw, &correction, err);
|
LCL_GetOffsetCorrection(raw, &correction, err);
|
||||||
UTI_AddDoubleToTimeval(raw, correction, cooked);
|
UTI_AddDoubleToTimespec(raw, correction, cooked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_GetOffsetCorrection(struct timeval *raw, double *correction, double *err)
|
LCL_GetOffsetCorrection(struct timespec *raw, double *correction, double *err)
|
||||||
{
|
{
|
||||||
/* Call system specific driver to get correction */
|
/* Call system specific driver to get correction */
|
||||||
(*drv_offset_convert)(raw, correction, err);
|
(*drv_offset_convert)(raw, correction, err);
|
||||||
@@ -413,7 +422,7 @@ clamp_freq(double freq)
|
|||||||
if (freq <= max_freq_ppm && freq >= -max_freq_ppm)
|
if (freq <= max_freq_ppm && freq >= -max_freq_ppm)
|
||||||
return freq;
|
return freq;
|
||||||
|
|
||||||
LOG(LOGS_WARN, LOGF_Local, "Frequency %.1f ppm exceeds allowed maximum", freq);
|
LOG(LOGS_WARN, "Frequency %.1f ppm exceeds allowed maximum", freq);
|
||||||
|
|
||||||
return CLAMP(-max_freq_ppm, freq, max_freq_ppm);
|
return CLAMP(-max_freq_ppm, freq, max_freq_ppm);
|
||||||
}
|
}
|
||||||
@@ -421,13 +430,13 @@ clamp_freq(double freq)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
check_offset(struct timeval *now, double offset)
|
check_offset(struct timespec *now, double offset)
|
||||||
{
|
{
|
||||||
/* Check if the time will be still sane with accumulated offset */
|
/* Check if the time will be still sane with accumulated offset */
|
||||||
if (UTI_IsTimeOffsetSane(now, -offset))
|
if (UTI_IsTimeOffsetSane(now, -offset))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
LOG(LOGS_WARN, LOGF_Local, "Adjustment of %.1f seconds is invalid", -offset);
|
LOG(LOGS_WARN, "Adjustment of %.1f seconds is invalid", -offset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +448,7 @@ check_offset(struct timeval *now, double offset)
|
|||||||
void
|
void
|
||||||
LCL_SetAbsoluteFrequency(double afreq_ppm)
|
LCL_SetAbsoluteFrequency(double afreq_ppm)
|
||||||
{
|
{
|
||||||
struct timeval raw, cooked;
|
struct timespec raw, cooked;
|
||||||
double dfreq;
|
double dfreq;
|
||||||
|
|
||||||
afreq_ppm = clamp_freq(afreq_ppm);
|
afreq_ppm = clamp_freq(afreq_ppm);
|
||||||
@@ -470,7 +479,7 @@ LCL_SetAbsoluteFrequency(double afreq_ppm)
|
|||||||
void
|
void
|
||||||
LCL_AccumulateDeltaFrequency(double dfreq)
|
LCL_AccumulateDeltaFrequency(double dfreq)
|
||||||
{
|
{
|
||||||
struct timeval raw, cooked;
|
struct timespec raw, cooked;
|
||||||
double old_freq_ppm;
|
double old_freq_ppm;
|
||||||
|
|
||||||
old_freq_ppm = current_freq_ppm;
|
old_freq_ppm = current_freq_ppm;
|
||||||
@@ -496,10 +505,10 @@ LCL_AccumulateDeltaFrequency(double dfreq)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
int
|
||||||
LCL_AccumulateOffset(double offset, double corr_rate)
|
LCL_AccumulateOffset(double offset, double corr_rate)
|
||||||
{
|
{
|
||||||
struct timeval raw, cooked;
|
struct timespec raw, cooked;
|
||||||
|
|
||||||
/* In this case, the cooked time to be passed to the notify clients
|
/* In this case, the cooked time to be passed to the notify clients
|
||||||
has to be the cooked time BEFORE the change was made */
|
has to be the cooked time BEFORE the change was made */
|
||||||
@@ -508,12 +517,14 @@ LCL_AccumulateOffset(double offset, double corr_rate)
|
|||||||
LCL_CookTime(&raw, &cooked, NULL);
|
LCL_CookTime(&raw, &cooked, NULL);
|
||||||
|
|
||||||
if (!check_offset(&cooked, offset))
|
if (!check_offset(&cooked, offset))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
(*drv_accrue_offset)(offset, corr_rate);
|
(*drv_accrue_offset)(offset, corr_rate);
|
||||||
|
|
||||||
/* Dispatch to all handlers */
|
/* Dispatch to all handlers */
|
||||||
invoke_parameter_change_handlers(&raw, &cooked, 0.0, offset, LCL_ChangeAdjust);
|
invoke_parameter_change_handlers(&raw, &cooked, 0.0, offset, LCL_ChangeAdjust);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -521,7 +532,7 @@ LCL_AccumulateOffset(double offset, double corr_rate)
|
|||||||
int
|
int
|
||||||
LCL_ApplyStepOffset(double offset)
|
LCL_ApplyStepOffset(double offset)
|
||||||
{
|
{
|
||||||
struct timeval raw, cooked;
|
struct timespec raw, cooked;
|
||||||
|
|
||||||
/* In this case, the cooked time to be passed to the notify clients
|
/* In this case, the cooked time to be passed to the notify clients
|
||||||
has to be the cooked time BEFORE the change was made */
|
has to be the cooked time BEFORE the change was made */
|
||||||
@@ -533,7 +544,7 @@ LCL_ApplyStepOffset(double offset)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(*drv_apply_step_offset)(offset)) {
|
if (!(*drv_apply_step_offset)(offset)) {
|
||||||
LOG(LOGS_ERR, LOGF_Local, "Could not step clock");
|
LOG(LOGS_ERR, "Could not step system clock");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,9 +560,11 @@ LCL_ApplyStepOffset(double offset)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_NotifyExternalTimeStep(struct timeval *raw, struct timeval *cooked,
|
LCL_NotifyExternalTimeStep(struct timespec *raw, struct timespec *cooked,
|
||||||
double offset, double dispersion)
|
double offset, double dispersion)
|
||||||
{
|
{
|
||||||
|
LCL_CancelOffsetCorrection();
|
||||||
|
|
||||||
/* Dispatch to all handlers */
|
/* Dispatch to all handlers */
|
||||||
invoke_parameter_change_handlers(raw, cooked, 0.0, offset, LCL_ChangeUnknownStep);
|
invoke_parameter_change_handlers(raw, cooked, 0.0, offset, LCL_ChangeUnknownStep);
|
||||||
|
|
||||||
@@ -563,7 +576,7 @@ LCL_NotifyExternalTimeStep(struct timeval *raw, struct timeval *cooked,
|
|||||||
void
|
void
|
||||||
LCL_NotifyLeap(int leap)
|
LCL_NotifyLeap(int leap)
|
||||||
{
|
{
|
||||||
struct timeval raw, cooked;
|
struct timespec raw, cooked;
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw);
|
LCL_ReadRawTime(&raw);
|
||||||
LCL_CookTime(&raw, &cooked, NULL);
|
LCL_CookTime(&raw, &cooked, NULL);
|
||||||
@@ -577,10 +590,10 @@ LCL_NotifyLeap(int leap)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
int
|
||||||
LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
|
LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
|
||||||
{
|
{
|
||||||
struct timeval raw, cooked;
|
struct timespec raw, cooked;
|
||||||
double old_freq_ppm;
|
double old_freq_ppm;
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw);
|
LCL_ReadRawTime(&raw);
|
||||||
@@ -589,7 +602,7 @@ LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
|
|||||||
LCL_CookTime(&raw, &cooked, NULL);
|
LCL_CookTime(&raw, &cooked, NULL);
|
||||||
|
|
||||||
if (!check_offset(&cooked, doffset))
|
if (!check_offset(&cooked, doffset))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
old_freq_ppm = current_freq_ppm;
|
old_freq_ppm = current_freq_ppm;
|
||||||
|
|
||||||
@@ -600,7 +613,7 @@ LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
|
|||||||
|
|
||||||
current_freq_ppm = clamp_freq(current_freq_ppm);
|
current_freq_ppm = clamp_freq(current_freq_ppm);
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_Local, "old_freq=%.3fppm new_freq=%.3fppm offset=%.6fsec",
|
DEBUG_LOG("old_freq=%.3fppm new_freq=%.3fppm offset=%.6fsec",
|
||||||
old_freq_ppm, current_freq_ppm, doffset);
|
old_freq_ppm, current_freq_ppm, doffset);
|
||||||
|
|
||||||
/* Call the system-specific driver for setting the frequency */
|
/* Call the system-specific driver for setting the frequency */
|
||||||
@@ -611,6 +624,26 @@ LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
|
|||||||
|
|
||||||
/* Dispatch to all handlers */
|
/* Dispatch to all handlers */
|
||||||
invoke_parameter_change_handlers(&raw, &cooked, dfreq, doffset, LCL_ChangeAdjust);
|
invoke_parameter_change_handlers(&raw, &cooked, dfreq, doffset, LCL_ChangeAdjust);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
LCL_AccumulateFrequencyAndOffsetNoHandlers(double dfreq, double doffset, double corr_rate)
|
||||||
|
{
|
||||||
|
ChangeListEntry *first_handler;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
first_handler = change_list.next;
|
||||||
|
change_list.next = &change_list;
|
||||||
|
|
||||||
|
r = LCL_AccumulateFrequencyAndOffset(dfreq, doffset, corr_rate);
|
||||||
|
|
||||||
|
change_list.next = first_handler;
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -647,7 +680,7 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
|
|||||||
|
|
||||||
current_freq_ppm = (*drv_read_freq)();
|
current_freq_ppm = (*drv_read_freq)();
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_Local, "Local freq=%.3fppm", current_freq_ppm);
|
DEBUG_LOG("Local freq=%.3fppm", current_freq_ppm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -657,7 +690,7 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
|
|||||||
int
|
int
|
||||||
LCL_MakeStep(void)
|
LCL_MakeStep(void)
|
||||||
{
|
{
|
||||||
struct timeval raw;
|
struct timespec raw;
|
||||||
double correction;
|
double correction;
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw);
|
LCL_ReadRawTime(&raw);
|
||||||
@@ -671,13 +704,26 @@ LCL_MakeStep(void)
|
|||||||
if (!LCL_ApplyStepOffset(-correction))
|
if (!LCL_ApplyStepOffset(-correction))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
LOG(LOGS_WARN, LOGF_Local, "System clock was stepped by %.6f seconds", correction);
|
LOG(LOGS_WARN, "System clock was stepped by %.6f seconds", correction);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
LCL_CancelOffsetCorrection(void)
|
||||||
|
{
|
||||||
|
struct timespec raw;
|
||||||
|
double correction;
|
||||||
|
|
||||||
|
LCL_ReadRawTime(&raw);
|
||||||
|
LCL_GetOffsetCorrection(&raw, &correction, NULL);
|
||||||
|
LCL_AccumulateOffset(correction, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
LCL_CanSystemLeap(void)
|
LCL_CanSystemLeap(void)
|
||||||
{
|
{
|
||||||
@@ -687,10 +733,10 @@ LCL_CanSystemLeap(void)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_SetSystemLeap(int leap)
|
LCL_SetSystemLeap(int leap, int tai_offset)
|
||||||
{
|
{
|
||||||
if (drv_set_leap) {
|
if (drv_set_leap) {
|
||||||
(drv_set_leap)(leap);
|
(drv_set_leap)(leap, tai_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
local.h
36
local.h
@@ -31,9 +31,8 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
/* Read the system clock. This is analogous to gettimeofday(),
|
/* Read the system clock */
|
||||||
but with the timezone information ignored */
|
extern void LCL_ReadRawTime(struct timespec *ts);
|
||||||
extern void LCL_ReadRawTime(struct timeval *);
|
|
||||||
|
|
||||||
/* Read the system clock, corrected according to all accumulated
|
/* Read the system clock, corrected according to all accumulated
|
||||||
drifts and uncompensated offsets.
|
drifts and uncompensated offsets.
|
||||||
@@ -44,15 +43,15 @@ extern void LCL_ReadRawTime(struct timeval *);
|
|||||||
adjtime()-like interface to correct offsets, and to adjust the
|
adjtime()-like interface to correct offsets, and to adjust the
|
||||||
frequency), we must correct the raw time to get this value */
|
frequency), we must correct the raw time to get this value */
|
||||||
|
|
||||||
extern void LCL_ReadCookedTime(struct timeval *t, double *err);
|
extern void LCL_ReadCookedTime(struct timespec *ts, double *err);
|
||||||
|
|
||||||
/* Convert raw time to cooked. */
|
/* Convert raw time to cooked. */
|
||||||
extern void LCL_CookTime(struct timeval *raw, struct timeval *cooked, double *err);
|
extern void LCL_CookTime(struct timespec *raw, struct timespec *cooked, double *err);
|
||||||
|
|
||||||
/* Read the current offset between the system clock and true time
|
/* Read the current offset between the system clock and true time
|
||||||
(i.e. 'cooked' - 'raw') (in seconds). */
|
(i.e. 'cooked' - 'raw') (in seconds). */
|
||||||
|
|
||||||
extern void LCL_GetOffsetCorrection(struct timeval *raw, double *correction, double *err);
|
extern void LCL_GetOffsetCorrection(struct timespec *raw, double *correction, double *err);
|
||||||
|
|
||||||
/* Type of routines that may be invoked as callbacks when there is a
|
/* Type of routines that may be invoked as callbacks when there is a
|
||||||
change to the frequency or offset.
|
change to the frequency or offset.
|
||||||
@@ -79,7 +78,7 @@ typedef enum {
|
|||||||
} LCL_ChangeType;
|
} LCL_ChangeType;
|
||||||
|
|
||||||
typedef void (*LCL_ParameterChangeHandler)
|
typedef void (*LCL_ParameterChangeHandler)
|
||||||
(struct timeval *raw, struct timeval *cooked,
|
(struct timespec *raw, struct timespec *cooked,
|
||||||
double dfreq,
|
double dfreq,
|
||||||
double doffset,
|
double doffset,
|
||||||
LCL_ChangeType change_type,
|
LCL_ChangeType change_type,
|
||||||
@@ -150,7 +149,7 @@ extern void LCL_AccumulateDeltaFrequency(double dfreq);
|
|||||||
forwards (i.e. it is currently slow of true time). Provided is also
|
forwards (i.e. it is currently slow of true time). Provided is also
|
||||||
a suggested correction rate (correction time * offset). */
|
a suggested correction rate (correction time * offset). */
|
||||||
|
|
||||||
extern void LCL_AccumulateOffset(double offset, double corr_rate);
|
extern int LCL_AccumulateOffset(double offset, double corr_rate);
|
||||||
|
|
||||||
/* Routine to apply an immediate offset by doing a sudden step if
|
/* Routine to apply an immediate offset by doing a sudden step if
|
||||||
possible. (Intended for use after an initial estimate of offset has
|
possible. (Intended for use after an initial estimate of offset has
|
||||||
@@ -163,7 +162,7 @@ extern int LCL_ApplyStepOffset(double offset);
|
|||||||
|
|
||||||
/* Routine to invoke notify handlers on an unexpected time jump
|
/* Routine to invoke notify handlers on an unexpected time jump
|
||||||
in system clock */
|
in system clock */
|
||||||
extern void LCL_NotifyExternalTimeStep(struct timeval *raw, struct timeval *cooked,
|
extern void LCL_NotifyExternalTimeStep(struct timespec *raw, struct timespec *cooked,
|
||||||
double offset, double dispersion);
|
double offset, double dispersion);
|
||||||
|
|
||||||
/* Routine to invoke notify handlers on leap second when the system clock
|
/* Routine to invoke notify handlers on leap second when the system clock
|
||||||
@@ -172,7 +171,12 @@ extern void LCL_NotifyLeap(int leap);
|
|||||||
|
|
||||||
/* Perform the combination of modifying the frequency and applying
|
/* Perform the combination of modifying the frequency and applying
|
||||||
a slew, in one easy step */
|
a slew, in one easy step */
|
||||||
extern void LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate);
|
extern int LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate);
|
||||||
|
|
||||||
|
/* Same as the routine above, except it does not call the registered
|
||||||
|
parameter change handlers */
|
||||||
|
extern int LCL_AccumulateFrequencyAndOffsetNoHandlers(double dfreq, double doffset,
|
||||||
|
double corr_rate);
|
||||||
|
|
||||||
/* Routine to read the system precision as a log to base 2 value. */
|
/* Routine to read the system precision as a log to base 2 value. */
|
||||||
extern int LCL_GetSysPrecisionAsLog(void);
|
extern int LCL_GetSysPrecisionAsLog(void);
|
||||||
@@ -198,14 +202,18 @@ extern void LCL_Finalise(void);
|
|||||||
to a timezone problem. */
|
to a timezone problem. */
|
||||||
extern int LCL_MakeStep(void);
|
extern int LCL_MakeStep(void);
|
||||||
|
|
||||||
|
/* Routine to cancel the outstanding system clock correction */
|
||||||
|
extern void LCL_CancelOffsetCorrection(void);
|
||||||
|
|
||||||
/* Check if the system driver supports leap seconds, i.e. LCL_SetSystemLeap
|
/* Check if the system driver supports leap seconds, i.e. LCL_SetSystemLeap
|
||||||
does something */
|
does something */
|
||||||
extern int LCL_CanSystemLeap(void);
|
extern int LCL_CanSystemLeap(void);
|
||||||
|
|
||||||
/* Routine to set the system clock to correct itself for a leap second if
|
/* Routine to set the system clock to correct itself for a leap second and also
|
||||||
supported. Leap second will be inserted at the end of the day if the
|
set its TAI-UTC offset. If supported, leap second will be inserted at the
|
||||||
argument is positive, deleted if negative, and zero resets the setting. */
|
end of the day if the argument is positive, deleted if negative, and zero
|
||||||
extern void LCL_SetSystemLeap(int leap);
|
resets the setting. */
|
||||||
|
extern void LCL_SetSystemLeap(int leap, int tai_offset);
|
||||||
|
|
||||||
/* Routine to set a frequency correction (in ppm) that should be applied
|
/* Routine to set a frequency correction (in ppm) that should be applied
|
||||||
to local clock to compensate for temperature changes. A positive
|
to local clock to compensate for temperature changes. A positive
|
||||||
|
|||||||
6
localp.h
6
localp.h
@@ -52,10 +52,10 @@ typedef int (*lcl_ApplyStepOffsetDriver)(double offset);
|
|||||||
/* System driver to convert a raw time to an adjusted (cooked) time.
|
/* System driver to convert a raw time to an adjusted (cooked) time.
|
||||||
The number of seconds returned in 'corr' have to be added to the
|
The number of seconds returned in 'corr' have to be added to the
|
||||||
raw time to get the corrected time */
|
raw time to get the corrected time */
|
||||||
typedef void (*lcl_OffsetCorrectionDriver)(struct timeval *raw, double *corr, double *err);
|
typedef void (*lcl_OffsetCorrectionDriver)(struct timespec *raw, double *corr, double *err);
|
||||||
|
|
||||||
/* System driver to schedule leap second */
|
/* System driver to schedule leap seconds and set TAI-UTC offset */
|
||||||
typedef void (*lcl_SetLeapDriver)(int leap);
|
typedef void (*lcl_SetLeapDriver)(int leap, int tai_offset);
|
||||||
|
|
||||||
/* System driver to set the synchronisation status */
|
/* System driver to set the synchronisation status */
|
||||||
typedef void (*lcl_SetSyncStatusDriver)(int synchronised, double est_error, double max_error);
|
typedef void (*lcl_SetSyncStatusDriver)(int synchronised, double est_error, double max_error);
|
||||||
|
|||||||
148
logging.c
148
logging.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2011-2014
|
* Copyright (C) Miroslav Lichvar 2011-2014, 2018-2020
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -29,25 +29,25 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* This is used by DEBUG_LOG macro */
|
/* This is used by DEBUG_LOG macro */
|
||||||
int log_debug_enabled = 0;
|
LOG_Severity log_min_severity = LOGS_INFO;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Flag indicating we have initialised */
|
/* Flag indicating we have initialised */
|
||||||
static int initialised = 0;
|
static int initialised = 0;
|
||||||
|
|
||||||
|
static FILE *file_log = NULL;
|
||||||
static int system_log = 0;
|
static int system_log = 0;
|
||||||
|
|
||||||
static int parent_fd = 0;
|
static int parent_fd = 0;
|
||||||
|
|
||||||
#define DEBUG_LEVEL_PRINT_FUNCTION 2
|
|
||||||
#define DEBUG_LEVEL_PRINT_DEBUG 2
|
|
||||||
static int debug_level = 0;
|
|
||||||
|
|
||||||
struct LogFile {
|
struct LogFile {
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *banner;
|
const char *banner;
|
||||||
@@ -62,13 +62,18 @@ static int n_filelogs = 0;
|
|||||||
|
|
||||||
static struct LogFile logfiles[MAX_FILELOGS];
|
static struct LogFile logfiles[MAX_FILELOGS];
|
||||||
|
|
||||||
|
/* Global prefix for debug messages */
|
||||||
|
static char *debug_prefix;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Init function */
|
/* Init function */
|
||||||
|
|
||||||
void
|
void
|
||||||
LOG_Initialise(void)
|
LOG_Initialise(void)
|
||||||
{
|
{
|
||||||
|
debug_prefix = Strdup("");
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
LOG_OpenFileLog(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -77,12 +82,16 @@ LOG_Initialise(void)
|
|||||||
void
|
void
|
||||||
LOG_Finalise(void)
|
LOG_Finalise(void)
|
||||||
{
|
{
|
||||||
if (system_log) {
|
if (system_log)
|
||||||
closelog();
|
closelog();
|
||||||
}
|
|
||||||
|
if (file_log)
|
||||||
|
fclose(file_log);
|
||||||
|
|
||||||
LOG_CycleLogFiles();
|
LOG_CycleLogFiles();
|
||||||
|
|
||||||
|
Free(debug_prefix);
|
||||||
|
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +121,8 @@ static void log_message(int fatal, LOG_Severity severity, const char *message)
|
|||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
syslog(priority, fatal ? "Fatal error : %s" : "%s", message);
|
syslog(priority, fatal ? "Fatal error : %s" : "%s", message);
|
||||||
} else {
|
} else if (file_log) {
|
||||||
fprintf(stderr, fatal ? "Fatal error : %s\n" : "%s\n", message);
|
fprintf(file_log, fatal ? "Fatal error : %s\n" : "%s\n", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,25 +130,28 @@ static void log_message(int fatal, LOG_Severity severity, const char *message)
|
|||||||
|
|
||||||
void LOG_Message(LOG_Severity severity,
|
void LOG_Message(LOG_Severity severity,
|
||||||
#if DEBUG > 0
|
#if DEBUG > 0
|
||||||
LOG_Facility facility, int line_number,
|
int line_number, const char *filename, const char *function_name,
|
||||||
const char *filename, const char *function_name,
|
|
||||||
#endif
|
#endif
|
||||||
const char *format, ...)
|
const char *format, ...)
|
||||||
{
|
{
|
||||||
char buf[2048];
|
char buf[2048];
|
||||||
va_list other_args;
|
va_list other_args;
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm stm;
|
struct tm *tm;
|
||||||
|
|
||||||
if (!system_log) {
|
assert(initialised);
|
||||||
|
|
||||||
|
if (!system_log && file_log && severity >= log_min_severity) {
|
||||||
/* Don't clutter up syslog with timestamps and internal debugging info */
|
/* Don't clutter up syslog with timestamps and internal debugging info */
|
||||||
time(&t);
|
time(&t);
|
||||||
stm = *gmtime(&t);
|
tm = gmtime(&t);
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &stm);
|
if (tm) {
|
||||||
fprintf(stderr, "%s ", buf);
|
strftime(buf, sizeof (buf), "%Y-%m-%dT%H:%M:%SZ", tm);
|
||||||
|
fprintf(file_log, "%s ", buf);
|
||||||
|
}
|
||||||
#if DEBUG > 0
|
#if DEBUG > 0
|
||||||
if (debug_level >= DEBUG_LEVEL_PRINT_FUNCTION)
|
if (log_min_severity <= LOGS_DEBUG)
|
||||||
fprintf(stderr, "%s:%d:(%s) ", filename, line_number, function_name);
|
fprintf(file_log, "%s%s:%d:(%s) ", debug_prefix, filename, line_number, function_name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,28 +164,52 @@ void LOG_Message(LOG_Severity severity,
|
|||||||
case LOGS_INFO:
|
case LOGS_INFO:
|
||||||
case LOGS_WARN:
|
case LOGS_WARN:
|
||||||
case LOGS_ERR:
|
case LOGS_ERR:
|
||||||
log_message(0, severity, buf);
|
if (severity >= log_min_severity)
|
||||||
|
log_message(0, severity, buf);
|
||||||
break;
|
break;
|
||||||
case LOGS_FATAL:
|
case LOGS_FATAL:
|
||||||
log_message(1, severity, buf);
|
if (severity >= log_min_severity)
|
||||||
|
log_message(1, severity, buf);
|
||||||
|
|
||||||
/* With syslog, send the message also to the grandparent
|
/* Send the message also to the foreground process if it is
|
||||||
process or write it to stderr if not detached */
|
still running, or stderr if it is still open */
|
||||||
if (system_log) {
|
if (parent_fd > 0) {
|
||||||
if (parent_fd > 0) {
|
if (write(parent_fd, buf, strlen(buf) + 1) < 0)
|
||||||
if (write(parent_fd, buf, strlen(buf) + 1) < 0)
|
; /* Not much we can do here */
|
||||||
; /* Not much we can do here */
|
} else if (system_log && parent_fd == 0) {
|
||||||
} else if (parent_fd == 0) {
|
system_log = 0;
|
||||||
system_log = 0;
|
log_message(1, severity, buf);
|
||||||
log_message(1, severity, buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
exit(1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
LOG_OpenFileLog(const char *log_file)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
if (log_file) {
|
||||||
|
f = UTI_OpenFile(NULL, log_file, NULL, 'A', 0640);
|
||||||
|
} else {
|
||||||
|
f = stderr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enable line buffering */
|
||||||
|
setvbuf(f, NULL, _IOLBF, BUFSIZ);
|
||||||
|
|
||||||
|
if (file_log && file_log != stderr)
|
||||||
|
fclose(file_log);
|
||||||
|
|
||||||
|
file_log = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -185,12 +221,27 @@ LOG_OpenSystemLog(void)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void LOG_SetDebugLevel(int level)
|
void LOG_SetMinSeverity(LOG_Severity severity)
|
||||||
{
|
{
|
||||||
debug_level = level;
|
/* Don't print any debug messages in a non-debug build */
|
||||||
if (level >= DEBUG_LEVEL_PRINT_DEBUG) {
|
log_min_severity = CLAMP(DEBUG > 0 ? LOGS_DEBUG : LOGS_INFO, severity, LOGS_FATAL);
|
||||||
log_debug_enabled = 1;
|
}
|
||||||
}
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
LOG_Severity
|
||||||
|
LOG_GetMinSeverity(void)
|
||||||
|
{
|
||||||
|
return log_min_severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
LOG_SetDebugPrefix(const char *prefix)
|
||||||
|
{
|
||||||
|
Free(debug_prefix);
|
||||||
|
debug_prefix = Strdup(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -199,6 +250,8 @@ void
|
|||||||
LOG_SetParentFd(int fd)
|
LOG_SetParentFd(int fd)
|
||||||
{
|
{
|
||||||
parent_fd = fd;
|
parent_fd = fd;
|
||||||
|
if (file_log == stderr)
|
||||||
|
file_log = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -216,7 +269,10 @@ LOG_CloseParentFd()
|
|||||||
LOG_FileID
|
LOG_FileID
|
||||||
LOG_FileOpen(const char *name, const char *banner)
|
LOG_FileOpen(const char *name, const char *banner)
|
||||||
{
|
{
|
||||||
assert(n_filelogs < MAX_FILELOGS);
|
if (n_filelogs >= MAX_FILELOGS) {
|
||||||
|
assert(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
logfiles[n_filelogs].name = name;
|
logfiles[n_filelogs].name = name;
|
||||||
logfiles[n_filelogs].banner = banner;
|
logfiles[n_filelogs].banner = banner;
|
||||||
@@ -238,18 +294,20 @@ LOG_FileWrite(LOG_FileID id, const char *format, ...)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!logfiles[id].file) {
|
if (!logfiles[id].file) {
|
||||||
char filename[512];
|
char *logdir = CNF_GetLogDir();
|
||||||
|
|
||||||
if (snprintf(filename, sizeof(filename), "%s/%s.log",
|
if (!logdir) {
|
||||||
CNF_GetLogDir(), logfiles[id].name) >= sizeof(filename) ||
|
LOG(LOGS_WARN, "logdir not specified");
|
||||||
!(logfiles[id].file = fopen(filename, "a"))) {
|
|
||||||
LOG(LOGS_WARN, LOGF_Refclock, "Couldn't open logfile %s for update", filename);
|
|
||||||
logfiles[id].name = NULL;
|
logfiles[id].name = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close on exec */
|
logfiles[id].file = UTI_OpenFile(logdir, logfiles[id].name, ".log", 'a', 0644);
|
||||||
UTI_FdSetCloexec(fileno(logfiles[id].file));
|
if (!logfiles[id].file) {
|
||||||
|
/* Disable the log */
|
||||||
|
logfiles[id].name = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
banner = CNF_GetLogBanner();
|
banner = CNF_GetLogBanner();
|
||||||
@@ -257,7 +315,7 @@ LOG_FileWrite(LOG_FileID id, const char *format, ...)
|
|||||||
char bannerline[256];
|
char bannerline[256];
|
||||||
int i, bannerlen;
|
int i, bannerlen;
|
||||||
|
|
||||||
bannerlen = strlen(logfiles[id].banner);
|
bannerlen = MIN(strlen(logfiles[id].banner), sizeof (bannerline) - 1);
|
||||||
|
|
||||||
for (i = 0; i < bannerlen; i++)
|
for (i = 0; i < bannerlen; i++)
|
||||||
bannerline[i] = '=';
|
bannerline[i] = '=';
|
||||||
|
|||||||
95
logging.h
95
logging.h
@@ -31,9 +31,6 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
/* Flag indicating whether debug messages are logged */
|
|
||||||
extern int log_debug_enabled;
|
|
||||||
|
|
||||||
/* Line logging macros. If the compiler is GNU C, we take advantage of
|
/* Line logging macros. If the compiler is GNU C, we take advantage of
|
||||||
being able to get the function name also. */
|
being able to get the function name also. */
|
||||||
|
|
||||||
@@ -46,76 +43,38 @@ extern int log_debug_enabled;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG > 0
|
#if DEBUG > 0
|
||||||
#define LOG_MESSAGE(severity, facility, ...) \
|
#define LOG_MESSAGE(severity, ...) \
|
||||||
LOG_Message(severity, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__);
|
LOG_Message(severity, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define LOG_MESSAGE(severity, facility, ...) \
|
#define LOG_MESSAGE(severity, ...) \
|
||||||
LOG_Message(severity, __VA_ARGS__);
|
LOG_Message(severity, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEBUG_LOG(facility, ...) \
|
#define DEBUG_LOG(...) \
|
||||||
do { \
|
do { \
|
||||||
if (DEBUG && log_debug_enabled) \
|
if (DEBUG && log_min_severity == LOGS_DEBUG) \
|
||||||
LOG_MESSAGE(LOGS_DEBUG, facility, __VA_ARGS__); \
|
LOG_MESSAGE(LOGS_DEBUG, __VA_ARGS__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LOG_FATAL(facility, ...) \
|
#define LOG_FATAL(...) \
|
||||||
do { \
|
do { \
|
||||||
LOG_MESSAGE(LOGS_FATAL, facility, __VA_ARGS__); \
|
LOG_MESSAGE(LOGS_FATAL, __VA_ARGS__); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LOG(severity, facility, ...) LOG_MESSAGE(severity, facility, __VA_ARGS__)
|
#define LOG(severity, ...) LOG_MESSAGE(severity, __VA_ARGS__)
|
||||||
|
|
||||||
/* Definition of severity */
|
/* Definition of severity */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LOGS_INFO,
|
LOGS_DEBUG = -1,
|
||||||
|
LOGS_INFO = 0,
|
||||||
LOGS_WARN,
|
LOGS_WARN,
|
||||||
LOGS_ERR,
|
LOGS_ERR,
|
||||||
LOGS_FATAL,
|
LOGS_FATAL,
|
||||||
LOGS_DEBUG
|
|
||||||
} LOG_Severity;
|
} LOG_Severity;
|
||||||
|
|
||||||
/* Definition of facility. Each message is tagged with who generated
|
/* Minimum severity of messages to be logged */
|
||||||
it, so that the user can customise what level of reporting he gets
|
extern LOG_Severity log_min_severity;
|
||||||
for each area of the software */
|
|
||||||
typedef enum {
|
|
||||||
LOGF_Reference,
|
|
||||||
LOGF_NtpIO,
|
|
||||||
LOGF_NtpCore,
|
|
||||||
LOGF_NtpSources,
|
|
||||||
LOGF_Scheduler,
|
|
||||||
LOGF_SourceStats,
|
|
||||||
LOGF_Sources,
|
|
||||||
LOGF_Local,
|
|
||||||
LOGF_Util,
|
|
||||||
LOGF_Main,
|
|
||||||
LOGF_Memory,
|
|
||||||
LOGF_Client,
|
|
||||||
LOGF_ClientLog,
|
|
||||||
LOGF_Configure,
|
|
||||||
LOGF_CmdMon,
|
|
||||||
LOGF_Acquire,
|
|
||||||
LOGF_Manual,
|
|
||||||
LOGF_Keys,
|
|
||||||
LOGF_Logging,
|
|
||||||
LOGF_Nameserv,
|
|
||||||
LOGF_PrivOps,
|
|
||||||
LOGF_Rtc,
|
|
||||||
LOGF_Regress,
|
|
||||||
LOGF_Sys,
|
|
||||||
LOGF_SysGeneric,
|
|
||||||
LOGF_SysLinux,
|
|
||||||
LOGF_SysMacOSX,
|
|
||||||
LOGF_SysNetBSD,
|
|
||||||
LOGF_SysSolaris,
|
|
||||||
LOGF_SysTimex,
|
|
||||||
LOGF_SysWinnt,
|
|
||||||
LOGF_TempComp,
|
|
||||||
LOGF_RtcLinux,
|
|
||||||
LOGF_Refclock,
|
|
||||||
LOGF_Smooth,
|
|
||||||
} LOG_Facility;
|
|
||||||
|
|
||||||
/* Init function */
|
/* Init function */
|
||||||
extern void LOG_Initialise(void);
|
extern void LOG_Initialise(void);
|
||||||
@@ -125,26 +84,32 @@ extern void LOG_Finalise(void);
|
|||||||
|
|
||||||
/* Line logging function */
|
/* Line logging function */
|
||||||
#if DEBUG > 0
|
#if DEBUG > 0
|
||||||
FORMAT_ATTRIBUTE_PRINTF(6, 7)
|
FORMAT_ATTRIBUTE_PRINTF(5, 6)
|
||||||
extern void LOG_Message(LOG_Severity severity, LOG_Facility facility,
|
extern void LOG_Message(LOG_Severity severity, int line_number, const char *filename,
|
||||||
int line_number, const char *filename,
|
|
||||||
const char *function_name, const char *format, ...);
|
const char *function_name, const char *format, ...);
|
||||||
#else
|
#else
|
||||||
FORMAT_ATTRIBUTE_PRINTF(2, 3)
|
FORMAT_ATTRIBUTE_PRINTF(2, 3)
|
||||||
extern void LOG_Message(LOG_Severity severity, const char *format, ...);
|
extern void LOG_Message(LOG_Severity severity, const char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set debug level:
|
/* Set the minimum severity of a message to be logged or printed to terminal.
|
||||||
0, 1 - only non-debug messages are logged
|
If the severity is LOGS_DEBUG and DEBUG is enabled, all messages will be
|
||||||
2 - debug messages are logged too, all messages are prefixed with
|
prefixed with the filename, line number, and function name. */
|
||||||
filename, line, and function name
|
extern void LOG_SetMinSeverity(LOG_Severity severity);
|
||||||
*/
|
|
||||||
extern void LOG_SetDebugLevel(int level);
|
/* Get the minimum severity */
|
||||||
|
extern LOG_Severity LOG_GetMinSeverity(void);
|
||||||
|
|
||||||
|
/* Set a prefix for debug messages */
|
||||||
|
extern void LOG_SetDebugPrefix(const char *prefix);
|
||||||
|
|
||||||
|
/* Log messages to a file instead of stderr, or stderr again if NULL */
|
||||||
|
extern void LOG_OpenFileLog(const char *log_file);
|
||||||
|
|
||||||
/* Log messages to syslog instead of stderr */
|
/* Log messages to syslog instead of stderr */
|
||||||
extern void LOG_OpenSystemLog(void);
|
extern void LOG_OpenSystemLog(void);
|
||||||
|
|
||||||
/* Send fatal message also to the foreground process */
|
/* Stop using stderr and send fatal message to the foreground process */
|
||||||
extern void LOG_SetParentFd(int fd);
|
extern void LOG_SetParentFd(int fd);
|
||||||
|
|
||||||
/* Close the pipe to the foreground process so it can exit */
|
/* Close the pipe to the foreground process so it can exit */
|
||||||
|
|||||||
433
main.c
433
main.c
@@ -4,7 +4,7 @@
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) John G. Hasler 2009
|
* Copyright (C) John G. Hasler 2009
|
||||||
* Copyright (C) Miroslav Lichvar 2012-2015
|
* Copyright (C) Miroslav Lichvar 2012-2020
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -35,8 +35,12 @@
|
|||||||
#include "local.h"
|
#include "local.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "ntp_io.h"
|
#include "ntp_io.h"
|
||||||
|
#include "ntp_signd.h"
|
||||||
#include "ntp_sources.h"
|
#include "ntp_sources.h"
|
||||||
#include "ntp_core.h"
|
#include "ntp_core.h"
|
||||||
|
#include "nts_ke_server.h"
|
||||||
|
#include "nts_ntp_server.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "sources.h"
|
#include "sources.h"
|
||||||
#include "sourcestats.h"
|
#include "sourcestats.h"
|
||||||
#include "reference.h"
|
#include "reference.h"
|
||||||
@@ -72,11 +76,18 @@ static REF_Mode ref_mode = REF_ModeNormal;
|
|||||||
static void
|
static void
|
||||||
do_platform_checks(void)
|
do_platform_checks(void)
|
||||||
{
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
/* Require at least 32-bit integers, two's complement representation and
|
/* Require at least 32-bit integers, two's complement representation and
|
||||||
the usual implementation of conversion of unsigned integers */
|
the usual implementation of conversion of unsigned integers */
|
||||||
assert(sizeof (int) >= 4);
|
assert(sizeof (int) >= 4);
|
||||||
assert(-1 == ~0);
|
assert(-1 == ~0);
|
||||||
assert((int32_t)4294967295U == (int32_t)-1);
|
assert((int32_t)4294967295U == (int32_t)-1);
|
||||||
|
|
||||||
|
/* Require time_t and tv_nsec in timespec to be signed */
|
||||||
|
ts.tv_sec = -1;
|
||||||
|
ts.tv_nsec = -1;
|
||||||
|
assert(ts.tv_sec < 0 && ts.tv_nsec < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -85,8 +96,12 @@ static void
|
|||||||
delete_pidfile(void)
|
delete_pidfile(void)
|
||||||
{
|
{
|
||||||
const char *pidfile = CNF_GetPidFile();
|
const char *pidfile = CNF_GetPidFile();
|
||||||
/* Don't care if this fails, there's not a lot we can do */
|
|
||||||
unlink(pidfile);
|
if (!pidfile)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!UTI_RemoveFile(NULL, pidfile, NULL))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -96,9 +111,8 @@ MAI_CleanupAndExit(void)
|
|||||||
{
|
{
|
||||||
if (!initialised) exit(exit_status);
|
if (!initialised) exit(exit_status);
|
||||||
|
|
||||||
if (CNF_GetDumpOnExit()) {
|
LCL_CancelOffsetCorrection();
|
||||||
SRC_DumpSources();
|
SRC_DumpSources();
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't update clock when removing sources */
|
/* Don't update clock when removing sources */
|
||||||
REF_SetMode(REF_ModeIgnore);
|
REF_SetMode(REF_ModeIgnore);
|
||||||
@@ -107,17 +121,23 @@ MAI_CleanupAndExit(void)
|
|||||||
TMC_Finalise();
|
TMC_Finalise();
|
||||||
MNL_Finalise();
|
MNL_Finalise();
|
||||||
CLG_Finalise();
|
CLG_Finalise();
|
||||||
|
NKS_Finalise();
|
||||||
|
NNS_Finalise();
|
||||||
|
NSD_Finalise();
|
||||||
NSR_Finalise();
|
NSR_Finalise();
|
||||||
SST_Finalise();
|
SST_Finalise();
|
||||||
NCR_Finalise();
|
NCR_Finalise();
|
||||||
NIO_Finalise();
|
NIO_Finalise();
|
||||||
CAM_Finalise();
|
CAM_Finalise();
|
||||||
|
|
||||||
KEY_Finalise();
|
KEY_Finalise();
|
||||||
RCL_Finalise();
|
RCL_Finalise();
|
||||||
SRC_Finalise();
|
SRC_Finalise();
|
||||||
REF_Finalise();
|
REF_Finalise();
|
||||||
RTC_Finalise();
|
RTC_Finalise();
|
||||||
SYS_Finalise();
|
SYS_Finalise();
|
||||||
|
|
||||||
|
SCK_Finalise();
|
||||||
SCH_Finalise();
|
SCH_Finalise();
|
||||||
LCL_Finalise();
|
LCL_Finalise();
|
||||||
PRV_Finalise();
|
PRV_Finalise();
|
||||||
@@ -125,9 +145,10 @@ MAI_CleanupAndExit(void)
|
|||||||
delete_pidfile();
|
delete_pidfile();
|
||||||
|
|
||||||
CNF_Finalise();
|
CNF_Finalise();
|
||||||
|
HSH_Finalise();
|
||||||
LOG_Finalise();
|
LOG_Finalise();
|
||||||
|
|
||||||
HSH_Finalise();
|
UTI_ResetGetRandomFunctions();
|
||||||
|
|
||||||
exit(exit_status);
|
exit(exit_status);
|
||||||
}
|
}
|
||||||
@@ -137,7 +158,18 @@ MAI_CleanupAndExit(void)
|
|||||||
static void
|
static void
|
||||||
signal_cleanup(int x)
|
signal_cleanup(int x)
|
||||||
{
|
{
|
||||||
if (!initialised) exit(0);
|
SCH_QuitProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
quit_timeout(void *arg)
|
||||||
|
{
|
||||||
|
LOG(LOGS_INFO, "Timeout reached");
|
||||||
|
|
||||||
|
/* Return with non-zero status if the clock is not synchronised */
|
||||||
|
exit_status = REF_GetOurStratum() >= NTP_MAX_STRATUM;
|
||||||
SCH_QuitProgram();
|
SCH_QuitProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,13 +188,14 @@ ntp_source_resolving_end(void)
|
|||||||
SRC_ReloadSources();
|
SRC_ReloadSources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SRC_RemoveDumpFiles();
|
||||||
RTC_StartMeasurements();
|
RTC_StartMeasurements();
|
||||||
RCL_StartRefclocks();
|
RCL_StartRefclocks();
|
||||||
NSR_StartSources();
|
NSR_StartSources();
|
||||||
NSR_AutoStartSources();
|
NSR_AutoStartSources();
|
||||||
|
|
||||||
/* Special modes can end only when sources update their reachability.
|
/* Special modes can end only when sources update their reachability.
|
||||||
Give up immediatelly if there are no active sources. */
|
Give up immediately if there are no active sources. */
|
||||||
if (ref_mode != REF_ModeNormal && !SRC_ActiveSources()) {
|
if (ref_mode != REF_ModeNormal && !SRC_ActiveSources()) {
|
||||||
REF_SetUnsynchronised();
|
REF_SetUnsynchronised();
|
||||||
}
|
}
|
||||||
@@ -229,63 +262,54 @@ post_init_rtc_hook(void *anything)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Return 1 if the process exists on the system. */
|
|
||||||
|
|
||||||
static int
|
static void
|
||||||
does_process_exist(int pid)
|
check_pidfile(void)
|
||||||
{
|
|
||||||
int status;
|
|
||||||
status = getsid(pid);
|
|
||||||
if (status >= 0) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
static int
|
|
||||||
maybe_another_chronyd_running(int *other_pid)
|
|
||||||
{
|
{
|
||||||
const char *pidfile = CNF_GetPidFile();
|
const char *pidfile = CNF_GetPidFile();
|
||||||
FILE *in;
|
FILE *in;
|
||||||
int pid, count;
|
int pid, count;
|
||||||
|
|
||||||
*other_pid = 0;
|
if (!pidfile)
|
||||||
|
return;
|
||||||
|
|
||||||
in = fopen(pidfile, "r");
|
in = UTI_OpenFile(NULL, pidfile, NULL, 'r', 0);
|
||||||
if (!in) return 0;
|
if (!in)
|
||||||
|
return;
|
||||||
|
|
||||||
count = fscanf(in, "%d", &pid);
|
count = fscanf(in, "%d", &pid);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
if (count != 1) return 0;
|
if (count != 1)
|
||||||
|
return;
|
||||||
|
|
||||||
*other_pid = pid;
|
if (getsid(pid) < 0)
|
||||||
return does_process_exist(pid);
|
return;
|
||||||
|
|
||||||
|
LOG_FATAL("Another chronyd may already be running (pid=%d), check %s",
|
||||||
|
pid, pidfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_lockfile(void)
|
write_pidfile(void)
|
||||||
{
|
{
|
||||||
const char *pidfile = CNF_GetPidFile();
|
const char *pidfile = CNF_GetPidFile();
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
|
||||||
out = fopen(pidfile, "w");
|
if (!pidfile)
|
||||||
if (!out) {
|
return;
|
||||||
LOG_FATAL(LOGF_Main, "could not open lockfile %s for writing", pidfile);
|
|
||||||
} else {
|
out = UTI_OpenFile(NULL, pidfile, NULL, 'W', 0644);
|
||||||
fprintf(out, "%d\n", (int)getpid());
|
fprintf(out, "%d\n", (int)getpid());
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
#define DEV_NULL "/dev/null"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
go_daemon(void)
|
go_daemon(void)
|
||||||
{
|
{
|
||||||
@@ -294,14 +318,14 @@ go_daemon(void)
|
|||||||
/* Create pipe which will the daemon use to notify the grandparent
|
/* Create pipe which will the daemon use to notify the grandparent
|
||||||
when it's initialised or send an error message */
|
when it's initialised or send an error message */
|
||||||
if (pipe(pipefd)) {
|
if (pipe(pipefd)) {
|
||||||
LOG_FATAL(LOGF_Logging, "Could not detach, pipe failed : %s", strerror(errno));
|
LOG_FATAL("pipe() failed : %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Does this preserve existing signal handlers? */
|
/* Does this preserve existing signal handlers? */
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
LOG_FATAL(LOGF_Logging, "Could not detach, fork failed : %s", strerror(errno));
|
LOG_FATAL("fork() failed : %s", strerror(errno));
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
/* In the 'grandparent' */
|
/* In the 'grandparent' */
|
||||||
char message[1024];
|
char message[1024];
|
||||||
@@ -312,7 +336,8 @@ go_daemon(void)
|
|||||||
if (r) {
|
if (r) {
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
/* Print the error message from the child */
|
/* Print the error message from the child */
|
||||||
fprintf(stderr, "%.1024s\n", message);
|
message[sizeof (message) - 1] = '\0';
|
||||||
|
fprintf(stderr, "%s\n", message);
|
||||||
}
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
} else
|
} else
|
||||||
@@ -326,7 +351,7 @@ go_daemon(void)
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
LOG_FATAL(LOGF_Logging, "Could not detach, fork failed : %s", strerror(errno));
|
LOG_FATAL("fork() failed : %s", strerror(errno));
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
exit(0); /* In the 'parent' */
|
exit(0); /* In the 'parent' */
|
||||||
} else {
|
} else {
|
||||||
@@ -334,7 +359,7 @@ go_daemon(void)
|
|||||||
|
|
||||||
/* Change current directory to / */
|
/* Change current directory to / */
|
||||||
if (chdir("/") < 0) {
|
if (chdir("/") < 0) {
|
||||||
LOG_FATAL(LOGF_Logging, "Could not chdir to / : %s", strerror(errno));
|
LOG_FATAL("chdir() failed : %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't keep stdin/out/err from before. But don't close
|
/* Don't keep stdin/out/err from before. But don't close
|
||||||
@@ -345,152 +370,257 @@ go_daemon(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_SetParentFd(pipefd[1]);
|
LOG_SetParentFd(pipefd[1]);
|
||||||
|
|
||||||
|
/* Open /dev/null as new stdin/out/err */
|
||||||
|
errno = 0;
|
||||||
|
if (open(DEV_NULL, O_RDONLY) != STDIN_FILENO ||
|
||||||
|
open(DEV_NULL, O_WRONLY) != STDOUT_FILENO ||
|
||||||
|
open(DEV_NULL, O_RDWR) != STDERR_FILENO)
|
||||||
|
LOG_FATAL("Could not open %s : %s", DEV_NULL, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_help(const char *progname)
|
||||||
|
{
|
||||||
|
printf("Usage: %s [OPTION]... [DIRECTIVE]...\n\n"
|
||||||
|
"Options:\n"
|
||||||
|
" -4\t\tUse IPv4 addresses only\n"
|
||||||
|
" -6\t\tUse IPv6 addresses only\n"
|
||||||
|
" -f FILE\tSpecify configuration file (%s)\n"
|
||||||
|
" -n\t\tDon't run as daemon\n"
|
||||||
|
" -d\t\tDon't run as daemon and log to stderr\n"
|
||||||
|
#if DEBUG > 0
|
||||||
|
" -d -d\t\tEnable debug messages\n"
|
||||||
|
#endif
|
||||||
|
" -l FILE\tLog to file\n"
|
||||||
|
" -L LEVEL\tSet logging threshold (0)\n"
|
||||||
|
" -p\t\tPrint configuration and exit\n"
|
||||||
|
" -q\t\tSet clock and exit\n"
|
||||||
|
" -Q\t\tLog offset and exit\n"
|
||||||
|
" -r\t\tReload dump files\n"
|
||||||
|
" -R\t\tAdapt configuration for restart\n"
|
||||||
|
" -s\t\tSet clock from RTC\n"
|
||||||
|
" -t SECONDS\tExit after elapsed time\n"
|
||||||
|
" -u USER\tSpecify user (%s)\n"
|
||||||
|
" -U\t\tDon't check for root\n"
|
||||||
|
" -F LEVEL\tSet system call filter level (0)\n"
|
||||||
|
" -P PRIORITY\tSet process priority (0)\n"
|
||||||
|
" -m\t\tLock memory\n"
|
||||||
|
" -x\t\tDon't control clock\n"
|
||||||
|
" -v, --version\tPrint version and exit\n"
|
||||||
|
" -h, --help\tPrint usage and exit\n",
|
||||||
|
progname, DEFAULT_CONF_FILE, DEFAULT_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_version(void)
|
||||||
|
{
|
||||||
|
printf("chronyd (chrony) version %s (%s)\n", CHRONY_VERSION, CHRONYD_FEATURES);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
parse_int_arg(const char *arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (sscanf(arg, "%d", &i) != 1)
|
||||||
|
LOG_FATAL("Invalid argument %s", arg);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
int main
|
int main
|
||||||
(int argc, char **argv)
|
(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *conf_file = DEFAULT_CONF_FILE;
|
const char *conf_file = DEFAULT_CONF_FILE;
|
||||||
const char *progname = argv[0];
|
const char *progname = argv[0];
|
||||||
char *user = NULL;
|
char *user = NULL, *log_file = NULL;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
int debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
|
int opt, debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
|
||||||
int do_init_rtc = 0, restarted = 0;
|
int do_init_rtc = 0, restarted = 0, client_only = 0, timeout = -1;
|
||||||
int other_pid;
|
|
||||||
int scfilter_level = 0, lock_memory = 0, sched_priority = 0;
|
int scfilter_level = 0, lock_memory = 0, sched_priority = 0;
|
||||||
int system_log = 1;
|
int clock_control = 1, system_log = 1, log_severity = LOGS_INFO;
|
||||||
int config_args = 0;
|
int user_check = 1, config_args = 0, print_config = 0;
|
||||||
|
|
||||||
do_platform_checks();
|
do_platform_checks();
|
||||||
|
|
||||||
LOG_Initialise();
|
LOG_Initialise();
|
||||||
|
|
||||||
/* Parse command line options */
|
/* Parse long command-line options */
|
||||||
while (++argv, (--argc)>0) {
|
for (optind = 1; optind < argc; optind++) {
|
||||||
|
if (!strcmp("--help", argv[optind])) {
|
||||||
if (!strcmp("-f", *argv)) {
|
print_help(progname);
|
||||||
++argv, --argc;
|
|
||||||
conf_file = *argv;
|
|
||||||
} else if (!strcmp("-P", *argv)) {
|
|
||||||
++argv, --argc;
|
|
||||||
if (argc == 0 || sscanf(*argv, "%d", &sched_priority) != 1) {
|
|
||||||
LOG_FATAL(LOGF_Main, "Bad scheduler priority");
|
|
||||||
}
|
|
||||||
} else if (!strcmp("-m", *argv)) {
|
|
||||||
lock_memory = 1;
|
|
||||||
} else if (!strcmp("-r", *argv)) {
|
|
||||||
reload = 1;
|
|
||||||
} else if (!strcmp("-R", *argv)) {
|
|
||||||
restarted = 1;
|
|
||||||
} else if (!strcmp("-u", *argv)) {
|
|
||||||
++argv, --argc;
|
|
||||||
if (argc == 0) {
|
|
||||||
LOG_FATAL(LOGF_Main, "Missing user name");
|
|
||||||
} else {
|
|
||||||
user = *argv;
|
|
||||||
}
|
|
||||||
} else if (!strcmp("-F", *argv)) {
|
|
||||||
++argv, --argc;
|
|
||||||
if (argc == 0 || sscanf(*argv, "%d", &scfilter_level) != 1)
|
|
||||||
LOG_FATAL(LOGF_Main, "Bad syscall filter level");
|
|
||||||
} else if (!strcmp("-s", *argv)) {
|
|
||||||
do_init_rtc = 1;
|
|
||||||
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
|
||||||
/* This write to the terminal is OK, it comes before we turn into a daemon */
|
|
||||||
printf("chronyd (chrony) version %s (%s)\n", CHRONY_VERSION, CHRONYD_FEATURES);
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!strcmp("-n", *argv)) {
|
} else if (!strcmp("--version", argv[optind])) {
|
||||||
nofork = 1;
|
print_version();
|
||||||
} else if (!strcmp("-d", *argv)) {
|
|
||||||
debug++;
|
|
||||||
nofork = 1;
|
|
||||||
system_log = 0;
|
|
||||||
} else if (!strcmp("-q", *argv)) {
|
|
||||||
ref_mode = REF_ModeUpdateOnce;
|
|
||||||
nofork = 1;
|
|
||||||
system_log = 0;
|
|
||||||
} else if (!strcmp("-Q", *argv)) {
|
|
||||||
ref_mode = REF_ModePrintOnce;
|
|
||||||
nofork = 1;
|
|
||||||
system_log = 0;
|
|
||||||
} else if (!strcmp("-4", *argv)) {
|
|
||||||
address_family = IPADDR_INET4;
|
|
||||||
} else if (!strcmp("-6", *argv)) {
|
|
||||||
address_family = IPADDR_INET6;
|
|
||||||
} else if (!strcmp("-h", *argv) || !strcmp("--help", *argv)) {
|
|
||||||
printf("Usage: %s [-4|-6] [-n|-d] [-q|-Q] [-r] [-R] [-s] [-f FILE|COMMAND...]\n",
|
|
||||||
progname);
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (*argv[0] == '-') {
|
|
||||||
LOG_FATAL(LOGF_Main, "Unrecognized command line option [%s]", *argv);
|
|
||||||
} else {
|
|
||||||
/* Process remaining arguments and configuration lines */
|
|
||||||
config_args = argc;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getuid() != 0) {
|
optind = 1;
|
||||||
/* This write to the terminal is OK, it comes before we turn into a daemon */
|
|
||||||
fprintf(stderr,"Not superuser\n");
|
/* Parse short command-line options */
|
||||||
return 1;
|
while ((opt = getopt(argc, argv, "46df:F:hl:L:mnpP:qQrRst:u:Uvx")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case '4':
|
||||||
|
case '6':
|
||||||
|
address_family = opt == '4' ? IPADDR_INET4 : IPADDR_INET6;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
debug++;
|
||||||
|
nofork = 1;
|
||||||
|
system_log = 0;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
conf_file = optarg;
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
scfilter_level = parse_int_arg(optarg);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
log_file = optarg;
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
log_severity = parse_int_arg(optarg);
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
lock_memory = 1;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
nofork = 1;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
print_config = 1;
|
||||||
|
user_check = 0;
|
||||||
|
nofork = 1;
|
||||||
|
system_log = 0;
|
||||||
|
log_severity = LOGS_WARN;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
sched_priority = parse_int_arg(optarg);
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
ref_mode = REF_ModeUpdateOnce;
|
||||||
|
nofork = 1;
|
||||||
|
client_only = 0;
|
||||||
|
system_log = 0;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
ref_mode = REF_ModePrintOnce;
|
||||||
|
nofork = 1;
|
||||||
|
client_only = 1;
|
||||||
|
user_check = 0;
|
||||||
|
clock_control = 0;
|
||||||
|
system_log = 0;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
reload = 1;
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
restarted = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
do_init_rtc = 1;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
timeout = parse_int_arg(optarg);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
user = optarg;
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
user_check = 0;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
print_version();
|
||||||
|
return 0;
|
||||||
|
case 'x':
|
||||||
|
clock_control = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print_help(progname);
|
||||||
|
return opt != 'h';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user_check && getuid() != 0)
|
||||||
|
LOG_FATAL("Not superuser");
|
||||||
|
|
||||||
/* Turn into a daemon */
|
/* Turn into a daemon */
|
||||||
if (!nofork) {
|
if (!nofork) {
|
||||||
go_daemon();
|
go_daemon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system_log) {
|
if (log_file) {
|
||||||
|
LOG_OpenFileLog(log_file);
|
||||||
|
} else if (system_log) {
|
||||||
LOG_OpenSystemLog();
|
LOG_OpenSystemLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_SetDebugLevel(debug);
|
LOG_SetMinSeverity(debug >= 2 ? LOGS_DEBUG : log_severity);
|
||||||
|
|
||||||
LOG(LOGS_INFO, LOGF_Main, "chronyd version %s starting (%s)",
|
LOG(LOGS_INFO, "chronyd version %s starting (%s)", CHRONY_VERSION, CHRONYD_FEATURES);
|
||||||
CHRONY_VERSION, CHRONYD_FEATURES);
|
|
||||||
|
|
||||||
DNS_SetAddressFamily(address_family);
|
DNS_SetAddressFamily(address_family);
|
||||||
|
|
||||||
CNF_Initialise(restarted);
|
CNF_Initialise(restarted, client_only);
|
||||||
|
if (print_config)
|
||||||
|
CNF_EnablePrint();
|
||||||
|
|
||||||
/* Parse the config file or the remaining command line arguments */
|
/* Parse the config file or the remaining command line arguments */
|
||||||
|
config_args = argc - optind;
|
||||||
if (!config_args) {
|
if (!config_args) {
|
||||||
CNF_ReadFile(conf_file);
|
CNF_ReadFile(conf_file);
|
||||||
} else {
|
} else {
|
||||||
do {
|
for (; optind < argc; optind++)
|
||||||
CNF_ParseLine(NULL, config_args - argc + 1, *argv);
|
CNF_ParseLine(NULL, config_args + optind - argc + 1, argv[optind]);
|
||||||
} while (++argv, --argc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether another chronyd may already be running. Do this after
|
if (print_config)
|
||||||
* forking, so that message logging goes to the right place (i.e. syslog), in
|
return 0;
|
||||||
* case this chronyd is being run from a boot script. */
|
|
||||||
if (maybe_another_chronyd_running(&other_pid)) {
|
|
||||||
LOG_FATAL(LOGF_Main, "Another chronyd may already be running (pid=%d), check lockfile (%s)",
|
|
||||||
other_pid, CNF_GetPidFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write our lockfile to prevent other chronyds running. This has *GOT* to
|
/* Check whether another chronyd may already be running */
|
||||||
* be done *AFTER* the daemon-creation fork() */
|
check_pidfile();
|
||||||
write_lockfile();
|
|
||||||
|
if (!user)
|
||||||
|
user = CNF_GetUser();
|
||||||
|
|
||||||
|
pw = getpwnam(user);
|
||||||
|
if (!pw)
|
||||||
|
LOG_FATAL("Could not get user/group ID of %s", user);
|
||||||
|
|
||||||
|
/* Create directories for sockets, log files, and dump files */
|
||||||
|
CNF_CreateDirs(pw->pw_uid, pw->pw_gid);
|
||||||
|
|
||||||
|
/* Write our pidfile to prevent other instances from running */
|
||||||
|
write_pidfile();
|
||||||
|
|
||||||
PRV_Initialise();
|
PRV_Initialise();
|
||||||
LCL_Initialise();
|
LCL_Initialise();
|
||||||
SCH_Initialise();
|
SCH_Initialise();
|
||||||
SYS_Initialise();
|
SCK_Initialise(address_family);
|
||||||
|
|
||||||
|
/* Start helper processes if needed */
|
||||||
|
NKS_PreInitialise(pw->pw_uid, pw->pw_gid, scfilter_level);
|
||||||
|
|
||||||
|
SYS_Initialise(clock_control);
|
||||||
RTC_Initialise(do_init_rtc);
|
RTC_Initialise(do_init_rtc);
|
||||||
SRC_Initialise();
|
SRC_Initialise();
|
||||||
RCL_Initialise();
|
RCL_Initialise();
|
||||||
KEY_Initialise();
|
KEY_Initialise();
|
||||||
|
|
||||||
/* Open privileged ports before dropping root */
|
/* Open privileged ports before dropping root */
|
||||||
CAM_Initialise(address_family);
|
CAM_Initialise();
|
||||||
NIO_Initialise(address_family);
|
NIO_Initialise();
|
||||||
NCR_Initialise();
|
NCR_Initialise();
|
||||||
CNF_SetupAccessRestrictions();
|
CNF_SetupAccessRestrictions();
|
||||||
|
|
||||||
@@ -506,23 +636,19 @@ int main
|
|||||||
SYS_LockMemory();
|
SYS_LockMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user) {
|
/* Drop root privileges if the specified user has a non-zero UID */
|
||||||
user = CNF_GetUser();
|
if (!geteuid() && (pw->pw_uid || pw->pw_gid))
|
||||||
}
|
SYS_DropRoot(pw->pw_uid, pw->pw_gid, SYS_MAIN_PROCESS);
|
||||||
|
|
||||||
if ((pw = getpwnam(user)) == NULL)
|
if (!geteuid())
|
||||||
LOG_FATAL(LOGF_Main, "Could not get %s uid/gid", user);
|
LOG(LOGS_WARN, "Running with root privileges");
|
||||||
|
|
||||||
/* Create all directories before dropping root */
|
|
||||||
CNF_CreateDirs(pw->pw_uid, pw->pw_gid);
|
|
||||||
|
|
||||||
/* Drop root privileges if the user has non-zero uid or gid */
|
|
||||||
if (pw->pw_uid || pw->pw_gid)
|
|
||||||
SYS_DropRoot(pw->pw_uid, pw->pw_gid);
|
|
||||||
|
|
||||||
REF_Initialise();
|
REF_Initialise();
|
||||||
SST_Initialise();
|
SST_Initialise();
|
||||||
NSR_Initialise();
|
NSR_Initialise();
|
||||||
|
NSD_Initialise();
|
||||||
|
NNS_Initialise();
|
||||||
|
NKS_Initialise();
|
||||||
CLG_Initialise();
|
CLG_Initialise();
|
||||||
MNL_Initialise();
|
MNL_Initialise();
|
||||||
TMC_Initialise();
|
TMC_Initialise();
|
||||||
@@ -531,12 +657,12 @@ int main
|
|||||||
/* From now on, it is safe to do finalisation on exit */
|
/* From now on, it is safe to do finalisation on exit */
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
UTI_SetQuitSignalsHandler(signal_cleanup);
|
UTI_SetQuitSignalsHandler(signal_cleanup, 1);
|
||||||
|
|
||||||
CAM_OpenUnixSocket();
|
CAM_OpenUnixSocket();
|
||||||
|
|
||||||
if (scfilter_level)
|
if (scfilter_level)
|
||||||
SYS_EnableSystemCallFilter(scfilter_level);
|
SYS_EnableSystemCallFilter(scfilter_level, SYS_MAIN_PROCESS);
|
||||||
|
|
||||||
if (ref_mode == REF_ModeNormal && CNF_GetInitSources() > 0) {
|
if (ref_mode == REF_ModeNormal && CNF_GetInitSources() > 0) {
|
||||||
ref_mode = REF_ModeInitStepSlew;
|
ref_mode = REF_ModeInitStepSlew;
|
||||||
@@ -545,6 +671,9 @@ int main
|
|||||||
REF_SetModeEndHandler(reference_mode_end);
|
REF_SetModeEndHandler(reference_mode_end);
|
||||||
REF_SetMode(ref_mode);
|
REF_SetMode(ref_mode);
|
||||||
|
|
||||||
|
if (timeout >= 0)
|
||||||
|
SCH_AddTimeoutByDelay(timeout, quit_timeout, NULL);
|
||||||
|
|
||||||
if (do_init_rtc) {
|
if (do_init_rtc) {
|
||||||
RTC_TimeInit(post_init_rtc_hook, NULL);
|
RTC_TimeInit(post_init_rtc_hook, NULL);
|
||||||
} else {
|
} else {
|
||||||
@@ -555,7 +684,7 @@ int main
|
|||||||
the scheduler. */
|
the scheduler. */
|
||||||
SCH_MainLoop();
|
SCH_MainLoop();
|
||||||
|
|
||||||
LOG(LOGS_INFO, LOGF_Main, "chronyd exiting");
|
LOG(LOGS_INFO, "chronyd exiting");
|
||||||
|
|
||||||
MAI_CleanupAndExit();
|
MAI_CleanupAndExit();
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ cd RELEASES/$subdir || exit 1
|
|||||||
|
|
||||||
echo $version > version.txt
|
echo $version > version.txt
|
||||||
|
|
||||||
sed -i -e "s%@@VERSION@@%${version}%" examples/chrony.spec
|
|
||||||
|
|
||||||
./configure && make -C doc man txt || exit 1
|
./configure && make -C doc man txt || exit 1
|
||||||
|
|
||||||
iconv -f utf-8 -t ascii//TRANSLIT < doc/installation.txt > INSTALL
|
iconv -f utf-8 -t ascii//TRANSLIT < doc/installation.txt > INSTALL
|
||||||
|
|||||||
69
manual.c
69
manual.c
@@ -47,7 +47,7 @@ static int enabled = 0;
|
|||||||
|
|
||||||
/* More recent samples at highest indices */
|
/* More recent samples at highest indices */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct timeval when; /* This is our 'cooked' time */
|
struct timespec when; /* This is our 'cooked' time */
|
||||||
double orig_offset; /*+ Not modified by slew samples */
|
double orig_offset; /*+ Not modified by slew samples */
|
||||||
double offset; /*+ if we are fast of the supplied reference */
|
double offset; /*+ if we are fast of the supplied reference */
|
||||||
double residual; /*+ regression residual (sign convention given by
|
double residual; /*+ regression residual (sign convention given by
|
||||||
@@ -64,8 +64,8 @@ static int n_samples;
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
slew_samples(struct timeval *raw,
|
slew_samples(struct timespec *raw,
|
||||||
struct timeval *cooked,
|
struct timespec *cooked,
|
||||||
double dfreq,
|
double dfreq,
|
||||||
double doffset,
|
double doffset,
|
||||||
LCL_ChangeType change_type,
|
LCL_ChangeType change_type,
|
||||||
@@ -92,12 +92,14 @@ MNL_Initialise(void)
|
|||||||
void
|
void
|
||||||
MNL_Finalise(void)
|
MNL_Finalise(void)
|
||||||
{
|
{
|
||||||
|
LCL_RemoveParameterChangeHandler(slew_samples, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
estimate_and_set_system(struct timeval *now, int offset_provided, double offset, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm)
|
estimate_and_set_system(struct timespec *now, int offset_provided, double offset,
|
||||||
|
double *reg_offset, double *dfreq_ppm, double *new_afreq_ppm)
|
||||||
{
|
{
|
||||||
double agos[MAX_SAMPLES], offsets[MAX_SAMPLES];
|
double agos[MAX_SAMPLES], offsets[MAX_SAMPLES];
|
||||||
double b0, b1;
|
double b0, b1;
|
||||||
@@ -108,32 +110,26 @@ estimate_and_set_system(struct timeval *now, int offset_provided, double offset,
|
|||||||
int found_freq;
|
int found_freq;
|
||||||
double slew_by;
|
double slew_by;
|
||||||
|
|
||||||
|
b0 = offset_provided ? offset : 0.0;
|
||||||
|
b1 = freq = 0.0;
|
||||||
|
found_freq = 0;
|
||||||
|
|
||||||
if (n_samples > 1) {
|
if (n_samples > 1) {
|
||||||
for (i=0; i<n_samples; i++) {
|
for (i=0; i<n_samples; i++) {
|
||||||
UTI_DiffTimevalsToDouble(&agos[i], &samples[n_samples-1].when, &samples[i].when);
|
agos[i] = UTI_DiffTimespecsToDouble(&samples[n_samples - 1].when, &samples[i].when);
|
||||||
offsets[i] = samples[i].offset;
|
offsets[i] = samples[i].offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
RGR_FindBestRobustRegression(agos, offsets, n_samples,
|
if (RGR_FindBestRobustRegression(agos, offsets, n_samples, 1.0e-8,
|
||||||
1.0e-8, /* 0.01ppm easily good enough for this! */
|
&b0, &b1, &n_runs, &best_start)) {
|
||||||
&b0, &b1, &n_runs, &best_start);
|
/* Ignore b0 from regression; treat offset as being the most
|
||||||
|
recently entered value. (If the administrator knows he's put
|
||||||
|
an outlier in, he will rerun the settime operation.) However,
|
||||||
/* Ignore b0 from regression; treat offset as being the most
|
the frequency estimate comes from the regression. */
|
||||||
recently entered value. (If the administrator knows he's put
|
freq = -b1;
|
||||||
an outlier in, he will rerun the settime operation.) However,
|
found_freq = 1;
|
||||||
the frequency estimate comes from the regression. */
|
|
||||||
|
|
||||||
freq = -b1;
|
|
||||||
found_freq = 1;
|
|
||||||
} else {
|
|
||||||
if (offset_provided) {
|
|
||||||
b0 = offset;
|
|
||||||
} else {
|
|
||||||
b0 = 0.0;
|
|
||||||
}
|
}
|
||||||
b1 = freq = 0.0;
|
} else {
|
||||||
found_freq = 0;
|
|
||||||
agos[0] = 0.0;
|
agos[0] = 0.0;
|
||||||
offsets[0] = b0;
|
offsets[0] = b0;
|
||||||
}
|
}
|
||||||
@@ -145,21 +141,20 @@ estimate_and_set_system(struct timeval *now, int offset_provided, double offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found_freq) {
|
if (found_freq) {
|
||||||
LOG(LOGS_INFO, LOGF_Manual,
|
LOG(LOGS_INFO, "Making a frequency change of %.3f ppm and a slew of %.6f",
|
||||||
"Making a frequency change of %.3f ppm and a slew of %.6f",
|
|
||||||
1.0e6 * freq, slew_by);
|
1.0e6 * freq, slew_by);
|
||||||
|
|
||||||
REF_SetManualReference(now,
|
REF_SetManualReference(now,
|
||||||
slew_by,
|
slew_by,
|
||||||
freq, skew);
|
freq, skew);
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_INFO, LOGF_Manual, "Making a slew of %.6f", slew_by);
|
LOG(LOGS_INFO, "Making a slew of %.6f", slew_by);
|
||||||
REF_SetManualReference(now,
|
REF_SetManualReference(now,
|
||||||
slew_by,
|
slew_by,
|
||||||
0.0, skew);
|
0.0, skew);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset_cs) *offset_cs = (long)(0.5 + 100.0 * b0);
|
if (reg_offset) *reg_offset = b0;
|
||||||
if (dfreq_ppm) *dfreq_ppm = 1.0e6 * freq;
|
if (dfreq_ppm) *dfreq_ppm = 1.0e6 * freq;
|
||||||
if (new_afreq_ppm) *new_afreq_ppm = LCL_ReadAbsoluteFrequency();
|
if (new_afreq_ppm) *new_afreq_ppm = LCL_ReadAbsoluteFrequency();
|
||||||
|
|
||||||
@@ -173,9 +168,9 @@ estimate_and_set_system(struct timeval *now, int offset_provided, double offset,
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm)
|
MNL_AcceptTimestamp(struct timespec *ts, double *reg_offset, double *dfreq_ppm, double *new_afreq_ppm)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timespec now;
|
||||||
double offset, diff;
|
double offset, diff;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -189,12 +184,12 @@ MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, doub
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (n_samples) {
|
if (n_samples) {
|
||||||
UTI_DiffTimevalsToDouble(&diff, &now, &samples[n_samples - 1].when);
|
diff = UTI_DiffTimespecsToDouble(&now, &samples[n_samples - 1].when);
|
||||||
if (diff < MIN_SAMPLE_SEPARATION)
|
if (diff < MIN_SAMPLE_SEPARATION)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&offset, &now, ts);
|
offset = UTI_DiffTimespecsToDouble(&now, ts);
|
||||||
|
|
||||||
/* Check if buffer full up */
|
/* Check if buffer full up */
|
||||||
if (n_samples == MAX_SAMPLES) {
|
if (n_samples == MAX_SAMPLES) {
|
||||||
@@ -210,7 +205,7 @@ MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, doub
|
|||||||
samples[n_samples].orig_offset = offset;
|
samples[n_samples].orig_offset = offset;
|
||||||
++n_samples;
|
++n_samples;
|
||||||
|
|
||||||
estimate_and_set_system(&now, 1, offset, offset_cs, dfreq_ppm, new_afreq_ppm);
|
estimate_and_set_system(&now, 1, offset, reg_offset, dfreq_ppm, new_afreq_ppm);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -224,8 +219,8 @@ MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, doub
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
slew_samples(struct timeval *raw,
|
slew_samples(struct timespec *raw,
|
||||||
struct timeval *cooked,
|
struct timespec *cooked,
|
||||||
double dfreq,
|
double dfreq,
|
||||||
double doffset,
|
double doffset,
|
||||||
LCL_ChangeType change_type,
|
LCL_ChangeType change_type,
|
||||||
@@ -239,7 +234,7 @@ slew_samples(struct timeval *raw,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<n_samples; i++) {
|
for (i=0; i<n_samples; i++) {
|
||||||
UTI_AdjustTimeval(&samples[i].when, cooked, &samples[i].when, &delta_time,
|
UTI_AdjustTimespec(&samples[i].when, cooked, &samples[i].when, &delta_time,
|
||||||
dfreq, doffset);
|
dfreq, doffset);
|
||||||
samples[i].offset += delta_time;
|
samples[i].offset += delta_time;
|
||||||
}
|
}
|
||||||
@@ -309,7 +304,7 @@ int
|
|||||||
MNL_DeleteSample(int index)
|
MNL_DeleteSample(int index)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct timeval now;
|
struct timespec now;
|
||||||
|
|
||||||
if ((index < 0) || (index >= n_samples)) {
|
if ((index < 0) || (index >= n_samples)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
2
manual.h
2
manual.h
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
extern void MNL_Initialise(void);
|
extern void MNL_Initialise(void);
|
||||||
extern void MNL_Finalise(void);
|
extern void MNL_Finalise(void);
|
||||||
extern int MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm);
|
extern int MNL_AcceptTimestamp(struct timespec *ts, double *reg_offset, double *dfreq_ppm, double *new_afreq_ppm);
|
||||||
|
|
||||||
extern void MNL_Enable(void);
|
extern void MNL_Enable(void);
|
||||||
extern void MNL_Disable(void);
|
extern void MNL_Disable(void);
|
||||||
|
|||||||
34
memory.c
34
memory.c
@@ -2,7 +2,7 @@
|
|||||||
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Miroslav Lichvar 2014
|
* Copyright (C) Miroslav Lichvar 2014, 2017
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -37,7 +37,7 @@ Malloc(size_t size)
|
|||||||
|
|
||||||
r = malloc(size);
|
r = malloc(size);
|
||||||
if (!r && size)
|
if (!r && size)
|
||||||
LOG_FATAL(LOGF_Memory, "Could not allocate memory");
|
LOG_FATAL("Could not allocate memory");
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -49,11 +49,37 @@ Realloc(void *ptr, size_t size)
|
|||||||
|
|
||||||
r = realloc(ptr, size);
|
r = realloc(ptr, size);
|
||||||
if (!r && size)
|
if (!r && size)
|
||||||
LOG_FATAL(LOGF_Memory, "Could not allocate memory");
|
LOG_FATAL("Could not allocate memory");
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
get_array_size(size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
size_t array_size;
|
||||||
|
|
||||||
|
array_size = nmemb * size;
|
||||||
|
|
||||||
|
/* Check for overflow */
|
||||||
|
if (nmemb > 0 && array_size / nmemb != size)
|
||||||
|
LOG_FATAL("Could not allocate memory");
|
||||||
|
|
||||||
|
return array_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
Malloc2(size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
return Malloc(get_array_size(nmemb, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
Realloc2(void *ptr, size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
return Realloc(ptr, get_array_size(nmemb, size));
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
Strdup(const char *s)
|
Strdup(const char *s)
|
||||||
{
|
{
|
||||||
@@ -61,7 +87,7 @@ Strdup(const char *s)
|
|||||||
|
|
||||||
r = strdup(s);
|
r = strdup(s);
|
||||||
if (!r)
|
if (!r)
|
||||||
LOG_FATAL(LOGF_Memory, "Could not allocate memory");
|
LOG_FATAL("Could not allocate memory");
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
8
memory.h
8
memory.h
@@ -27,15 +27,19 @@
|
|||||||
#ifndef GOT_MEMORY_H
|
#ifndef GOT_MEMORY_H
|
||||||
#define GOT_MEMORY_H
|
#define GOT_MEMORY_H
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
/* Wrappers checking for errors */
|
/* Wrappers checking for errors */
|
||||||
extern void *Malloc(size_t size);
|
extern void *Malloc(size_t size);
|
||||||
extern void *Realloc(void *ptr, size_t size);
|
extern void *Realloc(void *ptr, size_t size);
|
||||||
|
extern void *Malloc2(size_t nmemb, size_t size);
|
||||||
|
extern void *Realloc2(void *ptr, size_t nmemb, size_t size);
|
||||||
extern char *Strdup(const char *s);
|
extern char *Strdup(const char *s);
|
||||||
|
|
||||||
/* Convenient macros */
|
/* Convenient macros */
|
||||||
#define MallocNew(T) ((T *) Malloc(sizeof(T)))
|
#define MallocNew(T) ((T *) Malloc(sizeof(T)))
|
||||||
#define MallocArray(T, n) ((T *) Malloc((n) * sizeof(T)))
|
#define MallocArray(T, n) ((T *) Malloc2(n, sizeof(T)))
|
||||||
#define ReallocArray(T,n,x) ((T *) Realloc((void *)(x), (n)*sizeof(T)))
|
#define ReallocArray(T, n, x) ((T *) Realloc2((void *)(x), n, sizeof(T)))
|
||||||
#define Free(x) free(x)
|
#define Free(x) free(x)
|
||||||
|
|
||||||
#endif /* GOT_MEMORY_H */
|
#endif /* GOT_MEMORY_H */
|
||||||
|
|||||||
110
nameserv.c
110
nameserv.c
@@ -30,7 +30,11 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
|
||||||
#include "nameserv.h"
|
#include "nameserv.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -46,15 +50,39 @@ DNS_SetAddressFamily(int family)
|
|||||||
DNS_Status
|
DNS_Status
|
||||||
DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETADDRINFO
|
|
||||||
struct addrinfo hints, *res, *ai;
|
struct addrinfo hints, *res, *ai;
|
||||||
int i, result;
|
int i, result;
|
||||||
|
IPAddr ip;
|
||||||
|
|
||||||
max_addrs = MIN(max_addrs, DNS_MAX_ADDRESSES);
|
max_addrs = MIN(max_addrs, DNS_MAX_ADDRESSES);
|
||||||
|
|
||||||
|
for (i = 0; i < max_addrs; i++)
|
||||||
|
ip_addrs[i].family = IPADDR_UNSPEC;
|
||||||
|
|
||||||
|
/* Avoid calling getaddrinfo() if the name is an IP address */
|
||||||
|
if (UTI_StringToIP(name, &ip)) {
|
||||||
|
if (address_family != IPADDR_UNSPEC && ip.family != address_family)
|
||||||
|
return DNS_Failure;
|
||||||
|
if (max_addrs >= 1)
|
||||||
|
ip_addrs[0] = ip;
|
||||||
|
return DNS_Success;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&hints, 0, sizeof (hints));
|
memset(&hints, 0, sizeof (hints));
|
||||||
hints.ai_family = AF_UNSPEC;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
switch (address_family) {
|
||||||
|
case IPADDR_INET4:
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
break;
|
||||||
|
#ifdef FEAT_IPV6
|
||||||
|
case IPADDR_INET6:
|
||||||
|
hints.ai_family = AF_INET6;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
}
|
||||||
|
hints.ai_socktype = SOCK_DGRAM;
|
||||||
|
|
||||||
result = getaddrinfo(name, NULL, &hints, &res);
|
result = getaddrinfo(name, NULL, &hints, &res);
|
||||||
|
|
||||||
@@ -79,6 +107,9 @@ DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
|||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
if (address_family != IPADDR_UNSPEC && address_family != IPADDR_INET6)
|
if (address_family != IPADDR_UNSPEC && address_family != IPADDR_INET6)
|
||||||
continue;
|
continue;
|
||||||
|
/* Don't return an address that would lose a scope ID */
|
||||||
|
if (((struct sockaddr_in6 *)ai->ai_addr)->sin6_scope_id != 0)
|
||||||
|
continue;
|
||||||
ip_addrs[i].family = IPADDR_INET6;
|
ip_addrs[i].family = IPADDR_INET6;
|
||||||
memcpy(&ip_addrs[i].addr.in6, &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr.s6_addr,
|
memcpy(&ip_addrs[i].addr.in6, &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr.s6_addr,
|
||||||
sizeof (ip_addrs->addr.in6));
|
sizeof (ip_addrs->addr.in6));
|
||||||
@@ -88,48 +119,9 @@ DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; i < max_addrs; i++)
|
|
||||||
ip_addrs[i].family = IPADDR_UNSPEC;
|
|
||||||
|
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
|
|
||||||
return !max_addrs || ip_addrs[0].family != IPADDR_UNSPEC ? DNS_Success : DNS_Failure;
|
return !max_addrs || ip_addrs[0].family != IPADDR_UNSPEC ? DNS_Success : DNS_Failure;
|
||||||
#else
|
|
||||||
struct hostent *host;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (address_family != IPADDR_UNSPEC && address_family != IPADDR_INET4)
|
|
||||||
return DNS_Failure;
|
|
||||||
|
|
||||||
max_addrs = MIN(max_addrs, DNS_MAX_ADDRESSES);
|
|
||||||
|
|
||||||
host = gethostbyname(name);
|
|
||||||
|
|
||||||
if (host == NULL) {
|
|
||||||
if (h_errno == TRY_AGAIN)
|
|
||||||
return DNS_TryAgain;
|
|
||||||
} else {
|
|
||||||
if (host->h_addrtype != AF_INET || !host->h_addr_list[0])
|
|
||||||
return DNS_Failure;
|
|
||||||
|
|
||||||
for (i = 0; host->h_addr_list[i] && i < max_addrs; i++) {
|
|
||||||
ip_addrs[i].family = IPADDR_INET4;
|
|
||||||
ip_addrs[i].addr.in4 = ntohl(*(uint32_t *)host->h_addr_list[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i < max_addrs; i++)
|
|
||||||
ip_addrs[i].family = IPADDR_UNSPEC;
|
|
||||||
|
|
||||||
return DNS_Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef FORCE_DNSRETRY
|
|
||||||
return DNS_TryAgain;
|
|
||||||
#else
|
|
||||||
return DNS_Failure;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -138,35 +130,21 @@ int
|
|||||||
DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len)
|
DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len)
|
||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
|
||||||
#ifdef FEAT_IPV6
|
#ifdef FEAT_IPV6
|
||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 saddr;
|
||||||
|
#else
|
||||||
|
struct sockaddr_in saddr;
|
||||||
|
#endif
|
||||||
|
IPSockAddr ip_saddr;
|
||||||
socklen_t slen;
|
socklen_t slen;
|
||||||
char hbuf[NI_MAXHOST];
|
char hbuf[NI_MAXHOST];
|
||||||
|
|
||||||
slen = UTI_IPAndPortToSockaddr(ip_addr, 0, (struct sockaddr *)&in6);
|
ip_saddr.ip_addr = *ip_addr;
|
||||||
if (!getnameinfo((struct sockaddr *)&in6, slen, hbuf, sizeof (hbuf), NULL, 0, 0))
|
ip_saddr.port = 0;
|
||||||
result = hbuf;
|
|
||||||
#else
|
|
||||||
struct hostent *host;
|
|
||||||
uint32_t addr;
|
|
||||||
|
|
||||||
switch (ip_addr->family) {
|
slen = SCK_IPSockAddrToSockaddr(&ip_saddr, (struct sockaddr *)&saddr, sizeof (saddr));
|
||||||
case IPADDR_INET4:
|
if (!getnameinfo((struct sockaddr *)&saddr, slen, hbuf, sizeof (hbuf), NULL, 0, 0))
|
||||||
addr = htonl(ip_addr->addr.in4);
|
result = hbuf;
|
||||||
host = gethostbyaddr((const char *) &addr, sizeof (ip_addr), AF_INET);
|
|
||||||
break;
|
|
||||||
#ifdef FEAT_IPV6
|
|
||||||
case IPADDR_INET6:
|
|
||||||
host = gethostbyaddr((const void *) ip_addr->addr.in6, sizeof (ip_addr->addr.in6), AF_INET6);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
host = NULL;
|
|
||||||
}
|
|
||||||
if (host)
|
|
||||||
result = host->h_name;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
result = UTI_IPToString(ip_addr);
|
result = UTI_IPToString(ip_addr);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct DNS_Async_Instance {
|
|||||||
int pipe[2];
|
int pipe[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
static int resolving_threads = 0;
|
static pthread_mutex_t privops_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -60,7 +60,9 @@ start_resolving(void *anything)
|
|||||||
{
|
{
|
||||||
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&privops_lock);
|
||||||
inst->status = PRV_Name2IPAddress(inst->name, inst->addresses, DNS_MAX_ADDRESSES);
|
inst->status = PRV_Name2IPAddress(inst->name, inst->addresses, DNS_MAX_ADDRESSES);
|
||||||
|
pthread_mutex_unlock(&privops_lock);
|
||||||
|
|
||||||
/* Notify the main thread that the result is ready */
|
/* Notify the main thread that the result is ready */
|
||||||
if (write(inst->pipe[1], "", 1) < 0)
|
if (write(inst->pipe[1], "", 1) < 0)
|
||||||
@@ -72,18 +74,16 @@ start_resolving(void *anything)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
end_resolving(void *anything)
|
end_resolving(int fd, int event, void *anything)
|
||||||
{
|
{
|
||||||
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (pthread_join(inst->thread, NULL)) {
|
if (pthread_join(inst->thread, NULL)) {
|
||||||
LOG_FATAL(LOGF_Nameserv, "pthread_join() failed");
|
LOG_FATAL("pthread_join() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
resolving_threads--;
|
SCH_RemoveFileHandler(inst->pipe[0]);
|
||||||
|
|
||||||
SCH_RemoveInputFileHandler(inst->pipe[0]);
|
|
||||||
close(inst->pipe[0]);
|
close(inst->pipe[0]);
|
||||||
close(inst->pipe[1]);
|
close(inst->pipe[1]);
|
||||||
|
|
||||||
@@ -110,17 +110,17 @@ DNS_Name2IPAddressAsync(const char *name, DNS_NameResolveHandler handler, void *
|
|||||||
inst->status = DNS_Failure;
|
inst->status = DNS_Failure;
|
||||||
|
|
||||||
if (pipe(inst->pipe)) {
|
if (pipe(inst->pipe)) {
|
||||||
LOG_FATAL(LOGF_Nameserv, "pipe() failed");
|
LOG_FATAL("pipe() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
resolving_threads++;
|
UTI_FdSetCloexec(inst->pipe[0]);
|
||||||
assert(resolving_threads <= 1);
|
UTI_FdSetCloexec(inst->pipe[1]);
|
||||||
|
|
||||||
if (pthread_create(&inst->thread, NULL, start_resolving, inst)) {
|
if (pthread_create(&inst->thread, NULL, start_resolving, inst)) {
|
||||||
LOG_FATAL(LOGF_Nameserv, "pthread_create() failed");
|
LOG_FATAL("pthread_create() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
SCH_AddInputFileHandler(inst->pipe[0], end_resolving, inst);
|
SCH_AddFileHandler(inst->pipe[0], SCH_FILE_INPUT, end_resolving, inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
109
ntp.h
109
ntp.h
@@ -38,23 +38,33 @@ typedef struct {
|
|||||||
|
|
||||||
typedef uint32_t NTP_int32;
|
typedef uint32_t NTP_int32;
|
||||||
|
|
||||||
|
/* The UDP port number used by NTP */
|
||||||
|
#define NTP_PORT 123
|
||||||
|
|
||||||
/* The NTP protocol version that we support */
|
/* The NTP protocol version that we support */
|
||||||
#define NTP_VERSION 4
|
#define NTP_VERSION 4
|
||||||
|
|
||||||
/* Maximum stratum number (infinity) */
|
/* Maximum stratum number (infinity) */
|
||||||
#define NTP_MAX_STRATUM 16
|
#define NTP_MAX_STRATUM 16
|
||||||
|
|
||||||
/* The minimum valid length of an extension field */
|
/* Invalid stratum number */
|
||||||
#define NTP_MIN_EXTENSION_LENGTH 16
|
#define NTP_INVALID_STRATUM 0
|
||||||
|
|
||||||
/* The maximum assumed length of all extension fields in received
|
|
||||||
packets (RFC 5905 doesn't specify a limit on length or number of
|
|
||||||
extension fields in one packet) */
|
|
||||||
#define NTP_MAX_EXTENSIONS_LENGTH 1024
|
|
||||||
|
|
||||||
/* The minimum and maximum supported length of MAC */
|
/* The minimum and maximum supported length of MAC */
|
||||||
#define NTP_MIN_MAC_LENGTH 16
|
#define NTP_MIN_MAC_LENGTH (4 + 16)
|
||||||
#define NTP_MAX_MAC_LENGTH MAX_HASH_LENGTH
|
#define NTP_MAX_MAC_LENGTH (4 + MAX_HASH_LENGTH)
|
||||||
|
|
||||||
|
/* The minimum valid length of an extension field */
|
||||||
|
#define NTP_MIN_EF_LENGTH 16
|
||||||
|
|
||||||
|
/* The maximum assumed length of all extension fields in an NTP packet,
|
||||||
|
including a MAC (RFC 5905 doesn't specify a limit on length or number of
|
||||||
|
extension fields in one packet) */
|
||||||
|
#define NTP_MAX_EXTENSIONS_LENGTH (1024 + NTP_MAX_MAC_LENGTH)
|
||||||
|
|
||||||
|
/* The maximum length of MAC in NTPv4 packets which allows deterministic
|
||||||
|
parsing of extension fields (RFC 7822) */
|
||||||
|
#define NTP_MAX_V4_MAC_LENGTH (4 + 20)
|
||||||
|
|
||||||
/* Type definition for leap bits */
|
/* Type definition for leap bits */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -86,21 +96,10 @@ typedef struct {
|
|||||||
NTP_int64 receive_ts;
|
NTP_int64 receive_ts;
|
||||||
NTP_int64 transmit_ts;
|
NTP_int64 transmit_ts;
|
||||||
|
|
||||||
/* Optional extension fields, we don't send packets with them yet */
|
uint8_t extensions[NTP_MAX_EXTENSIONS_LENGTH];
|
||||||
/* uint8_t extensions[] */
|
|
||||||
|
|
||||||
/* Optional message authentication code (MAC) */
|
|
||||||
NTP_int32 auth_keyid;
|
|
||||||
uint8_t auth_data[NTP_MAX_MAC_LENGTH];
|
|
||||||
} NTP_Packet;
|
} NTP_Packet;
|
||||||
|
|
||||||
#define NTP_NORMAL_PACKET_LENGTH (int)offsetof(NTP_Packet, auth_keyid)
|
#define NTP_HEADER_LENGTH (int)offsetof(NTP_Packet, extensions)
|
||||||
|
|
||||||
/* The buffer used to hold a datagram read from the network */
|
|
||||||
typedef struct {
|
|
||||||
NTP_Packet ntp_pkt;
|
|
||||||
uint8_t extensions[NTP_MAX_EXTENSIONS_LENGTH];
|
|
||||||
} NTP_Receive_Buffer;
|
|
||||||
|
|
||||||
/* Macros to work with the lvm field */
|
/* Macros to work with the lvm field */
|
||||||
#define NTP_LVM_TO_LEAP(lvm) (((lvm) >> 6) & 0x3)
|
#define NTP_LVM_TO_LEAP(lvm) (((lvm) >> 6) & 0x3)
|
||||||
@@ -114,4 +113,70 @@ typedef struct {
|
|||||||
#define NTP_REFID_LOCAL 0x7F7F0101UL /* 127.127.1.1 */
|
#define NTP_REFID_LOCAL 0x7F7F0101UL /* 127.127.1.1 */
|
||||||
#define NTP_REFID_SMOOTH 0x7F7F01FFUL /* 127.127.1.255 */
|
#define NTP_REFID_SMOOTH 0x7F7F01FFUL /* 127.127.1.255 */
|
||||||
|
|
||||||
|
/* Non-authentication extension fields and corresponding internal flags */
|
||||||
|
|
||||||
|
#define NTP_EF_EXP1 0xF323
|
||||||
|
|
||||||
|
#define NTP_EF_FLAG_EXP1 0x1
|
||||||
|
|
||||||
|
/* Pre-NTPv5 experimental extension field */
|
||||||
|
typedef struct {
|
||||||
|
uint32_t magic;
|
||||||
|
NTP_int32 root_delay;
|
||||||
|
NTP_int32 root_dispersion;
|
||||||
|
NTP_int64 mono_receive_ts;
|
||||||
|
uint32_t mono_epoch;
|
||||||
|
} NTP_ExtFieldExp1;
|
||||||
|
|
||||||
|
#define NTP_EF_EXP1_MAGIC 0xF5BEDD9AU
|
||||||
|
|
||||||
|
/* Authentication extension fields */
|
||||||
|
|
||||||
|
#define NTP_EF_NTS_UNIQUE_IDENTIFIER 0x0104
|
||||||
|
#define NTP_EF_NTS_COOKIE 0x0204
|
||||||
|
#define NTP_EF_NTS_COOKIE_PLACEHOLDER 0x0304
|
||||||
|
#define NTP_EF_NTS_AUTH_AND_EEF 0x0404
|
||||||
|
|
||||||
|
/* Enumeration for authentication modes of NTP packets */
|
||||||
|
typedef enum {
|
||||||
|
NTP_AUTH_NONE = 0, /* No authentication */
|
||||||
|
NTP_AUTH_SYMMETRIC, /* NTP MAC or CMAC using a symmetric key
|
||||||
|
(RFC 1305, RFC 5905, RFC 8573) */
|
||||||
|
NTP_AUTH_MSSNTP, /* MS-SNTP authenticator field */
|
||||||
|
NTP_AUTH_MSSNTP_EXT, /* MS-SNTP extended authenticator field */
|
||||||
|
NTP_AUTH_NTS, /* Network Time Security (RFC 8915) */
|
||||||
|
} NTP_AuthMode;
|
||||||
|
|
||||||
|
/* Structure describing an NTP packet */
|
||||||
|
typedef struct {
|
||||||
|
int length;
|
||||||
|
int version;
|
||||||
|
NTP_Mode mode;
|
||||||
|
|
||||||
|
int ext_fields;
|
||||||
|
int ext_field_flags;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
NTP_AuthMode mode;
|
||||||
|
struct {
|
||||||
|
int start;
|
||||||
|
int length;
|
||||||
|
uint32_t key_id;
|
||||||
|
} mac;
|
||||||
|
} auth;
|
||||||
|
} NTP_PacketInfo;
|
||||||
|
|
||||||
|
/* Structure used to save NTP measurements. time is the local time at which
|
||||||
|
the sample is to be considered to have been made and offset is the offset at
|
||||||
|
the time (positive indicates that the local clock is slow relative to the
|
||||||
|
source). root_delay/root_dispersion include peer_delay/peer_dispersion. */
|
||||||
|
typedef struct {
|
||||||
|
struct timespec time;
|
||||||
|
double offset;
|
||||||
|
double peer_delay;
|
||||||
|
double peer_dispersion;
|
||||||
|
double root_delay;
|
||||||
|
double root_dispersion;
|
||||||
|
} NTP_Sample;
|
||||||
|
|
||||||
#endif /* GOT_NTP_H */
|
#endif /* GOT_NTP_H */
|
||||||
|
|||||||
386
ntp_auth.c
Normal file
386
ntp_auth.c
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2019-2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
NTP authentication
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "keys.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "ntp_auth.h"
|
||||||
|
#include "ntp_signd.h"
|
||||||
|
#include "nts_ntp.h"
|
||||||
|
#include "nts_ntp_client.h"
|
||||||
|
#include "nts_ntp_server.h"
|
||||||
|
#include "srcparams.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
/* Structure to hold authentication configuration and state */
|
||||||
|
|
||||||
|
struct NAU_Instance_Record {
|
||||||
|
NTP_AuthMode mode; /* Authentication mode of NTP packets */
|
||||||
|
uint32_t key_id; /* Identifier of a symmetric key */
|
||||||
|
NNC_Instance nts; /* Client NTS state */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
generate_symmetric_auth(uint32_t key_id, NTP_Packet *packet, NTP_PacketInfo *info)
|
||||||
|
{
|
||||||
|
int auth_len, max_auth_len;
|
||||||
|
|
||||||
|
if (info->length + NTP_MIN_MAC_LENGTH > sizeof (*packet)) {
|
||||||
|
DEBUG_LOG("Packet too long");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Truncate long MACs in NTPv4 packets to allow deterministic parsing
|
||||||
|
of extension fields (RFC 7822) */
|
||||||
|
max_auth_len = (info->version == 4 ? NTP_MAX_V4_MAC_LENGTH : NTP_MAX_MAC_LENGTH) - 4;
|
||||||
|
max_auth_len = MIN(max_auth_len, sizeof (*packet) - info->length - 4);
|
||||||
|
|
||||||
|
auth_len = KEY_GenerateAuth(key_id, packet, info->length,
|
||||||
|
(unsigned char *)packet + info->length + 4, max_auth_len);
|
||||||
|
if (auth_len < NTP_MIN_MAC_LENGTH - 4) {
|
||||||
|
DEBUG_LOG("Could not generate auth data with key %"PRIu32, key_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(uint32_t *)((unsigned char *)packet + info->length) = htonl(key_id);
|
||||||
|
|
||||||
|
info->auth.mac.start = info->length;
|
||||||
|
info->auth.mac.length = 4 + auth_len;
|
||||||
|
info->auth.mac.key_id = key_id;
|
||||||
|
info->length += info->auth.mac.length;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_symmetric_auth(NTP_Packet *packet, NTP_PacketInfo *info)
|
||||||
|
{
|
||||||
|
int trunc_len;
|
||||||
|
|
||||||
|
if (info->auth.mac.length < NTP_MIN_MAC_LENGTH)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
trunc_len = info->version == 4 && info->auth.mac.length <= NTP_MAX_V4_MAC_LENGTH ?
|
||||||
|
NTP_MAX_V4_MAC_LENGTH : NTP_MAX_MAC_LENGTH;
|
||||||
|
|
||||||
|
if (!KEY_CheckAuth(info->auth.mac.key_id, packet, info->auth.mac.start,
|
||||||
|
(unsigned char *)packet + info->auth.mac.start + 4,
|
||||||
|
info->auth.mac.length - 4, trunc_len - 4))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static NAU_Instance
|
||||||
|
create_instance(NTP_AuthMode mode)
|
||||||
|
{
|
||||||
|
NAU_Instance instance;
|
||||||
|
|
||||||
|
instance = MallocNew(struct NAU_Instance_Record);
|
||||||
|
instance->mode = mode;
|
||||||
|
instance->key_id = INACTIVE_AUTHKEY;
|
||||||
|
instance->nts = NULL;
|
||||||
|
|
||||||
|
assert(sizeof (instance->key_id) == 4);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NAU_Instance
|
||||||
|
NAU_CreateNoneInstance(void)
|
||||||
|
{
|
||||||
|
return create_instance(NTP_AUTH_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NAU_Instance
|
||||||
|
NAU_CreateSymmetricInstance(uint32_t key_id)
|
||||||
|
{
|
||||||
|
NAU_Instance instance = create_instance(NTP_AUTH_SYMMETRIC);
|
||||||
|
|
||||||
|
instance->key_id = key_id;
|
||||||
|
|
||||||
|
if (!KEY_KeyKnown(key_id))
|
||||||
|
LOG(LOGS_WARN, "Key %"PRIu32" is %s", key_id, "missing");
|
||||||
|
else if (!KEY_CheckKeyLength(key_id))
|
||||||
|
LOG(LOGS_WARN, "Key %"PRIu32" is %s", key_id, "too short");
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NAU_Instance
|
||||||
|
NAU_CreateNtsInstance(IPSockAddr *nts_address, const char *name, uint32_t cert_set,
|
||||||
|
uint16_t ntp_port)
|
||||||
|
{
|
||||||
|
NAU_Instance instance = create_instance(NTP_AUTH_NTS);
|
||||||
|
|
||||||
|
instance->nts = NNC_CreateInstance(nts_address, name, cert_set, ntp_port);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NAU_DestroyInstance(NAU_Instance instance)
|
||||||
|
{
|
||||||
|
if (instance->mode == NTP_AUTH_NTS)
|
||||||
|
NNC_DestroyInstance(instance->nts);
|
||||||
|
Free(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_IsAuthEnabled(NAU_Instance instance)
|
||||||
|
{
|
||||||
|
return instance->mode != NTP_AUTH_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_GetSuggestedNtpVersion(NAU_Instance instance)
|
||||||
|
{
|
||||||
|
/* If the MAC in NTPv4 packets would be truncated, prefer NTPv3 for
|
||||||
|
compatibility with older chronyd servers */
|
||||||
|
if (instance->mode == NTP_AUTH_SYMMETRIC &&
|
||||||
|
KEY_GetAuthLength(instance->key_id) + sizeof (instance->key_id) > NTP_MAX_V4_MAC_LENGTH)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
return NTP_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_PrepareRequestAuth(NAU_Instance instance)
|
||||||
|
{
|
||||||
|
switch (instance->mode) {
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
if (!NNC_PrepareForAuth(instance->nts))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_GenerateRequestAuth(NAU_Instance instance, NTP_Packet *request, NTP_PacketInfo *info)
|
||||||
|
{
|
||||||
|
switch (instance->mode) {
|
||||||
|
case NTP_AUTH_NONE:
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_SYMMETRIC:
|
||||||
|
if (!generate_symmetric_auth(instance->key_id, request, info))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
if (!NNC_GenerateRequestAuth(instance->nts, request, info))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
info->auth.mode = instance->mode;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_CheckRequestAuth(NTP_Packet *request, NTP_PacketInfo *info, uint32_t *kod)
|
||||||
|
{
|
||||||
|
*kod = 0;
|
||||||
|
|
||||||
|
switch (info->auth.mode) {
|
||||||
|
case NTP_AUTH_NONE:
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_SYMMETRIC:
|
||||||
|
if (!check_symmetric_auth(request, info))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_MSSNTP:
|
||||||
|
/* MS-SNTP requests are not authenticated */
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_MSSNTP_EXT:
|
||||||
|
/* Not supported yet */
|
||||||
|
return 0;
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
if (!NNS_CheckRequestAuth(request, info, kod))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *request_info,
|
||||||
|
NTP_Packet *response, NTP_PacketInfo *response_info,
|
||||||
|
NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
|
||||||
|
uint32_t kod)
|
||||||
|
{
|
||||||
|
switch (request_info->auth.mode) {
|
||||||
|
case NTP_AUTH_NONE:
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_SYMMETRIC:
|
||||||
|
if (!generate_symmetric_auth(request_info->auth.mac.key_id, response, response_info))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_MSSNTP:
|
||||||
|
/* Sign the packet asynchronously by ntp_signd */
|
||||||
|
if (!NSD_SignAndSendPacket(request_info->auth.mac.key_id, response, response_info,
|
||||||
|
remote_addr, local_addr))
|
||||||
|
return 0;
|
||||||
|
/* Don't send the original packet */
|
||||||
|
return 0;
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
if (!NNS_GenerateResponseAuth(request, request_info, response, response_info, kod))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DEBUG_LOG("Could not authenticate response auth_mode=%d", (int)request_info->auth.mode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
response_info->auth.mode = request_info->auth.mode;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NAU_CheckResponseAuth(NAU_Instance instance, NTP_Packet *response, NTP_PacketInfo *info)
|
||||||
|
{
|
||||||
|
/* The authentication must match the expected mode */
|
||||||
|
if (info->auth.mode != instance->mode)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (info->auth.mode) {
|
||||||
|
case NTP_AUTH_NONE:
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_SYMMETRIC:
|
||||||
|
/* Check if it is authenticated with the specified key */
|
||||||
|
if (info->auth.mac.key_id != instance->key_id)
|
||||||
|
return 0;
|
||||||
|
/* and that the MAC is valid */
|
||||||
|
if (!check_symmetric_auth(response, info))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
if (!NNC_CheckResponseAuth(instance->nts, response, info))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NAU_ChangeAddress(NAU_Instance instance, IPAddr *address)
|
||||||
|
{
|
||||||
|
switch (instance->mode) {
|
||||||
|
case NTP_AUTH_NONE:
|
||||||
|
case NTP_AUTH_SYMMETRIC:
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
NNC_ChangeAddress(instance->nts, address);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NAU_DumpData(NAU_Instance instance)
|
||||||
|
{
|
||||||
|
switch (instance->mode) {
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
NNC_DumpData(instance->nts);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NAU_GetReport(NAU_Instance instance, RPT_AuthReport *report)
|
||||||
|
{
|
||||||
|
memset(report, 0, sizeof (*report));
|
||||||
|
|
||||||
|
report->mode = instance->mode;
|
||||||
|
report->last_ke_ago = -1;
|
||||||
|
|
||||||
|
switch (instance->mode) {
|
||||||
|
case NTP_AUTH_NONE:
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_SYMMETRIC:
|
||||||
|
report->key_id = instance->key_id;
|
||||||
|
KEY_GetKeyInfo(instance->key_id, &report->key_type, &report->key_length);
|
||||||
|
break;
|
||||||
|
case NTP_AUTH_NTS:
|
||||||
|
NNC_GetReport(instance->nts, report);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
84
ntp_auth.h
Normal file
84
ntp_auth.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2019
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for NTP authentication
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTP_AUTH_H
|
||||||
|
#define GOT_NTP_AUTH_H
|
||||||
|
|
||||||
|
#include "addressing.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
#include "reports.h"
|
||||||
|
|
||||||
|
typedef struct NAU_Instance_Record *NAU_Instance;
|
||||||
|
|
||||||
|
/* Create an authenticator instance in a specific mode */
|
||||||
|
extern NAU_Instance NAU_CreateNoneInstance(void);
|
||||||
|
extern NAU_Instance NAU_CreateSymmetricInstance(uint32_t key_id);
|
||||||
|
extern NAU_Instance NAU_CreateNtsInstance(IPSockAddr *nts_address, const char *name,
|
||||||
|
uint32_t cert_set, uint16_t ntp_port);
|
||||||
|
|
||||||
|
/* Destroy an instance */
|
||||||
|
extern void NAU_DestroyInstance(NAU_Instance instance);
|
||||||
|
|
||||||
|
/* Check if an instance is not in the None mode */
|
||||||
|
extern int NAU_IsAuthEnabled(NAU_Instance instance);
|
||||||
|
|
||||||
|
/* Get NTP version recommended for better compatibility */
|
||||||
|
extern int NAU_GetSuggestedNtpVersion(NAU_Instance instance);
|
||||||
|
|
||||||
|
/* Perform operations necessary for NAU_GenerateRequestAuth() */
|
||||||
|
extern int NAU_PrepareRequestAuth(NAU_Instance instance);
|
||||||
|
|
||||||
|
/* Extend a request with data required by the authentication mode */
|
||||||
|
extern int NAU_GenerateRequestAuth(NAU_Instance instance, NTP_Packet *request,
|
||||||
|
NTP_PacketInfo *info);
|
||||||
|
|
||||||
|
/* Verify that a request is authentic. If it is not authentic and a non-zero
|
||||||
|
kod code is returned, a KoD response should be sent back. */
|
||||||
|
extern int NAU_CheckRequestAuth(NTP_Packet *request, NTP_PacketInfo *info, uint32_t *kod);
|
||||||
|
|
||||||
|
/* Extend a response with data required by the authentication mode. This
|
||||||
|
function can be called only if the previous call of NAU_CheckRequestAuth()
|
||||||
|
was on the same request. */
|
||||||
|
extern int NAU_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *request_info,
|
||||||
|
NTP_Packet *response, NTP_PacketInfo *response_info,
|
||||||
|
NTP_Remote_Address *remote_addr,
|
||||||
|
NTP_Local_Address *local_addr,
|
||||||
|
uint32_t kod);
|
||||||
|
|
||||||
|
/* Verify that a response is authentic */
|
||||||
|
extern int NAU_CheckResponseAuth(NAU_Instance instance, NTP_Packet *response,
|
||||||
|
NTP_PacketInfo *info);
|
||||||
|
|
||||||
|
/* Change an authentication-specific address (e.g. after replacing a source) */
|
||||||
|
extern void NAU_ChangeAddress(NAU_Instance instance, IPAddr *address);
|
||||||
|
|
||||||
|
/* Save authentication-specific data to speed up the next start */
|
||||||
|
extern void NAU_DumpData(NAU_Instance instance);
|
||||||
|
|
||||||
|
/* Provide a report about the current authentication state */
|
||||||
|
extern void NAU_GetReport(NAU_Instance instance, RPT_AuthReport *report);
|
||||||
|
|
||||||
|
#endif
|
||||||
2195
ntp_core.c
2195
ntp_core.c
File diff suppressed because it is too large
Load Diff
56
ntp_core.h
56
ntp_core.h
@@ -38,6 +38,18 @@ typedef enum {
|
|||||||
NTP_SERVER, NTP_PEER
|
NTP_SERVER, NTP_PEER
|
||||||
} NTP_Source_Type;
|
} NTP_Source_Type;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NTP_TS_DAEMON = 0,
|
||||||
|
NTP_TS_KERNEL,
|
||||||
|
NTP_TS_HARDWARE
|
||||||
|
} NTP_Timestamp_Source;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
struct timespec ts;
|
||||||
|
double err;
|
||||||
|
NTP_Timestamp_Source source;
|
||||||
|
} NTP_Local_Timestamp;
|
||||||
|
|
||||||
/* This is a private data type used for storing the instance record for
|
/* This is a private data type used for storing the instance record for
|
||||||
each source that we are chiming with */
|
each source that we are chiming with */
|
||||||
typedef struct NCR_Instance_Record *NCR_Instance;
|
typedef struct NCR_Instance_Record *NCR_Instance;
|
||||||
@@ -47,7 +59,8 @@ extern void NCR_Initialise(void);
|
|||||||
extern void NCR_Finalise(void);
|
extern void NCR_Finalise(void);
|
||||||
|
|
||||||
/* Get a new instance for a server or peer */
|
/* Get a new instance for a server or peer */
|
||||||
extern NCR_Instance NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params);
|
extern NCR_Instance NCR_CreateInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
|
||||||
|
SourceParameters *params, const char *name);
|
||||||
|
|
||||||
/* Destroy an instance */
|
/* Destroy an instance */
|
||||||
extern void NCR_DestroyInstance(NCR_Instance instance);
|
extern void NCR_DestroyInstance(NCR_Instance instance);
|
||||||
@@ -58,26 +71,39 @@ extern void NCR_StartInstance(NCR_Instance instance);
|
|||||||
/* Reset an instance */
|
/* Reset an instance */
|
||||||
extern void NCR_ResetInstance(NCR_Instance inst);
|
extern void NCR_ResetInstance(NCR_Instance inst);
|
||||||
|
|
||||||
|
/* Reset polling interval of an instance */
|
||||||
|
extern void NCR_ResetPoll(NCR_Instance instance);
|
||||||
|
|
||||||
/* Change the remote address of an instance */
|
/* Change the remote address of an instance */
|
||||||
extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr);
|
extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr,
|
||||||
|
int ntp_only);
|
||||||
|
|
||||||
/* This routine is called when a new packet arrives off the network,
|
/* This routine is called when a new packet arrives off the network,
|
||||||
and it relates to a source we have an ongoing protocol exchange with */
|
and it relates to a source we have an ongoing protocol exchange with */
|
||||||
extern int NCR_ProcessKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data, NTP_Local_Address *local_addr, int length);
|
extern int NCR_ProcessRxKnown(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length);
|
||||||
|
|
||||||
/* This routine is called when a new packet arrives off the network,
|
/* This routine is called when a new packet arrives off the network,
|
||||||
and we do not recognize its source */
|
and we do not recognize its source */
|
||||||
extern void NCR_ProcessUnknown(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);
|
extern void NCR_ProcessRxUnknown(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length);
|
||||||
|
|
||||||
|
/* This routine is called when a packet is sent to a source we have
|
||||||
|
an ongoing protocol exchange with */
|
||||||
|
extern void NCR_ProcessTxKnown(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *tx_ts, NTP_Packet *message, int length);
|
||||||
|
|
||||||
|
/* This routine is called when a packet is sent to a destination we
|
||||||
|
do not recognize */
|
||||||
|
extern void NCR_ProcessTxUnknown(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *tx_ts, NTP_Packet *message, int length);
|
||||||
|
|
||||||
/* Slew receive and transmit times in instance records */
|
/* Slew receive and transmit times in instance records */
|
||||||
extern void NCR_SlewTimes(NCR_Instance inst, struct timeval *when, double dfreq, double doffset);
|
extern void NCR_SlewTimes(NCR_Instance inst, struct timespec *when, double dfreq, double doffset);
|
||||||
|
|
||||||
/* Take a particular source online (i.e. start sampling it) */
|
/* Take a particular source online (i.e. start sampling it) or offline
|
||||||
extern void NCR_TakeSourceOnline(NCR_Instance inst);
|
(i.e. stop sampling it) */
|
||||||
|
extern void NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity);
|
||||||
/* Take a particular source offline (i.e. stop sampling it, without
|
|
||||||
marking it unreachable in the source selection stuff) */
|
|
||||||
extern void NCR_TakeSourceOffline(NCR_Instance inst);
|
|
||||||
|
|
||||||
extern void NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll);
|
extern void NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll);
|
||||||
|
|
||||||
@@ -95,7 +121,9 @@ extern void NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target);
|
|||||||
|
|
||||||
extern void NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_samples);
|
extern void NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_samples);
|
||||||
|
|
||||||
extern void NCR_ReportSource(NCR_Instance inst, RPT_SourceReport *report, struct timeval *now);
|
extern void NCR_ReportSource(NCR_Instance inst, RPT_SourceReport *report, struct timespec *now);
|
||||||
|
extern void NCR_GetAuthReport(NCR_Instance inst, RPT_AuthReport *report);
|
||||||
|
extern void NCR_GetNTPReport(NCR_Instance inst, RPT_NTPReport *report);
|
||||||
|
|
||||||
extern int NCR_AddAccessRestriction(IPAddr *ip_addr, int subnet_bits, int allow, int all);
|
extern int NCR_AddAccessRestriction(IPAddr *ip_addr, int subnet_bits, int allow, int all);
|
||||||
extern int NCR_CheckAccessRestriction(IPAddr *ip_addr);
|
extern int NCR_CheckAccessRestriction(IPAddr *ip_addr);
|
||||||
@@ -109,6 +137,8 @@ extern uint32_t NCR_GetLocalRefid(NCR_Instance inst);
|
|||||||
|
|
||||||
extern int NCR_IsSyncPeer(NCR_Instance instance);
|
extern int NCR_IsSyncPeer(NCR_Instance instance);
|
||||||
|
|
||||||
extern void NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval);
|
extern void NCR_DumpAuthData(NCR_Instance inst);
|
||||||
|
|
||||||
|
extern void NCR_AddBroadcastDestination(NTP_Remote_Address *addr, int interval);
|
||||||
|
|
||||||
#endif /* GOT_NTP_CORE_H */
|
#endif /* GOT_NTP_CORE_H */
|
||||||
|
|||||||
192
ntp_ext.c
Normal file
192
ntp_ext.c
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2019-2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Functions for adding and parsing NTPv4 extension fields
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "ntp_ext.h"
|
||||||
|
|
||||||
|
struct ExtFieldHeader {
|
||||||
|
uint16_t type;
|
||||||
|
uint16_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
format_field(unsigned char *buffer, int buffer_length, int start,
|
||||||
|
int type, int body_length, int *length, void **body)
|
||||||
|
{
|
||||||
|
struct ExtFieldHeader *header;
|
||||||
|
|
||||||
|
if (buffer_length < 0 || start < 0 || buffer_length <= start ||
|
||||||
|
buffer_length - start < sizeof (*header) || start % 4 != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
header = (struct ExtFieldHeader *)(buffer + start);
|
||||||
|
|
||||||
|
if (body_length < 0 || sizeof (*header) + body_length > 0xffff ||
|
||||||
|
start + sizeof (*header) + body_length > buffer_length || body_length % 4 != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
header->type = htons(type);
|
||||||
|
header->length = htons(sizeof (*header) + body_length);
|
||||||
|
*length = sizeof (*header) + body_length;
|
||||||
|
*body = header + 1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NEF_SetField(unsigned char *buffer, int buffer_length, int start,
|
||||||
|
int type, void *body, int body_length, int *length)
|
||||||
|
{
|
||||||
|
void *ef_body;
|
||||||
|
|
||||||
|
if (!format_field(buffer, buffer_length, start, type, body_length, length, &ef_body))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(ef_body, body, body_length);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NEF_AddBlankField(NTP_Packet *packet, NTP_PacketInfo *info, int type, int body_length, void **body)
|
||||||
|
{
|
||||||
|
int ef_length, length = info->length;
|
||||||
|
|
||||||
|
if (length < NTP_HEADER_LENGTH || length >= sizeof (*packet) || length % 4 != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Only NTPv4 packets can have extension fields */
|
||||||
|
if (info->version != 4)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!format_field((unsigned char *)packet, sizeof (*packet), length,
|
||||||
|
type, body_length, &ef_length, body))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (ef_length < NTP_MIN_EF_LENGTH)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
info->length += ef_length;
|
||||||
|
info->ext_fields++;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NEF_AddField(NTP_Packet *packet, NTP_PacketInfo *info,
|
||||||
|
int type, void *body, int body_length)
|
||||||
|
{
|
||||||
|
void *ef_body;
|
||||||
|
|
||||||
|
if (!NEF_AddBlankField(packet, info, type, body_length, &ef_body))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(ef_body, body, body_length);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NEF_ParseSingleField(unsigned char *buffer, int buffer_length, int start,
|
||||||
|
int *length, int *type, void **body, int *body_length)
|
||||||
|
{
|
||||||
|
struct ExtFieldHeader *header;
|
||||||
|
int ef_length;
|
||||||
|
|
||||||
|
if (buffer_length < 0 || start < 0 || buffer_length <= start ||
|
||||||
|
buffer_length - start < sizeof (*header))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
header = (struct ExtFieldHeader *)(buffer + start);
|
||||||
|
|
||||||
|
assert(sizeof (*header) == 4);
|
||||||
|
|
||||||
|
ef_length = ntohs(header->length);
|
||||||
|
|
||||||
|
if (ef_length < (int)(sizeof (*header)) || start + ef_length > buffer_length ||
|
||||||
|
ef_length % 4 != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (length)
|
||||||
|
*length = ef_length;
|
||||||
|
if (type)
|
||||||
|
*type = ntohs(header->type);
|
||||||
|
if (body)
|
||||||
|
*body = header + 1;
|
||||||
|
if (body_length)
|
||||||
|
*body_length = ef_length - sizeof (*header);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NEF_ParseField(NTP_Packet *packet, int packet_length, int start,
|
||||||
|
int *length, int *type, void **body, int *body_length)
|
||||||
|
{
|
||||||
|
int ef_length;
|
||||||
|
|
||||||
|
if (packet_length <= NTP_HEADER_LENGTH || packet_length > sizeof (*packet) ||
|
||||||
|
packet_length <= start || packet_length % 4 != 0 ||
|
||||||
|
start < NTP_HEADER_LENGTH || start % 4 != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Only NTPv4 packets have extension fields */
|
||||||
|
if (NTP_LVM_TO_VERSION(packet->lvm) != 4)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Check if the remaining data is a MAC. RFC 7822 specifies the maximum
|
||||||
|
length of a MAC in NTPv4 packets in order to enable deterministic
|
||||||
|
parsing. */
|
||||||
|
if (packet_length - start <= NTP_MAX_V4_MAC_LENGTH)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!NEF_ParseSingleField((unsigned char *)packet, packet_length, start,
|
||||||
|
&ef_length, type, body, body_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (ef_length < NTP_MIN_EF_LENGTH)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (length)
|
||||||
|
*length = ef_length;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
43
ntp_ext.h
Normal file
43
ntp_ext.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2019
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for NTP extension fields
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTP_EXT_H
|
||||||
|
#define GOT_NTP_EXT_H
|
||||||
|
|
||||||
|
#include "ntp.h"
|
||||||
|
|
||||||
|
extern int NEF_SetField(unsigned char *buffer, int buffer_length, int start,
|
||||||
|
int type, void *body, int body_length, int *length);
|
||||||
|
extern int NEF_AddBlankField(NTP_Packet *packet, NTP_PacketInfo *info, int type,
|
||||||
|
int body_length, void **body);
|
||||||
|
extern int NEF_AddField(NTP_Packet *packet, NTP_PacketInfo *info,
|
||||||
|
int type, void *body, int body_length);
|
||||||
|
extern int NEF_ParseSingleField(unsigned char *buffer, int buffer_length, int start,
|
||||||
|
int *length, int *type, void **body, int *body_length);
|
||||||
|
extern int NEF_ParseField(NTP_Packet *packet, int packet_length, int start,
|
||||||
|
int *length, int *type, void **body, int *body_length);
|
||||||
|
|
||||||
|
#endif
|
||||||
15
ntp_io.h
15
ntp_io.h
@@ -31,9 +31,10 @@
|
|||||||
|
|
||||||
#include "ntp.h"
|
#include "ntp.h"
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
/* Function to initialise the module. */
|
/* Function to initialise the module. */
|
||||||
extern void NIO_Initialise(int family);
|
extern void NIO_Initialise(void);
|
||||||
|
|
||||||
/* Function to finalise the module */
|
/* Function to finalise the module */
|
||||||
extern void NIO_Finalise(void);
|
extern void NIO_Finalise(void);
|
||||||
@@ -53,7 +54,17 @@ extern void NIO_CloseServerSocket(int sock_fd);
|
|||||||
/* Function to check if socket is a server socket */
|
/* Function to check if socket is a server socket */
|
||||||
extern int NIO_IsServerSocket(int sock_fd);
|
extern int NIO_IsServerSocket(int sock_fd);
|
||||||
|
|
||||||
|
/* Function to check if a server socket is currently open */
|
||||||
|
extern int NIO_IsServerSocketOpen(void);
|
||||||
|
|
||||||
|
/* Function to check if client packets can be sent to a server */
|
||||||
|
extern int NIO_IsServerConnectable(NTP_Remote_Address *remote_addr);
|
||||||
|
|
||||||
|
/* Function to unwrap an NTP message from non-native transport (e.g. PTP) */
|
||||||
|
extern int NIO_UnwrapMessage(SCK_Message *message, int sock_fd);
|
||||||
|
|
||||||
/* Function to transmit a packet */
|
/* Function to transmit a packet */
|
||||||
extern int NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);
|
extern int NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr,
|
||||||
|
NTP_Local_Address *local_addr, int length, int process_tx);
|
||||||
|
|
||||||
#endif /* GOT_NTP_IO_H */
|
#endif /* GOT_NTP_IO_H */
|
||||||
|
|||||||
847
ntp_io_linux.c
Normal file
847
ntp_io_linux.c
Normal file
@@ -0,0 +1,847 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016-2019
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Functions for NTP I/O specific to Linux
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <linux/ethtool.h>
|
||||||
|
#include <linux/net_tstamp.h>
|
||||||
|
#include <linux/sockios.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include "array.h"
|
||||||
|
#include "conf.h"
|
||||||
|
#include "hwclock.h"
|
||||||
|
#include "local.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "ntp_core.h"
|
||||||
|
#include "ntp_io.h"
|
||||||
|
#include "ntp_io_linux.h"
|
||||||
|
#include "ntp_sources.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "socket.h"
|
||||||
|
#include "sys_linux.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
struct Interface {
|
||||||
|
char name[IF_NAMESIZE];
|
||||||
|
int if_index;
|
||||||
|
int phc_fd;
|
||||||
|
int phc_mode;
|
||||||
|
int phc_nocrossts;
|
||||||
|
/* Link speed in mbit/s */
|
||||||
|
int link_speed;
|
||||||
|
/* Start of UDP data at layer 2 for IPv4 and IPv6 */
|
||||||
|
int l2_udp4_ntp_start;
|
||||||
|
int l2_udp6_ntp_start;
|
||||||
|
/* Compensation of errors in TX and RX timestamping */
|
||||||
|
double tx_comp;
|
||||||
|
double rx_comp;
|
||||||
|
HCL_Instance clock;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Number of PHC readings per HW clock sample */
|
||||||
|
#define PHC_READINGS 25
|
||||||
|
|
||||||
|
/* Minimum interval between PHC readings */
|
||||||
|
#define MIN_PHC_POLL -6
|
||||||
|
|
||||||
|
/* Maximum acceptable offset between SW/HW and daemon timestamp */
|
||||||
|
#define MAX_TS_DELAY 1.0
|
||||||
|
|
||||||
|
/* Array of Interfaces */
|
||||||
|
static ARR_Instance interfaces;
|
||||||
|
|
||||||
|
/* RX/TX and TX-specific timestamping socket options */
|
||||||
|
static int ts_flags;
|
||||||
|
static int ts_tx_flags;
|
||||||
|
|
||||||
|
/* Flag indicating the socket options can't be changed in control messages */
|
||||||
|
static int permanent_ts_options;
|
||||||
|
|
||||||
|
/* When sending client requests to a close and fast server, it is possible that
|
||||||
|
a response will be received before the HW transmit timestamp of the request
|
||||||
|
itself. To avoid processing of the response without the HW timestamp, we
|
||||||
|
monitor events returned by select() and suspend reading of packets from the
|
||||||
|
receive queue for up to 200 microseconds. As the requests are normally
|
||||||
|
separated by at least 200 milliseconds, it is sufficient to monitor and
|
||||||
|
suspend one socket at a time. */
|
||||||
|
static int monitored_socket;
|
||||||
|
static int suspended_socket;
|
||||||
|
static SCH_TimeoutID resume_timeout_id;
|
||||||
|
|
||||||
|
#define RESUME_TIMEOUT 200.0e-6
|
||||||
|
|
||||||
|
/* Unbound socket keeping the kernel RX timestamping permanently enabled
|
||||||
|
in order to avoid a race condition between receiving a server response
|
||||||
|
and the kernel actually starting to timestamp received packets after
|
||||||
|
enabling the timestamping and sending a request */
|
||||||
|
static int dummy_rxts_socket;
|
||||||
|
|
||||||
|
#define INVALID_SOCK_FD -3
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
add_interface(CNF_HwTsInterface *conf_iface)
|
||||||
|
{
|
||||||
|
struct ethtool_ts_info ts_info;
|
||||||
|
struct hwtstamp_config ts_config;
|
||||||
|
struct ifreq req;
|
||||||
|
int sock_fd, if_index, phc_fd, req_hwts_flags, rx_filter;
|
||||||
|
unsigned int i;
|
||||||
|
struct Interface *iface;
|
||||||
|
|
||||||
|
/* Check if the interface was not already added */
|
||||||
|
for (i = 0; i < ARR_GetSize(interfaces); i++) {
|
||||||
|
if (!strcmp(conf_iface->name, ((struct Interface *)ARR_GetElement(interfaces, i))->name))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenUdpSocket(NULL, NULL, NULL, 0);
|
||||||
|
if (sock_fd < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof (req));
|
||||||
|
memset(&ts_info, 0, sizeof (ts_info));
|
||||||
|
|
||||||
|
if (snprintf(req.ifr_name, sizeof (req.ifr_name), "%s", conf_iface->name) >=
|
||||||
|
sizeof (req.ifr_name)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(sock_fd, SIOCGIFINDEX, &req)) {
|
||||||
|
DEBUG_LOG("ioctl(%s) failed : %s", "SIOCGIFINDEX", strerror(errno));
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if_index = req.ifr_ifindex;
|
||||||
|
|
||||||
|
ts_info.cmd = ETHTOOL_GET_TS_INFO;
|
||||||
|
req.ifr_data = (char *)&ts_info;
|
||||||
|
|
||||||
|
if (ioctl(sock_fd, SIOCETHTOOL, &req)) {
|
||||||
|
DEBUG_LOG("ioctl(%s) failed : %s", "SIOCETHTOOL", strerror(errno));
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
req_hwts_flags = SOF_TIMESTAMPING_RX_HARDWARE | SOF_TIMESTAMPING_TX_HARDWARE |
|
||||||
|
SOF_TIMESTAMPING_RAW_HARDWARE;
|
||||||
|
if ((ts_info.so_timestamping & req_hwts_flags) != req_hwts_flags) {
|
||||||
|
DEBUG_LOG("HW timestamping not supported on %s", req.ifr_name);
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts_info.phc_index < 0) {
|
||||||
|
DEBUG_LOG("PHC missing on %s", req.ifr_name);
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (conf_iface->rxfilter) {
|
||||||
|
case CNF_HWTS_RXFILTER_ANY:
|
||||||
|
#ifdef HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP
|
||||||
|
if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_NTP_ALL))
|
||||||
|
rx_filter = HWTSTAMP_FILTER_NTP_ALL;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_ALL))
|
||||||
|
rx_filter = HWTSTAMP_FILTER_ALL;
|
||||||
|
else
|
||||||
|
rx_filter = HWTSTAMP_FILTER_NONE;
|
||||||
|
break;
|
||||||
|
case CNF_HWTS_RXFILTER_NONE:
|
||||||
|
rx_filter = HWTSTAMP_FILTER_NONE;
|
||||||
|
break;
|
||||||
|
#ifdef HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP
|
||||||
|
case CNF_HWTS_RXFILTER_NTP:
|
||||||
|
rx_filter = HWTSTAMP_FILTER_NTP_ALL;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case CNF_HWTS_RXFILTER_PTP:
|
||||||
|
if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT))
|
||||||
|
rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
|
||||||
|
else if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_PTP_V2_EVENT))
|
||||||
|
rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
|
||||||
|
else
|
||||||
|
rx_filter = HWTSTAMP_FILTER_NONE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rx_filter = HWTSTAMP_FILTER_ALL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ts_config.flags = 0;
|
||||||
|
ts_config.tx_type = HWTSTAMP_TX_ON;
|
||||||
|
ts_config.rx_filter = rx_filter;
|
||||||
|
req.ifr_data = (char *)&ts_config;
|
||||||
|
|
||||||
|
if (ioctl(sock_fd, SIOCSHWTSTAMP, &req)) {
|
||||||
|
LOG(errno == EPERM ? LOGS_ERR : LOGS_DEBUG,
|
||||||
|
"ioctl(%s) failed : %s", "SIOCSHWTSTAMP", strerror(errno));
|
||||||
|
|
||||||
|
/* Check the current timestamping configuration in case this interface
|
||||||
|
allows only reading of the configuration and it was already configured
|
||||||
|
as requested */
|
||||||
|
req.ifr_data = (char *)&ts_config;
|
||||||
|
#ifdef SIOCGHWTSTAMP
|
||||||
|
if (ioctl(sock_fd, SIOCGHWTSTAMP, &req) ||
|
||||||
|
ts_config.tx_type != HWTSTAMP_TX_ON || ts_config.rx_filter != rx_filter)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
|
||||||
|
phc_fd = SYS_Linux_OpenPHC(NULL, ts_info.phc_index);
|
||||||
|
if (phc_fd < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
iface = ARR_GetNewElement(interfaces);
|
||||||
|
|
||||||
|
snprintf(iface->name, sizeof (iface->name), "%s", conf_iface->name);
|
||||||
|
iface->if_index = if_index;
|
||||||
|
iface->phc_fd = phc_fd;
|
||||||
|
iface->phc_mode = 0;
|
||||||
|
iface->phc_nocrossts = conf_iface->nocrossts;
|
||||||
|
|
||||||
|
/* Start with 1 gbit and no VLANs or IPv4/IPv6 options */
|
||||||
|
iface->link_speed = 1000;
|
||||||
|
iface->l2_udp4_ntp_start = 42;
|
||||||
|
iface->l2_udp6_ntp_start = 62;
|
||||||
|
|
||||||
|
iface->tx_comp = conf_iface->tx_comp;
|
||||||
|
iface->rx_comp = conf_iface->rx_comp;
|
||||||
|
|
||||||
|
iface->clock = HCL_CreateInstance(conf_iface->min_samples, conf_iface->max_samples,
|
||||||
|
UTI_Log2ToDouble(MAX(conf_iface->minpoll, MIN_PHC_POLL)),
|
||||||
|
conf_iface->precision);
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, "Enabled HW timestamping %son %s",
|
||||||
|
ts_config.rx_filter == HWTSTAMP_FILTER_NONE ? "(TX only) " : "", iface->name);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
add_all_interfaces(CNF_HwTsInterface *conf_iface_all)
|
||||||
|
{
|
||||||
|
CNF_HwTsInterface conf_iface;
|
||||||
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
conf_iface = *conf_iface_all;
|
||||||
|
|
||||||
|
if (getifaddrs(&ifaddr)) {
|
||||||
|
DEBUG_LOG("getifaddrs() failed : %s", strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (r = 0, ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
|
||||||
|
conf_iface.name = ifa->ifa_name;
|
||||||
|
if (add_interface(&conf_iface))
|
||||||
|
r = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeifaddrs(ifaddr);
|
||||||
|
|
||||||
|
/* Return success if at least one interface was added */
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_interface_speed(struct Interface *iface)
|
||||||
|
{
|
||||||
|
struct ethtool_cmd cmd;
|
||||||
|
struct ifreq req;
|
||||||
|
int sock_fd, link_speed;
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenUdpSocket(NULL, NULL, NULL, 0);
|
||||||
|
if (sock_fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof (req));
|
||||||
|
memset(&cmd, 0, sizeof (cmd));
|
||||||
|
|
||||||
|
snprintf(req.ifr_name, sizeof (req.ifr_name), "%s", iface->name);
|
||||||
|
cmd.cmd = ETHTOOL_GSET;
|
||||||
|
req.ifr_data = (char *)&cmd;
|
||||||
|
|
||||||
|
if (ioctl(sock_fd, SIOCETHTOOL, &req)) {
|
||||||
|
DEBUG_LOG("ioctl(%s) failed : %s", "SIOCETHTOOL", strerror(errno));
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
|
||||||
|
link_speed = ethtool_cmd_speed(&cmd);
|
||||||
|
|
||||||
|
if (iface->link_speed != link_speed) {
|
||||||
|
iface->link_speed = link_speed;
|
||||||
|
DEBUG_LOG("Updated speed of %s to %d Mb/s", iface->name, link_speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
#if defined(HAVE_LINUX_TIMESTAMPING_OPT_PKTINFO) || defined(HAVE_LINUX_TIMESTAMPING_OPT_TX_SWHW)
|
||||||
|
static int
|
||||||
|
check_timestamping_option(int option)
|
||||||
|
{
|
||||||
|
int sock_fd;
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenUdpSocket(NULL, NULL, NULL, 0);
|
||||||
|
if (sock_fd < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!SCK_SetIntOption(sock_fd, SOL_SOCKET, SO_TIMESTAMPING, option)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
open_dummy_socket(void)
|
||||||
|
{
|
||||||
|
int sock_fd, events = 0;
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenUdpSocket(NULL, NULL, NULL, 0);
|
||||||
|
if (sock_fd < 0)
|
||||||
|
return INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
if (!NIO_Linux_SetTimestampSocketOptions(sock_fd, 1, &events)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return INVALID_SOCK_FD;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sock_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NIO_Linux_Initialise(void)
|
||||||
|
{
|
||||||
|
CNF_HwTsInterface *conf_iface;
|
||||||
|
unsigned int i;
|
||||||
|
int hwts;
|
||||||
|
|
||||||
|
interfaces = ARR_CreateInstance(sizeof (struct Interface));
|
||||||
|
|
||||||
|
/* Enable HW timestamping on specified interfaces. If "*" was specified, try
|
||||||
|
all interfaces. If no interface was specified, enable SW timestamping. */
|
||||||
|
|
||||||
|
for (i = hwts = 0; CNF_GetHwTsInterface(i, &conf_iface); i++) {
|
||||||
|
if (!strcmp("*", conf_iface->name))
|
||||||
|
continue;
|
||||||
|
if (!add_interface(conf_iface))
|
||||||
|
LOG_FATAL("Could not enable HW timestamping on %s", conf_iface->name);
|
||||||
|
hwts = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; CNF_GetHwTsInterface(i, &conf_iface); i++) {
|
||||||
|
if (strcmp("*", conf_iface->name))
|
||||||
|
continue;
|
||||||
|
if (add_all_interfaces(conf_iface))
|
||||||
|
hwts = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ts_flags = SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE;
|
||||||
|
ts_tx_flags = SOF_TIMESTAMPING_TX_SOFTWARE;
|
||||||
|
|
||||||
|
if (hwts) {
|
||||||
|
ts_flags |= SOF_TIMESTAMPING_RAW_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE;
|
||||||
|
ts_tx_flags |= SOF_TIMESTAMPING_TX_HARDWARE;
|
||||||
|
#ifdef HAVE_LINUX_TIMESTAMPING_OPT_PKTINFO
|
||||||
|
if (check_timestamping_option(SOF_TIMESTAMPING_OPT_PKTINFO))
|
||||||
|
ts_flags |= SOF_TIMESTAMPING_OPT_PKTINFO;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_LINUX_TIMESTAMPING_OPT_TX_SWHW
|
||||||
|
if (check_timestamping_option(SOF_TIMESTAMPING_OPT_TX_SWHW))
|
||||||
|
ts_flags |= SOF_TIMESTAMPING_OPT_TX_SWHW;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enable IP_PKTINFO in messages looped back to the error queue */
|
||||||
|
ts_flags |= SOF_TIMESTAMPING_OPT_CMSG;
|
||||||
|
|
||||||
|
/* Kernels before 4.7 ignore timestamping flags set in control messages */
|
||||||
|
permanent_ts_options = !SYS_Linux_CheckKernelVersion(4, 7);
|
||||||
|
|
||||||
|
monitored_socket = INVALID_SOCK_FD;
|
||||||
|
suspended_socket = INVALID_SOCK_FD;
|
||||||
|
dummy_rxts_socket = INVALID_SOCK_FD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NIO_Linux_Finalise(void)
|
||||||
|
{
|
||||||
|
struct Interface *iface;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (dummy_rxts_socket != INVALID_SOCK_FD)
|
||||||
|
SCK_CloseSocket(dummy_rxts_socket);
|
||||||
|
|
||||||
|
for (i = 0; i < ARR_GetSize(interfaces); i++) {
|
||||||
|
iface = ARR_GetElement(interfaces, i);
|
||||||
|
HCL_DestroyInstance(iface->clock);
|
||||||
|
close(iface->phc_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARR_DestroyInstance(interfaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int *events)
|
||||||
|
{
|
||||||
|
int val, flags;
|
||||||
|
|
||||||
|
if (!ts_flags)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Enable SCM_TIMESTAMPING control messages and the socket's error queue in
|
||||||
|
order to receive our transmitted packets with more accurate timestamps */
|
||||||
|
|
||||||
|
val = 1;
|
||||||
|
flags = ts_flags;
|
||||||
|
|
||||||
|
if (client_only || permanent_ts_options)
|
||||||
|
flags |= ts_tx_flags;
|
||||||
|
|
||||||
|
if (!SCK_SetIntOption(sock_fd, SOL_SOCKET, SO_SELECT_ERR_QUEUE, val)) {
|
||||||
|
ts_flags = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SCK_SetIntOption(sock_fd, SOL_SOCKET, SO_TIMESTAMPING, flags)) {
|
||||||
|
ts_flags = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*events |= SCH_FILE_EXCEPTION;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
resume_socket(int sock_fd)
|
||||||
|
{
|
||||||
|
if (monitored_socket == sock_fd)
|
||||||
|
monitored_socket = INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
if (sock_fd == INVALID_SOCK_FD || sock_fd != suspended_socket)
|
||||||
|
return;
|
||||||
|
|
||||||
|
suspended_socket = INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_INPUT, 1);
|
||||||
|
|
||||||
|
DEBUG_LOG("Resumed RX processing %s timeout fd=%d",
|
||||||
|
resume_timeout_id ? "before" : "on", sock_fd);
|
||||||
|
|
||||||
|
if (resume_timeout_id) {
|
||||||
|
SCH_RemoveTimeout(resume_timeout_id);
|
||||||
|
resume_timeout_id = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
resume_timeout(void *arg)
|
||||||
|
{
|
||||||
|
resume_timeout_id = 0;
|
||||||
|
resume_socket(suspended_socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
suspend_socket(int sock_fd)
|
||||||
|
{
|
||||||
|
resume_socket(suspended_socket);
|
||||||
|
|
||||||
|
suspended_socket = sock_fd;
|
||||||
|
|
||||||
|
SCH_SetFileHandlerEvent(suspended_socket, SCH_FILE_INPUT, 0);
|
||||||
|
resume_timeout_id = SCH_AddTimeoutByDelay(RESUME_TIMEOUT, resume_timeout, NULL);
|
||||||
|
|
||||||
|
DEBUG_LOG("Suspended RX processing fd=%d", sock_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NIO_Linux_ProcessEvent(int sock_fd, int event)
|
||||||
|
{
|
||||||
|
if (sock_fd != monitored_socket)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (event == SCH_FILE_INPUT) {
|
||||||
|
suspend_socket(monitored_socket);
|
||||||
|
monitored_socket = INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
/* Don't process the message yet */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static struct Interface *
|
||||||
|
get_interface(int if_index)
|
||||||
|
{
|
||||||
|
struct Interface *iface;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ARR_GetSize(interfaces); i++) {
|
||||||
|
iface = ARR_GetElement(interfaces, i);
|
||||||
|
if (iface->if_index != if_index)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return iface;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_hw_timestamp(struct Interface *iface, struct timespec *hw_ts,
|
||||||
|
NTP_Local_Timestamp *local_ts, int rx_ntp_length, int family,
|
||||||
|
int l2_length)
|
||||||
|
{
|
||||||
|
struct timespec sample_phc_ts, sample_sys_ts, sample_local_ts, ts;
|
||||||
|
struct timespec phc_readings[PHC_READINGS][3];
|
||||||
|
double rx_correction, ts_delay, phc_err, local_err;
|
||||||
|
int n_readings;
|
||||||
|
|
||||||
|
if (HCL_NeedsNewSample(iface->clock, &local_ts->ts)) {
|
||||||
|
n_readings = SYS_Linux_GetPHCReadings(iface->phc_fd, iface->phc_nocrossts,
|
||||||
|
&iface->phc_mode, PHC_READINGS, phc_readings);
|
||||||
|
if (n_readings > 0 &&
|
||||||
|
HCL_ProcessReadings(iface->clock, n_readings, phc_readings,
|
||||||
|
&sample_phc_ts, &sample_sys_ts, &phc_err)) {
|
||||||
|
LCL_CookTime(&sample_sys_ts, &sample_local_ts, &local_err);
|
||||||
|
HCL_AccumulateSample(iface->clock, &sample_phc_ts, &sample_local_ts,
|
||||||
|
phc_err + local_err);
|
||||||
|
|
||||||
|
update_interface_speed(iface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We need to transpose RX timestamps as hardware timestamps are normally
|
||||||
|
preamble timestamps and RX timestamps in NTP are supposed to be trailer
|
||||||
|
timestamps. If we don't know the length of the packet at layer 2, we
|
||||||
|
make an assumption that UDP data start at the same position as in the
|
||||||
|
last transmitted packet which had a HW TX timestamp. */
|
||||||
|
if (rx_ntp_length && iface->link_speed) {
|
||||||
|
if (!l2_length)
|
||||||
|
l2_length = (family == IPADDR_INET4 ? iface->l2_udp4_ntp_start :
|
||||||
|
iface->l2_udp6_ntp_start) + rx_ntp_length;
|
||||||
|
|
||||||
|
/* Include the frame check sequence (FCS) */
|
||||||
|
l2_length += 4;
|
||||||
|
|
||||||
|
rx_correction = l2_length / (1.0e6 / 8 * iface->link_speed);
|
||||||
|
|
||||||
|
UTI_AddDoubleToTimespec(hw_ts, rx_correction, hw_ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!HCL_CookTime(iface->clock, hw_ts, &ts, &local_err))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!rx_ntp_length && iface->tx_comp)
|
||||||
|
UTI_AddDoubleToTimespec(&ts, iface->tx_comp, &ts);
|
||||||
|
else if (rx_ntp_length && iface->rx_comp)
|
||||||
|
UTI_AddDoubleToTimespec(&ts, -iface->rx_comp, &ts);
|
||||||
|
|
||||||
|
ts_delay = UTI_DiffTimespecsToDouble(&local_ts->ts, &ts);
|
||||||
|
|
||||||
|
if (fabs(ts_delay) > MAX_TS_DELAY) {
|
||||||
|
DEBUG_LOG("Unacceptable timestamp delay %.9f", ts_delay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
local_ts->ts = ts;
|
||||||
|
local_ts->err = local_err;
|
||||||
|
local_ts->source = NTP_TS_HARDWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_sw_timestamp(struct timespec *sw_ts, NTP_Local_Timestamp *local_ts)
|
||||||
|
{
|
||||||
|
double ts_delay, local_err;
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
LCL_CookTime(sw_ts, &ts, &local_err);
|
||||||
|
|
||||||
|
ts_delay = UTI_DiffTimespecsToDouble(&local_ts->ts, &ts);
|
||||||
|
|
||||||
|
if (fabs(ts_delay) > MAX_TS_DELAY) {
|
||||||
|
DEBUG_LOG("Unacceptable timestamp delay %.9f", ts_delay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
local_ts->ts = ts;
|
||||||
|
local_ts->err = local_err;
|
||||||
|
local_ts->source = NTP_TS_KERNEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
/* Extract UDP data from a layer 2 message. Supported is Ethernet
|
||||||
|
with optional VLAN tags. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
extract_udp_data(unsigned char *msg, NTP_Remote_Address *remote_addr, int len)
|
||||||
|
{
|
||||||
|
unsigned char *msg_start = msg;
|
||||||
|
|
||||||
|
remote_addr->ip_addr.family = IPADDR_UNSPEC;
|
||||||
|
remote_addr->port = 0;
|
||||||
|
|
||||||
|
/* Skip MACs */
|
||||||
|
if (len < 12)
|
||||||
|
return 0;
|
||||||
|
len -= 12, msg += 12;
|
||||||
|
|
||||||
|
/* Skip VLAN tag(s) if present */
|
||||||
|
while (len >= 4 && msg[0] == 0x81 && msg[1] == 0x00)
|
||||||
|
len -= 4, msg += 4;
|
||||||
|
|
||||||
|
/* Skip IPv4 or IPv6 ethertype */
|
||||||
|
if (len < 2 || !((msg[0] == 0x08 && msg[1] == 0x00) ||
|
||||||
|
(msg[0] == 0x86 && msg[1] == 0xdd)))
|
||||||
|
return 0;
|
||||||
|
len -= 2, msg += 2;
|
||||||
|
|
||||||
|
/* Parse destination address and port from IPv4/IPv6 and UDP headers */
|
||||||
|
if (len >= 20 && msg[0] >> 4 == 4) {
|
||||||
|
int ihl = (msg[0] & 0xf) * 4;
|
||||||
|
uint32_t addr;
|
||||||
|
|
||||||
|
if (len < ihl + 8 || msg[9] != 17)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(&addr, msg + 16, sizeof (addr));
|
||||||
|
remote_addr->ip_addr.addr.in4 = ntohl(addr);
|
||||||
|
remote_addr->port = ntohs(*(uint16_t *)(msg + ihl + 2));
|
||||||
|
remote_addr->ip_addr.family = IPADDR_INET4;
|
||||||
|
len -= ihl + 8, msg += ihl + 8;
|
||||||
|
#ifdef FEAT_IPV6
|
||||||
|
} else if (len >= 48 && msg[0] >> 4 == 6) {
|
||||||
|
int eh_len, next_header = msg[6];
|
||||||
|
|
||||||
|
memcpy(&remote_addr->ip_addr.addr.in6, msg + 24, sizeof (remote_addr->ip_addr.addr.in6));
|
||||||
|
len -= 40, msg += 40;
|
||||||
|
|
||||||
|
/* Skip IPv6 extension headers if present */
|
||||||
|
while (next_header != 17) {
|
||||||
|
switch (next_header) {
|
||||||
|
case 44: /* Fragment Header */
|
||||||
|
/* Process only the first fragment */
|
||||||
|
if (ntohs(*(uint16_t *)(msg + 2)) >> 3 != 0)
|
||||||
|
return 0;
|
||||||
|
eh_len = 8;
|
||||||
|
break;
|
||||||
|
case 0: /* Hop-by-Hop Options */
|
||||||
|
case 43: /* Routing Header */
|
||||||
|
case 60: /* Destination Options */
|
||||||
|
case 135: /* Mobility Header */
|
||||||
|
eh_len = 8 * (msg[1] + 1);
|
||||||
|
break;
|
||||||
|
case 51: /* Authentication Header */
|
||||||
|
eh_len = 4 * (msg[1] + 2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eh_len < 8 || len < eh_len + 8)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
next_header = msg[0];
|
||||||
|
len -= eh_len, msg += eh_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
remote_addr->port = ntohs(*(uint16_t *)(msg + 2));
|
||||||
|
remote_addr->ip_addr.family = IPADDR_INET6;
|
||||||
|
len -= 8, msg += 8;
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move the message to fix alignment of its fields */
|
||||||
|
if (len > 0)
|
||||||
|
memmove(msg_start, msg, len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NIO_Linux_ProcessMessage(SCK_Message *message, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *local_ts, int event)
|
||||||
|
{
|
||||||
|
struct Interface *iface;
|
||||||
|
int is_tx, ts_if_index, l2_length;
|
||||||
|
|
||||||
|
is_tx = event == SCH_FILE_EXCEPTION;
|
||||||
|
iface = NULL;
|
||||||
|
|
||||||
|
ts_if_index = message->timestamp.if_index;
|
||||||
|
if (ts_if_index == INVALID_IF_INDEX)
|
||||||
|
ts_if_index = message->if_index;
|
||||||
|
l2_length = message->timestamp.l2_length;
|
||||||
|
|
||||||
|
if (!UTI_IsZeroTimespec(&message->timestamp.hw)) {
|
||||||
|
iface = get_interface(ts_if_index);
|
||||||
|
if (iface) {
|
||||||
|
process_hw_timestamp(iface, &message->timestamp.hw, local_ts, !is_tx ? message->length : 0,
|
||||||
|
message->remote_addr.ip.ip_addr.family, l2_length);
|
||||||
|
} else {
|
||||||
|
DEBUG_LOG("HW clock not found for interface %d", ts_if_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If a HW transmit timestamp was received, resume processing
|
||||||
|
of non-error messages on this socket */
|
||||||
|
if (is_tx)
|
||||||
|
resume_socket(local_addr->sock_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_ts->source == NTP_TS_DAEMON && !UTI_IsZeroTimespec(&message->timestamp.kernel) &&
|
||||||
|
(!is_tx || UTI_IsZeroTimespec(&message->timestamp.hw))) {
|
||||||
|
process_sw_timestamp(&message->timestamp.kernel, local_ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the kernel is slow with enabling RX timestamping, open a dummy
|
||||||
|
socket to keep the kernel RX timestamping permanently enabled */
|
||||||
|
if (!is_tx && local_ts->source == NTP_TS_DAEMON && ts_flags) {
|
||||||
|
DEBUG_LOG("Missing kernel RX timestamp");
|
||||||
|
if (dummy_rxts_socket == INVALID_SOCK_FD)
|
||||||
|
dummy_rxts_socket = open_dummy_socket();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the message if it's not received from the error queue */
|
||||||
|
if (!is_tx)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* The data from the error queue includes all layers up to UDP. We have to
|
||||||
|
extract the UDP data and also the destination address with port as there
|
||||||
|
currently doesn't seem to be a better way to get them both. */
|
||||||
|
l2_length = message->length;
|
||||||
|
message->length = extract_udp_data(message->data, &message->remote_addr.ip, message->length);
|
||||||
|
|
||||||
|
DEBUG_LOG("Extracted message for %s fd=%d len=%d",
|
||||||
|
UTI_IPSockAddrToString(&message->remote_addr.ip),
|
||||||
|
local_addr->sock_fd, message->length);
|
||||||
|
|
||||||
|
/* Update assumed position of UDP data at layer 2 for next received packet */
|
||||||
|
if (iface && message->length) {
|
||||||
|
if (message->remote_addr.ip.ip_addr.family == IPADDR_INET4)
|
||||||
|
iface->l2_udp4_ntp_start = l2_length - message->length;
|
||||||
|
else if (message->remote_addr.ip.ip_addr.family == IPADDR_INET6)
|
||||||
|
iface->l2_udp6_ntp_start = l2_length - message->length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Drop the message if it has no timestamp or its processing failed */
|
||||||
|
if (local_ts->source == NTP_TS_DAEMON) {
|
||||||
|
DEBUG_LOG("Missing TX timestamp");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NIO_UnwrapMessage(message, local_addr->sock_fd))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (message->length < NTP_HEADER_LENGTH || message->length > sizeof (NTP_Packet))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
NSR_ProcessTx(&message->remote_addr.ip, local_addr, local_ts, message->data, message->length);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NIO_Linux_RequestTxTimestamp(SCK_Message *message, int sock_fd)
|
||||||
|
{
|
||||||
|
if (!ts_flags)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* If a HW transmit timestamp is requested on a client socket, monitor
|
||||||
|
events on the socket in order to avoid processing of a fast response
|
||||||
|
without the HW timestamp of the request */
|
||||||
|
if (ts_tx_flags & SOF_TIMESTAMPING_TX_HARDWARE && !NIO_IsServerSocket(sock_fd))
|
||||||
|
monitored_socket = sock_fd;
|
||||||
|
|
||||||
|
/* Check if TX timestamping is disabled on this socket */
|
||||||
|
if (permanent_ts_options || !NIO_IsServerSocket(sock_fd))
|
||||||
|
return;
|
||||||
|
|
||||||
|
message->timestamp.tx_flags = ts_tx_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NIO_Linux_NotifySocketClosing(int sock_fd)
|
||||||
|
{
|
||||||
|
resume_socket(sock_fd);
|
||||||
|
}
|
||||||
47
ntp_io_linux.h
Normal file
47
ntp_io_linux.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
This is the header file for the Linux-specific NTP socket I/O bits.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTP_IO_LINUX_H
|
||||||
|
#define GOT_NTP_IO_LINUX_H
|
||||||
|
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
|
extern void NIO_Linux_Initialise(void);
|
||||||
|
|
||||||
|
extern void NIO_Linux_Finalise(void);
|
||||||
|
|
||||||
|
extern int NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int *events);
|
||||||
|
|
||||||
|
extern int NIO_Linux_ProcessEvent(int sock_fd, int event);
|
||||||
|
|
||||||
|
extern int NIO_Linux_ProcessMessage(SCK_Message *message, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *local_ts, int event);
|
||||||
|
|
||||||
|
extern void NIO_Linux_RequestTxTimestamp(SCK_Message *message, int sock_fd);
|
||||||
|
|
||||||
|
extern void NIO_Linux_NotifySocketClosing(int sock_fd);
|
||||||
|
|
||||||
|
#endif
|
||||||
341
ntp_signd.c
Normal file
341
ntp_signd.c
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Support for MS-SNTP authentication in Samba (ntp_signd)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "array.h"
|
||||||
|
#include "conf.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "ntp_io.h"
|
||||||
|
#include "ntp_signd.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "socket.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
/* Declarations per samba/source4/librpc/idl/ntp_signd.idl */
|
||||||
|
|
||||||
|
#define SIGND_VERSION 0
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SIGN_TO_CLIENT = 0,
|
||||||
|
ASK_SERVER_TO_SIGN = 1,
|
||||||
|
CHECK_SERVER_SIGNATURE = 2,
|
||||||
|
SIGNING_SUCCESS = 3,
|
||||||
|
SIGNING_FAILURE = 4,
|
||||||
|
} SigndOp;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t length;
|
||||||
|
uint32_t version;
|
||||||
|
uint32_t op;
|
||||||
|
uint16_t packet_id;
|
||||||
|
uint16_t _pad;
|
||||||
|
uint32_t key_id;
|
||||||
|
NTP_Packet packet_to_sign;
|
||||||
|
} SigndRequest;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t length;
|
||||||
|
uint32_t version;
|
||||||
|
uint32_t op;
|
||||||
|
uint32_t packet_id;
|
||||||
|
NTP_Packet signed_packet;
|
||||||
|
} SigndResponse;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
NTP_Remote_Address remote_addr;
|
||||||
|
NTP_Local_Address local_addr;
|
||||||
|
|
||||||
|
int sent;
|
||||||
|
int received;
|
||||||
|
int request_length;
|
||||||
|
struct timespec request_ts;
|
||||||
|
SigndRequest request;
|
||||||
|
SigndResponse response;
|
||||||
|
} SignInstance;
|
||||||
|
|
||||||
|
/* As the communication with ntp_signd is asynchronous, incoming packets are
|
||||||
|
saved in a queue in order to avoid loss when they come in bursts */
|
||||||
|
|
||||||
|
#define MAX_QUEUE_LENGTH 16U
|
||||||
|
#define NEXT_QUEUE_INDEX(index) (((index) + 1) % MAX_QUEUE_LENGTH)
|
||||||
|
#define IS_QUEUE_EMPTY() (queue_head == queue_tail)
|
||||||
|
|
||||||
|
/* Fixed-size array of SignInstance */
|
||||||
|
static ARR_Instance queue;
|
||||||
|
static unsigned int queue_head;
|
||||||
|
static unsigned int queue_tail;
|
||||||
|
|
||||||
|
#define INVALID_SOCK_FD (-6)
|
||||||
|
|
||||||
|
/* Unix domain socket connected to ntp_signd */
|
||||||
|
static int sock_fd;
|
||||||
|
|
||||||
|
/* Flag indicating if the MS-SNTP authentication is enabled */
|
||||||
|
static int enabled;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void read_write_socket(int sock_fd, int event, void *anything);
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
close_socket(void)
|
||||||
|
{
|
||||||
|
SCH_RemoveFileHandler(sock_fd);
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
sock_fd = INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
/* Empty the queue */
|
||||||
|
queue_head = queue_tail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
open_socket(void)
|
||||||
|
{
|
||||||
|
char path[PATH_MAX];
|
||||||
|
|
||||||
|
if (sock_fd != INVALID_SOCK_FD)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (snprintf(path, sizeof (path), "%s/socket", CNF_GetNtpSigndSocket()) >= sizeof (path)) {
|
||||||
|
DEBUG_LOG("signd socket path too long");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenUnixStreamSocket(path, NULL, 0);
|
||||||
|
if (sock_fd < 0) {
|
||||||
|
sock_fd = INVALID_SOCK_FD;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCH_AddFileHandler(sock_fd, SCH_FILE_INPUT, read_write_socket, NULL);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_response(SignInstance *inst)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
double delay;
|
||||||
|
|
||||||
|
if (ntohs(inst->request.packet_id) != ntohl(inst->response.packet_id)) {
|
||||||
|
DEBUG_LOG("Invalid response ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ntohl(inst->response.op) != SIGNING_SUCCESS) {
|
||||||
|
DEBUG_LOG("Signing failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if the file descriptor is still valid */
|
||||||
|
if (!NIO_IsServerSocket(inst->local_addr.sock_fd)) {
|
||||||
|
DEBUG_LOG("Invalid NTP socket");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCH_GetLastEventTime(NULL, NULL, &ts);
|
||||||
|
delay = UTI_DiffTimespecsToDouble(&ts, &inst->request_ts);
|
||||||
|
|
||||||
|
DEBUG_LOG("Signing succeeded (delay %f)", delay);
|
||||||
|
|
||||||
|
/* Send the signed NTP packet */
|
||||||
|
NIO_SendPacket(&inst->response.signed_packet, &inst->remote_addr, &inst->local_addr,
|
||||||
|
ntohl(inst->response.length) + sizeof (inst->response.length) -
|
||||||
|
offsetof(SigndResponse, signed_packet), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
read_write_socket(int sock_fd, int event, void *anything)
|
||||||
|
{
|
||||||
|
SignInstance *inst;
|
||||||
|
uint32_t response_length;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
inst = ARR_GetElement(queue, queue_head);
|
||||||
|
|
||||||
|
if (event == SCH_FILE_OUTPUT) {
|
||||||
|
assert(!IS_QUEUE_EMPTY());
|
||||||
|
assert(inst->sent < inst->request_length);
|
||||||
|
|
||||||
|
if (!inst->sent)
|
||||||
|
SCH_GetLastEventTime(NULL, NULL, &inst->request_ts);
|
||||||
|
|
||||||
|
s = SCK_Send(sock_fd, (char *)&inst->request + inst->sent,
|
||||||
|
inst->request_length - inst->sent, 0);
|
||||||
|
|
||||||
|
if (s < 0) {
|
||||||
|
close_socket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->sent += s;
|
||||||
|
|
||||||
|
/* Try again later if the request is not complete yet */
|
||||||
|
if (inst->sent < inst->request_length)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Disable output and wait for a response */
|
||||||
|
SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event == SCH_FILE_INPUT) {
|
||||||
|
if (IS_QUEUE_EMPTY()) {
|
||||||
|
DEBUG_LOG("Unexpected signd response");
|
||||||
|
close_socket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(inst->received < sizeof (inst->response));
|
||||||
|
s = SCK_Receive(sock_fd, (char *)&inst->response + inst->received,
|
||||||
|
sizeof (inst->response) - inst->received, 0);
|
||||||
|
|
||||||
|
if (s <= 0) {
|
||||||
|
close_socket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->received += s;
|
||||||
|
|
||||||
|
if (inst->received < sizeof (inst->response.length))
|
||||||
|
return;
|
||||||
|
|
||||||
|
response_length = ntohl(inst->response.length) + sizeof (inst->response.length);
|
||||||
|
|
||||||
|
if (response_length < offsetof(SigndResponse, signed_packet) ||
|
||||||
|
response_length > sizeof (SigndResponse)) {
|
||||||
|
DEBUG_LOG("Invalid response length");
|
||||||
|
close_socket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for more data if not complete yet */
|
||||||
|
if (inst->received < response_length)
|
||||||
|
return;
|
||||||
|
|
||||||
|
process_response(inst);
|
||||||
|
|
||||||
|
/* Move the head and enable output for the next packet */
|
||||||
|
queue_head = NEXT_QUEUE_INDEX(queue_head);
|
||||||
|
if (!IS_QUEUE_EMPTY())
|
||||||
|
SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NSD_Initialise()
|
||||||
|
{
|
||||||
|
sock_fd = INVALID_SOCK_FD;
|
||||||
|
enabled = CNF_GetNtpSigndSocket() && CNF_GetNtpSigndSocket()[0];
|
||||||
|
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
queue = ARR_CreateInstance(sizeof (SignInstance));
|
||||||
|
ARR_SetSize(queue, MAX_QUEUE_LENGTH);
|
||||||
|
queue_head = queue_tail = 0;
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, "MS-SNTP authentication enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NSD_Finalise()
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
if (sock_fd != INVALID_SOCK_FD)
|
||||||
|
close_socket();
|
||||||
|
ARR_DestroyInstance(queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NSD_SignAndSendPacket(uint32_t key_id, NTP_Packet *packet, NTP_PacketInfo *info,
|
||||||
|
NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr)
|
||||||
|
{
|
||||||
|
SignInstance *inst;
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
|
DEBUG_LOG("signd disabled");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue_head == NEXT_QUEUE_INDEX(queue_tail)) {
|
||||||
|
DEBUG_LOG("signd queue full");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info->length != NTP_HEADER_LENGTH) {
|
||||||
|
DEBUG_LOG("Invalid packet length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!open_socket())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inst = ARR_GetElement(queue, queue_tail);
|
||||||
|
inst->remote_addr = *remote_addr;
|
||||||
|
inst->local_addr = *local_addr;
|
||||||
|
inst->sent = 0;
|
||||||
|
inst->received = 0;
|
||||||
|
inst->request_length = offsetof(SigndRequest, packet_to_sign) + info->length;
|
||||||
|
|
||||||
|
/* The length field doesn't include itself */
|
||||||
|
inst->request.length = htonl(inst->request_length - sizeof (inst->request.length));
|
||||||
|
inst->request.version = htonl(SIGND_VERSION);
|
||||||
|
inst->request.op = htonl(SIGN_TO_CLIENT);
|
||||||
|
inst->request.packet_id = htons(queue_tail);
|
||||||
|
inst->request._pad = 0;
|
||||||
|
inst->request.key_id = htonl(key_id);
|
||||||
|
|
||||||
|
memcpy(&inst->request.packet_to_sign, packet, info->length);
|
||||||
|
|
||||||
|
/* Enable output if there was no pending request */
|
||||||
|
if (IS_QUEUE_EMPTY())
|
||||||
|
SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 1);
|
||||||
|
|
||||||
|
queue_tail = NEXT_QUEUE_INDEX(queue_tail);
|
||||||
|
|
||||||
|
DEBUG_LOG("Packet added to signd queue (%u:%u)", queue_head, queue_tail);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
42
ntp_signd.h
Normal file
42
ntp_signd.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header for MS-SNTP authentication via Samba (ntp_signd) */
|
||||||
|
|
||||||
|
#ifndef GOT_NTP_SIGND_H
|
||||||
|
#define GOT_NTP_SIGND_H
|
||||||
|
|
||||||
|
#include "addressing.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
|
||||||
|
/* Initialisation function */
|
||||||
|
extern void NSD_Initialise(void);
|
||||||
|
|
||||||
|
/* Finalisation function */
|
||||||
|
extern void NSD_Finalise(void);
|
||||||
|
|
||||||
|
/* Function to sign an NTP packet and send it */
|
||||||
|
extern int NSD_SignAndSendPacket(uint32_t key_id, NTP_Packet *packet, NTP_PacketInfo *info,
|
||||||
|
NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr);
|
||||||
|
|
||||||
|
#endif
|
||||||
1010
ntp_sources.c
1010
ntp_sources.c
File diff suppressed because it is too large
Load Diff
@@ -44,16 +44,21 @@ typedef enum {
|
|||||||
NSR_NoSuchSource, /* Remove - attempt to remove a source that is not known */
|
NSR_NoSuchSource, /* Remove - attempt to remove a source that is not known */
|
||||||
NSR_AlreadyInUse, /* AddSource - attempt to add a source that is already known */
|
NSR_AlreadyInUse, /* AddSource - attempt to add a source that is already known */
|
||||||
NSR_TooManySources, /* AddSource - too many sources already present */
|
NSR_TooManySources, /* AddSource - too many sources already present */
|
||||||
NSR_InvalidAF /* AddSource - attempt to add a source with invalid address family */
|
NSR_InvalidAF, /* AddSource - attempt to add a source with invalid address family */
|
||||||
|
NSR_InvalidName, /* AddSourceByName - attempt to add a source with invalid name */
|
||||||
|
NSR_UnresolvedName, /* AddSourceByName - name will be resolved later */
|
||||||
} NSR_Status;
|
} NSR_Status;
|
||||||
|
|
||||||
/* Procedure to add a new server or peer source. */
|
/* Procedure to add a new server or peer source. */
|
||||||
extern NSR_Status NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params);
|
extern NSR_Status NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
|
||||||
|
SourceParameters *params, uint32_t *conf_id);
|
||||||
|
|
||||||
/* Procedure to add a new server, peer source, or pool of servers specified by
|
/* Procedure to add a new server, peer source, or pool of servers specified by
|
||||||
name instead of address. The name is resolved in exponentially increasing
|
name instead of address. The name is resolved in exponentially increasing
|
||||||
intervals until it succeeds or fails with a non-temporary error. */
|
intervals until it succeeds or fails with a non-temporary error. If the
|
||||||
extern void NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, SourceParameters *params);
|
name is an address, it is equivalent to NSR_AddSource(). */
|
||||||
|
extern NSR_Status NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
|
||||||
|
SourceParameters *params, uint32_t *conf_id);
|
||||||
|
|
||||||
/* Function type for handlers to be called back when an attempt
|
/* Function type for handlers to be called back when an attempt
|
||||||
* (possibly unsuccessful) to resolve unresolved sources ends */
|
* (possibly unsuccessful) to resolve unresolved sources ends */
|
||||||
@@ -72,7 +77,10 @@ extern void NSR_StartSources(void);
|
|||||||
extern void NSR_AutoStartSources(void);
|
extern void NSR_AutoStartSources(void);
|
||||||
|
|
||||||
/* Procedure to remove a source */
|
/* Procedure to remove a source */
|
||||||
extern NSR_Status NSR_RemoveSource(NTP_Remote_Address *remote_addr);
|
extern NSR_Status NSR_RemoveSource(IPAddr *address);
|
||||||
|
|
||||||
|
/* Procedure to remove all sources matching a configuration ID */
|
||||||
|
extern void NSR_RemoveSourcesById(uint32_t conf_id);
|
||||||
|
|
||||||
/* Procedure to remove all sources */
|
/* Procedure to remove all sources */
|
||||||
extern void NSR_RemoveAllSources(void);
|
extern void NSR_RemoveAllSources(void);
|
||||||
@@ -83,11 +91,26 @@ extern void NSR_HandleBadSource(IPAddr *address);
|
|||||||
/* Procedure to resolve all names again */
|
/* Procedure to resolve all names again */
|
||||||
extern void NSR_RefreshAddresses(void);
|
extern void NSR_RefreshAddresses(void);
|
||||||
|
|
||||||
|
/* Procedure to update the address of a source. The update may be
|
||||||
|
postponed. */
|
||||||
|
extern NSR_Status NSR_UpdateSourceNtpAddress(NTP_Remote_Address *old_addr,
|
||||||
|
NTP_Remote_Address *new_addr);
|
||||||
|
|
||||||
/* Procedure to get local reference ID corresponding to a source */
|
/* Procedure to get local reference ID corresponding to a source */
|
||||||
extern uint32_t NSR_GetLocalRefid(IPAddr *address);
|
extern uint32_t NSR_GetLocalRefid(IPAddr *address);
|
||||||
|
|
||||||
|
/* Procedure to get the name of a source as it was specified (it may be
|
||||||
|
an IP address) */
|
||||||
|
extern char *NSR_GetName(IPAddr *address);
|
||||||
|
|
||||||
/* This routine is called by ntp_io when a new packet arrives off the network */
|
/* This routine is called by ntp_io when a new packet arrives off the network */
|
||||||
extern void NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);
|
extern void NSR_ProcessRx(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length);
|
||||||
|
|
||||||
|
/* This routine is called by ntp_io when a packet was sent to the network and
|
||||||
|
an accurate transmit timestamp was captured */
|
||||||
|
extern void NSR_ProcessTx(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
|
||||||
|
NTP_Local_Timestamp *tx_ts, NTP_Packet *message, int length);
|
||||||
|
|
||||||
/* Initialisation function */
|
/* Initialisation function */
|
||||||
extern void NSR_Initialise(void);
|
extern void NSR_Initialise(void);
|
||||||
@@ -96,14 +119,9 @@ extern void NSR_Initialise(void);
|
|||||||
extern void NSR_Finalise(void);
|
extern void NSR_Finalise(void);
|
||||||
|
|
||||||
/* This routine is used to indicate that sources whose IP addresses
|
/* This routine is used to indicate that sources whose IP addresses
|
||||||
match a particular subnet should be set online again. Returns a
|
match a particular subnet should be set online or offline. It returns
|
||||||
flag indicating whether any hosts matched the address */
|
a flag indicating whether any hosts matched the address. */
|
||||||
extern int NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address);
|
extern int NSR_SetConnectivity(IPAddr *mask, IPAddr *address, SRC_Connectivity connectivity);
|
||||||
|
|
||||||
/* This routine is used to indicate that sources whose IP addresses
|
|
||||||
match a particular subnet should be set offline. Returns a flag
|
|
||||||
indicating whether any hosts matched the address */
|
|
||||||
extern int NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address);
|
|
||||||
|
|
||||||
extern int NSR_ModifyMinpoll(IPAddr *address, int new_minpoll);
|
extern int NSR_ModifyMinpoll(IPAddr *address, int new_minpoll);
|
||||||
|
|
||||||
@@ -121,8 +139,14 @@ extern int NSR_ModifyPolltarget(IPAddr *address, int new_poll_target);
|
|||||||
|
|
||||||
extern int NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples, IPAddr *mask, IPAddr *address);
|
extern int NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples, IPAddr *mask, IPAddr *address);
|
||||||
|
|
||||||
extern void NSR_ReportSource(RPT_SourceReport *report, struct timeval *now);
|
extern void NSR_ReportSource(RPT_SourceReport *report, struct timespec *now);
|
||||||
|
|
||||||
|
extern int NSR_GetAuthReport(IPAddr *address, RPT_AuthReport *report);
|
||||||
|
|
||||||
|
extern int NSR_GetNTPReport(RPT_NTPReport *report);
|
||||||
|
|
||||||
extern void NSR_GetActivityReport(RPT_ActivityReport *report);
|
extern void NSR_GetActivityReport(RPT_ActivityReport *report);
|
||||||
|
|
||||||
|
extern void NSR_DumpAuthData(void);
|
||||||
|
|
||||||
#endif /* GOT_NTP_SOURCES_H */
|
#endif /* GOT_NTP_SOURCES_H */
|
||||||
|
|||||||
81
nts_ke.h
Normal file
81
nts_ke.h
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for the NTS Key Establishment protocol
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_KE_H
|
||||||
|
#define GOT_NTS_KE_H
|
||||||
|
|
||||||
|
#include "siv.h"
|
||||||
|
|
||||||
|
#define NKE_PORT 4460
|
||||||
|
|
||||||
|
#define NKE_RECORD_CRITICAL_BIT (1U << 15)
|
||||||
|
#define NKE_RECORD_END_OF_MESSAGE 0
|
||||||
|
#define NKE_RECORD_NEXT_PROTOCOL 1
|
||||||
|
#define NKE_RECORD_ERROR 2
|
||||||
|
#define NKE_RECORD_WARNING 3
|
||||||
|
#define NKE_RECORD_AEAD_ALGORITHM 4
|
||||||
|
#define NKE_RECORD_COOKIE 5
|
||||||
|
#define NKE_RECORD_NTPV4_SERVER_NEGOTIATION 6
|
||||||
|
#define NKE_RECORD_NTPV4_PORT_NEGOTIATION 7
|
||||||
|
|
||||||
|
#define NKE_NEXT_PROTOCOL_NTPV4 0
|
||||||
|
|
||||||
|
#define NKE_ERROR_UNRECOGNIZED_CRITICAL_RECORD 0
|
||||||
|
#define NKE_ERROR_BAD_REQUEST 1
|
||||||
|
#define NKE_ERROR_INTERNAL_SERVER_ERROR 2
|
||||||
|
|
||||||
|
#define NKE_ALPN_NAME "ntske/1"
|
||||||
|
#define NKE_EXPORTER_LABEL "EXPORTER-network-time-security"
|
||||||
|
#define NKE_EXPORTER_CONTEXT_C2S "\x0\x0\x0\xf\x0"
|
||||||
|
#define NKE_EXPORTER_CONTEXT_S2C "\x0\x0\x0\xf\x1"
|
||||||
|
|
||||||
|
#define NKE_MAX_MESSAGE_LENGTH 16384
|
||||||
|
#define NKE_MAX_RECORD_BODY_LENGTH 256
|
||||||
|
#define NKE_MAX_COOKIE_LENGTH 256
|
||||||
|
#define NKE_MAX_COOKIES 8
|
||||||
|
#define NKE_MAX_KEY_LENGTH SIV_MAX_KEY_LENGTH
|
||||||
|
|
||||||
|
#define NKE_RETRY_FACTOR2_CONNECT 4
|
||||||
|
#define NKE_RETRY_FACTOR2_TLS 10
|
||||||
|
#define NKE_MAX_RETRY_INTERVAL2 19
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int length;
|
||||||
|
unsigned char key[NKE_MAX_KEY_LENGTH];
|
||||||
|
} NKE_Key;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SIV_Algorithm algorithm;
|
||||||
|
NKE_Key c2s;
|
||||||
|
NKE_Key s2c;
|
||||||
|
} NKE_Context;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int length;
|
||||||
|
unsigned char cookie[NKE_MAX_COOKIE_LENGTH];
|
||||||
|
} NKE_Cookie;
|
||||||
|
|
||||||
|
#endif
|
||||||
442
nts_ke_client.c
Normal file
442
nts_ke_client.c
Normal file
@@ -0,0 +1,442 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020-2021
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
NTS-KE client
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "nts_ke_client.h"
|
||||||
|
|
||||||
|
#include "conf.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "nameserv_async.h"
|
||||||
|
#include "nts_ke_session.h"
|
||||||
|
#include "siv.h"
|
||||||
|
#include "socket.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#define CLIENT_TIMEOUT 16.0
|
||||||
|
|
||||||
|
struct NKC_Instance_Record {
|
||||||
|
char *name;
|
||||||
|
IPSockAddr address;
|
||||||
|
NKSN_Credentials credentials;
|
||||||
|
NKSN_Instance session;
|
||||||
|
int destroying;
|
||||||
|
int got_response;
|
||||||
|
int resolving_name;
|
||||||
|
|
||||||
|
NKE_Context context;
|
||||||
|
NKE_Cookie cookies[NKE_MAX_COOKIES];
|
||||||
|
int num_cookies;
|
||||||
|
char server_name[NKE_MAX_RECORD_BODY_LENGTH + 2];
|
||||||
|
IPSockAddr ntp_address;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static NKSN_Credentials default_credentials = NULL;
|
||||||
|
static int default_credentials_refs = 0;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
name_resolve_handler(DNS_Status status, int n_addrs, IPAddr *ip_addrs, void *arg)
|
||||||
|
{
|
||||||
|
NKC_Instance inst = arg;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
inst->resolving_name = 0;
|
||||||
|
|
||||||
|
if (inst->destroying) {
|
||||||
|
Free(inst);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != DNS_Success || n_addrs < 1) {
|
||||||
|
LOG(LOGS_ERR, "Could not resolve NTP server %s from %s", inst->server_name, inst->name);
|
||||||
|
/* Force restart */
|
||||||
|
inst->got_response = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->ntp_address.ip_addr = ip_addrs[0];
|
||||||
|
|
||||||
|
/* Prefer an address in the same family as the NTS-KE server */
|
||||||
|
for (i = 0; i < n_addrs; i++) {
|
||||||
|
DEBUG_LOG("%s resolved to %s", inst->server_name, UTI_IPToString(&ip_addrs[i]));
|
||||||
|
if (ip_addrs[i].family == inst->address.ip_addr.family) {
|
||||||
|
inst->ntp_address.ip_addr = ip_addrs[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
prepare_request(NKC_Instance inst)
|
||||||
|
{
|
||||||
|
NKSN_Instance session = inst->session;
|
||||||
|
uint16_t datum;
|
||||||
|
|
||||||
|
NKSN_BeginMessage(session);
|
||||||
|
|
||||||
|
datum = htons(NKE_NEXT_PROTOCOL_NTPV4);
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_NEXT_PROTOCOL, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
datum = htons(AEAD_AES_SIV_CMAC_256);
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_AEAD_ALGORITHM, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!NKSN_EndMessage(session))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
process_response(NKC_Instance inst)
|
||||||
|
{
|
||||||
|
int next_protocol = -1, aead_algorithm = -1, error = 0;
|
||||||
|
int i, critical, type, length;
|
||||||
|
uint16_t data[NKE_MAX_RECORD_BODY_LENGTH / sizeof (uint16_t)];
|
||||||
|
|
||||||
|
assert(NKE_MAX_COOKIE_LENGTH <= NKE_MAX_RECORD_BODY_LENGTH);
|
||||||
|
assert(sizeof (data) % sizeof (uint16_t) == 0);
|
||||||
|
assert(sizeof (uint16_t) == 2);
|
||||||
|
|
||||||
|
inst->num_cookies = 0;
|
||||||
|
inst->ntp_address.ip_addr.family = IPADDR_UNSPEC;
|
||||||
|
inst->ntp_address.port = 0;
|
||||||
|
inst->server_name[0] = '\0';
|
||||||
|
|
||||||
|
while (!error) {
|
||||||
|
if (!NKSN_GetRecord(inst->session, &critical, &type, &length, &data, sizeof (data)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (length > sizeof (data)) {
|
||||||
|
DEBUG_LOG("Record too long type=%d length=%d critical=%d", type, length, critical);
|
||||||
|
if (critical)
|
||||||
|
error = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case NKE_RECORD_NEXT_PROTOCOL:
|
||||||
|
if (!critical || length != 2 || ntohs(data[0]) != NKE_NEXT_PROTOCOL_NTPV4) {
|
||||||
|
DEBUG_LOG("Unexpected NTS-KE next protocol");
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next_protocol = NKE_NEXT_PROTOCOL_NTPV4;
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_AEAD_ALGORITHM:
|
||||||
|
if (length != 2 || ntohs(data[0]) != AEAD_AES_SIV_CMAC_256) {
|
||||||
|
DEBUG_LOG("Unexpected NTS-KE AEAD algorithm");
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
aead_algorithm = AEAD_AES_SIV_CMAC_256;
|
||||||
|
inst->context.algorithm = aead_algorithm;
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_ERROR:
|
||||||
|
if (length == 2)
|
||||||
|
DEBUG_LOG("NTS-KE error %d", ntohs(data[0]));
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_WARNING:
|
||||||
|
if (length == 2)
|
||||||
|
DEBUG_LOG("NTS-KE warning %d", ntohs(data[0]));
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_COOKIE:
|
||||||
|
DEBUG_LOG("Got cookie length=%d", length);
|
||||||
|
|
||||||
|
if (length < 1 || length > NKE_MAX_COOKIE_LENGTH || length % 4 != 0 ||
|
||||||
|
inst->num_cookies >= NKE_MAX_COOKIES) {
|
||||||
|
DEBUG_LOG("Unexpected length/cookie");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(NKE_MAX_COOKIE_LENGTH == sizeof (inst->cookies[inst->num_cookies].cookie));
|
||||||
|
assert(NKE_MAX_COOKIES == sizeof (inst->cookies) /
|
||||||
|
sizeof (inst->cookies[inst->num_cookies]));
|
||||||
|
inst->cookies[inst->num_cookies].length = length;
|
||||||
|
memcpy(inst->cookies[inst->num_cookies].cookie, data, length);
|
||||||
|
|
||||||
|
inst->num_cookies++;
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_NTPV4_SERVER_NEGOTIATION:
|
||||||
|
if (length < 1 || length >= sizeof (inst->server_name)) {
|
||||||
|
DEBUG_LOG("Invalid server name");
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(inst->server_name, data, length);
|
||||||
|
inst->server_name[length] = '\0';
|
||||||
|
|
||||||
|
/* Make sure the name is printable and has no spaces */
|
||||||
|
for (i = 0; i < length && isgraph((unsigned char)inst->server_name[i]); i++)
|
||||||
|
;
|
||||||
|
if (i != length) {
|
||||||
|
DEBUG_LOG("Invalid server name");
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Negotiated server %s", inst->server_name);
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_NTPV4_PORT_NEGOTIATION:
|
||||||
|
if (length != 2) {
|
||||||
|
DEBUG_LOG("Invalid port");
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
inst->ntp_address.port = ntohs(data[0]);
|
||||||
|
DEBUG_LOG("Negotiated port %d", inst->ntp_address.port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DEBUG_LOG("Unknown record type=%d length=%d critical=%d", type, length, critical);
|
||||||
|
if (critical)
|
||||||
|
error = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("NTS-KE response: error=%d next=%d aead=%d",
|
||||||
|
error, next_protocol, aead_algorithm);
|
||||||
|
|
||||||
|
if (error || inst->num_cookies == 0 ||
|
||||||
|
next_protocol != NKE_NEXT_PROTOCOL_NTPV4 ||
|
||||||
|
aead_algorithm != AEAD_AES_SIV_CMAC_256)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
handle_message(void *arg)
|
||||||
|
{
|
||||||
|
NKC_Instance inst = arg;
|
||||||
|
|
||||||
|
if (!process_response(inst)) {
|
||||||
|
LOG(LOGS_ERR, "Received invalid NTS-KE response from %s", inst->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NKSN_GetKeys(inst->session, inst->context.algorithm,
|
||||||
|
&inst->context.c2s, &inst->context.s2c))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (inst->server_name[0] != '\0') {
|
||||||
|
if (inst->resolving_name)
|
||||||
|
return 0;
|
||||||
|
if (!UTI_StringToIP(inst->server_name, &inst->ntp_address.ip_addr)) {
|
||||||
|
int length = strlen(inst->server_name);
|
||||||
|
|
||||||
|
/* Add a trailing dot if not present to force the name to be
|
||||||
|
resolved as a fully qualified domain name */
|
||||||
|
if (length < 1 || length + 1 >= sizeof (inst->server_name))
|
||||||
|
return 0;
|
||||||
|
if (inst->server_name[length - 1] != '.') {
|
||||||
|
inst->server_name[length] = '.';
|
||||||
|
inst->server_name[length + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
DNS_Name2IPAddressAsync(inst->server_name, name_resolve_handler, inst);
|
||||||
|
inst->resolving_name = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->got_response = 1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NKC_Instance
|
||||||
|
NKC_CreateInstance(IPSockAddr *address, const char *name, uint32_t cert_set)
|
||||||
|
{
|
||||||
|
const char **trusted_certs;
|
||||||
|
uint32_t *certs_ids;
|
||||||
|
NKC_Instance inst;
|
||||||
|
int n_certs;
|
||||||
|
|
||||||
|
inst = MallocNew(struct NKC_Instance_Record);
|
||||||
|
|
||||||
|
inst->address = *address;
|
||||||
|
inst->name = Strdup(name);
|
||||||
|
inst->session = NKSN_CreateInstance(0, inst->name, handle_message, inst);
|
||||||
|
inst->resolving_name = 0;
|
||||||
|
inst->destroying = 0;
|
||||||
|
inst->got_response = 0;
|
||||||
|
|
||||||
|
n_certs = CNF_GetNtsTrustedCertsPaths(&trusted_certs, &certs_ids);
|
||||||
|
|
||||||
|
/* Share the credentials among clients using the default set of trusted
|
||||||
|
certificates, which likely contains most certificates */
|
||||||
|
if (cert_set == 0) {
|
||||||
|
if (!default_credentials)
|
||||||
|
default_credentials = NKSN_CreateClientCertCredentials(trusted_certs, certs_ids,
|
||||||
|
n_certs, cert_set);
|
||||||
|
inst->credentials = default_credentials;
|
||||||
|
if (default_credentials)
|
||||||
|
default_credentials_refs++;
|
||||||
|
} else {
|
||||||
|
inst->credentials = NKSN_CreateClientCertCredentials(trusted_certs, certs_ids,
|
||||||
|
n_certs, cert_set);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKC_DestroyInstance(NKC_Instance inst)
|
||||||
|
{
|
||||||
|
NKSN_DestroyInstance(inst->session);
|
||||||
|
|
||||||
|
Free(inst->name);
|
||||||
|
|
||||||
|
if (inst->credentials) {
|
||||||
|
if (inst->credentials == default_credentials) {
|
||||||
|
default_credentials_refs--;
|
||||||
|
if (default_credentials_refs <= 0) {
|
||||||
|
NKSN_DestroyCertCredentials(default_credentials);
|
||||||
|
default_credentials = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NKSN_DestroyCertCredentials(inst->credentials);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the asynchronous resolver is running, let the handler free
|
||||||
|
the instance later */
|
||||||
|
if (inst->resolving_name) {
|
||||||
|
inst->destroying = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Free(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKC_Start(NKC_Instance inst)
|
||||||
|
{
|
||||||
|
IPSockAddr local_addr;
|
||||||
|
char label[512], *iface;
|
||||||
|
int sock_fd;
|
||||||
|
|
||||||
|
assert(!NKC_IsActive(inst));
|
||||||
|
|
||||||
|
inst->got_response = 0;
|
||||||
|
|
||||||
|
if (!inst->credentials) {
|
||||||
|
DEBUG_LOG("Missing client credentials");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Follow the bindacqaddress and bindacqdevice settings */
|
||||||
|
CNF_GetBindAcquisitionAddress(inst->address.ip_addr.family, &local_addr.ip_addr);
|
||||||
|
local_addr.port = 0;
|
||||||
|
iface = CNF_GetBindAcquisitionInterface();
|
||||||
|
|
||||||
|
/* Make a label containing both the address and name of the server */
|
||||||
|
if (snprintf(label, sizeof (label), "%s (%s)",
|
||||||
|
UTI_IPSockAddrToString(&inst->address), inst->name) >= sizeof (label))
|
||||||
|
;
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenTcpSocket(&inst->address, &local_addr, iface, 0);
|
||||||
|
if (sock_fd < 0) {
|
||||||
|
LOG(LOGS_ERR, "Could not connect to %s", label);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start an NTS-KE session */
|
||||||
|
if (!NKSN_StartSession(inst->session, sock_fd, label, inst->credentials, CLIENT_TIMEOUT)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send a request */
|
||||||
|
if (!prepare_request(inst)) {
|
||||||
|
DEBUG_LOG("Could not prepare NTS-KE request");
|
||||||
|
NKSN_StopSession(inst->session);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKC_IsActive(NKC_Instance inst)
|
||||||
|
{
|
||||||
|
return !NKSN_IsStopped(inst->session) || inst->resolving_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKC_GetNtsData(NKC_Instance inst, NKE_Context *context,
|
||||||
|
NKE_Cookie *cookies, int *num_cookies, int max_cookies,
|
||||||
|
IPSockAddr *ntp_address)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!inst->got_response || inst->resolving_name)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*context = inst->context;
|
||||||
|
|
||||||
|
for (i = 0; i < inst->num_cookies && i < max_cookies; i++)
|
||||||
|
cookies[i] = inst->cookies[i];
|
||||||
|
*num_cookies = i;
|
||||||
|
|
||||||
|
*ntp_address = inst->ntp_address;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKC_GetRetryFactor(NKC_Instance inst)
|
||||||
|
{
|
||||||
|
return NKSN_GetRetryFactor(inst->session);
|
||||||
|
}
|
||||||
56
nts_ke_client.h
Normal file
56
nts_ke_client.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for the NTS-KE client
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_KE_CLIENT_H
|
||||||
|
#define GOT_NTS_KE_CLIENT_H
|
||||||
|
|
||||||
|
#include "addressing.h"
|
||||||
|
#include "nts_ke.h"
|
||||||
|
|
||||||
|
typedef struct NKC_Instance_Record *NKC_Instance;
|
||||||
|
|
||||||
|
/* Create a client NTS-KE instance */
|
||||||
|
extern NKC_Instance NKC_CreateInstance(IPSockAddr *address, const char *name, uint32_t cert_set);
|
||||||
|
|
||||||
|
/* Destroy an instance */
|
||||||
|
extern void NKC_DestroyInstance(NKC_Instance inst);
|
||||||
|
|
||||||
|
/* Connect to the server, start an NTS-KE session, send an NTS-KE request, and
|
||||||
|
process the response (asynchronously) */
|
||||||
|
extern int NKC_Start(NKC_Instance inst);
|
||||||
|
|
||||||
|
/* Check if the client is still running */
|
||||||
|
extern int NKC_IsActive(NKC_Instance inst);
|
||||||
|
|
||||||
|
/* Get the NTS data if the session was successful */
|
||||||
|
extern int NKC_GetNtsData(NKC_Instance inst, NKE_Context *context,
|
||||||
|
NKE_Cookie *cookies, int *num_cookies, int max_cookies,
|
||||||
|
IPSockAddr *ntp_address);
|
||||||
|
|
||||||
|
/* Get a factor to calculate retry interval (in log2 seconds) */
|
||||||
|
extern int NKC_GetRetryFactor(NKC_Instance inst);
|
||||||
|
|
||||||
|
#endif
|
||||||
967
nts_ke_server.c
Normal file
967
nts_ke_server.c
Normal file
@@ -0,0 +1,967 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
NTS-KE server
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "nts_ke_server.h"
|
||||||
|
|
||||||
|
#include "array.h"
|
||||||
|
#include "conf.h"
|
||||||
|
#include "clientlog.h"
|
||||||
|
#include "local.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "ntp_core.h"
|
||||||
|
#include "nts_ke_session.h"
|
||||||
|
#include "privops.h"
|
||||||
|
#include "siv.h"
|
||||||
|
#include "socket.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "sys.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#define SERVER_TIMEOUT 2.0
|
||||||
|
|
||||||
|
#define SERVER_COOKIE_SIV AEAD_AES_SIV_CMAC_256
|
||||||
|
#define SERVER_COOKIE_NONCE_LENGTH 16
|
||||||
|
|
||||||
|
#define KEY_ID_INDEX_BITS 2
|
||||||
|
#define MAX_SERVER_KEYS (1U << KEY_ID_INDEX_BITS)
|
||||||
|
#define FUTURE_KEYS 1
|
||||||
|
|
||||||
|
#define DUMP_FILENAME "ntskeys"
|
||||||
|
#define DUMP_IDENTIFIER "NKS0\n"
|
||||||
|
|
||||||
|
#define INVALID_SOCK_FD (-7)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t key_id;
|
||||||
|
unsigned char nonce[SERVER_COOKIE_NONCE_LENGTH];
|
||||||
|
} ServerCookieHeader;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t id;
|
||||||
|
unsigned char key[SIV_MAX_KEY_LENGTH];
|
||||||
|
SIV_Instance siv;
|
||||||
|
} ServerKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t key_id;
|
||||||
|
unsigned char key[SIV_MAX_KEY_LENGTH];
|
||||||
|
IPAddr client_addr;
|
||||||
|
uint16_t client_port;
|
||||||
|
uint16_t _pad;
|
||||||
|
} HelperRequest;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static ServerKey server_keys[MAX_SERVER_KEYS];
|
||||||
|
static int current_server_key;
|
||||||
|
static double last_server_key_ts;
|
||||||
|
static int key_rotation_interval;
|
||||||
|
|
||||||
|
static int server_sock_fd4;
|
||||||
|
static int server_sock_fd6;
|
||||||
|
|
||||||
|
static int helper_sock_fd;
|
||||||
|
static int is_helper;
|
||||||
|
|
||||||
|
static int initialised = 0;
|
||||||
|
|
||||||
|
/* Array of NKSN instances */
|
||||||
|
static ARR_Instance sessions;
|
||||||
|
static NKSN_Credentials server_credentials;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int handle_message(void *arg);
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
handle_client(int sock_fd, IPSockAddr *addr)
|
||||||
|
{
|
||||||
|
NKSN_Instance inst, *instp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Leave at least half of the descriptors which can handled by select()
|
||||||
|
to other use */
|
||||||
|
if (sock_fd > FD_SETSIZE / 2) {
|
||||||
|
DEBUG_LOG("Rejected connection from %s (%s)",
|
||||||
|
UTI_IPSockAddrToString(addr), "too many descriptors");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find an unused server slot or one with an already stopped session */
|
||||||
|
for (i = 0, inst = NULL; i < ARR_GetSize(sessions); i++) {
|
||||||
|
instp = ARR_GetElement(sessions, i);
|
||||||
|
if (!*instp) {
|
||||||
|
/* NULL handler arg will be replaced with the session instance */
|
||||||
|
inst = NKSN_CreateInstance(1, NULL, handle_message, NULL);
|
||||||
|
*instp = inst;
|
||||||
|
break;
|
||||||
|
} else if (NKSN_IsStopped(*instp)) {
|
||||||
|
inst = *instp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inst) {
|
||||||
|
DEBUG_LOG("Rejected connection from %s (%s)",
|
||||||
|
UTI_IPSockAddrToString(addr), "too many connections");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(server_credentials);
|
||||||
|
|
||||||
|
if (!NKSN_StartSession(inst, sock_fd, UTI_IPSockAddrToString(addr),
|
||||||
|
server_credentials, SERVER_TIMEOUT))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_helper_request(int fd, int event, void *arg)
|
||||||
|
{
|
||||||
|
SCK_Message *message;
|
||||||
|
HelperRequest *req;
|
||||||
|
IPSockAddr client_addr;
|
||||||
|
int sock_fd;
|
||||||
|
|
||||||
|
/* Receive the helper request with the NTS-KE session socket.
|
||||||
|
With multiple helpers EAGAIN errors are expected here. */
|
||||||
|
message = SCK_ReceiveMessage(fd, SCK_FLAG_MSG_DESCRIPTOR);
|
||||||
|
if (!message)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sock_fd = message->descriptor;
|
||||||
|
if (sock_fd < 0) {
|
||||||
|
/* Message with no descriptor is a shutdown command */
|
||||||
|
SCH_QuitProgram();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initialised) {
|
||||||
|
DEBUG_LOG("Uninitialised helper");
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->length != sizeof (HelperRequest))
|
||||||
|
LOG_FATAL("Invalid helper request");
|
||||||
|
|
||||||
|
req = message->data;
|
||||||
|
|
||||||
|
/* Extract the current server key and client address from the request */
|
||||||
|
server_keys[current_server_key].id = ntohl(req->key_id);
|
||||||
|
assert(sizeof (server_keys[current_server_key].key) == sizeof (req->key));
|
||||||
|
memcpy(server_keys[current_server_key].key, req->key,
|
||||||
|
sizeof (server_keys[current_server_key].key));
|
||||||
|
UTI_IPNetworkToHost(&req->client_addr, &client_addr.ip_addr);
|
||||||
|
client_addr.port = ntohs(req->client_port);
|
||||||
|
|
||||||
|
if (!SIV_SetKey(server_keys[current_server_key].siv, server_keys[current_server_key].key,
|
||||||
|
SIV_GetKeyLength(SERVER_COOKIE_SIV)))
|
||||||
|
LOG_FATAL("Could not set SIV key");
|
||||||
|
|
||||||
|
if (!handle_client(sock_fd, &client_addr)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Accepted helper request fd=%d", sock_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
accept_connection(int listening_fd, int event, void *arg)
|
||||||
|
{
|
||||||
|
SCK_Message message;
|
||||||
|
IPSockAddr addr;
|
||||||
|
int log_index, sock_fd;
|
||||||
|
struct timespec now;
|
||||||
|
|
||||||
|
sock_fd = SCK_AcceptConnection(listening_fd, &addr);
|
||||||
|
if (sock_fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!NCR_CheckAccessRestriction(&addr.ip_addr)) {
|
||||||
|
DEBUG_LOG("Rejected connection from %s (%s)",
|
||||||
|
UTI_IPSockAddrToString(&addr), "access denied");
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCH_GetLastEventTime(&now, NULL, NULL);
|
||||||
|
|
||||||
|
log_index = CLG_LogServiceAccess(CLG_NTSKE, &addr.ip_addr, &now);
|
||||||
|
if (log_index >= 0 && CLG_LimitServiceRate(CLG_NTSKE, log_index)) {
|
||||||
|
DEBUG_LOG("Rejected connection from %s (%s)",
|
||||||
|
UTI_IPSockAddrToString(&addr), "rate limit");
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pass the socket to a helper process if enabled. Otherwise, handle the
|
||||||
|
client in the main process. */
|
||||||
|
if (helper_sock_fd != INVALID_SOCK_FD) {
|
||||||
|
HelperRequest req;
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof (req));
|
||||||
|
|
||||||
|
/* Include the current server key and client address in the request */
|
||||||
|
req.key_id = htonl(server_keys[current_server_key].id);
|
||||||
|
assert(sizeof (req.key) == sizeof (server_keys[current_server_key].key));
|
||||||
|
memcpy(req.key, server_keys[current_server_key].key, sizeof (req.key));
|
||||||
|
UTI_IPHostToNetwork(&addr.ip_addr, &req.client_addr);
|
||||||
|
req.client_port = htons(addr.port);
|
||||||
|
|
||||||
|
SCK_InitMessage(&message, SCK_ADDR_UNSPEC);
|
||||||
|
message.data = &req;
|
||||||
|
message.length = sizeof (req);
|
||||||
|
message.descriptor = sock_fd;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
if (!SCK_SendMessage(helper_sock_fd, &message, SCK_FLAG_MSG_DESCRIPTOR)) {
|
||||||
|
/* If sending failed with EPIPE, it means all helpers closed their end of
|
||||||
|
the socket (e.g. due to a fatal error) */
|
||||||
|
if (errno == EPIPE)
|
||||||
|
LOG_FATAL("NTS-KE helpers failed");
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
} else {
|
||||||
|
if (!handle_client(sock_fd, &addr)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Accepted connection from %s fd=%d", UTI_IPSockAddrToString(&addr), sock_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
open_socket(int family)
|
||||||
|
{
|
||||||
|
IPSockAddr local_addr;
|
||||||
|
int backlog, sock_fd;
|
||||||
|
char *iface;
|
||||||
|
|
||||||
|
if (!SCK_IsIpFamilyEnabled(family))
|
||||||
|
return INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
CNF_GetBindAddress(family, &local_addr.ip_addr);
|
||||||
|
local_addr.port = CNF_GetNtsServerPort();
|
||||||
|
iface = CNF_GetBindNtpInterface();
|
||||||
|
|
||||||
|
sock_fd = SCK_OpenTcpSocket(NULL, &local_addr, iface, 0);
|
||||||
|
if (sock_fd < 0) {
|
||||||
|
LOG(LOGS_ERR, "Could not open NTS-KE socket on %s", UTI_IPSockAddrToString(&local_addr));
|
||||||
|
return INVALID_SOCK_FD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the maximum number of waiting connections on the socket to the maximum
|
||||||
|
number of concurrent sessions */
|
||||||
|
backlog = MAX(CNF_GetNtsServerProcesses(), 1) * CNF_GetNtsServerConnections();
|
||||||
|
|
||||||
|
if (!SCK_ListenOnSocket(sock_fd, backlog)) {
|
||||||
|
SCK_CloseSocket(sock_fd);
|
||||||
|
return INVALID_SOCK_FD;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCH_AddFileHandler(sock_fd, SCH_FILE_INPUT, accept_connection, NULL);
|
||||||
|
|
||||||
|
return sock_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
helper_signal(int x)
|
||||||
|
{
|
||||||
|
SCH_QuitProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
prepare_response(NKSN_Instance session, int error, int next_protocol, int aead_algorithm)
|
||||||
|
{
|
||||||
|
NKE_Context context;
|
||||||
|
NKE_Cookie cookie;
|
||||||
|
char *ntp_server;
|
||||||
|
uint16_t datum;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
DEBUG_LOG("NTS KE response: error=%d next=%d aead=%d", error, next_protocol, aead_algorithm);
|
||||||
|
|
||||||
|
NKSN_BeginMessage(session);
|
||||||
|
|
||||||
|
if (error >= 0) {
|
||||||
|
datum = htons(error);
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_ERROR, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
} else if (next_protocol < 0) {
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_NEXT_PROTOCOL, NULL, 0))
|
||||||
|
return 0;
|
||||||
|
} else if (aead_algorithm < 0) {
|
||||||
|
datum = htons(next_protocol);
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_NEXT_PROTOCOL, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_AEAD_ALGORITHM, NULL, 0))
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
datum = htons(next_protocol);
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_NEXT_PROTOCOL, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
datum = htons(aead_algorithm);
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_AEAD_ALGORITHM, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (CNF_GetNTPPort() != NTP_PORT) {
|
||||||
|
datum = htons(CNF_GetNTPPort());
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_NTPV4_PORT_NEGOTIATION, &datum, sizeof (datum)))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ntp_server = CNF_GetNtsNtpServer();
|
||||||
|
if (ntp_server) {
|
||||||
|
if (!NKSN_AddRecord(session, 1, NKE_RECORD_NTPV4_SERVER_NEGOTIATION,
|
||||||
|
ntp_server, strlen(ntp_server)))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.algorithm = aead_algorithm;
|
||||||
|
|
||||||
|
if (!NKSN_GetKeys(session, aead_algorithm, &context.c2s, &context.s2c))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < NKE_MAX_COOKIES; i++) {
|
||||||
|
if (!NKS_GenerateCookie(&context, &cookie))
|
||||||
|
return 0;
|
||||||
|
if (!NKSN_AddRecord(session, 0, NKE_RECORD_COOKIE, cookie.cookie, cookie.length))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NKSN_EndMessage(session))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
process_request(NKSN_Instance session)
|
||||||
|
{
|
||||||
|
int next_protocol_records = 0, aead_algorithm_records = 0;
|
||||||
|
int next_protocol_values = 0, aead_algorithm_values = 0;
|
||||||
|
int next_protocol = -1, aead_algorithm = -1, error = -1;
|
||||||
|
int i, critical, type, length;
|
||||||
|
uint16_t data[NKE_MAX_RECORD_BODY_LENGTH / sizeof (uint16_t)];
|
||||||
|
|
||||||
|
assert(NKE_MAX_RECORD_BODY_LENGTH % sizeof (uint16_t) == 0);
|
||||||
|
assert(sizeof (uint16_t) == 2);
|
||||||
|
|
||||||
|
while (error < 0) {
|
||||||
|
if (!NKSN_GetRecord(session, &critical, &type, &length, &data, sizeof (data)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case NKE_RECORD_NEXT_PROTOCOL:
|
||||||
|
if (!critical || length < 2 || length % 2 != 0) {
|
||||||
|
error = NKE_ERROR_BAD_REQUEST;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
next_protocol_records++;
|
||||||
|
|
||||||
|
for (i = 0; i < MIN(length, sizeof (data)) / 2; i++) {
|
||||||
|
next_protocol_values++;
|
||||||
|
if (ntohs(data[i]) == NKE_NEXT_PROTOCOL_NTPV4)
|
||||||
|
next_protocol = NKE_NEXT_PROTOCOL_NTPV4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_AEAD_ALGORITHM:
|
||||||
|
if (length < 2 || length % 2 != 0) {
|
||||||
|
error = NKE_ERROR_BAD_REQUEST;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
aead_algorithm_records++;
|
||||||
|
|
||||||
|
for (i = 0; i < MIN(length, sizeof (data)) / 2; i++) {
|
||||||
|
aead_algorithm_values++;
|
||||||
|
if (ntohs(data[i]) == AEAD_AES_SIV_CMAC_256)
|
||||||
|
aead_algorithm = AEAD_AES_SIV_CMAC_256;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NKE_RECORD_ERROR:
|
||||||
|
case NKE_RECORD_WARNING:
|
||||||
|
case NKE_RECORD_COOKIE:
|
||||||
|
error = NKE_ERROR_BAD_REQUEST;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (critical)
|
||||||
|
error = NKE_ERROR_UNRECOGNIZED_CRITICAL_RECORD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
if (next_protocol_records != 1 || next_protocol_values < 1 ||
|
||||||
|
(next_protocol == NKE_NEXT_PROTOCOL_NTPV4 &&
|
||||||
|
(aead_algorithm_records != 1 || aead_algorithm_values < 1)))
|
||||||
|
error = NKE_ERROR_BAD_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!prepare_response(session, error, next_protocol, aead_algorithm))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
handle_message(void *arg)
|
||||||
|
{
|
||||||
|
NKSN_Instance session = arg;
|
||||||
|
|
||||||
|
return process_request(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
generate_key(int index)
|
||||||
|
{
|
||||||
|
int key_length;
|
||||||
|
|
||||||
|
if (index < 0 || index >= MAX_SERVER_KEYS)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
key_length = SIV_GetKeyLength(SERVER_COOKIE_SIV);
|
||||||
|
if (key_length > sizeof (server_keys[index].key))
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
UTI_GetRandomBytesUrandom(server_keys[index].key, key_length);
|
||||||
|
|
||||||
|
if (!server_keys[index].siv ||
|
||||||
|
!SIV_SetKey(server_keys[index].siv, server_keys[index].key, key_length))
|
||||||
|
LOG_FATAL("Could not set SIV key");
|
||||||
|
|
||||||
|
UTI_GetRandomBytes(&server_keys[index].id, sizeof (server_keys[index].id));
|
||||||
|
|
||||||
|
/* Encode the index in the lowest bits of the ID */
|
||||||
|
server_keys[index].id &= -1U << KEY_ID_INDEX_BITS;
|
||||||
|
server_keys[index].id |= index;
|
||||||
|
|
||||||
|
DEBUG_LOG("Generated server key %"PRIX32, server_keys[index].id);
|
||||||
|
|
||||||
|
last_server_key_ts = SCH_GetLastEventMonoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
save_keys(void)
|
||||||
|
{
|
||||||
|
char buf[SIV_MAX_KEY_LENGTH * 2 + 1], *dump_dir;
|
||||||
|
int i, index, key_length;
|
||||||
|
double last_key_age;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
/* Don't save the keys if rotation is disabled to enable an external
|
||||||
|
management of the keys (e.g. share them with another server) */
|
||||||
|
if (key_rotation_interval == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dump_dir = CNF_GetNtsDumpDir();
|
||||||
|
if (!dump_dir)
|
||||||
|
return;
|
||||||
|
|
||||||
|
f = UTI_OpenFile(dump_dir, DUMP_FILENAME, ".tmp", 'w', 0600);
|
||||||
|
if (!f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
key_length = SIV_GetKeyLength(SERVER_COOKIE_SIV);
|
||||||
|
last_key_age = SCH_GetLastEventMonoTime() - last_server_key_ts;
|
||||||
|
|
||||||
|
if (fprintf(f, "%s%d %.1f\n", DUMP_IDENTIFIER, SERVER_COOKIE_SIV, last_key_age) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_SERVER_KEYS; i++) {
|
||||||
|
index = (current_server_key + i + 1 + FUTURE_KEYS) % MAX_SERVER_KEYS;
|
||||||
|
|
||||||
|
if (key_length > sizeof (server_keys[index].key) ||
|
||||||
|
!UTI_BytesToHex(server_keys[index].key, key_length, buf, sizeof (buf)) ||
|
||||||
|
fprintf(f, "%08"PRIX32" %s\n", server_keys[index].id, buf) < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
/* Rename the temporary file, or remove it if that fails */
|
||||||
|
if (!UTI_RenameTempFile(dump_dir, DUMP_FILENAME, ".tmp", NULL)) {
|
||||||
|
if (!UTI_RemoveFile(dump_dir, DUMP_FILENAME, ".tmp"))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
DEBUG_LOG("Could not %s server keys", "save");
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (!UTI_RemoveFile(dump_dir, DUMP_FILENAME, NULL))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
#define MAX_WORDS 2
|
||||||
|
|
||||||
|
static int
|
||||||
|
load_keys(void)
|
||||||
|
{
|
||||||
|
char *dump_dir, line[1024], *words[MAX_WORDS];
|
||||||
|
unsigned char key[SIV_MAX_KEY_LENGTH];
|
||||||
|
int i, index, key_length, algorithm;
|
||||||
|
double key_age;
|
||||||
|
FILE *f;
|
||||||
|
uint32_t id;
|
||||||
|
|
||||||
|
dump_dir = CNF_GetNtsDumpDir();
|
||||||
|
if (!dump_dir)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
f = UTI_OpenFile(dump_dir, DUMP_FILENAME, NULL, 'r', 0);
|
||||||
|
if (!f)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!fgets(line, sizeof (line), f) || strcmp(line, DUMP_IDENTIFIER) != 0 ||
|
||||||
|
!fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 2 ||
|
||||||
|
sscanf(words[0], "%d", &algorithm) != 1 || algorithm != SERVER_COOKIE_SIV ||
|
||||||
|
sscanf(words[1], "%lf", &key_age) != 1)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
key_length = SIV_GetKeyLength(SERVER_COOKIE_SIV);
|
||||||
|
last_server_key_ts = SCH_GetLastEventMonoTime() - MAX(key_age, 0.0);
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_SERVER_KEYS && fgets(line, sizeof (line), f); i++) {
|
||||||
|
if (UTI_SplitString(line, words, MAX_WORDS) != 2 ||
|
||||||
|
sscanf(words[0], "%"PRIX32, &id) != 1)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (UTI_HexToBytes(words[1], key, sizeof (key)) != key_length)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
index = id % MAX_SERVER_KEYS;
|
||||||
|
|
||||||
|
server_keys[index].id = id;
|
||||||
|
assert(sizeof (server_keys[index].key) == sizeof (key));
|
||||||
|
memcpy(server_keys[index].key, key, key_length);
|
||||||
|
|
||||||
|
if (!SIV_SetKey(server_keys[index].siv, server_keys[index].key, key_length))
|
||||||
|
LOG_FATAL("Could not set SIV key");
|
||||||
|
|
||||||
|
DEBUG_LOG("Loaded key %"PRIX32, id);
|
||||||
|
|
||||||
|
current_server_key = (index + MAX_SERVER_KEYS - FUTURE_KEYS) % MAX_SERVER_KEYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
error:
|
||||||
|
DEBUG_LOG("Could not %s server keys", "load");
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
key_timeout(void *arg)
|
||||||
|
{
|
||||||
|
current_server_key = (current_server_key + 1) % MAX_SERVER_KEYS;
|
||||||
|
generate_key((current_server_key + FUTURE_KEYS) % MAX_SERVER_KEYS);
|
||||||
|
save_keys();
|
||||||
|
|
||||||
|
SCH_AddTimeoutByDelay(key_rotation_interval, key_timeout, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
run_helper(uid_t uid, gid_t gid, int scfilter_level)
|
||||||
|
{
|
||||||
|
LOG_Severity log_severity;
|
||||||
|
|
||||||
|
/* Finish minimal initialisation and run using the scheduler loop
|
||||||
|
similarly to the main process */
|
||||||
|
|
||||||
|
DEBUG_LOG("Helper started");
|
||||||
|
|
||||||
|
/* Suppress a log message about disabled clock control */
|
||||||
|
log_severity = LOG_GetMinSeverity();
|
||||||
|
LOG_SetMinSeverity(LOGS_ERR);
|
||||||
|
|
||||||
|
SYS_Initialise(0);
|
||||||
|
LOG_SetMinSeverity(log_severity);
|
||||||
|
|
||||||
|
if (!geteuid() && (uid || gid))
|
||||||
|
SYS_DropRoot(uid, gid, SYS_NTSKE_HELPER);
|
||||||
|
|
||||||
|
NKS_Initialise();
|
||||||
|
|
||||||
|
UTI_SetQuitSignalsHandler(helper_signal, 1);
|
||||||
|
if (scfilter_level != 0)
|
||||||
|
SYS_EnableSystemCallFilter(scfilter_level, SYS_NTSKE_HELPER);
|
||||||
|
|
||||||
|
SCH_MainLoop();
|
||||||
|
|
||||||
|
DEBUG_LOG("Helper exiting");
|
||||||
|
|
||||||
|
NKS_Finalise();
|
||||||
|
SCK_Finalise();
|
||||||
|
SYS_Finalise();
|
||||||
|
SCH_Finalise();
|
||||||
|
LCL_Finalise();
|
||||||
|
PRV_Finalise();
|
||||||
|
CNF_Finalise();
|
||||||
|
LOG_Finalise();
|
||||||
|
|
||||||
|
UTI_ResetGetRandomFunctions();
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKS_PreInitialise(uid_t uid, gid_t gid, int scfilter_level)
|
||||||
|
{
|
||||||
|
int i, processes, sock_fd1, sock_fd2;
|
||||||
|
const char **certs, **keys;
|
||||||
|
char prefix[16];
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
helper_sock_fd = INVALID_SOCK_FD;
|
||||||
|
is_helper = 0;
|
||||||
|
|
||||||
|
if (CNF_GetNtsServerCertAndKeyFiles(&certs, &keys) <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
processes = CNF_GetNtsServerProcesses();
|
||||||
|
if (processes <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Start helper processes to perform (computationally expensive) NTS-KE
|
||||||
|
sessions with clients on sockets forwarded from the main process */
|
||||||
|
|
||||||
|
sock_fd1 = SCK_OpenUnixSocketPair(0, &sock_fd2);
|
||||||
|
if (sock_fd1 < 0)
|
||||||
|
LOG_FATAL("Could not open socket pair");
|
||||||
|
|
||||||
|
for (i = 0; i < processes; i++) {
|
||||||
|
pid = fork();
|
||||||
|
|
||||||
|
if (pid < 0)
|
||||||
|
LOG_FATAL("fork() failed : %s", strerror(errno));
|
||||||
|
|
||||||
|
if (pid > 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
is_helper = 1;
|
||||||
|
|
||||||
|
UTI_ResetGetRandomFunctions();
|
||||||
|
|
||||||
|
snprintf(prefix, sizeof (prefix), "nks#%d:", i + 1);
|
||||||
|
LOG_SetDebugPrefix(prefix);
|
||||||
|
LOG_CloseParentFd();
|
||||||
|
|
||||||
|
SCK_CloseSocket(sock_fd1);
|
||||||
|
SCH_AddFileHandler(sock_fd2, SCH_FILE_INPUT, handle_helper_request, NULL);
|
||||||
|
|
||||||
|
run_helper(uid, gid, scfilter_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
SCK_CloseSocket(sock_fd2);
|
||||||
|
helper_sock_fd = sock_fd1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKS_Initialise(void)
|
||||||
|
{
|
||||||
|
const char **certs, **keys;
|
||||||
|
int i, n_certs_keys;
|
||||||
|
double key_delay;
|
||||||
|
|
||||||
|
server_sock_fd4 = INVALID_SOCK_FD;
|
||||||
|
server_sock_fd6 = INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
n_certs_keys = CNF_GetNtsServerCertAndKeyFiles(&certs, &keys);
|
||||||
|
if (n_certs_keys <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (helper_sock_fd == INVALID_SOCK_FD) {
|
||||||
|
server_credentials = NKSN_CreateServerCertCredentials(certs, keys, n_certs_keys);
|
||||||
|
if (!server_credentials)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
server_credentials = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sessions = ARR_CreateInstance(sizeof (NKSN_Instance));
|
||||||
|
for (i = 0; i < CNF_GetNtsServerConnections(); i++)
|
||||||
|
*(NKSN_Instance *)ARR_GetNewElement(sessions) = NULL;
|
||||||
|
|
||||||
|
/* Generate random keys, even if they will be replaced by reloaded keys,
|
||||||
|
or unused (in the helper) */
|
||||||
|
for (i = 0; i < MAX_SERVER_KEYS; i++) {
|
||||||
|
server_keys[i].siv = SIV_CreateInstance(SERVER_COOKIE_SIV);
|
||||||
|
generate_key(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
current_server_key = MAX_SERVER_KEYS - 1;
|
||||||
|
|
||||||
|
if (!is_helper) {
|
||||||
|
server_sock_fd4 = open_socket(IPADDR_INET4);
|
||||||
|
server_sock_fd6 = open_socket(IPADDR_INET6);
|
||||||
|
|
||||||
|
key_rotation_interval = MAX(CNF_GetNtsRotate(), 0);
|
||||||
|
|
||||||
|
/* Reload saved keys, or save the new keys */
|
||||||
|
if (!load_keys())
|
||||||
|
save_keys();
|
||||||
|
|
||||||
|
if (key_rotation_interval > 0) {
|
||||||
|
key_delay = key_rotation_interval - (SCH_GetLastEventMonoTime() - last_server_key_ts);
|
||||||
|
SCH_AddTimeoutByDelay(MAX(key_delay, 0.0), key_timeout, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialised = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKS_Finalise(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!initialised)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (helper_sock_fd != INVALID_SOCK_FD) {
|
||||||
|
/* Send the helpers a request to exit */
|
||||||
|
for (i = 0; i < CNF_GetNtsServerProcesses(); i++) {
|
||||||
|
if (!SCK_Send(helper_sock_fd, "", 1, 0))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
SCK_CloseSocket(helper_sock_fd);
|
||||||
|
}
|
||||||
|
if (server_sock_fd4 != INVALID_SOCK_FD)
|
||||||
|
SCK_CloseSocket(server_sock_fd4);
|
||||||
|
if (server_sock_fd6 != INVALID_SOCK_FD)
|
||||||
|
SCK_CloseSocket(server_sock_fd6);
|
||||||
|
|
||||||
|
if (!is_helper)
|
||||||
|
save_keys();
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_SERVER_KEYS; i++)
|
||||||
|
SIV_DestroyInstance(server_keys[i].siv);
|
||||||
|
|
||||||
|
for (i = 0; i < ARR_GetSize(sessions); i++) {
|
||||||
|
NKSN_Instance session = *(NKSN_Instance *)ARR_GetElement(sessions, i);
|
||||||
|
if (session)
|
||||||
|
NKSN_DestroyInstance(session);
|
||||||
|
}
|
||||||
|
ARR_DestroyInstance(sessions);
|
||||||
|
|
||||||
|
if (server_credentials)
|
||||||
|
NKSN_DestroyCertCredentials(server_credentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKS_DumpKeys(void)
|
||||||
|
{
|
||||||
|
save_keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKS_ReloadKeys(void)
|
||||||
|
{
|
||||||
|
/* Don't load the keys if they are expected to be generated by this server
|
||||||
|
instance (i.e. they are already loaded) to not delay the next rotation */
|
||||||
|
if (key_rotation_interval > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
load_keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
/* A server cookie consists of key ID, nonce, and encrypted C2S+S2C keys */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKS_GenerateCookie(NKE_Context *context, NKE_Cookie *cookie)
|
||||||
|
{
|
||||||
|
unsigned char plaintext[2 * NKE_MAX_KEY_LENGTH], *ciphertext;
|
||||||
|
int plaintext_length, tag_length;
|
||||||
|
ServerCookieHeader *header;
|
||||||
|
ServerKey *key;
|
||||||
|
|
||||||
|
if (!initialised) {
|
||||||
|
DEBUG_LOG("NTS server disabled");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The algorithm is hardcoded for now */
|
||||||
|
if (context->algorithm != AEAD_AES_SIV_CMAC_256) {
|
||||||
|
DEBUG_LOG("Unexpected SIV algorithm");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->c2s.length < 0 || context->c2s.length > NKE_MAX_KEY_LENGTH ||
|
||||||
|
context->s2c.length < 0 || context->s2c.length > NKE_MAX_KEY_LENGTH) {
|
||||||
|
DEBUG_LOG("Invalid key length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
key = &server_keys[current_server_key];
|
||||||
|
|
||||||
|
header = (ServerCookieHeader *)cookie->cookie;
|
||||||
|
|
||||||
|
header->key_id = htonl(key->id);
|
||||||
|
UTI_GetRandomBytes(header->nonce, sizeof (header->nonce));
|
||||||
|
|
||||||
|
plaintext_length = context->c2s.length + context->s2c.length;
|
||||||
|
assert(plaintext_length <= sizeof (plaintext));
|
||||||
|
memcpy(plaintext, context->c2s.key, context->c2s.length);
|
||||||
|
memcpy(plaintext + context->c2s.length, context->s2c.key, context->s2c.length);
|
||||||
|
|
||||||
|
tag_length = SIV_GetTagLength(key->siv);
|
||||||
|
cookie->length = sizeof (*header) + plaintext_length + tag_length;
|
||||||
|
assert(cookie->length <= sizeof (cookie->cookie));
|
||||||
|
ciphertext = cookie->cookie + sizeof (*header);
|
||||||
|
|
||||||
|
if (!SIV_Encrypt(key->siv, header->nonce, sizeof (header->nonce),
|
||||||
|
"", 0,
|
||||||
|
plaintext, plaintext_length,
|
||||||
|
ciphertext, plaintext_length + tag_length)) {
|
||||||
|
DEBUG_LOG("Could not encrypt cookie");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKS_DecodeCookie(NKE_Cookie *cookie, NKE_Context *context)
|
||||||
|
{
|
||||||
|
unsigned char plaintext[2 * NKE_MAX_KEY_LENGTH], *ciphertext;
|
||||||
|
int ciphertext_length, plaintext_length, tag_length;
|
||||||
|
ServerCookieHeader *header;
|
||||||
|
ServerKey *key;
|
||||||
|
uint32_t key_id;
|
||||||
|
|
||||||
|
if (!initialised) {
|
||||||
|
DEBUG_LOG("NTS server disabled");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cookie->length <= (int)sizeof (*header)) {
|
||||||
|
DEBUG_LOG("Invalid cookie length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header = (ServerCookieHeader *)cookie->cookie;
|
||||||
|
ciphertext = cookie->cookie + sizeof (*header);
|
||||||
|
ciphertext_length = cookie->length - sizeof (*header);
|
||||||
|
|
||||||
|
key_id = ntohl(header->key_id);
|
||||||
|
key = &server_keys[key_id % MAX_SERVER_KEYS];
|
||||||
|
if (key_id != key->id) {
|
||||||
|
DEBUG_LOG("Unknown key %"PRIX32, key_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
tag_length = SIV_GetTagLength(key->siv);
|
||||||
|
if (tag_length >= ciphertext_length) {
|
||||||
|
DEBUG_LOG("Invalid cookie length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
plaintext_length = ciphertext_length - tag_length;
|
||||||
|
if (plaintext_length > sizeof (plaintext) || plaintext_length % 2 != 0) {
|
||||||
|
DEBUG_LOG("Invalid cookie length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SIV_Decrypt(key->siv, header->nonce, sizeof (header->nonce),
|
||||||
|
"", 0,
|
||||||
|
ciphertext, ciphertext_length,
|
||||||
|
plaintext, plaintext_length)) {
|
||||||
|
DEBUG_LOG("Could not decrypt cookie");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
context->algorithm = AEAD_AES_SIV_CMAC_256;
|
||||||
|
|
||||||
|
context->c2s.length = plaintext_length / 2;
|
||||||
|
context->s2c.length = plaintext_length / 2;
|
||||||
|
assert(context->c2s.length <= sizeof (context->c2s.key));
|
||||||
|
|
||||||
|
memcpy(context->c2s.key, plaintext, context->c2s.length);
|
||||||
|
memcpy(context->s2c.key, plaintext + context->c2s.length, context->s2c.length);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
49
nts_ke_server.h
Normal file
49
nts_ke_server.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for the NTS-KE server
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_KE_SERVER_H
|
||||||
|
#define GOT_NTS_KE_SERVER_H
|
||||||
|
|
||||||
|
#include "nts_ke.h"
|
||||||
|
|
||||||
|
/* Init and fini functions */
|
||||||
|
extern void NKS_PreInitialise(uid_t uid, gid_t gid, int scfilter_level);
|
||||||
|
extern void NKS_Initialise(void);
|
||||||
|
extern void NKS_Finalise(void);
|
||||||
|
|
||||||
|
/* Save the current server keys */
|
||||||
|
extern void NKS_DumpKeys(void);
|
||||||
|
|
||||||
|
/* Reload the keys */
|
||||||
|
extern void NKS_ReloadKeys(void);
|
||||||
|
|
||||||
|
/* Generate an NTS cookie with a given context */
|
||||||
|
extern int NKS_GenerateCookie(NKE_Context *context, NKE_Cookie *cookie);
|
||||||
|
|
||||||
|
/* Validate a cookie and decode the context */
|
||||||
|
extern int NKS_DecodeCookie(NKE_Cookie *cookie, NKE_Context *context);
|
||||||
|
|
||||||
|
#endif
|
||||||
927
nts_ke_session.c
Normal file
927
nts_ke_session.c
Normal file
@@ -0,0 +1,927 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020-2021
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
NTS-KE session used by server and client
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "nts_ke_session.h"
|
||||||
|
|
||||||
|
#include "conf.h"
|
||||||
|
#include "local.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "siv.h"
|
||||||
|
#include "socket.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#include <gnutls/gnutls.h>
|
||||||
|
#include <gnutls/x509.h>
|
||||||
|
|
||||||
|
#define INVALID_SOCK_FD (-8)
|
||||||
|
|
||||||
|
struct RecordHeader {
|
||||||
|
uint16_t type;
|
||||||
|
uint16_t body_length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message {
|
||||||
|
int length;
|
||||||
|
int sent;
|
||||||
|
int parsed;
|
||||||
|
int complete;
|
||||||
|
unsigned char data[NKE_MAX_MESSAGE_LENGTH];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
KE_WAIT_CONNECT,
|
||||||
|
KE_HANDSHAKE,
|
||||||
|
KE_SEND,
|
||||||
|
KE_RECEIVE,
|
||||||
|
KE_SHUTDOWN,
|
||||||
|
KE_STOPPED,
|
||||||
|
} KeState;
|
||||||
|
|
||||||
|
struct NKSN_Instance_Record {
|
||||||
|
int server;
|
||||||
|
char *server_name;
|
||||||
|
NKSN_MessageHandler handler;
|
||||||
|
void *handler_arg;
|
||||||
|
|
||||||
|
KeState state;
|
||||||
|
int sock_fd;
|
||||||
|
char *label;
|
||||||
|
gnutls_session_t tls_session;
|
||||||
|
SCH_TimeoutID timeout_id;
|
||||||
|
int retry_factor;
|
||||||
|
|
||||||
|
struct Message message;
|
||||||
|
int new_message;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static gnutls_priority_t priority_cache;
|
||||||
|
|
||||||
|
static int credentials_counter = 0;
|
||||||
|
|
||||||
|
static int clock_updates = 0;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
reset_message(struct Message *message)
|
||||||
|
{
|
||||||
|
message->length = 0;
|
||||||
|
message->sent = 0;
|
||||||
|
message->parsed = 0;
|
||||||
|
message->complete = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
add_record(struct Message *message, int critical, int type, const void *body, int body_length)
|
||||||
|
{
|
||||||
|
struct RecordHeader header;
|
||||||
|
|
||||||
|
assert(message->length <= sizeof (message->data));
|
||||||
|
|
||||||
|
if (body_length < 0 || body_length > 0xffff || type < 0 || type > 0x7fff ||
|
||||||
|
message->length + sizeof (header) + body_length > sizeof (message->data))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
header.type = htons(!!critical * NKE_RECORD_CRITICAL_BIT | type);
|
||||||
|
header.body_length = htons(body_length);
|
||||||
|
|
||||||
|
memcpy(&message->data[message->length], &header, sizeof (header));
|
||||||
|
message->length += sizeof (header);
|
||||||
|
|
||||||
|
if (body_length > 0) {
|
||||||
|
memcpy(&message->data[message->length], body, body_length);
|
||||||
|
message->length += body_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
reset_message_parsing(struct Message *message)
|
||||||
|
{
|
||||||
|
message->parsed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_record(struct Message *message, int *critical, int *type, int *body_length,
|
||||||
|
void *body, int buffer_length)
|
||||||
|
{
|
||||||
|
struct RecordHeader header;
|
||||||
|
int blen, rlen;
|
||||||
|
|
||||||
|
if (message->length < message->parsed + sizeof (header) ||
|
||||||
|
buffer_length < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(&header, &message->data[message->parsed], sizeof (header));
|
||||||
|
|
||||||
|
blen = ntohs(header.body_length);
|
||||||
|
rlen = sizeof (header) + blen;
|
||||||
|
assert(blen >= 0 && rlen > 0);
|
||||||
|
|
||||||
|
if (message->length < message->parsed + rlen)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (critical)
|
||||||
|
*critical = !!(ntohs(header.type) & NKE_RECORD_CRITICAL_BIT);
|
||||||
|
if (type)
|
||||||
|
*type = ntohs(header.type) & ~NKE_RECORD_CRITICAL_BIT;
|
||||||
|
if (body)
|
||||||
|
memcpy(body, &message->data[message->parsed + sizeof (header)], MIN(buffer_length, blen));
|
||||||
|
if (body_length)
|
||||||
|
*body_length = blen;
|
||||||
|
|
||||||
|
message->parsed += rlen;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_message_format(struct Message *message, int eof)
|
||||||
|
{
|
||||||
|
int critical = 0, type = -1, length = -1, ends = 0;
|
||||||
|
|
||||||
|
reset_message_parsing(message);
|
||||||
|
message->complete = 0;
|
||||||
|
|
||||||
|
while (get_record(message, &critical, &type, &length, NULL, 0)) {
|
||||||
|
if (type == NKE_RECORD_END_OF_MESSAGE) {
|
||||||
|
if (!critical || length != 0 || ends > 0)
|
||||||
|
return 0;
|
||||||
|
ends++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the message cannot be fully parsed, but more data may be coming,
|
||||||
|
consider the format to be ok */
|
||||||
|
if (message->length == 0 || message->parsed < message->length)
|
||||||
|
return !eof;
|
||||||
|
|
||||||
|
if (type != NKE_RECORD_END_OF_MESSAGE)
|
||||||
|
return !eof;
|
||||||
|
|
||||||
|
message->complete = 1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static gnutls_session_t
|
||||||
|
create_tls_session(int server_mode, int sock_fd, const char *server_name,
|
||||||
|
gnutls_certificate_credentials_t credentials,
|
||||||
|
gnutls_priority_t priority)
|
||||||
|
{
|
||||||
|
unsigned char alpn_name[sizeof (NKE_ALPN_NAME)];
|
||||||
|
gnutls_session_t session;
|
||||||
|
gnutls_datum_t alpn;
|
||||||
|
unsigned int flags;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = gnutls_init(&session, GNUTLS_NONBLOCK | GNUTLS_NO_TICKETS |
|
||||||
|
(server_mode ? GNUTLS_SERVER : GNUTLS_CLIENT));
|
||||||
|
if (r < 0) {
|
||||||
|
LOG(LOGS_ERR, "Could not %s TLS session : %s", "create", gnutls_strerror(r));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!server_mode) {
|
||||||
|
assert(server_name);
|
||||||
|
|
||||||
|
if (!UTI_IsStringIP(server_name)) {
|
||||||
|
r = gnutls_server_name_set(session, GNUTLS_NAME_DNS, server_name, strlen(server_name));
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
flags = 0;
|
||||||
|
|
||||||
|
if (clock_updates < CNF_GetNoCertTimeCheck()) {
|
||||||
|
flags |= GNUTLS_VERIFY_DISABLE_TIME_CHECKS | GNUTLS_VERIFY_DISABLE_TRUSTED_TIME_CHECKS;
|
||||||
|
DEBUG_LOG("Disabled time checks");
|
||||||
|
}
|
||||||
|
|
||||||
|
gnutls_session_set_verify_cert(session, server_name, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = gnutls_priority_set(session, priority);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
r = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, credentials);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
memcpy(alpn_name, NKE_ALPN_NAME, sizeof (alpn_name));
|
||||||
|
alpn.data = alpn_name;
|
||||||
|
alpn.size = sizeof (alpn_name) - 1;
|
||||||
|
|
||||||
|
r = gnutls_alpn_set_protocols(session, &alpn, 1, 0);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
gnutls_transport_set_int(session, sock_fd);
|
||||||
|
|
||||||
|
return session;
|
||||||
|
|
||||||
|
error:
|
||||||
|
LOG(LOGS_ERR, "Could not %s TLS session : %s", "set", gnutls_strerror(r));
|
||||||
|
gnutls_deinit(session);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
stop_session(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
if (inst->state == KE_STOPPED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
inst->state = KE_STOPPED;
|
||||||
|
|
||||||
|
SCH_RemoveFileHandler(inst->sock_fd);
|
||||||
|
SCK_CloseSocket(inst->sock_fd);
|
||||||
|
inst->sock_fd = INVALID_SOCK_FD;
|
||||||
|
|
||||||
|
Free(inst->label);
|
||||||
|
inst->label = NULL;
|
||||||
|
|
||||||
|
gnutls_deinit(inst->tls_session);
|
||||||
|
inst->tls_session = NULL;
|
||||||
|
|
||||||
|
SCH_RemoveTimeout(inst->timeout_id);
|
||||||
|
inst->timeout_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
session_timeout(void *arg)
|
||||||
|
{
|
||||||
|
NKSN_Instance inst = arg;
|
||||||
|
|
||||||
|
LOG(inst->server ? LOGS_DEBUG : LOGS_ERR, "NTS-KE session with %s timed out", inst->label);
|
||||||
|
|
||||||
|
inst->timeout_id = 0;
|
||||||
|
stop_session(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_alpn(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
gnutls_datum_t alpn;
|
||||||
|
|
||||||
|
if (gnutls_alpn_get_selected_protocol(inst->tls_session, &alpn) < 0 ||
|
||||||
|
alpn.size != sizeof (NKE_ALPN_NAME) - 1 ||
|
||||||
|
memcmp(alpn.data, NKE_ALPN_NAME, sizeof (NKE_ALPN_NAME) - 1) != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_input_output(NKSN_Instance inst, int output)
|
||||||
|
{
|
||||||
|
SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_INPUT, !output);
|
||||||
|
SCH_SetFileHandlerEvent(inst->sock_fd, SCH_FILE_OUTPUT, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
change_state(NKSN_Instance inst, KeState state)
|
||||||
|
{
|
||||||
|
int output;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case KE_HANDSHAKE:
|
||||||
|
output = !inst->server;
|
||||||
|
break;
|
||||||
|
case KE_WAIT_CONNECT:
|
||||||
|
case KE_SEND:
|
||||||
|
case KE_SHUTDOWN:
|
||||||
|
output = 1;
|
||||||
|
break;
|
||||||
|
case KE_RECEIVE:
|
||||||
|
output = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_input_output(inst, output);
|
||||||
|
|
||||||
|
inst->state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
handle_event(NKSN_Instance inst, int event)
|
||||||
|
{
|
||||||
|
struct Message *message = &inst->message;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
DEBUG_LOG("Session event %d fd=%d state=%d", event, inst->sock_fd, (int)inst->state);
|
||||||
|
|
||||||
|
switch (inst->state) {
|
||||||
|
case KE_WAIT_CONNECT:
|
||||||
|
/* Check if connect() succeeded */
|
||||||
|
if (event != SCH_FILE_OUTPUT)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Get the socket error */
|
||||||
|
if (!SCK_GetIntOption(inst->sock_fd, SOL_SOCKET, SO_ERROR, &r))
|
||||||
|
r = EINVAL;
|
||||||
|
|
||||||
|
if (r != 0) {
|
||||||
|
LOG(LOGS_ERR, "Could not connect to %s : %s", inst->label, strerror(r));
|
||||||
|
stop_session(inst);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Connected to %s", inst->label);
|
||||||
|
|
||||||
|
change_state(inst, KE_HANDSHAKE);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case KE_HANDSHAKE:
|
||||||
|
r = gnutls_handshake(inst->tls_session);
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
if (gnutls_error_is_fatal(r)) {
|
||||||
|
gnutls_datum_t cert_error;
|
||||||
|
|
||||||
|
/* Get a description of verification errors */
|
||||||
|
if (r != GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR ||
|
||||||
|
gnutls_certificate_verification_status_print(
|
||||||
|
gnutls_session_get_verify_cert_status(inst->tls_session),
|
||||||
|
gnutls_certificate_type_get(inst->tls_session), &cert_error, 0) < 0)
|
||||||
|
cert_error.data = NULL;
|
||||||
|
|
||||||
|
LOG(inst->server ? LOGS_DEBUG : LOGS_ERR,
|
||||||
|
"TLS handshake with %s failed : %s%s%s", inst->label, gnutls_strerror(r),
|
||||||
|
cert_error.data ? " " : "", cert_error.data ? (const char *)cert_error.data : "");
|
||||||
|
|
||||||
|
if (cert_error.data)
|
||||||
|
gnutls_free(cert_error.data);
|
||||||
|
|
||||||
|
stop_session(inst);
|
||||||
|
|
||||||
|
/* Increase the retry interval if the handshake did not fail due
|
||||||
|
to the other end closing the connection */
|
||||||
|
if (r != GNUTLS_E_PULL_ERROR && r != GNUTLS_E_PREMATURE_TERMINATION)
|
||||||
|
inst->retry_factor = NKE_RETRY_FACTOR2_TLS;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable output when the handshake is trying to receive data */
|
||||||
|
set_input_output(inst, gnutls_record_get_direction(inst->tls_session));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->retry_factor = NKE_RETRY_FACTOR2_TLS;
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
char *description = gnutls_session_get_desc(inst->tls_session);
|
||||||
|
DEBUG_LOG("Handshake with %s completed %s",
|
||||||
|
inst->label, description ? description : "");
|
||||||
|
gnutls_free(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!check_alpn(inst)) {
|
||||||
|
LOG(inst->server ? LOGS_DEBUG : LOGS_ERR, "NTS-KE not supported by %s", inst->label);
|
||||||
|
stop_session(inst);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Client will send a request to the server */
|
||||||
|
change_state(inst, inst->server ? KE_RECEIVE : KE_SEND);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case KE_SEND:
|
||||||
|
assert(inst->new_message && message->complete);
|
||||||
|
assert(message->length <= sizeof (message->data) && message->length > message->sent);
|
||||||
|
|
||||||
|
r = gnutls_record_send(inst->tls_session, &message->data[message->sent],
|
||||||
|
message->length - message->sent);
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
if (gnutls_error_is_fatal(r)) {
|
||||||
|
LOG(inst->server ? LOGS_DEBUG : LOGS_ERR,
|
||||||
|
"Could not send NTS-KE message to %s : %s", inst->label, gnutls_strerror(r));
|
||||||
|
stop_session(inst);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Sent %d bytes to %s", r, inst->label);
|
||||||
|
|
||||||
|
message->sent += r;
|
||||||
|
if (message->sent < message->length)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Client will receive a response */
|
||||||
|
change_state(inst, inst->server ? KE_SHUTDOWN : KE_RECEIVE);
|
||||||
|
reset_message(&inst->message);
|
||||||
|
inst->new_message = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case KE_RECEIVE:
|
||||||
|
do {
|
||||||
|
if (message->length >= sizeof (message->data)) {
|
||||||
|
DEBUG_LOG("Message is too long");
|
||||||
|
stop_session(inst);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = gnutls_record_recv(inst->tls_session, &message->data[message->length],
|
||||||
|
sizeof (message->data) - message->length);
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
/* Handle a renegotiation request on both client and server as
|
||||||
|
a protocol error */
|
||||||
|
if (gnutls_error_is_fatal(r) || r == GNUTLS_E_REHANDSHAKE) {
|
||||||
|
LOG(inst->server ? LOGS_DEBUG : LOGS_ERR,
|
||||||
|
"Could not receive NTS-KE message from %s : %s",
|
||||||
|
inst->label, gnutls_strerror(r));
|
||||||
|
stop_session(inst);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Received %d bytes from %s", r, inst->label);
|
||||||
|
|
||||||
|
message->length += r;
|
||||||
|
|
||||||
|
} while (gnutls_record_check_pending(inst->tls_session) > 0);
|
||||||
|
|
||||||
|
if (!check_message_format(message, r == 0)) {
|
||||||
|
LOG(inst->server ? LOGS_DEBUG : LOGS_ERR,
|
||||||
|
"Received invalid NTS-KE message from %s", inst->label);
|
||||||
|
stop_session(inst);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for more data if the message is not complete yet */
|
||||||
|
if (!message->complete)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Server will send a response to the client */
|
||||||
|
change_state(inst, inst->server ? KE_SEND : KE_SHUTDOWN);
|
||||||
|
|
||||||
|
/* Return success to process the received message */
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
case KE_SHUTDOWN:
|
||||||
|
r = gnutls_bye(inst->tls_session, GNUTLS_SHUT_RDWR);
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
if (gnutls_error_is_fatal(r)) {
|
||||||
|
DEBUG_LOG("Shutdown with %s failed : %s", inst->label, gnutls_strerror(r));
|
||||||
|
stop_session(inst);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable output when the TLS shutdown is trying to receive data */
|
||||||
|
set_input_output(inst, gnutls_record_get_direction(inst->tls_session));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCK_ShutdownConnection(inst->sock_fd);
|
||||||
|
stop_session(inst);
|
||||||
|
|
||||||
|
DEBUG_LOG("Shutdown completed");
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
read_write_socket(int fd, int event, void *arg)
|
||||||
|
{
|
||||||
|
NKSN_Instance inst = arg;
|
||||||
|
|
||||||
|
if (!handle_event(inst, event))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* A valid message was received. Call the handler to process the message,
|
||||||
|
and prepare a response if it is a server. */
|
||||||
|
|
||||||
|
reset_message_parsing(&inst->message);
|
||||||
|
|
||||||
|
if (!(inst->handler)(inst->handler_arg)) {
|
||||||
|
stop_session(inst);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static time_t
|
||||||
|
get_time(time_t *t)
|
||||||
|
{
|
||||||
|
struct timespec now;
|
||||||
|
|
||||||
|
LCL_ReadCookedTime(&now, NULL);
|
||||||
|
if (t)
|
||||||
|
*t = now.tv_sec;
|
||||||
|
|
||||||
|
return now.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_step(struct timespec *raw, struct timespec *cooked, double dfreq,
|
||||||
|
double doffset, LCL_ChangeType change_type, void *anything)
|
||||||
|
{
|
||||||
|
if (change_type != LCL_ChangeUnknownStep && clock_updates < INT_MAX)
|
||||||
|
clock_updates++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int gnutls_initialised = 0;
|
||||||
|
|
||||||
|
static int
|
||||||
|
init_gnutls(void)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if (gnutls_initialised)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
r = gnutls_global_init();
|
||||||
|
if (r < 0)
|
||||||
|
LOG_FATAL("Could not initialise %s : %s", "gnutls", gnutls_strerror(r));
|
||||||
|
|
||||||
|
/* Prepare a priority cache for server and client NTS-KE sessions
|
||||||
|
(the NTS specification requires TLS1.3 or later) */
|
||||||
|
r = gnutls_priority_init2(&priority_cache,
|
||||||
|
"-VERS-SSL3.0:-VERS-TLS1.0:-VERS-TLS1.1:-VERS-TLS1.2:-VERS-DTLS-ALL",
|
||||||
|
NULL, GNUTLS_PRIORITY_INIT_DEF_APPEND);
|
||||||
|
if (r < 0) {
|
||||||
|
LOG(LOGS_ERR, "Could not initialise %s : %s",
|
||||||
|
"priority cache for TLS", gnutls_strerror(r));
|
||||||
|
gnutls_global_deinit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use our clock instead of the system clock in certificate verification */
|
||||||
|
gnutls_global_set_time_function(get_time);
|
||||||
|
|
||||||
|
gnutls_initialised = 1;
|
||||||
|
DEBUG_LOG("Initialised");
|
||||||
|
|
||||||
|
LCL_AddParameterChangeHandler(handle_step, NULL);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
deinit_gnutls(void)
|
||||||
|
{
|
||||||
|
if (!gnutls_initialised || credentials_counter > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
LCL_RemoveParameterChangeHandler(handle_step, NULL);
|
||||||
|
|
||||||
|
gnutls_priority_deinit(priority_cache);
|
||||||
|
gnutls_global_deinit();
|
||||||
|
gnutls_initialised = 0;
|
||||||
|
DEBUG_LOG("Deinitialised");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static NKSN_Credentials
|
||||||
|
create_credentials(const char **certs, const char **keys, int n_certs_keys,
|
||||||
|
const char **trusted_certs, uint32_t *trusted_certs_ids,
|
||||||
|
int n_trusted_certs, uint32_t trusted_cert_set)
|
||||||
|
{
|
||||||
|
gnutls_certificate_credentials_t credentials = NULL;
|
||||||
|
int i, r;
|
||||||
|
|
||||||
|
if (!init_gnutls())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
r = gnutls_certificate_allocate_credentials(&credentials);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (certs && keys) {
|
||||||
|
if (trusted_certs || trusted_certs_ids)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
for (i = 0; i < n_certs_keys; i++) {
|
||||||
|
r = gnutls_certificate_set_x509_key_file(credentials, certs[i], keys[i],
|
||||||
|
GNUTLS_X509_FMT_PEM);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (certs || keys || n_certs_keys > 0)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
if (trusted_cert_set == 0 && !CNF_GetNoSystemCert()) {
|
||||||
|
r = gnutls_certificate_set_x509_system_trust(credentials);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trusted_certs && trusted_certs_ids) {
|
||||||
|
for (i = 0; i < n_trusted_certs; i++) {
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
|
if (trusted_certs_ids[i] != trusted_cert_set)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (stat(trusted_certs[i], &buf) == 0 && S_ISDIR(buf.st_mode))
|
||||||
|
r = gnutls_certificate_set_x509_trust_dir(credentials, trusted_certs[i],
|
||||||
|
GNUTLS_X509_FMT_PEM);
|
||||||
|
else
|
||||||
|
r = gnutls_certificate_set_x509_trust_file(credentials, trusted_certs[i],
|
||||||
|
GNUTLS_X509_FMT_PEM);
|
||||||
|
if (r < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
DEBUG_LOG("Added %d trusted certs from %s", r, trusted_certs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
credentials_counter++;
|
||||||
|
|
||||||
|
return (NKSN_Credentials)credentials;
|
||||||
|
|
||||||
|
error:
|
||||||
|
LOG(LOGS_ERR, "Could not set credentials : %s", gnutls_strerror(r));
|
||||||
|
if (credentials)
|
||||||
|
gnutls_certificate_free_credentials(credentials);
|
||||||
|
deinit_gnutls();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NKSN_Credentials
|
||||||
|
NKSN_CreateServerCertCredentials(const char **certs, const char **keys, int n_certs_keys)
|
||||||
|
{
|
||||||
|
return create_credentials(certs, keys, n_certs_keys, NULL, NULL, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NKSN_Credentials
|
||||||
|
NKSN_CreateClientCertCredentials(const char **certs, uint32_t *ids,
|
||||||
|
int n_certs_ids, uint32_t trusted_cert_set)
|
||||||
|
{
|
||||||
|
return create_credentials(NULL, NULL, 0, certs, ids, n_certs_ids, trusted_cert_set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKSN_DestroyCertCredentials(NKSN_Credentials credentials)
|
||||||
|
{
|
||||||
|
gnutls_certificate_free_credentials((gnutls_certificate_credentials_t)credentials);
|
||||||
|
credentials_counter--;
|
||||||
|
deinit_gnutls();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NKSN_Instance
|
||||||
|
NKSN_CreateInstance(int server_mode, const char *server_name,
|
||||||
|
NKSN_MessageHandler handler, void *handler_arg)
|
||||||
|
{
|
||||||
|
NKSN_Instance inst;
|
||||||
|
|
||||||
|
inst = MallocNew(struct NKSN_Instance_Record);
|
||||||
|
|
||||||
|
inst->server = server_mode;
|
||||||
|
inst->server_name = server_name ? Strdup(server_name) : NULL;
|
||||||
|
inst->handler = handler;
|
||||||
|
inst->handler_arg = handler_arg;
|
||||||
|
/* Replace a NULL argument with the session itself */
|
||||||
|
if (!inst->handler_arg)
|
||||||
|
inst->handler_arg = inst;
|
||||||
|
|
||||||
|
inst->state = KE_STOPPED;
|
||||||
|
inst->sock_fd = INVALID_SOCK_FD;
|
||||||
|
inst->label = NULL;
|
||||||
|
inst->tls_session = NULL;
|
||||||
|
inst->timeout_id = 0;
|
||||||
|
inst->retry_factor = NKE_RETRY_FACTOR2_CONNECT;
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKSN_DestroyInstance(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
stop_session(inst);
|
||||||
|
|
||||||
|
Free(inst->server_name);
|
||||||
|
Free(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_StartSession(NKSN_Instance inst, int sock_fd, const char *label,
|
||||||
|
NKSN_Credentials credentials, double timeout)
|
||||||
|
{
|
||||||
|
assert(inst->state == KE_STOPPED);
|
||||||
|
|
||||||
|
inst->tls_session = create_tls_session(inst->server, sock_fd, inst->server_name,
|
||||||
|
(gnutls_certificate_credentials_t)credentials,
|
||||||
|
priority_cache);
|
||||||
|
if (!inst->tls_session)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inst->sock_fd = sock_fd;
|
||||||
|
SCH_AddFileHandler(sock_fd, SCH_FILE_INPUT, read_write_socket, inst);
|
||||||
|
|
||||||
|
inst->label = Strdup(label);
|
||||||
|
inst->timeout_id = SCH_AddTimeoutByDelay(timeout, session_timeout, inst);
|
||||||
|
inst->retry_factor = NKE_RETRY_FACTOR2_CONNECT;
|
||||||
|
|
||||||
|
reset_message(&inst->message);
|
||||||
|
inst->new_message = 0;
|
||||||
|
|
||||||
|
change_state(inst, inst->server ? KE_HANDSHAKE : KE_WAIT_CONNECT);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKSN_BeginMessage(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
reset_message(&inst->message);
|
||||||
|
inst->new_message = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_AddRecord(NKSN_Instance inst, int critical, int type, const void *body, int body_length)
|
||||||
|
{
|
||||||
|
assert(inst->new_message && !inst->message.complete);
|
||||||
|
assert(type != NKE_RECORD_END_OF_MESSAGE);
|
||||||
|
|
||||||
|
return add_record(&inst->message, critical, type, body, body_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_EndMessage(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
assert(!inst->message.complete);
|
||||||
|
|
||||||
|
/* Terminate the message */
|
||||||
|
if (!add_record(&inst->message, 1, NKE_RECORD_END_OF_MESSAGE, NULL, 0))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inst->message.complete = 1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_GetRecord(NKSN_Instance inst, int *critical, int *type, int *body_length,
|
||||||
|
void *body, int buffer_length)
|
||||||
|
{
|
||||||
|
int type2;
|
||||||
|
|
||||||
|
assert(inst->message.complete);
|
||||||
|
|
||||||
|
if (body_length)
|
||||||
|
*body_length = 0;
|
||||||
|
|
||||||
|
if (!get_record(&inst->message, critical, &type2, body_length, body, buffer_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Hide the end-of-message record */
|
||||||
|
if (type2 == NKE_RECORD_END_OF_MESSAGE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (type)
|
||||||
|
*type = type2;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_GetKeys(NKSN_Instance inst, SIV_Algorithm siv, NKE_Key *c2s, NKE_Key *s2c)
|
||||||
|
{
|
||||||
|
int length = SIV_GetKeyLength(siv);
|
||||||
|
|
||||||
|
if (length <= 0 || length > sizeof (c2s->key) || length > sizeof (s2c->key)) {
|
||||||
|
DEBUG_LOG("Invalid algorithm");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gnutls_prf_rfc5705(inst->tls_session,
|
||||||
|
sizeof (NKE_EXPORTER_LABEL) - 1, NKE_EXPORTER_LABEL,
|
||||||
|
sizeof (NKE_EXPORTER_CONTEXT_C2S) - 1, NKE_EXPORTER_CONTEXT_C2S,
|
||||||
|
length, (char *)c2s->key) < 0 ||
|
||||||
|
gnutls_prf_rfc5705(inst->tls_session,
|
||||||
|
sizeof (NKE_EXPORTER_LABEL) - 1, NKE_EXPORTER_LABEL,
|
||||||
|
sizeof (NKE_EXPORTER_CONTEXT_S2C) - 1, NKE_EXPORTER_CONTEXT_S2C,
|
||||||
|
length, (char *)s2c->key) < 0) {
|
||||||
|
DEBUG_LOG("Could not export key");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
c2s->length = length;
|
||||||
|
s2c->length = length;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_IsStopped(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
return inst->state == KE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NKSN_StopSession(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
stop_session(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NKSN_GetRetryFactor(NKSN_Instance inst)
|
||||||
|
{
|
||||||
|
return inst->retry_factor;
|
||||||
|
}
|
||||||
93
nts_ke_session.h
Normal file
93
nts_ke_session.h
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for the NTS-KE session
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_KE_SESSION_H
|
||||||
|
#define GOT_NTS_KE_SESSION_H
|
||||||
|
|
||||||
|
#include "nts_ke.h"
|
||||||
|
#include "siv.h"
|
||||||
|
|
||||||
|
typedef struct NKSN_Credentials_Record *NKSN_Credentials;
|
||||||
|
|
||||||
|
typedef struct NKSN_Instance_Record *NKSN_Instance;
|
||||||
|
|
||||||
|
/* Handler for received NTS-KE messages. A zero return code stops
|
||||||
|
the session. */
|
||||||
|
typedef int (*NKSN_MessageHandler)(void *arg);
|
||||||
|
|
||||||
|
/* Get server or client credentials using a server certificate and key,
|
||||||
|
or certificates of trusted CAs. The credentials may be shared between
|
||||||
|
different clients or servers. */
|
||||||
|
extern NKSN_Credentials NKSN_CreateServerCertCredentials(const char **certs, const char **keys,
|
||||||
|
int n_certs_keys);
|
||||||
|
extern NKSN_Credentials NKSN_CreateClientCertCredentials(const char **certs, uint32_t *ids,
|
||||||
|
int n_certs_ids,
|
||||||
|
uint32_t trusted_cert_set);
|
||||||
|
|
||||||
|
/* Destroy the credentials */
|
||||||
|
extern void NKSN_DestroyCertCredentials(NKSN_Credentials credentials);
|
||||||
|
|
||||||
|
/* Create an instance */
|
||||||
|
extern NKSN_Instance NKSN_CreateInstance(int server_mode, const char *server_name,
|
||||||
|
NKSN_MessageHandler handler, void *handler_arg);
|
||||||
|
|
||||||
|
/* Destroy an instance */
|
||||||
|
extern void NKSN_DestroyInstance(NKSN_Instance inst);
|
||||||
|
|
||||||
|
/* Start a new NTS-KE session */
|
||||||
|
extern int NKSN_StartSession(NKSN_Instance inst, int sock_fd, const char *label,
|
||||||
|
NKSN_Credentials credentials, double timeout);
|
||||||
|
|
||||||
|
/* Begin an NTS-KE message. A request should be made right after starting
|
||||||
|
the session and response should be made in the message handler. */
|
||||||
|
extern void NKSN_BeginMessage(NKSN_Instance inst);
|
||||||
|
|
||||||
|
/* Add a record to the message */
|
||||||
|
extern int NKSN_AddRecord(NKSN_Instance inst, int critical, int type,
|
||||||
|
const void *body, int body_length);
|
||||||
|
|
||||||
|
/* Terminate the message */
|
||||||
|
extern int NKSN_EndMessage(NKSN_Instance inst);
|
||||||
|
|
||||||
|
/* Get the next record from the received message. This function should be
|
||||||
|
called from the message handler. */
|
||||||
|
extern int NKSN_GetRecord(NKSN_Instance inst, int *critical, int *type, int *body_length,
|
||||||
|
void *body, int buffer_length);
|
||||||
|
|
||||||
|
/* Export NTS keys for a specified algorithm */
|
||||||
|
extern int NKSN_GetKeys(NKSN_Instance inst, SIV_Algorithm siv, NKE_Key *c2s, NKE_Key *s2c);
|
||||||
|
|
||||||
|
/* Check if the session has stopped */
|
||||||
|
extern int NKSN_IsStopped(NKSN_Instance inst);
|
||||||
|
|
||||||
|
/* Stop the session */
|
||||||
|
extern void NKSN_StopSession(NKSN_Instance inst);
|
||||||
|
|
||||||
|
/* Get a factor to calculate retry interval (in log2 seconds)
|
||||||
|
based on the session state or how it was terminated */
|
||||||
|
extern int NKSN_GetRetryFactor(NKSN_Instance inst);
|
||||||
|
|
||||||
|
#endif
|
||||||
36
nts_ntp.h
Normal file
36
nts_ntp.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for the NTS-NTP protocol
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_NTP_H
|
||||||
|
#define GOT_NTS_NTP_H
|
||||||
|
|
||||||
|
#define NTP_KOD_NTS_NAK 0x4e54534e
|
||||||
|
|
||||||
|
#define NTS_MIN_UNIQ_ID_LENGTH 32
|
||||||
|
#define NTS_MIN_UNPADDED_NONCE_LENGTH 16
|
||||||
|
#define NTS_MAX_COOKIES 8
|
||||||
|
|
||||||
|
#endif
|
||||||
183
nts_ntp_auth.c
Normal file
183
nts_ntp_auth.c
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
NTS Authenticator and Encrypted Extension Fields extension field
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "nts_ntp_auth.h"
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
#include "ntp_ext.h"
|
||||||
|
#include "nts_ntp.h"
|
||||||
|
#include "siv.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
struct AuthHeader {
|
||||||
|
uint16_t nonce_length;
|
||||||
|
uint16_t ciphertext_length;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_padding_length(int length)
|
||||||
|
{
|
||||||
|
return length % 4U ? 4 - length % 4U : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_padded_length(int length)
|
||||||
|
{
|
||||||
|
return length + get_padding_length(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNA_GenerateAuthEF(NTP_Packet *packet, NTP_PacketInfo *info, SIV_Instance siv,
|
||||||
|
const unsigned char *nonce, int nonce_length,
|
||||||
|
const unsigned char *plaintext, int plaintext_length,
|
||||||
|
int min_ef_length)
|
||||||
|
{
|
||||||
|
int auth_length, ciphertext_length, assoc_length;
|
||||||
|
int nonce_padding, ciphertext_padding, additional_padding;
|
||||||
|
unsigned char *ciphertext, *body;
|
||||||
|
struct AuthHeader *header;
|
||||||
|
|
||||||
|
assert(sizeof (*header) == 4);
|
||||||
|
|
||||||
|
if (nonce_length <= 0 || plaintext_length < 0) {
|
||||||
|
DEBUG_LOG("Invalid nonce/plaintext length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
assoc_length = info->length;
|
||||||
|
ciphertext_length = SIV_GetTagLength(siv) + plaintext_length;
|
||||||
|
nonce_padding = get_padding_length(nonce_length);
|
||||||
|
ciphertext_padding = get_padding_length(ciphertext_length);
|
||||||
|
min_ef_length = get_padded_length(min_ef_length);
|
||||||
|
|
||||||
|
auth_length = sizeof (*header) + nonce_length + nonce_padding +
|
||||||
|
ciphertext_length + ciphertext_padding;
|
||||||
|
additional_padding = MAX(min_ef_length - auth_length - 4, 0);
|
||||||
|
additional_padding = MAX(NTS_MIN_UNPADDED_NONCE_LENGTH - nonce_length - nonce_padding,
|
||||||
|
additional_padding);
|
||||||
|
auth_length += additional_padding;
|
||||||
|
|
||||||
|
if (!NEF_AddBlankField(packet, info, NTP_EF_NTS_AUTH_AND_EEF, auth_length,
|
||||||
|
(void **)&header)) {
|
||||||
|
DEBUG_LOG("Could not add EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header->nonce_length = htons(nonce_length);
|
||||||
|
header->ciphertext_length = htons(ciphertext_length);
|
||||||
|
|
||||||
|
body = (unsigned char *)(header + 1);
|
||||||
|
ciphertext = body + nonce_length + nonce_padding;
|
||||||
|
|
||||||
|
if ((unsigned char *)header + auth_length !=
|
||||||
|
ciphertext + ciphertext_length + ciphertext_padding + additional_padding)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
memcpy(body, nonce, nonce_length);
|
||||||
|
memset(body + nonce_length, 0, nonce_padding);
|
||||||
|
|
||||||
|
if (!SIV_Encrypt(siv, nonce, nonce_length, packet, assoc_length,
|
||||||
|
plaintext, plaintext_length, ciphertext, ciphertext_length)) {
|
||||||
|
DEBUG_LOG("SIV encrypt failed");
|
||||||
|
info->length = assoc_length;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(ciphertext + ciphertext_length, 0, ciphertext_padding + additional_padding);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNA_DecryptAuthEF(NTP_Packet *packet, NTP_PacketInfo *info, SIV_Instance siv, int ef_start,
|
||||||
|
unsigned char *plaintext, int buffer_length, int *plaintext_length)
|
||||||
|
{
|
||||||
|
unsigned int siv_tag_length, nonce_length, ciphertext_length;
|
||||||
|
unsigned char *nonce, *ciphertext;
|
||||||
|
int ef_type, ef_body_length;
|
||||||
|
void *ef_body;
|
||||||
|
struct AuthHeader *header;
|
||||||
|
|
||||||
|
if (buffer_length < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!NEF_ParseField(packet, info->length, ef_start,
|
||||||
|
NULL, &ef_type, &ef_body, &ef_body_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (ef_type != NTP_EF_NTS_AUTH_AND_EEF || ef_body_length < sizeof (*header))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
header = ef_body;
|
||||||
|
|
||||||
|
nonce_length = ntohs(header->nonce_length);
|
||||||
|
ciphertext_length = ntohs(header->ciphertext_length);
|
||||||
|
|
||||||
|
if (get_padded_length(nonce_length) +
|
||||||
|
get_padded_length(ciphertext_length) > ef_body_length)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
nonce = (unsigned char *)(header + 1);
|
||||||
|
ciphertext = nonce + get_padded_length(nonce_length);
|
||||||
|
|
||||||
|
siv_tag_length = SIV_GetTagLength(siv);
|
||||||
|
|
||||||
|
if (nonce_length < 1 ||
|
||||||
|
ciphertext_length < siv_tag_length ||
|
||||||
|
ciphertext_length - siv_tag_length > buffer_length) {
|
||||||
|
DEBUG_LOG("Unexpected nonce/ciphertext length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ef_body_length < sizeof (*header) +
|
||||||
|
NTS_MIN_UNPADDED_NONCE_LENGTH + get_padded_length(ciphertext_length)) {
|
||||||
|
DEBUG_LOG("Missing padding");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*plaintext_length = ciphertext_length - siv_tag_length;
|
||||||
|
assert(*plaintext_length >= 0);
|
||||||
|
|
||||||
|
if (!SIV_Decrypt(siv, nonce, nonce_length, packet, ef_start,
|
||||||
|
ciphertext, ciphertext_length, plaintext, *plaintext_length)) {
|
||||||
|
DEBUG_LOG("SIV decrypt failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
43
nts_ntp_auth.h
Normal file
43
nts_ntp_auth.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header for NTS Authenticator and Encrypted Extension Fields
|
||||||
|
extension field
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_NTP_AUTH_H
|
||||||
|
#define GOT_NTS_NTP_AUTH_H
|
||||||
|
|
||||||
|
#include "ntp.h"
|
||||||
|
#include "siv.h"
|
||||||
|
|
||||||
|
extern int NNA_GenerateAuthEF(NTP_Packet *packet, NTP_PacketInfo *info, SIV_Instance siv,
|
||||||
|
const unsigned char *nonce, int nonce_length,
|
||||||
|
const unsigned char *plaintext, int plaintext_length,
|
||||||
|
int min_ef_length);
|
||||||
|
|
||||||
|
extern int NNA_DecryptAuthEF(NTP_Packet *packet, NTP_PacketInfo *info, SIV_Instance siv,
|
||||||
|
int ef_start, unsigned char *plaintext, int buffer_length,
|
||||||
|
int *plaintext_length);
|
||||||
|
|
||||||
|
#endif
|
||||||
709
nts_ntp_client.c
Normal file
709
nts_ntp_client.c
Normal file
@@ -0,0 +1,709 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Client NTS-NTP authentication
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "nts_ntp_client.h"
|
||||||
|
|
||||||
|
#include "conf.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
#include "ntp_ext.h"
|
||||||
|
#include "ntp_sources.h"
|
||||||
|
#include "nts_ke_client.h"
|
||||||
|
#include "nts_ntp.h"
|
||||||
|
#include "nts_ntp_auth.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "siv.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
/* Maximum length of all cookies to avoid IP fragmentation */
|
||||||
|
#define MAX_TOTAL_COOKIE_LENGTH (8 * 108)
|
||||||
|
|
||||||
|
/* Magic string of files containing keys and cookies */
|
||||||
|
#define DUMP_IDENTIFIER "NNC0\n"
|
||||||
|
|
||||||
|
struct NNC_Instance_Record {
|
||||||
|
/* Address of NTS-KE server */
|
||||||
|
IPSockAddr nts_address;
|
||||||
|
/* Hostname or IP address for certificate verification */
|
||||||
|
char *name;
|
||||||
|
/* ID of trusted certificates */
|
||||||
|
uint32_t cert_set;
|
||||||
|
/* Configured NTP port */
|
||||||
|
uint16_t default_ntp_port;
|
||||||
|
/* Address of NTP server (can be negotiated in NTS-KE) */
|
||||||
|
IPSockAddr ntp_address;
|
||||||
|
|
||||||
|
NKC_Instance nke;
|
||||||
|
SIV_Instance siv;
|
||||||
|
|
||||||
|
int nke_attempts;
|
||||||
|
double next_nke_attempt;
|
||||||
|
double last_nke_success;
|
||||||
|
|
||||||
|
NKE_Context context;
|
||||||
|
unsigned int context_id;
|
||||||
|
NKE_Cookie cookies[NTS_MAX_COOKIES];
|
||||||
|
int num_cookies;
|
||||||
|
int cookie_index;
|
||||||
|
int auth_ready;
|
||||||
|
int nak_response;
|
||||||
|
int ok_response;
|
||||||
|
unsigned char nonce[NTS_MIN_UNPADDED_NONCE_LENGTH];
|
||||||
|
unsigned char uniq_id[NTS_MIN_UNIQ_ID_LENGTH];
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void save_cookies(NNC_Instance inst);
|
||||||
|
static void load_cookies(NNC_Instance inst);
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
reset_instance(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
if (inst->nke)
|
||||||
|
NKC_DestroyInstance(inst->nke);
|
||||||
|
inst->nke = NULL;
|
||||||
|
if (inst->siv)
|
||||||
|
SIV_DestroyInstance(inst->siv);
|
||||||
|
inst->siv = NULL;
|
||||||
|
|
||||||
|
inst->nke_attempts = 0;
|
||||||
|
inst->next_nke_attempt = 0.0;
|
||||||
|
inst->last_nke_success = 0.0;
|
||||||
|
|
||||||
|
memset(&inst->context, 0, sizeof (inst->context));
|
||||||
|
inst->context_id = 0;
|
||||||
|
memset(inst->cookies, 0, sizeof (inst->cookies));
|
||||||
|
inst->num_cookies = 0;
|
||||||
|
inst->cookie_index = 0;
|
||||||
|
inst->auth_ready = 0;
|
||||||
|
inst->nak_response = 0;
|
||||||
|
inst->ok_response = 1;
|
||||||
|
memset(inst->nonce, 0, sizeof (inst->nonce));
|
||||||
|
memset(inst->uniq_id, 0, sizeof (inst->uniq_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
NNC_Instance
|
||||||
|
NNC_CreateInstance(IPSockAddr *nts_address, const char *name, uint32_t cert_set, uint16_t ntp_port)
|
||||||
|
{
|
||||||
|
NNC_Instance inst;
|
||||||
|
|
||||||
|
inst = MallocNew(struct NNC_Instance_Record);
|
||||||
|
|
||||||
|
inst->nts_address = *nts_address;
|
||||||
|
inst->name = Strdup(name);
|
||||||
|
inst->cert_set = cert_set;
|
||||||
|
inst->default_ntp_port = ntp_port;
|
||||||
|
inst->ntp_address.ip_addr = nts_address->ip_addr;
|
||||||
|
inst->ntp_address.port = ntp_port;
|
||||||
|
inst->siv = NULL;
|
||||||
|
inst->nke = NULL;
|
||||||
|
|
||||||
|
reset_instance(inst);
|
||||||
|
|
||||||
|
/* Try to reload saved keys and cookies */
|
||||||
|
load_cookies(inst);
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NNC_DestroyInstance(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
save_cookies(inst);
|
||||||
|
|
||||||
|
reset_instance(inst);
|
||||||
|
|
||||||
|
Free(inst->name);
|
||||||
|
Free(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_cookies(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
/* Force a new NTS-KE session if a NAK was received without a valid response,
|
||||||
|
or the keys encrypting the cookies need to be refreshed */
|
||||||
|
if (inst->num_cookies > 0 &&
|
||||||
|
((inst->nak_response && !inst->ok_response) ||
|
||||||
|
SCH_GetLastEventMonoTime() - inst->last_nke_success > CNF_GetNtsRefresh())) {
|
||||||
|
inst->num_cookies = 0;
|
||||||
|
DEBUG_LOG("Dropped cookies");
|
||||||
|
}
|
||||||
|
|
||||||
|
return inst->num_cookies > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
set_ntp_address(NNC_Instance inst, NTP_Remote_Address *negotiated_address)
|
||||||
|
{
|
||||||
|
NTP_Remote_Address old_address, new_address;
|
||||||
|
|
||||||
|
old_address = inst->ntp_address;
|
||||||
|
new_address = *negotiated_address;
|
||||||
|
|
||||||
|
if (new_address.ip_addr.family == IPADDR_UNSPEC)
|
||||||
|
new_address.ip_addr = inst->nts_address.ip_addr;
|
||||||
|
if (new_address.port == 0)
|
||||||
|
new_address.port = inst->default_ntp_port;
|
||||||
|
|
||||||
|
if (UTI_CompareIPs(&old_address.ip_addr, &new_address.ip_addr, NULL) == 0 &&
|
||||||
|
old_address.port == new_address.port)
|
||||||
|
/* Nothing to do */
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (NSR_UpdateSourceNtpAddress(&old_address, &new_address) != NSR_Success) {
|
||||||
|
LOG(LOGS_ERR, "Could not change %s to negotiated address %s",
|
||||||
|
UTI_IPToString(&old_address.ip_addr), UTI_IPToString(&new_address.ip_addr));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->ntp_address = new_address;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_next_nke_attempt(NNC_Instance inst, double now)
|
||||||
|
{
|
||||||
|
int factor, interval;
|
||||||
|
|
||||||
|
if (!inst->nke)
|
||||||
|
return;
|
||||||
|
|
||||||
|
factor = NKC_GetRetryFactor(inst->nke);
|
||||||
|
interval = MIN(factor + inst->nke_attempts - 1, NKE_MAX_RETRY_INTERVAL2);
|
||||||
|
inst->next_nke_attempt = now + UTI_Log2ToDouble(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_cookies(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
NTP_Remote_Address ntp_address;
|
||||||
|
double now;
|
||||||
|
int got_data;
|
||||||
|
|
||||||
|
assert(inst->num_cookies == 0);
|
||||||
|
|
||||||
|
now = SCH_GetLastEventMonoTime();
|
||||||
|
|
||||||
|
/* Create and start a new NTS-KE session if not already present */
|
||||||
|
if (!inst->nke) {
|
||||||
|
if (now < inst->next_nke_attempt) {
|
||||||
|
DEBUG_LOG("Limiting NTS-KE request rate (%f seconds)",
|
||||||
|
inst->next_nke_attempt - now);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->nke = NKC_CreateInstance(&inst->nts_address, inst->name, inst->cert_set);
|
||||||
|
|
||||||
|
inst->nke_attempts++;
|
||||||
|
update_next_nke_attempt(inst, now);
|
||||||
|
|
||||||
|
if (!NKC_Start(inst->nke))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
update_next_nke_attempt(inst, now);
|
||||||
|
|
||||||
|
/* Wait until the session stops */
|
||||||
|
if (NKC_IsActive(inst->nke))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
assert(sizeof (inst->cookies) / sizeof (inst->cookies[0]) == NTS_MAX_COOKIES);
|
||||||
|
|
||||||
|
/* Get the new keys, cookies and NTP address if the session was successful */
|
||||||
|
got_data = NKC_GetNtsData(inst->nke, &inst->context,
|
||||||
|
inst->cookies, &inst->num_cookies, NTS_MAX_COOKIES,
|
||||||
|
&ntp_address);
|
||||||
|
|
||||||
|
NKC_DestroyInstance(inst->nke);
|
||||||
|
inst->nke = NULL;
|
||||||
|
|
||||||
|
if (!got_data)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (inst->siv)
|
||||||
|
SIV_DestroyInstance(inst->siv);
|
||||||
|
inst->siv = NULL;
|
||||||
|
|
||||||
|
inst->context_id++;
|
||||||
|
|
||||||
|
/* Force a new session if the NTP address is used by another source, with
|
||||||
|
an expectation that it will eventually get a non-conflicting address */
|
||||||
|
if (!set_ntp_address(inst, &ntp_address)) {
|
||||||
|
inst->num_cookies = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->last_nke_success = now;
|
||||||
|
inst->cookie_index = 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNC_PrepareForAuth(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
inst->auth_ready = 0;
|
||||||
|
|
||||||
|
/* Prepare data for the next request and invalidate any responses to the
|
||||||
|
previous request */
|
||||||
|
UTI_GetRandomBytes(inst->uniq_id, sizeof (inst->uniq_id));
|
||||||
|
UTI_GetRandomBytes(inst->nonce, sizeof (inst->nonce));
|
||||||
|
|
||||||
|
/* Get new cookies if there are not any, or they are no longer usable */
|
||||||
|
if (!check_cookies(inst)) {
|
||||||
|
if (!get_cookies(inst))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->nak_response = 0;
|
||||||
|
|
||||||
|
if (!inst->siv)
|
||||||
|
inst->siv = SIV_CreateInstance(inst->context.algorithm);
|
||||||
|
|
||||||
|
if (!inst->siv ||
|
||||||
|
!SIV_SetKey(inst->siv, inst->context.c2s.key, inst->context.c2s.length)) {
|
||||||
|
DEBUG_LOG("Could not set SIV key");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->auth_ready = 1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNC_GenerateRequestAuth(NNC_Instance inst, NTP_Packet *packet,
|
||||||
|
NTP_PacketInfo *info)
|
||||||
|
{
|
||||||
|
NKE_Cookie *cookie;
|
||||||
|
int i, req_cookies;
|
||||||
|
void *ef_body;
|
||||||
|
|
||||||
|
if (!inst->auth_ready)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inst->auth_ready = 0;
|
||||||
|
|
||||||
|
if (inst->num_cookies <= 0 || !inst->siv)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (info->mode != MODE_CLIENT)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
cookie = &inst->cookies[inst->cookie_index];
|
||||||
|
inst->num_cookies--;
|
||||||
|
inst->cookie_index = (inst->cookie_index + 1) % NTS_MAX_COOKIES;
|
||||||
|
|
||||||
|
req_cookies = MIN(NTS_MAX_COOKIES - inst->num_cookies,
|
||||||
|
MAX_TOTAL_COOKIE_LENGTH / (cookie->length + 4));
|
||||||
|
|
||||||
|
if (!NEF_AddField(packet, info, NTP_EF_NTS_UNIQUE_IDENTIFIER,
|
||||||
|
inst->uniq_id, sizeof (inst->uniq_id)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!NEF_AddField(packet, info, NTP_EF_NTS_COOKIE,
|
||||||
|
cookie->cookie, cookie->length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < req_cookies - 1; i++) {
|
||||||
|
if (!NEF_AddBlankField(packet, info, NTP_EF_NTS_COOKIE_PLACEHOLDER,
|
||||||
|
cookie->length, &ef_body))
|
||||||
|
return 0;
|
||||||
|
memset(ef_body, 0, cookie->length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NNA_GenerateAuthEF(packet, info, inst->siv, inst->nonce, sizeof (inst->nonce),
|
||||||
|
(const unsigned char *)"", 0, NTP_MAX_V4_MAC_LENGTH + 4))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inst->ok_response = 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
parse_encrypted_efs(NNC_Instance inst, unsigned char *plaintext, int length)
|
||||||
|
{
|
||||||
|
int ef_length, parsed;
|
||||||
|
|
||||||
|
for (parsed = 0; parsed < length; parsed += ef_length) {
|
||||||
|
if (!NEF_ParseSingleField(plaintext, length, parsed, &ef_length, NULL, NULL, NULL)) {
|
||||||
|
DEBUG_LOG("Could not parse encrypted EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
extract_cookies(NNC_Instance inst, unsigned char *plaintext, int length)
|
||||||
|
{
|
||||||
|
int ef_type, ef_body_length, ef_length, parsed, index, acceptable, saved;
|
||||||
|
void *ef_body;
|
||||||
|
|
||||||
|
acceptable = saved = 0;
|
||||||
|
|
||||||
|
for (parsed = 0; parsed < length; parsed += ef_length) {
|
||||||
|
if (!NEF_ParseSingleField(plaintext, length, parsed,
|
||||||
|
&ef_length, &ef_type, &ef_body, &ef_body_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (ef_type != NTP_EF_NTS_COOKIE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ef_length < NTP_MIN_EF_LENGTH || ef_body_length > sizeof (inst->cookies[0].cookie)) {
|
||||||
|
DEBUG_LOG("Unexpected cookie length %d", ef_body_length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
acceptable++;
|
||||||
|
|
||||||
|
if (inst->num_cookies >= NTS_MAX_COOKIES)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
index = (inst->cookie_index + inst->num_cookies) % NTS_MAX_COOKIES;
|
||||||
|
assert(index >= 0 && index < NTS_MAX_COOKIES);
|
||||||
|
assert(sizeof (inst->cookies) / sizeof (inst->cookies[0]) == NTS_MAX_COOKIES);
|
||||||
|
|
||||||
|
memcpy(inst->cookies[index].cookie, ef_body, ef_body_length);
|
||||||
|
inst->cookies[index].length = ef_body_length;
|
||||||
|
inst->num_cookies++;
|
||||||
|
|
||||||
|
saved++;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Extracted %d cookies (saved %d)", acceptable, saved);
|
||||||
|
|
||||||
|
return acceptable > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNC_CheckResponseAuth(NNC_Instance inst, NTP_Packet *packet,
|
||||||
|
NTP_PacketInfo *info)
|
||||||
|
{
|
||||||
|
int ef_type, ef_body_length, ef_length, parsed, plaintext_length;
|
||||||
|
int has_valid_uniq_id = 0, has_valid_auth = 0;
|
||||||
|
unsigned char plaintext[NTP_MAX_EXTENSIONS_LENGTH];
|
||||||
|
void *ef_body;
|
||||||
|
|
||||||
|
if (info->ext_fields == 0 || info->mode != MODE_SERVER)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Accept at most one response per request */
|
||||||
|
if (inst->ok_response || inst->auth_ready)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!inst->siv ||
|
||||||
|
!SIV_SetKey(inst->siv, inst->context.s2c.key, inst->context.s2c.length)) {
|
||||||
|
DEBUG_LOG("Could not set SIV key");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (parsed = NTP_HEADER_LENGTH; parsed < info->length; parsed += ef_length) {
|
||||||
|
if (!NEF_ParseField(packet, info->length, parsed,
|
||||||
|
&ef_length, &ef_type, &ef_body, &ef_body_length))
|
||||||
|
/* This is not expected as the packet already passed parsing */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (ef_type) {
|
||||||
|
case NTP_EF_NTS_UNIQUE_IDENTIFIER:
|
||||||
|
if (ef_body_length != sizeof (inst->uniq_id) ||
|
||||||
|
memcmp(ef_body, inst->uniq_id, sizeof (inst->uniq_id)) != 0) {
|
||||||
|
DEBUG_LOG("Invalid uniq id");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
has_valid_uniq_id = 1;
|
||||||
|
break;
|
||||||
|
case NTP_EF_NTS_COOKIE:
|
||||||
|
DEBUG_LOG("Unencrypted cookie");
|
||||||
|
break;
|
||||||
|
case NTP_EF_NTS_AUTH_AND_EEF:
|
||||||
|
if (parsed + ef_length != info->length) {
|
||||||
|
DEBUG_LOG("Auth not last EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NNA_DecryptAuthEF(packet, info, inst->siv, parsed,
|
||||||
|
plaintext, sizeof (plaintext), &plaintext_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!parse_encrypted_efs(inst, plaintext, plaintext_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
has_valid_auth = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has_valid_uniq_id || !has_valid_auth) {
|
||||||
|
if (has_valid_uniq_id && packet->stratum == NTP_INVALID_STRATUM &&
|
||||||
|
ntohl(packet->reference_id) == NTP_KOD_NTS_NAK) {
|
||||||
|
DEBUG_LOG("NTS NAK");
|
||||||
|
inst->nak_response = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG("Missing NTS EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!extract_cookies(inst, plaintext, plaintext_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inst->ok_response = 1;
|
||||||
|
|
||||||
|
/* At this point we know the client interoperates with the server. Allow a
|
||||||
|
new NTS-KE session to be started as soon as the cookies run out. */
|
||||||
|
inst->nke_attempts = 0;
|
||||||
|
inst->next_nke_attempt = 0.0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NNC_ChangeAddress(NNC_Instance inst, IPAddr *address)
|
||||||
|
{
|
||||||
|
save_cookies(inst);
|
||||||
|
|
||||||
|
inst->nts_address.ip_addr = *address;
|
||||||
|
inst->ntp_address.ip_addr = *address;
|
||||||
|
|
||||||
|
reset_instance(inst);
|
||||||
|
|
||||||
|
DEBUG_LOG("NTS reset");
|
||||||
|
|
||||||
|
load_cookies(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
save_cookies(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
char buf[2 * NKE_MAX_COOKIE_LENGTH + 2], *dump_dir, *filename;
|
||||||
|
struct timespec now;
|
||||||
|
double context_time;
|
||||||
|
FILE *f;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (inst->num_cookies < 1 || !UTI_IsIPReal(&inst->nts_address.ip_addr))
|
||||||
|
return;
|
||||||
|
|
||||||
|
dump_dir = CNF_GetNtsDumpDir();
|
||||||
|
if (!dump_dir)
|
||||||
|
return;
|
||||||
|
|
||||||
|
filename = UTI_IPToString(&inst->nts_address.ip_addr);
|
||||||
|
|
||||||
|
f = UTI_OpenFile(dump_dir, filename, ".tmp", 'w', 0600);
|
||||||
|
if (!f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SCH_GetLastEventTime(&now, NULL, NULL);
|
||||||
|
context_time = inst->last_nke_success - SCH_GetLastEventMonoTime();
|
||||||
|
context_time += UTI_TimespecToDouble(&now);
|
||||||
|
|
||||||
|
if (fprintf(f, "%s%s\n%.1f\n%s %d\n%u %d ",
|
||||||
|
DUMP_IDENTIFIER, inst->name, context_time,
|
||||||
|
UTI_IPToString(&inst->ntp_address.ip_addr), inst->ntp_address.port,
|
||||||
|
inst->context_id, (int)inst->context.algorithm) < 0 ||
|
||||||
|
!UTI_BytesToHex(inst->context.s2c.key, inst->context.s2c.length, buf, sizeof (buf)) ||
|
||||||
|
fprintf(f, "%s ", buf) < 0 ||
|
||||||
|
!UTI_BytesToHex(inst->context.c2s.key, inst->context.c2s.length, buf, sizeof (buf)) ||
|
||||||
|
fprintf(f, "%s\n", buf) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
for (i = 0; i < inst->num_cookies; i++) {
|
||||||
|
if (!UTI_BytesToHex(inst->cookies[i].cookie, inst->cookies[i].length, buf, sizeof (buf)) ||
|
||||||
|
fprintf(f, "%s\n", buf) < 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (!UTI_RenameTempFile(dump_dir, filename, ".tmp", ".nts"))
|
||||||
|
;
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
DEBUG_LOG("Could not %s cookies for %s", "save", filename);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
if (!UTI_RemoveFile(dump_dir, filename, ".nts"))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
#define MAX_WORDS 4
|
||||||
|
|
||||||
|
static void
|
||||||
|
load_cookies(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
char line[2 * NKE_MAX_COOKIE_LENGTH + 2], *dump_dir, *filename, *words[MAX_WORDS];
|
||||||
|
unsigned int context_id;
|
||||||
|
int i, algorithm, port;
|
||||||
|
double context_time;
|
||||||
|
struct timespec now;
|
||||||
|
IPSockAddr ntp_addr;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
dump_dir = CNF_GetNtsDumpDir();
|
||||||
|
if (!dump_dir)
|
||||||
|
return;
|
||||||
|
|
||||||
|
filename = UTI_IPToString(&inst->nts_address.ip_addr);
|
||||||
|
|
||||||
|
f = UTI_OpenFile(dump_dir, filename, ".nts", 'r', 0);
|
||||||
|
if (!f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Don't load this file again */
|
||||||
|
if (!UTI_RemoveFile(dump_dir, filename, ".nts"))
|
||||||
|
;
|
||||||
|
|
||||||
|
if (inst->siv)
|
||||||
|
SIV_DestroyInstance(inst->siv);
|
||||||
|
inst->siv = NULL;
|
||||||
|
|
||||||
|
if (!fgets(line, sizeof (line), f) || strcmp(line, DUMP_IDENTIFIER) != 0 ||
|
||||||
|
!fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 1 ||
|
||||||
|
strcmp(words[0], inst->name) != 0 ||
|
||||||
|
!fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 1 ||
|
||||||
|
sscanf(words[0], "%lf", &context_time) != 1 ||
|
||||||
|
!fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 2 ||
|
||||||
|
!UTI_StringToIP(words[0], &ntp_addr.ip_addr) || sscanf(words[1], "%d", &port) != 1 ||
|
||||||
|
!fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 4 ||
|
||||||
|
sscanf(words[0], "%u", &context_id) != 1 || sscanf(words[1], "%d", &algorithm) != 1)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
inst->context.algorithm = algorithm;
|
||||||
|
inst->context.s2c.length = UTI_HexToBytes(words[2], inst->context.s2c.key,
|
||||||
|
sizeof (inst->context.s2c.key));
|
||||||
|
inst->context.c2s.length = UTI_HexToBytes(words[3], inst->context.c2s.key,
|
||||||
|
sizeof (inst->context.c2s.key));
|
||||||
|
|
||||||
|
if (inst->context.s2c.length != SIV_GetKeyLength(algorithm) ||
|
||||||
|
inst->context.c2s.length != inst->context.s2c.length)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
for (i = 0; i < NTS_MAX_COOKIES && fgets(line, sizeof (line), f); i++) {
|
||||||
|
if (UTI_SplitString(line, words, MAX_WORDS) != 1)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
inst->cookies[i].length = UTI_HexToBytes(words[0], inst->cookies[i].cookie,
|
||||||
|
sizeof (inst->cookies[i].cookie));
|
||||||
|
if (inst->cookies[i].length == 0)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
inst->num_cookies = i;
|
||||||
|
|
||||||
|
ntp_addr.port = port;
|
||||||
|
if (!set_ntp_address(inst, &ntp_addr))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
SCH_GetLastEventTime(&now, NULL, NULL);
|
||||||
|
context_time -= UTI_TimespecToDouble(&now);
|
||||||
|
if (context_time > 0)
|
||||||
|
context_time = 0;
|
||||||
|
inst->last_nke_success = context_time + SCH_GetLastEventMonoTime();
|
||||||
|
inst->context_id = context_id;
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
DEBUG_LOG("Loaded %d cookies for %s", i, filename);
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
DEBUG_LOG("Could not %s cookies for %s", "load", filename);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
memset(&inst->context, 0, sizeof (inst->context));
|
||||||
|
inst->num_cookies = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NNC_DumpData(NNC_Instance inst)
|
||||||
|
{
|
||||||
|
save_cookies(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NNC_GetReport(NNC_Instance inst, RPT_AuthReport *report)
|
||||||
|
{
|
||||||
|
report->key_id = inst->context_id;
|
||||||
|
report->key_type = inst->context.algorithm;
|
||||||
|
report->key_length = 8 * inst->context.s2c.length;
|
||||||
|
report->ke_attempts = inst->nke_attempts;
|
||||||
|
if (report->key_length > 0)
|
||||||
|
report->last_ke_ago = SCH_GetLastEventMonoTime() - inst->last_nke_success;
|
||||||
|
else
|
||||||
|
report->last_ke_ago = -1;
|
||||||
|
report->cookies = inst->num_cookies;
|
||||||
|
report->cookie_length = inst->num_cookies > 0 ? inst->cookies[inst->cookie_index].length : 0;
|
||||||
|
report->nak = inst->nak_response;
|
||||||
|
}
|
||||||
51
nts_ntp_client.h
Normal file
51
nts_ntp_client.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for client NTS-NTP authentication
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_NTP_CLIENT_H
|
||||||
|
#define GOT_NTS_NTP_CLIENT_H
|
||||||
|
|
||||||
|
#include "addressing.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
#include "reports.h"
|
||||||
|
|
||||||
|
typedef struct NNC_Instance_Record *NNC_Instance;
|
||||||
|
|
||||||
|
extern NNC_Instance NNC_CreateInstance(IPSockAddr *nts_address, const char *name,
|
||||||
|
uint32_t cert_set, uint16_t ntp_port);
|
||||||
|
extern void NNC_DestroyInstance(NNC_Instance inst);
|
||||||
|
extern int NNC_PrepareForAuth(NNC_Instance inst);
|
||||||
|
extern int NNC_GenerateRequestAuth(NNC_Instance inst, NTP_Packet *packet,
|
||||||
|
NTP_PacketInfo *info);
|
||||||
|
extern int NNC_CheckResponseAuth(NNC_Instance inst, NTP_Packet *packet,
|
||||||
|
NTP_PacketInfo *info);
|
||||||
|
|
||||||
|
extern void NNC_ChangeAddress(NNC_Instance inst, IPAddr *address);
|
||||||
|
|
||||||
|
extern void NNC_DumpData(NNC_Instance inst);
|
||||||
|
|
||||||
|
extern void NNC_GetReport(NNC_Instance inst, RPT_AuthReport *report);
|
||||||
|
|
||||||
|
#endif
|
||||||
283
nts_ntp_server.c
Normal file
283
nts_ntp_server.c
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Server NTS-NTP authentication
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "nts_ntp_server.h"
|
||||||
|
|
||||||
|
#include "conf.h"
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
#include "ntp_ext.h"
|
||||||
|
#include "nts_ke_server.h"
|
||||||
|
#include "nts_ntp.h"
|
||||||
|
#include "nts_ntp_auth.h"
|
||||||
|
#include "siv.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#define SERVER_SIV AEAD_AES_SIV_CMAC_256
|
||||||
|
|
||||||
|
struct NtsServer {
|
||||||
|
SIV_Instance siv;
|
||||||
|
unsigned char nonce[NTS_MIN_UNPADDED_NONCE_LENGTH];
|
||||||
|
NKE_Cookie cookies[NTS_MAX_COOKIES];
|
||||||
|
int num_cookies;
|
||||||
|
NTP_int64 req_tx;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The server instance handling all requests */
|
||||||
|
struct NtsServer *server;
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NNS_Initialise(void)
|
||||||
|
{
|
||||||
|
const char **certs, **keys;
|
||||||
|
|
||||||
|
/* Create an NTS-NTP server instance only if NTS-KE server is enabled */
|
||||||
|
if (CNF_GetNtsServerCertAndKeyFiles(&certs, &keys) <= 0) {
|
||||||
|
server = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
server = Malloc(sizeof (struct NtsServer));
|
||||||
|
server->siv = SIV_CreateInstance(SERVER_SIV);
|
||||||
|
if (!server->siv)
|
||||||
|
LOG_FATAL("Could not initialise SIV cipher");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NNS_Finalise(void)
|
||||||
|
{
|
||||||
|
if (!server)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SIV_DestroyInstance(server->siv);
|
||||||
|
Free(server);
|
||||||
|
server = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNS_CheckRequestAuth(NTP_Packet *packet, NTP_PacketInfo *info, uint32_t *kod)
|
||||||
|
{
|
||||||
|
int ef_type, ef_body_length, ef_length, has_uniq_id = 0, has_auth = 0, has_cookie = 0;
|
||||||
|
int i, plaintext_length, parsed, requested_cookies, cookie_length = -1, auth_start = 0;
|
||||||
|
unsigned char plaintext[NTP_MAX_EXTENSIONS_LENGTH];
|
||||||
|
NKE_Context context;
|
||||||
|
NKE_Cookie cookie;
|
||||||
|
void *ef_body;
|
||||||
|
|
||||||
|
*kod = 0;
|
||||||
|
|
||||||
|
if (!server)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
server->num_cookies = 0;
|
||||||
|
server->req_tx = packet->transmit_ts;
|
||||||
|
|
||||||
|
if (info->ext_fields == 0 || info->mode != MODE_CLIENT)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
requested_cookies = 0;
|
||||||
|
|
||||||
|
for (parsed = NTP_HEADER_LENGTH; parsed < info->length; parsed += ef_length) {
|
||||||
|
if (!NEF_ParseField(packet, info->length, parsed,
|
||||||
|
&ef_length, &ef_type, &ef_body, &ef_body_length))
|
||||||
|
/* This is not expected as the packet already passed NAU_ParsePacket() */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (ef_type) {
|
||||||
|
case NTP_EF_NTS_UNIQUE_IDENTIFIER:
|
||||||
|
has_uniq_id = 1;
|
||||||
|
break;
|
||||||
|
case NTP_EF_NTS_COOKIE:
|
||||||
|
if (has_cookie || ef_body_length > sizeof (cookie.cookie)) {
|
||||||
|
DEBUG_LOG("Unexpected cookie/length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cookie.length = ef_body_length;
|
||||||
|
memcpy(cookie.cookie, ef_body, ef_body_length);
|
||||||
|
has_cookie = 1;
|
||||||
|
/* Fall through */
|
||||||
|
case NTP_EF_NTS_COOKIE_PLACEHOLDER:
|
||||||
|
requested_cookies++;
|
||||||
|
|
||||||
|
if (cookie_length >= 0 && cookie_length != ef_body_length) {
|
||||||
|
DEBUG_LOG("Invalid cookie/placeholder length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cookie_length = ef_body_length;
|
||||||
|
break;
|
||||||
|
case NTP_EF_NTS_AUTH_AND_EEF:
|
||||||
|
if (parsed + ef_length != info->length) {
|
||||||
|
DEBUG_LOG("Auth not last EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auth_start = parsed;
|
||||||
|
has_auth = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has_uniq_id || !has_cookie || !has_auth) {
|
||||||
|
DEBUG_LOG("Missing an NTS EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NKS_DecodeCookie(&cookie, &context)) {
|
||||||
|
*kod = NTP_KOD_NTS_NAK;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.algorithm != SERVER_SIV) {
|
||||||
|
DEBUG_LOG("Unexpected SIV");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SIV_SetKey(server->siv, context.c2s.key, context.c2s.length)) {
|
||||||
|
DEBUG_LOG("Could not set C2S key");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NNA_DecryptAuthEF(packet, info, server->siv, auth_start,
|
||||||
|
plaintext, sizeof (plaintext), &plaintext_length)) {
|
||||||
|
*kod = NTP_KOD_NTS_NAK;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (parsed = 0; parsed < plaintext_length; parsed += ef_length) {
|
||||||
|
if (!NEF_ParseSingleField(plaintext, plaintext_length, parsed,
|
||||||
|
&ef_length, &ef_type, &ef_body, &ef_body_length)) {
|
||||||
|
DEBUG_LOG("Could not parse encrypted EF");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (ef_type) {
|
||||||
|
case NTP_EF_NTS_COOKIE_PLACEHOLDER:
|
||||||
|
if (cookie_length != ef_body_length) {
|
||||||
|
DEBUG_LOG("Invalid cookie/placeholder length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
requested_cookies++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SIV_SetKey(server->siv, context.s2c.key, context.s2c.length)) {
|
||||||
|
DEBUG_LOG("Could not set S2C key");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare data for NNS_GenerateResponseAuth() to minimise the time spent
|
||||||
|
there (when the TX timestamp is already set) */
|
||||||
|
|
||||||
|
UTI_GetRandomBytes(server->nonce, sizeof (server->nonce));
|
||||||
|
|
||||||
|
assert(sizeof (server->cookies) / sizeof (server->cookies[0]) == NTS_MAX_COOKIES);
|
||||||
|
for (i = 0; i < NTS_MAX_COOKIES && i < requested_cookies; i++)
|
||||||
|
if (!NKS_GenerateCookie(&context, &server->cookies[i]))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
server->num_cookies = i;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
NNS_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *req_info,
|
||||||
|
NTP_Packet *response, NTP_PacketInfo *res_info,
|
||||||
|
uint32_t kod)
|
||||||
|
{
|
||||||
|
int i, ef_type, ef_body_length, ef_length, parsed;
|
||||||
|
void *ef_body;
|
||||||
|
unsigned char plaintext[NTP_MAX_EXTENSIONS_LENGTH];
|
||||||
|
int plaintext_length;
|
||||||
|
|
||||||
|
if (!server || req_info->mode != MODE_CLIENT || res_info->mode != MODE_SERVER)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Make sure this is a response to the request from the last call
|
||||||
|
of NNS_CheckRequestAuth() */
|
||||||
|
if (UTI_CompareNtp64(&server->req_tx, &request->transmit_ts) != 0)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
for (parsed = NTP_HEADER_LENGTH; parsed < req_info->length; parsed += ef_length) {
|
||||||
|
if (!NEF_ParseField(request, req_info->length, parsed,
|
||||||
|
&ef_length, &ef_type, &ef_body, &ef_body_length))
|
||||||
|
/* This is not expected as the packet already passed parsing */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (ef_type) {
|
||||||
|
case NTP_EF_NTS_UNIQUE_IDENTIFIER:
|
||||||
|
/* Copy the ID from the request */
|
||||||
|
if (!NEF_AddField(response, res_info, ef_type, ef_body, ef_body_length))
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* NTS NAK response does not have any other fields */
|
||||||
|
if (kod)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
for (i = 0, plaintext_length = 0; i < server->num_cookies; i++) {
|
||||||
|
if (!NEF_SetField(plaintext, sizeof (plaintext), plaintext_length,
|
||||||
|
NTP_EF_NTS_COOKIE, server->cookies[i].cookie,
|
||||||
|
server->cookies[i].length, &ef_length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
plaintext_length += ef_length;
|
||||||
|
assert(plaintext_length <= sizeof (plaintext));
|
||||||
|
}
|
||||||
|
|
||||||
|
server->num_cookies = 0;
|
||||||
|
|
||||||
|
/* Generate an authenticator field which will make the length
|
||||||
|
of the response equal to the length of the request */
|
||||||
|
if (!NNA_GenerateAuthEF(response, res_info, server->siv,
|
||||||
|
server->nonce, sizeof (server->nonce),
|
||||||
|
plaintext, plaintext_length,
|
||||||
|
req_info->length - res_info->length))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
40
nts_ntp_server.h
Normal file
40
nts_ntp_server.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2020
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for server NTS-NTP authentication
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_NTS_NTP_SERVER_H
|
||||||
|
#define GOT_NTS_NTP_SERVER_H
|
||||||
|
|
||||||
|
#include "ntp.h"
|
||||||
|
|
||||||
|
extern void NNS_Initialise(void);
|
||||||
|
extern void NNS_Finalise(void);
|
||||||
|
|
||||||
|
extern int NNS_CheckRequestAuth(NTP_Packet *packet, NTP_PacketInfo *info, uint32_t *kod);
|
||||||
|
extern int NNS_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *req_info,
|
||||||
|
NTP_Packet *response, NTP_PacketInfo *res_info,
|
||||||
|
uint32_t kod);
|
||||||
|
|
||||||
|
#endif
|
||||||
58
pktlength.c
58
pktlength.c
@@ -82,12 +82,12 @@ static const struct request_length request_lengths[] = {
|
|||||||
REQ_LENGTH_ENTRY(allow_deny, null), /* CMDDENYALL */
|
REQ_LENGTH_ENTRY(allow_deny, null), /* CMDDENYALL */
|
||||||
REQ_LENGTH_ENTRY(ac_check, null), /* ACCHECK */
|
REQ_LENGTH_ENTRY(ac_check, null), /* ACCHECK */
|
||||||
REQ_LENGTH_ENTRY(ac_check, null), /* CMDACCHECK */
|
REQ_LENGTH_ENTRY(ac_check, null), /* CMDACCHECK */
|
||||||
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SERVER */
|
{ 0, 0 }, /* ADD_SERVER */
|
||||||
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_PEER */
|
{ 0, 0 }, /* ADD_PEER */
|
||||||
REQ_LENGTH_ENTRY(del_source, null), /* DEL_SOURCE */
|
REQ_LENGTH_ENTRY(del_source, null), /* DEL_SOURCE */
|
||||||
REQ_LENGTH_ENTRY(null, null), /* WRITERTC */
|
REQ_LENGTH_ENTRY(null, null), /* WRITERTC */
|
||||||
REQ_LENGTH_ENTRY(dfreq, null), /* DFREQ */
|
REQ_LENGTH_ENTRY(dfreq, null), /* DFREQ */
|
||||||
REQ_LENGTH_ENTRY(doffset, null), /* DOFFSET */
|
{ 0, 0 }, /* DOFFSET - not supported */
|
||||||
REQ_LENGTH_ENTRY(null, tracking), /* TRACKING */
|
REQ_LENGTH_ENTRY(null, tracking), /* TRACKING */
|
||||||
REQ_LENGTH_ENTRY(sourcestats, sourcestats), /* SOURCESTATS */
|
REQ_LENGTH_ENTRY(sourcestats, sourcestats), /* SOURCESTATS */
|
||||||
REQ_LENGTH_ENTRY(null, rtc), /* RTCREPORT */
|
REQ_LENGTH_ENTRY(null, rtc), /* RTCREPORT */
|
||||||
@@ -110,9 +110,25 @@ static const struct request_length request_lengths[] = {
|
|||||||
REQ_LENGTH_ENTRY(smoothtime, null), /* SMOOTHTIME */
|
REQ_LENGTH_ENTRY(smoothtime, null), /* SMOOTHTIME */
|
||||||
REQ_LENGTH_ENTRY(null, null), /* REFRESH */
|
REQ_LENGTH_ENTRY(null, null), /* REFRESH */
|
||||||
REQ_LENGTH_ENTRY(null, server_stats), /* SERVER_STATS */
|
REQ_LENGTH_ENTRY(null, server_stats), /* SERVER_STATS */
|
||||||
REQ_LENGTH_ENTRY(client_accesses_by_index,
|
{ 0, 0 }, /* CLIENT_ACCESSES_BY_INDEX2 - not supported */
|
||||||
client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */
|
|
||||||
REQ_LENGTH_ENTRY(local, null), /* LOCAL2 */
|
REQ_LENGTH_ENTRY(local, null), /* LOCAL2 */
|
||||||
|
REQ_LENGTH_ENTRY(ntp_data, ntp_data), /* NTP_DATA */
|
||||||
|
{ 0, 0 }, /* ADD_SERVER2 */
|
||||||
|
{ 0, 0 }, /* ADD_PEER2 */
|
||||||
|
{ 0, 0 }, /* ADD_SERVER3 */
|
||||||
|
{ 0, 0 }, /* ADD_PEER3 */
|
||||||
|
REQ_LENGTH_ENTRY(null, null), /* SHUTDOWN */
|
||||||
|
REQ_LENGTH_ENTRY(null, null), /* ONOFFLINE */
|
||||||
|
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SOURCE */
|
||||||
|
REQ_LENGTH_ENTRY(ntp_source_name,
|
||||||
|
ntp_source_name), /* NTP_SOURCE_NAME */
|
||||||
|
REQ_LENGTH_ENTRY(null, null), /* RESET_SOURCES */
|
||||||
|
REQ_LENGTH_ENTRY(auth_data, auth_data), /* AUTH_DATA */
|
||||||
|
REQ_LENGTH_ENTRY(client_accesses_by_index,
|
||||||
|
client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX3 */
|
||||||
|
REQ_LENGTH_ENTRY(select_data, select_data), /* SELECT_DATA */
|
||||||
|
REQ_LENGTH_ENTRY(null, null), /* RELOAD_SOURCES */
|
||||||
|
REQ_LENGTH_ENTRY(doffset, null), /* DOFFSET2 */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t reply_lengths[] = {
|
static const uint16_t reply_lengths[] = {
|
||||||
@@ -120,18 +136,27 @@ static const uint16_t reply_lengths[] = {
|
|||||||
RPY_LENGTH_ENTRY(null), /* NULL */
|
RPY_LENGTH_ENTRY(null), /* NULL */
|
||||||
RPY_LENGTH_ENTRY(n_sources), /* N_SOURCES */
|
RPY_LENGTH_ENTRY(n_sources), /* N_SOURCES */
|
||||||
RPY_LENGTH_ENTRY(source_data), /* SOURCE_DATA */
|
RPY_LENGTH_ENTRY(source_data), /* SOURCE_DATA */
|
||||||
RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP */
|
0, /* MANUAL_TIMESTAMP */
|
||||||
RPY_LENGTH_ENTRY(tracking), /* TRACKING */
|
RPY_LENGTH_ENTRY(tracking), /* TRACKING */
|
||||||
RPY_LENGTH_ENTRY(sourcestats), /* SOURCESTATS */
|
RPY_LENGTH_ENTRY(sourcestats), /* SOURCESTATS */
|
||||||
RPY_LENGTH_ENTRY(rtc), /* RTC */
|
RPY_LENGTH_ENTRY(rtc), /* RTC */
|
||||||
0, /* SUBNETS_ACCESSED - not supported */
|
0, /* SUBNETS_ACCESSED - not supported */
|
||||||
0, /* CLIENT_ACCESSES - not supported */
|
0, /* CLIENT_ACCESSES - not supported */
|
||||||
0, /* CLIENT_ACCESSES_BY_INDEX - not supported */
|
0, /* CLIENT_ACCESSES_BY_INDEX - not supported */
|
||||||
0, /* MANUAL_LIST - variable length */
|
0, /* MANUAL_LIST - not supported */
|
||||||
RPY_LENGTH_ENTRY(activity), /* ACTIVITY */
|
RPY_LENGTH_ENTRY(activity), /* ACTIVITY */
|
||||||
RPY_LENGTH_ENTRY(smoothing), /* SMOOTHING */
|
RPY_LENGTH_ENTRY(smoothing), /* SMOOTHING */
|
||||||
RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS */
|
0, /* SERVER_STATS - not supported */
|
||||||
RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */
|
0, /* CLIENT_ACCESSES_BY_INDEX2 - not supported */
|
||||||
|
RPY_LENGTH_ENTRY(ntp_data), /* NTP_DATA */
|
||||||
|
RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP2 */
|
||||||
|
RPY_LENGTH_ENTRY(manual_list), /* MANUAL_LIST2 */
|
||||||
|
RPY_LENGTH_ENTRY(ntp_source_name), /* NTP_SOURCE_NAME */
|
||||||
|
RPY_LENGTH_ENTRY(auth_data), /* AUTH_DATA */
|
||||||
|
RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX3 */
|
||||||
|
0, /* SERVER_STATS2 - not supported */
|
||||||
|
RPY_LENGTH_ENTRY(select_data), /* SELECT_DATA */
|
||||||
|
RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS3 */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -188,21 +213,6 @@ PKL_ReplyLength(CMD_Reply *r)
|
|||||||
if (type < 1 || type >= N_REPLY_TYPES)
|
if (type < 1 || type >= N_REPLY_TYPES)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Length of MANUAL_LIST depends on number of samples stored in it */
|
|
||||||
if (type == RPY_MANUAL_LIST) {
|
|
||||||
uint32_t ns;
|
|
||||||
|
|
||||||
if (r->status != htons(STT_SUCCESS))
|
|
||||||
return offsetof(CMD_Reply, data);
|
|
||||||
|
|
||||||
ns = ntohl(r->data.manual_list.n_samples);
|
|
||||||
if (ns > MAX_MANUAL_LIST_SAMPLES)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return offsetof(CMD_Reply, data.manual_list.samples) +
|
|
||||||
ns * sizeof (RPY_ManualListSample);
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply_lengths[type];
|
return reply_lengths[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
199
privops.c
199
privops.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Bryan Christianson 2015
|
* Copyright (C) Bryan Christianson 2015
|
||||||
* Copyright (C) Miroslav Lichvar 2016
|
* Copyright (C) Miroslav Lichvar 2017
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "nameserv.h"
|
#include "nameserv.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "privops.h"
|
#include "privops.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define OP_ADJUSTTIME 1024
|
#define OP_ADJUSTTIME 1024
|
||||||
@@ -40,6 +41,7 @@
|
|||||||
#define OP_SETTIME 1026
|
#define OP_SETTIME 1026
|
||||||
#define OP_BINDSOCKET 1027
|
#define OP_BINDSOCKET 1027
|
||||||
#define OP_NAME2IPADDRESS 1028
|
#define OP_NAME2IPADDRESS 1028
|
||||||
|
#define OP_RELOADDNS 1029
|
||||||
#define OP_QUIT 1099
|
#define OP_QUIT 1099
|
||||||
|
|
||||||
union sockaddr_in46 {
|
union sockaddr_in46 {
|
||||||
@@ -157,7 +159,7 @@ res_fatal(PrvResponse *res, const char *fmt, ...)
|
|||||||
static int
|
static int
|
||||||
send_response(int fd, const PrvResponse *res)
|
send_response(int fd, const PrvResponse *res)
|
||||||
{
|
{
|
||||||
if (send(fd, res, sizeof (*res), 0) != sizeof (*res))
|
if (SCK_Send(fd, res, sizeof (*res), 0) != sizeof (*res))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -169,37 +171,23 @@ send_response(int fd, const PrvResponse *res)
|
|||||||
static int
|
static int
|
||||||
receive_from_daemon(int fd, PrvRequest *req)
|
receive_from_daemon(int fd, PrvRequest *req)
|
||||||
{
|
{
|
||||||
struct msghdr msg;
|
SCK_Message *message;
|
||||||
struct cmsghdr *cmsg;
|
|
||||||
struct iovec iov;
|
|
||||||
char cmsgbuf[256];
|
|
||||||
|
|
||||||
iov.iov_base = req;
|
message = SCK_ReceiveMessage(fd, SCK_FLAG_MSG_DESCRIPTOR);
|
||||||
iov.iov_len = sizeof (*req);
|
if (!message || message->length != sizeof (*req))
|
||||||
|
|
||||||
msg.msg_name = NULL;
|
|
||||||
msg.msg_namelen = 0;
|
|
||||||
msg.msg_iov = &iov;
|
|
||||||
msg.msg_iovlen = 1;
|
|
||||||
msg.msg_control = (void *)cmsgbuf;
|
|
||||||
msg.msg_controllen = sizeof (cmsgbuf);
|
|
||||||
msg.msg_flags = MSG_WAITALL;
|
|
||||||
|
|
||||||
/* read the data */
|
|
||||||
if (recvmsg(fd, &msg, 0) != sizeof (*req))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
memcpy(req, message->data, sizeof (*req));
|
||||||
|
|
||||||
if (req->op == OP_BINDSOCKET) {
|
if (req->op == OP_BINDSOCKET) {
|
||||||
/* extract transferred descriptor */
|
req->data.bind_socket.sock = message->descriptor;
|
||||||
req->data.bind_socket.sock = -1;
|
|
||||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
|
||||||
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
|
|
||||||
memcpy(&req->data.bind_socket.sock, CMSG_DATA(cmsg), sizeof (int));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* return error if valid descriptor not found */
|
/* return error if valid descriptor not found */
|
||||||
if (req->data.bind_socket.sock < 0)
|
if (req->data.bind_socket.sock < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (message->descriptor >= 0) {
|
||||||
|
SCK_CloseSocket(message->descriptor);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -256,8 +244,7 @@ do_set_time(const ReqSetTime *req, PrvResponse *res)
|
|||||||
static void
|
static void
|
||||||
do_bind_socket(ReqBindSocket *req, PrvResponse *res)
|
do_bind_socket(ReqBindSocket *req, PrvResponse *res)
|
||||||
{
|
{
|
||||||
unsigned short port;
|
IPSockAddr ip_saddr;
|
||||||
IPAddr ip;
|
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
struct sockaddr *sa;
|
struct sockaddr *sa;
|
||||||
socklen_t sa_len;
|
socklen_t sa_len;
|
||||||
@@ -266,10 +253,11 @@ do_bind_socket(ReqBindSocket *req, PrvResponse *res)
|
|||||||
sa_len = req->sa_len;
|
sa_len = req->sa_len;
|
||||||
sock_fd = req->sock;
|
sock_fd = req->sock;
|
||||||
|
|
||||||
UTI_SockaddrToIPAndPort(sa, &ip, &port);
|
SCK_SockaddrToIPSockAddr(sa, sa_len, &ip_saddr);
|
||||||
if (port && port != CNF_GetNTPPort()) {
|
if (ip_saddr.port != 0 && ip_saddr.port != CNF_GetNTPPort() &&
|
||||||
close(sock_fd);
|
ip_saddr.port != CNF_GetAcquisitionPort() && ip_saddr.port != CNF_GetPtpPort()) {
|
||||||
res_fatal(res, "Invalid port %d", port);
|
SCK_CloseSocket(sock_fd);
|
||||||
|
res_fatal(res, "Invalid port %d", ip_saddr.port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +266,7 @@ do_bind_socket(ReqBindSocket *req, PrvResponse *res)
|
|||||||
res->res_errno = errno;
|
res->res_errno = errno;
|
||||||
|
|
||||||
/* sock is still open on daemon side, but we're done with it in the helper */
|
/* sock is still open on daemon side, but we're done with it in the helper */
|
||||||
close(sock_fd);
|
SCK_CloseSocket(sock_fd);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -293,8 +281,6 @@ do_name_to_ipaddress(ReqName2IPAddress *req, PrvResponse *res)
|
|||||||
/* make sure the string is terminated */
|
/* make sure the string is terminated */
|
||||||
req->name[sizeof (req->name) - 1] = '\0';
|
req->name[sizeof (req->name) - 1] = '\0';
|
||||||
|
|
||||||
DNS_Reload();
|
|
||||||
|
|
||||||
res->rc = DNS_Name2IPAddress(req->name, res->data.name_to_ipaddress.addresses,
|
res->rc = DNS_Name2IPAddress(req->name, res->data.name_to_ipaddress.addresses,
|
||||||
DNS_MAX_ADDRESSES);
|
DNS_MAX_ADDRESSES);
|
||||||
}
|
}
|
||||||
@@ -302,6 +288,19 @@ do_name_to_ipaddress(ReqName2IPAddress *req, PrvResponse *res)
|
|||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
|
/* HELPER - perform DNS_Reload() */
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_RELOADDNS
|
||||||
|
static void
|
||||||
|
do_reload_dns(PrvResponse *res)
|
||||||
|
{
|
||||||
|
DNS_Reload();
|
||||||
|
res->rc = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
|
||||||
/* HELPER - main loop - action requests from the daemon */
|
/* HELPER - main loop - action requests from the daemon */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -343,6 +342,11 @@ helper_main(int fd)
|
|||||||
case OP_NAME2IPADDRESS:
|
case OP_NAME2IPADDRESS:
|
||||||
do_name_to_ipaddress(&req.data.name_to_ipaddress, &res);
|
do_name_to_ipaddress(&req.data.name_to_ipaddress, &res);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef PRIVOPS_RELOADDNS
|
||||||
|
case OP_RELOADDNS:
|
||||||
|
do_reload_dns(&res);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
case OP_QUIT:
|
case OP_QUIT:
|
||||||
quit = 1;
|
quit = 1;
|
||||||
@@ -356,7 +360,7 @@ helper_main(int fd)
|
|||||||
send_response(fd, &res);
|
send_response(fd, &res);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
SCK_CloseSocket(fd);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,16 +373,16 @@ receive_response(PrvResponse *res)
|
|||||||
{
|
{
|
||||||
int resp_len;
|
int resp_len;
|
||||||
|
|
||||||
resp_len = recv(helper_fd, res, sizeof (*res), 0);
|
resp_len = SCK_Receive(helper_fd, res, sizeof (*res), 0);
|
||||||
if (resp_len < 0)
|
if (resp_len < 0)
|
||||||
LOG_FATAL(LOGF_PrivOps, "Could not read from helper : %s", strerror(errno));
|
LOG_FATAL("Could not read from helper : %s", strerror(errno));
|
||||||
if (resp_len != sizeof (*res))
|
if (resp_len != sizeof (*res))
|
||||||
LOG_FATAL(LOGF_PrivOps, "Invalid helper response");
|
LOG_FATAL("Invalid helper response");
|
||||||
|
|
||||||
if (res->fatal_error)
|
if (res->fatal_error)
|
||||||
LOG_FATAL(LOGF_PrivOps, "Error in helper : %s", res->data.fatal_msg.msg);
|
LOG_FATAL("Error in helper : %s", res->data.fatal_msg.msg);
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_PrivOps, "Received response rc=%d", res->rc);
|
DEBUG_LOG("Received response rc=%d", res->rc);
|
||||||
|
|
||||||
/* if operation failed in the helper, set errno so daemon can print log message */
|
/* if operation failed in the helper, set errno so daemon can print log message */
|
||||||
if (res->res_errno)
|
if (res->res_errno)
|
||||||
@@ -392,47 +396,28 @@ receive_response(PrvResponse *res)
|
|||||||
static void
|
static void
|
||||||
send_request(PrvRequest *req)
|
send_request(PrvRequest *req)
|
||||||
{
|
{
|
||||||
struct msghdr msg;
|
SCK_Message message;
|
||||||
struct iovec iov;
|
int flags;
|
||||||
char cmsgbuf[256];
|
|
||||||
|
|
||||||
iov.iov_base = req;
|
SCK_InitMessage(&message, SCK_ADDR_UNSPEC);
|
||||||
iov.iov_len = sizeof (*req);
|
|
||||||
|
|
||||||
msg.msg_name = NULL;
|
message.data = req;
|
||||||
msg.msg_namelen = 0;
|
message.length = sizeof (*req);
|
||||||
msg.msg_iov = &iov;
|
flags = 0;
|
||||||
msg.msg_iovlen = 1;
|
|
||||||
msg.msg_control = NULL;
|
|
||||||
msg.msg_controllen = 0;
|
|
||||||
msg.msg_flags = 0;
|
|
||||||
|
|
||||||
if (req->op == OP_BINDSOCKET) {
|
if (req->op == OP_BINDSOCKET) {
|
||||||
/* send file descriptor as a control message */
|
/* send file descriptor as a control message */
|
||||||
struct cmsghdr *cmsg;
|
message.descriptor = req->data.bind_socket.sock;
|
||||||
int *ptr_send_fd;
|
flags |= SCK_FLAG_MSG_DESCRIPTOR;
|
||||||
|
|
||||||
msg.msg_control = cmsgbuf;
|
|
||||||
msg.msg_controllen = CMSG_SPACE(sizeof (int));
|
|
||||||
|
|
||||||
cmsg = CMSG_FIRSTHDR(&msg);
|
|
||||||
memset(cmsg, 0, CMSG_SPACE(sizeof (int)));
|
|
||||||
|
|
||||||
cmsg->cmsg_level = SOL_SOCKET;
|
|
||||||
cmsg->cmsg_type = SCM_RIGHTS;
|
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof (int));
|
|
||||||
|
|
||||||
ptr_send_fd = (int *)CMSG_DATA(cmsg);
|
|
||||||
*ptr_send_fd = req->data.bind_socket.sock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendmsg(helper_fd, &msg, 0) < 0) {
|
if (!SCK_SendMessage(helper_fd, &message, flags)) {
|
||||||
/* don't try to send another request from exit() */
|
/* don't try to send another request from exit() */
|
||||||
helper_fd = -1;
|
helper_fd = -1;
|
||||||
LOG_FATAL(LOGF_PrivOps, "Could not send to helper : %s", strerror(errno));
|
LOG_FATAL("Could not send to helper : %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_PrivOps, "Sent request op=%d", req->op);
|
DEBUG_LOG("Sent request op=%d", req->op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
@@ -556,13 +541,14 @@ PRV_SetTime(const struct timeval *tp, const struct timezone *tzp)
|
|||||||
int
|
int
|
||||||
PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len)
|
PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len)
|
||||||
{
|
{
|
||||||
|
IPSockAddr ip_saddr;
|
||||||
PrvRequest req;
|
PrvRequest req;
|
||||||
PrvResponse res;
|
PrvResponse res;
|
||||||
IPAddr ip;
|
|
||||||
unsigned short port;
|
|
||||||
|
|
||||||
UTI_SockaddrToIPAndPort(address, &ip, &port);
|
SCK_SockaddrToIPSockAddr(address, address_len, &ip_saddr);
|
||||||
assert(!port || port == CNF_GetNTPPort());
|
if (ip_saddr.port != 0 && ip_saddr.port != CNF_GetNTPPort() &&
|
||||||
|
ip_saddr.port != CNF_GetAcquisitionPort() && ip_saddr.port != CNF_GetPtpPort())
|
||||||
|
assert(0);
|
||||||
|
|
||||||
if (!have_helper())
|
if (!have_helper())
|
||||||
return bind(sock, address, address_len);
|
return bind(sock, address, address_len);
|
||||||
@@ -571,6 +557,7 @@ PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len)
|
|||||||
req.op = OP_BINDSOCKET;
|
req.op = OP_BINDSOCKET;
|
||||||
req.data.bind_socket.sock = sock;
|
req.data.bind_socket.sock = sock;
|
||||||
req.data.bind_socket.sa_len = address_len;
|
req.data.bind_socket.sa_len = address_len;
|
||||||
|
assert(address_len <= sizeof (req.data.bind_socket.sa));
|
||||||
memcpy(&req.data.bind_socket.sa.u, address, address_len);
|
memcpy(&req.data.bind_socket.sa.u, address, address_len);
|
||||||
|
|
||||||
submit_request(&req, &res);
|
submit_request(&req, &res);
|
||||||
@@ -598,7 +585,6 @@ PRV_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
|||||||
req.op = OP_NAME2IPADDRESS;
|
req.op = OP_NAME2IPADDRESS;
|
||||||
if (snprintf(req.data.name_to_ipaddress.name, sizeof (req.data.name_to_ipaddress.name),
|
if (snprintf(req.data.name_to_ipaddress.name, sizeof (req.data.name_to_ipaddress.name),
|
||||||
"%s", name) >= sizeof (req.data.name_to_ipaddress.name)) {
|
"%s", name) >= sizeof (req.data.name_to_ipaddress.name)) {
|
||||||
DEBUG_LOG(LOGF_PrivOps, "Name too long");
|
|
||||||
return DNS_Failure;
|
return DNS_Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,6 +599,30 @@ PRV_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
|||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
||||||
|
/* DAEMON - request res_init() */
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_RELOADDNS
|
||||||
|
void
|
||||||
|
PRV_ReloadDNS(void)
|
||||||
|
{
|
||||||
|
PrvRequest req;
|
||||||
|
PrvResponse res;
|
||||||
|
|
||||||
|
if (!have_helper()) {
|
||||||
|
DNS_Reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof (req));
|
||||||
|
req.op = OP_RELOADDNS;
|
||||||
|
|
||||||
|
submit_request(&req, &res);
|
||||||
|
assert(!res.rc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
|
||||||
void
|
void
|
||||||
PRV_Initialise(void)
|
PRV_Initialise(void)
|
||||||
{
|
{
|
||||||
@@ -628,44 +638,41 @@ void
|
|||||||
PRV_StartHelper(void)
|
PRV_StartHelper(void)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int fd, sock_pair[2];
|
int fd, sock_fd1, sock_fd2;
|
||||||
|
|
||||||
if (have_helper())
|
if (have_helper())
|
||||||
LOG_FATAL(LOGF_PrivOps, "Helper already running");
|
LOG_FATAL("Helper already running");
|
||||||
|
|
||||||
if (
|
sock_fd1 = SCK_OpenUnixSocketPair(SCK_FLAG_BLOCK, &sock_fd2);
|
||||||
#ifdef SOCK_SEQPACKET
|
if (sock_fd1 < 0)
|
||||||
socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sock_pair) &&
|
LOG_FATAL("Could not open socket pair");
|
||||||
#endif
|
|
||||||
socketpair(AF_UNIX, SOCK_DGRAM, 0, sock_pair))
|
|
||||||
LOG_FATAL(LOGF_PrivOps, "socketpair() failed : %s", strerror(errno));
|
|
||||||
|
|
||||||
UTI_FdSetCloexec(sock_pair[0]);
|
|
||||||
UTI_FdSetCloexec(sock_pair[1]);
|
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
LOG_FATAL(LOGF_PrivOps, "fork() failed : %s", strerror(errno));
|
LOG_FATAL("fork() failed : %s", strerror(errno));
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/* child process */
|
/* child process */
|
||||||
close(sock_pair[0]);
|
SCK_CloseSocket(sock_fd1);
|
||||||
|
|
||||||
/* close other descriptors inherited from the parent process */
|
/* close other descriptors inherited from the parent process, except
|
||||||
for (fd = 0; fd < 1024; fd++) {
|
stdin, stdout, and stderr */
|
||||||
if (fd != sock_pair[1])
|
for (fd = STDERR_FILENO + 1; fd < 1024; fd++) {
|
||||||
|
if (fd != sock_fd2)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignore signals, the process will exit on OP_QUIT request */
|
UTI_ResetGetRandomFunctions();
|
||||||
UTI_SetQuitSignalsHandler(SIG_IGN);
|
|
||||||
|
|
||||||
helper_main(sock_pair[1]);
|
/* ignore signals, the process will exit on OP_QUIT request */
|
||||||
|
UTI_SetQuitSignalsHandler(SIG_IGN, 1);
|
||||||
|
|
||||||
|
helper_main(sock_fd2);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* parent process */
|
/* parent process */
|
||||||
close(sock_pair[1]);
|
SCK_CloseSocket(sock_fd2);
|
||||||
helper_fd = sock_pair[0];
|
helper_fd = sock_fd1;
|
||||||
helper_pid = pid;
|
helper_pid = pid;
|
||||||
|
|
||||||
/* stop the helper even when not exiting cleanly from the main function */
|
/* stop the helper even when not exiting cleanly from the main function */
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ int PRV_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs);
|
|||||||
#define PRV_Name2IPAddress DNS_Name2IPAddress
|
#define PRV_Name2IPAddress DNS_Name2IPAddress
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PRIVOPS_RELOADDNS
|
||||||
|
void PRV_ReloadDNS(void);
|
||||||
|
#else
|
||||||
|
#define PRV_ReloadDNS DNS_Reload
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PRIVOPS_HELPER
|
#ifdef PRIVOPS_HELPER
|
||||||
void PRV_Initialise(void);
|
void PRV_Initialise(void);
|
||||||
void PRV_StartHelper(void);
|
void PRV_StartHelper(void);
|
||||||
|
|||||||
64
ptp.h
Normal file
64
ptp.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2021
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
This is the header file for the Precision Time Protocol (PTP).
|
||||||
|
|
||||||
|
*/
|
||||||
|
#ifndef GOT_PTP_H
|
||||||
|
#define GOT_PTP_H
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
|
#include "ntp.h"
|
||||||
|
|
||||||
|
#define PTP_VERSION 2
|
||||||
|
#define PTP_TYPE_DELAY_REQ 1
|
||||||
|
#define PTP_DOMAIN_NTP 123
|
||||||
|
#define PTP_FLAG_UNICAST (1 << (2 + 8))
|
||||||
|
#define PTP_TLV_NTP 0x2023
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t version;
|
||||||
|
uint16_t length;
|
||||||
|
uint8_t domain;
|
||||||
|
uint8_t min_sdoid;
|
||||||
|
uint16_t flags;
|
||||||
|
uint8_t rest[26];
|
||||||
|
} PTP_Header;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t type;
|
||||||
|
uint16_t length;
|
||||||
|
} PTP_TlvHeader;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PTP_Header header;
|
||||||
|
uint8_t origin_ts[10];
|
||||||
|
PTP_TlvHeader tlv_header;
|
||||||
|
NTP_Packet ntp_msg;
|
||||||
|
} PTP_NtpMessage;
|
||||||
|
|
||||||
|
#define PTP_NTP_PREFIX_LENGTH (int)offsetof(PTP_NtpMessage, ntp_msg)
|
||||||
|
|
||||||
|
#endif
|
||||||
209
quantiles.c
Normal file
209
quantiles.c
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2022
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Estimation of quantiles using the Frugal-2U streaming algorithm
|
||||||
|
(https://arxiv.org/pdf/1407.1121v1.pdf)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "quantiles.h"
|
||||||
|
#include "regress.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
/* Maximum number of repeated estimates for stabilisation */
|
||||||
|
#define MAX_REPEAT 64
|
||||||
|
|
||||||
|
struct Quantile {
|
||||||
|
double est;
|
||||||
|
double step;
|
||||||
|
int sign;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct QNT_Instance_Record {
|
||||||
|
struct Quantile *quants;
|
||||||
|
int n_quants;
|
||||||
|
int repeat;
|
||||||
|
int q;
|
||||||
|
int min_k;
|
||||||
|
double min_step;
|
||||||
|
int n_set;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
QNT_Instance
|
||||||
|
QNT_CreateInstance(int min_k, int max_k, int q, int repeat, double min_step)
|
||||||
|
{
|
||||||
|
QNT_Instance inst;
|
||||||
|
long seed;
|
||||||
|
|
||||||
|
if (q < 2 || min_k > max_k || min_k < 1 || max_k >= q ||
|
||||||
|
repeat < 1 || repeat > MAX_REPEAT || min_step <= 0.0)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
inst = MallocNew(struct QNT_Instance_Record);
|
||||||
|
inst->n_quants = (max_k - min_k + 1) * repeat;
|
||||||
|
inst->quants = MallocArray(struct Quantile, inst->n_quants);
|
||||||
|
inst->repeat = repeat;
|
||||||
|
inst->q = q;
|
||||||
|
inst->min_k = min_k;
|
||||||
|
inst->min_step = min_step;
|
||||||
|
|
||||||
|
QNT_Reset(inst);
|
||||||
|
|
||||||
|
/* Seed the random number generator, which will not be isolated from
|
||||||
|
other instances and other random() users */
|
||||||
|
UTI_GetRandomBytes(&seed, sizeof (seed));
|
||||||
|
srandom(seed);
|
||||||
|
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
QNT_DestroyInstance(QNT_Instance inst)
|
||||||
|
{
|
||||||
|
Free(inst->quants);
|
||||||
|
Free(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
QNT_Reset(QNT_Instance inst)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
inst->n_set = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < inst->n_quants; i++) {
|
||||||
|
inst->quants[i].est = 0.0;
|
||||||
|
inst->quants[i].step = inst->min_step;
|
||||||
|
inst->quants[i].sign = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
insert_initial_value(QNT_Instance inst, double value)
|
||||||
|
{
|
||||||
|
int i, j, r = inst->repeat;
|
||||||
|
|
||||||
|
if (inst->n_set * r >= inst->n_quants)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
/* Keep the initial estimates repeated and ordered */
|
||||||
|
for (i = inst->n_set; i > 0 && inst->quants[(i - 1) * r].est > value; i--) {
|
||||||
|
for (j = 0; j < r; j++)
|
||||||
|
inst->quants[i * r + j].est = inst->quants[(i - 1) * r].est;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < r; j++)
|
||||||
|
inst->quants[i * r + j].est = value;
|
||||||
|
inst->n_set++;
|
||||||
|
|
||||||
|
/* Duplicate the largest value in unset quantiles */
|
||||||
|
for (i = inst->n_set * r; i < inst->n_quants; i++)
|
||||||
|
inst->quants[i].est = inst->quants[i - 1].est;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_estimate(struct Quantile *quantile, double value, double p, double rand,
|
||||||
|
double min_step)
|
||||||
|
{
|
||||||
|
if (value > quantile->est && rand > (1.0 - p)) {
|
||||||
|
quantile->step += quantile->sign > 0 ? min_step : -min_step;
|
||||||
|
quantile->est += quantile->step > 0.0 ? fabs(quantile->step) : min_step;
|
||||||
|
if (quantile->est > value) {
|
||||||
|
quantile->step += value - quantile->est;
|
||||||
|
quantile->est = value;
|
||||||
|
}
|
||||||
|
if (quantile->sign < 0 && quantile->step > min_step)
|
||||||
|
quantile->step = min_step;
|
||||||
|
quantile->sign = 1;
|
||||||
|
} else if (value < quantile->est && rand > p) {
|
||||||
|
quantile->step += quantile->sign < 0 ? min_step : -min_step;
|
||||||
|
quantile->est -= quantile->step > 0.0 ? fabs(quantile->step) : min_step;
|
||||||
|
if (quantile->est < value) {
|
||||||
|
quantile->step += quantile->est - value;
|
||||||
|
quantile->est = value;
|
||||||
|
}
|
||||||
|
if (quantile->sign > 0 && quantile->step > min_step)
|
||||||
|
quantile->step = min_step;
|
||||||
|
quantile->sign = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
QNT_Accumulate(QNT_Instance inst, double value)
|
||||||
|
{
|
||||||
|
double p, rand;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Initialise the estimates with first received values */
|
||||||
|
if (inst->n_set * inst->repeat < inst->n_quants) {
|
||||||
|
insert_initial_value(inst, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < inst->n_quants; i++) {
|
||||||
|
p = (double)(i / inst->repeat + inst->min_k) / inst->q;
|
||||||
|
rand = (double)random() / ((1U << 31) - 1);
|
||||||
|
|
||||||
|
update_estimate(&inst->quants[i], value, p, rand, inst->min_step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
QNT_GetMinK(QNT_Instance inst)
|
||||||
|
{
|
||||||
|
return inst->min_k;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
double
|
||||||
|
QNT_GetQuantile(QNT_Instance inst, int k)
|
||||||
|
{
|
||||||
|
double estimates[MAX_REPEAT];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (k < inst->min_k || k - inst->min_k >= inst->n_quants)
|
||||||
|
assert(0);
|
||||||
|
|
||||||
|
for (i = 0; i < inst->repeat; i++)
|
||||||
|
estimates[i] = inst->quants[(k - inst->min_k) * inst->repeat + i].est;
|
||||||
|
|
||||||
|
return RGR_FindMedian(estimates, inst->repeat);
|
||||||
|
}
|
||||||
41
quantiles.h
Normal file
41
quantiles.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2022
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for estimation of quantiles.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_QUANTILES_H
|
||||||
|
#define GOT_QUANTILES_H
|
||||||
|
|
||||||
|
typedef struct QNT_Instance_Record *QNT_Instance;
|
||||||
|
|
||||||
|
extern QNT_Instance QNT_CreateInstance(int min_k, int max_k, int q, int repeat, double min_step);
|
||||||
|
extern void QNT_DestroyInstance(QNT_Instance inst);
|
||||||
|
|
||||||
|
extern void QNT_Reset(QNT_Instance inst);
|
||||||
|
extern void QNT_Accumulate(QNT_Instance inst, double value);
|
||||||
|
extern int QNT_GetMinK(QNT_Instance inst);
|
||||||
|
extern double QNT_GetQuantile(QNT_Instance inst, int k);
|
||||||
|
|
||||||
|
#endif
|
||||||
855
refclock.c
855
refclock.c
File diff suppressed because it is too large
Load Diff
18
refclock.h
18
refclock.h
@@ -37,16 +37,22 @@ typedef struct {
|
|||||||
int driver_poll;
|
int driver_poll;
|
||||||
int poll;
|
int poll;
|
||||||
int filter_length;
|
int filter_length;
|
||||||
|
int local;
|
||||||
|
int pps_forced;
|
||||||
int pps_rate;
|
int pps_rate;
|
||||||
int min_samples;
|
int min_samples;
|
||||||
int max_samples;
|
int max_samples;
|
||||||
int sel_options;
|
int sel_options;
|
||||||
|
int max_lock_age;
|
||||||
|
int stratum;
|
||||||
|
int tai;
|
||||||
uint32_t ref_id;
|
uint32_t ref_id;
|
||||||
uint32_t lock_ref_id;
|
uint32_t lock_ref_id;
|
||||||
double offset;
|
double offset;
|
||||||
double delay;
|
double delay;
|
||||||
double precision;
|
double precision;
|
||||||
double max_dispersion;
|
double max_dispersion;
|
||||||
|
double pulse_width;
|
||||||
} RefclockParameters;
|
} RefclockParameters;
|
||||||
|
|
||||||
typedef struct RCL_Instance_Record *RCL_Instance;
|
typedef struct RCL_Instance_Record *RCL_Instance;
|
||||||
@@ -61,14 +67,20 @@ extern void RCL_Initialise(void);
|
|||||||
extern void RCL_Finalise(void);
|
extern void RCL_Finalise(void);
|
||||||
extern int RCL_AddRefclock(RefclockParameters *params);
|
extern int RCL_AddRefclock(RefclockParameters *params);
|
||||||
extern void RCL_StartRefclocks(void);
|
extern void RCL_StartRefclocks(void);
|
||||||
extern void RCL_ReportSource(RPT_SourceReport *report, struct timeval *now);
|
extern void RCL_ReportSource(RPT_SourceReport *report, struct timespec *now);
|
||||||
|
|
||||||
/* functions used by drivers */
|
/* functions used by drivers */
|
||||||
extern void RCL_SetDriverData(RCL_Instance instance, void *data);
|
extern void RCL_SetDriverData(RCL_Instance instance, void *data);
|
||||||
extern void *RCL_GetDriverData(RCL_Instance instance);
|
extern void *RCL_GetDriverData(RCL_Instance instance);
|
||||||
extern char *RCL_GetDriverParameter(RCL_Instance instance);
|
extern char *RCL_GetDriverParameter(RCL_Instance instance);
|
||||||
|
extern void RCL_CheckDriverOptions(RCL_Instance instance, const char **options);
|
||||||
extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
|
extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
|
||||||
extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, int leap);
|
extern int RCL_AddSample(RCL_Instance instance, struct timespec *sample_time,
|
||||||
extern int RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second);
|
struct timespec *ref_time, int leap);
|
||||||
|
extern int RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second);
|
||||||
|
extern int RCL_AddCookedPulse(RCL_Instance instance, struct timespec *cooked_time,
|
||||||
|
double second, double dispersion, double raw_correction);
|
||||||
|
extern double RCL_GetPrecision(RCL_Instance instance);
|
||||||
|
extern int RCL_GetDriverPoll(RCL_Instance instance);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
225
refclock_phc.c
225
refclock_phc.c
@@ -2,7 +2,7 @@
|
|||||||
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Miroslav Lichvar 2013
|
* Copyright (C) Miroslav Lichvar 2013, 2017
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -33,151 +33,142 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include <linux/ptp_clock.h>
|
|
||||||
|
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
|
#include "hwclock.h"
|
||||||
|
#include "local.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "sched.h"
|
||||||
|
#include "sys_linux.h"
|
||||||
|
|
||||||
/* From linux/include/linux/posix-timers.h */
|
struct phc_instance {
|
||||||
#define CPUCLOCK_MAX 3
|
int fd;
|
||||||
#define CLOCKFD CPUCLOCK_MAX
|
int mode;
|
||||||
#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
|
int nocrossts;
|
||||||
|
int extpps;
|
||||||
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
|
int pin;
|
||||||
|
int channel;
|
||||||
#define NUM_READINGS 10
|
HCL_Instance clock;
|
||||||
|
|
||||||
static int no_sys_offset_ioctl = 0;
|
|
||||||
|
|
||||||
struct phc_reading {
|
|
||||||
struct timespec sys_ts1;
|
|
||||||
struct timespec phc_ts;;
|
|
||||||
struct timespec sys_ts2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static double diff_ts(struct timespec *ts1, struct timespec *ts2)
|
static void read_ext_pulse(int sockfd, int event, void *anything);
|
||||||
{
|
|
||||||
return (ts1->tv_sec - ts2->tv_sec) + (ts1->tv_nsec - ts2->tv_nsec) / 1e9;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_phc_ioctl(struct phc_reading *readings, int phc_fd, int n)
|
|
||||||
{
|
|
||||||
#if defined(PTP_SYS_OFFSET) && NUM_READINGS <= PTP_MAX_SAMPLES
|
|
||||||
struct ptp_sys_offset sys_off;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Silence valgrind */
|
|
||||||
memset(&sys_off, 0, sizeof (sys_off));
|
|
||||||
|
|
||||||
sys_off.n_samples = n;
|
|
||||||
if (ioctl(phc_fd, PTP_SYS_OFFSET, &sys_off)) {
|
|
||||||
LOG(LOGS_ERR, LOGF_Refclock, "ioctl(PTP_SYS_OFFSET) failed : %s", strerror(errno));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
readings[i].sys_ts1.tv_sec = sys_off.ts[i * 2].sec;
|
|
||||||
readings[i].sys_ts1.tv_nsec = sys_off.ts[i * 2].nsec;
|
|
||||||
readings[i].phc_ts.tv_sec = sys_off.ts[i * 2 + 1].sec;
|
|
||||||
readings[i].phc_ts.tv_nsec = sys_off.ts[i * 2 + 1].nsec;
|
|
||||||
readings[i].sys_ts2.tv_sec = sys_off.ts[i * 2 + 2].sec;
|
|
||||||
readings[i].sys_ts2.tv_nsec = sys_off.ts[i * 2 + 2].nsec;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
#else
|
|
||||||
/* Not available */
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_phc_user(struct phc_reading *readings, int phc_fd, int n)
|
|
||||||
{
|
|
||||||
clockid_t phc_id;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
phc_id = FD_TO_CLOCKID(phc_fd);
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
if (clock_gettime(CLOCK_REALTIME, &readings[i].sys_ts1) ||
|
|
||||||
clock_gettime(phc_id, &readings[i].phc_ts) ||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &readings[i].sys_ts2)) {
|
|
||||||
LOG(LOGS_ERR, LOGF_Refclock, "clock_gettime() failed : %s", strerror(errno));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int phc_initialise(RCL_Instance instance)
|
static int phc_initialise(RCL_Instance instance)
|
||||||
{
|
{
|
||||||
struct ptp_clock_caps caps;
|
const char *options[] = {"nocrossts", "extpps", "pin", "channel", "clear", NULL};
|
||||||
int phc_fd;
|
struct phc_instance *phc;
|
||||||
char *path;
|
int phc_fd, rising_edge;
|
||||||
|
char *path, *s;
|
||||||
|
|
||||||
|
RCL_CheckDriverOptions(instance, options);
|
||||||
|
|
||||||
path = RCL_GetDriverParameter(instance);
|
path = RCL_GetDriverParameter(instance);
|
||||||
|
|
||||||
phc_fd = open(path, O_RDONLY);
|
phc_fd = SYS_Linux_OpenPHC(path, 0);
|
||||||
if (phc_fd < 0) {
|
if (phc_fd < 0)
|
||||||
LOG_FATAL(LOGF_Refclock, "open() failed on %s", path);
|
LOG_FATAL("Could not open PHC");
|
||||||
return 0;
|
|
||||||
|
phc = MallocNew(struct phc_instance);
|
||||||
|
phc->fd = phc_fd;
|
||||||
|
phc->mode = 0;
|
||||||
|
phc->nocrossts = RCL_GetDriverOption(instance, "nocrossts") ? 1 : 0;
|
||||||
|
phc->extpps = RCL_GetDriverOption(instance, "extpps") ? 1 : 0;
|
||||||
|
|
||||||
|
phc->clock = HCL_CreateInstance(0, 16, UTI_Log2ToDouble(RCL_GetDriverPoll(instance)),
|
||||||
|
RCL_GetPrecision(instance));
|
||||||
|
|
||||||
|
if (phc->extpps) {
|
||||||
|
s = RCL_GetDriverOption(instance, "pin");
|
||||||
|
phc->pin = s ? atoi(s) : 0;
|
||||||
|
s = RCL_GetDriverOption(instance, "channel");
|
||||||
|
phc->channel = s ? atoi(s) : 0;
|
||||||
|
rising_edge = RCL_GetDriverOption(instance, "clear") ? 0 : 1;
|
||||||
|
|
||||||
|
if (!SYS_Linux_SetPHCExtTimestamping(phc->fd, phc->pin, phc->channel,
|
||||||
|
rising_edge, !rising_edge, 1))
|
||||||
|
LOG_FATAL("Could not enable external PHC timestamping");
|
||||||
|
|
||||||
|
SCH_AddFileHandler(phc->fd, SCH_FILE_INPUT, read_ext_pulse, instance);
|
||||||
|
} else {
|
||||||
|
phc->pin = phc->channel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure it is a PHC */
|
RCL_SetDriverData(instance, phc);
|
||||||
if (ioctl(phc_fd, PTP_CLOCK_GETCAPS, &caps)) {
|
|
||||||
LOG_FATAL(LOGF_Refclock, "ioctl(PTP_CLOCK_GETCAPS) failed : %s", strerror(errno));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
UTI_FdSetCloexec(phc_fd);
|
|
||||||
|
|
||||||
RCL_SetDriverData(instance, (void *)(long)phc_fd);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void phc_finalise(RCL_Instance instance)
|
static void phc_finalise(RCL_Instance instance)
|
||||||
{
|
{
|
||||||
close((long)RCL_GetDriverData(instance));
|
struct phc_instance *phc;
|
||||||
|
|
||||||
|
phc = (struct phc_instance *)RCL_GetDriverData(instance);
|
||||||
|
|
||||||
|
if (phc->extpps) {
|
||||||
|
SCH_RemoveFileHandler(phc->fd);
|
||||||
|
SYS_Linux_SetPHCExtTimestamping(phc->fd, phc->pin, phc->channel, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
HCL_DestroyInstance(phc->clock);
|
||||||
|
close(phc->fd);
|
||||||
|
Free(phc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void read_ext_pulse(int fd, int event, void *anything)
|
||||||
|
{
|
||||||
|
RCL_Instance instance;
|
||||||
|
struct phc_instance *phc;
|
||||||
|
struct timespec phc_ts, local_ts;
|
||||||
|
double local_err;
|
||||||
|
int channel;
|
||||||
|
|
||||||
|
instance = anything;
|
||||||
|
phc = RCL_GetDriverData(instance);
|
||||||
|
|
||||||
|
if (!SYS_Linux_ReadPHCExtTimestamp(phc->fd, &phc_ts, &channel))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (channel != phc->channel) {
|
||||||
|
DEBUG_LOG("Unexpected extts channel %d\n", channel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!HCL_CookTime(phc->clock, &phc_ts, &local_ts, &local_err))
|
||||||
|
return;
|
||||||
|
|
||||||
|
RCL_AddCookedPulse(instance, &local_ts, 1.0e-9 * local_ts.tv_nsec, local_err,
|
||||||
|
UTI_DiffTimespecsToDouble(&phc_ts, &local_ts));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PHC_READINGS 25
|
||||||
|
|
||||||
static int phc_poll(RCL_Instance instance)
|
static int phc_poll(RCL_Instance instance)
|
||||||
{
|
{
|
||||||
struct phc_reading readings[NUM_READINGS];
|
struct timespec phc_ts, sys_ts, local_ts, readings[PHC_READINGS][3];
|
||||||
struct timeval tv;
|
struct phc_instance *phc;
|
||||||
double offset = 0.0, delay, best_delay = 0.0;
|
double phc_err, local_err;
|
||||||
int i, phc_fd, best;
|
int n_readings;
|
||||||
|
|
||||||
phc_fd = (long)RCL_GetDriverData(instance);
|
|
||||||
|
|
||||||
if (!no_sys_offset_ioctl) {
|
phc = (struct phc_instance *)RCL_GetDriverData(instance);
|
||||||
if (!read_phc_ioctl(readings, phc_fd, NUM_READINGS)) {
|
|
||||||
no_sys_offset_ioctl = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!read_phc_user(readings, phc_fd, NUM_READINGS))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the fastest reading */
|
n_readings = SYS_Linux_GetPHCReadings(phc->fd, phc->nocrossts, &phc->mode,
|
||||||
for (i = 0; i < NUM_READINGS; i++) {
|
PHC_READINGS, readings);
|
||||||
delay = diff_ts(&readings[i].sys_ts2, &readings[i].sys_ts1);
|
if (n_readings < 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!i || best_delay > delay) {
|
if (!HCL_ProcessReadings(phc->clock, n_readings, readings, &phc_ts, &sys_ts, &phc_err))
|
||||||
best = i;
|
return 0;
|
||||||
best_delay = delay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = diff_ts(&readings[best].phc_ts, &readings[best].sys_ts2) + best_delay / 2.0;
|
LCL_CookTime(&sys_ts, &local_ts, &local_err);
|
||||||
tv.tv_sec = readings[best].sys_ts2.tv_sec;
|
HCL_AccumulateSample(phc->clock, &phc_ts, &local_ts, phc_err + local_err);
|
||||||
tv.tv_usec = readings[best].sys_ts2.tv_nsec / 1000;
|
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_Refclock, "PHC offset: %+.9f delay: %.9f", offset, best_delay);
|
if (phc->extpps)
|
||||||
|
return 0;
|
||||||
|
|
||||||
return RCL_AddSample(instance, &tv, offset, LEAP_Normal);
|
DEBUG_LOG("PHC offset: %+.9f err: %.9f",
|
||||||
|
UTI_DiffTimespecsToDouble(&phc_ts, &sys_ts), phc_err);
|
||||||
|
|
||||||
|
return RCL_AddSample(instance, &sys_ts, &phc_ts, LEAP_Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefclockDriver RCL_PHC_driver = {
|
RefclockDriver RCL_PHC_driver = {
|
||||||
|
|||||||
@@ -48,59 +48,49 @@ struct pps_instance {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int pps_initialise(RCL_Instance instance) {
|
static int pps_initialise(RCL_Instance instance) {
|
||||||
|
const char *options[] = {"clear", NULL};
|
||||||
pps_handle_t handle;
|
pps_handle_t handle;
|
||||||
pps_params_t params;
|
pps_params_t params;
|
||||||
struct pps_instance *pps;
|
struct pps_instance *pps;
|
||||||
int fd, edge_clear, mode;
|
int fd, edge_clear, mode;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
|
RCL_CheckDriverOptions(instance, options);
|
||||||
|
|
||||||
path = RCL_GetDriverParameter(instance);
|
path = RCL_GetDriverParameter(instance);
|
||||||
edge_clear = RCL_GetDriverOption(instance, "clear") ? 1 : 0;
|
edge_clear = RCL_GetDriverOption(instance, "clear") ? 1 : 0;
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
LOG_FATAL(LOGF_Refclock, "open() failed on %s", path);
|
LOG_FATAL("Could not open %s : %s", path, strerror(errno));
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
UTI_FdSetCloexec(fd);
|
UTI_FdSetCloexec(fd);
|
||||||
|
|
||||||
if (time_pps_create(fd, &handle) < 0) {
|
if (time_pps_create(fd, &handle) < 0)
|
||||||
LOG_FATAL(LOGF_Refclock, "time_pps_create() failed on %s", path);
|
LOG_FATAL("time_pps_create() failed on %s : %s", path, strerror(errno));
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time_pps_getcap(handle, &mode) < 0) {
|
if (time_pps_getcap(handle, &mode) < 0)
|
||||||
LOG_FATAL(LOGF_Refclock, "time_pps_getcap() failed on %s", path);
|
LOG_FATAL("time_pps_getcap() failed on %s : %s", path, strerror(errno));
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time_pps_getparams(handle, ¶ms) < 0) {
|
if (time_pps_getparams(handle, ¶ms) < 0)
|
||||||
LOG_FATAL(LOGF_Refclock, "time_pps_getparams() failed on %s", path);
|
LOG_FATAL("time_pps_getparams() failed on %s : %s", path, strerror(errno));
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!edge_clear) {
|
if (!edge_clear) {
|
||||||
if (!(mode & PPS_CAPTUREASSERT)) {
|
if (!(mode & PPS_CAPTUREASSERT))
|
||||||
LOG_FATAL(LOGF_Refclock, "CAPTUREASSERT not supported on %s", path);
|
LOG_FATAL("CAPTUREASSERT not supported on %s", path);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
params.mode |= PPS_CAPTUREASSERT;
|
params.mode |= PPS_CAPTUREASSERT;
|
||||||
params.mode &= ~PPS_CAPTURECLEAR;
|
params.mode &= ~PPS_CAPTURECLEAR;
|
||||||
} else {
|
} else {
|
||||||
if (!(mode & PPS_CAPTURECLEAR)) {
|
if (!(mode & PPS_CAPTURECLEAR))
|
||||||
LOG_FATAL(LOGF_Refclock, "CAPTURECLEAR not supported on %s", path);
|
LOG_FATAL("CAPTURECLEAR not supported on %s", path);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
params.mode |= PPS_CAPTURECLEAR;
|
params.mode |= PPS_CAPTURECLEAR;
|
||||||
params.mode &= ~PPS_CAPTUREASSERT;
|
params.mode &= ~PPS_CAPTUREASSERT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time_pps_setparams(handle, ¶ms) < 0) {
|
if (time_pps_setparams(handle, ¶ms) < 0)
|
||||||
LOG_FATAL(LOGF_Refclock, "time_pps_setparams() failed on %s", path);
|
LOG_FATAL("time_pps_setparams() failed on %s : %s", path, strerror(errno));
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pps = MallocNew(struct pps_instance);
|
pps = MallocNew(struct pps_instance);
|
||||||
pps->handle = handle;
|
pps->handle = handle;
|
||||||
@@ -124,7 +114,6 @@ static int pps_poll(RCL_Instance instance)
|
|||||||
{
|
{
|
||||||
struct pps_instance *pps;
|
struct pps_instance *pps;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct timeval tv;
|
|
||||||
pps_info_t pps_info;
|
pps_info_t pps_info;
|
||||||
pps_seq_t seq;
|
pps_seq_t seq;
|
||||||
|
|
||||||
@@ -134,7 +123,7 @@ static int pps_poll(RCL_Instance instance)
|
|||||||
ts.tv_nsec = 0;
|
ts.tv_nsec = 0;
|
||||||
|
|
||||||
if (time_pps_fetch(pps->handle, PPS_TSFMT_TSPEC, &pps_info, &ts) < 0) {
|
if (time_pps_fetch(pps->handle, PPS_TSFMT_TSPEC, &pps_info, &ts) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_Refclock, "time_pps_fetch() failed : %s", strerror(errno));
|
LOG(LOGS_ERR, "time_pps_fetch() failed : %s", strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,17 +135,15 @@ static int pps_poll(RCL_Instance instance)
|
|||||||
ts = pps_info.clear_timestamp;
|
ts = pps_info.clear_timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seq == pps->last_seq || (ts.tv_sec == 0 && ts.tv_nsec == 0)) {
|
if (seq == pps->last_seq || UTI_IsZeroTimespec(&ts)) {
|
||||||
DEBUG_LOG(LOGF_Refclock, "PPS sample ignored seq=%lu ts=%lu.%09lu",
|
DEBUG_LOG("PPS sample ignored seq=%lu ts=%s",
|
||||||
seq, ts.tv_sec, ts.tv_nsec);
|
(unsigned long)seq, UTI_TimespecToString(&ts));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pps->last_seq = seq;
|
pps->last_seq = seq;
|
||||||
tv.tv_sec = ts.tv_sec;
|
|
||||||
tv.tv_usec = ts.tv_nsec / 1000;
|
|
||||||
|
|
||||||
return RCL_AddPulse(instance, &tv, ts.tv_nsec / 1e9);
|
return RCL_AddPulse(instance, &ts, 1.0e-9 * ts.tv_nsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefclockDriver RCL_PPS_driver = {
|
RefclockDriver RCL_PPS_driver = {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user