You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. START=15
  4. USE_PROCD=1
  5. PROG=/usr/sbin/chronyd
  6. CONFIGFILE=/etc/chrony/chrony.conf
  7. INCLUDEFILE=/var/etc/chrony.d/10-uci.conf
  8. RTCDEVICE=/dev/rtc0
  9. handle_source() {
  10. local cfg=$1 sourcetype=$2 disabled hostname minpoll maxpoll iburst nts
  11. config_get_bool disabled "$cfg" disabled 0
  12. [ "$disabled" = "1" ] && return
  13. hostname=$NTP_SOURCE_HOSTNAME
  14. [ -z "$hostname" ] && config_get hostname "$cfg" hostname
  15. [ -z "$hostname" ] && return
  16. config_get minpoll "$cfg" minpoll
  17. config_get maxpoll "$cfg" maxpoll
  18. config_get_bool iburst "$cfg" iburst 0
  19. config_get_bool nts "$cfg" nts 0
  20. echo $(
  21. echo $sourcetype $hostname
  22. [ -n "$minpoll" ] && echo minpoll $minpoll
  23. [ -n "$maxpoll" ] && echo maxpoll $maxpoll
  24. [ "$iburst" = "1" ] && echo iburst
  25. [ "$nts" = "1" ] && echo nts
  26. )
  27. }
  28. handle_allow() {
  29. local cfg=$1 iface wan_iface wan6_iface subnet subnets subnets6
  30. network_find_wan wan_iface true
  31. network_find_wan6 wan6_iface true
  32. config_get iface "$cfg" interface
  33. if [ "$wan_iface" = "$iface" ]; then
  34. echo allow 0/0
  35. elif [ "$wan6_iface" = "$iface" ]; then
  36. echo allow ::/0
  37. else
  38. network_get_subnets subnets $iface
  39. network_get_subnets6 subnets6 $iface
  40. for subnet in $subnets $subnets6; do
  41. echo allow $subnet
  42. done
  43. fi
  44. }
  45. handle_makestep() {
  46. local cfg=$1 threshold limit
  47. config_get threshold "$cfg" threshold
  48. config_get limit "$cfg" limit
  49. [ -z "$threshold" -o -z "$limit" ] && return
  50. echo makestep $threshold $limit
  51. }
  52. handle_nts() {
  53. local cfg=$1 threshold limit
  54. config_get_bool rtccheck "$cfg" rtccheck 0
  55. config_get_bool systemcerts "$cfg" systemcerts 1
  56. config_get trustedcerts "$cfg" trustedcerts
  57. # Disable certificate time checks if no RTC is present
  58. [ "$rtccheck" = "1" ] && ! [ -c $RTCDEVICE ] && echo nocerttimecheck 1
  59. [ "$systemcerts" = "0" ] && echo nosystemcert
  60. [ -n "$trustedcerts" ] && echo ntstrustedcerts "$trustedcerts"
  61. }
  62. start_service() {
  63. . /lib/functions/network.sh
  64. procd_open_instance
  65. procd_set_param command $PROG -n
  66. procd_set_param file $CONFIGFILE
  67. procd_set_param file $INCLUDEFILE
  68. procd_close_instance
  69. config_load chrony
  70. mkdir -p $(dirname $INCLUDEFILE)
  71. (
  72. config_foreach handle_source server server
  73. config_foreach handle_source pool pool
  74. config_foreach handle_source peer peer
  75. config_foreach handle_allow allow
  76. config_foreach handle_makestep makestep
  77. config_foreach handle_nts nts
  78. ) > $INCLUDEFILE
  79. }