1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 OpenWrt.org
9 HOTPLUG_HELPER
=/usr
/sbin
/ntpd.hotplug-helper
11 config_file
=/var
/run
/ntpd.conf
14 echo -n "" > $config_file
18 echo -e "$@" >> $config_file
21 validate_ntp_section
() {
22 uci_validate_section system timeserver
"${1}" \
23 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' \
24 'interface:list(string)'
28 local server enabled enable_server interface intf
30 validate_ntp_section ntp ||
{
31 echo "validation failed"
35 [ "$enabled" = 0 ] && return
37 [ -z "$server" -a "$enable_server" = 0 ] && return
39 # not sure that the interfaces enumerated should be validated,
40 # since some of them might be dynamic interfaces (like IPsec
41 # tunnels) which aren't known by ubus.
44 emit
"driftfile /var/lib/ntp/ntp.drift\n"
46 if [ "$enable_server" != 0 ]; then
47 emit
"restrict default limited kod nomodify notrap nopeer"
48 emit
"restrict -6 default limited kod nomodify notrap nopeer"
50 emit
"restrict -4 default noserve"
51 emit
"restrict -6 default noserve"
53 emit
"restrict source noquery"
55 emit
"\n# No limits for local monitoring"
56 emit
"restrict 127.0.0.1"
57 emit
"restrict -6 ::1\n"
59 if [ -n "$interface" ]; then
60 local loopback
=$
(ubus call network.interface dump | jsonfilter
-e "@.interface[@.interface='loopback']['device']")
63 for intf
in $interface; do
64 emit
"interface listen $intf"
65 [ "$intf" = "$loopback" ] && saw_lo
=1
67 [ -z "$saw_lo" ] && emit
"interface listen $loopback"
71 emit
"server $server iburst"
74 chown
-R ntp
:ntp
/var
/lib
/ntp
77 procd_set_param
command $PROG -g -u ntp
:ntp
-p /var
/run
/ntpd.pid
-n \
82 procd_set_param
command $HOTPLUG_HELPER