]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2778] Implement "apeers" ntpq command to include associd
authorHarlan Stenn <stenn@ntp.org>
Wed, 10 Jun 2015 10:52:55 +0000 (10:52 +0000)
committerHarlan Stenn <stenn@ntp.org>
Wed, 10 Jun 2015 10:52:55 +0000 (10:52 +0000)
bk: 55781707H58CTQH80B16KuTsaZp4vA

ChangeLog
ntpq/invoke-ntpq.texi
ntpq/ntpq-opts.c
ntpq/ntpq-opts.def
ntpq/ntpq-opts.h
ntpq/ntpq-subs.c
ntpq/ntpq.1ntpqman
ntpq/ntpq.1ntpqmdoc
ntpq/ntpq.man.in
ntpq/ntpq.mdoc.in

index 97d1605aae0d4d06913b45f5f2040481776fa3bd..1713664afe7c37a92ba1fcb31c1999f0cf83a091 100644 (file)
--- 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.
 ---
index a1f7b299de9dec0698ac882bce7ca0043d0b3796..78ee5cbc26ea853e997c35a48a4addb0732284ad 100644 (file)
@@ -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}.
index 28c5ada45bdd83f04d9ce205ab05f2f64dbcfab6..5d87aff4c0810d41a9b4b36c8a39cba008b8e094 100644 (file)
@@ -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
  *
index 2a9f08c4758462256987946194171ab75cf6d97a..bac20d79af9379c80080a794c472ae6cca7d5bc0 100644 (file)
@@ -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 .
index 788bf2334f7d8edd05a34dcf19d8a0e7e32ad1d8..28ca504e82f7ee0da5af7bfdaa1f7c4419d8e2af 100644 (file)
@@ -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
  *
index c91e70302ff7278f168ce8072c7c5f279d3d4c77..47ca19ccd01e4f31e41de38360947beedc2a114f 100644 (file)
@@ -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
  */
index cb788f94181b867d14f39191d75c8722faaa2f13..788cd482546d8f9361daf09d1d17a728efc770db 100644 (file)
 .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
index 81ced3b96a136f8013e719d381db86c3d943a33a..999a552f0b17428561a2788e9ec1477262bb0969 100644 (file)
@@ -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 .
index ef8dc24418dbdc7701f5e86ed3944b8e55da7c42..2af564a74031b5949e2e9fb33ddede2e74e6cdfa 100644 (file)
 .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
index b938b88757523f860ad345266414cd4cf5520b69..0ccbd78a206d1d39a34834595f35ff5a6a263dc8 100644 (file)
@@ -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 .