<div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px">One feature that was requested is the ability to specify a list of interfaces to get servers from.</div><div style="font-size:12.8px">You can save the list as an option to the config file and add a trigger to only those interfaces.</div><div style="font-size:12.8px">Regards,</div><div style="font-size:12.8px">Amine.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 19, 2016 at 6:57 PM, Hans Dedecker <span dir="ltr"><<a href="mailto:dedeckeh@gmail.com" target="_blank">dedeckeh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The busybox ntpd utility currently uses ntp servers specified in uci.<br>
This patch allows the ntpd utility to use NTP servers received via DHCP(v6)<br>
Following uci parameters have been added:<br>
use_dhcp : enables NTP server config via DHCP(v6)<br>
dhcp_interface : use NTP servers received only on the specified DHCP(v6) interfaces; if empty all interfaces are considered<br>
<br>
Signed-off-by: Hans Dedecker <<a href="mailto:dedeckeh@gmail.com">dedeckeh@gmail.com</a>><br>
---<br>
<br>
The patch is based on a previous discussion held on the OpenWRT-devel mailing list<br>
(<a href="https://lists.openwrt.org/pipermail/openwrt-devel/2016-January/039081.html" rel="noreferrer" target="_blank">https://lists.openwrt.org/pipermail/openwrt-devel/2016-January/039081.html</a>) as per Felix's<br>
comments this solution is based on procd interface service triggers<br>
<br>
package/utils/busybox/Makefile | 2 +-<br>
package/utils/busybox/files/sysntpd | 43 ++++++++++++++++++++++++++++++++-----<br>
2 files changed, 39 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile<br>
index 24c064c..24e0e11 100644<br>
--- a/package/utils/busybox/Makefile<br>
+++ b/package/utils/busybox/Makefile<br>
@@ -42,7 +42,7 @@ define Package/busybox<br>
MAINTAINER:=Felix Fietkau <<a href="mailto:nbd@openwrt.org">nbd@openwrt.org</a>><br>
TITLE:=Core utilities for embedded Linux<br>
URL:=<a href="http://busybox.net/" rel="noreferrer" target="_blank">http://busybox.net/</a><br>
- DEPENDS:=+BUSYBOX_USE_LIBRPC:librpc +BUSYBOX_CONFIG_PAM:libpam<br>
+ DEPENDS:=+BUSYBOX_USE_LIBRPC:librpc +BUSYBOX_CONFIG_PAM:libpam +jsonfilter<br>
MENU:=1<br>
endef<br>
<br>
diff --git a/package/utils/busybox/files/sysntpd b/package/utils/busybox/files/sysntpd<br>
index f73bb83..5c663d7 100755<br>
--- a/package/utils/busybox/files/sysntpd<br>
+++ b/package/utils/busybox/files/sysntpd<br>
@@ -7,13 +7,35 @@ USE_PROCD=1<br>
PROG=/usr/sbin/ntpd<br>
HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug<br>
<br>
+get_dhcp_ntp_servers() {<br>
+ local interfaces="$1"<br>
+ local filter="*"<br>
+ local network_dump interface ntpservers ntpserver<br>
+<br>
+ network_dump=$(ubus call network.interface dump)<br>
+ for interface in $interfaces; do<br>
+ [ "$filter" = "*" ] && filter="@.interface='$interface'" || filter="$filter,@.interface='$interface'"<br>
+ done<br>
+<br>
+ ntpservers=$(jsonfilter -s "$network_dump" -e "@.interface[$filter]['data']['ntpserver']")<br>
+<br>
+ for ntpserver in $ntpservers; do<br>
+ local duplicate=0<br>
+ local entry<br>
+ for entry in $server; do<br>
+ [ "$ntpserver" = "$entry" ] && duplicate=1<br>
+ done<br>
+ [ "$duplicate" = 0 ] && server="$server $ntpserver"<br>
+ done<br>
+}<br>
+<br>
validate_ntp_section() {<br>
uci_validate_section system timeserver "${1}" \<br>
- 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0'<br>
+ 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' 'use_dhcp:bool:0' 'dhcp_interface:list(string)'<br>
}<br>
<br>
start_service() {<br>
- local server enabled enable_server peer<br>
+ local server enabled enable_server use_dhcp dhcp_interface peer<br>
<br>
validate_ntp_section ntp || {<br>
echo "validation failed"<br>
@@ -22,6 +44,8 @@ start_service() {<br>
<br>
[ $enabled = 0 ] && return<br>
<br>
+ [ $use_dhcp = 1 ] && get_dhcp_ntp_servers "$dhcp_interface"<br>
+<br>
[ -z "$server" ] && return<br>
<br>
procd_open_instance<br>
@@ -35,8 +59,17 @@ start_service() {<br>
procd_close_instance<br>
}<br>
<br>
-service_triggers()<br>
-{<br>
- procd_add_reload_trigger "system"<br>
+service_triggers() {<br>
+ local script name<br>
+<br>
+ script=$(readlink -f "$initscript")<br>
+ name=$(basename ${script:-$initscript})<br>
+<br>
+ procd_open_trigger<br>
+ procd_add_config_trigger "config.change" "system" /etc/init.d/$name reload<br>
+<br>
+ procd_add_raw_trigger "interface.*" 2000 /etc/init.d/$name reload<br>
+ procd_close_trigger<br>
+<br>
procd_add_validation validate_ntp_section<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
_______________________________________________<br>
openwrt-devel mailing list<br>
<a href="mailto:openwrt-devel@lists.openwrt.org">openwrt-devel@lists.openwrt.org</a><br>
<a href="https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel" rel="noreferrer" target="_blank">https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel</a><br>
</font></span></blockquote></div><br></div>