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.

44 lines
1.1 KiB

  1. #!/bin/sh
  2. # Set chronyd online/offline status, allow NTP access and add servers from DHCP
  3. [ "$ACTION" = ifup -o "$ACTION" = ifdown ] || exit 0
  4. run_command() {
  5. /usr/bin/chronyc -n "$*" > /dev/null 2>&1
  6. }
  7. run_command tracking || exit 0
  8. . /lib/functions/network.sh
  9. network_find_wan iface4
  10. network_find_wan6 iface6
  11. run_command $([ -n "$iface4" ] && echo online || echo offline) 0.0.0.0/0.0.0.0
  12. run_command $([ -n "$iface6" ] && echo online || echo offline) ::/0
  13. [ "$ACTION" = ifup ] || exit 0
  14. . /lib/functions.sh
  15. . /etc/init.d/chronyd
  16. config_load chrony
  17. config_foreach handle_allow allow | while read command; do
  18. run_command "$command"
  19. done
  20. # Add servers from DHCP only if the config has a dhcp_ntp_server section
  21. [ -z "$(config_foreach echo dhcp_ntp_server)" ] && exit 0
  22. . /usr/share/libubox/jshn.sh
  23. for iface in $iface4 $iface6; do
  24. json_load "$(ifstatus $iface)"
  25. json_select data
  26. json_get_var dhcp_ntp_servers ntpserver
  27. for server in $dhcp_ntp_servers; do
  28. run_command add $(NTP_SOURCE_HOSTNAME=$server config_foreach \
  29. handle_source dhcp_ntp_server server)
  30. done
  31. done