<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>Eric S. Raymond pushed to branch master at <a href="https://gitlab.com/NTPsec/ntpsec">NTPsec / ntpsec</a></h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://gitlab.com/NTPsec/ntpsec/commit/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc">f0a57d5e</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-15T18:49:19Z</i>
</div>
<pre class='commit-message'>Checkpoint: replay mode before trying to implement full packet parsing.</pre>
</li>
</ul>
<h4>3 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
ntpd/ntp_intercept.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
ntpd/ntp_intercept.h
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
ntpd/ntpd.c
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/NTPsec/ntpsec/commit/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc#diff-0'>
<strong>
ntpd/ntp_intercept.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/ntpd/ntp_intercept.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/ntpd/ntp_intercept.c
</span><span style="color: #aaaaaa">@@ -18,21 +18,19 @@ following kinds:
</span> 
 6. Calls to the host's random-number generator.
 
<span style="color: #000000;background-color: #ffdddd">-7. Alarm events.
</span><span style="color: #000000;background-color: #ddffdd">+7. Calls to adjtime/ntp_adjtime/adjtime to adjust the system clock.
</span> 
<span style="color: #000000;background-color: #ffdddd">-8. Calls to adjtime/ntp_adjtime/adjtime to adjust the system clock.
</span><span style="color: #000000;background-color: #ddffdd">+8  Calls to ntp_set_tod to set the system clock.
</span> 
<span style="color: #000000;background-color: #ffdddd">-9  Calls to ntp_set_tod to set the system clock.
</span><span style="color: #000000;background-color: #ddffdd">+9. Read of the system leapsecond file.
</span> 
<span style="color: #000000;background-color: #ffdddd">-10. Read of the system leapsecond file.
</span><span style="color: #000000;background-color: #ddffdd">+10. Packets incoming from NTP peers and others.
</span> 
<span style="color: #000000;background-color: #ffdddd">-11. Packets incoming from NTP peers and others.
</span><span style="color: #000000;background-color: #ddffdd">+11. Packets outgoing to NTP peers and others.
</span> 
<span style="color: #000000;background-color: #ffdddd">-12. Packets outgoing to NTP peers and others.
</span><span style="color: #000000;background-color: #ddffdd">+12. Read of authkey file
</span> 
<span style="color: #000000;background-color: #ffdddd">-13. Read of authkey file
-
-14. Termination.
</span><span style="color: #000000;background-color: #ddffdd">+13. Termination.
</span> 
 We must support two modes of operation.  In "capture" mode, ntpd
 operates normally, logging all events.  In "replay" mode, ntpd accepts
<span style="color: #aaaaaa">@@ -331,16 +329,6 @@ long intercept_ntp_random(const char *legend)
</span>     return roll;
 }
 
<span style="color: #000000;background-color: #ffdddd">-void intercept_timer(void)
-{
-    timer();
-    if (mode == capture)
-       printf("timer\n");
-    else if (mode == replay)
-       /* probably is not necessary to record this... */
-       get_operation("timer");
-}
-
</span> bool intercept_drift_read(const char *drift_file, double *drift)
 {
     if (mode == replay) {
<span style="color: #aaaaaa">@@ -625,7 +613,7 @@ intercept_leapsec_load_file(
</span> }
 
 static void packet_dump(char *buf, size_t buflen,
<span style="color: #000000;background-color: #ffdddd">-                        sockaddr_u *dest, struct pkt *pkt, int len)
</span><span style="color: #000000;background-color: #ddffdd">+                   sockaddr_u *dest, struct pkt *pkt, size_t len)
</span> {
     size_t i;
     /*
<span style="color: #aaaaaa">@@ -650,6 +638,23 @@ static void packet_dump(char *buf, size_t buflen,
</span>   }
 }
 
<span style="color: #000000;background-color: #ddffdd">+static void recvbuf_dump(char *buf, size_t buflen, struct recvbuf *rbufp)
+{
+    char pkt_dump[BUFSIZ];
+
+    packet_dump(pkt_dump, sizeof(pkt_dump),
+               &rbufp->recv_srcadr, &rbufp->recv_pkt, rbufp->recv_length);
+    /*
+     * Order is: cast flags, receipt time, source address, packet,
+     * MAC.  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.
+     */
+    snprintf(buf, buflen,
+            "receive %0x %s %s\n",
+            rbufp->cast_flags, lfpdump(&rbufp->recv_time), pkt_dump);
+}
+
</span> void intercept_sendpkt(const char *legend,
                  sockaddr_u *dest, struct interface *ep, int ttl,
                  struct pkt *pkt, int len)
<span style="color: #aaaaaa">@@ -677,31 +682,62 @@ void intercept_sendpkt(const char *legend,
</span> 
 void intercept_receive(struct recvbuf *rbufp)
 {
<span style="color: #000000;background-color: #ffdddd">-    char pkt_dump[BUFSIZ], newpacket[BUFSIZ];
</span><span style="color: #000000;background-color: #ddffdd">+    /* never called in replay mode */
+    if (mode == capture) {
+       char pkt_dump[BUFSIZ];
</span> 
<span style="color: #000000;background-color: #ffdddd">-    packet_dump(pkt_dump, sizeof(pkt_dump),
-               &rbufp->recv_srcadr,
-               &rbufp->recv_pkt, rbufp->recv_length);
-    /*
-     * Order is: cast flags, receipt time, source address, packet,
-     * MAC.  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.
-     */
-    snprintf(newpacket, sizeof(newpacket),
-            "receive %0x %s %s\n",
-            rbufp->cast_flags, lfpdump(&rbufp->recv_time), pkt_dump);
</span><span style="color: #000000;background-color: #ddffdd">+   recvbuf_dump(pkt_dump, sizeof(pkt_dump), rbufp);
+       fputs(pkt_dump, stdout);
+    }
</span> 
<span style="color: #000000;background-color: #ffdddd">-    if (mode == replay) {
-       if (strcmp(linebuf, newpacket) != 0) {
-           fprintf(stderr, "ntpd: line %d, receive mismatch saw %s\n",
-                   lineno, newpacket);
</span><span style="color: #000000;background-color: #ddffdd">+    receive(rbufp);
+}
+
+void intercept_replay(void)
+{
+    printf("# entering replay loop at line %d\n", lineno);
+    for (;;) {
+       get_operation(NULL);
+       if (strncmp(linebuf, "finish", 6) == 0)
+           break;
+       else if (strncmp(linebuf, "receive ", 8) == 0)
+       {
+           struct recvbuf rbuf;
+           char recvbuf[BUFSIZ], srcbuf[BUFSIZ], pktbuf[BUFSIZ], macbuf[BUFSIZ];
+
+           if (sscanf(linebuf, "receive %x %s %s %s %s",
+                      &rbuf.cast_flags, recvbuf, srcbuf, pktbuf, macbuf) != 5)
+           {
+               fprintf(stderr, "ntpd: bad receive format at line %d\n", lineno);
+               exit(1);
+           }
+
+           atolfp(recvbuf, &rbuf.recv_time);
+           /* FIXME: parse source address */
+           /* FIXME: parse packet and MAC */
+
+           /*
+            * If the packet doesn't dump identically to how it came in,
+            * something is wrong with our packet parsing.
+            */
+           recvbuf_dump(recvbuf, sizeof(recvbuf), &rbuf);
+           if (strcmp(linebuf, recvbuf) != 0)
+           {
+               fprintf(stderr, "ntpd: round-trip failure at line %d\n", lineno);
+               fprintf(stderr, "old = %s\n", linebuf);
+               fprintf(stderr, "new = %s\n", recvbuf);
+               exit(1);
+           }
+
+           /* executing the receive call may pop other things off the queue */
+           receive(&rbuf);
+       }
+       else
+       {
+           fprintf(stderr, "ntpd: unexpected operation at line %d\n", lineno);
</span>       exit(1);
        }
<span style="color: #000000;background-color: #ffdddd">-    } else if (mode == capture)
-       fputs(newpacket, stdout);
-
-    receive(rbufp);
</span><span style="color: #000000;background-color: #ddffdd">+    }
</span> }
 
 void
</code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://gitlab.com/NTPsec/ntpsec/commit/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc#diff-1'>
<strong>
ntpd/ntp_intercept.h
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/ntpd/ntp_intercept.h
</span><span style="color: #000000;background-color: #ddffdd">+++ b/ntpd/ntp_intercept.h
</span><span style="color: #aaaaaa">@@ -20,7 +20,6 @@ void intercept_argparse(int *, char ***);
</span> void intercept_getconfig(const char *);
 void intercept_get_systime(const char *, l_fp *);
 long intercept_ntp_random(const char *);
<span style="color: #000000;background-color: #ffdddd">-void intercept_timer(void);
</span> void intercept_sendpkt(const char *,
                       sockaddr_u *, struct interface *, int, struct pkt *, int);
 void intercept_receive(struct recvbuf *);
<span style="color: #aaaaaa">@@ -34,6 +33,7 @@ int intercept_set_tod(struct timespec *tvs);
</span> extern bool intercept_leapsec_load_file(const char * fname, struct stat * sb,
                                        bool force, bool logall);
 void intercept_getauthkeys(const char *);
<span style="color: #000000;background-color: #ddffdd">+void intercept_replay(void);
</span> void intercept_exit(const int);
 
 /* end */
</code></pre>

<br>
</li>
<li id='diff-2'>
<a href='https://gitlab.com/NTPsec/ntpsec/commit/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc#diff-2'>
<strong>
ntpd/ntpd.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/ntpd/ntpd.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/ntpd/ntpd.c
</span><span style="color: #aaaaaa">@@ -935,7 +935,10 @@ ntpdmain(
</span>           msyslog(LOG_INFO, "running as non-root disables dynamic interface tracking");
        }
 
<span style="color: #000000;background-color: #ffdddd">-        mainloop();
</span><span style="color: #000000;background-color: #ddffdd">+   if (intercept_get_mode() == replay)
+           intercept_replay();
+       else
+           mainloop();
</span>   return 1;
 }
 
<span style="color: #aaaaaa">@@ -980,7 +983,7 @@ static void mainloop(void)
</span>                    * Out here, signals are unblocked.  Call timer routine
                         * to process expiry.
                         */
<span style="color: #000000;background-color: #ffdddd">-                        intercept_timer();
</span><span style="color: #000000;background-color: #ddffdd">+                   timer();
</span>                   was_alarmed = false;
                        BLOCK_IO_AND_ALARM();
                }
</code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>

<br>
<a href="https://gitlab.com/NTPsec/ntpsec/commit/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc">View it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://gitlab.com/NTPsec/ntpsec/commit/f0a57d5e59c8dda9f3a9ec789bd79ab7fde791cc"}}</script>
</p>
</div>
</body>
</html>