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.

69 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006 OpenWrt.org
  3. START=60
  4. USE_PROCD=1
  5. PROG=/usr/sbin/chronyd
  6. CONFIGFILE=/var/etc/chrony.conf
  7. handle_source() {
  8. local cfg=$1 sourcetype=$2 hostname minpoll maxpoll iburst
  9. config_get hostname "$cfg" hostname
  10. [ -z "$hostname" ] && return
  11. config_get minpoll "$cfg" minpoll
  12. config_get maxpoll "$cfg" maxpoll
  13. config_get_bool iburst "$cfg" iburst 0
  14. echo $(
  15. echo $sourcetype $hostname
  16. [ -n "$minpoll" ] && echo minpoll $minpoll
  17. [ -n "$maxpoll" ] && echo maxpoll $maxpoll
  18. [ "$iburst" = "1" ] && echo iburst
  19. ) >> $CONFIGFILE
  20. }
  21. handle_allow() {
  22. local cfg=$1 iface wan_iface wan6_iface subnet subnets subnets6
  23. network_find_wan wan_iface true
  24. network_find_wan6 wan6_iface true
  25. config_get iface "$cfg" interface
  26. if [ "$wan_iface" = "$iface" ]; then
  27. echo allow >> $CONFIGFILE
  28. else
  29. network_get_subnets subnets $iface || \
  30. network_get_subnets subnets6 $iface || continue
  31. for subnet in $subnets $subnets6; do
  32. echo allow $subnet >> $CONFIGFILE
  33. done
  34. fi
  35. }
  36. handle_makestep() {
  37. local cfg=$1 threshold limit
  38. config_get threshold "$cfg" threshold
  39. config_get limit "$cfg" limit
  40. [ -z "$threshold" -o -z "$limit" ] && return
  41. echo makestep $threshold $limit >> $CONFIGFILE
  42. }
  43. start_service() {
  44. . /lib/functions/network.sh
  45. procd_open_instance
  46. procd_set_param command $PROG -n -f $CONFIGFILE
  47. procd_set_param file $CONFIGFILE
  48. procd_set_param file /etc/chrony/chrony.conf
  49. procd_close_instance
  50. echo include /etc/chrony/chrony.conf > $CONFIGFILE
  51. config_load ntpd
  52. config_foreach handle_source server server
  53. config_foreach handle_source pool pool
  54. config_foreach handle_source peer peer
  55. config_foreach handle_allow allow
  56. config_foreach handle_makestep makestep
  57. }