[Git][NTPsec/ntpsec][master] 2 commits: Avoid some indirectitions through the driver table.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Jun 28 16:07:55 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
012a5f93 by Eric S. Raymond at 2016-06-28T11:35:27-04:00
Avoid some indirectitions through the driver table.

- - - - -
f0cf98a9 by Eric S. Raymond at 2016-06-28T12:07:08-04:00
Clean up a bit more around driver structure access.

- - - - -


3 changed files:

- include/ntp_refclock.h
- ntpd/ntp_control.c
- ntpd/ntp_refclock.c


Changes:

=====================================
include/ntp_refclock.h
=====================================
--- a/include/ntp_refclock.h
+++ b/include/ntp_refclock.h
@@ -147,7 +147,7 @@ extern	HANDLE	WaitableIoEventHandle;
 
 struct refclockproc {
 	void *	unitptr;	/* pointer to unit structure */
-	struct refclock * conf;	/* refclock_conf[type] */
+	struct refclock * conf;	/* pointer to driver method table */
 	struct refclockio io;	/* I/O handler structure */
 	uint8_t	leap;		/* leap/synchronization code */
 	uint8_t	currentstatus;	/* clock status */


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -2319,8 +2319,7 @@ ctl_putpeer(
 #ifdef REFCLOCK
 		if (p->procptr != NULL) {
 		    char buf[NI_MAXHOST];
-		    snprintf(buf, sizeof(buf), "%s(%d)",
-			     p->procptr->clockname, p->refclkunit);
+		    strlcpy(buf, refclock_name(p), sizeof(buf));
 		    ctl_putunqstr(peer_var[id].text, buf, strlen(buf));
 		}
 #endif /* REFCLOCK */


=====================================
ntpd/ntp_refclock.c
=====================================
--- a/ntpd/ntp_refclock.c
+++ b/ntpd/ntp_refclock.c
@@ -125,17 +125,11 @@ refclock_name(
 	)
 {
 	char *buf;
-	const char *rclock;
 
 	LIB_GETBUF(buf);
-	rclock = peer->procptr->clockname;
 
-	if (rclock != NULL)
-		snprintf(buf, LIB_BUFLENGTH, "%s(%d)",
-			 rclock, peer->refclkunit);
-	else
-		snprintf(buf, LIB_BUFLENGTH, "REFCLK(%d,%d)",
-			 peer->refclktype, peer->refclkunit);
+	snprintf(buf, LIB_BUFLENGTH, "%s(%d)",
+			 peer->procptr->clockname, peer->refclkunit);
 
 	return buf;
 }
@@ -180,10 +174,12 @@ refclock_newpeer(
 	int unit;
 
 	/*
-	 * If already running, shut it down.
+	 * This is the only place outside of the config parser
+	 * that still knows about magic clock addresses.  Alas...
 	 */
 	clktype = (uint8_t)REFCLOCKTYPE(&peer->srcadr);
 	unit = REFCLOCKUNIT(&peer->srcadr);
+
 	if (clktype >= num_refclock_conf ||
 		refclock_conf[clktype]->clock_start == noentry) {
 		msyslog(LOG_ERR,
@@ -228,7 +224,7 @@ refclock_newpeer(
 	 * Do driver dependent initialization. The above defaults
 	 * can be wiggled, then finish up for consistency.
 	 */
-	if (!((refclock_conf[clktype]->clock_start)(unit, peer))) {
+	if (!((pp->conf->clock_start)(unit, peer))) {
 		refclock_unpeer(peer);
 		return false;
 	}
@@ -245,7 +241,6 @@ refclock_unpeer(
 	struct peer *peer	/* peer structure pointer */
 	)
 {
-	uint8_t clktype;
 	int unit;
 
 	/*
@@ -255,10 +250,9 @@ refclock_unpeer(
 	if (NULL == peer->procptr)
 		return;
 
-	clktype = peer->refclktype;
 	unit = peer->refclkunit;
-	if (refclock_conf[clktype]->clock_shutdown != noentry)
-		(refclock_conf[clktype]->clock_shutdown)(unit, peer);
+	if (peer->procptr->conf->clock_shutdown != noentry)
+		(peer->procptr->conf->clock_shutdown)(unit, peer);
 	free(peer->procptr);
 	peer->procptr = NULL;
 }
@@ -297,10 +291,8 @@ refclock_transmit(
 	struct peer *peer	/* peer structure pointer */
 	)
 {
-	uint8_t clktype;
 	int unit;
 
-	clktype = peer->refclktype;
 	unit = peer->refclkunit;
 	peer->sent++;
 	get_systime(&peer->xmt);
@@ -339,8 +331,8 @@ refclock_transmit(
 	} else {
 		peer->burst--;
 	}
-	if (refclock_conf[clktype]->clock_poll != noentry)
-		(refclock_conf[clktype]->clock_poll)(unit, peer);
+	if (peer->procptr->conf->clock_poll != noentry)
+		(peer->procptr->conf->clock_poll)(unit, peer);
 	poll_update(peer, peer->hpoll);
 }
 
@@ -946,7 +938,6 @@ refclock_control(
 {
 	struct peer *peer;
 	struct refclockproc *pp;
-	uint8_t clktype;
 	int unit;
 
 	/*
@@ -961,7 +952,6 @@ refclock_control(
 		return;
 
 	pp = peer->procptr;
-	clktype = peer->refclktype;
 	unit = peer->refclkunit;
 
 	/*
@@ -1034,8 +1024,8 @@ refclock_control(
 	/*
 	 * Give the stuff to the clock
 	 */
-	if (refclock_conf[clktype]->clock_control != noentry)
-		(refclock_conf[clktype]->clock_control)(unit, in, out, peer);
+	if (peer->procptr->conf->clock_control != noentry)
+		(peer->procptr->conf->clock_control)(unit, in, out, peer);
 }
 
 
@@ -1054,8 +1044,6 @@ refclock_buginfo(
 {
 	struct peer *peer;
 	struct refclockproc *pp;
-	int clktype;
-	int unit;
 	unsigned u;
 
 	/*
@@ -1070,9 +1058,6 @@ refclock_buginfo(
 	if (pp == NULL)
 	    return;
 
-	clktype = peer->refclktype;
-	unit = peer->refclkunit;
-
 	/*
 	 * Copy structure values
 	 */
@@ -1095,8 +1080,8 @@ refclock_buginfo(
 	/*
 	 * Give the stuff to the clock
 	 */
-	if (refclock_conf[clktype]->clock_buginfo != noentry)
-		(refclock_conf[clktype]->clock_buginfo)(unit, bug, peer);
+	if (peer->procptr->conf->clock_buginfo != noentry)
+		(peer->procptr->conf->clock_buginfo)(peer->refclkunit, bug, peer);
 }
 
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7fb3fe2bea6c3f7c3eb394916d1e4d2002e79d8d...f0cf98a93d34fae8f7e3a8403c452581b6298b4d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160628/b907c520/attachment.html>


More information about the vc mailing list