[Git][NTPsec/ntpsec][master] This revision *almost* successfully round-trips a receive in replay.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Dec 22 12:03:42 UTC 2015


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


Commits:
77337b66 by Eric S. Raymond at 2015-12-22T07:03:20Z
This revision *almost* successfully round-trips a receive in replay.

Something unfortunate going oin with low-order bts in a timestamp.

- - - - -


4 changed files:

- ntpd/ntp_intercept.c
- ntpd/ntp_io.c
- ntpd/ntp_proto.c
- ntpd/ntp_timer.c


Changes:

=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -645,17 +645,18 @@ static void packet_dump(char *buf, size_t buflen,
 static void packet_parse(char *pktbuf, char *macbuf, struct pkt *pkt)
 {
     char refbuf[32], orgbuf[32], recbuf[32], xmtbuf[32];
-    int li_vn_mode = 0, stratum = 0, ppoll = 0, precision = 0;
-
-    if (sscanf(pktbuf, "%d:%d:%d:%d:%u:%u:%u:%s:%s:%s:%s",
-	       &li_vn_mode, &stratum,
-	       &ppoll, &precision,
-	       &pkt->rootdelay, &pkt->rootdisp,
-	       &pkt->refid,
-	       refbuf, orgbuf, recbuf, xmtbuf) != 7)
+    int fc, li_vn_mode = 0, stratum = 0, ppoll = 0, precision = 0;
+
+    printf("Foo! %s\n", pktbuf);
+    if ((fc = sscanf(pktbuf, "%d:%d:%d:%d:%u:%u:%u:%[^:]:%[^:]:%[^:]:%[^:]",
+		     &li_vn_mode, &stratum,
+		     &ppoll, &precision,
+		     &pkt->rootdelay, &pkt->rootdisp,
+		     &pkt->refid,
+		     refbuf, orgbuf, recbuf, xmtbuf)) != 11)
     {
-	fprintf(stderr, "ntpd: malformed packet dump at line %d\n",
-		lineno);
+	fprintf(stderr, "ntpd: %d fields in malformed packet dump at line %d\n",
+		fc, lineno);
 	exit(1);
     }
     /* extra transfers required because the struct members are int8_t */
@@ -731,6 +732,11 @@ void intercept_receive(struct recvbuf *rbufp)
 	fputs(pkt_dump, stdout);
     }
 
+    /*
+     * Processing has to come after the dump so that if a send or time adjustment
+     * is called during replay the corresponding event in the log will be found
+     * where it should be after the receive.
+     */
     receive(rbufp);
 }
 
@@ -739,9 +745,9 @@ void intercept_replay(void)
     printf("# entering replay loop at line %d\n", lineno);
     for (;;) {
 	get_operation(NULL);
-	if (strncmp(linebuf, "finish", 6) == 0)
+	if (strncmp(linebuf, "finish", 7) == 0)
 	    break;
-	else if (strncmp(linebuf, "sendpkt ", 9) == 0)
+	else if (strncmp(linebuf, "sendpkt ", 8) == 0)
 	    /*
 	     * If we get here, this is a sendpkt generated not by the protocol
 	     * machine but by an initial association setup. No way to check it,
@@ -768,7 +774,7 @@ void intercept_replay(void)
 	    }
 
 	    pkt = &rbuf.recv_pkt;
-	    packet_parse(recvbuf, macbuf, pkt);
+	    packet_parse(pktbuf, macbuf, pkt);
 
 	    /*
 	     * If the packet doesn't dump identically to how it came in,


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -3395,7 +3395,11 @@ fetch_timestamp(
 				break;
 #endif  /* USE_SCM_TIMESTAMP */
 			}
-			fuzz = intercept_ntp_random(__func__) * 2. / FRAC * sys_fuzz;
+			/*
+			 * RNG call does notb have toi be recorded for replay
+			 * because the fuzzed timestamp is recorded.
+			 */
+			fuzz = ntp_random() * 2. / FRAC * sys_fuzz;
 			DTOLFP(fuzz, &lfpfuzz);
 			L_ADD(&nts, &lfpfuzz);
 #ifdef DEBUG_TIMING


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -2024,12 +2024,12 @@ clock_update(
 		if (leapsec == LSPROX_NOWARN) {
 			if (leap_vote_ins > leap_vote_del
 			    && leap_vote_ins > sys_survivors / 2) {
-				intercept_get_systime(__func__, &now);
+				get_systime(&now);
 				leapsec_add_dyn(true, now.l_ui, NULL);
 			}
 			if (leap_vote_del > leap_vote_ins
 			    && leap_vote_del > sys_survivors / 2) {
-				intercept_get_systime(__func__, &now);
+				get_systime(&now);
 				leapsec_add_dyn(false, now.l_ui, NULL);
 			}
 		}
@@ -2142,7 +2142,11 @@ poll_update(
 			next = 1 << hpoll;
 		else
 #endif /* REFCLOCK */
-			next = ((0x1000UL | (intercept_ntp_random(__func__) & 0x0ff)) <<
+			/*
+			 * Doesn't need to be captured, because the poll interval
+			 * has no effect on replay.
+			 */
+			next = ((0x1000UL | (ntp_random() & 0x0ff)) <<
 			    hpoll) >> 12;
 		next += peer->outdate;
 		if (next > utemp)
@@ -3106,7 +3110,7 @@ peer_xmit(
 		 * Transmit a-priori timestamps.  This is paired with
 		 * a later call used to record transmission time.
 		 */
-		intercept_get_systime("pre-sendpkt", &xmt_tx);
+		get_systime(&xmt_tx);
 		if (peer->flip == 0) {	/* basic mode */
 			peer->aorg = xmt_tx;
 			HTONL_FP(&xmt_tx, &xpkt.xmt);
@@ -3137,7 +3141,7 @@ peer_xmit(
 		/*
 		 * Capture a-posteriori timestamps
 		 */
-		intercept_get_systime("post-sendpkt", &xmt_ty);
+		get_systime(&xmt_ty);
 		if (peer->flip != 0) {		/* interleaved modes */
 			if (peer->flip > 0)
 				peer->aorg = xmt_ty;


=====================================
ntpd/ntp_timer.c
=====================================
--- a/ntpd/ntp_timer.c
+++ b/ntpd/ntp_timer.c
@@ -331,10 +331,7 @@ timer(void)
 		sys_rootdisp = 0;
 	}
 
-	/*
-	 * Recorded and played back in case the leap-second check fires.
-	 */
-	intercept_get_systime(__func__, &now);
+	get_systime(&now);
 	time(&tnow);
 
 	/*



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/77337b663d95d3d756ca4e00feb0b920c7e0ad8b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151222/341b5b64/attachment.html>


More information about the vc mailing list