]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
reference: add orphan mode to local reference
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 30 Mar 2016 15:39:14 +0000 (17:39 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 31 Mar 2016 14:08:49 +0000 (16:08 +0200)
Add orphan option to the local directive. It will enable an orphan mode
compatible with ntpd.

cmdparse.c
cmdparse.h
conf.c
conf.h
reference.c
reference.h

index 37d15813e8e5db03c2c22a3b4957173219b14e6b..1f1064a89eb0e912e6dfbaa21022d24e4dee0f76 100644 (file)
@@ -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;
index 69444753d30be3707cef3f64dad3272976000fbd..a61fdc23ff902489e2bec82138548193c88bdf85 100644 (file)
@@ -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 8c125fffd0be246b790add831ef6f36864a992cd..94f4ee1dba91aa95606d55a23a9bee084f44f37a 100644 (file)
--- 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 6ded8f52171b03410e4a7c760a7712cf542d747b..7168fb3da97e1cacc8edbb2a7f0a27e4221ec715 100644 (file)
--- 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);
 
index 2b51f0149c4e362834211e52cbee9561202cd394..c531356f35259987876120163cad788580cbed9b 100644 (file)
@@ -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)
 {
index 6ffc97d319cbdc0889c36740a8e1d0d1d488b603..abd205f45e3aabc4437969ef28d7cb856d9793dd 100644 (file)
@@ -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);