1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* ntpq.h - definitions of interest to ntpq
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1999-12-09 13:01:21 +00:00
|
|
|
#include "ntp_fp.h"
|
|
|
|
#include "ntp.h"
|
2014-12-20 22:52:39 +00:00
|
|
|
#include "ntp_stdlib.h"
|
1999-12-09 13:01:21 +00:00
|
|
|
#include "ntp_string.h"
|
|
|
|
#include "ntp_malloc.h"
|
2014-12-20 22:52:39 +00:00
|
|
|
#include "ntp_assert.h"
|
|
|
|
#include "ntp_control.h"
|
2013-12-04 21:33:17 +00:00
|
|
|
#include "lib_strbuf.h"
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2016-04-27 05:37:54 +00:00
|
|
|
#include "ntpq-opts.h"
|
|
|
|
|
1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* Maximum number of arguments
|
|
|
|
*/
|
|
|
|
#define MAXARGS 4
|
|
|
|
|
|
|
|
/*
|
2014-12-20 22:52:39 +00:00
|
|
|
* Limit on packets in a single response. Increasing this value to
|
|
|
|
* 96 will marginally speed "mrulist" operation on lossless networks
|
|
|
|
* but it has been observed to cause loss on WiFi networks and with
|
|
|
|
* an IPv6 go6.net tunnel over UDP. That loss causes the request
|
|
|
|
* row limit to be cut in half, and it grows back very slowly to
|
|
|
|
* ensure forward progress is made and loss isn't triggered too quickly
|
|
|
|
* afterward. While the lossless case gains only marginally with
|
|
|
|
* MAXFRAGS == 96, the lossy case is a lot slower due to the repeated
|
|
|
|
* timeouts. Empirally, MAXFRAGS == 32 avoids most of the routine loss
|
|
|
|
* on both the WiFi and UDP v6 tunnel tests and seems a good compromise.
|
|
|
|
* This suggests some device in the path has a limit of 32 ~512 byte UDP
|
|
|
|
* packets in queue.
|
|
|
|
* Lowering MAXFRAGS may help with particularly lossy networks, but some
|
|
|
|
* ntpq commands may rely on the longtime value of 24 implicitly,
|
|
|
|
* assuming a single multipacket response will be large enough for any
|
|
|
|
* needs. In contrast, the "mrulist" command is implemented as a series
|
|
|
|
* of requests and multipacket responses to each.
|
1999-12-09 13:01:21 +00:00
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
#define MAXFRAGS 32
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error codes for internal use
|
|
|
|
*/
|
|
|
|
#define ERR_UNSPEC 256
|
|
|
|
#define ERR_INCOMPLETE 257
|
|
|
|
#define ERR_TIMEOUT 258
|
|
|
|
#define ERR_TOOMUCH 259
|
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/*
|
|
|
|
* Flags for forming descriptors.
|
|
|
|
*/
|
|
|
|
#define OPT 0x80 /* this argument is optional, or'd with type */
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
#define NO 0x0
|
|
|
|
#define NTP_STR 0x1 /* string argument */
|
|
|
|
#define NTP_UINT 0x2 /* unsigned integer */
|
|
|
|
#define NTP_INT 0x3 /* signed integer */
|
|
|
|
#define NTP_ADD 0x4 /* IP network address */
|
|
|
|
#define IP_VERSION 0x5 /* IP version */
|
2014-12-20 22:52:39 +00:00
|
|
|
#define NTP_ADP 0x6 /* IP address and port */
|
|
|
|
#define NTP_LFP 0x7 /* NTP timestamp */
|
|
|
|
#define NTP_MODE 0x8 /* peer mode */
|
|
|
|
#define NTP_2BIT 0x9 /* leap bits */
|
2020-03-04 13:59:29 +00:00
|
|
|
#define NTP_REFID 0xA /* RefID */
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments are returned in a union
|
|
|
|
*/
|
|
|
|
typedef union {
|
2014-12-20 22:52:39 +00:00
|
|
|
const char *string;
|
1999-12-09 13:01:21 +00:00
|
|
|
long ival;
|
|
|
|
u_long uval;
|
2013-12-04 21:33:17 +00:00
|
|
|
sockaddr_u netnum;
|
1999-12-09 13:01:21 +00:00
|
|
|
} arg_v;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure for passing parsed command line
|
|
|
|
*/
|
|
|
|
struct parse {
|
|
|
|
const char *keyword;
|
|
|
|
arg_v argval[MAXARGS];
|
2015-02-05 20:53:33 +00:00
|
|
|
size_t nargs;
|
1999-12-09 13:01:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ntpdc includes a command parser which could charitably be called
|
|
|
|
* crude. The following structure is used to define the command
|
|
|
|
* syntax.
|
|
|
|
*/
|
|
|
|
struct xcmd {
|
|
|
|
const char *keyword; /* command key word */
|
2013-12-04 21:33:17 +00:00
|
|
|
void (*handler) (struct parse *, FILE *); /* command handler */
|
1999-12-09 13:01:21 +00:00
|
|
|
u_char arg[MAXARGS]; /* descriptors for arguments */
|
|
|
|
const char *desc[MAXARGS]; /* descriptions for arguments */
|
|
|
|
const char *comment;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure to hold association data
|
|
|
|
*/
|
|
|
|
struct association {
|
2013-12-04 21:33:17 +00:00
|
|
|
associd_t assid;
|
1999-12-09 13:01:21 +00:00
|
|
|
u_short status;
|
|
|
|
};
|
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
/*
|
|
|
|
* mrulist terminal status interval
|
|
|
|
*/
|
|
|
|
#define MRU_REPORT_SECS 5
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/*
|
2014-12-20 22:52:39 +00:00
|
|
|
* var_format is used to override cooked formatting for selected vars.
|
1999-12-09 13:01:21 +00:00
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
typedef struct var_format_tag {
|
|
|
|
const char * varname;
|
|
|
|
u_short fmt;
|
|
|
|
} var_format;
|
|
|
|
|
|
|
|
typedef struct chost_tag chost;
|
|
|
|
struct chost_tag {
|
|
|
|
const char *name;
|
|
|
|
int fam;
|
1999-12-09 13:01:21 +00:00
|
|
|
};
|
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
extern chost chosts[];
|
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
extern int interactive; /* are we prompting? */
|
|
|
|
extern int old_rv; /* use old rv behavior? --old-rv */
|
2016-04-27 05:37:54 +00:00
|
|
|
extern te_Refid drefid; /* How should we display a refid? */
|
2014-12-20 22:52:39 +00:00
|
|
|
extern u_int assoc_cache_slots;/* count of allocated array entries */
|
|
|
|
extern u_int numassoc; /* number of cached associations */
|
|
|
|
extern u_int numhosts;
|
2013-12-04 21:33:17 +00:00
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
extern void grow_assoc_cache(void);
|
2013-12-04 21:33:17 +00:00
|
|
|
extern void asciize (int, char *, FILE *);
|
|
|
|
extern int getnetnum (const char *, sockaddr_u *, char *, int);
|
|
|
|
extern void sortassoc (void);
|
|
|
|
extern void show_error_msg (int, associd_t);
|
2014-12-20 22:52:39 +00:00
|
|
|
extern int dogetassoc (FILE *);
|
2016-01-08 08:06:14 +00:00
|
|
|
extern int doquery (int, associd_t, int, size_t, const char *,
|
|
|
|
u_short *, size_t *, const char **);
|
|
|
|
extern int doqueryex (int, associd_t, int, size_t, const char *,
|
|
|
|
u_short *, size_t *, const char **, int);
|
2014-12-20 22:52:39 +00:00
|
|
|
extern const char * nntohost (sockaddr_u *);
|
|
|
|
extern const char * nntohost_col (sockaddr_u *, size_t, int);
|
|
|
|
extern const char * nntohostp (sockaddr_u *);
|
2013-12-04 21:33:17 +00:00
|
|
|
extern int decodets (char *, l_fp *);
|
|
|
|
extern int decodeuint (char *, u_long *);
|
2016-01-08 08:06:14 +00:00
|
|
|
extern int nextvar (size_t *, const char **, char **, char **);
|
2013-12-04 21:33:17 +00:00
|
|
|
extern int decodetime (char *, l_fp *);
|
2016-01-08 08:06:14 +00:00
|
|
|
extern void printvars (size_t, const char *, int, int, int, FILE *);
|
2013-12-04 21:33:17 +00:00
|
|
|
extern int decodeint (char *, long *);
|
2016-01-08 08:06:14 +00:00
|
|
|
extern void makeascii (size_t, const char *, FILE *);
|
2014-12-20 22:52:39 +00:00
|
|
|
extern const char * trunc_left (const char *, size_t);
|
|
|
|
extern const char * trunc_right(const char *, size_t);
|
2016-01-08 08:06:14 +00:00
|
|
|
|
|
|
|
typedef int/*BOOL*/ (*Ctrl_C_Handler)(void);
|
|
|
|
extern int/*BOOL*/ push_ctrl_c_handler(Ctrl_C_Handler);
|
|
|
|
extern int/*BOOL*/ pop_ctrl_c_handler(Ctrl_C_Handler);
|