blob: 6e73489d4ae8e7842eaf0a2c753b314c1dd1fd7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=65
STOP=65
USE_PROCD=1
PROG=/sbin/ntpd
HOTPLUG_HELPER=/usr/sbin/ntpd.hotplug-helper
config_file=/var/etc/ntpd.conf
trunc() {
echo -n "" > $config_file
}
emit() {
echo -e "$@" >> $config_file
}
validate_ntp_section() {
uci_load_validate system timeserver "$1" "$2" \
'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' \
'interface:list(string)'
}
start_ntpd_instance() {
local intf i
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
[ "$enabled" = 0 ] && return
[ -z "$server" -a "$enable_server" = 0 ] && return
# not sure that the interfaces enumerated should be validated,
# since some of them might be dynamic interfaces (like IPsec
# tunnels) which aren't known by ubus.
trunc
emit "driftfile /var/lib/ntp/ntp.drift\n"
if [ "$enable_server" != 0 ]; then
emit "restrict default limited kod nomodify notrap nopeer"
emit "restrict -6 default limited kod nomodify notrap nopeer"
else
emit "restrict -4 default noserve"
emit "restrict -6 default noserve"
fi
emit "restrict source noquery"
emit "\n# No limits for local monitoring"
emit "restrict 127.0.0.1"
emit "restrict -6 ::1\n"
if [ -n "$interface" ]; then
local loopback=$(ubus call network.interface dump | jsonfilter -e "@.interface[@.interface='loopback']['device']")
local saw_lo=
for intf in $interface; do
emit "interface listen $intf"
[ "$intf" = "$loopback" ] && saw_lo=1
done
[ -z "$saw_lo" ] && emit "interface listen $loopback"
emit ""
fi
for i in $server
do
emit "server $i iburst"
done
mkdir -p /var/lib/ntp
chown -R ntp:ntp /var/lib/ntp
procd_open_instance
procd_set_param command $PROG -g -u ntp:ntp -p /var/run/ntpd.pid -n \
-c $config_file
procd_close_instance
procd_open_instance
procd_set_param command $HOTPLUG_HELPER
procd_close_instance
}
start_service() {
validate_ntp_section ntp start_ntpd_instance
}
service_triggers() {
procd_add_reload_trigger "system"
procd_add_validation validate_ntp_section
}
|