Modify

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#7316 closed enhancement (fixed)

[patch] enhance rdate to ntpclient functionality (interface, interval)

Reported by: Maddes <maddes_trac@…> Owned by: developers
Priority: normal Milestone: Backfire 10.03.1
Component: base system Version: Trunk
Keywords: Cc:

Description

The patch was created to save flash space by using BusyBox's rdate instead of installing ntpclient (and dependencies).
Prerequisite is #7312.

As several programs need the correct time (e.g. OpenVPN) the changes also allow to re-use the hotplug script for cron jobs or a manual update:

( INTERFACE=wan ; . /etc/functions.sh ; . /etc/hotplug.d/iface/40-rdate; )

Changes:

  • the route/grep check did not work on devices without inet access that should be synced with local ntp servers.
    Also with a tun device for a VPN server a gateway is always present.
    Therefore the required interface can be defined in system.@rdate[0].interface and defaults to "wan".
  • the ntpclient functionality to define the ntp server for a specific interface was added.
  • the ntp servers are stored in a separate config, so it can be re-used by the ntpclient package. Additionally this should also reduce JFFS2 usage, as the system config is often change (e.g. timezone) but not the ntp servers.
  • ntp servers from OpenWrt's ntp.org pool are used to further reduce space consumption (smaller list)

Attachments (4)

rdate_like_ntpclient.r21403.patch (3.3 KB) - added by Maddes <maddes_trac@…> 8 years ago.
-p0 patch for trunk/backfire. Adds ntpclient functionality to rdate
base_files_bump_rdate.r21403.patch (398 bytes) - added by Maddes <maddes_trac@…> 8 years ago.
-p0 patch for trunk/backfire. Bump release number.
rdate_like_ntpclient_v2.r21425.patch (4.2 KB) - added by Maddes <maddes_trac@…> 8 years ago.
-p0 patch for trunk/backfire. Adds ntpclient functionality to rdate
rdate_like_ntpclient_v21.r21425.patch (4.2 KB) - added by Maddes <maddes_trac@…> 8 years ago.
-p0 patch for trunk/backfire. Final, replaces all previous patches. Adds ntpclient functionality to rdate and higher reliability.

Download all attachments as: .zip

Change History (23)

Changed 8 years ago by Maddes <maddes_trac@…>

-p0 patch for trunk/backfire. Adds ntpclient functionality to rdate

Changed 8 years ago by Maddes <maddes_trac@…>

-p0 patch for trunk/backfire. Bump release number.

comment:1 Changed 8 years ago by jow

Somehow your patch does not make sence. The rdate applet *does not* support ntp, you can't just let it query ntp servers, it won't work for the majority of hosts in the pools.

comment:2 Changed 8 years ago by anonymous

Hi,
unfortunately most of the servers in the default config don't seem to work anyhow.
Please, please consider using busybox (1.16) ntpd applet. rdate is way outdated...

comment:3 Changed 8 years ago by Maddes <maddes_trac@…>

OpenWrt currently uses 1.15, so now ntpd applet yet. But I will keep this in mind when it gets updated. Thanks.

Also reworked my patch for time servers (v2).

The original timeserver pools work well with rdate, but rarely it doesn't, but over the day it works much more than it doesn't.

Changed 8 years ago by Maddes <maddes_trac@…>

-p0 patch for trunk/backfire. Adds ntpclient functionality to rdate

comment:4 Changed 8 years ago by Maddes <maddes_trac@…>

Here's an example output of the current script:

root@OpenWrt:/# logread | grep rdate
May 11 21:10:35 OpenWrt user.notice rdate: No usable time server for loopback found
May 11 21:10:41 OpenWrt user.notice rdate: Synced with cudns.cit.cornell.edu
May 11 21:17:01 OpenWrt cron.err crond[1153]: USER root pid 2315 cmd ( INTERFACE=`uci -q get system.@rdate[0].interface` ; check_ifup.sh $INTERFACE && { . /etc/functions.sh ; . /etc/hotplug.d/iface/40-rdate; } )
May 11 21:17:02 OpenWrt user.notice rdate: Failed to sync with ac-ntp1.net.cmu.edu
May 11 21:17:02 OpenWrt user.notice rdate: Synced with ptbtime1.ptb.de
May 11 22:17:01 OpenWrt cron.err crond[1153]: USER root pid 2405 cmd ( INTERFACE=`uci -q get system.@rdate[0].interface` ; check_ifup.sh $INTERFACE && { . /etc/functions.sh ; . /etc/hotplug.d/iface/40-rdate; } )
May 11 22:17:02 OpenWrt user.notice rdate: Failed to sync with ac-ntp0.net.cmu.edu
May 11 22:17:02 OpenWrt user.notice rdate: Failed to sync with ptbtime3.ptb.de
May 11 22:17:03 OpenWrt user.notice rdate: Synced with cudns.cit.cornell.edu
...
May 12 03:17:01 OpenWrt cron.err crond[1153]: USER root pid 2767 cmd ( INTERFACE=`uci -q get system.@rdate[0].interface` ; check_ifup.sh $INTERFACE && { . /etc/functions.sh ; . /etc/hotplug.d/iface/40-rdate; } )
May 12 03:17:01 OpenWrt user.notice rdate: Failed to sync with ptbtime3.ptb.de
May 12 03:17:02 OpenWrt user.notice rdate: Synced with cudns.cit.cornell.edu
...
May 12 08:17:01 OpenWrt cron.err crond[1153]: USER root pid 2959 cmd ( INTERFACE=`uci -q get system.@rdate[0].interface` ; check_ifup.sh $INTERFACE && { . /etc/functions.sh ; . /etc/hotplug.d/iface/40-rdate; } )
May 12 08:17:02 OpenWrt user.notice rdate: Failed to sync with ac-ntp0.net.cmu.edu
May 12 08:17:02 OpenWrt user.notice rdate: Synced with ptbtime1.ptb.de
May 12 09:17:01 OpenWrt cron.err crond[1153]: USER root pid 2977 cmd ( INTERFACE=`uci -q get system.@rdate[0].interface` ; check_ifup.sh $INTERFACE && { . /etc/functions.sh ; . /etc/hotplug.d/iface/40-rdate; } )
May 12 09:17:01 OpenWrt user.notice rdate: Failed to sync with ptbtime3.ptb.de
May 12 09:17:02 OpenWrt user.notice rdate: Synced with cudns.cit.cornell.edu

comment:5 Changed 8 years ago by anonymous

Hi,
according to ticket 7054 a3 out of 7 from the serverlist don't support rdate any longer. And if randomness strikes lucky ....

comment:6 Changed 8 years ago by anonymous

Hi again,

these servers seem to work atm, maybe change the defaults for a quick fix

tick.greyware.com
ptbtime1.ptb.de
ntp.xs4all.nl
ptbtime2.ptb.de
cudns.cit.cornell.edu

comment:7 Changed 8 years ago by Maddes <maddes_trac@…>

The current list is quite ok as most servers from these pools(!!!) support time protocol.
It's really a rare situation that all seven pools miss.

If tick.greyware.com is also working most of time then it should be added.

I think the situation will definitely change if BusyBox 1.16 will be adopted by the OpenWrt team.

comment:8 Changed 8 years ago by anonymous

Hi
as you say "...most of the time..." why then keep the ones that definitely don't serve rdate any longer? they have proven not to work some time ago and they don't work atm...

comment:9 Changed 8 years ago by Maddes <maddes_trac@…>

Tested tick.greyware.com for 2 days every 30 mins without any problems.
In conjunction with my updated script the clock sync is done every time.

If any 100% time protocol server are known then they should be added to the list.

Changed 8 years ago by Maddes <maddes_trac@…>

-p0 patch for trunk/backfire. Final, replaces all previous patches. Adds ntpclient functionality to rdate and higher reliability.

comment:10 Changed 8 years ago by Maddes <maddes_trac@…>

Reviewed all my patches uci_get_state() should be used for getting "network.$INTERFACE.lease_timesrv".

comment:11 Changed 8 years ago by jow

  • Resolution set to fixed
  • Status changed from new to closed

Committed in r21495 - thanks!

comment:12 Changed 8 years ago by hschupp

Will this be backported to 10.3?
Is it compatible?
Please advise

comment:13 Changed 8 years ago by maddes

I developed it on the Backfire branch, and I hope it will get added to Backfire after some testing time in trunk.

You can just update the scripts on your router to use it.
Also check out this forum thread how I re-use the hotplug script for a cron job.
Please report your experience after some days (check with "logread | grep rdate", try rebooting and restarting network).

See these files from r21495 and r21489:

comment:14 Changed 8 years ago by anonymous

Trunk uses now BusyBox 1.16 so replacing rdate with ntpd from BusyBox is possible now (see comment:2)

comment:15 follow-up: Changed 7 years ago by z80yyz <gerrit@…>

Please re-open and apply the attached patch. Rdate was not using any servers in the list because they were not being added to the internal array. (Control never reached that line of code). Moving the 'add to array list' line fixes the problem.

comment:16 in reply to: ↑ 15 Changed 7 years ago by z80yyz <gerrit@…>

Replying to z80yyz <gerrit@…>:
Couldn't add file so putting the patch inline:

--- 40-rdate    2010-08-06 20:02:34.000000000 -0400
+++ /tmp/40-rdate       2010-09-07 16:05:27.000000000 -0400
@@ -27,10 +27,10 @@
        config_get iface "$section" interface
        [ -z "$iface" ] && iface=$IFACE_GLOBAL
        [ -n "$iface" ] && {
+               SERVERS="${SERVERS} $server"; : $((MAX++))
                [ "$iface" = "$INTERFACE" ] || return
        }

-       SERVERS="${SERVERS} $server"; : $((MAX++))
 }

 sync_time()

comment:17 Changed 7 years ago by z80yyz <gerrit@…>

Please ignore this reopen request, figured out my error in /etc/config/system.... was using eth0 instead of lan.

comment:18 Changed 7 years ago by jow

See r22975.

comment:19 Changed 7 years ago by maddes

To z80yyz:
normally the correct interface is "wan" on a router.
If another device is establishing your internet connection or you have a local ntp server, then "lan" would be correct.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.