netutils: add DHCP-provided NTP server for ntpc#3451
Conversation
|
Thank you @masc2008 very nice useful feature :-) |
oh, I can't image that you keep eyes on those PR in a so timely style. you just replied while I am still working on this PR. I am quite new to the PR process, thanks for understanding. |
no worries and have fun :-) i am just working on some NuttX code too :-) |
|
Can you please provide in the PR description runtime logs showing that/how the solution works? Can you please provide a documentation update with information about this feature? Thanks again @masc2008 :-) |
sure, will do it later. |
bbdb39f to
68ce878
Compare
masc2008
left a comment
There was a problem hiding this comment.
code should be ready now, will keep on working on doc later.
68ce878 to
a4873bb
Compare
updated in PR, added related info in PR. |
a4873bb to
b9b6ded
Compare
Request DHCP option 42 and store the returned IPv4 NTP server addresses in struct dhcpc_state for later consumers. Signed-off-by: Jerry Ma <masc2008@gmail.com>
sorry, I missed this one when last commit. |
9f18374 to
db11971
Compare
masc2008
left a comment
There was a problem hiding this comment.
updated version, please review.
Use the DHCP-learned NTP server list as the default ntpc server source when DHCP option 42 is available. Fall back to CONFIG_NETUTILS_NTPCLIENT_SERVER only when DHCP does not provide any NTP servers, and restart ntpc when the DHCP-provided server list changes. Signed-off-by: Jerry Ma <masc2008@gmail.com>
db11971 to
ae63429
Compare
|
@masc2008 nice work! Please update https://nuttx.apache.org/docs/latest/applications/system/ntpc/index.html to explain that NTP now can be provided over DHCP. Please include there the details you added here in the Summary. |
acassis
left a comment
There was a problem hiding this comment.
Please update Documentation/ (to reflect at https://nuttx.apache.org/docs/latest/applications/system/ntpc/index.html ) and include the details from Summary showing how to test it.
Here is doc: apache/nuttx#18752 |
|
@masc2008 you missed to reply @xiaoxiang781216 question about "g_dhcp_ntp_servers and g_dhcp_ntp_callback" |
|
@xiaoxiang781216 , @acassis
|
Please notice the "Pending" in the image. It means you forgot to submit the reply |


Summary
request and parse DHCP option 42 in
dhcpcstore DHCP-provided IPv4 NTP server addresses in
struct dhcpc_statepass the learned NTP server list through DHCP IPv4 bring-up
let
ntpcfall back to DHCP-provided servers whenCONFIG_NETUTILS_NTPCLIENT_SERVERis emptykeep configured NTP servers as the highest-priority source
If ntpc is running with the configured default and DHCP later provides NTP servers, ntpc restarts and
switches to the DHCP list.
If ntpc is already running with DHCP-provided servers and the DHCP NTP list changes, ntpc restarts
and uses the updated DHCP list.
If ntpc previously had no available server and did not start, receiving DHCP option 42 later will
automatically start ntpc.
If DHCP no longer provides NTP servers, ntpc falls back to CONFIG_NETUTILS_NTPCLIENT_SERVER when
configured.
Impact
ntpccan now use DHCP-provided NTP servers.CONFIG_NETUTILS_NTPCLIENT_SERVERis empty.Testing
I confirm that changes are verified on local setup:
arm/qemu-armv7a:full../nuttx/tools/checkpatch.sh -m -g HEAD~2..HEADarm/qemu-armv7a:fullstart dhcp server with dnsmasq:
dnsmasq --no-daemon --log-dhcp --log-queries \ --interface=tap0 --bind-interfaces \ --dhcp-authoritative \ --dhcp-range=192.168.50.20,192.168.50.50,255.255.255.0 \ --dhcp-option=option:router,192.168.50.1 \ --dhcp-option=option:dns-server,1.1.1.1 \ --dhcp-option=option:ntp-server,162.159.200.123related logs:
Details
dhcpc_request: Received ACK
dhcpc_request: Got IP address 192.168.50.42
dhcpc_request: Got netmask 255.255.255.0
dhcpc_request: Got DNS server 0: 1.1.1.1
dhcpc_request: Got NTP server 0: 162.159.200.123
dhcpc_request: Got default router 192.168.50.1
dhcpc_request: Lease expires in 3600 seconds
.
.
.
ntpc_daemon: NTP sample[0]: offset: 1.000 sec, round-trip delay: 0.056 sec
ntpc_daemon: NTP sample[1]: offset: 1.000 sec, round-trip delay: 0.057 sec
ntpc_daemon: NTP sample[2]: offset: 1.000 sec, round-trip delay: 0.056 sec
ntpc_daemon: NTP sample[3]: offset: 1.001 sec, round-trip delay: 0.057 sec
ntpc_daemon: NTP sample[4]: offset: 1.001 sec, round-trip delay: 0.059 sec
ntpc_settime: Set time to 1775977211.017 seconds (offset: 1.000).