4 * ntpdc_ops.c - subroutines which are called to perform operations by
17 #include "ntp_control.h"
18 #include "ntp_refclock.h"
19 #include "ntp_stdlib.h"
22 #ifdef HAVE_SYS_TIMEX_H
23 # include <sys/timex.h>
25 #if !defined(__bsdi__) && !defined(apollo)
26 #ifdef HAVE_NETINET_IN_H
27 #include <netinet/in.h>
31 #include <arpa/inet.h>
36 static int checkitems (int, FILE *);
37 static int checkitemsize (int, int);
38 static int check1item (int, FILE *);
41 * Declarations for command handlers in here
43 static void peerlist (struct parse
*, FILE *);
44 static void peers (struct parse
*, FILE *);
45 static void doconfig (struct parse
*pcmd
, FILE *fp
, int mode
, int refc
);
46 static void dmpeers (struct parse
*, FILE *);
47 static void dopeers (struct parse
*, FILE *, int);
48 static void printpeer (struct info_peer
*, FILE *);
49 static void showpeer (struct parse
*, FILE *);
50 static void peerstats (struct parse
*, FILE *);
51 static void loopinfo (struct parse
*, FILE *);
52 static void sysinfo (struct parse
*, FILE *);
53 static void sysstats (struct parse
*, FILE *);
54 static void iostats (struct parse
*, FILE *);
55 static void memstats (struct parse
*, FILE *);
56 static void timerstats (struct parse
*, FILE *);
57 static void addpeer (struct parse
*, FILE *);
58 static void addserver (struct parse
*, FILE *);
59 static void addrefclock (struct parse
*, FILE *);
60 static void broadcast (struct parse
*, FILE *);
61 static void doconfig (struct parse
*, FILE *, int, int);
62 static void unconfig (struct parse
*, FILE *);
63 static void set (struct parse
*, FILE *);
64 static void sys_clear (struct parse
*, FILE *);
65 static void doset (struct parse
*, FILE *, int);
66 static void reslist (struct parse
*, FILE *);
67 static void new_restrict (struct parse
*, FILE *);
68 static void unrestrict (struct parse
*, FILE *);
69 static void delrestrict (struct parse
*, FILE *);
70 static void do_restrict (struct parse
*, FILE *, int);
71 static void monlist (struct parse
*, FILE *);
72 static void reset (struct parse
*, FILE *);
73 static void preset (struct parse
*, FILE *);
74 static void readkeys (struct parse
*, FILE *);
75 static void trustkey (struct parse
*, FILE *);
76 static void untrustkey (struct parse
*, FILE *);
77 static void do_trustkey (struct parse
*, FILE *, int);
78 static void authinfo (struct parse
*, FILE *);
79 static void traps (struct parse
*, FILE *);
80 static void addtrap (struct parse
*, FILE *);
81 static void clrtrap (struct parse
*, FILE *);
82 static void do_addclr_trap (struct parse
*, FILE *, int);
83 static void requestkey (struct parse
*, FILE *);
84 static void controlkey (struct parse
*, FILE *);
85 static void do_changekey (struct parse
*, FILE *, int);
86 static void ctlstats (struct parse
*, FILE *);
87 static void clockstat (struct parse
*, FILE *);
88 static void fudge (struct parse
*, FILE *);
89 static void clkbug (struct parse
*, FILE *);
90 static void kerninfo (struct parse
*, FILE *);
91 static void get_if_stats (struct parse
*, FILE *);
92 static void do_if_reload (struct parse
*, FILE *);
95 * Commands we understand. Ntpdc imports this.
97 struct xcmd opcmds
[] = {
98 { "listpeers", peerlist
, { OPT
|IP_VERSION
, NO
, NO
, NO
},
99 { "-4|-6", "", "", "" },
100 "display list of peers the server knows about [IP Version]" },
101 { "peers", peers
, { OPT
|IP_VERSION
, NO
, NO
, NO
},
102 { "-4|-6", "", "", "" },
103 "display peer summary information [IP Version]" },
104 { "dmpeers", dmpeers
, { OPT
|IP_VERSION
, NO
, NO
, NO
},
105 { "-4|-6", "", "", "" },
106 "display peer summary info the way Dave Mills likes it (IP Version)" },
107 { "showpeer", showpeer
, { NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
},
108 { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
109 "display detailed information for one or more peers" },
110 { "pstats", peerstats
, { NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
},
111 { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
112 "display statistical information for one or more peers" },
113 { "loopinfo", loopinfo
, { OPT
|NTP_STR
, NO
, NO
, NO
},
114 { "oneline|multiline", "", "", "" },
115 "display loop filter information" },
116 { "sysinfo", sysinfo
, { NO
, NO
, NO
, NO
},
118 "display local server information" },
119 { "sysstats", sysstats
, { NO
, NO
, NO
, NO
},
121 "display local server statistics" },
122 { "memstats", memstats
, { NO
, NO
, NO
, NO
},
124 "display peer memory usage statistics" },
125 { "iostats", iostats
, { NO
, NO
, NO
, NO
},
127 "display I/O subsystem statistics" },
128 { "timerstats", timerstats
, { NO
, NO
, NO
, NO
},
130 "display event timer subsystem statistics" },
131 { "addpeer", addpeer
, { NTP_ADD
, OPT
|NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
},
132 { "addr", "keyid", "version", "minpoll#|prefer|burst|iburst|'minpoll N'|'maxpoll N'|'keyid N'|'version N' ..." },
133 "configure a new peer association" },
134 { "addserver", addserver
, { NTP_ADD
, OPT
|NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
},
135 { "addr", "keyid", "version", "minpoll#|prefer|burst|iburst|'minpoll N'|'maxpoll N'|'keyid N'|'version N' ..." },
136 "configure a new server" },
137 { "addrefclock",addrefclock
, { NTP_ADD
, OPT
|NTP_UINT
, OPT
|NTP_STR
, OPT
|NTP_STR
},
138 { "addr", "mode", "minpoll|prefer", "minpoll|prefer" },
139 "configure a new server" },
140 { "broadcast", broadcast
, { NTP_ADD
, OPT
|NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
},
141 { "addr", "keyid", "version", "minpoll" },
142 "configure broadcasting time service" },
143 { "unconfig", unconfig
, { NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
},
144 { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
145 "unconfigure existing peer assocations" },
146 { "enable", set
, { NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
},
147 { "auth|bclient|monitor|pll|kernel|stats", "...", "...", "..." },
148 "set a system flag (auth, bclient, monitor, pll, kernel, stats)" },
149 { "disable", sys_clear
, { NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
},
150 { "auth|bclient|monitor|pll|kernel|stats", "...", "...", "..." },
151 "clear a system flag (auth, bclient, monitor, pll, kernel, stats)" },
152 { "reslist", reslist
, {OPT
|IP_VERSION
, NO
, NO
, NO
},
153 { "-4|-6", "", "", "" },
154 "display the server's restrict list" },
155 { "restrict", new_restrict
, { NTP_ADD
, NTP_ADD
, NTP_STR
, OPT
|NTP_STR
},
157 "ntpport|ignore|noserve|notrust|noquery|nomodify|nopeer|version|kod",
159 "create restrict entry/add flags to entry" },
160 { "unrestrict", unrestrict
, { NTP_ADD
, NTP_ADD
, NTP_STR
, OPT
|NTP_STR
},
162 "ntpport|ignore|noserve|notrust|noquery|nomodify|nopeer|version|kod",
164 "remove flags from a restrict entry" },
165 { "delrestrict", delrestrict
, { NTP_ADD
, NTP_ADD
, OPT
|NTP_STR
, NO
},
166 { "address", "mask", "ntpport", "" },
167 "delete a restrict entry" },
168 { "monlist", monlist
, { OPT
|NTP_INT
, NO
, NO
, NO
},
169 { "version", "", "", "" },
170 "display data the server's monitor routines have collected" },
171 { "reset", reset
, { NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
, OPT
|NTP_STR
},
172 { "io|sys|mem|timer|auth|allpeers", "...", "...", "..." },
173 "reset various subsystem statistics counters" },
174 { "preset", preset
, { NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
},
175 { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
176 "reset stat counters associated with particular peer(s)" },
177 { "readkeys", readkeys
, { NO
, NO
, NO
, NO
},
179 "request a reread of the keys file and re-init of system keys" },
180 { "trustedkey", trustkey
, { NTP_UINT
, OPT
|NTP_UINT
, OPT
|NTP_UINT
, OPT
|NTP_UINT
},
181 { "keyid", "keyid", "keyid", "keyid" },
182 "add one or more key ID's to the trusted list" },
183 { "untrustedkey", untrustkey
, { NTP_UINT
, OPT
|NTP_UINT
, OPT
|NTP_UINT
, OPT
|NTP_UINT
},
184 { "keyid", "keyid", "keyid", "keyid" },
185 "remove one or more key ID's from the trusted list" },
186 { "authinfo", authinfo
, { NO
, NO
, NO
, NO
},
188 "display the state of the authentication code" },
189 { "traps", traps
, { NO
, NO
, NO
, NO
},
191 "display the traps set in the server" },
192 { "addtrap", addtrap
, { NTP_ADD
, OPT
|NTP_UINT
, OPT
|NTP_ADD
, NO
},
193 { "address", "port", "interface", "" },
194 "configure a trap in the server" },
195 { "clrtrap", clrtrap
, { NTP_ADD
, OPT
|NTP_UINT
, OPT
|NTP_ADD
, NO
},
196 { "address", "port", "interface", "" },
197 "remove a trap (configured or otherwise) from the server" },
198 { "requestkey", requestkey
, { NTP_UINT
, NO
, NO
, NO
},
199 { "keyid", "", "", "" },
200 "change the keyid the server uses to authenticate requests" },
201 { "controlkey", controlkey
, { NTP_UINT
, NO
, NO
, NO
},
202 { "keyid", "", "", "" },
203 "change the keyid the server uses to authenticate control messages" },
204 { "ctlstats", ctlstats
, { NO
, NO
, NO
, NO
},
206 "display packet count statistics from the control module" },
207 { "clockstat", clockstat
, { NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
},
208 { "address", "address", "address", "address" },
209 "display clock status information" },
210 { "fudge", fudge
, { NTP_ADD
, NTP_STR
, NTP_STR
, NO
},
211 { "address", "time1|time2|val1|val2|flags", "value", "" },
212 "set/change one of a clock's fudge factors" },
213 { "clkbug", clkbug
, { NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
, OPT
|NTP_ADD
},
214 { "address", "address", "address", "address" },
215 "display clock debugging information" },
216 { "kerninfo", kerninfo
, { NO
, NO
, NO
, NO
},
218 "display the kernel pll/pps variables" },
219 { "ifstats", get_if_stats
, { NO
, NO
, NO
, NO
},
221 "list interface statistics" },
222 { "ifreload", do_if_reload
, { NO
, NO
, NO
, NO
},
224 "reload interface configuration" },
225 { 0, 0, { NO
, NO
, NO
, NO
},
226 { "", "", "", "" }, "" }
230 * For quick string comparisons
232 #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
235 * SET_SS_LEN_IF_PRESENT - used by SET_ADDR, SET_ADDRS macros
238 #ifdef ISC_PLATFORM_HAVESALEN
239 #define SET_SS_LEN_IF_PRESENT(psau) \
241 (psau)->sas.ss_len = SOCKLEN(psau); \
244 #define SET_SS_LEN_IF_PRESENT(psau) do { } while (0)
248 * SET_ADDR - setup address for v4/v6 as needed
250 #define SET_ADDR(address, v6flag, v4addr, v6addr) \
252 memset(&(address), 0, sizeof(address)); \
254 AF(&(address)) = AF_INET6; \
255 SOCK_ADDR6(&(address)) = (v6addr); \
257 AF(&(address)) = AF_INET; \
258 NSRCADR(&(address)) = (v4addr); \
260 SET_SS_LEN_IF_PRESENT(&(address)); \
265 * SET_ADDRS - setup source and destination addresses for
268 #define SET_ADDRS(a1, a2, info, a1prefix, a2prefix) \
270 memset(&(a1), 0, sizeof(a1)); \
271 memset(&(a2), 0, sizeof(a2)); \
272 if ((info)->v6_flag) { \
273 AF(&(a1)) = AF_INET6; \
274 AF(&(a2)) = AF_INET6; \
275 SOCK_ADDR6(&(a1)) = (info)->a1prefix##6; \
276 SOCK_ADDR6(&(a2)) = (info)->a2prefix##6; \
278 AF(&(a1)) = AF_INET; \
279 AF(&(a2)) = AF_INET; \
280 NSRCADR(&(a1)) = (info)->a1prefix; \
281 NSRCADR(&(a2)) = (info)->a2prefix; \
283 SET_SS_LEN_IF_PRESENT(&(a1)); \
284 SET_SS_LEN_IF_PRESENT(&(a2)); \
289 * SET_ADDRS - setup source and destination addresses for
293 #define SET_ADDR_MASK(address, addrmask, info) \
295 memset(&(address), 0, sizeof(address)); \
296 memset(&(mask), 0, sizeof(mask)); \
297 if ((info)->v6_flag) { \
298 AF(&(address)) = AF_INET6; \
299 AF(&(addrmask)) = AF_INET6; \
300 SOCK_ADDR6(&(address)) = (info)->addr6; \
301 SOCK_ADDR6(&(addrmask)) = (info)->mask6; \
303 AF(&(address)) = AF_INET; \
304 AF(&(addrmask)) = AF_INET; \
305 NSRCADR(&(address)) = (info)->addr; \
306 NSRCADR(&(addrmask)) = (info)->mask; \
308 SET_SS_LEN_IF_PRESENT(&(address)); \
309 SET_SS_LEN_IF_PRESENT(&(addrmask)); \
314 * checkitems - utility to print a message if no items were returned
323 (void) fprintf(fp
, "No data returned in response to query\n");
331 * checkitemsize - utility to print a message if the item size is wrong
339 if (itemsize
!= expected
) {
340 (void) fprintf(stderr
,
341 "***Incorrect item size returned by remote host (%d should be %d)\n",
350 * check1item - check to make sure we have exactly one item
359 (void) fprintf(fp
, "No data returned in response to query\n");
363 (void) fprintf(fp
, "Expected one item in response, got %d\n",
372 * peerlist - get a short list of peers
381 struct info_peer_list
*plist
;
388 res
= doquery(impl_ver
, REQ_PEER_LIST
, 0, 0, 0, (char *)NULL
, &items
,
389 &itemsize
, (void *)&plist
, 0,
390 sizeof(struct info_peer_list
));
392 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
393 impl_ver
= IMPL_XNTPD_OLD
;
400 if (!checkitems(items
, fp
))
403 if (!checkitemsize(itemsize
, sizeof(struct info_peer_list
)) &&
404 !checkitemsize(itemsize
, v4sizeof(struct info_peer_list
)))
408 SET_ADDR(paddr
, plist
->v6_flag
, plist
->addr
, plist
->addr6
);
409 if ((pcmd
->nargs
== 0) ||
410 ((pcmd
->argval
->ival
== 6) && (plist
->v6_flag
!= 0)) ||
411 ((pcmd
->argval
->ival
== 4) && (plist
->v6_flag
== 0)))
412 (void) fprintf(fp
, "%-9s %s\n",
413 modetoa(plist
->hmode
),
422 * peers - show peer summary
430 dopeers(pcmd
, fp
, 0);
434 * dmpeers - show peer summary, Dave Mills style
442 dopeers(pcmd
, fp
, 1);
447 * peers - show peer summary
457 struct info_peer_summary
*plist
;
468 res
= doquery(impl_ver
, REQ_PEER_LIST_SUM
, 0, 0, 0, (char *)NULL
,
469 &items
, &itemsize
, (void *)&plist
, 0,
470 sizeof(struct info_peer_summary
));
472 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
473 impl_ver
= IMPL_XNTPD_OLD
;
480 if (!checkitems(items
, fp
))
483 if (!checkitemsize(itemsize
, sizeof(struct info_peer_summary
)) &&
484 !checkitemsize(itemsize
, v4sizeof(struct info_peer_summary
)))
488 " remote local st poll reach delay offset disp\n");
490 "=======================================================================\n");
493 if (plist
->flags
& INFO_FLAG_SYSPEER
)
495 else if (plist
->hmode
== MODE_ACTIVE
)
497 else if (plist
->hmode
== MODE_PASSIVE
)
499 else if (plist
->hmode
== MODE_CLIENT
)
501 else if (plist
->hmode
== MODE_BROADCAST
)
503 else if (plist
->hmode
== MODE_BCLIENT
)
508 if (plist
->flags
& INFO_FLAG_SYSPEER
)
510 else if (plist
->flags
& INFO_FLAG_SHORTLIST
)
512 else if (plist
->flags
& INFO_FLAG_SEL_CANDIDATE
)
517 NTOHL_FP(&(plist
->offset
), &tempts
);
518 ntp_poll
= 1<<max(min3(plist
->ppoll
, plist
->hpoll
, NTP_MAXPOLL
),
520 SET_ADDRS(dstadr
, srcadr
, plist
, dstadr
, srcadr
);
521 if ((pcmd
->nargs
== 0) ||
522 ((pcmd
->argval
->ival
== 6) && (plist
->v6_flag
!= 0)) ||
523 ((pcmd
->argval
->ival
== 4) && (plist
->v6_flag
== 0)))
525 "%c%-15.15s %-15.15s %2d %4d %3o %7.7s %9.9s %7.7s\n",
526 c
, nntohost(&srcadr
), stoa(&dstadr
),
527 plist
->stratum
, ntp_poll
, plist
->reach
,
528 fptoa(NTOHS_FP(plist
->delay
), 5),
530 ufptoa(NTOHS_FP(plist
->dispersion
), 5));
536 /* Convert a refid & stratum (in host order) to a string */
546 memmove(junk
, (char *)&refid
, 4);
550 return numtoa(refid
);
562 (void) fprintf(fp
, " none\n");
565 if (flags
& INFO_FLAG_SYSPEER
) {
566 (void) fprintf(fp
, " system_peer");
569 if (flags
& INFO_FLAG_CONFIG
) {
570 (void) fprintf(fp
, "%s config", str
);
573 if (flags
& INFO_FLAG_REFCLOCK
) {
574 (void) fprintf(fp
, "%s refclock", str
);
577 if (flags
& INFO_FLAG_AUTHENABLE
) {
578 (void) fprintf(fp
, "%s auth", str
);
581 if (flags
& INFO_FLAG_BCLIENT
) {
582 (void) fprintf(fp
, "%s bclient", str
);
585 if (flags
& INFO_FLAG_PREFER
) {
586 (void) fprintf(fp
, "%s prefer", str
);
589 if (flags
& INFO_FLAG_IBURST
) {
590 (void) fprintf(fp
, "%s iburst", str
);
593 if (flags
& INFO_FLAG_BURST
) {
594 (void) fprintf(fp
, "%s burst", str
);
596 (void) fprintf(fp
, "\n");
600 * printpeer - print detail information for a peer
604 register struct info_peer
*pp
,
610 sockaddr_u srcadr
, dstadr
;
612 SET_ADDRS(dstadr
, srcadr
, pp
, dstadr
, srcadr
);
614 (void) fprintf(fp
, "remote %s, local %s\n",
615 stoa(&srcadr
), stoa(&dstadr
));
616 (void) fprintf(fp
, "hmode %s, pmode %s, stratum %d, precision %d\n",
617 modetoa(pp
->hmode
), modetoa(pp
->pmode
),
618 pp
->stratum
, pp
->precision
);
621 "leap %c%c, refid [%s], rootdistance %s, rootdispersion %s\n",
622 pp
->leap
& 0x2 ? '1' : '0',
623 pp
->leap
& 0x1 ? '1' : '0',
624 refid_string(pp
->refid
, pp
->stratum
), fptoa(NTOHS_FP(pp
->rootdelay
), 5),
625 ufptoa(NTOHS_FP(pp
->rootdispersion
), 5));
628 "ppoll %d, hpoll %d, keyid %lu, version %d, association %u\n",
629 pp
->ppoll
, pp
->hpoll
, (u_long
)pp
->keyid
, pp
->version
, ntohs(pp
->associd
));
632 "reach %03o, unreach %d, flash 0x%04x, ",
633 pp
->reach
, pp
->unreach
, pp
->flash2
);
635 (void) fprintf(fp
, "boffset %s, ttl/mode %d\n",
636 fptoa(NTOHS_FP(pp
->estbdelay
), 5), pp
->ttl
);
638 (void) fprintf(fp
, "timer %lds, flags", (long)ntohl(pp
->timer
));
639 print_pflag(fp
, pp
->flags
);
641 NTOHL_FP(&pp
->reftime
, &tempts
);
642 (void) fprintf(fp
, "reference time: %s\n",
643 prettydate(&tempts
));
644 NTOHL_FP(&pp
->org
, &tempts
);
645 (void) fprintf(fp
, "originate timestamp: %s\n",
646 prettydate(&tempts
));
647 NTOHL_FP(&pp
->rec
, &tempts
);
648 (void) fprintf(fp
, "receive timestamp: %s\n",
649 prettydate(&tempts
));
650 NTOHL_FP(&pp
->xmt
, &tempts
);
651 (void) fprintf(fp
, "transmit timestamp: %s\n",
652 prettydate(&tempts
));
654 (void) fprintf(fp
, "filter delay: ");
655 for (i
= 0; i
< NTP_SHIFT
; i
++) {
656 (void) fprintf(fp
, " %-8.8s",
657 fptoa(NTOHS_FP(pp
->filtdelay
[i
]), 5));
658 if (i
== (NTP_SHIFT
>>1)-1)
659 (void) fprintf(fp
, "\n ");
661 (void) fprintf(fp
, "\n");
663 (void) fprintf(fp
, "filter offset:");
664 for (i
= 0; i
< NTP_SHIFT
; i
++) {
665 NTOHL_FP(&pp
->filtoffset
[i
], &tempts
);
666 (void) fprintf(fp
, " %-8.8s", lfptoa(&tempts
, 6));
667 if (i
== (NTP_SHIFT
>>1)-1)
668 (void) fprintf(fp
, "\n ");
670 (void) fprintf(fp
, "\n");
672 (void) fprintf(fp
, "filter order: ");
673 for (i
= 0; i
< NTP_SHIFT
; i
++) {
674 (void) fprintf(fp
, " %-8d", pp
->order
[i
]);
675 if (i
== (NTP_SHIFT
>>1)-1)
676 (void) fprintf(fp
, "\n ");
678 (void) fprintf(fp
, "\n");
681 NTOHL_FP(&pp
->offset
, &tempts
);
683 "offset %s, delay %s, error bound %s, filter error %s\n",
684 lfptoa(&tempts
, 6), fptoa(NTOHS_FP(pp
->delay
), 5),
685 ufptoa(NTOHS_FP(pp
->dispersion
), 5),
686 ufptoa(NTOHS_FP(pp
->selectdisp
), 5));
691 * showpeer - show detailed information for a peer
699 struct info_peer
*pp
;
700 /* 4 is the maximum number of peers which will fit in a packet */
701 struct info_peer_list
*pl
, plist
[min(MAXARGS
, 4)];
710 if (impl_ver
== IMPL_XNTPD
)
711 sendsize
= sizeof(struct info_peer_list
);
713 sendsize
= v4sizeof(struct info_peer_list
);
715 qitemlim
= min(pcmd
->nargs
, COUNTOF(plist
));
716 for (qitems
= 0, pl
= plist
; qitems
< qitemlim
; qitems
++) {
717 if (IS_IPV4(&pcmd
->argval
[qitems
].netnum
)) {
718 pl
->addr
= NSRCADR(&pcmd
->argval
[qitems
].netnum
);
719 if (impl_ver
== IMPL_XNTPD
)
722 if (impl_ver
== IMPL_XNTPD_OLD
) {
724 "***Server doesn't understand IPv6 addresses\n");
727 pl
->addr6
= SOCK_ADDR6(&pcmd
->argval
[qitems
].netnum
);
730 pl
->port
= (u_short
)s_port
;
731 pl
->hmode
= pl
->flags
= 0;
732 pl
= (struct info_peer_list
*)((char *)pl
+ sendsize
);
735 res
= doquery(impl_ver
, REQ_PEER_INFO
, 0, qitems
,
736 sendsize
, (char *)plist
, &items
,
737 &itemsize
, (void *)&pp
, 0, sizeof(struct info_peer
));
739 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
740 impl_ver
= IMPL_XNTPD_OLD
;
747 if (!checkitems(items
, fp
))
750 if (!checkitemsize(itemsize
, sizeof(struct info_peer
)) &&
751 !checkitemsize(itemsize
, v4sizeof(struct info_peer
)))
754 while (items
-- > 0) {
757 (void) fprintf(fp
, "\n");
764 * peerstats - return statistics for a peer
772 struct info_peer_stats
*pp
;
773 /* 4 is the maximum number of peers which will fit in a packet */
774 struct info_peer_list
*pl
, plist
[min(MAXARGS
, 4)];
784 if (impl_ver
== IMPL_XNTPD
)
785 sendsize
= sizeof(struct info_peer_list
);
787 sendsize
= v4sizeof(struct info_peer_list
);
789 memset(plist
, 0, sizeof(plist
));
791 qitemlim
= min(pcmd
->nargs
, COUNTOF(plist
));
792 for (qitems
= 0, pl
= plist
; qitems
< qitemlim
; qitems
++) {
793 if (IS_IPV4(&pcmd
->argval
[qitems
].netnum
)) {
794 pl
->addr
= NSRCADR(&pcmd
->argval
[qitems
].netnum
);
795 if (impl_ver
== IMPL_XNTPD
)
798 if (impl_ver
== IMPL_XNTPD_OLD
) {
800 "***Server doesn't understand IPv6 addresses\n");
803 pl
->addr6
= SOCK_ADDR6(&pcmd
->argval
[qitems
].netnum
);
806 pl
->port
= (u_short
)s_port
;
807 pl
->hmode
= plist
[qitems
].flags
= 0;
808 pl
= (struct info_peer_list
*)((char *)pl
+ sendsize
);
811 res
= doquery(impl_ver
, REQ_PEER_STATS
, 0, qitems
,
812 sendsize
, (char *)plist
, &items
,
813 &itemsize
, (void *)&pp
, 0,
814 sizeof(struct info_peer_stats
));
816 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
817 impl_ver
= IMPL_XNTPD_OLD
;
824 if (!checkitems(items
, fp
))
827 if (!checkitemsize(itemsize
, sizeof(struct info_peer_stats
)) &&
828 !checkitemsize(itemsize
, v4sizeof(struct info_peer_stats
)))
831 while (items
-- > 0) {
834 if (pp
->v6_flag
!= 0) {
837 SOCK_ADDR6(&dst
) = pp
->dstadr6
;
838 SOCK_ADDR6(&src
) = pp
->srcadr6
;
842 NSRCADR(&dst
) = pp
->dstadr
;
843 NSRCADR(&src
) = pp
->srcadr
;
845 #ifdef ISC_PLATFORM_HAVESALEN
846 src
.sas
.ss_len
= SOCKLEN(&src
);
847 dst
.sas
.ss_len
= SOCKLEN(&dst
);
849 (void) fprintf(fp
, "remote host: %s\n",
851 (void) fprintf(fp
, "local interface: %s\n",
853 (void) fprintf(fp
, "time last received: %lds\n",
854 (long)ntohl(pp
->timereceived
));
855 (void) fprintf(fp
, "time until next send: %lds\n",
856 (long)ntohl(pp
->timetosend
));
857 (void) fprintf(fp
, "reachability change: %lds\n",
858 (long)ntohl(pp
->timereachable
));
859 (void) fprintf(fp
, "packets sent: %ld\n",
860 (long)ntohl(pp
->sent
));
861 (void) fprintf(fp
, "packets received: %ld\n",
862 (long)ntohl(pp
->processed
));
863 (void) fprintf(fp
, "bad authentication: %ld\n",
864 (long)ntohl(pp
->badauth
));
865 (void) fprintf(fp
, "bogus origin: %ld\n",
866 (long)ntohl(pp
->bogusorg
));
867 (void) fprintf(fp
, "duplicate: %ld\n",
868 (long)ntohl(pp
->oldpkt
));
869 (void) fprintf(fp
, "bad dispersion: %ld\n",
870 (long)ntohl(pp
->seldisp
));
871 (void) fprintf(fp
, "bad reference time: %ld\n",
872 (long)ntohl(pp
->selbroken
));
873 (void) fprintf(fp
, "candidate order: %d\n",
876 (void) fprintf(fp
, "\n");
877 (void) fprintf(fp
, "flags: ");
878 print_pflag(fp
, ntohs(pp
->flags
));
885 * loopinfo - show loop filter information
893 struct info_loop
*il
;
900 if (pcmd
->nargs
> 0) {
901 if (STREQ(pcmd
->argval
[0].string
, "oneline"))
903 else if (STREQ(pcmd
->argval
[0].string
, "multiline"))
906 (void) fprintf(stderr
, "How many lines?\n");
912 res
= doquery(impl_ver
, REQ_LOOP_INFO
, 0, 0, 0, (char *)NULL
,
913 &items
, &itemsize
, (void *)&il
, 0,
914 sizeof(struct info_loop
));
916 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
917 impl_ver
= IMPL_XNTPD_OLD
;
924 if (!check1item(items
, fp
))
927 if (!checkitemsize(itemsize
, sizeof(struct info_loop
)))
933 NTOHL_FP(&il
->last_offset
, &tempts
);
934 NTOHL_FP(&il
->drift_comp
, &temp2ts
);
937 "offset %s, frequency %s, time_const %ld, watchdog %ld\n",
940 (long)(int32
)ntohl((u_long
)il
->compliance
),
941 (u_long
)ntohl((u_long
)il
->watchdog_timer
));
943 NTOHL_FP(&il
->last_offset
, &tempts
);
944 (void) fprintf(fp
, "offset: %s s\n",
946 NTOHL_FP(&il
->drift_comp
, &tempts
);
947 (void) fprintf(fp
, "frequency: %s ppm\n",
949 (void) fprintf(fp
, "poll adjust: %ld\n",
950 (long)(int32
)ntohl(il
->compliance
));
951 (void) fprintf(fp
, "watchdog timer: %ld s\n",
952 (u_long
)ntohl(il
->watchdog_timer
));
958 * sysinfo - show current system state
975 res
= doquery(impl_ver
, REQ_SYS_INFO
, 0, 0, 0, (char *)NULL
,
976 &items
, &itemsize
, (void *)&is
, 0,
977 sizeof(struct info_sys
));
979 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
980 impl_ver
= IMPL_XNTPD_OLD
;
987 if (!check1item(items
, fp
))
990 if (!checkitemsize(itemsize
, sizeof(struct info_sys
)) &&
991 !checkitemsize(itemsize
, v4sizeof(struct info_sys
)))
994 SET_ADDR(peeraddr
, is
->v6_flag
, is
->peer
, is
->peer6
);
996 (void) fprintf(fp
, "system peer: %s\n", nntohost(&peeraddr
));
997 (void) fprintf(fp
, "system peer mode: %s\n", modetoa(is
->peer_mode
));
998 (void) fprintf(fp
, "leap indicator: %c%c\n",
999 is
->leap
& 0x2 ? '1' : '0',
1000 is
->leap
& 0x1 ? '1' : '0');
1001 (void) fprintf(fp
, "stratum: %d\n", (int)is
->stratum
);
1002 (void) fprintf(fp
, "precision: %d\n", (int)is
->precision
);
1003 (void) fprintf(fp
, "root distance: %s s\n",
1004 fptoa(NTOHS_FP(is
->rootdelay
), 5));
1005 (void) fprintf(fp
, "root dispersion: %s s\n",
1006 ufptoa(NTOHS_FP(is
->rootdispersion
), 5));
1007 (void) fprintf(fp
, "reference ID: [%s]\n",
1008 refid_string(is
->refid
, is
->stratum
));
1009 NTOHL_FP(&is
->reftime
, &tempts
);
1010 (void) fprintf(fp
, "reference time: %s\n", prettydate(&tempts
));
1012 (void) fprintf(fp
, "system flags: ");
1013 if ((is
->flags
& (INFO_FLAG_BCLIENT
| INFO_FLAG_AUTHENABLE
|
1014 INFO_FLAG_NTP
| INFO_FLAG_KERNEL
| INFO_FLAG_CAL
|
1015 INFO_FLAG_PPS_SYNC
| INFO_FLAG_MONITOR
| INFO_FLAG_FILEGEN
)) == 0) {
1016 (void) fprintf(fp
, "none\n");
1018 if (is
->flags
& INFO_FLAG_BCLIENT
)
1019 (void) fprintf(fp
, "bclient ");
1020 if (is
->flags
& INFO_FLAG_AUTHENTICATE
)
1021 (void) fprintf(fp
, "auth ");
1022 if (is
->flags
& INFO_FLAG_MONITOR
)
1023 (void) fprintf(fp
, "monitor ");
1024 if (is
->flags
& INFO_FLAG_NTP
)
1025 (void) fprintf(fp
, "ntp ");
1026 if (is
->flags
& INFO_FLAG_KERNEL
)
1027 (void) fprintf(fp
, "kernel ");
1028 if (is
->flags
& INFO_FLAG_FILEGEN
)
1029 (void) fprintf(fp
, "stats ");
1030 if (is
->flags
& INFO_FLAG_CAL
)
1031 (void) fprintf(fp
, "calibrate ");
1032 if (is
->flags
& INFO_FLAG_PPS_SYNC
)
1033 (void) fprintf(fp
, "pps ");
1034 (void) fprintf(fp
, "\n");
1036 (void) fprintf(fp
, "jitter: %s s\n",
1037 fptoa(ntohl(is
->frequency
), 6));
1038 (void) fprintf(fp
, "stability: %s ppm\n",
1039 ufptoa(ntohl(is
->stability
), 3));
1040 (void) fprintf(fp
, "broadcastdelay: %s s\n",
1041 fptoa(NTOHS_FP(is
->bdelay
), 6));
1042 NTOHL_FP(&is
->authdelay
, &tempts
);
1043 (void) fprintf(fp
, "authdelay: %s s\n", lfptoa(&tempts
, 6));
1048 * sysstats - print system statistics
1057 struct info_sys_stats
*ss
;
1063 res
= doquery(impl_ver
, REQ_SYS_STATS
, 0, 0, 0, (char *)NULL
,
1064 &items
, &itemsize
, (void *)&ss
, 0,
1065 sizeof(struct info_sys_stats
));
1067 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1068 impl_ver
= IMPL_XNTPD_OLD
;
1075 if (!check1item(items
, fp
))
1078 if (itemsize
!= sizeof(struct info_sys_stats
) &&
1079 itemsize
!= sizeof(struct old_info_sys_stats
)) {
1080 /* issue warning according to new structure size */
1081 checkitemsize(itemsize
, sizeof(struct info_sys_stats
));
1084 fprintf(fp
, "time since restart: %ld\n",
1085 (u_long
)ntohl(ss
->timeup
));
1086 fprintf(fp
, "time since reset: %ld\n",
1087 (u_long
)ntohl(ss
->timereset
));
1088 fprintf(fp
, "packets received: %ld\n",
1089 (u_long
)ntohl(ss
->received
));
1090 fprintf(fp
, "packets processed: %ld\n",
1091 (u_long
)ntohl(ss
->processed
));
1092 fprintf(fp
, "current version: %ld\n",
1093 (u_long
)ntohl(ss
->newversionpkt
));
1094 fprintf(fp
, "previous version: %ld\n",
1095 (u_long
)ntohl(ss
->oldversionpkt
));
1096 fprintf(fp
, "declined: %ld\n",
1097 (u_long
)ntohl(ss
->unknownversion
));
1098 fprintf(fp
, "access denied: %ld\n",
1099 (u_long
)ntohl(ss
->denied
));
1100 fprintf(fp
, "bad length or format: %ld\n",
1101 (u_long
)ntohl(ss
->badlength
));
1102 fprintf(fp
, "bad authentication: %ld\n",
1103 (u_long
)ntohl(ss
->badauth
));
1104 if (itemsize
!= sizeof(struct info_sys_stats
))
1107 fprintf(fp
, "rate exceeded: %ld\n",
1108 (u_long
)ntohl(ss
->limitrejected
));
1114 * iostats - print I/O statistics
1123 struct info_io_stats
*io
;
1129 res
= doquery(impl_ver
, REQ_IO_STATS
, 0, 0, 0, (char *)NULL
,
1130 &items
, &itemsize
, (void *)&io
, 0,
1131 sizeof(struct info_io_stats
));
1133 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1134 impl_ver
= IMPL_XNTPD_OLD
;
1141 if (!check1item(items
, fp
))
1144 if (!checkitemsize(itemsize
, sizeof(struct info_io_stats
)))
1147 (void) fprintf(fp
, "time since reset: %ld\n",
1148 (u_long
)ntohl(io
->timereset
));
1149 (void) fprintf(fp
, "receive buffers: %d\n",
1150 ntohs(io
->totalrecvbufs
));
1151 (void) fprintf(fp
, "free receive buffers: %d\n",
1152 ntohs(io
->freerecvbufs
));
1153 (void) fprintf(fp
, "used receive buffers: %d\n",
1154 ntohs(io
->fullrecvbufs
));
1155 (void) fprintf(fp
, "low water refills: %d\n",
1156 ntohs(io
->lowwater
));
1157 (void) fprintf(fp
, "dropped packets: %ld\n",
1158 (u_long
)ntohl(io
->dropped
));
1159 (void) fprintf(fp
, "ignored packets: %ld\n",
1160 (u_long
)ntohl(io
->ignored
));
1161 (void) fprintf(fp
, "received packets: %ld\n",
1162 (u_long
)ntohl(io
->received
));
1163 (void) fprintf(fp
, "packets sent: %ld\n",
1164 (u_long
)ntohl(io
->sent
));
1165 (void) fprintf(fp
, "packets not sent: %ld\n",
1166 (u_long
)ntohl(io
->notsent
));
1167 (void) fprintf(fp
, "interrupts handled: %ld\n",
1168 (u_long
)ntohl(io
->interrupts
));
1169 (void) fprintf(fp
, "received by int: %ld\n",
1170 (u_long
)ntohl(io
->int_received
));
1175 * memstats - print peer memory statistics
1184 struct info_mem_stats
*mem
;
1191 res
= doquery(impl_ver
, REQ_MEM_STATS
, 0, 0, 0, (char *)NULL
,
1192 &items
, &itemsize
, (void *)&mem
, 0,
1193 sizeof(struct info_mem_stats
));
1195 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1196 impl_ver
= IMPL_XNTPD_OLD
;
1203 if (!check1item(items
, fp
))
1206 if (!checkitemsize(itemsize
, sizeof(struct info_mem_stats
)))
1209 (void) fprintf(fp
, "time since reset: %ld\n",
1210 (u_long
)ntohl(mem
->timereset
));
1211 (void) fprintf(fp
, "total peer memory: %d\n",
1212 ntohs(mem
->totalpeermem
));
1213 (void) fprintf(fp
, "free peer memory: %d\n",
1214 ntohs(mem
->freepeermem
));
1215 (void) fprintf(fp
, "calls to findpeer: %ld\n",
1216 (u_long
)ntohl(mem
->findpeer_calls
));
1217 (void) fprintf(fp
, "new peer allocations: %ld\n",
1218 (u_long
)ntohl(mem
->allocations
));
1219 (void) fprintf(fp
, "peer demobilizations: %ld\n",
1220 (u_long
)ntohl(mem
->demobilizations
));
1222 (void) fprintf(fp
, "hash table counts: ");
1223 for (i
= 0; i
< NTP_HASH_SIZE
; i
++) {
1224 (void) fprintf(fp
, "%4d", (int)mem
->hashcount
[i
]);
1225 if ((i
% 8) == 7 && i
!= (NTP_HASH_SIZE
-1)) {
1226 (void) fprintf(fp
, "\n ");
1229 (void) fprintf(fp
, "\n");
1235 * timerstats - print timer statistics
1244 struct info_timer_stats
*tim
;
1250 res
= doquery(impl_ver
, REQ_TIMER_STATS
, 0, 0, 0, (char *)NULL
,
1251 &items
, &itemsize
, (void *)&tim
, 0,
1252 sizeof(struct info_timer_stats
));
1254 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1255 impl_ver
= IMPL_XNTPD_OLD
;
1262 if (!check1item(items
, fp
))
1265 if (!checkitemsize(itemsize
, sizeof(struct info_timer_stats
)))
1268 (void) fprintf(fp
, "time since reset: %ld\n",
1269 (u_long
)ntohl(tim
->timereset
));
1270 (void) fprintf(fp
, "alarms handled: %ld\n",
1271 (u_long
)ntohl(tim
->alarms
));
1272 (void) fprintf(fp
, "alarm overruns: %ld\n",
1273 (u_long
)ntohl(tim
->overflows
));
1274 (void) fprintf(fp
, "calls to transmit: %ld\n",
1275 (u_long
)ntohl(tim
->xmtcalls
));
1280 * addpeer - configure an active mode association
1288 doconfig(pcmd
, fp
, MODE_ACTIVE
, 0);
1293 * addserver - configure a client mode association
1301 doconfig(pcmd
, fp
, MODE_CLIENT
, 0);
1305 * addrefclock - configure a reference clock association
1313 doconfig(pcmd
, fp
, MODE_CLIENT
, 1);
1317 * broadcast - configure a broadcast mode association
1325 doconfig(pcmd
, fp
, MODE_BROADCAST
, 0);
1330 * config - configure a new peer association
1340 struct conf_peer cpeer
;
1360 minpoll
= NTP_MINDPOLL
;
1361 maxpoll
= NTP_MAXDPOLL
;
1366 if (impl_ver
== IMPL_XNTPD
)
1367 sendsize
= sizeof(struct conf_peer
);
1369 sendsize
= v4sizeof(struct conf_peer
);
1372 while (pcmd
->nargs
> items
) {
1373 if (STREQ(pcmd
->argval
[items
].string
, "prefer"))
1374 flags
|= CONF_FLAG_PREFER
;
1375 else if (STREQ(pcmd
->argval
[items
].string
, "burst"))
1376 flags
|= CONF_FLAG_BURST
;
1377 else if (STREQ(pcmd
->argval
[items
].string
, "iburst"))
1378 flags
|= CONF_FLAG_IBURST
;
1379 else if (!refc
&& STREQ(pcmd
->argval
[items
].string
, "keyid"))
1381 else if (!refc
&& STREQ(pcmd
->argval
[items
].string
, "version"))
1383 else if (STREQ(pcmd
->argval
[items
].string
, "minpoll"))
1385 else if (STREQ(pcmd
->argval
[items
].string
, "maxpoll"))
1389 if (!atoint(pcmd
->argval
[items
].string
, &val
))
1398 version
= (u_int
) val
;
1403 minpoll
= (u_char
)val
;
1408 maxpoll
= (u_char
)val
;
1413 cmode
= (u_char
)val
;
1418 (void) fprintf(fp
, "*** '%s' not understood\n",
1419 pcmd
->argval
[items
].string
);
1424 (void) fprintf(stderr
,
1425 "***Value '%s' should be unsigned\n",
1426 pcmd
->argval
[items
].string
);
1433 flags
|= CONF_FLAG_AUTHENABLE
;
1434 if (version
> NTP_VERSION
||
1435 version
< NTP_OLDVERSION
) {
1436 (void)fprintf(fp
, "***invalid version number: %u\n",
1440 if (minpoll
< NTP_MINPOLL
|| minpoll
> NTP_MAXPOLL
||
1441 maxpoll
< NTP_MINPOLL
|| maxpoll
> NTP_MAXPOLL
||
1442 minpoll
> maxpoll
) {
1443 (void) fprintf(fp
, "***min/max-poll must be within %d..%d\n",
1444 NTP_MINPOLL
, NTP_MAXPOLL
);
1451 memset(&cpeer
, 0, sizeof(cpeer
));
1453 if (IS_IPV4(&pcmd
->argval
[0].netnum
)) {
1454 cpeer
.peeraddr
= NSRCADR(&pcmd
->argval
[0].netnum
);
1455 if (impl_ver
== IMPL_XNTPD
)
1458 if (impl_ver
== IMPL_XNTPD_OLD
) {
1460 "***Server doesn't understand IPv6 addresses\n");
1463 cpeer
.peeraddr6
= SOCK_ADDR6(&pcmd
->argval
[0].netnum
);
1466 cpeer
.hmode
= (u_char
) mode
;
1467 cpeer
.keyid
= keyid
;
1468 cpeer
.version
= (u_char
) version
;
1469 cpeer
.minpoll
= minpoll
;
1470 cpeer
.maxpoll
= maxpoll
;
1471 cpeer
.flags
= (u_char
)flags
;
1474 res
= doquery(impl_ver
, REQ_CONFIG
, 1, 1,
1475 sendsize
, (char *)&cpeer
, &items
,
1476 &itemsize
, &dummy
, 0, sizeof(struct conf_peer
));
1478 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1479 impl_ver
= IMPL_XNTPD_OLD
;
1483 if (res
== INFO_ERR_FMT
) {
1485 "***Retrying command with old conf_peer size\n");
1486 res
= doquery(impl_ver
, REQ_CONFIG
, 1, 1,
1487 sizeof(struct old_conf_peer
), (char *)&cpeer
,
1488 &items
, &itemsize
, &dummy
, 0,
1489 sizeof(struct conf_peer
));
1492 (void) fprintf(fp
, "done!\n");
1498 * unconfig - unconfigure some associations
1506 /* 8 is the maximum number of peers which will fit in a packet */
1507 struct conf_unpeer
*pl
, plist
[min(MAXARGS
, 8)];
1517 if (impl_ver
== IMPL_XNTPD
)
1518 sendsize
= sizeof(struct conf_unpeer
);
1520 sendsize
= v4sizeof(struct conf_unpeer
);
1522 qitemlim
= min(pcmd
->nargs
, COUNTOF(plist
));
1523 for (qitems
= 0, pl
= plist
; qitems
< qitemlim
; qitems
++) {
1524 if (IS_IPV4(&pcmd
->argval
[0].netnum
)) {
1525 pl
->peeraddr
= NSRCADR(&pcmd
->argval
[qitems
].netnum
);
1526 if (impl_ver
== IMPL_XNTPD
)
1529 if (impl_ver
== IMPL_XNTPD_OLD
) {
1531 "***Server doesn't understand IPv6 addresses\n");
1535 SOCK_ADDR6(&pcmd
->argval
[qitems
].netnum
);
1538 pl
= (struct conf_unpeer
*)((char *)pl
+ sendsize
);
1541 res
= doquery(impl_ver
, REQ_UNCONFIG
, 1, qitems
,
1542 sendsize
, (char *)plist
, &items
,
1543 &itemsize
, &dummy
, 0, sizeof(struct conf_unpeer
));
1545 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1546 impl_ver
= IMPL_XNTPD_OLD
;
1551 (void) fprintf(fp
, "done!\n");
1556 * set - set some system flags
1564 doset(pcmd
, fp
, REQ_SET_SYS_FLAG
);
1569 * clear - clear some system flags
1577 doset(pcmd
, fp
, REQ_CLR_SYS_FLAG
);
1582 * doset - set/clear system flags
1591 struct conf_sys_flags sys
;
1599 for (items
= 0; items
< pcmd
->nargs
; items
++) {
1600 if (STREQ(pcmd
->argval
[items
].string
, "auth"))
1601 sys
.flags
|= SYS_FLAG_AUTH
;
1602 else if (STREQ(pcmd
->argval
[items
].string
, "bclient"))
1603 sys
.flags
|= SYS_FLAG_BCLIENT
;
1604 else if (STREQ(pcmd
->argval
[items
].string
, "calibrate"))
1605 sys
.flags
|= SYS_FLAG_CAL
;
1606 else if (STREQ(pcmd
->argval
[items
].string
, "kernel"))
1607 sys
.flags
|= SYS_FLAG_KERNEL
;
1608 else if (STREQ(pcmd
->argval
[items
].string
, "monitor"))
1609 sys
.flags
|= SYS_FLAG_MONITOR
;
1610 else if (STREQ(pcmd
->argval
[items
].string
, "ntp"))
1611 sys
.flags
|= SYS_FLAG_NTP
;
1612 else if (STREQ(pcmd
->argval
[items
].string
, "pps"))
1613 sys
.flags
|= SYS_FLAG_PPS
;
1614 else if (STREQ(pcmd
->argval
[items
].string
, "stats"))
1615 sys
.flags
|= SYS_FLAG_FILEGEN
;
1617 (void) fprintf(fp
, "Unknown flag %s\n",
1618 pcmd
->argval
[items
].string
);
1623 sys
.flags
= htonl(sys
.flags
);
1624 if (res
|| sys
.flags
== 0)
1628 res
= doquery(impl_ver
, req
, 1, 1,
1629 sizeof(struct conf_sys_flags
), (char *)&sys
, &items
,
1630 &itemsize
, &dummy
, 0, sizeof(struct conf_sys_flags
));
1632 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1633 impl_ver
= IMPL_XNTPD_OLD
;
1638 (void) fprintf(fp
, "done!\n");
1643 * data for printing/interrpreting the restrict flags
1650 /* XXX: HMS: we apparently don't report set bits we do not recognize. */
1652 static struct resflags resflagsV2
[] = {
1653 { "ignore", 0x001 },
1654 { "noserve", 0x002 },
1655 { "notrust", 0x004 },
1656 { "noquery", 0x008 },
1657 { "nomodify", 0x010 },
1658 { "nopeer", 0x020 },
1659 { "notrap", 0x040 },
1660 { "lptrap", 0x080 },
1661 { "limited", 0x100 },
1665 static struct resflags resflagsV3
[] = {
1666 { "ignore", RES_IGNORE
},
1667 { "noserve", RES_DONTSERVE
},
1668 { "notrust", RES_DONTTRUST
},
1669 { "noquery", RES_NOQUERY
},
1670 { "nomodify", RES_NOMODIFY
},
1671 { "nopeer", RES_NOPEER
},
1672 { "notrap", RES_NOTRAP
},
1673 { "lptrap", RES_LPTRAP
},
1674 { "limited", RES_LIMITED
},
1675 { "version", RES_VERSION
},
1677 { "timeout", RES_TIMEOUT
},
1682 static struct resflags resmflags
[] = {
1683 { "ntpport", RESM_NTPONLY
},
1684 { "interface", RESM_INTERFACE
},
1690 * reslist - obtain and print the server's restrict list
1699 struct info_restrict
*rl
;
1701 sockaddr_u maskaddr
;
1708 struct resflags
*rf
;
1713 static const char *comma
= ", ";
1716 res
= doquery(impl_ver
, REQ_GET_RESTRICT
, 0, 0, 0, (char *)NULL
,
1717 &items
, &itemsize
, (void *)&rl
, 0,
1718 sizeof(struct info_restrict
));
1720 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1721 impl_ver
= IMPL_XNTPD_OLD
;
1728 if (!checkitems(items
, fp
))
1731 if (!checkitemsize(itemsize
, sizeof(struct info_restrict
)) &&
1732 !checkitemsize(itemsize
, v4sizeof(struct info_restrict
)))
1736 " address mask count flags\n");
1738 "=====================================================================\n");
1741 SET_ADDRS(resaddr
, maskaddr
, rl
, addr
, mask
);
1742 if (rl
->v6_flag
!= 0) {
1743 addr
= nntohost(&resaddr
);
1745 if ((rl
->mask
== (u_int32
)0xffffffff))
1746 addr
= nntohost(&resaddr
);
1748 addr
= stoa(&resaddr
);
1750 mask
= stoa(&maskaddr
);
1752 if ((pcmd
->nargs
== 0) ||
1753 ((pcmd
->argval
->ival
== 6) && (rl
->v6_flag
!= 0)) ||
1754 ((pcmd
->argval
->ival
== 4) && (rl
->v6_flag
== 0)))
1756 count
= ntohl(rl
->count
);
1757 flags
= ntohs(rl
->flags
);
1758 mflags
= ntohs(rl
->mflags
);
1763 while (rf
->bit
!= 0) {
1764 if (mflags
& rf
->bit
) {
1766 (void) strcat(flagstr
, comma
);
1768 (void) strcat(flagstr
, rf
->str
);
1773 rf
= (impl_ver
== IMPL_XNTPD_OLD
)
1777 while (rf
->bit
!= 0) {
1778 if (flags
& rf
->bit
) {
1780 (void) strcat(flagstr
, comma
);
1782 (void) strcat(flagstr
, rf
->str
);
1787 if (flagstr
[0] == '\0')
1788 (void) strcpy(flagstr
, "none");
1791 (void) fprintf(fp
, "%-15.15s %-15.15s %9ld %s\n",
1792 addr
, mask
, (u_long
)count
, flagstr
);
1801 * new_restrict - create/add a set of restrictions
1809 do_restrict(pcmd
, fp
, REQ_RESADDFLAGS
);
1814 * unrestrict - remove restriction flags from existing entry
1822 do_restrict(pcmd
, fp
, REQ_RESSUBFLAGS
);
1827 * delrestrict - delete an existing restriction
1835 do_restrict(pcmd
, fp
, REQ_UNRESTRICT
);
1840 * do_restrict - decode commandline restrictions and make the request
1849 struct conf_restrict cres
;
1860 /* Initialize cres */
1868 if (impl_ver
== IMPL_XNTPD
)
1869 sendsize
= sizeof(struct conf_restrict
);
1871 sendsize
= v4sizeof(struct conf_restrict
);
1873 if (IS_IPV4(&pcmd
->argval
[0].netnum
)) {
1874 cres
.addr
= NSRCADR(&pcmd
->argval
[0].netnum
);
1875 cres
.mask
= NSRCADR(&pcmd
->argval
[1].netnum
);
1876 if (impl_ver
== IMPL_XNTPD
)
1879 if (impl_ver
== IMPL_XNTPD_OLD
) {
1881 "***Server doesn't understand IPv6 addresses\n");
1884 cres
.addr6
= SOCK_ADDR6(&pcmd
->argval
[0].netnum
);
1890 for (res
= 2; res
< pcmd
->nargs
; res
++) {
1891 if (STREQ(pcmd
->argval
[res
].string
, "ntpport")) {
1892 cres
.mflags
|= RESM_NTPONLY
;
1894 for (i
= 0; resflagsV3
[i
].bit
!= 0; i
++) {
1895 if (STREQ(pcmd
->argval
[res
].string
,
1899 if (resflagsV3
[i
].bit
!= 0) {
1900 cres
.flags
|= resflagsV3
[i
].bit
;
1901 if (req_code
== REQ_UNRESTRICT
) {
1903 "Flag %s inappropriate\n",
1908 (void) fprintf(fp
, "Unknown flag %s\n",
1909 pcmd
->argval
[res
].string
);
1914 cres
.flags
= htons(cres
.flags
);
1915 cres
.mflags
= htons(cres
.mflags
);
1918 * Make sure mask for default address is zero. Otherwise,
1919 * make sure mask bits are contiguous.
1921 if (IS_IPV4(&pcmd
->argval
[0].netnum
)) {
1922 if (cres
.addr
== 0) {
1925 num
= ntohl(cres
.mask
);
1926 for (bit
= 0x80000000; bit
!= 0; bit
>>= 1)
1927 if ((num
& bit
) == 0)
1929 for ( ; bit
!= 0; bit
>>= 1)
1930 if ((num
& bit
) != 0)
1933 (void) fprintf(fp
, "Invalid mask %s\n",
1939 /* XXX IPv6 sanity checking stuff */
1945 res
= doquery(impl_ver
, req_code
, 1, 1,
1946 sendsize
, (char *)&cres
, &items
,
1947 &itemsize
, &dummy
, 0, sizeof(struct conf_restrict
));
1949 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1950 impl_ver
= IMPL_XNTPD_OLD
;
1955 (void) fprintf(fp
, "done!\n");
1961 * monlist - obtain and print the server's monitor data
1978 if (pcmd
->nargs
> 0) {
1979 version
= pcmd
->argval
[0].ival
;
1983 res
= doquery(impl_ver
,
1984 (version
== 1 || version
== -1) ? REQ_MON_GETLIST_1
:
1985 REQ_MON_GETLIST
, 0, 0, 0, (char *)NULL
,
1986 &items
, &itemsize
, &struct_star
,
1987 (version
< 0) ? (1 << INFO_ERR_REQ
) : 0,
1988 sizeof(struct info_monitor_1
));
1990 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
1991 impl_ver
= IMPL_XNTPD_OLD
;
1995 if (res
== INFO_ERR_REQ
&& version
< 0)
1996 res
= doquery(impl_ver
, REQ_MON_GETLIST
, 0, 0, 0, (char *)NULL
,
1997 &items
, &itemsize
, &struct_star
, 0,
1998 sizeof(struct info_monitor
));
2003 if (!checkitems(items
, fp
))
2006 if (itemsize
== sizeof(struct info_monitor_1
) ||
2007 itemsize
== v4sizeof(struct info_monitor_1
)) {
2008 struct info_monitor_1
*ml
= (struct info_monitor_1
*) struct_star
;
2011 "remote address port local address count m ver rstr avgint lstint\n");
2013 "===============================================================================\n");
2015 SET_ADDRS(dstadr
, addr
, ml
, daddr
, addr
);
2016 if ((pcmd
->nargs
== 0) ||
2017 ((pcmd
->argval
->ival
== 6) && (ml
->v6_flag
!= 0)) ||
2018 ((pcmd
->argval
->ival
== 4) && (ml
->v6_flag
== 0)))
2020 "%-22.22s %5d %-15s %8ld %1d %1d %6lx %6lu %7lu\n",
2024 (u_long
)ntohl(ml
->count
),
2027 (u_long
)ntohl(ml
->restr
),
2028 (u_long
)ntohl(ml
->lasttime
),
2029 (u_long
)ntohl(ml
->firsttime
));
2033 } else if (itemsize
== sizeof(struct info_monitor
) ||
2034 itemsize
== v4sizeof(struct info_monitor
)) {
2035 struct info_monitor
*ml
= (struct info_monitor
*) struct_star
;
2038 " address port count mode ver rstr avgint lstint\n");
2040 "===============================================================================\n");
2042 SET_ADDR(dstadr
, ml
->v6_flag
, ml
->addr
, ml
->addr6
);
2043 if ((pcmd
->nargs
== 0) ||
2044 ((pcmd
->argval
->ival
== 6) && (ml
->v6_flag
!= 0)) ||
2045 ((pcmd
->argval
->ival
== 4) && (ml
->v6_flag
== 0)))
2047 "%-25.25s %5d %9ld %4d %2d %9lx %9lu %9lu\n",
2050 (u_long
)ntohl(ml
->count
),
2053 (u_long
)ntohl(ml
->restr
),
2054 (u_long
)ntohl(ml
->lasttime
),
2055 (u_long
)ntohl(ml
->firsttime
));
2059 } else if (itemsize
== sizeof(struct old_info_monitor
)) {
2060 struct old_info_monitor
*oml
= (struct old_info_monitor
*)struct_star
;
2062 " address port count mode version lasttime firsttime\n");
2064 "======================================================================\n");
2066 SET_ADDR(dstadr
, oml
->v6_flag
, oml
->addr
, oml
->addr6
);
2067 (void) fprintf(fp
, "%-20.20s %5d %9ld %4d %3d %9lu %9lu\n",
2070 (u_long
)ntohl(oml
->count
),
2073 (u_long
)ntohl(oml
->lasttime
),
2074 (u_long
)ntohl(oml
->firsttime
));
2079 /* issue warning according to new info_monitor size */
2080 checkitemsize(itemsize
, sizeof(struct info_monitor
));
2086 * Mapping between command line strings and stat reset flags
2092 { "io", RESET_FLAG_IO
},
2093 { "sys", RESET_FLAG_SYS
},
2094 { "mem", RESET_FLAG_MEM
},
2095 { "timer", RESET_FLAG_TIMER
},
2096 { "auth", RESET_FLAG_AUTH
},
2097 { "allpeers", RESET_FLAG_ALLPEERS
},
2102 * reset - reset statistic counters
2110 struct reset_flags rflags
;
2120 for (res
= 0; res
< pcmd
->nargs
; res
++) {
2121 for (i
= 0; sreset
[i
].flag
!= 0; i
++) {
2122 if (STREQ(pcmd
->argval
[res
].string
, sreset
[i
].str
))
2125 if (sreset
[i
].flag
== 0) {
2126 (void) fprintf(fp
, "Flag %s unknown\n",
2127 pcmd
->argval
[res
].string
);
2130 rflags
.flags
|= sreset
[i
].flag
;
2133 rflags
.flags
= htonl(rflags
.flags
);
2136 (void) fprintf(fp
, "Not done due to errors\n");
2141 res
= doquery(impl_ver
, REQ_RESET_STATS
, 1, 1,
2142 sizeof(struct reset_flags
), (char *)&rflags
, &items
,
2143 &itemsize
, &dummy
, 0, sizeof(struct reset_flags
));
2145 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2146 impl_ver
= IMPL_XNTPD_OLD
;
2151 (void) fprintf(fp
, "done!\n");
2158 * preset - reset stat counters for particular peers
2166 /* 8 is the maximum number of peers which will fit in a packet */
2167 struct conf_unpeer
*pl
, plist
[min(MAXARGS
, 8)];
2177 if (impl_ver
== IMPL_XNTPD
)
2178 sendsize
= sizeof(struct conf_unpeer
);
2180 sendsize
= v4sizeof(struct conf_unpeer
);
2182 qitemlim
= min(pcmd
->nargs
, COUNTOF(plist
));
2183 for (qitems
= 0, pl
= plist
; qitems
< qitemlim
; qitems
++) {
2184 if (IS_IPV4(&pcmd
->argval
[qitems
].netnum
)) {
2185 pl
->peeraddr
= NSRCADR(&pcmd
->argval
[qitems
].netnum
);
2186 if (impl_ver
== IMPL_XNTPD
)
2189 if (impl_ver
== IMPL_XNTPD_OLD
) {
2191 "***Server doesn't understand IPv6 addresses\n");
2195 SOCK_ADDR6(&pcmd
->argval
[qitems
].netnum
);
2198 pl
= (struct conf_unpeer
*)((char *)pl
+ sendsize
);
2201 res
= doquery(impl_ver
, REQ_RESET_PEER
, 1, qitems
,
2202 sendsize
, (char *)plist
, &items
,
2203 &itemsize
, &dummy
, 0, sizeof(struct conf_unpeer
));
2205 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2206 impl_ver
= IMPL_XNTPD_OLD
;
2211 (void) fprintf(fp
, "done!\n");
2216 * readkeys - request the server to reread the keys file
2231 res
= doquery(impl_ver
, REQ_REREAD_KEYS
, 1, 0, 0, (char *)0,
2232 &items
, &itemsize
, &dummy
, 0, sizeof(dummy
));
2234 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2235 impl_ver
= IMPL_XNTPD_OLD
;
2240 (void) fprintf(fp
, "done!\n");
2246 * trustkey - add some keys to the trusted key list
2254 do_trustkey(pcmd
, fp
, REQ_TRUSTKEY
);
2259 * untrustkey - remove some keys from the trusted key list
2267 do_trustkey(pcmd
, fp
, REQ_UNTRUSTKEY
);
2272 * do_trustkey - do grunge work of adding/deleting keys
2281 u_long keyids
[MAXARGS
];
2290 for (i
= 0; i
< pcmd
->nargs
; i
++) {
2291 keyids
[ritems
++] = pcmd
->argval
[i
].uval
;
2295 res
= doquery(impl_ver
, req
, 1, ritems
, sizeof(u_long
),
2296 (char *)keyids
, &items
, &itemsize
, &dummy
, 0,
2299 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2300 impl_ver
= IMPL_XNTPD_OLD
;
2305 (void) fprintf(fp
, "done!\n");
2312 * authinfo - obtain and print info about authentication
2321 struct info_auth
*ia
;
2327 res
= doquery(impl_ver
, REQ_AUTHINFO
, 0, 0, 0, (char *)NULL
,
2328 &items
, &itemsize
, (void *)&ia
, 0,
2329 sizeof(struct info_auth
));
2331 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2332 impl_ver
= IMPL_XNTPD_OLD
;
2339 if (!check1item(items
, fp
))
2342 if (!checkitemsize(itemsize
, sizeof(struct info_auth
)))
2345 (void) fprintf(fp
, "time since reset: %ld\n",
2346 (u_long
)ntohl(ia
->timereset
));
2347 (void) fprintf(fp
, "stored keys: %ld\n",
2348 (u_long
)ntohl(ia
->numkeys
));
2349 (void) fprintf(fp
, "free keys: %ld\n",
2350 (u_long
)ntohl(ia
->numfreekeys
));
2351 (void) fprintf(fp
, "key lookups: %ld\n",
2352 (u_long
)ntohl(ia
->keylookups
));
2353 (void) fprintf(fp
, "keys not found: %ld\n",
2354 (u_long
)ntohl(ia
->keynotfound
));
2355 (void) fprintf(fp
, "uncached keys: %ld\n",
2356 (u_long
)ntohl(ia
->keyuncached
));
2357 (void) fprintf(fp
, "encryptions: %ld\n",
2358 (u_long
)ntohl(ia
->encryptions
));
2359 (void) fprintf(fp
, "decryptions: %ld\n",
2360 (u_long
)ntohl(ia
->decryptions
));
2361 (void) fprintf(fp
, "expired keys: %ld\n",
2362 (u_long
)ntohl(ia
->expired
));
2368 * traps - obtain and print a list of traps
2378 struct info_trap
*it
;
2379 sockaddr_u trap_addr
, local_addr
;
2385 res
= doquery(impl_ver
, REQ_TRAPS
, 0, 0, 0, (char *)NULL
,
2386 &items
, &itemsize
, (void *)&it
, 0,
2387 sizeof(struct info_trap
));
2389 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2390 impl_ver
= IMPL_XNTPD_OLD
;
2397 if (!checkitems(items
, fp
))
2400 if (!checkitemsize(itemsize
, sizeof(struct info_trap
)) &&
2401 !checkitemsize(itemsize
, v4sizeof(struct info_trap
)))
2404 for (i
= 0; i
< items
; i
++ ) {
2406 (void) fprintf(fp
, "\n");
2407 SET_ADDRS(trap_addr
, local_addr
, it
, trap_address
, local_address
);
2408 (void) fprintf(fp
, "address %s, port %d\n",
2410 ntohs(it
->trap_port
));
2411 (void) fprintf(fp
, "interface: %s, ",
2412 (it
->local_address
== 0)
2414 : stoa(&local_addr
));
2415 if (ntohl(it
->flags
) & TRAP_CONFIGURED
)
2416 (void) fprintf(fp
, "configured\n");
2417 else if (ntohl(it
->flags
) & TRAP_NONPRIO
)
2418 (void) fprintf(fp
, "low priority\n");
2420 (void) fprintf(fp
, "normal priority\n");
2422 (void) fprintf(fp
, "set for %ld secs, last set %ld secs ago\n",
2423 (long)ntohl(it
->origtime
),
2424 (long)ntohl(it
->settime
));
2425 (void) fprintf(fp
, "sequence %d, number of resets %ld\n",
2426 ntohs(it
->sequence
),
2427 (long)ntohl(it
->resets
));
2433 * addtrap - configure a trap
2441 do_addclr_trap(pcmd
, fp
, REQ_ADD_TRAP
);
2446 * clrtrap - clear a trap from the server
2454 do_addclr_trap(pcmd
, fp
, REQ_CLR_TRAP
);
2459 * do_addclr_trap - do grunge work of adding/deleting traps
2468 struct conf_trap ctrap
;
2476 if (impl_ver
== IMPL_XNTPD
)
2477 sendsize
= sizeof(struct conf_trap
);
2479 sendsize
= v4sizeof(struct conf_trap
);
2481 if (IS_IPV4(&pcmd
->argval
[0].netnum
)) {
2482 ctrap
.trap_address
= NSRCADR(&pcmd
->argval
[0].netnum
);
2483 if (impl_ver
== IMPL_XNTPD
)
2486 if (impl_ver
== IMPL_XNTPD_OLD
) {
2488 "***Server doesn't understand IPv6 addresses\n");
2491 ctrap
.trap_address6
= SOCK_ADDR6(&pcmd
->argval
[0].netnum
);
2494 ctrap
.local_address
= 0;
2495 ctrap
.trap_port
= htons(TRAPPORT
);
2498 if (pcmd
->nargs
> 1) {
2499 ctrap
.trap_port
= htons((u_short
)pcmd
->argval
[1].uval
);
2500 if (pcmd
->nargs
> 2) {
2501 if (AF(&pcmd
->argval
[2].netnum
) !=
2502 AF(&pcmd
->argval
[0].netnum
)) {
2504 "***Cannot mix IPv4 and IPv6 addresses\n");
2507 if (IS_IPV4(&pcmd
->argval
[2].netnum
))
2508 ctrap
.local_address
= NSRCADR(&pcmd
->argval
[2].netnum
);
2510 ctrap
.local_address6
= SOCK_ADDR6(&pcmd
->argval
[2].netnum
);
2514 res
= doquery(impl_ver
, req
, 1, 1, sendsize
,
2515 (char *)&ctrap
, &items
, &itemsize
, &dummy
, 0,
2516 sizeof(struct conf_trap
));
2518 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2519 impl_ver
= IMPL_XNTPD_OLD
;
2524 (void) fprintf(fp
, "done!\n");
2531 * requestkey - change the server's request key (a dangerous request)
2539 do_changekey(pcmd
, fp
, REQ_REQUEST_KEY
);
2544 * controlkey - change the server's control key
2552 do_changekey(pcmd
, fp
, REQ_CONTROL_KEY
);
2558 * do_changekey - do grunge work of changing keys
2574 key
= htonl((u_int32
)pcmd
->argval
[0].uval
);
2577 res
= doquery(impl_ver
, req
, 1, 1, sizeof(u_int32
),
2578 (char *)&key
, &items
, &itemsize
, &dummy
, 0,
2581 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2582 impl_ver
= IMPL_XNTPD_OLD
;
2587 (void) fprintf(fp
, "done!\n");
2594 * ctlstats - obtain and print info about authentication
2603 struct info_control
*ic
;
2609 res
= doquery(impl_ver
, REQ_GET_CTLSTATS
, 0, 0, 0, (char *)NULL
,
2610 &items
, &itemsize
, (void *)&ic
, 0,
2611 sizeof(struct info_control
));
2613 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2614 impl_ver
= IMPL_XNTPD_OLD
;
2621 if (!check1item(items
, fp
))
2624 if (!checkitemsize(itemsize
, sizeof(struct info_control
)))
2627 (void) fprintf(fp
, "time since reset: %ld\n",
2628 (u_long
)ntohl(ic
->ctltimereset
));
2629 (void) fprintf(fp
, "requests received: %ld\n",
2630 (u_long
)ntohl(ic
->numctlreq
));
2631 (void) fprintf(fp
, "responses sent: %ld\n",
2632 (u_long
)ntohl(ic
->numctlresponses
));
2633 (void) fprintf(fp
, "fragments sent: %ld\n",
2634 (u_long
)ntohl(ic
->numctlfrags
));
2635 (void) fprintf(fp
, "async messages sent: %ld\n",
2636 (u_long
)ntohl(ic
->numasyncmsgs
));
2637 (void) fprintf(fp
, "error msgs sent: %ld\n",
2638 (u_long
)ntohl(ic
->numctlerrors
));
2639 (void) fprintf(fp
, "total bad pkts: %ld\n",
2640 (u_long
)ntohl(ic
->numctlbadpkts
));
2641 (void) fprintf(fp
, "packet too short: %ld\n",
2642 (u_long
)ntohl(ic
->numctltooshort
));
2643 (void) fprintf(fp
, "response on input: %ld\n",
2644 (u_long
)ntohl(ic
->numctlinputresp
));
2645 (void) fprintf(fp
, "fragment on input: %ld\n",
2646 (u_long
)ntohl(ic
->numctlinputfrag
));
2647 (void) fprintf(fp
, "error set on input: %ld\n",
2648 (u_long
)ntohl(ic
->numctlinputerr
));
2649 (void) fprintf(fp
, "bad offset on input: %ld\n",
2650 (u_long
)ntohl(ic
->numctlbadoffset
));
2651 (void) fprintf(fp
, "bad version packets: %ld\n",
2652 (u_long
)ntohl(ic
->numctlbadversion
));
2653 (void) fprintf(fp
, "data in pkt too short: %ld\n",
2654 (u_long
)ntohl(ic
->numctldatatooshort
));
2655 (void) fprintf(fp
, "unknown op codes: %ld\n",
2656 (u_long
)ntohl(ic
->numctlbadop
));
2661 * clockstat - get and print clock status information
2669 struct info_clock
*cl
;
2670 /* 8 is the maximum number of clocks which will fit in a packet */
2671 u_long clist
[min(MAXARGS
, 8)];
2678 struct clktype
*clk
;
2680 qitemlim
= min(pcmd
->nargs
, COUNTOF(clist
));
2681 for (qitems
= 0; qitems
< qitemlim
; qitems
++)
2682 clist
[qitems
] = NSRCADR(&pcmd
->argval
[qitems
].netnum
);
2685 res
= doquery(impl_ver
, REQ_GET_CLOCKINFO
, 0, qitems
,
2686 sizeof(u_int32
), (char *)clist
, &items
,
2687 &itemsize
, (void *)&cl
, 0, sizeof(struct info_clock
));
2689 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2690 impl_ver
= IMPL_XNTPD_OLD
;
2697 if (!checkitems(items
, fp
))
2700 if (!checkitemsize(itemsize
, sizeof(struct info_clock
)))
2703 while (items
-- > 0) {
2704 (void) fprintf(fp
, "clock address: %s\n",
2705 numtoa(cl
->clockadr
));
2706 for (clk
= clktypes
; clk
->code
>= 0; clk
++)
2707 if (clk
->code
== cl
->type
)
2710 (void) fprintf(fp
, "clock type: %s\n",
2713 (void) fprintf(fp
, "clock type: unknown type (%d)\n",
2715 (void) fprintf(fp
, "last event: %d\n",
2717 (void) fprintf(fp
, "current status: %d\n",
2719 (void) fprintf(fp
, "number of polls: %lu\n",
2720 (u_long
)ntohl(cl
->polls
));
2721 (void) fprintf(fp
, "no response to poll: %lu\n",
2722 (u_long
)ntohl(cl
->noresponse
));
2723 (void) fprintf(fp
, "bad format responses: %lu\n",
2724 (u_long
)ntohl(cl
->badformat
));
2725 (void) fprintf(fp
, "bad data responses: %lu\n",
2726 (u_long
)ntohl(cl
->baddata
));
2727 (void) fprintf(fp
, "running time: %lu\n",
2728 (u_long
)ntohl(cl
->timestarted
));
2729 NTOHL_FP(&cl
->fudgetime1
, &ts
);
2730 (void) fprintf(fp
, "fudge time 1: %s\n",
2732 NTOHL_FP(&cl
->fudgetime2
, &ts
);
2733 (void) fprintf(fp
, "fudge time 2: %s\n",
2735 (void) fprintf(fp
, "stratum: %ld\n",
2736 (u_long
)ntohl(cl
->fudgeval1
));
2737 (void) fprintf(fp
, "reference ID: %s\n",
2738 refid_string(ntohl(cl
->fudgeval2
), 0));
2739 (void) fprintf(fp
, "fudge flags: 0x%x\n",
2743 (void) fprintf(fp
, "\n");
2750 * fudge - set clock fudge factors
2758 struct conf_fudge fudgedata
;
2770 memset((char *)&fudgedata
, 0, sizeof fudgedata
);
2771 fudgedata
.clockadr
= NSRCADR(&pcmd
->argval
[0].netnum
);
2773 if (STREQ(pcmd
->argval
[1].string
, "time1")) {
2774 fudgedata
.which
= htonl(FUDGE_TIME1
);
2775 if (!atolfp(pcmd
->argval
[2].string
, &ts
))
2778 NTOHL_FP(&ts
, &fudgedata
.fudgetime
);
2779 } else if (STREQ(pcmd
->argval
[1].string
, "time2")) {
2780 fudgedata
.which
= htonl(FUDGE_TIME2
);
2781 if (!atolfp(pcmd
->argval
[2].string
, &ts
))
2784 NTOHL_FP(&ts
, &fudgedata
.fudgetime
);
2785 } else if (STREQ(pcmd
->argval
[1].string
, "val1")) {
2786 fudgedata
.which
= htonl(FUDGE_VAL1
);
2787 if (!atoint(pcmd
->argval
[2].string
, &val
))
2790 fudgedata
.fudgeval_flags
= htonl(val
);
2791 } else if (STREQ(pcmd
->argval
[1].string
, "val2")) {
2792 fudgedata
.which
= htonl(FUDGE_VAL2
);
2793 if (!atoint(pcmd
->argval
[2].string
, &val
))
2796 fudgedata
.fudgeval_flags
= htonl((u_int32
)val
);
2797 } else if (STREQ(pcmd
->argval
[1].string
, "flags")) {
2798 fudgedata
.which
= htonl(FUDGE_FLAGS
);
2799 if (!hextoint(pcmd
->argval
[2].string
, &u_val
))
2802 fudgedata
.fudgeval_flags
= htonl((u_int32
)(u_val
& 0xf));
2804 (void) fprintf(stderr
, "What fudge is %s?\n",
2805 pcmd
->argval
[1].string
);
2810 (void) fprintf(stderr
, "Unknown fudge parameter %s\n",
2811 pcmd
->argval
[2].string
);
2816 res
= doquery(impl_ver
, REQ_SET_CLKFUDGE
, 1, 1,
2817 sizeof(struct conf_fudge
), (char *)&fudgedata
, &items
,
2818 &itemsize
, &dummy
, 0, sizeof(dummy
));
2820 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2821 impl_ver
= IMPL_XNTPD_OLD
;
2826 (void) fprintf(fp
, "done!\n");
2831 * clkbug - get and print clock debugging information
2842 struct info_clkbug
*cl
;
2843 /* 8 is the maximum number of clocks which will fit in a packet */
2844 u_long clist
[min(MAXARGS
, 8)];
2854 qitemlim
= min(pcmd
->nargs
, COUNTOF(clist
));
2855 for (qitems
= 0; qitems
< qitemlim
; qitems
++)
2856 clist
[qitems
] = NSRCADR(&pcmd
->argval
[qitems
].netnum
);
2859 res
= doquery(impl_ver
, REQ_GET_CLKBUGINFO
, 0, qitems
,
2860 sizeof(u_int32
), (char *)clist
, &items
,
2861 &itemsize
, (void *)&cl
, 0, sizeof(struct info_clkbug
));
2863 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2864 impl_ver
= IMPL_XNTPD_OLD
;
2871 if (!checkitems(items
, fp
))
2874 if (!checkitemsize(itemsize
, sizeof(struct info_clkbug
)))
2877 while (items
-- > 0) {
2878 (void) fprintf(fp
, "clock address: %s\n",
2879 numtoa(cl
->clockadr
));
2880 n
= (int)cl
->nvalues
;
2881 (void) fprintf(fp
, "values: %d", n
);
2882 s
= ntohs(cl
->svalues
);
2883 if (n
> NUMCBUGVALUES
)
2885 for (i
= 0; i
< n
; i
++) {
2886 ltemp
= ntohl(cl
->values
[i
]);
2887 ltemp
&= 0xffffffff; /* HMS: This does nothing now */
2889 (void) fprintf(fp
, "\n");
2891 (void) fprintf(fp
, "%12ld", (u_long
)ltemp
);
2893 (void) fprintf(fp
, "%12lu", (u_long
)ltemp
);
2895 (void) fprintf(fp
, "\n");
2897 n
= (int)cl
->ntimes
;
2898 (void) fprintf(fp
, "times: %d", n
);
2899 s
= ntohl(cl
->stimes
);
2900 if (n
> NUMCBUGTIMES
)
2903 for (i
= 0; i
< n
; i
++) {
2904 if ((i
& 0x1) == 0) {
2905 (void) fprintf(fp
, "\n");
2907 for (;needsp
> 0; needsp
--)
2910 NTOHL_FP(&cl
->times
[i
], &ts
);
2912 (void) fprintf(fp
, "%17s",
2916 (void) fprintf(fp
, "%37s",
2921 (void) fprintf(fp
, "\n");
2924 (void) fprintf(fp
, "\n");
2931 * kerninfo - display the kernel pll/pps variables
2939 struct info_kernel
*ik
;
2944 double tscale
= 1e-6;
2947 res
= doquery(impl_ver
, REQ_GET_KERNEL
, 0, 0, 0, (char *)NULL
,
2948 &items
, &itemsize
, (void *)&ik
, 0,
2949 sizeof(struct info_kernel
));
2951 if (res
== INFO_ERR_IMPL
&& impl_ver
== IMPL_XNTPD
) {
2952 impl_ver
= IMPL_XNTPD_OLD
;
2958 if (!check1item(items
, fp
))
2960 if (!checkitemsize(itemsize
, sizeof(struct info_kernel
)))
2963 status
= ntohs(ik
->status
) & 0xffff;
2965 * pll variables. We know more than we should about the NANO bit.
2968 if (status
& STA_NANO
)
2971 (void)fprintf(fp
, "pll offset: %g s\n",
2972 (int32
)ntohl(ik
->offset
) * tscale
);
2973 (void)fprintf(fp
, "pll frequency: %s ppm\n",
2974 fptoa((s_fp
)ntohl(ik
->freq
), 3));
2975 (void)fprintf(fp
, "maximum error: %g s\n",
2976 (u_long
)ntohl(ik
->maxerror
) * 1e-6);
2977 (void)fprintf(fp
, "estimated error: %g s\n",
2978 (u_long
)ntohl(ik
->esterror
) * 1e-6);
2979 (void)fprintf(fp
, "status: %04x ", status
);
2981 if (status
& STA_PLL
) (void)fprintf(fp
, " pll");
2984 if (status
& STA_PPSFREQ
) (void)fprintf(fp
, " ppsfreq");
2987 if (status
& STA_PPSTIME
) (void)fprintf(fp
, " ppstime");
2990 if (status
& STA_FLL
) (void)fprintf(fp
, " fll");
2993 if (status
& STA_INS
) (void)fprintf(fp
, " ins");
2996 if (status
& STA_DEL
) (void)fprintf(fp
, " del");
2999 if (status
& STA_UNSYNC
) (void)fprintf(fp
, " unsync");
3002 if (status
& STA_FREQHOLD
) (void)fprintf(fp
, " freqhold");
3004 #ifdef STA_PPSSIGNAL
3005 if (status
& STA_PPSSIGNAL
) (void)fprintf(fp
, " ppssignal");
3007 #ifdef STA_PPSJITTER
3008 if (status
& STA_PPSJITTER
) (void)fprintf(fp
, " ppsjitter");
3010 #ifdef STA_PPSWANDER
3011 if (status
& STA_PPSWANDER
) (void)fprintf(fp
, " ppswander");
3014 if (status
& STA_PPSERROR
) (void)fprintf(fp
, " ppserror");
3017 if (status
& STA_CLOCKERR
) (void)fprintf(fp
, " clockerr");
3020 if (status
& STA_NANO
) (void)fprintf(fp
, " nano");
3023 if (status
& STA_MODE
) (void)fprintf(fp
, " mode=fll");
3026 if (status
& STA_CLK
) (void)fprintf(fp
, " src=B");
3028 (void)fprintf(fp
, "\n");
3029 (void)fprintf(fp
, "pll time constant: %ld\n",
3030 (u_long
)ntohl(ik
->constant
));
3031 (void)fprintf(fp
, "precision: %g s\n",
3032 (u_long
)ntohl(ik
->precision
) * tscale
);
3033 (void)fprintf(fp
, "frequency tolerance: %s ppm\n",
3034 fptoa((s_fp
)ntohl(ik
->tolerance
), 0));
3037 * For backwards compatibility (ugh), we find the pps variables
3038 * only if the shift member is nonzero.
3046 (void)fprintf(fp
, "pps frequency: %s ppm\n",
3047 fptoa((s_fp
)ntohl(ik
->ppsfreq
), 3));
3048 (void)fprintf(fp
, "pps stability: %s ppm\n",
3049 fptoa((s_fp
)ntohl(ik
->stabil
), 3));
3050 (void)fprintf(fp
, "pps jitter: %g s\n",
3051 (u_long
)ntohl(ik
->jitter
) * tscale
);
3052 (void)fprintf(fp
, "calibration interval: %d s\n",
3053 1 << ntohs(ik
->shift
));
3054 (void)fprintf(fp
, "calibration cycles: %ld\n",
3055 (u_long
)ntohl(ik
->calcnt
));
3056 (void)fprintf(fp
, "jitter exceeded: %ld\n",
3057 (u_long
)ntohl(ik
->jitcnt
));
3058 (void)fprintf(fp
, "stability exceeded: %ld\n",
3059 (u_long
)ntohl(ik
->stbcnt
));
3060 (void)fprintf(fp
, "calibration errors: %ld\n",
3061 (u_long
)ntohl(ik
->errcnt
));
3064 #define IF_LIST_FMT "%2d %c %48s %c %c %12.12s %03x %3d %2d %5d %5d %5d %2d %3d %7d\n"
3065 #define IF_LIST_FMT_STR "%2s %c %48s %c %c %12.12s %3s %3s %2s %5s %5s %5s %2s %3s %7s\n"
3066 #define IF_LIST_AFMT_STR " %48s %c\n"
3067 #define IF_LIST_LABELS "#", 'A', "Address/Mask/Broadcast", 'T', 'E', "IF name", "Flg", "TL", "#M", "recv", "sent", "drop", "S", "PC", "uptime"
3068 #define IF_LIST_LINE "==================================================================================================================\n"
3073 struct info_if_stats
*ifs
,
3079 static char *actions
= "?.+-";
3085 if (!checkitems(items
, fp
))
3088 if (!checkitemsize(itemsize
, sizeof(struct info_if_stats
)))
3091 fprintf(fp
, IF_LIST_FMT_STR
, IF_LIST_LABELS
);
3092 fprintf(fp
, IF_LIST_LINE
);
3095 SET_ADDR(saddr
, ntohl(ifs
->v6_flag
),
3096 ifs
->unaddr
.addr
.s_addr
, ifs
->unaddr
.addr6
);
3097 fprintf(fp
, IF_LIST_FMT
,
3099 actions
[(ifs
->action
>= 1 && ifs
->action
< 4) ? ifs
->action
: 0],
3100 stoa((&saddr
)), 'A',
3101 ifs
->ignore_packets
? 'D' : 'E',
3104 ntohl(ifs
->last_ttl
),
3105 ntohl(ifs
->num_mcast
),
3106 ntohl(ifs
->received
),
3108 ntohl(ifs
->notsent
),
3109 ntohl(ifs
->scopeid
),
3110 ntohl(ifs
->peercnt
),
3111 ntohl(ifs
->uptime
));
3113 SET_ADDR(saddr
, ntohl(ifs
->v6_flag
),
3114 ifs
->unmask
.addr
.s_addr
, ifs
->unmask
.addr6
);
3115 fprintf(fp
, IF_LIST_AFMT_STR
, stoa(&saddr
), 'M');
3117 if (!ntohl(ifs
->v6_flag
) && ntohl(ifs
->flags
) & (INT_BCASTOPEN
)) {
3118 SET_ADDR(saddr
, ntohl(ifs
->v6_flag
),
3119 ifs
->unbcast
.addr
.s_addr
, ifs
->unbcast
.addr6
);
3120 fprintf(fp
, IF_LIST_AFMT_STR
, stoa(&saddr
), 'B');
3136 struct info_if_stats
*ifs
;
3141 res
= doquery(impl_ver
, REQ_IF_STATS
, 1, 0, 0, (char *)NULL
, &items
,
3142 &itemsize
, (void *)&ifs
, 0,
3143 sizeof(struct info_if_stats
));
3144 iflist(fp
, ifs
, items
, itemsize
, res
);
3154 struct info_if_stats
*ifs
;
3159 res
= doquery(impl_ver
, REQ_IF_RELOAD
, 1, 0, 0, (char *)NULL
, &items
,
3160 &itemsize
, (void *)&ifs
, 0,
3161 sizeof(struct info_if_stats
));
3162 iflist(fp
, ifs
, items
, itemsize
, res
);