reference: add orphan mode to local reference
Add orphan option to the local directive. It will enable an orphan mode compatible with ntpd.
This commit is contained in:
parent
81f440a882
commit
8fe5e9cf1e
6 changed files with 26 additions and 6 deletions
|
@ -224,13 +224,14 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
CPS_ParseLocal(char *line, int *stratum, double *distance)
|
CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
|
|
||||||
*stratum = 10;
|
*stratum = 10;
|
||||||
*distance = 1.0;
|
*distance = 1.0;
|
||||||
|
*orphan = 0;
|
||||||
|
|
||||||
while (*line) {
|
while (*line) {
|
||||||
cmd = line;
|
cmd = line;
|
||||||
|
@ -239,6 +240,9 @@ CPS_ParseLocal(char *line, int *stratum, double *distance)
|
||||||
if (!strcasecmp(cmd, "stratum")) {
|
if (!strcasecmp(cmd, "stratum")) {
|
||||||
if (sscanf(line, "%d%n", stratum, &n) != 1)
|
if (sscanf(line, "%d%n", stratum, &n) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "orphan")) {
|
||||||
|
*orphan = 1;
|
||||||
|
n = 0;
|
||||||
} else if (!strcasecmp(cmd, "distance")) {
|
} else if (!strcasecmp(cmd, "distance")) {
|
||||||
if (sscanf(line, "%lf%n", distance, &n) != 1)
|
if (sscanf(line, "%lf%n", distance, &n) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -60,7 +60,7 @@ typedef struct {
|
||||||
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
||||||
|
|
||||||
/* Parse a command to enable local reference */
|
/* Parse a command to enable local reference */
|
||||||
extern int CPS_ParseLocal(char *line, int *stratum, double *distance);
|
extern int CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance);
|
||||||
|
|
||||||
/* Get a string describing error status */
|
/* Get a string describing error status */
|
||||||
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
||||||
|
|
6
conf.c
6
conf.c
|
@ -108,6 +108,7 @@ static char *dumpdir;
|
||||||
|
|
||||||
static int enable_local=0;
|
static int enable_local=0;
|
||||||
static int local_stratum;
|
static int local_stratum;
|
||||||
|
static int local_orphan;
|
||||||
static double local_distance;
|
static double local_distance;
|
||||||
|
|
||||||
/* Threshold (in seconds) - if absolute value of initial error is less
|
/* Threshold (in seconds) - if absolute value of initial error is less
|
||||||
|
@ -818,7 +819,7 @@ parse_log(char *line)
|
||||||
static void
|
static void
|
||||||
parse_local(char *line)
|
parse_local(char *line)
|
||||||
{
|
{
|
||||||
if (!CPS_ParseLocal(line, &local_stratum, &local_distance))
|
if (!CPS_ParseLocal(line, &local_stratum, &local_orphan, &local_distance))
|
||||||
command_parse_error();
|
command_parse_error();
|
||||||
enable_local = 1;
|
enable_local = 1;
|
||||||
}
|
}
|
||||||
|
@ -1566,10 +1567,11 @@ CNF_GetCommandPort(void) {
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
CNF_AllowLocalReference(int *stratum, double *distance)
|
CNF_AllowLocalReference(int *stratum, int *orphan, double *distance)
|
||||||
{
|
{
|
||||||
if (enable_local) {
|
if (enable_local) {
|
||||||
*stratum = local_stratum;
|
*stratum = local_stratum;
|
||||||
|
*orphan = local_orphan;
|
||||||
*distance = local_distance;
|
*distance = local_distance;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
2
conf.h
2
conf.h
|
@ -92,7 +92,7 @@ extern double CNF_GetReselectDistance(void);
|
||||||
extern double CNF_GetStratumWeight(void);
|
extern double CNF_GetStratumWeight(void);
|
||||||
extern double CNF_GetCombineLimit(void);
|
extern double CNF_GetCombineLimit(void);
|
||||||
|
|
||||||
extern int CNF_AllowLocalReference(int *stratum, double *distance);
|
extern int CNF_AllowLocalReference(int *stratum, int *orphan, double *distance);
|
||||||
|
|
||||||
extern void CNF_SetupAccessRestrictions(void);
|
extern void CNF_SetupAccessRestrictions(void);
|
||||||
|
|
||||||
|
|
13
reference.c
13
reference.c
|
@ -45,6 +45,7 @@
|
||||||
static int are_we_synchronised;
|
static int are_we_synchronised;
|
||||||
static int enable_local_stratum;
|
static int enable_local_stratum;
|
||||||
static int local_stratum;
|
static int local_stratum;
|
||||||
|
static int local_orphan;
|
||||||
static double local_distance;
|
static double local_distance;
|
||||||
static NTP_Leap our_leap_status;
|
static NTP_Leap our_leap_status;
|
||||||
static int our_leap_sec;
|
static int our_leap_sec;
|
||||||
|
@ -236,7 +237,7 @@ REF_Initialise(void)
|
||||||
|
|
||||||
correction_time_ratio = CNF_GetCorrectionTimeRatio();
|
correction_time_ratio = CNF_GetCorrectionTimeRatio();
|
||||||
|
|
||||||
enable_local_stratum = CNF_AllowLocalReference(&local_stratum, &local_distance);
|
enable_local_stratum = CNF_AllowLocalReference(&local_stratum, &local_orphan, &local_distance);
|
||||||
local_timeout_id = 0;
|
local_timeout_id = 0;
|
||||||
|
|
||||||
leap_timeout_id = 0;
|
leap_timeout_id = 0;
|
||||||
|
@ -1274,6 +1275,16 @@ REF_GetOurStratum(void)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
REF_GetOrphanStratum(void)
|
||||||
|
{
|
||||||
|
if (!enable_local_stratum || !local_orphan)
|
||||||
|
return NTP_MAX_STRATUM;
|
||||||
|
return local_stratum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
double
|
double
|
||||||
REF_GetSkew(void)
|
REF_GetSkew(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -165,6 +165,9 @@ REF_SetUnsynchronised(void);
|
||||||
synchronised */
|
synchronised */
|
||||||
extern int REF_GetOurStratum(void);
|
extern int REF_GetOurStratum(void);
|
||||||
|
|
||||||
|
/* Return stratum of the local reference if orphan mode is enabled */
|
||||||
|
extern int REF_GetOrphanStratum(void);
|
||||||
|
|
||||||
/* Return the current skew */
|
/* Return the current skew */
|
||||||
extern double REF_GetSkew(void);
|
extern double REF_GetSkew(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue