cmdparse: add functions for parsing refclock refid and select options
This will be used in new chronyc command working on refclocks.
This commit is contained in:
parent
1a98c5ffa9
commit
3260dc82fe
3 changed files with 47 additions and 26 deletions
45
cmdparse.c
45
cmdparse.c
|
@ -44,7 +44,7 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
{
|
{
|
||||||
char *hostname, *cmd;
|
char *hostname, *cmd;
|
||||||
uint32_t ef_type;
|
uint32_t ef_type;
|
||||||
int n;
|
int n, sel_option;
|
||||||
|
|
||||||
src->port = SRC_DEFAULT_PORT;
|
src->port = SRC_DEFAULT_PORT;
|
||||||
src->params.minpoll = SRC_DEFAULT_MINPOLL;
|
src->params.minpoll = SRC_DEFAULT_MINPOLL;
|
||||||
|
@ -101,14 +101,6 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
src->params.iburst = 1;
|
src->params.iburst = 1;
|
||||||
} else if (!strcasecmp(cmd, "offline")) {
|
} else if (!strcasecmp(cmd, "offline")) {
|
||||||
src->params.connectivity = SRC_OFFLINE;
|
src->params.connectivity = SRC_OFFLINE;
|
||||||
} else if (!strcasecmp(cmd, "noselect")) {
|
|
||||||
src->params.sel_options |= SRC_SELECT_NOSELECT;
|
|
||||||
} else if (!strcasecmp(cmd, "prefer")) {
|
|
||||||
src->params.sel_options |= SRC_SELECT_PREFER;
|
|
||||||
} else if (!strcasecmp(cmd, "require")) {
|
|
||||||
src->params.sel_options |= SRC_SELECT_REQUIRE;
|
|
||||||
} else if (!strcasecmp(cmd, "trust")) {
|
|
||||||
src->params.sel_options |= SRC_SELECT_TRUST;
|
|
||||||
} else if (!strcasecmp(cmd, "certset")) {
|
} else if (!strcasecmp(cmd, "certset")) {
|
||||||
if (sscanf(line, "%"SCNu32"%n", &src->params.cert_set, &n) != 1)
|
if (sscanf(line, "%"SCNu32"%n", &src->params.cert_set, &n) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -187,6 +179,8 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!strcasecmp(cmd, "xleave")) {
|
} else if (!strcasecmp(cmd, "xleave")) {
|
||||||
src->params.interleaved = 1;
|
src->params.interleaved = 1;
|
||||||
|
} else if ((sel_option = CPS_GetSelectOption(cmd)) != 0) {
|
||||||
|
src->params.sel_options |= sel_option;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -197,6 +191,23 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CPS_GetSelectOption(char *option)
|
||||||
|
{
|
||||||
|
if (!strcasecmp(option, "noselect")) {
|
||||||
|
return SRC_SELECT_NOSELECT;
|
||||||
|
} else if (!strcasecmp(option, "prefer")) {
|
||||||
|
return SRC_SELECT_PREFER;
|
||||||
|
} else if (!strcasecmp(option, "require")) {
|
||||||
|
return SRC_SELECT_REQUIRE;
|
||||||
|
} else if (!strcasecmp(option, "trust")) {
|
||||||
|
return SRC_SELECT_TRUST;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
CPS_ParseAllowDeny(char *line, int *all, IPAddr *ip, int *subnet_bits)
|
CPS_ParseAllowDeny(char *line, int *all, IPAddr *ip, int *subnet_bits)
|
||||||
{
|
{
|
||||||
|
@ -396,3 +407,19 @@ CPS_ParseKey(char *line, uint32_t *id, const char **type, char **key)
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CPS_ParseRefid(char *line, uint32_t *ref_id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = *ref_id = 0; line[i] && !isspace((unsigned char)line[i]); i++) {
|
||||||
|
if (i >= 4)
|
||||||
|
return 0;
|
||||||
|
*ref_id |= (uint32_t)line[i] << (24 - i * 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ typedef struct {
|
||||||
/* Parse a command to add an NTP server or peer */
|
/* Parse a command to add an NTP server or peer */
|
||||||
extern int CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
extern int CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
||||||
|
|
||||||
|
/* Get an NTP/refclock select option */
|
||||||
|
extern int CPS_GetSelectOption(char *option);
|
||||||
|
|
||||||
/* Parse a command to allow/deny access */
|
/* Parse a command to allow/deny access */
|
||||||
extern int CPS_ParseAllowDeny(char *line, int *all, IPAddr *ip, int *subnet_bits);
|
extern int CPS_ParseAllowDeny(char *line, int *all, IPAddr *ip, int *subnet_bits);
|
||||||
|
|
||||||
|
@ -54,4 +57,7 @@ extern char *CPS_SplitWord(char *line);
|
||||||
/* Parse a key from keyfile */
|
/* Parse a key from keyfile */
|
||||||
extern int CPS_ParseKey(char *line, uint32_t *id, const char **type, char **key);
|
extern int CPS_ParseKey(char *line, uint32_t *id, const char **type, char **key);
|
||||||
|
|
||||||
|
/* Parse a refclock reference ID (returns number of characters) */
|
||||||
|
extern int CPS_ParseRefid(char *line, uint32_t *ref_id);
|
||||||
|
|
||||||
#endif /* GOT_CMDPARSE_H */
|
#endif /* GOT_CMDPARSE_H */
|
||||||
|
|
22
conf.c
22
conf.c
|
@ -862,11 +862,10 @@ static void
|
||||||
parse_refclock(char *line)
|
parse_refclock(char *line)
|
||||||
{
|
{
|
||||||
int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options;
|
int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options;
|
||||||
int local, max_lock_age, pps_forced, stratum, tai;
|
int local, max_lock_age, pps_forced, sel_option, stratum, tai;
|
||||||
uint32_t ref_id, lock_ref_id;
|
uint32_t ref_id, lock_ref_id;
|
||||||
double offset, delay, precision, max_dispersion, pulse_width;
|
double offset, delay, precision, max_dispersion, pulse_width;
|
||||||
char *p, *cmd, *name, *param;
|
char *p, *cmd, *name, *param;
|
||||||
unsigned char ref[5];
|
|
||||||
RefclockParameters *refclock;
|
RefclockParameters *refclock;
|
||||||
|
|
||||||
poll = 4;
|
poll = 4;
|
||||||
|
@ -912,13 +911,11 @@ parse_refclock(char *line)
|
||||||
line = CPS_SplitWord(line);
|
line = CPS_SplitWord(line);
|
||||||
|
|
||||||
if (!strcasecmp(cmd, "refid")) {
|
if (!strcasecmp(cmd, "refid")) {
|
||||||
if (sscanf(line, "%4s%n", (char *)ref, &n) != 1)
|
if ((n = CPS_ParseRefid(line, &ref_id)) == 0)
|
||||||
break;
|
break;
|
||||||
ref_id = (uint32_t)ref[0] << 24 | ref[1] << 16 | ref[2] << 8 | ref[3];
|
|
||||||
} else if (!strcasecmp(cmd, "lock")) {
|
} else if (!strcasecmp(cmd, "lock")) {
|
||||||
if (sscanf(line, "%4s%n", (char *)ref, &n) != 1)
|
if ((n = CPS_ParseRefid(line, &lock_ref_id)) == 0)
|
||||||
break;
|
break;
|
||||||
lock_ref_id = (uint32_t)ref[0] << 24 | ref[1] << 16 | ref[2] << 8 | ref[3];
|
|
||||||
} else if (!strcasecmp(cmd, "poll")) {
|
} else if (!strcasecmp(cmd, "poll")) {
|
||||||
if (sscanf(line, "%d%n", &poll, &n) != 1) {
|
if (sscanf(line, "%d%n", &poll, &n) != 1) {
|
||||||
break;
|
break;
|
||||||
|
@ -971,18 +968,9 @@ parse_refclock(char *line)
|
||||||
} else if (!strcasecmp(cmd, "width")) {
|
} else if (!strcasecmp(cmd, "width")) {
|
||||||
if (sscanf(line, "%lf%n", &pulse_width, &n) != 1)
|
if (sscanf(line, "%lf%n", &pulse_width, &n) != 1)
|
||||||
break;
|
break;
|
||||||
} else if (!strcasecmp(cmd, "noselect")) {
|
} else if ((sel_option = CPS_GetSelectOption(cmd)) != 0) {
|
||||||
n = 0;
|
n = 0;
|
||||||
sel_options |= SRC_SELECT_NOSELECT;
|
sel_options |= sel_option;
|
||||||
} else if (!strcasecmp(cmd, "prefer")) {
|
|
||||||
n = 0;
|
|
||||||
sel_options |= SRC_SELECT_PREFER;
|
|
||||||
} else if (!strcasecmp(cmd, "trust")) {
|
|
||||||
n = 0;
|
|
||||||
sel_options |= SRC_SELECT_TRUST;
|
|
||||||
} else if (!strcasecmp(cmd, "require")) {
|
|
||||||
n = 0;
|
|
||||||
sel_options |= SRC_SELECT_REQUIRE;
|
|
||||||
} else {
|
} else {
|
||||||
other_parse_error("Invalid refclock option");
|
other_parse_error("Invalid refclock option");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue