2 * event.c Server event handling
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2007 The FreeRADIUS server project
21 * Copyright 2007 Alan DeKok <aland@deployingradius.com>
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/event.h>
30 #include <freeradius-devel/detail.h>
32 #include <freeradius-devel/rad_assert.h>
37 #ifdef HAVE_SYS_WAIT_H
38 # include <sys/wait.h>
41 #define USEC (1000000)
43 extern pid_t radius_pid;
45 extern int check_config;
46 extern void force_log_reopen(void);
47 extern char *debug_condition;
50 * Ridiculous amounts of local state.
52 static fr_event_list_t *el = NULL;
53 static fr_packet_list_t *pl = NULL;
54 static int request_num_counter = 0;
55 static struct timeval now;
57 static int have_children;
58 static int has_detail_listener = FALSE;
59 static int just_started = TRUE;
62 static int self_pipe[2];
67 static pthread_mutex_t proxy_mutex;
70 #define PTHREAD_MUTEX_LOCK if (have_children) pthread_mutex_lock
71 #define PTHREAD_MUTEX_UNLOCK if (have_children) pthread_mutex_unlock
73 static pthread_t NO_SUCH_CHILD_PID;
76 * This is easier than ifdef's throughout the code.
78 #define PTHREAD_MUTEX_LOCK(_x)
79 #define PTHREAD_MUTEX_UNLOCK(_x)
80 int thread_pool_addrequest(REQUEST *request, RAD_REQUEST_FUNP fun)
82 radius_handle_request(request, fun);
87 #define INSERT_EVENT(_function, _ctx) if (!fr_event_insert(el, _function, _ctx, &((_ctx)->when), &((_ctx)->ev))) { _rad_panic(__FILE__, __LINE__, "Failed to insert event"); }
90 static fr_packet_list_t *proxy_list = NULL;
93 * We keep the proxy FD's here. The RADIUS Id's are marked
94 * "allocated" per Id, via a bit per proxy FD.
96 static int proxy_fds[32];
97 static rad_listen_t *proxy_listeners[32];
99 #define remove_from_proxy_hash(foo)
102 static void request_post_handler(REQUEST *request);
103 static void wait_a_bit(void *ctx);
104 static void event_socket_handler(fr_event_list_t *xel, UNUSED int fd, void *ctx);
106 static void NEVER_RETURNS _rad_panic(const char *file, unsigned int line,
109 radlog(L_ERR, "[%s:%d] %s", file, line, msg);
113 #define rad_panic(x) _rad_panic(__FILE__, __LINE__, x)
116 static void tv_add(struct timeval *tv, int usec_delay)
118 if (usec_delay > USEC) {
119 tv->tv_sec += usec_delay / USEC;
122 tv->tv_usec += usec_delay;
124 if (tv->tv_usec > USEC) {
130 static void remove_from_request_hash(REQUEST *request)
132 if (!request->in_request_hash) return;
134 fr_packet_list_yank(pl, request->packet);
135 request->in_request_hash = FALSE;
137 request_stats_final(request);
142 static REQUEST *lookup_in_proxy_hash(RADIUS_PACKET *reply)
144 RADIUS_PACKET **proxy_p;
147 PTHREAD_MUTEX_LOCK(&proxy_mutex);
148 proxy_p = fr_packet_list_find_byreply(proxy_list, reply);
151 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
155 request = fr_packet2myptr(REQUEST, proxy, proxy_p);
158 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
162 request->num_proxied_responses++;
165 * Catch the most common case of everything working
168 if (request->num_proxied_requests == request->num_proxied_responses) {
169 fr_packet_list_yank(proxy_list, request->proxy);
170 fr_packet_list_id_free(proxy_list, request->proxy);
171 request->in_proxy_hash = FALSE;
175 * On the FIRST reply, decrement the count of outstanding
176 * requests. Note that this is NOT the count of sent
177 * packets, but whether or not the home server has
180 if (!request->proxy_reply &&
181 request->home_server->currently_outstanding) {
182 request->home_server->currently_outstanding--;
185 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
191 static void remove_from_proxy_hash(REQUEST *request)
193 if (!request->in_proxy_hash) return;
195 PTHREAD_MUTEX_LOCK(&proxy_mutex);
196 fr_packet_list_yank(proxy_list, request->proxy);
197 fr_packet_list_id_free(proxy_list, request->proxy);
200 * The home server hasn't replied, but we've given up on
201 * this request. Don't count this request against the
204 if (!request->proxy_reply &&
205 request->home_server->currently_outstanding) {
206 request->home_server->currently_outstanding--;
209 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
211 request->in_proxy_hash = FALSE;
215 static int insert_into_proxy_hash(REQUEST *request)
220 rad_assert(request->proxy != NULL);
221 rad_assert(proxy_list != NULL);
223 request->proxy->sockfd = -1;
225 PTHREAD_MUTEX_LOCK(&proxy_mutex);
227 request->home_server->currently_outstanding++;
229 if (!fr_packet_list_id_alloc(proxy_list, request->proxy)) {
231 rad_listen_t *proxy_listener;
234 * Allocate a new proxy fd. This function adds
235 * it to the tail of the list of listeners. With
236 * some care, this can be thread-safe.
238 proxy_listener = proxy_new_listener();
239 if (!proxy_listener) {
240 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
241 RDEBUG2("ERROR: Failed to create a new socket for proxying requests.");
249 proxy = proxy_listener->fd;
250 for (i = 0; i < 32; i++) {
252 * Found a free entry. Save the socket,
253 * and remember where we saved it.
255 if (proxy_fds[(proxy + i) & 0x1f] == -1) {
256 found = (proxy + i) & 0x1f;
257 proxy_fds[found] = proxy;
258 proxy_listeners[found] = proxy_listener;
262 rad_assert(found >= 0);
264 if (!fr_packet_list_socket_add(proxy_list, proxy_listener->fd)) {
265 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
266 RDEBUG2("ERROR: Failed to create a new socket for proxying requests.");
271 if (!fr_packet_list_id_alloc(proxy_list, request->proxy)) {
272 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
273 RDEBUG2("ERROR: Failed to create a new socket for proxying requests.");
278 * Signal the main thread to add the new FD to the list
281 radius_signal_self(RADIUS_SIGNAL_SELF_NEW_FD);
283 rad_assert(request->proxy->sockfd >= 0);
286 * FIXME: Hack until we get rid of rad_listen_t, and put
287 * the information into the packet_list.
290 for (i = 0; i < 32; i++) {
291 if (proxy_fds[i] == request->proxy->sockfd) {
298 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
299 RDEBUG2("ERROR: All sockets are full.");
303 rad_assert(proxy_fds[proxy] != -1);
304 rad_assert(proxy_listeners[proxy] != NULL);
305 request->proxy_listener = proxy_listeners[proxy];
307 if (!fr_packet_list_insert(proxy_list, &request->proxy)) {
308 fr_packet_list_id_free(proxy_list, request->proxy);
309 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
310 RDEBUG2("ERROR: Failed to insert entry into proxy list");
314 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
316 RDEBUG3(" proxy: allocating destination %s port %d - Id %d",
317 inet_ntop(request->proxy->dst_ipaddr.af,
318 &request->proxy->dst_ipaddr.ipaddr, buf, sizeof(buf)),
319 request->proxy->dst_port,
322 request->in_proxy_hash = TRUE;
329 * Called as BOTH an event, and in-line from other functions.
331 static void wait_for_proxy_id_to_expire(void *ctx)
333 REQUEST *request = ctx;
334 home_server *home = request->home_server;
336 rad_assert(request->magic == REQUEST_MAGIC);
337 rad_assert(request->proxy != NULL);
339 if (!fr_event_now(el, &now)) gettimeofday(&now, NULL);
340 request->when = request->proxy_when;
341 request->when.tv_sec += home->response_window;
343 if ((request->num_proxied_requests == request->num_proxied_responses) ||
344 timercmp(&now, &request->when, >)) {
345 if (request->packet) {
346 RDEBUG2("Cleaning up request %d ID %d with timestamp +%d",
347 request->number, request->packet->id,
348 (unsigned int) (request->timestamp - fr_start_time));
350 RDEBUG2("Cleaning up request %d with timestamp +%d",
352 (unsigned int) (request->timestamp - fr_start_time));
354 fr_event_delete(el, &request->ev);
355 remove_from_proxy_hash(request);
356 remove_from_request_hash(request);
357 request_free(&request);
361 INSERT_EVENT(wait_for_proxy_id_to_expire, request);
365 #ifdef HAVE_PTHREAD_H
366 static void wait_for_child_to_die(void *ctx)
368 REQUEST *request = ctx;
370 rad_assert(request->magic == REQUEST_MAGIC);
372 if ((request->child_state == REQUEST_QUEUED) |
373 (request->child_state == REQUEST_RUNNING)) {
374 request->delay += (request->delay >> 1);
375 tv_add(&request->when, request->delay);
377 RDEBUG2("Child is still stuck for request %d", request->number);
379 INSERT_EVENT(wait_for_child_to_die, request);
383 RDEBUG2("Child is finally responsive for request %d", request->number);
384 remove_from_request_hash(request);
387 if (request->proxy) {
388 wait_for_proxy_id_to_expire(request);
393 request_free(&request);
397 static void cleanup_delay(void *ctx)
399 REQUEST *request = ctx;
401 rad_assert(request->magic == REQUEST_MAGIC);
402 rad_assert((request->child_state == REQUEST_CLEANUP_DELAY) ||
403 (request->child_state == REQUEST_DONE));
405 remove_from_request_hash(request);
408 if (request->proxy && request->in_proxy_hash) {
409 wait_for_proxy_id_to_expire(request);
414 RDEBUG2("Cleaning up request %d ID %d with timestamp +%d",
415 request->number, request->packet->id,
416 (unsigned int) (request->timestamp - fr_start_time));
418 fr_event_delete(el, &request->ev);
419 request_free(&request);
424 * FIXME: Put into a libradius function.
426 #define MAX_PACKET_CODE (52)
427 static const char *packet_codes[] = {
432 "Accounting-Request",
433 "Accounting-Response",
438 "Accounting-Message",
449 "Resource-Free-Request",
450 "Resource-Free-Response",
451 "Resource-Query-Request",
452 "Resource-Query-Response",
453 "Alternate-Resource-Reclaim-Request",
454 "NAS-Reboot-Request",
455 "NAS-Reboot-Response",
468 "Disconnect-Request",
478 "IP-Address-Allocate",
484 * In daemon mode, AND this request has debug flags set.
486 #define DEBUG_PACKET if (!debug_flag && request->options) debug_packet
488 static void debug_packet(REQUEST *request, RADIUS_PACKET *packet, int direction)
492 const char *received, *from;
493 const fr_ipaddr_t *ip;
498 if (direction == 0) {
499 received = "Received";
500 from = "from"; /* what else? */
501 ip = &packet->src_ipaddr;
502 port = packet->src_port;
505 received = "Sending";
506 from = "to"; /* hah! */
507 ip = &packet->dst_ipaddr;
508 port = packet->dst_port;
512 * Client-specific debugging re-prints the input
513 * packet into the client log.
515 * This really belongs in a utility library
517 if ((packet->code > 0) && (packet->code < MAX_PACKET_CODE)) {
518 RDEBUG("%s %s packet %s host %s port %d, id=%d, length=%d",
519 received, packet_codes[packet->code], from,
520 inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)),
521 port, packet->id, packet->data_len);
523 RDEBUG("%s packet %s host %s port %d code=%d, id=%d, length=%d",
525 inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)),
527 packet->code, packet->id, packet->data_len);
530 for (vp = packet->vps; vp != NULL; vp = vp->next) {
531 vp_prints(buffer, sizeof(buffer), vp);
532 request->radlog(L_DBG, 0, request, "\t%s", buffer);
536 static void reject_delay(void *ctx)
538 REQUEST *request = ctx;
540 rad_assert(request->magic == REQUEST_MAGIC);
541 rad_assert(request->child_state == REQUEST_REJECT_DELAY);
543 RDEBUG2("Sending delayed reject for request %d", request->number);
545 if (!debug_flag && request->options) {
546 debug_packet(request, request->reply, 1);
548 request->listener->send(request->listener, request);
550 request->when.tv_sec += request->root->cleanup_delay;
551 request->child_state = REQUEST_CLEANUP_DELAY;
553 INSERT_EVENT(cleanup_delay, request);
558 static void revive_home_server(void *ctx)
560 home_server *home = ctx;
563 home->state = HOME_STATE_ALIVE;
564 radlog(L_INFO, "PROXY: Marking home server %s port %d alive again... we have no idea if it really is alive or not.",
565 inet_ntop(home->ipaddr.af, &home->ipaddr.ipaddr,
566 buffer, sizeof(buffer)),
568 home->currently_outstanding = 0;
569 home->revive_time = now;
573 static void no_response_to_ping(void *ctx)
575 REQUEST *request = ctx;
576 home_server *home = request->home_server;
579 home->num_received_pings = 0;
581 RDEBUG2("No response to status check %d from home server %s port %d",
583 inet_ntop(request->proxy->dst_ipaddr.af,
584 &request->proxy->dst_ipaddr.ipaddr,
585 buffer, sizeof(buffer)),
586 request->proxy->dst_port);
588 wait_for_proxy_id_to_expire(request);
592 static void received_response_to_ping(REQUEST *request)
594 home_server *home = request->home_server;
597 home->num_received_pings++;
599 RDEBUG2("Received response to status check %d (%d in current sequence)",
600 request->number, home->num_received_pings);
602 if (home->num_received_pings < home->num_pings_to_alive) {
603 wait_for_proxy_id_to_expire(request);
607 radlog(L_INFO, "PROXY: Marking home server %s port %d alive",
608 inet_ntop(request->proxy->dst_ipaddr.af,
609 &request->proxy->dst_ipaddr.ipaddr,
610 buffer, sizeof(buffer)),
611 request->proxy->dst_port);
613 if (!fr_event_delete(el, &home->ev)) {
614 RDEBUG2("Hmm... no event for home server, WTF?");
617 if (!fr_event_delete(el, &request->ev)) {
618 RDEBUG2("Hmm... no event for request, WTF?");
621 wait_for_proxy_id_to_expire(request);
623 home->state = HOME_STATE_ALIVE;
624 home->currently_outstanding = 0;
625 home->revive_time = now;
629 static void ping_home_server(void *ctx)
632 home_server *home = ctx;
636 if (home->state == HOME_STATE_ALIVE) {
637 radlog(L_INFO, "Suspicious proxy state... continuing");
641 request = request_alloc();
642 request->number = request_num_counter++;
644 request->proxy = rad_alloc(1);
645 rad_assert(request->proxy != NULL);
647 fr_event_now(el, &request->when);
648 home->when = request->when;
650 if (home->ping_check == HOME_PING_CHECK_STATUS_SERVER) {
651 request->proxy->code = PW_STATUS_SERVER;
653 radius_pairmake(request, &request->proxy->vps,
654 "Message-Authenticator", "0x00", T_OP_SET);
656 } else if (home->type == HOME_TYPE_AUTH) {
657 request->proxy->code = PW_AUTHENTICATION_REQUEST;
659 radius_pairmake(request, &request->proxy->vps,
660 "User-Name", home->ping_user_name, T_OP_SET);
661 radius_pairmake(request, &request->proxy->vps,
662 "User-Password", home->ping_user_password, T_OP_SET);
663 radius_pairmake(request, &request->proxy->vps,
664 "Service-Type", "Authenticate-Only", T_OP_SET);
665 radius_pairmake(request, &request->proxy->vps,
666 "Message-Authenticator", "0x00", T_OP_SET);
669 #ifdef WITH_ACCOUNTING
670 request->proxy->code = PW_ACCOUNTING_REQUEST;
672 radius_pairmake(request, &request->proxy->vps,
673 "User-Name", home->ping_user_name, T_OP_SET);
674 radius_pairmake(request, &request->proxy->vps,
675 "Acct-Status-Type", "Stop", T_OP_SET);
676 radius_pairmake(request, &request->proxy->vps,
677 "Acct-Session-Id", "00000000", T_OP_SET);
678 vp = radius_pairmake(request, &request->proxy->vps,
679 "Event-Timestamp", "0", T_OP_SET);
680 vp->vp_date = now.tv_sec;
682 rad_assert("Internal sanity check failed");
686 radius_pairmake(request, &request->proxy->vps,
687 "NAS-Identifier", "Status Check. Are you alive?",
690 request->proxy->dst_ipaddr = home->ipaddr;
691 request->proxy->dst_port = home->port;
692 request->home_server = home;
694 rad_assert(request->proxy_listener == NULL);
696 if (!insert_into_proxy_hash(request)) {
697 RDEBUG2("ERROR: Failed inserting status check %d into proxy hash. Discarding it.",
699 request_free(&request);
702 rad_assert(request->proxy_listener != NULL);
703 request->proxy_listener->send(request->proxy_listener,
706 request->next_callback = NULL;
707 request->child_state = REQUEST_PROXIED;
708 request->when.tv_sec += home->ping_timeout;;
710 INSERT_EVENT(no_response_to_ping, request);
713 * Add +/- 2s of jitter, as suggested in RFC 3539
714 * and in the Issues and Fixes draft.
716 home->when.tv_sec += home->ping_interval - 2;
719 jitter ^= (jitter >> 10);
720 jitter &= ((1 << 23) - 1); /* 22 bits of 1 */
722 tv_add(&home->when, jitter);
725 INSERT_EVENT(ping_home_server, home);
729 static void check_for_zombie_home_server(REQUEST *request)
735 home = request->home_server;
737 if (home->state != HOME_STATE_ZOMBIE) return;
739 when = home->zombie_period_start;
740 when.tv_sec += home->zombie_period;
742 fr_event_now(el, &now);
743 if (timercmp(&now, &when, <)) {
748 * It's been a zombie for too long, mark it as
751 radlog(L_INFO, "PROXY: Marking home server %s port %d as dead.",
752 inet_ntop(request->proxy->dst_ipaddr.af,
753 &request->proxy->dst_ipaddr.ipaddr,
754 buffer, sizeof(buffer)),
755 request->proxy->dst_port);
756 home->state = HOME_STATE_IS_DEAD;
757 home->num_received_pings = 0;
758 home->when = request->when;
760 if (home->ping_check != HOME_PING_CHECK_NONE) {
761 rad_assert((home->ping_check == HOME_PING_CHECK_STATUS_SERVER) ||
762 (home->ping_user_name != NULL));
763 home->when.tv_sec += home->ping_interval;
765 INSERT_EVENT(ping_home_server, home);
767 home->when.tv_sec += home->revive_interval;
769 INSERT_EVENT(revive_home_server, home);
773 static int proxy_to_virtual_server(REQUEST *request);
775 static int virtual_server_handler(UNUSED REQUEST *request)
777 proxy_to_virtual_server(request);
781 static void proxy_fallback_handler(REQUEST *request)
784 * A proper time is required for wait_a_bit.
786 request->delay = USEC / 10;
787 gettimeofday(&now, NULL);
788 request->next_when = now;
789 tv_add(&request->next_when, request->delay);
790 request->next_callback = wait_a_bit;
793 * Re-queue the request.
795 request->child_state = REQUEST_QUEUED;
797 rad_assert(request->proxy != NULL);
798 if (!thread_pool_addrequest(request, virtual_server_handler)) {
799 request->child_state = REQUEST_DONE;
802 #ifdef HAVE_PTHREAD_H
804 * MAY free the request if we're over max_request_time,
805 * AND we're not in threaded mode!
807 * Note that we call this ONLY if we're threaded, as
808 * if we're NOT threaded, request_post_handler() calls
809 * wait_a_bit(), which means that "request" may not
812 if (have_children) wait_a_bit(request);
817 static int setup_post_proxy_fail(REQUEST *request)
819 DICT_VALUE *dval = NULL;
822 if (request->packet->code == PW_AUTHENTICATION_REQUEST) {
823 dval = dict_valbyname(PW_POST_PROXY_TYPE, "Fail-Authentication");
825 } else if (request->packet->code == PW_ACCOUNTING_REQUEST) {
826 dval = dict_valbyname(PW_POST_PROXY_TYPE, "Fail-Accounting");
832 if (!dval) dval = dict_valbyname(PW_POST_PROXY_TYPE, "Fail");
835 pairdelete(&request->config_items, PW_POST_PROXY_TYPE);
839 vp = pairfind(request->config_items, PW_POST_PROXY_TYPE);
840 if (!vp) vp = radius_paircreate(request, &request->config_items,
841 PW_POST_PROXY_TYPE, PW_TYPE_INTEGER);
842 vp->vp_integer = dval->value;
844 rad_assert(request->proxy_reply == NULL);
850 static int null_handler(UNUSED REQUEST *request)
855 static void post_proxy_fail_handler(REQUEST *request)
858 * A proper time is required for wait_a_bit.
860 request->delay = USEC / 10;
861 gettimeofday(&now, NULL);
864 * Not set up to run Post-Proxy-Type = Fail.
866 * Mark the request as still running, and figure out what
869 if (!setup_post_proxy_fail(request)) {
870 request->child_state = REQUEST_RUNNING;
871 request_post_handler(request);
875 * Re-queue the request.
877 request->child_state = REQUEST_QUEUED;
880 * There is a post-proxy-type of fail. We run
881 * the request through the pre/post proxy
882 * handlers, just like it was a real proxied
883 * request. However, we set the per-request
884 * handler to NULL, as we don't want to do
887 * Note that when we're not threaded, this will
888 * process the request even if it's greater than
889 * max_request_time. That's not fatal.
891 request->priority = 0;
892 rad_assert(request->proxy != NULL);
893 thread_pool_addrequest(request, null_handler);
897 * MAY free the request if we're over max_request_time,
898 * AND we're not in threaded mode!
900 * Note that we call this ONLY if we're threaded, as
901 * if we're NOT threaded, request_post_handler() calls
902 * wait_a_bit(), which means that "request" may not
905 if (have_children) wait_a_bit(request);
909 /* maybe check this against wait_for_proxy_id_to_expire? */
910 static void no_response_to_proxied_request(void *ctx)
912 REQUEST *request = ctx;
916 rad_assert(request->magic == REQUEST_MAGIC);
917 rad_assert(request->child_state == REQUEST_PROXIED);
920 * If we've failed over to an internal home server,
921 * replace the callback with the correct one. This
922 * is due to locking issues with child threads...
924 if (request->home_server->server) {
929 radlog(L_ERR, "Rejecting request %d due to lack of any response from home server %s port %d",
931 inet_ntop(request->proxy->dst_ipaddr.af,
932 &request->proxy->dst_ipaddr.ipaddr,
933 buffer, sizeof(buffer)),
934 request->proxy->dst_port);
936 check_for_zombie_home_server(request);
938 home = request->home_server;
940 post_proxy_fail_handler(request);
943 * Don't touch request due to race conditions
945 if (home->state == HOME_STATE_IS_DEAD) {
946 rad_assert(home->ev != NULL); /* or it will never wake up */
951 * Enable the zombie period when we notice that the home
952 * server hasn't responded. We also back-date the start
953 * of the zombie period to when the proxied request was
956 if (home->state == HOME_STATE_ALIVE) {
957 radlog(L_ERR, "PROXY: Marking home server %s port %d as zombie (it looks like it is dead).",
958 inet_ntop(home->ipaddr.af, &home->ipaddr.ipaddr,
959 buffer, sizeof(buffer)),
961 home->state = HOME_STATE_ZOMBIE;
962 home->zombie_period_start = now;
963 home->zombie_period_start.tv_sec -= home->response_window;
969 static void wait_a_bit(void *ctx)
972 REQUEST *request = ctx;
973 fr_event_callback_t callback = NULL;
975 rad_assert(request->magic == REQUEST_MAGIC);
977 switch (request->child_state) {
979 case REQUEST_RUNNING:
980 when = request->received;
981 when.tv_sec += request->root->max_request_time;
984 * Normally called from the event loop with the
985 * proper event loop time. Otherwise, called from
986 * post proxy fail handler, which sets "now", and
987 * this call won't re-set it, because we're not
990 fr_event_now(el, &now);
993 * Request still has more time. Continue
996 if (timercmp(&now, &when, <) ||
997 ((request->listener->type == RAD_LISTEN_DETAIL) &&
998 (request->child_state == REQUEST_QUEUED))) {
999 if (request->delay < (USEC / 10)) {
1000 request->delay = USEC / 10;
1002 request->delay += request->delay >> 1;
1006 * Cap wait at some sane value for detail
1009 if ((request->listener->type == RAD_LISTEN_DETAIL) &&
1010 (request->delay > (request->root->max_request_time * USEC))) {
1011 request->delay = request->root->max_request_time * USEC;
1015 request->when = now;
1016 tv_add(&request->when, request->delay);
1017 callback = wait_a_bit;
1021 #if defined(HAVE_PTHREAD_H) || defined(WITH_PROXY)
1023 * A child thread MAY still be running on the
1024 * request. Ask the thread to stop working on
1027 if (have_children) {
1028 /* FIXME: kill unresponsive children? */
1031 * Print this error message ONLY if
1032 * there's a child currently processing
1033 * the request. As we don't have thread
1034 * locks here, there may be race
1035 * conditions on this check. But it's
1036 * just an error message, so that's OK.
1038 if (!pthread_equal(request->child_pid, NO_SUCH_CHILD_PID)) {
1039 radlog(L_ERR, "WARNING: Unresponsive child for request %d, in module %s component %s",
1041 request->module ? request->module : "<server core>",
1042 request->component ? request->component : "<server core>");
1045 request->master_state = REQUEST_STOP_PROCESSING;
1047 request->delay = USEC / 4;
1048 tv_add(&request->when, request->delay);
1049 callback = wait_for_child_to_die;
1055 * Else there are no child threads. We probably
1056 * should have just marked the request as 'done'
1057 * elsewhere, like in the post-proxy-fail
1058 * handler. But doing that would involve
1059 * checking for max_request_time in multiple
1060 * places, so this may be simplest.
1062 request->child_state = REQUEST_DONE;
1066 * Mark the request as no longer running,
1070 #ifdef HAVE_PTHREAD_H
1071 request->child_pid = NO_SUCH_CHILD_PID;
1073 request_stats_final(request);
1074 cleanup_delay(request);
1077 case REQUEST_REJECT_DELAY:
1078 case REQUEST_CLEANUP_DELAY:
1079 #ifdef HAVE_PTHREAD_H
1080 request->child_pid = NO_SUCH_CHILD_PID;
1082 request_stats_final(request);
1084 case REQUEST_PROXIED:
1085 rad_assert(request->next_callback != NULL);
1086 rad_assert(request->next_callback != wait_a_bit);
1088 request->when = request->next_when;
1089 callback = request->next_callback;
1090 request->next_callback = NULL;
1094 rad_panic("Internal sanity check failure");
1099 * Something major went wrong. Discard the request, and
1102 * FIXME: No idea why this happens or how to fix it...
1103 * It seems to happen *only* when requests are proxied,
1104 * and where the home server doesn't respond. So it looks
1105 * like a race condition above, but it happens in debug
1106 * mode, with no threads...
1109 RDEBUG("WARNING: Internal sanity check failed in event handler for request %d: Discarding the request!", request->number);
1110 fr_event_delete(el, &request->ev);
1111 remove_from_proxy_hash(request);
1112 remove_from_request_hash(request);
1113 request_free(&request);
1117 INSERT_EVENT(callback, request);
1122 static int process_proxy_reply(REQUEST *request)
1125 int post_proxy_type = 0;
1129 * Delete any reply we had accumulated until now.
1131 pairfree(&request->reply->vps);
1134 * Run the packet through the post-proxy stage,
1135 * BEFORE playing games with the attributes.
1137 vp = pairfind(request->config_items, PW_POST_PROXY_TYPE);
1139 RDEBUG2(" Found Post-Proxy-Type %s", vp->vp_strvalue);
1140 post_proxy_type = vp->vp_integer;
1143 rad_assert(request->home_pool != NULL);
1145 if (request->home_pool->virtual_server) {
1146 const char *old_server = request->server;
1148 request->server = request->home_pool->virtual_server;
1149 RDEBUG2(" server %s {", request->server);
1150 rcode = module_post_proxy(post_proxy_type, request);
1152 request->server = old_server;
1154 rcode = module_post_proxy(post_proxy_type, request);
1158 * There may NOT be a proxy reply, as we may be
1159 * running Post-Proxy-Type = Fail.
1161 if (request->proxy_reply) {
1163 * Delete the Proxy-State Attributes from
1164 * the reply. These include Proxy-State
1165 * attributes from us and remote server.
1167 pairdelete(&request->proxy_reply->vps, PW_PROXY_STATE);
1170 * Add the attributes left in the proxy
1171 * reply to the reply list.
1173 pairadd(&request->reply->vps, request->proxy_reply->vps);
1174 request->proxy_reply->vps = NULL;
1177 * Free proxy request pairs.
1179 pairfree(&request->proxy->vps);
1183 default: /* Don't do anything */
1185 case RLM_MODULE_FAIL:
1186 /* FIXME: debug print stuff */
1187 request->child_state = REQUEST_DONE;
1190 case RLM_MODULE_HANDLED:
1191 /* FIXME: debug print stuff */
1192 request->child_state = REQUEST_DONE;
1200 static int request_pre_handler(REQUEST *request)
1204 rad_assert(request->magic == REQUEST_MAGIC);
1205 rad_assert(request->packet != NULL);
1207 request->child_state = REQUEST_RUNNING;
1210 * Don't decode the packet if it's an internal "fake"
1211 * request. Instead, just return so that the caller can
1214 if (request->packet->dst_port == 0) {
1215 request->username = pairfind(request->packet->vps,
1217 request->password = pairfind(request->packet->vps,
1224 * Put the decoded packet into it's proper place.
1226 if (request->proxy_reply != NULL) {
1227 rcode = request->proxy_listener->decode(request->proxy_listener,
1229 DEBUG_PACKET(request, request->proxy_reply, 0);
1232 if (request->packet->vps == NULL) {
1233 rcode = request->listener->decode(request->listener, request);
1235 if (debug_condition) {
1239 * Ignore parse errors.
1241 radius_evaluate_condition(request, RLM_MODULE_OK, 0,
1242 &debug_condition, 1,
1245 request->priority = 2;
1246 request->radlog = radlog_request;
1250 DEBUG_PACKET(request, request->packet, 0);
1256 radlog(L_ERR, "%s Dropping packet without response.", fr_strerror());
1257 request->child_state = REQUEST_DONE;
1262 if (!request->proxy)
1265 request->username = pairfind(request->packet->vps,
1270 return process_proxy_reply(request);
1280 * Do state handling when we proxy a request.
1282 static int proxy_request(REQUEST *request)
1284 struct timeval when;
1287 if (request->home_server->server) {
1288 RDEBUG("ERROR: Cannot perform real proxying to a virtual server.");
1292 if (!insert_into_proxy_hash(request)) {
1293 RDEBUG("ERROR: Failed inserting request into proxy hash.");
1297 request->proxy_listener->encode(request->proxy_listener, request);
1299 when = request->received;
1300 when.tv_sec += request->root->max_request_time;
1302 gettimeofday(&request->proxy_when, NULL);
1304 request->next_when = request->proxy_when;
1305 request->next_when.tv_sec += request->home_server->response_window;
1307 rad_assert(request->home_server->response_window > 0);
1309 if (timercmp(&when, &request->next_when, <)) {
1310 request->next_when = when;
1312 request->next_callback = no_response_to_proxied_request;
1314 RDEBUG2("Proxying request %d to home server %s port %d",
1316 inet_ntop(request->proxy->dst_ipaddr.af,
1317 &request->proxy->dst_ipaddr.ipaddr,
1318 buffer, sizeof(buffer)),
1319 request->proxy->dst_port);
1322 * Note that we set proxied BEFORE sending the packet.
1324 * Once we send it, the request is tainted, as
1325 * another thread may have picked it up. Don't
1328 request->num_proxied_requests = 1;
1329 request->num_proxied_responses = 0;
1330 #ifdef HAVE_PTHREAD_H
1331 request->child_pid = NO_SUCH_CHILD_PID;
1333 request->child_state = REQUEST_PROXIED;
1335 if (!debug_flag && request->options) {
1336 debug_packet(request, request->proxy, 1);
1339 request->proxy_listener->send(request->proxy_listener,
1346 * "Proxy" the request by sending it to a new virtual server.
1348 static int proxy_to_virtual_server(REQUEST *request)
1351 RAD_REQUEST_FUNP fun;
1353 if (!request->home_server || !request->home_server->server) return 0;
1355 if (request->parent) {
1356 RDEBUG2("WARNING: Cancelling proxy request to virtual server %s as this request was itself proxied.", request->home_server->server);
1360 fake = request_alloc_fake(request);
1362 RDEBUG2("WARNING: Out of memory");
1366 fake->packet->vps = paircopy(request->proxy->vps);
1367 fake->server = request->home_server->server;
1369 if (request->proxy->code == PW_AUTHENTICATION_REQUEST) {
1370 fun = rad_authenticate;
1372 #ifdef WITH_ACCOUNTING
1373 } else if (request->proxy->code == PW_ACCOUNTING_REQUEST) {
1374 fun = rad_accounting;
1378 RDEBUG2("Unknown packet type %d", request->proxy->code);
1382 RDEBUG2(">>> Sending proxied request internally to virtual server.");
1383 radius_handle_request(fake, fun);
1384 RDEBUG2("<<< Received proxied response from internal virtual server.");
1386 request->proxy_reply = fake->reply;
1389 request_free(&fake);
1391 process_proxy_reply(request);
1394 return 2; /* success, but NOT '1' !*/
1399 * Return 1 if we did proxy it, or the proxy attempt failed
1400 * completely. Either way, the caller doesn't touch the request
1401 * any more if we return 1.
1403 static int successfully_proxied_request(REQUEST *request)
1406 int pre_proxy_type = 0;
1407 VALUE_PAIR *realmpair;
1408 VALUE_PAIR *strippedname;
1412 REALM *realm = NULL;
1416 * If it was already proxied, do nothing.
1418 * FIXME: This should really be a serious error.
1420 if (request->in_proxy_hash) {
1424 realmpair = pairfind(request->config_items, PW_PROXY_TO_REALM);
1425 if (!realmpair || (realmpair->length == 0)) {
1429 realmname = (char *) realmpair->vp_strvalue;
1431 realm = realm_find2(realmname);
1433 RDEBUG2("ERROR: Cannot proxy to unknown realm %s", realmname);
1438 * Figure out which pool to use.
1440 if (request->packet->code == PW_AUTHENTICATION_REQUEST) {
1441 pool = realm->auth_pool;
1443 #ifdef WITH_ACCOUNTING
1444 } else if (request->packet->code == PW_ACCOUNTING_REQUEST) {
1445 pool = realm->acct_pool;
1449 rad_panic("Internal sanity check failed");
1453 RDEBUG2(" WARNING: Cancelling proxy to Realm %s, as the realm is local.",
1458 home = home_server_ldb(realmname, pool, request);
1460 RDEBUG2("ERROR: Failed to find live home server for realm %s",
1464 request->home_pool = pool;
1467 * Remember that we sent the request to a Realm.
1469 pairadd(&request->packet->vps,
1470 pairmake("Realm", realmname, T_OP_EQ));
1474 * We read the packet from a detail file, AND it came from
1475 * the server we're about to send it to. Don't do that.
1477 if ((request->packet->code == PW_ACCOUNTING_REQUEST) &&
1478 (request->listener->type == RAD_LISTEN_DETAIL) &&
1479 (home->ipaddr.af == AF_INET) &&
1480 (request->packet->src_ipaddr.af == AF_INET) &&
1481 (home->ipaddr.ipaddr.ip4addr.s_addr == request->packet->src_ipaddr.ipaddr.ip4addr.s_addr)) {
1482 RDEBUG2(" rlm_realm: Packet came from realm %s, proxy cancelled", realmname);
1488 * Allocate the proxy packet, only if it wasn't already
1489 * allocated by a module. This check is mainly to support
1490 * the proxying of EAP-TTLS and EAP-PEAP tunneled requests.
1492 * In those cases, the EAP module creates a "fake"
1493 * request, and recursively passes it through the
1494 * authentication stage of the server. The module then
1495 * checks if the request was supposed to be proxied, and
1496 * if so, creates a proxy packet from the TUNNELED request,
1497 * and not from the EAP request outside of the tunnel.
1499 * The proxy then works like normal, except that the response
1500 * packet is "eaten" by the EAP module, and encapsulated into
1503 if (!request->proxy) {
1504 if ((request->proxy = rad_alloc(TRUE)) == NULL) {
1505 radlog(L_ERR|L_CONS, "no memory");
1510 * Copy the request, then look up name and
1511 * plain-text password in the copy.
1513 * Note that the User-Name attribute is the
1514 * *original* as sent over by the client. The
1515 * Stripped-User-Name attribute is the one hacked
1516 * through the 'hints' file.
1518 request->proxy->vps = paircopy(request->packet->vps);
1522 * Strip the name, if told to.
1524 * Doing it here catches the case of proxied tunneled
1527 if (realm->striprealm == TRUE &&
1528 (strippedname = pairfind(request->proxy->vps, PW_STRIPPED_USER_NAME)) != NULL) {
1530 * If there's a Stripped-User-Name attribute in
1531 * the request, then use THAT as the User-Name
1532 * for the proxied request, instead of the
1535 * This is done by making a copy of the
1536 * Stripped-User-Name attribute, turning it into
1537 * a User-Name attribute, deleting the
1538 * Stripped-User-Name and User-Name attributes
1539 * from the vps list, and making the new
1540 * User-Name the head of the vps list.
1542 vp = pairfind(request->proxy->vps, PW_USER_NAME);
1544 vp = radius_paircreate(request, NULL,
1545 PW_USER_NAME, PW_TYPE_STRING);
1546 rad_assert(vp != NULL); /* handled by above function */
1547 /* Insert at the START of the list */
1548 vp->next = request->proxy->vps;
1549 request->proxy->vps = vp;
1551 memcpy(vp->vp_strvalue, strippedname->vp_strvalue,
1552 sizeof(vp->vp_strvalue));
1553 vp->length = strippedname->length;
1556 * Do NOT delete Stripped-User-Name.
1561 * If there is no PW_CHAP_CHALLENGE attribute but
1562 * there is a PW_CHAP_PASSWORD we need to add it
1563 * since we can't use the request authenticator
1564 * anymore - we changed it.
1566 if (pairfind(request->proxy->vps, PW_CHAP_PASSWORD) &&
1567 pairfind(request->proxy->vps, PW_CHAP_CHALLENGE) == NULL) {
1568 vp = radius_paircreate(request, &request->proxy->vps,
1569 PW_CHAP_CHALLENGE, PW_TYPE_OCTETS);
1570 vp->length = AUTH_VECTOR_LEN;
1571 memcpy(vp->vp_strvalue, request->packet->vector, AUTH_VECTOR_LEN);
1575 * The RFC's say we have to do this, but FreeRADIUS
1578 vp = radius_paircreate(request, &request->proxy->vps,
1579 PW_PROXY_STATE, PW_TYPE_OCTETS);
1580 snprintf(vp->vp_strvalue, sizeof(vp->vp_strvalue), "%d",
1581 request->packet->id);
1582 vp->length = strlen(vp->vp_strvalue);
1585 * Should be done BEFORE inserting into proxy hash, as
1586 * pre-proxy may use this information, or change it.
1588 request->proxy->code = request->packet->code;
1589 request->proxy->dst_ipaddr = home->ipaddr;
1590 request->proxy->dst_port = home->port;
1591 request->home_server = home;
1594 * Call the pre-proxy routines.
1596 vp = pairfind(request->config_items, PW_PRE_PROXY_TYPE);
1598 RDEBUG2(" Found Pre-Proxy-Type %s", vp->vp_strvalue);
1599 pre_proxy_type = vp->vp_integer;
1602 rad_assert(request->home_pool != NULL);
1604 if (request->home_pool->virtual_server) {
1605 const char *old_server = request->server;
1607 request->server = request->home_pool->virtual_server;
1608 RDEBUG2(" server %s {", request->server);
1609 rcode = module_pre_proxy(pre_proxy_type, request);
1611 request->server = old_server;
1613 rcode = module_pre_proxy(pre_proxy_type, request);
1616 case RLM_MODULE_FAIL:
1617 case RLM_MODULE_INVALID:
1618 case RLM_MODULE_NOTFOUND:
1619 case RLM_MODULE_USERLOCK:
1621 /* FIXME: debug print failed stuff */
1624 case RLM_MODULE_REJECT:
1625 case RLM_MODULE_HANDLED:
1629 * Only proxy the packet if the pre-proxy code succeeded.
1631 case RLM_MODULE_NOOP:
1633 case RLM_MODULE_UPDATED:
1638 * If it's a fake request, don't send the proxy
1639 * packet. The outer tunnel session will take
1640 * care of doing that.
1642 if (request->packet->dst_port == 0) {
1643 request->home_server = NULL;
1647 if (request->home_server->server) {
1648 return proxy_to_virtual_server(request);
1651 if (!proxy_request(request)) {
1652 RDEBUG("ERROR: Failed to proxy request %d", request->number);
1661 static void request_post_handler(REQUEST *request)
1663 int child_state = -1;
1664 struct timeval when;
1667 if ((request->master_state == REQUEST_STOP_PROCESSING) ||
1669 (request->parent->master_state == REQUEST_STOP_PROCESSING))) {
1670 RDEBUG2("Request %d was cancelled.", request->number);
1671 #ifdef HAVE_PTHREAD_H
1672 request->child_pid = NO_SUCH_CHILD_PID;
1674 request->child_state = REQUEST_DONE;
1678 if (request->child_state != REQUEST_RUNNING) {
1679 rad_panic("Internal sanity check failed");
1682 if ((request->reply->code == 0) &&
1683 ((vp = pairfind(request->config_items, PW_AUTH_TYPE)) != NULL) &&
1684 (vp->vp_integer == PW_AUTHTYPE_REJECT)) {
1685 request->reply->code = PW_AUTHENTICATION_REJECT;
1689 if (request->root->proxy_requests &&
1690 !request->in_proxy_hash &&
1691 (request->reply->code == 0) &&
1692 (request->packet->dst_port != 0) &&
1693 (request->packet->code != PW_STATUS_SERVER)) {
1694 int rcode = successfully_proxied_request(request);
1696 if (rcode == 1) return;
1699 * Failed proxying it (dead home servers, etc.)
1700 * Run it through Post-Proxy-Type = Fail, and
1701 * respond to the request.
1703 * Note that we're in a child thread here, so we
1704 * do NOT re-schedule the request. Instead, we
1705 * do what we would have done, which is run the
1706 * pre-handler, a NULL request handler, and then
1709 if ((rcode < 0) && setup_post_proxy_fail(request)) {
1710 request_pre_handler(request);
1714 * Else we weren't supposed to proxy it,
1715 * OR we proxied it internally to a virutal server.
1721 * Fake requests don't get encoded or signed. The caller
1722 * also requires the reply VP's, so we don't free them
1725 if (request->packet->dst_port == 0) {
1726 /* FIXME: RDEBUG going to the next request */
1727 #ifdef HAVE_PTHREAD_H
1728 request->child_pid = NO_SUCH_CHILD_PID;
1730 request->child_state = REQUEST_DONE;
1736 * Copy Proxy-State from the request to the reply.
1738 vp = paircopy2(request->packet->vps, PW_PROXY_STATE);
1739 if (vp) pairadd(&request->reply->vps, vp);
1743 * Access-Requests get delayed or cached.
1745 switch (request->packet->code) {
1746 case PW_AUTHENTICATION_REQUEST:
1747 gettimeofday(&request->next_when, NULL);
1749 if (request->reply->code == 0) {
1751 * Check if the lack of response is intentional.
1753 vp = pairfind(request->config_items,
1754 PW_RESPONSE_PACKET_TYPE);
1756 RDEBUG2("There was no response configured: rejecting request %d",
1758 request->reply->code = PW_AUTHENTICATION_REJECT;
1759 } else if (vp->vp_integer == 256) {
1760 RDEBUG2("Not responding to request %d",
1764 request->reply->code = vp->vp_integer;
1770 * Run rejected packets through
1772 * Post-Auth-Type = Reject
1774 if (request->reply->code == PW_AUTHENTICATION_REJECT) {
1775 pairdelete(&request->config_items, PW_POST_AUTH_TYPE);
1776 vp = radius_pairmake(request, &request->config_items,
1777 "Post-Auth-Type", "Reject",
1779 if (vp) rad_postauth(request);
1782 * If configured, delay Access-Reject packets.
1784 * If request->root->reject_delay = 0, we discover
1785 * that we have to send the packet now.
1787 when = request->received;
1788 when.tv_sec += request->root->reject_delay;
1790 if (timercmp(&when, &request->next_when, >)) {
1791 RDEBUG2("Delaying reject of request %d for %d seconds",
1793 request->root->reject_delay);
1794 request->next_when = when;
1795 request->next_callback = reject_delay;
1796 #ifdef HAVE_PTHREAD_H
1797 request->child_pid = NO_SUCH_CHILD_PID;
1799 request->child_state = REQUEST_REJECT_DELAY;
1804 request->next_when.tv_sec += request->root->cleanup_delay;
1805 request->next_callback = cleanup_delay;
1806 child_state = REQUEST_CLEANUP_DELAY;
1809 case PW_ACCOUNTING_REQUEST:
1810 request->next_callback = NULL; /* just to be safe */
1811 child_state = REQUEST_DONE;
1815 * FIXME: Status-Server should probably not be
1818 case PW_STATUS_SERVER:
1819 request->next_callback = NULL;
1820 child_state = REQUEST_DONE;
1824 if ((request->packet->code > 1024) &&
1825 (request->packet->code < (1024 + 254 + 1))) {
1826 request->next_callback = NULL;
1827 child_state = REQUEST_DONE;
1831 radlog(L_ERR, "Unknown packet type %d", request->packet->code);
1832 rad_panic("Unknown packet type");
1837 * Suppress "no reply" packets here, unless we're reading
1838 * from the "detail" file. In that case, we've got to
1839 * tell the detail file handler that the request is dead,
1840 * and it should re-send it.
1841 * If configured, encode, sign, and send.
1843 if ((request->reply->code != 0) ||
1844 (request->listener->type == RAD_LISTEN_DETAIL)) {
1845 DEBUG_PACKET(request, request->reply, 1);
1846 request->listener->send(request->listener, request);
1850 * Clean up. These are no longer needed.
1852 pairfree(&request->config_items);
1854 pairfree(&request->packet->vps);
1855 request->username = NULL;
1856 request->password = NULL;
1858 pairfree(&request->reply->vps);
1861 if (request->proxy) {
1862 pairfree(&request->proxy->vps);
1864 if (request->proxy_reply) {
1865 pairfree(&request->proxy_reply->vps);
1870 * We're not tracking responses from the home
1871 * server, we can therefore free this memory in
1874 if (!request->in_proxy_hash) {
1875 rad_free(&request->proxy);
1876 rad_free(&request->proxy_reply);
1877 request->home_server = NULL;
1883 RDEBUG2("Finished request %d.", request->number);
1885 request->child_state = child_state;
1888 * Single threaded mode: update timers now.
1890 if (!have_children) wait_a_bit(request);
1894 static void received_retransmit(REQUEST *request, const RADCLIENT *client)
1900 RAD_STATS_TYPE_INC(request->listener, total_dup_requests);
1901 RAD_STATS_CLIENT_INC(request->listener, client, total_dup_requests);
1903 switch (request->child_state) {
1904 case REQUEST_QUEUED:
1905 case REQUEST_RUNNING:
1909 radlog(L_ERR, "Discarding duplicate request from "
1910 "client %s port %d - ID: %d due to unfinished request %d",
1912 request->packet->src_port,request->packet->id,
1917 case REQUEST_PROXIED:
1919 * We're not supposed to have duplicate
1920 * accounting packets. The other states handle
1921 * duplicates fine (discard, or send duplicate
1922 * reply). But we do NOT want to retransmit an
1923 * accounting request here, because that would
1924 * involve updating the Acct-Delay-Time, and
1925 * therefore changing the packet Id, etc.
1927 * Instead, we just discard the packet. We may
1928 * eventually respond, or the client will send a
1929 * new accounting packet.
1931 if (request->packet->code == PW_ACCOUNTING_REQUEST) {
1935 check_for_zombie_home_server(request);
1938 * If we've just discovered that the home server is
1939 * dead, send the packet to another one.
1941 if ((request->packet->dst_port != 0) &&
1942 (request->home_server->state == HOME_STATE_IS_DEAD)) {
1945 remove_from_proxy_hash(request);
1947 home = home_server_ldb(NULL, request->home_pool, request);
1949 RDEBUG2("Failed to find live home server for request %d", request->number);
1952 * Do post-request processing,
1953 * and any insertion of necessary
1956 post_proxy_fail_handler(request);
1960 request->proxy->code = request->packet->code;
1961 request->proxy->dst_ipaddr = home->ipaddr;
1962 request->proxy->dst_port = home->port;
1963 request->home_server = home;
1966 * Free the old packet, to force re-encoding
1968 free(request->proxy->data);
1969 request->proxy->data = NULL;
1970 request->proxy->data_len = 0;
1973 * This request failed over to a virtual
1974 * server. Push it back onto the queue
1977 if (request->home_server->server) {
1978 proxy_fallback_handler(request);
1983 * Try to proxy the request.
1985 if (!proxy_request(request)) {
1986 RDEBUG("ERROR: Failed to re-proxy request %d", request->number);
1987 goto no_home_servers;
1991 * This code executes in the main server
1992 * thread, so there's no need for locking.
1994 rad_assert(request->next_callback != NULL);
1995 INSERT_EVENT(request->next_callback, request);
1996 request->next_callback = NULL;
1998 } /* else the home server is still alive */
2000 RDEBUG2("Sending duplicate proxied request to home server %s port %d - ID: %d",
2001 inet_ntop(request->proxy->dst_ipaddr.af,
2002 &request->proxy->dst_ipaddr.ipaddr,
2003 buffer, sizeof(buffer)),
2004 request->proxy->dst_port,
2005 request->proxy->id);
2006 request->num_proxied_requests++;
2008 DEBUG_PACKET(request, request->proxy, 1);
2009 request->proxy_listener->send(request->proxy_listener,
2014 case REQUEST_REJECT_DELAY:
2015 RDEBUG2("Waiting to send Access-Reject "
2016 "to client %s port %d - ID: %d",
2018 request->packet->src_port, request->packet->id);
2021 case REQUEST_CLEANUP_DELAY:
2023 RDEBUG2("Sending duplicate reply "
2024 "to client %s port %d - ID: %d",
2026 request->packet->src_port, request->packet->id);
2027 DEBUG_PACKET(request, request->reply, 1);
2028 request->listener->send(request->listener, request);
2034 static void received_conflicting_request(REQUEST *request,
2035 const RADCLIENT *client)
2037 radlog(L_ERR, "Received conflicting packet from "
2038 "client %s port %d - ID: %d due to unfinished request %d. Giving up on old request.",
2040 request->packet->src_port, request->packet->id,
2044 * Nuke it from the request hash, so we can receive new
2047 remove_from_request_hash(request);
2049 switch (request->child_state) {
2050 #ifdef HAVE_PTHREAD_H
2052 * It's queued or running. Tell it to stop, and
2053 * wait for it to do so.
2055 case REQUEST_QUEUED:
2056 case REQUEST_RUNNING:
2057 request->master_state = REQUEST_STOP_PROCESSING;
2058 request->delay += request->delay >> 1;
2060 tv_add(&request->when, request->delay);
2062 INSERT_EVENT(wait_for_child_to_die, request);
2067 * It's in some other state, and therefore also
2068 * in the event queue. At some point, the
2069 * child will notice, and we can then delete it.
2072 rad_assert(request->ev != NULL);
2078 static int can_handle_new_request(RADIUS_PACKET *packet,
2080 struct main_config_t *root)
2083 * Count the total number of requests, to see if
2084 * there are too many. If so, return with an
2087 if (root->max_requests) {
2088 int request_count = fr_packet_list_num_elements(pl);
2091 * This is a new request. Let's see if
2092 * it makes us go over our configured
2095 if (request_count > root->max_requests) {
2096 radlog(L_ERR, "Dropping request (%d is too many): "
2097 "from client %s port %d - ID: %d", request_count,
2099 packet->src_port, packet->id);
2100 radlog(L_INFO, "WARNING: Please check the configuration file.\n"
2101 "\tThe value for 'max_requests' is probably set too low.\n");
2103 } /* else there were a small number of requests */
2104 } /* else there was no configured limit for requests */
2107 * FIXME: Add per-client checks. If one client is sending
2108 * too many packets, start discarding them.
2110 * We increment the counters here, and decrement them
2111 * when the response is sent... somewhere in this file.
2115 * FUTURE: Add checks for system load. If the system is
2116 * busy, start dropping requests...
2118 * We can probably keep some statistics ourselves... if
2119 * there are more requests coming in than we can handle,
2120 * start dropping some.
2127 int received_request(rad_listen_t *listener,
2128 RADIUS_PACKET *packet, REQUEST **prequest,
2131 RADIUS_PACKET **packet_p;
2132 REQUEST *request = NULL;
2133 struct main_config_t *root = &mainconfig;
2135 packet_p = fr_packet_list_find(pl, packet);
2137 request = fr_packet2myptr(REQUEST, packet, packet_p);
2138 rad_assert(request->in_request_hash);
2140 if ((request->packet->data_len == packet->data_len) &&
2141 (memcmp(request->packet->vector, packet->vector,
2142 sizeof(packet->vector)) == 0)) {
2143 received_retransmit(request, client);
2148 * The new request is different from the old one,
2149 * but maybe the old is finished. If so, delete
2152 switch (request->child_state) {
2153 struct timeval when;
2156 gettimeofday(&when, NULL);
2160 * If the cached request was received
2161 * within the last second, then we
2162 * discard the NEW request instead of the
2163 * old one. This will happen ONLY when
2164 * the client is severely broken, and is
2165 * sending conflicting packets very
2168 if (timercmp(&when, &request->received, <)) {
2169 radlog(L_ERR, "Discarding conflicting packet from "
2170 "client %s port %d - ID: %d due to recent request %d.",
2172 packet->src_port, packet->id,
2177 received_conflicting_request(request, client);
2181 case REQUEST_REJECT_DELAY:
2182 case REQUEST_CLEANUP_DELAY:
2183 request->child_state = REQUEST_DONE;
2185 cleanup_delay(request);
2192 * We may want to quench the new request.
2194 if ((listener->type != RAD_LISTEN_DETAIL) &&
2195 !can_handle_new_request(packet, client, root)) {
2200 * Create and initialize the new request.
2202 request = request_alloc(); /* never fails */
2204 if ((request->reply = rad_alloc(0)) == NULL) {
2205 radlog(L_ERR, "No memory");
2209 request->listener = listener;
2210 request->client = client;
2211 request->packet = packet;
2212 request->packet->timestamp = request->timestamp;
2213 request->number = request_num_counter++;
2214 request->priority = listener->type;
2215 #ifdef HAVE_PTHREAD_H
2216 request->child_pid = NO_SUCH_CHILD_PID;
2220 * Status-Server packets go to the head of the queue.
2222 if (request->packet->code == PW_STATUS_SERVER) request->priority = 0;
2225 * Set virtual server identity
2227 if (client->server) {
2228 request->server = client->server;
2229 } else if (listener->server) {
2230 request->server = listener->server;
2232 request->server = NULL;
2236 * Remember the request in the list.
2238 if (!fr_packet_list_insert(pl, &request->packet)) {
2239 radlog(L_ERR, "Failed to insert request %d in the list of live requests: discarding", request->number);
2240 request_free(&request);
2244 request->in_request_hash = TRUE;
2245 request->root = root;
2249 * The request passes many of our sanity checks.
2250 * From here on in, if anything goes wrong, we
2251 * send a reject message, instead of dropping the
2256 * Build the reply template from the request.
2259 request->reply->sockfd = request->packet->sockfd;
2260 request->reply->dst_ipaddr = request->packet->src_ipaddr;
2261 request->reply->src_ipaddr = request->packet->dst_ipaddr;
2262 request->reply->dst_port = request->packet->src_port;
2263 request->reply->src_port = request->packet->dst_port;
2264 request->reply->id = request->packet->id;
2265 request->reply->code = 0; /* UNKNOWN code */
2266 memcpy(request->reply->vector, request->packet->vector,
2267 sizeof(request->reply->vector));
2268 request->reply->vps = NULL;
2269 request->reply->data = NULL;
2270 request->reply->data_len = 0;
2272 request->master_state = REQUEST_ACTIVE;
2273 request->child_state = REQUEST_QUEUED;
2274 request->next_callback = NULL;
2276 gettimeofday(&request->received, NULL);
2277 request->timestamp = request->received.tv_sec;
2278 request->when = request->received;
2280 request->delay = USEC;
2282 tv_add(&request->when, request->delay);
2284 INSERT_EVENT(wait_a_bit, request);
2286 *prequest = request;
2292 REQUEST *received_proxy_response(RADIUS_PACKET *packet)
2298 if (!home_server_find(&packet->src_ipaddr, packet->src_port)) {
2299 radlog(L_ERR, "Ignoring request from unknown home server %s port %d",
2300 inet_ntop(packet->src_ipaddr.af,
2301 &packet->src_ipaddr.ipaddr,
2302 buffer, sizeof(buffer)),
2309 * Also removes from the proxy hash if responses == requests
2311 request = lookup_in_proxy_hash(packet);
2314 radlog(L_PROXY, "No outstanding request was found for proxy reply from home server %s port %d - ID %d",
2315 inet_ntop(packet->src_ipaddr.af,
2316 &packet->src_ipaddr.ipaddr,
2317 buffer, sizeof(buffer)),
2318 packet->src_port, packet->id);
2323 home = request->home_server;
2325 gettimeofday(&now, NULL);
2327 home->state = HOME_STATE_ALIVE;
2329 if (request->reply && request->reply->code != 0) {
2330 RDEBUG2("We already replied to this request. Discarding response from home server.");
2336 * We had previously received a reply, so we don't need
2337 * to do anything here.
2339 if (request->proxy_reply) {
2340 if (memcmp(request->proxy_reply->vector,
2342 sizeof(request->proxy_reply->vector)) == 0) {
2343 RDEBUG2("Discarding duplicate reply from home server %s port %d - ID: %d for request %d",
2344 inet_ntop(packet->src_ipaddr.af,
2345 &packet->src_ipaddr.ipaddr,
2346 buffer, sizeof(buffer)),
2347 packet->src_port, packet->id,
2351 * ? The home server gave us a new proxy
2352 * reply, which doesn't match the old
2355 RDEBUG2("Ignoring conflicting proxy reply");
2358 /* assert that there's an event queued for request? */
2364 * The average includes our time to receive packets and
2365 * look them up in the hashes, which should be the same
2368 * We update the response time only for the FIRST packet
2371 else if (home->ema.window > 0) {
2372 radius_stats_ema(&home->ema, &now, &request->proxy_when);
2377 switch (request->child_state) {
2378 case REQUEST_QUEUED:
2379 case REQUEST_RUNNING:
2380 rad_panic("Internal sanity check failed for child state");
2383 case REQUEST_REJECT_DELAY:
2384 case REQUEST_CLEANUP_DELAY:
2386 radlog(L_ERR, "Reply from home server %s port %d - ID: %d arrived too late for request %d. Try increasing 'retry_delay' or 'max_request_time'",
2387 inet_ntop(packet->src_ipaddr.af,
2388 &packet->src_ipaddr.ipaddr,
2389 buffer, sizeof(buffer)),
2390 packet->src_port, packet->id,
2392 /* assert that there's an event queued for request? */
2396 case REQUEST_PROXIED:
2400 request->proxy_reply = packet;
2404 * Perform RTT calculations, as per RFC 2988 (for TCP).
2405 * Note that we do so only if we sent one request, and
2406 * received one response. If we sent two requests, we
2407 * have no idea if the response is for the first, or for
2408 * the second request/
2410 if (request->num_proxied_requests == 1) {
2412 home_server *home = request->home_server;
2414 rtt = now.tv_sec - request->proxy_when.tv_sec;
2417 rtt -= request->proxy_when.tv_usec;
2419 if (!home->has_rtt) {
2420 home->has_rtt = TRUE;
2423 home->rttvar = rtt / 2;
2426 home->rttvar -= home->rttvar >> 2;
2427 home->rttvar += (home->srtt - rtt);
2428 home->srtt -= home->srtt >> 3;
2429 home->srtt += rtt >> 3;
2432 home->rto = home->srtt;
2433 if (home->rttvar > (USEC / 4)) {
2434 home->rto += home->rttvar * 4;
2442 * There's no incoming request, so it's a proxied packet
2445 if (!request->packet) {
2446 received_response_to_ping(request);
2450 request->child_state = REQUEST_QUEUED;
2451 request->when = now;
2452 request->delay = USEC;
2453 request->priority = RAD_LISTEN_PROXY;
2454 tv_add(&request->when, request->delay);
2457 * Wait a bit will take care of max_request_time
2459 INSERT_EVENT(wait_a_bit, request);
2465 void event_new_fd(rad_listen_t *this)
2469 this->print(this, buffer, sizeof(buffer));
2471 if (this->status == RAD_LISTEN_STATUS_INIT) {
2473 DEBUG("Listening on %s", buffer);
2475 DEBUG2(" ... adding new socket %s", buffer);
2477 if (!fr_event_fd_insert(el, 0, this->fd,
2478 event_socket_handler, this)) {
2479 radlog(L_ERR, "Failed remembering handle for proxy socket!");
2483 this->status = RAD_LISTEN_STATUS_KNOWN;
2487 if (this->status == RAD_LISTEN_STATUS_CLOSED) {
2488 DEBUG2(" ... closing socket %s", buffer);
2490 fr_event_fd_delete(el, 0, this->fd);
2491 this->status = RAD_LISTEN_STATUS_FINISH;
2494 * Close the fd AFTER fixing up the requests and
2495 * listeners, so that they don't send/recv on the
2496 * wrong socket (if someone manages to open
2505 static void event_detail_timer(void *ctx)
2507 rad_listen_t *listener = ctx;
2508 RAD_REQUEST_FUNP fun;
2511 if (listener->recv(listener, &fun, &request)) {
2512 if (!thread_pool_addrequest(request, fun)) {
2513 request->child_state = REQUEST_DONE;
2519 static void handle_signal_self(int flag)
2521 if ((flag & (RADIUS_SIGNAL_SELF_EXIT | RADIUS_SIGNAL_SELF_TERM)) != 0) {
2522 if ((flag & RADIUS_SIGNAL_SELF_EXIT) != 0) {
2523 fr_event_loop_exit(el, 1);
2525 fr_event_loop_exit(el, 2);
2529 } /* else exit/term flags weren't set */
2532 * Tell the even loop to stop processing.
2534 if ((flag & RADIUS_SIGNAL_SELF_HUP) != 0) {
2536 static time_t last_hup = 0;
2538 DEBUG("Received HUP signal.");
2541 if ((int) (when - last_hup) < 5) {
2542 radlog(L_INFO, "Ignoring HUP (less than 5s since last one)");
2547 fr_event_loop_exit(el, 0x80);
2551 if ((flag & RADIUS_SIGNAL_SELF_DETAIL) != 0) {
2554 for (this = mainconfig.listen;
2556 this = this->next) {
2558 struct timeval when;
2560 if (this->type != RAD_LISTEN_DETAIL) continue;
2562 delay = detail_delay(this);
2563 if (!delay) continue;
2565 fr_event_now(el, &now);
2567 tv_add(&when, delay);
2569 if (delay > 100000) {
2570 DEBUG("Delaying next detail event for %d.%01u seconds.",
2571 delay / USEC, (delay % USEC) / 100000);
2574 if (!fr_event_insert(el, event_detail_timer, this,
2576 radlog(L_ERR, "Failed remembering timer");
2583 if ((flag & RADIUS_SIGNAL_SELF_NEW_FD) != 0) {
2586 for (this = mainconfig.listen;
2588 this = this->next) {
2589 if (this->status == RAD_LISTEN_STATUS_KNOWN) continue;
2597 void radius_signal_self(int flag)
2599 handle_signal_self(flag);
2603 * Inform ourselves that we received a signal.
2605 void radius_signal_self(int flag)
2611 * The read MUST be non-blocking for this to work.
2613 rcode = read(self_pipe[0], buffer, sizeof(buffer));
2617 for (i = 0; i < rcode; i++) {
2618 buffer[0] |= buffer[i];
2626 write(self_pipe[1], buffer, 1);
2630 static void event_signal_handler(UNUSED fr_event_list_t *xel,
2631 UNUSED int fd, UNUSED void *ctx)
2636 rcode = read(self_pipe[0], buffer, sizeof(buffer));
2637 if (rcode <= 0) return;
2640 * Merge pending signals.
2642 for (i = 0; i < rcode; i++) {
2643 buffer[0] |= buffer[i];
2646 handle_signal_self(buffer[0]);
2651 static void event_socket_handler(fr_event_list_t *xel, UNUSED int fd,
2654 rad_listen_t *listener = ctx;
2655 RAD_REQUEST_FUNP fun;
2658 rad_assert(xel == el);
2662 if (listener->fd < 0) rad_panic("Socket was closed on us!");
2664 if (!listener->recv(listener, &fun, &request)) return;
2666 if (!thread_pool_addrequest(request, fun)) {
2667 request->child_state = REQUEST_DONE;
2673 * This function is called periodically to see if any FD's are
2674 * available for reading.
2676 static void event_poll_detail(UNUSED void *ctx)
2679 RAD_REQUEST_FUNP fun;
2682 struct timeval when;
2684 fr_event_now(el, &now);
2688 for (this = mainconfig.listen; this != NULL; this = this->next) {
2689 if (this->type != RAD_LISTEN_DETAIL) continue;
2691 if (this->fd >= 0) continue;
2694 * Try to read something.
2696 * FIXME: This does poll AND receive.
2698 rcode = this->recv(this, &fun, &request);
2699 if (!rcode) continue;
2701 rad_assert(fun != NULL);
2702 rad_assert(request != NULL);
2704 if (!thread_pool_addrequest(request, fun)) {
2705 request->child_state = REQUEST_DONE;
2712 if (!fr_event_insert(el, event_poll_detail, NULL,
2714 radlog(L_ERR, "Failed creating handler");
2720 static void event_status(struct timeval *wake)
2722 #if !defined(HAVE_PTHREAD_H) && defined(WNOHANG)
2726 if (debug_flag == 0) {
2728 radlog(L_INFO, "Ready to process requests.");
2729 just_started = FALSE;
2735 DEBUG("Ready to process requests.");
2737 } else if ((wake->tv_sec != 0) ||
2738 (wake->tv_usec >= 100000)) {
2739 DEBUG("Waking up in %d.%01u seconds.",
2740 (int) wake->tv_sec, (unsigned int) wake->tv_usec / 100000);
2745 * FIXME: Put this somewhere else, where it isn't called
2746 * all of the time...
2749 #if !defined(HAVE_PTHREAD_H) && defined(WNOHANG)
2751 * If there are no child threads, then there may
2752 * be child processes. In that case, wait for
2753 * their exit status, and throw that exit status
2754 * away. This helps get rid of zxombie children.
2756 while (waitpid(-1, &argval, WNOHANG) > 0) {
2765 * Externally-visibly functions.
2767 int radius_event_init(CONF_SECTION *cs, int spawn_flag)
2769 rad_listen_t *this, *head = NULL;
2773 time(&fr_start_time);
2775 el = fr_event_list_create(event_status);
2778 pl = fr_packet_list_create(0);
2781 request_num_counter = 0;
2784 * Move all of the thread calls to this file?
2786 * It may be best for the mutexes to be in this file...
2788 have_children = spawn_flag;
2791 if (mainconfig.proxy_requests) {
2793 * Create the tree for managing proxied requests and
2796 proxy_list = fr_packet_list_create(1);
2797 if (!proxy_list) return 0;
2799 #ifdef HAVE_PTHREAD_H
2800 if (pthread_mutex_init(&proxy_mutex, NULL) != 0) {
2801 radlog(L_ERR, "FATAL: Failed to initialize proxy mutex: %s",
2810 * Just before we spawn the child threads, force the log
2811 * subsystem to re-open the log file for every write.
2813 if (spawn_flag) force_log_reopen();
2815 #ifdef HAVE_PTHREAD_H
2817 NO_SUCH_CHILD_PID = (pthread_t ) (0);
2819 NO_SUCH_CHILD_PID = pthread_self(); /* not a child thread */
2821 if (thread_pool_init(cs, spawn_flag) < 0) {
2827 DEBUG("%s: #### Skipping IP addresses and Ports ####",
2834 * Child threads need a pipe to signal us, as do the
2837 if (pipe(self_pipe) < 0) {
2838 radlog(L_ERR, "radiusd: Error opening internal pipe: %s",
2842 if (fcntl(self_pipe[0], F_SETFL, O_NONBLOCK | FD_CLOEXEC) < 0) {
2843 radlog(L_ERR, "radiusd: Error setting internal flags: %s",
2847 if (fcntl(self_pipe[1], F_SETFL, O_NONBLOCK | FD_CLOEXEC) < 0) {
2848 radlog(L_ERR, "radiusd: Error setting internal flags: %s",
2853 if (!fr_event_fd_insert(el, 0, self_pipe[0],
2854 event_signal_handler, el)) {
2855 radlog(L_ERR, "Failed creating handler for signals");
2862 * Mark the proxy Fd's as unused.
2867 for (i = 0; i < 32; i++) proxy_fds[i] = -1;
2871 DEBUG("%s: #### Opening IP addresses and Ports ####",
2874 if (listen_init(cs, &head) < 0) {
2879 * Add all of the sockets to the event loop.
2883 this = this->next) {
2886 this->print(this, buffer, sizeof(buffer));
2888 switch (this->type) {
2890 case RAD_LISTEN_DETAIL:
2891 DEBUG("Listening on %s", buffer);
2892 has_detail_listener = TRUE;
2897 case RAD_LISTEN_PROXY:
2898 rad_assert(proxy_fds[this->fd & 0x1f] == -1);
2899 rad_assert(proxy_listeners[this->fd & 0x1f] == NULL);
2901 proxy_fds[this->fd & 0x1f] = this->fd;
2902 proxy_listeners[this->fd & 0x1f] = this;
2903 if (!fr_packet_list_socket_add(proxy_list,
2915 * The file descriptor isn't ready. Poll for
2916 * when it will become ready. This is for the
2926 if (has_detail_listener) {
2927 struct timeval when;
2929 gettimeofday(&when, NULL);
2932 if (!fr_event_insert(el, event_poll_detail, NULL,
2934 radlog(L_ERR, "Failed creating handler");
2939 mainconfig.listen = head;
2945 static int request_hash_cb(UNUSED void *ctx, void *data)
2947 REQUEST *request = fr_packet2myptr(REQUEST, packet, data);
2950 rad_assert(request->in_proxy_hash == FALSE);
2953 fr_event_delete(el, &request->ev);
2954 remove_from_request_hash(request);
2955 request_free(&request);
2962 static int proxy_hash_cb(UNUSED void *ctx, void *data)
2964 REQUEST *request = fr_packet2myptr(REQUEST, proxy, data);
2966 fr_packet_list_yank(proxy_list, request->proxy);
2967 request->in_proxy_hash = FALSE;
2969 if (!request->in_request_hash) {
2970 fr_event_delete(el, &request->ev);
2971 request_free(&request);
2978 void radius_event_free(void)
2981 * FIXME: Stop all threads, or at least check that
2982 * they're all waiting on the semaphore, and the queues
2988 * There are requests in the proxy hash that aren't
2989 * referenced from anywhere else. Remove them first.
2992 PTHREAD_MUTEX_LOCK(&proxy_mutex);
2993 fr_packet_list_walk(proxy_list, NULL, proxy_hash_cb);
2994 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
2995 fr_packet_list_free(proxy_list);
3000 fr_packet_list_walk(pl, NULL, request_hash_cb);
3002 fr_packet_list_free(pl);
3005 fr_event_list_free(el);
3008 int radius_event_process(void)
3012 return fr_event_loop(el);
3015 void radius_handle_request(REQUEST *request, RAD_REQUEST_FUNP fun)
3017 request->options = RAD_REQUEST_OPTION_DEBUG2;
3019 if (request_pre_handler(request)) {
3020 rad_assert(fun != NULL);
3021 rad_assert(request != NULL);
3023 if (request->server) RDEBUG("server %s {",
3027 if (request->server) RDEBUG("} # server %s",
3030 request_post_handler(request);
3033 DEBUG2("Going to the next request");