1c0b746e5SOllivier Robert /* 2c0b746e5SOllivier Robert * ntpq.h - definitions of interest to ntpq 3c0b746e5SOllivier Robert */ 42b15cb3dSCy Schubert #ifdef HAVE_UNISTD_H 52b15cb3dSCy Schubert # include <unistd.h> 62b15cb3dSCy Schubert #endif 7c0b746e5SOllivier Robert #include "ntp_fp.h" 8c0b746e5SOllivier Robert #include "ntp.h" 92b15cb3dSCy Schubert #include "ntp_stdlib.h" 10c0b746e5SOllivier Robert #include "ntp_string.h" 11c0b746e5SOllivier Robert #include "ntp_malloc.h" 122b15cb3dSCy Schubert #include "ntp_assert.h" 132b15cb3dSCy Schubert #include "ntp_control.h" 14c0b746e5SOllivier Robert 154990d495SXin LI #include "ntpq-opts.h" 164990d495SXin LI 17c0b746e5SOllivier Robert /* 18c0b746e5SOllivier Robert * Maximum number of arguments 19c0b746e5SOllivier Robert */ 20c0b746e5SOllivier Robert #define MAXARGS 4 21c0b746e5SOllivier Robert 22c0b746e5SOllivier Robert /* 232b15cb3dSCy Schubert * Limit on packets in a single response. Increasing this value to 242b15cb3dSCy Schubert * 96 will marginally speed "mrulist" operation on lossless networks 252b15cb3dSCy Schubert * but it has been observed to cause loss on WiFi networks and with 262b15cb3dSCy Schubert * an IPv6 go6.net tunnel over UDP. That loss causes the request 272b15cb3dSCy Schubert * row limit to be cut in half, and it grows back very slowly to 282b15cb3dSCy Schubert * ensure forward progress is made and loss isn't triggered too quickly 292b15cb3dSCy Schubert * afterward. While the lossless case gains only marginally with 302b15cb3dSCy Schubert * MAXFRAGS == 96, the lossy case is a lot slower due to the repeated 312b15cb3dSCy Schubert * timeouts. Empirally, MAXFRAGS == 32 avoids most of the routine loss 322b15cb3dSCy Schubert * on both the WiFi and UDP v6 tunnel tests and seems a good compromise. 332b15cb3dSCy Schubert * This suggests some device in the path has a limit of 32 ~512 byte UDP 342b15cb3dSCy Schubert * packets in queue. 352b15cb3dSCy Schubert * Lowering MAXFRAGS may help with particularly lossy networks, but some 362b15cb3dSCy Schubert * ntpq commands may rely on the longtime value of 24 implicitly, 372b15cb3dSCy Schubert * assuming a single multipacket response will be large enough for any 382b15cb3dSCy Schubert * needs. In contrast, the "mrulist" command is implemented as a series 392b15cb3dSCy Schubert * of requests and multipacket responses to each. 40c0b746e5SOllivier Robert */ 412b15cb3dSCy Schubert #define MAXFRAGS 32 422b15cb3dSCy Schubert 432b15cb3dSCy Schubert /* 442b15cb3dSCy Schubert * Error codes for internal use 452b15cb3dSCy Schubert */ 462b15cb3dSCy Schubert #define ERR_UNSPEC 256 472b15cb3dSCy Schubert #define ERR_INCOMPLETE 257 482b15cb3dSCy Schubert #define ERR_TIMEOUT 258 492b15cb3dSCy Schubert #define ERR_TOOMUCH 259 502b15cb3dSCy Schubert 51ea906c41SOllivier Robert /* 52ea906c41SOllivier Robert * Flags for forming descriptors. 53ea906c41SOllivier Robert */ 54c0b746e5SOllivier Robert #define OPT 0x80 /* this argument is optional, or'd with type */ 55c0b746e5SOllivier Robert 56c0b746e5SOllivier Robert #define NO 0x0 57ea906c41SOllivier Robert #define NTP_STR 0x1 /* string argument */ 58ea906c41SOllivier Robert #define NTP_UINT 0x2 /* unsigned integer */ 59ea906c41SOllivier Robert #define NTP_INT 0x3 /* signed integer */ 60ea906c41SOllivier Robert #define NTP_ADD 0x4 /* IP network address */ 61ea906c41SOllivier Robert #define IP_VERSION 0x5 /* IP version */ 622b15cb3dSCy Schubert #define NTP_ADP 0x6 /* IP address and port */ 632b15cb3dSCy Schubert #define NTP_LFP 0x7 /* NTP timestamp */ 642b15cb3dSCy Schubert #define NTP_MODE 0x8 /* peer mode */ 652b15cb3dSCy Schubert #define NTP_2BIT 0x9 /* leap bits */ 66*2d4e511cSCy Schubert #define NTP_REFID 0xA /* RefID */ 67c0b746e5SOllivier Robert 68c0b746e5SOllivier Robert /* 69c0b746e5SOllivier Robert * Arguments are returned in a union 70c0b746e5SOllivier Robert */ 71c0b746e5SOllivier Robert typedef union { 722b15cb3dSCy Schubert const char *string; 73c0b746e5SOllivier Robert long ival; 74c0b746e5SOllivier Robert u_long uval; 752b15cb3dSCy Schubert sockaddr_u netnum; 76c0b746e5SOllivier Robert } arg_v; 77c0b746e5SOllivier Robert 78c0b746e5SOllivier Robert /* 79c0b746e5SOllivier Robert * Structure for passing parsed command line 80c0b746e5SOllivier Robert */ 81c0b746e5SOllivier Robert struct parse { 82c0b746e5SOllivier Robert const char *keyword; 83c0b746e5SOllivier Robert arg_v argval[MAXARGS]; 842b15cb3dSCy Schubert size_t nargs; 85c0b746e5SOllivier Robert }; 86c0b746e5SOllivier Robert 87c0b746e5SOllivier Robert /* 88c0b746e5SOllivier Robert * ntpdc includes a command parser which could charitably be called 89c0b746e5SOllivier Robert * crude. The following structure is used to define the command 90c0b746e5SOllivier Robert * syntax. 91c0b746e5SOllivier Robert */ 92c0b746e5SOllivier Robert struct xcmd { 93c0b746e5SOllivier Robert const char *keyword; /* command key word */ 942b15cb3dSCy Schubert void (*handler) (struct parse *, FILE *); /* command handler */ 95c0b746e5SOllivier Robert u_char arg[MAXARGS]; /* descriptors for arguments */ 96c0b746e5SOllivier Robert const char *desc[MAXARGS]; /* descriptions for arguments */ 97c0b746e5SOllivier Robert const char *comment; 98c0b746e5SOllivier Robert }; 99c0b746e5SOllivier Robert 100c0b746e5SOllivier Robert /* 101c0b746e5SOllivier Robert * Structure to hold association data 102c0b746e5SOllivier Robert */ 103c0b746e5SOllivier Robert struct association { 1042b15cb3dSCy Schubert associd_t assid; 105c0b746e5SOllivier Robert u_short status; 106c0b746e5SOllivier Robert }; 107c0b746e5SOllivier Robert 1082b15cb3dSCy Schubert /* 1092b15cb3dSCy Schubert * mrulist terminal status interval 1102b15cb3dSCy Schubert */ 1112b15cb3dSCy Schubert #define MRU_REPORT_SECS 5 112c0b746e5SOllivier Robert 113c0b746e5SOllivier Robert /* 1142b15cb3dSCy Schubert * var_format is used to override cooked formatting for selected vars. 115c0b746e5SOllivier Robert */ 1162b15cb3dSCy Schubert typedef struct var_format_tag { 1172b15cb3dSCy Schubert const char * varname; 118c0b746e5SOllivier Robert u_short fmt; 1192b15cb3dSCy Schubert } var_format; 1202b15cb3dSCy Schubert 1212b15cb3dSCy Schubert typedef struct chost_tag chost; 1222b15cb3dSCy Schubert struct chost_tag { 1232b15cb3dSCy Schubert const char *name; 1242b15cb3dSCy Schubert int fam; 125c0b746e5SOllivier Robert }; 126c0b746e5SOllivier Robert 1272b15cb3dSCy Schubert extern chost chosts[]; 1282b15cb3dSCy Schubert 1292b15cb3dSCy Schubert extern int interactive; /* are we prompting? */ 1302b15cb3dSCy Schubert extern int old_rv; /* use old rv behavior? --old-rv */ 1314990d495SXin LI extern te_Refid drefid; /* How should we display a refid? */ 1322b15cb3dSCy Schubert extern u_int assoc_cache_slots;/* count of allocated array entries */ 1332b15cb3dSCy Schubert extern u_int numassoc; /* number of cached associations */ 1342b15cb3dSCy Schubert extern u_int numhosts; 1352b15cb3dSCy Schubert 1362b15cb3dSCy Schubert extern void grow_assoc_cache(void); 1372b15cb3dSCy Schubert extern void asciize (int, char *, FILE *); 1382b15cb3dSCy Schubert extern int getnetnum (const char *, sockaddr_u *, char *, int); 1392b15cb3dSCy Schubert extern void sortassoc (void); 1402b15cb3dSCy Schubert extern void show_error_msg (int, associd_t); 1412b15cb3dSCy Schubert extern int dogetassoc (FILE *); 1423311ff84SXin LI extern int doquery (int, associd_t, int, size_t, const char *, 1433311ff84SXin LI u_short *, size_t *, const char **); 1443311ff84SXin LI extern int doqueryex (int, associd_t, int, size_t, const char *, 1453311ff84SXin LI u_short *, size_t *, const char **, int); 1462b15cb3dSCy Schubert extern const char * nntohost (sockaddr_u *); 1472b15cb3dSCy Schubert extern const char * nntohost_col (sockaddr_u *, size_t, int); 1482b15cb3dSCy Schubert extern const char * nntohostp (sockaddr_u *); 1492b15cb3dSCy Schubert extern int decodets (char *, l_fp *); 1502b15cb3dSCy Schubert extern int decodeuint (char *, u_long *); 1513311ff84SXin LI extern int nextvar (size_t *, const char **, char **, char **); 1522b15cb3dSCy Schubert extern int decodetime (char *, l_fp *); 1533311ff84SXin LI extern void printvars (size_t, const char *, int, int, int, FILE *); 1542b15cb3dSCy Schubert extern int decodeint (char *, long *); 1553311ff84SXin LI extern void makeascii (size_t, const char *, FILE *); 1562b15cb3dSCy Schubert extern const char * trunc_left (const char *, size_t); 1572b15cb3dSCy Schubert extern const char * trunc_right(const char *, size_t); 1583311ff84SXin LI 1593311ff84SXin LI typedef int/*BOOL*/ (*Ctrl_C_Handler)(void); 1603311ff84SXin LI extern int/*BOOL*/ push_ctrl_c_handler(Ctrl_C_Handler); 1613311ff84SXin LI extern int/*BOOL*/ pop_ctrl_c_handler(Ctrl_C_Handler); 162