[Git][NTPsec/ntpsec][master] Begin prying ntpd loose from assumptions about magic refclock addresses.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Jun 21 21:07:06 UTC 2016


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


Commits:
21c311d5 by Eric S. Raymond at 2016-06-21T17:03:38-04:00
Begin prying ntpd loose from assumptions about magic refclock addresses.

For the moment this change just makes some logic use peer structure members
rather than equivalent magic address bits. It's a baby step towards getting
rid of magic address bits entirely.

- - - - -


6 changed files:

- include/ntp.h
- include/ntp_net.h
- ntpd/ntp_control.c
- ntpd/ntp_io.c
- ntpd/ntp_peer.c
- ntpd/ntp_refclock.c


Changes:

=====================================
include/ntp.h
=====================================
--- a/include/ntp.h
+++ b/include/ntp.h
@@ -232,6 +232,15 @@ struct interface {
 #define	PEER_BOGON_MASK	(BOGON10 | BOGON11 | BOGON12 | BOGON13)
 
 /*
+ * Does a peer node represent a reference clock?
+ */
+#ifdef REFCLOCK
+#define IS_PEER_REFCLOCK(p)	((p)->procptr != NULL)
+#else
+#define IS_PEER_REFCLOCK(p)	false
+#endif
+
+/*
  * The peer structure. Holds state information relating to the guys
  * we are peering with. Most of this stuff is from section 3.2 of the
  * spec.


=====================================
include/ntp_net.h
=====================================
--- a/include/ntp_net.h
+++ b/include/ntp_net.h
@@ -198,7 +198,7 @@ typedef union {
  * 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 interpretted as
+ * 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 */


=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -4356,7 +4356,7 @@ report_event(
 
 		peer->last_event = errlast;
 		peer->num_events++;
-		if (ISREFCLOCKADR(&peer->srcadr))
+		if (IS_PEER_REFCLOCK(peer))
 			src = refnumtoa(&peer->srcadr);
 		else
 			src = stoa(&peer->srcadr);


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -3864,7 +3864,7 @@ select_peerinterface(
 	 * This might happen in some systems and would preclude proper
 	 * operation with public key cryptography.
 	 */
-	if (ISREFCLOCKADR(srcadr)) {
+	if (IS_PEER_REFCLOCK(peer)) {
 		ep = loopback_interface;
 	} else if (peer->cast_flags &
 		   (MDF_BCLNT | MDF_ACAST | MDF_MCAST | MDF_BCAST)) {


=====================================
ntpd/ntp_peer.c
=====================================
--- a/ntpd/ntp_peer.c
+++ b/ntpd/ntp_peer.c
@@ -884,7 +884,7 @@ newpeer(
 	peer->timereachable = current_time;
 	peer->timereceived = current_time;
 
-	if (ISREFCLOCKADR(&peer->srcadr)) {
+	if (IS_PEER_REFCLOCK(peer)) {
 #ifdef REFCLOCK
 		/*
 		 * We let the reference clock support do clock


=====================================
ntpd/ntp_refclock.c
=====================================
--- a/ntpd/ntp_refclock.c
+++ b/ntpd/ntp_refclock.c
@@ -162,7 +162,7 @@ refclock_newpeer(
 	 * Check for valid clock address. If already running, shut it
 	 * down first.
 	 */
-	if (!ISREFCLOCKADR(&peer->srcadr)) {
+	if (!IS_PEER_REFCLOCK(peer)) {
 		msyslog(LOG_ERR,
 			"refclock_newpeer: clock address %s invalid",
 			stoa(&peer->srcadr));
@@ -939,19 +939,17 @@ refclock_control(
 	/*
 	 * Check for valid address and running peer
 	 */
-	if (!ISREFCLOCKADR(srcadr))
-		return;
-
-	clktype = (uint8_t)REFCLOCKTYPE(srcadr);
-	unit = REFCLOCKUNIT(srcadr);
-
 	peer = findexistingpeer(srcadr, NULL, NULL, -1, 0);
 
 	if (NULL == peer)
 		return;
 
-	NTP_INSIST(peer->procptr != NULL);
+	if (!IS_PEER_REFCLOCK(peer))
+		return;
+
 	pp = peer->procptr;
+	clktype = peer->refclktype;
+	unit = peer->refclkunit;
 
 	/*
 	 * Initialize requested data
@@ -1048,20 +1046,19 @@ refclock_buginfo(
 	unsigned u;
 
 	/*
-	 * Check for valid address and peer structure
+	 * Check for valid peer structure and address
 	 */
-	if (!ISREFCLOCKADR(srcadr))
-		return;
-
-	clktype = (uint8_t) REFCLOCKTYPE(srcadr);
-	unit = REFCLOCKUNIT(srcadr);
-
 	peer = findexistingpeer(srcadr, NULL, NULL, -1, 0);
 
 	if (NULL == peer || NULL == peer->procptr)
 		return;
 
 	pp = peer->procptr;
+	if (pp == NULL)
+	    return;
+
+	clktype = peer->refclktype;
+	unit = peer->refclkunit;
 
 	/*
 	 * Copy structure values



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/21c311d50505982ba6b3312e90ffad3a8077988d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160621/fb32d5e4/attachment.html>


More information about the vc mailing list