diff --git a/cmdparse.c b/cmdparse.c index 37d1581..1f1064a 100644 --- a/cmdparse.c +++ b/cmdparse.c @@ -224,13 +224,14 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src) /* ================================================== */ int -CPS_ParseLocal(char *line, int *stratum, double *distance) +CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance) { int n; char *cmd; *stratum = 10; *distance = 1.0; + *orphan = 0; while (*line) { cmd = line; @@ -239,6 +240,9 @@ CPS_ParseLocal(char *line, int *stratum, double *distance) if (!strcasecmp(cmd, "stratum")) { if (sscanf(line, "%d%n", stratum, &n) != 1) return 0; + } else if (!strcasecmp(cmd, "orphan")) { + *orphan = 1; + n = 0; } else if (!strcasecmp(cmd, "distance")) { if (sscanf(line, "%lf%n", distance, &n) != 1) return 0; diff --git a/cmdparse.h b/cmdparse.h index 6944475..a61fdc2 100644 --- a/cmdparse.h +++ b/cmdparse.h @@ -60,7 +60,7 @@ typedef struct { extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src); /* 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 */ extern void CPS_StatusToString(CPS_Status status, char *dest, int len); diff --git a/conf.c b/conf.c index 8c125ff..94f4ee1 100644 --- a/conf.c +++ b/conf.c @@ -108,6 +108,7 @@ static char *dumpdir; static int enable_local=0; static int local_stratum; +static int local_orphan; static double local_distance; /* Threshold (in seconds) - if absolute value of initial error is less @@ -818,7 +819,7 @@ parse_log(char *line) static void 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(); enable_local = 1; } @@ -1566,10 +1567,11 @@ CNF_GetCommandPort(void) { /* ================================================== */ int -CNF_AllowLocalReference(int *stratum, double *distance) +CNF_AllowLocalReference(int *stratum, int *orphan, double *distance) { if (enable_local) { *stratum = local_stratum; + *orphan = local_orphan; *distance = local_distance; return 1; } else { diff --git a/conf.h b/conf.h index 6ded8f5..7168fb3 100644 --- a/conf.h +++ b/conf.h @@ -92,7 +92,7 @@ extern double CNF_GetReselectDistance(void); extern double CNF_GetStratumWeight(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); diff --git a/reference.c b/reference.c index 2b51f01..c531356 100644 --- a/reference.c +++ b/reference.c @@ -45,6 +45,7 @@ static int are_we_synchronised; static int enable_local_stratum; static int local_stratum; +static int local_orphan; static double local_distance; static NTP_Leap our_leap_status; static int our_leap_sec; @@ -236,7 +237,7 @@ REF_Initialise(void) 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; 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 REF_GetSkew(void) { diff --git a/reference.h b/reference.h index 6ffc97d..abd205f 100644 --- a/reference.h +++ b/reference.h @@ -165,6 +165,9 @@ REF_SetUnsynchronised(void); synchronised */ 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 */ extern double REF_GetSkew(void);