1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*
* ntpq.h - definitions of interest to ntpq
*/
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "ntp_fp.h"
#include "ntp.h"
#include "ntp_stdlib.h"
#include "ntp_string.h"
#include "ntp_malloc.h"
#include "ntp_assert.h"
#include "ntp_control.h"
#include "lib_strbuf.h"
#include "ntpq-opts.h"
/*
* Maximum number of arguments
*/
#define MAXARGS 4
/*
* 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.
*/
#define MAXFRAGS 32
/*
* Error codes for internal use
*/
#define ERR_UNSPEC 256
#define ERR_INCOMPLETE 257
#define ERR_TIMEOUT 258
#define ERR_TOOMUCH 259
/*
* Flags for forming descriptors.
*/
#define OPT 0x80 /* this argument is optional, or'd with type */
#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 */
#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 */
#define NTP_REFID 0xA /* RefID */
/*
* Arguments are returned in a union
*/
typedef union {
const char *string;
long ival;
u_long uval;
sockaddr_u netnum;
} arg_v;
/*
* Structure for passing parsed command line
*/
struct parse {
const char *keyword;
arg_v argval[MAXARGS];
size_t nargs;
};
/*
* 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 */
void (*handler) (struct parse *, FILE *); /* command handler */
u_char arg[MAXARGS]; /* descriptors for arguments */
const char *desc[MAXARGS]; /* descriptions for arguments */
const char *comment;
};
/*
* Structure to hold association data
*/
struct association {
associd_t assid;
u_short status;
};
/*
* mrulist terminal status interval
*/
#define MRU_REPORT_SECS 5
/*
* var_format is used to override cooked formatting for selected vars.
*/
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;
};
extern chost chosts[];
extern int interactive; /* are we prompting? */
extern int old_rv; /* use old rv behavior? --old-rv */
extern te_Refid drefid; /* How should we display a refid? */
extern u_int assoc_cache_slots;/* count of allocated array entries */
extern u_int numassoc; /* number of cached associations */
extern u_int numhosts;
extern void grow_assoc_cache(void);
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);
extern int dogetassoc (FILE *);
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);
extern const char * nntohost (sockaddr_u *);
extern const char * nntohost_col (sockaddr_u *, size_t, int);
extern const char * nntohostp (sockaddr_u *);
extern int decodets (char *, l_fp *);
extern int decodeuint (char *, u_long *);
extern int nextvar (size_t *, const char **, char **, char **);
extern int decodetime (char *, l_fp *);
extern void printvars (size_t, const char *, int, int, int, FILE *);
extern int decodeint (char *, long *);
extern void makeascii (size_t, const char *, FILE *);
extern const char * trunc_left (const char *, size_t);
extern const char * trunc_right(const char *, size_t);
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);
|