clock_select() with multiple preferred servers inntp_proto.c
I saw some behavior in our ntp server that puzzled me and in hunting
through the code to
understand what I'd done wrong I found what seems to be incorrect code.
I admit that my
understanding of ntp is poor, and ntp seems hideously complicated so I
thought I should
ask about it.
If more than one server is configured with the "prefer" key word then
the ntp server
seems to select the server with the higher stratum as the sys_prefer
peer. The clock_select()
function in ntp_proto.c builds a peer_list[] array of peer pointers. It
seems to build the array
sorted by increasing (root_distance(peer) + peer->stratum *
sys_maxdist). But later when
trying to select a peer for sys_prefer it searches through the list from
start to end looking
for peers with FLAG_PREFER set. If there is more than one peer with
FLAG_PREFER set
then sys_prefer will be set to the one with the highest value of the
sort metric.
This seems wrong and it seems that it could be improved by changing the
loop from
for (i = 0; i < nlist; i++)
to
for (i = nlist - 1; i >= 0; i--)
But as I said before my understnanding of ntp is poor so there is likely
something I've failed
to consider. Gentle correction would be appreciated.
Thank you in advance.
Re: clock_select() with multiple preferred servers in ntp_proto.c
Breck,
The prefer option is not designed to handle multiple instances. You
probably want it as a failover provision and it was never designed for that.
Dave
Breck Beatie wrote:
[color=blue]
> I saw some behavior in our ntp server that puzzled me and in hunting
> through the code to
> understand what I'd done wrong I found what seems to be incorrect code.
> I admit that my
> understanding of ntp is poor, and ntp seems hideously complicated so I
> thought I should
> ask about it.
>
> If more than one server is configured with the "prefer" key word then
> the ntp server
> seems to select the server with the higher stratum as the sys_prefer
> peer. The clock_select()
> function in ntp_proto.c builds a peer_list[] array of peer pointers. It
> seems to build the array
> sorted by increasing (root_distance(peer) + peer->stratum *
> sys_maxdist). But later when
> trying to select a peer for sys_prefer it searches through the list from
> start to end looking
> for peers with FLAG_PREFER set. If there is more than one peer with
> FLAG_PREFER set
> then sys_prefer will be set to the one with the highest value of the
> sort metric.
>
> This seems wrong and it seems that it could be improved by changing the
> loop from
> for (i = 0; i < nlist; i++)
> to
> for (i = nlist - 1; i >= 0; i--)
>
> But as I said before my understnanding of ntp is poor so there is likely
> something I've failed
> to consider. Gentle correction would be appreciated.
>
> Thank you in advance.[/color]