From: Alan T. DeKok Date: Mon, 24 Jul 2017 19:32:07 +0000 (-0400) Subject: start of "start timers" code. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=244ec153b4379283a033b361752bbb415f26b871;p=thirdparty%2Ffreeradius-server.git start of "start timers" code. Probably has to be put elsewhere, but... --- diff --git a/src/modules/rlm_radius/track.c b/src/modules/rlm_radius/track.c index 6846594c42c..280bf16e507 100644 --- a/src/modules/rlm_radius/track.c +++ b/src/modules/rlm_radius/track.c @@ -361,3 +361,76 @@ void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag) id->use_authenticator = flag; } + +#if 0 +#ifndef USEC +#define USEC (1000000) +#endif + +static void rr_timeout(UNUSED fr_event_list_t *el, struct timeval *now, void *uctx) +{ + rlm_radius_request_t *rr = uctx; + struct timeval next; + + // re-send the packet using request_io_ctx + + /* + * Get when we SHOULD have woken up, which might not be + * the same as 'now'. + */ + next = rr->start; + next.tv_usec += rr->rt; + + /* + * Try to update the delays + */ + + // @todo get rlm_radius_retry_t pointer, or just copy all of the data to the request_io_ctx? + // - that also lets us change retransmissions on the fly for free... + + if (!rlm_radius_update_delay(&rr->start, &rr->rt, &rr->count, rr->code, rr->client_io_ctx, now)) { + // @todo - something intelligent? + return; + } + + /* + * Get the next delay time. + */ + next.tv_usec += rr->rt; + if (next.tv_usec > USEC) { + next.tv_sec += (next.tv_usec / USEC); + next.tv_usec %= USEC; + } + + if (fr_event_timer_insert(rr->request, el, &rr->ev, &next, rr_timeout, rr) < 0) { + // @todo - something intelligent? + return; + } +} + +int rr_track_start(rlm_radius_id_t *id, rlm_radius_request_t *rr, int code, fr_event_list_t *el) +{ + struct timeval next; + + (void) talloc_get_type_abort(id, rlm_radius_id_t); + + gettimeofday(&rr->start, NULL); + + if (!rlm_radius_update_delay(&rr->start, &rr->rt, &rr->count, code, rr->client_io_ctx, NULL)) { + return -1; + } + + next = rr->start; + next.tv_usec += rr->rt; + if (next.tv_usec > USEC) { + next.tv_sec += (next.tv_usec / USEC); + next.tv_usec %= USEC; + } + + if (fr_event_timer_insert(rr->request, el, &rr->ev, &next, rr_timeout, rr) < 0) { + return -1; + } + + return 0; +} +#endif