From: Alan T. DeKok Date: Mon, 2 Oct 2017 15:08:16 +0000 (-0400) Subject: move retry into udp_request_t X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f0bdbd94445ff673002d3b14c92b8aa2ddd5f1b;p=thirdparty%2Ffreeradius-server.git move retry into udp_request_t so we can access it when there's no connection --- diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 3e2ed1fe160..043ac67770e 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -864,8 +864,9 @@ static void status_check_timeout(UNUSED fr_event_list_t *el, struct timeval *now * do that here than to overload conn_write(), which is * already a bit complex. */ + rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); rcode = rr_track_retry(c->id, u->rr, c->thread->el, status_check_timeout, - u, &c->inst->parent->retry[u->code], now); + u, now); if (rcode < 0) { /* * Failed inserting event... the request is done. @@ -1011,7 +1012,8 @@ static void response_timeout(UNUSED fr_event_list_t *el, struct timeval *now, vo rlm_radius_udp_connection_t *c = u->c; REQUEST *request; - rcode = rr_track_retry(c->id, u->rr, c->thread->el, response_timeout, u, &c->inst->parent->retry[u->code], now); + rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); + rcode = rr_track_retry(c->id, u->rr, c->thread->el, response_timeout, u, now); if (rcode < 0) { /* * Failed inserting event... the request is done. @@ -1314,8 +1316,9 @@ static int conn_write(rlm_radius_udp_connection_t *c, rlm_radius_udp_request_t * RDEBUG("Proxying request. Expecting response within %d.%06ds", u->timer.rt / USEC, u->timer.rt % USEC); - if (rr_track_start(c->id, u->rr, c->thread->el, response_timeout, u, - &c->inst->parent->retry[u->code]) < 0) { + rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); + + if (rr_track_start(c->id, u->rr, c->thread->el, response_timeout, u) < 0) { RDEBUG("Failed starting retransmit tracking"); return -1; } @@ -1334,8 +1337,9 @@ static int conn_write(rlm_radius_udp_connection_t *c, rlm_radius_udp_request_t * } } else if (u->timer.count == 0) { - if (rr_track_start(c->id, u->rr, c->thread->el, status_check_timeout, - u, &c->inst->parent->retry[u->code]) < 0) { + rad_assert(u->timer.retry == &c->inst->parent->retry[u->code]); + + if (rr_track_start(c->id, u->rr, c->thread->el, status_check_timeout, u) < 0) { RDEBUG("Failed starting retransmit tracking"); return -1; } @@ -1557,6 +1561,8 @@ static fr_connection_state_t _conn_failed(int fd, fr_connection_state_t state, v rlm_radius_udp_request_t *u = c->status_u; memset(&u->timer, 0, sizeof(u->timer)); + u->timer.retry = &c->inst->parent->retry[u->code]; + rad_assert(u->c == c); if (u->packet) TALLOC_FREE(u->packet); @@ -1737,7 +1743,10 @@ static fr_connection_state_t _conn_open(UNUSED fr_event_list_t *el, UNUSED int f * Reset the timer, retransmission counters, etc. */ if (c->status_u) { - memset(&c->status_u->timer, 0, sizeof(c->status_u->timer)); + rlm_radius_udp_request_t *u = c->status_u; + + memset(&u->timer, 0, sizeof(u->timer)); + u->timer.retry = &c->inst->parent->retry[u->code]; } /* @@ -2012,6 +2021,7 @@ static rlm_radius_udp_connection_t *connection_get(rlm_radius_udp_thread_t *t, r rad_assert(c->state == CONN_ACTIVE); rad_assert(c->num_requests < c->max_requests); + u->timer.retry = &c->inst->parent->retry[u->code]; u->rr = rr_track_alloc(c->id, u->link->request, u->code, u->link, &u->timer); if (!u->rr) { rad_assert(0 == 1); diff --git a/src/modules/rlm_radius/track.c b/src/modules/rlm_radius/track.c index b610445d136..021ed1eedc7 100644 --- a/src/modules/rlm_radius/track.c +++ b/src/modules/rlm_radius/track.c @@ -386,7 +386,7 @@ void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag) } int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx, rlm_radius_retry_t *retry, + fr_event_cb_t callback, void *uctx, struct timeval *now) { uint32_t delay, frac; @@ -407,22 +407,22 @@ int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *e /* * We retried too many times. Fail. */ - if (retry->mrc && (rr->timer->count > retry->mrc)) { - DEBUG3("RETRANSMIT - reached MRC %d", retry->mrc); + if (rr->timer->retry->mrc && (rr->timer->count > rr->timer->retry->mrc)) { + DEBUG3("RETRANSMIT - reached MRC %d", rr->timer->retry->mrc); return 0; } /* * Cap delay at MRD */ - if (retry->mrd) { + if (rr->timer->retry->mrd) { struct timeval end; end = rr->timer->start; - end.tv_sec += retry->mrd; + end.tv_sec += rr->timer->retry->mrd; if (timercmp(now, &end, >=)) { - DEBUG3("RETRANSMIT - reached MRD %d", retry->mrd); + DEBUG3("RETRANSMIT - reached MRD %d", rr->timer->retry->mrd); return 0; } } @@ -445,8 +445,8 @@ int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *e /* * Cap delay at MRT */ - if (retry->mrt && (delay > (retry->mrt * USEC))) { - int mrt_usec = retry->mrt * USEC; + if (rr->timer->retry->mrt && (delay > (rr->timer->retry->mrt * USEC))) { + int mrt_usec = rr->timer->retry->mrt * USEC; /* * delay = MRT + RAND * MRT @@ -481,12 +481,12 @@ int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *e int rr_track_start(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx, rlm_radius_retry_t *retry) + fr_event_cb_t callback, void *uctx) { struct timeval next; rr->timer->count = 1; - rr->timer->rt = retry->irt * USEC; /* rt is in usec */ + rr->timer->rt = rr->timer->retry->irt * USEC; /* rt is in usec */ next = rr->timer->start; next.tv_usec += rr->timer->rt; diff --git a/src/modules/rlm_radius/track.h b/src/modules/rlm_radius/track.h index b999a809767..125728ad102 100644 --- a/src/modules/rlm_radius/track.h +++ b/src/modules/rlm_radius/track.h @@ -32,6 +32,7 @@ typedef struct rlm_radius_retransmit_t { uint32_t count; //!< how many times we sent this packet uint32_t rt; //!< retransmit timer (microseconds) 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; /** Track one request to a response @@ -75,9 +76,9 @@ int rr_track_delete(rlm_radius_id_t *id, rlm_radius_request_t *rr) CC_HINT(nonnu void rr_track_use_authenticator(rlm_radius_id_t *id, bool flag) CC_HINT(nonnull); int rr_track_start(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx, rlm_radius_retry_t *retry) CC_HINT(nonnull); + fr_event_cb_t callback, void *uctx) CC_HINT(nonnull); int rr_track_retry(TALLOC_CTX *ctx, rlm_radius_request_t *rr, fr_event_list_t *el, - fr_event_cb_t callback, void *uctx, rlm_radius_retry_t *retry, + fr_event_cb_t callback, void *uctx, struct timeval *no) CC_HINT(nonnull); #endif /* _RLM_RADIUS_TRACK_H */