Browse Source

correctly set refid in replies with NTP protocol versions < 4.

code path for NTP4 remains unchanged, we already set refid correctly there.
NTP3 and older uses an IPv4 address as refid.
use the IP of the server we last synced to if it was a IPv4 one.
sometimes we use the average offset between two, in that case just pick
one for the IP.
this scheme naturally fails when we query IPv6 servers and have to reply
to IPv4 NTP3 (or even older NTP versions) clients - refid stays at 0 then.
this is a protocol limitation, nothing we can do about it.
OPENBSD_3_7
henning 20 years ago
parent
commit
7096d1be44
2 changed files with 7 additions and 3 deletions
  1. +5
    -1
      src/usr.sbin/ntpd/ntp.c
  2. +2
    -2
      src/usr.sbin/ntpd/server.c

+ 5
- 1
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.35 2004/10/13 09:20:41 henning Exp $ */
/* $OpenBSD: ntp.c,v 1.36 2004/10/13 12:22:39 henning Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -385,6 +385,10 @@ ntp_adjtime(void)
conf->status.reftime = gettime(); conf->status.reftime = gettime();
conf->status.leap = LI_NOWARNING; /* XXX */ conf->status.leap = LI_NOWARNING; /* XXX */
if (peers[offset_cnt / 2]->addr->ss.ss_family == AF_INET)
conf->status.refid = ((struct sockaddr_in *)
&peers[offset_cnt / 2]->addr->ss)->sin_addr.s_addr;
} }
free(peers); free(peers);


+ 2
- 2
src/usr.sbin/ntpd/server.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: server.c,v 1.13 2004/09/07 22:43:07 henning Exp $ */
/* $OpenBSD: server.c,v 1.14 2004/10/13 12:22:39 henning Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -140,7 +140,7 @@ server_dispatch(int fd, struct ntpd_conf *conf)
if (version > 3) if (version > 3)
reply.refid = reply.xmttime.fraction; reply.refid = reply.xmttime.fraction;
else else
reply.refid = 0; /* XXX */
reply.refid = conf->status.refid;
ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply, size, 0); ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply, size, 0);
return (0); return (0);


Loading…
Cancel
Save