2 * realms.c Realm handling code
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/rad_assert.h>
39 * For POSIX Regular expressions.
40 * (0) Means no extended regular expressions.
41 * REG_EXTENDED means use extended regular expressions.
44 #define REG_EXTENDED (0)
56 static rbtree_t *realms_byname = NULL;
59 typedef struct realm_regex_t {
61 struct realm_regex_t *next;
64 static realm_regex_t *realms_regex = NULL;
66 #endif /* HAVE_REGEX_H */
68 typedef struct realm_config_t {
74 int wake_all_if_all_dead;
77 static realm_config_t *realm_config = NULL;
80 static rbtree_t *home_servers_byaddr = NULL;
81 static rbtree_t *home_servers_byname = NULL;
83 static int home_server_max_number = 0;
84 static rbtree_t *home_servers_bynumber = NULL;
87 static rbtree_t *home_pools_byname = NULL;
90 * Map the proxy server configuration parameters to variables.
92 static const CONF_PARSER proxy_config[] = {
93 { "retry_delay", PW_TYPE_INTEGER,
94 offsetof(realm_config_t, retry_delay),
95 NULL, Stringify(RETRY_DELAY) },
97 { "retry_count", PW_TYPE_INTEGER,
98 offsetof(realm_config_t, retry_count),
99 NULL, Stringify(RETRY_COUNT) },
101 { "default_fallback", PW_TYPE_BOOLEAN,
102 offsetof(realm_config_t, fallback),
105 { "dead_time", PW_TYPE_INTEGER,
106 offsetof(realm_config_t, dead_time),
107 NULL, Stringify(DEAD_TIME) },
109 { "wake_all_if_all_dead", PW_TYPE_BOOLEAN,
110 offsetof(realm_config_t, wake_all_if_all_dead),
113 { NULL, -1, 0, NULL, NULL }
117 static int realm_name_cmp(const void *one, const void *two)
119 const REALM *a = one;
120 const REALM *b = two;
122 return strcasecmp(a->name, b->name);
127 static int home_server_name_cmp(const void *one, const void *two)
129 const home_server *a = one;
130 const home_server *b = two;
132 if (a->type < b->type) return -1;
133 if (a->type > b->type) return +1;
135 return strcasecmp(a->name, b->name);
138 static int home_server_addr_cmp(const void *one, const void *two)
140 const home_server *a = one;
141 const home_server *b = two;
143 if (a->server && !b->server) return -1;
144 if (!a->server && b->server) return +1;
145 if (a->server && b->server) {
146 int rcode = a->type - b->type;
147 if (rcode != 0) return rcode;
148 return strcmp(a->server, b->server);
151 if (a->port < b->port) return -1;
152 if (a->port > b->port) return +1;
154 return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
158 static int home_server_number_cmp(const void *one, const void *two)
160 const home_server *a = one;
161 const home_server *b = two;
163 return (a->number - b->number);
167 static int home_pool_name_cmp(const void *one, const void *two)
169 const home_pool_t *a = one;
170 const home_pool_t *b = two;
172 if (a->server_type < b->server_type) return -1;
173 if (a->server_type > b->server_type) return +1;
175 return strcasecmp(a->name, b->name);
180 * Xlat for %{home_server:foo}
182 static size_t xlat_home_server(UNUSED void *instance, REQUEST *request,
183 char *fmt, char *out, size_t outlen,
184 UNUSED RADIUS_ESCAPE_STRING func)
186 const char *value = NULL;
189 if (!fmt || !out || (outlen < 1)) return 0;
191 if (!request || !request->home_server) {
196 cp = cf_pair_find(request->home_server->cs, fmt);
197 if (!cp || !(value = cf_pair_value(cp))) {
202 strlcpy(out, value, outlen);
209 * Xlat for %{home_server_pool:foo}
211 static size_t xlat_server_pool(UNUSED void *instance, REQUEST *request,
212 char *fmt, char *out, size_t outlen,
213 UNUSED RADIUS_ESCAPE_STRING func)
215 const char *value = NULL;
218 if (!fmt || !out || (outlen < 1)) return 0;
220 if (!request || !request->home_pool) {
225 cp = cf_pair_find(request->home_pool->cs, fmt);
226 if (!cp || !(value = cf_pair_value(cp))) {
231 strlcpy(out, value, outlen);
237 void realms_free(void)
241 rbtree_free(home_servers_bynumber);
242 home_servers_bynumber = NULL;
245 rbtree_free(home_servers_byname);
246 home_servers_byname = NULL;
248 rbtree_free(home_servers_byaddr);
249 home_servers_byaddr = NULL;
251 rbtree_free(home_pools_byname);
252 home_pools_byname = NULL;
255 rbtree_free(realms_byname);
256 realms_byname = NULL;
260 realm_regex_t *this, *next;
262 for (this = realms_regex; this != NULL; this = next) {
277 static struct in_addr hs_ip4addr;
278 static struct in6_addr hs_ip6addr;
279 static char *hs_type = NULL;
280 static char *hs_check = NULL;
281 static char *hs_virtual_server = NULL;
283 static CONF_PARSER home_server_config[] = {
284 { "ipaddr", PW_TYPE_IPADDR,
285 0, &hs_ip4addr, NULL },
286 { "ipv6addr", PW_TYPE_IPV6ADDR,
287 0, &hs_ip6addr, NULL },
288 { "virtual_server", PW_TYPE_STRING_PTR,
289 0, &hs_virtual_server, NULL },
291 { "port", PW_TYPE_INTEGER,
292 offsetof(home_server,port), NULL, "0" },
294 { "type", PW_TYPE_STRING_PTR,
297 { "secret", PW_TYPE_STRING_PTR,
298 offsetof(home_server,secret), NULL, NULL},
300 { "response_window", PW_TYPE_INTEGER,
301 offsetof(home_server,response_window), NULL, "30" },
302 { "max_outstanding", PW_TYPE_INTEGER,
303 offsetof(home_server,max_outstanding), NULL, "65536" },
304 { "require_message_authenticator", PW_TYPE_BOOLEAN,
305 offsetof(home_server, message_authenticator), 0, NULL },
307 { "zombie_period", PW_TYPE_INTEGER,
308 offsetof(home_server,zombie_period), NULL, "40" },
309 { "status_check", PW_TYPE_STRING_PTR,
310 0, &hs_check, "none" },
311 { "ping_check", PW_TYPE_STRING_PTR,
312 0, &hs_check, NULL },
314 { "ping_interval", PW_TYPE_INTEGER,
315 offsetof(home_server,ping_interval), NULL, "30" },
316 { "check_interval", PW_TYPE_INTEGER,
317 offsetof(home_server,ping_interval), NULL, "30" },
318 { "num_answers_to_alive", PW_TYPE_INTEGER,
319 offsetof(home_server,num_pings_to_alive), NULL, "3" },
320 { "num_pings_to_alive", PW_TYPE_INTEGER,
321 offsetof(home_server,num_pings_to_alive), NULL, "3" },
322 { "revive_interval", PW_TYPE_INTEGER,
323 offsetof(home_server,revive_interval), NULL, "300" },
324 { "status_check_timeout", PW_TYPE_INTEGER,
325 offsetof(home_server,ping_timeout), NULL, "4" },
327 { "username", PW_TYPE_STRING_PTR,
328 offsetof(home_server,ping_user_name), NULL, NULL},
329 { "password", PW_TYPE_STRING_PTR,
330 offsetof(home_server,ping_user_password), NULL, NULL},
333 { "historic_average_window", PW_TYPE_INTEGER,
334 offsetof(home_server,ema.window), NULL, NULL },
338 { "irt", PW_TYPE_INTEGER,
339 offsetof(home_server, coa_irt), 0, Stringify(2) },
340 { "mrt", PW_TYPE_INTEGER,
341 offsetof(home_server, coa_mrt), 0, Stringify(16) },
342 { "mrc", PW_TYPE_INTEGER,
343 offsetof(home_server, coa_mrc), 0, Stringify(5) },
344 { "mrd", PW_TYPE_INTEGER,
345 offsetof(home_server, coa_mrd), 0, Stringify(30) },
348 { NULL, -1, 0, NULL, NULL } /* end the list */
352 static int home_server_add(realm_config_t *rc, CONF_SECTION *cs, int pool_type)
359 free(hs_virtual_server); /* used only for printing during parsing */
360 hs_virtual_server = NULL;
362 name2 = cf_section_name1(cs);
363 if (!name2 || (strcasecmp(name2, "home_server") != 0)) {
364 cf_log_err(cf_sectiontoitem(cs),
365 "Section is not a home_server.");
369 name2 = cf_section_name2(cs);
371 cf_log_err(cf_sectiontoitem(cs),
372 "Home server section is missing a name.");
376 home = rad_malloc(sizeof(*home));
377 memset(home, 0, sizeof(*home));
382 memset(&hs_ip4addr, 0, sizeof(hs_ip4addr));
383 memset(&hs_ip6addr, 0, sizeof(hs_ip6addr));
384 if (cf_section_parse(cs, home, home_server_config) < 0) {
390 * Figure out which one to use.
392 if (cf_pair_find(cs, "ipaddr")) {
393 home->ipaddr.af = AF_INET;
394 home->ipaddr.ipaddr.ip4addr = hs_ip4addr;
396 } else if (cf_pair_find(cs, "ipv6addr")) {
397 home->ipaddr.af = AF_INET6;
398 home->ipaddr.ipaddr.ip6addr = hs_ip6addr;
400 } else if ((cp = cf_pair_find(cs, "virtual_server")) != NULL) {
401 home->ipaddr.af = AF_UNSPEC;
402 home->server = cf_pair_value(cp);
404 cf_log_err(cf_sectiontoitem(cs),
405 "Invalid value for virtual_server");
409 if (!cf_section_sub_find_name2(rc->cs, "server", home->server)) {
411 cf_log_err(cf_sectiontoitem(cs),
412 "No such server %s", home->server);
417 * When CoA is used, the user has to specify the type
418 * of the home server, even when they point to
421 home->secret = strdup("");
425 cf_log_err(cf_sectiontoitem(cs),
426 "No ipaddr, ipv6addr, or virtual_server defined for home server \"%s\".",
437 if (!home->port || (home->port > 65535)) {
438 cf_log_err(cf_sectiontoitem(cs),
439 "No port, or invalid port defined for home server %s.",
445 cf_log_err(cf_sectiontoitem(cs),
446 "Fatal error! Home server %s is ourselves!",
452 cf_log_err(cf_sectiontoitem(cs),
453 "No shared secret defined for home server %s.",
459 * Use a reasonable default.
462 if (!hs_type) hs_type = strdup("auth+acct");
464 if (strcasecmp(hs_type, "auth") == 0) {
465 home->type = HOME_TYPE_AUTH;
466 if (pool_type != home->type) {
468 cf_log_err(cf_sectiontoitem(cs),
469 "Server pool cannot include home server %s of type \"%s\"",
474 } else if (strcasecmp(hs_type, "acct") == 0) {
475 home->type = HOME_TYPE_ACCT;
476 if (pool_type != home->type) goto mismatch;
478 } else if (strcasecmp(hs_type, "auth+acct") == 0) {
479 home->type = HOME_TYPE_AUTH;
483 } else if (strcasecmp(hs_type, "coa") == 0) {
484 home->type = HOME_TYPE_COA;
487 if (pool_type != home->type) goto mismatch;
489 if (home->server != NULL) {
490 cf_log_err(cf_sectiontoitem(cs),
491 "Home servers of type \"coa\" cannot point to a virtual server");
497 cf_log_err(cf_sectiontoitem(cs),
498 "Invalid type \"%s\" for home server %s.",
505 if (!hs_check || (strcasecmp(hs_check, "none") == 0)) {
506 home->ping_check = HOME_PING_CHECK_NONE;
508 } else if (strcasecmp(hs_check, "status-server") == 0) {
509 home->ping_check = HOME_PING_CHECK_STATUS_SERVER;
511 } else if (strcasecmp(hs_check, "request") == 0) {
512 home->ping_check = HOME_PING_CHECK_REQUEST;
515 cf_log_err(cf_sectiontoitem(cs),
516 "Invalid ping_check \"%s\" for home server %s.",
523 if ((home->ping_check != HOME_PING_CHECK_NONE) &&
524 (home->ping_check != HOME_PING_CHECK_STATUS_SERVER)) {
525 if (!home->ping_user_name) {
526 cf_log_err(cf_sectiontoitem(cs), "You must supply a user name to enable ping checks");
530 if ((home->type == HOME_TYPE_AUTH) &&
531 !home->ping_user_password) {
532 cf_log_err(cf_sectiontoitem(cs), "You must supply a password to enable ping checks");
537 if ((home->ipaddr.af != AF_UNSPEC) && /* could be virtual server */
538 rbtree_finddata(home_servers_byaddr, home)) {
539 cf_log_err(cf_sectiontoitem(cs), "Duplicate home server");
543 if (!rbtree_insert(home_servers_byname, home)) {
544 cf_log_err(cf_sectiontoitem(cs),
545 "Internal error %d adding home server %s.",
550 if ((home->ipaddr.af != AF_UNSPEC) && /* could be virtual server */
551 !rbtree_insert(home_servers_byaddr, home)) {
552 rbtree_deletebydata(home_servers_byname, home);
553 cf_log_err(cf_sectiontoitem(cs),
554 "Internal error %d adding home server %s.",
560 home->number = home_server_max_number++;
561 if (!rbtree_insert(home_servers_bynumber, home)) {
562 rbtree_deletebydata(home_servers_byname, home);
563 if (home->ipaddr.af != AF_UNSPEC) {
564 rbtree_deletebydata(home_servers_byname, home);
566 cf_log_err(cf_sectiontoitem(cs),
567 "Internal error %d adding home server %s.",
573 if (home->response_window < 5) home->response_window = 5;
574 if (home->response_window > 60) home->response_window = 60;
576 if (home->max_outstanding < 8) home->max_outstanding = 8;
577 if (home->max_outstanding > 65536*16) home->max_outstanding = 65536*16;
579 if (home->ping_interval < 6) home->ping_interval = 6;
580 if (home->ping_interval > 120) home->ping_interval = 120;
582 if (home->zombie_period < 20) home->zombie_period = 20;
583 if (home->zombie_period > 120) home->zombie_period = 120;
585 if (home->zombie_period < home->response_window) {
586 home->zombie_period = home->response_window;
589 if (home->num_pings_to_alive < 3) home->num_pings_to_alive = 3;
590 if (home->num_pings_to_alive > 10) home->num_pings_to_alive = 10;
592 if (home->ping_timeout < 3) home->ping_timeout = 3;
593 if (home->ping_timeout > 10) home->ping_timeout = 10;
595 if (home->revive_interval < 60) home->revive_interval = 60;
596 if (home->revive_interval > 3600) home->revive_interval = 3600;
599 if (home->coa_irt < 1) home->coa_irt = 1;
600 if (home->coa_irt > 5) home->coa_irt = 5;
602 if (home->coa_mrc < 0) home->coa_mrc = 0;
603 if (home->coa_mrc > 20 ) home->coa_mrc = 20;
605 if (home->coa_mrt < 0) home->coa_mrt = 0;
606 if (home->coa_mrt > 30 ) home->coa_mrt = 30;
608 if (home->coa_mrd < 5) home->coa_mrd = 5;
609 if (home->coa_mrd > 60 ) home->coa_mrd = 60;
613 home_server *home2 = rad_malloc(sizeof(*home2));
615 memcpy(home2, home, sizeof(*home2));
617 home2->type = HOME_TYPE_ACCT;
619 home2->ping_user_password = NULL;
622 if (!rbtree_insert(home_servers_byname, home2)) {
623 cf_log_err(cf_sectiontoitem(cs),
624 "Internal error %d adding home server %s.",
630 if ((home->ipaddr.af != AF_UNSPEC) &&
631 !rbtree_insert(home_servers_byaddr, home2)) {
632 rbtree_deletebydata(home_servers_byname, home2);
633 cf_log_err(cf_sectiontoitem(cs),
634 "Internal error %d adding home server %s.",
641 home2->number = home_server_max_number++;
642 if (!rbtree_insert(home_servers_bynumber, home2)) {
643 rbtree_deletebydata(home_servers_byname, home2);
644 if (home2->ipaddr.af != AF_UNSPEC) {
645 rbtree_deletebydata(home_servers_byname, home2);
647 cf_log_err(cf_sectiontoitem(cs),
648 "Internal error %d adding home server %s.",
660 static home_pool_t *server_pool_alloc(const char *name, home_pool_type_t type,
661 int server_type, int num_home_servers)
665 pool = rad_malloc(sizeof(*pool) + (sizeof(pool->servers[0]) *
667 if (!pool) return NULL; /* just for pairanoia */
669 memset(pool, 0, sizeof(*pool) + (sizeof(pool->servers[0]) *
674 pool->server_type = server_type;
675 pool->num_home_servers = num_home_servers;
680 static int pool_check_home_server(realm_config_t *rc, CONF_PAIR *cp,
681 const char *name, int server_type,
684 home_server myhome, *home;
685 CONF_SECTION *server_cs;
688 cf_log_err(cf_pairtoitem(cp),
689 "No value given for home_server.");
694 myhome.type = server_type;
695 home = rbtree_finddata(home_servers_byname, &myhome);
701 server_cs = cf_section_sub_find_name2(rc->cs, "home_server", name);
703 cf_log_err(cf_pairtoitem(cp),
704 "Unknown home_server \"%s\".", name);
708 if (!home_server_add(rc, server_cs, server_type)) {
712 home = rbtree_finddata(home_servers_byname, &myhome);
722 static int server_pool_add(realm_config_t *rc,
723 CONF_SECTION *cs, int server_type, int do_print)
726 home_pool_t *pool = NULL;
729 int num_home_servers;
732 name2 = cf_section_name1(cs);
733 if (!name2 || ((strcasecmp(name2, "server_pool") != 0) &&
734 (strcasecmp(name2, "home_server_pool") != 0))) {
735 cf_log_err(cf_sectiontoitem(cs),
736 "Section is not a home_server_pool.");
740 name2 = cf_section_name2(cs);
742 cf_log_err(cf_sectiontoitem(cs),
743 "Server pool section is missing a name.");
748 * Count the home servers and initalize them.
750 num_home_servers = 0;
751 for (cp = cf_pair_find(cs, "home_server");
753 cp = cf_pair_find_next(cs, cp, "home_server")) {
756 if (!pool_check_home_server(rc, cp, cf_pair_value(cp),
757 server_type, &home)) {
763 if (num_home_servers == 0) {
764 cf_log_err(cf_sectiontoitem(cs),
765 "No home servers defined in pool %s",
770 pool = server_pool_alloc(name2, HOME_POOL_FAIL_OVER, server_type,
776 * Fallback servers must be defined, and must be
779 cp = cf_pair_find(cs, "fallback");
782 if (server_type == HOME_TYPE_COA) {
783 cf_log_err(cf_sectiontoitem(cs), "Home server pools of type \"coa\" cannot have a fallback virtual server.");
788 if (!pool_check_home_server(rc, cp, cf_pair_value(cp),
789 server_type, &pool->fallback)) {
794 if (!pool->fallback->server) {
795 cf_log_err(cf_sectiontoitem(cs), "Fallback home_server %s does NOT contain a virtual_server directive.", pool->fallback->name);
800 if (do_print) cf_log_info(cs, " home_server_pool %s {", name2);
802 cp = cf_pair_find(cs, "type");
804 static FR_NAME_NUMBER pool_types[] = {
805 { "load-balance", HOME_POOL_LOAD_BALANCE },
806 { "fail-over", HOME_POOL_FAIL_OVER },
807 { "round_robin", HOME_POOL_LOAD_BALANCE },
808 { "fail_over", HOME_POOL_FAIL_OVER },
809 { "client-balance", HOME_POOL_CLIENT_BALANCE },
810 { "client-port-balance", HOME_POOL_CLIENT_PORT_BALANCE },
811 { "keyed-balance", HOME_POOL_KEYED_BALANCE },
815 value = cf_pair_value(cp);
817 cf_log_err(cf_pairtoitem(cp),
818 "No value given for type.");
822 pool->type = fr_str2int(pool_types, value, 0);
824 cf_log_err(cf_pairtoitem(cp),
825 "Unknown type \"%s\".",
830 if (do_print) cf_log_info(cs, "\ttype = %s", value);
833 cp = cf_pair_find(cs, "virtual_server");
835 pool->virtual_server = cf_pair_value(cp);
836 if (!pool->virtual_server) {
837 cf_log_err(cf_pairtoitem(cp), "No value given for virtual_server");
842 cf_log_info(cs, "\tvirtual_server = %s", pool->virtual_server);
845 if (!cf_section_sub_find_name2(rc->cs, "server",
846 pool->virtual_server)) {
847 cf_log_err(cf_pairtoitem(cp), "No such server %s",
848 pool->virtual_server);
854 num_home_servers = 0;
855 for (cp = cf_pair_find(cs, "home_server");
857 cp = cf_pair_find_next(cs, cp, "home_server")) {
860 value = cf_pair_value(cp);
862 memset(&myhome, 0, sizeof(&myhome));
864 myhome.type = server_type;
866 home = rbtree_finddata(home_servers_byname, &myhome);
868 DEBUG2("Internal sanity check failed");
873 DEBUG2("Warning: Duplicate home server %s in server pool %s", home->name, pool->name);
877 if (do_print) cf_log_info(cs, "\thome_server = %s", home->name);
878 pool->servers[num_home_servers++] = home;
879 } /* loop over home_server's */
881 if (pool->fallback && do_print) {
882 cf_log_info(cs, "\tfallback = %s", pool->fallback->name);
885 if (!rbtree_insert(home_pools_byname, pool)) {
886 rad_assert("Internal sanity check failed");
890 if (do_print) cf_log_info(cs, " }");
892 cf_data_add(cs, "home_server_pool", pool, free);
894 rad_assert(pool->server_type != 0);
899 if (do_print) cf_log_info(cs, " }");
905 static int old_server_add(realm_config_t *rc, CONF_SECTION *cs,
907 const char *name, const char *secret,
908 home_pool_type_t ldflag, home_pool_t **pool_p,
909 int type, const char *server)
912 int i, insert_point, num_home_servers;
913 home_server myhome, *home;
914 home_pool_t mypool, *pool;
917 rc = rc; /* -Wunused */
926 * LOCAL realms get sanity checked, and nothing else happens.
928 if (strcmp(name, "LOCAL") == 0) {
930 cf_log_err(cf_sectiontoitem(cs), "Realm \"%s\" cannot be both LOCAL and remote", name);
937 return 0; /* Not proxying. Can't do non-LOCAL realms */
941 mypool.server_type = type;
942 pool = rbtree_finddata(home_pools_byname, &mypool);
944 if (pool->type != ldflag) {
945 cf_log_err(cf_sectiontoitem(cs), "Inconsistent ldflag for server pool \"%s\"", name);
949 if (pool->server_type != type) {
950 cf_log_err(cf_sectiontoitem(cs), "Inconsistent home server type for server pool \"%s\"", name);
957 home = rbtree_finddata(home_servers_byname, &myhome);
959 if (secret && (strcmp(home->secret, secret) != 0)) {
960 cf_log_err(cf_sectiontoitem(cs), "Inconsistent shared secret for home server \"%s\"", name);
964 if (home->type != type) {
965 cf_log_err(cf_sectiontoitem(cs), "Inconsistent type for home server \"%s\"", name);
970 * See if the home server is already listed
971 * in the pool. If so, do nothing else.
973 if (pool) for (i = 0; i < pool->num_home_servers; i++) {
974 if (pool->servers[i] == home) {
981 * If we do have a pool, check that there is room to
982 * insert the home server we've found, or the one that we
985 * Note that we insert it into the LAST available
986 * position, in order to maintain the same order as in
987 * the configuration files.
991 for (i = pool->num_home_servers - 1; i >= 0; i--) {
992 if (pool->servers[i]) break;
994 if (!pool->servers[i]) {
999 if (insert_point < 0) {
1000 cf_log_err(cf_sectiontoitem(cs), "No room in pool to add home server \"%s\". Please update the realm configuration to use the new-style home servers and server pools.", name);
1006 * No home server, allocate one.
1012 home = rad_malloc(sizeof(*home));
1013 memset(home, 0, sizeof(*home));
1016 home->hostname = name;
1018 home->secret = secret;
1021 p = strchr(name, ':');
1023 if (type == HOME_TYPE_AUTH) {
1024 home->port = PW_AUTH_UDP_PORT;
1026 home->port = PW_ACCT_UDP_PORT;
1032 } else if (p == name) {
1033 cf_log_err(cf_sectiontoitem(cs),
1034 "Invalid hostname %s.",
1040 home->port = atoi(p + 1);
1041 if ((home->port == 0) || (home->port > 65535)) {
1042 cf_log_err(cf_sectiontoitem(cs),
1049 q = rad_malloc((p - name) + 1);
1050 memcpy(q, name, (p - name));
1056 if (ip_hton(p, AF_UNSPEC, &home->ipaddr) < 0) {
1057 cf_log_err(cf_sectiontoitem(cs),
1058 "Failed looking up hostname %s.",
1065 home->ipaddr.af = AF_UNSPEC;
1066 home->server = server;
1071 * Use the old-style configuration.
1073 home->max_outstanding = 65535*16;
1074 home->zombie_period = rc->retry_delay * rc->retry_count;
1075 if (home->zombie_period == 0) home->zombie_period =30;
1076 home->response_window = home->zombie_period - 1;
1078 home->ping_check = HOME_PING_CHECK_NONE;
1080 home->revive_interval = rc->dead_time;
1082 if (rbtree_finddata(home_servers_byaddr, home)) {
1083 cf_log_err(cf_sectiontoitem(cs), "Home server %s has the same IP address and/or port as another home server.", name);
1088 if (!rbtree_insert(home_servers_byname, home)) {
1089 cf_log_err(cf_sectiontoitem(cs), "Internal error %d adding home server %s.", __LINE__, name);
1094 if (!rbtree_insert(home_servers_byaddr, home)) {
1095 rbtree_deletebydata(home_servers_byname, home);
1096 cf_log_err(cf_sectiontoitem(cs), "Internal error %d adding home server %s.", __LINE__, name);
1102 home->number = home_server_max_number++;
1103 if (!rbtree_insert(home_servers_bynumber, home)) {
1104 rbtree_deletebydata(home_servers_byname, home);
1105 if (home->ipaddr.af != AF_UNSPEC) {
1106 rbtree_deletebydata(home_servers_byname, home);
1108 cf_log_err(cf_sectiontoitem(cs),
1109 "Internal error %d adding home server %s.",
1118 * We now have a home server, see if we can insert it
1119 * into pre-existing pool.
1121 if (insert_point >= 0) {
1122 rad_assert(pool != NULL);
1123 pool->servers[insert_point] = home;
1127 rad_assert(pool == NULL);
1128 rad_assert(home != NULL);
1131 * Count the old-style realms of this name.
1133 num_home_servers = 0;
1134 for (subcs = cf_section_find_next(cs, NULL, "realm");
1136 subcs = cf_section_find_next(cs, subcs, "realm")) {
1137 const char *this = cf_section_name2(subcs);
1139 if (!this || (strcmp(this, realm) != 0)) continue;
1143 if (num_home_servers == 0) {
1144 cf_log_err(cf_sectiontoitem(cs), "Internal error counting pools for home server %s.", name);
1149 pool = server_pool_alloc(realm, ldflag, type, num_home_servers);
1152 pool->servers[0] = home;
1154 if (!rbtree_insert(home_pools_byname, pool)) {
1155 rad_assert("Internal sanity check failed");
1165 static int old_realm_config(realm_config_t *rc, CONF_SECTION *cs, REALM *r)
1168 const char *secret = NULL;
1169 home_pool_type_t ldflag;
1172 cp = cf_pair_find(cs, "ldflag");
1173 ldflag = HOME_POOL_FAIL_OVER;
1175 host = cf_pair_value(cp);
1177 cf_log_err(cf_pairtoitem(cp), "No value specified for ldflag");
1181 if (strcasecmp(host, "fail_over") == 0) {
1182 cf_log_info(cs, "\tldflag = fail_over");
1184 } else if (strcasecmp(host, "round_robin") == 0) {
1185 ldflag = HOME_POOL_LOAD_BALANCE;
1186 cf_log_info(cs, "\tldflag = round_robin");
1189 cf_log_err(cf_sectiontoitem(cs), "Unknown value \"%s\" for ldflag", host);
1192 } /* else don't print it. */
1195 * Allow old-style if it doesn't exist, or if it exists and
1198 cp = cf_pair_find(cs, "authhost");
1200 host = cf_pair_value(cp);
1202 cf_log_err(cf_pairtoitem(cp), "No value specified for authhost");
1206 if (strcmp(host, "LOCAL") != 0) {
1207 cp = cf_pair_find(cs, "secret");
1209 cf_log_err(cf_sectiontoitem(cs), "No shared secret supplied for realm: %s", r->name);
1213 secret = cf_pair_value(cp);
1215 cf_log_err(cf_pairtoitem(cp), "No value specified for secret");
1220 cf_log_info(cs, "\tauthhost = %s", host);
1222 if (!old_server_add(rc, cs, r->name, host, secret, ldflag,
1223 &r->auth_pool, HOME_TYPE_AUTH, NULL)) {
1228 cp = cf_pair_find(cs, "accthost");
1230 host = cf_pair_value(cp);
1232 cf_log_err(cf_pairtoitem(cp), "No value specified for accthost");
1237 * Don't look for a secret again if it was found
1240 if ((strcmp(host, "LOCAL") != 0) && !secret) {
1241 cp = cf_pair_find(cs, "secret");
1243 cf_log_err(cf_sectiontoitem(cs), "No shared secret supplied for realm: %s", r->name);
1247 secret = cf_pair_value(cp);
1249 cf_log_err(cf_pairtoitem(cp), "No value specified for secret");
1254 cf_log_info(cs, "\taccthost = %s", host);
1256 if (!old_server_add(rc, cs, r->name, host, secret, ldflag,
1257 &r->acct_pool, HOME_TYPE_ACCT, NULL)) {
1262 cp = cf_pair_find(cs, "virtual_server");
1264 host = cf_pair_value(cp);
1266 cf_log_err(cf_pairtoitem(cp), "No value specified for virtual_server");
1270 cf_log_info(cs, "\tvirtual_server = %s", host);
1272 if (!old_server_add(rc, cs, r->name, host, "", ldflag,
1273 &r->auth_pool, HOME_TYPE_AUTH, host)) {
1276 if (!old_server_add(rc, cs, r->name, host, "", ldflag,
1277 &r->acct_pool, HOME_TYPE_ACCT, host)) {
1282 if (secret) cf_log_info(cs, "\tsecret = %s", secret);
1290 static int add_pool_to_realm(realm_config_t *rc, CONF_SECTION *cs,
1291 const char *name, home_pool_t **dest,
1292 int server_type, int do_print)
1294 home_pool_t mypool, *pool;
1297 mypool.server_type = server_type;
1299 pool = rbtree_finddata(home_pools_byname, &mypool);
1301 CONF_SECTION *pool_cs;
1303 pool_cs = cf_section_sub_find_name2(rc->cs,
1307 pool_cs = cf_section_sub_find_name2(rc->cs,
1312 cf_log_err(cf_sectiontoitem(cs), "Failed to find home_server_pool \"%s\"", name);
1316 if (!server_pool_add(rc, pool_cs, server_type, do_print)) {
1320 pool = rbtree_finddata(home_pools_byname, &mypool);
1322 radlog(L_ERR, "Internal sanity check failed in add_pool_to_realm");
1327 if (pool->server_type != server_type) {
1328 cf_log_err(cf_sectiontoitem(cs), "Incompatible home_server_pool \"%s\" (mixed auth_pool / acct_pool)", name);
1339 static int realm_add(realm_config_t *rc, CONF_SECTION *cs)
1345 home_pool_t *auth_pool, *acct_pool;
1346 const char *auth_pool_name, *acct_pool_name;
1349 name2 = cf_section_name1(cs);
1350 if (!name2 || (strcasecmp(name2, "realm") != 0)) {
1351 cf_log_err(cf_sectiontoitem(cs), "Section is not a realm.");
1355 name2 = cf_section_name2(cs);
1357 cf_log_err(cf_sectiontoitem(cs), "Realm section is missing the realm name.");
1362 auth_pool = acct_pool = NULL;
1363 auth_pool_name = acct_pool_name = NULL;
1366 * Prefer new configuration to old one.
1368 cp = cf_pair_find(cs, "pool");
1369 if (!cp) cp = cf_pair_find(cs, "home_server_pool");
1370 if (cp) auth_pool_name = cf_pair_value(cp);
1371 if (cp && auth_pool_name) {
1372 acct_pool_name = auth_pool_name;
1373 if (!add_pool_to_realm(rc, cs,
1374 auth_pool_name, &auth_pool,
1375 HOME_TYPE_AUTH, 1)) {
1378 if (!add_pool_to_realm(rc, cs,
1379 auth_pool_name, &acct_pool,
1380 HOME_TYPE_ACCT, 0)) {
1385 cp = cf_pair_find(cs, "auth_pool");
1386 if (cp) auth_pool_name = cf_pair_value(cp);
1387 if (cp && auth_pool_name) {
1389 cf_log_err(cf_sectiontoitem(cs), "Cannot use \"pool\" and \"auth_pool\" at the same time.");
1392 if (!add_pool_to_realm(rc, cs,
1393 auth_pool_name, &auth_pool,
1394 HOME_TYPE_AUTH, 1)) {
1399 cp = cf_pair_find(cs, "acct_pool");
1400 if (cp) acct_pool_name = cf_pair_value(cp);
1401 if (cp && acct_pool_name) {
1402 int do_print = TRUE;
1405 cf_log_err(cf_sectiontoitem(cs), "Cannot use \"pool\" and \"acct_pool\" at the same time.");
1410 (strcmp(auth_pool_name, acct_pool_name) != 0)) {
1414 if (!add_pool_to_realm(rc, cs,
1415 acct_pool_name, &acct_pool,
1416 HOME_TYPE_ACCT, do_print)) {
1422 cf_log_info(cs, " realm %s {", name2);
1426 * The realm MAY already exist if it's an old-style realm.
1427 * In that case, merge the old-style realm with this one.
1429 r = realm_find2(name2);
1430 if (r && (strcmp(r->name, name2) == 0)) {
1431 if (cf_pair_find(cs, "auth_pool") ||
1432 cf_pair_find(cs, "acct_pool")) {
1433 cf_log_err(cf_sectiontoitem(cs), "Duplicate realm \"%s\"", name2);
1437 if (!old_realm_config(rc, cs, r)) {
1441 cf_log_info(cs, " } # realm %s", name2);
1447 if (name2[0] == '~') {
1451 * Include substring matches.
1453 if (regcomp(®, name2 + 1,
1454 REG_EXTENDED | REG_NOSUB | REG_ICASE) != 0) {
1455 cf_log_err(cf_sectiontoitem(cs),
1456 "Invalid regex in realm \"%s\"", name2);
1463 r = rad_malloc(sizeof(*r));
1464 memset(r, 0, sizeof(*r));
1469 r->auth_pool = auth_pool;
1470 r->acct_pool = acct_pool;
1472 if (auth_pool_name &&
1473 (auth_pool_name == acct_pool_name)) { /* yes, ptr comparison */
1474 cf_log_info(cs, "\tpool = %s", auth_pool_name);
1476 if (auth_pool_name) cf_log_info(cs, "\tauth_pool = %s", auth_pool_name);
1477 if (acct_pool_name) cf_log_info(cs, "\tacct_pool = %s", acct_pool_name);
1481 cp = cf_pair_find(cs, "nostrip");
1482 if (cp && (cf_pair_value(cp) == NULL)) {
1484 cf_log_info(cs, "\tnostrip");
1488 * We're a new-style realm. Complain if we see the old
1491 if (r->auth_pool || r->acct_pool) {
1492 if (((cp = cf_pair_find(cs, "authhost")) != NULL) ||
1493 ((cp = cf_pair_find(cs, "accthost")) != NULL) ||
1494 ((cp = cf_pair_find(cs, "secret")) != NULL) ||
1495 ((cp = cf_pair_find(cs, "ldflag")) != NULL)) {
1496 DEBUG2("WARNING: Ignoring old-style configuration entry \"%s\" in realm \"%s\"", cf_pair_attr(cp), r->name);
1501 * The realm MAY be an old-style realm, as there
1502 * was no auth_pool or acct_pool. Double-check
1503 * it, just to be safe.
1505 } else if (!old_realm_config(rc, cs, r)) {
1511 * It's a regex. Add it to a separate list.
1513 if (name2[0] == '~') {
1514 realm_regex_t *rr, **last;
1516 rr = rad_malloc(sizeof(*rr));
1518 last = &realms_regex;
1519 while (*last) last = &((*last)->next); /* O(N^2)... sue me. */
1527 cf_log_info(cs, " }");
1532 if (!rbtree_insert(realms_byname, r)) {
1533 rad_assert("Internal sanity check failed");
1537 cf_log_info(cs, " }");
1542 cf_log_info(cs, " } # realm %s", name2);
1548 static int pool_peek_type(CONF_SECTION *cs)
1554 cp = cf_pair_find(cs, "home_server");
1556 cf_log_err(cf_sectiontoitem(cs), "Pool does not contain a \"home_server\" entry");
1557 return HOME_TYPE_INVALID;
1560 name = cf_pair_value(cp);
1562 cf_log_err(cf_pairtoitem(cp), "home_server entry does not reference a home server");
1563 return HOME_TYPE_INVALID;
1566 home = home_server_byname(name);
1568 cf_log_err(cf_pairtoitem(cp), "home_server \"%s\" does not exist", name);
1569 return HOME_TYPE_INVALID;
1576 int realms_init(CONF_SECTION *config)
1579 realm_config_t *rc, *old_rc;
1581 if (realms_byname) return 1;
1583 realms_byname = rbtree_create(realm_name_cmp, free, 0);
1584 if (!realms_byname) {
1590 home_servers_byaddr = rbtree_create(home_server_addr_cmp, free, 0);
1591 if (!home_servers_byaddr) {
1596 home_servers_byname = rbtree_create(home_server_name_cmp, NULL, 0);
1597 if (!home_servers_byname) {
1603 home_servers_bynumber = rbtree_create(home_server_number_cmp, NULL, 0);
1604 if (!home_servers_bynumber) {
1610 home_pools_byname = rbtree_create(home_pool_name_cmp, NULL, 0);
1611 if (!home_pools_byname) {
1617 rc = rad_malloc(sizeof(*rc));
1618 memset(rc, 0, sizeof(*rc));
1622 cs = cf_subsection_find_next(config, NULL, "proxy");
1624 cf_section_parse(cs, rc, proxy_config);
1626 rc->dead_time = DEAD_TIME;
1627 rc->retry_count = RETRY_COUNT;
1628 rc->retry_delay = RETRY_DELAY;
1630 rc->wake_all_if_all_dead= 0;
1634 for (cs = cf_subsection_find_next(config, NULL, "realm");
1636 cs = cf_subsection_find_next(config, cs, "realm")) {
1637 if (!realm_add(rc, cs)) {
1646 * CoA pools aren't tied to realms.
1648 for (cs = cf_subsection_find_next(config, NULL, "home_server_pool");
1650 cs = cf_subsection_find_next(config, cs, "home_server_pool")) {
1653 if (cf_data_find(cs, "home_server_pool")) continue;
1655 type = pool_peek_type(cs);
1656 if (type == HOME_TYPE_INVALID) return 0;
1658 if (!server_pool_add(rc, cs, type, TRUE)) {
1666 xlat_register("home_server", xlat_home_server, NULL);
1667 xlat_register("home_server_pool", xlat_server_pool, NULL);
1671 * Swap pointers atomically.
1673 old_rc = realm_config;
1681 * Find a realm where "name" might be the regex.
1683 REALM *realm_find2(const char *name)
1688 if (!name) name = "NULL";
1690 myrealm.name = name;
1691 realm = rbtree_finddata(realms_byname, &myrealm);
1692 if (realm) return realm;
1696 realm_regex_t *this;
1698 for (this = realms_regex; this != NULL; this = this->next) {
1699 if (strcmp(this->realm->name, name) == 0) {
1707 * Couldn't find a realm. Look for DEFAULT.
1709 myrealm.name = "DEFAULT";
1710 return rbtree_finddata(realms_byname, &myrealm);
1715 * Find a realm in the REALM list.
1717 REALM *realm_find(const char *name)
1722 if (!name) name = "NULL";
1724 myrealm.name = name;
1725 realm = rbtree_finddata(realms_byname, &myrealm);
1726 if (realm) return realm;
1730 realm_regex_t *this;
1732 for (this = realms_regex; this != NULL; this = this->next) {
1737 * Include substring matches.
1739 if (regcomp(®, this->realm->name + 1,
1740 REG_EXTENDED | REG_NOSUB | REG_ICASE) != 0) {
1744 compare = regexec(®, name, 0, NULL, 0);
1747 if (compare == 0) return this->realm;
1753 * Couldn't find a realm. Look for DEFAULT.
1755 myrealm.name = "DEFAULT";
1756 return rbtree_finddata(realms_byname, &myrealm);
1761 home_server *home_server_ldb(const char *realmname,
1762 home_pool_t *pool, REQUEST *request)
1766 home_server *found = NULL;
1772 * Determine how to pick choose the home server.
1774 switch (pool->type) {
1778 * For load-balancing by client IP address, we
1779 * pick a home server by hashing the client IP.
1781 * This isn't as even a load distribution as
1782 * tracking the State attribute, but it's better
1785 case HOME_POOL_CLIENT_BALANCE:
1786 switch (request->packet->src_ipaddr.af) {
1788 hash = fr_hash(&request->packet->src_ipaddr.ipaddr.ip4addr,
1789 sizeof(request->packet->src_ipaddr.ipaddr.ip4addr));
1792 hash = fr_hash(&request->packet->src_ipaddr.ipaddr.ip6addr,
1793 sizeof(request->packet->src_ipaddr.ipaddr.ip6addr));
1799 start = hash % pool->num_home_servers;
1802 case HOME_POOL_CLIENT_PORT_BALANCE:
1803 switch (request->packet->src_ipaddr.af) {
1805 hash = fr_hash(&request->packet->src_ipaddr.ipaddr.ip4addr,
1806 sizeof(request->packet->src_ipaddr.ipaddr.ip4addr));
1809 hash = fr_hash(&request->packet->src_ipaddr.ipaddr.ip6addr,
1810 sizeof(request->packet->src_ipaddr.ipaddr.ip6addr));
1816 fr_hash_update(&request->packet->src_port,
1817 sizeof(request->packet->src_port), hash);
1818 start = hash % pool->num_home_servers;
1821 case HOME_POOL_KEYED_BALANCE:
1822 if ((vp = pairfind(request->config_items, PW_LOAD_BALANCE_KEY)) != NULL) {
1823 hash = fr_hash(vp->vp_strvalue, vp->length);
1824 start = hash % pool->num_home_servers;
1829 case HOME_POOL_LOAD_BALANCE:
1830 case HOME_POOL_FAIL_OVER:
1834 default: /* this shouldn't happen... */
1841 * Starting with the home server we chose, loop through
1842 * all home servers. If the current one is dead, skip
1843 * it. If it is too busy, skip it.
1845 * Otherwise, use it.
1847 for (count = 0; count < pool->num_home_servers; count++) {
1848 home_server *home = pool->servers[(start + count) % pool->num_home_servers];
1850 if (!home) continue;
1852 if (home->state == HOME_STATE_IS_DEAD) {
1857 * This home server is too busy. Choose another one.
1859 if (home->currently_outstanding >= home->max_outstanding) {
1865 * We read the packet from a detail file, AND it
1866 * came from this server. Don't re-proxy it
1869 if ((request->listener->type == RAD_LISTEN_DETAIL) &&
1870 (request->packet->code == PW_ACCOUNTING_REQUEST) &&
1871 (fr_ipaddr_cmp(&home->ipaddr, &request->packet->src_ipaddr) == 0)) {
1877 * We've found the first "live" one. Use that.
1879 if (pool->type == HOME_POOL_FAIL_OVER) {
1885 * Otherwise we're doing some kind of load balancing.
1886 * If we haven't found one yet, pick this one.
1893 RDEBUG3("PROXY %s %d\t%s %d",
1894 found->name, found->currently_outstanding,
1895 home->name, home->currently_outstanding);
1898 * Prefer this server if it's less busy than the
1899 * one we had previously found.
1901 if (home->currently_outstanding < found->currently_outstanding) {
1902 RDEBUG3("PROXY Choosing %s: It's less busy than %s",
1903 home->name, found->name);
1909 * Ignore servers which are busier than the one
1912 if (home->currently_outstanding > found->currently_outstanding) {
1913 RDEBUG3("PROXY Skipping %s: It's busier than %s",
1914 home->name, found->name);
1919 * From the list of servers which have the same
1920 * load, choose one at random.
1922 if (((count + 1) * (fr_rand() & 0xffff)) < (uint32_t) 0x10000) {
1925 } /* loop over the home servers */
1928 * There's a fallback if they're all dead.
1930 if (!found && pool->fallback) {
1931 found = pool->fallback;
1937 * Allocate the proxy packet, only if it wasn't
1938 * already allocated by a module. This check is
1939 * mainly to support the proxying of EAP-TTLS and
1940 * EAP-PEAP tunneled requests.
1942 * In those cases, the EAP module creates a
1943 * "fake" request, and recursively passes it
1944 * through the authentication stage of the
1945 * server. The module then checks if the request
1946 * was supposed to be proxied, and if so, creates
1947 * a proxy packet from the TUNNELED request, and
1948 * not from the EAP request outside of the
1951 * The proxy then works like normal, except that
1952 * the response packet is "eaten" by the EAP
1953 * module, and encapsulated into an EAP packet.
1955 if (!request->proxy) {
1956 if ((request->proxy = rad_alloc(TRUE)) == NULL) {
1957 radlog(L_ERR|L_CONS, "no memory");
1962 * Copy the request, then look up name
1963 * and plain-text password in the copy.
1965 * Note that the User-Name attribute is
1966 * the *original* as sent over by the
1967 * client. The Stripped-User-Name
1968 * attribute is the one hacked through
1971 request->proxy->vps = paircopy(request->packet->vps);
1975 * Update the various fields as appropriate.
1977 request->proxy->dst_ipaddr = found->ipaddr;
1978 request->proxy->dst_port = found->port;
1979 request->home_server = found;
1982 * We're supposed to add a Message-Authenticator
1983 * if it doesn't exist, and it doesn't exist.
1985 if (found->message_authenticator &&
1986 (request->packet->code == PW_AUTHENTICATION_REQUEST) &&
1987 !pairfind(request->proxy->vps, PW_MESSAGE_AUTHENTICATOR)) {
1988 radius_pairmake(request, &request->proxy->vps,
1989 "Message-Authenticator", "0x00",
1997 * No live match found, and no fallback to the "DEFAULT"
1998 * realm. We fix this by blindly marking all servers as
1999 * "live". But only do it for ones that don't support
2000 * "pings", as they will be marked live when they
2001 * actually are live.
2003 if (!realm_config->fallback &&
2004 realm_config->wake_all_if_all_dead) {
2005 for (count = 0; count < pool->num_home_servers; count++) {
2006 home_server *home = pool->servers[count];
2008 if (!home) continue;
2010 if ((home->state == HOME_STATE_IS_DEAD) &&
2011 (home->ping_check == HOME_PING_CHECK_NONE)) {
2012 home->state = HOME_STATE_ALIVE;
2013 if (!found) found = home;
2017 if (found) goto update_and_return;
2021 * Still nothing. Look up the DEFAULT realm, but only
2022 * if we weren't looking up the NULL or DEFAULT realms.
2024 if (realm_config->fallback &&
2026 (strcmp(realmname, "NULL") != 0) &&
2027 (strcmp(realmname, "DEFAULT") != 0)) {
2028 REALM *rd = realm_find("DEFAULT");
2030 if (!rd) return NULL;
2033 if (request->packet->code == PW_AUTHENTICATION_REQUEST) {
2034 pool = rd->auth_pool;
2036 } else if (request->packet->code == PW_ACCOUNTING_REQUEST) {
2037 pool = rd->acct_pool;
2039 if (!pool) return NULL;
2041 RDEBUG2("PROXY - realm %s has no live home servers. Falling back to the DEFAULT realm.", realmname);
2042 return home_server_ldb(rd->name, pool, request);
2046 * Still haven't found anything. Oh well.
2052 home_server *home_server_find(fr_ipaddr_t *ipaddr, int port)
2056 memset(&myhome, 0, sizeof(myhome));
2057 myhome.ipaddr = *ipaddr;
2059 myhome.server = NULL; /* we're not called for internal proxying */
2061 return rbtree_finddata(home_servers_byaddr, &myhome);
2065 home_server *home_server_byname(const char *name)
2069 memset(&myhome, 0, sizeof(myhome));
2072 return rbtree_finddata(home_servers_byname, &myhome);
2077 home_server *home_server_bynumber(int number)
2081 memset(&myhome, 0, sizeof(myhome));
2082 myhome.number = number;
2083 myhome.server = NULL; /* we're not called for internal proxying */
2085 return rbtree_finddata(home_servers_bynumber, &myhome);
2089 home_pool_t *home_pool_byname(const char *name, int type)
2093 memset(&mypool, 0, sizeof(mypool));
2095 mypool.server_type = type;
2096 return rbtree_finddata(home_pools_byname, &mypool);