From: Arran Cudbard-Bell Date: Fri, 24 May 2019 18:04:11 +0000 (-0400) Subject: Strip FR_TYPE_TIMEVAL from module configurations and replace with FR_TYPE_TIME_DELTA X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04026a0df54c9752540fe2cc5e67ac1e57522f29;p=thirdparty%2Ffreeradius-server.git Strip FR_TYPE_TIMEVAL from module configurations and replace with FR_TYPE_TIME_DELTA Remove timevals from: exec API connection pool API LDAP library delay module many other modules --- diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index 431f4c451bb..e6e345d80fd 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -115,7 +115,7 @@ struct fr_worker_t { 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 @@ -643,7 +643,6 @@ static void worker_reset_timer(fr_worker_t *worker) rad_assert(worker->num_active > 0); cleanup = worker->max_request_time; - cleanup *= NSEC; cleanup += request->async->recv_time; /* @@ -657,7 +656,8 @@ static void worker_reset_timer(fr_worker_t *worker) 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."); @@ -677,8 +677,8 @@ static void worker_reset_timer(fr_worker_t *worker) */ 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. @@ -689,7 +689,7 @@ static void fr_worker_check_timeouts(fr_worker_t *worker, fr_time_t now) 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. @@ -1287,7 +1287,7 @@ nomem: 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"); diff --git a/src/lib/ldap/base.c b/src/lib/ldap/base.c index 000c1e33b0b..806e0785b14 100644 --- a/src/lib/ldap/base.c +++ b/src/lib/ldap/base.c @@ -104,7 +104,7 @@ FR_NAME_NUMBER const fr_ldap_dereference[] = { * 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; @@ -131,16 +131,16 @@ void fr_ldap_timeout_debug(REQUEST *request, fr_ldap_connection_t const *conn, 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"); @@ -149,8 +149,8 @@ void fr_ldap_timeout_debug(REQUEST *request, fr_ldap_connection_t const *conn, #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"); @@ -393,7 +393,7 @@ process_error: 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; @@ -420,7 +420,7 @@ fr_ldap_rcode_t fr_ldap_result(LDAPMessage **result, LDAPControl ***ctrls, if (!timeout) { fr_timeval_from_nsec(&tv, conn->config->res_timeout); } else { - tv = *timeout; + tv = fr_time_delta_to_timeval(timeout); } /* @@ -481,7 +481,7 @@ fr_ldap_rcode_t fr_ldap_bind(REQUEST *request, #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; @@ -533,7 +533,7 @@ fr_ldap_rcode_t fr_ldap_bind(REQUEST *request, /* 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) { @@ -600,7 +600,7 @@ fr_ldap_rcode_t fr_ldap_search(LDAPMessage **result, REQUEST *request, 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__); } /* @@ -616,7 +616,7 @@ fr_ldap_rcode_t fr_ldap_search(LDAPMessage **result, REQUEST *request, 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; @@ -643,7 +643,7 @@ fr_ldap_rcode_t fr_ldap_search(LDAPMessage **result, REQUEST *request, 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; @@ -721,7 +721,7 @@ fr_ldap_rcode_t fr_ldap_search_async(int *msgid, REQUEST *request, 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 @@ -736,7 +736,7 @@ fr_ldap_rcode_t fr_ldap_search_async(int *msgid, REQUEST *request, 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; @@ -802,7 +802,7 @@ fr_ldap_rcode_t fr_ldap_modify(REQUEST *request, fr_ldap_connection_t **pconn, 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. @@ -811,7 +811,7 @@ fr_ldap_rcode_t fr_ldap_modify(REQUEST *request, fr_ldap_connection_t **pconn, 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; } @@ -825,7 +825,7 @@ fr_ldap_rcode_t fr_ldap_modify(REQUEST *request, fr_ldap_connection_t **pconn, (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; diff --git a/src/lib/ldap/base.h b/src/lib/ldap/base.h index f31157caaca..36822ebda45 100644 --- a/src/lib/ldap/base.h +++ b/src/lib/ldap/base.h @@ -379,7 +379,7 @@ static inline void fr_ldap_berval_to_value(fr_value_box_t *value, struct berval * 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); @@ -395,7 +395,7 @@ fr_ldap_rcode_t fr_ldap_bind(REQUEST *request, #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); @@ -420,7 +420,7 @@ fr_ldap_rcode_t fr_ldap_error_check(LDAPControl ***ctrls, fr_ldap_connection_t c 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); @@ -481,7 +481,7 @@ fr_ldap_rcode_t fr_ldap_sasl_interactive(REQUEST *request, 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 /* diff --git a/src/lib/ldap/bind.c b/src/lib/ldap/bind.c index 4484ed871f9..24b04d5ce4d 100644 --- a/src/lib/ldap/bind.c +++ b/src/lib/ldap/bind.c @@ -72,9 +72,11 @@ static void _ldap_bind_io_read(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED 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) { diff --git a/src/lib/ldap/connection.c b/src/lib/ldap/connection.c index 2b8882a7eb2..387f960f941 100644 --- a/src/lib/ldap/connection.c +++ b/src/lib/ldap/connection.c @@ -131,7 +131,7 @@ static int fr_ldap_rebind(LDAP *handle, LDAP_CONST char *url, } 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); @@ -474,15 +474,11 @@ fr_ldap_connection_t *fr_ldap_connection_state_alloc(TALLOC_CTX *ctx, fr_event_l 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, diff --git a/src/lib/ldap/sasl.c b/src/lib/ldap/sasl.c index d2b2f9736f7..dda69c36c02 100644 --- a/src/lib/ldap/sasl.c +++ b/src/lib/ldap/sasl.c @@ -122,12 +122,12 @@ static void _ldap_sasl_bind_io_read(fr_event_list_t *el, int fd, UNUSED int flag 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: diff --git a/src/lib/ldap/sasl_s.c b/src/lib/ldap/sasl_s.c index 6767a9ac375..7b9c8846d10 100644 --- a/src/lib/ldap/sasl_s.c +++ b/src/lib/ldap/sasl_s.c @@ -112,7 +112,7 @@ fr_ldap_rcode_t fr_ldap_sasl_interactive(REQUEST *request, 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; diff --git a/src/lib/ldap/start_tls.c b/src/lib/ldap/start_tls.c index 3dde58b2b29..f08ee4acae1 100644 --- a/src/lib/ldap/start_tls.c +++ b/src/lib/ldap/start_tls.c @@ -99,9 +99,11 @@ static void _ldap_start_tls_io_read(UNUSED fr_event_list_t *el, UNUSED int fd, U 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) { diff --git a/src/lib/redis/cluster.c b/src/lib/redis/cluster.c index 2cf71c0a540..70840c78867 100644 --- a/src/lib/redis/cluster.c +++ b/src/lib/redis/cluster.c @@ -1209,34 +1209,27 @@ static int _cluster_pool_walk(void *data, void *uctx) * - 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 @@ -1324,7 +1317,7 @@ static int cluster_node_find_live(fr_redis_cluster_node_t **live_node, fr_redis_ uint32_t i; cluster_nodes_live_t *live; - struct timeval now; + fr_time_t now; RDEBUG2("Searching for live cluster nodes"); @@ -1344,14 +1337,14 @@ static int cluster_node_find_live(fr_redis_cluster_node_t **live_node, fr_redis_ 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; @@ -1361,7 +1354,7 @@ static int cluster_node_find_live(fr_redis_cluster_node_t **live_node, fr_redis_ 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); } @@ -1466,7 +1459,7 @@ static int _cluster_conn_free(fr_redis_conn_t *conn) * - 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; @@ -1476,7 +1469,7 @@ void *fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, struct timev 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); diff --git a/src/lib/redis/cluster.h b/src/lib/redis/cluster.h index 927e438d8d7..4c125d7761e 100644 --- a/src/lib/redis/cluster.h +++ b/src/lib/redis/cluster.h @@ -78,7 +78,7 @@ fr_redis_cluster_rcode_t fr_redis_cluster_remap(REQUEST *request, fr_redis_clust /* * 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 diff --git a/src/lib/server/cf_parse.h b/src/lib/server/cf_parse.h index 8262c9aedbd..f90021ec4e6 100644 --- a/src/lib/server/cf_parse.h +++ b/src/lib/server/cf_parse.h @@ -342,14 +342,12 @@ do {\ #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) diff --git a/src/lib/server/client.c b/src/lib/server/client.c index dac1ae78727..72a2353f121 100644 --- a/src/lib/server/client.c +++ b/src/lib/server/client.c @@ -445,7 +445,7 @@ static const CONF_PARSER client_config[] = { { 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) }, @@ -860,11 +860,10 @@ RADCLIENT *client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *serv * 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 diff --git a/src/lib/server/client.h b/src/lib/server/client.h index a53dc4316a4..e0d14bab8ba 100644 --- a/src/lib/server/client.h +++ b/src/lib/server/client.h @@ -113,7 +113,7 @@ struct rad_client { # 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). diff --git a/src/lib/server/connection.c b/src/lib/server/connection.c index 7bcaa3e7506..aa5b9c1a6cb 100644 --- a/src/lib/server/connection.c +++ b/src/lib/server/connection.c @@ -68,9 +68,9 @@ struct fr_conn { 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. @@ -164,8 +164,7 @@ static void connection_state_failed(fr_connection_t *conn, fr_time_t now) 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 */ @@ -189,7 +188,7 @@ static void _connection_timeout(UNUSED fr_event_list_t *el, fr_time_t now, void { 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); } @@ -315,9 +314,9 @@ static void connection_state_init(fr_connection_t *conn, fr_time_t 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; @@ -429,8 +428,8 @@ static int _connection_free(fr_connection_t *conn) * - 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) @@ -447,8 +446,8 @@ fr_connection_t *fr_connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el, 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; diff --git a/src/lib/server/connection.h b/src/lib/server/connection.h index 42980737c23..a84b79db293 100644 --- a/src/lib/server/connection.h +++ b/src/lib/server/connection.h @@ -106,8 +106,8 @@ typedef fr_connection_state_t (*fr_connection_failed_t)(int fd, fr_connection_st 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); diff --git a/src/lib/server/exec.c b/src/lib/server/exec.c index b80519217ab..6993d33f009 100644 --- a/src/lib/server/exec.c +++ b/src/lib/server/exec.c @@ -435,13 +435,13 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait, * - -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 @@ -466,29 +466,28 @@ int radius_readfrom_program(int fd, pid_t pid, int timeout, } 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); @@ -582,7 +581,7 @@ int radius_readfrom_program(int fd, pid_t pid, int timeout, */ 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; diff --git a/src/lib/server/exec.h b/src/lib/server/exec.h index 6a927a70003..6b5709ed9dd 100644 --- a/src/lib/server/exec.h +++ b/src/lib/server/exec.h @@ -31,7 +31,7 @@ extern "C" { #include -#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); @@ -53,12 +53,12 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait, 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 } diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 9e972411b21..723168d225a 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -169,7 +169,7 @@ static const CONF_PARSER server_config[] = { { 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" }, diff --git a/src/lib/server/main_config.h b/src/lib/server/main_config.h index 43a0d995baa..89c2644f02f 100644 --- a/src/lib/server/main_config.h +++ b/src/lib/server/main_config.h @@ -58,7 +58,7 @@ struct main_config_s { 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 diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 4c57832dc51..720e9064f76 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -762,7 +762,7 @@ static int map_exec_to_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, v 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); diff --git a/src/lib/server/pool.c b/src/lib/server/pool.c index 648029ad211..3c66d53cbe4 100644 --- a/src/lib/server/pool.c +++ b/src/lib/server/pool.c @@ -54,9 +54,9 @@ struct fr_pool_connection_s { 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, @@ -101,9 +101,9 @@ struct fr_pool_s { 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, @@ -134,9 +134,9 @@ struct fr_pool_s { //!< 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. @@ -158,9 +158,9 @@ static const CONF_PARSER pool_config[] = { { 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 @@ -171,13 +171,8 @@ static const CONF_PARSER pool_config[] = { 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 @@ -185,14 +180,8 @@ static int last_reserved_cmp(void const *one, void const *two) 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 @@ -334,7 +323,7 @@ static fr_pool_connection_t *connection_find(fr_pool_t *pool, void *conn) * - 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; @@ -372,7 +361,7 @@ static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, 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; @@ -381,8 +370,8 @@ static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, 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; @@ -438,7 +427,7 @@ static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, * 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); @@ -482,7 +471,7 @@ static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, 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; /* @@ -512,7 +501,7 @@ static fr_pool_connection_t *connection_spawn(fr_pool_t *pool, REQUEST *request, 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; @@ -626,9 +615,9 @@ static int connection_manage(fr_pool_t *pool, REQUEST *request, fr_pool_connecti } 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; } @@ -652,11 +641,11 @@ static int connection_manage(fr_pool_t *pool, REQUEST *request, fr_pool_connecti */ 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; } @@ -767,9 +756,7 @@ static int connection_check(fr_pool_t *pool, REQUEST *request) 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; @@ -815,14 +802,14 @@ 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 @@ -849,7 +836,7 @@ static void *connection_get_internal(fr_pool_t *pool, REQUEST *request, bool spa /* * 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; } @@ -883,7 +870,7 @@ static void *connection_get_internal(fr_pool_t *pool, REQUEST *request, bool spa 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 @@ -1067,11 +1054,12 @@ fr_pool_t *fr_pool_init(TALLOC_CTX *ctx, 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); } /* @@ -1079,7 +1067,7 @@ fr_pool_t *fr_pool_init(TALLOC_CTX *ctx, * 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 @@ -1156,7 +1144,7 @@ fr_pool_state_t const *fr_pool_state(fr_pool_t *pool) * @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; } @@ -1381,9 +1369,9 @@ void *fr_pool_connection_get(fr_pool_t *pool, REQUEST *request) */ 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; @@ -1393,34 +1381,35 @@ void fr_pool_connection_release(fr_pool_t *pool, REQUEST *request, void *conn) /* * 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. @@ -1520,7 +1509,7 @@ int fr_pool_connection_close(fr_pool_t *pool, REQUEST *request, void *conn) /* * 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); diff --git a/src/lib/server/pool.h b/src/lib/server/pool.h index ecafc63d72d..cfbb1023e1f 100644 --- a/src/lib/server/pool.h +++ b/src/lib/server/pool.h @@ -45,23 +45,23 @@ extern "C" { 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. @@ -112,7 +112,7 @@ typedef void (*fr_pool_reconnect_t)(fr_pool_t *pool, void *opaque); * - 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 * @@ -149,7 +149,7 @@ fr_pool_t *fr_pool_copy(TALLOC_CTX *ctx, fr_pool_t *pool, void *opaque); 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); diff --git a/src/lib/server/realms.h b/src/lib/server/realms.h index 8a05d95a0c0..bbf636aa9c7 100644 --- a/src/lib/server/realms.h +++ b/src/lib/server/realms.h @@ -93,7 +93,7 @@ typedef struct { 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. diff --git a/src/lib/server/tmpl.c b/src/lib/server/tmpl.c index f481e3d7388..21ac8a11dd5 100644 --- a/src/lib/server/tmpl.c +++ b/src/lib/server/tmpl.c @@ -1564,7 +1564,7 @@ ssize_t _tmpl_to_type(void *out, } 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); } @@ -1855,7 +1855,7 @@ ssize_t _tmpl_to_atype(TALLOC_CTX *ctx, void *out, 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; diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index fe81787a45f..86c42bbab6f 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -387,7 +387,6 @@ typedef enum { 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) @@ -410,6 +409,14 @@ typedef enum { #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); diff --git a/src/lib/server/trigger.c b/src/lib/server/trigger.c index c4968b05b17..5b62b31472b 100644 --- a/src/lib/server/trigger.c +++ b/src/lib/server/trigger.c @@ -332,7 +332,8 @@ int trigger_exec(REQUEST *request, CONF_SECTION const *cs, char const *name, boo * 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); diff --git a/src/lib/tls/validate.c b/src/lib/tls/validate.c index 25721e6ff31..d2a73840b9c 100644 --- a/src/lib/tls/validate.c +++ b/src/lib/tls/validate.c @@ -308,7 +308,7 @@ int tls_validate_cert_cb(int ok, X509_STORE_CTX *x509_ctx) 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 { diff --git a/src/lib/unlang/xlat.c b/src/lib/unlang/xlat.c index 5dde060672d..ad50f44ad32 100644 --- a/src/lib/unlang/xlat.c +++ b/src/lib/unlang/xlat.c @@ -429,7 +429,7 @@ static unlang_action_t unlang_xlat_inline(REQUEST *request, } 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; } } diff --git a/src/lib/util/socket.c b/src/lib/util/socket.c index d96c629cae5..168916b7376 100644 --- a/src/lib/util/socket.c +++ b/src/lib/util/socket.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -607,10 +608,9 @@ int fr_socket_client_tcp(fr_ipaddr_t const *src_ipaddr, fr_ipaddr_t const *dst_i * - -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 */ @@ -622,7 +622,7 @@ int fr_socket_wait_for_connect(int sockfd, struct timeval const *timeout) /* 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) { @@ -645,8 +645,7 @@ int fr_socket_wait_for_connect(int sockfd, struct timeval const *timeout) 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 */ diff --git a/src/lib/util/socket.h b/src/lib/util/socket.h index 326a78ebc18..38e116c61f7 100644 --- a/src/lib/util/socket.h +++ b/src/lib/util/socket.h @@ -34,6 +34,7 @@ extern "C" { #include #include #include +#include #include #include @@ -46,7 +47,7 @@ int fr_socket_client_udp(fr_ipaddr_t *src_ipaddr, uint16_t *src_port, fr_ipaddr 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); diff --git a/src/modules/proto_ldap_sync/proto_ldap_sync.c b/src/modules/proto_ldap_sync/proto_ldap_sync.c index 5c678a51e84..9aa645caf6d 100644 --- a/src/modules/proto_ldap_sync/proto_ldap_sync.c +++ b/src/modules/proto_ldap_sync/proto_ldap_sync.c @@ -61,17 +61,17 @@ typedef struct { 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. /* @@ -181,8 +181,8 @@ static const CONF_PARSER module_config[] = { { 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 @@ -576,13 +576,13 @@ static void proto_ldap_sync_reinit(fr_event_list_t *el, fr_time_t now, void *use */ 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()); } @@ -923,7 +923,7 @@ static int proto_ldap_socket_recv(rad_listen_t *listen) 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 */ @@ -933,21 +933,21 @@ static int proto_ldap_socket_recv(rad_listen_t *listen) */ 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()); } @@ -1004,11 +1004,11 @@ static int proto_ldap_socket_open(UNUSED CONF_SECTION *cs, rad_listen_t *listen) 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()); } @@ -1021,7 +1021,7 @@ static int proto_ldap_socket_open(UNUSED CONF_SECTION *cs, rad_listen_t *listen) &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; diff --git a/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c b/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c index 49cf0ace5a3..21e71fe6898 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c @@ -61,7 +61,7 @@ static int _mod_conn_free(rlm_cache_memcached_handle_t *mandle) /** 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; @@ -76,7 +76,7 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval con 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: diff --git a/src/modules/rlm_couchbase/mod.c b/src/modules/rlm_couchbase/mod.c index b86bd557b50..d61f01361de 100644 --- a/src/modules/rlm_couchbase/mod.c +++ b/src/modules/rlm_couchbase/mod.c @@ -155,7 +155,7 @@ int mod_build_api_opts(CONF_SECTION *conf, void *instance) * - 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 */ @@ -166,7 +166,7 @@ void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *tim /* 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) { diff --git a/src/modules/rlm_couchbase/mod.h b/src/modules/rlm_couchbase/mod.h index 775af015432..7c071bad0de 100644 --- a/src/modules/rlm_couchbase/mod.h +++ b/src/modules/rlm_couchbase/mod.h @@ -74,7 +74,7 @@ typedef struct { } 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); diff --git a/src/modules/rlm_delay/rlm_delay.c b/src/modules/rlm_delay/rlm_delay.c index f1a42dc0137..cd317b35c19 100644 --- a/src/modules/rlm_delay/rlm_delay.c +++ b/src/modules/rlm_delay/rlm_delay.c @@ -149,14 +149,14 @@ static void mod_delay_cancel(UNUSED void *instance, UNUSED void *thread, REQUEST 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; } /* @@ -168,16 +168,16 @@ static rlm_rcode_t CC_HINT(nonnull) mod_delay(void *instance, UNUSED void *threa /* * 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"); @@ -188,24 +188,21 @@ static rlm_rcode_t CC_HINT(nonnull) mod_delay(void *instance, UNUSED void *threa } 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); @@ -230,7 +227,6 @@ static xlat_action_t xlat_delay(TALLOC_CTX *ctx, UNUSED fr_cursor_t *out, 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 */ @@ -274,10 +270,10 @@ static xlat_action_t xlat_delay(TALLOC_CTX *ctx, UNUSED fr_cursor_t *out, } 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"); diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index 55d379209ec..79f7921c929 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -43,7 +43,7 @@ typedef struct { 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[] = { @@ -52,7 +52,7 @@ 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 }; @@ -233,10 +233,10 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * 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; } @@ -244,8 +244,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * 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; } diff --git a/src/modules/rlm_ldap/conn.c b/src/modules/rlm_ldap/conn.c index 9f5725a781b..c05883ac08c 100644 --- a/src/modules/rlm_ldap/conn.c +++ b/src/modules/rlm_ldap/conn.c @@ -109,12 +109,11 @@ void mod_conn_release(rlm_ldap_t const *inst, REQUEST *request, fr_ldap_connecti * * 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; @@ -124,9 +123,7 @@ void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *tim 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; diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index a4429d13f39..ed8e6c4e639 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -788,7 +788,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, UNUSED void &conn, dn, request->password->vp_strvalue, inst->user_sasl.mech ? &sasl : NULL, - NULL, + 0, NULL, NULL); switch (status) { case LDAP_PROC_SUCCESS: @@ -1029,7 +1029,7 @@ static rlm_rcode_t mod_authorize(void *instance, UNUSED void *thread, REQUEST *r * 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; diff --git a/src/modules/rlm_ldap/rlm_ldap.h b/src/modules/rlm_ldap/rlm_ldap.h index 260dd4d3874..207fea48029 100644 --- a/src/modules/rlm_ldap/rlm_ldap.h +++ b/src/modules/rlm_ldap/rlm_ldap.h @@ -191,4 +191,4 @@ fr_ldap_connection_t *mod_conn_get(rlm_ldap_t const *inst, REQUEST *request); 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); diff --git a/src/modules/rlm_ldap/user.c b/src/modules/rlm_ldap/user.c index 6b81ffcd429..e608639c8b5 100644 --- a/src/modules/rlm_ldap/user.c +++ b/src/modules/rlm_ldap/user.c @@ -104,7 +104,7 @@ char const *rlm_ldap_find_user(rlm_ldap_t const *inst, REQUEST *request, fr_ldap 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; diff --git a/src/modules/rlm_linelog/rlm_linelog.c b/src/modules/rlm_linelog/rlm_linelog.c index 034bdd6722b..d5fa351553a 100644 --- a/src/modules/rlm_linelog/rlm_linelog.c +++ b/src/modules/rlm_linelog/rlm_linelog.c @@ -194,7 +194,7 @@ static int _mod_conn_free(linelog_conn_t *conn) 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; @@ -241,7 +241,7 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval con } if (errno == EINPROGRESS) { - if (FR_TIMEVAL_TO_MS(timeout)) { + if (timeout) { DEBUG2("Waiting for connection to complete..."); } else { DEBUG2("Blocking until connection complete..."); @@ -257,7 +257,7 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval con /* * 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; diff --git a/src/modules/rlm_logtee/rlm_logtee.c b/src/modules/rlm_logtee/rlm_logtee.c index ced5f7f2580..539af247e5c 100644 --- a/src/modules/rlm_logtee/rlm_logtee.c +++ b/src/modules/rlm_logtee/rlm_logtee.c @@ -544,7 +544,6 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc { 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)); @@ -559,13 +558,10 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc 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; diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index 63df9b6386e..0974a3fc7d6 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -93,7 +93,7 @@ static const CONF_PARSER module_config[] = { { 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" }, @@ -638,7 +638,7 @@ static int _mod_conn_free(struct wbcContext **wb_ctx) /* * 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; @@ -850,7 +850,7 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t const *inst, /* * 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"); @@ -2191,16 +2191,16 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * 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; } diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 53fde203134..a55aa60ed01 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -2634,7 +2634,6 @@ static void conn_alloc(rlm_radius_udp_t *inst, fr_io_connection_thread_t *t) { 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; @@ -2679,10 +2678,7 @@ static void conn_alloc(rlm_radius_udp_t *inst, fr_io_connection_thread_t *t) } 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, diff --git a/src/modules/rlm_redis_ippool/rlm_redis_ippool.c b/src/modules/rlm_redis_ippool/rlm_redis_ippool.c index 8329e22fffc..154a78b1f5e 100644 --- a/src/modules/rlm_redis_ippool/rlm_redis_ippool.c +++ b/src/modules/rlm_redis_ippool/rlm_redis_ippool.c @@ -73,7 +73,7 @@ typedef struct { 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 @@ -115,7 +115,7 @@ static CONF_PARSER module_config[] = { { 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) }, @@ -467,7 +467,7 @@ static void ippool_action_print(REQUEST *request, ippool_action_t action, */ 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, ...) { @@ -500,7 +500,7 @@ static fr_redis_rcode_t ippool_script(redisReply **out, REQUEST *request, fr_red 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, @@ -626,7 +626,7 @@ static ippool_rcode_t redis_ippool_allocate(rlm_redis_ippool_t const *inst, REQU 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, @@ -837,7 +837,7 @@ static ippool_rcode_t redis_ippool_update(rlm_redis_ippool_t const *inst, REQUES 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, @@ -852,7 +852,7 @@ static ippool_rcode_t redis_ippool_update(rlm_redis_ippool_t const *inst, REQUES 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, @@ -975,7 +975,7 @@ static ippool_rcode_t redis_ippool_release(rlm_redis_ippool_t const *inst, REQUE 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, @@ -989,7 +989,7 @@ static ippool_rcode_t redis_ippool_release(rlm_redis_ippool_t const *inst, REQUE 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, diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 1d0ce7b2d55..5cdced3595a 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -273,7 +273,7 @@ static int _mod_conn_free(rlm_rest_handle_t *randle) * @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; @@ -1818,7 +1818,7 @@ int rest_request_config(rlm_rest_t const *inst, rlm_rest_thread_t *t, rlm_rest_s 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; @@ -1874,10 +1874,10 @@ int rest_request_config(rlm_rest_t const *inst, rlm_rest_thread_t *t, rlm_rest_s } 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)); diff --git a/src/modules/rlm_rest/rest.h b/src/modules/rlm_rest/rest.h index ced526403a4..656d72b1b02 100644 --- a/src/modules/rlm_rest/rest.h +++ b/src/modules/rlm_rest/rest.h @@ -147,7 +147,7 @@ typedef struct { 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; @@ -307,7 +307,7 @@ typedef size_t (*rest_read_t)(void *ptr, size_t size, size_t nmemb, 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 diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index 2366f79991f..582e31e3af9 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -90,7 +90,7 @@ static const CONF_PARSER section_config[] = { { 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" }, @@ -110,7 +110,7 @@ static const CONF_PARSER xlat_config[] = { { 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 */ @@ -119,7 +119,7 @@ static const CONF_PARSER xlat_config[] = { }; 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" }, diff --git a/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c b/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c index 3323763876b..a3dd37bee97 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c @@ -116,7 +116,7 @@ typedef struct { 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. @@ -131,22 +131,22 @@ typedef struct { //!< 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. @@ -192,10 +192,10 @@ static CONF_PARSER load_balance_dc_aware_config[] = { }; 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 }; @@ -231,7 +231,7 @@ static const CONF_PARSER driver_config[] = { { 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" }, @@ -354,7 +354,7 @@ static int _sql_socket_destructor(rlm_sql_cassandra_conn_t *conn) 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; @@ -377,7 +377,7 @@ static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *c * 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); @@ -818,13 +818,7 @@ do {\ 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); @@ -839,27 +833,15 @@ do {\ } 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); } diff --git a/src/modules/rlm_sql/drivers/rlm_sql_db2/rlm_sql_db2.c b/src/modules/rlm_sql/drivers/rlm_sql_db2/rlm_sql_db2.c index c2b09a223ae..6a1935f4c09 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_db2/rlm_sql_db2.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_db2/rlm_sql_db2.c @@ -60,7 +60,8 @@ static int _sql_socket_destructor(rlm_sql_db2_conn_t *conn) 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 diff --git a/src/modules/rlm_sql/drivers/rlm_sql_firebird/rlm_sql_firebird.c b/src/modules/rlm_sql/drivers/rlm_sql_firebird/rlm_sql_firebird.c index ad55126b8d5..4f4942d3088 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_firebird/rlm_sql_firebird.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_firebird/rlm_sql_firebird.c @@ -68,7 +68,7 @@ static int _sql_socket_destructor(rlm_sql_firebird_conn_t *conn) * */ 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; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_freetds/rlm_sql_freetds.c b/src/modules/rlm_sql/drivers/rlm_sql_freetds/rlm_sql_freetds.c index 973556b0b52..8690b96f901 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_freetds/rlm_sql_freetds.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_freetds/rlm_sql_freetds.c @@ -676,10 +676,10 @@ static int _sql_socket_destructor(rlm_sql_freetds_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); diff --git a/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c b/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c index a2a95c4fa9a..b9d077cf481 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c @@ -217,11 +217,11 @@ static int mod_load(void) 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)); diff --git a/src/modules/rlm_sql/drivers/rlm_sql_null/rlm_sql_null.c b/src/modules/rlm_sql/drivers/rlm_sql_null/rlm_sql_null.c index d4264b8a9c0..3b8b596adc9 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_null/rlm_sql_null.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_null/rlm_sql_null.c @@ -33,7 +33,7 @@ static sql_rcode_t sql_free_result(rlm_sql_handle_t*, rlm_sql_config_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; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c b/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c index 4983ac74887..db9de06d475 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c @@ -140,7 +140,7 @@ static int _sql_socket_destructor(rlm_sql_oracle_conn_t *conn) } 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]; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c index 3d19d7fed42..e82b48b8f26 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c @@ -226,7 +226,7 @@ static int _sql_socket_destructor(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_postgres_t *inst = config->driver; rlm_sql_postgres_conn_t *conn; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c index 989afcb7f0b..3c87fdb92e1 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c @@ -409,7 +409,7 @@ static void _sql_greatest(sqlite3_context *ctx, int num_values, sqlite3_value ** } 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; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_unixodbc/rlm_sql_unixodbc.c b/src/modules/rlm_sql/drivers/rlm_sql_unixodbc/rlm_sql_unixodbc.c index dbb1636263c..4529741977e 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_unixodbc/rlm_sql_unixodbc.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_unixodbc/rlm_sql_unixodbc.c @@ -64,11 +64,11 @@ static int _sql_socket_destructor(rlm_sql_unixodbc_conn_t *conn) } 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); diff --git a/src/modules/rlm_sql/rlm_sql.h b/src/modules/rlm_sql/rlm_sql.h index 961e127a09d..354f8bb46da 100644 --- a/src/modules/rlm_sql/rlm_sql.h +++ b/src/modules/rlm_sql/rlm_sql.h @@ -189,7 +189,7 @@ typedef struct { 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); @@ -240,7 +240,7 @@ struct rlm_sql_grouplist_s { 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); diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 0a84e53e4cd..18e9eb1926d 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -63,7 +63,7 @@ const FR_NAME_NUMBER sql_rcode_table[] = { { 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; diff --git a/src/modules/rlm_winbind/rlm_winbind.c b/src/modules/rlm_winbind/rlm_winbind.c index 36d1b32e5a1..6769660bae3 100644 --- a/src/modules/rlm_winbind/rlm_winbind.c +++ b/src/modules/rlm_winbind/rlm_winbind.c @@ -294,7 +294,7 @@ static int _mod_conn_free(struct wbcContext **wb_ctx) * * @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; diff --git a/src/modules/rlm_yubikey/validate.c b/src/modules/rlm_yubikey/validate.c index a653541ce6b..b8e25760b7a 100644 --- a/src/modules/rlm_yubikey/validate.c +++ b/src/modules/rlm_yubikey/validate.c @@ -37,7 +37,7 @@ static int _mod_conn_free(ykclient_handle_t **yandle) * @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;