154359Sroberto/* 254359Sroberto * ntpq.h - definitions of interest to ntpq 354359Sroberto */ 4290000Sglebius#ifdef HAVE_UNISTD_H 5290000Sglebius# include <unistd.h> 6290000Sglebius#endif 754359Sroberto#include "ntp_fp.h" 854359Sroberto#include "ntp.h" 9290000Sglebius#include "ntp_stdlib.h" 1054359Sroberto#include "ntp_string.h" 1154359Sroberto#include "ntp_malloc.h" 12290000Sglebius#include "ntp_assert.h" 13290000Sglebius#include "ntp_control.h" 14290000Sglebius#include "lib_strbuf.h" 1554359Sroberto 16298770Sdelphij#include "ntpq-opts.h" 17298770Sdelphij 1854359Sroberto/* 1954359Sroberto * Maximum number of arguments 2054359Sroberto */ 2154359Sroberto#define MAXARGS 4 2254359Sroberto 2354359Sroberto/* 24290000Sglebius * Limit on packets in a single response. Increasing this value to 25290000Sglebius * 96 will marginally speed "mrulist" operation on lossless networks 26290000Sglebius * but it has been observed to cause loss on WiFi networks and with 27290000Sglebius * an IPv6 go6.net tunnel over UDP. That loss causes the request 28290000Sglebius * row limit to be cut in half, and it grows back very slowly to 29290000Sglebius * ensure forward progress is made and loss isn't triggered too quickly 30290000Sglebius * afterward. While the lossless case gains only marginally with 31290000Sglebius * MAXFRAGS == 96, the lossy case is a lot slower due to the repeated 32290000Sglebius * timeouts. Empirally, MAXFRAGS == 32 avoids most of the routine loss 33290000Sglebius * on both the WiFi and UDP v6 tunnel tests and seems a good compromise. 34290000Sglebius * This suggests some device in the path has a limit of 32 ~512 byte UDP 35290000Sglebius * packets in queue. 36290000Sglebius * Lowering MAXFRAGS may help with particularly lossy networks, but some 37290000Sglebius * ntpq commands may rely on the longtime value of 24 implicitly, 38290000Sglebius * assuming a single multipacket response will be large enough for any 39290000Sglebius * needs. In contrast, the "mrulist" command is implemented as a series 40290000Sglebius * of requests and multipacket responses to each. 4154359Sroberto */ 42290000Sglebius#define MAXFRAGS 32 43290000Sglebius 44182007Sroberto/* 45290000Sglebius * Error codes for internal use 46290000Sglebius */ 47290000Sglebius#define ERR_UNSPEC 256 48290000Sglebius#define ERR_INCOMPLETE 257 49290000Sglebius#define ERR_TIMEOUT 258 50290000Sglebius#define ERR_TOOMUCH 259 51290000Sglebius 52290000Sglebius/* 53182007Sroberto * Flags for forming descriptors. 54182007Sroberto */ 55182007Sroberto#define OPT 0x80 /* this argument is optional, or'd with type */ 5654359Sroberto 57182007Sroberto#define NO 0x0 58182007Sroberto#define NTP_STR 0x1 /* string argument */ 59182007Sroberto#define NTP_UINT 0x2 /* unsigned integer */ 60182007Sroberto#define NTP_INT 0x3 /* signed integer */ 61182007Sroberto#define NTP_ADD 0x4 /* IP network address */ 62182007Sroberto#define IP_VERSION 0x5 /* IP version */ 63290000Sglebius#define NTP_ADP 0x6 /* IP address and port */ 64290000Sglebius#define NTP_LFP 0x7 /* NTP timestamp */ 65290000Sglebius#define NTP_MODE 0x8 /* peer mode */ 66290000Sglebius#define NTP_2BIT 0x9 /* leap bits */ 6754359Sroberto 6854359Sroberto/* 6954359Sroberto * Arguments are returned in a union 7054359Sroberto */ 7154359Srobertotypedef union { 72290000Sglebius const char *string; 7354359Sroberto long ival; 7454359Sroberto u_long uval; 75290000Sglebius sockaddr_u netnum; 7654359Sroberto} arg_v; 7754359Sroberto 7854359Sroberto/* 7954359Sroberto * Structure for passing parsed command line 8054359Sroberto */ 8154359Srobertostruct parse { 8254359Sroberto const char *keyword; 8354359Sroberto arg_v argval[MAXARGS]; 84290000Sglebius size_t nargs; 8554359Sroberto}; 8654359Sroberto 8754359Sroberto/* 8854359Sroberto * ntpdc includes a command parser which could charitably be called 8954359Sroberto * crude. The following structure is used to define the command 9054359Sroberto * syntax. 9154359Sroberto */ 9254359Srobertostruct xcmd { 9354359Sroberto const char *keyword; /* command key word */ 94290000Sglebius void (*handler) (struct parse *, FILE *); /* command handler */ 9554359Sroberto u_char arg[MAXARGS]; /* descriptors for arguments */ 9654359Sroberto const char *desc[MAXARGS]; /* descriptions for arguments */ 9754359Sroberto const char *comment; 9854359Sroberto}; 9954359Sroberto 10054359Sroberto/* 10154359Sroberto * Structure to hold association data 10254359Sroberto */ 10354359Srobertostruct association { 104290000Sglebius associd_t assid; 10554359Sroberto u_short status; 10654359Sroberto}; 10754359Sroberto 108290000Sglebius/* 109290000Sglebius * mrulist terminal status interval 110290000Sglebius */ 111290000Sglebius#define MRU_REPORT_SECS 5 11254359Sroberto 11354359Sroberto/* 114290000Sglebius * var_format is used to override cooked formatting for selected vars. 11554359Sroberto */ 116290000Sglebiustypedef struct var_format_tag { 117290000Sglebius const char * varname; 118290000Sglebius u_short fmt; 119290000Sglebius} var_format; 120290000Sglebius 121290000Sglebiustypedef struct chost_tag chost; 122290000Sglebiusstruct chost_tag { 123290000Sglebius const char *name; 124290000Sglebius int fam; 12554359Sroberto}; 12654359Sroberto 127290000Sglebiusextern chost chosts[]; 128290000Sglebius 129290000Sglebiusextern int interactive; /* are we prompting? */ 130290000Sglebiusextern int old_rv; /* use old rv behavior? --old-rv */ 131298770Sdelphijextern te_Refid drefid; /* How should we display a refid? */ 132290000Sglebiusextern u_int assoc_cache_slots;/* count of allocated array entries */ 133290000Sglebiusextern u_int numassoc; /* number of cached associations */ 134290000Sglebiusextern u_int numhosts; 135290000Sglebius 136290000Sglebiusextern void grow_assoc_cache(void); 137290000Sglebiusextern void asciize (int, char *, FILE *); 138290000Sglebiusextern int getnetnum (const char *, sockaddr_u *, char *, int); 139290000Sglebiusextern void sortassoc (void); 140290000Sglebiusextern void show_error_msg (int, associd_t); 141290000Sglebiusextern int dogetassoc (FILE *); 142293894Sglebiusextern int doquery (int, associd_t, int, size_t, const char *, 143293894Sglebius u_short *, size_t *, const char **); 144293894Sglebiusextern int doqueryex (int, associd_t, int, size_t, const char *, 145293894Sglebius u_short *, size_t *, const char **, int); 146290000Sglebiusextern const char * nntohost (sockaddr_u *); 147290000Sglebiusextern const char * nntohost_col (sockaddr_u *, size_t, int); 148290000Sglebiusextern const char * nntohostp (sockaddr_u *); 149290000Sglebiusextern int decodets (char *, l_fp *); 150290000Sglebiusextern int decodeuint (char *, u_long *); 151293894Sglebiusextern int nextvar (size_t *, const char **, char **, char **); 152290000Sglebiusextern int decodetime (char *, l_fp *); 153293894Sglebiusextern void printvars (size_t, const char *, int, int, int, FILE *); 154290000Sglebiusextern int decodeint (char *, long *); 155293894Sglebiusextern void makeascii (size_t, const char *, FILE *); 156290000Sglebiusextern const char * trunc_left (const char *, size_t); 157290000Sglebiusextern const char * trunc_right(const char *, size_t); 158293894Sglebius 159293894Sglebiustypedef int/*BOOL*/ (*Ctrl_C_Handler)(void); 160293894Sglebiusextern int/*BOOL*/ push_ctrl_c_handler(Ctrl_C_Handler); 161293894Sglebiusextern int/*BOOL*/ pop_ctrl_c_handler(Ctrl_C_Handler); 162