This adds a command to reset or activate the time smoothing process.
#define REQ_RESELECTDISTANCE 49
#define REQ_MODIFY_MAKESTEP 50
#define REQ_SMOOTHING 51
-#define N_REQUEST_TYPES 52
+#define REQ_SMOOTHTIME 52
+#define N_REQUEST_TYPES 53
/* Special utoken value used to log on with first exchange being the
password. (This time value has long since gone by) */
int32_t EOR;
} REQ_ReselectDistance;
+#define REQ_SMOOTHTIME_RESET 0
+#define REQ_SMOOTHTIME_ACTIVATE 1
+
+typedef struct {
+ int32_t option;
+ int32_t EOR;
+} REQ_SmoothTime;
+
/* ================================================== */
#define PKT_TYPE_CMD_REQUEST 1
Version 6 : added padding to requests to prevent amplification attack,
changed maximum number of samples in manual list to 16, new commands: modify
- makestep
+ makestep, smoothing report, smoothtime command
*/
#define PROTO_VERSION_NUMBER 6
REQ_ClientAccessesByIndex client_accesses_by_index;
REQ_ManualDelete manual_delete;
REQ_ReselectDistance reselect_distance;
+ REQ_SmoothTime smoothtime;
} data; /* Command specific parameters */
/* The following fields only set the maximum size of the packet.
PERMIT_AUTH, /* RESELECTDISTANCE */
PERMIT_AUTH, /* MODIFY_MAKESTEP */
PERMIT_OPEN, /* SMOOTHING */
+ PERMIT_AUTH, /* SMOOTHTIME */
};
/* ================================================== */
/* ================================================== */
+static void
+handle_smoothtime(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+ struct timeval now;
+ int option;
+
+ if (!SMT_IsEnabled()) {
+ tx_message->status = htons(STT_NOTENABLED);
+ return;
+ }
+
+ option = ntohl(rx_message->data.smoothtime.option);
+ SCH_GetLastEventTime(&now, NULL, NULL);
+
+ switch (option) {
+ case REQ_SMOOTHTIME_RESET:
+ SMT_Reset(&now);
+ break;
+ case REQ_SMOOTHTIME_ACTIVATE:
+ SMT_Activate(&now);
+ break;
+ default:
+ tx_message->status = htons(STT_INVALID);
+ break;
+ }
+}
+
+/* ================================================== */
+
static void
handle_sourcestats(CMD_Request *rx_message, CMD_Reply *tx_message)
{
handle_smoothing(&rx_message, &tx_message);
break;
+ case REQ_SMOOTHTIME:
+ handle_smoothtime(&rx_message, &tx_message);
+ break;
+
case REQ_SOURCESTATS:
handle_sourcestats(&rx_message, &tx_message);
break;
return offsetof(CMD_Request, data.modify_polltarget.EOR);
case REQ_SMOOTHING:
return offsetof(CMD_Request, data.null.EOR);
+ case REQ_SMOOTHTIME:
+ return offsetof(CMD_Request, data.smoothtime.EOR);
default:
/* If we fall through the switch, it most likely means we've forgotten to implement a new case */
assert(0);
return PADDING_LENGTH(data.modify_polltarget.EOR, data.null.EOR);
case REQ_SMOOTHING:
return PADDING_LENGTH(data.null.EOR, data.smoothing.EOR);
+ case REQ_SMOOTHTIME:
+ return PADDING_LENGTH(data.smoothtime.EOR, data.null.EOR);
default:
/* If we fall through the switch, it most likely means we've forgotten to implement a new case */
assert(0);
{
/* Don't accept offset/frequency until the clock has stabilized */
if (locked) {
- if (REF_GetSkew() / max_wander < UNLOCK_SKEW_WANDER_RATIO || leap_only_mode) {
- LOG(LOGS_INFO, LOGF_Smooth, "Time smoothing activated%s", leap_only_mode ?
- " (leap seconds only)" : "");
- locked = 0;
- last_update = *now;
- }
+ if (REF_GetSkew() / max_wander < UNLOCK_SKEW_WANDER_RATIO || leap_only_mode)
+ SMT_Activate(now);
return;
}
return offset;
}
+void
+SMT_Activate(struct timeval *now)
+{
+ if (!enabled || !locked)
+ return;
+
+ LOG(LOGS_INFO, LOGF_Smooth, "Time smoothing activated%s", leap_only_mode ?
+ " (leap seconds only)" : "");
+ locked = 0;
+ last_update = *now;
+}
+
void
SMT_Reset(struct timeval *now)
{
extern double SMT_GetOffset(struct timeval *now);
+extern void SMT_Activate(struct timeval *now);
+
extern void SMT_Reset(struct timeval *now);
extern void SMT_Leap(struct timeval *now, int leap);