]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Split request_receive() into two functions.
authorAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2011 08:27:11 +0000 (10:27 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2011 08:27:11 +0000 (10:27 +0200)
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

src/include/process.h
src/main/detail.c
src/main/process.c

index 61dfeb49175dfe7ec3d23d28871bac5e1a9d6c84..b100096f24e1c2795894161fa2674da17085b130 100644 (file)
@@ -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
index 4a2df792c3809adacd745896c507b832e322d5de..432dcf3657015312da575156d6ae6cecb5be4906 100644 (file)
@@ -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 */
index efeefc2b4233a3c75cec5e2a69fbb1617b25376c..214064f7445cce3ebc8c6f19cd012ee6106d1c52 100644 (file)
@@ -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 */