From: Harlan Stenn Date: Wed, 10 Jun 2015 10:52:55 +0000 (+0000) Subject: [Bug 2778] Implement "apeers" ntpq command to include associd X-Git-Tag: NTP_4_3_38~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab80daf03096b9898e49c3762843bf0b33da56fa;p=thirdparty%2Fntp.git [Bug 2778] Implement "apeers" ntpq command to include associd bk: 55781707H58CTQH80B16KuTsaZp4vA --- diff --git a/ChangeLog b/ChangeLog index 97d1605aa..1713664af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,7 @@ * [Bug 2837] add test for DSCP to ntpd/complete.conf.in * [Bug 2842] Glitch in ntp.conf.def documentation stanza. * [Bug 2842] Bug in mdoc2man. +* [Bug 2887] Implement "apeers" ntpq command to include associd. * Report select() debug messages at debug level 3 now. * sntp/scripts/genLocInfo: treat raspbian as debian. --- diff --git a/ntpq/invoke-ntpq.texi b/ntpq/invoke-ntpq.texi index a1f7b299d..78ee5cbc2 100644 --- a/ntpq/invoke-ntpq.texi +++ b/ntpq/invoke-ntpq.texi @@ -6,7 +6,7 @@ # # EDIT THIS FILE WITH CAUTION (invoke-ntpq.texi) # -# It has been AutoGen-ed May 12, 2015 at 04:33:35 AM by AutoGen 5.18.5 +# It has been AutoGen-ed June 10, 2015 at 10:52:07 AM by AutoGen 5.18.5 # From the definitions ntpq-opts.def # and the template file agtexi-cmd.tpl @end ignore @@ -474,6 +474,16 @@ offset of server relative to this host @item @code{jitter} jitter @end table +@item @code{apeers} +Display a list of peers in the form: +@example +[tally]remote refid assid st t when pool reach delay offset jitter +@end example +where the output is just like the +@code{peers} +command except that the +@code{refid} +is displayed in hex format and the association number is also displayed. @item @code{pstats} @kbd{assocID} Show the statistics for the peer with the given @kbd{assocID}. diff --git a/ntpq/ntpq-opts.c b/ntpq/ntpq-opts.c index 28c5ada45..5d87aff4c 100644 --- a/ntpq/ntpq-opts.c +++ b/ntpq/ntpq-opts.c @@ -1,7 +1,7 @@ /* * EDIT THIS FILE WITH CAUTION (ntpq-opts.c) * - * It has been AutoGen-ed May 12, 2015 at 04:32:57 AM by AutoGen 5.18.5 + * It has been AutoGen-ed June 10, 2015 at 10:51:48 AM by AutoGen 5.18.5 * From the definitions ntpq-opts.def * and the template file options * diff --git a/ntpq/ntpq-opts.def b/ntpq/ntpq-opts.def index 2a9f08c47..bac20d79a 100644 --- a/ntpq/ntpq-opts.def +++ b/ntpq/ntpq-opts.def @@ -608,6 +608,14 @@ offset of server relative to this host .It Ic jitter jitter .El +.It Ic apeers +Display a list of peers in the form: +.Dl [tally]remote refid assid st t when pool reach delay offset jitter +where the output is just like the +.Ic peers +command except that the +.Ic refid +is displayed in hex format and the association number is also displayed. .It Ic pstats Ar assocID Show the statistics for the peer with the given .Ar assocID . diff --git a/ntpq/ntpq-opts.h b/ntpq/ntpq-opts.h index 788bf2334..28ca504e8 100644 --- a/ntpq/ntpq-opts.h +++ b/ntpq/ntpq-opts.h @@ -1,7 +1,7 @@ /* * EDIT THIS FILE WITH CAUTION (ntpq-opts.h) * - * It has been AutoGen-ed May 12, 2015 at 04:32:56 AM by AutoGen 5.18.5 + * It has been AutoGen-ed June 10, 2015 at 10:51:48 AM by AutoGen 5.18.5 * From the definitions ntpq-opts.def * and the template file options * diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index c91e70302..47ca19ccd 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -60,6 +60,8 @@ static int doprintpeers (struct varlist *, int, int, int, const char *, FILE *, static int dogetpeers (struct varlist *, associd_t, FILE *, int); static void dopeers (int, FILE *, int); static void peers (struct parse *, FILE *); +static void doapeers (int, FILE *, int); +static void apeers (struct parse *, FILE *); static void lpeers (struct parse *, FILE *); static void doopeers (int, FILE *, int); static void opeers (struct parse *, FILE *); @@ -156,6 +158,9 @@ struct xcmd opcmds[] = { { "peers", peers, { OPT|IP_VERSION, NO, NO, NO }, { "-4|-6", "", "", "" }, "obtain and print a list of the server's peers [IP version]" }, + { "apeers", apeers, { OPT|IP_VERSION, NO, NO, NO }, + { "-4|-6", "", "", "" }, + "obtain and print a list of the server's peers and their assocIDs [IP version]" }, { "lpeers", lpeers, { OPT|IP_VERSION, NO, NO, NO }, { "-4|-6", "", "", "" }, "obtain and print a list of all peers and clients [IP version]" }, @@ -1559,6 +1564,26 @@ struct varlist peervarlist[] = { { 0, 0 } }; +struct varlist apeervarlist[] = { + { "srcadr", 0 }, /* 0 */ + { "refid", 0 }, /* 1 */ + { "assid", 0 }, /* 2 */ + { "stratum", 0 }, /* 3 */ + { "hpoll", 0 }, /* 4 */ + { "ppoll", 0 }, /* 5 */ + { "reach", 0 }, /* 6 */ + { "delay", 0 }, /* 7 */ + { "offset", 0 }, /* 8 */ + { "jitter", 0 }, /* 9 */ + { "dispersion", 0 }, /* 10 */ + { "rec", 0 }, /* 11 */ + { "reftime", 0 }, /* 12 */ + { "srcport", 0 }, /* 13 */ + { "hmode", 0 }, /* 14 */ + { "srchost", 0 }, /* 15 */ + { 0, 0 } +}; + /* * Decode an incoming data buffer and print a line in the peer list @@ -1675,6 +1700,35 @@ doprintpeers( } else { have_da_rid = FALSE; } + } else if (pvl == apeervarlist) { + have_da_rid = TRUE; + drlen = strlen(value); + if (0 == drlen) { + dstadr_refid = ""; + } else if (drlen <= 4) { + ZERO(u32); + memcpy(&u32, value, drlen); + dstadr_refid = refid_str(u32, 1); + //fprintf(stderr, "apeervarlist S1 refid: value=<%s>\n", value); + } else if (decodenetnum(value, &refidadr)) { + if (SOCK_UNSPEC(&refidadr)) + dstadr_refid = "0.0.0.0"; + else if (ISREFCLOCKADR(&refidadr)) + dstadr_refid = + refnumtoa(&refidadr); + else { + char *buf = emalloc(10); + int i = ntohl(refidadr.sa4.sin_addr.s_addr); + + snprintf(buf, 10, + "%0x", i); + dstadr_refid = buf; + //fprintf(stderr, "apeervarlist refid: value=<%x>\n", i); + } + //fprintf(stderr, "apeervarlist refid: value=<%s>\n", value); + } else { + have_da_rid = FALSE; + } } } else if (!strcmp("stratum", name)) { decodeuint(value, &stratum); @@ -1705,6 +1759,8 @@ doprintpeers( } else if (!strcmp("reftime", name)) { if (!decodets(value, &reftime)) L_CLR(&reftime); + } else { + // fprintf(stderr, "UNRECOGNIZED name=%s ", name); } } @@ -1783,8 +1839,14 @@ doprintpeers( drlen = strlen(dstadr_refid); makeascii(drlen, dstadr_refid, fp); } - while (drlen++ < 15) - fputc(' ', fp); + if (pvl == apeervarlist) { + while (drlen++ < 9) + fputc(' ', fp); + fprintf(fp, "%-6d", associd); + } else { + while (drlen++ < 15) + fputc(' ', fp); + } fprintf(fp, " %2ld %c %4.4s %4.4s %3lo %7.7s %8.7s %7.7s\n", stratum, type, @@ -1903,6 +1965,60 @@ dopeers( } +/* + * doapeers - print a peer spreadsheet with assocIDs + */ +static void +doapeers( + int showall, + FILE *fp, + int af + ) +{ + u_int u; + char fullname[LENHOSTNAME]; + sockaddr_u netnum; + const char * name_or_num; + size_t sl; + + if (!dogetassoc(fp)) + return; + + for (u = 0; u < numhosts; u++) { + if (getnetnum(chosts[u].name, &netnum, fullname, af)) { + name_or_num = nntohost(&netnum); + sl = strlen(name_or_num); + maxhostlen = max(maxhostlen, sl); + } + } + if (numhosts > 1) + fprintf(fp, "%-*.*s ", (int)maxhostlen, (int)maxhostlen, + "server (local)"); + fprintf(fp, + " remote refid assid st t when poll reach delay offset jitter\n"); + if (numhosts > 1) + for (u = 0; u <= maxhostlen; u++) + fprintf(fp, "="); + fprintf(fp, + "==============================================================================\n"); + + for (u = 0; u < numassoc; u++) { + if (!showall && + !(CTL_PEER_STATVAL(assoc_cache[u].status) + & (CTL_PST_CONFIG|CTL_PST_REACH))) { + if (debug) + fprintf(stderr, "eliding [%d]\n", + (int)assoc_cache[u].assid); + continue; + } + if (!dogetpeers(apeervarlist, (int)assoc_cache[u].assid, + fp, af)) + return; + } + return; +} + + /* * peers - print a peer spreadsheet */ @@ -1925,6 +2041,28 @@ peers( } +/* + * apeers - print a peer spreadsheet, with assocIDs + */ +/*ARGSUSED*/ +static void +apeers( + struct parse *pcmd, + FILE *fp + ) +{ + int af = 0; + + if (pcmd->nargs == 1) { + if (pcmd->argval->ival == 6) + af = AF_INET6; + else + af = AF_INET; + } + doapeers(0, fp, af); +} + + /* * lpeers - print a peer spreadsheet including all fuzzball peers */ diff --git a/ntpq/ntpq.1ntpqman b/ntpq/ntpq.1ntpqman index cb788f941..788cd4825 100644 --- a/ntpq/ntpq.1ntpqman +++ b/ntpq/ntpq.1ntpqman @@ -10,11 +10,11 @@ .ds B-Font B .ds I-Font I .ds R-Font R -.TH ntpq 1ntpqman "12 May 2015" "4.2.8p3-RC1" "User Commands" +.TH ntpq 1ntpqman "10 Jun 2015" "4.2.8p3-RC1" "User Commands" .\" -.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-NfaO_W/ag-5faG.W) +.\" EDIT THIS FILE WITH CAUTION (in-mem file) .\" -.\" It has been AutoGen-ed May 12, 2015 at 04:33:29 AM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 10, 2015 at 10:52:09 AM by AutoGen 5.18.5 .\" From the definitions ntpq-opts.def .\" and the template file agman-cmd.tpl .SH NAME @@ -667,6 +667,17 @@ jitter .br .ns .TP 10 +.NOP \f\*[B-Font]apeers\f[] +Display a list of peers in the form: +.Dl [tally]remote refid assid st t when pool reach delay offset jitter +where the output is just like the +\f\*[B-Font]peers\f[] +command except that the +\f\*[B-Font]refid\f[] +is displayed in hex format and the association number is also displayed. +.br +.ns +.TP 10 .NOP \f\*[B-Font]pstats\f[] \f\*[I-Font]assocID\f[] Show the statistics for the peer with the given \f\*[I-Font]assocID\f[]. @@ -737,7 +748,7 @@ appears in the configuration file. \f\*[I-Font]filename\f[] can use -\fCstrftime\fR()\f[] +\fCstrftime\f[]\fR()\f[] format specifies to substitute the current date and time, for example, \f\*[B-Font]q]saveconfig\f[] \f\*[B-Font]ntp-%Y%m%d-%H%M%S.confq]\f[]. The filename used is stored in system variable diff --git a/ntpq/ntpq.1ntpqmdoc b/ntpq/ntpq.1ntpqmdoc index 81ced3b96..999a552f0 100644 --- a/ntpq/ntpq.1ntpqmdoc +++ b/ntpq/ntpq.1ntpqmdoc @@ -1,9 +1,9 @@ -.Dd May 12 2015 +.Dd June 10 2015 .Dt NTPQ 1ntpqmdoc User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntpq-opts.mdoc) .\" -.\" It has been AutoGen-ed May 12, 2015 at 04:33:37 AM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 10, 2015 at 10:52:04 AM by AutoGen 5.18.5 .\" From the definitions ntpq-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME @@ -506,6 +506,14 @@ offset of server relative to this host .It Ic jitter jitter .El +.It Ic apeers +Display a list of peers in the form: +.Dl [tally]remote refid assid st t when pool reach delay offset jitter +where the output is just like the +.Ic peers +command except that the +.Ic refid +is displayed in hex format and the association number is also displayed. .It Ic pstats Ar assocID Show the statistics for the peer with the given .Ar assocID . diff --git a/ntpq/ntpq.man.in b/ntpq/ntpq.man.in index ef8dc2441..2af564a74 100644 --- a/ntpq/ntpq.man.in +++ b/ntpq/ntpq.man.in @@ -10,11 +10,11 @@ .ds B-Font B .ds I-Font I .ds R-Font R -.TH ntpq @NTPQ_MS@ "12 May 2015" "4.2.8p3-RC1" "User Commands" +.TH ntpq @NTPQ_MS@ "10 Jun 2015" "4.2.8p3-RC1" "User Commands" .\" -.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-NfaO_W/ag-5faG.W) +.\" EDIT THIS FILE WITH CAUTION (in-mem file) .\" -.\" It has been AutoGen-ed May 12, 2015 at 04:33:29 AM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 10, 2015 at 10:52:09 AM by AutoGen 5.18.5 .\" From the definitions ntpq-opts.def .\" and the template file agman-cmd.tpl .SH NAME @@ -667,6 +667,17 @@ jitter .br .ns .TP 10 +.NOP \f\*[B-Font]apeers\f[] +Display a list of peers in the form: +.Dl [tally]remote refid assid st t when pool reach delay offset jitter +where the output is just like the +\f\*[B-Font]peers\f[] +command except that the +\f\*[B-Font]refid\f[] +is displayed in hex format and the association number is also displayed. +.br +.ns +.TP 10 .NOP \f\*[B-Font]pstats\f[] \f\*[I-Font]assocID\f[] Show the statistics for the peer with the given \f\*[I-Font]assocID\f[]. @@ -737,7 +748,7 @@ appears in the configuration file. \f\*[I-Font]filename\f[] can use -\fCstrftime\fR()\f[] +\fCstrftime\f[]\fR()\f[] format specifies to substitute the current date and time, for example, \f\*[B-Font]q]saveconfig\f[] \f\*[B-Font]ntp-%Y%m%d-%H%M%S.confq]\f[]. The filename used is stored in system variable diff --git a/ntpq/ntpq.mdoc.in b/ntpq/ntpq.mdoc.in index b938b8875..0ccbd78a2 100644 --- a/ntpq/ntpq.mdoc.in +++ b/ntpq/ntpq.mdoc.in @@ -1,9 +1,9 @@ -.Dd May 12 2015 +.Dd June 10 2015 .Dt NTPQ @NTPQ_MS@ User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntpq-opts.mdoc) .\" -.\" It has been AutoGen-ed May 12, 2015 at 04:33:37 AM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 10, 2015 at 10:52:04 AM by AutoGen 5.18.5 .\" From the definitions ntpq-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME @@ -506,6 +506,14 @@ offset of server relative to this host .It Ic jitter jitter .El +.It Ic apeers +Display a list of peers in the form: +.Dl [tally]remote refid assid st t when pool reach delay offset jitter +where the output is just like the +.Ic peers +command except that the +.Ic refid +is displayed in hex format and the association number is also displayed. .It Ic pstats Ar assocID Show the statistics for the peer with the given .Ar assocID .