[Git][NTPsec/ntpsec][master] 2 commits: TESTFRAME: Packet & address dumping for intercept_sendpkt().
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Nov 30 07:22:31 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
a49546fa by Eric S. Raymond at 2015-11-29T18:48:54Z
TESTFRAME: Packet & address dumping for intercept_sendpkt().
- - - - -
d9634441 by Eric S. Raymond at 2015-11-30T02:20:55Z
Unbreak the build on Mac OS X.
Broken in "Refactor so intercept_log does not have to be visible."
- - - - -
2 changed files:
- ntpd/ntp_intercept.c
- ntpd/ntpd.c
Changes:
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -24,9 +24,9 @@ following kinds:
9. Read of the system leapsecond file.
-10. Packets incoming from NTP daemons. (TODO)
+10. Packets incoming from NTP peers and others. (TODO)
-11. Packets outgoing to NTP daemons. (TODO)
+11. Packets outgoing to NTP peers and others.
12. Read of authkey file
@@ -86,6 +86,8 @@ no mismatches.
#include <netinet/in.h>
#include <arpa/inet.h>
#include <libgen.h>
+#include <sys/socket.h>
+#include <netdb.h>
#include "ntpd.h"
#include "ntp_io.h"
@@ -325,10 +327,33 @@ void intercept_sendpkt(const char *legend,
sendpkt(dest, ep, ttl, pkt, len);
if (mode != none) {
- printf("event sendpkt \"%s\" ...", legend);
- /* FIXME: dump the destination and the guts of the packet */
- fputs("\n", stdout);
+ char host[BUFSIZ], serv[BUFSIZ];
+ /* sanity check: serv should always be "ntp" */
+ int status = getnameinfo(&dest->sa, SOCKLEN(dest),
+ host, sizeof(host),
+ serv, sizeof(serv),
+ NI_NUMERICSERV);
+ if (status != 0)
+ fprintf(stderr, "ntpd: getnameinfo() failed in intercept_sendpkt()\n");
+ else {
+ size_t i;
+ printf("event sendpkt \"%s\" %s %s %d:%d:%d:%d:%u:%u:%u:%d:%d:%d:%d",
+ legend, host, serv,
+ 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);
+ }
}
+
+ /* FIXME: replay logic goes here */
}
void
@@ -354,33 +379,15 @@ intercept_getauthkeys(
/* FIXME: replay logic goes here */
}
-#if !defined(SIM) && defined(SIGDIE1)
-/*
- * finish - exit gracefully
- */
-void intercept_finish(const int sig)
+void intercept_finish(int sig)
{
- if (mode == capture)
- printf("finish %d\n", 0);
+ if (mode != none)
+ printf("finish %d\n", sig);
- if (mode != replay) {
- const char *sig_desc;
-
- sig_desc = NULL;
- sig_desc = strsignal(sig);
- if (sig_desc == NULL)
- sig_desc = "";
- msyslog(LOG_NOTICE, "%s exiting on signal %d (%s)", progname,
- sig, sig_desc);
- /* See Bug 2513 and Bug 2522 re the unlink of PIDFILE */
-# if defined(HAVE_DNS_SD_H) && defined(ENABLE_MDNS_REGISTRATION)
- if (mdns != NULL)
- DNSServiceRefDeallocate(mdns);
-# endif
- peer_cleanup();
- exit(0);
- }
-}
+#if !defined(SIM) && defined(SIGDIE1)
+ extern void finish(int); /* ugh */
+ finish(sig);
#endif /* !SIM && SIGDIE1 */
+}
/* end */
=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -1047,6 +1047,36 @@ ntpdmain(
}
#endif /* !SIM */
+
+#if !defined(SIM) && defined(SIGDIE1)
+/*
+ * finish - exit gracefully
+ */
+void
+finish(
+ int sig
+ )
+{
+ const char *sig_desc;
+
+ intercept_log("event shutdown 0\n");
+ sig_desc = NULL;
+ sig_desc = strsignal(sig);
+ if (sig_desc == NULL)
+ sig_desc = "";
+ msyslog(LOG_NOTICE, "%s exiting on signal %d (%s)", progname,
+ sig, sig_desc);
+ /* See Bug 2513 and Bug 2522 re the unlink of PIDFILE */
+# if defined(HAVE_DNS_SD_H) && defined(ENABLE_MDNS_REGISTRATION)
+ if (mdns != NULL)
+ DNSServiceRefDeallocate(mdns);
+# endif
+ peer_cleanup();
+ exit(0);
+}
+#endif /* !SIM && SIGDIE1 */
+
+
#ifndef SIM
/*
* wait_child_sync_if - implements parent side of -w/--wait-sync
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/9da2eff0ba84774de3379a26aa8d26c7a8c4c3bd...d96344411cc91969dcc1e742f64f8aba7802804d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151130/0a1fc74e/attachment.html>
More information about the vc
mailing list