OpenWrt Forum Archive

Topic: Ntpd and ntpclient with no WAN connection at boot

The content of this topic has been archived on 9 Feb 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have just installed RC5, and I am testing it in an "unfriendly" environment. I am trying to set up openwrt so that if the internet connection is not available at boot, it still can start correctly and become fully functional when internet connection becomes available. I am having issues with setting the time in this process.


Question 1:

I have installed openntpd, then checked if it works (it does) and then removed the WAN cable and reboot. 20 minutes after reboot, I have plugged in the WAN interface, and found that ntpd (that's still running) cannot successfully set time, even if it can now reach the time servers.

From times to times, it tries to adjust time and fails like this:

Jan  1 00:23:15 (none) kern.info /usr/sbin/ntpd[583]: adjusting local clock by 197191402.822987s
Jan  1 00:23:15 (none) kern.crit /usr/sbin/ntpd[583]: adjtime failed: Invalid argument

So it seems that ntpd can set time properly only at startup, and cannot set it if it tries after 20 minutes from the startup.

Why?


Question 2:

ntpclient (not ntpd) takes its ntp server from a nvram variable, that contains two ip addresses by default (at least on the Asus WL500G Deluxe that I am installing on). I thought about using "pool.ntp.org" instead of these IP addresses, but what happens if the DNS resolution is not available when ntpclient starts? I mean, if I connect the WAN interface some times after starting ntpclient, can it solve the hostnames, or must I restart it?

Q1) Try running it via a cron script.
Q2) I believe udhcpc will check every minute or so for a WAN connection.. when it finds it, it gets its DNS servers then. If you have ntpclient in chron also, you should be good.

- Yasha

Yes, using ntpclient in cron seems to be the only thing that works.

Anyway, there are still issues with ntpd, because it does not work at all if it cannot reach time servers at startup. Even after having set up the clock using ntpclient, ntpd still goes on saying:

Apr  1 07:55:08 (none) kern.info /usr/sbin/ntpd[583]: adjusting local clock by 197191402.818977s
Apr  1 07:55:08 (none) kern.crit /usr/sbin/ntpd[583]: adjtime failed: Invalid argument

You can see that time is now set correctly, and ntpd should NOT tell that it tries to adjust clock by 197 million seconds, and also should not fail.

This seems like something we need to fix somehow.

Seems like a bug in the code somewhere, yes.

What I find interesting is that in the hardware arena PCs for over 10 years now have had "wake on LAN' and "wake on modem" ability, but there's no software I know of that accepts an input (socket or signal) that tells it "you're good to go now".

It would be a good idea to have notify hooks in udhcpc or whatever that would tell local processes that a connection to the rest of the world is now available.  As a standard API or some other mechanism.

The discussion might have continued from here.