d15db42
diff -up ntp-4.2.6p5/html/miscopt.html.backfwdstep ntp-4.2.6p5/html/miscopt.html
d15db42
--- ntp-4.2.6p5/html/miscopt.html.backfwdstep	2015-05-13 17:07:13.553206904 +0200
d15db42
+++ ntp-4.2.6p5/html/miscopt.html	2015-05-13 17:55:59.226133427 +0200
d15db42
@@ -70,7 +70,7 @@
d15db42
 			
Specify the directory in which to write configuration snapshots requested with <tt>ntpq</tt>'s saveconfig command. If <tt>saveconfigdir</tt> does not appear in the configuration file, saveconfig requests are rejected by ntpd.
d15db42
 			
<tt>setvar variable [default]</tt>
d15db42
 			
This command adds an additional system variable. These variables can be used to distribute additional information such as the access policy. If the variable of the form <tt>name = value</tt> is followed by the <tt>default</tt> keyword, the variable will be listed as part of the default system variables (<tt>ntpq rv</tt> command). These additional variables serve informational purposes only. They are not related to the protocol other that they can be listed. The known protocol variables will always override any variables defined via the <tt>setvar</tt> mechanism. There are three special variables that contain the names of all variable of the same group. The <tt>sys_var_list</tt> holds the names of all system variables. The <tt>peer_var_list</tt> holds the names of all peer variables and the <tt>clock_var_list</tt> holds the names of the reference clock variables.
d15db42
-			
<tt>tinker [ allan allan | dispersion dispersion | freq freq | huffpuff huffpuff | panic panic | step step | stepout stepout ]</tt>
d15db42
+			
<tt>tinker [ allan allan | dispersion dispersion | freq freq | huffpuff huffpuff | panic panic | step step | stepback step | stepfwd step | stepout stepout ]</tt>
d15db42
 			
This command alters certain system variables used by the clock discipline algorithm. The default values of these variables have been carefully optimized for a wide range of network speeds and reliability expectations. Very rarely is it necessary to change the default values; but, some folks can't resist twisting the knobs. The options are as follows:
d15db42
 				
d15db42
 					
<tt>allan allan</tt>
d15db42
@@ -89,6 +89,10 @@
d15db42
 						occur. Note: The kernel time discipline is disabled if
d15db42
 						the step threshold is set to zero or greater than 0.5
d15db42
 						s and the threshold is applied also to leap second corrections.
d15db42
+					
<tt>stepback step</tt>
d15db42
+					
Specifies the step threshold, but only in the backward direction.
d15db42
+					
<tt>stepfwd step</tt>
d15db42
+					
Specifies the step threshold, but only in the forward direction. To avoid problems with frequency stabilization after large slews it's not recommended to set one direction to a value greater than 0.5 s without setting also the other direction to at least 0.5 s.
d15db42
 					
<tt>stepout stepout</tt>
d15db42
 					
Specifies the stepout threshold in seconds. The default without this
d15db42
 						command is 900 s.  If set to zero, popcorn spikes will
d15db42
diff -up ntp-4.2.6p5/include/ntp.h.backfwdstep ntp-4.2.6p5/include/ntp.h
d15db42
--- ntp-4.2.6p5/include/ntp.h.backfwdstep	2011-12-01 03:55:17.000000000 +0100
d15db42
+++ ntp-4.2.6p5/include/ntp.h	2015-05-13 17:23:19.953372541 +0200
d15db42
@@ -725,6 +725,8 @@ struct pkt {
d15db42
 #define LOOP_KERN_CLEAR		11	/* reset kernel pll parameters */
d15db42
 #define LOOP_CODEC		12	/* set audio codec frequency */
d15db42
 #define	LOOP_LEAP		13	/* insert leap after second 23:59 */
d15db42
+#define LOOP_MAX_BACK		14	/* set bacward-step offset */
d15db42
+#define LOOP_MAX_FWD		15	/* set forward-step offset */
d15db42
 
d15db42
 /*
d15db42
  * Configuration items for the stats printer
d15db42
diff -up ntp-4.2.6p5/include/ntpd.h.backfwdstep ntp-4.2.6p5/include/ntpd.h
d15db42
--- ntp-4.2.6p5/include/ntpd.h.backfwdstep	2015-05-13 17:07:13.498212244 +0200
d15db42
+++ ntp-4.2.6p5/include/ntpd.h	2015-05-13 17:28:42.516052737 +0200
d15db42
@@ -345,7 +345,8 @@ extern int	maxactivefd;
d15db42
 /* ntp_loopfilter.c */
d15db42
 extern double	drift_comp;		/* clock frequency (s/s) */
d15db42
 extern double	clock_stability;	/* clock stability (s/s) */
d15db42
-extern double	clock_max;		/* max offset before step (s) */
d15db42
+extern double	clock_max_back;		/* max backward offset before step (s) */
d15db42
+extern double	clock_max_fwd;		/* max forward offset before step (s) */
d15db42
 extern double	clock_panic;		/* max offset before panic (s) */
d15db42
 extern double	clock_phi;		/* dispersion rate (s/s) */
d15db42
 extern double	clock_minstep;		/* step timeout (s) */
d15db42
diff -up ntp-4.2.6p5/ntpd/cmd_args.c.backfwdstep ntp-4.2.6p5/ntpd/cmd_args.c
d15db42
--- ntp-4.2.6p5/ntpd/cmd_args.c.backfwdstep	2009-12-25 10:03:41.000000000 +0100
d15db42
+++ ntp-4.2.6p5/ntpd/cmd_args.c	2015-05-13 17:25:05.726102347 +0200
d15db42
@@ -161,8 +161,7 @@ getCmdOpts(
d15db42
 	}
d15db42
 
d15db42
 	if (HAVE_OPT( SLEW )) {
d15db42
-		clock_max = 600;
d15db42
-		kern_enable = 0;
d15db42
+		loop_config(LOOP_MAX, 600);
d15db42
 	}
d15db42
 	if (HAVE_OPT( UPDATEINTERVAL )) {
d15db42
 		long val = OPT_VALUE_UPDATEINTERVAL;
d15db42
diff -up ntp-4.2.6p5/ntpd/keyword-gen.c.backfwdstep ntp-4.2.6p5/ntpd/keyword-gen.c
d15db42
--- ntp-4.2.6p5/ntpd/keyword-gen.c.backfwdstep	2010-04-18 10:05:39.000000000 +0200
d15db42
+++ ntp-4.2.6p5/ntpd/keyword-gen.c	2015-05-13 17:39:08.889233906 +0200
d15db42
@@ -173,6 +173,8 @@ struct key_tok ntp_keywords[] = {
d15db42
 { "stats",		T_Stats,		FOLLBY_TOKEN },
d15db42
 /* tinker_option */
d15db42
 { "step",		T_Step,			FOLLBY_TOKEN },
d15db42
+{ "stepback",		T_Stepback,		FOLLBY_TOKEN },
d15db42
+{ "stepfwd",		T_Stepfwd,		FOLLBY_TOKEN },
d15db42
 { "panic",		T_Panic,		FOLLBY_TOKEN },
d15db42
 { "dispersion",		T_Dispersion,		FOLLBY_TOKEN },
d15db42
 { "stepout",		T_Stepout,		FOLLBY_TOKEN },
d15db42
diff -up ntp-4.2.6p5/ntpd/ntp_config.c.backfwdstep ntp-4.2.6p5/ntpd/ntp_config.c
d15db42
--- ntp-4.2.6p5/ntpd/ntp_config.c.backfwdstep	2015-05-13 17:07:13.534208748 +0200
d15db42
+++ ntp-4.2.6p5/ntpd/ntp_config.c	2015-05-13 17:36:12.929319050 +0200
d15db42
@@ -2407,6 +2407,14 @@ config_tinker(
d15db42
 			item = LOOP_MAX;
d15db42
 			break;
d15db42
 
d15db42
+		case T_Stepback:
d15db42
+			item = LOOP_MAX_BACK;
d15db42
+			break;
d15db42
+
d15db42
+		case T_Stepfwd:
d15db42
+			item = LOOP_MAX_FWD;
d15db42
+			break;
d15db42
+
d15db42
 		case T_Stepout:
d15db42
 			item = LOOP_MINSTEP;
d15db42
 			break;
d15db42
diff -up ntp-4.2.6p5/ntpd/ntp_loopfilter.c.backfwdstep ntp-4.2.6p5/ntpd/ntp_loopfilter.c
d15db42
--- ntp-4.2.6p5/ntpd/ntp_loopfilter.c.backfwdstep	2015-05-13 17:07:13.499212146 +0200
d15db42
+++ ntp-4.2.6p5/ntpd/ntp_loopfilter.c	2015-05-13 17:20:42.362674093 +0200
d15db42
@@ -107,7 +107,8 @@
d15db42
 /*
d15db42
  * Program variables that can be tinkered.
d15db42
  */
d15db42
-double	clock_max = CLOCK_MAX;	/* step threshold */
d15db42
+double	clock_max_back = CLOCK_MAX;	/* step threshold */
d15db42
+double	clock_max_fwd =  CLOCK_MAX;	/* step threshold */
d15db42
 double	clock_minstep = CLOCK_MINSTEP; /* stepout threshold */
d15db42
 double	clock_panic = CLOCK_PANIC; /* panic threshold */
d15db42
 double	clock_phi = CLOCK_PHI;	/* dispersion rate (s/s) */
d15db42
@@ -257,7 +258,8 @@ local_clock(
d15db42
 	 * directly to the terminal.
d15db42
 	 */
d15db42
 	if (mode_ntpdate) {
d15db42
-		if (fabs(fp_offset) > clock_max && clock_max > 0) {
d15db42
+		if (  ( fp_offset > clock_max_fwd  && clock_max_fwd  > 0)
d15db42
+		   || (-fp_offset > clock_max_back && clock_max_back > 0)) {
d15db42
 			step_systime(fp_offset);
d15db42
 			msyslog(LOG_NOTICE, "ntpd: time set %+.6f s",
d15db42
 	   		    fp_offset);
d15db42
@@ -319,7 +321,8 @@ local_clock(
d15db42
 	mu = current_time - clock_epoch;
d15db42
 	clock_frequency = drift_comp;
d15db42
 	rval = 1;
d15db42
-	if (fabs(fp_offset) > clock_max && clock_max > 0) {
d15db42
+	if (  ( fp_offset > clock_max_fwd  && clock_max_fwd  > 0)
d15db42
+	   || (-fp_offset > clock_max_back && clock_max_back > 0)) {
d15db42
 		switch (state) {
d15db42
 
d15db42
 		/*
d15db42
@@ -1007,8 +1010,20 @@ loop_config(
d15db42
 		break;
d15db42
 
d15db42
 	case LOOP_MAX:		/* step threshold (step) */
d15db42
-		clock_max = freq;
d15db42
-		if (clock_max == 0 || clock_max > 0.5)
d15db42
+		clock_max_fwd = clock_max_back = freq;
d15db42
+		if (freq == 0 || freq > 0.5)
d15db42
+			kern_enable = 0;
d15db42
+		break;
d15db42
+
d15db42
+	case LOOP_MAX_BACK:	/* step threshold (step) */
d15db42
+		clock_max_back = freq;
d15db42
+		if (freq == 0 || freq > 0.5)
d15db42
+			kern_enable = 0;
d15db42
+		break;
d15db42
+
d15db42
+	case LOOP_MAX_FWD:	/* step threshold (step) */
d15db42
+		clock_max_fwd = freq;
d15db42
+		if (freq == 0 || freq > 0.5)
d15db42
 			kern_enable = 0;
d15db42
 		break;
d15db42
 
d15db42
diff -up ntp-4.2.6p5/ntpd/ntp_parser.y.backfwdstep ntp-4.2.6p5/ntpd/ntp_parser.y
d15db42
--- ntp-4.2.6p5/ntpd/ntp_parser.y.backfwdstep	2010-10-24 08:29:35.000000000 +0200
d15db42
+++ ntp-4.2.6p5/ntpd/ntp_parser.y	2015-05-13 17:40:45.207881673 +0200
d15db42
@@ -190,6 +190,8 @@
d15db42
 %token	<Integer>	T_Stats
d15db42
 %token	<Integer>	T_Statsdir
d15db42
 %token	<Integer>	T_Step
d15db42
+%token	<Integer>	T_Stepback
d15db42
+%token	<Integer>	T_Stepfwd
d15db42
 %token	<Integer>	T_Stepout
d15db42
 %token	<Integer>	T_Stratum
d15db42
 %token	<String>	T_String
d15db42
@@ -899,6 +901,8 @@ tinker_option_keyword
d15db42
 	|	T_Huffpuff
d15db42
 	|	T_Panic
d15db42
 	|	T_Step
d15db42
+	|	T_Stepback
d15db42
+	|	T_Stepfwd
d15db42
 	|	T_Stepout
d15db42
 	;
d15db42
 
d15db42
diff -up ntp-4.2.6p5/ntpd/ntp_timer.c.backfwdstep ntp-4.2.6p5/ntpd/ntp_timer.c
d15db42
--- ntp-4.2.6p5/ntpd/ntp_timer.c.backfwdstep	2015-05-13 17:07:13.554206806 +0200
d15db42
+++ ntp-4.2.6p5/ntpd/ntp_timer.c	2015-05-13 17:27:45.659573319 +0200
d15db42
@@ -450,7 +450,7 @@ timer(void)
d15db42
 			sys_tai = leap_tai;
d15db42
 #ifdef KERNEL_PLL
d15db42
 			if (!pll_control || !kern_enable) {
d15db42
-				if (clock_max < 1.0 && clock_max > 0.0) {
d15db42
+				if (clock_max_back < 1.0 && clock_max_back > 0.0) {
d15db42
 					step_systime(-1.0);
d15db42
 					msyslog(LOG_NOTICE, "Inserting positive leap second");
d15db42
 				} else {