]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move retry into udp_request_t
authorAlan T. DeKok <aland@freeradius.org>
Mon, 2 Oct 2017 15:08:16 +0000 (11:08 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 2 Oct 2017 15:08:16 +0000 (11:08 -0400)
so we can access it when there's no connection

src/modules/rlm_radius/rlm_radius_udp.c
src/modules/rlm_radius/track.c
src/modules/rlm_radius/track.h

index 3e2ed1fe1604da18b42c826dcfefe600b95b9f2c..043ac67770e76ad997307e67229a456e1a176d7e 100644 (file)
@@ -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);
index b610445d136864d33d2a391dec063e4fb1a68d61..021ed1eedc7612064e0a3c89165ecf02180ca8d7 100644 (file)
@@ -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;
index b999a809767254226ad90fc78eb13c89497b507c..125728ad102a092af85a160c5e03ce551bf39420 100644 (file)
@@ -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 */