<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/b6e96fe6c7c2e23c9ca0e12db50c88c46871873e">b6e96fe6</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-13T06:02:08Z</i>
</div>
<pre class='commit-message'>Simplified replay implementation of send and receive.</pre>
</li>
<li>
<strong><a href="https://gitlab.com/NTPsec/ntpsec/commit/f9e35ff6dda2b8b383f46de06cbf103dd6955439">f9e35ff6</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-13T06:58:58Z</i>
</div>
<pre class='commit-message'>First complete version of replay interpreter ready for test.</pre>
</li>
</ul>
<h4>1 changed file:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
ntpd/ntp_intercept.c
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/NTPsec/ntpsec/compare/2a62a835720abda7fab87740dd05ae284893c3dc...f9e35ff6dda2b8b383f46de06cbf103dd6955439#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">@@ -210,36 +210,49 @@ static bool pump(const char *fn, const char *lead, const char *trail, FILE *ofp)
</span> }
}
<span style="color: #000000;background-color: #ffdddd">-
-void intercept_getconfig(const char *configfile)
</span><span style="color: #000000;background-color: #ddffdd">+static void file_replay(const char *configfile, char *delimiter, char *tempfile)
</span> {
<span style="color: #000000;background-color: #ffdddd">- if (mode != replay)
- /* this can be null if the default config doesn't exist */
- configfile = getconfig(configfile);
</span><span style="color: #000000;background-color: #ddffdd">+ FILE *tfp;
</span>
<span style="color: #000000;background-color: #ffdddd">- if (configfile != NULL && mode != none)
- pump(configfile, "startconfig\n", "endconfig\n", stdout);
</span><span style="color: #000000;background-color: #ddffdd">+ tfp = fopen(tempfile, "w");
+ if (tfp == NULL) {
+ fprintf(stderr,
+ "ntpd: replay failed, can't copy %s\n", configfile);
+ exit(1);
+ }
+ for (;;) {
+ char *nextline = fgets(linebuf, sizeof(linebuf), stdin);
</span>
<span style="color: #000000;background-color: #ddffdd">+ ++lineno;
+ if (nextline == NULL) {
+ fprintf(stderr,
+ "ntpd: replay failed, unexpected EOF at line %d\n", lineno);
+ exit(1);
+ }
+ if (strncmp(linebuf, delimiter, strlen(delimiter)) == 0)
+ break;
+ fputs(linebuf, tfp);
+ }
+ fclose(tfp);
+}
+
+void intercept_getconfig(const char *configfile)
+{
</span> if (mode == replay) {
char tempfile[PATH_MAX];
<span style="color: #000000;background-color: #ffdddd">- FILE *tfp;
</span>
stats_control = false; /* suppress writing stats files */
get_operation("startconfig");
snprintf(tempfile, sizeof(tempfile), ".fake_ntp_config_%d", getpid());
<span style="color: #000000;background-color: #ffdddd">- tfp = fopen(tempfile, "w");
- for (;;) {
- char *nextline = fgets(linebuf, sizeof(linebuf), stdin);
- if (nextline == NULL) {
- fputs("ntpd: replay failed, unexpected EOF in config\n", stderr);
- exit(1);
- }
- if (strncmp(linebuf, "endconfig", 9) == 0)
- break;
- fputs(linebuf, tfp);
- }
</span><span style="color: #000000;background-color: #ddffdd">+ file_replay(configfile, "endconfig", tempfile);
</span> getconfig(tempfile);
unlink(tempfile);
<span style="color: #000000;background-color: #ddffdd">+ } else {
+ /* this can be null if the default config doesn't exist */
+ configfile = getconfig(configfile);
+
+ if (configfile != NULL && mode != none)
+ pump(configfile, "startconfig\n", "endconfig\n", stdout);
</span> }
}
<span style="color: #aaaaaa">@@ -256,7 +269,7 @@ void intercept_get_systime(const char *legend, l_fp *now)
</span> if (mode == replay) {
int sec, subsec;
char expecting[BUFSIZ];
<span style="color: #000000;background-color: #ffdddd">- get_operation("systime");
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("systime ");
</span> if (sscanf(linebuf, "systime %s %d.%d", expecting, &sec, &subsec) != 3) {
fprintf(stderr, "ntpd: garbled systime format, line %d\n", lineno);
exit(1);
<span style="color: #aaaaaa">@@ -289,6 +302,7 @@ long intercept_ntp_random(const char *legend)
</span> * as all the environment-altering functions that call ntp_random()
* are themselves intercepted.
*/
<span style="color: #000000;background-color: #ddffdd">+ get_operation("random ");
</span> if (sscanf(linebuf, "random %s %ld", expecting, &roll) != 2) {
fprintf(stderr, "ntpd: garbled random format, line %d\n", lineno);
exit(1);
<span style="color: #aaaaaa">@@ -323,7 +337,7 @@ bool intercept_drift_read(const char *drift_file, double *drift)
</span> {
if (mode == replay) {
float df;
<span style="color: #000000;background-color: #ffdddd">- get_operation("drift_read");
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("drift_read ");
</span> if (strstr(linebuf, "false") != NULL)
return false;
/*
<span style="color: #aaaaaa">@@ -373,7 +387,7 @@ void intercept_drift_write(char *driftfile, double drift)
</span> * replay mode, so just check that we're writing out the same drift.
*/
float df;
<span style="color: #000000;background-color: #ffdddd">- get_operation("drift-write");
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("drift-write ");
</span> /* See the comment of drift-read chwxcking. */
if (sscanf(linebuf, "drift-write %f'", &df) != 1) {
fprintf(stderr, "ntpd: garbled drift-write format, line %d\n",lineno);
<span style="color: #aaaaaa">@@ -423,7 +437,7 @@ int intercept_adjtime(const struct timeval *ntv, struct timeval *otv)
</span> {
if (mode == replay) {
struct timeval rntv, rotv;
<span style="color: #000000;background-color: #ffdddd">- get_operation("adjtime");
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("adjtime ");
</span> /* bletch - likely to foo up on 32-bit machines */
if (sscanf(linebuf, "adjtime %ld %ld %ld %ld",
&rntv.tv_sec, &rntv.tv_usec,
<span style="color: #aaaaaa">@@ -491,7 +505,7 @@ int intercept_ntp_adjtime(struct timex *tx)
</span> if (mode == replay)
{
struct timex rtx;
<span style="color: #000000;background-color: #ffdddd">- get_operation("ntp_adjtime");
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("ntp_adjtime ");
</span> if (sscanf(linebuf, "ntp_adtime " ADJFMT " %d",
&rtx.modes,
&rtx.offset,
<span style="color: #aaaaaa">@@ -555,42 +569,65 @@ int intercept_ntp_adjtime(struct timex *tx)
</span>
int intercept_set_tod(struct timespec *tvs)
{
<span style="color: #000000;background-color: #ddffdd">+ char newset[BUFSIZ];
+ snprintf(newset, sizeof(newset),
+ "set_tod %ld %ld\n", (long)tvs->tv_sec, (long)tvs->tv_nsec);
+
</span> if (mode == replay) {
get_operation("set_tod");
<span style="color: #000000;background-color: #ffdddd">- /* FIXME: more replay logic goes here */
</span><span style="color: #000000;background-color: #ddffdd">+ if (strcmp(linebuf, newset) != 0) {
+ fprintf(stderr, "ntpd: line %d, set_tod mismatch saw %s\n",
+ lineno, newset);
+ exit(1);
+ }
+ return 0;
</span> }
else {
if (mode == capture)
<span style="color: #000000;background-color: #ffdddd">- printf("set_tod %ld %ld\n", (long)tvs->tv_sec, (long)tvs->tv_nsec);
</span><span style="color: #000000;background-color: #ddffdd">+ fputs(newset, stdout);
</span> return ntp_set_tod(tvs);
}
<span style="color: #000000;background-color: #ffdddd">- return 0;
</span> }
bool
intercept_leapsec_load_file(
<span style="color: #000000;background-color: #ffdddd">- const char * fname,
- struct stat * sb_old,
</span><span style="color: #000000;background-color: #ddffdd">+ const char *leapsecfile,
+ struct stat *sb_old,
</span> bool force,
bool logall)
{
bool loaded = true;
<span style="color: #000000;background-color: #ffdddd">- if (mode != replay)
- loaded = leapsec_load_file(fname, sb_old, force, logall);
</span><span style="color: #000000;background-color: #ddffdd">+ if (mode == replay) {
+ char tempfile[PATH_MAX];
</span>
<span style="color: #000000;background-color: #ffdddd">- if (mode == capture)
- pump(fname, "startleapsec\n", "endleapsec\n", stdout);
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("startleapsec");
+ snprintf(tempfile, sizeof(tempfile), ".fake_leapsec_file_%d", getpid());
+ file_replay(leapsecfile, "endleapsec", tempfile);
+ loaded = leapsec_load_file(tempfile, sb_old, force, logall);
+ unlink(tempfile);
+ } else {
+ loaded = leapsec_load_file(leapsecfile, sb_old, force, logall);
+
+ if (mode == capture)
+ pump(leapsecfile, "startleapsec\n", "endleapsec\n", stdout);
+ }
</span>
<span style="color: #000000;background-color: #ffdddd">- /* FIXME: replay logic goes here */
-
</span> return loaded;
}
<span style="color: #000000;background-color: #ffdddd">-static void packet_dump(sockaddr_u *dest, struct pkt *pkt, int len)
</span><span style="color: #000000;background-color: #ddffdd">+static void packet_dump(char *buf, size_t buflen,
+ sockaddr_u *dest, struct pkt *pkt, int len)
</span> {
<span style="color: #000000;background-color: #ddffdd">+ /*
+ * Order is: cast flags, receipt time, interface name, 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.
+ */
</span> size_t i;
<span style="color: #000000;background-color: #ffdddd">- printf("%s %d:%d:%d:%d:%u:%u:%u:%s:%s:%s:%s",
</span><span style="color: #000000;background-color: #ddffdd">+ snprintf(buf, buflen, "%s %d:%d:%d:%d:%u:%u:%u:%s:%s:%s:%s",
</span> socktoa(dest),
pkt->li_vn_mode, pkt->stratum, pkt->ppoll, pkt->precision,
/* FIXME: might be better to dump these in fixed-point */
<span style="color: #aaaaaa">@@ -607,54 +644,68 @@ void intercept_sendpkt(const char *legend,
</span> sockaddr_u *dest, struct interface *ep, int ttl,
struct pkt *pkt, int len)
{
<span style="color: #000000;background-color: #ffdddd">- if (mode != replay)
</span><span style="color: #000000;background-color: #ddffdd">+ char pkt_dump[BUFSIZ], newpacket[BUFSIZ];
+ packet_dump(pkt_dump, sizeof(pkt_dump), dest, pkt, len);
+ snprintf(newpacket, sizeof(newpacket), "sendpkt %s %s\n", legend, pkt_dump);
+
+ if (mode == replay)
+ {
+ get_operation("sendpkt ");
+ if (strcmp(linebuf, newpacket) != 0) {
+ fprintf(stderr, "ntpd: line %d, sendpkt mismatch saw %s\n",
+ lineno, pkt_dump);
+ exit(1);
+ }
+ } else {
</span> sendpkt(dest, ep, ttl, pkt, len);
<span style="color: #000000;background-color: #ffdddd">- if (mode != none) {
- printf("sendpkt \"%s\" ", legend);
- packet_dump(dest, pkt, len);
- fputs("\n", stdout);
</span><span style="color: #000000;background-color: #ddffdd">+ if (mode == capture)
+ fputs(newpacket, stdout);
</span> }
<span style="color: #000000;background-color: #ffdddd">-
- /* FIXME: replay logic goes here */
</span> }
void intercept_receive(struct recvbuf *rbufp)
{
<span style="color: #000000;background-color: #ffdddd">- if (mode != none) {
- /*
- * Order is: cast flags, receipt time, interface name, 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("receive %0x %s %s ",
- rbufp->cast_flags,
- lfpdump(&rbufp->recv_time),
- rbufp->dstadr->name);
- packet_dump(&rbufp->recv_srcadr, &rbufp->recv_pkt, rbufp->recv_length);
- fputs("\n", stdout);
- }
</span><span style="color: #000000;background-color: #ddffdd">+ char pkt_dump[BUFSIZ], newpacket[BUFSIZ];
+ packet_dump(pkt_dump, sizeof(pkt_dump),
+ &rbufp->recv_srcadr,
+ &rbufp->recv_pkt, rbufp->recv_length);
+ 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: #ffdddd">- if (mode != replay)
- receive(rbufp);
</span><span style="color: #000000;background-color: #ddffdd">+ if (mode == replay) {
+ get_operation("receive ");
+ if (strcmp(linebuf, newpacket) != 0) {
+ fprintf(stderr, "ntpd: line %d, receive mismatch saw %s\n",
+ lineno, newpacket);
+ exit(1);
+ }
+ } else {
+ if (mode == capture)
+ fputs(newpacket, stdout);
</span>
<span style="color: #000000;background-color: #ffdddd">- /* FIXME: replay logic goes here */
</span><span style="color: #000000;background-color: #ddffdd">+ receive(rbufp);
+ }
</span> }
void
<span style="color: #000000;background-color: #ffdddd">-intercept_getauthkeys(
- const char * fname)
</span><span style="color: #000000;background-color: #ddffdd">+intercept_getauthkeys(const char *authkeysfile)
</span> {
<span style="color: #000000;background-color: #ffdddd">- if (mode != replay)
- getauthkeys(fname);
</span><span style="color: #000000;background-color: #ddffdd">+ if (mode == replay) {
+ char tempfile[PATH_MAX];
</span>
<span style="color: #000000;background-color: #ffdddd">- if (mode == capture) {
- pump(fname, "startauthkeys", "endauthkeys", stdout);
- }
</span><span style="color: #000000;background-color: #ddffdd">+ get_operation("startauthkeys");
+ snprintf(tempfile, sizeof(tempfile), ".fake_ntp_authkeys_%d", getpid());
+ file_replay(authkeysfile, "endauthkeys", tempfile);
+ getauthkeys(tempfile);
+ unlink(tempfile);
+ } else {
+ getauthkeys(authkeysfile);
</span>
<span style="color: #000000;background-color: #ffdddd">- /* FIXME: replay logic goes here */
</span><span style="color: #000000;background-color: #ddffdd">+ if (mode == capture)
+ pump(authkeysfile, "startauthkeys\n", "endauthkeys\n", stdout);
+ }
</span> }
void intercept_exit(int sig)
</code></pre>
<br>
</li>
</div>
<div class='footer' style='margin-top: 10px;'>
<p>
—
<br>
<a href="https://gitlab.com/NTPsec/ntpsec/compare/2a62a835720abda7fab87740dd05ae284893c3dc...f9e35ff6dda2b8b383f46de06cbf103dd6955439">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.
</p>
</div>
</body>
</html>