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 just_started = TRUE;
61 static int self_pipe[2];
66 static pthread_mutex_t proxy_mutex;
69 #define PTHREAD_MUTEX_LOCK if (have_children) pthread_mutex_lock
70 #define PTHREAD_MUTEX_UNLOCK if (have_children) pthread_mutex_unlock
72 static pthread_t NO_SUCH_CHILD_PID;
75 * This is easier than ifdef's throughout the code.
77 #define PTHREAD_MUTEX_LOCK(_x)
78 #define PTHREAD_MUTEX_UNLOCK(_x)
79 int thread_pool_addrequest(REQUEST *request, RAD_REQUEST_FUNP fun)
81 radius_handle_request(request, fun);
86 #define INSERT_EVENT(_function, _ctx) if (!fr_event_insert(el, _function, _ctx, &((_ctx)->when), &((_ctx)->ev))) { _rad_panic(__FILE__, __LINE__, "Failed to insert event"); }
89 static fr_packet_list_t *proxy_list = NULL;
92 * We keep the proxy FD's here. The RADIUS Id's are marked
93 * "allocated" per Id, via a bit per proxy FD.
95 static int proxy_fds[32];
96 static rad_listen_t *proxy_listeners[32];
98 #define remove_from_proxy_hash(foo)
101 static void request_post_handler(REQUEST *request);
102 static void wait_a_bit(void *ctx);
103 static void event_socket_handler(fr_event_list_t *xel, UNUSED int fd, void *ctx);
105 static void event_poll_detail(void *ctx);
108 static void NEVER_RETURNS _rad_panic(const char *file, unsigned int line,
111 radlog(L_ERR, "[%s:%d] %s", file, line, msg);
115 #define rad_panic(x) _rad_panic(__FILE__, __LINE__, x)
118 static void tv_add(struct timeval *tv, int usec_delay)
120 if (usec_delay > USEC) {
121 tv->tv_sec += usec_delay / USEC;
124 tv->tv_usec += usec_delay;
126 if (tv->tv_usec > USEC) {
132 static void remove_from_request_hash(REQUEST *request)
134 if (!request->in_request_hash) return;
136 fr_packet_list_yank(pl, request->packet);
137 request->in_request_hash = FALSE;
139 request_stats_final(request);
144 static REQUEST *lookup_in_proxy_hash(RADIUS_PACKET *reply)
146 RADIUS_PACKET **proxy_p;
149 PTHREAD_MUTEX_LOCK(&proxy_mutex);
150 proxy_p = fr_packet_list_find_byreply(proxy_list, reply);
153 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
157 request = fr_packet2myptr(REQUEST, proxy, proxy_p);
160 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
164 request->num_proxied_responses++;
167 * Catch the most common case of everything working
170 if (request->num_proxied_requests == request->num_proxied_responses) {
171 fr_packet_list_yank(proxy_list, request->proxy);
172 fr_packet_list_id_free(proxy_list, request->proxy);
173 request->in_proxy_hash = FALSE;
177 * On the FIRST reply, decrement the count of outstanding
178 * requests. Note that this is NOT the count of sent
179 * packets, but whether or not the home server has
182 if (!request->proxy_reply &&
183 request->home_server->currently_outstanding) {
184 request->home_server->currently_outstanding--;
187 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
193 static void remove_from_proxy_hash(REQUEST *request)
195 if (!request->in_proxy_hash) return;
197 PTHREAD_MUTEX_LOCK(&proxy_mutex);
198 fr_packet_list_yank(proxy_list, request->proxy);
199 fr_packet_list_id_free(proxy_list, request->proxy);
202 * The home server hasn't replied, but we've given up on
203 * this request. Don't count this request against the
206 if (!request->proxy_reply &&
207 request->home_server->currently_outstanding) {
208 request->home_server->currently_outstanding--;
211 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
213 request->in_proxy_hash = FALSE;
217 static int insert_into_proxy_hash(REQUEST *request)
222 rad_assert(request->proxy != NULL);
223 rad_assert(proxy_list != NULL);
225 request->proxy->sockfd = -1;
227 PTHREAD_MUTEX_LOCK(&proxy_mutex);
229 request->home_server->currently_outstanding++;
231 if (!fr_packet_list_id_alloc(proxy_list, request->proxy)) {
233 rad_listen_t *proxy_listener;
236 * Allocate a new proxy fd. This function adds
237 * it to the tail of the list of listeners. With
238 * some care, this can be thread-safe.
240 proxy_listener = proxy_new_listener();
241 if (!proxy_listener) {
242 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
243 RDEBUG2("ERROR: Failed to create a new socket for proxying requests.");
251 proxy = proxy_listener->fd;
252 for (i = 0; i < 32; i++) {
254 * Found a free entry. Save the socket,
255 * and remember where we saved it.
257 if (proxy_fds[(proxy + i) & 0x1f] == -1) {
258 found = (proxy + i) & 0x1f;
259 proxy_fds[found] = proxy;
260 proxy_listeners[found] = proxy_listener;
264 rad_assert(found >= 0);
266 if (!fr_packet_list_socket_add(proxy_list, proxy_listener->fd)) {
267 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
268 RDEBUG2("ERROR: Failed to create a new socket for proxying requests.");
273 if (!fr_packet_list_id_alloc(proxy_list, request->proxy)) {
274 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
275 RDEBUG2("ERROR: Failed to create a new socket for proxying requests.");
280 * Signal the main thread to add the new FD to the list
283 radius_signal_self(RADIUS_SIGNAL_SELF_NEW_FD);
285 rad_assert(request->proxy->sockfd >= 0);
288 * FIXME: Hack until we get rid of rad_listen_t, and put
289 * the information into the packet_list.
292 for (i = 0; i < 32; i++) {
293 if (proxy_fds[i] == request->proxy->sockfd) {
300 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
301 RDEBUG2("ERROR: All sockets are full.");
305 rad_assert(proxy_fds[proxy] != -1);
306 rad_assert(proxy_listeners[proxy] != NULL);
307 request->proxy_listener = proxy_listeners[proxy];
309 if (!fr_packet_list_insert(proxy_list, &request->proxy)) {
310 fr_packet_list_id_free(proxy_list, request->proxy);
311 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
312 RDEBUG2("ERROR: Failed to insert entry into proxy list");
316 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
318 RDEBUG3(" proxy: allocating destination %s port %d - Id %d",
319 inet_ntop(request->proxy->dst_ipaddr.af,
320 &request->proxy->dst_ipaddr.ipaddr, buf, sizeof(buf)),
321 request->proxy->dst_port,
324 request->in_proxy_hash = TRUE;
331 * Called as BOTH an event, and in-line from other functions.
333 static void wait_for_proxy_id_to_expire(void *ctx)
335 REQUEST *request = ctx;
336 home_server *home = request->home_server;
338 rad_assert(request->magic == REQUEST_MAGIC);
339 rad_assert(request->proxy != NULL);
341 if (!fr_event_now(el, &now)) gettimeofday(&now, NULL);
342 request->when = request->proxy_when;
343 request->when.tv_sec += home->response_window;
345 if ((request->num_proxied_requests == request->num_proxied_responses) ||
346 timercmp(&now, &request->when, >)) {
347 if (request->packet) {
348 RDEBUG2("Cleaning up request %d ID %d with timestamp +%d",
349 request->number, request->packet->id,
350 (unsigned int) (request->timestamp - fr_start_time));
352 RDEBUG2("Cleaning up request %d with timestamp +%d",
354 (unsigned int) (request->timestamp - fr_start_time));
356 fr_event_delete(el, &request->ev);
357 remove_from_proxy_hash(request);
358 remove_from_request_hash(request);
359 request_free(&request);
363 INSERT_EVENT(wait_for_proxy_id_to_expire, request);
367 #ifdef HAVE_PTHREAD_H
368 static void wait_for_child_to_die(void *ctx)
370 REQUEST *request = ctx;
372 rad_assert(request->magic == REQUEST_MAGIC);
374 if ((request->child_state == REQUEST_QUEUED) |
375 (request->child_state == REQUEST_RUNNING)) {
376 request->delay += (request->delay >> 1);
377 tv_add(&request->when, request->delay);
379 RDEBUG2("Child is still stuck for request %d", request->number);
381 INSERT_EVENT(wait_for_child_to_die, request);
385 RDEBUG2("Child is finally responsive for request %d", request->number);
386 remove_from_request_hash(request);
389 if (request->proxy) {
390 wait_for_proxy_id_to_expire(request);
395 request_free(&request);
399 static void cleanup_delay(void *ctx)
401 REQUEST *request = ctx;
403 rad_assert(request->magic == REQUEST_MAGIC);
404 rad_assert((request->child_state == REQUEST_CLEANUP_DELAY) ||
405 (request->child_state == REQUEST_DONE));
407 remove_from_request_hash(request);
410 if (request->proxy && request->in_proxy_hash) {
411 wait_for_proxy_id_to_expire(request);
416 RDEBUG2("Cleaning up request %d ID %d with timestamp +%d",
417 request->number, request->packet->id,
418 (unsigned int) (request->timestamp - fr_start_time));
420 fr_event_delete(el, &request->ev);
421 request_free(&request);
426 * FIXME: Put into a libradius function.
428 #define MAX_PACKET_CODE (52)
429 static const char *packet_codes[] = {
434 "Accounting-Request",
435 "Accounting-Response",
440 "Accounting-Message",
451 "Resource-Free-Request",
452 "Resource-Free-Response",
453 "Resource-Query-Request",
454 "Resource-Query-Response",
455 "Alternate-Resource-Reclaim-Request",
456 "NAS-Reboot-Request",
457 "NAS-Reboot-Response",
470 "Disconnect-Request",
480 "IP-Address-Allocate",
486 * In daemon mode, AND this request has debug flags set.
488 #define DEBUG_PACKET if (!debug_flag && request->options && request->radlog) debug_packet
490 static void debug_packet(REQUEST *request, RADIUS_PACKET *packet, int direction)
494 const char *received, *from;
495 const fr_ipaddr_t *ip;
500 if (direction == 0) {
501 received = "Received";
502 from = "from"; /* what else? */
503 ip = &packet->src_ipaddr;
504 port = packet->src_port;
507 received = "Sending";
508 from = "to"; /* hah! */
509 ip = &packet->dst_ipaddr;
510 port = packet->dst_port;
514 * Client-specific debugging re-prints the input
515 * packet into the client log.
517 * This really belongs in a utility library
519 if ((packet->code > 0) && (packet->code < MAX_PACKET_CODE)) {
520 RDEBUG("%s %s packet %s host %s port %d, id=%d, length=%d",
521 received, packet_codes[packet->code], from,
522 inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)),
523 port, packet->id, packet->data_len);
525 RDEBUG("%s packet %s host %s port %d code=%d, id=%d, length=%d",
527 inet_ntop(ip->af, &ip->ipaddr, buffer, sizeof(buffer)),
529 packet->code, packet->id, packet->data_len);
532 for (vp = packet->vps; vp != NULL; vp = vp->next) {
533 vp_prints(buffer, sizeof(buffer), vp);
534 request->radlog(L_DBG, 0, request, "\t%s", buffer);
538 static void reject_delay(void *ctx)
540 REQUEST *request = ctx;
542 rad_assert(request->magic == REQUEST_MAGIC);
543 rad_assert(request->child_state == REQUEST_REJECT_DELAY);
545 RDEBUG2("Sending delayed reject for request %d", request->number);
547 DEBUG_PACKET(request, request->reply, 1);
549 request->listener->send(request->listener, request);
551 request->when.tv_sec += request->root->cleanup_delay;
552 request->child_state = REQUEST_CLEANUP_DELAY;
554 INSERT_EVENT(cleanup_delay, request);
559 void revive_home_server(void *ctx)
561 home_server *home = ctx;
564 home->state = HOME_STATE_ALIVE;
565 home->currently_outstanding = 0;
566 home->revive_time = now;
569 * Delete any outstanding events.
571 if (home->ev) fr_event_delete(el, &home->ev);
573 radlog(L_INFO, "PROXY: Marking home server %s port %d alive again... we have no idea if it really is alive or not.",
574 inet_ntop(home->ipaddr.af, &home->ipaddr.ipaddr,
575 buffer, sizeof(buffer)),
581 static void no_response_to_ping(void *ctx)
583 REQUEST *request = ctx;
584 home_server *home = request->home_server;
587 home->num_received_pings = 0;
589 RDEBUG2("No response to status check %d from home server %s port %d",
591 inet_ntop(request->proxy->dst_ipaddr.af,
592 &request->proxy->dst_ipaddr.ipaddr,
593 buffer, sizeof(buffer)),
594 request->proxy->dst_port);
596 wait_for_proxy_id_to_expire(request);
600 static void received_response_to_ping(REQUEST *request)
602 home_server *home = request->home_server;
605 home->num_received_pings++;
607 RDEBUG2("Received response to status check %d (%d in current sequence)",
608 request->number, home->num_received_pings);
611 * Remove the request from any hashes
613 fr_event_delete(el, &request->ev);
614 remove_from_proxy_hash(request);
615 rad_assert(request->in_request_hash == FALSE);
616 request_free(&request);
619 * The control socket may have marked the home server as
620 * alive. OR, it may have suddenly started responding to
621 * requests again. If so, don't re-do the "make alive"
624 if (home->state == HOME_STATE_ALIVE) return;
627 * We haven't received enough ping responses to mark it
628 * "alive". Wait a bit.
630 if (home->num_received_pings < home->num_pings_to_alive) {
634 home->state = HOME_STATE_ALIVE;
635 home->currently_outstanding = 0;
636 home->revive_time = now;
638 if (!fr_event_delete(el, &home->ev)) {
639 RDEBUG2("Hmm... no event for home server. Oh well.");
642 radlog(L_INFO, "PROXY: Marking home server %s port %d alive",
643 inet_ntop(request->proxy->dst_ipaddr.af,
644 &request->proxy->dst_ipaddr.ipaddr,
645 buffer, sizeof(buffer)),
646 request->proxy->dst_port);
651 * Called from start of zombie period, OR after control socket
652 * marks the home server dead.
654 static void ping_home_server(void *ctx)
657 home_server *home = ctx;
661 if (home->state == HOME_STATE_ALIVE) {
662 radlog(L_INFO, "Suspicious proxy state... continuing");
666 request = request_alloc();
667 request->number = request_num_counter++;
669 request->proxy = rad_alloc(1);
670 rad_assert(request->proxy != NULL);
672 fr_event_now(el, &request->when);
673 home->when = request->when;
675 if (home->ping_check == HOME_PING_CHECK_STATUS_SERVER) {
676 request->proxy->code = PW_STATUS_SERVER;
678 radius_pairmake(request, &request->proxy->vps,
679 "Message-Authenticator", "0x00", T_OP_SET);
681 } else if (home->type == HOME_TYPE_AUTH) {
682 request->proxy->code = PW_AUTHENTICATION_REQUEST;
684 radius_pairmake(request, &request->proxy->vps,
685 "User-Name", home->ping_user_name, T_OP_SET);
686 radius_pairmake(request, &request->proxy->vps,
687 "User-Password", home->ping_user_password, T_OP_SET);
688 radius_pairmake(request, &request->proxy->vps,
689 "Service-Type", "Authenticate-Only", T_OP_SET);
690 radius_pairmake(request, &request->proxy->vps,
691 "Message-Authenticator", "0x00", T_OP_SET);
694 #ifdef WITH_ACCOUNTING
695 request->proxy->code = PW_ACCOUNTING_REQUEST;
697 radius_pairmake(request, &request->proxy->vps,
698 "User-Name", home->ping_user_name, T_OP_SET);
699 radius_pairmake(request, &request->proxy->vps,
700 "Acct-Status-Type", "Stop", T_OP_SET);
701 radius_pairmake(request, &request->proxy->vps,
702 "Acct-Session-Id", "00000000", T_OP_SET);
703 vp = radius_pairmake(request, &request->proxy->vps,
704 "Event-Timestamp", "0", T_OP_SET);
705 vp->vp_date = now.tv_sec;
707 rad_assert("Internal sanity check failed");
711 radius_pairmake(request, &request->proxy->vps,
712 "NAS-Identifier", "Status Check. Are you alive?",
715 request->proxy->dst_ipaddr = home->ipaddr;
716 request->proxy->dst_port = home->port;
717 request->home_server = home;
719 rad_assert(request->proxy_listener == NULL);
721 if (!insert_into_proxy_hash(request)) {
722 RDEBUG2("ERROR: Failed inserting status check %d into proxy hash. Discarding it.",
724 request_free(&request);
727 rad_assert(request->proxy_listener != NULL);
728 request->proxy_listener->send(request->proxy_listener,
731 request->next_callback = NULL;
732 request->child_state = REQUEST_PROXIED;
733 request->when.tv_sec += home->ping_timeout;;
735 INSERT_EVENT(no_response_to_ping, request);
738 * Add +/- 2s of jitter, as suggested in RFC 3539
739 * and in the Issues and Fixes draft.
741 home->when.tv_sec += home->ping_interval - 2;
744 jitter ^= (jitter >> 10);
745 jitter &= ((1 << 23) - 1); /* 22 bits of 1 */
747 tv_add(&home->when, jitter);
749 INSERT_EVENT(ping_home_server, home);
753 void mark_home_server_dead(home_server *home, struct timeval *when)
755 int previous_state = home->state;
758 radlog(L_INFO, "PROXY: Marking home server %s port %d as dead.",
759 inet_ntop(home->ipaddr.af, &home->ipaddr.ipaddr,
760 buffer, sizeof(buffer)),
763 home->state = HOME_STATE_IS_DEAD;
764 home->num_received_pings = 0;
766 if (home->ping_check != HOME_PING_CHECK_NONE) {
768 * If the control socket marks us dead, start
769 * pinging. Otherwise, we already started
770 * pinging when it was marked "zombie".
772 if (previous_state == HOME_STATE_ALIVE) {
773 ping_home_server(home);
778 * Revive it after a fixed period of time. This
779 * is very, very, bad.
782 home->when.tv_sec += home->revive_interval;
784 INSERT_EVENT(revive_home_server, home);
788 static void check_for_zombie_home_server(REQUEST *request)
793 home = request->home_server;
795 if (home->state != HOME_STATE_ZOMBIE) return;
797 when = home->zombie_period_start;
798 when.tv_sec += home->zombie_period;
800 fr_event_now(el, &now);
801 if (timercmp(&now, &when, <)) {
805 mark_home_server_dead(home, &request->when);
808 static int proxy_to_virtual_server(REQUEST *request);
810 static int virtual_server_handler(UNUSED REQUEST *request)
812 proxy_to_virtual_server(request);
816 static void proxy_fallback_handler(REQUEST *request)
819 * A proper time is required for wait_a_bit.
821 request->delay = USEC / 10;
822 gettimeofday(&now, NULL);
823 request->next_when = now;
824 tv_add(&request->next_when, request->delay);
825 request->next_callback = wait_a_bit;
828 * Re-queue the request.
830 request->child_state = REQUEST_QUEUED;
832 rad_assert(request->proxy != NULL);
833 if (!thread_pool_addrequest(request, virtual_server_handler)) {
834 request->child_state = REQUEST_DONE;
837 #ifdef HAVE_PTHREAD_H
839 * MAY free the request if we're over max_request_time,
840 * AND we're not in threaded mode!
842 * Note that we call this ONLY if we're threaded, as
843 * if we're NOT threaded, request_post_handler() calls
844 * wait_a_bit(), which means that "request" may not
847 if (have_children) wait_a_bit(request);
852 static int setup_post_proxy_fail(REQUEST *request)
854 DICT_VALUE *dval = NULL;
857 if (request->packet->code == PW_AUTHENTICATION_REQUEST) {
858 dval = dict_valbyname(PW_POST_PROXY_TYPE, "Fail-Authentication");
860 } else if (request->packet->code == PW_ACCOUNTING_REQUEST) {
861 dval = dict_valbyname(PW_POST_PROXY_TYPE, "Fail-Accounting");
867 if (!dval) dval = dict_valbyname(PW_POST_PROXY_TYPE, "Fail");
870 pairdelete(&request->config_items, PW_POST_PROXY_TYPE);
874 vp = pairfind(request->config_items, PW_POST_PROXY_TYPE);
875 if (!vp) vp = radius_paircreate(request, &request->config_items,
876 PW_POST_PROXY_TYPE, PW_TYPE_INTEGER);
877 vp->vp_integer = dval->value;
879 rad_assert(request->proxy_reply == NULL);
885 static int null_handler(UNUSED REQUEST *request)
890 static void post_proxy_fail_handler(REQUEST *request)
893 * A proper time is required for wait_a_bit.
895 request->delay = USEC / 10;
896 gettimeofday(&now, NULL);
899 * Not set up to run Post-Proxy-Type = Fail.
901 * Mark the request as still running, and figure out what
904 if (!setup_post_proxy_fail(request)) {
905 request->child_state = REQUEST_RUNNING;
906 request_post_handler(request);
910 * Re-queue the request.
912 request->child_state = REQUEST_QUEUED;
915 * There is a post-proxy-type of fail. We run
916 * the request through the pre/post proxy
917 * handlers, just like it was a real proxied
918 * request. However, we set the per-request
919 * handler to NULL, as we don't want to do
922 * Note that when we're not threaded, this will
923 * process the request even if it's greater than
924 * max_request_time. That's not fatal.
926 request->priority = 0;
927 rad_assert(request->proxy != NULL);
928 thread_pool_addrequest(request, null_handler);
932 * MAY free the request if we're over max_request_time,
933 * AND we're not in threaded mode!
935 * Note that we call this ONLY if we're threaded, as
936 * if we're NOT threaded, request_post_handler() calls
937 * wait_a_bit(), which means that "request" may not
940 if (have_children) wait_a_bit(request);
944 /* maybe check this against wait_for_proxy_id_to_expire? */
945 static void no_response_to_proxied_request(void *ctx)
947 REQUEST *request = ctx;
951 rad_assert(request->magic == REQUEST_MAGIC);
952 rad_assert(request->child_state == REQUEST_PROXIED);
955 * If we've failed over to an internal home server,
956 * replace the callback with the correct one. This
957 * is due to locking issues with child threads...
959 if (request->home_server->server) {
964 radlog(L_ERR, "Rejecting request %d due to lack of any response from home server %s port %d",
966 inet_ntop(request->proxy->dst_ipaddr.af,
967 &request->proxy->dst_ipaddr.ipaddr,
968 buffer, sizeof(buffer)),
969 request->proxy->dst_port);
971 check_for_zombie_home_server(request);
973 home = request->home_server;
975 post_proxy_fail_handler(request);
978 * Don't touch request due to race conditions
980 if (home->state == HOME_STATE_IS_DEAD) {
981 rad_assert(home->ev != NULL); /* or it will never wake up */
986 * Enable the zombie period when we notice that the home
987 * server hasn't responded. We do NOT back-date the start
988 * of the zombie period.
990 if (home->state == HOME_STATE_ALIVE) {
991 radlog(L_ERR, "PROXY: Marking home server %s port %d as zombie (it looks like it is dead).",
992 inet_ntop(home->ipaddr.af, &home->ipaddr.ipaddr,
993 buffer, sizeof(buffer)),
995 home->state = HOME_STATE_ZOMBIE;
996 home->zombie_period_start = now;
999 * Start pinging the home server.
1001 ping_home_server(home);
1006 static void wait_a_bit(void *ctx)
1008 struct timeval when;
1009 REQUEST *request = ctx;
1010 fr_event_callback_t callback = NULL;
1012 rad_assert(request->magic == REQUEST_MAGIC);
1014 switch (request->child_state) {
1015 case REQUEST_QUEUED:
1016 case REQUEST_RUNNING:
1017 when = request->received;
1018 when.tv_sec += request->root->max_request_time;
1021 * Normally called from the event loop with the
1022 * proper event loop time. Otherwise, called from
1023 * post proxy fail handler, which sets "now", and
1024 * this call won't re-set it, because we're not
1025 * in the event loop.
1027 fr_event_now(el, &now);
1030 * Request still has more time. Continue
1033 if (timercmp(&now, &when, <) ||
1034 ((request->listener->type == RAD_LISTEN_DETAIL) &&
1035 (request->child_state == REQUEST_QUEUED))) {
1036 if (request->delay < (USEC / 10)) {
1037 request->delay = USEC / 10;
1039 request->delay += request->delay >> 1;
1043 * Cap wait at some sane value for detail
1046 if ((request->listener->type == RAD_LISTEN_DETAIL) &&
1047 (request->delay > (request->root->max_request_time * USEC))) {
1048 request->delay = request->root->max_request_time * USEC;
1052 request->when = now;
1053 tv_add(&request->when, request->delay);
1054 callback = wait_a_bit;
1058 #if defined(HAVE_PTHREAD_H)
1060 * A child thread MAY still be running on the
1061 * request. Ask the thread to stop working on
1064 if (have_children) {
1065 /* FIXME: kill unresponsive children? */
1068 * Print this error message ONLY if
1069 * there's a child currently processing
1070 * the request. As we don't have thread
1071 * locks here, there may be race
1072 * conditions on this check. But it's
1073 * just an error message, so that's OK.
1075 if (!pthread_equal(request->child_pid, NO_SUCH_CHILD_PID)) {
1076 radlog(L_ERR, "WARNING: Unresponsive child for request %d, in module %s component %s",
1078 request->module ? request->module : "<server core>",
1079 request->component ? request->component : "<server core>");
1082 request->master_state = REQUEST_STOP_PROCESSING;
1084 request->delay = USEC / 4;
1085 tv_add(&request->when, request->delay);
1086 callback = wait_for_child_to_die;
1092 * Else there are no child threads. We probably
1093 * should have just marked the request as 'done'
1094 * elsewhere, like in the post-proxy-fail
1095 * handler. But doing that would involve
1096 * checking for max_request_time in multiple
1097 * places, so this may be simplest.
1099 request->child_state = REQUEST_DONE;
1103 * Mark the request as no longer running,
1107 #ifdef HAVE_PTHREAD_H
1108 request->child_pid = NO_SUCH_CHILD_PID;
1110 request_stats_final(request);
1111 cleanup_delay(request);
1114 case REQUEST_REJECT_DELAY:
1115 case REQUEST_CLEANUP_DELAY:
1116 #ifdef HAVE_PTHREAD_H
1117 request->child_pid = NO_SUCH_CHILD_PID;
1119 request_stats_final(request);
1121 case REQUEST_PROXIED:
1122 rad_assert(request->next_callback != NULL);
1123 rad_assert(request->next_callback != wait_a_bit);
1125 request->when = request->next_when;
1126 callback = request->next_callback;
1127 request->next_callback = NULL;
1131 rad_panic("Internal sanity check failure");
1136 * Something major went wrong. Discard the request, and
1139 * FIXME: No idea why this happens or how to fix it...
1140 * It seems to happen *only* when requests are proxied,
1141 * and where the home server doesn't respond. So it looks
1142 * like a race condition above, but it happens in debug
1143 * mode, with no threads...
1146 RDEBUG("WARNING: Internal sanity check failed in event handler for request %d: Discarding the request!", request->number);
1147 fr_event_delete(el, &request->ev);
1148 remove_from_proxy_hash(request);
1149 remove_from_request_hash(request);
1150 request_free(&request);
1154 INSERT_EVENT(callback, request);
1159 static int process_proxy_reply(REQUEST *request)
1162 int post_proxy_type = 0;
1166 * Delete any reply we had accumulated until now.
1168 pairfree(&request->reply->vps);
1171 * Run the packet through the post-proxy stage,
1172 * BEFORE playing games with the attributes.
1174 vp = pairfind(request->config_items, PW_POST_PROXY_TYPE);
1176 RDEBUG2(" Found Post-Proxy-Type %s", vp->vp_strvalue);
1177 post_proxy_type = vp->vp_integer;
1180 rad_assert(request->home_pool != NULL);
1182 if (request->home_pool->virtual_server) {
1183 const char *old_server = request->server;
1185 request->server = request->home_pool->virtual_server;
1186 RDEBUG2(" server %s {", request->server);
1187 rcode = module_post_proxy(post_proxy_type, request);
1189 request->server = old_server;
1191 rcode = module_post_proxy(post_proxy_type, request);
1195 * There may NOT be a proxy reply, as we may be
1196 * running Post-Proxy-Type = Fail.
1198 if (request->proxy_reply) {
1200 * Delete the Proxy-State Attributes from
1201 * the reply. These include Proxy-State
1202 * attributes from us and remote server.
1204 pairdelete(&request->proxy_reply->vps, PW_PROXY_STATE);
1207 * Add the attributes left in the proxy
1208 * reply to the reply list.
1210 pairadd(&request->reply->vps, request->proxy_reply->vps);
1211 request->proxy_reply->vps = NULL;
1214 * Free proxy request pairs.
1216 pairfree(&request->proxy->vps);
1220 default: /* Don't do anything */
1222 case RLM_MODULE_FAIL:
1223 /* FIXME: debug print stuff */
1224 request->child_state = REQUEST_DONE;
1227 case RLM_MODULE_HANDLED:
1228 /* FIXME: debug print stuff */
1229 request->child_state = REQUEST_DONE;
1237 static int request_pre_handler(REQUEST *request)
1241 rad_assert(request->magic == REQUEST_MAGIC);
1242 rad_assert(request->packet != NULL);
1244 request->child_state = REQUEST_RUNNING;
1247 * Don't decode the packet if it's an internal "fake"
1248 * request. Instead, just return so that the caller can
1251 if (request->packet->dst_port == 0) {
1252 request->username = pairfind(request->packet->vps,
1254 request->password = pairfind(request->packet->vps,
1261 * Put the decoded packet into it's proper place.
1263 if (request->proxy_reply != NULL) {
1264 rcode = request->proxy_listener->decode(request->proxy_listener,
1266 DEBUG_PACKET(request, request->proxy_reply, 0);
1269 if (request->packet->vps == NULL) {
1270 rcode = request->listener->decode(request->listener, request);
1272 if (debug_condition) {
1274 const char *my_debug = debug_condition;
1277 * Ignore parse errors.
1279 radius_evaluate_condition(request, RLM_MODULE_OK, 0,
1283 request->options = 2;
1284 request->radlog = radlog_request;
1288 DEBUG_PACKET(request, request->packet, 0);
1294 radlog(L_ERR, "%s Dropping packet without response.", fr_strerror());
1295 request->child_state = REQUEST_DONE;
1300 if (!request->proxy)
1303 request->username = pairfind(request->packet->vps,
1308 return process_proxy_reply(request);
1318 * Do state handling when we proxy a request.
1320 static int proxy_request(REQUEST *request)
1322 struct timeval when;
1325 if (request->home_server->server) {
1326 RDEBUG("ERROR: Cannot perform real proxying to a virtual server.");
1330 if (!insert_into_proxy_hash(request)) {
1331 RDEBUG("ERROR: Failed inserting request into proxy hash.");
1335 request->proxy_listener->encode(request->proxy_listener, request);
1337 when = request->received;
1338 when.tv_sec += request->root->max_request_time;
1340 gettimeofday(&request->proxy_when, NULL);
1342 request->next_when = request->proxy_when;
1343 request->next_when.tv_sec += request->home_server->response_window;
1345 rad_assert(request->home_server->response_window > 0);
1347 if (timercmp(&when, &request->next_when, <)) {
1348 request->next_when = when;
1350 request->next_callback = no_response_to_proxied_request;
1352 RDEBUG2("Proxying request %d to home server %s port %d",
1354 inet_ntop(request->proxy->dst_ipaddr.af,
1355 &request->proxy->dst_ipaddr.ipaddr,
1356 buffer, sizeof(buffer)),
1357 request->proxy->dst_port);
1360 * Note that we set proxied BEFORE sending the packet.
1362 * Once we send it, the request is tainted, as
1363 * another thread may have picked it up. Don't
1366 request->num_proxied_requests = 1;
1367 request->num_proxied_responses = 0;
1368 #ifdef HAVE_PTHREAD_H
1369 request->child_pid = NO_SUCH_CHILD_PID;
1371 request->child_state = REQUEST_PROXIED;
1373 DEBUG_PACKET(request, request->proxy, 1);
1375 request->proxy_listener->send(request->proxy_listener,
1382 * "Proxy" the request by sending it to a new virtual server.
1384 static int proxy_to_virtual_server(REQUEST *request)
1387 RAD_REQUEST_FUNP fun;
1389 if (!request->home_server || !request->home_server->server) return 0;
1391 if (request->parent) {
1392 RDEBUG2("WARNING: Cancelling proxy request to virtual server %s as this request was itself proxied.", request->home_server->server);
1396 fake = request_alloc_fake(request);
1398 RDEBUG2("WARNING: Out of memory");
1402 fake->packet->vps = paircopy(request->proxy->vps);
1403 fake->server = request->home_server->server;
1405 if (request->proxy->code == PW_AUTHENTICATION_REQUEST) {
1406 fun = rad_authenticate;
1408 #ifdef WITH_ACCOUNTING
1409 } else if (request->proxy->code == PW_ACCOUNTING_REQUEST) {
1410 fun = rad_accounting;
1414 RDEBUG2("Unknown packet type %d", request->proxy->code);
1415 request_free(&fake);
1419 RDEBUG2(">>> Sending proxied request internally to virtual server.");
1420 radius_handle_request(fake, fun);
1421 RDEBUG2("<<< Received proxied response from internal virtual server.");
1423 request->proxy_reply = fake->reply;
1426 request_free(&fake);
1428 process_proxy_reply(request);
1431 return 2; /* success, but NOT '1' !*/
1436 * Return 1 if we did proxy it, or the proxy attempt failed
1437 * completely. Either way, the caller doesn't touch the request
1438 * any more if we return 1.
1440 static int successfully_proxied_request(REQUEST *request)
1443 int pre_proxy_type = 0;
1444 VALUE_PAIR *realmpair;
1445 VALUE_PAIR *strippedname;
1449 REALM *realm = NULL;
1453 * If it was already proxied, do nothing.
1455 * FIXME: This should really be a serious error.
1457 if (request->in_proxy_hash) {
1461 realmpair = pairfind(request->config_items, PW_PROXY_TO_REALM);
1462 if (!realmpair || (realmpair->length == 0)) {
1466 realmname = (char *) realmpair->vp_strvalue;
1468 realm = realm_find2(realmname);
1470 RDEBUG2("ERROR: Cannot proxy to unknown realm %s", realmname);
1475 * Figure out which pool to use.
1477 if (request->packet->code == PW_AUTHENTICATION_REQUEST) {
1478 pool = realm->auth_pool;
1480 #ifdef WITH_ACCOUNTING
1481 } else if (request->packet->code == PW_ACCOUNTING_REQUEST) {
1482 pool = realm->acct_pool;
1486 rad_panic("Internal sanity check failed");
1490 RDEBUG2(" WARNING: Cancelling proxy to Realm %s, as the realm is local.",
1495 home = home_server_ldb(realmname, pool, request);
1497 RDEBUG2("ERROR: Failed to find live home server for realm %s",
1501 request->home_pool = pool;
1504 * Remember that we sent the request to a Realm.
1506 pairadd(&request->packet->vps,
1507 pairmake("Realm", realmname, T_OP_EQ));
1511 * We read the packet from a detail file, AND it came from
1512 * the server we're about to send it to. Don't do that.
1514 if ((request->packet->code == PW_ACCOUNTING_REQUEST) &&
1515 (request->listener->type == RAD_LISTEN_DETAIL) &&
1516 (home->ipaddr.af == AF_INET) &&
1517 (request->packet->src_ipaddr.af == AF_INET) &&
1518 (home->ipaddr.ipaddr.ip4addr.s_addr == request->packet->src_ipaddr.ipaddr.ip4addr.s_addr)) {
1519 RDEBUG2(" rlm_realm: Packet came from realm %s, proxy cancelled", realmname);
1525 * Allocate the proxy packet, only if it wasn't already
1526 * allocated by a module. This check is mainly to support
1527 * the proxying of EAP-TTLS and EAP-PEAP tunneled requests.
1529 * In those cases, the EAP module creates a "fake"
1530 * request, and recursively passes it through the
1531 * authentication stage of the server. The module then
1532 * checks if the request was supposed to be proxied, and
1533 * if so, creates a proxy packet from the TUNNELED request,
1534 * and not from the EAP request outside of the tunnel.
1536 * The proxy then works like normal, except that the response
1537 * packet is "eaten" by the EAP module, and encapsulated into
1540 if (!request->proxy) {
1541 if ((request->proxy = rad_alloc(TRUE)) == NULL) {
1542 radlog(L_ERR|L_CONS, "no memory");
1547 * Copy the request, then look up name and
1548 * plain-text password in the copy.
1550 * Note that the User-Name attribute is the
1551 * *original* as sent over by the client. The
1552 * Stripped-User-Name attribute is the one hacked
1553 * through the 'hints' file.
1555 request->proxy->vps = paircopy(request->packet->vps);
1559 * Strip the name, if told to.
1561 * Doing it here catches the case of proxied tunneled
1564 if (realm->striprealm == TRUE &&
1565 (strippedname = pairfind(request->proxy->vps, PW_STRIPPED_USER_NAME)) != NULL) {
1567 * If there's a Stripped-User-Name attribute in
1568 * the request, then use THAT as the User-Name
1569 * for the proxied request, instead of the
1572 * This is done by making a copy of the
1573 * Stripped-User-Name attribute, turning it into
1574 * a User-Name attribute, deleting the
1575 * Stripped-User-Name and User-Name attributes
1576 * from the vps list, and making the new
1577 * User-Name the head of the vps list.
1579 vp = pairfind(request->proxy->vps, PW_USER_NAME);
1581 vp = radius_paircreate(request, NULL,
1582 PW_USER_NAME, PW_TYPE_STRING);
1583 rad_assert(vp != NULL); /* handled by above function */
1584 /* Insert at the START of the list */
1585 vp->next = request->proxy->vps;
1586 request->proxy->vps = vp;
1588 memcpy(vp->vp_strvalue, strippedname->vp_strvalue,
1589 sizeof(vp->vp_strvalue));
1590 vp->length = strippedname->length;
1593 * Do NOT delete Stripped-User-Name.
1598 * If there is no PW_CHAP_CHALLENGE attribute but
1599 * there is a PW_CHAP_PASSWORD we need to add it
1600 * since we can't use the request authenticator
1601 * anymore - we changed it.
1603 if (pairfind(request->proxy->vps, PW_CHAP_PASSWORD) &&
1604 pairfind(request->proxy->vps, PW_CHAP_CHALLENGE) == NULL) {
1605 vp = radius_paircreate(request, &request->proxy->vps,
1606 PW_CHAP_CHALLENGE, PW_TYPE_OCTETS);
1607 vp->length = AUTH_VECTOR_LEN;
1608 memcpy(vp->vp_strvalue, request->packet->vector, AUTH_VECTOR_LEN);
1612 * The RFC's say we have to do this, but FreeRADIUS
1615 vp = radius_paircreate(request, &request->proxy->vps,
1616 PW_PROXY_STATE, PW_TYPE_OCTETS);
1617 snprintf(vp->vp_strvalue, sizeof(vp->vp_strvalue), "%d",
1618 request->packet->id);
1619 vp->length = strlen(vp->vp_strvalue);
1622 * Should be done BEFORE inserting into proxy hash, as
1623 * pre-proxy may use this information, or change it.
1625 request->proxy->code = request->packet->code;
1626 request->proxy->dst_ipaddr = home->ipaddr;
1627 request->proxy->dst_port = home->port;
1628 request->home_server = home;
1631 * Call the pre-proxy routines.
1633 vp = pairfind(request->config_items, PW_PRE_PROXY_TYPE);
1635 RDEBUG2(" Found Pre-Proxy-Type %s", vp->vp_strvalue);
1636 pre_proxy_type = vp->vp_integer;
1639 rad_assert(request->home_pool != NULL);
1641 if (request->home_pool->virtual_server) {
1642 const char *old_server = request->server;
1644 request->server = request->home_pool->virtual_server;
1645 RDEBUG2(" server %s {", request->server);
1646 rcode = module_pre_proxy(pre_proxy_type, request);
1648 request->server = old_server;
1650 rcode = module_pre_proxy(pre_proxy_type, request);
1653 case RLM_MODULE_FAIL:
1654 case RLM_MODULE_INVALID:
1655 case RLM_MODULE_NOTFOUND:
1656 case RLM_MODULE_USERLOCK:
1658 /* FIXME: debug print failed stuff */
1661 case RLM_MODULE_REJECT:
1662 case RLM_MODULE_HANDLED:
1666 * Only proxy the packet if the pre-proxy code succeeded.
1668 case RLM_MODULE_NOOP:
1670 case RLM_MODULE_UPDATED:
1675 * If it's a fake request, don't send the proxy
1676 * packet. The outer tunnel session will take
1677 * care of doing that.
1679 if (request->packet->dst_port == 0) {
1680 request->home_server = NULL;
1684 if (request->home_server->server) {
1685 return proxy_to_virtual_server(request);
1688 if (!proxy_request(request)) {
1689 RDEBUG("ERROR: Failed to proxy request %d", request->number);
1698 static void request_post_handler(REQUEST *request)
1700 int child_state = -1;
1701 struct timeval when;
1704 if ((request->master_state == REQUEST_STOP_PROCESSING) ||
1706 (request->parent->master_state == REQUEST_STOP_PROCESSING))) {
1707 RDEBUG2("Request %d was cancelled.", request->number);
1708 #ifdef HAVE_PTHREAD_H
1709 request->child_pid = NO_SUCH_CHILD_PID;
1711 request->child_state = REQUEST_DONE;
1715 if (request->child_state != REQUEST_RUNNING) {
1716 rad_panic("Internal sanity check failed");
1719 if ((request->reply->code == 0) &&
1720 ((vp = pairfind(request->config_items, PW_AUTH_TYPE)) != NULL) &&
1721 (vp->vp_integer == PW_AUTHTYPE_REJECT)) {
1722 request->reply->code = PW_AUTHENTICATION_REJECT;
1726 if (request->root->proxy_requests &&
1727 !request->in_proxy_hash &&
1728 (request->reply->code == 0) &&
1729 (request->packet->dst_port != 0) &&
1730 (request->packet->code != PW_STATUS_SERVER)) {
1731 int rcode = successfully_proxied_request(request);
1733 if (rcode == 1) return;
1736 * Failed proxying it (dead home servers, etc.)
1737 * Run it through Post-Proxy-Type = Fail, and
1738 * respond to the request.
1740 * Note that we're in a child thread here, so we
1741 * do NOT re-schedule the request. Instead, we
1742 * do what we would have done, which is run the
1743 * pre-handler, a NULL request handler, and then
1746 if ((rcode < 0) && setup_post_proxy_fail(request)) {
1747 request_pre_handler(request);
1751 * Else we weren't supposed to proxy it,
1752 * OR we proxied it internally to a virutal server.
1758 * Fake requests don't get encoded or signed. The caller
1759 * also requires the reply VP's, so we don't free them
1762 if (request->packet->dst_port == 0) {
1763 /* FIXME: RDEBUG going to the next request */
1764 #ifdef HAVE_PTHREAD_H
1765 request->child_pid = NO_SUCH_CHILD_PID;
1767 request->child_state = REQUEST_DONE;
1773 * Copy Proxy-State from the request to the reply.
1775 vp = paircopy2(request->packet->vps, PW_PROXY_STATE);
1776 if (vp) pairadd(&request->reply->vps, vp);
1780 * Access-Requests get delayed or cached.
1782 switch (request->packet->code) {
1783 case PW_AUTHENTICATION_REQUEST:
1784 gettimeofday(&request->next_when, NULL);
1786 if (request->reply->code == 0) {
1788 * Check if the lack of response is intentional.
1790 vp = pairfind(request->config_items,
1791 PW_RESPONSE_PACKET_TYPE);
1793 RDEBUG2("There was no response configured: rejecting request %d",
1795 request->reply->code = PW_AUTHENTICATION_REJECT;
1796 } else if (vp->vp_integer == 256) {
1797 RDEBUG2("Not responding to request %d",
1801 request->reply->code = vp->vp_integer;
1807 * Run rejected packets through
1809 * Post-Auth-Type = Reject
1811 if (request->reply->code == PW_AUTHENTICATION_REJECT) {
1812 pairdelete(&request->config_items, PW_POST_AUTH_TYPE);
1813 vp = radius_pairmake(request, &request->config_items,
1814 "Post-Auth-Type", "Reject",
1816 if (vp) rad_postauth(request);
1819 * If configured, delay Access-Reject packets.
1821 * If request->root->reject_delay = 0, we discover
1822 * that we have to send the packet now.
1824 when = request->received;
1825 when.tv_sec += request->root->reject_delay;
1827 if (timercmp(&when, &request->next_when, >)) {
1828 RDEBUG2("Delaying reject of request %d for %d seconds",
1830 request->root->reject_delay);
1831 request->next_when = when;
1832 request->next_callback = reject_delay;
1833 #ifdef HAVE_PTHREAD_H
1834 request->child_pid = NO_SUCH_CHILD_PID;
1836 request->child_state = REQUEST_REJECT_DELAY;
1841 request->next_when.tv_sec += request->root->cleanup_delay;
1842 request->next_callback = cleanup_delay;
1843 child_state = REQUEST_CLEANUP_DELAY;
1846 case PW_ACCOUNTING_REQUEST:
1847 request->next_callback = NULL; /* just to be safe */
1848 child_state = REQUEST_DONE;
1852 * FIXME: Status-Server should probably not be
1855 case PW_STATUS_SERVER:
1856 request->next_callback = NULL;
1857 child_state = REQUEST_DONE;
1861 if ((request->packet->code > 1024) &&
1862 (request->packet->code < (1024 + 254 + 1))) {
1863 request->next_callback = NULL;
1864 child_state = REQUEST_DONE;
1868 radlog(L_ERR, "Unknown packet type %d", request->packet->code);
1869 rad_panic("Unknown packet type");
1874 * Suppress "no reply" packets here, unless we're reading
1875 * from the "detail" file. In that case, we've got to
1876 * tell the detail file handler that the request is dead,
1877 * and it should re-send it.
1878 * If configured, encode, sign, and send.
1880 if ((request->reply->code != 0) ||
1881 (request->listener->type == RAD_LISTEN_DETAIL)) {
1882 DEBUG_PACKET(request, request->reply, 1);
1883 request->listener->send(request->listener, request);
1887 * Clean up. These are no longer needed.
1889 pairfree(&request->config_items);
1891 pairfree(&request->packet->vps);
1892 request->username = NULL;
1893 request->password = NULL;
1895 pairfree(&request->reply->vps);
1898 if (request->proxy) {
1899 pairfree(&request->proxy->vps);
1901 if (request->proxy_reply) {
1902 pairfree(&request->proxy_reply->vps);
1907 * We're not tracking responses from the home
1908 * server, we can therefore free this memory in
1911 if (!request->in_proxy_hash) {
1912 rad_free(&request->proxy);
1913 rad_free(&request->proxy_reply);
1914 request->home_server = NULL;
1920 RDEBUG2("Finished request %d.", request->number);
1922 request->child_state = child_state;
1925 * Single threaded mode: update timers now.
1927 if (!have_children) wait_a_bit(request);
1931 static void received_retransmit(REQUEST *request, const RADCLIENT *client)
1937 RAD_STATS_TYPE_INC(request->listener, total_dup_requests);
1938 RAD_STATS_CLIENT_INC(request->listener, client, total_dup_requests);
1940 switch (request->child_state) {
1941 case REQUEST_QUEUED:
1942 case REQUEST_RUNNING:
1946 radlog(L_ERR, "Discarding duplicate request from "
1947 "client %s port %d - ID: %d due to unfinished request %d",
1949 request->packet->src_port,request->packet->id,
1954 case REQUEST_PROXIED:
1956 * We're not supposed to have duplicate
1957 * accounting packets. The other states handle
1958 * duplicates fine (discard, or send duplicate
1959 * reply). But we do NOT want to retransmit an
1960 * accounting request here, because that would
1961 * involve updating the Acct-Delay-Time, and
1962 * therefore changing the packet Id, etc.
1964 * Instead, we just discard the packet. We may
1965 * eventually respond, or the client will send a
1966 * new accounting packet.
1968 if (request->packet->code == PW_ACCOUNTING_REQUEST) {
1972 check_for_zombie_home_server(request);
1975 * If we've just discovered that the home server is
1976 * dead, send the packet to another one.
1978 if ((request->packet->dst_port != 0) &&
1979 (request->home_server->state == HOME_STATE_IS_DEAD)) {
1982 remove_from_proxy_hash(request);
1984 home = home_server_ldb(NULL, request->home_pool, request);
1986 RDEBUG2("Failed to find live home server for request %d", request->number);
1989 * Do post-request processing,
1990 * and any insertion of necessary
1993 post_proxy_fail_handler(request);
1997 request->proxy->code = request->packet->code;
1998 request->proxy->dst_ipaddr = home->ipaddr;
1999 request->proxy->dst_port = home->port;
2000 request->home_server = home;
2003 * Free the old packet, to force re-encoding
2005 free(request->proxy->data);
2006 request->proxy->data = NULL;
2007 request->proxy->data_len = 0;
2010 * This request failed over to a virtual
2011 * server. Push it back onto the queue
2014 if (request->home_server->server) {
2015 proxy_fallback_handler(request);
2020 * Try to proxy the request.
2022 if (!proxy_request(request)) {
2023 RDEBUG("ERROR: Failed to re-proxy request %d", request->number);
2024 goto no_home_servers;
2028 * This code executes in the main server
2029 * thread, so there's no need for locking.
2031 rad_assert(request->next_callback != NULL);
2032 INSERT_EVENT(request->next_callback, request);
2033 request->next_callback = NULL;
2035 } /* else the home server is still alive */
2037 RDEBUG2("Sending duplicate proxied request to home server %s port %d - ID: %d",
2038 inet_ntop(request->proxy->dst_ipaddr.af,
2039 &request->proxy->dst_ipaddr.ipaddr,
2040 buffer, sizeof(buffer)),
2041 request->proxy->dst_port,
2042 request->proxy->id);
2043 request->num_proxied_requests++;
2045 DEBUG_PACKET(request, request->proxy, 1);
2046 request->proxy_listener->send(request->proxy_listener,
2051 case REQUEST_REJECT_DELAY:
2052 RDEBUG2("Waiting to send Access-Reject "
2053 "to client %s port %d - ID: %d",
2055 request->packet->src_port, request->packet->id);
2058 case REQUEST_CLEANUP_DELAY:
2060 RDEBUG2("Sending duplicate reply "
2061 "to client %s port %d - ID: %d",
2063 request->packet->src_port, request->packet->id);
2064 DEBUG_PACKET(request, request->reply, 1);
2065 request->listener->send(request->listener, request);
2071 static void received_conflicting_request(REQUEST *request,
2072 const RADCLIENT *client)
2074 radlog(L_ERR, "Received conflicting packet from "
2075 "client %s port %d - ID: %d due to unfinished request %d. Giving up on old request.",
2077 request->packet->src_port, request->packet->id,
2081 * Nuke it from the request hash, so we can receive new
2084 remove_from_request_hash(request);
2086 switch (request->child_state) {
2087 #ifdef HAVE_PTHREAD_H
2089 * It's queued or running. Tell it to stop, and
2090 * wait for it to do so.
2092 case REQUEST_QUEUED:
2093 case REQUEST_RUNNING:
2094 request->master_state = REQUEST_STOP_PROCESSING;
2095 request->delay += request->delay >> 1;
2097 tv_add(&request->when, request->delay);
2099 INSERT_EVENT(wait_for_child_to_die, request);
2104 * It's in some other state, and therefore also
2105 * in the event queue. At some point, the
2106 * child will notice, and we can then delete it.
2109 rad_assert(request->ev != NULL);
2115 static int can_handle_new_request(RADIUS_PACKET *packet,
2117 struct main_config_t *root)
2120 * Count the total number of requests, to see if
2121 * there are too many. If so, return with an
2124 if (root->max_requests) {
2125 int request_count = fr_packet_list_num_elements(pl);
2128 * This is a new request. Let's see if
2129 * it makes us go over our configured
2132 if (request_count > root->max_requests) {
2133 radlog(L_ERR, "Dropping request (%d is too many): "
2134 "from client %s port %d - ID: %d", request_count,
2136 packet->src_port, packet->id);
2137 radlog(L_INFO, "WARNING: Please check the configuration file.\n"
2138 "\tThe value for 'max_requests' is probably set too low.\n");
2140 } /* else there were a small number of requests */
2141 } /* else there was no configured limit for requests */
2144 * FIXME: Add per-client checks. If one client is sending
2145 * too many packets, start discarding them.
2147 * We increment the counters here, and decrement them
2148 * when the response is sent... somewhere in this file.
2152 * FUTURE: Add checks for system load. If the system is
2153 * busy, start dropping requests...
2155 * We can probably keep some statistics ourselves... if
2156 * there are more requests coming in than we can handle,
2157 * start dropping some.
2164 int received_request(rad_listen_t *listener,
2165 RADIUS_PACKET *packet, REQUEST **prequest,
2168 RADIUS_PACKET **packet_p;
2169 REQUEST *request = NULL;
2170 struct main_config_t *root = &mainconfig;
2172 packet_p = fr_packet_list_find(pl, packet);
2174 request = fr_packet2myptr(REQUEST, packet, packet_p);
2175 rad_assert(request->in_request_hash);
2177 if ((request->packet->data_len == packet->data_len) &&
2178 (memcmp(request->packet->vector, packet->vector,
2179 sizeof(packet->vector)) == 0)) {
2180 received_retransmit(request, client);
2185 * The new request is different from the old one,
2186 * but maybe the old is finished. If so, delete
2189 switch (request->child_state) {
2190 struct timeval when;
2193 gettimeofday(&when, NULL);
2197 * If the cached request was received
2198 * within the last second, then we
2199 * discard the NEW request instead of the
2200 * old one. This will happen ONLY when
2201 * the client is severely broken, and is
2202 * sending conflicting packets very
2205 if (timercmp(&when, &request->received, <)) {
2206 radlog(L_ERR, "Discarding conflicting packet from "
2207 "client %s port %d - ID: %d due to recent request %d.",
2209 packet->src_port, packet->id,
2214 received_conflicting_request(request, client);
2218 case REQUEST_REJECT_DELAY:
2219 case REQUEST_CLEANUP_DELAY:
2220 request->child_state = REQUEST_DONE;
2222 cleanup_delay(request);
2229 * We may want to quench the new request.
2231 if ((listener->type != RAD_LISTEN_DETAIL) &&
2232 !can_handle_new_request(packet, client, root)) {
2237 * Create and initialize the new request.
2239 request = request_alloc(); /* never fails */
2241 if ((request->reply = rad_alloc(0)) == NULL) {
2242 radlog(L_ERR, "No memory");
2246 request->listener = listener;
2247 request->client = client;
2248 request->packet = packet;
2249 request->packet->timestamp = request->timestamp;
2250 request->number = request_num_counter++;
2251 request->priority = listener->type;
2252 #ifdef HAVE_PTHREAD_H
2253 request->child_pid = NO_SUCH_CHILD_PID;
2257 * Status-Server packets go to the head of the queue.
2259 if (request->packet->code == PW_STATUS_SERVER) request->priority = 0;
2262 * Set virtual server identity
2264 if (client->server) {
2265 request->server = client->server;
2266 } else if (listener->server) {
2267 request->server = listener->server;
2269 request->server = NULL;
2273 * Remember the request in the list.
2275 if (!fr_packet_list_insert(pl, &request->packet)) {
2276 radlog(L_ERR, "Failed to insert request %d in the list of live requests: discarding", request->number);
2277 request_free(&request);
2281 request->in_request_hash = TRUE;
2282 request->root = root;
2286 * The request passes many of our sanity checks.
2287 * From here on in, if anything goes wrong, we
2288 * send a reject message, instead of dropping the
2293 * Build the reply template from the request.
2296 request->reply->sockfd = request->packet->sockfd;
2297 request->reply->dst_ipaddr = request->packet->src_ipaddr;
2298 request->reply->src_ipaddr = request->packet->dst_ipaddr;
2299 request->reply->dst_port = request->packet->src_port;
2300 request->reply->src_port = request->packet->dst_port;
2301 request->reply->id = request->packet->id;
2302 request->reply->code = 0; /* UNKNOWN code */
2303 memcpy(request->reply->vector, request->packet->vector,
2304 sizeof(request->reply->vector));
2305 request->reply->vps = NULL;
2306 request->reply->data = NULL;
2307 request->reply->data_len = 0;
2309 request->master_state = REQUEST_ACTIVE;
2310 request->child_state = REQUEST_QUEUED;
2311 request->next_callback = NULL;
2313 gettimeofday(&request->received, NULL);
2314 request->timestamp = request->received.tv_sec;
2315 request->when = request->received;
2317 request->delay = USEC;
2319 tv_add(&request->when, request->delay);
2321 INSERT_EVENT(wait_a_bit, request);
2323 *prequest = request;
2329 REQUEST *received_proxy_response(RADIUS_PACKET *packet)
2335 if (!home_server_find(&packet->src_ipaddr, packet->src_port)) {
2336 radlog(L_ERR, "Ignoring request from unknown home server %s port %d",
2337 inet_ntop(packet->src_ipaddr.af,
2338 &packet->src_ipaddr.ipaddr,
2339 buffer, sizeof(buffer)),
2346 * Also removes from the proxy hash if responses == requests
2348 request = lookup_in_proxy_hash(packet);
2351 radlog(L_PROXY, "No outstanding request was found for proxy reply from home server %s port %d - ID %d",
2352 inet_ntop(packet->src_ipaddr.af,
2353 &packet->src_ipaddr.ipaddr,
2354 buffer, sizeof(buffer)),
2355 packet->src_port, packet->id);
2360 home = request->home_server;
2362 gettimeofday(&now, NULL);
2365 * FIXME: mark the home server alive?
2367 home->state = HOME_STATE_ALIVE;
2369 if (request->reply && request->reply->code != 0) {
2370 RDEBUG2("We already replied to this request. Discarding response from home server.");
2376 * We had previously received a reply, so we don't need
2377 * to do anything here.
2379 if (request->proxy_reply) {
2380 if (memcmp(request->proxy_reply->vector,
2382 sizeof(request->proxy_reply->vector)) == 0) {
2383 RDEBUG2("Discarding duplicate reply from home server %s port %d - ID: %d for request %d",
2384 inet_ntop(packet->src_ipaddr.af,
2385 &packet->src_ipaddr.ipaddr,
2386 buffer, sizeof(buffer)),
2387 packet->src_port, packet->id,
2391 * ? The home server gave us a new proxy
2392 * reply, which doesn't match the old
2395 RDEBUG2("Ignoring conflicting proxy reply");
2398 /* assert that there's an event queued for request? */
2404 * The average includes our time to receive packets and
2405 * look them up in the hashes, which should be the same
2408 * We update the response time only for the FIRST packet
2411 else if (home->ema.window > 0) {
2412 radius_stats_ema(&home->ema, &now, &request->proxy_when);
2417 switch (request->child_state) {
2418 case REQUEST_QUEUED:
2419 case REQUEST_RUNNING:
2420 rad_panic("Internal sanity check failed for child state");
2423 case REQUEST_REJECT_DELAY:
2424 case REQUEST_CLEANUP_DELAY:
2426 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'",
2427 inet_ntop(packet->src_ipaddr.af,
2428 &packet->src_ipaddr.ipaddr,
2429 buffer, sizeof(buffer)),
2430 packet->src_port, packet->id,
2432 /* assert that there's an event queued for request? */
2436 case REQUEST_PROXIED:
2440 request->proxy_reply = packet;
2444 * Perform RTT calculations, as per RFC 2988 (for TCP).
2445 * Note that we only do so on the first response.
2447 if ((request->num_proxied_responses == 1)
2449 home_server *home = request->home_server;
2451 rtt = now.tv_sec - request->proxy_when.tv_sec;
2454 rtt -= request->proxy_when.tv_usec;
2456 if (!home->has_rtt) {
2457 home->has_rtt = TRUE;
2460 home->rttvar = rtt / 2;
2463 home->rttvar -= home->rttvar >> 2;
2464 home->rttvar += (home->srtt - rtt);
2465 home->srtt -= home->srtt >> 3;
2466 home->srtt += rtt >> 3;
2469 home->rto = home->srtt;
2470 if (home->rttvar > (USEC / 4)) {
2471 home->rto += home->rttvar * 4;
2479 * There's no incoming request, so it's a proxied packet
2482 if (!request->packet) {
2483 received_response_to_ping(request);
2487 request->child_state = REQUEST_QUEUED;
2488 request->when = now;
2489 request->delay = USEC;
2490 request->priority = RAD_LISTEN_PROXY;
2491 tv_add(&request->when, request->delay);
2494 * Wait a bit will take care of max_request_time
2496 INSERT_EVENT(wait_a_bit, request);
2502 void event_new_fd(rad_listen_t *this)
2506 this->print(this, buffer, sizeof(buffer));
2508 if (this->status == RAD_LISTEN_STATUS_INIT) {
2510 DEBUG("Listening on %s", buffer);
2512 DEBUG2(" ... adding new socket %s", buffer);
2514 if (!fr_event_fd_insert(el, 0, this->fd,
2515 event_socket_handler, this)) {
2516 radlog(L_ERR, "Failed remembering handle for proxy socket!");
2520 this->status = RAD_LISTEN_STATUS_KNOWN;
2524 if (this->status == RAD_LISTEN_STATUS_CLOSED) {
2525 DEBUG2(" ... closing socket %s", buffer);
2527 fr_event_fd_delete(el, 0, this->fd);
2528 this->status = RAD_LISTEN_STATUS_FINISH;
2531 * Close the fd AFTER fixing up the requests and
2532 * listeners, so that they don't send/recv on the
2533 * wrong socket (if someone manages to open
2541 static void handle_signal_self(int flag)
2543 if ((flag & (RADIUS_SIGNAL_SELF_EXIT | RADIUS_SIGNAL_SELF_TERM)) != 0) {
2544 if ((flag & RADIUS_SIGNAL_SELF_EXIT) != 0) {
2545 fr_event_loop_exit(el, 1);
2547 fr_event_loop_exit(el, 2);
2551 } /* else exit/term flags weren't set */
2554 * Tell the even loop to stop processing.
2556 if ((flag & RADIUS_SIGNAL_SELF_HUP) != 0) {
2558 static time_t last_hup = 0;
2560 DEBUG("Received HUP signal.");
2563 if ((int) (when - last_hup) < 5) {
2564 radlog(L_INFO, "Ignoring HUP (less than 5s since last one)");
2569 fr_event_loop_exit(el, 0x80);
2573 if ((flag & RADIUS_SIGNAL_SELF_DETAIL) != 0) {
2577 * FIXME: O(N) loops suck.
2579 for (this = mainconfig.listen;
2581 this = this->next) {
2583 struct timeval when;
2585 if (this->type != RAD_LISTEN_DETAIL) continue;
2587 delay = detail_delay(this);
2588 if (!delay) continue;
2590 fr_event_now(el, &now);
2592 tv_add(&when, delay);
2594 if (delay > (USEC / 10)) {
2595 DEBUG("Delaying next detail event for %d.%01u seconds.",
2596 delay / USEC, (delay % USEC) / 100000);
2600 * Reset the detail timer.
2602 if (!fr_event_insert(el, event_poll_detail, this,
2604 radlog(L_ERR, "Failed remembering detail timer");
2611 if ((flag & RADIUS_SIGNAL_SELF_NEW_FD) != 0) {
2614 for (this = mainconfig.listen;
2616 this = this->next) {
2617 if (this->status == RAD_LISTEN_STATUS_KNOWN) continue;
2625 void radius_signal_self(int flag)
2627 handle_signal_self(flag);
2631 * Inform ourselves that we received a signal.
2633 void radius_signal_self(int flag)
2639 * The read MUST be non-blocking for this to work.
2641 rcode = read(self_pipe[0], buffer, sizeof(buffer));
2645 for (i = 0; i < rcode; i++) {
2646 buffer[0] |= buffer[i];
2654 write(self_pipe[1], buffer, 1);
2658 static void event_signal_handler(UNUSED fr_event_list_t *xel,
2659 UNUSED int fd, UNUSED void *ctx)
2664 rcode = read(self_pipe[0], buffer, sizeof(buffer));
2665 if (rcode <= 0) return;
2668 * Merge pending signals.
2670 for (i = 0; i < rcode; i++) {
2671 buffer[0] |= buffer[i];
2674 handle_signal_self(buffer[0]);
2679 static void event_socket_handler(fr_event_list_t *xel, UNUSED int fd,
2682 rad_listen_t *listener = ctx;
2683 RAD_REQUEST_FUNP fun;
2686 rad_assert(xel == el);
2690 if (listener->fd < 0) rad_panic("Socket was closed on us!");
2692 if (!listener->recv(listener, &fun, &request)) return;
2694 if (!thread_pool_addrequest(request, fun)) {
2695 request->child_state = REQUEST_DONE;
2701 * This function is called periodically to see if this detail
2702 * file is available for reading.
2704 static void event_poll_detail(void *ctx)
2707 RAD_REQUEST_FUNP fun;
2709 rad_listen_t *this = ctx;
2710 struct timeval when;
2712 fr_event_now(el, &now);
2716 * Set the next poll time to be 1.0 to 1.1s, to help
2717 * spread the load a bit over time.
2720 when.tv_usec += fr_rand() % (USEC / 10);
2722 rad_assert(this->type == RAD_LISTEN_DETAIL);
2725 * Try to read something.
2727 * FIXME: This does poll AND receive.
2729 rcode = this->recv(this, &fun, &request);
2731 rad_assert(fun != NULL);
2732 rad_assert(request != NULL);
2734 if (!thread_pool_addrequest(request, fun)) {
2735 request->child_state = REQUEST_DONE;
2740 * Reset the poll to fire one second from now. If the
2741 * detail reader DOES read a packet, it will send us a
2742 * signal when it's done, and the signal handler will
2743 * reset the timer to a more appropriate (i.e. shorter)
2746 if (!fr_event_insert(el, event_poll_detail, this,
2748 radlog(L_ERR, "Failed creating handler");
2754 static void event_status(struct timeval *wake)
2756 #if !defined(HAVE_PTHREAD_H) && defined(WNOHANG)
2760 if (debug_flag == 0) {
2762 radlog(L_INFO, "Ready to process requests.");
2763 just_started = FALSE;
2769 DEBUG("Ready to process requests.");
2771 } else if ((wake->tv_sec != 0) ||
2772 (wake->tv_usec >= 100000)) {
2773 DEBUG("Waking up in %d.%01u seconds.",
2774 (int) wake->tv_sec, (unsigned int) wake->tv_usec / 100000);
2779 * FIXME: Put this somewhere else, where it isn't called
2780 * all of the time...
2783 #if !defined(HAVE_PTHREAD_H) && defined(WNOHANG)
2785 * If there are no child threads, then there may
2786 * be child processes. In that case, wait for
2787 * their exit status, and throw that exit status
2788 * away. This helps get rid of zxombie children.
2790 while (waitpid(-1, &argval, WNOHANG) > 0) {
2798 * Externally-visibly functions.
2800 int radius_event_init(CONF_SECTION *cs, int spawn_flag)
2802 rad_listen_t *this, *head = NULL;
2806 time(&fr_start_time);
2808 el = fr_event_list_create(event_status);
2811 pl = fr_packet_list_create(0);
2812 if (!pl) return 0; /* leak el */
2814 request_num_counter = 0;
2817 * Move all of the thread calls to this file?
2819 * It may be best for the mutexes to be in this file...
2821 have_children = spawn_flag;
2824 if (mainconfig.proxy_requests) {
2826 * Create the tree for managing proxied requests and
2829 proxy_list = fr_packet_list_create(1);
2830 if (!proxy_list) return 0;
2832 #ifdef HAVE_PTHREAD_H
2833 if (pthread_mutex_init(&proxy_mutex, NULL) != 0) {
2834 radlog(L_ERR, "FATAL: Failed to initialize proxy mutex: %s",
2843 * Just before we spawn the child threads, force the log
2844 * subsystem to re-open the log file for every write.
2846 if (spawn_flag) force_log_reopen();
2848 #ifdef HAVE_PTHREAD_H
2850 NO_SUCH_CHILD_PID = (pthread_t ) (0);
2852 NO_SUCH_CHILD_PID = pthread_self(); /* not a child thread */
2854 if (thread_pool_init(cs, spawn_flag) < 0) {
2860 DEBUG("%s: #### Skipping IP addresses and Ports ####",
2867 * Child threads need a pipe to signal us, as do the
2870 if (pipe(self_pipe) < 0) {
2871 radlog(L_ERR, "radiusd: Error opening internal pipe: %s",
2875 if (fcntl(self_pipe[0], F_SETFL, O_NONBLOCK | FD_CLOEXEC) < 0) {
2876 radlog(L_ERR, "radiusd: Error setting internal flags: %s",
2880 if (fcntl(self_pipe[1], F_SETFL, O_NONBLOCK | FD_CLOEXEC) < 0) {
2881 radlog(L_ERR, "radiusd: Error setting internal flags: %s",
2886 if (!fr_event_fd_insert(el, 0, self_pipe[0],
2887 event_signal_handler, el)) {
2888 radlog(L_ERR, "Failed creating handler for signals");
2895 * Mark the proxy Fd's as unused.
2900 for (i = 0; i < 32; i++) proxy_fds[i] = -1;
2904 DEBUG("%s: #### Opening IP addresses and Ports ####",
2908 * The server temporarily switches to an unprivileged
2909 * user very early in the bootstrapping process.
2910 * However, some sockets MAY require privileged access
2911 * (bind to device, or to port < 1024, or to raw
2912 * sockets). Those sockets need to call suid up/down
2913 * themselves around the functions that need a privileged
2916 if (listen_init(cs, &head) < 0) {
2921 * At this point, no one has any business *ever* going
2924 fr_suid_down_permanent();
2927 * Add all of the sockets to the event loop.
2931 this = this->next) {
2934 this->print(this, buffer, sizeof(buffer));
2936 switch (this->type) {
2938 struct timeval when;
2940 case RAD_LISTEN_DETAIL:
2941 DEBUG("Listening on %s", buffer);
2944 * Add some initial jitter to help spread
2947 when.tv_sec = fr_start_time + 1;
2948 when.tv_usec = fr_rand() % USEC;
2950 if (!fr_event_insert(el, event_poll_detail, this,
2952 radlog(L_ERR, "Failed creating detail poll timer");
2959 case RAD_LISTEN_PROXY:
2960 rad_assert(proxy_fds[this->fd & 0x1f] == -1);
2961 rad_assert(proxy_listeners[this->fd & 0x1f] == NULL);
2963 proxy_fds[this->fd & 0x1f] = this->fd;
2964 proxy_listeners[this->fd & 0x1f] = this;
2965 if (!fr_packet_list_socket_add(proxy_list,
2977 * The file descriptor isn't ready. Poll for
2978 * when it will become ready. This is for the
2988 mainconfig.listen = head;
2994 static int request_hash_cb(UNUSED void *ctx, void *data)
2996 REQUEST *request = fr_packet2myptr(REQUEST, packet, data);
2999 rad_assert(request->in_proxy_hash == FALSE);
3002 fr_event_delete(el, &request->ev);
3003 remove_from_request_hash(request);
3004 request_free(&request);
3011 static int proxy_hash_cb(UNUSED void *ctx, void *data)
3013 REQUEST *request = fr_packet2myptr(REQUEST, proxy, data);
3015 fr_packet_list_yank(proxy_list, request->proxy);
3016 request->in_proxy_hash = FALSE;
3018 if (!request->in_request_hash) {
3019 fr_event_delete(el, &request->ev);
3020 request_free(&request);
3027 void radius_event_free(void)
3030 * FIXME: Stop all threads, or at least check that
3031 * they're all waiting on the semaphore, and the queues
3037 * There are requests in the proxy hash that aren't
3038 * referenced from anywhere else. Remove them first.
3041 PTHREAD_MUTEX_LOCK(&proxy_mutex);
3042 fr_packet_list_walk(proxy_list, NULL, proxy_hash_cb);
3043 PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
3044 fr_packet_list_free(proxy_list);
3049 fr_packet_list_walk(pl, NULL, request_hash_cb);
3051 fr_packet_list_free(pl);
3054 fr_event_list_free(el);
3057 int radius_event_process(void)
3061 return fr_event_loop(el);
3064 void radius_handle_request(REQUEST *request, RAD_REQUEST_FUNP fun)
3066 request->options = RAD_REQUEST_OPTION_DEBUG2;
3068 if (request_pre_handler(request)) {
3069 rad_assert(fun != NULL);
3070 rad_assert(request != NULL);
3072 if (request->server) RDEBUG("server %s {",
3076 if (request->server) RDEBUG("} # server %s",
3079 request_post_handler(request);
3082 DEBUG2("Going to the next request");