/* ================================================== */
static void
-set_bucket_params(int interval, int burst, uint16_t *max_tokens,
- uint16_t *tokens_per_packet, int *token_shift)
+set_bucket_params(int interval, int burst, uint16_t *mtokens, uint16_t *tphit, int *tshift)
{
interval = CLAMP(MIN_LIMIT_INTERVAL, interval, MAX_LIMIT_INTERVAL);
burst = CLAMP(MIN_LIMIT_BURST, burst, MAX_LIMIT_BURST);
if (interval >= -TS_FRAC) {
/* Find the smallest shift with which the maximum number fits in 16 bits */
- for (*token_shift = 0; *token_shift < interval + TS_FRAC; (*token_shift)++) {
- if (burst << (TS_FRAC + interval - *token_shift) < 1U << 16)
+ for (*tshift = 0; *tshift < interval + TS_FRAC; (*tshift)++) {
+ if (burst << (TS_FRAC + interval - *tshift) < 1U << 16)
break;
}
} else {
/* Coarse rate limiting */
- *token_shift = interval + TS_FRAC;
- *tokens_per_packet = 1;
- burst = MAX(1U << -*token_shift, burst);
+ *tshift = interval + TS_FRAC;
+ *tphit = 1;
+ burst = MAX(1U << -*tshift, burst);
}
- *tokens_per_packet = 1U << (TS_FRAC + interval - *token_shift);
- *max_tokens = *tokens_per_packet * burst;
+ *tphit = 1U << (TS_FRAC + interval - *tshift);
+ *mtokens = *tphit * burst;
- DEBUG_LOG("Tokens max %d packet %d shift %d",
- *max_tokens, *tokens_per_packet, *token_shift);
+ DEBUG_LOG("Tokens max %d packet %d shift %d", *mtokens, *tphit, *tshift);
}
/* ================================================== */
static void
parse_refclock(char *line)
{
- int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options;
+ int n, poll, dpoll, filter_length, pps_rate, min_samples_, max_samples_, sel_options;
int local, max_lock_age, max_unreach, pps_forced, sel_option, stratum, tai;
uint32_t ref_id, lock_ref_id;
double offset, delay, precision, max_dispersion, pulse_width;
local = 0;
pps_forced = 0;
pps_rate = 0;
- min_samples = SRC_DEFAULT_MINSAMPLES;
- max_samples = SRC_DEFAULT_MAXSAMPLES;
+ min_samples_ = SRC_DEFAULT_MINSAMPLES;
+ max_samples_ = SRC_DEFAULT_MAXSAMPLES;
max_unreach = SRC_DEFAULT_MAXUNREACH;
sel_options = 0;
offset = 0.0;
if (!SSCANF_IN_RANGE(line, "%d%n", &pps_rate, &n, 1, INT_MAX))
break;
} else if (!strcasecmp(cmd, "minsamples")) {
- if (!SSCANF_IN_RANGE(line, "%d%n", &min_samples, &n, 0, INT_MAX))
+ if (!SSCANF_IN_RANGE(line, "%d%n", &min_samples_, &n, 0, INT_MAX))
break;
} else if (!strcasecmp(cmd, "maxlockage")) {
if (!SSCANF_IN_RANGE(line, "%d%n", &max_lock_age, &n, 0, INT_MAX))
break;
} else if (!strcasecmp(cmd, "maxsamples")) {
- if (!SSCANF_IN_RANGE(line, "%d%n", &max_samples, &n, 0, INT_MAX))
+ if (!SSCANF_IN_RANGE(line, "%d%n", &max_samples_, &n, 0, INT_MAX))
break;
} else if (!strcasecmp(cmd, "maxunreach")) {
if (!SSCANF_IN_RANGE(line, "%d%n", &max_unreach, &n, 0, INT_MAX))
refclock->local = local;
refclock->pps_forced = pps_forced;
refclock->pps_rate = pps_rate;
- refclock->min_samples = min_samples;
- refclock->max_samples = max_samples;
+ refclock->min_samples = min_samples_;
+ refclock->max_samples = max_samples_;
refclock->max_unreach = max_unreach;
refclock->sel_options = sel_options;
refclock->stratum = stratum;
/* ================================================== */
void
-CNF_GetMailOnChange(int *enabled, double *threshold, char **user)
+CNF_GetMailOnChange(int *enabled, double *threshold, char **user_)
{
if (mail_user_on_change) {
*enabled = 1;
*threshold = mail_change_threshold;
- *user = mail_user_on_change;
+ *user_ = mail_user_on_change;
} else {
*enabled = 0;
*threshold = 0.0;
- *user = NULL;
+ *user_ = NULL;
}
}
/* ================================================== */
-static void read_write_socket(int sock_fd, int event, void *anything);
+static void read_write_socket(int fd, int event, void *anything);
/* ================================================== */
/* ================================================== */
static void
-read_write_socket(int sock_fd, int event, void *anything)
+read_write_socket(int fd, int event, void *anything)
{
SignInstance *inst;
uint32_t response_length;
if (!inst->sent)
SCH_GetLastEventTime(NULL, NULL, &inst->request_ts);
- s = SCK_Send(sock_fd, (char *)&inst->request + inst->sent,
+ s = SCK_Send(fd, (char *)&inst->request + inst->sent,
inst->request_length - inst->sent, 0);
if (s < 0) {
return;
/* Disable output and wait for a response */
- SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 0);
+ SCH_SetFileHandlerEvent(fd, SCH_FILE_OUTPUT, 0);
}
if (event == SCH_FILE_INPUT) {
}
assert(inst->received < sizeof (inst->response));
- s = SCK_Receive(sock_fd, (char *)&inst->response + inst->received,
+ s = SCK_Receive(fd, (char *)&inst->response + inst->received,
sizeof (inst->response) - inst->received, 0);
if (s <= 0) {
/* Move the head and enable output for the next packet */
queue_head = NEXT_QUEUE_INDEX(queue_head);
if (!IS_QUEUE_EMPTY())
- SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 1);
+ SCH_SetFileHandlerEvent(fd, SCH_FILE_OUTPUT, 1);
}
}
static void measurement_timeout(void *any);
-static void read_from_device(int fd_, int event, void *any);
+static void read_from_device(int fd, int event, void *any);
/* ================================================== */
/* ================================================== */
-static int fd;
+static int rtc_fd;
#define LOWEST_MEASUREMENT_PERIOD 15
#define HIGHEST_MEASUREMENT_PERIOD 480
RTC_Linux_Initialise(void)
{
/* Try to open the device */
- fd = open(CNF_GetRtcDevice(), O_RDWR);
- if (fd < 0) {
+ rtc_fd = open(CNF_GetRtcDevice(), O_RDWR);
+ if (rtc_fd < 0) {
LOG(LOGS_ERR, "Could not open RTC device %s : %s",
CNF_GetRtcDevice(), strerror(errno));
return 0;
}
/* Make sure the RTC supports interrupts */
- if (!RTC_Linux_SwitchInterrupt(fd, 1) || !RTC_Linux_SwitchInterrupt(fd, 0)) {
- close(fd);
+ if (!RTC_Linux_SwitchInterrupt(rtc_fd, 1) || !RTC_Linux_SwitchInterrupt(rtc_fd, 0)) {
+ close(rtc_fd);
return 0;
}
/* Close on exec */
- UTI_FdSetCloexec(fd);
+ UTI_FdSetCloexec(rtc_fd);
rtc_sec = MallocArray(time_t, MAX_SAMPLES);
system_times = MallocArray(struct timespec, MAX_SAMPLES);
operating_mode = OM_NORMAL;
/* Register file handler */
- SCH_AddFileHandler(fd, SCH_FILE_INPUT, read_from_device, NULL);
+ SCH_AddFileHandler(rtc_fd, SCH_FILE_INPUT, read_from_device, NULL);
/* Register slew handler */
LCL_AddParameterChangeHandler(slew_samples, NULL);
timeout_id = 0;
/* Remove input file handler */
- if (fd >= 0) {
- SCH_RemoveFileHandler(fd);
- RTC_Linux_SwitchInterrupt(fd, 0);
- close(fd);
+ if (rtc_fd >= 0) {
+ SCH_RemoveFileHandler(rtc_fd);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 0);
+ close(rtc_fd);
/* Save the RTC data */
(void) RTC_Linux_WriteParameters();
measurement_timeout(void *any)
{
timeout_id = 0;
- RTC_Linux_SwitchInterrupt(fd, 1);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 1);
}
/* ================================================== */
rtc_from_t(&new_rtc_time, &rtc_raw, rtc_on_utc);
- status = ioctl(fd, RTC_SET_TIME, &rtc_raw);
+ status = ioctl(rtc_fd, RTC_SET_TIME, &rtc_raw);
if (status < 0) {
LOG(LOGS_ERR, "Could not set RTC time");
}
}
static void
-read_from_device(int fd_, int event, void *any)
+read_from_device(int fd, int event, void *any)
{
struct timespec sys_time;
int status, error = 0;
time_t rtc_t;
- status = RTC_Linux_CheckInterrupt(fd);
+ status = RTC_Linux_CheckInterrupt(rtc_fd);
if (status < 0) {
- SCH_RemoveFileHandler(fd);
- RTC_Linux_SwitchInterrupt(fd, 0); /* Likely to raise error too, but just to be sure... */
- close(fd);
- fd = -1;
+ SCH_RemoveFileHandler(rtc_fd);
+ /* Likely to raise error too, but just to be sure... */
+ RTC_Linux_SwitchInterrupt(rtc_fd, 0);
+ close(rtc_fd);
+ rtc_fd = -1;
return;
} else if (status == 0) {
/* Wait for the next interrupt, this one may be bogus */
return;
}
- rtc_t = RTC_Linux_ReadTimeAfterInterrupt(fd, rtc_on_utc, &sys_time, NULL);
+ rtc_t = RTC_Linux_ReadTimeAfterInterrupt(rtc_fd, rtc_on_utc, &sys_time, NULL);
if (rtc_t == (time_t)-1) {
error = 1;
goto turn_off_interrupt;
operating_mode = OM_NORMAL;
(after_init_hook)(after_init_hook_arg);
- RTC_Linux_SwitchInterrupt(fd, 0);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 0);
timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
}
DEBUG_LOG("Could not complete after trim relock due to errors");
operating_mode = OM_NORMAL;
- RTC_Linux_SwitchInterrupt(fd, 0);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 0);
timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
}
break;
case OM_NORMAL:
- RTC_Linux_SwitchInterrupt(fd, 0);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 0);
timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
operating_mode = OM_INITIAL;
timeout_id = 0;
- RTC_Linux_SwitchInterrupt(fd, 1);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 1);
}
/* ================================================== */
{
int retval;
- if (fd < 0) {
+ if (rtc_fd < 0) {
return RTC_ST_NODRV;
}
/* And start rapid sampling, interrupts on now */
SCH_RemoveTimeout(timeout_id);
timeout_id = 0;
- RTC_Linux_SwitchInterrupt(fd, 1);
+ RTC_Linux_SwitchInterrupt(rtc_fd, 1);
}
return 1;
static int max_tick_bias;
/* The kernel USER_HZ constant */
-static int hz;
+static int sys_hz;
static double dhz; /* And dbl prec version of same for arithmetic */
/* The assumed rate at which the effective frequency and tick values are
USER_HZ <= 250, the maximum frequency adjustment of 500 ppm overlaps at
least two ticks and we can stick to the current tick if it's next to the
required tick. */
- if (hz <= 250 && (required_delta_tick + 1 == current_delta_tick ||
- required_delta_tick - 1 == current_delta_tick)) {
+ if (sys_hz <= 250 && (required_delta_tick + 1 == current_delta_tick ||
+ required_delta_tick - 1 == current_delta_tick)) {
required_delta_tick = current_delta_tick;
}
static void
get_version_specific_details(void)
{
- int major, minor, patch;
+ int hz, major, minor, patch;
hz = get_hz();
if (!hz)
hz = guess_hz();
+ sys_hz = hz;
dhz = (double) hz;
nominal_tick = (1000000L + (hz/2))/hz; /* Mirror declaration in kernel */
max_tick_bias = nominal_tick / 10;
}
static void
-read_points(const char *filename)
+read_points(const char *path)
{
FILE *f;
char line[256];
struct Point *p;
- f = UTI_OpenFile(NULL, filename, NULL, 'R', 0);
+ f = UTI_OpenFile(NULL, path, NULL, 'R', 0);
points = ARR_CreateInstance(sizeof (struct Point));
while (fgets(line, sizeof (line), f)) {
p = (struct Point *)ARR_GetNewElement(points);
if (sscanf(line, "%lf %lf", &p->temp, &p->comp) != 2) {
- LOG_FATAL("Could not read tempcomp point from %s", filename);
+ LOG_FATAL("Could not read tempcomp point from %s", path);
break;
}
}
fclose(f);
if (ARR_GetSize(points) < 2)
- LOG_FATAL("Not enough points in %s", filename);
+ LOG_FATAL("Not enough points in %s", path);
}
void
}
static void
-generate_key_file(const char *name, uint32_t *keys)
+generate_key_file(const char *name, uint32_t *key_ids)
{
FILE *f;
int i;
f = fopen(name, "w");
TEST_CHECK(f);
for (i = 0; i < KEYS; i++)
- keys[i] = write_random_key(f);
+ key_ids[i] = write_random_key(f);
fclose(f);
}
test_unit(void)
{
int i, j, data_len, auth_len, type, bits, s, timing_fails, timing_iters;
- uint32_t keys[KEYS], key;
+ uint32_t key_ids[KEYS], key;
unsigned char data[100], auth[MAX_HASH_LENGTH], auth2[MAX_HASH_LENGTH];
struct timespec ts1, ts2;
double diff1, diff2;
CNF_ParseLine(NULL, i + 1, conf[i]);
LCL_Initialise();
- generate_key_file(KEYFILE, keys);
+ generate_key_file(KEYFILE, key_ids);
KEY_Initialise();
for (i = 0; i < 100; i++) {
DEBUG_LOG("iteration %d", i);
if (i) {
- generate_key_file(KEYFILE, keys);
+ generate_key_file(KEYFILE, key_ids);
KEY_Reload();
}
UTI_GetRandomBytes(data, sizeof (data));
for (j = 0; j < KEYS; j++) {
- TEST_CHECK(KEY_KeyKnown(keys[j]));
- TEST_CHECK(KEY_GetAuthLength(keys[j]) >= 16);
+ TEST_CHECK(KEY_KeyKnown(key_ids[j]));
+ TEST_CHECK(KEY_GetAuthLength(key_ids[j]) >= 16);
data_len = random() % (sizeof (data) + 1);
- auth_len = KEY_GenerateAuth(keys[j], data, data_len, auth, sizeof (auth));
+ auth_len = KEY_GenerateAuth(key_ids[j], data, data_len, auth, sizeof (auth));
TEST_CHECK(auth_len >= 16);
- TEST_CHECK(KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
+ TEST_CHECK(KEY_CheckAuth(key_ids[j], data, data_len, auth, auth_len, auth_len));
- if (j > 0 && keys[j - 1] != keys[j])
- TEST_CHECK(!KEY_CheckAuth(keys[j - 1], data, data_len, auth, auth_len, auth_len));
+ if (j > 0 && key_ids[j - 1] != key_ids[j])
+ TEST_CHECK(!KEY_CheckAuth(key_ids[j - 1], data, data_len, auth, auth_len, auth_len));
auth_len = random() % auth_len + 1;
if (auth_len < MAX_HASH_LENGTH)
auth[auth_len]++;
- TEST_CHECK(KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
+ TEST_CHECK(KEY_CheckAuth(key_ids[j], data, data_len, auth, auth_len, auth_len));
auth[auth_len - 1]++;
- TEST_CHECK(!KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
+ TEST_CHECK(!KEY_CheckAuth(key_ids[j], data, data_len, auth, auth_len, auth_len));
- TEST_CHECK(KEY_GetKeyInfo(keys[j], &type, &bits));
+ TEST_CHECK(KEY_GetKeyInfo(key_ids[j], &type, &bits));
TEST_CHECK(type > 0 && bits > 0);
}
static int
handle_request(void *arg)
{
- NKSN_Instance server = arg;
+ NKSN_Instance inst = arg;
- verify_message(server);
+ verify_message(inst);
request_received = 1;
- send_message(server);
+ send_message(inst);
return 1;
}
static int
handle_response(void *arg)
{
- NKSN_Instance client = arg;
+ NKSN_Instance inst = arg;
response_received = 1;
- verify_message(client);
+ verify_message(inst);
return 1;
}