Allow busybox to act as a stratum 1 server if no peer is specified on the command line.
This allow busybox to act as a time reference in an isolated network where it is not possible to reach a real stratum server through the IP network. For this feature to work correctly the busybox system needs to be synchronized to a real time source through other means like for example a GPS device. Signed-off-by: Jean-Christophe DUBOIS <[email protected]> --- networking/Config.src | 10 ++++++++++ networking/ntpd.c | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/networking/Config.src b/networking/Config.src index 4494362..3cd1ce9 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -665,6 +665,16 @@ config FEATURE_NTPD_SERVER Make ntpd usable as a NTP server. If you disable this option ntpd will be usable only as a NTP client. +config FEATURE_NTPD_STRATUM_1 + bool "Make ntpd usable as a standalone stratum 1 NTP server" + default n + depends on FEATURE_NTPD_SERVER + help + Make ntpd usable as a standalone STRATUM 1 NTP server. + In this mode ntpd can work without any peer defined on the + command line. The system is assumed to get its time synchronized + through other means such as GPS. + config PING bool "ping" default y diff --git a/networking/ntpd.c b/networking/ntpd.c index 0f0772b..c49e7d6 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1763,6 +1763,11 @@ recv_and_process_client_pkt(void /*int fd*/) msg.m_stratum = G.stratum; msg.m_ppoll = G.poll_exp; msg.m_precision_exp = G_precision_exp; +#ifdef CONFIG_FEATURE_NTPD_STRATUM_1 + if (G.stratum == 1) { + G.reftime = gettime1900d(); /* sets G.cur_time too */ + } +#endif /* this time was obtained between poll() and recv() */ msg.m_rectime = d_to_lfp(G.cur_time); msg.m_xmttime = d_to_lfp(gettime1900d()); /* this instant */ @@ -1940,12 +1945,24 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) ntp_init(argv); - /* it is useless to continue if no peer is defined */ - /* if in server mode, we will never sync */ - /* if in client mode, we will never sync */ if (G.peer_cnt == 0) { +#ifdef CONFIG_FEATURE_NTPD_STRATUM_1 + /* + * No peer is defined on the command line. So this is + * an isolated system and we will pretend being a + * stratum 1 assuming our local clock is correctly + * synchronized through another mean (like GPS). + */ + G.stratum = 1; +#else + /* + * it is useless to continue if no peer is defined + * if in server mode, we will never sync + * if in client mode, we will never sync + */ bb_error_msg("no peer defined"); return -EINVAL; +#endif } /* If ENABLE_FEATURE_NTPD_SERVER, + 1 for listen_fd: */ -- 1.7.0.4 _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
