From: Alan T. DeKok Date: Tue, 3 Oct 2017 16:42:39 +0000 (-0400) Subject: move timer insert to udp function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ce9f88c975b7672af17cd6efebba8e52b1e98db;p=thirdparty%2Ffreeradius-server.git move timer insert to udp function --- diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 07fb62f66b5..eacd1b8bb28 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -868,7 +868,7 @@ static void status_check_timeout(UNUSED fr_event_list_t *el, struct timeval *now * already a bit complex. */ rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); - rcode = rr_track_retry(u, &u->timer, c->thread->el, status_check_timeout, u, now); + rcode = rr_track_retry(&u->timer, now); if (rcode < 0) { /* * Failed inserting event... the request is done. @@ -884,6 +884,12 @@ static void status_check_timeout(UNUSED fr_event_list_t *el, struct timeval *now return; } + if (fr_event_timer_insert(u, c->thread->el, &u->timer.ev, &u->timer.next, status_check_timeout, u) < 0) { + RDEBUG("Failed inserting status check timer for connection %s", c->name); + talloc_free(c); + return; + } + /* * Link it into the connection queue for retransmission. */ @@ -1033,7 +1039,7 @@ static void response_timeout(fr_event_list_t *el, struct timeval *now, void *uct */ if (u->rr) RDEBUG("Retransmitting ID %d on connection %s", u->rr->id, c->name); - rcode = rr_track_retry(u, &u->timer, el, response_timeout, u, now); + rcode = rr_track_retry(&u->timer, now); if (rcode < 0) { if (c) { REDEBUG("Failing proxied request ID %d due to error trying to proxy on connection %s", @@ -1061,6 +1067,12 @@ static void response_timeout(fr_event_list_t *el, struct timeval *now, void *uct return; } + if (fr_event_timer_insert(u, el, &u->timer.ev, &u->timer.next, response_timeout, u) < 0) { + RDEBUG("Failed inserting status check timer for connection %s", c->name); + mod_finished_request(c, u); + return; + } + /* * If we can retransmit it, do so. Otherwise, it will * get retransmitted when we get around to polling @@ -1350,7 +1362,13 @@ static int conn_write(rlm_radius_udp_connection_t *c, rlm_radius_udp_request_t * if (!c->inst->parent->synchronous) { rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); - if (rr_track_start(u, &u->timer, c->thread->el, response_timeout, u) < 0) { + if (rr_track_start(&u->timer) < 0) { + RDEBUG("Failed starting retransmit tracking"); + return -1; + } + + if (fr_event_timer_insert(u, c->thread->el, &u->timer.ev, &u->timer.next, + response_timeout, u) < 0) { RDEBUG("Failed starting retransmit tracking"); return -1; } @@ -1375,11 +1393,17 @@ static int conn_write(rlm_radius_udp_connection_t *c, rlm_radius_udp_request_t * } else if (u->timer.count == 0) { rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); - if (rr_track_start(u, &u->timer, c->thread->el, status_check_timeout, u) < 0) { + if (rr_track_start(&u->timer) < 0) { RDEBUG("Failed starting retransmit tracking"); return -1; } + if (fr_event_timer_insert(u, c->thread->el, &u->timer.ev, &u->timer.next, + status_check_timeout, u) < 0) { + RDEBUG("Failed starting retransmit tracking"); + return -1; + } + RDEBUG("Sending %s status check. Expecting response within %d.%06ds", fr_packet_codes[u->code], u->timer.rt / USEC, u->timer.rt % USEC); diff --git a/src/modules/rlm_radius/track.c b/src/modules/rlm_radius/track.c index 95f77bd7ca5..25bdd17895f 100644 --- a/src/modules/rlm_radius/track.c +++ b/src/modules/rlm_radius/track.c @@ -381,19 +381,16 @@ void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag) id->use_authenticator = flag; } -int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_retransmit_t *timer, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx, - struct timeval *now) +int rr_track_retry(rlm_radius_retransmit_t *timer, struct timeval *now) { uint32_t delay, frac; - struct timeval next; /* * Get when we SHOULD have woken up, which might not be * the same as 'now'. */ - next = timer->start; - next.tv_usec += timer->rt; + timer->next = timer->start; + timer->next.tv_usec += timer->rt; /* * Increment retransmission counter @@ -463,35 +460,24 @@ int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_retransmit_t *timer, fr_event_lis /* * Get the next delay time. */ - next.tv_usec += timer->rt; - next.tv_sec += (next.tv_usec / USEC); - next.tv_usec %= USEC; - - if (fr_event_timer_insert(ctx, el, &timer->ev, &next, callback, uctx) < 0) { - return -1; - } + timer->next.tv_usec += timer->rt; + timer->next.tv_sec += (timer->next.tv_usec / USEC); + timer->next.tv_usec %= USEC; DEBUG3("RETRANSMIT - in %d.%06ds", timer->rt / USEC, timer->rt % USEC); return 1; } -int rr_track_start(TALLOC_CTX *ctx, rlm_radius_retransmit_t *timer, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx) +int rr_track_start(rlm_radius_retransmit_t *timer) { - struct timeval next; - timer->count = 1; timer->rt = timer->retry->irt * USEC; /* rt is in usec */ - next = timer->start; - next.tv_usec += timer->rt; - next.tv_sec += (next.tv_usec / USEC); - next.tv_usec %= USEC; - - if (fr_event_timer_insert(ctx, el, &timer->ev, &next, callback, uctx) < 0) { - return -1; - } + timer->next = timer->start; + timer->next.tv_usec += timer->rt; + timer->next.tv_sec += (timer->next.tv_usec / USEC); + timer->next.tv_usec %= USEC; return 0; } diff --git a/src/modules/rlm_radius/track.h b/src/modules/rlm_radius/track.h index ec4f79d1ed1..dec38587ee3 100644 --- a/src/modules/rlm_radius/track.h +++ b/src/modules/rlm_radius/track.h @@ -31,6 +31,7 @@ typedef struct rlm_radius_retransmit_t { struct timeval start; //!< when we started sending the packet uint32_t count; //!< how many times we sent this packet uint32_t rt; //!< retransmit timer (microseconds) + struct timeval next; //!< next time the timer should fire fr_event_timer_t const *ev; //!< timer event associated with this packet rlm_radius_retry_t *retry; //!< pointer to retry structure } rlm_radius_retransmit_t; @@ -75,10 +76,7 @@ rlm_radius_request_t *rr_track_find(rlm_radius_id_t *id, int packet_id, uint8_t int rr_track_delete(rlm_radius_id_t *id, rlm_radius_request_t *rr) CC_HINT(nonnull); void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag) CC_HINT(nonnull); -int rr_track_start(TALLOC_CTX *ctx, rlm_radius_retransmit_t *timer, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx) CC_HINT(nonnull); -int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_retransmit_t *timer, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx, - struct timeval *no) CC_HINT(nonnull); +int rr_track_start(rlm_radius_retransmit_t *timer) CC_HINT(nonnull); +int rr_track_retry(rlm_radius_retransmit_t *timer, struct timeval *now) CC_HINT(nonnull); #endif /* _RLM_RADIUS_TRACK_H */