From: Alan T. DeKok Date: Fri, 3 Jun 2011 08:27:11 +0000 (+0200) Subject: Split request_receive() into two functions. X-Git-Tag: release_3_0_0_beta0~783 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88587f704b2b7020725c21b3d91a8057900a4c8d;p=thirdparty%2Ffreeradius-server.git Split request_receive() into two functions. One is for sockets, and enforces limits, duplicates, etc. The other allocates the request and inserts it into the queue, independent of limits. This is called directly by the detail file reader --- diff --git a/src/include/process.h b/src/include/process.h index 61dfeb49175..b100096f24e 100644 --- a/src/include/process.h +++ b/src/include/process.h @@ -52,7 +52,9 @@ int request_enqueue(REQUEST *request); int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet, RADCLIENT *client, RAD_REQUEST_FUNP fun); - +int request_insert(rad_listen_t *listener, RADIUS_PACKET *packet, + RADCLIENT *client, RAD_REQUEST_FUNP fun, + struct timeval *pnow); #ifdef WITH_PROXY int request_proxy_reply(RADIUS_PACKET *packet); #endif diff --git a/src/main/detail.c b/src/main/detail.c index 4a2df792c38..432dcf36570 100644 --- a/src/main/detail.c +++ b/src/main/detail.c @@ -733,7 +733,7 @@ int detail_recv(rad_listen_t *listener) * * Try again later... */ - if (!request_receive(listener, packet, &data->detail_client, + if (!request_insert(listener, packet, &data->detail_client, rad_accounting)) { rad_free(&packet); data->state = STATE_NO_REPLY; /* try again later */ diff --git a/src/main/process.c b/src/main/process.c index efeefc2b423..214064f7445 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -425,6 +425,9 @@ static void request_done(REQUEST *request, int action) case FR_ACTION_DONE: #ifdef DEBUG_STATE_MACHINE if (debug_flag) printf("(%u) ********\tSTATE %s C%u -> C%u\t********\n", request->number, __FUNCTION__, request->child_state, REQUEST_DONE); +#endif +#ifdef HAVE_PTHREAD_H + rad_assert(request->child_pid == NO_SUCH_CHILD_PID); #endif request->child_state = REQUEST_DONE; break; @@ -1187,19 +1190,13 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet, RADIUS_PACKET **packet_p; REQUEST *request = NULL; struct timeval now; + listen_socket_t *sock = listener->data; /* * Set the last packet received. */ gettimeofday(&now, NULL); -#ifdef WITH_DETAIL - if (listener->type != RAD_LISTEN_DETAIL) -#endif - { - listen_socket_t *sock = listener->data; - - sock->last_packet = now.tv_sec; - } + sock->last_packet = now.tv_sec; packet_p = fr_packet_list_find(pl, packet); if (packet_p) { @@ -1254,13 +1251,8 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet, /* * Quench maximum number of outstanding requests. - * - * But we can always read from the detail file. */ if (mainconfig.max_requests && -#ifdef WITH_DETAIL - (listener->type != RAD_LISTEN_DETAIL) && -#endif ((count = fr_packet_list_num_elements(pl)) > mainconfig.max_requests)) { static time_t last_complained = 0; @@ -1281,6 +1273,15 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet, return 0; } + return request_insert(listener, packet, client, fun); +} + +int request_insert(rad_listen_t *listener, RADIUS_PACKET *packet, + RADCLIENT *client, RAD_REQUEST_FUNP fun, + struct timeval *pnow) +{ + REQUEST *request; + /* * Create and initialize the new request. */ @@ -1295,7 +1296,7 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet, request->listener = listener; request->client = client; request->packet = packet; - request->packet->timestamp = now; + request->packet->timestamp = *pnow; request->number = request_num_counter++; request->priority = listener->type; request->master_state = REQUEST_ACTIVE; @@ -2451,6 +2452,9 @@ static void ping_home_server(void *ctx) #ifdef DEBUG_STATE_MACHINE if (debug_flag) printf("(%u) ********\tSTATE %s C%u -> C%u\t********\n", request->number, __FUNCTION__, request->child_state, REQUEST_DONE); if (debug_flag) printf("(%u) ********\tNEXT-STATE %s -> %s\n", request->number, __FUNCTION__, "request_ping"); +#endif +#ifdef HAVE_PTHREAD_H + rad_assert(request->child_pid == NO_SUCH_CHILD_PID); #endif request->child_state = REQUEST_DONE; request->process = request_ping; @@ -2709,6 +2713,9 @@ static void request_proxied(REQUEST *request, int action) gettimeofday(&request->reply->timestamp, NULL); #ifdef DEBUG_STATE_MACHINE if (debug_flag) printf("(%u) ********\tSTATE %s C%u -> C%u\t********\n", request->number, __FUNCTION__, request->child_state, REQUEST_DONE); +#endif +#ifdef HAVE_PTHREAD_H + rad_assert(request->child_pid == NO_SUCH_CHILD_PID); #endif request->child_state = REQUEST_DONE; request_process_timer(request); @@ -3159,7 +3166,6 @@ static void request_coa_process(REQUEST *request, int action) RDEBUG3("%s: Ignoring action %s", __FUNCTION__, action_codes[action]); break; } - } #endif /* WITH_COA */