[Git][NTPsec/ntpsec][master] More steps towards TESTFRAME capture mode - dump most of incoming packets.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Dec 7 21:26:13 UTC 2015


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


Commits:
3921a9eb by Eric S. Raymond at 2015-12-07T16:25:49Z
More steps towards TESTFRAME capture mode - dump most of incoming packets.

- - - - -


2 changed files:

- ntpd/ntp_intercept.c
- ntpd/ntp_intercept.h


Changes:

=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -24,7 +24,7 @@ following kinds:
 
 9. Read of the system leapsecond file.
 
-10. Packets incoming from NTP peers and others.  (TODO)
+10. Packets incoming from NTP peers and others.
 
 11. Packets outgoing to NTP peers and others.
 
@@ -319,15 +319,14 @@ intercept_leapsec_load_file(
 static void packet_dump(sockaddr_u *dest, struct pkt *pkt, int len)
 {
     size_t i;
-    printf("%s %d:%d:%d:%d:%u:%u:%u:%d:%d:%d:%d",
+    printf("%s %d:%d:%d:%d:%u:%u:%u:%s:%s:%s:%s",
 	   socktoa(dest),
 	   pkt->li_vn_mode, pkt->stratum, pkt->ppoll, pkt->precision,
 	   /* FIXME: might be better to dump these in fixed-point */
 	   pkt->rootdelay, pkt->rootdisp,
 	   pkt->refid,
-	   /* FIXME: might be better to dump last 4 in fixed-point */
-	   pkt->reftime.l_uf, pkt->org.l_uf,
-	   pkt->rec.l_uf, pkt->xmt.l_uf);
+	   lfptoa(&pkt->reftime, 10), lfptoa(&pkt->org, 10),
+	   lfptoa(&pkt->rec, 10), lfptoa(&pkt->xmt, 10));
     /* dump MAC as len - LEN_PKT_NOMAC chars in hex */
     for (i = 0; i < len - LEN_PKT_NOMAC; i++)
 	printf("%02x", pkt->exten[i]);
@@ -350,6 +349,27 @@ void intercept_sendpkt(const char *legend,
     /* FIXME: replay logic goes here */
 }
 
+void intercept_receive(struct recvbuf *rbufp)
+{
+    if (mode != replay)
+	receive(rbufp);
+
+    if (mode != none) {
+	/*
+	 * Order is: cast flags, receipt time, source address, packet, length.
+	 * Cast flags are only kept because they change the ntpq display,
+	 * they have no implications for the protocol machine.
+	 * We don't dump srcadr because only the parse clock uses that.
+	 */
+	printf("event receive %0x %s ",
+	       rbufp->cast_flags, lfptoa(&rbufp->recv_time, 10));
+	packet_dump(&rbufp->recv_srcadr, &rbufp->recv_pkt, rbufp->recv_length);
+	fputs("\n", stdout);
+    }
+
+    /* FIXME: replay logic goes here */
+}
+
 void
 intercept_getauthkeys(
 	const char  * fname)


=====================================
ntpd/ntp_intercept.h
=====================================
--- a/ntpd/ntp_intercept.h
+++ b/ntpd/ntp_intercept.h
@@ -32,6 +32,7 @@ long intercept_ntp_random(const char *);
 void intercept_timer(void);
 void intercept_sendpkt(const char *,
 		       sockaddr_u *, struct interface *, int, struct pkt *, int);
+void intercept_receive(struct recvbuf *);
 bool intercept_drift_read(const char *, double *);
 void intercept_drift_write(char *, double);
 #ifdef HAVE_KERNEL_PLL



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/3921a9eb7f8abe2d323bfc1a651e5214d69a9d70
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151207/fffb114a/attachment.html>


More information about the vc mailing list