[ntp:bk-ntp-dev-send] BitKeeper diffs

Harlan Stenn stenn at whimsy.udel.edu
Thu Oct 18 05:55:06 UTC 2007


#### ChangeSet ####
2007-10-18 01:52:51-04:00, stenn at whimsy.udel.edu 
  refclock_acts.c, ntp_peer.c, ChangeLog, ntp_proto.c, ntp_config.c:
    Association and other cleanup from Dave Mills
  ntp.h:
    NTP_UNREACH changes from Dave Mills.

==== ChangeLog ====
2007-10-18 01:52:32-04:00, stenn at whimsy.udel.edu +2 -0
  Association and other cleanup from Dave Mills

--- 1.127/ChangeLog	2007-10-17 20:21:15 -04:00
+++ 1.128/ChangeLog	2007-10-18 01:52:32 -04:00
@@ -1,3 +1,5 @@
+* Association and other cleanup from Dave Mills.
+* NTP_UNREACH changes from Dave Mills.
 * Fix the readline history test.
 * [Bug 931] Require -lreadline to be asked for explicitly.
 * [Bug 764] When looking for -lreadline support, also try using -lncurses.

==== include/ntp.h ====
2007-10-18 01:48:28-04:00, stenn at whimsy.udel.edu +2 -2
  NTP_UNREACH changes from Dave Mills.

--- 1.138/include/ntp.h	2007-09-30 11:54:35 -04:00
+++ 1.139/include/ntp.h	2007-10-18 01:48:28 -04:00
@@ -103,7 +103,7 @@ typedef char s_char;
 /*
  * Poll interval parameters
  */
-#define NTP_UNREACH	24	/* poll unreach threshold */
+#define NTP_UNREACH	10	/* poll unreach threshold */
 #define	NTP_MINPOLL	4	/* log2 min poll interval (16 s) */
 #define NTP_MINDPOLL	6	/* log2 default min poll (64 s) */
 #define NTP_MAXDPOLL	10	/* log2 default max poll (~17 m) */
@@ -363,7 +363,7 @@ struct peer {
 	 */
 	u_long	update;		/* receive epoch */
 #define end_clear_to_zero update
-	u_int	unreach;	/* unreachable count */
+	u_int	unreach;	/* watchdog counter */
 	u_long	outdate;	/* send time last packet */
 	u_long	nextdate;	/* send time next packet */
 	u_long	nextaction;	/* peer local activity timeout (refclocks) */

==== ntpd/ntp_config.c ====
2007-10-18 01:51:59-04:00, stenn at whimsy.udel.edu +20 -24
  Association and other cleanup from Dave Mills

--- 1.167/ntpd/ntp_config.c	2007-10-03 21:33:28 -04:00
+++ 1.168/ntpd/ntp_config.c	2007-10-18 01:51:59 -04:00
@@ -1768,32 +1768,28 @@ config_peers(void)
 		 */
 		else {
 			res_bak = res;
-			/* Loop to configure the desired number of associations 
+
+			/*
+			 * Loop to configure the desired number of
+			 * associations 
 			 */
-			for (i = 0; (i < no_needed) && res; res = res->ai_next) {
+			for (i = 0; (i < no_needed) && res; res =
+			    res->ai_next) {
 				++i;
-				memcpy(&peeraddr, res->ai_addr, res->ai_addrlen);
-#ifdef DEBUG
-				if (debug > 1)
-					printf("configuring host %s with address %s\n",
-					       curr_peer->addr->address, stoa(&peeraddr));
-#endif
-				if (is_sane_resolved_address(peeraddr, curr_peer->host_mode)) {
-					if (peer_config(&peeraddr,
-							ANY_INTERFACE_CHOOSE(&peeraddr), 
-							hmode,
-							curr_peer->peerversion, 
-							curr_peer->minpoll, 
-							curr_peer->maxpoll, 
-							curr_peer->peerflags,
-							curr_peer->ttl, 
-							curr_peer->peerkey, 
-							(u_char *)"*") == 0) {
-						msyslog(LOG_ERR,
-							"configuration of %s failed",
-							stoa(&peeraddr));
-					}
-				}
+				memcpy(&peeraddr, res->ai_addr,
+				    res->ai_addrlen);
+				if (is_sane_resolved_address(peeraddr,
+				    curr_peer->host_mode))
+					peer_config(&peeraddr,
+				        ANY_INTERFACE_CHOOSE(&peeraddr), 
+					    hmode,
+					    curr_peer->peerversion, 
+					    curr_peer->minpoll, 
+					    curr_peer->maxpoll, 
+					    curr_peer->peerflags,
+					    curr_peer->ttl, 
+					    curr_peer->peerkey, 
+					    (u_char *)"*");
 			}
 			freeaddrinfo(res_bak);
 		}

==== ntpd/ntp_peer.c ====
2007-10-18 01:52:04-04:00, stenn at whimsy.udel.edu +45 -65
  Association and other cleanup from Dave Mills

--- 1.107/ntpd/ntp_peer.c	2007-09-09 07:09:28 -04:00
+++ 1.108/ntpd/ntp_peer.c	2007-10-18 01:52:04 -04:00
@@ -426,38 +426,14 @@ peer_config(
 	u_char *keystr
 	)
 {
-	register struct peer *peer;
 	u_char cast_flags;
 
 	/*
-	 * First search from the beginning for an association with given
-	 * remote address and mode. If an interface is given, search
-	 * from there to find the association which matches that
-	 * destination.  If the given interface is "any", track down
-	 * the actual interface, because that's what gets put into the
-	 * peer structure.
-	 */
-	peer = findexistingpeer(srcadr, (struct peer *)0, hmode);
-	if (dstadr != 0) {
-		while (peer != 0) {
-			if (peer->dstadr == dstadr)
-				break;
-
-			if (dstadr == ANY_INTERFACE_CHOOSE(srcadr) &&
-			    peer->dstadr == findinterface(srcadr))
-				break;
-
-			peer = findexistingpeer(srcadr, peer, hmode);
-		}
-	}
-
-	/*
 	 * We do a dirty little jig to figure the cast flags. This is
 	 * probably not the best place to do this, at least until the
 	 * configure code is rebuilt. Note only one flag can be set.
 	 */
 	switch (hmode) {
-
 	case MODE_BROADCAST:
 		if(srcadr->ss_family == AF_INET) {
 			if (IN_CLASSD(ntohl(((struct sockaddr_in*)srcadr)->sin_addr.s_addr)))
@@ -465,15 +441,13 @@ peer_config(
 			else
 				cast_flags = MDF_BCAST;
 			break;
-		}
-		else {
+		} else {
                         if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)srcadr)->sin6_addr))
         	                cast_flags = MDF_MCAST;
 	        	else
                         	cast_flags = MDF_BCAST;
                 	break;
                 }
-
 	case MODE_CLIENT:
 		if(srcadr->ss_family == AF_INET) {
 			if (IN_CLASSD(ntohl(((struct sockaddr_in*)srcadr)->sin_addr.s_addr)))
@@ -481,8 +455,7 @@ peer_config(
 			else
 				cast_flags = MDF_UCAST;
 			break;
-		}
-		else {
+		} else {
 			if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)srcadr)->sin6_addr))
 				cast_flags = MDF_ACAST;
 			else
@@ -495,34 +468,13 @@ peer_config(
 	}
 
 	/*
-	 * If the peer is already configured, some dope has a duplicate
-	 * configureation entry or another dope is wiggling from afar.
-	 */
-	if (peer != 0) {
-		peer->hmode = (u_char)hmode;
-		peer->version = (u_char) version;
-		peer->minpoll = (u_char) minpoll;
-		peer->maxpoll = (u_char) maxpoll;
-		peer->flags = flags | FLAG_CONFIG |
-		    (peer->flags & FLAG_REFCLOCK);
-		peer->cast_flags = cast_flags;
-		peer->ttl = (u_char) ttl;
-		peer->keyid = key;
-		peer->precision = sys_precision;
-		peer_clear(peer, "RMOT");
-		return (peer);
-	}
-
-	/*
-	 * Here no match has been found, so presumably this is a new
-	 * persistent association. Mobilize the thing and initialize its
-	 * variables. If emulating ntpdate, force iburst.
+	 * Mobilize the association and initialize its variables. If
+	 * emulating ntpdate, force iburst.
 	 */
 	if (mode_ntpdate)
 		flags |= FLAG_IBURST;
-	peer = newpeer(srcadr, dstadr, hmode, version, minpoll, maxpoll,
-	    flags | FLAG_CONFIG, cast_flags, ttl, key);
-	return (peer);
+	return(newpeer(srcadr, dstadr, hmode, version, minpoll, maxpoll,
+	    flags | FLAG_CONFIG, cast_flags, ttl, key));
 }
 
 /*
@@ -724,13 +676,43 @@ newpeer(
 	keyid_t key
 	)
 {
-	register struct peer *peer;
-	register int i;
+	struct peer *peer;
+	int	i;
 #ifdef OPENSSL
 	char	statstr[NTP_MAXSTRLEN]; /* statistics for filegen */
 #endif /* OPENSSL */
 
 	/*
+	 * First search from the beginning for an association with given
+	 * remote address and mode. If an interface is given, search
+	 * from there to find the association which matches that
+	 * destination. If the given interface is "any", track down the
+	 * actual interface, because that's what gets put into the peer
+	 * structure.
+	 */
+	peer = findexistingpeer(srcadr, (struct peer *)0, hmode);
+	if (dstadr != 0) {
+		while (peer != 0) {
+			if (peer->dstadr == dstadr)
+				break;
+
+			if (dstadr == ANY_INTERFACE_CHOOSE(srcadr) &&
+			    peer->dstadr == findinterface(srcadr))
+				break;
+
+			peer = findexistingpeer(srcadr, peer, hmode);
+		}
+	}
+
+	/*
+	 * If a peer is found, this would be a duplicate and we don't
+	 * allow that. This is mostly to avoid duplicate pool
+	 * associations.
+	 */
+	if (peer != NULL)
+		return (NULL);
+
+	/*
 	 * Allocate a new peer structure. Some dirt here, since some of
 	 * the initialization requires knowlege of our system state.
 	 */
@@ -857,12 +839,10 @@ newpeer(
 #endif /* OPENSSL */
 
 	DPRINTF(1, ("newpeer: %s->%s mode %d vers %d poll %d %d flags 0x%x 0x%x ttl %d key %08x\n",
-		    peer->dstadr == NULL ? "<null>" : stoa(&peer->dstadr->sin),
-		    stoa(&peer->srcadr),
-		    peer->hmode, peer->version, peer->minpoll,
-		    peer->maxpoll, peer->flags, peer->cast_flags,
-		    peer->ttl, peer->keyid));
-
+	    peer->dstadr == NULL ? "<null>" : stoa(&peer->dstadr->sin),
+	    stoa(&peer->srcadr), peer->hmode, peer->version,
+	    peer->minpoll, peer->maxpoll, peer->flags, peer->cast_flags,
+	    peer->ttl, peer->keyid));
 	return (peer);
 }
 
@@ -896,13 +876,13 @@ peer_unconfig(
 			 * mode. The protocol will eventually terminate
 			 * undesirables on its own.
 			 */
-			if (peer->hmode == MODE_ACTIVE
-			    && peer->pmode == MODE_ACTIVE) {
+			if (peer->hmode == MODE_ACTIVE && peer->pmode ==
+			    MODE_ACTIVE) {
 				peer->hmode = MODE_PASSIVE;
 				peer->flags &= ~FLAG_CONFIG;
 			} else {
 				unpeer(peer);
-				peer = 0;
+				peer = NULL;
 			}
 		}
 		peer = findexistingpeer(srcadr, peer, mode);

==== ntpd/ntp_proto.c ====
2007-10-18 01:52:05-04:00, stenn at whimsy.udel.edu +11 -34
  Association and other cleanup from Dave Mills

--- 1.262/ntpd/ntp_proto.c	2007-09-09 07:09:29 -04:00
+++ 1.263/ntpd/ntp_proto.c	2007-10-18 01:52:05 -04:00
@@ -210,6 +210,7 @@ transmit(
 		 */
 		oreach = peer->reach & 0xfe;
 		peer->outdate = current_time;
+		peer->unreach++;
 		peer->reach <<= 1;
 		if (!(peer->reach & 0x0f))
 			clock_filter(peer, 0., 0., MAXDISPERSE);
@@ -217,16 +218,11 @@ transmit(
 
 			/*
 			 * Here the peer is unreachable. If it was
-			 * previously reachable raise a trap. Bump the
-			 * unreach counter such that the association
-			 * times out in a reasonable time after becoming
-			 * unreachable.
-			 */
+			 * previously reachable raise a trap.					 */
 			if (oreach) {
 				report_event(EVNT_UNREACH, peer);
 				peer->timereachable = current_time;
 			}
-			peer->unreach += 2;
 		} else {
 
 			/*
@@ -236,29 +232,11 @@ transmit(
 			 * only if enabled and the peer is fit.
 			 */
 			hpoll = sys_poll;
+			if (!oreach)
+				peer->unreach = 0;
 			if (peer->flags & FLAG_BURST &&
 			    !peer_unfit(peer))
 				peer->burst = NTP_BURST;
-
-			/*
-			 * Respond to the peer evaluation produced by
-			 * the selection algorithm. If less than the
-			 * outlyer level, up the unreach by three. If
-			 * there are excess associations, up the unreach
-			 * by two if not a candidate and by one if so.
-			 */
-			if (!(peer->flags & FLAG_PREEMPT)) {
-				peer->unreach = 0;
-			} else if (peer->status < CTL_PST_SEL_SELCAND) {
-				peer->unreach += 3;
-			} else if (peer_preempt > sys_maxclock) {
-				if (peer->status < CTL_PST_SEL_SYNCCAND)
-					peer->unreach += 2;
-				else
-					peer->unreach++;
-			} else {
-				peer->unreach = 0;
-			}
 		}
 
 		/*
@@ -781,7 +759,7 @@ receive(
 		    hisversion, NTP_MINDPOLL, NTP_MAXDPOLL,
 		    FLAG_IBURST | FLAG_PREEMPT, MDF_UCAST | MDF_ACLNT,
 		    0, skeyid)) == NULL)
-			return;			/* system error */
+			return;			/* ignore duplicate  */
 
 		/*
 		 * We don't need these, but it warms the billboards.
@@ -832,7 +810,7 @@ receive(
 			    pkt->ppoll, max(pkt->ppoll, allan_xpt - 5),
 			    FLAG_MCAST | FLAG_IBURST, MDF_BCLNT, 0,
 			    skeyid)) == NULL)
-				return;		/* system error */
+				return;		/* ignore duplicate */
 #ifdef OPENSSL
 			/*
 			 * Ordinarily this will be an association reply
@@ -867,7 +845,7 @@ receive(
 			    rbufp->dstadr, MODE_BCLIENT, hisversion,
 			    pkt->ppoll, max(pkt->ppoll, allan_xpt - 5),
 			    0, MDF_BCLNT, 0, skeyid)) == NULL)
-				return;		/* system error */
+				return;		/* ignore duplicate */
 		}
 		break;
 
@@ -912,7 +890,7 @@ receive(
 		    rbufp->dstadr, MODE_PASSIVE, hisversion,
 		    NTP_MINDPOLL, NTP_MAXDPOLL, 0, MDF_UCAST, 0,
 		    skeyid)) == NULL)
-			return;			/* system error */
+			return;			/* ignore duplicate */
 		break;
 
 	/*
@@ -1044,9 +1022,6 @@ receive(
 		if (rval != XEVNT_OK) {
 			peer_clear(peer, "CRYP");
 			peer->flash |= TEST9;	/* crypto error */
-			if (peer->flags & FLAG_PREEMPT ||
-			    !(peer->flags & FLAG_CONFIG))
-				unpeer(peer);
 			return;
 
 		} else if (hismode == MODE_SERVER) {
@@ -2327,8 +2302,10 @@ clock_select(void)
 	 */
 	leap_next = 0;
 	for (i = 0; i < nlist; i++) {
-		peer = peer_list[i];
 		sys_survivors++;
+		peer = peer_list[i];
+		if (i < sys_maxclock)
+			peer->unreach = 0;
 		if (peer->leap == LEAP_ADDSECOND) {
 			if (peer->flags & FLAG_REFCLOCK)
 				leap_next = nlist;

==== ntpd/refclock_acts.c ====
2007-10-18 01:52:11-04:00, stenn at whimsy.udel.edu +2 -0
  Association and other cleanup from Dave Mills

--- 1.31/ntpd/refclock_acts.c	2007-08-17 01:37:20 -04:00
+++ 1.32/ntpd/refclock_acts.c	2007-10-18 01:52:11 -04:00
@@ -770,6 +770,8 @@ acts_timeout(
 			fd = refclock_open(device, SPEED232,
 			    LDISC_ACTS | LDISC_RAW | LDISC_REMOTE);
 			if (fd == 0) {
+				msyslog(LOG_ERR,
+				    "acts: open fails");
 				return;
 			}
 			pp->io.fd = fd;


More information about the bk-ntp-dev-send mailing list