int message_set_size; //!< default start number of messages
int ring_buffer_size; //!< default start size for the ring buffers
- int max_request_time; //!< maximum time a request can be processed
+ fr_time_delta_t max_request_time; //!< maximum time a request can be processed
size_t talloc_pool_size; //!< for each REQUEST
rad_assert(worker->num_active > 0);
cleanup = worker->max_request_time;
- cleanup *= NSEC;
cleanup += request->async->recv_time;
/*
worker->next_cleanup = cleanup;
- DEBUG2("Resetting worker %i cleanup timer to +%ds", worker->max_request_time, fr_schedule_worker_id());
+ DEBUG2("Resetting worker %pV cleanup timer to +%ds",
+ fr_box_time_delta(worker->max_request_time), fr_schedule_worker_id());
if (fr_event_timer_at(worker, worker->el, &worker->ev_cleanup,
cleanup, fr_worker_max_request_time, worker) < 0) {
ERROR("Failed inserting max_request_time timer.");
*/
static void fr_worker_check_timeouts(fr_worker_t *worker, fr_time_t now)
{
- fr_channel_data_t *cd;
- fr_time_t waiting;
+ fr_channel_data_t *cd;
+ fr_time_t waiting;
/*
* Check the "localized" queue for old packets.
while ((cd = fr_dlist_tail(&worker->localized.list)) != NULL) {
waiting = now - cd->m.when;
- if (waiting < ((worker->max_request_time - 2) * (fr_time_t) NSEC)) break;
+ if (waiting < (worker->max_request_time - fr_time_delta_from_sec(2))) break;
/*
* Waiting too long, delete it.
worker->talloc_pool_size = 4096; /* at least enough for a REQUEST */
worker->message_set_size = 1024;
worker->ring_buffer_size = (1 << 16);
- worker->max_request_time = 30;
+ worker->max_request_time = fr_time_delta_from_sec(30);
if (fr_event_pre_insert(worker->el, fr_worker_pre_event, worker) < 0) {
fr_strerror_printf("Failed adding pre-check to event list");
* issues with them, hence the need for this function.
*/
void fr_ldap_timeout_debug(REQUEST *request, fr_ldap_connection_t const *conn,
- struct timeval const *timeout, char const *prefix)
+ fr_time_delta_t timeout, char const *prefix)
{
struct timeval *net = NULL, *client = NULL;
int server = 0;
ROPTIONAL(RDEBUG4, DEBUG4, "%s: Timeout settings", prefix);
if (timeout) {
- ROPTIONAL(RDEBUG4, DEBUG4, "Client side result timeout (ovr): %ld.%06ld",
- (long)timeout->tv_sec, (long)timeout->tv_usec);
+ ROPTIONAL(RDEBUG4, DEBUG4, "Client side result timeout (ovr): %pVs",
+ fr_box_time_delta(timeout));
} else {
ROPTIONAL(RDEBUG4, DEBUG4, "Client side result timeout (ovr): unset");
}
#ifdef LDAP_OPT_TIMEOUT
if (client && (client->tv_sec != -1)) {
- ROPTIONAL(RDEBUG4, DEBUG4, "Client side result timeout (dfl): %ld.%06ld",
- (long)client->tv_sec, (long)client->tv_usec);
+ ROPTIONAL(RDEBUG4, DEBUG4, "Client side result timeout (dfl): %pVs",
+ fr_box_time_delta(fr_time_delta_from_timeval(client)));
} else {
ROPTIONAL(RDEBUG4, DEBUG4, "Client side result timeout (dfl): unset");
#ifdef LDAP_OPT_NETWORK_TIMEOUT
if (net && (net->tv_sec != -1)) {
- ROPTIONAL(RDEBUG4, DEBUG4, "Client side network I/O timeout : %ld.%06ld",
- (long)net->tv_sec, (long)net->tv_usec);
+ ROPTIONAL(RDEBUG4, DEBUG4, "Client side network I/O timeout : %pVs",
+ fr_box_time_delta(fr_time_delta_from_timeval(net)));
} else {
ROPTIONAL(RDEBUG4, DEBUG4, "Client side network I/O timeout : unset");
fr_ldap_rcode_t fr_ldap_result(LDAPMessage **result, LDAPControl ***ctrls,
fr_ldap_connection_t const *conn, int msgid, int all,
char const *dn,
- struct timeval const *timeout)
+ fr_time_delta_t timeout)
{
fr_ldap_rcode_t status = LDAP_PROC_SUCCESS;
int lib_errno;
if (!timeout) {
fr_timeval_from_nsec(&tv, conn->config->res_timeout);
} else {
- tv = *timeout;
+ tv = fr_time_delta_to_timeval(timeout);
}
/*
#else
NDEBUG_UNUSED fr_ldap_sasl_t const *sasl,
#endif
- struct timeval const *timeout,
+ fr_time_delta_t timeout,
LDAPControl **serverctrls, LDAPControl **clientctrls)
{
fr_ldap_rcode_t status = LDAP_PROC_ERROR;
/* We got a valid message ID */
if ((ret == 0) && (msgid >= 0)) ROPTIONAL(RDEBUG2, DEBUG2, "Waiting for bind result...");
- status = fr_ldap_result(NULL, NULL, *pconn, msgid, 0, dn, NULL);
+ status = fr_ldap_result(NULL, NULL, *pconn, msgid, 0, dn, 0);
}
switch (status) {
rad_assert(*pconn && (*pconn)->handle);
if (DEBUG_ENABLED4 || (request && RDEBUG_ENABLED4)) {
- fr_ldap_timeout_debug(request, *pconn, NULL, __FUNCTION__);
+ fr_ldap_timeout_debug(request, *pconn, 0, __FUNCTION__);
}
/*
if ((*pconn)->rebound) {
status = fr_ldap_bind(request, pconn,
(*pconn)->config->admin_identity, (*pconn)->config->admin_password,
- &(*pconn)->config->admin_sasl, NULL,
+ &(*pconn)->config->admin_sasl, 0,
NULL, NULL);
if (status != LDAP_PROC_SUCCESS) return LDAP_PROC_ERROR;
0, our_serverctrls, our_clientctrls, NULL, 0, &msgid);
ROPTIONAL(RDEBUG2, DEBUG2, "Waiting for search result...");
- status = fr_ldap_result(&our_result, NULL, *pconn, msgid, 1, dn, NULL);
+ status = fr_ldap_result(&our_result, NULL, *pconn, msgid, 1, dn, 0);
switch (status) {
case LDAP_PROC_SUCCESS:
break;
rad_assert(*pconn && (*pconn)->handle);
- if (DEBUG_ENABLED4 || (request && RDEBUG_ENABLED4)) fr_ldap_timeout_debug(request, *pconn, NULL, __FUNCTION__);
+ if (DEBUG_ENABLED4 || (request && RDEBUG_ENABLED4)) fr_ldap_timeout_debug(request, *pconn, 0, __FUNCTION__);
/*
* OpenLDAP library doesn't declare attrs array as const, but
if ((*pconn)->rebound) {
status = fr_ldap_bind(request, pconn,
(*pconn)->config->admin_identity, (*pconn)->config->admin_password,
- &(*pconn)->config->admin_sasl, NULL,
+ &(*pconn)->config->admin_sasl, 0,
NULL, NULL);
if (status != LDAP_PROC_SUCCESS) return LDAP_PROC_ERROR;
rad_assert(*pconn && (*pconn)->handle);
- if (RDEBUG_ENABLED4) fr_ldap_timeout_debug(request, *pconn, NULL, __FUNCTION__);
+ if (RDEBUG_ENABLED4) fr_ldap_timeout_debug(request, *pconn, 0, __FUNCTION__);
/*
* Perform all modifications as the admin user.
status = fr_ldap_bind(request, pconn,
(*pconn)->config->admin_identity, (*pconn)->config->admin_password,
&(*pconn)->config->admin_sasl,
- NULL, NULL, NULL);
+ 0, NULL, NULL);
if (status != LDAP_PROC_SUCCESS) {
return LDAP_PROC_ERROR;
}
(void) ldap_modify_ext((*pconn)->handle, dn, mods, our_serverctrls, our_clientctrls, &msgid);
RDEBUG2("Waiting for modify result...");
- status = fr_ldap_result(NULL, NULL, *pconn, msgid, 0, dn, NULL);
+ status = fr_ldap_result(NULL, NULL, *pconn, msgid, 0, dn, 0);
switch (status) {
case LDAP_PROC_SUCCESS:
break;
* ldap.c - Wrappers arounds OpenLDAP functions.
*/
void fr_ldap_timeout_debug(REQUEST *request, fr_ldap_connection_t const *conn,
- struct timeval const *timeout, char const *prefix);
+ fr_time_delta_t timeout, char const *prefix);
size_t fr_ldap_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, char const *in, UNUSED void *arg);
#else
NDEBUG_UNUSED fr_ldap_sasl_t const *sasl,
#endif
- struct timeval const *timeout,
+ fr_time_delta_t timeout,
LDAPControl **serverctrls, LDAPControl **clientctrls);
char const *fr_ldap_error_str(fr_ldap_connection_t const *conn);
fr_ldap_rcode_t fr_ldap_result(LDAPMessage **result, LDAPControl ***ctrls,
fr_ldap_connection_t const *conn, int msgid, int all,
char const *dn,
- struct timeval const *timeout);
+ fr_time_delta_t timeout);
int fr_ldap_global_config(int debug_level, char const *tls_random_file);
fr_ldap_connection_t *pconn, char const *dn,
char const *password, fr_ldap_sasl_t const *sasl,
LDAPControl **serverctrls, LDAPControl **clientctrls,
- struct timeval const *timeout);
+ fr_time_delta_t timeout);
#endif
/*
fr_ldap_connection_t *c = bind_ctx->c;
fr_ldap_rcode_t status;
- struct timeval tv = { 0, 0 }; /* We're I/O driven, if there's no data someone lied to us */
- status = fr_ldap_result(NULL, NULL, c, bind_ctx->msgid, LDAP_MSG_ALL, bind_ctx->bind_dn, &tv);
+ /*
+ * We're I/O driven, if there's no data someone lied to us
+ */
+ status = fr_ldap_result(NULL, NULL, c, bind_ctx->msgid, LDAP_MSG_ALL, bind_ctx->bind_dn, 0);
talloc_free(bind_ctx); /* Also removes fd events */
switch (status) {
}
status = fr_ldap_bind(NULL, &conn, admin_identity, admin_password,
- &conn->config->admin_sasl, NULL, NULL, NULL);
+ &conn->config->admin_sasl, 0, NULL, NULL);
if (status != LDAP_PROC_SUCCESS) {
ldap_get_option(handle, LDAP_OPT_ERROR_NUMBER, &ldap_errno);
fr_ldap_config_t const *config, char *log_prefix)
{
fr_ldap_connection_t *c;
- struct timeval connection_timeout, reconnection_delay;
-
- fr_timeval_from_nsec(&connection_timeout, config->net_timeout);
- fr_timeval_from_nsec(&reconnection_delay, config->reconnection_delay);
MEM(c = fr_ldap_connection_alloc(ctx));
c->config = config;
c->conn = fr_connection_alloc(c, el,
- &connection_timeout, &reconnection_delay,
+ config->net_timeout, config->reconnection_delay,
_ldap_connection_init,
NULL,
_ldap_connection_close,
fr_ldap_sasl_ctx_t *sasl_ctx = talloc_get_type_abort(uctx, fr_ldap_sasl_ctx_t);
fr_ldap_connection_t *c = sasl_ctx->c;
fr_ldap_rcode_t status;
- struct timeval tv = { 0, 0 }; /* We're I/O driven, if there's no data someone lied to us */
+
/*
* If LDAP parse result indicates there was an error
* then we're done.
*/
- status = fr_ldap_result(&sasl_ctx->result, NULL, c, sasl_ctx->msgid, LDAP_MSG_ALL, sasl_ctx->identity, &tv);
+ status = fr_ldap_result(&sasl_ctx->result, NULL, c, sasl_ctx->msgid, LDAP_MSG_ALL, sasl_ctx->identity, 0);
switch (status) {
case LDAP_PROC_SUCCESS:
case LDAP_PROC_CONTINUE:
fr_ldap_connection_t *conn, char const *identity,
char const *password, fr_ldap_sasl_t const *sasl,
LDAPControl **serverctrls, LDAPControl **clientctrls,
- struct timeval const *timeout)
+ fr_time_delta_t timeout)
{
fr_ldap_rcode_t status;
int ret = 0;
fr_ldap_connection_t *c = tls_ctx->c;
int ret;
fr_ldap_rcode_t status;
- struct timeval tv = { 0, 0 }; /* We're I/O driven, if there's no data someone lied to us */
- status = fr_ldap_result(NULL, NULL, c, tls_ctx->msgid, LDAP_MSG_ALL, NULL, &tv);
+ /*
+ * We're I/O driven, if there's no data someone lied to us
+ */
+ status = fr_ldap_result(NULL, NULL, c, tls_ctx->msgid, LDAP_MSG_ALL, NULL, 0);
talloc_free(tls_ctx); /* Free explicitly so we don't accumulate contexts */
switch (status) {
* - 2-11000 the pool is likely to be good, with a higher number
* indicating higher probability of liveness.
*/
-static int cluster_node_pool_health(struct timeval const *now, fr_pool_state_t const *state)
+static int cluster_node_pool_health(fr_time_t now, fr_pool_state_t const *state)
{
- struct timeval diff;
- uint64_t diff_ms;
-
/*
* Failed spawn recently, probably bad
*/
- if ((((time_t)now->tv_sec - state->last_failed) * 1000) < FAILED_PERIOD) return FAILED_WEIGHT;
+ if (fr_time_delta_to_msec(now - state->last_failed) < FAILED_PERIOD) return FAILED_WEIGHT;
/*
* Closed recently, probably bad
*/
- fr_timeval_subtract(&diff, now, &state->last_closed);
- diff_ms = FR_TIMEVAL_TO_MS(&diff);
- if (diff_ms < CLOSED_PERIOD) return CLOSED_WEIGHT;
+ if (fr_time_delta_to_msec(now - state->last_closed) < CLOSED_PERIOD) return CLOSED_WEIGHT;
/*
* Released too long ago, don't know
*/
- fr_timeval_subtract(&diff, now, &state->last_released);
- diff_ms = FR_TIMEVAL_TO_MS(&diff);
- if (diff_ms > RELEASED_PERIOD) return RELEASED_MIN_WEIGHT;
+ if (fr_time_delta_to_msec(now - state->last_released) > RELEASED_PERIOD) return RELEASED_MIN_WEIGHT;
/*
* Released not long ago, might be ok.
*/
- return RELEASED_MIN_WEIGHT + (RELEASED_PERIOD - diff_ms);
+ return RELEASED_MIN_WEIGHT + (RELEASED_PERIOD - fr_time_delta_to_msec(now - state->last_released));
}
/** Issue a ping request against a cluster node
uint32_t i;
cluster_nodes_live_t *live;
- struct timeval now;
+ fr_time_t now;
RDEBUG2("Searching for live cluster nodes");
rad_assert(live->next); /* There should be at least one */
if (live->next == 1) goto no_alts; /* Weird, but conceivable */
- fr_time_to_timeval(&now, fr_time());
+ now = fr_time();
/*
* Weighted random selection
*/
for (i = 0; (i < cluster->conf->max_alt) && live->next; i++) {
fr_redis_conn_t *conn;
- fr_redis_cluster_node_t *node;
+ fr_redis_cluster_node_t *node;
uint8_t j;
int first, last, pivot; /* Must be signed for BS */
unsigned int find, cumulative = 0;
for (j = 0; j < live->next; j++) {
int weight;
- weight = cluster_node_pool_health(&now, live->node[j].pool_state);
+ weight = cluster_node_pool_health(now, live->node[j].pool_state);
RDEBUG3("Node %i weight: %i", live->node[j].id, weight);
live->node[j].cumulative = (cumulative += weight);
}
* - New #fr_redis_conn_t on success.
* - NULL on failure.
*/
-void *fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
+void *fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
fr_redis_cluster_node_t *node = instance;
fr_redis_conn_t *conn = NULL;
DEBUG2("%s - [%i] Connecting to node %s:%i", log_prefix, node->id, node->name, node->addr.port);
- handle = redisConnectWithTimeout(node->name, node->addr.port, *timeout);
+ handle = redisConnectWithTimeout(node->name, node->addr.port, fr_time_delta_to_timeval(timeout));
if ((handle != NULL) && handle->err) {
ERROR("%s - [%i] Connection failed: %s", log_prefix, node->id, handle->errstr);
redisFree(handle);
/*
* Callback for the connection pool to create a new connection
*/
-void *fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
+void *fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_t timeout);
/*
* Functions to resolve a key to a cluster node
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound) FR_INTEGER_COND_CHECK(_name, _var, (_var _op _bound), _bound)
-#define FR_TIMEVAL_BOUND_CHECK(_name, _var, _op, _bound_sec, _bound_usec)\
+#define FR_TIME_DELTA_COND_CHECK(_name, _var, _cond, _new)\
do {\
- struct timeval _bound = {_bound_sec, _bound_usec};\
- if (!timercmp(_var, &_bound, _op)) {\
- WARN("Ignoring \"" _name " = %d.%.06d\", forcing to \"" _name " = %d.%06d\"",\
- (int)(_var)->tv_sec, (int)(_var)->tv_usec,\
- (int)_bound.tv_sec, (int)_bound.tv_usec);\
- *_var = _bound;\
+ if (!(_cond)) {\
+ WARN("Ignoring \"" _name " = %pV\", forcing to \"" _name " = %pV\"", \
+ fr_box_time_delta(_var), fr_box_time_delta(_new));\
+ _var = _new;\
}\
} while (0)
{ FR_CONF_OFFSET("nas_type", FR_TYPE_STRING, RADCLIENT, nas_type) },
{ FR_CONF_OFFSET("virtual_server", FR_TYPE_STRING, RADCLIENT, server) },
- { FR_CONF_OFFSET("response_window", FR_TYPE_TIMEVAL, RADCLIENT, response_window) },
+ { FR_CONF_OFFSET("response_window", FR_TYPE_TIME_DELTA, RADCLIENT, response_window) },
{ FR_CONF_OFFSET("track_connections", FR_TYPE_BOOL, RADCLIENT, use_connected) },
* A response_window of zero is OK, and means that it's
* ignored by the rest of the server timers.
*/
- if (fr_timeval_isset(&c->response_window)) {
- FR_TIMEVAL_BOUND_CHECK("response_window", &c->response_window, >=, 0, 1000);
- FR_TIMEVAL_BOUND_CHECK("response_window", &c->response_window, <=, 60, 0);
- FR_TIMEVAL_BOUND_CHECK("response_window", &c->response_window, <=,
- main_config->max_request_time, 0);
+ if (c->response_window) {
+ FR_TIME_DELTA_BOUND_CHECK("response_window", c->response_window, >=, fr_time_delta_from_usec(1000));
+ FR_TIME_DELTA_BOUND_CHECK("response_window", c->response_window, <=, fr_time_delta_from_sec(60));
+ FR_TIME_DELTA_BOUND_CHECK("response_window", c->response_window, <=, main_config->max_request_time);
}
#ifdef WITH_TLS
# endif
#endif
- struct timeval response_window; //!< How long the client has to respond.
+ fr_time_delta_t response_window; //!< How long the client has to respond.
int proto; //!< Protocol number.
fr_socket_limit_t limit; //!< Connections per client (TCP clients only).
fr_event_timer_t const *connection_timer; //!< Timer to prevent connections going on indefinitely.
fr_event_timer_t const *reconnection_timer; //!< Timer to delay retries.
- struct timeval connection_timeout; //!< How long to wait in the
+ fr_time_delta_t connection_timeout; //!< How long to wait in the
//!< #FR_CONNECTION_STATE_CONNECTING state.
- struct timeval reconnection_delay; //!< How long to wait in the
+ fr_time_delta_t reconnection_delay; //!< How long to wait in the
//!< #FR_CONNECTION_STATE_FAILED state.
char const *log_prefix; //!< Prefix to add to log messages.
case FR_CONNECTION_STATE_CONNECTING: /* Failed during connecting */
STATE_TRANSITION(FR_CONNECTION_STATE_FAILED);
fr_event_timer_at(conn, conn->el, &conn->reconnection_timer,
- now + fr_time_delta_from_timeval(&conn->reconnection_delay),
- _reconnect_delay_done, conn);
+ now + conn->reconnection_delay, _reconnect_delay_done, conn);
break;
case FR_CONNECTION_STATE_TIMEOUT: /* Failed during connecting */
{
fr_connection_t *conn = talloc_get_type_abort(uctx, fr_connection_t);
- ERROR("Connection failed - timed out after %pVs", fr_box_timeval(conn->connection_timeout));
+ ERROR("Connection failed - timed out after %pVs", fr_box_time_delta(conn->connection_timeout));
STATE_TRANSITION(FR_CONNECTION_STATE_TIMEOUT);
connection_state_failed(conn, now);
}
* If there's a connection timeout,
* set, then add the timer.
*/
- if (conn->connection_timeout.tv_sec || conn->connection_timeout.tv_usec) {
+ if (conn->connection_timeout) {
fr_event_timer_at(conn, conn->el, &conn->connection_timer,
- now + fr_time_delta_from_timeval(&conn->connection_timeout),
+ now + conn->connection_timeout,
_connection_timeout, conn);
}
break;
* - NULL on failure.
*/
fr_connection_t *fr_connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el,
- struct timeval const *connection_timeout,
- struct timeval const *reconnection_delay,
+ fr_time_delta_t connection_timeout,
+ fr_time_delta_t reconnection_delay,
fr_connection_init_t init, fr_connection_open_t open, fr_connection_close_t close,
char const *log_prefix,
void *uctx)
conn->state = FR_CONNECTION_STATE_HALTED;
conn->el = el;
conn->fd = -1;
- conn->reconnection_delay = *reconnection_delay;
- conn->connection_timeout = *connection_timeout;
+ conn->reconnection_delay = reconnection_delay;
+ conn->connection_timeout = connection_timeout;
conn->init = init;
conn->open = open;
conn->close = close;
typedef void (*fr_connection_close_t)(int fd, void *uctx);
fr_connection_t *fr_connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el,
- struct timeval const *connection_timeout,
- struct timeval const *reconnection_delay,
+ fr_time_delta_t connection_timeout,
+ fr_time_delta_t reconnection_delay,
fr_connection_init_t init, fr_connection_open_t open,
fr_connection_close_t close,
char const *log_prefix, void *uctx);
* - -1 on failure.
* - Length of output.
*/
-int radius_readfrom_program(int fd, pid_t pid, int timeout,
+int radius_readfrom_program(int fd, pid_t pid, fr_time_delta_t timeout,
char *answer, int left)
{
int done = 0;
#ifndef __MINGW32__
int status;
- struct timeval start;
+ fr_time_t start;
#ifdef O_NONBLOCK
bool nonblock = true;
#endif
} while (0);
#endif
+ /*
+ * Minimum timeout period is one section
+ */
+ if (timeout < NSEC) timeout = fr_time_delta_from_sec(1);
/*
* Read from the pipe until we doesn't get any more or
* until the message is full.
*/
- fr_time_to_timeval(&start, fr_time());
+ start = fr_time();
while (1) {
- int rcode;
- fd_set fds;
- struct timeval when, elapsed, wake;
+ int rcode;
+ fd_set fds;
+ fr_time_delta_t elapsed;
FD_ZERO(&fds);
FD_SET(fd, &fds);
- fr_time_to_timeval(&when, fr_time());
- fr_timeval_subtract(&elapsed, &when, &start);
- if (elapsed.tv_sec >= timeout) goto too_long;
-
- when.tv_sec = timeout;
- when.tv_usec = 0;
- fr_timeval_subtract(&wake, &when, &elapsed);
+ elapsed = fr_time() - start;
+ if (elapsed >= timeout) goto too_long;
- rcode = select(fd + 1, &fds, NULL, NULL, &wake);
+ rcode = select(fd + 1, &fds, NULL, NULL, &fr_time_delta_to_timeval(timeout - elapsed));
if (rcode == 0) {
too_long:
DEBUG("Child PID %u is taking too much time: forcing failure and killing child.", pid);
*/
int radius_exec_program(TALLOC_CTX *ctx, char *out, size_t outlen, VALUE_PAIR **output_pairs,
REQUEST *request, char const *cmd, VALUE_PAIR *input_pairs,
- bool exec_wait, bool shell_escape, int timeout)
+ bool exec_wait, bool shell_escape, fr_time_delta_t timeout)
{
pid_t pid;
#include <unistd.h>
-#define EXEC_TIMEOUT 10 //!< Default wait time for exec calls.
+#define EXEC_TIMEOUT 10 //!< Default wait time for exec calls (in seconds).
extern pid_t (*rad_fork)(void);
extern pid_t (*rad_waitpid)(pid_t pid, int *status);
int *input_fd, int *output_fd,
VALUE_PAIR *input_pairs, bool shell_escape);
-int radius_readfrom_program(int fd, pid_t pid, int timeout,
+int radius_readfrom_program(int fd, pid_t pid, fr_time_delta_t timeout,
char *answer, int left);
int radius_exec_program(TALLOC_CTX *ctx, char *out, size_t outlen, VALUE_PAIR **output_pairs,
REQUEST *request, char const *cmd, VALUE_PAIR *input_pairs,
- bool exec_wait, bool shell_escape, int timeout) CC_HINT(nonnull (5, 6));
+ bool exec_wait, bool shell_escape, fr_time_delta_t timeout) CC_HINT(nonnull (5, 6));
#ifdef __cplusplus
}
{ FR_CONF_OFFSET("panic_action", FR_TYPE_STRING, main_config_t, panic_action) },
{ FR_CONF_OFFSET("reverse_lookups", FR_TYPE_BOOL, main_config_t, reverse_lookups), .dflt = "no", .func = reverse_lookups_parse },
{ FR_CONF_OFFSET("hostname_lookups", FR_TYPE_BOOL, main_config_t, hostname_lookups), .dflt = "yes", .func = hostname_lookups_parse },
- { FR_CONF_OFFSET("max_request_time", FR_TYPE_UINT32, main_config_t, max_request_time), .dflt = STRINGIFY(MAX_REQUEST_TIME), .func = max_request_time_parse },
+ { FR_CONF_OFFSET("max_request_time", FR_TYPE_TIME_DELTA, main_config_t, max_request_time), .dflt = STRINGIFY(MAX_REQUEST_TIME), .func = max_request_time_parse },
{ FR_CONF_OFFSET("pidfile", FR_TYPE_STRING, main_config_t, pid_file), .dflt = "${run_dir}/radiusd.pid"},
{ FR_CONF_OFFSET("debug_level", FR_TYPE_UINT32, main_config_t, debug_level), .dflt = "0" },
bool spawn_workers; //!< Should the server spawn threads.
char const *pid_file; //!< Path to write out PID file.
- uint32_t max_request_time; //!< How long a request can be processed for before
+ fr_time_delta_t max_request_time; //!< How long a request can be processed for before
//!< timing out.
uint32_t num_networks; //!< number of network threads
result = radius_exec_program(ctx, answer, sizeof(answer),
(map->lhs->type == TMPL_TYPE_LIST) ? &output_pairs : NULL,
request, map->rhs->name, input_pairs ? *input_pairs : NULL,
- true, true, EXEC_TIMEOUT);
+ true, true, fr_time_delta_from_sec(EXEC_TIMEOUT));
talloc_free(expanded);
if (result != 0) {
REDEBUG("Exec failed with code (%i)", result);
int32_t heap_id; //!< For the next connection heap.
time_t created; //!< Time connection was created.
- struct timeval last_reserved; //!< Last time the connection was reserved.
+ fr_time_t last_reserved; //!< Last time the connection was reserved.
- struct timeval last_released; //!< Time the connection was released.
+ fr_time_t last_released; //!< Time the connection was released.
uint32_t num_uses; //!< Number of times the connection has been reserved.
uint64_t number; //!< Unique ID assigned when the connection is created,
uint32_t pending_window; //!< Sliding window of pending connections.
uint32_t lifetime; //!< How long a connection can be open before being
//!< closed (irrespective of whether it's idle or not).
- uint32_t idle_timeout; //!< How long a connection can be idle before
+ fr_time_delta_t idle_timeout; //!< How long a connection can be idle before
//!< being closed.
- struct timeval connect_timeout; //!< New connection timeout, enforced by the create
+ fr_time_delta_t connect_timeout; //!< New connection timeout, enforced by the create
//!< callback.
bool spread; //!< If true we spread requests over the connections,
//!< fired by the connection pool code.
VALUE_PAIR *trigger_args; //!< Arguments to make available in connection pool triggers.
- struct timeval held_trigger_min; //!< If a connection is held for less than the specified
+ fr_time_delta_t held_trigger_min; //!< If a connection is held for less than the specified
//!< period, fire a trigger.
- struct timeval held_trigger_max; //!< If a connection is held for longer than the specified
+ fr_time_delta_t held_trigger_max; //!< If a connection is held for longer than the specified
//!< period, fire a trigger.
fr_pool_connection_create_t create; //!< Function used to create new connections.
{ FR_CONF_OFFSET("cleanup_delay", FR_TYPE_UINT32, fr_pool_t, cleanup_interval) },
{ FR_CONF_OFFSET("cleanup_interval", FR_TYPE_UINT32, fr_pool_t, cleanup_interval), .dflt = "30" },
{ FR_CONF_OFFSET("idle_timeout", FR_TYPE_UINT32, fr_pool_t, idle_timeout), .dflt = "60" },
- { FR_CONF_OFFSET("connect_timeout", FR_TYPE_TIMEVAL, fr_pool_t, connect_timeout), .dflt = "3.0" },
- { FR_CONF_OFFSET("held_trigger_min", FR_TYPE_TIMEVAL, fr_pool_t, held_trigger_min), .dflt = "0.0" },
- { FR_CONF_OFFSET("held_trigger_max", FR_TYPE_TIMEVAL, fr_pool_t, held_trigger_max), .dflt = "0.5" },
+ { FR_CONF_OFFSET("connect_timeout", FR_TYPE_TIME_DELTA, fr_pool_t, connect_timeout), .dflt = "3.0" },
+ { FR_CONF_OFFSET("held_trigger_min", FR_TYPE_TIME_DELTA, fr_pool_t, held_trigger_min), .dflt = "0.0" },
+ { FR_CONF_OFFSET("held_trigger_max", FR_TYPE_TIME_DELTA, fr_pool_t, held_trigger_max), .dflt = "0.5" },
{ FR_CONF_OFFSET("retry_delay", FR_TYPE_UINT32, fr_pool_t, retry_delay), .dflt = "1" },
{ FR_CONF_OFFSET("spread", FR_TYPE_BOOL, fr_pool_t, spread), .dflt = "no" },
CONF_PARSER_TERMINATOR
static int last_reserved_cmp(void const *one, void const *two)
{
fr_pool_connection_t const *a = one, *b = two;
- int ret;
- ret = (a->last_reserved.tv_sec < b->last_reserved.tv_sec) - (a->last_reserved.tv_sec > b->last_reserved.tv_sec);
- if (ret != 0) return ret;
-
- return (a->last_reserved.tv_usec < b->last_reserved.tv_usec) -
- (a->last_reserved.tv_usec > b->last_reserved.tv_usec);
+ return fr_time_cmp(a->last_reserved, b->last_reserved);
}
/** Order connections by released longest ago
static int last_released_cmp(void const *one, void const *two)
{
fr_pool_connection_t const *a = one, *b = two;
- int ret;
-
- ret = (b->last_released.tv_sec < a->last_released.tv_sec) -
- (b->last_released.tv_sec > a->last_released.tv_sec);
- if (ret != 0) return ret;
- return (b->last_released.tv_usec < a->last_released.tv_usec) -
- (b->last_released.tv_usec > a->last_released.tv_usec);
+ return fr_time_cmp(a->last_released, b->last_released);
}
/** Removes a connection from the connection list
* - New connection struct.
* - NULL on error.
*/
-static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, time_t now, bool in_use, bool unlock)
+static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, fr_time_t now, bool in_use, bool unlock)
{
uint64_t number;
uint32_t pending_window;
if (pool->state.last_failed && ((pool->state.last_failed + pool->retry_delay) > now)) {
bool complain = false;
- if (pool->state.last_throttled != now) {
+ if ((now - pool->state.last_throttled) >= NSEC) {
complain = true;
pool->state.last_throttled = now;
pthread_mutex_unlock(&pool->mutex);
if (!RATE_LIMIT_ENABLED || complain) {
- ROPTIONAL(RERROR, ERROR, "Last connection attempt failed, waiting %d seconds before retrying",
- (int)((pool->state.last_failed + pool->retry_delay) - now));
+ ROPTIONAL(RERROR, ERROR, "Last connection attempt failed, waiting %pV seconds before retrying",
+ fr_box_time_delta(pool->state.last_failed + pool->retry_delay) - now);
}
return NULL;
* about other threads opening new connections, as we
* already have no free connections.
*/
- conn = pool->create(ctx, pool->opaque, &pool->connect_timeout);
+ conn = pool->create(ctx, pool->opaque, pool->connect_timeout);
if (!conn) {
ROPTIONAL(RERROR, ERROR, "Opening connection failed (%" PRIu64 ")", number);
this->in_use = in_use;
this->number = number;
- fr_time_to_timeval(&this->last_reserved, fr_time());
+ this->last_reserved = fr_time();
this->last_released = this->last_reserved;
/*
pool->pending_window++;
}
- pool->state.last_spawned = time(NULL);
+ pool->state.last_spawned = fr_time();
pool->delay_interval = pool->cleanup_interval;
pool->state.next_delay = pool->cleanup_interval;
pool->state.last_failed = 0;
}
if ((pool->idle_timeout > 0) &&
- ((this->last_released.tv_sec + pool->idle_timeout) < now)) {
- ROPTIONAL(RINFO, INFO, "Closing connection (%" PRIu64 "): Hit idle_timeout, was idle for %u seconds",
- this->number, (int) (now - this->last_released.tv_sec));
+ ((this->last_released + pool->idle_timeout) < now)) {
+ ROPTIONAL(RINFO, INFO, "Closing connection (%" PRIu64 "): Hit idle_timeout, was idle for %pVs",
+ this->number, fr_box_time_delta(now - this->last_released));
goto do_delete;
}
*/
static int connection_check(fr_pool_t *pool, REQUEST *request)
{
- uint32_t spawn, idle, extra;
- time_t now = time(NULL);
- fr_pool_connection_t *this, *next;
+ uint32_t spawn, idle, extra;
+ fr_time_t now = fr_time();
+ fr_pool_connection_t *this, *next;
- if (pool->state.last_checked == now) {
+ if ((now - pool->state.last_checked) >= NSEC) {
pthread_mutex_unlock(&pool->mutex);
return 1;
}
for (this = pool->tail; this != NULL; this = this->prev) {
if (this->in_use) continue;
- if (!found || (fr_timeval_cmp(&this->last_reserved, &found->last_reserved) < 0)) {
- found = this;
- }
+ if (!found || (this->last_reserved < found->last_reserved)) found = this;
}
if (!fr_cond_assert(found)) goto done;
*/
static void *connection_get_internal(fr_pool_t *pool, REQUEST *request, bool spawn)
{
- time_t now;
+ fr_time_t now;
fr_pool_connection_t *this;
if (!pool) return NULL;
pthread_mutex_lock(&pool->mutex);
- now = time(NULL);
+ now = fr_time();
/*
* Grab the link with the lowest latency, and check it
/*
* Rate-limit complaints.
*/
- if (pool->state.last_at_max != now) {
+ if ((now - pool->state.last_at_max) > NSEC) {
complain = true;
pool->state.last_at_max = now;
}
do_return:
pool->state.active++;
this->num_uses++;
- fr_time_to_timeval(&this->last_reserved, fr_time());
+ this->last_reserved = fr_time();
this->in_use = true;
#ifdef PTHREAD_DEBUG
FR_INTEGER_BOUND_CHECK("spare", pool->spare, <=, (pool->max - pool->min));
if (pool->lifetime > 0) {
- FR_INTEGER_COND_CHECK("idle_timeout", pool->idle_timeout, (pool->idle_timeout <= pool->lifetime), 0);
+ FR_TIME_DELTA_COND_CHECK("idle_timeout", pool->idle_timeout,
+ (pool->idle_timeout <= pool->lifetime), 0);
}
if (pool->idle_timeout > 0) {
- FR_INTEGER_BOUND_CHECK("cleanup_interval", pool->cleanup_interval, <=, pool->idle_timeout);
+ FR_TIME_DELTA_BOUND_CHECK("cleanup_interval", pool->cleanup_interval, <=, pool->idle_timeout);
}
/*
* as instantaneous timeout. Solve the inconsistency by making
* the smallest allowable timeout 100ms.
*/
- FR_TIMEVAL_BOUND_CHECK("connect_timeout", &pool->connect_timeout, >=, 0, 100000);
+ FR_TIME_DELTA_BOUND_CHECK("connect_timeout", pool->connect_timeout, >=, fr_time_delta_from_msec(100));
/*
* Don't open any connections. Instead, force the limits
* @param[in] pool to get connection timeout for.
* @return the connection timeout configured for the pool.
*/
-struct timeval fr_pool_timeout(fr_pool_t *pool)
+fr_time_delta_t fr_pool_timeout(fr_pool_t *pool)
{
return pool->connect_timeout;
}
*/
void fr_pool_connection_release(fr_pool_t *pool, REQUEST *request, void *conn)
{
- fr_pool_connection_t *this;
- struct timeval held;
- bool trigger_min = false, trigger_max = false;
+ fr_pool_connection_t *this;
+ fr_time_delta_t held;
+ bool trigger_min = false, trigger_max = false;
this = connection_find(pool, conn);
if (!this) return;
/*
* Record when the connection was last released
*/
- fr_time_to_timeval(&this->last_reserved, fr_time());
+ this->last_reserved = fr_time();
pool->state.last_released = this->last_released;
/*
* This is done inside the mutex to ensure
* updates are atomic.
*/
- fr_timeval_subtract(&held, &this->last_released, &this->last_reserved);
+ held = this->last_released - this->last_reserved;
/*
* Check we've not exceeded out trigger limits
+ *
+ * These should only fire once per second.
*/
- if ((pool->held_trigger_min.tv_sec || pool->held_trigger_min.tv_usec) &&
- (fr_timeval_cmp(&held, &pool->held_trigger_min) < 0) &&
- (pool->state.last_held_min != this->last_released.tv_sec)) {
+ if (pool->held_trigger_min &&
+ (held < pool->held_trigger_min) &&
+ ((this->last_released - pool->state.last_held_min) >= NSEC)) {
trigger_min = true;
- pool->state.last_held_min = this->last_released.tv_sec;
+ pool->state.last_held_min = this->last_released;
}
- if ((pool->held_trigger_max.tv_sec || pool->held_trigger_min.tv_usec) &&
- (fr_timeval_cmp(&held, &pool->held_trigger_max) > 0) &&
- (pool->state.last_held_max != this->last_released.tv_sec)) {
+ if (pool->held_trigger_min &&
+ (held > pool->held_trigger_max) &&
+ ((this->last_released - pool->state.last_held_max) >= NSEC)) {
trigger_max = true;
- pool->state.last_held_max = this->last_released.tv_sec;
+ pool->state.last_held_max = this->last_released;
}
- fr_stats_bins(&pool->state.held_stats,
- fr_time_from_timeval(&this->last_reserved), fr_time_from_timeval(&this->last_released));
+ fr_stats_bins(&pool->state.held_stats, this->last_reserved, this->last_released);
/*
* Insert the connection in the heap.
/*
* Record the last time a connection was closed
*/
- fr_time_to_timeval(&pool->state.last_closed, fr_time());
+ pool->state.last_closed = fr_time();
ROPTIONAL(RINFO, INFO, "Deleting connection (%" PRIu64 ")", this->number);
struct fr_pool_state_s {
uint32_t pending; //!< Number of pending open connections.
- time_t last_checked; //!< Last time we pruned the connection pool.
- time_t last_spawned; //!< Last time we spawned a connection.
- time_t last_failed; //!< Last time we tried to spawn a connection but failed.
- time_t last_throttled; //!< Last time we refused to spawn a connection because
+ fr_time_t last_checked; //!< Last time we pruned the connection pool.
+ fr_time_t last_spawned; //!< Last time we spawned a connection.
+ fr_time_t last_failed; //!< Last time we tried to spawn a connection but failed.
+ fr_time_t last_throttled; //!< Last time we refused to spawn a connection because
//!< the last connection failed, or we were already spawning
//!< a connection.
- time_t last_at_max; //!< Last time we hit the maximum number of allowed
+ fr_time_t last_at_max; //!< Last time we hit the maximum number of allowed
//!< connections.
- struct timeval last_released; //!< Last time a connection was released.
- struct timeval last_closed; //!< Last time a connection was closed.
+ fr_time_t last_released; //!< Last time a connection was released.
+ fr_time_t last_closed; //!< Last time a connection was closed.
#ifdef WITH_STATS
fr_stats_t held_stats; //!< How long connections were held for.
#endif
- time_t last_held_min; //!< Last time we warned about a low latency event.
- time_t last_held_max; //!< Last time we warned about a high latency event.
+ fr_time_t last_held_min; //!< Last time we warned about a low latency event.
+ fr_time_t last_held_max; //!< Last time we warned about a high latency event.
uint32_t next_delay; //!< The next delay time. cleanup. Initialized to
//!< cleanup_interval, and decays from there.
* - NULL on error.
* - A connection handle on success.
*/
-typedef void *(*fr_pool_connection_create_t)(TALLOC_CTX *ctx, void *opaque, struct timeval const *timeout);
+typedef void *(*fr_pool_connection_create_t)(TALLOC_CTX *ctx, void *opaque, fr_time_delta_t timeout);
/** Check a connection handle is still viable
*
void fr_pool_enable_triggers(fr_pool_t *pool,
char const *trigger_prefix, VALUE_PAIR *vp);
-struct timeval fr_pool_timeout(fr_pool_t *pool);
+fr_time_delta_t fr_pool_timeout(fr_pool_t *pool);
int fr_pool_start_num(fr_pool_t *pool);
fr_event_timer_t const *ev;
struct timeval when;
- struct timeval response_window;
+ fr_time_delta_t response_window;
uint32_t response_timeouts;
uint32_t max_response_timeouts;
uint32_t max_outstanding; //!< Maximum outstanding requests.
}
if (radius_exec_program(request, (char *)buff, bufflen, NULL, request, vpt->name, NULL,
- true, false, EXEC_TIMEOUT) != 0) return -1;
+ true, false, fr_time_delta_from_sec(EXEC_TIMEOUT)) != 0) return -1;
value_to_cast.vb_strvalue = (char *)buff;
value_to_cast.datum.length = strlen((char *)buff);
}
MEM(value.vb_strvalue = talloc_array(tmp_ctx, char, 1024));
if (radius_exec_program(request, (char *)value.datum.ptr, 1024, NULL, request, vpt->name, NULL,
- true, false, EXEC_TIMEOUT) != 0) {
+ true, false, fr_time_delta_from_sec(EXEC_TIMEOUT)) != 0) {
error:
talloc_free(tmp_ctx);
return slen;
uint16_t *: FR_TYPE_UINT16, \
uint32_t *: FR_TYPE_UINT32, \
uint64_t *: FR_TYPE_UINT64, \
- struct timeval *: FR_TYPE_TIMEVAL, \
fr_value_box_t **: FR_TYPE_VALUE_BOX, \
fr_value_box_t const **: FR_TYPE_VALUE_BOX)
#define tmpl_aexpand(_ctx, _out, _request, _vpt, _escape, _escape_ctx) \
_tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, _escape, _escape_ctx, FR_TYPE_FROM_PTR(_out))
+/** Expand a tmpl to a C type, allocing a new buffer to hold the string
+ *
+ * Takes an explicit type which must match the ctype pointed to by out.
+ *
+ * @see _tmpl_to_atype
+ */
+#define tmpl_aexpand_type(_ctx, _out, _type, _request, _vpt, _escape, _escape_ctx) \
+ _tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, _escape, _escape_ctx, _type)
VALUE_PAIR **radius_list(REQUEST *request, pair_list_t list);
* Don't fire triggers if we're just testing
*/
if (!check_config) ret = radius_exec_program(request, NULL, 0, NULL,
- request, value, vp, false, true, EXEC_TIMEOUT);
+ request, value, vp, false, true,
+ fr_time_delta_from_sec(EXEC_TIMEOUT));
(void) request_data_get(request, &trigger_exec_main, REQUEST_INDEX_TRIGGER_NAME);
(void) request_data_get(request, &trigger_exec_main, REQUEST_INDEX_TRIGGER_ARGS);
RDEBUG2("Verifying client certificate with cmd");
if (radius_exec_program(request, NULL, 0, NULL, request, conf->verify_client_cert_cmd,
- request->packet->vps, true, true, EXEC_TIMEOUT) != 0) {
+ request->packet->vps, true, true, fr_time_delta_from_sec(EXEC_TIMEOUT)) != 0) {
REDEBUG("Client certificate CN \"%s\" failed external verification", common_name);
my_ok = 0;
} else {
} else {
RDEBUG2("`%s`", mx->xlat_name);
radius_exec_program(request, NULL, 0, NULL, request, mx->xlat_name, request->packet->vps,
- false, true, EXEC_TIMEOUT);
+ false, true, fr_time_delta_from_sec(EXEC_TIMEOUT));
return UNLANG_ACTION_EXECUTE_NEXT;
}
}
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/udpfromto.h>
+#include <freeradius-devel/util/value.h>
#include <fcntl.h>
#include <netdb.h>
* - -2 on timeout.
* - -3 on select error.
*/
-int fr_socket_wait_for_connect(int sockfd, struct timeval const *timeout)
+int fr_socket_wait_for_connect(int sockfd, fr_time_delta_t timeout)
{
int ret;
- struct timeval tv = *timeout;
fd_set error_set;
fd_set write_set; /* POSIX says sockets are open when they become writable */
/* Don't let signals mess up the select */
do {
- ret = select(sockfd + 1, NULL, &write_set, &error_set, &tv);
+ ret = select(sockfd + 1, NULL, &write_set, &error_set, &fr_time_delta_to_timeval(timeout));
} while ((ret == -1) && (errno == EINTR));
switch (ret) {
case 0: /* timeout */
if (!fr_cond_assert(timeout)) return -1;
- fr_strerror_printf("Connection timed out after %" PRIu64"ms",
- (timeout->tv_sec * (uint64_t)1000) + (timeout->tv_usec / 1000));
+ fr_strerror_printf("Connection timed out after %pVs", fr_box_time_delta(timeout));
return -2;
case -1: /* select error */
#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/inet.h>
+#include <freeradius-devel/util/time.h>
#include <stdbool.h>
#include <stdint.h>
uint16_t dst_port, bool async);
int fr_socket_client_tcp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_ipaddr,
uint16_t dst_port, bool async);
-int fr_socket_wait_for_connect(int sockfd, struct timeval const *timeout);
+int fr_socket_wait_for_connect(int sockfd, fr_time_delta_t timeout);
int fr_socket_server_udp(fr_ipaddr_t const *ipaddr, uint16_t *port, char const *port_name, bool async);
int fr_socket_server_tcp(fr_ipaddr_t const *ipaddr, uint16_t *port, char const *port_name, bool async);
fr_ipaddr_t src_ipaddr; //!< Our src interface.
uint16_t src_port; //!< Our src port.
- fr_ldap_connection_t *conn; //!< Our connection to the LDAP directory.
+ fr_ldap_connection_t *conn; //!< Our connection to the LDAP directory.
RADCLIENT *client; //!< Fake client representing the connection.
/*
* Per instance config
*/
- struct timeval sync_retry_interval; //!< How long to wait before trying to re-start
+ fr_time_delta_t sync_retry_interval; //!< How long to wait before trying to re-start
//!< a sync.
- struct timeval conn_retry_interval; //!< How long to wait before trying to re-establish
+ fr_time_delta_t conn_retry_interval; //!< How long to wait before trying to re-establish
//!< a connection.
/*
{ FR_CONF_OFFSET("password", FR_TYPE_STRING | FR_TYPE_SECRET, proto_ldap_inst_t, handle_config.admin_password) },
{ FR_CONF_OFFSET("sasl", FR_TYPE_SUBSECTION, proto_ldap_inst_t, handle_config.admin_sasl), .subcs = (void const *) sasl_mech_static },
- { FR_CONF_OFFSET("sync_retry_interval", FR_TYPE_TIMEVAL, proto_ldap_inst_t, sync_retry_interval), .dflt = "5" },
- { FR_CONF_OFFSET("conn_retry_interval", FR_TYPE_TIMEVAL, proto_ldap_inst_t, conn_retry_interval), .dflt = "5" },
+ { FR_CONF_OFFSET("sync_retry_interval", FR_TYPE_TIME_DELTA, proto_ldap_inst_t, sync_retry_interval), .dflt = "5" },
+ { FR_CONF_OFFSET("conn_retry_interval", FR_TYPE_TIME_DELTA, proto_ldap_inst_t, conn_retry_interval), .dflt = "5" },
/*
* Areas of the DIT to listen on
*/
if (sync_state_init(inst->conn, config, NULL, true) == 0) return;
- PERROR("Failed reinitialising sync, will retry in %pT seconds", &inst->sync_retry_interval);
+ PERROR("Failed reinitialising sync, will retry in %pV seconds", fr_box_time_delta(inst->sync_retry_interval));
/*
* We want the time from when we were called
*/
if (fr_event_timer_at(inst, el, &inst->sync_retry_ev,
- now + fr_time_delta_from_timeval(&inst->sync_retry_interval),
+ now + inst->sync_retry_interval,
proto_ldap_sync_reinit, user_ctx) < 0) {
FATAL("Failed inserting event: %s", fr_strerror());
}
return 1;
case -1:
- PERROR("Sync failed - will retry in %pT seconds", &inst->sync_retry_interval);
+ PERROR("Sync failed - will retry in %pV seconds", fr_box_time_delta(inst->sync_retry_interval));
config = sync_state_config_get(inst->conn, sync_id);
sync_state_destroy(inst->conn, sync_id); /* Destroy the old state */
*/
memcpy(&ctx, &config, sizeof(ctx));
if (fr_event_timer_in(inst, inst->el, &inst->sync_retry_ev,
- fr_time_delta_from_timeval(&inst->sync_retry_interval),
+ inst->sync_retry_interval,
proto_ldap_sync_reinit, ctx) < 0) {
FATAL("Failed inserting event: %s", fr_strerror());
}
return 1;
case -2:
- PERROR("Connection failed - will retry in %pT seconds", &inst->conn_retry_interval);
+ PERROR("Connection failed - will retry in %pV seconds", fr_box_time_delta(inst->conn_retry_interval));
/*
* Schedule conn reinit, but don't perform it immediately
*/
memcpy(&ctx, &config, sizeof(ctx));
if (fr_event_timer_in(inst, inst->el, &inst->conn_retry_ev,
- fr_time_delta_from_timeval(&inst->conn_retry_interval),
+ inst->conn_retry_interval,
proto_ldap_connection_init, listen) < 0) {
FATAL("Failed inserting event: %s", fr_strerror());
}
error:
TALLOC_FREE(inst->conn);
- PERROR("Failed (re)initialising connection, will retry in %pT seconds",
- &inst->conn_retry_interval);
+ PERROR("Failed (re)initialising connection, will retry in %pV seconds",
+ fr_box_time_delta(inst->conn_retry_interval));
if (fr_event_timer_in(inst, inst->el, &inst->conn_retry_ev,
- fr_time_delta_from_timeval(&inst->conn_retry_interval),
+ inst->conn_retry_interval,
proto_ldap_connection_init, listen) < 0) {
FATAL("Failed inserting event: %s", fr_strerror());
}
&inst->conn,
inst->conn->config->admin_identity, inst->conn->config->admin_password,
&(inst->conn->config->admin_sasl),
- NULL,
+ 0,
NULL, NULL);
if (status != LDAP_PROC_SUCCESS) goto error;
/** Create a new memcached handle
*
*/
-static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
+static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
rlm_cache_memcached_t *driver = instance;
rlm_cache_memcached_handle_t *mandle;
return NULL;
}
- ret = memcached_behavior_set(sandle, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, (uint64_t)FR_TIMEVAL_TO_MS(timeout));
+ ret = memcached_behavior_set(sandle, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, fr_time_delta_to_msec(timeout));
if (ret != MEMCACHED_SUCCESS) {
ERROR("%s: %s", memcached_strerror(sandle, ret), memcached_last_error_message(sandle));
error:
* - New connection handle.
* - NULL on error.
*/
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
rlm_couchbase_t const *inst = instance; /* module instance pointer */
rlm_couchbase_handle_t *chandle = NULL; /* connection handle pointer */
/* create instance */
cb_error = couchbase_init_connection(&cb_inst, inst->server, inst->bucket, inst->username,
- inst->password, FR_TIMEVAL_TO_MS(timeout) * 1000, opts);
+ inst->password, fr_time_delta_to_sec(timeout), opts);
/* check couchbase instance */
if (cb_error != LCB_SUCCESS) {
} rlm_couchbase_handle_t;
/* define functions */
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout);
int mod_conn_alive(UNUSED void *instance, void *handle);
static rlm_rcode_t CC_HINT(nonnull) mod_delay(void *instance, UNUSED void *thread, REQUEST *request)
{
rlm_delay_t const *inst = instance;
- struct timeval delay;
+ fr_time_delta_t delay;
fr_time_t resume_at, *yielded_at;
- struct timeval resume_at_tv, yielded_at_tv;
if (inst->delay) {
- if (tmpl_aexpand(request, &delay, request, inst->delay, NULL, NULL) < 0) return RLM_MODULE_FAIL;
+ if (tmpl_aexpand_type(request, &delay, FR_TYPE_TIME_DELTA,
+ request, inst->delay, NULL, NULL) < 0) return RLM_MODULE_FAIL;
} else {
- memset(&delay, 0, sizeof(delay));
+ delay = 0;
}
/*
/*
* Setup the delay for this request
*/
- if (delay_add(request, &resume_at, *yielded_at, fr_time_delta_from_timeval(&delay),
+ if (delay_add(request, &resume_at, *yielded_at, delay,
inst->force_reschedule, inst->delay) != 0) {
return RLM_MODULE_NOOP;
}
- fr_time_to_timeval(&resume_at_tv, resume_at);
- fr_time_to_timeval(&yielded_at_tv, *yielded_at);
-
- RDEBUG3("Current time %pV, resume time %pV",
- fr_box_timeval(yielded_at_tv), fr_box_timeval(resume_at_tv));
+ /*
+ * FIXME - Should print wallclock time
+ */
+ RDEBUG3("Current time %pVs, resume time %pVs",
+ fr_box_time_delta(*yielded_at), fr_box_time_delta(resume_at));
if (unlang_module_timeout_add(request, _delay_done, yielded_at, resume_at) < 0) {
RPEDEBUG("Adding event failed");
}
static xlat_action_t xlat_delay_resume(TALLOC_CTX *ctx, fr_cursor_t *out,
- REQUEST *request,
+ REQUEST *request,
UNUSED void const *xlat_inst, UNUSED void *xlat_thread_inst,
UNUSED fr_value_box_t **in, void *rctx)
{
fr_time_t *yielded_at = talloc_get_type_abort(rctx, fr_time_t);
fr_time_t delayed;
- struct timeval delayed_tv;
fr_value_box_t *vb;
delayed = fr_time() - *yielded_at;
talloc_free(yielded_at);
- delayed_tv = fr_time_delta_to_timeval(delayed);
-
- RDEBUG3("Request delayed by %pVs", fr_box_time_delta(delayed));
+ MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL, false));
+ vb->vb_time_delta = delayed;
- MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIMEVAL, NULL, false));
- vb->vb_timeval = delayed_tv;
+ RDEBUG3("Request delayed by %pVs", vb);
fr_cursor_insert(out, vb);
void *instance;
struct timeval delay_tv;
fr_time_t resume_at, *yielded_at;
- struct timeval resume_at_tv, yielded_at_tv;
memcpy(&instance, xlat_inst, sizeof(instance)); /* Stupid const issues */
}
yield:
- fr_time_to_timeval(&resume_at_tv, resume_at);
- fr_time_to_timeval(&yielded_at_tv, *yielded_at);
-
- RDEBUG3("Current time %pV, resume time %pV", fr_box_timeval(yielded_at_tv), fr_box_timeval(resume_at_tv));
+ /*
+ * FIXME - Should print wallclock time
+ */
+ RDEBUG3("Current time %pVs, resume time %pVs", fr_box_time_delta(*yielded_at), fr_box_time_delta(resume_at));
if (unlang_xlat_event_timeout_add(request, _xlat_delay_done, yielded_at, resume_at) < 0) {
RPEDEBUG("Adding event failed");
pair_list_t input_list;
pair_list_t output_list;
bool shell_escape;
- uint32_t timeout;
+ fr_time_delta_t timeout;
} rlm_exec_t;
static const CONF_PARSER module_config[] = {
{ FR_CONF_OFFSET("input_pairs", FR_TYPE_STRING, rlm_exec_t, input) },
{ FR_CONF_OFFSET("output_pairs", FR_TYPE_STRING, rlm_exec_t, output) },
{ FR_CONF_OFFSET("shell_escape", FR_TYPE_BOOL, rlm_exec_t, shell_escape), .dflt = "yes" },
- { FR_CONF_OFFSET("timeout", FR_TYPE_UINT32, rlm_exec_t, timeout) },
+ { FR_CONF_OFFSET("timeout", FR_TYPE_TIME_DELTA, rlm_exec_t, timeout) },
CONF_PARSER_TERMINATOR
};
* Get the time to wait before killing the child
*/
if (!inst->timeout) {
- inst->timeout = EXEC_TIMEOUT;
+ inst->timeout = fr_time_delta_from_sec(EXEC_TIMEOUT);
}
- if (inst->timeout < 1) {
- cf_log_err(conf, "Timeout '%d' is too small (minimum: 1)", inst->timeout);
+ if (inst->timeout < fr_time_delta_from_sec(1)) {
+ cf_log_err(conf, "Timeout '%pVs' is too small (minimum: 1s)", fr_box_time_delta(inst->timeout));
return -1;
}
* Blocking a request longer than max_request_time isn't going to help anyone.
*/
if (inst->timeout > main_config->max_request_time) {
- cf_log_err(conf, "Timeout '%d' is too large (maximum: %d)",
- inst->timeout, main_config->max_request_time);
+ cf_log_err(conf, "Timeout '%pVs' is too large (maximum: %pVs)",
+ fr_box_time_delta(inst->timeout), fr_box_time_delta(main_config->max_request_time));
return -1;
}
*
* Create a new ldap connection and allocate memory for a new rlm_handle_t
*/
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
fr_ldap_rcode_t status;
fr_ldap_connection_t *conn;
fr_ldap_config_t const *handle_config = instance; /* Not talloced */
- fr_time_delta_t delta;
conn = fr_ldap_connection_alloc(ctx);
if (!conn) return NULL;
return NULL;
}
- delta = fr_time_delta_from_timeval(timeout);
-
- fr_ldap_connection_timeout_set(conn, delta);
+ fr_ldap_connection_timeout_set(conn, timeout);
if (handle_config->start_tls) {
if (ldap_start_tls_s(conn->handle, NULL, NULL) != LDAP_SUCCESS) {
int ldap_errno;
&conn,
dn, request->password->vp_strvalue,
inst->user_sasl.mech ? &sasl : NULL,
- NULL,
+ 0,
NULL, NULL);
switch (status) {
case LDAP_PROC_SUCCESS:
* Bind as the user
*/
conn->rebound = true;
- status = fr_ldap_bind(request, &conn, dn, vp->vp_strvalue, NULL, NULL, NULL, NULL);
+ status = fr_ldap_bind(request, &conn, dn, vp->vp_strvalue, NULL, 0, NULL, NULL);
switch (status) {
case LDAP_PROC_SUCCESS:
rcode = RLM_MODULE_OK;
void mod_conn_release(rlm_ldap_t const *inst, REQUEST *request, fr_ldap_connection_t *conn);
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout);
if ((*pconn)->rebound) {
status = fr_ldap_bind(request, pconn, (*pconn)->config->admin_identity,
(*pconn)->config->admin_password, &(*pconn)->config->admin_sasl,
- NULL, NULL, NULL);
+ 0, NULL, NULL);
if (status != LDAP_PROC_SUCCESS) {
*rcode = RLM_MODULE_FAIL;
return NULL;
return 0;
}
-static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
+static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
linelog_instance_t const *inst = instance;
linelog_conn_t *conn;
}
if (errno == EINPROGRESS) {
- if (FR_TIMEVAL_TO_MS(timeout)) {
+ if (timeout) {
DEBUG2("Waiting for connection to complete...");
} else {
DEBUG2("Blocking until connection complete...");
/*
* Set blocking operation as we have no timeout set
*/
- if (!FR_TIMEVAL_TO_MS(timeout) && (fr_blocking(sockfd) < 0)) {
+ if (!timeout && (fr_blocking(sockfd) < 0)) {
ERROR("Failed setting nonblock flag on fd");
close(sockfd);
return NULL;
{
rlm_logtee_t *inst = talloc_get_type_abort(instance, rlm_logtee_t);
rlm_logtee_thread_t *t = talloc_get_type_abort(thread, rlm_logtee_thread_t);
- struct timeval connection_timeout, reconnection_delay;
MEM(t->fring = fr_fring_alloc(t, inst->buffer_depth, false));
MEM(t->type = fr_pair_afrom_da(t, attr_log_type));
MEM(t->lvl = fr_pair_afrom_da(t, attr_log_level));
- fr_timeval_from_nsec(&connection_timeout, inst->connection_timeout);
- fr_timeval_from_nsec(&reconnection_delay, inst->reconnection_delay);
-
/*
* This opens the outbound connection
*/
- t->conn = fr_connection_alloc(t, el, &connection_timeout, &reconnection_delay,
+ t->conn = fr_connection_alloc(t, el, inst->connection_timeout, inst->reconnection_delay,
_logtee_conn_init, _logtee_conn_open, _logtee_conn_close,
inst->name, t);
if (t->conn == NULL) return -1;
{ FR_CONF_OFFSET("require_strong", FR_TYPE_BOOL, rlm_mschap_t, require_strong), .dflt = "no" },
{ FR_CONF_OFFSET("with_ntdomain_hack", FR_TYPE_BOOL, rlm_mschap_t, with_ntdomain_hack), .dflt = "yes" },
{ FR_CONF_OFFSET("ntlm_auth", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_mschap_t, ntlm_auth) },
- { FR_CONF_OFFSET("ntlm_auth_timeout", FR_TYPE_UINT32, rlm_mschap_t, ntlm_auth_timeout) },
+ { FR_CONF_OFFSET("ntlm_auth_timeout", FR_TYPE_TIME_DELTA, rlm_mschap_t, ntlm_auth_timeout) },
{ FR_CONF_POINTER("passchange", FR_TYPE_SUBSECTION, NULL), .subcs = (void const *) passchange_config },
{ FR_CONF_OFFSET("allow_retry", FR_TYPE_BOOL, rlm_mschap_t, allow_retry), .dflt = "yes" },
/*
* Create connection pool winbind context
*/
-static void *mod_conn_create(TALLOC_CTX *ctx, UNUSED void *instance, UNUSED struct timeval const *timeout)
+static void *mod_conn_create(TALLOC_CTX *ctx, UNUSED void *instance, UNUSED fr_time_delta_t timeout)
{
struct wbcContext **wb_ctx;
/*
* Read from the child
*/
- len = radius_readfrom_program(from_child, pid, 10, buf, sizeof(buf));
+ len = radius_readfrom_program(from_child, pid, fr_time_delta_from_sec(10), buf, sizeof(buf));
if (len < 0) {
/* radius_readfrom_program will have closed from_child for us */
REDEBUG("Failure reading from child");
* Check ntlm_auth_timeout is sane
*/
if (!inst->ntlm_auth_timeout) {
- inst->ntlm_auth_timeout = EXEC_TIMEOUT;
+ inst->ntlm_auth_timeout = fr_time_delta_from_sec(EXEC_TIMEOUT);
}
- if (inst->ntlm_auth_timeout < 1) {
- cf_log_err(conf, "ntml_auth_timeout '%d' is too small (minimum: 1)",
- inst->ntlm_auth_timeout);
+ if (inst->ntlm_auth_timeout < fr_time_delta_from_sec(1)) {
+ cf_log_err(conf, "ntml_auth_timeout '%pVs' is too small (minimum: 1s)",
+ fr_box_time_delta(inst->ntlm_auth_timeout));
return -1;
}
- if (inst->ntlm_auth_timeout > 10) {
- cf_log_err(conf, "ntlm_auth_timeout '%d' is too large (maximum: 10)",
- inst->ntlm_auth_timeout);
+ if (inst->ntlm_auth_timeout > fr_time_delta_from_sec(10)) {
+ cf_log_err(conf, "ntlm_auth_timeout '%pVs' is too large (maximum: 10s)",
+ fr_box_time_delta(inst->ntlm_auth_timeout));
return -1;
}
{
fr_io_connection_t *c;
rlm_radius_udp_connection_t *radius;
- struct timeval connection_timeout, reconnection_delay;
c = talloc_zero(t, fr_io_connection_t);
c->module_name = inst->parent->name;
}
fr_dlist_init(&c->sent, fr_io_request_t, entry);
- fr_timeval_from_nsec(&connection_timeout, t->connection_timeout);
- fr_timeval_from_nsec(&reconnection_delay, t->reconnection_delay);
-
- c->conn = fr_connection_alloc(c, t->el, &connection_timeout, &reconnection_delay,
+ c->conn = fr_connection_alloc(c, t->el, t->connection_timeout, t->reconnection_delay,
_conn_init,
_conn_open,
_conn_close,
uint32_t wait_num; //!< How many slaves we want to acknowledge allocations
//!< or updates.
- struct timeval wait_timeout; //!< How long we wait for slaves to acknowledge writing.
+ fr_time_delta_t wait_timeout; //!< How long we wait for slaves to acknowledge writing.
vp_tmpl_t *device_id; //!< Unique device identifier. Could be mac-address
//!< or a combination of User-Name and something
{ FR_CONF_OFFSET("lease_time", FR_TYPE_TMPL | FR_TYPE_REQUIRED, rlm_redis_ippool_t, lease_time) },
{ FR_CONF_OFFSET("wait_num", FR_TYPE_UINT32, rlm_redis_ippool_t, wait_num) },
- { FR_CONF_OFFSET("wait_timeout", FR_TYPE_TIMEVAL, rlm_redis_ippool_t, wait_timeout) },
+ { FR_CONF_OFFSET("wait_timeout", FR_TYPE_TIME_DELTA, rlm_redis_ippool_t, wait_timeout) },
{ FR_CONF_OFFSET("requested_address", FR_TYPE_TMPL | FR_TYPE_REQUIRED, rlm_redis_ippool_t, requested_address), .dflt = "%{%{DHCP-Requested-IP-Address}:-%{DHCP-Client-IP-Address}}", .quote = T_DOUBLE_QUOTED_STRING },
{ FR_CONF_DEPRECATED("ip_address", FR_TYPE_TMPL | FR_TYPE_REQUIRED, rlm_redis_ippool_t, NULL) },
*/
static fr_redis_rcode_t ippool_script(redisReply **out, REQUEST *request, fr_redis_cluster_t *cluster,
uint8_t const *key, size_t key_len,
- uint32_t wait_num, uint32_t wait_timeout,
+ uint32_t wait_num, fr_time_delta_t wait_timeout,
char const digest[], char const *script,
char const *cmd, ...)
{
va_end(copy);
pipelined = 1;
if (wait_num) {
- redisAppendCommand(conn->handle, "WAIT %i %i", wait_num, wait_timeout);
+ redisAppendCommand(conn->handle, "WAIT %i %i", wait_num, fr_time_delta_to_msec(wait_timeout));
pipelined++;
}
reply_cnt = fr_redis_pipeline_result(&pipelined, &status,
status = ippool_script(&reply, request, inst->cluster,
key_prefix, key_prefix_len,
- inst->wait_num, FR_TIMEVAL_TO_MS(&inst->wait_timeout),
+ inst->wait_num, inst->wait_timeout,
lua_alloc_digest, lua_alloc_cmd,
"EVALSHA %s 1 %b %u %u %b %b",
lua_alloc_digest,
if ((ip->af == AF_INET) && inst->ipv4_integer) {
status = ippool_script(&reply, request, inst->cluster,
key_prefix, key_prefix_len,
- inst->wait_num, FR_TIMEVAL_TO_MS(&inst->wait_timeout),
+ inst->wait_num, inst->wait_timeout,
lua_update_digest, lua_update_cmd,
"EVALSHA %s 1 %b %u %u %u %b %b",
lua_update_digest,
IPPOOL_SPRINT_IP(ip_buff, ip, ip->prefix);
status = ippool_script(&reply, request, inst->cluster,
key_prefix, key_prefix_len,
- inst->wait_num, FR_TIMEVAL_TO_MS(&inst->wait_timeout),
+ inst->wait_num, inst->wait_timeout,
lua_update_digest, lua_update_cmd,
"EVALSHA %s 1 %b %u %u %s %b %b",
lua_update_digest,
if ((ip->af == AF_INET) && inst->ipv4_integer) {
status = ippool_script(&reply, request, inst->cluster,
key_prefix, key_prefix_len,
- inst->wait_num, FR_TIMEVAL_TO_MS(&inst->wait_timeout),
+ inst->wait_num, inst->wait_timeout,
lua_release_digest, lua_release_cmd,
"EVALSHA %s 1 %b %u %u %b",
lua_release_digest,
IPPOOL_SPRINT_IP(ip_buff, ip, ip->prefix);
status = ippool_script(&reply, request, inst->cluster,
key_prefix, key_prefix_len,
- inst->wait_num, FR_TIMEVAL_TO_MS(&inst->wait_timeout),
+ inst->wait_num, inst->wait_timeout,
lua_release_digest, lua_release_cmd,
"EVALSHA %s 1 %b %u %s %b",
lua_release_digest,
* @see fr_pool_connection_create_t
* @see connection.c
*/
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED struct timeval const *timeout)
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED fr_time_delta_t timeout)
{
rlm_rest_t const *inst = instance;
rlm_rest_handle_t *randle = handle;
rlm_rest_curl_context_t *ctx = randle->ctx;
CURL *candle = randle->candle;
- struct timeval timeout;
+ fr_time_delta_t timeout;
http_auth_type_t auth = section->auth;
}
timeout = fr_pool_timeout(t->pool);
- RDEBUG3("Connect timeout is %" PRIu64", request timeout is %" PRIu64,
- FR_TIMEVAL_TO_MS(&timeout), FR_TIMEVAL_TO_MS(§ion->timeout_tv));
- SET_OPTION(CURLOPT_CONNECTTIMEOUT_MS, FR_TIMEVAL_TO_MS(&timeout));
- SET_OPTION(CURLOPT_TIMEOUT_MS, FR_TIMEVAL_TO_MS(§ion->timeout_tv));
+ RDEBUG3("Connect timeout is %pVs, request timeout is %pVs",
+ fr_box_time_delta(timeout), fr_box_time_delta(section->timeout));
+ SET_OPTION(CURLOPT_CONNECTTIMEOUT_MS, fr_time_delta_to_msec(timeout));
+ SET_OPTION(CURLOPT_TIMEOUT_MS, fr_time_delta_to_msec(section->timeout));
#ifdef CURLOPT_PROTOCOLS
SET_OPTION(CURLOPT_PROTOCOLS, (CURLPROTO_HTTP | CURLPROTO_HTTPS));
bool tls_check_cert_cn;
bool tls_extract_cert_attrs;
- struct timeval timeout_tv; //!< Timeout timeval.
+ fr_time_delta_t timeout; //!< Timeout timeval.
uint32_t chunk; //!< Max chunk-size (mainly for testing the encoders)
size_t max_body_in; //!< Maximum size of incoming data.
} rlm_rest_section_t;
void *userdata);
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout);
/*
* Request processing API
{ FR_CONF_OFFSET("require_auth", FR_TYPE_BOOL, rlm_rest_section_t, require_auth), .dflt = "no" },
/* Transfer configuration */
- { FR_CONF_OFFSET("timeout", FR_TYPE_TIMEVAL, rlm_rest_section_t, timeout_tv), .dflt = "4.0" },
+ { FR_CONF_OFFSET("timeout", FR_TYPE_TIME_DELTA, rlm_rest_section_t, timeout), .dflt = "4.0" },
{ FR_CONF_OFFSET("chunk", FR_TYPE_UINT32, rlm_rest_section_t, chunk), .dflt = "0" },
{ FR_CONF_OFFSET("max_body_in", FR_TYPE_SIZE, rlm_rest_section_t, max_body_in), .dflt = "16k" },
{ FR_CONF_OFFSET("require_auth", FR_TYPE_BOOL, rlm_rest_section_t, require_auth), .dflt = "no" },
/* Transfer configuration */
- { FR_CONF_OFFSET("timeout", FR_TYPE_TIMEVAL, rlm_rest_section_t, timeout_tv), .dflt = "4.0" },
+ { FR_CONF_OFFSET("timeout", FR_TYPE_TIME_DELTA, rlm_rest_section_t, timeout), .dflt = "4.0" },
{ FR_CONF_OFFSET("chunk", FR_TYPE_SIZE, rlm_rest_section_t, chunk), .dflt = "0" },
/* TLS Parameters */
};
static const CONF_PARSER module_config[] = {
- { FR_CONF_DEPRECATED("connect_timeout", FR_TYPE_TIMEVAL, rlm_rest_t, connect_timeout) },
+ { FR_CONF_DEPRECATED("connect_timeout", FR_TYPE_TIME_DELTA, rlm_rest_t, connect_timeout) },
{ FR_CONF_OFFSET("connect_proxy", FR_TYPE_STRING, rlm_rest_t, connect_proxy) },
{ FR_CONF_OFFSET("http_negotiation", FR_TYPE_VOID, rlm_rest_t, http_negotiation),
.func = cf_table_parse_int, .uctx = http_negotiation_table, .dflt = "default" },
uint32_t spawn_max; //!< The maximum number of connections that
//!< will be created concurrently.
- struct timeval spawn_retry_delay; //!< Amount of time to wait before attempting
+ fr_time_delta_t spawn_retry_delay; //!< Amount of time to wait before attempting
//!< to reconnect.
bool load_balance_round_robin; //!< Enable round robin load balancing.
//!< dc hosts are available and the consistency level
//!< is LOCAL_ONE or LOCAL_QUORUM.
- struct timeval lar_exclusion_threshold; //!< How much worse the latency me be, compared to
+ fr_time_delta_t lar_exclusion_threshold; //!< How much worse the latency me be, compared to
//!< the average latency of the best performing node
//!< before it's penalized.
//!< This gets mangled to a double.
- struct timeval lar_scale; //!< Weight given to older latencies when calculating
+ fr_time_delta_t lar_scale; //!< Weight given to older latencies when calculating
//!< the average latency of a node. A bigger scale will
//!< give more weight to older latency measurements.
- struct timeval lar_retry_period; //!< The amount of time a node is penalized by the
+ fr_time_delta_t lar_retry_period; //!< The amount of time a node is penalized by the
//!< policy before being given a second chance when
//!< the current average latency exceeds the calculated
//!< threshold
//!< (exclusion_threshold * best_average_latency).
- struct timeval lar_update_rate; //!< The rate at which the best average latency is
+ fr_time_delta_t lar_update_rate; //!< The rate at which the best average latency is
//!< recomputed.
uint64_t lar_min_measured; //!< The minimum number of measurements per-host
//!< required to be considered by the policy.
};
static CONF_PARSER latency_aware_routing_config[] = {
- { FR_CONF_OFFSET("exclusion_threshold", FR_TYPE_TIMEVAL, rlm_sql_cassandra_t, lar_exclusion_threshold), .dflt = "2.0" },
- { FR_CONF_OFFSET("scale", FR_TYPE_TIMEVAL, rlm_sql_cassandra_t, lar_scale), .dflt = "0.1" },
- { FR_CONF_OFFSET("retry_period", FR_TYPE_TIMEVAL, rlm_sql_cassandra_t, lar_retry_period), .dflt = "10" },
- { FR_CONF_OFFSET("update_rate", FR_TYPE_TIMEVAL, rlm_sql_cassandra_t, lar_update_rate), .dflt = "0.1" },
+ { FR_CONF_OFFSET("exclusion_threshold", FR_TYPE_FLOAT64, rlm_sql_cassandra_t, lar_exclusion_threshold), .dflt = "2.0" },
+ { FR_CONF_OFFSET("scale", FR_TYPE_TIME_DELTA, rlm_sql_cassandra_t, lar_scale), .dflt = "0.1" },
+ { FR_CONF_OFFSET("retry_period", FR_TYPE_TIME_DELTA, rlm_sql_cassandra_t, lar_retry_period), .dflt = "10" },
+ { FR_CONF_OFFSET("update_rate", FR_TYPE_TIME_DELTA, rlm_sql_cassandra_t, lar_update_rate), .dflt = "0.1" },
{ FR_CONF_OFFSET("min_measured", FR_TYPE_UINT64, rlm_sql_cassandra_t, lar_min_measured), .dflt = "50" },
CONF_PARSER_TERMINATOR
};
{ FR_CONF_OFFSET("spawn_threshold", FR_TYPE_UINT32, rlm_sql_cassandra_t, spawn_threshold) },
{ FR_CONF_OFFSET("spawn_max", FR_TYPE_UINT32, rlm_sql_cassandra_t, spawn_max) },
- { FR_CONF_OFFSET("spawn_retry_delay", FR_TYPE_TIMEVAL, rlm_sql_cassandra_t, spawn_retry_delay) },
+ { FR_CONF_OFFSET("spawn_retry_delay", FR_TYPE_TIME_DELTA, rlm_sql_cassandra_t, spawn_retry_delay) },
{ FR_CONF_POINTER("load_balance_dc_aware", FR_TYPE_SUBSECTION, NULL), .subcs = (void const *) load_balance_dc_aware_config },
{ FR_CONF_OFFSET("load_balance_round_robin", FR_TYPE_BOOL, rlm_sql_cassandra_t, load_balance_round_robin), .dflt = "no" },
return 0;
}
-static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
+static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, fr_time_delta_t timeout)
{
rlm_sql_cassandra_conn_t *conn;
rlm_sql_cassandra_t *inst = config->driver;
* Easier to do this here instead of mod_instantiate
* as we don't have a pointer to the pool.
*/
- cass_cluster_set_connect_timeout(inst->cluster, FR_TIMEVAL_TO_MS(timeout));
+ cass_cluster_set_connect_timeout(inst->cluster, fr_time_delta_to_msec(timeout));
DEBUG2("Connecting to Cassandra cluster");
future = cass_session_connect_keyspace(inst->session, inst->cluster, config->sql_db);
cass_cluster_set_max_concurrent_creation(inst->cluster, inst->spawn_max));
}
- {
- uint32_t delay;
-
- delay = (inst->spawn_retry_delay.tv_sec * (uint64_t)1000) +
- (inst->spawn_retry_delay.tv_usec / 1000);
- if (delay) cass_cluster_set_reconnect_wait_time(inst->cluster, delay);
- }
+ if (delay) cass_cluster_set_reconnect_wait_time(inst->cluster, fr_time_delta_to_msec(inst->spawn_retry_delay));
if (inst->load_balance_round_robin) cass_cluster_set_load_balance_round_robin(inst->cluster);
}
if (do_latency_aware_routing) {
- cass_double_t exclusion_threshold;
- uint64_t scale_ms, retry_period_ms, update_rate_ms;
-
- exclusion_threshold = inst->lar_exclusion_threshold.tv_sec +
- (inst->lar_exclusion_threshold.tv_usec / 1000000);
-
- scale_ms = (inst->lar_scale.tv_sec * (uint64_t)1000) + (inst->lar_scale.tv_usec / 1000);
- retry_period_ms = (inst->lar_retry_period.tv_sec * (uint64_t)1000) +
- (inst->lar_retry_period.tv_usec / 1000);
- update_rate_ms = (inst->lar_update_rate.tv_sec * (uint64_t)1000) +
- (inst->lar_update_rate.tv_usec / 1000);
-
/* Can't fail */
cass_cluster_set_latency_aware_routing(inst->cluster, true);
/* Can't fail */
cass_cluster_set_latency_aware_routing_settings(inst->cluster,
- exclusion_threshold,
- scale_ms,
- retry_period_ms,
- update_rate_ms,
+ (cass_double_t)inst->lar_exclusion_threshold,
+ fr_time_delta_to_msec(inst->lar_scale),
+ fr_time_delta_to_msec(inst->lar_retry_period),
+ fr_time_delta_to_msec(inst->lar_update_rate),
inst->lar_min_measured);
}
return RLM_SQL_OK;
}
-static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, UNUSED struct timeval const *timeout)
+static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
+ UNUSED fr_time_delta_t timeout)
{
SQLRETURN row;
#if 0
*
*/
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
- UNUSED struct timeval const *timeout)
+ UNUSED fr_time_delta_t timeout)
{
rlm_sql_firebird_conn_t *conn;
return RLM_SQL_OK;
}
-static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
+static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, fr_time_delta_t timeout)
{
rlm_sql_freetds_conn_t *conn;
- unsigned int timeout_ms = FR_TIMEVAL_TO_MS(timeout);
+ unsigned int timeout_ms = fr_time_delta_to_msec(timeout);
MEM(conn = handle->conn = talloc_zero(handle, rlm_sql_freetds_conn_t));
talloc_set_destructor(conn, _sql_socket_destructor);
return 0;
}
-static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
+static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, fr_time_delta_t timeout)
{
rlm_sql_mysql_conn_t *conn;
rlm_sql_mysql_t *inst = config->driver;
- unsigned int connect_timeout = timeout->tv_sec;
+ unsigned int connect_timeout = (unsigned int)fr_time_delta_to_sec(timeout);
unsigned long sql_flags;
MEM(conn = handle->conn = talloc_zero(handle, rlm_sql_mysql_conn_t));
static const void *fake = "fake";
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config,
- UNUSED struct timeval const *timeout)
+ UNUSED fr_time_delta_t timeout)
{
memcpy(&handle->conn, &fake, sizeof(handle->conn));
return 0;
}
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
- UNUSED struct timeval const *timeout)
+ UNUSED fr_time_delta_t timeout)
{
char errbuff[512];
}
static int CC_HINT(nonnull) sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
- UNUSED struct timeval const *timeout)
+ UNUSED fr_time_delta_t timeout)
{
rlm_sql_postgres_t *inst = config->driver;
rlm_sql_postgres_conn_t *conn;
}
static int CC_HINT(nonnull) sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
- UNUSED struct timeval const *timeout)
+ UNUSED fr_time_delta_t timeout)
{
rlm_sql_sqlite_conn_t *conn;
rlm_sql_sqlite_t *inst = config->driver;
}
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
- struct timeval const *timeout)
+ fr_time_delta_t timeout)
{
rlm_sql_unixodbc_conn_t *conn;
long err_handle;
- uint32_t timeout_ms = FR_TIMEVAL_TO_MS(timeout);
+ uint32_t timeout_ms = fr_time_delta_to_msec(timeout);
MEM(conn = handle->conn = talloc_zero(handle, rlm_sql_unixodbc_conn_t));
talloc_set_destructor(conn, _sql_socket_destructor);
sql_rcode_t (*mod_instantiate)(rlm_sql_config_t const *config, void *instance, CONF_SECTION *cs);
sql_rcode_t (*sql_socket_init)(rlm_sql_handle_t *handle, rlm_sql_config_t *config,
- struct timeval const *timeout);
+ fr_time_delta_t timeout);
sql_rcode_t (*sql_query)(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query);
sql_rcode_t (*sql_select_query)(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query);
rlm_sql_grouplist_t *next;
};
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout);
int sql_fr_pair_list_afrom_str(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **first_pair, rlm_sql_row_t row);
int sql_read_realms(rlm_sql_handle_t *handle);
int sql_getvpdata(TALLOC_CTX *ctx, rlm_sql_t const *inst, REQUEST *request, rlm_sql_handle_t **handle, VALUE_PAIR **pair, char const *query);
{ NULL, 0 }
};
-void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
+void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
{
int rcode;
rlm_sql_t *inst = instance;
*
* @return pointer to libwbclient context
*/
-static void *mod_conn_create(TALLOC_CTX *ctx, UNUSED void *instance, UNUSED struct timeval const *timeout)
+static void *mod_conn_create(TALLOC_CTX *ctx, UNUSED void *instance, UNUSED fr_time_delta_t timeout)
{
struct wbcContext **wb_ctx;
* @see fr_pool_connection_create_t
* @see connection.c
*/
-static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED struct timeval const *timeout)
+static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED fr_time_delta_t timeout)
{
rlm_yubikey_t const *inst = instance;
ykclient_rc status;