From: Alan T. DeKok Date: Fri, 16 Mar 2012 15:47:54 +0000 (-0400) Subject: request_proxy_anew MAY get packets which aren't in the proxy hash X-Git-Tag: release_3_0_0_beta0~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd8a8c2101c4c3baac696f95e7026362b43eb1a2;p=thirdparty%2Ffreeradius-server.git request_proxy_anew MAY get packets which aren't in the proxy hash Because the socket got closed due to inactivity, errors, etc. So check for that, and handle that case Also handle the case of request_proxy() getting a request which is already in the proxy hash. --- diff --git a/src/main/process.c b/src/main/process.c index 86a4a7cf621..2301385bfd2 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -2264,7 +2264,7 @@ static int request_proxy(REQUEST *request, int retransmit) /* * We're actually sending a proxied packet. Do that now. */ - if (!insert_into_proxy_hash(request)) { + if (!request->in_proxy_hash && !insert_into_proxy_hash(request)) { radlog_request(L_PROXY, 0, request, "Failed to insert initial packet into the proxy list."); return -1; } @@ -2298,9 +2298,13 @@ static int request_proxy_anew(REQUEST *request) /* * Keep a copy of the old Id so that the * re-transmitted request doesn't re-use the old - * Id. + * Id. Note that in certain cases (socket crash) + * there is no Id as they have been purged from + * proxy_list, but there should still be a leftover + * packet hung off this request. */ RADIUS_PACKET old = *request->proxy; + int old_hash = request->in_proxy_hash; home_server *home; home_server *old_home = request->home_server; #ifdef WITH_TCP @@ -2327,7 +2331,7 @@ static int request_proxy_anew(REQUEST *request) } /* - * Don't free the old Id on error. + * Don't free the old Id (if any) on error. */ if (!insert_into_proxy_hash(request)) { radlog_request(L_PROXY, 0, request, "Failed to insert retransmission into the proxy list."); @@ -2335,16 +2339,18 @@ static int request_proxy_anew(REQUEST *request) } /* - * Now that we have a new Id, free the old one + * Now that we have a new Id, free the old one (if any) * and update the various statistics. */ PTHREAD_MUTEX_LOCK(&proxy_mutex); - fr_packet_list_yank(proxy_list, &old); - fr_packet_list_id_free(proxy_list, &old); - old_home->currently_outstanding--; + if (old_hash) { + fr_packet_list_yank(proxy_list, &old); + fr_packet_list_id_free(proxy_list, &old); + old_home->currently_outstanding--; #ifdef WITH_TCP - if (listener) listener->count--; + if (listener) listener->count--; #endif + } PTHREAD_MUTEX_UNLOCK(&proxy_mutex); /*