Delay decoding of packet until we are in the child thread
authorAlan T. DeKok <aland@freeradius.org>
Tue, 1 Jun 2010 08:20:09 +0000 (10:20 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 1 Jun 2010 08:20:09 +0000 (10:20 +0200)
This also delays removing the packet from the proxy hash.  When the server
is busy, this means that the ID's are used for extended periods of time
as compared to 2.1.x.  However, if the server is busy and can't process
existing requests, then it has no business proxying even more packets
upstream.

src/main/event.c

index 4a94d04..5a50410 100644 (file)
@@ -1868,15 +1868,20 @@ static int request_pre_handler(REQUEST *request)
         *      Put the decoded packet into it's proper place.
         */
        if (request->proxy_reply != NULL) {
+               rcode = request->proxy_listener->decode(request->proxy_listener, request);
+               DEBUG_PACKET(request, request->proxy_reply, 0);
+
                /*
-                *      FIXME: For now, we can only proxy RADIUS packets.
-                *
-                *      In order to proxy other packets, we need to
-                *      somehow cache the "decode" function.
+                *      Pro-actively remove it from the proxy hash.
+                *      This is later than in 2.1.x, but it means that
+                *      the replies are authenticated before being
+                *      removed from the hash.
                 */
-               rcode = rad_decode(request->proxy_reply, request->proxy,
-                                  request->home_server->secret);
-               DEBUG_PACKET(request, request->proxy_reply, 0);
+               if ((rcode == 0) &&
+                   (request->num_proxied_requests <= request->num_proxied_responses)) {
+                       remove_from_proxy_hash(request);
+               }
+
        } else
 #endif
        if (request->packet->vps == NULL) {
@@ -3112,7 +3117,7 @@ REQUEST *received_proxy_response(RADIUS_PACKET *packet)
                 *      sockets.
                 *
                 *      We do this AFTER looking the request up in the
-                *      hash, and AFTER vhecking if we saw a previous
+                *      hash, and AFTER checking if we saw a previous
                 *      request.  This helps minimize the DoS effect
                 *      of people attacking us with spoofed packets.
                 *
@@ -3129,20 +3134,6 @@ REQUEST *received_proxy_response(RADIUS_PACKET *packet)
        }
 
        /*
-        *      Now that we know it's a good reply, see if we can
-        *      delete it from the proxy hash.  This lets the source
-        *      ports && Ids be re-used earlier.
-        *
-        *      FIXME: protect by mutex?  This is likely less relevant
-        *      as if we have the reply, the originating thread knows to
-        *      avoid touching the request.  Any retransmits are done from
-        *      the main server thread (i.e. this thread).
-        */
-       if (request->num_proxied_requests <= request->num_proxied_responses) {
-               remove_from_proxy_hash(request);
-       }
-
-       /*
         *      Check (again) if it's a duplicate reply.  We do this
         *      after deleting the packet from the proxy hash.
         */