<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/9ddcb323e89f0250d82441365f0618c56cab421e">9ddcb323</a></strong>
<div>
<span>by Eric S. Raymond</span>
<i>at 2015-12-11T15:05:16Z</i>
</div>
<pre class='commit-message'>Partial implementation of replay.</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/commit/9ddcb323e89f0250d82441365f0618c56cab421e#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">@@ -114,6 +114,8 @@ static intercept_mode mode = none;
</span> /* mock the clock state */
static l_fp replay_time;
<span style="color: #000000;background-color: #ddffdd">+static char linebuf[256];
+
</span> intercept_mode intercept_get_mode(void)
{
return mode;
<span style="color: #aaaaaa">@@ -128,9 +130,35 @@ void intercept_set_mode(intercept_mode newmode)
</span> }
}
<span style="color: #000000;background-color: #ddffdd">+static void get_operation(const char *expect)
+/* get the next (non-comment) line from the log */
+{
+ for (;;)
+ {
+ char *in = fgets(linebuf, sizeof(linebuf), stdin);
+
+ if (in == NULL) {
+ fputs("ntpd: replay failed, unexpected EOF\n", stderr);
+ exit(1);
+ }
+
+ if (expect != NULL && strncmp(linebuf, expect, strlen(expect)) != 0) {
+ fprintf(stderr, "ntpd: replay failed, expected %s but saw %*s\n",
+ expect, (int)strlen(expect), linebuf);
+ exit(1);
+ }
+
+ if (linebuf[0] != '#')
+ break;
+ }
+
+}
+
</span> void intercept_argparse(int *argc, char ***argv)
{
int i;
<span style="color: #000000;background-color: #ddffdd">+ const char *leader = "NTP replay version 1";
+
</span> for (i = 1; i < *argc; i++)
if (strcmp((*argv)[i], "-y") == 0)
intercept_set_mode(capture);
<span style="color: #aaaaaa">@@ -139,7 +167,7 @@ void intercept_argparse(int *argc, char ***argv)
</span>
if (mode == capture)
{
<span style="color: #000000;background-color: #ffdddd">- printf("NTP replay version 1\n");
</span><span style="color: #000000;background-color: #ddffdd">+ printf("%s\n", leader);
</span>
printf("startup");
for (i = 1; i < *argc; i++)
<span style="color: #aaaaaa">@@ -147,8 +175,24 @@ void intercept_argparse(int *argc, char ***argv)
</span> printf(" %s", (*argv)[i]);
putchar('\n');
}
<span style="color: #000000;background-color: #ffdddd">-
- /* FIXME: replay logic goes here */
</span><span style="color: #000000;background-color: #ddffdd">+ else if (mode == replay)
+ {
+ char *cp;
+ bool was_space = true;
+
+ /* require a log first line that matches what we can interpret */
+ get_operation(leader);
+
+ get_operation("startup ");
+ *argc = 0;
+ for (cp = strdup(linebuf + 9); *cp; cp++) {
+ if (was_space && !isspace(*cp))
+ (*argv)[(*argc)++] = cp;
+ was_space = isspace(*cp);
+ if (was_space)
+ *cp = '\0';
+ }
+ }
</span> }
static bool pump(const char *fn, const char *lead, const char *trail, FILE *ofp)
<span style="color: #aaaaaa">@@ -180,13 +224,31 @@ void intercept_getconfig(const char *configfile)
</span> pump(configfile, "startconfig\n", "endconfig\n", stdout);
if (mode == replay) {
<span style="color: #000000;background-color: #ddffdd">+ char tempfile[PATH_MAX];
+ FILE *tfp;
+
</span> stats_control = false; /* suppress writing stats files */
<span style="color: #000000;background-color: #ddffdd">+ get_operation("startconfig");
+ snprintf(tempfile, sizeof(tempfile), ".fake_ntp_config_%d", getpid());
+ 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);
+ }
+ getconfig(tempfile);
+ unlink(tempfile);
</span> }
}
void intercept_log(const char *fmt, ...)
{
<span style="color: #000000;background-color: #ffdddd">- if (mode != none) {
</span><span style="color: #000000;background-color: #ddffdd">+ if (mode == capture) {
</span> va_list ap;
va_start(ap, fmt);
vfprintf(stdout, fmt, ap);
</code></pre>
<br>
</li>
</div>
<div class='footer' style='margin-top: 10px;'>
<p>
—
<br>
<a href="https://gitlab.com/NTPsec/ntpsec/commit/9ddcb323e89f0250d82441365f0618c56cab421e">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/9ddcb323e89f0250d82441365f0618c56cab421e"}}</script>
</p>
</div>
</body>
</html>