[packages] ntpclient: add option to bind ntpclient to a specific interface (#6470)
[openwrt/svn-archive/archive.git] / net / ntpclient / files / ntpclient.hotplug
index 87f0c0c0e39d197021d4f392d67b9e2028d77f0e..c932688c9a951233d36ea6d6c6c75aaec3d168f4 100644 (file)
@@ -7,16 +7,28 @@ unset SERVER
 unset PORT
 unset INTERVAL
 unset COUNT
+unset INTERFACE_GLOBAL
+
 NTPC=`which ntpclient`
 
 check_server() {
        local hostname
        local port
+       local interface
        [ -n "$SERVER" ] && return
        config_get hostname $1 hostname
        config_get port $1 port
+       config_get interface $1 interface
+
+       [ -z "$interface" ] && interface=$INTERFACE_GLOBAL
+
+       [ -n "$interface" ] && {
+               # $INTERFACE is passed from hotplug event
+               [ "$interface" = "$INTERFACE" ] || return
+       }
+
        [ -z "$hostname" ] && return
-       $NTPC -c 1 -p ${port:-123} -h $hostname > /dev/null && { SERVER=$hostname; PORT=${port:-123}; }
+       $NTPC -c 1 -p ${port:-123} -i 2 -h $hostname > /dev/null && { SERVER=$hostname; PORT=${port:-123}; }
 }
 
 set_drift() {
@@ -29,7 +41,7 @@ start_ntpclient() {
        config_foreach check_server ntpserver
        [ -z "$SERVER" ] && exit 0
        logger starting ntpclient
-       $NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -D -p $PORT -h $SERVER 2> /dev/null
+       $NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -s -l -D -p $PORT -h $SERVER 2> /dev/null
 }
 
 stop_ntpclient() {
@@ -44,20 +56,21 @@ load_settings() {
        
        config_get interval $1 interval
        config_get count $1 count
+       config_get interface $1 interface
        
        [ -n "$count" ] && COUNT=$count
        [ -n "$interval" ] && INTERVAL=$interval
+       [ -n "$interface" ] && INTERFACE_GLOBAL=$interface
 }
 
 config_load ntpclient
 config_foreach load_settings ntpclient
 
-DEF_ROUTE=`route -n | grep '^0.0.0.0'`
 NTP_RUNNING=`ps  | grep $NTPC | grep -v grep`
 
 case "${ACTION:-ifup}" in
        ifup)
-               [ -n "$DEF_ROUTE" -a -z "$NTP_RUNNING" ] && start_ntpclient 
+               [ -z "$NTP_RUNNING" ] && start_ntpclient 
        ;;
        ifdown)
                [ -n "$NTP_RUNNING" ] && stop_ntpclient