[Git][NTPsec/ntpsec][master] 2 commits: Refactor, we're going to need packet dumping for packet receives.
Eric S. Raymond
gitlab at mg.gitlab.com
Fri Dec 4 12:49:30 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
c39eb9f4 by Eric S. Raymond at 2015-12-04T06:11:39Z
Refactor, we're going to need packet dumping for packet receives.
- - - - -
6b1754ad by Eric S. Raymond at 2015-12-04T07:47:54Z
Properly intercept and replay timer events.
- - - - -
3 changed files:
- ntpd/ntp_intercept.c
- ntpd/ntp_intercept.h
- ntpd/ntpd.c
Changes:
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -30,9 +30,7 @@ following kinds:
12. Read of authkey file
-13. getaddrinfo() calls (TODO)
-
-14. Termination.
+13. Termination.
We must support two modes of operation. In "capture" mode, ntpd
operates normally, logging all events. In "replay" mode, ntpd accepts
@@ -187,12 +185,11 @@ long intercept_ntp_random(const char *legend)
return rand;
}
-void intercept_alarm(void)
+void intercept_timer(void)
{
- /* FIXME: replay mode, calling timer(), goes here */
-
if (mode != none)
- printf("event tick\n");
+ printf("event timer\n");
+ timer();
}
bool intercept_drift_read(const char *drift_file, double *drift)
@@ -319,6 +316,24 @@ intercept_leapsec_load_file(
return loaded;
}
+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",
+ 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);
+ /* dump MAC as len - LEN_PKT_NOMAC chars in hex */
+ for (i = 0; i < len - LEN_PKT_NOMAC; i++)
+ printf("%02x", pkt->exten[i]);
+ fputs("\n", stdout);
+}
+
void intercept_sendpkt(const char *legend,
sockaddr_u *dest, struct interface *ep, int ttl,
struct pkt *pkt, int len)
@@ -327,19 +342,8 @@ void intercept_sendpkt(const char *legend,
sendpkt(dest, ep, ttl, pkt, len);
if (mode != none) {
- size_t i;
- printf("event sendpkt \"%s\" %s %d:%d:%d:%d:%u:%u:%u:%d:%d:%d:%d",
- legend, 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);
- /* dump MAC as len - LEN_PKT_NOMAC chars in hex */
- for (i = 0; i < len - LEN_PKT_NOMAC; i++)
- printf("%02x", pkt->exten[i]);
+ printf("event sendpkt \"%s\"", legend);
+ packet_dump(dest, pkt, len);
fputs("\n", stdout);
}
=====================================
ntpd/ntp_intercept.h
=====================================
--- a/ntpd/ntp_intercept.h
+++ b/ntpd/ntp_intercept.h
@@ -29,7 +29,7 @@ void intercept_argparse(int *, char ***);
void intercept_getconfig(const char *);
void intercept_get_systime(const char *, l_fp *);
long intercept_ntp_random(const char *);
-void intercept_alarm(void);
+void intercept_timer(void);
void intercept_sendpkt(const char *,
sockaddr_u *, struct interface *, int, struct pkt *, int);
bool intercept_drift_read(const char *, double *);
=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -961,13 +961,12 @@ static void mainloop(void)
}
if (was_alarmed) {
- intercept_alarm();
UNBLOCK_IO_AND_ALARM();
/*
* Out here, signals are unblocked. Call timer routine
* to process expiry.
*/
- timer();
+ intercept_timer();
was_alarmed = false;
BLOCK_IO_AND_ALARM();
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/804a57f98785806e6393056d249b47b6a0836f60...6b1754ade2d34ffbb28e6fc1ad955dc1d75fb89b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151204/f759f9bb/attachment.html>
More information about the vc
mailing list