From patchwork Thu May 19 16:57:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 624159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (caladan.dune.hu [78.24.191.180]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r9chH2QPqz9sCy for ; Fri, 20 May 2016 02:58:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=vCP4Ch4d; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 350F2B916AD; Thu, 19 May 2016 18:58:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Thu, 19 May 2016 18:58:01 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 85581B916A6 for ; Thu, 19 May 2016 18:57:59 +0200 (CEST) X-policyd-weight: using cached result; rate: -7 Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 19 May 2016 18:57:58 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id s63so8047069wme.2 for ; Thu, 19 May 2016 09:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ejY9RoAJ72ooh41X7VFvadcFtXfJCp0LVGPbPT9APBQ=; b=vCP4Ch4dn/zadAq0obtdvoGQo9d4B8tyvhNcDAOj96wsl0B/SRHZPXVBnZtQe+EQDX Eg13tOawJmhi45p5Cy3OUEQXMOIjbsyz0cbLzLOheprpPkU7UGRbZBGhAOi0rsa1JPyZ hzBLoChAaLeJ9yQ4ZiXzFj24lOXd4GXEJFg4c8ar3kaeWmEDDSneMD9t4wp2xfUb+5g/ 0o3rhbYIsWOLQbFK8d1Ompm0AAAQYMSkhTY7gXKaRvB2w8RWLQPWZlcUGfOmvmIJKxd4 4J+P8CjZqwJ/EFtytamHnxn0joSumrqLBC3OH4iJrePKvVBjR4MGCg3oHbRVcpcQ0lJq 5FIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ejY9RoAJ72ooh41X7VFvadcFtXfJCp0LVGPbPT9APBQ=; b=m76zV8or9SPgKMdA+ZNyZybBm5bACKeYH3JbdbKN5cLwD3brADSpFgTBFKHWdnoXt7 UbQdxqprD+QZNdADbEh21edESxHYn6t5zDBJEwxw8XPN0vRZVzVw/voZhvcZpDch/kC3 iZarzh360y3V9oBiznLK8Ja6OnGNgdZa2ThOvowYEDjcjfYu/kmVsoDvQK463oMfHKFQ pqSWMPQv0E9ISjk4UnMuj5RFsIBH6Ex4WFdqBMle2DdFzOtzd1hVPgTQnbG76asBkwwk HDQZGx+RN2Wc+hIwR/faGMl7T1uQt/ZW9xB0acHNWgO4+U3ulYY3RxzfQKj2gVDOT5rp vhTQ== X-Gm-Message-State: AOPr4FXFWrpaOubtDMU6g/WLjF9eet1kRsBWdlCRP6bHHY/WCJukyObKFXNBggVfLfpZSA== X-Received: by 10.194.85.132 with SMTP id h4mr14511403wjz.50.1463677078475; Thu, 19 May 2016 09:57:58 -0700 (PDT) Received: from cplx43.eu.thmulti.com ([141.11.62.7]) by smtp.gmail.com with ESMTPSA id ib1sm15307126wjb.48.2016.05.19.09.57.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 May 2016 09:57:57 -0700 (PDT) From: Hans Dedecker To: lede-dev@lists.infradead.org, openwrt-devel@lists.openwrt.org Date: Thu, 19 May 2016 18:57:51 +0200 Message-Id: <1463677071-17121-1-git-send-email-dedeckeh@gmail.com> X-Mailer: git-send-email 1.9.1 Subject: [OpenWrt-Devel] [PATCH] busybox: sysntpd - Support for NTP servers received via DHCP(v6) X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Dedecker , steven@midlink.org MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 --- The patch is based on a previous discussion held on the OpenWRT-devel mailing list (https://lists.openwrt.org/pipermail/openwrt-devel/2016-January/039081.html) as per Felix's comments this solution is based on procd interface service triggers package/utils/busybox/Makefile | 2 +- package/utils/busybox/files/sysntpd | 43 ++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile index 24c064c..24e0e11 100644 --- a/package/utils/busybox/Makefile +++ b/package/utils/busybox/Makefile @@ -42,7 +42,7 @@ define Package/busybox MAINTAINER:=Felix Fietkau 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 +jsonfilter MENU:=1 endef diff --git a/package/utils/busybox/files/sysntpd b/package/utils/busybox/files/sysntpd index f73bb83..5c663d7 100755 --- a/package/utils/busybox/files/sysntpd +++ b/package/utils/busybox/files/sysntpd @@ -7,13 +7,35 @@ USE_PROCD=1 PROG=/usr/sbin/ntpd HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug +get_dhcp_ntp_servers() { + local interfaces="$1" + local filter="*" + local network_dump interface ntpservers ntpserver + + network_dump=$(ubus call network.interface dump) + for interface in $interfaces; do + [ "$filter" = "*" ] && filter="@.interface='$interface'" || filter="$filter,@.interface='$interface'" + done + + ntpservers=$(jsonfilter -s "$network_dump" -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:0' '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 +44,8 @@ start_service() { [ $enabled = 0 ] && return + [ $use_dhcp = 1 ] && get_dhcp_ntp_servers "$dhcp_interface" + [ -z "$server" ] && return procd_open_instance @@ -35,8 +59,17 @@ start_service() { procd_close_instance } -service_triggers() -{ - procd_add_reload_trigger "system" +service_triggers() { + local script name + + script=$(readlink -f "$initscript") + name=$(basename ${script:-$initscript}) + + procd_open_trigger + procd_add_config_trigger "config.change" "system" /etc/init.d/$name reload + + procd_add_raw_trigger "interface.*" 2000 /etc/init.d/$name reload + procd_close_trigger + procd_add_validation validate_ntp_section }