From: Alan T. DeKok Date: Thu, 27 Jul 2017 16:07:13 +0000 (-0400) Subject: simplify loop over dlist X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ff7264ca8e61c366770f0bd552a49d3a92a90f2;p=thirdparty%2Ffreeradius-server.git simplify loop over dlist --- diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index e2ecf4c2e3c..69634be63e8 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -292,27 +292,23 @@ static void conn_read(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx) static void conn_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx) { rlm_radius_udp_connection_t *c = talloc_get_type_abort(uctx, rlm_radius_udp_connection_t); - fr_dlist_t *entry, *next; + fr_dlist_t *entry; bool pending; /* * Clear our backlog */ - for (entry = FR_DLIST_FIRST(c->queued); - entry != NULL; - entry = next) { + while ((entry = FR_DLIST_FIRST(c->queued)) != NULL) { rlm_radius_udp_request_t *u; REQUEST *request; ssize_t packet_len; ssize_t rcode; - next = FR_DLIST_NEXT(c->queued, entry); - u = fr_ptr_to_type(rlm_radius_udp_request_t, entry, entry); request = u->link->request; packet_len = fr_radius_encode(c->buffer, c->buflen, NULL, - c->inst->secret, u->rr->id, u->code, u->rr->id, + c->inst->secret, u->rr->id, u->code, 1, request->packet->vps); if (packet_len <= 0) break; @@ -467,7 +463,7 @@ static fr_connection_state_t conn_init(int *fd_out, void *uctx) */ static int conn_free(rlm_radius_udp_connection_t *c) { - fr_dlist_t *entry, *next; + fr_dlist_t *entry; rlm_radius_udp_thread_t *t = c->thread; talloc_free_children(c); /* clears out FD events, timers, etc. */ @@ -475,13 +471,9 @@ static int conn_free(rlm_radius_udp_connection_t *c) /* * Move "sent" packets back to the main thread queue */ - for (entry = FR_DLIST_FIRST(c->sent); - entry != NULL; - entry = next) { + while ((entry = FR_DLIST_FIRST(c->sent)) != NULL) { rlm_radius_udp_request_t *u; - next = FR_DLIST_NEXT(c->sent, entry); - u = fr_ptr_to_type(rlm_radius_udp_request_t, entry, entry); u->rr = NULL; @@ -493,13 +485,9 @@ static int conn_free(rlm_radius_udp_connection_t *c) /* * Move "queued" packets back to the main thread queue */ - for (entry = FR_DLIST_FIRST(c->queued); - entry != NULL; - entry = next) { + while ((entry = FR_DLIST_FIRST(c->queued)) != NULL) { rlm_radius_udp_request_t *u; - next = FR_DLIST_NEXT(c->queued, entry); - u = fr_ptr_to_type(rlm_radius_udp_request_t, entry, entry); u->rr = NULL; @@ -573,6 +561,7 @@ static rlm_radius_udp_connection_t *connection_get(rlm_radius_udp_thread_t *t, r { rlm_radius_udp_connection_t *c; fr_dlist_t *entry; + REQUEST *request; entry = FR_DLIST_FIRST(t->active); if (!entry) return NULL; @@ -585,6 +574,9 @@ static rlm_radius_udp_connection_t *connection_get(rlm_radius_udp_thread_t *t, r u->rr = rr_track_alloc(c->id, u->link->request, u->code, u->link); if (!u->rr) return NULL; + request = u->link->request; + RDEBUG("Allocated ID %d", u->rr->id); + return c; } @@ -606,19 +598,15 @@ static int udp_request_free(rlm_radius_udp_request_t *u) static void mod_clear_backlog(rlm_radius_udp_thread_t *t) { - fr_dlist_t *entry, *next; + fr_dlist_t *entry; entry = FR_DLIST_FIRST(t->active); if (!entry) return; - for (entry = FR_DLIST_FIRST(t->queued); - entry != NULL; - entry = next) { + while ((entry = FR_DLIST_FIRST(t->queued)) != NULL) { rlm_radius_udp_request_t *u; rlm_radius_udp_connection_t *c; - next = FR_DLIST_NEXT(t->queued, entry); - u = fr_ptr_to_type(rlm_radius_udp_request_t, entry, entry); c = connection_get(t, u); if (!c) break;