Re: Question about NTP via DHCP - RFC 2132
Roy Marples
Fri Jul 24 11:10:29 2020
On 24/07/2020 10:22, Stefano Cappa wrote:
Hi Roy,
finally I worked on this topic and I discovered that systemd-timesyncd already
has fallback servers.
It's not working exactly as fallback as I thought, but better than nothing.
To do that I have to reload systemd configuration, because there is no way to do
it dynamically at runtime.
I also upgraded to the latest dhcpcd 9.x.x and it's working perfectly.
Good :)
I have 3 questions:
1) Which dhcpcd events should I listen to in my hook file?
Because in my dhcpcd hook, I trigger the update of systemd configuration passing
new_ntp_servers when $if_up is true, but for sure I have to listen for other
changes, in particular about $reason values.
I suppose that I should also handle BOUND, RENEW, REBIND and REBOOT reasons.
Do you have suggestions about this?
$if_up = true is mainly based on $reason so you don't have to worry too much
about $reason.
$if_up means we have something working.
A NTP server may or may not be given, so you then need to test $new_ntp_servers.
2) Based on your experience, do you know which router is able to set a custom
NTP server and send it via DHCP? Because, It's very difficult to work on this
without being able to try it in a real network. I found Cisco routers, but I
prefer to find something cheaper like a domestic/home router, because I need it
only to test my configuration.
There are many many different routers, and with the prevlance of open source
people can build their own (like me) to their own specification.
The answer simply is, you just don't know.
All you can do is ask for a NTP server in the DHCP request. If you get
$new_ntp_servers then you can be pretty sure there *should* be a NTP server at
that address. If you get nothing then you can be pretty sure there is no NTP
server for you to use - that doesn't not mean one does not exist, but there is
no other mechanism to detect it short of listen for NTP on the wire which is
outside the scope of dhcpcd.
3) Which is the best way to log DHCP packets on my device with dhcpcd to
understand if it's really receiving an NTP via DHCP?
/var/db/dhcpcd/$interface.lease is the raw DHCP message from the wire.
You could parse this with dhcpcd like so
cat /var/db/dhcpcd/$interface.lease | dhcpcd -U4
But the output would be no different from the env variables inside the hook
script - minus the new/old prefixes.
Or could you run this in another process:
tcpdump -s0 -w/tmp/dhcp.cap -i $interface port bootpc
That would store the full on wire packet including IP and UDP headers which the
dhcpcd lease file doesn't have. You could then view this capture in wireshark.
However, that would be all DHCP requests your interface see's - including
messages to/from other hosts to/from other hosts. You would need to filter yours
by hardware address, clientid, etc.
But please be sure - if new_ntp_servers is empty, the NTP server really isn't
there. The DHCP -> env var parser in dhcpcd has proven to be best in class.
Roy
Archive administrator: postmaster@marples.name