ntpdc_ops.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* ntpdc_ops.c - subroutines which are called to perform operations by xntpdc
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <ctype.h>
#include <netdb.h>
#endif
#include "ntpdc.h"
#include "ntp_control.h"
#include "ntp_refclock.h"
#include "ntp_stdlib.h"
/*
* Declarations for command handlers in here
*/
static int checkitems P((int, FILE *));
static int checkitemsize P((int, int));
static int check1item P((int, FILE *));
static char *refid_string P((u_int32, int));
/*
* Commands we understand. Ntpdc imports this.
*/
{ "", "", "", "" },
"display list of peers the server knows about" },
{ "", "", "", "" },
"display peer summary information" },
{ "", "", "", "" },
"display peer summary info the way Dave Mills likes it" },
{ "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
"display detailed information for one or more peers" },
{ "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
"display statistical information for one or more peers" },
{ "oneline|multiline", "", "", "" },
"display loop filter information" },
{ "", "", "", "" },
"display local server information" },
{ "", "", "", "" },
"display local server statistics" },
{ "", "", "", "" },
"display peer memory usage statistics" },
{ "", "", "", "" },
"display I/O subsystem statistics" },
{ "", "", "", "" },
"display event timer subsystem statistics" },
{ "addr", "keyid", "version", "minpoll|prefer" },
"configure a new peer association" },
{ "addr", "keyid", "version", "minpoll|prefer" },
"configure a new server" },
{ "addr", "mode", "minpoll|prefer", "minpoll|prefer" },
"configure a new server" },
{ "addr", "keyid", "version", "minpoll" },
"configure broadcasting time service" },
{ "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
"unconfigure existing peer assocations" },
{ "auth|bclient|monitor|pll|pps|stats", "...", "...", "..." },
"set a system flag (auth, bclient, monitor, pll, pps, stats)" },
{ "auth|bclient|monitor|pll|pps|stats", "...", "...", "..." },
"clear a system flag (auth, bclient, monitor, pll, pps, stats)" },
{ "", "", "", "" },
"display the server's restrict list" },
{ "address", "mask",
"ntpport|ignore|noserve|notrust|noquery|nomodify|nopeer",
"..." },
{ "address", "mask",
"ntpport|ignore|noserve|notrust|noquery|nomodify|nopeer",
"..." },
"remove flags from a restrict entry" },
{ "address", "mask", "ntpport", "" },
"delete a restrict entry" },
{ "version", "", "", "" },
"display data the server's monitor routines have collected" },
{ "io|sys|mem|timer|auth|allpeers", "...", "...", "..." },
"reset various subsystem statistics counters" },
{ "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
"reset stat counters associated with particular peer(s)" },
{ "", "", "", "" },
"request a reread of the keys file and re-init of system keys" },
{ "keyid", "keyid", "keyid", "keyid" },
"add one or more key ID's to the trusted list" },
{ "keyid", "keyid", "keyid", "keyid" },
"remove one or more key ID's from the trusted list" },
{ "", "", "", "" },
"display the state of the authentication code" },
{ "", "", "", "" },
"display the traps set in the server" },
{ "address", "port", "interface", "" },
"configure a trap in the server" },
{ "address", "port", "interface", "" },
"remove a trap (configured or otherwise) from the server" },
{ "keyid", "", "", "" },
"change the keyid the server uses to authenticate requests" },
{ "keyid", "", "", "" },
"change the keyid the server uses to authenticate control messages" },
{ "", "", "", "" },
"display packet count statistics from the control module" },
{ "", "", "", "" },
"display the current leap second state" },
{ "address", "address", "address", "address" },
"display clock status information" },
{ "address", "time1|time2|val1|val2|flags", "value", "" },
{ "address", "address", "address", "address" },
"display clock debugging information" },
{ "", "", "", "" },
{ "", "", "", "" }, "" }
};
/*
* Imported from ntpdc.c
*/
extern int showhostnames;
extern int debug;
extern struct servent *server_entry;
/*
* For quick string comparisons
*/
/*
* checkitems - utility to print a message if no items were returned
*/
static int
int items;
{
if (items == 0) {
return 0;
}
return 1;
}
/*
* checkitemsize - utility to print a message if the item size is wrong
*/
static int
int itemsize;
int expected;
{
"***Incorrect item size returned by remote host (%d should be %d)\n",
return 0;
}
return 1;
}
/*
* check1item - check to make sure we have exactly one item
*/
static int
int items;
{
if (items == 0) {
return 0;
}
if (items > 1) {
items);
return 0;
}
return 1;
}
/*
* peerlist - get a short list of peers
*/
/*ARGSUSED*/
static void
{
struct info_peer_list *plist;
int items;
int itemsize;
int res;
return;
return;
return;
while (items > 0) {
plist++;
items--;
}
}
/*
* peers - show peer summary
*/
static void
{
}
/*
* dmpeers - show peer summary, Dave Mills style
*/
static void
{
}
/*
* peers - show peer summary
*/
/*ARGSUSED*/
static void
int dmstyle;
{
struct info_peer_summary *plist;
int items;
int itemsize;
int ntp_poll;
int res;
int c;
return;
return;
return;
" remote local st poll reach delay offset disp\n");
"=======================================================================\n");
while (items > 0) {
if (!dmstyle) {
c = '*';
c = '+';
c = '-';
c = '=';
c = '^';
c = '~';
else
c = ' ';
} else {
c = '*';
c = '+';
c = '.';
else
c = ' ';
}
"%c%-15.15s %-15.15s %2d %4d %3o %7.7s %9.9s %7.7s\n",
plist++;
items--;
}
}
/* Convert a refid & stratum (in host order) to a string */
static char*
int stratum;
{
if (stratum <= 1) {
static char junk[5];
junk[4] = 0;
return junk;
}
}
/*
* printpeer - print detail information for a peer
*/
static void
{
register int i;
char *str;
"leap %c%c, refid [%s], rootdistance %s, rootdispersion %s\n",
"ppoll %d, hpoll %d, keyid %lu, version %d, association %u\n",
"valid %d, reach %03o, unreach %d, flash %03o, ",
} else {
str = "";
str = ",";
}
str = ",";
}
str = ",";
}
str = ",";
}
str = ",";
}
}
}
prettydate(&tempts));
prettydate(&tempts));
prettydate(&tempts));
prettydate(&tempts));
for (i = 0; i < NTP_SHIFT; i++) {
}
for (i = 0; i < NTP_SHIFT; i++) {
}
for (i = 0; i < NTP_SHIFT; i++) {
}
"offset %s, delay %s, dispersion %s, selectdisp %s\n",
}
/*
* showpeer - show detailed information for a peer
*/
static void
{
/* 4 is the maximum number of peers which will fit in a packet */
int qitems;
int items;
int itemsize;
int res;
}
return;
return;
return;
while (items-- > 0) {
if (items > 0)
pp++;
}
}
/*
* peerstats - return statistics for a peer
*/
static void
{
struct info_peer_stats *pp;
/* 4 is the maximum number of peers which will fit in a packet */
int qitems;
int items;
int itemsize;
int res;
}
return;
return;
return;
while (items-- > 0) {
if (items > 0)
pp++;
}
}
/*
* loopinfo - show loop filter information
*/
static void
{
int items;
int itemsize;
int oneline = 0;
int res;
oneline = 1;
oneline = 0;
else {
return;
}
}
return;
return;
return;
if (oneline) {
"offset %s, frequency %s, time_const %ld, watchdog %ld\n",
} else {
}
}
/*
* sysinfo - show current system state
*/
/*ARGSUSED*/
static void
{
int items;
int itemsize;
int res;
return;
return;
return;
} else {
}
}
/*
* sysstats - print system statistics
*/
/*ARGSUSED*/
static void
{
struct info_sys_stats *ss;
int items;
int itemsize;
int res;
return;
return;
if (itemsize != sizeof(struct info_sys_stats) &&
itemsize != sizeof(struct old_info_sys_stats)) {
/* issue warning according to new structure size */
return;
}
if (itemsize != sizeof(struct info_sys_stats))
return;
}
/*
* iostats - print I/O statistics
*/
/*ARGSUSED*/
static void
{
struct info_io_stats *io;
int items;
int itemsize;
int res;
return;
return;
return;
}
/*
* memstats - print peer memory statistics
*/
/*ARGSUSED*/
static void
{
struct info_mem_stats *mem;
int i;
int items;
int itemsize;
int res;
return;
return;
return;
for (i = 0; i < HASH_SIZE; i++) {
}
}
}
/*
* timerstats - print timer statistics
*/
/*ARGSUSED*/
static void
{
struct info_timer_stats *tim;
int items;
int itemsize;
int res;
return;
return;
return;
}
/*
* addpeer - configure an active mode association
*/
static void
{
}
/*
* addserver - configure a client mode association
*/
static void
{
}
/*
* addrefclock - configure a reference clock association
*/
static void
{
}
/*
* broadcast - configure a broadcast mode association
*/
static void
{
}
/*
* config - configure a new peer association
*/
static void
int mode;
int refc;
{
int items;
int itemsize;
char *dummy;
int res;
keyid = 0;
flags = 0;
res = 0;
cmode = 0;
if (refc) {
items = 2;
}
} else {
if (keyid > 0) {
}
if (version > NTP_VERSION
|| version < NTP_OLDVERSION) {
"funny version number %u specified\n",
version);
res++;
}
items = 3;
}
}
}
"prefer"))
else {
long val;
"%s not understood\n",
res++;
break;
} else {
} else {
"minpol must be within %d..%d\n",
res++;
break;
}
}
}
items++;
}
if (res)
return;
if (res == 0)
return;
}
/*
* unconfig - unconfigure some associations
*/
static void
{
/* 8 is the maximum number of peers which will fit in a packet */
int qitems;
int items;
int itemsize;
char *dummy;
int res;
}
if (res == 0)
}
/*
* set - set some system flags
*/
static void
{
}
/*
* clear - clear some system flags
*/
static void
{
}
/*
*/
static void
int req;
{
/* 8 is the maximum number of peers which will fit in a packet */
struct conf_sys_flags sys;
int items;
int itemsize;
char *dummy;
int res;
res = 0;
else {
res = 1;
}
}
return;
if (res == 0)
}
/*
* data for printing/interrpreting the restrict flags
*/
struct resflags {
const char *str;
int bit;
};
{ "ignore", RES_IGNORE },
{ "noserve", RES_DONTSERVE },
{ "notrust", RES_DONTTRUST },
{ "noquery", RES_NOQUERY },
{ "nomodify", RES_NOMODIFY },
{ "nopeer", RES_NOPEER },
{ "notrap", RES_NOTRAP },
{ "lptrap", RES_LPTRAP },
{ "limited", RES_LIMITED },
{ "", 0 }
};
{ "ntpport", RESM_NTPONLY },
{ "interface", RESM_INTERFACE },
{ "", 0 }
};
/*
* reslist - obtain and print the server's restrict list
*/
/*ARGSUSED*/
static void
{
struct info_restrict *rl;
int items;
int itemsize;
int res;
char *addr;
char *mask;
char flagstr[300];
static const char *comma = ", ";
return;
return;
return;
" address mask count flags\n");
"=====================================================================\n");
while (items > 0) {
else
flagstr[0] = '\0';
res = 1;
if (!res)
res = 0;
}
rf++;
}
if (!res)
res = 0;
}
rf++;
}
if (flagstr[0] == '\0')
rl++;
items--;
}
}
/*
*/
static void
{
}
/*
* unrestrict - remove restriction flags from existing entry
*/
static void
{
}
/*
* delrestrict - delete an existing restriction
*/
static void
{
}
/*
* do_restrict - decode commandline restrictions and make the request
*/
static void
int req_code;
{
struct conf_restrict cres;
int items;
int itemsize;
char *dummy;
int i;
int res;
int err;
err = 0;
} else {
break;
}
if (req_code == REQ_UNRESTRICT) {
"Flag %s inappropriate\n",
err++;
}
} else {
err++;
}
}
}
/*
* Make sure mask for default address is zero. Otherwise,
* make sure mask bits are contiguous.
*/
} else {
break;
break;
if (bit != 0) {
err++;
}
}
if (err)
return;
if (res == 0)
return;
}
/*
* monlist - obtain and print the server's monitor data
*/
/*ARGSUSED*/
static void
{
char *struct_star;
int items;
int itemsize;
int res;
int version = -1;
}
REQ_MON_GETLIST, 0, 0, 0, (char *)NULL,
return;
return;
if (itemsize == sizeof(struct info_monitor_1)) {
"remote address port local address count m ver drop last first\n");
"===============================================================================\n");
while (items > 0) {
"%-22.22s %5d %-15s %8ld %1d %1d %6lu %6lu %7lu\n",
ml++;
items--;
}
} else if (itemsize == sizeof(struct info_monitor)) {
" address port count mode ver lastdrop lasttime firsttime\n");
"===============================================================================\n");
while (items > 0) {
"%-25.25s %5d %9ld %4d %2d %9lu %9lu %9lu\n",
ml++;
items--;
}
} else if (itemsize == sizeof(struct old_info_monitor)) {
" address port count mode version lasttime firsttime\n");
"======================================================================\n");
while (items > 0) {
oml++;
items--;
}
} else {
/* issue warning according to new info_monitor size */
}
}
/*
* Mapping between command line strings and stat reset flags
*/
struct statreset {
const char *str;
int flag;
} sreset[] = {
{ "io", RESET_FLAG_IO },
{ "sys", RESET_FLAG_SYS },
{ "mem", RESET_FLAG_MEM },
{ "timer", RESET_FLAG_TIMER },
{ "auth", RESET_FLAG_AUTH },
{ "allpeers", RESET_FLAG_ALLPEERS },
{ "", 0 }
};
/*
* reset - reset statistic counters
*/
static void
{
struct reset_flags rflags;
int items;
int itemsize;
char *dummy;
int i;
int res;
int err;
err = 0;
break;
}
err++;
} else {
}
}
if (err) {
return;
}
if (res == 0)
return;
}
/*
* preset - reset stat counters for particular peers
*/
static void
{
/* 8 is the maximum number of peers which will fit in a packet */
int qitems;
int items;
int itemsize;
char *dummy;
int res;
}
if (res == 0)
}
/*
* readkeys - request the server to reread the keys file
*/
/*ARGSUSED*/
static void
{
int items;
int itemsize;
char *dummy;
int res;
if (res == 0)
return;
}
/*
* trustkey - add some keys to the trusted key list
*/
static void
{
}
/*
* untrustkey - remove some keys from the trusted key list
*/
static void
{
}
/*
*/
static void
int req;
{
int i;
int items;
int itemsize;
char *dummy;
int ritems;
int res;
ritems = 0;
}
if (res == 0)
return;
}
/*
* authinfo - obtain and print info about authentication
*/
/*ARGSUSED*/
static void
{
int items;
int itemsize;
int res;
return;
return;
return;
}
/*
* traps - obtain and print a list of traps
*/
/*ARGSUSED*/
static void
{
int i;
int items;
int itemsize;
int res;
return;
return;
return;
for (i = 0; i < items; i++ ) {
if (i != 0)
(it->local_address == 0)
? "wildcard"
else
}
}
/*
* addtrap - configure a trap
*/
static void
{
}
/*
* clrtrap - clear a trap from the server
*/
static void
{
}
/*
*/
static void
int req;
{
int items;
int itemsize;
char *dummy;
int res;
ctrap.local_address = 0;
}
if (res == 0)
return;
}
/*
* requestkey - change the server's request key (a dangerous request)
*/
static void
{
}
/*
* controlkey - change the server's control key
*/
static void
{
}
/*
* do_changekey - do grunge work of changing keys
*/
static void
int req;
{
int items;
int itemsize;
char *dummy;
int res;
if (res == 0)
return;
}
/*
* ctlstats - obtain and print info about authentication
*/
/*ARGSUSED*/
static void
{
struct info_control *ic;
int items;
int itemsize;
int res;
return;
return;
return;
}
/*
* Table for human printing leap bits
*/
const char *leapbittab[] = {
"00 (no leap second scheduled)",
"01 (second to be added at end of month)",
"10 (second to be deleted at end of month)",
"11 (clock out of sync)"
};
const char *controlleapbittab[] = {
"00 (leap controlled by lower stratum)",
"01 (second to be added at end of month)",
"10 (second to be deleted at end of month)",
"11 (lower stratum leap information ignored - no leap)"
};
/*
* leapinfo - obtain information about the state of the leap second support
*/
/*ARGSUSED*/
static void
{
int items;
int itemsize;
int res;
return;
return;
return;
get_systime(&ts);
}
/*
* clockstat - get and print clock status information
*/
static void
{
struct info_clock *cl;
/* 8 is the maximum number of clocks which will fit in a packet */
int qitems;
int items;
int itemsize;
int res;
return;
return;
return;
while (items-- > 0) {
break;
else
cl->currentstatus);
(char *)<emp);
if (items > 0)
cl++;
}
}
/*
* fudge - set clock fudge factors
*/
static void
{
struct conf_fudge fudgedata;
int items;
int itemsize;
char *dummy;
int res;
long val;
int err;
err = 0;
err = 1;
else
err = 1;
else
err = 1;
else
err = 1;
else
err = 1;
else
} else {
return;
}
if (err) {
return;
}
if (res == 0)
return;
}
/*
* clkbug - get and print clock debugging information
*/
static void
{
register int i;
register int n;
register u_int32 s;
struct info_clkbug *cl;
/* 8 is the maximum number of clocks which will fit in a packet */
int qitems;
int items;
int itemsize;
int res;
return;
return;
return;
while (items-- > 0) {
if (n > NUMCBUGVALUES)
n = NUMCBUGVALUES;
for (i = 0; i < n; i++) {
if ((i & 0x3) == 0)
if (s & (1 << i))
else
}
if (n > NUMCBUGTIMES)
n = NUMCBUGTIMES;
for (i = 0; i < n; i++) {
int needsp = 0;
if ((i & 0x1) == 0)
else {
}
if (s & (1 << i)) {
needsp = 22;
} else {
needsp = 2;
}
}
if (items > 0) {
cl++;
}
}
}
/*
*/
static void
{
struct info_kernel *ik;
int items;
int itemsize;
int res;
return;
return;
return;
/*
* pll variables
*/
/*
* For backwards compatibility (ugh), we find the pps variables
* only if the shift member is nonzero.
*/
return;
/*
* pps variables
*/
}