Skip to content
Commits on Source (12)
......@@ -3463,7 +3463,7 @@ display both build and runtime OpenSSL versions when they differ.
* Documentation updates from Dave Mills.
* Include 4.2.4p5: 2008/08/17 Released by Harlan Stenn <stenn@ntp.org>
* [Bug 861] leap info was not being transmitted.
* [Bug 1046] refnumtoa.c is using the wrong header file.
* [Bug 1046] refnumtoa0.c is using the wrong header file.
* [Bug 1047] enable/disable options processing fix.
* header file cleanup.
* [Bug 1037] buffer in subroutine was 1 byte short.
......
......@@ -541,4 +541,14 @@ some configurations.
|+flags+ |driver flags
|==========================================
== Compatibility ==
When listing refids, addresses of the form 127.127.x.x are no
longer automatically interpreted as local refclocks as in older
versons of +ntpq+.
In older versions, the 'type' variable associated with a
reference clock was a numeric driver type index. It has been replaced
by 'name', a shortname for the driver type.
// end
......@@ -194,20 +194,6 @@ typedef union {
ANY_INTERFACE_BYFAM(AF(psau))
/*
* We tell reference clocks from real peers by giving the reference
* clocks an address of the form 127.127.t.u, where t is the type and
* u is the unit number. We define some of this here since we will need
* some sanity checks to make sure this address isn't interpreted as
* that of a normal peer.
*/
#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */
#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */
#define ISREFCLOCKADR(srcadr) \
(IS_IPV4(srcadr) && \
(SRCADR(srcadr) & REFCLOCK_MASK) == REFCLOCK_ADDR)
/*
* Macro for checking for invalid addresses. This is really, really
* gross, but is needed so no one configures a host on net 127 now that
......
......@@ -66,7 +66,6 @@ extern struct clktype clktypes[];
* Structure for returning clock status
*/
struct refclockstat {
uint8_t type; /* clock type */
uint8_t flags; /* clock flags */
uint8_t haveflags; /* bit array of valid flags */
u_short lencode; /* length of last timecode */
......@@ -76,6 +75,7 @@ struct refclockstat {
uint32_t badformat; /* bad format timecode received */
uint32_t baddata; /* invalid data timecode received */
uint32_t timereset; /* driver resets */
const char *clockname; /* refclockname */
const char *clockdesc; /* ASCII description */
double fudgetime1; /* configure fudge time1 */
double fudgetime2; /* configure fudge time2 */
......@@ -152,7 +152,6 @@ struct refclockproc {
uint8_t leap; /* leap/synchronization code */
uint8_t currentstatus; /* clock status */
uint8_t lastevent; /* last exception event */
uint8_t type; /* clock type */
const char *clockname; /* clock name (tag for logging) */
const char *clockdesc; /* clock description */
u_long nextaction; /* local activity timeout */
......
......@@ -170,7 +170,6 @@ extern int sockaddr_masktoprefixlen(const sockaddr_u *);
extern const char * socktohost (const sockaddr_u *);
extern bool octtoint (const char *, u_long *);
extern u_long ranp2 (int);
extern const char *refnumtoa (sockaddr_u *);
extern const char *refid_str (uint32_t, int);
extern bool decodenetnum (const char *, sockaddr_u *);
......
......@@ -180,7 +180,7 @@ extern void peer_clr_stats (void);
extern struct peer *peer_config(sockaddr_u *, const char *,
endpt *, uint8_t, uint8_t,
uint8_t, uint8_t, u_int, uint32_t,
keyid_t);
keyid_t, bool clockaddr);
extern void peer_reset (struct peer *);
extern void refresh_all_peerinterfaces(void);
extern void unpeer (struct peer *);
......
......@@ -74,8 +74,19 @@ struct recvbuf {
#define recv_pkt recv_space.X_recv_pkt
#define recv_buffer recv_space.X_recv_buffer
int used; /* reference count */
#ifdef REFCLOCK
bool network_packet;
#endif /* REFCLOCK */
};
/* true for network packets, false for refclock packets */
#ifdef REFCLOCK
#define is_network_packet(rbufp) ((rbufp)->network_packet)
#else
#define is_network_packet(rbufp) false
#endif /* REFCLOCK */
extern void init_recvbuff(int);
/* freerecvbuf - make a single recvbuf available for reuse
......
/*
* refnumtoa - return asciized refclock addresses stored in local array space
*/
#include <config.h>
#include <stdio.h>
#include "ntp_net.h"
#include "lib_strbuf.h"
#include "ntp_stdlib.h"
const char *
refnumtoa(
sockaddr_u *num
)
{
uint32_t netnum;
char *buf;
const char *rclock;
if (!ISREFCLOCKADR(num))
return socktoa(num);
LIB_GETBUF(buf);
netnum = SRCADR(num);
rclock = clockname((int)((u_long)netnum >> 8) & 0xff);
if (rclock != NULL)
snprintf(buf, LIB_BUFLENGTH, "%s(%lu)",
rclock, (u_long)netnum & 0xff);
else
snprintf(buf, LIB_BUFLENGTH, "REFCLK(%lu,%lu)",
((u_long)netnum >> 8) & 0xff,
(u_long)netnum & 0xff);
return buf;
}
......@@ -37,7 +37,6 @@ def build(ctx):
"numtohost.c",
"prettydate.c",
"recvbuff.c",
"refnumtoa.c",
"refidsmear.c",
"socket.c",
"socktoa.c",
......
......@@ -49,6 +49,25 @@
int yyparse (void);
#endif
/*
* In the past, we told reference clocks from network peers by giving the
* reference clocks an address of the form 127.127.t.u, where t is the
* type and u is the unit number. In ntpd itself, the filtering that
* used to be done based on this magic address prefix is now done
* using the is_network_packet() test on incoming packets. In ntpq, the
* filtering is replaced by asking the server how a peer's name should
* be displayed.
*
* Address filtering is still done here so we can tell which config
* declarations refer to clocks.
*/
#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */
#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */
#define ISREFCLOCKADR(srcadr) \
(IS_IPV4(srcadr) && \
(SRCADR(srcadr) & REFCLOCK_MASK) == REFCLOCK_ADDR)
/* list of servers from command line for config_peers() */
int cmdline_server_count;
......@@ -3072,7 +3091,8 @@ config_peers(
0,
FLAG_IBURST,
0,
0);
0,
ISREFCLOCKADR(&peeraddr));
} else if (force_synchronous_dns) {
if (intercept_getaddrinfo(*cmdline_servers, &peeraddr)) {
peer_config(
......@@ -3085,7 +3105,8 @@ config_peers(
0,
FLAG_IBURST,
0,
0);
0,
false);
}
} else {
/* we have a hostname to resolve */
......@@ -3135,7 +3156,8 @@ config_peers(
curr_peer->maxpoll,
peerflag_bits(curr_peer),
curr_peer->ttl,
curr_peer->peerkey);
curr_peer->peerkey,
ISREFCLOCKADR(&peeraddr));
/*
* If we have a numeric address, we can safely
* proceed in the mainline with it.
......@@ -3156,7 +3178,8 @@ config_peers(
curr_peer->maxpoll,
peerflag_bits(curr_peer),
curr_peer->ttl,
curr_peer->peerkey);
curr_peer->peerkey,
ISREFCLOCKADR(&peeraddr));
/*
* synchronous lookup may be forced.
*/
......@@ -3172,7 +3195,8 @@ config_peers(
curr_peer->maxpoll,
peerflag_bits(curr_peer),
curr_peer->ttl,
curr_peer->peerkey);
curr_peer->peerkey,
false);
}
} else {
/* hand the hostname off to the blocking child */
......@@ -3277,7 +3301,8 @@ peer_name_resolved(
ctx->maxpoll,
ctx->flags,
ctx->ttl,
ctx->keyid);
ctx->keyid,
ISREFCLOCKADR(&peeraddr));
break;
}
}
......
......@@ -269,12 +269,13 @@ static const struct ctl_proc control_codes[] = {
#define CP_SELDISP 48
#define CP_SELBROKEN 49
#define CP_CANDIDATE 50
#define CP_MAXCODE CP_CANDIDATE
#define CP_DISPLAYNAME 51
#define CP_MAXCODE CP_DISPLAYNAME
/*
* Clock variables we understand
*/
#define CC_TYPE 1
#define CC_NAME 1
#define CC_TIMECODE 2
#define CC_POLL 3
#define CC_NOREPLY 4
......@@ -479,7 +480,8 @@ static const struct ctl_var peer_var[] = {
{ CP_SELDISP, RO, "seldisp" }, /* 48 */
{ CP_SELBROKEN, RO, "selbroken" }, /* 49 */
{ CP_CANDIDATE, RO, "candidate" }, /* 50 */
{ 0, EOV, "" } /* 50/58 */
{ CP_DISPLAYNAME, RO, "displayname" }, /* 51 */
{ 0, EOV, "" } /* 51/58 */
};
......@@ -521,6 +523,7 @@ static const uint8_t def_peer_var[] = {
CP_FILTDELAY,
CP_FILTOFFSET,
CP_FILTERROR,
CP_DISPLAYNAME,
0
};
......@@ -531,7 +534,7 @@ static const uint8_t def_peer_var[] = {
*/
static const struct ctl_var clock_var[] = {
{ 0, PADDING, "" }, /* 0 */
{ CC_TYPE, RO, "type" }, /* 1 */
{ CC_NAME, RO, "name" }, /* 1 */
{ CC_TIMECODE, RO, "timecode" }, /* 2 */
{ CC_POLL, RO, "poll" }, /* 3 */
{ CC_NOREPLY, RO, "noreply" }, /* 4 */
......@@ -553,7 +556,7 @@ static const struct ctl_var clock_var[] = {
*/
static const uint8_t def_clock_var[] = {
CC_DEVICE,
CC_TYPE, /* won't be output if device = known */
CC_NAME,
CC_TIMECODE,
CC_POLL,
CC_NOREPLY,
......@@ -2311,6 +2314,16 @@ ctl_putpeer(
case CP_CANDIDATE:
ctl_putuint(peer_var[id].text, p->status);
break;
case CP_DISPLAYNAME:
if (p->procptr != NULL) {
char buf[NI_MAXHOST];
snprintf(buf, sizeof(buf), "%s(%d)",
p->procptr->clockname, p->refclkunit);
ctl_putunqstr(peer_var[id].text, buf, 6);
}
break;
default:
break;
}
......@@ -2336,10 +2349,16 @@ ctl_putclock(
switch (id) {
case CC_TYPE:
if (mustput || pcs->clockdesc == NULL
|| *(pcs->clockdesc) == '\0') {
ctl_putuint(clock_var[id].text, pcs->type);
case CC_NAME:
if (pcs->clockname == NULL ||
*(pcs->clockname) == '\0') {
if (mustput)
ctl_putstr(clock_var[id].text,
"", 0);
} else {
ctl_putstr(clock_var[id].text,
pcs->clockname,
strlen(pcs->clockname));
}
break;
case CC_TIMECODE:
......
......@@ -3286,6 +3286,7 @@ read_refclock_packet(
rb->fd = fd;
rb->recv_time = ts;
rb->receiver = rp->clock_recv;
rb->network_packet = false;
consumed = indicate_refclock_packet(rp, rb);
if (!consumed) {
......@@ -3561,6 +3562,9 @@ read_network_packet(
#endif
rb->recv_time = ts;
rb->receiver = intercept_receive;
#ifdef REFCLOCK
rb->network_packet = true;
#endif /* REFCLOCK */
add_full_recv_buffer(rb);
......
......@@ -557,7 +557,8 @@ peer_config(
uint8_t maxpoll,
u_int flags,
uint32_t ttl,
keyid_t key
keyid_t key,
bool clockaddr
)
{
uint8_t cast_flags;
......@@ -602,7 +603,7 @@ peer_config(
flags &= ~FLAG_PREEMPT;
return newpeer(srcadr, hostname, dstadr, hmode, version,
minpoll, maxpoll, flags, cast_flags, ttl, key,
ISREFCLOCKADR(srcadr));
clockaddr);
}
/*
......
......@@ -370,7 +370,6 @@ transmit(
poll_update(peer, hpoll);
}
/*
* receive - receive procedure called for each packet received
*/
......@@ -420,7 +419,12 @@ receive(
sys_badlength++;
return; /* bogus port */
}
restrict_mask = restrictions(&rbufp->recv_srcadr);
#ifdef REFCLOCK
if (!is_network_packet(rbufp))
restrict_mask = 0;
else
#endif /* REFCLOCK */
restrict_mask = restrictions(&rbufp->recv_srcadr);
DPRINTF(2, ("receive: at %ld %s<-%s flags %x restrict %03x\n",
current_time, stoa(&rbufp->dstadr->sin),
stoa(&rbufp->recv_srcadr),
......@@ -805,7 +809,7 @@ receive(
peer2->maxpoll, FLAG_PREEMPT |
(FLAG_IBURST & peer2->flags), MDF_UCAST |
MDF_UCLNT, 0, skeyid,
ISREFCLOCKADR(&rbufp->recv_srcadr));
is_network_packet(rbufp));
if (NULL == peer) {
sys_declined++;
return; /* ignore duplicate */
......@@ -883,7 +887,7 @@ receive(
match_ep, MODE_BCLIENT, hisversion,
pkt->ppoll, pkt->ppoll, FLAG_PREEMPT,
MDF_BCLNT, 0, skeyid,
ISREFCLOCKADR(&rbufp->recv_srcadr));
is_network_packet(rbufp));
if (NULL == peer) {
sys_restricted++;
return; /* ignore duplicate */
......@@ -906,7 +910,7 @@ receive(
peer = newpeer(&rbufp->recv_srcadr, NULL, match_ep,
MODE_CLIENT, hisversion, pkt->ppoll, pkt->ppoll,
FLAG_BC_VOL | FLAG_IBURST | FLAG_PREEMPT, MDF_BCLNT,
0, skeyid, ISREFCLOCKADR(&rbufp->recv_srcadr));
0, skeyid, is_network_packet(rbufp));
if (NULL == peer) {
sys_restricted++;
return; /* ignore duplicate */
......@@ -990,7 +994,7 @@ receive(
if ((peer = newpeer(&rbufp->recv_srcadr, NULL,
rbufp->dstadr, MODE_PASSIVE, hisversion, pkt->ppoll,
NTP_MAXDPOLL, 0, MDF_UCAST, 0, skeyid,
ISREFCLOCKADR(&rbufp->recv_srcadr))) == NULL) {
is_network_packet(rbufp))) == NULL) {
sys_declined++;
return; /* ignore duplicate */
}
......
......@@ -207,7 +207,6 @@ refclock_newpeer(
peer->leap = LEAP_NOTINSYNC;
peer->stratum = STRATUM_REFCLOCK;
peer->ppoll = peer->maxpoll;
pp->type = clktype;
pp->conf = refclock_conf[clktype];
pp->timestarted = current_time;
pp->io.fd = -1;
......@@ -1026,7 +1025,7 @@ refclock_control(
out->lastevent = pp->lastevent;
out->currentstatus = pp->currentstatus;
out->type = pp->type;
out->clockname = pp->clockname;
out->clockdesc = pp->clockdesc;
out->lencode = (u_short)pp->lencode;
out->p_lastcode = pp->a_lastcode;
......
......@@ -620,8 +620,7 @@ restrict_source(
restrict_u * res;
int found_specific;
if (!restrict_source_enabled || SOCK_UNSPEC(addr) ||
IS_MCAST(addr) || ISREFCLOCKADR(addr))
if (!restrict_source_enabled || SOCK_UNSPEC(addr) || IS_MCAST(addr))
return;
NTP_REQUIRE(AF_INET == AF(addr) || AF_INET6 == AF(addr));
......
......@@ -2370,10 +2370,11 @@ jjy_receive_seiko_tsys_tdc_300 ( struct recvbuf *rbufp )
}
time( &now ) ;
pTime = localtime_r( &now, &tmbuf ) ;
up->year = pTime->tm_year ;
up->month = pTime->tm_mon + 1 ;
up->day = pTime->tm_mday ;
if ((pTime = localtime_r( &now, &tmbuf )) != NULL) {
up->year = pTime->tm_year ;
up->month = pTime->tm_mon + 1 ;
up->day = pTime->tm_mday ;
}
break ;
......
......@@ -657,7 +657,6 @@ neoclock4x_control(int unit,
char tmpbuf[80];
out->kv_list = (struct ctl_var *)0;
out->type = REFCLK_NEOCLOCK4X;
snprintf(tmpbuf, sizeof(tmpbuf)-1,
"%04d-%02d-%02d %02d:%02d:%02d.%03d",
......
......@@ -3017,8 +3017,6 @@ parse_control(
outstatus[0] = '\0';
out->type = REFCLK_PARSE;
/*
* keep fudgetime2 in sync with TRUSTTIME/MAXUNSYNC flag1
*/
......
......@@ -47,6 +47,7 @@
*/
#define PRECISION (-1) /* precision assumed (0.5 s) */
#define REFID "SHM" /* reference ID */
#define NAME "SHM"
#define DESCRIPTION "SHM/Shared memory interface"
#define NSAMPLES 3 /* stages of median filter */
......@@ -237,6 +238,7 @@ shm_start(
peer->precision = up->shm->precision;
up->shm->valid = 0;
up->shm->nsamples = NSAMPLES;
pp->clockname = NAME;
pp->clockdesc = DESCRIPTION;
/* items to be changed later in 'shm_control()': */
up->max_delay = 5;
......