dhcpcd-discuss

Re: Question about NTP via DHCP - RFC 2132

Stefano Cappa

Fri Jul 24 13:47:49 2020

Ok,
thanks for all the info about debugging.

I add some comments/other questions below.


> > 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.
>

How many times dhcpcd calls my custom hook? I suppose multiple times, or am
I wrong?
If dhcpcd calls the hook multiple times and $if_up is always true, I'll
restart my ntp service many times.
To prevent this, is it right to compare "old_" and "new_" ntp_servers
variables to understand if something is changed to decide if I should
reboot systemd or not?
Obviously, as you suggested, I should also check if the variable is empty.

All this discussion is about my worries about runtime/live changes of the
router configuration. Because, if I change NTP on the router, I expect that
my device with dhcpcd will always receive and update the new NTP via DHCP
packet. But obviously, I don't want to restart NTP daemon if there are no
real reasons to do it.


> 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.
>

"The answer simply is, you just don't know." I absolutely agree with this
and I have to trust in dhcpcd.
But my question was more about to find a commercial router that I can buy
without spending too much money to try my configuration.
Because at the moment I don't have any physical router that can set NTP via
DHCP. I found only routers able to set the local time, but not an ip
address. Also searching on the web I found only some professional Cisco
routers, but not something cheaper to buy. I'm really surprised that this
feature is so uncommon on domestic routers.
If you have this information, can you suggest, also privately, the model of
router available on the market that can let me try this feature on a real
network? At least, to check if what I've done is really working, because
now I'm simulating everything and I don't really trust what I've done.





Il giorno ven 24 lug 2020 alle ore 12:10 Roy Marples <roy@xxxxxxxxxxxx> ha
scritto:

> 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
>

Follow-Ups:
Re: Question about NTP via DHCP - RFC 2132Roy Marples
References:
Question about NTP via DHCP - RFC 2132Stefano Cappa
Re: Question about NTP via DHCP - RFC 2132Roy Marples
Re: Question about NTP via DHCP - RFC 2132Neal P. Murphy
Re: Question about NTP via DHCP - RFC 2132Stefano Cappa
Re: Question about NTP via DHCP - RFC 2132Stefano Cappa
Re: Question about NTP via DHCP - RFC 2132Roy Marples
Archive administrator: postmaster@marples.name