UCI ntpclient configuration doesn't clear old configuration etc

Hi,

When I do UCI ntpclient configuration using code configuration, configuration file /etc/config/ntpclient still keep old configuration ( i.e. not clean the old configuration ). Please see below:

root@freewave-ib:/root# uci show ntpclient
ntpclient.@ntpserver[0]=ntpserver
ntpclient.@ntpserver[0].port='215'
ntpclient.@ntpserver[0].interface='0.0.0.0'
ntpclient.@ntpserver[0].hostname=' 4.3.2.1 12.13.14.15 9.0.9.0'
ntpclient.@ntpserver[1]=ntpserver
ntpclient.@ntpserver[1].port='123'
ntpclient.@ntpserver[1].hostname=' 222.222.222.222 0.0.0.1 5.5.5.5'
ntpclient.@ntpserver[2]=ntpserver
ntpclient.@ntpserver[2].port='123'
ntpclient.@ntpserver[2].hostname=' 0.0.0.1 5.5.5.5'
ntpclient.@ntpserver[3]=ntpserver
ntpclient.@ntpserver[3].port='123'
ntpclient.@ntpserver[3].hostname=' 5.5.5.5'
ntpclient.@ntpdrift[0]=ntpdrift
ntpclient.@ntpdrift[0].freq='0'

This doesn't happen to UCI network configuration by using code. ( UCI ntpclient code configuration is very
similar to UCI network code configuration).

Is there any solution on this?

Thanks,
Scott

https://openwrt.org/docs/guide-user/base-system/uci

uci commit

perhaps?

Without knowing the code you use it is hard to tell anything. But my guess is that you're using a mere uci add ntpserver to add a new section, without deleting old sections.

Try something like this:

# loop as long as we can delete an existing section of type ntpserver
while uci -q delete ntpclient.@ntpserver[0]; do
    :
done

# add a new ntpserver section and set values
uci add ntpclient ntpserver
uci set ntpclient.@ntpserver[0].port=215
uci set ntpclient.@ntpserver[0].hostname=1.2.3.4

I found out the reason. Please ignore the issue.

Jeff,

Thanks a lot! I have already found the reason, which has nothing to do with openwrt uci.

Thanks,

Scott

Jeff,

In my job, I have to port NTP code to openwrt environment, do you know how to convert this code

to openwrt uci equivalent:

"ntpdate -p8 any_net_work_time_server"

Linux ntpdate command option -p just mean "samples".

Thanks in advance!

Regards,

Scott

busybox version of ntp, not the "real" ntp, correct?

Personally, if you've got enough space in your build, I'd install the "real" ntpd, especially if time is important enough to you to request 8 samples from your reference time server.

I don't see a clear equivalent of the -pN option to ntpdate in the busybox-supplied version.

jeff@office:~$ sudo busybox ntpd --help
BusyBox v1.29.2 () multi-call binary.

Usage: ntpd [-dnqNwl -I IFACE] [-S PROG] [-p PEER]...

NTP client/server

	-d	Verbose (may be repeated)
	-n	Do not daemonize
	-q	Quit after clock is set
	-N	Run at high priority
	-w	Do not set time (only query peers), implies -n
	-S PROG	Run PROG after stepping time, stratum change, and every 11 mins
	-p PEER	Obtain time from PEER (may be repeated)
	-l	Also run as server on port 123
	-I IFACE Bind server to IFACE, implies -l

Jeff,

Thanks!

The only thing is that my supervisor doesn't allow me to use busybox.

He would like me to use UCI NTP configuration directly or through UBUS.

He even restrict me just use C/C++ to invoke UBUS's ubs_connect(), ubus_lookup_id(),

ubus_invoke() etc. UBUS code. However, if you can tell me how to use

UCI command line directly, I can figure out how to translate to code.

The major thing that I am not clear is:

how to specify "ntp .. server"'s server.

Is the server equivalent to:

UCI's ntpclient.@ntpclient[0].interface

or

UCI's ntpclient.@ntpserver[0], {1], {2], {3].

I thought that it seems the ntpclient.@ntpclient[0].interface because it also allow user

to specify options count and samples. ( Can the interface representing a server. From

network viewpoint, that is true because server use one interface IP address as it's

IP addrss.)

However, Linux ntpdate allows you to specify more than one server in ntpdate command line.

so I am confusing!

The other thing bothers me is that if it means ntpclient.@ntpserver[], then how do you invoke

them in the code to simulate the "ntpdate ... server1 server2 ..."

Many thanks,

Scott

The config files can be "edited" through UCI -- https://openwrt.org/docs/guide-user/base-system/uci

The times I've worked with it have taken some poking about to get the right order of commands and creating/selecting lists of things, but it is a very functional interface to the config.

https://openwrt.org/docs/guide-user/advanced/ntp_configuration may help with the variables, along with looking at the config that LuCI generates.

Jeff,

What's the difference between busybox ntp and "real" ntp?

My supervisor would like to use UCI/UBUS compatible code in openwrt. The "ntpdate -p" command was used in embedded Linux, not openwrt Linux.

Also, is busybox implementation based on UCI/Ubus? The reason that I am asking this question is because busybox seems exist beyond openwrt and

we will only use openwrt UCI/Ubus compatible implementation in openwrt environment ( according to my suoervisor ).

Many thanks,

Scott

"Real" NTP to me is that of or based on the reference implementation of NTPv4. The package ntpd for OpenWrt uses reference-implementation sources.

busybox implements probably something like 90% if the executables on OpenWrt. In general, the busybox "applets" are functional for the basic purposes needed, but usually lacking in functionality past that.

https://busybox.net/about.html
https://busybox.net/tinyutils.html

In my experience the ntp implementation in busybox is functional, but not as accurate or robust as that of the reference implementation, nor as flexible. For most people looking for synchronization to a couple tenths of a second, it is generally sufficient.

I have no idea what

means in your situation. Both the "real" and the busybox implementation can be configured with UCI and started with procd. How ubus fits into your requirements, you'll have to get clarification from your supervisor as, for most applications, ubus is completely behind the scenes or doesn't come into play at all.

Jeff,

Do you know which script or file during system boot/initialization invoke /etc/config/ntpclient?

I don't see /etc/init.d nor /usr/sbin/ntpd-hotplug invoking /etc/config/ntpclient.

/etc/config/ntpclient is openwrt ntp configuration file, why no script/file invoke it?

Thanks,

Scott

fgrep and find are tools that can often answer these questions.

root@OpenWrt:/etc# fgrep -ri ntp /etc

quickly reveals

/etc/init.d/sysntpd:PROG=/usr/sbin/ntpd

among other references.


root@OpenWrt:/etc# find /rom -iname '*ntp*'
/rom/etc/hotplug.d/ntp
/rom/etc/init.d/sysntpd
/rom/etc/rc.d/S98sysntpd
/rom/usr/sbin/ntpd
/rom/usr/sbin/ntpd-hotplug

is fast and effective when you can guess the name of the file.

Jeff,

Many thanks,

I believe that /usr/sbin/ntpd is not busybox ( openwrt) ntpd. It reads configuration file from /etc/init.d/ntp.conf.

( If you type /usr/sbin/ntpd, the manual page is going to mention the configuration file as /etc/init.d/ntp.conf.)

However, openwrt UCI's configuration file is located at /etc/config/network/ntpclient

By the way, what's the difference between /etc/init.d/syntpd and busybox's ntpd ( I believe that it is located in /bin )

Many thanks!

Regards,

Scott

Past that one is a start-up script and one is an executable, you can examine the various start-up scripts and see which executables they run and how any needed configuration files are created. I believe the start-up script for the busybox version of ntpd is sysntpd