WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: enhance parsing dhcp supplied ntp-servers option  (Read 479 times)

Offline miesi

  • Newbie
  • *
  • Posts: 3
enhance parsing dhcp supplied ntp-servers option
« on: May 03, 2024, 02:03:09 AM »
When I log into piCorePlayer (based on tcl) I'm greeted with

The system date (Thu Jan  1 01:16:30 CET 1970) appears to be incorrect.
The current ntp server is being set to 10.2.215.5 10.2.215.10, by kernel commandline or dhcp.

Execute the command: 'sudo ntpd -dd -n -q -p 10.2.215.5 10.2.215.10' to debug.

my dhcpd.conf reads

option ntp-servers 10.2.215.5, 10.2.215.10;

sudo ntpd -dd -n -q -p 10.2.215.5 -p 10.2.215.10

would work.

Where can I find the source code of the tcl scripts as git so that I can provide a merge request with an enhanced script?

Offline miesi

  • Newbie
  • *
  • Posts: 3
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #1 on: May 03, 2024, 02:26:46 AM »
Changing /usr/bin/getTime.sh to someting like this should do the trick
Code: [Select]
#!/bin/busybox ash
# bmarkus - 26/02/2014
# miesi - 03/05/2024

if [ -f /etc/sysconfig/ntpserver ]; then
        set $(cat /etc/sysconfig/ntpserver)
        while [ "$1" != "" ]; do
                NTPOPTS="$NTPOPTS -p $1"
                shift
        done
else
        NTPOPTS=""
fi
/usr/sbin/ntpd -q $NTPOPTS

I have no practical experience with busybox ash so this might not work

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14572
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #2 on: May 03, 2024, 03:23:33 AM »
Where can I find the source code of the tcl scripts as git so that I can provide a merge request with an enhanced script?

https://github.com/tinycorelinux

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #3 on: May 03, 2024, 05:58:50 AM »
hi miesi,

Use https://forums.slimdevices.com/ for piCorePlayer support.

This forum is for piCore only.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11257
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #4 on: May 03, 2024, 06:53:46 AM »
Hi Greg Erskine
True, but the issue miesi reported and offered a fix for is
relevant to piCore and Tinycore too, not just piCorePlayer.

The ntp daemon can handle multiple time sources:
Code: [Select]
tc@E310:~$ ntpd --help
BusyBox v1.29.3 (2018-12-19 15:29:37 UTC) multi-call binary.

 ----- Snip -----

        -p PEER Obtain time from PEER (may be repeated)

 ----- Snip -----
The fix is designed to handle multiple entries separated by spaces
and preceding each entry with a  -p  switch.

The parsing code appears fine and worked correctly when tested.

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #5 on: May 03, 2024, 07:54:10 AM »
Hi Rich,

We have been working on various issues with setting the time properly for years on piCorePlayer.

There has been a lot of discussions over on the Slimdevices forum, very little here.

I think the multiple server issue raised here may have already been implemented in piCorePlayer by Paul. I know we discussed it over a year ago.

regards
Greg

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1089
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #6 on: May 03, 2024, 08:00:00 AM »
It sort of applies, but since piCore/Tinycore doesn't include a udhcpc script to process ntp from dhcp, more needs to be done.

https://github.com/tinycorelinux/Core-scripts/blob/master/usr/share/udhcpc/default.script

piCorePlayer has a completely different implementation for dhcp/ntp.

Offline miesi

  • Newbie
  • *
  • Posts: 3
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #7 on: May 05, 2024, 04:03:44 AM »
Ok, I hope I get this rght now:
For some reason the tcl git contains getTime.sh ... but it is not used for piCore/Tinycore.

First I'll raise a pr to implement better handling if getTime.sh is actually used.

Then I'll see what my time budget allows.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11257
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #8 on: May 05, 2024, 07:15:39 AM »
Hi miesi
Both piCore and Tinycore have getTime.sh present when
they boot up, which is why I felt your post was relevant.

... but it is not used for piCore/Tinycore. ...
I think it was originally created by bmarkus to set the current
time on pi zero.

As near as I can tell, getTime.sh is an option for individuals who
want a convenient way to set their systems clock.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1089
Re: enhance parsing dhcp supplied ntp-servers option
« Reply #9 on: May 05, 2024, 07:41:16 AM »
It is a relevant, just not a complete fix.  The change posted won’t alone do anything, since getTime will never get anything from dhcp without changing that too.

Tinycore/piCore has always used a bootcode to specify the ntpserver.  So if we want to change how this works, it needs to be a complete solution.  I have seen routers advertise incorrect ntp servers via dhcp.  (Amazon eero routers for one). So the bootcode needs to be first priority.