diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2016-05-23 14:30:57 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2016-05-24 13:30:58 +0200 |
commit | 6707d9750aa37df75fc1d5c9e64ab599f608c3a2 (patch) | |
tree | c28c2c4655b77c5008ba93e358592d680abbb8cb /package/utils | |
parent | 2ac21bd793946a214295b760cd652b4150d3dc07 (diff) | |
download | mtk-20170518-6707d9750aa37df75fc1d5c9e64ab599f608c3a2.zip mtk-20170518-6707d9750aa37df75fc1d5c9e64ab599f608c3a2.tar.gz mtk-20170518-6707d9750aa37df75fc1d5c9e64ab599f608c3a2.tar.bz2 |
busybox: sysntpd - Support for NTP servers received via DHCP(v6)
The busybox ntpd utility currently uses ntp servers specified in uci.
This patch allows the ntpd utility to use NTP servers received via DHCP(v6)
Following uci parameters have been added:
use_dhcp : enables NTP server config via DHCP(v6)
dhcp_interface : use NTP servers received only on the specified DHCP(v6) interfaces; if empty all interfaces are considered
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'package/utils')
-rw-r--r-- | package/utils/busybox/Makefile | 4 | ||||
-rwxr-xr-x | package/utils/busybox/files/sysntpd | 57 |
2 files changed, 54 insertions, 7 deletions
diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile index 24c064c..065bf7d 100644 --- a/package/utils/busybox/Makefile +++ b/package/utils/busybox/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=busybox PKG_VERSION:=1.24.2 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_FLAGS:=essential PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 @@ -42,7 +42,7 @@ define Package/busybox MAINTAINER:=Felix Fietkau <nbd@openwrt.org> TITLE:=Core utilities for embedded Linux URL:=http://busybox.net/ - DEPENDS:=+BUSYBOX_USE_LIBRPC:librpc +BUSYBOX_CONFIG_PAM:libpam + DEPENDS:=+BUSYBOX_USE_LIBRPC:librpc +BUSYBOX_CONFIG_PAM:libpam +BUSYBOX_CONFIG_NTPD:jsonfilter MENU:=1 endef diff --git a/package/utils/busybox/files/sysntpd b/package/utils/busybox/files/sysntpd index f73bb83..6d44280 100755 --- a/package/utils/busybox/files/sysntpd +++ b/package/utils/busybox/files/sysntpd @@ -7,13 +7,34 @@ USE_PROCD=1 PROG=/usr/sbin/ntpd HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug +get_dhcp_ntp_servers() { + local interfaces="$1" + local filter="*" + local interface ntpservers ntpserver + + for interface in $interfaces; do + [ "$filter" = "*" ] && filter="@.interface='$interface'" || filter="$filter,@.interface='$interface'" + done + + ntpservers=$(ubus call network.interface dump | jsonfilter -e "@.interface[$filter]['data']['ntpserver']") + + for ntpserver in $ntpservers; do + local duplicate=0 + local entry + for entry in $server; do + [ "$ntpserver" = "$entry" ] && duplicate=1 + done + [ "$duplicate" = 0 ] && server="$server $ntpserver" + done +} + validate_ntp_section() { uci_validate_section system timeserver "${1}" \ - 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' + 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' 'use_dhcp:bool:1' 'dhcp_interface:list(string)' } start_service() { - local server enabled enable_server peer + local server enabled enable_server use_dhcp dhcp_interface peer validate_ntp_section ntp || { echo "validation failed" @@ -22,6 +43,8 @@ start_service() { [ $enabled = 0 ] && return + [ $use_dhcp = 1 ] && get_dhcp_ntp_servers "$dhcp_interface" + [ -z "$server" ] && return procd_open_instance @@ -35,8 +58,32 @@ start_service() { procd_close_instance } -service_triggers() -{ - procd_add_reload_trigger "system" +service_triggers() { + local script name use_dhcp + + script=$(readlink -f "$initscript") + name=$(basename ${script:-$initscript}) + + procd_open_trigger + procd_add_config_trigger "config.change" "system" /etc/init.d/$name reload + + config_load system + config_get use_dhcp ntp use_dhcp 1 + + [ $use_dhcp = 1 ] && { + local dhcp_interface + config_get dhcp_interface ntp dhcp_interface + + if [ -n "$dhcp_interface" ]; then + for n in $dhcp_interface; do + procd_add_interface_trigger "interface.*" $n /etc/init.d/$name reload + done + else + procd_add_raw_trigger "interface.*" 1000 /etc/init.d/$name reload + fi + } + + procd_close_trigger + procd_add_validation validate_ntp_section } |